[ Index ]

PHP Cross Reference of phpBB 3.0 Beta 3

title

Body

[close]

/includes/acp/ -> acp_email.php (source)

   1  <?php
   2  /** 
   3  *
   4  * @package acp
   5  * @version $Id: acp_email.php,v 1.22 2006/11/03 21:04:09 acydburn Exp $
   6  * @copyright (c) 2005 phpBB Group 
   7  * @license http://opensource.org/licenses/gpl-license.php GNU Public License 
   8  *
   9  */
  10  
  11  /**
  12  * @package acp
  13  */
  14  class acp_email
  15  {
  16      var $u_action;
  17  
  18  	function main($id, $mode)
  19      {
  20          global $config, $db, $user, $auth, $template, $cache;
  21          global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
  22  
  23          $user->add_lang('acp/email');
  24          $this->tpl_name = 'acp_email';
  25          $this->page_title = 'ACP_MASS_EMAIL';
  26  
  27          // Set some vars
  28          $submit = (isset($_POST['submit'])) ? true : false;
  29          $error = array();
  30  
  31          $usernames    = request_var('usernames', '', true);
  32          $group_id    = request_var('g', 0);
  33          $subject    = request_var('subject', '', true);
  34          $message    = request_var('message', '', true);
  35  
  36          // Do the job ...
  37          if ($submit)
  38          {
  39              // Error checking needs to go here ... if no subject and/or no message then skip 
  40              // over the send and return to the form
  41              $use_queue        = (isset($_POST['send_immediatly'])) ? false : true;
  42              $priority        = request_var('mail_priority_flag', MAIL_NORMAL_PRIORITY);
  43  
  44              if (!$subject)
  45              {
  46                  $error[] = $user->lang['NO_EMAIL_SUBJECT'];
  47              }
  48  
  49              if (!$message)
  50              {
  51                  $error[] = $user->lang['NO_EMAIL_MESSAGE'];
  52              }
  53  
  54              if (!sizeof($error))    
  55              {
  56                  if ($usernames)
  57                  {
  58                      $sql = 'SELECT username, user_email, user_jabber, user_notify_type, user_lang 
  59                          FROM ' . USERS_TABLE . '
  60                          WHERE ' . $db->sql_in_set('username_clean', array_map('utf8_clean_string', explode("\n", $usernames))) . '
  61                              AND user_allow_massemail = 1
  62                          ORDER BY user_lang, user_notify_type'; // , SUBSTRING(user_email FROM INSTR(user_email, '@'))
  63                  }
  64                  else
  65                  {
  66                      if ($group_id)
  67                      {
  68                          $sql = 'SELECT u.user_email, u.username, u.user_lang, u.user_jabber, u.user_notify_type 
  69                              FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug 
  70                              WHERE ug.group_id = $group_id 
  71                                  AND ug.user_pending = 0
  72                                  AND u.user_id = ug.user_id 
  73                                  AND u.user_allow_massemail = 1
  74                              ORDER BY u.user_lang, u.user_notify_type";
  75                      }
  76                      else
  77                      {
  78                          $sql = 'SELECT username, user_email, user_jabber, user_notify_type, user_lang 
  79                              FROM ' . USERS_TABLE . '
  80                              WHERE user_allow_massemail = 1
  81                              ORDER BY user_lang, user_notify_type';
  82                      }
  83                  }
  84                  $result = $db->sql_query($sql);
  85                  $row = $db->sql_fetchrow($result);
  86  
  87                  if (!$row)
  88                  {
  89                      $db->sql_freeresult($result);
  90                      trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING);
  91                  }
  92      
  93                  $i = $j = 0;
  94  
  95                  // Send with BCC, no more than 50 recipients for one mail (to not exceed the limit)
  96                  $max_chunk_size = 50;
  97                  $email_list = array();
  98                  $old_lang = $row['user_lang'];
  99                  $old_notify_type = $row['user_notify_type'];
 100  
 101                  do
 102                  {
 103                      if (($row['user_notify_type'] == NOTIFY_EMAIL && $row['user_email']) ||
 104                          ($row['user_notify_type'] == NOTIFY_IM && $row['user_jabber']) ||
 105                          ($row['user_notify_type'] == NOTIFY_BOTH && $row['user_email'] && $row['user_jabber']))
 106                      {
 107                          if ($i == $max_chunk_size || $row['user_lang'] != $old_lang || $row['user_notify_type'] != $old_notify_type)
 108                          {
 109                              $i = 0;
 110                              $j++;
 111                              $old_lang = $row['user_lang'];
 112                              $old_notify_type = $row['user_notify_type'];
 113                          }
 114  
 115                          $email_list[$j][$i]['lang']        = $row['user_lang'];
 116                          $email_list[$j][$i]['method']    = $row['user_notify_type'];
 117                          $email_list[$j][$i]['email']    = $row['user_email'];
 118                          $email_list[$j][$i]['name']        = $row['username'];
 119                          $email_list[$j][$i]['jabber']    = $row['user_jabber'];
 120                          $i++;
 121                      }
 122                  }
 123                  while ($row = $db->sql_fetchrow($result));
 124                  $db->sql_freeresult($result);
 125  
 126                  // Send the messages
 127                  include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
 128                  include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
 129                  $messenger = new messenger($use_queue);
 130  
 131                  $errored = false;
 132  
 133                  for ($i = 0, $size = sizeof($email_list); $i < $size; $i++)
 134                  {
 135                      $used_lang = $email_list[$i][0]['lang'];
 136                      $used_method = $email_list[$i][0]['method'];
 137  
 138                      for ($j = 0, $list_size = sizeof($email_list[$i]); $j < $list_size; $j++)
 139                      {
 140                          $email_row = $email_list[$i][$j];
 141  
 142                          $messenger->{((sizeof($email_list[$i]) == 1) ? 'to' : 'bcc')}($email_row['email'], $email_row['name']);
 143                          $messenger->im($email_row['jabber'], $email_row['name']);
 144                      }
 145  
 146                      $messenger->template('admin_send_email', $used_lang);
 147  
 148                      $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
 149                      $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
 150                      $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
 151                      $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
 152              
 153                      $messenger->subject(htmlspecialchars_decode($subject));
 154                      $messenger->replyto($config['board_email']);
 155                      $messenger->set_mail_priority($priority);
 156  
 157                      $messenger->assign_vars(array(
 158                          'CONTACT_EMAIL' => $config['board_contact'],
 159                          'MESSAGE'        => htmlspecialchars_decode($message))
 160                      );
 161      
 162                      if (!($messenger->send($used_method)))
 163                      {
 164                          $errored = true;
 165                      }
 166                  }
 167                  unset($email_list);
 168  
 169                  $messenger->save_queue();
 170  
 171                  if ($group_id)
 172                  {
 173                      $group_name = get_group_name($group_id);
 174                  }
 175                  else
 176                  {
 177                      // Not great but the logging routine doesn't cope well with localising on the fly
 178                      $group_name = $user->lang['ALL_USERS'];
 179                  }
 180  
 181                  add_log('admin', 'LOG_MASS_EMAIL', $group_name);
 182  
 183                  if (!$errored)
 184                  {
 185                      $message = ($use_queue) ? $user->lang['EMAIL_SENT_QUEUE'] : $user->lang['EMAIL_SENT'];
 186                      trigger_error($message . adm_back_link($this->u_action));
 187                  }
 188                  else
 189                  {
 190                      $message = sprintf($user->lang['EMAIL_SEND_ERROR'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=logs&amp;mode=critical') . '">', '</a>');
 191                      trigger_error($message . adm_back_link($this->u_action), E_USER_WARNING);
 192                  }
 193              }
 194          }
 195  
 196          // Exclude bots...
 197          $sql = 'SELECT group_id
 198              FROM ' . GROUPS_TABLE . "
 199              WHERE group_name = 'BOTS'";
 200          $result = $db->sql_query($sql);
 201          $bot_group_id = (int) $db->sql_fetchfield('group_id');
 202          $db->sql_freeresult($result);
 203  
 204          $select_list = '<option value="0"' . ((!$group_id) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_USERS'] . '</option>';
 205          $select_list .= group_select_options($group_id, array($bot_group_id));
 206          
 207          $s_priority_options = '<option value="' . MAIL_LOW_PRIORITY . '">' . $user->lang['MAIL_LOW_PRIORITY'] . '</option>';
 208          $s_priority_options .= '<option value="' . MAIL_NORMAL_PRIORITY . '" selected="selected">' . $user->lang['MAIL_NORMAL_PRIORITY'] . '</option>';
 209          $s_priority_options .= '<option value="' . MAIL_HIGH_PRIORITY . '">' . $user->lang['MAIL_HIGH_PRIORITY'] . '</option>';
 210  
 211          $template->assign_vars(array(
 212              'S_WARNING'                => (sizeof($error)) ? true : false,
 213              'WARNING_MSG'            => (sizeof($error)) ? implode('<br />', $error) : '',
 214              'U_ACTION'                => $this->u_action,
 215              'S_GROUP_OPTIONS'        => $select_list,
 216              'USERNAMES'                => $usernames,
 217              'U_FIND_USERNAME'        => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=acp_email&amp;field=usernames'),
 218              'UA_FIND_USERNAME'        => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=acp_email&field=usernames', false),
 219              'SUBJECT'                => $subject,
 220              'MESSAGE'                => $message,
 221              'S_PRIORITY_OPTIONS'    => $s_priority_options)
 222          );
 223  
 224      }
 225  }
 226  
 227  ?>


Generated: Wed Nov 22 00:35:05 2006 Cross-referenced by PHPXref 0.6