| 1 |
<?php |
<?php |
| 2 |
// $Id: user_edit_notify.module,v 1.0 2007/12/08 13:31:54 davistv Exp $ |
// ; $Id$ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 6 |
* Notifies site_mail of user profile modifications. |
* Notifies a configurable email address of user profile modifications. |
| 7 |
|
* If email isn't set, defaults to site_mail or sendmail_from. |
| 8 |
*/ |
*/ |
| 9 |
|
|
| 10 |
/** |
/** |
| 11 |
|
* Display help and module information |
| 12 |
|
* @param section which section of the site we're displaying help |
| 13 |
|
* @return help text for section |
| 14 |
|
*/ |
| 15 |
|
function user_edit_notify_help($section='') { |
| 16 |
|
|
| 17 |
|
$output = ''; |
| 18 |
|
|
| 19 |
|
switch ($section) { |
| 20 |
|
case "admin/help#user_edit_notify": |
| 21 |
|
$output = '<p>'. t("Notifies a configurable email of changes to user profiles. |
| 22 |
|
Falls back on sending email to site_mail or sendmail_from if possible. |
| 23 |
|
Be sure to configure the <a href='/admin/user/access'>Access control</a> so the menu |
| 24 |
|
item appears under <a href='/admin/settings'>Site configuration</a>. Then proceed |
| 25 |
|
to <a href='/admin/settings/edit_notify'>Site configuration -> User edit notification</a> |
| 26 |
|
to set the email address that will receive notifications.") . '</p>'; |
| 27 |
|
break; |
| 28 |
|
} |
| 29 |
|
|
| 30 |
|
return $output; |
| 31 |
|
} // function user_edit_notify_help |
| 32 |
|
|
| 33 |
|
/** |
| 34 |
|
* Valid permissions for this module |
| 35 |
|
* @return array An array of valid permissions for the user_edit_notify module |
| 36 |
|
*/ |
| 37 |
|
|
| 38 |
|
function user_edit_notify_perm() { |
| 39 |
|
return array('administer user_edit_notify'); |
| 40 |
|
} // function user_edit_notify_perm() |
| 41 |
|
|
| 42 |
|
/** |
| 43 |
* Implementation of hook_user(). |
* Implementation of hook_user(). |
| 44 |
*/ |
*/ |
| 45 |
function user_edit_notify_user($op, &$edit, &$account, $category = NULL) { |
function user_edit_notify_user($op, &$edit, &$account, $category = NULL) { |
| 46 |
switch ($op) { |
switch ($op) { |
| 47 |
case 'after_update': |
case 'after_update': |
| 48 |
if ($account->status) { |
if ($account->status) { |
| 49 |
$account_info = user_load(array('uid' => $account->uid)); |
$user_edit_notify_mailto = variable_get('user_edit_notify_mailto', ''); |
| 50 |
$subject = t('Edited account details for !username at !site', array('!username' => $account->name, '!site' => variable_get('site_name', 'Drupal'))); |
if ($user_edit_notify_mailto == '') { |
| 51 |
$to = $from = variable_get('site_mail', ini_get('sendmail_from')); |
$user_edit_notify_mailto = variable_get('site_mail', ''); |
|
$body = t("!user (!uri) has edited their profile.\n\n!edit-uri", array('!uri' => url("user/$account->uid", NULL, NULL, TRUE), '!user' => $account->name, '!edit-uri' => url("user/$account->uid/edit", NULL, NULL, TRUE))); |
|
|
|
|
|
$body .= "\n\nAccount Information:\n\n"; |
|
|
|
|
|
$body .= "Email: " . $account->mail . "\n\n"; |
|
|
|
|
|
$result = db_query('SELECT * FROM {profile_fields} ORDER BY category, weight'); |
|
|
while ($field = db_fetch_object($result)) { |
|
|
$options[$field->name] = $field->title; |
|
| 52 |
} |
} |
| 53 |
foreach ($options as $key => $value) { |
if ($user_edit_notify_mailto == '') { |
| 54 |
$body .= $value . ": " . $account_info->$key . "\n\n"; |
$user_edit_notify_mailto = ini_get('sendmail_from'); |
| 55 |
|
} |
| 56 |
|
if ($user_edit_notify_mailto == '') { |
| 57 |
|
# Can't send email, abort |
| 58 |
|
} else { |
| 59 |
|
$account_info = user_load(array('uid' => $account->uid)); |
| 60 |
|
$subject = t('Edited account details for !username at !site', array('!username' => $account->name, '!site' => variable_get('site_name', 'Drupal'))); |
| 61 |
|
|
| 62 |
|
$to = $from = $user_edit_notify_mailto; |
| 63 |
|
$body = t("!user (!uri) has edited their profile.\n\n!edit-uri", array('!uri' => url("user/$account->uid", NULL, NULL, TRUE), '!user' => $account->name, '!edit-uri' => url("user/$account->uid/edit", NULL, NULL, TRUE))); |
| 64 |
|
|
| 65 |
|
$body = $body . "\n\nAccount Information:\n\n"; |
| 66 |
|
|
| 67 |
|
$body = $body . "Email: " . $account->mail . "\n\n"; |
| 68 |
|
|
| 69 |
|
$result = db_query('SELECT * FROM {profile_fields} ORDER BY category, weight'); |
| 70 |
|
while ($field = db_fetch_object($result)) { |
| 71 |
|
$options[$field->name] = $field->title; |
| 72 |
|
} |
| 73 |
|
foreach ($options as $key => $value) { |
| 74 |
|
$body = $body . $value . ": " . $account_info->$key . "\n\n"; |
| 75 |
|
} |
| 76 |
|
|
| 77 |
|
drupal_mail( |
| 78 |
|
'user-edit-notify-admin', |
| 79 |
|
$to, |
| 80 |
|
$subject, |
| 81 |
|
$body, |
| 82 |
|
$from |
| 83 |
|
); |
| 84 |
} |
} |
|
|
|
|
drupal_mail( |
|
|
'user-edit-notify-admin', |
|
|
$to, |
|
|
$subject, |
|
|
$body, |
|
|
$from |
|
|
); |
|
| 85 |
} |
} |
| 86 |
break; |
break; |
| 87 |
} |
} |
| 88 |
} |
} |
| 89 |
|
|
| 90 |
|
/** |
| 91 |
|
* Implementation of hook_menu(). |
| 92 |
|
*/ |
| 93 |
|
function user_edit_notify_menu($may_cache) { |
| 94 |
|
$items = array(); |
| 95 |
|
if ($may_cache) { |
| 96 |
|
$items[] = array( |
| 97 |
|
'path' => 'admin/settings/edit_notify', |
| 98 |
|
'title' => t('User edit notification'), |
| 99 |
|
'callback' => 'drupal_get_form', |
| 100 |
|
'callback arguments' => array('user_edit_notify_settings'), |
| 101 |
|
'description' => t('Configure the User edit notification module.'), |
| 102 |
|
'access' => user_access('administer user_edit_notify settings'), |
| 103 |
|
'type' => MENU_NORMAL_ITEM, |
| 104 |
|
); |
| 105 |
|
} |
| 106 |
|
return $items; |
| 107 |
|
} |
| 108 |
|
|
| 109 |
|
|
| 110 |
|
/** |
| 111 |
|
* Menu callback for admin settings form. |
| 112 |
|
*/ |
| 113 |
|
function user_edit_notify_settings() { |
| 114 |
|
$def_val = variable_get('site_mail', ''); |
| 115 |
|
if ($def_val == '') { |
| 116 |
|
$def_val = ini_get('sendmail_from'); |
| 117 |
|
} |
| 118 |
|
$form['user_edit_notify_mailto'] = array( |
| 119 |
|
'#type' => 'textfield', |
| 120 |
|
'#title' => t('Send notifications to this email address'), |
| 121 |
|
'#description' => t('If you leave this blank, the site email address, %mailto, will be used.', array('%mailto' => $def_val)), |
| 122 |
|
'#default_value' => variable_get('user_edit_notify_mailto', ''), |
| 123 |
|
'#size' => 40, |
| 124 |
|
'#maxlength' => 255, |
| 125 |
|
); |
| 126 |
|
return system_settings_form($form); |
| 127 |
|
} |