Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
cron_manager_edit_fns.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
19 
32 {
33 
34 
40  function __construct()
41  {
42  parent::__construct();
43 
44  $this->static_screens = Array(
45  'details' => Array(
46  'name' => translate('view_jobs'),
47  'force_unlock' => FALSE,
48  ),
49  'permissions' => Array(
50  'name' => translate('permissions'),
51  'force_unlock' => TRUE,
52  ),
53  'logs' => Array(
54  'name' => translate('logs'),
55  'force_unlock' => TRUE,
56  ),
57  );
58 
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']);
69 
70  }//end constructor
71 
72 
82  public function getWhenBoxHoursMins(Cron_Manager $cron_mgr, $one_off)
83  {
84  $repeating = !$one_off; // for easier reading
85 
86  $options = Array(
87  'mins' => Array(),
88  'hours' => Array(),
89  );
90 
91  $one_hour = 60 * 60;
92  $one_day = 24 * $one_hour;
93 
94  $refresh_secs = (int) $cron_mgr->attr('refresh_time');
95  $refresh_mins = floor($refresh_secs / 60);
96  $refresh_hours = floor($refresh_mins / 60);
97 
98  $epoch_date = getdate($cron_mgr->attr('epoch'));
99 
100  // how often in an hour do we refresh
101  if ($refresh_mins == 0) {
102  $num_refreshes = 60;
103  } else if ($refresh_mins >= 60) {
104  $num_refreshes = 1;
105  } else {
106  $num_refreshes = floor(60 / $refresh_mins);
107  }
108 
109  if ($one_off) {
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);
113  }
114  } else if ($repeating) {
115  // handle the minute option differently for a repeating (TI) job
116  // showing minute options in the selection box as multiple of refresh time
117  for ($i = 0; $i < 60; $i += (60 / $num_refreshes)) {
118  $options['mins'][] = $i;
119  }
120  }
121  sort($options['mins']);
122 
123  // how often in an day do we refresh
124  if ($refresh_hours == 0) {
125  $num_refreshes = 24;
126  } else if ($refresh_hours >= 24) {
127  $num_refreshes = 1;
128  } else {
129  $num_refreshes = floor(24 / $refresh_hours);
130  }
131 
132  if ($one_off) {
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);
136  }
137  } else if ($repeating) {
138  // handle the hour option differently for a repeating (TI) job
139  // showing hour options in the selection box as multiple of refresh time
140  for ($i = 0; $i < 24; $i += (24 / $num_refreshes)) {
141  $options['hours'][] = $i;
142  }
143  }
144 
145  sort($options['hours']);
146 
147  return $options;
148 
149  }//end getWhenBoxHoursMins()
150 
151 
162  public function paintJobs(Cron_Manager $asset, Backend_Outputter $o, $prefix)
163  {
164  $jobs = $asset->getJobs('cron_job', FALSE);
165  if (empty($jobs)) {
166  $o->openField('');
167  $o->note(translate('cron_no_jobs_registered'));
168  } else {
169  $num_per_page = 20;
170  $total_assets = count($jobs);
171  $num_pages = ceil($total_assets / $num_per_page);
172 
173  $link_offset = array_get_index($_POST, $prefix.'_link_offset', 0);
174 
175  // if the page number is greater to the total of pages
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;
178  }
179  $whens = Array(
180  'OO' => Array(),
181  'ET' => Array(),
182  'HR' => Array(),
183  'DL' => Array(),
184  'WK' => Array(),
185  'MT' => Array(),
186  'YR' => Array(),
187  );
188 
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');
192  }
193  ?>
194 
195  <!-- start print pagination bar top -->
196  <?php $o->openField('', 'new_line')?>
197  <table class="sq-backend-table">
198  <tr><td class="sq-backend-table-header-header"><b>
199  <?php
200  hidden_field($prefix.'_link_offset', $link_offset);
201  if ($link_offset > 0) {
202  ?>
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;">
204  <?php
205  } else {
206  ?><span title="<?php echo translate('pagination_cannot_go_further_back') ?>" style="color: #333"><?php
207  }
208  ?>
209  &lt;&lt;
210  <?php
211  if ($link_offset > 0) {
212  ?></a><?php
213  } else {
214  ?></span><?php
215  }
216  ?> &nbsp; &nbsp; <?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
219  } else {
220  ?><span title="<?php echo translate('pagination_cannot_go_further_back') ?>" style="color: #333"><?php
221  }
222  ?>
223  &lt;
224  <?php
225  if ($link_offset > 0) {
226  ?></a><?php
227  } else {
228  ?></span><?php
229  }
230  ?>
231  &nbsp; &nbsp; <?php echo translate('page_number', round(($link_offset + $num_per_page) / $num_per_page), ceil($total_assets / $num_per_page)); ?> &nbsp; &nbsp;
232  <?php
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
235  } else {
236  ?><span title="<?php echo translate('pagination_cannot_go_further_forward') ?>" style="color: #333"><?php
237  }
238  ?>
239  &gt;
240  <?php
241  if (($link_offset + $num_per_page) < $total_assets) {
242  ?></a><?php
243  } else {
244  ?></span><?php
245  }
246  ?> &nbsp; &nbsp; <?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
249  } else {
250  ?><span title="<?php echo translate('pagination_cannot_go_further_forward') ?>" style="color: #333"><?php
251  }
252  ?>
253  &gt;&gt;
254  <?php
255  if (($link_offset + $num_per_page) < $total_assets) {
256  ?></a><?php
257  } else {
258  ?></span><?php
259  }
260  ?>
261  </b></td><tr>
262  </table>
263  <?php $o->closeField(); ?>
264  <!-- end print pagination bar -->
265  <?php
266  $counter = 0;
267  for (reset($whens); NULL !== ($type = key($whens)); next($whens)) {
268  if (empty($whens[$type])) continue;
269  asort($whens[$type], SORT_STRING);
270  $o->openField(Cron_Job::whenTypeName($type), 'new_line');
271  ?>
272  <table class="sq-backend-table">
273  <tr>
274  <td class="sq-backend-table-header">
275  When
276  </td>
277  <td class="sq-backend-table-header">
278  <?php echo translate('details'); ?>
279  </td>
280  <?php
281  if ($asset->writeAccess('links')) {
282  ?>
283  <td class="sq-backend-table-header" style="text-align: center;">
284  <?php echo translate('delete_question'); ?>
285  </td>
286  <?php
287  }//end if
288  ?>
289  </tr>
290  <?php
291  foreach ($whens[$type] as $i => $when) {
292  if (!(($counter < $link_offset) || (($link_offset+$num_per_page-1) < $counter))) {
293  ?>
294  <tr>
295  <td class="sq-backend-table-cell">
296  <?php echo $jobs[$i]->readableWhen(FALSE); ?>
297  </td>
298  <td class="sq-backend-table-cell">
299  <table border="0" cellspacing="0" cellpadding="0">
300  <tr>
301  <td class="sq-backend-table-cell" style="font-weight: bold; text-align: right; border-bottom: none">
302  <?php echo translate('name'); ?> :&nbsp;
303  </td>
304  <td class="sq-backend-table-cell" style="border-bottom: none">
305  <?php echo get_asset_tag_line($jobs[$i]->id); ?>
306  </td>
307  </tr>
308  <tr>
309  <td class="sq-backend-table-cell" style="font-weight: bold; text-align: right; border-bottom: none">
310  <?php echo translate('run_as'); ?> :&nbsp;
311  </td>
312  <td class="sq-backend-table-cell" style="border-bottom: none">
313  <?php
314  $user = $jobs[$i]->getRunningUser();
315  if ($user) {
316  echo get_asset_tag_line($user->id);
317  } else {
318  ?><em><?php echo translate('system'); ?></em><?php
319  }
320  ?>
321  </td>
322  </tr>
323  <?php
324  if (($asset->attr('current_job') == $jobs[$i]->id) && ((int) $asset->attr('run_check') >= (int) $asset->attr('warn_after_num_run_checks'))) {
325  ?>
326  <tr>
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>
328  </tr>
329  <?php
330  }
331  ?>
332  </table>
333  </td>
334  <?php
335  if ($asset->writeAccess('links')) {
336  ?>
337  <td class="sq-backend-table-cell" style="text-align: center;">
338  <?php
339  if ($jobs[$i]->canDelete()) {
340  check_box($prefix.'_remove_jobs[]', $jobs[$i]->id);
341  } else {
342  echo '&nbsp;';
343  }//end if
344  ?>
345  </td>
346  <?php
347  }//end if
348  ?>
349  </tr>
350  <?php
351  }//end if
352  $counter++;
353  }//end foreach
354  ?>
355  </table>
356  <?php
357  $o->closeField();
358 
359  }//end for
360 
361  ?>
362  </table>
363  <?php
364 
365  }//end else
366  return TRUE;
367 
368  }//end paintJobs()
369 
370 
381  public function processJobs(Cron_Manager $asset, Backend_Outputter $o, $prefix)
382  {
383  if (empty($_POST[$prefix.'_remove_jobs'])) {
384  return FALSE;
385  }
386  if (!$asset->writeAccess('links')) return FALSE;
387 
388  $jobs = $asset->getJobs('cron_job', FALSE);
389  if (empty($jobs)) return FALSE;
390 
391  for ($i = 0, $total = count($jobs); $i < $total; $i++) {
392  if (in_array($jobs[$i]->id, $_POST[$prefix.'_remove_jobs'])) {
393  $asset->removeJob($jobs[$i]);
394  }
395  }
396 
397  return TRUE;
398 
399  }//end processJobs()
400 
401 
412  protected function _getEpochDateTimeField(Cron_Manager $asset, $prefix)
413  {
414  require_once SQ_FUDGE_PATH.'/datetime_field/datetime_field.inc';
415  $epoch_date = getdate((int) $asset->attr('epoch'));
416 
417  $value_arr = Array(
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'],
424  );
425 
426  $date = getdate();
427  $parameters = Array(
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'),
433  'style' => Array(
434  'y' => 's',
435  'm' => 's',
436  'd' => 's',
437  'h' => 's',
438  'i' => 's',
439  's' => 's',
440  ),
441  );
442 
443  $value = '';
444  $field = new DateTime_Field($prefix.'_epoch', $value, $parameters);
445  $value = $field->unitsArrayToStr($value_arr);
446  $field->setValue($value);
447 
448  return $field;
449 
450  }//end _getEpochDateTimeField()
451 
452 
463  public function paintEpoch(Cron_Manager $asset, Backend_Outputter $o, $prefix)
464  {
465  $field = $this->_getEpochDateTimeField($asset, $prefix);
466 
467  // take into account lock, plus only root can edit
468  if ($asset->writeAccess('attributes') && $GLOBALS['SQ_SYSTEM']->userRoot()) {
469  $field->printField();
470  } else {
471  echo $field->format();
472  }//end if
473 
474  $attr = $asset->getAttribute('epoch');
475  echo '<br />&nbsp;';
476  $o->note($attr->description);
477 
478  }//end paintEpoch()
479 
480 
491  public function processEpoch(Cron_Manager $asset, Backend_Outputter $o, $prefix)
492  {
493  $field = $this->_getEpochDateTimeField($asset, $prefix);
494 
495  // take into account lock, plus only root can edit
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']);
500  return $asset->setAttrValue('epoch', $epoch);
501 
502  }//end if
503  }//end if
504 
505  return FALSE;
506 
507  }//end processEpoch()
508 
509 
520  public function paintLastRun(Cron_Manager $asset, Backend_Outputter $o, $prefix)
521  {
522  echo $GLOBALS['SQ_SYSTEM']->datetime((int) $asset->attr('last_run'));
523 
524  }//end paintLastRun()
525 
526 
537  public function paintDeadLockStatus(Cron_Manager $asset, Backend_Outputter $o, $prefix)
538  {
539  // if we have a suspicion of being in DeadLock, then allow them to override
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()) {
543  if ($asset->writeAccess('all')) {
544  $current_job_id = $asset->attr('current_job');
545  ?>
546  <table border="0">
547  <tr>
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>
553  </ol>
554 
555  <?php
556  if (!empty($current_job_id)) {
557  ?>
558  <p class="sq-backend-data">
559  <?php echo translate('cron_deadlock_warning_offending_job', get_asset_tag_line($current_job_id)); ?>
560  </p>
561  <?php
562  }
563  ?>
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>
568  </p>
569  </td>
570  </tr>
571  <tr>
572  <td valign="top" class="sq-backend-data">
573  <?php
574  check_box($prefix.'_force_remove_lock');
575  label(translate('cron_force_lock_removal'));
576  ?>
577  </td>
578  </tr>
579  <tr>
580  <td valign="top" class="sq-backend-data">
581  <?php security_key(25, 30, 2, TRUE); ?>
582  </td>
583  </tr>
584  </table>
585  <?php
586  } else {
587  echo translate('cron_deadlock_must_acquire_lock');
588  }
589  } else {
590  echo translate('cron_deadlock_warning_contact_root');
591  }//end if
592 
593  // else everything is OK
594  } else {
595  $o->openField(translate('cron_manager_appears_to_be_fine'), 'new_line');
596 
597  }//end if run_check
598 
599  return TRUE;
600 
601  }//end paintDeadLockStatus()
602 
603 
614  public function processDeadLockStatus(Cron_Manager $asset, Backend_Outputter $o, $prefix)
615  {
616  if (empty($_POST[$prefix.'_force_remove_lock'])) {
617  return FALSE;
618  }
619 
620  if ($asset->attr('running') && (int) $asset->attr('run_check') >= (int) $asset->attr('warn_after_num_run_checks')) {
621  // if we have a suspicion of being in DeadLock, then allow them to override
622  if ($GLOBALS['SQ_SYSTEM']->userRoot() && $asset->writeAccess('all')) {
623  if (validate_security_key()) {
624  $asset->setAttrValue('running', FALSE);
625  $asset->setAttrValue('run_check', 0);
626  return TRUE;
627 
628  } else {
629  trigger_localised_error('CRON0013', E_USER_NOTICE);
630  }//end if
631  }//end if
632  }//endif
633 
634  return FALSE;
635 
636  }//end processDeadLockStatus()
637 
638 
649  public function paintExcludedTime(Cron_Manager $asset, Backend_Outputter $o, $prefix)
650  {
651  $hours_array = Array(
652  0 => '00',
653  1 => '01',
654  2 => '02',
655  3 => '03',
656  4 => '04',
657  5 => '05',
658  6 => '06',
659  7 => '07',
660  8 => '08',
661  9 => '09',
662  10 => '10',
663  11 => '11',
664  12 => '12',
665  13 => '13',
666  14 => '14',
667  15 => '15',
668  16 => '16',
669  17 => '17',
670  18 => '18',
671  19 => '19',
672  20 => '20',
673  21 => '21',
674  22 => '22',
675  23 => '23',
676  );
677  $days_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'),
685  );
686 
687  $write_access = $asset->writeAccess('all') && $GLOBALS['SQ_SYSTEM']->userRoot();
688 
689  $exclude_times = $asset->attr('exclude_times');
690 
691  if ($write_access || !empty($exclude_times)) {
692  ?>
693  <table class="sq-backend-table">
694  <tr>
695  <th class="sq-backend-table-header"><?php echo translate('cron_excluded_time') ?></th>
696  <?php
697  if ($write_access) {
698  ?><th class="sq-backend-table-header"><?php echo translate('delete') ?></th><?php
699  }
700  ?>
701  </tr><?php
702 
703  }
704 
705  if ($write_access) {
706 
707  foreach ($exclude_times as $key => $details) {
708  ?>
709  <tr>
710  <?php
711  $field_prefix = $prefix.'_exlude_times['.$key.']';
712  ob_start();
713  combo_box($field_prefix.'[from]', $hours_array, FALSE, $details['from']);
714  $from = ob_get_contents();
715  ob_end_clean();
716  ob_start();
717  combo_box($field_prefix.'[to]', $hours_array, FALSE, $details['to']);
718  $to = ob_get_contents();
719  ob_end_clean();
720  ob_start();
721  combo_box($field_prefix.'[days]', $days_array, TRUE, $details['days']);
722  $days = ob_get_contents();
723  ob_end_clean();
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
729  }
730 
731  ?>
732  <tr><td colspan="2">Add <?php check_box($prefix.'_add_exclude_time', TRUE, FALSE); ?></tr>
733  <?php
734 
735  } else {
736  if (!empty($exclude_times)) {
737 
738  foreach ($exclude_times as $key => $details) {
739  ?>
740  <tr>
741  <?php
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];
748  }
749  $days = implode(', ', $selected_days);
750  }
751  ?><td class="sq-backend-table-cell" colspan="2"><?php
752  echo translate('cron_excluded_time_hour', $from, $to);
753  if (!empty($days)) {
754  if (count($selected_days) == 7) {
755  echo translate('cron_excluded_time_every_day');
756  } else {
757  echo translate('cron_excluded_time_days', $days);
758  }
759  }
760  ?></td></tr><?php
761  }
762  } else {
763  echo translate('cron_excluded_not_specified');
764  }
765  }
766 
767  if ($write_access || !empty($exclude_times)) {
768  ?></table><?php
769  }
770 
771  return $write_access;
772 
773  }//end paintExcludedTime()
774 
775 
786  public function processExcludedTime(Cron_Manager $asset, Backend_Outputter $o, $prefix)
787  {
788  $modified = FALSE;
789 
790  $exlude_times = Array();
791  if (isset($_POST[$prefix.'_exlude_times'])) {
792  $modified = TRUE;
793  foreach ($_POST[$prefix.'_exlude_times'] as $key => $exclude_period) {
794  if (isset($_POST[$prefix.'_exlude_times'][$key]['delete'])) {
795  continue;
796  }
797 
798  if (!isset($exclude_period['days'])) {
799  $exclude_period['days'] = Array();
800  }
801 
802  $exlude_times[] = $exclude_period;
803  }
804  }
805 
806  if (isset($_POST[$prefix.'_add_exclude_time'])) {
807  $modified = TRUE;
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;
813 
814  }
815 
816  if ($modified) {
817  return $asset->setAttrValue('exclude_times', $exlude_times);
818  }
819 
820  return FALSE;
821 
822  }//end processExcludedTime()
823 
824 
835  public function paintLogRotateTime(Cron_Manager $asset, Backend_Outputter $o, $prefix)
836  {
837  $hours_array = Array(
838  0 => '00',
839  1 => '01',
840  2 => '02',
841  3 => '03',
842  4 => '04',
843  5 => '05',
844  6 => '06',
845  7 => '07',
846  8 => '08',
847  9 => '09',
848  10 => '10',
849  11 => '11',
850  12 => '12',
851  13 => '13',
852  14 => '14',
853  15 => '15',
854  16 => '16',
855  17 => '17',
856  18 => '18',
857  19 => '19',
858  20 => '20',
859  21 => '21',
860  22 => '22',
861  23 => '23',
862  );
863 
864  $write_access = $asset->writeAccess('all') && $GLOBALS['SQ_SYSTEM']->userRoot();
865 
866  $lm = $GLOBALS['SQ_SYSTEM']->getLogManager();
867  $log_rotate_time = $lm->attr('log_rotate_time');
868 
869  if ($write_access) {
870  combo_box($prefix.'_log_rotate_time', $hours_array, FALSE, $log_rotate_time);
871  } else {
872  echo $hours_array[$log_rotate_time];
873  }//end if
874 
875  echo translate('cron_log_rotate_time_desc2');
876 
877  return $write_access;
878 
879  }//end paintLogRotateTime()
880 
881 
892  public function processLogRotateTime(Cron_Manager $asset, Backend_Outputter $o, $prefix)
893  {
894  $lm = $GLOBALS['SQ_SYSTEM']->getLogManager();
895  if (isset($_POST[$prefix.'_log_rotate_time'])) {
896  $log_rotate_time = (int) $_POST[$prefix.'_log_rotate_time'];
897 
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');
902 
903  return TRUE;
904  }
905 
906  return FALSE;
907 
908  }//end processLogRotateTime()
909 
910 
921  public function paintEmailSelection(Cron_Manager $asset, Backend_Outputter $o, $prefix)
922  {
923 
924  // get all the user already defined to send the dead lock emails to
925  $users = $asset->attr('dead_lock_email_to');
926 
928  $write_access = $asset->writeAccess('all') && $GLOBALS['SQ_SYSTEM']->userRoot();
929 
930  if ($write_access) {
931  multiple_asset_finder($prefix.'_dead_lock_emails_to', $users, Array('user' => 'D', 'user_group' => 'D'));
932  } else {
933  ?><ul><?php
934 
935  foreach ($users as $assetid) {
936  if ($assetid == '0') continue;
937  echo '<li>'.get_asset_tag_line($assetid).'</li>';
938  }
939  ?></ul><?php
940  }
941 
942  return TRUE;
943 
944  }// end paintEmailSelection()
945 
946 
957  public function processEmailSelection(Cron_Manager $asset, Backend_Outputter $o, $prefix)
958  {
959  if (!isset($_POST[$prefix.'_dead_lock_emails_to'])) return FALSE;
960 
961  $new_users = $_POST[$prefix.'_dead_lock_emails_to'];
962  $users_to_mail = Array();
963  foreach ($new_users as $index => $new_user) {
964  // skip if the assetid is not set or if it is root user
965  if ($new_user['assetid'] == '0' || $new_user['assetid'] == '12') continue;
966  $users_to_mail[] = $new_user['assetid'];
967  }
968 
969  // process new stuff here
970  $new_value = serialize($users_to_mail);
971  $asset->setAttrValue('dead_lock_email_to', $new_value);
972  return $asset->saveAttributes();
973 
974  }// end processEmailSelection()
975 
976 
977 }//end class
978 ?>