17 require_once SQ_INCLUDE_PATH.
'/asset_edit/asset_edit_fns.inc';
18 require_once SQ_DATA_PATH.
'/private/conf/tools.inc';
44 parent::__construct();
45 $this->static_screens[
'details'][
'force_unlock'] = FALSE;
65 $write_access = $asset->writeAccess(
'attributes');
66 $recipients = $asset->attr(
'recipients');
69 multiple_asset_finder($prefix.
'_groups', $recipients);
72 foreach ($recipients as $assetid) {
74 if (!empty($assetid)) {
75 $group_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
78 if (!is_null($group_asset)) {
79 ?><li><?php echo get_asset_tag_line($group_asset->id); ?></li><?php
81 echo translate(
'bulkmail_recipient_group_asset_not_found');
105 if (!$asset->writeAccess(
'attributes'))
return FALSE;
108 if (is_array($_POST[$prefix.
'_groups'])) {
109 foreach ($_POST[$prefix.
'_groups'] as $group_node) {
110 if (!empty($group_node[
'assetid'])) {
111 $groups[] = $group_node[
'assetid'];
116 return $asset->setAttrValue(
'recipients', $groups);
133 $write_access = $asset->writeAccess(
'attributes');
134 $server_details = $asset->attr(
'server_details');
136 $field_name = translate(
'bulkmail_server_detail_mail_method_field_name');
137 $o->openField($field_name);
140 'sendmail' =>
'Sendmail',
143 $onChange =
'onChange="switchDriver(this.value)"';
144 $value = array_get_index($server_details,
'driver',
'smtp');
146 combo_box($prefix.
'_server_det_driver', $options, FALSE, $value, 0, $onChange);
148 echo $options[$value];
152 $smtp = !($value ==
'smtp');
154 $field_name = translate(
'bulkmail_server_detail_host_field_name');
155 $name = $prefix.
'_server_detail_smtp_host';
156 $o->openField($field_name,
'',
'', $smtp, $name.
'_field');
157 $value = array_get_index($server_details,
'host',
'');
159 text_box($name, array_get_index($server_details,
'host',
''));
165 $field_name = translate(
'bulkmail_server_detail_port_field_name');
166 $name = $prefix.
'_server_detail_smtp_port';
167 $o->openField($field_name,
'',
'', $smtp, $name.
'_field');
168 $value = array_get_index($server_details,
'port',
'');
170 int_text_box($name, $value, FALSE, 4);
176 $field_name = translate(
'bulkmail_server_detail_auth_field_name');
177 $name = $prefix.
'_server_detail_smtp_auth';
178 $o->openField($field_name,
'',
'Server requires authentication?', $smtp, $name.
'_field');
179 $auth = array_get_index($server_details,
'auth', FALSE);
182 check_box($name, TRUE, $auth,
'switchAuthentication(this.checked)');
185 <img src=
"<?php echo sq_web_path('lib'); ?>/web/images/<?php echo $auth ? 'tick' : 'cross'; ?>.gif" width=
"15" height=
"15" />
190 $disabled = ($auth) ?
'' :
'disabled=TRUE';
192 $name = $prefix.
'_server_detail_smtp_auth_username';
193 $o->openField(translate(
'username'),
'',
'', $smtp, $name.
'_field');
194 $value = array_get_index($server_details,
'username',
'');
196 text_box($name, $value,
'',
'', FALSE, $disabled);
202 $name = $prefix.
'_server_detail_smtp_auth_password';
203 $o->openField(translate(
'password'),
'',
'', $smtp, $name.
'_field');
204 $value = array_get_index($server_details,
'password',
'');
206 password_box($name, $value,
'',
'', $disabled);
208 echo str_repeat(
'*', strlen($value));
212 $field_name = translate(
'bulkmail_server_detail_path_field_name');
213 $name = $prefix.
'_server_detail_sendmail_sendmail_path';
214 $o->openField($field_name,
'',
'The path to your sendmail binary. Use config file data/private/conf/tools.inc.', !$smtp, $name.
'_field');
215 echo SQ_TOOL_SENDMAIL_PATH;
218 $field_name = translate(
'bulkmail_server_detail_arg_field_name');
219 $name = $prefix.
'_server_detail_sendmail_sendmail_args';
220 $o->openField($field_name,
'',
'Use config file data/private/conf/tools.inc.', !$smtp, $name.
'_field');
221 echo SQ_TOOL_SENDMAIL_ARGS;
225 <script type=
"text/javascript">
226 function switchDriver(driver) {
227 var prefix =
'<?php echo $prefix; ?>';
228 var regex_string1 = prefix +
'_server_detail.*_field';
229 var regex_string2 = prefix +
'_server_detail_' + driver +
'.*_field';
230 var re1 =
new RegExp(regex_string1);
231 var re2 =
new RegExp(regex_string2);
232 var elements = document.getElementsByTagName(
'tr');
234 for (i = 0; i < elements.length; i++) {
235 if (elements[i].
id.match(re1)) {
236 if (elements[i].
id.match(re2)) {
237 elements[i].style[
'display'] =
'';
239 elements[i].style[
'display'] =
'none';
245 function switchAuthentication(checked) {
246 var prefix =
'<?php echo $prefix; ?>';
247 var regex_string1 = prefix +
'_server_detail_smtp_auth_.*';
248 var re1 =
new RegExp(regex_string1);
249 var elements = document.main_form.elements;
251 for (i = 0; i < elements.length; i++) {
252 if (elements[i].name.match(re1)) {
253 elements[i].disabled = !checked;
260 return $write_access;
278 if (!$asset->writeAccess(
'attributes'))
return FALSE;
280 $driver = array_get_index($_REQUEST, $prefix.
'_server_det_driver',
'smtp');
281 foreach ($_REQUEST as $key => $value) {
282 if (preg_match(
'/'.$prefix.
'_server_detail_'.$driver.
'_(auth_)?([^^]*)/', $key, $matches)) {
284 if ($value) $server_details[$matches[2]] = $value;
287 $server_details[
'driver'] = $driver;
289 if (array_get_index($server_details,
'driver',
'smtp') ==
'smtp') {
290 if (array_get_index($server_details,
'auth', FALSE) == FALSE) {
291 $server_details[
'auth'] = FALSE;
292 $server_details[
'username'] =
'';
293 $server_details[
'password'] =
'';
296 return $asset->setAttrValue(
'server_details', $server_details);
314 $write_access = $asset->writeAccess(
'attributes');
316 $header_details = $asset->attr(
'header_details');
317 if (!empty($header_details)) {
319 <table
class=
"sq-backend-table">
321 <th
class=
"sq-backend-table-header"><b><?php echo translate(
'bulkmail_header_detail_field_name'); ?></b></th>
322 <th
class=
"sq-backend-table-header"><b><?php echo translate(
'bulkmail_header_detail_field_body'); ?></b></th>
325 ?><th
class=
"sq-backend-table-header"><b><?php echo translate(
'delete_question'); ?></b></th><?php
331 foreach ($header_details as $field_name => $field_body) {
334 <td
class=
"sq-backend-table-cell"><?php echo text_box($prefix.
'_header_key_'.$index, $field_name);?></td>
335 <td
class=
"sq-backend-table-cell"><?php echo text_box($prefix.
'_header_value_'.$index, $field_body);?></td>
336 <td
class=
"sq-backend-table-cell"><?php check_box($prefix.
'_header_delete_'.$index, TRUE, FALSE);?></td>
340 <td
class=
"sq-backend-table-cell"><?php echo $field_name;?></td>
341 <td
class=
"sq-backend-table-cell" colspan=
"2"><?php echo htmlspecialchars($field_body);?></td>
351 echo translate(
'bulkmail_header_none');
354 return $write_access;
372 if (!$asset->writeAccess(
'attributes'))
return FALSE;
374 $header_details = $asset->attr(
'header_details');
377 $new_header_details = Array();
378 foreach ($header_details as $field_name => $field_body) {
379 $key = trim(array_get_index($_REQUEST, $prefix.
'_header_key_'.$index));
380 $value = trim(array_get_index($_REQUEST, $prefix.
'_header_value_'.$index));
381 $delete = array_get_index($_REQUEST, $prefix.
'_header_delete_'.$index, FALSE);
383 if (!empty($key) && !$delete) {
384 $new_header_details[$key] = $value;
389 $asset->setAttrValue(
'header_details', $new_header_details);
407 $write_access = $asset->writeAccess(
'attributes');
411 echo translate(
'key'),
': ';
412 text_box($prefix.
'_header_new_key',
'', 30);
413 echo
' ', translate(
'value'),
': ';
414 text_box($prefix.
'_header_new_value',
'', 30);
434 $header_key = array_get_index($_REQUEST, $prefix.
'_header_new_key',
'');
435 $header_value = array_get_index($_REQUEST, $prefix.
'_header_new_value',
'');
437 $header_details = $asset->attr(
'header_details');
439 if ( (!empty($header_key)) && (!empty($header_value)) ) {
440 $header_details[$header_key] = $header_value;
443 $asset->setAttrValue(
'header_details', $header_details);
465 $write_access = $asset->writeAccess(
'attributes');
467 $bm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'bulkmail_manager');
468 $use_bm_threshold = $bm->attr(
'use_bm_threshold');
470 $threshold = $bm->attr(
'threshold');
471 $write_access = FALSE;
473 $threshold = $asset->attr(
'threshold');
477 if (!empty($threshold)) {
478 $o->openField(translate(
'bulkmail_threshold_current_rules'));
479 ?><table
class=
"sq-backend-table">
481 <th
class=
"sq-backend-table-header"><?php echo translate(
'type') ?></th>
482 <th
class=
"sq-backend-table-header"><?php echo translate(
'bulkmail_threshold_allow_multiple') ?></th>
483 <th
class=
"sq-backend-table-header"><?php echo translate(
'rule') ?></th>
486 ?><th
class=
"sq-backend-table-header"><?php echo translate(
'delete_rule') ?></th><?php
490 foreach ($threshold as $key => $rule) {
492 <td
class=
"sq-backend-table-cell"><?php echo $rule[
'type']; ?></td>
493 <td
class=
"sq-backend-table-cell"><?php echo ($rule[
'multiple']) ? translate(
'yes') : translate(
'no'); ?></td>
495 switch ($rule[
'type']) {
496 case translate(
'bulkmail_threshold_rule_excluded_time') :
499 case translate(
'bulkmail_threshold_rule_send_rate') :
500 $this->
_paintSendRateRule($asset, $o, $prefix.
'_threshold_rule_'.$key, $rule, $write_access);
508 if ($use_bm_threshold && !($asset instanceof Bulkmail_Manager)) {
509 $o->note(translate(
'bulkmail_threshold_override_note', get_asset_tag_line($bm->id)));
515 if (!($use_bm_threshold && !($asset instanceof Bulkmail_Manager))) {
516 $this->
paintAddRule($asset, $o, $prefix, $write_access);
536 $write_access = $asset->writeAccess(
'attributes');
538 $bm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'bulkmail_manager');
539 $use_bm_threshold = $bm->attr(
'use_bm_threshold');
541 $write_access = FALSE;
543 if (!$write_access)
return FALSE;
545 $threshold = $asset->attr(
'threshold');
546 if (!empty($threshold)) {
547 foreach ($threshold as $key => $rule) {
548 switch ($rule[
'type']) {
549 case translate(
'bulkmail_threshold_rule_excluded_time') :
552 case translate(
'bulkmail_threshold_rule_send_rate') :
560 $threshold = $this->
processAddRule($asset, $o, $prefix, $threshold, $write_access);
561 $asset->setAttrValue(
'threshold', $threshold);
580 $o->openField(translate(
'bulkmail_threshold_add_rule'),
'', translate(
'bulkmail_threshold_add_rule_note'));
582 $rules = Array(
'' =>
'-- '.translate(
'bulkmail_threshold_choose_type').
' --');
584 translate(
'bulkmail_threshold_rule_excluded_time'),
585 translate(
'bulkmail_threshold_rule_send_rate'),
587 combo_box($prefix.
'_rule_type', $rules, FALSE,
'');
610 translate(
'bulkmail_threshold_rule_excluded_time'),
611 translate(
'bulkmail_threshold_rule_send_rate'),
613 if (isset($_POST[$prefix.
'_rule_type'])) {
614 $type = (isset($rules[$_POST[$prefix.
'_rule_type']])) ? $rules[$_POST[$prefix.
'_rule_type']] :
'';
617 foreach ($threshold as $key => $val) {
618 if ($val[
'type'] == $type) {
619 if (!$val[
'multiple'])
return $threshold;
622 $threshold_types = $asset->attr(
'threshold_types');
624 case translate(
'bulkmail_threshold_rule_excluded_time') :
625 $threshold_types[0][
'type'] = $type;
626 $threshold[] = $threshold_types[0];
628 case translate(
'bulkmail_threshold_rule_send_rate') :
629 $threshold_types[1][
'type'] = $type;
630 $threshold[] = $threshold_types[1];
656 $hours_array = Array(
683 0 => translate(
'sunday'),
684 1 => translate(
'monday'),
685 2 => translate(
'tuesday'),
686 3 => translate(
'wednesday'),
687 4 => translate(
'thursday'),
688 5 => translate(
'friday'),
689 6 => translate(
'saturday'),
694 combo_box($prefix.
'_from', $hours_array, FALSE, $rule[
'params'][
'from']);
695 $from = ob_get_contents();
698 combo_box($prefix.
'_to', $hours_array, FALSE, $rule[
'params'][
'to']);
699 $to = ob_get_contents();
702 combo_box($prefix.
'_days', $days_array, TRUE, $rule[
'params'][
'days']);
703 $days = ob_get_contents();
705 ?><td
class=
"sq-backend-table-cell"><?php
706 echo translate(
'bulkmail_threshold_rule_excluded_time_hour', $from, $to);
707 echo translate(
'bulkmail_threshold_rule_excluded_time_days', $days);
708 ?></td><td
class=
"sq-backend-table-cell"><?php
709 check_box($prefix.
'_delete', TRUE, FALSE);?></td><?php
711 $from = $hours_array[$rule[
'params'][
'from']];
712 $to = $hours_array[$rule[
'params'][
'to']];
713 if (!empty($rule[
'params'][
'days'])) {
714 $selected_days = Array();
715 foreach ($rule[
'params'][
'days'] as $day) {
716 $selected_days[] = $days_array[$day];
718 $days = implode(
', ', $selected_days);
720 ?><td
class=
"sq-backend-table-cell" colspan=
"2"><?php
721 echo translate(
'bulkmail_threshold_rule_excluded_time_hour', $from, $to);
723 if (count($selected_days) == 7) {
724 echo translate(
'bulkmail_threshold_rule_excluded_time_every_day');
726 echo translate(
'bulkmail_threshold_rule_excluded_time_days', $days);
749 if (isset($_POST[$prefix.
'_from'])) {
750 $params[
'from'] = $_POST[$prefix.
'_from'];
751 $params[
'to'] = $_POST[$prefix.
'_to'];
753 if ($_POST[$prefix.
'_to'] == $params[
'from']) {
754 trigger_localised_error(
'BML0014', E_USER_NOTICE);
756 if ($threshold[$key][
'params'][
'to'] == $_POST[$prefix.
'_to'] && $threshold[$key][
'params'][
'from'] == $_POST[$prefix.
'_from']) {
759 $params[
'from'] = $threshold[$key][
'params'][
'from'];
760 $params[
'to'] = $threshold[$key][
'params'][
'to'];
764 if (!isset($_POST[$prefix.
'_days']) && !isset($threshold[$key][
'params'][
'days'])) {
765 trigger_localised_error(
'BML0015', E_USER_NOTICE);
767 }
else if (!isset($_POST[$prefix.
'_days']) && isset($threshold[$key][
'params'][
'days'])) {
768 trigger_localised_error(
'BML0015', E_USER_NOTICE);
769 $params[
'days'] = $threshold[$key][
'params'][
'days'];
771 $params[
'days'] = (isset($_POST[$prefix.
'_days'])) ? $_POST[$prefix.
'_days'] : Array();
774 $threshold[$key][
'params'] = $params;
776 if (isset($_POST[$prefix.
'_delete']) || $remove) {
777 unset($threshold[$key]);
800 60 => translate(
'minute'),
801 3600 => translate(
'hour'),
802 86400 => translate(
'day'),
806 $max_send_rate = 600;
807 $send_rate = ($rule[
'params'][
'value']/$rule[
'params'][
'unit']) * 60;
810 int_text_box($prefix.
'_value', $rule[
'params'][
'value'], FALSE);
811 $value = ob_get_contents();
814 combo_box($prefix.
'_unit', $time_unit, FALSE, $rule[
'params'][
'unit']);
815 $unit = ob_get_contents();
817 ?><td
class=
"sq-backend-table-cell"><?php
818 echo translate(
'bulkmail_threshold_rule_send_rate_detail', $value, $unit);
819 if ($send_rate < $min_send_rate) {
820 ?><br /><span
class=
"sq-backend-warning"><?php echo translate(
'bm_warning_send_rate_min', $min_send_rate); ?></span><?php
821 }
else if ($send_rate > $max_send_rate) {
822 ?><br /><span
class=
"sq-backend-warning"><?php echo translate(
'bm_warning_send_rate_max', $max_send_rate); ?></span><?php
824 ?></td><td
class=
"sq-backend-table-cell"><?php
825 check_box($prefix.
'_delete', TRUE, FALSE);?></td><?php
827 $value = $rule[
'params'][
'value'];
828 $unit = $time_unit[$rule[
'params'][
'unit']];
829 ?><td
class=
"sq-backend-table-cell" colspan=
"2"><?php
830 echo translate(
'bulkmail_threshold_rule_send_rate_detail', $value, $unit);
831 if ($send_rate < $min_send_rate) {
832 ?><br /><span
class=
"sq-backend-warning"><?php echo translate(
'bm_warning_send_rate_min', $min_send_rate); ?></span><?php
833 }
else if ($send_rate > $max_send_rate) {
834 ?><br /><span
class=
"sq-backend-warning"><?php echo translate(
'bm_warning_send_rate_max', $max_send_rate); ?></span><?php
854 if (isset($_POST[$prefix.
'_value'])) {
855 $params[
'value'] = $_POST[$prefix.
'_value'];
856 $params[
'unit'] = $_POST[$prefix.
'_unit'];
858 if (!$params[
'value']) $params[
'value'] = 1;
860 $threshold[$key][
'params'] = $params;
861 if (isset($_POST[$prefix.
'_delete'])) {
862 unset($threshold[$key]);
885 $write_access = $asset->writeAccess(
'attributes');
886 $bulkmail_manager = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'bulkmail_manager');
887 $bulkmail_manager_edit_fns = $bulkmail_manager->getEditFns();
889 $jobs = $bulkmail_manager->getQueuedJobs(NULL, $asset->id);
890 $bulkmail_manager_edit_fns->_paintJobQueue($asset, $jobs);
893 return $write_access;
910 $write_access = $asset->writeAccess(
'attributes');
911 $bulkmail_manager = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'bulkmail_manager');
912 $bulkmail_manager_edit_fns = $bulkmail_manager->getEditFns();
913 if (!$write_access)
return;
915 $jobs = $bulkmail_manager->getQueuedJobs(NULL, $asset->id);
916 $bulkmail_manager_edit_fns->_processJobQueue($asset, $jobs);
934 $bulkmail_manager = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'bulkmail_manager');
935 $jobs = $bulkmail_manager->getQueuedJobs(NULL, $asset->id);
937 return (empty($jobs) ? FALSE : TRUE);