8 define(
'CH_SECURITY_EXCEPTIONS',
true);
14 require_once(
'../inc/header.inc.php' );
15 require_once( CH_DIRECTORY_PATH_INC .
'design.inc.php' );
16 require_once( CH_DIRECTORY_PATH_INC .
'admin_design.inc.php' );
17 require_once( CH_DIRECTORY_PATH_INC .
'utils.inc.php' );
18 require_once( CH_DIRECTORY_PATH_INC .
'prof.inc.php' );
37 $sActionResult =
DeleteMessage() ?
_t(
'_adm_mmail_Message_was_deleted') :
_t(
'_adm_mmail_Message_was_not_deleted');
40 if(
ch_get(
'action') ==
'empty' )
41 $sActionResult =
EmptyQueue() ?
_t(
'_adm_mmail_Queue_empty') :
_t(
'_adm_mmail_Queue_emptying_failed');
43 if (isset($_POST[
'adm-ms-delete'])) {
52 'massmailer' => array (
54 'title' =>
_t(
'_adm_mmail_title'),
55 'url' => CH_WSB_URL_ADMIN .
'notifies.php?mode=massmailer',
56 'func' =>
'PageCodeMassmailer',
57 'func_params' => array(),
59 'manage_subscribers' => array (
61 'title' =>
_t(
'_adm_page_cpt_manage_subscribers'),
62 'url' => CH_WSB_URL_ADMIN .
'notifies.php?mode=manage_subscribers',
63 'func' =>
'PageCodeManageSubscribers',
68 'title' =>
_t(
'_Settings'),
69 'url' => CH_WSB_URL_ADMIN .
'notifies.php?mode=settings',
70 'func' =>
'PageCodeSettings',
71 'func_params' => array(),
84 'title' => $r[
'title'],
85 'active' => $k ==
$sMode ? 1 : 0
91 'css_name' => array(
'forms_adv.css',
'manage_subscribers.css'),
92 'header' =>
_t(
'_adm_mmail_title')
113 $iStart =
ch_get(
'start') !==
false ? (int)
ch_get(
'start') : 0;
119 'page_url' => CH_WSB_URL_ADMIN .
'notifies.php?mode=manage_subscribers&start={start}',
124 'adm-ms-delete' =>
_t(
'_adm_btn_ms_delete')
129 $s =
$GLOBALS[
'oAdmTemplate']->parseHtmlByName(
'manage_subscribers.html', array(
130 'ch_repeat:items' => is_array($aSubscribers) && !
empty($aSubscribers) ? $aSubscribers :
MsgBox(
_t(
'_Empty')),
131 'paginate' => $oPaginate->getPaginate(),
132 'controls' => $sControls
146 if (isset($_POST[
'save']) && isset($_POST[
'cat']))
158 $sSubjC =
_t(
'_Subject');
159 $sEmailsC =
_t(
'_adm_mmail_emails');
160 $sEmptyQueueC =
_t(
'_adm_mmail_Empty_Queue');
161 $sCupidStatusC =
_t(
'_adm_mmail_Cupid_mails_status');
163 $sSingleEmailsTRs =
'';
166 $iCount = (int)
$GLOBALS[
'MySQL']->getOne(
"SELECT COUNT(`id`) AS `count` FROM `sys_sbs_queue`");
168 $sSingleEmailsTRs .=
"<tr><td align=center><b class='sys-adm-failed'>" .
_t(
'_adm_mmail_no_emails_in_queue') .
"</b></td></tr>";
170 $sSingleEmailsTRs .=
"<tr><td align='center'>" .
_t(
'_adm_mmail_mails_in_queue', $iCount) .
"</td></tr>";
172 $sEmptyQueueTable =
'';
175 $sEmptyQueueTable =
"
176 <div class=\"ch-def-hr\"></div>
177 <table class=\"text\" width=\"50%\" style=\"height: 30px;\">
179 <td align=\"center\" colspan=\"3\">
180 <a href=\"" . CH_WSB_URL_ADMIN .
"notifies.php?action=empty\">{$sEmptyQueueC}</a>
184 <div class=\"ch-def-hr\"></div>";
190 <
table cellspacing=2 cellpadding=2
class=text border=0>
191 <tr
class=
header align=
"center"><td><?=
_t(
'_adm_mmail_Queue_status');?>:</td></tr>
192 <?=$sSingleEmailsTRs;?>
194 <?=$sEmptyQueueTable;?>
199 if(!
empty($sActionResult))
207 $aMessages =
$GLOBALS[
'MySQL']->getAll(
"SELECT `id`, `subject`, (`id`= ? OR `subject`= ? ) AS `selected` FROM `sys_sbs_messages`", [
212 $sAllMessagesOptions =
'';
213 foreach($aMessages
as $aMessage)
214 $sAllMessagesOptions .=
"<option value=\"" . $aMessage[
'id'] .
"\" " . ($aMessage[
'selected'] ?
"selected=\"selected\"" :
"") .
">" . $aMessage[
'subject'] .
"</option>";
218 <
form name=
"form_messages" method=
"POST" action=
"<?=$GLOBALS['site']['url_admin'] . 'notifies.php';?>">
220 <center
class=
"text"><?=
_t(
'_Messages'); ?>:
221 <select
name=msgs_id onChange=
"javascript: document.forms['form_messages'].submit();">
222 <option
value=0><?=
_t(
'_None');?></option>
223 <?=$sAllMessagesOptions;?>
235 $sErrorC =
_t(
'_Error Occured');
236 $sApplyChangesC =
_t(
'_Save');
237 $sSubjectC =
_t(
'_Subject');
238 $sBodyC =
_t(
'_adm_mmail_Body');
239 $sTextBodyC =
_t(
'_adm_mmail_Text_email_body');
240 $sPreviewMessageC =
_t(
'_Preview');
241 $sDeleteC =
_t(
'_Delete');
245 $sSubject = $sBody =
"";
249 } elseif ( $sMessageID )
250 list($sSubject, $sBody) =
$GLOBALS[
'MySQL']->getRow(
"SELECT `subject`, `body` FROM `sys_sbs_messages` WHERE `id`= ? LIMIT 1", [$sMessageID], PDO::FETCH_NUM);
252 $sSubject = htmlspecialchars($sSubject);
255 'form_attrs' => array(
256 'name' =>
'sys_sbs_messages',
257 'action' =>
$GLOBALS[
'site'][
'url_admin'] .
'notifies.php',
262 'table' =>
'sys_sbs_messages',
264 'submit_name' =>
'add_message',
271 'value' => $sSubject,
272 'caption' => $sSubjectC,
276 'params' => array(2,128),
284 'type' =>
'textarea',
287 'caption' => $sBodyC,
290 'html_no_link_conversion' =>
true,
291 'attrs' => array(
'style' =>
"height:400px;"),
294 'params' => array(10,32000),
304 'value' => $sMessageID,
307 'type' =>
'input_set',
310 'name' =>
'add_message',
311 'caption' => $sApplyChangesC,
312 'value' => $sApplyChangesC,
316 'name' =>
'preview_message',
317 'caption' => $sPreviewMessageC,
318 'value' => $sPreviewMessageC,
324 $aForm[
'inputs'][
'control'][] = array (
326 'name' =>
'delete_message',
327 'caption' => $sDeleteC,
328 'value' => $sDeleteC,
335 if (
$oForm->isSubmittedAndValid()) {
337 if ($sMessageID > 0) {
338 $oForm->update($sMessageID);
340 $sMessageID =
$oForm->insert();
354 if ( isset($_POST[
'msgs_id']) ) {
355 $aSexValues = $aAgeValues = array(
357 'selectively' =>
_t(
'_Selectively'),
361 foreach($aSexesValues
as $sKey => $sValue)
362 $aSexesValues[$sKey] =
_t($sValue);
364 $aStartAgesOptions = array();
365 $aEndAgesOptions = array();
366 $gl_search_start_age = (int)
getParam(
'search_start_age');
367 $gl_search_end_age = (int)
getParam(
'search_end_age');
368 for ( $i = $gl_search_start_age ; $i <= $gl_search_end_age ; $i++ ) {
369 $aStartAgesOptions[$i] = $i;
371 for ( $i = $gl_search_start_age ; $i <= $gl_search_end_age ; $i++ ) {
372 $aEndAgesOptions[$i] = $i;
375 $aCountryOptions = array(
'all' =>
_t(
'_All'));
376 foreach ( $aPreValues[
'Country']
as $key => $value ) {
377 $aCountryOptions[$key] =
_t($value[
'LKey']);
380 $aMembershipOptions = array(
'all' =>
_t(
'_All'));
382 foreach ( $memberships_arr
as $membershipID => $membershipName ) {
384 $aMembershipOptions[$membershipID] = $membershipName;
387 $iRecipientMembers = (int)
$GLOBALS[
'MySQL']->getOne(
"SELECT COUNT(`ID`) AS `count` FROM `Profiles` WHERE `Status`<>'Unconfirmed' AND `EmailNotify` = 1 LIMIT 1");
389 'form_attrs' => array(
390 'name' =>
'form_queue',
391 'class' =>
'form_queue_form',
392 'action' =>
$GLOBALS[
'site'][
'url_admin'] .
'notifies.php',
397 'type' =>
'checkbox',
398 'name' =>
'send_to_subscribers',
399 'label' =>
_t(
'_adm_mmail_Send_to_subscribers'),
404 'type' =>
'checkbox',
405 'name' =>
'send_to_members',
406 'label' =>
_t(
'_adm_mmail_Send_to_members'),
410 'onClick' =>
'setControlsState();',
412 'info' =>
_t(
'_adm_mmail_Send_to_members_info', $iRecipientMembers),
417 'caption' =>
_t(
'_adm_mmail_Sex'),
419 'values' => $aSexValues,
421 'onClick' =>
'setSexState();',
425 'type' =>
'checkbox_set',
427 'values' => $aSexesValues,
428 'value' => array_keys($aSexesValues)
433 'caption' =>
_t(
'_adm_mmail_Age'),
435 'values' => $aAgeValues,
437 'onClick' =>
'setAgeState();',
440 'StartAge' => array (
442 'name' =>
'age_start',
443 'caption' =>
_t(
'_from'),
444 'values' => $aStartAgesOptions,
445 'value' => $gl_search_start_age,
450 'caption' =>
_t(
'_to'),
451 'values' => $aEndAgesOptions,
452 'value' => $gl_search_end_age,
457 'caption' =>
_t(
'_Country'),
458 'values' => $aCountryOptions,
461 'Membership' => array (
463 'name' =>
'membership',
464 'caption' =>
_t(
'_adm_mmi_membership_levels'),
465 'values' => $aMembershipOptions,
471 'value' => (
int)$_POST[
'msgs_id'],
475 'name' =>
'queue_message',
476 'value' =>
_t(
'_Submit'),
482 $sTmplResult =
$GLOBALS[
'oAdmTemplate']->parseHtmlByName(
'notifies_filter.html', array());
493 $iMsgId = (int)$_POST[
'msgs_id'];
495 $aOriginalMessage = $MySQL->getRow(
"SELECT `id`, `subject`, `body` FROM `sys_sbs_messages` WHERE `id`= ? LIMIT 1", [$iMsgId]);
496 if(!is_array($aOriginalMessage) ||
empty($aOriginalMessage)) {
497 return _t(
'_adm_mmail_Failed_to_queue_emails_X', $iMsgId);
502 if($_POST[
'send_to_subscribers'] ==
'non') {
504 `tsu`.`name` AS `user_name`,
505 `tsu`.`email` AS `user_email`,
506 `tst`.`template` AS `template_name`
507 FROM `sys_sbs_types` AS `tst`
508 INNER JOIN `sys_sbs_entries` AS `tse` ON `tst`.`id`=`tse`.`subscription_id` AND `tse`.`subscriber_type`='" .
CH_WSB_SBS_TYPE_VISITOR .
"'
509 INNER JOIN `sys_sbs_users` AS `tsu` ON `tse`.`subscriber_id`=`tsu`.`id`
511 `tst`.`unit`='system' AND
512 `tst`.`action`='mass_mailer'";
513 $aSubscribers = $MySQL->getAll($sSql);
515 foreach($aSubscribers
as $aSubscriber) {
516 if(
empty($aSubscriber[
'user_email']))
519 $aMessage = $oEmailTemplates->parseTemplate($aSubscriber[
'template_name'], array(
520 'RealName' => $aSubscriber[
'user_name'],
521 'Email' => $aSubscriber[
'user_email'],
522 'MessageSubject' => $aOriginalMessage[
'subject'],
523 'MessageText' => $aOriginalMessage[
'body']
527 if($mixedResult ===
false) {
528 $sReturn .=
_t(
'_adm_mmail_Email_not_added_to_queue_X', $aSubscriber[
'user_email']);
536 if($_POST[
'send_to_members'] ==
'memb') {
538 $sex_filter_sql =
'';
539 $sex = $_POST[
'sex'];
540 if($sex !=
'all' && !
empty($_POST[
'sexes']) && is_array($_POST[
'sexes']))
541 $sex_filter_sql =
"AND `Sex` IN ('" . implode(
"','", $_POST[
'sexes']) .
"')";
544 $age_filter_sql =
'';
545 $age = $_POST[
'age'];
547 $age_start = (int)$_POST[
'age_start'];
548 $age_end = (int)$_POST[
'age_end'];
549 if ( $age_start && $age_end ) {
550 $date_start = (int)( date(
"Y" ) - $age_start );
551 $date_end = (int)( date(
"Y" ) - $age_end - 1 );
552 $date_start = $date_start . date(
"-m-d" );
553 $date_end = $date_end . date(
"-m-d" );
554 $age_filter_sql =
"AND (TO_DAYS(`DateOfBirth`) BETWEEN TO_DAYS('{$date_end}') AND (TO_DAYS('{$date_start}')+1))";
559 $country_filter_sql =
'';
560 if($_POST[
'country'] !=
'all') {
562 $country_filter_sql =
"AND `Country` = '{$country}'";
566 $membershipID = $_POST[
'membership'] !=
'all' ? (int)$_POST[
'membership'] : -1;
568 $aMembers = $MySQL->getAll(
"SELECT `ID` AS `id`, `Email` AS `email` FROM `Profiles` WHERE `Status` <> 'Unconfirmed' AND `EmailNotify` = 1 AND (`Couple` = '0' OR `Couple` > `ID`) {$sex_filter_sql} {$age_filter_sql} {$country_filter_sql}");
569 foreach($aMembers
as $aMember) {
570 if(
empty($aMember[
'email']))
574 if ($membershipID != -1) {
576 if ($membership_info[
'ID'] != $membershipID )
580 $aMessage = $oEmailTemplates->parseTemplate(
't_AdminEmail', array(
581 'MessageSubject' => $aOriginalMessage[
'subject'],
582 'MessageText' => $aOriginalMessage[
'body']
586 if($mixedResult ===
false) {
587 $sReturn .=
_t(
'_adm_mmail_Email_not_added_to_queue_X', $aMember[
'email']);
594 $sReturn .=
_t(
'_adm_mmail_X_emails_was_succ_added_to_queue', (
int)$iEmails);
601 $aMessage = $oEmailTemplate->parseTemplate(
't_AdminEmail', array(
610 $mixedResult =
$GLOBALS[
'MySQL']->query(
"DELETE FROM `sys_sbs_messages` WHERE `id`='". (
int)$_POST[
'msgs_id'] .
"' LIMIT 1");
611 if($mixedResult ===
false)
614 $_POST[
'msgs_id'] = 0;
620 return db_res(
"TRUNCATE TABLE `sys_sbs_queue`");