Просмотр файла admin/mass_email.php

Размер файла: 4.66Kb
  1. <?php
  2. /***************************************************************************
  3. * mides.ru
  4. * -------------------
  5. ***************************************************************************/
  6. define('IN_PHPBB', 1);
  7.  
  8. if( !empty($setmodules) )
  9. {
  10. $filename = basename(__FILE__);
  11. return;
  12. }
  13.  
  14. $no_page_header = TRUE;
  15. $phpbb_root_path = './../';
  16. require($phpbb_root_path . 'extension.inc');
  17. require('./pagestart.' . $phpEx);
  18.  
  19. @set_time_limit(1200);
  20.  
  21. $message = '';
  22. $subject = '';
  23.  
  24. if ( isset($HTTP_POST_VARS['submit']) )
  25. {
  26. $subject = stripslashes(trim($HTTP_POST_VARS['subject']));
  27. $message = stripslashes(trim($HTTP_POST_VARS['message']));
  28. $error = FALSE;
  29. $error_msg = '';
  30.  
  31. if ( empty($subject) )
  32. {
  33. $error = true;
  34. $error_msg .= ( !empty($error_msg) ) ? '<br />' . $lang['Empty_subject'] : $lang['Empty_subject'];
  35. }
  36.  
  37. if ( empty($message) )
  38. {
  39. $error = true;
  40. $error_msg .= ( !empty($error_msg) ) ? '<br />' . 'Вы должны ввести текст сообщения' : $lang['Empty_message'];
  41. }
  42.  
  43. $group_id = intval($HTTP_POST_VARS[POST_GROUPS_URL]);
  44.  
  45. $sql = ( $group_id != -1 ) ? "SELECT u.user_email FROM " . USERS_TABLE . " u, " . USER_GROUP_TABLE . " ug WHERE ug.group_id = $group_id AND ug.user_pending <> " . TRUE . " AND u.user_id = ug.user_id" : "SELECT user_email FROM " . USERS_TABLE;
  46. if ( !($result = $db->sql_query($sql)) )
  47. {
  48. message_die(GENERAL_ERROR, 'Could not select group members', '', __LINE__, __FILE__, $sql);
  49. }
  50.  
  51. if ( $row = $db->sql_fetchrow($result) )
  52. {
  53. $bcc_list = array();
  54. do
  55. {
  56. $bcc_list[] = $row['user_email'];
  57. }
  58. while ( $row = $db->sql_fetchrow($result) );
  59.  
  60. $db->sql_freeresult($result);
  61. }
  62. else
  63. {
  64. $message = ( $group_id != -1 ) ? $lang['Group_not_exist'] : $lang['No_such_user'];
  65.  
  66. $error = true;
  67. $error_msg .= ( !empty($error_msg) ) ? '<br />' . $message : $message;
  68. }
  69.  
  70. if ( !$error )
  71. {
  72. include($phpbb_root_path . 'includes/emailer.'.$phpEx);
  73.  
  74. if ( preg_match('/[c-z]:\\\.*/i', getenv('PATH')) && !$board_config['smtp_delivery'])
  75. {
  76. $ini_val = ( @phpversion() >= '4.0.0' ) ? 'ini_get' : 'get_cfg_var';
  77.  
  78. $board_config['smtp_delivery'] = 1;
  79. $board_config['smtp_host'] = @$ini_val('SMTP');
  80. }
  81.  
  82. $emailer = new emailer($board_config['smtp_delivery']);
  83. $emailer->from($board_config['board_email']);
  84. $emailer->replyto($board_config['board_email']);
  85.  
  86. for ($i = 0; $i < count($bcc_list); $i++)
  87. {
  88. $emailer->bcc($bcc_list[$i]);
  89. }
  90.  
  91. $email_headers = 'X-AntiAbuse: Board servername - ' . $board_config['server_name'] . "\n";
  92. $email_headers .= 'X-AntiAbuse: User_id - ' . $userdata['user_id'] . "\n";
  93. $email_headers .= 'X-AntiAbuse: Username - ' . $userdata['username'] . "\n";
  94. $email_headers .= 'X-AntiAbuse: User IP - ' . decode_ip($user_ip) . "\n";
  95.  
  96. $emailer->use_template('admin_send_email');
  97. $emailer->email_address($board_config['board_email']);
  98. $emailer->set_subject($subject);
  99. $emailer->extra_headers($email_headers);
  100.  
  101. $emailer->assign_vars(array(
  102. 'SITENAME' => $board_config['sitename'],
  103. 'BOARD_EMAIL' => $board_config['board_email'],
  104. 'MESSAGE' => $message)
  105. );
  106. $emailer->send();
  107. $emailer->reset();
  108.  
  109. message_die(GENERAL_MESSAGE, 'Сообщение было отправлено' . '<br />');
  110. }
  111. }
  112.  
  113. if ( $error )
  114. {
  115. $template->set_filenames(array(
  116. 'reg_header' => 'error_body.tpl')
  117. );
  118. $template->assign_vars(array(
  119. 'ERROR_MESSAGE' => $error_msg)
  120. );
  121. $template->assign_var_from_handle('ERROR_BOX', 'reg_header');
  122. }
  123.  
  124. $sql = "SELECT group_id, group_name
  125. FROM ".GROUPS_TABLE . "
  126. WHERE group_single_user <> 1";
  127. if ( !($result = $db->sql_query($sql)) )
  128. {
  129. message_die(GENERAL_ERROR, 'Could not obtain list of groups', '', __LINE__, __FILE__, $sql);
  130. }
  131.  
  132. $select_list = '<select name = "' . POST_GROUPS_URL . '"><option value = "-1">' . $lang['All_users'] . '</option>';
  133. if ( $row = $db->sql_fetchrow($result) )
  134. {
  135. do
  136. {
  137. $select_list .= '<option value = "' . $row['group_id'] . '">' . $row['group_name'] . '</option>';
  138. }
  139. while ( $row = $db->sql_fetchrow($result) );
  140. }
  141. $select_list .= '</select>';
  142.  
  143. include('./page_header_admin.'.$phpEx);
  144.  
  145. $template->set_filenames(array(
  146. 'body' => 'admin/user_email_body.tpl')
  147. );
  148.  
  149. $template->assign_vars(array(
  150. 'MESSAGE' => $message,
  151. 'SUBJECT' => $subject,
  152.  
  153. 'L_EMAIL_TITLE' => $lang['Email'],
  154. 'L_EMAIL_EXPLAIN' => $lang['Mass_email_explain'],
  155. 'L_COMPOSE' => $lang['Compose'],
  156. 'L_RECIPIENTS' => $lang['Recipients'],
  157. 'L_EMAIL_SUBJECT' => $lang['Subject'],
  158. 'L_EMAIL_MSG' => $lang['Message'],
  159. 'L_EMAIL' => $lang['Email'],
  160. 'L_NOTICE' => $notice,
  161.  
  162. 'S_USER_ACTION' => append_sid('admin_mass_email.'.$phpEx),
  163. 'S_GROUP_SELECT' => $select_list)
  164. );
  165.  
  166. $template->pparse('body');
  167.  
  168. include('./page_footer_admin.'.$phpEx);
  169.  
  170. ?>