PageRenderTime 46ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/administrator/components/com_sm2emailmarketing/includes/message.admin.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 894 lines | 608 code | 179 blank | 107 comment | 90 complexity | 3e63950451f7321bfd0d207426425901 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. // $Id: message.admin.php,v 1.45 2008/03/31 01:59:10 sm2tony Exp $
  3. /**
  4. * sm2emailmarketing - Email Marketing Newsletter
  5. *
  6. * Joomla! Newsletter Component that supports multiple list mailing and message queueing
  7. *
  8. * @package Joomla!
  9. * @subpackage com_sm2emailmarketing
  10. * @copyright Copyright (C) 2006 SM2 / All Rights Reserved
  11. * @license commercial
  12. * @author SM2 <info@sm2joomla.com>
  13. */
  14. /**
  15. * Makes sure this is included by a parent file
  16. */
  17. defined('_VALID_MOS') or die('Direct Access to this location is not allowed.');
  18. function showMessages($option) {
  19. global $database, $mainframe, $mosConfig_list_limit, $mosConfig_absolute_path, $emErrorHandler;
  20. // get some data from the request information
  21. $limit = $mainframe->getUserStateFromRequest( 'viewmessagelimit', 'limit', $mosConfig_list_limit );
  22. $limitstart = $mainframe->getUserStateFromRequest( 'view'.$option.'messagestart', 'limitstart', 0 );
  23. $search = $mainframe->getUserStateFromRequest('search'.$option.'messages', 'search', '');
  24. $search = $database->getEscaped(trim(strtolower($search)));
  25. // test to see if necessary permission is set
  26. testJoomlaDatabaseUserPrivileges();
  27. // see if we may need to clean up some tables
  28. cleanupTemporaryTables();
  29. // determine if there is anything to search for
  30. if (!empty($search)) {
  31. $where = ' WHERE (LOWER(am.subject) LIKE '
  32. .$database->Quote('%'.$search.'%').')';
  33. } else {
  34. $where = '';
  35. }
  36. // Get the total number of records
  37. $qrysql = 'SELECT COUNT(*)'
  38. .' FROM #__emktg_message am'
  39. .$where;
  40. $database->setQuery($qrysql);
  41. $total = $database->loadResult();
  42. // handle the page navigation
  43. include_once($mosConfig_absolute_path.'/administrator/includes/pageNavigation.php');
  44. $pageNav = new mosPageNav($total, $limitstart, $limit);
  45. // build the query to get the data to display
  46. $qrysql = 'SELECT am.messageid, am.subject, at.template_name, am.send_date'
  47. .' FROM #__emktg_message am'
  48. .' LEFT JOIN #__emktg_template at ON am.templateid = at.templateid'
  49. .$where
  50. .' ORDER BY am.messageid desc'
  51. .' LIMIT '.(int)$pageNav->limitstart.', '.(int)$pageNav->limit;
  52. // get the data to display
  53. $database->setQuery($qrysql);
  54. $rows = $database->loadObjectList();
  55. if ($database->getErrorNum()) {
  56. $emErrorHandler->addError('<p><strong>Error (message.admin.php->showMessages() line ' . __LINE__ . '):</strong>'._EMKTG_MESSAGE_ERROR.'</p>');
  57. return false;
  58. }
  59. // preparse the rows found
  60. if (!empty($rows)) {
  61. $k = 0;
  62. for ($i=0; $i < count($rows); $i++) {
  63. $row = &$rows[$i];
  64. $row->id = $row->messageid;
  65. $row->checked_out=0;
  66. $row->k = $k;
  67. $row->link = 'index2.php?option='.$option.'&task=checkmessage&hidemainmenu=0&cid[]='.$row->id;
  68. $row->checkedDisplay = mosCommonHTML::CheckedOutProcessing($row, $i);
  69. if ($row->send_date!=0) {
  70. $row->send_dateDisplay = mosFormatDate($row->send_date, _EMKTG_MESSAGE_SENDDATE_FORMAT);
  71. } else {
  72. $row->send_dateDisplay = '';
  73. }
  74. $k = 1 - $k;
  75. } // for
  76. }
  77. // load the language elements
  78. $lang = sm2emailmarketingLanguage();
  79. // call the object to display the list
  80. $tmpl = sm2emailmarketingPatTemplate('message.tpl', $option);
  81. $tmpl->addVar('header', 'FORM_NAME', _EMKTG_MESSAGE_FORM);
  82. $tmpl->addVar('manager', 'SEARCH', $search);
  83. $tmpl->addVar('manager', 'NUM_ROWS', count($rows));
  84. $tmpl->addObject('manager', $lang, 'LANG');
  85. $tmpl->addObject('rows', $rows, 'ROW_');
  86. $tmpl->addVar('manager', 'LISTFOOTER', $pageNav->getListFooter());
  87. $tmpl->displayParsedTemplate('manager');
  88. } // showMessages()
  89. function checkMessage($id, $option, $task) {
  90. global $database;
  91. // create an instance of the table class
  92. $row = new sm2emailmarketingMessage();
  93. // Load the row from the db table
  94. $row->load($id);
  95. if ($row->send_date == $database->getNullDate()) {
  96. // not sent yet so send to editMessage
  97. mosRedirect('index2.php?option='.$option.'&task=editmessage&hidemainmenu=0&cid[]='.$id);
  98. } else {
  99. // load the language elements
  100. $lang = sm2emailmarketingLanguage();
  101. // call the object to display the list
  102. $tmpl = sm2emailmarketingPatTemplate('message.tpl', $option);
  103. $tmpl->addVar('header', 'FORM_NAME', _E_EDIT.' '._EMKTG_MESSAGE);
  104. $tmpl->addObject('check', $lang, 'LANG');
  105. $tmpl->addObject('check', $row, 'ROW_');
  106. $tmpl->displayParsedTemplate('check');
  107. }
  108. } // checkMessage()
  109. function editMessage($id, $option, $task) {
  110. global $database, $sm2emailmarketingConfig, $mosConfig_absolute_path, $mosConfig_fromname, $mosConfig_mailfrom;
  111. // create an instance of the table class
  112. $row = new sm2emailmarketingMessage();
  113. // Load the row from the db table
  114. $row->load($id);
  115. // load the plugins and setup so they can be processed easily
  116. // get the data from the plugins//where enabled=1
  117. $database->setQuery('SELECT * FROM #__emktg_plugin ORDER BY ordering');
  118. $plugins = $database->loadObjectList();
  119. $contentPluginIndex = null;
  120. foreach (array_keys($plugins) as $index) {
  121. if (!file_exists($mosConfig_absolute_path.'/administrator/components/'.$option.'/plugins/'.$plugins[$index]->filename)) {
  122. unset($plugins[$index]);
  123. continue;
  124. }
  125. if ($plugins[$index]->filename == 'content.plugin.php') {
  126. $contentPluginIndex = $index;
  127. }
  128. $plugins[$index]->_plugin = require_once($mosConfig_absolute_path.'/administrator/components/'.$option.'/plugins/'.$plugins[$index]->filename);
  129. } // foreach()
  130. // initialise lists
  131. $lists = new stdClass();
  132. // get the list of templates
  133. $templates = array();
  134. $templates[] = mosHTML::makeOption('0', _EMKTG_TEMPLATE_DESC);
  135. $database->setQuery('SELECT templateid AS value, template_name AS text FROM #__emktg_template WHERE published=1 ORDER BY template_name');
  136. $templates = array_merge($templates, $database->loadObjectList());
  137. $lists->templateid = mosHTML::selectList($templates, 'templateid', 'tabindex="5" class="inputbox" size="1"', 'value', 'text', $row->templateid);
  138. unset($templates);
  139. // get the image list
  140. $path = $sm2emailmarketingConfig->get('attachment_path', $mosConfig_absolute_path.'/images/stories/');
  141. $lists->attachments = getAttachments('attachments[]', convertArrayToOptions(explode(',', $row->attachments)), '', $path);
  142. // process the plugins to display the extras
  143. $messageExtras = '';
  144. $pluginExtraValidation = '';
  145. foreach ($plugins as $plugin) {
  146. //if (!isset($plugin->_plugin)) continue;
  147. if (!is_object($plugin->_plugin)) continue;
  148. if (method_exists($plugin->_plugin, 'displayMessageExtras')) {
  149. $messageExtras .= $plugin->_plugin->displayMessageExtras($row, $plugin, $option);
  150. }
  151. $pluginExtraValidation .= $plugin->_plugin->_plugin_extra_validation;
  152. }
  153. // get the list of content items available
  154. $query = 'SELECT A.id AS value, CONCAT(B.title, '
  155. .$database->Quote('/').', C.title, '
  156. .$database->Quote('/').', A.title) AS text, A.created'
  157. .' FROM #__content AS A, #__sections AS B, #__categories AS C'
  158. .' WHERE A.sectionid = B.id AND A.catid = C.id'
  159. .' AND A.state=1'
  160. .' ORDER BY B.title, C.title, A.title';
  161. $database->setQuery($query);
  162. $contentitems = $database->loadObjectList();
  163. // determine if we need to display the content date
  164. $showContentDate = false;
  165. if ($contentPluginIndex!==null) {
  166. if (array_key_exists($contentPluginIndex, $plugins)) {
  167. $contentPlugin = $plugins[$contentPluginIndex];
  168. $pluginFile = $mosConfig_absolute_path.'/administrator/components/'.$option.'/plugins/'.str_replace('.php', '.xml', $contentPlugin->filename);
  169. if (file_exists($pluginFile)) {
  170. $params =& new sm2emailmarketingParams($contentPlugin->params, $pluginFile, 'sm2emailmarketing_plugin');
  171. }
  172. if ($params->get('available_date', 0)) {
  173. $showContentDate = true;
  174. foreach ($contentitems as $index=>$value) {
  175. $contentitems[$index]->text .= ' ['
  176. .mosFormatDate($value->created,
  177. _EMKTG_MESSAGE_SENDDATE_FORMAT)
  178. .']';
  179. }
  180. }
  181. }
  182. }
  183. $size = min(count($contentitems), 10);
  184. $lists->availcontent = mosHTML::selectList($contentitems, 'availContent', 'tabindex="9" id="availContent" class="inputbox" style="width:100%;" size="'.$size.'" multiple', 'value', 'text', null);
  185. unset($contentitems);
  186. // build the list of selected items
  187. if (empty($row->content_items)) {
  188. $foundItems = array();
  189. } else {
  190. $foundItems = explode(',',$row->content_items);
  191. }
  192. // use the same query but get the data differently
  193. $contentMatrix = $database->loadObjectList('value');
  194. $contentitems = array();
  195. foreach ($foundItems as $contentid) {
  196. if ($showContentDate) {
  197. $contentMatrix[$contentid]->text .= ' ['
  198. .mosFormatDate($contentMatrix[$contentid]->created,
  199. _EMKTG_MESSAGE_SENDDATE_FORMAT)
  200. .']';
  201. }
  202. // add the found items to the content items array in order
  203. $contentitems[] = $contentMatrix[$contentid];
  204. }
  205. $lists->selectedcontent = mosHTML::selectList($contentitems, 'selectedContent', 'tabindex="10" id="selectedContent" class="inputbox" style="width:100%;" size="'.$size.'" multiple', 'value', 'text', null);
  206. unset($contentitems);
  207. if (!empty($row->intro_only)) {
  208. $row->intro_only = ' checked';
  209. } else {
  210. $row->intro_only = '';
  211. }
  212. ob_start();
  213. editorArea( 'editor1', $row->message_html , 'message_html', 500, 200, '70', '20' );
  214. $row->message_htmlDisplay = ob_get_contents();
  215. ob_end_clean();
  216. ob_start();
  217. getEditorContents('editor1', 'message_html');
  218. $row->message_htmlValidation = ob_get_contents();
  219. ob_end_clean();
  220. if (empty($row->fromname)) {
  221. $row->fromname = $sm2emailmarketingConfig->get('fromname', $mosConfig_fromname);
  222. }
  223. if (empty($row->fromemail)) {
  224. $row->fromemail = $sm2emailmarketingConfig->get('fromemail', $mosConfig_mailfrom);
  225. }
  226. if (empty($row->bounceemail)) {
  227. $row->bounceemail = $sm2emailmarketingConfig->get('bounceemail', $mosConfig_mailfrom);
  228. }
  229. if ($row->send_date==0) {
  230. $row->send_date = '';
  231. }
  232. // get the filters from the plugins
  233. $pluginData = '';
  234. $pluginValidation = '';
  235. foreach ($plugins as $plugin) {
  236. //if (!isset($plugin->_plugin)) continue;
  237. if (!is_object($plugin->_plugin)) continue;
  238. if (!$plugin->enabled) continue;
  239. if (method_exists($plugin->_plugin, 'displayMessageFilters')) {
  240. $pluginData .= $plugin->_plugin->displayMessageFilters($id, $plugin->pluginid, $option);
  241. }
  242. $pluginValidation .= $plugin->_plugin->_plugin_validation;
  243. } // foreach()
  244. switch ($task) {
  245. case 'newmessage':
  246. $title= _E_ADD;
  247. break;
  248. case 'copymessage':
  249. $title = _EMKTG_COPY;
  250. $row->messageid = 0;
  251. $row->subject = sm2emailmarketingProcessCopyTitle($row->subject);
  252. $row->send_date = '';
  253. break;
  254. case 'editmessage':
  255. default:
  256. $title = _E_EDIT;
  257. break;
  258. }
  259. // load the language elements
  260. $lang = sm2emailmarketingLanguage();
  261. // display the form
  262. mosMakeHtmlSafe($row, ENT_QUOTES, array('message_htmlDisplay', 'message_htmlValidation'));
  263. mosCommonHTML::loadOverlib();
  264. $tmpl = sm2emailmarketingPatTemplate('message.tpl', $option);
  265. $tmpl->addVar('header', 'FORM_NAME', $title.' '._EMKTG_MESSAGE);
  266. $tmpl->addVar('edit', 'messageextras', $messageExtras);
  267. $tmpl->addVar('edit', 'PLUGINDATA', $pluginData);
  268. $tmpl->addVar('edit', 'PLUGINVALIDATION', $pluginValidation);
  269. $tmpl->addVar('edit', 'PLUGINEXTRAVALIDATION', $pluginExtraValidation);
  270. $tmpl->addObject('edit', $lang, 'LANG');
  271. $tmpl->addObject('edit', $row, 'ROW_');
  272. $tmpl->addObject('edit', $lists, 'LIST_');
  273. $tmpl->displayParsedTemplate('edit');
  274. } // editMessage()
  275. function saveMessage($option, $task) {
  276. global $database, $mosConfig_absolute_path, $emErrorHandler;
  277. // create an instance of the table class
  278. $row = new sm2emailmarketingMessage();
  279. // attempt to bind the class to the data posted
  280. if (defined('_JLEGACY')) {
  281. $post = JRequest::get('post', JREQUEST_ALLOWRAW);
  282. } else {
  283. $post = $_POST;
  284. }
  285. if (!$row->bind($post)) {
  286. $emErrorHandler->addError($row->getError(), true);
  287. }
  288. // check the record
  289. if (!$row->check()) {
  290. $emErrorHandler->addError($row->getError(), true);
  291. }
  292. // fix the two arrays
  293. if (!empty($row->attachments)) {
  294. $row->attachments = implode(',', $row->attachments);
  295. }
  296. // attempt to insert/update the record
  297. if (!$row->store(true)) {
  298. $emErrorHandler->addError($row->getError(), true);
  299. }
  300. // store the data from the plugins //where enabled=1
  301. $database->setQuery('SELECT * FROM #__emktg_plugin ORDER BY ordering');
  302. $data = $database->loadObjectList();
  303. $pluginData = '';
  304. foreach ($data as $rec) {
  305. if (!file_exists($mosConfig_absolute_path.'/administrator/components/'.$option.'/plugins/'.$rec->filename)) continue;
  306. $obj = require_once($mosConfig_absolute_path.'/administrator/components/'.$option.'/plugins/'.$rec->filename);
  307. if (method_exists($obj, 'processMessageEdit')) {
  308. $pluginData .= $obj->processMessageEdit($row->messageid, $rec->pluginid, $option);
  309. }
  310. } // foreach()
  311. switch ($task) {
  312. case 'sendmessage':
  313. sendMessage($row->messageid, $option, $task);
  314. break;
  315. case 'applymessage':
  316. mosRedirect('index2.php?option='.$option.'&task=editmessage&hidemainmenu=0&cid[]='.$row->messageid, _EMKTG_MESSAGE_SAVED);
  317. break;
  318. case 'savepreviewmessage':
  319. previewMessage($row->messageid, $option, $task);
  320. break;
  321. case 'savemessage':
  322. default:
  323. mosRedirect('index2.php?option='.$option.'&task=showmessages', _EMKTG_MESSAGE_SAVED);
  324. break;
  325. }
  326. } // saveMessage()
  327. function deleteMessage($ids, $option) {
  328. global $emErrorHandler;
  329. // validate that ids are ok
  330. if (!is_array($ids) or count($ids) < 1) {
  331. $emErrorHandler->addError('(message.admin.php->deleteMessage() line ' . __LINE__ . '):Nothing selected to process', true);
  332. }
  333. // load the table object and perform a delete
  334. $row = new sm2emailmarketingMessage();
  335. foreach ($ids as $id) {
  336. if (!$row->deleteRelated($id)) {
  337. $emErrorHandler->addError($row->getError(), true);
  338. }
  339. if (!$row->delete($id)) {
  340. $emErrorHandler->addError($row->getError(), true);
  341. }
  342. }
  343. mosRedirect('index2.php?option='.$option.'&task=showmessages', _EMKTG_MESSAGE_DELETED);
  344. } // deleteMessage()
  345. function sendMessage($messageid, $option) {
  346. global $database, $mosConfig_absolute_path, $emErrorHandler;
  347. // create an instance of the table class
  348. $row = new sm2emailmarketingMessage();
  349. // attempt to bind the class to the data posted
  350. if (!$row->load($messageid)) {
  351. $emErrorHandler->addError($row->getError(), true);
  352. }
  353. $row->sendMessage($option);
  354. $row->send_date = date('Y-m-d H:i:s');
  355. $row->store();
  356. // insert a record into the overall stats
  357. $database->setQuery('INSERT INTO #__emktg_stats_overall (messageid, html_sent, text_sent, html_read)'
  358. .' VALUES ('.(int)$row->messageid.', 0, 0, 0)');
  359. $database->query();
  360. // send to the queue processing
  361. mosRedirect('index2.php?option='.$option.'&task=processqueue&hidemainmenu=0&cid[]='.$row->messageid);
  362. } // sendMessage()
  363. function getAttachments($name, $active, $javascript=NULL, $directory=NULL) {
  364. global $mosConfig_absolute_path;
  365. if (!$javascript) {
  366. $javascript = 'onchange="javascript:if (document.forms[0].image.options[selectedIndex].value!=\'\') {document.imagelib.src=\'../images/stories/\' + document.forms[0].image.options[selectedIndex].value} else {document.imagelib.src=\'../images/blank.png\'}"';
  367. }
  368. if ( !$directory ) {
  369. $directory = $mosConfig_absolute_path.'/images/stories/';
  370. }
  371. $fileList = array();
  372. $files = mosReadDirectory($directory);
  373. foreach ($files as $file) {
  374. if (is_dir($mosConfig_absolute_path.$directory.'/'.$file)) continue;
  375. $fileList[] = mosHTML::makeOption($file);
  376. }
  377. $size = min(count($fileList), 10);
  378. $files = mosHTML::selectList($fileList, $name, 'class="inputbox" size="'.$size.'" tabindex="8" multiple '/*.$javascript*/, 'value', 'text', $active);
  379. return $files;
  380. } // getAttachments()
  381. function convertArrayToOptions($array) {
  382. $return = array();
  383. if (empty($array)) return $return;
  384. if (!is_array($array)) return $return;
  385. foreach ($array as $index=>$item) {
  386. $return[$index] = mosHTML::makeOption($item);
  387. }
  388. return $return;
  389. } // convertArrayToOptions()
  390. function previewMessage($id, $option) {
  391. global $database, $sm2emailmarketingConfig, $mainframe;
  392. global $mosConfig_absolute_path, $mosConfig_live_site, $mosConfig_fromname, $mosConfig_mailfrom, $mosConfig_list_limit;
  393. sm2emSEF();
  394. // get some data from the request information
  395. $action = mosGetParam($_GET, 'action', 0);
  396. $limitstart = (int)mosGetParam($_GET, 'limitstart', 0 );
  397. // create an instance of the table class
  398. $row = new sm2emailmarketingMessage();
  399. // Load the row from the db table
  400. $row->load($id);
  401. //build message
  402. $row->replaceTags(true);
  403. if (empty($row->fromname)) {
  404. $row->fromname = $sm2emailmarketingConfig->get('fromname', $mosConfig_fromname);
  405. }
  406. if (empty($row->fromemail)) {
  407. $row->fromemail = $sm2emailmarketingConfig->get('fromemail', $mosConfig_mailfrom);
  408. }
  409. if (empty($row->bounceemail)) {
  410. $row->bounceemail = $sm2emailmarketingConfig->get('bounceemail', $mosConfig_mailfrom);
  411. }
  412. if ($row->send_date==0) {
  413. $row->send_date = '';
  414. }
  415. // get the plugins to process
  416. $database->setQuery('SELECT * FROM #__emktg_plugin WHERE enabled=1 ORDER BY ordering');
  417. $plugins = $database->loadObjectList();
  418. // process the plugins
  419. foreach ($plugins as $plugin) {
  420. // load the plugin
  421. if (!file_exists($mosConfig_absolute_path.'/administrator/components/'.$option.'/plugins/'.$plugin->filename)) continue;
  422. require_once($mosConfig_absolute_path.'/administrator/components/'.$option.'/plugins/'.$plugin->filename);
  423. $class = $plugin->classname;
  424. $obj = new $class();
  425. // process the send of the plugin
  426. if (method_exists($obj, 'processMessage')) {
  427. $obj->processMessage($id, $plugin->pluginid, $option, $row, 0);
  428. }
  429. } // foreach()
  430. // load the language elements
  431. $lang = sm2emailmarketingLanguage();
  432. if (!is_array($row->attachments)) $row->attachments = explode(',', $row->attachments);
  433. $attachments = implode('<br />', $row->attachments);
  434. unset($row->attachments);
  435. $row->message_htmlDisplay = $row->message_html.'<br style="clear: both;" /><br /><hr /><strong>Attachments:</strong><br />'.$attachments;
  436. $row->message_textDisplay = nl2br($row->message_text.'<hr /><strong>Attachments:</strong><br />'.$attachments);
  437. sm2emailmarketing_addAbsolutePath($row->message_htmlDisplay);
  438. if ($action!=1) {
  439. // display outside of a iframe
  440. $title = _EMKTG_MESSAGE_PREVIEW;
  441. mosMakeHtmlSafe($row, ENT_QUOTES, array('message_htmlDisplay','message_textDisplay'));
  442. $tmpl = sm2emailmarketingPatTemplate('message.tpl', $option);
  443. $tmpl->addVar('header', 'FORM_NAME', $title);
  444. $tmpl->addObject('preview', $sm2emailmarketingConfig->toObject(), 'CONFIG_');
  445. $tmpl->addObject('preview', $lang, 'LANG');
  446. $tmpl->addObject('preview', $row, 'ROW_');
  447. $tmpl->addVar('preview', 'action', $action);
  448. }
  449. switch ($action) {
  450. case 1:
  451. echo $row->message_htmlDisplay;
  452. break;
  453. case 2:
  454. $tmpl->addVar('preview', 'tab2active', ' activeTab');
  455. $tmpl->addVar('preview', 'TEXT_MESSAGE', $row->message_textDisplay);
  456. break;
  457. case 3:
  458. $tmpl->addVar('preview', 'tab3active', ' activeTab');
  459. // if (empty($limitstart)) {
  460. // precess the send message
  461. $row->sendMessage($option, true);
  462. // }
  463. $sessionSuffix = determineSessionTableSuffix();
  464. // get the data in the queue
  465. $database->setQuery('SELECT COUNT(*)'
  466. .' FROM #__emktg_stats_message'.$sessionSuffix
  467. .' WHERE `html`=1');
  468. $totalHTML = $database->loadResult();
  469. $database->setQuery('SELECT COUNT(*)'
  470. .' FROM #__emktg_stats_message'.$sessionSuffix
  471. .' WHERE `html`=0');
  472. $totalText = $database->loadResult();
  473. $total = max($totalHTML, $totalText);
  474. $totalAll = $totalHTML + $totalText;
  475. // handle the page navigation
  476. if (defined('_JLEGACY')) {
  477. $tempClientId = $mainframe->_clientId;
  478. $mainframe->_clientId = 0;
  479. }
  480. include_once($mosConfig_absolute_path.'/administrator/includes/pageNavigation.php');
  481. $pageNav = new mosPageNav($total, $limitstart, _EMKTG_MESSAGE_PREVIEW_PAGE);
  482. $link = 'administrator/index2.php?option='.$option
  483. .'&task=previewmessage&action=3&cid[]='.(int)$id;
  484. if (defined('_JLEGACY')) {
  485. $app = &JFactory::getApplication();
  486. $router = &$app->getRouter();
  487. $router->setVars(
  488. array(
  489. 'option'=>$option,
  490. 'task'=>'previewmessage',
  491. 'action'=>3,
  492. 'cid[]'=>(int)$id
  493. )
  494. );
  495. }
  496. $tmpl->addVar('preview', 'PREVIEW_TOTAL', $total);
  497. $tmpl->addVar('preview', 'TOTAL_HTML', $totalHTML);
  498. $tmpl->addVar('preview', 'TOTAL_TEXT', $totalText);
  499. $tmpl->addVar('preview', 'TOTAL', $totalAll);
  500. $tmpl->addVar('preview', 'PAGE_LINK', $pageNav->writePagesLinks($link));
  501. if (defined('_JLEGACY')) {
  502. $mainframe->_clientId = $tempClientId;
  503. }
  504. $database->setQuery('SELECT id, name, email, `html`'
  505. .' FROM #__emktg_stats_message'.$sessionSuffix
  506. .' WHERE `html`=1'
  507. .' ORDER BY name, email'
  508. .' LIMIT '.(int)$pageNav->limitstart.', '.(int)$pageNav->limit);
  509. $html = $database->loadObjectList();
  510. if (is_array($html)) {
  511. foreach ($html as $rec) {
  512. $tmpl->addObject('html', $rec, 'HTML_');
  513. $tmpl->parseTemplate('html', 'a');
  514. }
  515. }
  516. $database->setQuery('SELECT id, name, email, `html`'
  517. .' FROM #__emktg_stats_message'.$sessionSuffix
  518. .' WHERE `html`=0'
  519. .' ORDER BY name, email'
  520. .' LIMIT '.(int)$pageNav->limitstart.', '.(int)$pageNav->limit);
  521. $text = $database->loadObjectList();
  522. if (is_array($text)) {
  523. foreach ($text as $rec) {
  524. $tmpl->addObject('text', $rec, 'TEXT_');
  525. $tmpl->parseTemplate('text', 'a');
  526. }
  527. }
  528. break;
  529. default:
  530. $tmpl->addVar('preview', 'tab0active', ' activeTab');
  531. break;
  532. }
  533. if ($action!=1)
  534. $tmpl->displayParsedTemplate('preview');
  535. } // previewMessage()
  536. function sendtestMessage($id, $option) {
  537. global $mosConfig_absolute_path, $sm2emailmarketingConfig, $mosConfig_fromname, $mosConfig_mailfrom, $_VERSION;
  538. global $database;
  539. sm2emSEF();
  540. $msg = '';
  541. $name = mosGetParam($_POST, 'testname', '');
  542. $email = mosGetParam($_POST, 'testemail', '');
  543. $use_html = mosGetParam($_POST, 'testhtml', 0);
  544. $emailaddresses = array();
  545. $path = $sm2emailmarketingConfig->get('attachment_path', $mosConfig_absolute_path.'/images/stories/');
  546. // determine what to set the memory limit to - if at all
  547. $currentMemoryLimit = (int)ini_get('memory_limit');
  548. $memoryLimit = (int)$sm2emailmarketingConfig->get('process_memory', 0);
  549. if ($memoryLimit) {
  550. if ($memoryLimit < $currentMemoryLimit) $memoryLimit += $currentMemoryLimit;
  551. ini_set('memory_limit', $memoryLimit.'M');
  552. }
  553. //build base message (without personalisation such as name etc)
  554. // create an instance of the table class
  555. $row = new sm2emailmarketingMessage();
  556. // Load the row from the db table
  557. $row->load($id);
  558. // validate from information
  559. if (empty($row->fromname)) {
  560. $row->fromname = $sm2emailmarketingConfig->get('fromname', '');
  561. }
  562. if (empty($row->fromemail)) {
  563. $row->fromemail = $sm2emailmarketingConfig->get('fromemail', '');
  564. }
  565. if (empty($row->bounceemail)) {
  566. $row->bounceemail = $sm2emailmarketingConfig->get('bounceemail', '');
  567. }
  568. //use Joomla! class to send mail
  569. $mail = mosCreateMail($row->fromemail, $row->fromname, $row->subject, '');
  570. // identify that we are sending and what the messageid is
  571. $mail->addCustomHeader('X-Mailer: SM2 Email Marketing');
  572. $mail->addCustomHeader('X-SM2MessageID: '.$row->messageid);
  573. // stop auto responders apparently
  574. $mail->addCustomHeader('Precedence: bulk');
  575. if (!empty($row->bounceemail)) {
  576. $mail->Sender = $row->bounceemail;
  577. }
  578. //error checking
  579. if (!$name) {
  580. $name = $sm2emailmarketingConfig->get('fromname', $mosConfig_fromname);
  581. }
  582. if (!$email) {
  583. $email = $sm2emailmarketingConfig->get('fromemail', $mosConfig_mailfrom);
  584. $emailaddresses = explode(',', $email);
  585. } else {
  586. $emailaddresses = explode(',', $email);
  587. }
  588. if (count($emailaddresses) > 10) {
  589. $emailaddresses = array_slice($emailaddresses, 0, 10);
  590. }
  591. // if demo and admin only allow sending 1 message at a time
  592. if (empty($_VERSION->SITE)) {
  593. $emailaddresses = array($emailaddresses[0]);
  594. // check to see how long since last message sent
  595. $lastSend = mosGetParam($_COOKIE, 'sm2em_restricted_send', 0);
  596. if ($lastSend > (time() - _EMKTG_LICENCE_DEMO_RESTRICT_SEC)) {
  597. mosRedirect('index2.php?option='.$option.'&amp;task=previewmessage&amp;cid[]='.$id, _EMKTG_LICENCE_DEMO_RESTRICT_SEC_WARNING);
  598. return;
  599. }
  600. setcookie('sm2em_restricted_send', time());
  601. }
  602. //build message
  603. $row->replaceTags();
  604. // get the plugins to process
  605. $database->setQuery('SELECT * FROM #__emktg_plugin WHERE enabled=1 ORDER BY ordering');
  606. $plugins = $database->loadObjectList();
  607. // process the plugins
  608. foreach ($plugins as $plugin) {
  609. // load the plugin
  610. if (!file_exists($mosConfig_absolute_path.'/administrator/components/'.$option.'/plugins/'.$plugin->filename)) continue;
  611. require_once($mosConfig_absolute_path.'/administrator/components/'.$option.'/plugins/'.$plugin->filename);
  612. $class = $plugin->classname;
  613. $obj = new $class();
  614. // process the send of the plugin
  615. if (method_exists($obj, 'processMessage')) {
  616. $obj->processMessage($id, $plugin->pluginid, $option, $row, 0);
  617. }
  618. } // foreach()
  619. //end build base message
  620. //send test message using the global configuration to determine delivery method
  621. foreach($emailaddresses as $email) {
  622. $thisrow = $row;
  623. //personalise the message
  624. $thisrow->replaceUserInfo($name,$email); //message is all set for sending
  625. sm2emailmarketing_addAbsolutePath($thisrow->message_html);
  626. $mail->addCustomHeader('X-SM2Recipient: '.$email);
  627. $mail->AddAddress($email, $name);
  628. $mail->Subject = $thisrow->subject;
  629. //get the correct format of message
  630. if ($use_html) { //html message to be sent
  631. $mail->IsHTML(true);
  632. $mail->Body = $thisrow->message_html;
  633. $mail->AltBody = $thisrow->message_text;
  634. } else { //plain text to be sent
  635. $mail->IsHTML(false);
  636. $mail->Body = $thisrow->message_text;
  637. }
  638. $wordWrap = $sm2emailmarketingConfig->get('word_wrap', 0);
  639. if ($wordWrap) {
  640. // word wrap both bodies
  641. $mail->Body = $mail->WrapText($mail->Body, $wordWrap);
  642. if (!empty($mail->AltBody))
  643. $mail->AltBody = $mail->WrapText($mail->AltBody, $wordWrap);
  644. }
  645. foreach ($thisrow->attachments as $attachment) {
  646. $mail->AddAttachment($attachment, basename($attachment));
  647. }
  648. foreach ($thisrow->embeddedImages as $embed) {
  649. $mail->AddEmbeddedImage($embed->image, $embed->cid, $embed->name, $embed->encoding, $embed->type);
  650. }
  651. //send message
  652. $sendMailOk = $mail->Send();
  653. if (!$sendMailOk) {
  654. mosRedirect('index2.php?option='.$option.'&task=editmessage&hidemainmenu=0&cid[]='.$id, _EMKTG_MESSAGE_TESTERROR.'::'.$mail->ErrorInfo);
  655. exit;
  656. } else {
  657. $msg = _EMKTG_MESSAGE_TESTSENT;
  658. }
  659. $mail->ClearAllRecipients();
  660. // clear the attachments so that they are not added again
  661. $mail->ClearAttachments();
  662. }
  663. //redirect back to the editmessage area of the message
  664. mosRedirect('index2.php?option='.$option.'&task=editmessage&hidemainmenu=0&cid[]='.$id, $msg);
  665. }
  666. function showMessageArchive($id, $option) {
  667. global $database, $sm2emailmarketingConfig;
  668. $action = mosGetParam($_GET, 'action', 0);
  669. $database->setQuery('SELECT * FROM #__emktg_stats_message WHERE id='.(int)$id);
  670. $rec = null;
  671. $database->loadObject($rec);
  672. // validate that this is an object correctly
  673. if (!is_object($rec)) {
  674. mosRedirect('index2.php?option='.$option.'&amp;task=showmessages&amp;hidemainmenu=0', _EMKTG_MESSAGE_ARCHIVE_NONEXISTENT);
  675. return;
  676. }
  677. $rec->send_dateDisplay = mosFormatDate($rec->send_date, _EMKTG_MESSAGE_SENDDATE_FORMAT);
  678. // create an instance of the table class
  679. $row = new sm2emailmarketingMessage();
  680. // Load the row from the db table
  681. $row->load($rec->messageid);
  682. //build message
  683. $row->replaceTags();
  684. $row->replaceUserInfo($rec->name, $rec->email);
  685. unset($row->cache, $row->embeddedImages);
  686. // load the language elements
  687. $lang = sm2emailmarketingLanguage();
  688. if (!is_array($row->attachments)) $row->attachments = explode(',', $row->attachments);
  689. $attachments = implode('<br />', $row->attachments);
  690. unset($row->attachments);
  691. $row->message_htmlDisplay = $row->message_html.'<br style="clear: both;" /><br /><hr /><strong>Attachments:</strong><br />'.$attachments;
  692. $row->message_textDisplay = nl2br($row->message_text.'<hr /><strong>Attachments:</strong><br />'.$attachments);
  693. sm2emailmarketing_addAbsolutePath($row->message_htmlDisplay);
  694. switch ($action) {
  695. case 1:
  696. if ($rec->html) {
  697. echo $row->message_htmlDisplay;
  698. } else {
  699. echo $row->message_textDisplay;
  700. }
  701. break;
  702. default:
  703. // display outside of a iframe
  704. $title = _EMKTG_ARCHIVE_FORM;
  705. //HTML_sm2emailmarketing_Messages::previewMessage($row, $option, $title, $lang);
  706. mosMakeHtmlSafe($row, ENT_QUOTES, array('message_htmlDisplay','message_textDisplay'));
  707. $tmpl = sm2emailmarketingPatTemplate('message.tpl', $option);
  708. $tmpl->addVar('header', 'FORM_NAME', $title);
  709. $tmpl->addObject('archive', $lang, 'LANG');
  710. $tmpl->addObject('archive', $rec, 'REC_');
  711. $tmpl->addObject('archive', $row, 'ROW_');
  712. $tmpl->displayParsedTemplate('archive');
  713. break;
  714. }
  715. } // showMessageArchive()