BxMassMailerModule.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup MassMailer Mass Mailer
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxMassMailerModule extends BxBaseModGeneralModule
  12. {
  13. private $aSegments = array();
  14. function __construct(&$aModule)
  15. {
  16. parent::__construct($aModule);
  17. $CNF = &$this->_oConfig->CNF;
  18. $aRv = array('lvl:0' => _t('_bx_massmailer_segments_all'));
  19. $oAccountQuery = BxDolAclQuery::getInstance();
  20. $aTmp = array();
  21. $oAccountQuery->getLevels(array('type' => 'all_active_pair'), $aTmp);
  22. foreach ($aTmp as $sKey => $sTmp){
  23. if ($sKey != MEMBERSHIP_ID_NON_MEMBER && $sKey != MEMBERSHIP_ID_ACCOUNT)
  24. $aRv['lvl:' . $sKey] = _t($sTmp);
  25. };
  26. $aTmp = $this->_oDb->getSegments();
  27. foreach ($aTmp as $sKey => $sTmp){
  28. $aRv['cst:' . $sKey] = _t($sTmp);
  29. };
  30. $this->aSegments = $aRv;
  31. }
  32. /**
  33. * ACTION METHODS
  34. */
  35. public function actionTrack($sActionName, $sHash)
  36. {
  37. if (isset($sHash) && trim($sHash) != ""){
  38. switch ($sActionName) {
  39. case 'click':
  40. $sLink = $this->_oDb->updateDateClickForLink($sHash);
  41. if (substr_count($sLink, '://') == 0)
  42. $sLink = BX_DOL_URL_ROOT . $sLink;
  43. header('Location: ' . $sLink);
  44. break;
  45. case 'seen':
  46. header('Content-Type: image/png');
  47. $this->_oDb->updateDateSeenForLetter($sHash);
  48. break;
  49. }
  50. }
  51. }
  52. public function actionGetReportsData($sReportName, $sReportType, $sDateFrom, $sDateTo, $sSegment)
  53. {
  54. if(!BxDolAcl::getInstance()->isMemberLevelInSet(128))
  55. return '';
  56. header('Content-Type: application/json');
  57. $aColors = array('#3366CC', '#DC3912', '#FF9900', '#109618', '#990099');
  58. $iDateFrom = strtotime($sDateFrom);
  59. $iDateTo = strtotime($sDateTo);
  60. $sType = "bar";
  61. $bIsTimeX = false;
  62. $iMinValueY = 0;
  63. $iMaxValueY = 0;
  64. $aValues = array('labels' => array(), 'values' => array(array('legend' => '', 'data' => array())), 'links' => array(), 'strings' => array(0 => _t('_bx_massmailer_txt_item'), 1 => _t('_bx_massmailer_txt_value')));
  65. switch ($sReportName) {
  66. case "SUBSCRIBERS_INFO":
  67. $sType = "line";
  68. $bIsTimeX = true;
  69. $aValues['strings'][0] = _t('_bx_massmailer_txt_date');
  70. $aValues['strings'][1] = '';
  71. $sSql = $this->getSqlBySegment($sSegment);
  72. $aData = $this->_oDb->getAccountsByTermsStat($iDateFrom, $iDateTo, $sSql);
  73. $aData2 = $this->_oDb->getAccountsByTermsStatUnsubscribe($iDateFrom, $iDateTo, $sSql);
  74. $iValuePrev = $this->_oDb->getAccountsByTermsStatInitValue($iDateFrom, $sSql);
  75. $iValuePrev2 = $this->_oDb->getAccountsByTermsStatInitValueUnsubscribe($iDateFrom, $sSql);
  76. $aTmpDates = array();
  77. $aTmpDates2 = array();
  78. $aValues['values'][0]['legend'] = _t('_bx_massmailer_txt_subscribed');
  79. $aValues['values'][1] = array('legend' => _t('_bx_massmailer_txt_unsubscribed') , 'data' => array());
  80. foreach ($aData as $aValue) {
  81. $aTmpDates[$aValue['period']] = $aValue['count'];
  82. }
  83. foreach ($aData2 as $aValue) {
  84. $aTmpDates2[$aValue['period']] = $aValue['count'];
  85. }
  86. for ($i = $iDateFrom; $i < $iDateTo ; $i = $i + 86400 ){
  87. $sX = date('Y-m-d', $i);
  88. if (!array_key_exists($sX, $aTmpDates)){
  89. array_push($aValues['values'][0]['data'], array('x' => $sX, 'y' => $sReportType == 'content_total' ? $iValuePrev : 0));
  90. }
  91. else{
  92. array_push($aValues['values'][0]['data'], array('x' => $sX, 'y' => $sReportType == 'content_total' ? $iValuePrev : $aTmpDates[$sX]));
  93. $iValuePrev += $aTmpDates[$sX];
  94. }
  95. if (!array_key_exists($sX, $aTmpDates2)){
  96. array_push($aValues['values'][1]['data'], array('x' => $sX, 'y' => $sReportType == 'content_total' ? $iValuePrev2 : 0));
  97. }
  98. else{
  99. array_push($aValues['values'][1]['data'], array('x' => $sX, 'y' => $sReportType == 'content_total' ? $iValuePrev2 : $aTmpDates2[$sX]));
  100. $iValuePrev2 += $aTmpDates2[$sX];
  101. }
  102. if ($sReportType == 'content_total'){
  103. if ($iValuePrev > $iMaxValueY)
  104. $iMaxValueY = $iValuePrev;
  105. if ($iValuePrev2 > $iMaxValueY)
  106. $iMaxValueY = $iValuePrev2;
  107. }
  108. else{
  109. if (array_key_exists($sX, $aTmpDates) && $aTmpDates[$sX] > $iMaxValueY)
  110. $iMaxValueY = $aTmpDates[$sX];
  111. if (array_key_exists($sX, $aTmpDates2) && $aTmpDates2[$sX] > $iMaxValueY)
  112. $iMaxValueY = $aTmpDates2[$sX];
  113. }
  114. }
  115. break;
  116. case "CAMPAIGN_REPORT":
  117. $aDataStat = $this->_oDb->getStatByCampaignId($sReportType);
  118. $aValues['values'][0]['legend'] = _t('_bx_massmailer_txt_sent_total_title', $aDataStat['total']);
  119. array_push($aValues['values'][0]['data'], $aDataStat['total']);
  120. $aValues['values'][1] = array('legend' => _t('_bx_massmailer_txt_opened_total_title', $aDataStat['seen']) , 'data' => array($aDataStat['seen']));
  121. $aValues['values'][2] = array('legend' => _t('_bx_massmailer_txt_unopened_total_title', $aDataStat['total'] - $aDataStat['seen']), 'data' => array($aDataStat['total'] - $aDataStat['seen']));
  122. $aValues['values'][3] = array('legend' => _t('_bx_massmailer_txt_clicked_total_title', $aDataStat['clicked']), 'data' => array($aDataStat['clicked']));
  123. $aValues['values'][4] = array('legend' => _t('_bx_massmailer_txt_unsubscribed_total_title', $aDataStat['unsubscribed']), 'data' => array($aDataStat['unsubscribed']));
  124. $iMaxValueY = $aDataStat['total'];
  125. break;
  126. }
  127. $iMaxValueY = ceil($iMaxValueY * 1.1);
  128. $aDataForChartXAxes = array();
  129. if ($bIsTimeX){
  130. $sUnit = 'day';
  131. $iInterval = ($iDateTo - $iDateFrom) / 86400;
  132. if ($iInterval > 50)
  133. $sUnit = 'week';
  134. if ($iInterval > 100)
  135. $sUnit = 'month';
  136. $aDataForChartXAxes = array(
  137. 'type' => 'time',
  138. 'time' => array(
  139. 'tooltipFormat' => 'DD.MM.YYYY',
  140. 'unit' => $sUnit,
  141. ),
  142. 'display' => true,
  143. 'distribution' => 'linear',
  144. 'ticks' => array(
  145. 'display' => true,
  146. 'autoSkip' => true,
  147. )
  148. );
  149. }
  150. else{
  151. $aDataForChartXAxes = array(
  152. 'ticks' => array(
  153. 'autoSkip' => false
  154. ),
  155. 'display' => true
  156. );
  157. }
  158. $aDataForChartDatasets = array();
  159. for($i = 0; $i < count($aValues['values']); $i++){
  160. $aDataForChartDatasets[] = array(
  161. 'label' => $aValues['values'][$i]['legend'],
  162. 'fill' => false,
  163. 'backgroundColor' => $aColors[$i],
  164. 'borderColor' => $aColors[$i],
  165. 'borderWidth' => 1,
  166. 'data' => $aValues['values'][$i]['data']
  167. );
  168. }
  169. $aDataForChart = array(
  170. 'type' => $sType,
  171. 'data' => array(
  172. 'labels' => $aValues['labels'],
  173. 'datasets' => $aDataForChartDatasets
  174. ),
  175. 'options' => array(
  176. 'legend' => array(
  177. 'position' => 'bottom',
  178. 'display' => count($aValues['values']) == 1 ? false : true
  179. ),
  180. 'scales' => array(
  181. 'yAxes' => array(
  182. array(
  183. 'ticks' => array(
  184. 'max' => $iMaxValueY,
  185. 'min' => $iMinValueY,
  186. 'stepSize' => $this->getReportStep($iMinValueY, $iMaxValueY),
  187. 'autoSkip' => true
  188. )
  189. )
  190. ),
  191. 'xAxes' => array($aDataForChartXAxes)
  192. )
  193. ),
  194. 'links' => $aValues['links'],
  195. 'strings' => $aValues['strings'],
  196. );
  197. echo json_encode($aDataForChart);
  198. }
  199. /**
  200. * SERVICE METHODS
  201. */
  202. /**
  203. * @page service Service Calls
  204. * @section bx_massmailer Mass mailer
  205. * @subsection bx_massmailer-page_blocks Page Blocks
  206. * @subsubsection bx_massmailer-campagn_subscribers campagn_subscribers
  207. *
  208. * @code bx_srv('bx_massmailer', 'campagn_subscribers', [...]); @endcode
  209. *
  210. * Get page block with the campagn's subscribers list
  211. *
  212. * @param $aParams an array with search params.
  213. * @return HTML string with block content to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  214. *
  215. * @see BxMassMailerModule::serviceCampagnSubscribers
  216. */
  217. /**
  218. * @ref bx_massmailer-campagn_subscribers "entity_view"
  219. */
  220. public function serviceCampagnSubscribers ($iContentId = 0, $sDisplay = false)
  221. {
  222. if(!$iContentId)
  223. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  224. if(!$iContentId)
  225. return false;
  226. $aData = $this->_oDb->getLettersByCampaignId($iContentId);
  227. if (count($aData) > 0)
  228. return $this->_oTemplate->getSubscribers($aData);
  229. return $iContentId;
  230. }
  231. /**
  232. * @page service Service Calls
  233. * @section bx_massmailer Mass mailer
  234. * @subsection bx_massmailer-page_blocks Page Blocks
  235. * @subsubsection bx_massmailer-campagn_info campagn_info
  236. *
  237. * @code bx_srv('bx_massmailer', 'campagn_info', [...]); @endcode
  238. *
  239. * Get page block with the campagn info
  240. *
  241. * @param $aParams an array with search params.
  242. * @return HTML string with block content to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  243. *
  244. * @see BxMassMailerModule::serviceCampagnInfo
  245. */
  246. /**
  247. * @ref bx_massmailer-campagn_info "campagn_info"
  248. */
  249. public function serviceCampagnInfo ($iContentId = 0, $sDisplay = false)
  250. {
  251. if(!$iContentId)
  252. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  253. if(!$iContentId)
  254. return false;
  255. return $this->_oTemplate->getInfo($iContentId);
  256. }
  257. /**
  258. * @page service Service Calls
  259. * @section bx_massmailer Mass mailer
  260. * @subsection bx_massmailer-page_blocks Page Blocks
  261. * @subsubsection bx_massmailer-campagn_links campagn_links
  262. *
  263. * @code bx_srv('bx_massmailer', 'campagn_links', [...]); @endcode
  264. *
  265. * Get page block with the campagn links list
  266. *
  267. * @param $aParams an array with search params.
  268. * @return HTML string with block content to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  269. *
  270. * @see BxMassMailerModule::serviceCampagnLinks
  271. */
  272. /**
  273. * @ref bx_massmailer-campagn_links "campagn_links"
  274. */
  275. public function serviceCampagnLinks ($iContentId = 0, $sDisplay = false)
  276. {
  277. if(!$iContentId)
  278. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  279. if(!$iContentId)
  280. return false;
  281. $aData = $this->_oDb->getClicksByCampaignId($iContentId);
  282. if (count($aData) > 0)
  283. return $this->_oTemplate->getClicks($aData);
  284. return $iContentId;
  285. }
  286. /**
  287. * @page service Service Calls
  288. * @section bx_massmailer Mass mailer
  289. * @subsection bx_massmailer-page_blocks Page Blocks
  290. * @subsubsection bx_massmailer-total_subscribers total_subscribers
  291. *
  292. * @code bx_srv('bx_massmailer', 'total_subscribers', [...]); @endcode
  293. *
  294. * Get page block with subscribers charts
  295. *
  296. * @param $aParams an array with search params.
  297. * @return HTML string with block content to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  298. *
  299. * @see BxMassMailerModule::serviceTotalSubscribers
  300. */
  301. /**
  302. * @ref bx_massmailer-total_subscribers "total_subscribers"
  303. */
  304. public function serviceTotalSubscribers ()
  305. {
  306. return $this->_oTemplate->getTotalSubscribers();
  307. }
  308. /**
  309. * @page service Service Calls
  310. * @section bx_massmailer Mass mailer
  311. * @subsection bx_massmailer-page_blocks Page Blocks
  312. * @subsubsection bx_massmailer-entity_breadcrumb entity_breadcrumb
  313. *
  314. * @code bx_srv('bx_massmailer', 'entity_breadcrumb', [...]); @endcode
  315. *
  316. * Get page block with page's breadcrumbs
  317. *
  318. * @param $aParams an array with search params.
  319. * @return HTML string with block content to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  320. *
  321. * @see BxMassMailerModule::serviceEntityBreadcrumb
  322. */
  323. /**
  324. * @ref bx_massmailer-entity_breadcrumb "entity_breadcrumb"
  325. */
  326. public function serviceEntityBreadcrumb ($iContentId = 0)
  327. {
  328. $CNF = &$this->_oConfig->CNF;
  329. $oPermalink = BxDolPermalinks::getInstance();
  330. if (!$iContentId)
  331. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  332. if (!$iContentId){
  333. $aContentInfo[$CNF['FIELD_TITLE']] = _t('_bx_massmailer_txt_breadcrumb_title_new_campaign');
  334. $aContentInfo['url'] = $oPermalink->permalink('page.php?i=' . $CNF['URI_ADD_CAMPAIGN']);
  335. }
  336. else{
  337. $aContentInfo = $this->_oDb->getCampaignInfoById($iContentId);
  338. if (!$aContentInfo)
  339. return false;
  340. $aContentInfo['url'] = $oPermalink->permalink('page.php?i=' . $CNF['URI_VIEW_CAMPAIGN'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  341. }
  342. return $this->_oTemplate->entryBreadcrumb($aContentInfo);
  343. }
  344. /**
  345. * @page service Service Calls
  346. * @section bx_massmailer Mass mailer
  347. * @subsection bx_massmailer-page_blocks Page Blocks
  348. * @subsubsection bx_massmailer-attributes attributes
  349. *
  350. * @code bx_srv('bx_massmailer', 'attributes', [...]); @endcode
  351. *
  352. * Get page block with attributes list
  353. *
  354. * @param $aParams an array with search params.
  355. * @return HTML string with block content to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  356. *
  357. * @see BxMassMailerModule::serviceAttributes
  358. */
  359. /**
  360. * @ref bx_massmailer-attributes "attributes"
  361. */
  362. public function serviceAttributes ()
  363. {
  364. $aAttributesParts = array();
  365. $aAttributesParts['account'] = array(_t('_bx_massmailer_txt_attribute_global'), array('email' => _t('_bx_massmailer_txt_attribute_email'), 'account_name' => _t('_bx_massmailer_txt_attribute_account_name'), 'account_id' => _t('_bx_massmailer_txt_attribute_account_id'), 'unsubscribe_url' => _t('_bx_massmailer_txt_attribute_unsubscribe_url')));
  366. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  367. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  368. foreach($aModules as $aModule){
  369. if(BxDolRequest::serviceExists($aModule['name'], 'act_as_profile') && BxDolService::call($aModule['name'], 'act_as_profile') == true){
  370. $oModule = BxDolModule::getInstance($aModule['name']);
  371. $aTmp2 = array();
  372. $aTmp = $oModule->serviceGetSearchableFieldsExtended('view');
  373. foreach($aTmp as $sKey => $aField){
  374. $aTmp2[$sKey] = _t($aField['caption']);
  375. }
  376. $aAttributesParts[$aModule['name']] = array($aModule['title'], $aTmp2);
  377. }
  378. }
  379. return $this->_oTemplate->getAttributes($aAttributesParts);
  380. }
  381. /**
  382. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  383. */
  384. public function checkAllowedAdd ($isPerformAction = false)
  385. {
  386. return $this->checkAllowed($isPerformAction);
  387. }
  388. /**
  389. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  390. */
  391. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  392. {
  393. return $this->checkAllowed($isPerformAction);
  394. }
  395. /**
  396. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  397. */
  398. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  399. {
  400. return $this->checkAllowed($isPerformAction);
  401. }
  402. public function getSegments($sKey = "")
  403. {
  404. if ($sKey == ""){
  405. return $this->aSegments;
  406. }
  407. else{
  408. if (isset($this->aSegments[$sKey]))
  409. return $this->aSegments[$sKey];
  410. return false;
  411. }
  412. }
  413. public function sendTest($sEmail, $iCampaignId)
  414. {
  415. $aTmp = $this->getDataForCampaign($iCampaignId);
  416. $aTemplate = $aTmp[0];
  417. $aCustomHeaders = $aTmp[1];
  418. if (!$aTemplate)
  419. return false;
  420. return $this->sendLetter($sEmail, $iCampaignId, $aCustomHeaders, bx_get_logged_profile_id(), $aTemplate, false);
  421. }
  422. public function sendAll($iCampaignId)
  423. {
  424. $aEmails = array();
  425. $aTmp = $this->getDataForCampaign($iCampaignId);
  426. $aTemplate = $aTmp[0];
  427. $aCustomHeaders = $aTmp[1];
  428. $aCampaign = $aTmp[2];
  429. if (!$aTemplate)
  430. return false;
  431. $this->_oDb->deleteCampaignData($iCampaignId);
  432. $aAccounts = $this->getEmailsBySegment($aCampaign['segments']);
  433. foreach ($aAccounts as $aAccountInfo){
  434. array_push($aEmails, $aAccountInfo['email']);
  435. $this->sendLetter($aAccountInfo['email'], $iCampaignId, $aCustomHeaders, $aAccountInfo['profile_id'], $aTemplate, true);
  436. }
  437. $this->_oDb->sendCampaign($iCampaignId, implode(',', $aEmails));
  438. return true;
  439. }
  440. private function sendLetter($sEmail, $iCampaignId, $aCustomHeaders, $iProfileId, $aTemplate, $bAddToQueue)
  441. {
  442. $sLetterCode = $this->_oDb->addLetter($iCampaignId, $sEmail);
  443. $regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
  444. $aTemplate['Body'] = preg_replace_callback("/$regexp/siU",
  445. function ($aMatch) use ($iCampaignId, $sLetterCode) {
  446. if ($aMatch[2] != '{unsubscribe_url}'){
  447. $sLinkCode = $this->_oDb->addLink($sLetterCode, $aMatch[2], $aMatch[3], $iCampaignId);
  448. return str_replace($aMatch[2], BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'track/click/' . $sLinkCode . "/", $aMatch[0]);
  449. }
  450. else{
  451. return $aMatch[0];
  452. }
  453. },
  454. $aTemplate['Body']);
  455. return sendMail($sEmail, $aTemplate['Subject'], $aTemplate['Body'], 0, $this->addMarkers($iProfileId, $sLetterCode), BX_EMAIL_MASS, 'html', false, $aCustomHeaders, $bAddToQueue);
  456. }
  457. public function getEmailCountInSegment($iCampaignId)
  458. {
  459. $aTmp = $this->getDataForCampaign($iCampaignId);
  460. $aCampaign = $aTmp[2];
  461. $aAccounts = $this->getEmailsBySegment($aCampaign['segments']);
  462. return count($aAccounts);
  463. }
  464. private function getEmailsBySegment($sSegment)
  465. {
  466. return $this->_oDb->getAccountsByTerms($this->getSqlBySegment($sSegment));
  467. }
  468. private function checkAllowed($isPerformAction = false)
  469. {
  470. $aCheck = checkActionModule($this->_iProfileId, 'use massmailer', $this->getName(), $isPerformAction);
  471. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  472. return _t('_sys_txt_access_denied');
  473. return CHECK_ACTION_RESULT_ALLOWED;
  474. }
  475. private function getSqlBySegment($sSegment)
  476. {
  477. $sRv = '';
  478. if (substr_count($sSegment, 'lvl:') > 0){
  479. $sLvl = str_replace('lvl:', '', $sSegment);
  480. switch ($sLvl) {
  481. case 0:
  482. $sRv = '';
  483. break;
  484. case MEMBERSHIP_ID_UNCONFIRMED:
  485. $sRv = " AND `ta`.`email_confirmed` = 0 AND `ta`.`phone_confirmed` = 0 ";
  486. break;
  487. case MEMBERSHIP_ID_SUSPENDED:
  488. $sRv = " AND `tp`.`status` = 'suspended' ";
  489. break;
  490. case MEMBERSHIP_ID_PENDING:
  491. $sRv = " AND `tp`.`status` = 'pending' ";
  492. break;
  493. case MEMBERSHIP_ID_STANDARD:
  494. $sRv = " AND `tp`.`id` NOT IN (SELECT `IDMember` FROM `sys_acl_levels_members`) ";
  495. break;
  496. default:
  497. $sRv = $this->_oDb->prepareAsString(" AND `tp`.`id` IN (SELECT `IDMember` FROM `sys_acl_levels_members` WHERE IDLevel = ?) ", $sLvl);
  498. break;
  499. }
  500. $sRv .= " AND `tp`.`type` IN ('" . implode("','", $this->getProfileModules()) . "')";
  501. }
  502. return $sRv;
  503. }
  504. private function getProfileModules()
  505. {
  506. $aResult = array();
  507. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  508. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  509. foreach($aModules as $aModule){
  510. if(BxDolRequest::serviceExists($aModule['name'], 'act_as_profile') && BxDolService::call($aModule['name'], 'act_as_profile') == true){
  511. array_push($aResult, $aModule['name']);
  512. }
  513. }
  514. return $aResult;
  515. }
  516. private function getDataForCampaign($iCampaignId)
  517. {
  518. $aCampaign = $this->_oDb->getCampaignInfoById($iCampaignId);
  519. $oEmailTemplates = BxDolEmailTemplates::getInstance();
  520. $aTemplate = $oEmailTemplates->parseTemplate('bx_massmailer_email', array('content' => $aCampaign['body']));
  521. $aTemplate['Subject'] = $aCampaign['subject'];
  522. $aCustomHeaders = array();
  523. $sFrom = $aCampaign['from_name'] != '' ? $aCampaign['from_name'] : getParam('bx_massmailer_initial_from_email');
  524. $aCustomHeaders['From'] = "=?UTF-8?B?" . base64_encode($sFrom) . "?= <" . getParam('site_email_notify') . ">" ;
  525. if ($aCampaign['reply_to'] != ''){
  526. $sFrom = $aCampaign['from_name'] != '' ? $aCampaign['from_name'] : getParam('site_title');
  527. $aCustomHeaders['Reply-To'] = "=?UTF-8?B?" . base64_encode($sFrom) . '?= <' . bx_process_output($aCampaign['reply_to']) . '>';
  528. $aCustomHeaders['X-Original-From'] = "=?UTF-8?B?" . base64_encode($sFrom) . '?= <' . bx_process_output($aCampaign['reply_to']) . '>';
  529. }
  530. return array($aTemplate, $aCustomHeaders, $aCampaign);
  531. }
  532. private function addMarkers($iProfileId, $sLetterCode)
  533. {
  534. $CNF = &$this->_oConfig->CNF;
  535. $aMarkers = array();
  536. $oProfile = BxDolProfile::getInstance($iProfileId);
  537. if ($oProfile){
  538. $oAccount = BxDolAccount::getInstance($oProfile->getAccountId());
  539. $aMarkers['email'] = $oAccount->getEmail();
  540. $aMarkers['account_name'] = $oAccount->getDisplayName();
  541. $aMarkers['account_id'] = $oProfile->getAccountId();
  542. $oModule = BxDolModule::getInstance($oProfile->getModule());
  543. if (BxDolRequest::serviceExists($oProfile->getModule(), 'get_info')){
  544. $aProfileInfo = $oModule->serviceGetInfo($oProfile->getContentId(), false);
  545. foreach ($aProfileInfo as $sKey => $sValue){
  546. if (!isset($aMarkers[$sKey]))
  547. $aMarkers[$sKey] = $sValue;
  548. }
  549. $aMarkers['seen_image_url'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'track/seen/' . $sLetterCode . "/";
  550. $aMarkers['unsubscribe_url'] = BX_DOL_URL_ROOT . $oAccount->getUnsubscribeLink(BX_EMAIL_MASS) . "&lhash=" . $sLetterCode;
  551. }
  552. }
  553. return $aMarkers;
  554. }
  555. private function getReportStep($iMin, $iMax)
  556. {
  557. $iCount = 10;
  558. return ceil(($iMax - $iMin) / $iCount);
  559. }
  560. }
  561. /** @} */