function pm_email_notify_user in Privatemsg 6
Same name and namespace in other branches
- 6.2 pm_email_notify/pm_email_notify.module \pm_email_notify_user()
Implements hook_user().
Display settings form and store its information.
File
- pm_email_notify/
pm_email_notify.module, line 152 - Notifies users about new Private Messages via Email.
Code
function pm_email_notify_user($op, &$edit, &$account, $category = NULL) {
switch ($op) {
case 'form':
if ($category == 'account' && privatemsg_user_access('read privatemsg', $account)) {
$form['enable_pm_mail'] = array(
'#type' => 'fieldset',
'#title' => t('Privatemsg e-mail notification'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight' => 10,
);
$form['enable_pm_mail']['pm_send_notifications'] = array(
'#type' => 'checkbox',
'#title' => t('Receive email notification for incoming private messages'),
'#default_value' => _pm_email_notify_is_enabled($account->uid),
);
}
return $form;
case 'submit':
if (isset($edit['pm_send_notifications']) && privatemsg_user_access('read privatemsg', $account)) {
$pm_email_enabled = $edit['pm_send_notifications'];
unset($edit['pm_send_notifications']);
// Update database entry with user preference.
$exists = db_result(db_query("SELECT 1 FROM {pm_email_notify} WHERE user_id = %d", $account->uid));
if ($exists) {
// If there is an existing entry, update.
db_query("UPDATE {pm_email_notify} SET email_notify_is_enabled = %d WHERE user_id = %d", $pm_email_enabled, $account->uid);
}
else {
// If not, create a new one.
db_query("INSERT INTO {pm_email_notify} (email_notify_is_enabled, user_id) VALUES (%d, %d)", $pm_email_enabled, $account->uid);
}
}
break;
case 'delete':
db_query("DELETE FROM {pm_email_notify} WHERE user_id = %d", $account->uid);
break;
}
}