17 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
18 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
40 function paintDetails(&$owner, &$o, &$ei, $keywords=NULL)
43 if (empty($owner->id))
return;
45 $root = $ei->findScreen(
'static_screen_details');
46 if (is_null($root))
return FALSE;
48 $prefix = $owner->getPrefix();
49 $print_commit_button = FALSE;
51 $display_status_sections = TRUE;
52 $parent_asset_href =
'';
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'));
60 foreach ($root->section as $section) {
63 if (is_null($keywords)) {
65 if (SQ_IN_LIMBO && (!isset($section->attributes()->limbo_access) || (
int)$section->attributes()->limbo_access == 0)) {
70 $section_keyword_name = strtolower(str_replace(
' ',
'_', $section->attributes()->name));
72 if (!$ei->_getAccess($owner, $section, $prefix)) {
76 if (!($num_fields = count($section->children()))) {
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));
90 foreach ($section->field as $field) {
92 switch (strtolower($field->attributes()->code)) {
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);
100 if ($safe_trash_enabled) {
101 if (empty($safe_trash_errors)) {
103 <div><?php echo translate(
'safe_trash_line_common'); ?><br/>
104 <?php echo translate(
'safe_trash_line_unblocked'); ?></div>
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>
113 if (!empty($safe_trash_errors[
'status'])) {
115 <li><?php echo translate(
'safe_trash_line_blocked_status'); ?></li>
120 if (!empty($safe_trash_errors[
'links'])) {
122 <li><?php echo translate(
'safe_trash_line_blocked_links', $owner->getBackendHref(
'linking')); ?></li>
127 if (!empty($safe_trash_errors[
'children'])) {
129 <li><?php echo translate(
'safe_trash_line_blocked_children'); ?></li>
138 <div><?php echo translate(
'safe_trash_line_common'); ?><br/>
139 <?php echo translate(
'safe_trash_line_disabled'); ?></div>
150 case 'status_current' :
152 if (!empty($field->display_name)) {
153 $display_name = translate(
'current');
159 $o->openField($display_name);
162 $need_commit = _paintDetailsCurrentStatus($owner, $o, $prefix);
163 $print_commit_button = $print_commit_button || $need_commit;
164 $contents = ob_get_clean();
167 if (_paintDetailsRegisterKeyword($ei, $keywords,
'fields',
'status_current', $contents) === FALSE) {
175 case 'status_change' :
177 if (!$display_status_sections) {
179 echo translate(
'asset_current_status_change_from_parent',$parent_asset_href[$parent_asset_link[0][
'majorid']]);
184 if (!empty($field->display_name)) {
185 $display_name = translate(
'change_question');
192 $o->openField($display_name);
195 $need_commit = _paintDetailsChangeStatus($owner, $o, $prefix);
196 $print_commit_button = $print_commit_button || $need_commit;
197 $contents = ob_get_clean();
200 if (_paintDetailsRegisterKeyword($ei, $keywords,
'fields',
'status_change', $contents) === FALSE) {
208 case 'status_future_status' :
209 if (!$display_status_sections) {
211 echo translate(
'asset_future_status_change_from_parent',$parent_asset_href[$parent_asset_link[0][
'majorid']]);
219 $need_commit = _paintDetailsFutureStatusCurrent($owner, $o, $prefix);
220 $print_commit_button = $print_commit_button || $need_commit;
221 $current_fs_contents = ob_get_clean();
224 $need_commit = _paintDetailsFutureStatusNew($owner, $o, $prefix);
225 $print_commit_button = $print_commit_button || $need_commit;
226 $new_fs_contents = ob_get_clean();
229 if (_paintDetailsRegisterKeyword($ei, $keywords,
'fields',
'status_future_status', $current_fs_contents.$new_fs_contents) === FALSE) {
231 if (empty($current_fs_contents) === FALSE) {
232 $o->openField(translate(
'scheduled_future_status_change'),
'new_line');
233 echo $current_fs_contents;
238 if ($owner->writeAccess()) {
239 $o->openField(translate(
'add_new_future_status'),
'new_line');
240 echo $new_fs_contents;
248 case 'thumbnail_change' :
250 if ($owner->writeAccess(
'links')) {
252 if (!empty($field->display_name)) {
253 $display_name = translate(
'change_question');
258 $o->openField($display_name);
261 $need_commit = _paintDetailsThumbnailChange($owner, $o, $prefix);
262 $print_commit_button = $print_commit_button || $need_commit;
263 $contents = ob_get_clean();
266 if (_paintDetailsRegisterKeyword($ei, $keywords,
'fields',
'thumbnail_change', $contents) === FALSE) {
275 case 'thumbnail_current' :
277 if (!empty($field->display_name)) {
278 $display_name = translate(
'current');
283 $o->openField($display_name);
286 $need_commit = _paintDetailsThumbnailCurrent($owner, $o, $prefix);
287 $print_commit_button = $print_commit_button || $need_commit;
288 $contents = ob_get_clean();
291 if (_paintDetailsRegisterKeyword($ei, $keywords,
'fields',
'thumbnail_current', $contents) === FALSE) {
301 $note = (string) $field->note;
308 if (!$avoiding_safe_trash_section) {
312 $section_contents = ob_get_clean();
314 if (_paintDetailsRegisterKeyword($ei, $keywords,
'sections', $section_keyword_name, $section_contents) === FALSE) {
315 echo $section_contents;
320 return $print_commit_button;
337 function _paintStatusChange(&$owner, &$o, $prefix, $statii, $default_status=0)
339 if (!empty($statii)) {
340 $statii = array_reverse($statii, TRUE);
342 $statii = array_reverse($statii, TRUE);
343 combo_box($prefix.
'_change_status', $statii, FALSE, $default_status);
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;
354 if (($status_code & SQ_SC_STATUS_ALL_APPROVED) > 0) {
355 $has_approved_status = TRUE;
365 if (($owner->adminAccess() === TRUE) && (($owner->status & (SQ_STATUS_LIVE | SQ_SC_STATUS_CAN_APPROVE)) > 0) && (($has_pending_status === TRUE) || ($has_approved_status === TRUE))) {
369 $stream_names = Array(
370 'workflow' => Array(),
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'];
386 if ($has_approved_status === TRUE) {
388 $bypassable_streams = $wfm->getBypassableStreams($owner->id, $schemaid);
389 $bypassable_streams = array_intersect($bypassable_streams, $streamids);
390 $workflowable_streams = array_diff($streamids, $bypassable_streams);
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);
396 $workflowable_streams = $streamids;
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);
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']);
413 'workflow' => Array(),
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');
422 $options[
'workflow'] = Array(
'SQ_USE_DEFAULT' =>
'Default Stream');
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;
434 if (count($options[
'bypass']) + count($options[
'workflow']) > 1) {
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();
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();
445 echo translate(
'workflow_stream_using_workflow_stream', $cb1.$cb2);
448 $all_options = $options[
'bypass'] + $options[
'workflow'];
450 hidden_field($prefix.
'_change_status_stream', key($all_options));
457 <script type=
"text/javascript">
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");
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';
468 stream_byp_cb.style.display =
'none';
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';
477 stream_wf_cb.disabled =
true;
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';
485 stream_byp_cb.disabled =
true;
493 check_box($prefix.
'_change_status_all_children');
494 label(translate(
'cascade_status_change'), $prefix.
'_change_status_all_children');
511 function _processStatusChange(&$owner, &$o, $prefix)
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) {
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'];
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'];
530 $hh->queueHipo(
'hipo_job_edit_status', $vars);
548 function processDetails(&$owner, &$o, &$ei)
551 if (empty($owner->id))
return FALSE;
553 $root = $ei->findScreen(
'static_screen_details');
554 if (is_null($root))
return FALSE;
556 $prefix = $owner->getPrefix();
560 foreach ($root->section as $section) {
562 if (!$ei->_getAccess($owner, $section, $prefix)) {
566 if (!($num_fields = count($section->children()))) {
570 foreach ($section->field as $field) {
572 switch (strtolower($field->attributes()->code)) {
574 case 'status_change' :
576 $is_updated = _processDetailsStatusChange($owner, $o, $prefix) || $is_updated;
579 case 'status_future_status' :
581 $is_updated = _processDetailsFutureStatusCurrent($owner, $o, $prefix) || $is_updated;
582 $is_updated = _processDetailsFutureStatusNew($owner, $o, $prefix) || $is_updated;
585 case 'thumbnail_change' :
587 $is_updated = _processDetailsThumbnailChange($owner, $o, $prefix) || $is_updated;
596 return ($is_updated);
614 function _paintDetailsRegisterKeyword(
Asset_Edit_Interface $ei, $keywords, $type, $name, $content)
617 if ($keywords === NULL)
return FALSE;
620 if (isset($keywords[$type][$name]) === FALSE) {
624 $ei->_tmp[
'layout_keyword_replacements'][$keywords[$type][$name]] = $content;
646 echo get_asset_status_icon($owner->status);
647 echo
' <i>'.$owner->getStatusDescription().
'</i>';
670 $needs_commit = FALSE;
672 if (empty($statii) === FALSE) {
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')));
680 _paintStatusChange($owner, $o, $prefix, $statii);
681 $needs_commit = TRUE;
683 $note = $status->getStatusChangeMessage();
691 return $needs_commit;
713 $fs_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($owner->id, SQ_LINK_NOTICE,
'cron_job_future_status', TRUE,
'minor');
715 if (!empty($fs_links)) {
717 <table
class=
"sq-backend-table">
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>
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');
729 <td
class=
"sq-backend-table-cell">
730 <?php echo $fs_job->statusName(); ?>
732 <td
class=
"sq-backend-table-cell">
733 <?php echo $fs_job->readableWhen(); ?>
735 <td align=
"center" class=
"sq-backend-table-cell">
737 if ($fs_job->attr(
'dependants_only')) {
738 echo translate(
'no');
740 echo translate(
'yes');
744 <td align=
"center" class=
"sq-backend-table-cell">
746 if ($fs_job->canDelete()) {
747 check_box($prefix.
'_remove_fs[]', $fs_job->id);
782 $needs_commit = FALSE;
784 $cron_mgr = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cron_manager');
786 $cron_epoc = (int)$cron_mgr->attr(
'epoch');
787 $cron_refresh = (int)$cron_mgr->attr(
'refresh_time');
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');
793 $edit_fns = $fs->getEditFns();
795 $edit_fns->paintInLineBackend($fs, $o, $prefix.
'_new_fs');
797 $o->
note(translate(
'cron_manager_next_run', $cron_mgr->readableRefreshTime(), readable_datetime($cron_mgr->timeOfNextRun())));
798 $needs_commit = TRUE;
800 echo translate(
'cron_manager_not_configured');
803 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($cron_mgr);
805 return $needs_commit;
824 $edit_fns->paintNoticeLinkedAsset($owner,
'thumbnail', Array(
'image' =>
'D'));
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']);
855 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($owner->id, SQ_LINK_NOTICE,
'image', FALSE,
'thumbnail');
857 $thumbnail = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
862 $edit_fns = $thumbnail->getEditFns();
863 $edit_fns->printExistingFileInfo($thumbnail);
865 echo translate(
'no_thumbnail_attatched');
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);
922 $cron_mgr = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cron_manager');
923 if ($cron_mgr === NULL)
return FALSE;
925 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'cron_job_future_status');
927 if (!empty($_POST[$prefix.
'_remove_fs'])) {
929 if (!empty($fs_jobs)) {
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])) {
940 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($cron_mgr->id,
'links');
943 trigger_localised_error(
'SYS0232', E_USER_NOTICE);
950 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($cron_mgr);
972 if ($owner->
writeAccess(
'') === FALSE)
return FALSE;
974 $cron_mgr = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cron_manager');
975 if ($cron_mgr === NULL)
return FALSE;
977 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'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');
988 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
990 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
993 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($cron_mgr);
1013 $is_updated = FALSE;
1016 if ($edit_fns->processNoticeLinkedAsset($owner,
'thumbnail')) {