18 require_once SQ_PACKAGES_PATH.
'/bulkmail/bulkmail_post_office/bulkmail_post_office_edit_fns.inc';
19 require_once SQ_FUDGE_PATH.
'/datetime_field/datetime_field.inc';
20 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
21 require_once SQ_FUDGE_PATH.
'/general/www.inc';
47 parent::__construct();
48 unset($this->static_screens[
'preview']);
49 $this->static_screens[
'details'][
'force_unlock'] = FALSE;
72 ?><p style=
"margin-top: 5px; margin-bottom: 5px"><?php
73 echo translate(
'bm_job_validation_validate_job');
75 echo normal_button($prefix.
'_validation_button', translate(
'bm_job_validation_button'),
'onClick= validate(); this.form.submit();');
76 echo hidden_field($prefix.
'_validation_hidden',
'0');
81 if (isset($_REQUEST[$prefix.
'_validation_hidden']) && $_REQUEST[$prefix.
'_validation_hidden'] == 1) {
82 $post_office = $asset->getPostOffice();
83 $bm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'bulkmail_manager');
84 $details_info = $bm->generateJobDetails($asset, $post_office);
85 $errors = $bm->isValidJob($details_info, TRUE);
86 $o->openField(translate(
'bm_job_validation_result'));
88 echo translate(
'bm_job_validation_successful');
91 <table
class=
"sq-backend-table">
93 <th
class=
"sq-backend-table-header"><?php echo translate(
'bm_configuration'); ?></th>
94 <th
class=
"sq-backend-table-header"><?php echo translate(
'bm_warning'); ?></th>
97 foreach ($errors as $error) {
98 $error_msg = explode(
':', $error, 2);
100 <td><?php echo $error_msg[0]; ?></td>
101 <td><span
class=
"sq-backend-warning"><?php echo $error_msg[1]; ?></span></td>
111 <script language=
"JavaScript" type=
"text/javascript">
112 function validate() {
113 var prefix =
'<?php echo $prefix; ?>';
114 var
id = prefix +
'_validation_hidden';
115 var element = document.getElementById(
id);
156 ?><span
class=
"sq-backend-warning"><?php echo translate(
'bm_warning_changes_no_effect'); ?></span><?php
190 $bulkmail_manager = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'bulkmail_manager');
191 $job = $bulkmail_manager->getQueuedJobs($asset->id);
193 return (empty($job)) ? FALSE : TRUE;
213 $write_access = $asset->writeAccess(
'attributes');
214 $use_post_office_header = $asset->attr(
'use_post_office_header');
218 check_box($prefix.
'_use_post_office_header', TRUE, $use_post_office_header);
221 <img src=
"<?php echo sq_web_path('lib'); ?>/web/images/<?php echo $use_post_office_header ? 'tick' : 'cross'; ?>.gif" width=
"15" height=
"15" />
224 $post_office = $asset->getPostOffice();
225 echo get_asset_tag_line($post_office->id);
227 return $write_access;
244 if (!$asset->writeAccess(
'attributes'))
return FALSE;
247 $use_header_details = isset($_POST[$prefix.
'_use_post_office_header']);
248 $asset->setAttrValue(
'use_post_office_header', $use_header_details);
266 return !($asset->attr(
'use_post_office_header'));
286 $write_access = $asset->writeAccess(
'attributes');
287 $bulkmail_manager = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'bulkmail_manager');
288 $bulkmail_manager_edit_fns = $bulkmail_manager->getEditFns();
290 $jobs = $bulkmail_manager->getQueuedJobs($asset->id);
291 $bulkmail_manager_edit_fns->_paintJobQueue($asset, $jobs);
295 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
296 if (isset($asset->_tmp[
'bulkmail.job.*'])){
297 $logs = $asset->_tmp[
'bulkmail.job.*'];
298 unset($asset->_tmp[
'bulkmail.job.*']);
300 $logs = $ms->getMessages(0,
'bulkmail.job.*', Array(), Array(), NULL, NULL,
'name', Array(
'assetid' => $asset->id));
301 $logs = array_slice($logs, 0, 5);
306 <table
class=
"sq-backend-table">
308 <th
class=
"sq-backend-table-header"><?php echo translate(
'date'); ?></th>
309 <th
class=
"sq-backend-table-header"><?php echo translate(
'subject'); ?></th>
310 <th
class=
"sq-backend-table-header"><?php echo translate(
'body'); ?></th>
313 foreach ($logs as $log_entry) {
316 <td align=
"left" class=
"sq-backend-table-cell"><?php echo ts_iso8601($log_entry[
'sent']); ?></td>
317 <td align=
"left" class=
"sq-backend-table-cell"><?php echo $log_entry[
'subject']; ?></td>
318 <td align=
"left" class=
"sq-backend-table-cell"><?php echo $log_entry[
'body']; ?></td>
326 return $write_access;
343 $write_access = $asset->writeAccess(
'attributes');
344 $bulkmail_manager = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'bulkmail_manager');
345 $bulkmail_manager_edit_fns = $bulkmail_manager->getEditFns();
346 if (!$write_access)
return;
348 $jobs = $bulkmail_manager->getQueuedJobs($asset->id);
349 $bulkmail_manager_edit_fns->_processJobQueue($asset, $jobs);
367 $bulkmail_manager = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'bulkmail_manager');
368 $job = $bulkmail_manager->getQueuedJobs($asset->id);
370 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
371 $logs = $ms->getMessages(0,
'bulkmail.job.*', Array(), Array(), NULL, NULL,
'name', Array(
'assetid' => $asset->id));
372 $logs = array_slice($logs, 0, 5);
373 $asset->_tmp[
'bulkmail.job.*'] = $logs;
375 return ((empty($job) && empty($logs)) ? FALSE : TRUE);
395 $write_access = $asset->writeAccess(
'attributes');
397 $current_user = $GLOBALS[
'SQ_SYSTEM']->user;
398 $email = $current_user->attr(
'email');
401 text_box($prefix.
'_preview_address', $email);
406 return $write_access;
423 if (!$asset->writeAccess(
'attributes'))
return FALSE;
425 $recipient = array_get_index($_REQUEST, $prefix.
'_preview_address',
'');
426 if (empty($recipient) || !valid_email($recipient)) {
427 trigger_localised_error(
'BML0013', E_USER_WARNING, $recipient);
431 if ($asset->sendPreviewMail($recipient)) {
433 'assetid' => $GLOBALS[
'SQ_SYSTEM']->currentUserId(),
434 'email_addr' => $recipient,
437 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
438 $message = $ms->newMessage(Array(),
'bulkmail.preview', $msg_reps);
440 $message->parameters[
'assetid'] = $asset->id;
441 $message->parameters[
'version'] = substr($asset->version, 0, strrpos($asset->version,
'.'));
464 $write_access = $asset->writeAccess(
'attributes');
465 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
466 $logs = $ms->getMessages(0,
'bulkmail.preview', Array(), Array(), NULL, NULL,
'name', Array(
'assetid' => $asset->id));
467 $logs = array_slice($logs, 0, 5);
471 <table
class=
"sq-backend-table">
473 <th
class=
"sq-backend-table-header"><?php echo translate(
'date'); ?></th>
474 <th
class=
"sq-backend-table-header"><?php echo translate(
'subject'); ?></th>
475 <th
class=
"sq-backend-table-header"><?php echo translate(
'body'); ?></th>
478 foreach ($logs as $log_entry) {
481 <td align=
"left" class=
"sq-backend-table-cell"><?php echo ts_iso8601($log_entry[
'sent']); ?></td>
482 <td align=
"left" class=
"sq-backend-table-cell"><?php echo $log_entry[
'subject']; ?></td>
483 <td align=
"left" class=
"sq-backend-table-cell"><?php echo $log_entry[
'body']; ?></td>
489 echo translate(
'bm_job_preview_never');
492 return $write_access;
527 $field_prefix = $prefix.
'_content_body_filter';
529 $enabled = $asset->
attr(
'content_body_filter');
530 $match = $asset->
attr(
'content_body_filter_match');
531 $filter_text = $asset->
attr(
'content_body_filter_text');
538 1 => translate(
'enabled'),
539 0 => translate(
'disabled'),
542 combo_box($field_prefix.
'_enabled', $contents, FALSE, $enabled, FALSE);
544 echo
'<div id="'.$field_prefix.
'_settings" style="padding: 1em 0em;">';
546 1 => translate(
'matches'),
547 0 => translate(
'does_not_match'),
549 echo translate(
'bulkmail_job_filter_explanation').
'<br/>';
550 combo_box($field_prefix.
'_match', $contents, FALSE, $match, FALSE);
552 text_box($field_prefix.
'_text', $filter_text, 30);
557 if (!empty($filter_text)) {
558 echo translate(
'enabled').
'<br/>';
559 echo translate(
'bulkmail_job_filter_explanation').
'<br/>';
561 echo translate(
'bulkmail_job_filter_enabled_format_true', $filter_text);
563 echo translate(
'bulkmail_job_filter_enabled_format_false', $filter_text);
566 echo
'<span class="sq-backend-warning">';
567 echo translate(
'bulkmail_job_enabled_but_not_valid');
569 echo translate(
'bulkmail_job_enabled_but_not_valid_explanation');
572 echo translate(
'disabled');
594 if (!$asset->
writeAccess(
'attributes'))
return FALSE;
596 $field_prefix = $prefix.
'_content_body_filter';
597 $asset->
setAttrValue(
'content_body_filter', (
bool)$_POST[$field_prefix.
'_enabled']);
598 $asset->
setAttrValue(
'content_body_filter_match', (
bool)$_POST[$field_prefix.
'_match']);
599 $asset->
setAttrValue(
'content_body_filter_text', $_POST[$field_prefix.
'_text']);
618 $write_access = $asset->writeAccess(
'attributes');
619 $subscription_enabled = $asset->attr(
'user_subscriptions_status');
620 $subscriptions = $asset->attr(
'subscriptions');
622 $option_type = Array(
623 'matches' =>
'Matches',
624 'contains' =>
'Contains',
627 $new_rule_type = Array(
628 '0' =>
'-- Add New Rule --',
629 'metadata' =>
'Asset Metadata field',
632 if ($subscription_enabled) {
633 $o->openField(translate(
'categories'));
634 echo
'<table class ="sq-backend-table" border="1" style="margin-bottom: 7px">';
635 echo
'<tr><td rowspan =2 width="12%">Name</td><td colspan="3">Rules</td></tr>';
636 echo
'<tr><td width="15%">Type</td><td>Details</td><td>Delete?</td></tr>';
638 foreach ($subscriptions as $name => $subscription) {
639 hidden_field($prefix.
'_subscriptions['.$name.
']',
'');
642 $rowspan = ($write_access) ? (count($subscription) + 1) : count($subscription);
643 if (empty($subscription)) $rowspan++;
644 echo
'<th rowspan='.$rowspan.
'>'.$name.
'</th>';
645 if (!empty($subscription)) {
646 foreach ($subscription as $index => $rules) {
647 if ($tr) echo
"<tr>";
648 $type_data = array_keys($rules);
649 echo
'<td>'.$new_rule_type[$type_data[0]].
'</td>';
652 asset_finder($prefix.
'_subscriptions['.$name.
']['.$index.
']['.$type_data[0].
'][assetid]', $rules[$type_data[0]][
'assetid'], Array(
'metadata_field' =>
'D'));
654 echo get_asset_tag_line($rules[$type_data[0]][
'assetid']);
656 echo
' ';
658 combo_box($prefix.
'_subscriptions['.$name.
']['.$index.
']['.$type_data[0].
'][rule_cond]', $option_type, FALSE, $rules[$type_data[0]][
'rule_cond']);
660 echo $rules[$type_data[0]][
'rule_cond'];
662 echo
' ';
664 text_box($prefix.
'_subscriptions['.$name.
']['.$index.
']['.$type_data[0].
'][rule_text]', $rules[$type_data[0]][
'rule_text'], 30);
666 echo $rules[$type_data[0]][
'rule_text'];
670 if ($write_access) check_box($prefix.
'_subscriptions['.$name.
']['.$index.
'][delete]');
676 echo
'<td colspan=3></td></tr>';
683 combo_box($prefix.
'_subscriptions['.$name.
'][new_rule]', $new_rule_type, FALSE);
692 label(translate(
'new_category'), $prefix.
'_new_category_name');
694 text_box($prefix.
'_new_category_name',
'', 15);
700 return $write_access;
717 $write_access = $asset->writeAccess(
'attributes');
718 $subscription_enabled = $asset->attr(
'user_subscriptions_status');
721 $new_subscriptions = Array();
722 if ($subscription_enabled) {
723 if (isset($_POST[$prefix.
'_subscriptions'])) {
724 foreach ($_POST[$prefix.
'_subscriptions'] as $sub_name => $subscription) {
725 foreach ($subscription as $index => $subscription_data) {
726 if ($index ===
'new_rule') {
727 if ($subscription[
'new_rule'] !==
'0') {
728 $new_subscriptions[$sub_name][][$subscription[
'new_rule']] = Array(
730 'rule_cond' =>
'contains',
737 if (!isset($subscription_data[
'delete'])) {
738 $category = array_keys($subscription_data);
739 $new_subscriptions[$sub_name][][$category[0]] = Array(
740 'assetid' => $subscription_data[$category[0]][
'assetid'][
'assetid'],
741 'rule_cond' => array_get_index($subscription_data[$category[0]],
'rule_cond',
'contains'),
742 'rule_text' => array_get_index($subscription_data[$category[0]],
'rule_text',
''),
748 $new_category_name = array_get_index($_POST, $prefix.
'_new_category_name',
'');
749 if (!empty($new_category_name)) {
750 $new_subscriptions[$new_category_name] = Array();
753 $asset->setAttrValue(
'subscriptions', $new_subscriptions);
754 return $asset->saveAttributes();
758 return $write_access;
775 $write_access = $asset->writeAccess(
'attributes');
776 $scheduling = $asset->attr(
'scheduled_time');
777 $interval_opt = Array(
778 'empty_val' =>
'None Selected',
779 'hourly' =>
'Hourly',
781 'weekly' =>
'Weekly',
782 'monthly' =>
'Monthly',
783 'yearly' =>
'Yearly',
785 $interval = array_get_index(array_keys($scheduling), 0,
'empty_val');
786 $start_date = array_get_index($scheduling, $interval, date(
'Y-m-d H:i').
':00');
792 echo
'<b>'.translate(
'start_date').
'</b>';
799 'min' =>
'2012-01-01 00:00:00',
800 'max' => ts_iso8601(time() + (60 * 60 * 24 * 365 * 4)),
801 'allow_circa' =>
'0',
802 'show' => Array(
'y',
'm',
'd',
'h',
'i'),
813 $parameters[
'print_format'] =
'j M Y H:i';
814 $from =
new Datetime_Field($prefix.
'_from', $start_date, $parameters);
818 if ($start_date == date(
'Y-m-d H:i').
':00') {
819 echo translate(
'not_configured');
830 echo
'<b>'.translate(
'repeating').
'</b>';
836 combo_box($prefix.
'_repeating', $interval_opt, FALSE, $interval);
838 echo $interval_opt[$interval];
846 return $write_access;
863 $write_access = $asset->writeAccess(
'attributes');
865 $interval = array_get_index($_POST, $prefix.
'_repeating',
'empty_val');
867 'min' =>
'2012-01-01 00:00:00',
868 'max' => ts_iso8601(time() + (60 * 60 * 24 * 365 * 4)),
869 'allow_circa' =>
'0',
870 'show' => Array(
'y',
'm',
'd',
'h',
'i'),
881 $parameters[
'print_format'] =
'j M Y H:i';
883 $from =
new Datetime_Field($prefix.
'_from', $value, $parameters);
884 $from->processField();
886 $scheduling = Array();
887 if ($interval !=
'empty_val') {
889 $interval => $from->value,
892 $asset->setAttrValue(
'scheduled_time', $scheduling);
893 $asset->setAttrValue(
'last_scheduled_run', 0);
896 return $write_access;