| 1 |
<?php |
<?php |
| 2 |
|
|
| 3 |
// $Id: $ |
// $Id: mail.module,v 1.20 2006/10/16 16:59:40 nedjo Exp $ |
| 4 |
|
|
| 5 |
/** |
/** |
| 6 |
* Provide online user help |
* Provide online user help |
| 161 |
} |
} |
| 162 |
|
|
| 163 |
$node = $form['#node']; |
$node = $form['#node']; |
| 164 |
if ($form['type']['#value'] .'_node_form' == $form_id && variable_get("mail_$node->type", TRUE) && user_access('send mail to users')) { |
if ($form['type']['#value'] .'_node_form' == $form_id && variable_get("mail_$node->type", FALSE) && user_access('send mail to users')) { |
| 165 |
|
|
| 166 |
$form['mail_options'] = array( |
$form['mail_options'] = array( |
| 167 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 173 |
'#title' => t('Email out a copy of this post'), |
'#title' => t('Email out a copy of this post'), |
| 174 |
'#default_value' => $node->mail_out, |
'#default_value' => $node->mail_out, |
| 175 |
); |
); |
| 176 |
|
$roles = user_roles(TRUE); |
| 177 |
|
unset($roles[DRUPAL_AUTHENTICATED_RID]); |
| 178 |
$form['mail_options']['mail_roles_selected'] = array( |
$form['mail_options']['mail_roles_selected'] = array( |
| 179 |
'#type' => 'checkboxes', |
'#type' => 'checkboxes', |
| 180 |
'#title' => t('Roles'), |
'#title' => t('Roles'), |
| 181 |
'#default_value' => $node->mail_roles_selected ? $node->mail_roles_selected : array(), |
'#default_value' => $node->mail_roles_selected ? $node->mail_roles_selected : array(), |
| 182 |
'#options' => user_roles(1), |
'#options' => $roles, |
| 183 |
'#description' => t('Select roles to send the email to. At least one role is required for email to be sent.'), |
'#description' => t('Select roles to send the email to. At least one role is required for email to be sent.'), |
| 184 |
); |
); |
| 185 |
$form['mail_options']['mail_format'] = array( |
$form['mail_options']['mail_format'] = array( |
| 219 |
*/ |
*/ |
| 220 |
function mail_nodeapi(&$node, $op, $arg) { |
function mail_nodeapi(&$node, $op, $arg) { |
| 221 |
global $db_url; |
global $db_url; |
| 222 |
|
if (variable_get('mail_'. $node->type, FALSE) && user_access('send mail to users')) { |
|
if (variable_get('mail_'. $node->type, 0) && user_access('send mail to users')) { |
|
| 223 |
switch ($op) { |
switch ($op) { |
| 224 |
case 'validate': |
case 'validate': |
| 225 |
if ($node->mail_out && empty($node->mail_roles_selected)) { |
if ($node->mail_out && empty($node->mail_roles_selected)) { |
| 228 |
break; |
break; |
| 229 |
case 'insert': |
case 'insert': |
| 230 |
case 'update': |
case 'update': |
| 231 |
if($node->mail_out) { |
if($node->mail_out && $node->status && !$node->moderate) { |
| 232 |
$node->mail_roles_selected = array_filter($node->mail_roles_selected); |
$node->mail_roles_selected = array_filter($node->mail_roles_selected); |
| 233 |
_mail_dispatch($node); |
_mail_dispatch($node); |
| 234 |
$db_type = substr($db_url, 0, strpos($db_url, '://')); |
$db_type = substr($db_url, 0, strpos($db_url, '://')); |
| 235 |
if ($db_type != 'pgsql') { |
if ($db_type != 'pgsql') { |
| 236 |
$body = '<p>' . t('This email was sent to users with the following roles: ') . implode(', ', _mail_get_roles_names($node->mail_roles_selected)) . "</p>\n"; |
$body = '<p>' . t('This email was sent to users with the following roles: ') . implode(', ', _mail_get_roles_names($node->mail_roles_selected)) . "</p>\n"; |
| 237 |
$body .= $node->body; |
$node->body = $body . $node->body; |
| 238 |
db_query('UPDATE {node} SET body = %s WHERE nid = %d', $node->nid, $body); |
$node->mail_out = FALSE; |
| 239 |
|
node_save($node); |
| 240 |
} |
} |
| 241 |
} |
} |
| 242 |
break; |
break; |
| 269 |
'#default_value' => $edit['mail_accept'], |
'#default_value' => $edit['mail_accept'], |
| 270 |
'#description' => t('Allow users posting content to sent it to you by email. Note that your e-mail address is not made public and that privileged users such as site administrators are able to email you even if you choose not to enable this feature.'), |
'#description' => t('Allow users posting content to sent it to you by email. Note that your e-mail address is not made public and that privileged users such as site administrators are able to email you even if you choose not to enable this feature.'), |
| 271 |
); |
); |
| 272 |
|
return $form; |
| 273 |
} |
} |
| 274 |
elseif ($type == 'validate') { |
elseif ($type == 'validate') { |
| 275 |
return array('mail_accept' => $edit['mail_accept']); |
return array('mail_accept' => $edit['mail_accept']); |
| 328 |
} |
} |
| 329 |
(count($roles_where) > 0) ? $where = ' AND (' . implode(' OR ', $roles_where) . ') ': $where = ''; |
(count($roles_where) > 0) ? $where = ' AND (' . implode(' OR ', $roles_where) . ') ': $where = ''; |
| 330 |
$result = db_query('SELECT DISTINCT(u.uid) FROM {users} u, {role} r, {users_roles} s WHERE u.uid = s.uid AND r.rid = s.rid AND u.status != 0' . $where); |
$result = db_query('SELECT DISTINCT(u.uid) FROM {users} u, {role} r, {users_roles} s WHERE u.uid = s.uid AND r.rid = s.rid AND u.status != 0' . $where); |
| 331 |
$success = true; |
$success = TRUE; |
| 332 |
while ($uid = db_fetch_object($result)) { |
while ($uid = db_fetch_object($result)) { |
| 333 |
$account = user_load(array('uid' => $uid->uid, 'status' => 1)); |
$account = user_load(array('uid' => $uid->uid, 'status' => 1)); |
| 334 |
if (!$account->mail_accept && !user_access('administer users')) { |
if (!$account->mail_accept && !user_access('administer users')) { |
| 345 |
$node->message = theme('mail_message', $node); |
$node->message = theme('mail_message', $node); |
| 346 |
} |
} |
| 347 |
if(!mail_send($node)) { |
if(!mail_send($node)) { |
| 348 |
$success = false; |
$success = FALSE; |
| 349 |
} |
} |
| 350 |
} |
} |
| 351 |
} |
} |