Notify Admin on Registration

Any abandoned MODs will be moved to this forum.

WARNING: MODs in this forum are not currently being supported or maintained by the original MOD author. Proceed at your own risk.
Forum rules
IMPORTANT: MOD Development Forum rules

WARNING: MODs in this forum are not currently being supported nor updated by the original MOD author. Proceed at your own risk.
MarkieMark1
Registered User
Posts: 5
Joined: Fri Feb 26, 2010 2:17 pm

Re: Notify Admin on Registration

Post by MarkieMark1 »

Hi,

for those who were looking for a way to allow individual admins to set the notification as active / inactive, here's the way I approached it

1 create a custom profile field, I call it 'admin_notn' [boolean, default=no] - the name is hard-coded here, although a more robust implementation would at least check the PROFILE_FIELDS_TABLE [phpbb_profile_fields] for the name of the column before risking an SQL error retrieving a value for the column from PROFILE_FIELDS_DATA_TABLE

2 make that profile field hidden - since 3.0.4 no MOD is necessary for that purpose, although some modification of the code is necessary to hide the field from Mods so that it's strictly admin who are allowed notifications; see http://www.phpbb.com/community/viewtopi ... 5&start=30 for detail of how to hide the field as well as how to adapt the code to hide the field from Mods

3 change the SQL that this MOD adds to the code of the file includes/ucp/ucp_register.php

from

Code: Select all

					// Also include founders
						$where_sql = ' WHERE user_type = ' . USER_FOUNDER;

						if (sizeof($admin_ary))
						{
							$where_sql .= ' OR ' . $db->sql_in_set('user_id', $admin_ary);
						}

						$sql = 'SELECT user_id, username, user_email, user_lang, user_jabber, user_notify_type
							FROM ' . USERS_TABLE . ' ' .
							$where_sql;
						$result = $db->sql_query($sql);
						while ($row = $db->sql_fetchrow($result))
						{
							$messenger->template('admin_notify_registered', $row['user_lang']);
							$messenger->to($row['user_email'], $row['username']);
							$messenger->im($row['user_jabber'], $row['username']);

							$messenger->assign_vars(array(
								'USERNAME'			=> htmlspecialchars_decode($data['username']),
								'USER_MAIL'			=> $data['email'],
								'USER_REGDATE'		=> date($config['default_dateformat'], $user_row['user_regdate']))
							);

							$messenger->send($row['user_notify_type']);
to

Code: Select all

						// Also include founders
						$where_sql = ' WHERE (u.user_type = ' . USER_FOUNDER;

						if (sizeof($admin_ary))
						{
							$where_sql .= ' OR ' . $db->sql_in_set('u.user_id', $admin_ary) . ') ';
						} else {
							$where_sql .= ') ';
						}
						
						$where_sql .= " AND f.pf_admin_notn = '1' ";

						$sql = 'SELECT u.user_id AS id, u.username AS name, '.
								'u.user_email AS email, u.user_lang AS lang, '. 
								'u.user_jabber AS jabber, u.user_notify_type '.
								'AS type FROM ' . USERS_TABLE . ' AS u NATURAL JOIN '.
								PROFILE_FIELDS_DATA_TABLE . ' AS f ' . $where_sql;
						$result = $db->sql_query($sql);
						
						while ($row = $db->sql_fetchrow($result))
						{
							$messenger->template('admin_notify_registered', $row['lang']);
							$messenger->to($row['email'], $row['name']);
							$messenger->im($row['jabber'], $row['name']);

							$messenger->assign_vars(array(
								'USERNAME'			=> htmlspecialchars_decode($data['username']),
								'USER_MAIL'			=> $data['email'],
								'USER_REGDATE'		=> date($config['default_dateformat'], $user_row['user_regdate']),
								'USER_IP'			=> $user_row['user_ip'],
								'MEMBERLINK'		=> "$server_url/memberlist.$phpEx?mode=viewprofile&u=$user_id")
							);

							$messenger->send($row['type']);
[the SQL I've written here is for MySQL, a more robust implementation would connect to the phpbb array->sql functions, YMMV]

Best

Mark
Post Reply

Return to “[3.0.x] Abandoned MODs”