Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
details.inc
1 <?php
17 require_once SQ_LIB_PATH.'/html_form/html_form.inc';
18 require_once SQ_FUDGE_PATH.'/general/file_system.inc';
19 
40 function paintDetails(&$owner, &$o, &$ei, $keywords=NULL)
41 {
42  // no static details screen fields relevant to an uncreated asset
43  if (empty($owner->id)) return;
44 
45  $root = $ei->findScreen('static_screen_details');
46  if (is_null($root)) return FALSE;
47 
48  $prefix = $owner->getPrefix();
49  $print_commit_button = FALSE;
50 
51  $display_status_sections = TRUE;
52  $parent_asset_href = '';
53  // check if the asset is linked to its parent exclusively and is dependent
54  $parent_asset_link = $GLOBALS['SQ_SYSTEM']->am->getLinks($owner->id, SQ_SC_LINK_ALL, '', TRUE, 'minor', NULL, TRUE, TRUE);
55  if (!empty($parent_asset_link)) {
56  $display_status_sections = FALSE;
57  $parent_asset_href = $GLOBALS['SQ_SYSTEM']->am->getAssetBackendHref(Array($parent_asset_link[0]['majorid'] => 'details'));
58  }
59 
60  foreach ($root->section as $section) {
61 
62  // only do this if we are not painting a layout
63  if (is_null($keywords)) {
64  // if we are in limbo and this section is not to be printed in limbo - dont print it
65  if (SQ_IN_LIMBO && (!isset($section->attributes()->limbo_access) || (int)$section->attributes()->limbo_access == 0)) {
66  continue;
67  }
68  }
69 
70  $section_keyword_name = strtolower(str_replace(' ', '_', $section->attributes()->name));
71 
72  if (!$ei->_getAccess($owner, $section, $prefix)) {
73  continue;
74  }
75 
76  if (!($num_fields = count($section->children()))) {
77  continue;
78  }
79 
80  ob_start();
81 
82  // If this is the Safe Trash section, hide the section if the asset is
83  // not attached to the Safe Trash cron job
84  $safe_trash_job_link = $GLOBALS['SQ_SYSTEM']->am->getLink($owner->id, SQ_LINK_NOTICE, 'cron_job_attempt_safe_trash', TRUE, NULL, 'minor');
85  $avoiding_safe_trash_section = ($section->attributes()->name == 'Safe Trash Status') && !$safe_trash_job_link;
86  if (!$avoiding_safe_trash_section) {
87  $o->openSection(array_get_index($section->attributes(), 'display_name', $section->attributes()->name));
88  }
89 
90  foreach ($section->field as $field) {
91 
92  switch (strtolower($field->attributes()->code)) {
93 
94  case 'safe_trash' :
95 
96  if (!$avoiding_safe_trash_section) {
97  $safe_trash_enabled = $GLOBALS['SQ_SYSTEM']->getUserPrefs('user', 'SQ_USER_SAFE_TYPE3_TRASH');
98  $safe_trash_errors = $GLOBALS['SQ_SYSTEM']->am->canSafeTrashAsset($owner->id);
99  $o->openRaw();
100  if ($safe_trash_enabled) {
101  if (empty($safe_trash_errors)) {
102  ?>
103  <div><?php echo translate('safe_trash_line_common'); ?><br/>
104  <?php echo translate('safe_trash_line_unblocked'); ?></div>
105  <?php
106  } else {
107  ?>
108  <div class="sq-backend-warning"><strong><?php echo translate('safe_trash_line_common'); ?><br/>
109  <?php echo translate('safe_trash_line_still_blocked'); ?></strong></div>
110 
111  <ul>
112  <?php
113  if (!empty($safe_trash_errors['status'])) {
114  ?>
115  <li><?php echo translate('safe_trash_line_blocked_status'); ?></li>
116  <?php
117  }
118  ?>
119  <?php
120  if (!empty($safe_trash_errors['links'])) {
121  ?>
122  <li><?php echo translate('safe_trash_line_blocked_links', $owner->getBackendHref('linking')); ?></li>
123  <?php
124  }
125  ?>
126  <?php
127  if (!empty($safe_trash_errors['children'])) {
128  ?>
129  <li><?php echo translate('safe_trash_line_blocked_children'); ?></li>
130  <?php
131  }
132  ?>
133  </ul></div>
134  <?php
135  }
136  } else {
137  ?>
138  <div><?php echo translate('safe_trash_line_common'); ?><br/>
139  <?php echo translate('safe_trash_line_disabled'); ?></div>
140  <?php
141  }
142 
143  $o->closeRaw();
144  }
145 
146  break;
147 
149 
150  case 'status_current' :
151 
152  if (!empty($field->display_name)) {
153  $display_name = translate('current');
154  } else {
155  // If we dont have a display name node then we dont have anything to say
156  $display_name = '';
157  }
158 
159  $o->openField($display_name);
160 
161  ob_start();
162  $need_commit = _paintDetailsCurrentStatus($owner, $o, $prefix);
163  $print_commit_button = $print_commit_button || $need_commit;
164  $contents = ob_get_clean();
165 
166  // If unable to save as a keyword replacement, echo it
167  if (_paintDetailsRegisterKeyword($ei, $keywords, 'fields', 'status_current', $contents) === FALSE) {
168  echo $contents;
169  }
170 
171  $o->closeField();
172 
173  break;
174 
175  case 'status_change' :
176 
177  if (!$display_status_sections) {
178  $o->openField('');
179  echo translate('asset_current_status_change_from_parent',$parent_asset_href[$parent_asset_link[0]['majorid']]);
180  $o->closeField();
181  break;
182  }
183 
184  if (!empty($field->display_name)) {
185  $display_name = translate('change_question');
186  } else {
187  // If we dont have a display name node then we dont have anything to say
188  $display_name = '';
189  }
190 
191 
192  $o->openField($display_name);
193 
194  ob_start();
195  $need_commit = _paintDetailsChangeStatus($owner, $o, $prefix);
196  $print_commit_button = $print_commit_button || $need_commit;
197  $contents = ob_get_clean();
198 
199  // If unable to save as a keyword replacement, echo it
200  if (_paintDetailsRegisterKeyword($ei, $keywords, 'fields', 'status_change', $contents) === FALSE) {
201  echo $contents;
202  }
203 
204  $o->closeField();
205 
206  break;
207 
208  case 'status_future_status' :
209  if (!$display_status_sections) {
210  $o->openField('');
211  echo translate('asset_future_status_change_from_parent',$parent_asset_href[$parent_asset_link[0]['majorid']]);
212  $o->closeField();
213  break;
214  }
215 
216  // One simple edit keyword covers TWO sections here, so
217  // a little more maneuvering is required
218  ob_start();
219  $need_commit = _paintDetailsFutureStatusCurrent($owner, $o, $prefix);
220  $print_commit_button = $print_commit_button || $need_commit;
221  $current_fs_contents = ob_get_clean();
222 
223  ob_start();
224  $need_commit = _paintDetailsFutureStatusNew($owner, $o, $prefix);
225  $print_commit_button = $print_commit_button || $need_commit;
226  $new_fs_contents = ob_get_clean();
227 
228  // If unable to save the lot as a keyword replacement...
229  if (_paintDetailsRegisterKeyword($ei, $keywords, 'fields', 'status_future_status', $current_fs_contents.$new_fs_contents) === FALSE) {
230  // Only show current contents if there are set FS jobs
231  if (empty($current_fs_contents) === FALSE) {
232  $o->openField(translate('scheduled_future_status_change'), 'new_line');
233  echo $current_fs_contents;
234  $o->closeField();
235  }
236 
237  // Only show Add FS section if write access allowed
238  if ($owner->writeAccess()) {
239  $o->openField(translate('add_new_future_status'), 'new_line');
240  echo $new_fs_contents;
241  $o->closeField();
242  }//end if
243 
244  }
245 
246  break;
247 
248  case 'thumbnail_change' :
249 
250  if ($owner->writeAccess('links')) {
251 
252  if (!empty($field->display_name)) {
253  $display_name = translate('change_question');
254  } else {
255  $display_name = '';
256  }
257 
258  $o->openField($display_name);
259 
260  ob_start();
261  $need_commit = _paintDetailsThumbnailChange($owner, $o, $prefix);
262  $print_commit_button = $print_commit_button || $need_commit;
263  $contents = ob_get_clean();
264 
265  // If unable to save as a keyword replacement, echo it
266  if (_paintDetailsRegisterKeyword($ei, $keywords, 'fields', 'thumbnail_change', $contents) === FALSE) {
267  echo $contents;
268  }
269 
270  $o->closeField();
271  }
272 
273  break;
274 
275  case 'thumbnail_current' :
276 
277  if (!empty($field->display_name)) {
278  $display_name = translate('current');
279  } else {
280  $display_name = '';
281  }
282 
283  $o->openField($display_name);
284 
285  ob_start();
286  $need_commit = _paintDetailsThumbnailCurrent($owner, $o, $prefix);
287  $print_commit_button = $print_commit_button || $need_commit;
288  $contents = ob_get_clean();
289 
290  // If unable to save as a keyword replacement, echo it
291  if (_paintDetailsRegisterKeyword($ei, $keywords, 'fields', 'thumbnail_current', $contents) === FALSE) {
292  echo $contents;
293  }
294 
295  $o->closeField();
296 
297  break;
298 
299  }//end switch
300 
301  $note = (string) $field->note;
302  if (!empty($note)) {
303  $o->note($note);
304  }
305 
306  }//end for
307 
308  if (!$avoiding_safe_trash_section) {
309  $o->closeSection();
310  }
311 
312  $section_contents = ob_get_clean();
313 
314  if (_paintDetailsRegisterKeyword($ei, $keywords, 'sections', $section_keyword_name, $section_contents) === FALSE) {
315  echo $section_contents;
316  }
317 
318  }//end for
319 
320  return $print_commit_button;
321 
322 }//end paintDetails()
323 
324 
337 function _paintStatusChange(&$owner, &$o, $prefix, $statii, $default_status=0)
338 {
339  if (!empty($statii)) {
340  $statii = array_reverse($statii, TRUE);
341  $statii[0] = '';
342  $statii = array_reverse($statii, TRUE);
343  combo_box($prefix.'_change_status', $statii, FALSE, $default_status);
344 
345  // Test whether we have a status that may need the stream
346  $has_pending_status = FALSE;
347  $has_approved_status = FALSE;
348  foreach ($statii as $status_code => $status_text) {
349  if (($status_code & SQ_SC_STATUS_PENDING) > 0) {
350  $has_pending_status = TRUE;
351  break;
352  }
353 
354  if (($status_code & SQ_SC_STATUS_ALL_APPROVED) > 0) {
355  $has_approved_status = TRUE;
356  break;
357  }
358  }
359 
360  // Workflow streams activate to those with admin permission where:
361  // - one of the options is a Pending status (either a Apply for Approval,
362  // or Place Up for Review);
363  // - the current status is either a "can approve" state (Safe Edit or
364  // U/C), or Live (otherwise we couldn't run Up for Review on a stream).
365  if (($owner->adminAccess() === TRUE) && (($owner->status & (SQ_STATUS_LIVE | SQ_SC_STATUS_CAN_APPROVE)) > 0) && (($has_pending_status === TRUE) || ($has_approved_status === TRUE))) {
366  echo '&nbsp;';
367  // If it is possible that we will have a "apply for approval" in the
368  // drop-down, paint the streams box and enable/disable when required.
369  $stream_names = Array(
370  'workflow' => Array(),
371  'bypass' => Array(),
372  );
373 
374  $wfm = $GLOBALS['SQ_SYSTEM']->getWorkflowManager();
375  $schemas = $wfm->getSchemas($owner->id);
376  foreach ($schemas as $schemaid => $granted) {
377  $stream_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($schemaid, SQ_LINK_TYPE_2, 'workflow_stream', TRUE);
378  $streamids = Array();
379  foreach ($stream_links as $stream_link) {
380  $step_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($stream_link['minorid'], SQ_LINK_TYPE_2, 'workflow_step', TRUE);
381  if ($stream_link['value'] !== 'default_stream') {
382  $streamids[] = $stream_link['minorid'];
383  }
384  }
385 
386  if ($has_approved_status === TRUE) {
387  // We can bypass workflow on at least one stream
388  $bypassable_streams = $wfm->getBypassableStreams($owner->id, $schemaid);
389  $bypassable_streams = array_intersect($bypassable_streams, $streamids);
390  $workflowable_streams = array_diff($streamids, $bypassable_streams);
391 
392  $bypass_stream_names = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo($bypassable_streams, 'workflow_stream', TRUE, 'name');
393  $stream_names['bypass'] = array_merge($stream_names['bypass'], $bypass_stream_names);
394  } else {
395  // We cannot bypass (either none work, or metadata is not finished)
396  $workflowable_streams = $streamids;
397  }
398 
399  $workflow_stream_names = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo($workflowable_streams, 'workflow_stream', TRUE, 'name');
400  $stream_names['workflow'] = array_merge($stream_names['workflow'], $workflow_stream_names);
401 
402  }//end foreach schema
403 
404  // Make both types of streams unique, then some streams are in
405  // both columns (possible if multiple schemas applied), eliminate
406  // them from the bypassable column
407  $stream_names['workflow'] = array_unique($stream_names['workflow']);
408  $stream_names['bypass'] = array_unique($stream_names['bypass']);
409  $stream_names['bypass'] = array_diff($stream_names['bypass'], $stream_names['workflow']);
410 
411  // Now generate the options
412  $options = Array(
413  'workflow' => Array(),
414  'bypass' => Array(),
415  );
416 
417  // Work out which set of options the default streams should be placed
418  $default_test = $wfm->testPublish($owner->id, $GLOBALS['SQ_SYSTEM']->user->id, '');
419  if (($has_approved_status === TRUE) && ($default_test === TRUE)) {
420  $options['bypass'] = Array('SQ_USE_DEFAULT' => 'Default Stream');
421  } else {
422  $options['workflow'] = Array('SQ_USE_DEFAULT' => 'Default Stream');
423  }
424 
425  $total_options = 1;
426  foreach (array_keys($stream_names) as $stream_type) {
427  foreach ($stream_names[$stream_type] as $workflow_stream_name) {
428  $options[$stream_type][$workflow_stream_name] = $workflow_stream_name;
429  $total_options++;
430  }
431  }
432 
433  // We have more than one stream, so paint out both drop-downs
434  if (count($options['bypass']) + count($options['workflow']) > 1) {
435  // The combo boxes are named the same, but have different IDs,
436  // and one is always disabled, so only one gets sent.
437  ob_start();
438  combo_box($prefix.'_change_status_stream', $options['bypass'], FALSE, Array(), 0, ' disabled="disabled" id="'.$prefix.'_change_status_stream_bypass"');
439  $cb1 = ob_get_clean();
440 
441  ob_start();
442  combo_box($prefix.'_change_status_stream', $options['workflow'], FALSE, Array(), 0, ' disabled="disabled" id="'.$prefix.'_change_status_stream_workflow"');
443  $cb2 = ob_get_clean();
444 
445  echo translate('workflow_stream_using_workflow_stream', $cb1.$cb2);
446  } else {
447  // Only one option; hide the stream field and chuck it into a hidden field
448  $all_options = $options['bypass'] + $options['workflow'];
449  reset($all_options);
450  hidden_field($prefix.'_change_status_stream', key($all_options));
451  }
452 
453  // Javascript to keep the stream lists happy. The "Apply for Approval"
454  // list is displayed first, and they are switched when "Apply for Approval"
455  // and "Approve" are selected, respectively.
456  ?>
457  <script type="text/javascript">
458  //<![CDATA[
459  var status_cb = document.getElementById("<?php echo $prefix ?>_change_status");
460  var stream_wf_cb = document.getElementById("<?php echo $prefix ?>_change_status_stream_workflow");
461  var stream_byp_cb = document.getElementById("<?php echo $prefix ?>_change_status_stream_bypass");
462 
463  if (stream_byp_cb !== null && stream_byp_cb !== undefined &&
464  stream_wf_cb !== null && stream_wf_cb !== undefined) {
465  if (stream_wf_cb.options.length == 0) {
466  stream_wf_cb.style.display = 'none';
467  } else {
468  stream_byp_cb.style.display = 'none';
469  }//end if
470 
471  status_cb.onchange = function() {
472  if ((this.value & <?php echo SQ_SC_STATUS_PENDING ?>) > 0) {
473  stream_wf_cb.disabled = false;
474  stream_wf_cb.style.display = 'inline';
475  stream_byp_cb.style.display = 'none';
476  } else {
477  stream_wf_cb.disabled = true;
478  }
479 
480  if ((this.value & <?php echo SQ_SC_STATUS_ALL_APPROVED ?>) > 0) {
481  stream_byp_cb.disabled = false;
482  stream_byp_cb.style.display = 'inline';
483  stream_wf_cb.style.display = 'none';
484  } else {
485  stream_byp_cb.disabled = true;
486  }
487  }
488  }//end if
489  // ]]></script>
490  <?php
491  }
492  echo '&nbsp;';
493  check_box($prefix.'_change_status_all_children');
494  label(translate('cascade_status_change'), $prefix.'_change_status_all_children');
495 
496  }
497 
498 }//end _paintStatusChange()
499 
500 
511 function _processStatusChange(&$owner, &$o, $prefix)
512 {
513  if (isset($_POST[$prefix.'_change_status'])) {
514  $dependants_only = (isset($_POST[$prefix.'_change_status_all_children']) && $_POST[$prefix.'_change_status_all_children']) ? FALSE : TRUE;
515  if ($_POST[$prefix.'_change_status'] > 0 || !$dependants_only) {
516  $new_status = 0;
517  if ($_POST[$prefix.'_change_status'] == 0 && !$dependants_only) {
518  $new_status = $owner->status;
519  } else if ($_POST[$prefix.'_change_status'] > 0) {
520  $new_status = $_POST[$prefix.'_change_status'];
521  }
522 
523  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
524  $vars = Array('assetid' => $owner->id, 'new_status' => $new_status, 'dependants_only' => $dependants_only);
525  if (isset($_POST[$prefix.'_change_status_stream'])) {
526  if ($_POST[$prefix.'_change_status_stream'] !== 'SQ_USE_DEFAULT') {
527  $vars['workflow_stream'] = $_POST[$prefix.'_change_status_stream'];
528  }
529  }
530  $hh->queueHipo('hipo_job_edit_status', $vars);
531  }
532  }
533 
534 }//end _processStatusChange()
535 
536 
548 function processDetails(&$owner, &$o, &$ei)
549 {
550  // no static details screen fields relevant to an uncreated asset
551  if (empty($owner->id)) return FALSE;
552 
553  $root = $ei->findScreen('static_screen_details');
554  if (is_null($root)) return FALSE;
555 
556  $prefix = $owner->getPrefix();
557 
558  $is_updated = FALSE;
559 
560  foreach ($root->section as $section) {
561 
562  if (!$ei->_getAccess($owner, $section, $prefix)) {
563  continue;
564  }
565 
566  if (!($num_fields = count($section->children()))) {
567  continue;
568  }
569 
570  foreach ($section->field as $field) {
571 
572  switch (strtolower($field->attributes()->code)) {
573 
574  case 'status_change' :
576  $is_updated = _processDetailsStatusChange($owner, $o, $prefix) || $is_updated;
577  break;
578 
579  case 'status_future_status' :
581  $is_updated = _processDetailsFutureStatusCurrent($owner, $o, $prefix) || $is_updated;
582  $is_updated = _processDetailsFutureStatusNew($owner, $o, $prefix) || $is_updated;
583  break;
584 
585  case 'thumbnail_change' :
587  $is_updated = _processDetailsThumbnailChange($owner, $o, $prefix) || $is_updated;
588  break;
589 
590  }//end switch on code
591 
592  }//end foreach field
593 
594  }//end foreach section
595 
596  return ($is_updated);
597 
598 }//end processDetails()
599 
600 
614 function _paintDetailsRegisterKeyword(Asset_Edit_Interface $ei, $keywords, $type, $name, $content)
615 {
616  // We are not searching for keywords at all
617  if ($keywords === NULL) return FALSE;
618 
619  // We are not searching for this keyword
620  if (isset($keywords[$type][$name]) === FALSE) {
621  return FALSE;
622  }
623 
624  $ei->_tmp['layout_keyword_replacements'][$keywords[$type][$name]] = $content;
625  return TRUE;
626 
627 }//end _paintDetailsRegisterKeyword()
628 
629 
630 //-- PAINTING FUNCTIONS --//
631 
632 
644 function _paintDetailsCurrentStatus(Asset $owner, Backend_Outputter $o, $prefix)
645 {
646  echo get_asset_status_icon($owner->status);
647  echo ' <i>'.$owner->getStatusDescription().'</i>';
648 
649  return FALSE;
650 
651 }//end _paintDetailsCurrentStatus()
652 
653 
654 
666 function _paintDetailsChangeStatus(Asset $owner, Backend_Outputter $o, $prefix)
667 {
668  // only print this field if the status can be changed
669  $statii = $owner->getAvailableStatii();
670  $needs_commit = FALSE;
671 
672  if (empty($statii) === FALSE) {
673  // if this asset is in workflow we do not let the change the status here
674  // because they need to go off to the workflow screen
675  $wfm = $GLOBALS['SQ_SYSTEM']->getWorkflowManager();
676  $running_schemas = $wfm->getSchemas($owner->id, TRUE, TRUE);
677  if (!empty($running_schemas)) {
678  $o->note(translate('asset_currently_in_workflow', $owner->getBackendHref('workflow')));
679  } else {
680  _paintStatusChange($owner, $o, $prefix, $statii);
681  $needs_commit = TRUE;
682  $status = $owner->getStatus();
683  $note = $status->getStatusChangeMessage();
684  if ($note) {
685  $o->note($note);
686  }
687  }
688 
689  }
690 
691  return $needs_commit;
692 
693 }//end _paintDetailsChangeStatus()
694 
695 
707 function _paintDetailsFutureStatusCurrent(Asset $owner, Backend_Outputter $o, $prefix)
708 {
709  // this makes assumptions about how to get the future status jobs for a particular asset, which is the domain of the cron manager.
710  // The problem is that when we ask the future status job to get a list of jobs it, in turn, asks the cron manager to get a list of
711  // jobs, which is turn asks the asset manager to get a list of links under the cron manager that are future status jobs.
712  // In a system with a large number of future status jobs, the details screen will become very slow to load.
713  $fs_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($owner->id, SQ_LINK_NOTICE, 'cron_job_future_status', TRUE, 'minor');
714 
715  if (!empty($fs_links)) {
716  ?>
717  <table class="sq-backend-table">
718  <tr>
719  <td class="sq-backend-table-header"><?php echo translate('status'); ?></td>
720  <td class="sq-backend-table-header"><?php echo translate('when'); ?></td>
721  <td align="center" class="sq-backend-table-header" style="text-align: center;"><?php echo translate('cascade_question'); ?></td>
722  <td align="center" class="sq-backend-table-header" style="text-align: center;"><?php echo translate('delete_question'); ?></td>
723  </tr>
724  <?php
725  for ($k = 0; $k < count($fs_links); $k++) {
726  $fs_job = $GLOBALS['SQ_SYSTEM']->am->getAsset($fs_links[$k]['majorid'], 'cron_job_future_status');
727  ?>
728  <tr>
729  <td class="sq-backend-table-cell">
730  <?php echo $fs_job->statusName(); ?>
731  </td>
732  <td class="sq-backend-table-cell">
733  <?php echo $fs_job->readableWhen(); ?>
734  </td>
735  <td align="center" class="sq-backend-table-cell">
736  <?php
737  if ($fs_job->attr('dependants_only')) {
738  echo translate('no');
739  } else {
740  echo translate('yes');
741  }
742  ?>
743  </td>
744  <td align="center" class="sq-backend-table-cell">
745  <?php
746  if ($fs_job->canDelete()) {
747  check_box($prefix.'_remove_fs[]', $fs_job->id);
748  } else {
749  echo '&nbsp;';
750  }
751  ?>
752  </td>
753  </tr>
754  <?php
755  }//end for
756  ?>
757  </table>
758  <?php
759 
760  }//end if
761 
762  return FALSE;
763 
764 }//end _paintDetailsFutureStatusCurrent()
765 
766 
778 function _paintDetailsFutureStatusNew(Asset $owner, Backend_Outputter $o, $prefix)
779 {
780  if ($owner->writeAccess() === FALSE) return FALSE;
781 
782  $needs_commit = FALSE;
783 
784  $cron_mgr = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('cron_manager');
785 
786  $cron_epoc = (int)$cron_mgr->attr('epoch');
787  $cron_refresh = (int)$cron_mgr->attr('refresh_time');
788 
789  if ($cron_epoc > 0 && $cron_refresh > 0) {
790  require_once SQ_FUDGE_PATH.'/general/datetime.inc';
791  $GLOBALS['SQ_SYSTEM']->am->includeAsset('cron_job_future_status');
792  $fs = new Cron_Job_Future_Status();
793  $edit_fns = $fs->getEditFns();
794 
795  $edit_fns->paintInLineBackend($fs, $o, $prefix.'_new_fs');
796 
797  $o->note(translate('cron_manager_next_run', $cron_mgr->readableRefreshTime(), readable_datetime($cron_mgr->timeOfNextRun())));
798  $needs_commit = TRUE;
799  } else {
800  echo translate('cron_manager_not_configured');
801  }
802 
803  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($cron_mgr);
804 
805  return $needs_commit;
806 
807 }//end _paintDetailsFutureStatusNew()
808 
809 
821 function _paintDetailsThumbnailChange(Asset $owner, Backend_Outputter $o, $prefix)
822 {
823  $edit_fns = $owner->getEditFns();
824  $edit_fns->paintNoticeLinkedAsset($owner, 'thumbnail', Array('image' => 'D'));
825 
826  return TRUE;
827 
828 }//end _paintDetailsThumbnailChange()
829 
830 
842 function _paintDetailsThumbnailCurrent(Asset $owner, Backend_Outputter $o, $prefix)
843 {
844  $thumbnail = NULL;
845  if ($owner->useSystemVersion()) {
846  $notice_links = unserialize(file_to_string($owner->data_path.'/.sq_notice_links'));
847  foreach ($notice_links as $link) {
848  if ($link['value'] == 'thumbnail') {
849  $thumbnail = $GLOBALS['SQ_SYSTEM']->am->getAsset($link['minorid']);
850  break;
851  }
852  }
853  }
854  else {
855  $link = $GLOBALS['SQ_SYSTEM']->am->getLink($owner->id, SQ_LINK_NOTICE, 'image', FALSE, 'thumbnail');
856  if (!empty($link)) {
857  $thumbnail = $GLOBALS['SQ_SYSTEM']->am->getAsset($link['minorid'], $link['minor_type_code']);
858  }
859  }
860 
861  if($thumbnail) {
862  $edit_fns = $thumbnail->getEditFns();
863  $edit_fns->printExistingFileInfo($thumbnail);
864  } else {
865  echo translate('no_thumbnail_attatched');
866  }
867 
868  return FALSE;
869 
870 }//end _paintDetailsThumbnailCurrent()
871 
872 
873 //-- PROCESSING FUNCTIONS --//
874 
875 
891 function _processDetailsStatusChange(Asset $owner, Backend_Outputter $o, $prefix)
892 {
893  $is_updated = FALSE;
894 
895  $wfm = $GLOBALS['SQ_SYSTEM']->getWorkflowManager();
896  $running_schemas = $wfm->getSchemas($owner->id, TRUE, TRUE);
897  if (empty($running_schemas)) {
898  _processStatusChange($owner, $o, $prefix);
899  $is_updated = TRUE;
900  }
901 
902  return $is_updated;
903 
904 }//end _processDetailsStatusChange()
905 
906 
918 function _processDetailsFutureStatusCurrent(Asset $owner, Backend_Outputter $o, $prefix)
919 {
920  $is_updated = FALSE;
921 
922  $cron_mgr = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('cron_manager');
923  if ($cron_mgr === NULL) return FALSE;
924 
925  $GLOBALS['SQ_SYSTEM']->am->includeAsset('cron_job_future_status');
926 
927  if (!empty($_POST[$prefix.'_remove_fs'])) {
928  $fs_jobs = Cron_Job_Future_Status::getActiveJobs($owner);
929  if (!empty($fs_jobs)) {
930 
931  if ($GLOBALS['SQ_SYSTEM']->am->acquireLock($cron_mgr->id, 'links')) {
932  for ($i = 0; $i < count($fs_jobs); $i++) {
933  if (in_array($fs_jobs[$i]->id, $_POST[$prefix.'_remove_fs'])) {
934  if ($cron_mgr->removeJob($fs_jobs[$i])) {
935  $is_updated = TRUE;
936  }
937  }// end if
938  }// end for
939 
940  $GLOBALS['SQ_SYSTEM']->am->releaseLock($cron_mgr->id, 'links');
941 
942  } else {
943  trigger_localised_error('SYS0232', E_USER_NOTICE);
944 
945  }// end if
946 
947  }// end if
948  }// end if
949 
950  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($cron_mgr);
951 
952  return $is_updated;
953 
954 }//end _processDetailsFutureStatusCurrent()
955 
956 
968 function _processDetailsFutureStatusNew(Asset $owner, Backend_Outputter $o, $prefix)
969 {
970  $is_updated = FALSE;
971 
972  if ($owner->writeAccess('') === FALSE) return FALSE;
973 
974  $cron_mgr = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('cron_manager');
975  if ($cron_mgr === NULL) return FALSE;
976 
977  $GLOBALS['SQ_SYSTEM']->am->includeAsset('cron_job_future_status');
978 
979  $fs = new Cron_Job_Future_Status();
980  $edit_fns = $fs->getEditFns();
981  if ($fs->setAssetToUpdate($owner) && $edit_fns->processInLineBackend($fs, $o, $prefix.'_new_fs')) {
982  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
983  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
984  if ($cron_mgr->addJob($fs, $GLOBALS['SQ_SYSTEM']->user)) {
985  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
986  $is_updated = TRUE;
987  } else {
988  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
989  }
990  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
991  }
992 
993  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($cron_mgr);
994 
995  return $is_updated;
996 
997 }//end _processDetailsFutureStatusNew()
998 
999 
1011 function _processDetailsThumbnailChange(Asset $owner, Backend_Outputter $o, $prefix)
1012 {
1013  $is_updated = FALSE;
1014 
1015  $edit_fns = $owner->getEditFns();
1016  if ($edit_fns->processNoticeLinkedAsset($owner, 'thumbnail')) {
1017  $is_updated = TRUE;
1018  }
1019 
1020  return $is_updated;
1021 
1022 }//end _processDetailsThumbnailChange()
1023 
1024 
1025 ?>