[ Index ]

PHP Cross Reference of phpBB-3.3.11-deutsch

title

Body

[close]

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

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  /**
  15  * @ignore
  16  */
  17  if (!defined('IN_PHPBB'))
  18  {
  19      exit;
  20  }
  21  
  22  class acp_email
  23  {
  24      var $u_action;
  25  
  26  	function main($id, $mode)
  27      {
  28          global $config, $db, $user, $template, $phpbb_log, $request;
  29          global $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_dispatcher;
  30  
  31          $user->add_lang('acp/email');
  32          $this->tpl_name = 'acp_email';
  33          $this->page_title = 'ACP_MASS_EMAIL';
  34  
  35          $form_key = 'acp_email';
  36          add_form_key($form_key);
  37  
  38          // Set some vars
  39          $submit = (isset($_POST['submit'])) ? true : false;
  40          $error = array();
  41  
  42          $usernames    = $request->variable('usernames', '', true);
  43          $usernames    = (!empty($usernames)) ? explode("\n", $usernames) : array();
  44          $group_id    = $request->variable('g', 0);
  45          $subject    = $request->variable('subject', '', true);
  46          $message    = $request->variable('message', '', true);
  47  
  48          // Do the job ...
  49          if ($submit)
  50          {
  51              // Error checking needs to go here ... if no subject and/or no message then skip
  52              // over the send and return to the form
  53              $use_queue        = (isset($_POST['send_immediately'])) ? false : true;
  54              $priority        = $request->variable('mail_priority_flag', MAIL_NORMAL_PRIORITY);
  55  
  56              if (!check_form_key($form_key))
  57              {
  58                  $error[] = $user->lang['FORM_INVALID'];
  59              }
  60  
  61              if (!$subject)
  62              {
  63                  $error[] = $user->lang['NO_EMAIL_SUBJECT'];
  64              }
  65  
  66              if (!$message)
  67              {
  68                  $error[] = $user->lang['NO_EMAIL_MESSAGE'];
  69              }
  70  
  71              if (!count($error))
  72              {
  73                  if (!empty($usernames))
  74                  {
  75                      // If giving usernames the admin is able to email inactive users too...
  76                      $sql_ary = array(
  77                          'SELECT'    => 'username, user_email, user_jabber, user_notify_type, user_lang',
  78                          'FROM'        => array(
  79                              USERS_TABLE        => '',
  80                          ),
  81                          'WHERE'        => $db->sql_in_set('username_clean', array_map('utf8_clean_string', $usernames)) . '
  82                              AND user_allow_massemail = 1',
  83                          'ORDER_BY'    => 'user_lang, user_notify_type',
  84                      );
  85                  }
  86                  else
  87                  {
  88                      if ($group_id)
  89                      {
  90                          $sql_ary = array(
  91                              'SELECT'    => 'u.user_email, u.username, u.username_clean, u.user_lang, u.user_jabber, u.user_notify_type',
  92                              'FROM'        => array(
  93                                  USERS_TABLE            => 'u',
  94                                  USER_GROUP_TABLE    => 'ug',
  95                              ),
  96                              'WHERE'        => 'ug.group_id = ' . $group_id . '
  97                                  AND ug.user_pending = 0
  98                                  AND u.user_id = ug.user_id
  99                                  AND u.user_allow_massemail = 1
 100                                  AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')',
 101                              'ORDER_BY'    => 'u.user_lang, u.user_notify_type',
 102                          );
 103                      }
 104                      else
 105                      {
 106                          $sql_ary = array(
 107                              'SELECT'    => 'u.username, u.username_clean, u.user_email, u.user_jabber, u.user_lang, u.user_notify_type',
 108                              'FROM'        => array(
 109                                  USERS_TABLE    => 'u',
 110                              ),
 111                              'WHERE'        => 'u.user_allow_massemail = 1
 112                                  AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')',
 113                              'ORDER_BY'    => 'u.user_lang, u.user_notify_type',
 114                          );
 115                      }
 116  
 117                      // Mail banned or not
 118                      if (!isset($_REQUEST['mail_banned_flag']))
 119                      {
 120                          $sql_ary['WHERE'] .= ' AND (b.ban_id IS NULL
 121                                  OR b.ban_exclude = 1)';
 122                          $sql_ary['LEFT_JOIN'] = array(
 123                              array(
 124                                  'FROM'    => array(
 125                                      BANLIST_TABLE    => 'b',
 126                                  ),
 127                                  'ON'    => 'u.user_id = b.ban_userid',
 128                              ),
 129                          );
 130                      }
 131                  }
 132                  /**
 133                  * Modify sql query to change the list of users the email is sent to
 134                  *
 135                  * @event core.acp_email_modify_sql
 136                  * @var    array    sql_ary        Array which is used to build the sql query
 137                  * @since 3.1.2-RC1
 138                  */
 139                  $vars = array('sql_ary');
 140                  extract($phpbb_dispatcher->trigger_event('core.acp_email_modify_sql', compact($vars)));
 141  
 142                  $sql = $db->sql_build_query('SELECT', $sql_ary);
 143                  $result = $db->sql_query($sql);
 144                  $row = $db->sql_fetchrow($result);
 145  
 146                  if (!$row)
 147                  {
 148                      $db->sql_freeresult($result);
 149                      trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING);
 150                  }
 151  
 152                  $i = $j = 0;
 153  
 154                  // Send with BCC
 155                  // Maximum number of bcc recipients
 156                  $max_chunk_size = (int) $config['email_max_chunk_size'];
 157                  $email_list = array();
 158                  $old_lang = $row['user_lang'];
 159                  $old_notify_type = $row['user_notify_type'];
 160  
 161                  do
 162                  {
 163                      if (($row['user_notify_type'] == NOTIFY_EMAIL && $row['user_email']) ||
 164                          ($row['user_notify_type'] == NOTIFY_IM && $row['user_jabber']) ||
 165                          ($row['user_notify_type'] == NOTIFY_BOTH && ($row['user_email'] || $row['user_jabber'])))
 166                      {
 167                          if ($i == $max_chunk_size || $row['user_lang'] != $old_lang || $row['user_notify_type'] != $old_notify_type)
 168                          {
 169                              $i = 0;
 170  
 171                              if (count($email_list))
 172                              {
 173                                  $j++;
 174                              }
 175  
 176                              $old_lang = $row['user_lang'];
 177                              $old_notify_type = $row['user_notify_type'];
 178                          }
 179  
 180                          $email_list[$j][$i]['lang']        = $row['user_lang'];
 181                          $email_list[$j][$i]['method']    = $row['user_notify_type'];
 182                          $email_list[$j][$i]['email']    = $row['user_email'];
 183                          $email_list[$j][$i]['name']        = $row['username'];
 184                          $email_list[$j][$i]['jabber']    = $row['user_jabber'];
 185                          $i++;
 186                      }
 187                  }
 188                  while ($row = $db->sql_fetchrow($result));
 189                  $db->sql_freeresult($result);
 190  
 191                  // Send the messages
 192                  if (!class_exists('messenger'))
 193                  {
 194                      include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
 195                  }
 196  
 197                  if (!function_exists('get_group_name'))
 198                  {
 199                      include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
 200                  }
 201                  $messenger = new messenger($use_queue);
 202  
 203                  $errored = false;
 204  
 205                  $email_template = 'admin_send_email';
 206                  $template_data = array(
 207                      'CONTACT_EMAIL' => phpbb_get_board_contact($config, $phpEx),
 208                      'MESSAGE'        => html_entity_decode($message, ENT_COMPAT),
 209                  );
 210                  $generate_log_entry = true;
 211  
 212                  /**
 213                  * Modify email template data before the emails are sent
 214                  *
 215                  * @event core.acp_email_send_before
 216                  * @var    string    email_template        The template to be used for sending the email
 217                  * @var    string    subject                The subject of the email
 218                  * @var    array    template_data        Array with template data assigned to email template
 219                  * @var    bool    generate_log_entry    If false, no log entry will be created
 220                  * @var    array    usernames            Usernames which will be displayed in log entry, if it will be created
 221                  * @var    int        group_id            The group this email will be sent to
 222                  * @var    bool    use_queue            If true, email queue will be used for sending
 223                  * @var    int        priority            Priority of sent emails
 224                  * @since 3.1.3-RC1
 225                  */
 226                  $vars = array(
 227                      'email_template',
 228                      'subject',
 229                      'template_data',
 230                      'generate_log_entry',
 231                      'usernames',
 232                      'group_id',
 233                      'use_queue',
 234                      'priority',
 235                  );
 236                  extract($phpbb_dispatcher->trigger_event('core.acp_email_send_before', compact($vars)));
 237  
 238                  for ($i = 0, $size = count($email_list); $i < $size; $i++)
 239                  {
 240                      $used_lang = $email_list[$i][0]['lang'];
 241                      $used_method = $email_list[$i][0]['method'];
 242  
 243                      for ($j = 0, $list_size = count($email_list[$i]); $j < $list_size; $j++)
 244                      {
 245                          $email_row = $email_list[$i][$j];
 246  
 247                          $messenger->{((count($email_list[$i]) == 1) ? 'to' : 'bcc')}($email_row['email'], $email_row['name']);
 248                          $messenger->im($email_row['jabber'], $email_row['name']);
 249                      }
 250  
 251                      $messenger->template($email_template, $used_lang);
 252  
 253                      $messenger->anti_abuse_headers($config, $user);
 254  
 255                      $messenger->subject(html_entity_decode($subject, ENT_COMPAT));
 256                      $messenger->set_mail_priority($priority);
 257  
 258                      $messenger->assign_vars($template_data);
 259  
 260                      if (!($messenger->send($used_method)))
 261                      {
 262                          $errored = true;
 263                      }
 264                  }
 265                  unset($email_list);
 266  
 267                  $messenger->save_queue();
 268  
 269                  if ($generate_log_entry)
 270                  {
 271                      if (!empty($usernames))
 272                      {
 273                          $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_MASS_EMAIL', false, array(implode(', ', utf8_normalize_nfc($usernames))));
 274                      }
 275                      else
 276                      {
 277                          if ($group_id)
 278                          {
 279                              $group_name = get_group_name($group_id);
 280                          }
 281                          else
 282                          {
 283                              // Not great but the logging routine doesn't cope well with localising on the fly
 284                              $group_name = $user->lang['ALL_USERS'];
 285                          }
 286  
 287                          $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_MASS_EMAIL', false, array($group_name));
 288                      }
 289                  }
 290  
 291                  if (!$errored)
 292                  {
 293                      $message = ($use_queue) ? $user->lang['EMAIL_SENT_QUEUE'] : $user->lang['EMAIL_SENT'];
 294                      trigger_error($message . adm_back_link($this->u_action));
 295                  }
 296                  else
 297                  {
 298                      $message = sprintf($user->lang['EMAIL_SEND_ERROR'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=logs&amp;mode=critical') . '">', '</a>');
 299                      trigger_error($message . adm_back_link($this->u_action), E_USER_WARNING);
 300                  }
 301              }
 302          }
 303  
 304          // Exclude bots and guests...
 305          $sql = 'SELECT group_id
 306              FROM ' . GROUPS_TABLE . "
 307              WHERE group_name IN ('BOTS', 'GUESTS')";
 308          $result = $db->sql_query($sql);
 309  
 310          $exclude = array();
 311          while ($row = $db->sql_fetchrow($result))
 312          {
 313              $exclude[] = $row['group_id'];
 314          }
 315          $db->sql_freeresult($result);
 316  
 317          $select_list = '<option value="0"' . ((!$group_id) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_USERS'] . '</option>';
 318          $select_list .= group_select_options($group_id, $exclude);
 319  
 320          $s_priority_options = '<option value="' . MAIL_LOW_PRIORITY . '">' . $user->lang['MAIL_LOW_PRIORITY'] . '</option>';
 321          $s_priority_options .= '<option value="' . MAIL_NORMAL_PRIORITY . '" selected="selected">' . $user->lang['MAIL_NORMAL_PRIORITY'] . '</option>';
 322          $s_priority_options .= '<option value="' . MAIL_HIGH_PRIORITY . '">' . $user->lang['MAIL_HIGH_PRIORITY'] . '</option>';
 323  
 324          $template_data = array(
 325              'S_WARNING'                => (count($error)) ? true : false,
 326              'WARNING_MSG'            => (count($error)) ? implode('<br />', $error) : '',
 327              'U_ACTION'                => $this->u_action,
 328              'S_GROUP_OPTIONS'        => $select_list,
 329              'USERNAMES'                => implode("\n", $usernames),
 330              'U_FIND_USERNAME'        => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=acp_email&amp;field=usernames'),
 331              'SUBJECT'                => $subject,
 332              'MESSAGE'                => $message,
 333              'S_PRIORITY_OPTIONS'    => $s_priority_options,
 334          );
 335  
 336          /**
 337          * Modify custom email template data before we display the form
 338          *
 339          * @event core.acp_email_display
 340          * @var    array    template_data        Array with template data assigned to email template
 341          * @var    array    exclude                Array with groups which are excluded from group selection
 342          * @var    array    usernames            Usernames which will be displayed in form
 343          *
 344          * @since 3.1.4-RC1
 345          */
 346          $vars = array('template_data', 'exclude', 'usernames');
 347          extract($phpbb_dispatcher->trigger_event('core.acp_email_display', compact($vars)));
 348  
 349          $template->assign_vars($template_data);
 350      }
 351  }


Generated: Sat Nov 4 14:26:03 2023 Cross-referenced by PHPXref 0.7.1