PageRenderTime 56ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/system/cp/cp.communicate.php

https://github.com/danboy/Croissierd
PHP | 1866 lines | 1137 code | 464 blank | 265 comment | 195 complexity | 92f3a7700e1742ea4f21a29273d039bc MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. =====================================================
  4. ExpressionEngine - by EllisLab
  5. -----------------------------------------------------
  6. http://expressionengine.com/
  7. -----------------------------------------------------
  8. Copyright (c) 2003 - 2010 EllisLab, Inc.
  9. =====================================================
  10. THIS IS COPYRIGHTED SOFTWARE
  11. PLEASE READ THE LICENSE AGREEMENT
  12. http://expressionengine.com/docs/license.html
  13. =====================================================
  14. File: cp.communicate.php
  15. -----------------------------------------------------
  16. Purpose: Email sending/management functions
  17. =====================================================
  18. */
  19. if ( ! defined('EXT'))
  20. {
  21. exit('Invalid file request');
  22. }
  23. class Communicate {
  24. var $wrapchars = 76;
  25. var $mailinglist_exists = FALSE;
  26. /** -----------------------------
  27. /** Constructor
  28. /** -----------------------------*/
  29. function Communicate()
  30. {
  31. global $DSP, $LANG, $IN, $DB;
  32. if ( ! $DSP->allowed_group('can_access_comm'))
  33. {
  34. return $DSP->no_access_message();
  35. }
  36. if (file_exists(PATH_MOD.'mailinglist/mod.mailinglist'.EXT) && $DB->table_exists('exp_mailing_lists') === TRUE)
  37. {
  38. $this->mailinglist_exists = TRUE;
  39. }
  40. // Fetch the needed language files
  41. $LANG->fetch_language_file('communicate');
  42. switch($IN->GBL('M'))
  43. {
  44. case 'send_email' : $this->send_email();
  45. break;
  46. case 'batch_send' : $this->batch_send();
  47. break;
  48. case 'view_cache' : $this->view_email_cache();
  49. break;
  50. case 'view_email' : $this->view_email();
  51. break;
  52. case 'delete_conf' : $this->delete_confirm();
  53. break;
  54. case 'delete' : $this->delete_emails();
  55. break;
  56. case 'spellcheck' : $this->spellcheck();
  57. break;
  58. case 'spellcheck_iframe' : $this->spellcheck_iframe();
  59. break;
  60. default : $this->email_form();
  61. break;
  62. }
  63. }
  64. /* END */
  65. /** -----------------------------
  66. /** Email form
  67. /** -----------------------------*/
  68. function email_form()
  69. {
  70. global $IN, $DSP, $DB, $PREFS, $SESS, $LANG;
  71. /** -----------------------------
  72. /** Default form values
  73. /** -----------------------------*/
  74. $member_groups = array();
  75. $mailing_lists = array();
  76. $default = array(
  77. 'from_name' => '',
  78. 'from_email' => $SESS->userdata['email'],
  79. 'recipient' => '',
  80. 'cc' => '',
  81. 'bcc' => '',
  82. 'subject' => '',
  83. 'message' => '',
  84. 'plaintext_alt' => '',
  85. 'priority' => 3,
  86. 'mailtype' => $PREFS->ini('mail_format'),
  87. 'word_wrap' => $PREFS->ini('word_wrap')
  88. );
  89. /** -----------------------------
  90. /** Are we emailing a member?
  91. /** -----------------------------*/
  92. if ($IN->GBL('M', 'GET') == 'email_mbr' AND $IN->GBL('mid', 'GET') AND $DSP->allowed_group('can_admin_members'))
  93. {
  94. $query = $DB->query("SELECT email, screen_name FROM exp_members WHERE member_id = '".$DB->escape_str($IN->GBL('mid', 'GET'))."'");
  95. if ($query->num_rows == 1)
  96. {
  97. $default['recipient'] = $query->row['email'];
  98. $default['message'] = $query->row['screen_name'].",";
  99. }
  100. }
  101. /** -----------------------------
  102. /** Fetch form data
  103. /** -----------------------------*/
  104. // If the user is viewing a cached email, we'll gather the data
  105. if ($id = $IN->GBL('id', 'GET'))
  106. {
  107. if ( ! $DSP->allowed_group('can_send_cached_email'))
  108. {
  109. return $DSP->no_access_message($LANG->line('not_allowed_to_email_mailinglist'));
  110. }
  111. // Fetch cached data
  112. $query = $DB->query("SELECT * FROM exp_email_cache WHERE cache_id = '".$DB->escape_str($id)."'");
  113. if ($query->num_rows > 0)
  114. {
  115. foreach ($query->row as $key => $val)
  116. {
  117. if (isset($default[$key]))
  118. {
  119. $default[$key] = $val;
  120. }
  121. }
  122. }
  123. // Fetch member group IDs
  124. $query = $DB->query("SELECT group_id FROM exp_email_cache_mg WHERE cache_id = '".$DB->escape_str($id)."'");
  125. if ($query->num_rows > 0)
  126. {
  127. foreach ($query->result as $row)
  128. {
  129. $member_groups[] = $row['group_id'];
  130. }
  131. }
  132. if ($this->mailinglist_exists == TRUE)
  133. {
  134. // Fetch mailing list IDs
  135. $query = $DB->query("SELECT list_id FROM exp_email_cache_ml WHERE cache_id = '".$DB->escape_str($id)."'");
  136. if ($query->num_rows > 0)
  137. {
  138. foreach ($query->result as $row)
  139. {
  140. $mailing_lists[] = $row['list_id'];
  141. }
  142. }
  143. }
  144. }
  145. /** -----------------------------------
  146. /** Turn default data into variables
  147. /** -----------------------------------*/
  148. foreach ($default as $key => $val)
  149. {
  150. $$key = $val;
  151. }
  152. /** -----------------------------------
  153. /** Create the email form
  154. /** -----------------------------------*/
  155. $DSP->title = $LANG->line('communicate');
  156. $DSP->crumb = $LANG->line('communicate');
  157. if ($DSP->allowed_group('can_send_cached_email'))
  158. {
  159. $DSP->right_crumb($LANG->line('view_email_cache'), BASE.AMP.'C=communicate'.AMP.'M=view_cache');
  160. }
  161. $r = $DSP->form_open(array('action' => 'C=communicate'.AMP.'M=send_email'));
  162. $r .= $DSP->qdiv('tableHeading', $LANG->line('send_an_email'));
  163. $r .= $DSP->div('box');
  164. $r .= $DSP->table('', '0', '0', '100%').
  165. $DSP->tr().
  166. $DSP->td('', '', '', '', 'top');
  167. /** -----------------------------
  168. /** Subject and message feilds
  169. /** -----------------------------*/
  170. $r .= $DSP->div('itemWrapper').
  171. $DSP->qdiv('itemTitle', $DSP->required().NBS.$LANG->line('subject', 'subject')).
  172. $DSP->qdiv('', $DSP->input_text('subject', $subject, '20', '75', 'input', '96%')).
  173. $DSP->div_c();
  174. if ( ! class_exists('Spellcheck'))
  175. {
  176. require PATH_CORE.'core.spellcheck'.EXT;
  177. }
  178. $SPELL = new Spellcheck();
  179. $r .= $SPELL->JavaScript(BASE.AMP.'C=communicate'.AMP.'M=spellcheck', TRUE);
  180. $r .= $DSP->div('itemWrapper').
  181. $DSP->qdiv('itemTitle', $DSP->required().NBS.$LANG->line('message', 'message')).
  182. $DSP->qdiv('', $DSP->input_textarea('message', $message, 25, 'textarea', '96%')).
  183. $DSP->div_c();
  184. $iframe_url = BASE.AMP.'C=communicate'.AMP.'M=spellcheck_iframe';
  185. $field_name = 'message';
  186. $r .= $DSP->table('tableBorderNoBot', '0', '', '96%');
  187. if ($SPELL->enabled === TRUE)
  188. {
  189. $r .= $DSP->tr().
  190. $DSP->td('tableCellTwoBold', '100%', 2).
  191. $DSP->div('itemWrapper').
  192. $DSP->anchor('javascript:nullo();', $LANG->line('check_spelling'), 'onclick="eeSpell.getResults(\''.$field_name.'\');return false;"').
  193. '<span id="spellcheck_hidden_'.$field_name.'" style="visibility:hidden;">'.
  194. NBS.NBS.NBS.NBS.'|'.NBS.NBS.NBS.NBS.
  195. $DSP->anchor('javascript:nullo();', $LANG->line('save_spellcheck'), 'onclick="SP_saveSpellCheck();return false;"').
  196. NBS.NBS.NBS.NBS.'|'.NBS.NBS.NBS.NBS.
  197. $DSP->anchor('javascript:nullo();', $LANG->line('revert_spellcheck'), 'onclick="SP_revertToOriginal();return false;"').
  198. '</span>'.
  199. $DSP->div_c();
  200. $r .= '<iframe src="'.$iframe_url.'" width="100%" style="display:none;" id="spellcheck_frame_'.$field_name.'" class="iframe" name="spellcheck_frame_'.$field_name.'"></iframe>'.
  201. '<div id="spellcheck_popup" class="wordSuggestion" style="position:absolute;visibility:hidden;"></div>';
  202. $r .= $DSP->td_c().
  203. $DSP->tr_c();
  204. }
  205. /** -----------------------------
  206. /** Mail formatting buttons
  207. /** -----------------------------*/
  208. $extra_js = <<<EOTJS
  209. <script type="text/javascript">
  210. function showhide_plaintext_field(val)
  211. {
  212. if (val == 'html')
  213. {
  214. document.getElementById('plaintext_field').style.display = 'block';
  215. }
  216. else
  217. {
  218. document.getElementById('plaintext_field').style.display = 'none';
  219. }
  220. }
  221. </script>
  222. EOTJS;
  223. $r .= $extra_js.
  224. $DSP->tr().
  225. $DSP->td('', '', 2);
  226. $r .= $DSP->table('', '0', '', '100%').
  227. $DSP->tr().
  228. $DSP->td('tableCellTwoBold', '40%').$LANG->line('mail_format').$DSP->td_c().
  229. $DSP->td('tableCellTwoBold', '60%').
  230. $DSP->input_select_header('mailtype', '', '', '', "onchange='showhide_plaintext_field(this.value);return false'").
  231. $DSP->input_select_option('plain', $LANG->line('plain_text'), ($mailtype == 'plain') ? 1 : '').
  232. $DSP->input_select_option('html', $LANG->line('html'), ($mailtype == 'html') ? 1 : '').
  233. $DSP->input_select_footer().
  234. $DSP->td_c().
  235. $DSP->tr_c();
  236. /** ---------------------------------------
  237. /** Alternative content field
  238. /** ---------------------------------------*/
  239. $r .= $DSP->tr().
  240. $DSP->td('', '', 2).
  241. $DSP->div('tableCellTwoBold', '', 'plaintext_field', '', ($mailtype == 'html') ? '' : "style='display:none;'").
  242. $DSP->qdiv('tableCellTwoBold', $LANG->line('plaintext_alt', 'plaintext_alt')).
  243. $DSP->qdiv('', $DSP->input_textarea('plaintext_alt', $plaintext_alt, 8, 'textarea', '96%')).
  244. $DSP->td_c().
  245. $DSP->tr_c().
  246. $DSP->table_c();
  247. /** ---------------------------------------
  248. /** Text Formatting
  249. /** ---------------------------------------*/
  250. $r .= $DSP->tr().
  251. $DSP->td('tableCellOneBold', '40%').$LANG->line('text_formatting').$DSP->td_c().
  252. $DSP->td('tableCellOneBold', '60%').
  253. $DSP->input_select_header('text_fmt').
  254. $DSP->input_select_option('none', $LANG->line('none'), 1);
  255. // Fetch formatting plugins
  256. $list = $this->fetch_plugins();
  257. foreach($list as $val)
  258. {
  259. $name = ucwords(str_replace('_', ' ', $val));
  260. if ($name == 'Br')
  261. {
  262. $name = $LANG->line('auto_br');
  263. }
  264. elseif ($name == 'Xhtml')
  265. {
  266. $name = $LANG->line('xhtml');
  267. }
  268. $r .= $DSP->input_select_option($val, $name);
  269. }
  270. $r .= $DSP->input_select_footer().
  271. $DSP->td_c().
  272. $DSP->tr_c();
  273. $r .= $DSP->tr().
  274. $DSP->td('tableCellTwoBold', '40%').$LANG->line('word_wrap').$DSP->td_c().
  275. $DSP->td('tableCellTwoBold', '60%').
  276. $DSP->input_select_header('wordwrap').
  277. $DSP->input_select_option('y', $LANG->line('on'), ($word_wrap == 'y') ? 1 : '').
  278. $DSP->input_select_option('n', $LANG->line('off'), ($word_wrap == 'n') ? 1 : '').
  279. $DSP->input_select_footer().
  280. $DSP->td_c().
  281. $DSP->tr_c();
  282. $r .= $DSP->tr().
  283. $DSP->td('tableCellOneBold').$LANG->line('priority').$DSP->td_c().
  284. $DSP->td('tableCellOneBold').
  285. $DSP->input_select_header('priority').
  286. $DSP->input_select_option('1', '1 ('.$LANG->line('highest').')', ($priority == 1) ? 1 : '').
  287. $DSP->input_select_option('2', '2 ('.$LANG->line('high').')', ($priority == 2) ? 1 : '').
  288. $DSP->input_select_option('3', '3 ('.$LANG->line('normal').')', ($priority == 3) ? 1 : '').
  289. $DSP->input_select_option('4', '4 ('.$LANG->line('low').')', ($priority == 4) ? 1 : '').
  290. $DSP->input_select_option('5', '5 ('.$LANG->line('lowest').')', ($priority == 5) ? 1 : '').
  291. $DSP->input_select_footer();
  292. $r .= $DSP->td_c().
  293. $DSP->tr_c().
  294. $DSP->table_c();
  295. /** -----------------------------
  296. /** Submit button
  297. /** -----------------------------*/
  298. if ($DSP->allowed_group('can_email_member_groups'))
  299. {
  300. $r .= $DSP->qdiv('itemWrapperTop', $DSP->input_checkbox('accept_admin_email', 'y', 1).NBS.$LANG->line('honor_email_pref'));
  301. }
  302. $r .= $DSP->qdiv('itemWrapper', $DSP->required(1));
  303. $r .= $DSP->qdiv('itemWrapper', $DSP->input_submit($LANG->line('send_it')));
  304. /** -----------------------------
  305. /** Right side of page
  306. /** -----------------------------*/
  307. $r .= $DSP->td_c().
  308. $DSP->td('', '300px', '', '', 'top');
  309. /** -----------------------------
  310. /** Sender/recipient fields
  311. /** -----------------------------*/
  312. $r .= $DSP->div('itemWrapper').
  313. $DSP->qdiv('itemTitle', $LANG->line('your_name', 'name')).
  314. $DSP->qdiv('', $DSP->input_text('name', $from_name, '20', '50', 'input', '300px')).
  315. $DSP->div_c();
  316. $r .= $DSP->div('itemWrapper').
  317. $DSP->qdiv('itemTitle', $DSP->required().NBS.$LANG->line('your_email', 'from')).
  318. $DSP->qdiv('', $DSP->input_text('from', $from_email, '20', '75', 'input', '300px')).
  319. $DSP->div_c();
  320. $r .= $DSP->div('itemWrapper').
  321. $DSP->qdiv('itemWrapper', '<b>'.$LANG->line('recipient', 'recipient').'</b>').
  322. $DSP->qdiv('', $LANG->line('separate_emails_with_comma')).
  323. $DSP->qdiv('', $DSP->input_text('recipient', $recipient, '20', '150', 'input', '300px')).
  324. $DSP->div_c();
  325. $r .= $DSP->div('itemWrapper').
  326. $DSP->qdiv('itemTitle', $LANG->line('cc', 'cc')).
  327. $DSP->qdiv('', $DSP->input_text('cc', $cc, '20', '150', 'input', '300px')).
  328. $DSP->div_c();
  329. $r .= $DSP->div('itemWrapper').
  330. $DSP->qdiv('itemTitle', $LANG->line('bcc', 'bcc')).
  331. $DSP->qdiv('', $DSP->input_text('bcc', $bcc, '20', '150', 'input', '300px').BR).
  332. $DSP->div_c();
  333. if ($DSP->allowed_group('can_email_mailinglist') AND $this->mailinglist_exists == TRUE)
  334. {
  335. $query = $DB->query("SELECT list_id, list_title FROM exp_mailing_lists ORDER BY list_title");
  336. if ($query->num_rows > 0)
  337. {
  338. $r .= $DSP->table('tableBorder', '0', '', '300px').
  339. $DSP->tr().
  340. $DSP->td('tableHeading').
  341. $DSP->qdiv('itemWrapper', $LANG->line('send_to_mailinglist')).
  342. $DSP->td_c().
  343. $DSP->tr_c();
  344. $i = 0;
  345. foreach ($query->result as $row)
  346. {
  347. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  348. $r .= $DSP->tr().
  349. $DSP->td($style, '50%').$DSP->qdiv('defaultBold', $DSP->input_checkbox('list_'.$row['list_id'], $row['list_id'], (in_array($row['list_id'], $mailing_lists)) ? 1 : '').$DSP->nbs(1).$row['list_title']).$DSP->td_c()
  350. .$DSP->tr_c();
  351. }
  352. $r .= $DSP->table_c();
  353. }
  354. }
  355. /** -----------------------------
  356. /** Member group selection
  357. /** -----------------------------*/
  358. if ($DSP->allowed_group('can_email_member_groups'))
  359. {
  360. $r .= $DSP->table('tableBorder', '0', '', '300px').
  361. $DSP->tr().
  362. $DSP->td('tableHeading').
  363. $DSP->qdiv('itemWrapper', $LANG->line('recipient_group')).
  364. $DSP->td_c().
  365. $DSP->tr_c();
  366. $i = 0;
  367. $query = $DB->query("SELECT group_id, group_title FROM exp_member_groups
  368. WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'
  369. AND include_in_mailinglists = 'y' ORDER BY group_title");
  370. foreach ($query->result as $row)
  371. {
  372. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  373. $r .= $DSP->tr().
  374. $DSP->td($style, '50%').$DSP->qdiv('defaultBold', $DSP->input_checkbox('group_'.$row['group_id'], $row['group_id'], (in_array($row['group_id'], $member_groups)) ? 1 : '').$DSP->nbs(1).$row['group_title']).$DSP->td_c()
  375. .$DSP->tr_c();
  376. }
  377. $r .= $DSP->table_c();
  378. }
  379. /** -----------------------------
  380. /** Table end
  381. /** -----------------------------*/
  382. $r .= $DSP->td_c()
  383. .$DSP->tr_c()
  384. .$DSP->table_c();
  385. $r .= $DSP->div_c();
  386. $r.= $DSP->form_close();
  387. $DSP->body = $r;
  388. }
  389. /* END */
  390. /** -----------------------------
  391. /** Debugging Message
  392. /** -----------------------------*/
  393. function debug_message($debug_array)
  394. {
  395. global $DSP;
  396. if ( ! is_array($debug_array) OR count($debug_array) == 0)
  397. {
  398. return '';
  399. }
  400. $str = $DSP->div('box').$DSP->div('defaultPad').$DSP->qdiv('itemWrapper', $DSP->heading('Debugging Message', 5));
  401. foreach ($debug_array as $val)
  402. {
  403. $str .= $val;
  404. }
  405. $str .= BR.$DSP->div_c().$DSP->div_c();
  406. return $str;
  407. }
  408. /* END */
  409. /** -----------------------------
  410. /** Send email
  411. /** -----------------------------*/
  412. function send_email()
  413. {
  414. global $DSP, $DB, $IN, $FNS, $REGX, $LANG, $SESS, $LOC, $PREFS;
  415. $debug_msg = '';
  416. /** -----------------------------
  417. /** Are we missing any fields?
  418. /** -----------------------------*/
  419. if ( ! $IN->GBL('from', 'POST') OR
  420. ! $IN->GBL('subject', 'POST') OR
  421. ! $IN->GBL('message', 'POST')
  422. )
  423. {
  424. return $DSP->error_message($LANG->line('empty_form_fields'));
  425. }
  426. /** -----------------------------
  427. /** Fetch $_POST data
  428. /** -----------------------------*/
  429. // We'll turn the $_POST data into variables for simplicity
  430. $groups = array();
  431. $list_ids = array();
  432. foreach ($_POST as $key => $val)
  433. {
  434. if (substr($key, 0, 6) == 'group_')
  435. {
  436. $groups[] = $val;
  437. }
  438. elseif (substr($key, 0, 5) == 'list_')
  439. {
  440. $list_ids[] = $val;
  441. }
  442. else
  443. {
  444. $$key = stripslashes($val);
  445. }
  446. }
  447. /** -----------------------------
  448. /** Verify privileges
  449. /** -----------------------------*/
  450. if (count($groups) > 0 AND ! $DSP->allowed_group('can_email_member_groups'))
  451. {
  452. return $DSP->no_access_message($LANG->line('not_allowed_to_email_member_groups'));
  453. }
  454. if (count($list_ids) > 0 AND ! $DSP->allowed_group('can_email_mailinglist') AND $this->mailinglist_exists == TRUE)
  455. {
  456. return $DSP->no_access_message($LANG->line('not_allowed_to_email_mailinglist'));
  457. }
  458. if (count($groups) == 0 AND count($list_ids) == 0 AND ! $IN->GBL('recipient', 'POST'))
  459. {
  460. return $DSP->error_message($LANG->line('empty_form_fields'));
  461. }
  462. /** -------------------------------
  463. /** Assign data for caching
  464. /** -------------------------------*/
  465. $cache_data = array(
  466. 'cache_id' => '',
  467. 'cache_date' => $LOC->now,
  468. 'total_sent' => 0,
  469. 'from_name' => $name,
  470. 'from_email' => $from,
  471. 'recipient' => $recipient,
  472. 'cc' => $cc,
  473. 'bcc' => $bcc,
  474. 'recipient_array' => '',
  475. 'subject' => $subject,
  476. 'message' => $message,
  477. 'plaintext_alt' => $plaintext_alt,
  478. 'mailtype' => $mailtype,
  479. 'text_fmt' => $text_fmt,
  480. 'wordwrap' => $wordwrap,
  481. 'priority' => $priority
  482. );
  483. /** ---------------------------------------
  484. /** Apply text formatting if necessary
  485. /** ---------------------------------------*/
  486. if ($text_fmt != 'none' && $text_fmt != '')
  487. {
  488. if ( ! class_exists('Typography'))
  489. {
  490. require PATH_CORE.'core.typography'.EXT;
  491. }
  492. $TYPE = new Typography(0);
  493. $TYPE->parse_smileys = FALSE;
  494. $subject = $TYPE->filter_censored_words($subject);
  495. $message = $TYPE->parse_type($message,
  496. array(
  497. 'text_format' => $text_fmt,
  498. 'html_format' => 'all',
  499. 'auto_links' => 'n',
  500. 'allow_img_url' => 'y'
  501. )
  502. );
  503. }
  504. /** -----------------------------
  505. /** Send a single email
  506. /** -----------------------------*/
  507. if (count($groups) == 0 AND count($list_ids) == 0 )
  508. {
  509. require PATH_CORE.'core.email'.EXT;
  510. $to = ($recipient == '') ? $SESS->userdata['email'] : $recipient;
  511. $email = new EEmail;
  512. $email->wordwrap = ($wordwrap == 'y') ? TRUE : FALSE;
  513. $email->mailtype = $mailtype;
  514. $email->priority = $priority;
  515. $email->from($from, $name);
  516. $email->to($to);
  517. $email->cc($cc);
  518. $email->bcc($bcc);
  519. $email->subject($subject);
  520. $email->message($message, $plaintext_alt);
  521. $error = FALSE;
  522. if ( ! $email->Send())
  523. {
  524. $error = TRUE;
  525. }
  526. $debug_msg = $this->debug_message($email->debug_msg);
  527. if ($error == TRUE)
  528. {
  529. return $DSP->error_message($LANG->line('error_sending_email').$debug_msg, 0);
  530. }
  531. /** ---------------------------------
  532. /** Save cache data
  533. /** ---------------------------------*/
  534. $cache_data['total_sent'] = $this->fetch_total($to, $cc, $bcc);
  535. $this->save_cache_data($cache_data);
  536. /** ---------------------------------
  537. /** Show success message
  538. /** ---------------------------------*/
  539. $DSP->set_return_data($LANG->line('email_sent'), $DSP->qdiv('defaultPad', $DSP->qdiv('success', $LANG->line('email_sent_message'))).$debug_msg, $LANG->line('email_sent'));
  540. // We're done
  541. return;
  542. }
  543. // Send Multi-emails
  544. /** ----------------------------------------
  545. /** Is Batch Mode set?
  546. /** ----------------------------------------*/
  547. $batch_mode = $PREFS->ini('email_batchmode');
  548. $batch_size = $PREFS->ini('email_batch_size');
  549. if ( ! is_numeric($batch_size))
  550. {
  551. $batch_mode = 'n';
  552. }
  553. $emails = array();
  554. /** ---------------------------------
  555. /** Fetch member group emails
  556. /** ---------------------------------*/
  557. if (count($groups) > 0)
  558. {
  559. $sql = "SELECT exp_members.member_id, exp_members.email, exp_members.screen_name
  560. FROM exp_members, exp_member_groups
  561. WHERE exp_members.group_id = exp_member_groups.group_id
  562. AND exp_member_groups.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'
  563. AND include_in_mailinglists = 'y' ";
  564. if (isset($_POST['accept_admin_email']))
  565. {
  566. $sql .= "AND exp_members.accept_admin_email = 'y' ";
  567. }
  568. $sql .= "AND exp_member_groups.group_id IN (";
  569. foreach ($groups as $id)
  570. {
  571. $sql .= "'".$DB->escape_str($id)."',";
  572. }
  573. $sql = substr($sql, 0, -1);
  574. $sql .= ")";
  575. // Run the query
  576. $query = $DB->query($sql);
  577. if ($query->num_rows > 0)
  578. {
  579. foreach ($query->result as $row)
  580. {
  581. $emails['m'.$row['member_id']] = array($row['email'], $row['screen_name']);
  582. }
  583. }
  584. }
  585. /** ---------------------------------
  586. /** Fetch mailing list emails
  587. /** ---------------------------------*/
  588. $list_templates = array();
  589. if ($this->mailinglist_exists == TRUE)
  590. {
  591. if (count($list_ids) > 0)
  592. {
  593. $sql = "SELECT authcode, email, list_id FROM exp_mailing_list WHERE list_id IN (";
  594. foreach ($list_ids as $id)
  595. {
  596. $sql .= "'".$DB->escape_str($id)."',";
  597. // Fetch the template for each list
  598. $query = $DB->query("SELECT list_template, list_title FROM exp_mailing_lists WHERE list_id = '".$DB->escape_str($id)."'");
  599. $list_templates[$id] = array('list_template' => $query->row['list_template'], 'list_title' => $query->row['list_title']);
  600. }
  601. $sql = substr($sql, 0, -1);
  602. $sql .= ")";
  603. $sql .= " ORDER BY user_id";
  604. $query = $DB->query($sql);
  605. // No result? Show error message
  606. if ($query->num_rows == 0 && sizeof($emails) == 0)
  607. {
  608. return $DSP->set_return_data($LANG->line('send_an_email'), $DSP->qdiv('defaultPad', $DSP->qdiv('alert', $LANG->line('no_email_matching_criteria'))), $LANG->line('send_an_email'));
  609. }
  610. if ($query->num_rows > 0)
  611. {
  612. foreach ($query->result as $row)
  613. {
  614. $emails['l'.$row['authcode']] = array($row['email'], $row['list_id']);
  615. }
  616. }
  617. }
  618. }
  619. /** ----------------------------------------
  620. /** Kill duplicates
  621. /** ----------------------------------------*/
  622. $cleaned_emails = array();
  623. foreach($emails as $key => $value)
  624. {
  625. if (is_array($value))
  626. {
  627. $val = $value['0'];
  628. }
  629. else
  630. {
  631. $val = $value;
  632. }
  633. if ( ! isset($cleaned_emails[$key]))
  634. {
  635. $cleaned_emails[$key] = $value;
  636. }
  637. }
  638. $emails = $cleaned_emails;
  639. /** ----------------------------------------
  640. /** After all that, do we have any emails?
  641. /** ----------------------------------------*/
  642. if (count($emails) == 0 AND $recipient == '')
  643. {
  644. return $DSP->set_return_data($LANG->line('send_an_email'), $DSP->qdiv('defaultPad', $DSP->qdiv('alert', $LANG->line('no_email_matching_criteria'))), $LANG->line('send_an_email'));
  645. }
  646. /** ----------------------------------------
  647. /** Do we have any CCs or BCCs?
  648. /** ----------------------------------------*/
  649. // If so, we'll send those separately first
  650. $total_sent = 0;
  651. $recips = array();
  652. if ($cc != '' || $bcc != '')
  653. {
  654. if ( ! class_exists('EEmail'))
  655. {
  656. require PATH_CORE.'core.email'.EXT;
  657. }
  658. $to = ($recipient == '') ? $SESS->userdata['email'] : $recipient;
  659. $email = new EEmail;
  660. $email->wordwrap = ($wordwrap == 'y') ? TRUE : FALSE;
  661. $email->mailtype = $mailtype;
  662. $email->priority = $priority;
  663. $email->from($from, $name);
  664. $email->to($to);
  665. $email->cc($cc);
  666. $email->bcc($bcc);
  667. $email->subject($subject);
  668. $email->message($message, $plaintext_alt);
  669. $error = FALSE;
  670. if ( ! $email->Send())
  671. {
  672. $error = TRUE;
  673. }
  674. $debug_msg = $this->debug_message($email->debug_msg);
  675. if ($error == TRUE)
  676. {
  677. return $DSP->error_message($LANG->line('error_sending_email').$debug_msg, 0);
  678. }
  679. $total_sent = $this->fetch_total($to, $cc, $bcc);
  680. }
  681. else
  682. {
  683. // No CC/BCCs? Convert recipients to an array so we can include them in the email sending cycle
  684. if ($recipient != '')
  685. $recips = $this->convert_recipients($recipient);
  686. }
  687. if (count($recips) > 0)
  688. {
  689. $emails = array_merge($emails, $recips);
  690. }
  691. /** ----------------------------------------
  692. /** If batch-mode is not set, send emails
  693. /** ----------------------------------------*/
  694. if (count($emails) <= $batch_size)
  695. {
  696. $batch_mode = 'n';
  697. }
  698. if ($batch_mode == 'n')
  699. {
  700. $action_id = $FNS->fetch_action_id('Mailinglist', 'unsubscribe');
  701. if ( ! class_exists('EEmail'))
  702. {
  703. require PATH_CORE.'core.email'.EXT;
  704. }
  705. $email = new EEmail;
  706. $email->wordwrap = ($wordwrap == 'y') ? TRUE : FALSE;
  707. $email->mailtype = $mailtype;
  708. $email->priority = $priority;
  709. foreach ($emails as $key => $val)
  710. {
  711. $screen_name = '';
  712. $list_id = FALSE;
  713. if (is_array($val) AND substr($key, 0, 1) == 'm')
  714. {
  715. $screen_name = $val['1'];
  716. $val = $val['0'];
  717. }
  718. elseif (is_array($val) AND substr($key, 0, 1) == 'l')
  719. {
  720. $list_id = $val['1'];
  721. $val = $val['0'];
  722. }
  723. $email->initialize();
  724. $email->to($val);
  725. $email->from($from, $name);
  726. $email->subject($subject);
  727. // We need to add the unsubscribe link to emails - but only ones
  728. // from the mailing list. When we gathered the email addresses
  729. // above, we added one of three prefixes to the array key:
  730. //
  731. // m = member id
  732. // l = mailing list
  733. // r = general recipient
  734. // Make a copy so we don't mess up the original
  735. $msg = $message;
  736. $msg_alt = $plaintext_alt;
  737. if (substr($key, 0, 1) == 'l')
  738. {
  739. $msg = $this->parse_template($list_templates[$list_id], $msg, $action_id, substr($key, 1), $mailtype);
  740. $msg_alt = $this->parse_template($list_templates[$list_id], $msg_alt, $action_id, substr($key, 1), 'plain');
  741. }
  742. $msg = str_replace('{name}', $screen_name, $msg);
  743. $msg_alt = str_replace('{name}', $screen_name, $msg_alt);
  744. $email->message($msg, $msg_alt);
  745. $error = FALSE;
  746. if ( ! $email->Send())
  747. {
  748. $error = TRUE;
  749. }
  750. $debug_msg = $this->debug_message($email->debug_msg);
  751. if ($error == TRUE)
  752. {
  753. return $DSP->error_message($LANG->line('error_sending_email').$debug_msg, 0);
  754. }
  755. $total_sent++;
  756. }
  757. /** ----------------------------------------
  758. /** Store email cache
  759. /** ----------------------------------------*/
  760. $cache_data['total_sent'] = $total_sent;
  761. $this->save_cache_data($cache_data, $groups, $list_ids);
  762. /** ----------------------------------------
  763. /** Success Mesage
  764. /** ----------------------------------------*/
  765. $DSP->set_return_data(
  766. $LANG->line('email_sent'),
  767. $DSP->qdiv('defaultPad', $DSP->qdiv('success', $LANG->line('email_sent_message'))).$DSP->qdiv('defaultPad', $DSP->qdiv('', $LANG->line('total_emails_sent').NBS.NBS.$total_sent)).$debug_msg,
  768. $LANG->line('email_sent')
  769. );
  770. // We're done
  771. return;
  772. }
  773. /** ----------------------------------------
  774. /** Start Batch-Mode
  775. /** ----------------------------------------*/
  776. // Store email cache
  777. $cache_data['recipient_array'] = addslashes(serialize($emails));
  778. $id = $this->save_cache_data($cache_data, $groups, $list_ids);
  779. // Turn on "refresh"
  780. // By putting the URL in the $DSP->refresh variable we'll tell the
  781. // system to write a <meta> refresh header, starting the batch process
  782. $DSP->refresh = BASE.AMP.'C=communicate'.AMP.'M=batch_send'.AMP.'id='.$id;
  783. $DSP->ref_rate = 6;
  784. // Kill the bread-crumb links, just to keep it away from the user
  785. $DSP->show_crumb = FALSE;
  786. // Write the initial message, telling the user the batch processor is about to start
  787. $r = $DSP->heading(BR.$LANG->line('sending_email'));
  788. $r .= $DSP->qdiv('itemWrapper', $LANG->line('batchmode_ready_to_begin'));
  789. $r .= $DSP->qdiv('', $DSP->qdiv('alert', $LANG->line('batchmode_warning')));
  790. $DSP->body = $r;
  791. }
  792. /* END */
  793. /** ----------------------------------------
  794. /** Add unsubscribe link to emails
  795. /** ----------------------------------------*/
  796. function parse_template($template, $message, $action_id, $code, $mailtype='plain')
  797. {
  798. global $PREFS, $LANG, $FNS;
  799. if (is_array($template))
  800. {
  801. $list_title = $template['list_title'];
  802. $temp = $template['list_template'];
  803. }
  804. else
  805. {
  806. $list_title = '';
  807. $temp = $template;
  808. }
  809. $qs = ($PREFS->ini('force_query_string') == 'y') ? '' : '?';
  810. $link_url = $FNS->fetch_site_index(0, 0).$qs.'ACT='.$action_id.'&id='.$code;
  811. $temp = str_replace('{unsubscribe_url}', $link_url, $temp);
  812. if ($mailtype == 'html')
  813. {
  814. $temp = preg_replace("/\{if\s+html_email\}(.+?)\{\/if\}/si", "\\1", $temp);
  815. $temp = preg_replace("/\{if\s+plain_email\}.+?\{\/if\}/si", "", $temp);
  816. }
  817. else
  818. {
  819. $temp = preg_replace("/\{if\s+plain_email\}(.+?)\{\/if\}/si", "\\1", $temp);
  820. $temp = preg_replace("/\{if\s+html_email\}.+?\{\/if\}/si", "", $temp);
  821. }
  822. $temp = str_replace('{mailing_list}', $list_title, $temp);
  823. return str_replace('{message_text}', $message, $temp);
  824. }
  825. /* END */
  826. /** ------------------------------------
  827. /** Convert recipient string to array
  828. /** ------------------------------------*/
  829. function convert_recipients($recipients = '')
  830. {
  831. $emails = array();
  832. $ct = 0;
  833. if ($recipients != '')
  834. {
  835. $recipients = trim(str_replace(",,", ",", $recipients), ',');
  836. if (strpos($recipients, ',') !== FALSE)
  837. {
  838. $x = explode(',', $recipients);
  839. for ($i = 0; $i < count($x); $i ++)
  840. $emails['r'.$ct] = trim($x[$i]);
  841. }
  842. else
  843. {
  844. $emails['r'.$ct] = $recipients;
  845. }
  846. }
  847. return $emails;
  848. }
  849. /* END */
  850. /** -----------------------------
  851. /** Count total recipients
  852. /** -----------------------------*/
  853. function fetch_total($to, $cc, $bcc)
  854. {
  855. $total = 0;
  856. if ($to != '')
  857. {
  858. $total += count(explode(",", $to));
  859. }
  860. if ($cc != '')
  861. {
  862. $total += count(explode(",", $cc));
  863. }
  864. if ($bcc != '')
  865. {
  866. $total += count(explode(",", $bcc));
  867. }
  868. return $total;
  869. }
  870. /* END */
  871. /** -----------------------------
  872. /** Save cache data
  873. /** -----------------------------*/
  874. function save_cache_data($cache_data, $groups = '', $list_ids = '')
  875. {
  876. global $DB;
  877. // We don't cache emails sent by "user blogs"
  878. if (USER_BLOG != FALSE)
  879. {
  880. return;
  881. }
  882. $DB->query($DB->insert_string('exp_email_cache', $cache_data));
  883. $cache_id = $DB->insert_id;
  884. if (is_array($groups))
  885. {
  886. if (count($groups) > 0)
  887. {
  888. foreach ($groups as $id)
  889. {
  890. $DB->query("INSERT INTO exp_email_cache_mg (cache_id, group_id) VALUES ('$cache_id', '".$DB->escape_str($id)."')");
  891. }
  892. }
  893. }
  894. if (is_array($list_ids))
  895. {
  896. if (count($list_ids) > 0)
  897. {
  898. foreach ($list_ids as $id)
  899. {
  900. $DB->query("INSERT INTO exp_email_cache_ml (cache_id, list_id) VALUES ('$cache_id', '".$DB->escape_str($id)."')");
  901. }
  902. }
  903. }
  904. return $cache_id;
  905. }
  906. /* END */
  907. /** -----------------------------
  908. /** Send email in batch mode
  909. /** -----------------------------*/
  910. function batch_send()
  911. {
  912. global $IN, $DSP, $FNS, $LANG, $DB, $SESS, $PREFS, $REGX;
  913. $DSP->title = $LANG->line('communicate');
  914. $DSP->show_crumb = FALSE;
  915. $debug_msg = '';
  916. if ( ! $id = $IN->GBL('id'))
  917. {
  918. return $DSP->error_message($LANG->line('problem_with_id'), 0);
  919. }
  920. /** -----------------------------
  921. /** Fetch mailing list IDs
  922. /** -----------------------------*/
  923. $list_templates = array();
  924. if ($this->mailinglist_exists == TRUE)
  925. {
  926. $query = $DB->query("SELECT list_id FROM exp_email_cache_ml WHERE cache_id = '".$DB->escape_str($id)."'");
  927. if ($query->num_rows > 0)
  928. {
  929. foreach ($query->result as $row)
  930. {
  931. // Fetch the template for each list
  932. $query = $DB->query("SELECT list_template, list_title FROM exp_mailing_lists WHERE list_id = '".$row['list_id']."'");
  933. $list_templates[$row['list_id']] = array('list_template' => $query->row['list_template'], 'list_title' => $query->row['list_title']);
  934. }
  935. }
  936. }
  937. /** -----------------------------
  938. /** Fetch cached email
  939. /** -----------------------------*/
  940. $query = $DB->query("SELECT * FROM exp_email_cache WHERE cache_id = '".$DB->escape_str($id)."'");
  941. if ($query->num_rows == 0)
  942. {
  943. return $DSP->error_message($LANG->line('cache_data_missing'), 0);
  944. }
  945. // Turn the result fields into variables
  946. foreach ($query->row as $key => $val)
  947. {
  948. if ($key == 'recipient_array')
  949. {
  950. $$key = $REGX->array_stripslashes(unserialize($val));
  951. }
  952. else
  953. {
  954. $$key = $val;
  955. }
  956. }
  957. /** -------------------------------------------------
  958. /** Determine which emails correspond to this batch
  959. /** -------------------------------------------------*/
  960. $finished = FALSE;
  961. $total = count($recipient_array);
  962. $batch = $PREFS->ini('email_batch_size');
  963. if ($batch > $total)
  964. {
  965. $batch = $total;
  966. $finished = TRUE;
  967. }
  968. /** ---------------------------------------
  969. /** Apply text formatting if necessary
  970. /** ---------------------------------------*/
  971. if ($text_fmt != 'none' && $text_fmt != '')
  972. {
  973. if ( ! class_exists('Typography'))
  974. {
  975. require PATH_CORE.'core.typography'.EXT;
  976. }
  977. $TYPE = new Typography(0);
  978. $TYPE->parse_smileys = FALSE;
  979. $message = $TYPE->parse_type($message,
  980. array(
  981. 'text_format' => $text_fmt,
  982. 'html_format' => 'all',
  983. 'auto_links' => 'n',
  984. 'allow_img_url' => 'y'
  985. )
  986. );
  987. }
  988. /** ---------------------
  989. /** Send emails
  990. /** ---------------------*/
  991. $action_id = $FNS->fetch_action_id('Mailinglist', 'unsubscribe');
  992. require PATH_CORE.'core.email'.EXT;
  993. $email = new EEmail;
  994. $email->wordwrap = ($wordwrap == 'y') ? TRUE : FALSE;
  995. $email->mailtype = $mailtype;
  996. $email->priority = $priority;
  997. $i = 0;
  998. foreach ($recipient_array as $key => $val)
  999. {
  1000. if ($i == $batch)
  1001. {
  1002. break;
  1003. }
  1004. $screen_name = '';
  1005. $list_id = FALSE;
  1006. if (is_array($val) AND substr($key, 0, 1) == 'm')
  1007. {
  1008. $screen_name = $val['1'];
  1009. $val = $val['0'];
  1010. }
  1011. elseif (is_array($val) AND substr($key, 0, 1) == 'l')
  1012. {
  1013. $list_id = $val['1'];
  1014. $val = $val['0'];
  1015. }
  1016. $email->initialize();
  1017. $email->from($from_email, $from_name);
  1018. $email->to($val);
  1019. $email->subject($subject);
  1020. // m = member id
  1021. // l = mailing list
  1022. // r = general recipient
  1023. // Make a copy so we don't mess up the original
  1024. $msg = $message;
  1025. $msg_alt = $plaintext_alt;
  1026. if (substr($key, 0, 1) == 'l')
  1027. {
  1028. $msg = $this->parse_template($list_templates[$list_id], $msg, $action_id, substr($key, 1), $mailtype);
  1029. $msg_alt = $this->parse_template($list_templates[$list_id], $msg_alt, $action_id, substr($key, 1), 'plain');
  1030. }
  1031. $msg = str_replace('{name}', $screen_name, $msg);
  1032. $msg_alt = str_replace('{name}', $screen_name, $msg_alt);
  1033. $email->message($msg, $msg_alt);
  1034. $error = FALSE;
  1035. if ( ! $email->Send())
  1036. {
  1037. $error = TRUE;
  1038. }
  1039. $debug_msg = $this->debug_message($email->debug_msg);
  1040. if ($error == TRUE)
  1041. {
  1042. return $DSP->error_message($LANG->line('error_sending_email').$debug_msg, 0);
  1043. }
  1044. $i++;
  1045. }
  1046. $n = $total_sent + $i;
  1047. /** ------------------------
  1048. /** More batches to do...
  1049. /** ------------------------*/
  1050. if ($finished == FALSE)
  1051. {
  1052. reset($recipient_array);
  1053. $recipient_array = addslashes(serialize(array_slice($recipient_array, $i)));
  1054. $DB->query("UPDATE exp_email_cache SET total_sent = '$n', recipient_array = '$recipient_array' WHERE cache_id = '".$DB->escape_str($id)."'");
  1055. $DSP->refresh = BASE.AMP.'C=communicate'.AMP.'M=batch_send'.AMP.'id='.$id;
  1056. $DSP->ref_rate = 4;
  1057. $r = $DSP->heading(BR.$LANG->line('sending_email'));
  1058. $stats = str_replace("%x", ($total_sent + 1), $LANG->line('currently_sending_batch'));
  1059. $stats = str_replace("%y", $n, $stats);
  1060. $r .= $DSP->qdiv('itemWrapper', $stats);
  1061. $remaining = $total - $batch;
  1062. $r .= $DSP->qdiv('itemWrapper', $LANG->line('emails_remaining').NBS.NBS.$remaining);
  1063. $r .= $DSP->qdiv('', $DSP->qdiv('alert', $LANG->line('batchmode_warning')));
  1064. }
  1065. /** ------------------------
  1066. /** Finished!
  1067. /** ------------------------*/
  1068. else
  1069. {
  1070. $DB->query("UPDATE exp_email_cache SET total_sent = '$n', recipient_array = '' WHERE cache_id = '".$DB->escape_str($id)."'");
  1071. $r = $DSP->heading(BR.$LANG->line('email_sent'));
  1072. $r .= $DSP->qdiv('success', $LANG->line('all_email_sent_message'));
  1073. $total = $total_sent + $batch;
  1074. $r .= $DSP->qdiv('itemWrapper', $LANG->line('total_emails_sent').NBS.NBS.$total);
  1075. }
  1076. $DSP->body = $r;
  1077. }
  1078. /* END */
  1079. /** ------------------------
  1080. /** View Email Cache
  1081. /** ------------------------*/
  1082. function view_email_cache($message = '')
  1083. {
  1084. global $IN, $DB, $LANG, $DSP, $LOC;
  1085. if ( ! $DSP->allowed_group('can_send_cached_email'))
  1086. {
  1087. return $DSP->no_access_message($LANG->line('not_allowed_to_email_mailinglist'));
  1088. }
  1089. /** -----------------------------
  1090. /** Define base variables
  1091. /** -----------------------------*/
  1092. $i = 0;
  1093. $s1 = 'tableCellOne';
  1094. $s2 = 'tableCellTwo';
  1095. $row_limit = 50;
  1096. $paginate = '';
  1097. $row_count = 0;
  1098. $DSP->title = $LANG->line('previous_email');
  1099. $DSP->crumb = $LANG->line('previous_email');
  1100. $DSP->body = $DSP->qdiv('tableHeading', $LANG->line('previous_email'));
  1101. if ($message != '')
  1102. {
  1103. $DSP->body .= $DSP->qdiv('success', $message);
  1104. }
  1105. /** -----------------------------
  1106. /** Run Query
  1107. /** -----------------------------*/
  1108. $sql = "SELECT * FROM exp_email_cache ORDER BY cache_id desc";
  1109. $query = $DB->query($sql);
  1110. if ($query->num_rows == 0)
  1111. {
  1112. if ($message == '')
  1113. $DSP->body .= $DSP->qdiv('box', $DSP->qdiv('itemWrapper', $DSP->qdiv('highlight', $LANG->line('no_cached_email'))));
  1114. return;
  1115. }
  1116. /** -----------------------------
  1117. /** Do we need pagination?
  1118. /** -----------------------------*/
  1119. if ($query->num_rows > $row_limit)
  1120. {
  1121. $row_count = ( ! $IN->GBL('row')) ? 0 : $IN->GBL('row');
  1122. $url = BASE.AMP.'C=communicate'.AMP.'M=view_cache';
  1123. $paginate = $DSP->pager( $url,
  1124. $query->num_rows,
  1125. $row_limit,
  1126. $row_count,
  1127. 'row'
  1128. );
  1129. $sql .= " LIMIT ".$row_count.", ".$row_limit;
  1130. $query = $DB->query($sql);
  1131. }
  1132. $DSP->body .= $DSP->toggle();
  1133. $DSP->body .= $DSP->form_open(
  1134. array(
  1135. 'action' => 'C=communicate'.AMP.'M=delete_conf',
  1136. 'name' => 'target',
  1137. 'id' => 'target'
  1138. )
  1139. );
  1140. $DSP->body .= $DSP->table('tableBorder', '0', '0', '100%').
  1141. $DSP->tr().
  1142. $DSP->table_qcell('tableHeading',
  1143. array(
  1144. NBS,
  1145. $LANG->line('email_title'),
  1146. $LANG->line('email_date'),
  1147. $LANG->line('total_recipients'),
  1148. $LANG->line('resend'),
  1149. $DSP->input_checkbox('toggleflag', '', '', "onclick=\"toggle(this);\"").NBS.$LANG->line('delete').NBS.NBS
  1150. )
  1151. ).
  1152. $DSP->tr_c();
  1153. /** -----------------------------
  1154. /** Table Rows
  1155. /** -----------------------------*/
  1156. $row_count++;
  1157. foreach ($query->result as $row)
  1158. {
  1159. $DSP->body .= $DSP->table_qrow( ($i++ % 2) ? $s1 : $s2,
  1160. array(
  1161. $row_count,
  1162. $DSP->anchorpop(BASE.AMP.'C=communicate'.AMP.'M=view_email'.AMP.'id='.$row['cache_id'].AMP.'Z=1', '<b>'.$row['subject'].'</b>', '600', '580'),
  1163. $LOC->set_human_time($row['cache_date']),
  1164. $row['total_sent'],
  1165. $DSP->qspan('defaultBold', $DSP->anchor(BASE.AMP.'C=communicate'.AMP.'id='.$row['cache_id'], $LANG->line('resend'))),
  1166. $DSP->input_checkbox('toggle[]', $row['cache_id'])
  1167. )
  1168. );
  1169. $row_count++;
  1170. }
  1171. $DSP->body .= $DSP->table_c();
  1172. if ($paginate != '')
  1173. {
  1174. $DSP->body .= $DSP->qdiv('itemWrapper', $paginate);
  1175. }
  1176. $DSP->body .= $DSP->qdiv('itemWrapper', BR.$DSP->input_submit($LANG->line('delete')));
  1177. $DSP->body .= $DSP->form_close();
  1178. }
  1179. /* END */
  1180. /** ------------------------
  1181. /** View a specific email
  1182. /** ------------------------*/
  1183. function view_email()
  1184. {
  1185. global $IN, $DB, $LANG, $DSP, $LOC;
  1186. if ( ! $DSP->allowed_group('can_send_cached_email'))
  1187. {
  1188. return $DSP->no_access_message($LANG->line('not_allowed_to_email_mailinglist'));
  1189. }
  1190. $id = $IN->GBL('id');
  1191. /** -----------------------------
  1192. /** Run Query
  1193. /** -----------------------------*/
  1194. $query = $DB->query("SELECT mailtype, subject, message FROM exp_email_cache WHERE cache_id = '".$DB->escape_str($id)."' ");
  1195. if ($query->num_rows == 0)
  1196. {
  1197. $DSP->body .= $DSP->qdiv('itemWrapper', $DSP->qdiv('highlight', $LANG->line('no_cached_email')));
  1198. return;
  1199. }
  1200. /** -----------------------------
  1201. /** Clean up message
  1202. /** -----------------------------*/
  1203. // If the message was submitted in HTML format
  1204. // we'll remove everything except the body
  1205. $message = $query->row['message'];
  1206. if ($query->row['mailtype'] == 'html')
  1207. {
  1208. $message = (preg_match("/<body.*?".">(.*)<\/body>/is", $message, $match)) ? $match['1'] : $message;
  1209. }
  1210. /** -----------------------------
  1211. /** Render output
  1212. /** -----------------------------*/
  1213. $DSP->body .= $DSP->heading(BR.$query->row['subject']);
  1214. /** ----------------------------------------
  1215. /** Instantiate Typography class
  1216. /** ----------------------------------------*/
  1217. if ( ! class_exists('Typography'))
  1218. {
  1219. require PATH_CORE.'core.typography'.EXT;
  1220. }
  1221. $TYPE = new Typography;
  1222. $DSP->body .= $TYPE->parse_type( $message,
  1223. array(
  1224. 'text_format' => 'xhtml',
  1225. 'html_format' => 'all',
  1226. 'auto_links' => 'y',
  1227. 'allow_img_url' => 'y'
  1228. )
  1229. );
  1230. }
  1231. /* END */
  1232. /** -------------------------------------------
  1233. /** Delete Confirm
  1234. /** -------------------------------------------*/
  1235. function delete_confirm()
  1236. {
  1237. global $IN, $DSP, $LANG;
  1238. if ( ! $DSP->allowed_group('can_send_cached_email'))
  1239. {
  1240. return $DSP->no_access_message($LANG->line('not_allowed_to_email_mailinglist'));
  1241. }
  1242. if ( ! $IN->GBL('toggle', 'POST'))
  1243. {
  1244. return $this->view_email_cache();
  1245. }
  1246. $DSP->title = $LANG->line('delete_emails');
  1247. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=communicate'.AMP.'M=view_cache', $LANG->line('view_email_cache'));
  1248. $DSP->crumb .= $DSP->crumb_item($LANG->line('delete_emails'));
  1249. $DSP->body .= $DSP->form_open(array('action' => 'C=communicate'.AMP.'M=delete'));
  1250. $i = 0;
  1251. foreach ($_POST as $key => $val)
  1252. {
  1253. if (strstr($key, 'toggle') AND ! is_array($val))
  1254. {
  1255. $DSP->body .= $DSP->input_hidden('delete[]', $val);
  1256. $i++;
  1257. }
  1258. }
  1259. $DSP->body .= $DSP->heading($DSP->qspan('alert', $LANG->line('delete_confirm')));
  1260. $DSP->body .= $DSP->div('box');
  1261. $DSP->body .= $DSP->qdiv('defaultBold', $LANG->line('delete_question'));
  1262. $DSP->body .= $DSP->qdiv('alert', BR.$LANG->line('action_can_not_be_undone'));
  1263. $DSP->body .= $DSP->qdiv('', BR.$DSP->input_submit($LANG->line('delete')));
  1264. $DSP->body .= $DSP->div_c();
  1265. $DSP->body .= $DSP->form_close();
  1266. }
  1267. /* END */
  1268. /** -------------------------------------------
  1269. /** Delete Emails
  1270. /** -------------------------------------------*/
  1271. function delete_emails()
  1272. {
  1273. global $IN, $DSP, $LANG, $DB;
  1274. if ( ! $DSP->allowed_group('can_send_cac…

Large files files are truncated, but you can click here to view the full file