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

/administrator/components/com_sm2emailmarketing/plugins/user.plugin.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 419 lines | 283 code | 69 blank | 67 comment | 53 complexity | bd9809b632d081a1ff6e5660c8b3fa68 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. // $Id: user.plugin.php,v 1.20 2007/09/24 00:57:31 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. class sm2emailmarketing_plugin_user extends sm2emPluginObj {
  19. var $name = 'SM2 Email Marketing User';
  20. var $filename = 'user.plugin.php';
  21. var $description = 'Allows SM2 Email Marketing to send messages based on Joomla User data';
  22. var $classname = 'sm2emailmarketing_plugin_user';
  23. var $fieldPrefix = 'emktg_user';
  24. /**
  25. * Constructor
  26. */
  27. function sm2emailmarketing_plugin_user() {
  28. } // sm2emailmarketing_plugin_user()
  29. /**
  30. * displayMessageEdit
  31. *
  32. * Method to display the fields on the Message Management form
  33. */
  34. function displayMessageFilters($messageid, $pluginid, $option) {
  35. global $database, $acl;
  36. if (!$this->validatePlugin($pluginid)) return false;
  37. $params = $this->getParams($pluginid);
  38. // get the selected lists
  39. $selected = $this->getMessageData($messageid, $pluginid);
  40. if (isset($selected['gid'])) {
  41. $selected['gid'] = convertArrayToOptions($selected['gid']);
  42. } else {
  43. $selected['gid'] = null;
  44. }
  45. if (!isset($selected['blocked'])) $selected['blocked'] = null;
  46. if (!isset($selected['last_login']['start'])) $selected['last_login']['start'] = null;
  47. if (!isset($selected['last_login']['end'])) $selected['last_login']['end'] = null;
  48. if (!isset($selected['loginStatus'])) $selected['loginStatus'] = null;
  49. $groupTitle = $params->get('group_title', 'User Groups');
  50. if ($params->get('group_description')) {
  51. $groupTitle = '<span class="editlinktip">'.mosToolTip(addslashes($params->get('group_description')), $groupTitle, '', '', $groupTitle, '#', 0).'</span>';
  52. }
  53. $gtree = $acl->get_group_children_tree( null, 'USERS', false );
  54. // add the select all item to the start of the list
  55. $selectAll = mosHTML::makeOption('-1', $params->get('group_select_all', 'Send to All Groups'));
  56. array_unshift($gtree, $selectAll);
  57. // build the user groups list
  58. $lists['gid'] = mosHTML::selectList($gtree, $this->fieldPrefix.'[gid][]', 'class="inputbox" size="10" multiple', 'value', 'text', $selected['gid']);
  59. $blockedTitle = $params->get('blocked_title', 'Blocked Users');
  60. if ($params->get('blocked_description')) {
  61. $blockedTitle = '<span class="editlinktip">'.mosToolTip(addslashes($params->get('blocked_description')), $blockedTitle, '', '', $blockedTitle, '#', 0).'</span>';
  62. }
  63. $blockedOptions = array(
  64. mosHTML::makeOption('', ''),
  65. mosHTML::makeOption('0', _CMN_NO),
  66. mosHTML::makeOption('1', _CMN_YES)
  67. );
  68. $lists['blocked'] = mosHTML::selectList($blockedOptions, $this->fieldPrefix.'[blocked]', 'class="inputbox"', 'value', 'text', $selected['blocked']);
  69. $lastLoginTitle = $params->get('last_login_title', 'Last Login');
  70. if ($params->get('last_login_description')) {
  71. $lastLoginTitle = '<span class="editlinktip">'.mosToolTip(addslashes($params->get('last_login_description')), $lastLoginTitle, '', '', $lastLoginTitle, '#', 0).'</span>';
  72. }
  73. //never logged in
  74. $loginstatus = array(
  75. mosHTML::makeOption('', ''),
  76. mosHTML::makeOption('1', 'Has Logged In Before'),
  77. mosHTML::makeOption('2', 'Has Never Logged In'),
  78. mosHTML::makeOption('3', 'Never Logged In, Resend Login Details')
  79. );
  80. $lists['loginstatus'] = mosHTML::selectList($loginstatus, $this->fieldPrefix.'[loginStatus]', 'class="inputbox"', 'value', 'text', $selected['loginStatus']);
  81. $loginStatusTitle = $params->get('login_status_title', 'Login Status');
  82. // start output buffering
  83. ob_start();
  84. ?>
  85. <tr>
  86. <th colspan="2"><?php echo $params->get('section_title', 'Joomla Users'); ?></th>
  87. </tr>
  88. <tr>
  89. <td colspan="2"><?php echo $params->get('section_description'); ?></td>
  90. </tr>
  91. <?php if ($params->get('groups', 1)) { ?>
  92. <tr>
  93. <td valign="top"><?php echo $groupTitle; ?></td>
  94. <td valign="top"><?php echo $lists['gid']; ?></td>
  95. </tr>
  96. <?php } ?>
  97. <?php if ($params->get('blocked', 1)) { ?>
  98. <tr>
  99. <td valign="top"><?php echo $blockedTitle; ?></td>
  100. <td valign="top"><?php echo $lists['blocked']; ?></td>
  101. </tr>
  102. <?php } ?>
  103. <?php if ($params->get('last_login', 1)) { ?>
  104. <tr>
  105. <td valign="top"><?php echo $lastLoginTitle; ?></td>
  106. <td valign="top">
  107. <table>
  108. <tr>
  109. <td><?php echo $params->get('last_login_from', 'From'); ?></td>
  110. <td>
  111. <input class="text_area" type="text" name="<?php echo $this->fieldPrefix; ?>[last_login][start]" id="<?php echo $this->fieldPrefix; ?>_last_login_start" size="25" maxlength="19" value="<?php echo $selected['last_login']['start']; ?>" />
  112. <input name="reset" type="reset" class="button" onClick="return showCalendar('<?php echo $this->fieldPrefix; ?>_last_login_start', 'y-mm-dd');" value="...">
  113. </td>
  114. </tr>
  115. <tr>
  116. <td><?php echo $params->get('last_login_to', 'To'); ?></td>
  117. <td>
  118. <input class="text_area" type="text" name="<?php echo $this->fieldPrefix; ?>[last_login][end]" id="<?php echo $this->fieldPrefix; ?>_last_login_end" size="25" maxlength="19" value="<?php echo $selected['last_login']['end']; ?>" />
  119. <input name="reset" type="reset" class="button" onClick="return showCalendar('<?php echo $this->fieldPrefix; ?>_last_login_end', 'y-mm-dd');" value="...">
  120. </td>
  121. </tr>
  122. </table>
  123. </td>
  124. </tr>
  125. <tr>
  126. <td valign="top"><?php echo $loginStatusTitle; ?></td>
  127. <td valign="top"><?php echo $lists['loginstatus']; ?></td>
  128. </tr>
  129. <?php } ?>
  130. <tr>
  131. <td colspan="2">&nbsp;</td>
  132. </tr>
  133. <?php
  134. $result = ob_get_contents();
  135. ob_end_clean();
  136. return $result;
  137. } // displayMessageFilters()
  138. /**
  139. * processMessageEdit
  140. *
  141. * Method to process the fields from the Message Management form
  142. * Data is stored in the emktg_message_plugin table
  143. */
  144. function processMessageEdit($messageid, $pluginid, $option) {
  145. global $database;
  146. if (!$this->validatePlugin($pluginid)) return false;
  147. // get the data passed by the form
  148. $data = mosGetParam($_POST, $this->fieldPrefix, array());
  149. if (@is_array($data['gid'])) {
  150. if (in_array(-1, $data['gid'])) {
  151. $data['gid'] = array(-1);
  152. }
  153. }
  154. // see if there is an existing record
  155. sm2emailmarketingSetPluginMessageData($messageid, $pluginid, $data);
  156. } // processMessageEdit
  157. /**
  158. * processSend
  159. *
  160. * Method to process a plugin send
  161. * Retrieves all of the users
  162. * Returns an array of name,email objects
  163. */
  164. function processSend($messageid, $pluginid, $option) {
  165. global $database;
  166. if (!$this->validatePlugin($pluginid)) return false;
  167. $params = $this->getParams($pluginid);
  168. // determine which users to send to
  169. $pluginData = $this->getMessageData($messageid, $pluginid);
  170. if (empty($pluginData)) return false;
  171. $return = false;
  172. // determine the tablename to process into
  173. $tablename = determineQueueProcessTable();
  174. if ($params->get('groups', 1)) {
  175. if (!empty($pluginData['gid'])) {
  176. $where = ' WHERE gid IN ('.implode(',', $pluginData['gid']).')';
  177. if (in_array('-1', $pluginData['gid'])) {
  178. $where = ' WHERE gid != -1';
  179. }
  180. $database->setQuery('INSERT IGNORE INTO '.$tablename
  181. .' (`messageid`, `userid`, `pluginid`, `name`, `email`, `html`)'
  182. .' SELECT '.(int)$messageid.', u.id, '.(int)$pluginid.', u.name, u.email, eu.receive_html'
  183. .' FROM #__users u'
  184. .' INNER JOIN #__emktg_user eu ON eu.id = u.id'
  185. .$where
  186. .' AND eu.confirmed=1 AND eu.unsubscribe_date =0'
  187. .' ORDER BY name');
  188. $database->query();
  189. $return = true;
  190. }
  191. }
  192. if ($params->get('blocked', 1)) {
  193. if (!empty($pluginData['blocked'])) {
  194. $database->setQuery('INSERT IGNORE INTO '.$tablename
  195. .' (`messageid`, `userid`, `pluginid`, `name`, `email`, `html`)'
  196. .' SELECT '.(int)$messageid.', u.id, '.(int)$pluginid.', u.name, u.email, eu.receive_html'
  197. .' FROM #__users u'
  198. .' INNER JOIN #__emktg_user eu ON eu.id = u.id'
  199. .' WHERE block='.$pluginData['blocked']
  200. .' AND eu.confirmed=1 AND eu.unsubscribe_date =0'
  201. .' ORDER BY name');
  202. $database->query();
  203. $return = true;
  204. }
  205. }
  206. if ($params->get('last_login', 1)) {
  207. $start = $pluginData['last_login']['start'];
  208. $end = $pluginData['last_login']['end'];
  209. // determine how to find the data
  210. if (!empty($start) || !empty($end)) {
  211. // fix nevers
  212. if (strtolower($start)=='never') $start = '0000-00-00';
  213. if (strtolower($end)=='never') $end = '0000-00-00';
  214. // fix dates if reversed
  215. if ($end < $start) {
  216. $temp = $start;
  217. $start = $end;
  218. $end = $temp;
  219. }
  220. $where = '';
  221. if ($start==$end) {
  222. $where = ' WHERE (lastvisitDate = '.$database->Quote($start).')';
  223. } else if (empty($start)) {
  224. $where = ' WHERE (lastvisitDate <= '.$database->Quote($end).')';
  225. } else if (empty($end)) {
  226. $where = ' WHERE (lastvisitDate >= '.$database->Quote($start).')';
  227. } else {
  228. $where = ' WHERE (lastvisitDate BETWEEN '
  229. .$database->Quote($start).' AND '
  230. .$database->Quote($end).')';
  231. }
  232. if (!empty($where)) {
  233. $database->setQuery('INSERT IGNORE INTO '.$tablename
  234. .' (`messageid`, `userid`, `pluginid`, `name`, `email`, `html`)'
  235. .' SELECT '.(int)$messageid.', u.id, '.(int)$pluginid.', u.name, u.email, eu.receive_html'
  236. .' from #__users u'
  237. .' INNER JOIN #__emktg_user eu ON eu.id = u.id'
  238. .$where
  239. .' AND eu.confirmed=1 AND eu.unsubscribe_date =0'
  240. .' ORDER BY name');
  241. $database->query();
  242. $return = true;
  243. }
  244. }
  245. }
  246. //login_status
  247. if($params->get('last_login', 1)){
  248. if (!empty($pluginData['loginStatus'])) {
  249. switch ($pluginData['loginStatus']) {
  250. case 1:
  251. $clause = ' `lastvisitDate` > 0';
  252. break;
  253. case 2:
  254. case 3:
  255. $clause = ' `lastvisitDate` = 0 OR `lastvisitDate` IS NULL';
  256. break;
  257. }
  258. $database->setQuery('INSERT IGNORE INTO '.$tablename
  259. .' (`messageid`, `userid`, `pluginid`, `name`, `email`, `html`)'
  260. .' SELECT '.(int)$messageid.', u.id, '.(int)$pluginid.', u.name, u.email, eu.receive_html'
  261. .' from #__users u'
  262. .' INNER JOIN #__emktg_user eu ON eu.id = u.id'
  263. .' WHERE '.$clause
  264. .' AND eu.confirmed=1 AND eu.unsubscribe_date =0'
  265. .' ORDER BY name');
  266. $database->query();
  267. $return = true;
  268. }
  269. }
  270. return $return;
  271. } // processSend()
  272. /**
  273. * processMessage
  274. *
  275. * Method to process a plugin send
  276. * Retrieves all of the users
  277. * Returns an array of name,email objects
  278. */
  279. function processMessage($messageid, $pluginid, $option, &$row, $userid) {
  280. global $database;
  281. $params = $this->getParams($pluginid);
  282. // determine which users to send to
  283. $pluginData = $this->getMessageData($messageid, $pluginid);
  284. if (empty($pluginData)) {
  285. //remove [DETAILS] tag - because option to send the details was not chosen
  286. $row->message_html = str_replace('[DETAILS]', '', $row->message_html);
  287. $row->message_text = str_replace('[DETAILS]', '', $row->message_text);
  288. return;
  289. }
  290. if($params->get('last_login', 1)){
  291. if (!empty($pluginData['loginStatus'])) {
  292. if ($pluginData['loginStatus']==3) {
  293. // check to see if details is there
  294. if (strpos($row->message_html, '[DETAILS]')===false) {
  295. $row->message_html .= '[DETAILS]';
  296. }
  297. if (strpos($row->message_text, '[DETAILS]')===false) {
  298. $row->message_text .= '[DETAILS]';
  299. }
  300. $logindetails = '';
  301. if (!empty($userid)) {
  302. // load the user information
  303. $user = new mosUser($database);
  304. $user->load($userid);
  305. if ($user->lastvisitDate=='0000-00-00 00:00:00') {
  306. // generate the password
  307. $pwd='';
  308. $pwd = mosMakePassword();
  309. // update the database
  310. $user->password = md5($pwd);
  311. $user->store();
  312. // create the details data
  313. // need to load client management config to decide
  314. // whether using email or username as login
  315. $userLoginType = $this->userLoginType();
  316. if ($userLoginType) { //use email
  317. $logindetails = 'Email Login: '.$user->email.'<br />Password: '.$pwd.'<br />';
  318. } else { //use username
  319. $logindetails = 'Username: '.$user->username.'<br />Password: '.$pwd.'<br />';
  320. }
  321. }
  322. }
  323. // replace in row data
  324. $row->message_html = str_replace('[DETAILS]', $logindetails, $row->message_html);
  325. $row->message_text = str_replace('[DETAILS]', $logindetails, $row->message_text);
  326. }
  327. }
  328. }
  329. //remove [DETAILS] tag - because option to send the details was not chosen
  330. $row->message_html = str_replace('[DETAILS]', '', $row->message_html);
  331. $row->message_text = str_replace('[DETAILS]', '', $row->message_text);
  332. } // processMessage()
  333. function userLoginType() {
  334. global $mosConfig_absolute_path;
  335. if(file_exists($mosConfig_absolute_path.'/administrator/components/com_member/member_config.php')){
  336. global $sm2CMConfig;
  337. include_once($mosConfig_absolute_path.'/administrator/components/com_member/member_config.php');
  338. if(!empty ($sm2CMConfig['email_login'])){
  339. return true;
  340. } else {
  341. return false;
  342. }
  343. } else {
  344. return false;
  345. }
  346. }
  347. } // class sm2emailmarketing_plugin_user
  348. $obj = new sm2emailmarketing_plugin_user();
  349. return $obj;
  350. ?>