function pm_email_notify_user in Privatemsg 6.2
Same name and namespace in other branches
- 6 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 371 - 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') {
$form['privatemsg']['pm_show_sender_mail'] = array(
'#type' => 'checkbox',
'#title' => t('Show my email address'),
'#description' => t('Use my private email address as a sender for notification mails to users I have sent private messages to. If unchecked, the notification will be sent by a generic account.'),
'#default_value' => _pm_email_notify_show_sender($account->uid),
'#access' => privatemsg_user_access('write privatemsg'),
);
if (privatemsg_user_access('read privatemsg', $account)) {
if (privatemsg_user_access('set privatemsg e-mail notification level')) {
$form['privatemsg']['pm_email_notify_level'] = array(
'#type' => 'radios',
'#title' => t('Send me an e-mail notification...'),
'#options' => array(
PM_EMAIL_NOTIFY_LEVEL_DISABLED => t('Never.'),
PM_EMAIL_NOTIFY_LEVEL_THREAD => t('Only for a new conversation'),
PM_EMAIL_NOTIFY_LEVEL_UNREAD_ONCE => t("Only once for a conversation until I've read the messages"),
PM_EMAIL_NOTIFY_LEVEL_ALL => t('Every time I receive a message'),
),
'#default_value' => _pm_email_notify_user_level($account->uid),
);
}
else {
// If the user does not have permissions to customize the notification
// level, allow him to opt out of email notifications if they are not
// disabled by default.
$is_enabled = _pm_email_notify_user_level();
$form['privatemsg']['pm_email_notify_level'] = array(
'#type' => 'checkbox',
'#title' => t('Receive email notification for incoming private messages'),
'#default_value' => $is_enabled ? PM_EMAIL_NOTIFY_LEVEL_DEFAULT : PM_EMAIL_NOTIFY_LEVEL_DISABLED,
'#access' => $is_enabled,
);
}
$form['privatemsg']['pm_email_only_user'] = array(
'#type' => 'checkbox',
'#title' => t("Don't send me e-mail notifications for mass messages."),
'#default_value' => _pm_email_notify_only_user($account->uid),
'#access' => privatemsg_user_access('change privatemsg e-mail notification for indirect messages'),
);
}
}
return $form;
case 'submit':
if (isset($edit['pm_email_notify_level'])) {
privatemsg_set_setting('user', $account->uid, 'email_notify_level', $edit['pm_email_notify_level']);
unset($edit['pm_email_notify_level']);
}
if (isset($edit['pm_email_only_user'])) {
privatemsg_set_setting('user', $account->uid, 'email_notify_only_user', $edit['pm_email_only_user']);
unset($edit['pm_email_only_user']);
}
if (isset($edit['pm_show_sender_mail'])) {
privatemsg_set_setting('user', $account->uid, 'show_sender_mail', $edit['pm_show_sender_mail']);
unset($edit['pm_show_sender_mail']);
}
break;
case 'delete':
privatemsg_del_setting('user', $account->uid, 'email_notify_level');
privatemsg_del_setting('user', $account->uid, 'email_notify_only_user');
privatemsg_del_setting('user', $account->uid, 'show_sender_mail');
break;
}
}