/[drupal]/contributions/modules/user_register_notify/user_register_notify.module
ViewVC logotype

Contents of /contributions/modules/user_register_notify/user_register_notify.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.20 - (show annotations) (download) (as text)
Thu Jul 2 03:41:42 2009 UTC (4 months, 3 weeks ago) by rmiddle
Branch: MAIN
CVS Tags: DRUPAL-6--1-11, HEAD
Changes since 1.19: +7 -9 lines
File MIME type: text/x-php
[#491114] Thanks iva2k Cleans up the custom email address and roles
1 <?php
2 // $Id: user_register_notify.module,v 1.19 2009/07/02 03:16:51 rmiddle Exp $
3 // Built for Drupal 6
4
5 /**
6 * @file
7 * Notifies administrator of new user registrations.
8 */
9
10 /**
11 * Implementation of hook_help().
12 */
13 function user_register_notify_help($path, $arg) {
14 if ($path == 'admin/help#user_register_notify') {
15 return '<p>'.
16 t('This module provides a way for an administrator to get'.
17 'an email when a user account is created. '.
18 'It assumes that the Drupal mailer is configured.') .
19 '</p>';
20 }
21 }
22
23 define('USER_REGISTER_NOTIFY_SUBJECT', t('Account details for !user_name at !site'));
24 define('USER_REGISTER_NOTIFY_BODY', t("!user_name (!user_view) has !action account.\n\nEdit user: !user_edit\n\nDelete User: !user_delete\n\n!profile"));
25
26 /**
27 * Implementation of hook_menu().
28 */
29 function user_register_notify_menu() {
30 $items['admin/settings/register_notify'] = array(
31 'title' => 'User Register Notify',
32 'page callback' => 'drupal_get_form',
33 'page arguments' => array('user_register_notify_settings'),
34 'description' => 'Configure the User Register Notify module.',
35 'file' => 'user_register_notify.admin.inc',
36 'access arguments' => array('administer site configuration'),
37 );
38 return $items;
39 }
40
41 function user_register_notify_setup_email(&$edit, &$account, $action = 'insert') {
42 // Notify administrator of new user only if this is not first user and
43 // if visitors can create accounts without administrator's approval.
44 // In case when accounts must be created with administrator's approval
45 // there is already a 'pending approval' e-mail notification.
46 if ($account->uid != 1 && (variable_get('user_register', 1) == 1 ? $account->status : !$account->status)) {
47 $notify_type = variable_get('user_register_notify_type', 'Custom');
48 $from = variable_get('site_mail', ini_get('sendmail_from'));
49 $params = array(
50 'account' => $account,
51 'action' => $action,
52 );
53
54 $emails = array();
55 switch ($notify_type) {
56 case 'Custom':
57 $emails = preg_split('/,[\w]+/', variable_get('user_register_notify_mailto', $from));
58 break;
59 case 'Both':
60 $emails = preg_split('/,[\w]+/', variable_get('user_register_notify_mailto', $from));
61 // There is no break here for a reason.
62 case 'Role':
63 $roles = implode(',', variable_get('user_register_notify_roles', array()));
64 if (!empty($roles)) {
65 $result = db_query("SELECT mail FROM {users} AS u INNER JOIN {users_roles} AS r ON u.uid = r.uid WHERE r.rid IN('%s')", $roles);
66 while ($mail = db_fetch_object($result)) {
67 $emails[] = $mail->mail;
68 }
69 }
70 break;
71 }
72 $emails = array_unique($emails);
73 $to = implode(', ', $emails);
74
75 // watchdog('user_register_notify', check_plain($to));
76
77 drupal_mail(
78 'user_register_notify',
79 'user-register-notify-admin',
80 $to,
81 language_default(),
82 $params,
83 $from,
84 TRUE // Automatically send
85 );
86 }
87 }
88
89
90 /**
91 * Implementation of hook_user().
92 */
93 function user_register_notify_user($op, &$edit, &$account, $category = NULL) {
94 switch ($op) {
95 case 'insert':
96 user_register_notify_setup_email($edit, $account);
97 break;
98 case 'update':
99 if (variable_get('user_register_notify_alert', 'create') == 'update')
100 user_register_notify_setup_email($edit, $account, 'update');
101 break;
102 }
103 }
104
105
106
107 function user_register_notify_mail($key, &$message, $params) {
108 global $base_url;
109 if ($key == 'user-register-notify-admin') {
110 $language = $message['language'];
111 $langcode = $language->language;
112 $uaccount = $params['account'];
113 $profile_data = "";
114 $og_data = "";
115
116 if ($params['action'] == 'insert') {
117 $action = 'created';
118 }
119 else {
120 $action = 'updated';
121 }
122 if (module_exists('profile')) {
123 $result = db_query('SELECT f.title, f.name, f.type, v.value FROM {profile_fields} f INNER JOIN {profile_values} v ON f.fid = v.fid WHERE uid = %d', $uaccount->uid);
124 while ($field = db_fetch_object($result)) {
125 switch ($field->type) {
126 case 'date':
127 $date_field = unserialize($field->value);
128 if (is_array($date_field)) {
129 $date_timestamp = mktime(0, 0, 0, $date_field['month'], $date_field['day'], $date_field['year']);
130 $profile_data .= sprintf("%s: %s\n", $field->title, format_date($date_timestamp));
131 $variables['!'. $field->name] = format_date($date_timestamp);
132 }
133 break;
134 case 'checkbox':
135 if ($field->value) {
136 $profile_data .= sprintf("%s: Checked\n", $field->title);
137 $variables['!'. $field->name] = "Checked";
138 }
139 else {
140 $profile_data .= sprintf("%s: Not Checked\n", $field->title);
141 $variables['!'. $field->name] = "Not Checked";
142 }
143 break;
144 default:
145 $profile_data .= sprintf("%s: %s\n", $field->title, $field->value);
146 $variables['!'. $field->name] = check_plain($field->value);
147 }
148 }
149 }
150 else {
151 $profile_data = t("Profile Module Not Installed.\n");
152 }
153
154 if (module_exists('og')) {
155 $result = db_query('SELECT o.og_description, n.title FROM {og_uid} u INNER JOIN {og} o ON o.nid = u.nid INNER JOIN {node} n on n.nid = u.nid WHERE u.uid = %d', $uaccount->uid);
156 $og_data = t("Organic groups belonged to:\n");
157
158 while ($og = db_fetch_object($result)) {
159 $og_data .= sprintf("%s - %s\n", $og->title, $og->og_description);
160 }
161 }
162 else {
163 $og_data = t("Organic Groups Module Not Installed.\n");
164 }
165
166 $variables['!user_name'] = isset($uaccount->realname) ? $uaccount->realname : $uaccount->name;
167 $variables['!user_mail'] = $uaccount->mail;
168 $variables['!user_view'] = url('user/'. $uaccount->uid, array('absolute' => TRUE));
169 $variables['!user_edit'] = url('user/'. $uaccount->uid .'/edit', array('absolute' => TRUE));
170 $variables['!user_delete'] = url('user/'. $uaccount->uid .'/delete', array('absolute' => TRUE));
171 $variables['!site'] = variable_get('site_name', 'Drupal');
172 $variables['!uri'] = $base_url;
173 $variables['!uri_brief'] = drupal_substr($base_url, drupal_strlen('http://'));
174 $variables['!date'] = format_date(time());
175 $variables['!profile'] = check_plain($profile_data);
176 $variables['!og'] = check_plain($og_data);
177 $variables['!action'] = check_plain($action);
178
179 $message['subject'] = t(variable_get('user_register_notify_subject', USER_REGISTER_NOTIFY_SUBJECT), $variables);
180 $message['body'] = t(variable_get('user_register_notify_body', USER_REGISTER_NOTIFY_BODY), $variables);
181 }
182 }
183

  ViewVC Help
Powered by ViewVC 1.1.2