18 require_once SQ_INCLUDE_PATH.
'/asset_edit/asset_edit_fns.inc';
42 parent::__construct();
44 $this->static_screens = Array(
46 'name' => translate(
'view_jobs'),
47 'force_unlock' => FALSE,
49 'permissions' => Array(
50 'name' => translate(
'permissions'),
51 'force_unlock' => TRUE,
54 'name' => translate(
'logs'),
55 'force_unlock' => TRUE,
59 unset($this->static_screens[
'settings']);
60 unset($this->static_screens[
'preview']);
61 unset($this->static_screens[
'lookupValues']);
62 unset($this->static_screens[
'web_paths']);
63 unset($this->static_screens[
'metadata']);
64 unset($this->static_screens[
'metadataSchemas']);
65 unset($this->static_screens[
'workflow']);
66 unset($this->static_screens[
'tagging']);
67 unset($this->static_screens[
'roles']);
68 unset($this->static_screens[
'permissions']);
84 $repeating = !$one_off;
92 $one_day = 24 * $one_hour;
94 $refresh_secs = (int) $cron_mgr->
attr(
'refresh_time');
95 $refresh_mins = floor($refresh_secs / 60);
96 $refresh_hours = floor($refresh_mins / 60);
98 $epoch_date = getdate($cron_mgr->
attr(
'epoch'));
101 if ($refresh_mins == 0) {
103 }
else if ($refresh_mins >= 60) {
106 $num_refreshes = floor(60 / $refresh_mins);
110 for ($i = $epoch_date[
'minutes']; $i < $epoch_date[
'minutes'] + 60; $i+= (60 / $num_refreshes)) {
111 $num = ($i >= 60) ? $i - 60 : $i;
112 $options[
'mins'][] = str_pad($num, 2,
'0', STR_PAD_LEFT);
114 }
else if ($repeating) {
117 for ($i = 0; $i < 60; $i += (60 / $num_refreshes)) {
118 $options[
'mins'][] = $i;
121 sort($options[
'mins']);
124 if ($refresh_hours == 0) {
126 }
else if ($refresh_hours >= 24) {
129 $num_refreshes = floor(24 / $refresh_hours);
133 for ($i = $epoch_date[
'hours']; $i < $epoch_date[
'hours'] + 24; $i+= (24 / $num_refreshes)) {
134 $num = ($i >= 24) ? $i - 24 : $i;
135 $options[
'hours'][] = str_pad($num, 2,
'0', STR_PAD_LEFT);
137 }
else if ($repeating) {
140 for ($i = 0; $i < 24; $i += (24 / $num_refreshes)) {
141 $options[
'hours'][] = $i;
145 sort($options[
'hours']);
164 $jobs = $asset->
getJobs(
'cron_job', FALSE);
167 $o->
note(translate(
'cron_no_jobs_registered'));
170 $total_assets = count($jobs);
171 $num_pages = ceil($total_assets / $num_per_page);
173 $link_offset = array_get_index($_POST, $prefix.
'_link_offset', 0);
176 if ( (round(($link_offset + $num_per_page) / $num_per_page)) > (ceil($total_assets / $num_per_page)) ) {
177 $link_offset = (ceil($total_assets / $num_per_page)-1)*$num_per_page;
189 for ($i = 0, $total = count($jobs); $i < $total; $i++) {
190 $w = $jobs[$i]->attr(
'when');
191 $whens[substr($w, 0, 2)][$i] = $jobs[$i]->attr(
'when');
195 <!-- start print pagination bar top -->
197 <table
class=
"sq-backend-table">
198 <tr><td
class=
"sq-backend-table-header-header"><b>
200 hidden_field($prefix.
'_link_offset', $link_offset);
201 if ($link_offset > 0) {
203 <a title=
"<?php echo translate('pagination_go_to_first') ?>" style=
"text-decoration: none; color: #fff" href=
"#" onClick=
"Javascript: set_hidden_field('<?php echo $prefix ?>_link_offset', '0'); set_hidden_field('process_form', '0'); submit_form(); return false;">
206 ?><span title=
"<?php echo translate('pagination_cannot_go_further_back') ?>" style=
"color: #333"><?php
211 if ($link_offset > 0) {
216 ?> <?php
217 if ($link_offset > 0) {
218 ?><a title=
"<?php echo translate('pagination_go_to_previous') ?>" style=
"text-decoration: none; color: #fff" href=
"#" onClick=
"Javascript: set_hidden_field('<?php echo $prefix ?>_link_offset', '<?php echo $link_offset - $num_per_page; ?>'); set_hidden_field('process_form', '0'); submit_form(); return false;"><?php
220 ?><span title=
"<?php echo translate('pagination_cannot_go_further_back') ?>" style=
"color: #333"><?php
225 if ($link_offset > 0) {
231 <?php echo translate(
'page_number', round(($link_offset + $num_per_page) / $num_per_page), ceil($total_assets / $num_per_page)); ?>
233 if (($link_offset + $num_per_page) < $total_assets) {
234 ?><a title=
"<?php echo translate('pagination_go_to_next') ?>" style=
"text-decoration: none; color: #fff" href=
"#" onClick=
"Javascript: set_hidden_field('<?php echo $prefix ?>_link_offset', '<?php echo $link_offset + $num_per_page; ?>'); set_hidden_field('process_form', '0'); submit_form(); return false;"><?php
236 ?><span title=
"<?php echo translate('pagination_cannot_go_further_forward') ?>" style=
"color: #333"><?php
241 if (($link_offset + $num_per_page) < $total_assets) {
246 ?> <?php
247 if (($link_offset + $num_per_page) < $total_assets) {
248 ?><a title=
"<?php echo translate('pagination_go_to_last') ?>" style=
"text-decoration: none; color: #fff" href=
"#" onClick=
"Javascript: set_hidden_field('<?php echo $prefix ?>_link_offset', '<?php echo ($num_pages - 1) * $num_per_page; ?>'); set_hidden_field('process_form', '0'); submit_form(); return false;"><?php
250 ?><span title=
"<?php echo translate('pagination_cannot_go_further_forward') ?>" style=
"color: #333"><?php
255 if (($link_offset + $num_per_page) < $total_assets) {
264 <!-- end print pagination bar -->
267 for (reset($whens); NULL !== ($type = key($whens)); next($whens)) {
268 if (empty($whens[$type]))
continue;
269 asort($whens[$type], SORT_STRING);
272 <table
class=
"sq-backend-table">
274 <td
class=
"sq-backend-table-header">
277 <td
class=
"sq-backend-table-header">
278 <?php echo translate(
'details'); ?>
283 <td
class=
"sq-backend-table-header" style=
"text-align: center;">
284 <?php echo translate(
'delete_question'); ?>
291 foreach ($whens[$type] as $i => $when) {
292 if (!(($counter < $link_offset) || (($link_offset+$num_per_page-1) < $counter))) {
295 <td
class=
"sq-backend-table-cell">
296 <?php echo $jobs[$i]->readableWhen(FALSE); ?>
298 <td
class=
"sq-backend-table-cell">
299 <table border=
"0" cellspacing=
"0" cellpadding=
"0">
301 <td
class=
"sq-backend-table-cell" style=
"font-weight: bold; text-align: right; border-bottom: none">
302 <?php echo translate(
'name'); ?> :
304 <td
class=
"sq-backend-table-cell" style=
"border-bottom: none">
305 <?php echo get_asset_tag_line($jobs[$i]->
id); ?>
309 <td
class=
"sq-backend-table-cell" style=
"font-weight: bold; text-align: right; border-bottom: none">
310 <?php echo translate(
'run_as'); ?> :
312 <td
class=
"sq-backend-table-cell" style=
"border-bottom: none">
314 $user = $jobs[$i]->getRunningUser();
316 echo get_asset_tag_line($user->id);
318 ?><em><?php echo translate(
'system'); ?></em><?php
324 if (($asset->
attr(
'current_job') == $jobs[$i]->id) && ((
int) $asset->
attr(
'run_check') >= (int) $asset->
attr(
'warn_after_num_run_checks'))) {
327 <td colspan=
"2" class=
"sq-backend-table-cell" style=
"border-bottom: none"><span
class=
"sq-backend-warning">This job appears to have deadlocked the Cron Manager</span></td>
337 <td
class=
"sq-backend-table-cell" style=
"text-align: center;">
339 if ($jobs[$i]->canDelete()) {
340 check_box($prefix.
'_remove_jobs[]', $jobs[$i]->id);
383 if (empty($_POST[$prefix.
'_remove_jobs'])) {
388 $jobs = $asset->
getJobs(
'cron_job', FALSE);
389 if (empty($jobs))
return FALSE;
391 for ($i = 0, $total = count($jobs); $i < $total; $i++) {
392 if (in_array($jobs[$i]->
id, $_POST[$prefix.
'_remove_jobs'])) {
414 require_once SQ_FUDGE_PATH.
'/datetime_field/datetime_field.inc';
415 $epoch_date = getdate((
int) $asset->
attr(
'epoch'));
418 'y' => $epoch_date[
'year'],
419 'm' => $epoch_date[
'mon'],
420 'd' => $epoch_date[
'mday'],
421 'h' => $epoch_date[
'hours'],
422 'i' => $epoch_date[
'minutes'],
423 's' => $epoch_date[
'seconds'],
428 'min' =>
'2003-01-01 00:00:00',
429 'max' => ($date[
'year'] + 1).
'-12-31 23:59:59',
430 'allow_circa' =>
'0',
431 'print_format' =>
'd/m/y h:i:s',
432 'show' => Array(
'y',
'm',
'd',
'h',
'i',
's'),
444 $field =
new DateTime_Field($prefix.
'_epoch', $value, $parameters);
445 $value = $field->unitsArrayToStr($value_arr);
446 $field->setValue($value);
468 if ($asset->
writeAccess(
'attributes') && $GLOBALS[
'SQ_SYSTEM']->userRoot()) {
469 $field->printField();
471 echo $field->format();
476 $o->
note($attr->description);
496 if ($asset->
writeAccess(
'attributes') && $GLOBALS[
'SQ_SYSTEM']->userRoot()) {
497 if ($field->processField()) {
498 $value_arr = $field->strToUnitsArray($field->value);
499 $epoch = mktime($value_arr[
'h'], $value_arr[
'i'], $value_arr[
's'], $value_arr[
'm'], $value_arr[
'd'], $value_arr[
'y']);
522 echo $GLOBALS[
'SQ_SYSTEM']->datetime((
int) $asset->
attr(
'last_run'));
540 if ($asset->
attr(
'running') && (int) $asset->
attr(
'run_check') >= (int) $asset->
attr(
'warn_after_num_run_checks')) {
541 $o->
openField(
'<div class="sq-backend-warning" style="text-align: center;">POTENTIAL CRON MANAGER DEAD LOCK DETECTED</div>',
'new_line');
542 if ($GLOBALS[
'SQ_SYSTEM']->userRoot()) {
544 $current_job_id = $asset->
attr(
'current_job');
548 <td
class=
"sq-backend-data">
549 <?php echo translate(
'cron_deadlock_warning_section_1', $asset->
attr(
'warn_after_num_run_checks')); ?>
550 <ol
class=
"sq-backend-data">
551 <li
class=
"sq-backend-data"><?php echo translate(
'cron_deadlock_warning_list_item_1'); ?></li>
552 <li
class=
"sq-backend-data"><?php echo translate(
'cron_deadlock_warning_list_item_2'); ?></li>
556 if (!empty($current_job_id)) {
558 <p
class=
"sq-backend-data">
559 <?php echo translate(
'cron_deadlock_warning_offending_job', get_asset_tag_line($current_job_id)); ?>
564 <?php echo translate(
'cron_deadlock_warning_check_error_log', hide_system_root(SQ_LOG_PATH).
'/'.$asset->error_log_file_name.SQ_CONF_LOG_EXTENSION); ?>
565 <p
class=
"sq-backend-data"><?php echo translate(
'cron_deadlock_warning_section_2'); ?></p>
566 <p
class=
"sq-backend-data">
567 <b><?php echo translate(
'cron_deadlock_warning_section_3'); ?></b>
572 <td valign=
"top" class=
"sq-backend-data">
574 check_box($prefix.
'_force_remove_lock');
575 label(translate(
'cron_force_lock_removal'));
580 <td valign=
"top" class=
"sq-backend-data">
581 <?php security_key(25, 30, 2, TRUE); ?>
587 echo translate(
'cron_deadlock_must_acquire_lock');
590 echo translate(
'cron_deadlock_warning_contact_root');
595 $o->
openField(translate(
'cron_manager_appears_to_be_fine'),
'new_line');
616 if (empty($_POST[$prefix.
'_force_remove_lock'])) {
620 if ($asset->
attr(
'running') && (int) $asset->
attr(
'run_check') >= (int) $asset->
attr(
'warn_after_num_run_checks')) {
622 if ($GLOBALS[
'SQ_SYSTEM']->userRoot() && $asset->
writeAccess(
'all')) {
623 if (validate_security_key()) {
629 trigger_localised_error(
'CRON0013', E_USER_NOTICE);
651 $hours_array = Array(
678 0 => translate(
'sunday'),
679 1 => translate(
'monday'),
680 2 => translate(
'tuesday'),
681 3 => translate(
'wednesday'),
682 4 => translate(
'thursday'),
683 5 => translate(
'friday'),
684 6 => translate(
'saturday'),
687 $write_access = $asset->
writeAccess(
'all') && $GLOBALS[
'SQ_SYSTEM']->userRoot();
689 $exclude_times = $asset->
attr(
'exclude_times');
691 if ($write_access || !empty($exclude_times)) {
693 <table
class=
"sq-backend-table">
695 <th
class=
"sq-backend-table-header"><?php echo translate(
'cron_excluded_time') ?></th>
698 ?><th
class=
"sq-backend-table-header"><?php echo translate(
'delete') ?></th><?php
707 foreach ($exclude_times as $key => $details) {
711 $field_prefix = $prefix.
'_exlude_times['.$key.
']';
713 combo_box($field_prefix.
'[from]', $hours_array, FALSE, $details[
'from']);
714 $from = ob_get_contents();
717 combo_box($field_prefix.
'[to]', $hours_array, FALSE, $details[
'to']);
718 $to = ob_get_contents();
721 combo_box($field_prefix.
'[days]', $days_array, TRUE, $details[
'days']);
722 $days = ob_get_contents();
724 ?><td
class=
"sq-backend-table-cell"><?php
725 echo translate(
'cron_excluded_time_hour', $from, $to);
726 echo translate(
'cron_excluded_time_days', $days);
727 ?></td><td
class=
"sq-backend-table-cell"><?php
728 check_box($field_prefix.
'[delete]', TRUE, FALSE);?></td></tr><?php
732 <tr><td colspan=
"2">Add <?php check_box($prefix.
'_add_exclude_time', TRUE, FALSE); ?></tr>
736 if (!empty($exclude_times)) {
738 foreach ($exclude_times as $key => $details) {
742 $from = $hours_array[$details[
'from']];
743 $to = $hours_array[$details[
'to']];
744 if (!empty($details[
'days'])) {
745 $selected_days = Array();
746 foreach ($details[
'days'] as $day) {
747 $selected_days[] = $days_array[$day];
749 $days = implode(
', ', $selected_days);
751 ?><td
class=
"sq-backend-table-cell" colspan=
"2"><?php
752 echo translate(
'cron_excluded_time_hour', $from, $to);
754 if (count($selected_days) == 7) {
755 echo translate(
'cron_excluded_time_every_day');
757 echo translate(
'cron_excluded_time_days', $days);
763 echo translate(
'cron_excluded_not_specified');
767 if ($write_access || !empty($exclude_times)) {
771 return $write_access;
790 $exlude_times = Array();
791 if (isset($_POST[$prefix.
'_exlude_times'])) {
793 foreach ($_POST[$prefix.
'_exlude_times'] as $key => $exclude_period) {
794 if (isset($_POST[$prefix.
'_exlude_times'][$key][
'delete'])) {
798 if (!isset($exclude_period[
'days'])) {
799 $exclude_period[
'days'] = Array();
802 $exlude_times[] = $exclude_period;
806 if (isset($_POST[$prefix.
'_add_exclude_time'])) {
808 $new_exclude_time = Array();
809 $new_exclude_time[
'from'] = 0;
810 $new_exclude_time[
'to'] = 0;
811 $new_exclude_time[
'days'] = Array();
812 $exlude_times[] = $new_exclude_time;
817 return $asset->
setAttrValue(
'exclude_times', $exlude_times);
837 $hours_array = Array(
864 $write_access = $asset->
writeAccess(
'all') && $GLOBALS[
'SQ_SYSTEM']->userRoot();
866 $lm = $GLOBALS[
'SQ_SYSTEM']->getLogManager();
867 $log_rotate_time = $lm->attr(
'log_rotate_time');
870 combo_box($prefix.
'_log_rotate_time', $hours_array, FALSE, $log_rotate_time);
872 echo $hours_array[$log_rotate_time];
875 echo translate(
'cron_log_rotate_time_desc2');
877 return $write_access;
894 $lm = $GLOBALS[
'SQ_SYSTEM']->getLogManager();
895 if (isset($_POST[$prefix.
'_log_rotate_time'])) {
896 $log_rotate_time = (int) $_POST[$prefix.
'_log_rotate_time'];
898 $GLOBALS[
'SQ_SYSTEM']->am->acquireLock($lm->id,
'attributes');
899 $lm->setAttrValue(
'log_rotate_time', $log_rotate_time);
900 $lm->saveAttributes();
901 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($lm->id,
'attributes');
925 $users = $asset->
attr(
'dead_lock_email_to');
928 $write_access = $asset->
writeAccess(
'all') && $GLOBALS[
'SQ_SYSTEM']->userRoot();
931 multiple_asset_finder($prefix.
'_dead_lock_emails_to', $users, Array(
'user' =>
'D',
'user_group' =>
'D'));
935 foreach ($users as $assetid) {
936 if ($assetid ==
'0')
continue;
937 echo
'<li>'.get_asset_tag_line($assetid).
'</li>';
959 if (!isset($_POST[$prefix.
'_dead_lock_emails_to']))
return FALSE;
961 $new_users = $_POST[$prefix.
'_dead_lock_emails_to'];
962 $users_to_mail = Array();
963 foreach ($new_users as $index => $new_user) {
965 if ($new_user[
'assetid'] ==
'0' || $new_user[
'assetid'] ==
'12')
continue;
966 $users_to_mail[] = $new_user[
'assetid'];
970 $new_value = serialize($users_to_mail);