19 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
26 define(
'SQ_EI_READ', 1);
27 define(
'SQ_EI_WRITE', 2);
49 var $_edit_fns = NULL;
61 var $_screens = Array();
67 var $_default_screen =
'';
79 $this->_type_code = $type_code;
81 $type_info = $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->_type_code);
82 $asset_dir = SQ_SYSTEM_ROOT.
'/'.$type_info[
'dir'];
83 $class_name = $this->_type_code.
'_edit_fns';
84 require_once $asset_dir.
'/'.$class_name.
'.inc';
85 $this->_edit_fns =
new $class_name();
89 assert_isset($this->_edit_fns->static_screens[
'details'], translate(
'no_details_screen_defined', $type_code));
91 $this->_dirs = Array($asset_dir);
92 $parent_type = $type_info[
'parent_type'];
94 while ($parent_type !=
'asset') {
95 $type_info = $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($parent_type);
96 $this->_dirs[] = SQ_SYSTEM_ROOT.
'/'.$type_info[
'dir'];
97 $parent_type = $type_info[
'parent_type'];
101 $this->_dirs[] = SQ_INCLUDE_PATH.
'/asset_edit';
103 if (!($file = $this->
findFile(
'screens')))
return;
106 $root =
new SimpleXMLElement($file, LIBXML_NOCDATA, TRUE);
107 }
catch (Exception $e) {
108 throw new Exception(
'Unable to parse screen list file "'.$file.
'": '.$e->getMessage());
111 $this->_screens = Array();
112 foreach ($root->screen as $screen_node) {
113 $code_name = strtolower(preg_replace(
'/[^a-z_]/',
'', (
string)$screen_node->attributes()->code_name));
114 if (!$code_name)
continue;
116 $force_unlock = ((isset($screen_node->attributes()->force_unlock)) ? (string)$screen_node->attributes()->force_unlock :
'1');
118 $this->_screens[$code_name] = Array(
119 'name' => (
string)$screen_node->attributes()->display_name,
120 'force_unlock' => ($force_unlock !=
'0'),
121 'lock_type' => (isset($screen_node->attributes()->lock_type)) ? (string)$screen_node->attributes()->lock_type :
'',
122 'invisible' => (!empty($screen_node->attributes()->invisible)),
126 if (!empty($screen_node->attributes()->default)) {
127 $this->_default_screen = $code_name;
142 return $this->_screens;
159 $asset_path = Array();
160 if (isset($_REQUEST[
'sq_asset_path'])) {
162 $matches = preg_split(
'|,([0-9]+:?),?|', $_REQUEST[
'sq_asset_path'], 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
163 for (reset($matches); NULL !== ($k = key($matches)); next($matches)) {
166 if (substr($matches[$k], -1) ==
':') {
167 $asset_path[] = $matches[$k].$matches[$k+1];
172 $asset_path[] = $matches[$k];
176 $url_lineage = $GLOBALS[
'SQ_SYSTEM']->am->getLineageFromURL();
177 foreach ($url_lineage as $asset_info) {
178 $asset_path[] = $asset_info[
'assetid'];
183 if ($owner->id) $asset_path[] = $owner->id;
187 $o->addFormActionGetVar(
'sq_asset_path', implode(
',', $asset_path), TRUE);
190 $closest_parentid = $owner->id;
192 foreach ($asset_path as $assetid) {
193 if ($assetid != $owner->id) {
194 $ancestor = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
199 if (is_null($ancestor)) {
204 $paths = $ancestor->getWebPaths();
205 if (!empty($paths)) $closest_parentid = $assetid;
207 if ($preview_url ==
'') {
209 $url = $ancestor->getUrl();
211 $preview_url = $ancestor->getUrl();
212 $closest_parentid = $assetid;
220 $preview_url .=
'/'.array_shift($paths);
224 $o->addHiddenField(
'sq_preview_url', $preview_url);
228 $GLOBALS[
'sq_preview_url'] = $preview_url;
230 return $closest_parentid;
245 function paint(&$owner, &$o, $creating)
248 if ($owner->id && !$owner->readAccess()) {
249 $GLOBALS[
'SQ_SYSTEM']->paintLogin(translate(
'login'), translate(
'cannot_access_asset', htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)));
253 if ($creating && SQ_IN_BACKEND) {
254 $o->addOnLoad(
'focusFirstTextInput();');
257 assert_false(!count($this->_screens) && empty($this->_edit_fns->static_screens));
260 $this->_type_code = $owner->type();
266 $check_screen_restrictions = !$creating && (!($GLOBALS[
'SQ_SYSTEM']->userRoot() || $GLOBALS[
'SQ_SYSTEM']->userSystemAdmin()));
267 if ($check_screen_restrictions) {
269 if (empty($allowed_screens)) {
270 $check_screen_restrictions = FALSE;
278 $create_sections = Array();
280 if (empty($_REQUEST[
'asset_ei_screen'])) {
281 if ((SQ_IN_LIMBO || isset($_GET[
'sq_from_frontend'])) && !empty($this->_default_screen)) {
282 $active_screen = $this->_default_screen;
284 $active_screen =
'details';
286 $_REQUEST[
'asset_ei_screen'] = $active_screen;
288 $active_screen = $_REQUEST[
'asset_ei_screen'];
294 if (!count($create_sections))
return;
298 if ($check_screen_restrictions) {
299 $user_is_not_allowed = TRUE;
301 foreach ($allowed_screens as $allowed_screen) {
304 if (isset($allowed_screen[
'screen']) && ($allowed_screen[
'screen'] === 0)) {
305 $user_is_not_allowed = FALSE;
306 }
else if (isset($allowed_screen[
'screen']) && ($allowed_screen[
'screen'] == $active_screen)) {
307 $user_is_not_allowed = FALSE;
311 if ($user_is_not_allowed) {
313 $GLOBALS[
'SQ_SYSTEM']->paintLogin(translate(
'login'), translate(
'cannot_access_inline_asset_screen', $active_screen, htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)));
318 if (SQ_IN_LIMBO && $owner->id) {
320 $GLOBALS[
'SQ_SYSTEM']->broadcastTriggerEvent(
'trigger_event_enter_simple_edit', $owner);
323 if (!isset($this->_edit_fns->static_screens[$active_screen]) && empty($this->_screens[$active_screen])) {
325 trigger_localised_error(
'SYS0076', E_USER_WARNING, $active_screen);
326 $active_screen =
'details';
330 $o->addFormActionGetVar(
'asset_ei_screen', $active_screen);
337 $full_write_access = $owner->writeAccess(
'');
340 $print_commit_button = FALSE;
343 $force_unlock_on_commit = TRUE;
346 if (SQ_IN_LIMBO && !empty($_REQUEST[
'sq_lock_release_manual'])) {
348 <script>top.location=
'<?php echo current_url(TRUE, TRUE); ?>';</script>
355 $screen_lock_type =
'all';
356 if (isset($this->_edit_fns->static_screens[$active_screen])) {
357 if (!empty($this->_edit_fns->static_screens[$active_screen][
'lock_type'])) {
358 $screen_lock_type = $this->_edit_fns->static_screens[$active_screen][
'lock_type'];
362 if (!empty($this->_screens[$active_screen][
'lock_type'])) {
363 $screen_lock_type = $this->_screens[$active_screen][
'lock_type'];
368 $acquire_lock_access = $owner->canLiveEdit($screen_lock_type);
370 $locks = $GLOBALS[
'SQ_SYSTEM']->am->getLockInfo($owner->id, $screen_lock_type, TRUE);
372 $have_any_locks = FALSE;
373 $have_all_locks = TRUE;
374 $need_force_locks = FALSE;
375 $can_force_locks = TRUE;
376 $do_the_limbo_lock = TRUE;
377 foreach ($locks as $lock_type => $lock) {
380 $have_all_locks = FALSE;
383 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($lock[
'userid']);
384 $editing = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($lock[
'source_assetid']);
386 if ($GLOBALS[
'SQ_SYSTEM']->currentUser($user)) {
387 $have_any_locks = TRUE;
389 $have_all_locks = FALSE;
390 $do_the_limbo_lock = FALSE;
393 $need_force_locks = TRUE;
396 if (!$owner->canForceablyAcquireLock($lock_type)) {
397 $can_force_locks = FALSE;
405 if (SQ_IN_LIMBO && $do_the_limbo_lock && !SQ_DESIGN_NO_FRAME) {
417 if ((strtolower($screen_lock_type) !=
'none') && empty($_REQUEST[
'print_view'])) {
420 $o->openSection(translate(
'locking_editing'));
423 <p
class=
"sq-lock-message"><?php
424 if (!$have_all_locks) {
425 if ($need_force_locks) {
426 if ($can_force_locks) {
427 echo
'<div class="sq-backend-locked-by-someone-else">'.translate(
'forcibly_acquire_lock', htmlspecialchars($user->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)).
'</div>';
429 }
else if ($full_write_access && $acquire_lock_access) {
430 echo translate(
'acquire_lock', translate(
'acquire_lock_button'), htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
433 if ($have_any_locks) {
434 echo translate(
'release_lock', translate(
'release_lock_button'), htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
437 <b
class=
"clickable" onclick=
"sq_toggle_lock_info();" id=
"sq_lock_info_toggle"><?php echo translate(
'show_lock_details'); ?></b><br />
440 <div
id=
"sq_lock_info" style=
"display: none;">
441 <table
class=
"sq-backend-table">
443 <td
class=
"sq-backend-table-header" style=
"width: 20px;">
444 <img src=
"<?php echo $o->filesPath('/images/blank.gif');?>" width=
"20" height=
"1" border=
"0" alt=
"" />
446 <td
class=
"sq-backend-table-header" align=
"left" nowrap>
447 <?php echo translate(
'lock_type'); ?>
449 <td
class=
"sq-backend-table-header" width=
"100%">
454 <td width=
"100%" colspan=
"3">
455 <table width=
"100%" cellspacing=
"0" cellpadding=
"0">
457 $class =
'sq-backend-table-cell-alt';
458 foreach ($locks as $lock_type => $lock) {
461 <td
class=
"sq-backend-table-cell" style=
"width: 20px;" align=
"center">
462 <script language=
"JavaScript" type=
"text/javascript">sq_print_icon(
"<?php echo sq_web_path('lib'); ?>/web/images/icons/<?php echo ((empty($lock)) ? 'un' : ''); ?>locked.png",
"16",
"16",
"");</script>
464 <td
class=
"sq-backend-table-cell">
465 <?php echo ucwords(str_replace(
'_',
' ', $lock_type)); ?>
467 <td
class=
"sq-backend-table-cell">
471 if ($full_write_access && $acquire_lock_access) {
472 echo translate(
'currently_not_held').
'.';
474 echo translate(
'no_access_to_edit', htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
479 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($lock[
'userid']);
480 $editing = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($lock[
'source_assetid']);
482 if (SQ_ROLLBACK_VIEW) {
483 $now = strtotime($_SESSION[
'sq_rollback_view'][
'rollback_time']);
488 if (is_null($lock[
'expires'])) {
489 $expires_in = translate(
'lock_held_indefinitely');
491 require_once SQ_FUDGE_PATH.
'/general/datetime.inc';
492 $expires_in = easy_time_total(($lock[
'expires'] - $now), TRUE);
494 $expires_in =
'1 '.translate(
'second');
496 $expires_in = translate(
'due_to_expire', $expires_in);
499 echo translate(
'lock_held_by', htmlspecialchars($user->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET), htmlspecialchars($editing->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)).
'. ';
515 if (!$have_all_locks || $have_any_locks) {
516 ?><div style=
"margin-top: 4px; margin-bottom: 0px"><?php
519 if (!$have_all_locks) {
520 hidden_field(
'sq_lock_acquire',
'0');
521 if ($need_force_locks) {
522 if ($can_force_locks) {
525 $popup_url =
'?SQ_BACKEND_PAGE=main&backend_section=am&ignore_frames=1&am_section=forceably_acquire_lock&assetid='.$owner->id.
'&sq_lock_type='.$screen_lock_type;
527 hidden_field(
'sq_lock_acquire_by_force',
'0');
528 normal_button(
'sq_forceably_acquire_lock', translate(
'acquire_lock_button'),
"window.open('$popup_url', 'sq_forceably_acquire_lock_popup', 'toolbar=0,menubar=0,location=0,status=0,scrollbars=1,resizable=1,width=500,height=300');");
531 }
else if ($full_write_access && $acquire_lock_access) {
532 hidden_field(
'sq_lock_acquire_by_force',
'0');
533 normal_button(
'', translate(
'acquire_lock_button'),
"document.getElementById('sq_lock_acquire').value = 1; submit_form(this.form)",
'accesskey="a"');
538 if ($have_any_locks) {
539 hidden_field(
'sq_lock_release_manual', 0);
540 normal_button(
'', translate(
'release_lock_button'),
"document.getElementById('sq_lock_release_manual').value = 1; submit_form(this.form)",
'accesskey="r"');
544 if (!$have_all_locks || $have_any_locks) {
556 hidden_field(
'sq_lock_type', $screen_lock_type);
562 $paint_layout = FALSE;
563 if (SQ_IN_LIMBO && !$creating) {
565 $layout_pattern =
'layout::'.$owner->type().
'::'.$active_screen;
566 $lookup_values = $owner->getLookupValues(TRUE, $layout_pattern);
567 foreach ($lookup_values as $values) {
568 foreach ($values as $look_key => $look_value) {
569 if (isset($look_value[
'value']) && ($look_value[
'value'] > 0)) {
570 $paint_layout = TRUE;
576 $lm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'layout_manager');
577 if ($lm->hasLayout($owner, $active_screen)) {
578 $paint_layout = TRUE;
585 if (isset($this->_edit_fns->static_screens[$active_screen])) {
586 $active_screen_name = $this->_edit_fns->static_screens[$active_screen][
'name'];
589 if (!$paint_layout) {
592 $paint_function =
'paint'.$active_screen;
594 if ($paint_function($owner, $o, $this)) {
595 $print_commit_button = TRUE;
599 $force_unlock_on_commit = $this->_edit_fns->static_screens[$active_screen][
'force_unlock'];
602 $file = @$this->
findFile(
'screen_'.$active_screen);
607 if (!($file = $this->
findFile(
'screen_'.$active_screen))) {
611 $force_unlock_on_commit = $this->_screens[$active_screen][
'force_unlock'];
612 $active_screen_name = $this->_screens[$active_screen][
'name'];
620 if (isset($_REQUEST[
'sq_link_path'])) {
621 $link_path = $_REQUEST[
'sq_link_path'];
625 $o->addFormActionGetVar(
'sq_link_path', $link_path, TRUE);
626 $o->addHiddenField(
'sq_link_path', $link_path);
642 if (isset($_REQUEST[
'ignore_frames']) && $_REQUEST[
'ignore_frames']) {
643 $o->addFormActionGetVar(
'ignore_frames',
'1', TRUE);
650 $layout_pattern =
'layout::'.$owner->type().
'::'.$active_screen;
651 $lookup_values = $owner->getLookupValues(TRUE, $layout_pattern);
653 foreach ($lookup_values as $values) {
654 foreach ($values as $look_key => $look_value) {
655 if (isset($look_value[
'value'])) {
656 $layoutid = $look_value[
'value'];
661 if ((!empty($layoutid)) && ($layoutid > 0)) {
662 $layout = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($layoutid);
664 if (!is_null($layout)) {
665 $o->addFormActionGetVar(
'asset_ei_screen', $active_screen, TRUE);
669 if (NULL !== ($layout = $lm->getLayout($owner, $active_screen))) {
670 $o->addFormActionGetVar(
'asset_ei_screen', $active_screen, TRUE);
678 if (!isset($_SESSION[
'sq_nav_history']) || !is_array($_SESSION[
'sq_nav_history'])) {
679 $_SESSION[
'sq_nav_history'] = Array();
683 if (!empty($_SESSION[
'sq_nav_history'])) {
684 if (isset($_REQUEST[
'sq_nav_goback'])) {
685 for ($i = count($_SESSION[
'sq_nav_history']); $i > $_REQUEST[
'sq_nav_goback']; $i--) {
686 array_pop($_SESSION[
'sq_nav_history']);
687 if (empty($_SESSION[
'sq_nav_history']))
break;
693 if (!empty($_SESSION[
'sq_nav_history'])) {
694 $nav_count = count($_SESSION[
'sq_nav_history']);
696 if ($nav_count >= 20) {
697 array_shift($_SESSION[
'sq_nav_history']);
701 $current_nav_node = $_SESSION[
'sq_nav_history'][($nav_count-1)];
702 if ($current_nav_node[
'assetid'] != $owner->id) {
703 $_SESSION[
'sq_nav_history'][$nav_count] = Array(
'assetid' => $owner->id,
'screen' => $active_screen);
704 }
else if ($current_nav_node[
'screen'] != $active_screen) {
705 $_SESSION[
'sq_nav_history'][($nav_count -1)] = Array(
'assetid' => $owner->id,
'screen' => $active_screen);
708 $_SESSION[
'sq_nav_history'][0] = Array(
'assetid' => $owner->id,
'screen' => $active_screen);
718 $page_heading = $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->_type_code,
'name').
' | ';
719 if (empty($_REQUEST[
'print_view'])) {
720 $infos = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($owner->id);
721 $page_heading .=
'<ul class="info_asset_finder">';
722 foreach ($infos as $assetid => $info) {
723 $page_heading .=
'<li>'.get_asset_tag_line($assetid).
'</li>';
725 $page_heading .=
'</ul>';
727 $page_heading .= htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET).
' (Id: #'.$owner->id.
') ';
729 $page_heading .=
'v. '.$owner->version;
731 $page_heading =
'Create new '.$GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->_type_code,
'name');
733 $page_heading .=
' | '.$active_screen_name;
735 $o->setHeading($page_heading, sq_get_icon($GLOBALS[
'SQ_SYSTEM']->am->getAssetIconURL($this->_type_code), 16, 16,
''));
737 $o->setPageTitle(htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
739 if ($closest_parentid != $owner->id) {
740 $closest_parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($closest_parentid);
741 if (!is_null($closest_parent)) {
742 $sub_heading = translate(
'currently_editing', $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($closest_parent->type(),
'name'), htmlspecialchars($closest_parent->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)).
'<br />';
745 $o->setSubHeading($sub_heading);
753 $current_location = $o->getCurrentLocation();
754 list($current_loc_base, $current_loc_query) = explode(
'?', $current_location);
757 foreach ($this->_edit_fns->static_screens as $code_name => $data) {
758 if ($check_screen_restrictions) {
759 $user_is_not_allowed = TRUE;
760 foreach ($allowed_screens as $allowed_screen) {
761 if (isset($allowed_screen[
'screen']) && ($allowed_screen[
'screen'] == $code_name)) {
762 $user_is_not_allowed = FALSE;
766 if ($user_is_not_allowed)
continue;
768 $url = replace_query_string_vars(Array(
'asset_ei_screen' => rawurlencode($code_name)), $current_loc_base, $current_loc_query);
769 $o->addStaticScreen($url, $data[
'name']);
771 for (reset($this->_screens); NULL !== ($code = key($this->_screens)); next($this->_screens)) {
772 if ($check_screen_restrictions) {
773 $user_is_not_allowed = TRUE;
774 foreach ($allowed_screens as $allowed_screen) {
775 if (isset($allowed_screen[
'screen']) && ($allowed_screen[
'screen'] == $code)) {
776 $user_is_not_allowed = FALSE;
780 if ($user_is_not_allowed)
continue;
782 if ($this->_screens[$code][
'invisible'] && $code != $active_screen) {
785 $url = replace_query_string_vars(Array(
'asset_ei_screen' => rawurlencode($code)), $current_loc_base, $current_loc_query);
786 $o->addScreen($url, $this->_screens[$code][
'name']);
795 $print_commit_button |= $this->
printEditInterface(
'screen_'.$active_screen, $owner, $o, $creating, $create_sections);
799 if ($print_commit_button && empty($_REQUEST[
'print_view'])) {
800 $o->commitButton(
'', $force_unlock_on_commit);
821 $print_commit_button = FALSE;
824 if ($owner->id && !$owner->readAccess()) {
827 <span
class=
"error"><?php echo translate(
'cannot_access_asset', htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)); ?></span>
834 assert_false(!count($this->_screens) && empty($this->_edit_fns->static_screens));
840 $check_screen_restrictions = !$creating && (!($GLOBALS[
'SQ_SYSTEM']->userRoot() || $GLOBALS[
'SQ_SYSTEM']->userSystemAdmin()));
841 if ($check_screen_restrictions) {
843 if (empty($allowed_screens)) {
844 $check_screen_restrictions = FALSE;
852 $create_sections = Array();
856 if (!count($create_sections))
return;
862 if ($check_screen_restrictions) {
863 $user_is_not_allowed = TRUE;
864 foreach ($allowed_screens as $allowed_screen) {
865 if (isset($allowed_screen[
'screen']) && ($allowed_screen[
'screen'] == $active_screen)) {
866 $user_is_not_allowed = FALSE;
870 if ($user_is_not_allowed) {
873 <span
class=
"error"><?php echo translate(
'cannot_access_inline_asset_screen', $active_screen, htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)); ?></span>
880 if (!isset($this->_edit_fns->static_screens[$active_screen]) && empty($this->_screens[$active_screen])) {
882 trigger_localised_error(
'SYS0076', E_USER_WARNING, $active_screen);
883 $active_screen =
'details';
887 $paint_layout = FALSE;
888 if (SQ_IN_LIMBO && !$creating) {
889 $lm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'layout_manager');
890 if ($lm->hasLayout($owner, $active_screen)) {
891 $paint_layout = TRUE;
897 if (isset($this->_edit_fns->static_screens[$active_screen])) {
898 $active_screen_name = $this->_edit_fns->static_screens[$active_screen][
'name'];
901 if (!$paint_layout) {
904 $paint_function =
'paint'.$active_screen;
906 if ($paint_function($owner, $o, $this)) {
907 $print_commit_button = TRUE;
911 $force_unlock_on_commit = $this->_edit_fns->static_screens[$active_screen][
'force_unlock'];
914 $file = @$this->
findFile(
'screen_'.$active_screen);
919 if (!($file = $this->
findFile(
'screen_'.$active_screen))) {
923 $force_unlock_on_commit = $this->_screens[$active_screen][
'force_unlock'];
924 $active_screen_name = $this->_screens[$active_screen][
'name'];
931 if (NULL !== ($layout = $lm->getLayout($owner, $active_screen))) {
932 $o->addFormActionGetVar(
'asset_ei_screen', $active_screen, TRUE);
941 $print_commit_button |= $this->
printEditInterface(
'screen_'.$active_screen, $owner, $o, $creating, $create_sections);
944 return $print_commit_button;
966 if (is_null($root))
return FALSE;
968 $print_commit_button = FALSE;
971 $prefix = $owner->getPrefix();
974 foreach ($root->section as $section) {
976 if (SQ_IN_LIMBO && (!isset($section->attributes()->limbo_access) || (
int)$section->attributes()->limbo_access == 0)) {
982 if ($creating && empty($create_sections[(
string)$section->attributes()->name])) {
986 $section_access = $this->
_getAccess($owner, $section, $prefix);
987 if (!($section_access & SQ_EI_READ)) {
992 if (!is_null($section->attributes()->display_name)) {
993 $o->openSection((
string)$section->attributes()->display_name);
995 $o->openSection((
string)$section->attributes()->name);
998 if (!($num_fields = count($section->children()))) {
1002 $section_note = NULL;
1003 if ($section->function_call) {
1005 $paint_node = $section->function_call->paint_function;
1007 if (!isset($paint_node->attributes()->name) || !method_exists($this->_edit_fns, (
string)$paint_node->attributes()->name)) {
1009 echo translate(
'section_not_found', (
string)$section->attributes()->name);
1013 if ($creating && !in_array((
string)$paint_node->attributes()->name, $create_sections[(string)$section->attributes()->name])) {
1017 if ($this->_edit_fns->{(
string) $paint_node->attributes()->name}($owner, $o, $prefix)) {
1018 $print_commit_button = TRUE;
1023 if (isset($section->note)) {
1024 if (count($section->note) > 1) {
1025 throw new Exception(
'Unable to parse edit interface for asset type "'.$owner->type().
'", screen "'.$screen.
'": a section has multiple section notes; it should have just one');
1027 $section_note = (string)$section->note;
1035 foreach ($section->children() as $field) {
1036 switch ($field->getName()) {
1042 foreach ($field->children() as $sub_field) {
1043 switch ($sub_field->getName()) {
1044 case 'display_name':
1045 $display_name = (string)$sub_field;
1048 $field_note = (string)$sub_field;
1052 if (!is_null($attr_tag)) {
1053 trigger_localised_error(
'SYS0194', E_USER_WARNING);
1055 $attr_tag = $sub_field;
1063 if (SQ_IN_LIMBO && (isset($field->attributes()->limbo_access) && (
int)$field->attributes()->limbo_access == 0)) {
1067 $field_access = $this->
_getAccess($owner, $field, $prefix, $section_access);
1068 if (!($field_access & SQ_EI_READ)) {
1072 if (!isset($field->attributes()->format)) {
1073 $field->attributes()->format =
'';
1076 if (!empty($field->attributes()->attribute)) {
1078 if (($field->getName() !=
'field') || ($creating && (empty($field->attributes()->attribute) || !in_array((
string)$field->attributes()->attribute, $create_sections[(string)$section->attributes()->name])))) {
1083 $o->openField($display_name, $field->attributes()->format,
'', isset($field->attributes()->hidden));
1084 $attr = $owner->getAttribute((
string)$field->attributes()->attribute);
1086 if (is_null($attr))
continue;
1088 if (!$attr->setEditParams($attr_tag))
continue;
1089 $attr->paint($prefix.
'_'.$attr->id, !($field_access & SQ_EI_WRITE));
1090 if ($field_access & SQ_EI_WRITE) {
1091 $print_commit_button = TRUE;
1094 if (!empty($field_note)) {
1095 $field_note = str_replace(
'%description%', $attr->description, $field_note);
1098 }
else if ($attr_tag->getName() ==
'function_call') {
1100 $paint_node = $attr_tag->paint_function;
1103 if ($field->getName() !=
'field' || ($creating && !in_array((
string) $paint_node->attributes()->name, $create_sections[(string) $section->attributes()->name]))) {
1107 $o->openField($display_name, $field->attributes()->format,
'', isset($field->attributes()->hidden));
1109 if (empty($paint_node->attributes()->name) || !method_exists($this->_edit_fns, $paint_node->attributes()->name)) {
1110 $o->note(translate(
'specific_painting_function_not_found', $paint_node->attributes()->name));
1112 $method_name = (string) $paint_node->attributes()->name;
1113 if ($this->_edit_fns->{$method_name}($owner, $o, $prefix)) {
1114 $print_commit_button = TRUE;
1120 if (!empty($field_note)) $o->note($field_note);
1126 if (!empty($field)) {
1127 $section_note = (string)$field;
1132 trigger_localised_error(
'SYS0140', E_USER_WARNING, $field->name);
1141 if (!empty($section_note)) {
1142 $o->sectionNote($section_note);
1150 if($creating && SQ_IN_BACKEND) {
1151 $o->openSection(translate(
'link'));
1152 $this->_edit_fns->paintCreateLink($owner, $o, $prefix);
1155 return $print_commit_button;
1171 function acquireLimboLocks(&$owner, &$o, $active_screen=
'details', $screen_lock_type=NULL)
1174 if (!is_null($screen_lock_type)) {
1175 $locks[] = $screen_lock_type;
1178 $lm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'layout_manager');
1180 if ($lm->hasLayout($owner, $active_screen)) {
1182 $layout = $lm->getLayout($owner, $active_screen);
1183 if (is_null($layout))
return FALSE;
1185 $keywords = $layout->getLayoutKeywords();
1186 if (empty($keywords))
return FALSE;
1188 if (isset($keywords[
'custom']) && !empty($keywords[
'custom'])) {
1190 $locks = array_merge($locks, $owner->getEditingLocks($keywords[
'custom']));
1194 $screens = array_merge(array_keys($keywords[
'screens']), array_keys($keywords[
'entire_screens']));
1195 $screens = array_unique($screens);
1197 foreach ($screens as $screen) {
1199 $screen_lock_type =
'all';
1200 if (isset($this->_edit_fns->static_screens[$screen])) {
1201 if (!empty($this->_edit_fns->static_screens[$screen][
'lock_type'])) {
1202 $screen_lock_type = $this->_edit_fns->static_screens[$screen][
'lock_type'];
1206 if (!empty($this->_screens[$screen][
'lock_type'])) {
1207 $screen_lock_type = $this->_screens[$screen][
'lock_type'];
1211 $locks[] = $screen_lock_type;
1217 $locks = array_unique($locks);
1218 $have_all_locks = TRUE;
1219 foreach ($locks as $lock_name) {
1220 $lock_info = $GLOBALS[
'SQ_SYSTEM']->am->getLockInfo($owner->id, $lock_name, TRUE);
1221 foreach ($lock_info as $lock_type => $lock_data) {
1222 if (!isset($lock_data[
'userid']) || $lock_data[
'userid'] != $GLOBALS[
'SQ_SYSTEM']->currentUserId()) {
1223 $have_all_locks = FALSE;
1228 if (!$have_all_locks) {
1229 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
1231 'assetids' => Array($owner->id,),
1232 'lock_type' => $locks,
1233 'forceably_acquire' => FALSE,
1237 $on_complete_url = (empty($o->_redirect) ?
'' : $o->_redirect);
1238 $hh->queueHipo(
'hipo_job_acquire_locks', $vars, $on_complete_url);
1239 $url = $hh->runQueuedJobs();
1243 $o->setRedirect($url);
1248 hidden_field(
'sq_limbo_lock_type', urlencode(serialize($locks)));
1264 function paintLayout(&$owner, &$o, &$layout)
1274 $layout_keywords_order = $this->_getLayoutKeywordsOrder($layout);
1276 $this->getKeywordsReplacementsForPaint($owner, $o, $layout, $layout_keywords_order);
1280 $layout->printBody();
1301 public function getKeywordsReplacementsForPaint(&$owner, &$o, &$layout, $layout_keywords_order, $set_keywords_replacement = TRUE, $invoke_backend = FALSE)
1303 $keywords = $layout->getLayoutKeywords();
1304 $print_commit_button = FALSE;
1307 if (!isset($keywords[
'screens'])) {
1308 $keywords[
'screens'] = Array();
1311 if (!isset($keywords[
'entire_screens'])) {
1312 $keywords[
'entire_screens'] = Array();
1315 $screens = array_merge(array_keys($keywords[
'screens']), array_keys($keywords[
'entire_screens']));
1316 $screens = array_unique($screens);
1318 $this->_tmp[
'layout_keyword_replacements'] = Array();
1321 $o->setBuffering(FALSE);
1323 foreach ($layout_keywords_order as $order_keyword) {
1326 if ($order_keyword ==
'screen') {
1327 foreach ($screens as $screen) {
1329 $entire_screen = FALSE;
1330 if (in_array($screen, array_keys($keywords[
'entire_screens']))) {
1331 $entire_screen = TRUE;
1340 if (isset($this->_edit_fns->static_screens[$screen]) || (($screen ==
'metadataschemas') && (isset($this->_edit_fns->static_screens[
'metadataSchemas']))) || (($screen ==
'lookupvalues') && (isset($this->_edit_fns->static_screens[
'lookupValues']))) ) {
1341 $static_keywords = (isset($keywords[
'screens'][$screen])) ? $keywords[
'screens'][$screen] : NULL;
1343 if (!is_null($static_keywords)) {
1344 $print_commit_button = TRUE;
1346 if (!is_null($static_keywords) || $entire_screen) {
1347 if (is_null($static_keywords)) {
1348 $static_keywords = Array();
1350 if ($screen ==
'metadataschemas') {
1351 if ($this->_getStaticScreenKeywordReplacements($owner, $o,
'metadataSchemas', $static_keywords, $entire_screen)) {
1352 $print_commit_button = TRUE;
1354 }
else if ($screen ==
'lookupvalues') {
1355 if ($this->_getStaticScreenKeywordReplacements($owner, $o,
'lookupValues', $static_keywords, $entire_screen)) {
1356 $print_commit_button = TRUE;
1358 }
else if ($screen ==
'metadata') {
1359 $layout_options = $layout->attr(
'options');
1360 if ($this->_getStaticScreenKeywordReplacements($owner, $o, $screen, $static_keywords, $entire_screen, $layout_options)) {
1361 $print_commit_button = TRUE;
1363 }
else if ($this->_getStaticScreenKeywordReplacements($owner, $o, $screen, $static_keywords, $entire_screen)) {
1364 $print_commit_button = TRUE;
1369 if ($screen ==
'metadata')
continue;
1370 if ($screen ==
'workflow')
continue;
1371 if ($screen ==
'tagging')
continue;
1372 if ($screen ==
'settings')
continue;
1373 if ($screen ==
'permissions')
continue;
1374 if ($screen ==
'roles')
continue;
1375 if ($screen ==
'metadataschemas')
continue;
1376 if ($screen ==
'dependants')
continue;
1377 if ($screen ==
'linking')
continue;
1378 if ($screen ==
'history')
continue;
1379 if ($screen ==
'logs')
continue;
1380 if ($screen ==
'preview')
continue;
1381 if ($screen ==
'tagging')
continue;
1382 if ($screen ==
'lookupvalues')
continue;
1383 if ($screen ==
'layouts')
continue;
1387 $file = $this->findLanguageFile(
'screen_'.$screen);
1389 $file = $this->findFile(
'screen_'.$screen);
1394 $root =
new SimpleXMLElement($file, LIBXML_NOCDATA, TRUE);
1395 }
catch (Exception $e) {
1396 throw new Exception(
'Unable to parse localised screen "'.$screen.
'" for asset type "'.$owner->type().
'": '.$e->getMessage());
1400 $root =
new SimpleXMLElement($file, LIBXML_NOCDATA, TRUE);
1405 if ($this->_getLayoutKeywordReplacements($root, $o, $owner, $keywords, $screen, $entire_screen)) {
1406 $print_commit_button = TRUE;
1415 if (isset($keywords[
'custom']) && !empty($keywords[
'custom']) && $order_keyword ==
'custom') {
1416 $custom_replacements = $owner->getCustomKeywordReplacements($keywords[
'custom'], $invoke_backend);
1418 if (!empty($custom_replacements)) {
1419 assert_isset_array_index($custom_replacements,
'replacements');
1420 assert_isset_array_index($custom_replacements,
'print_commit_button');
1421 $replacements = Array();
1424 foreach ($custom_replacements[
'replacements'] as $keyword => $replacement) {
1425 $replacements[
'__custom-'.$keyword] = $replacement;
1427 $this->_tmp[
'layout_keyword_replacements'] = array_merge($this->_tmp[
'layout_keyword_replacements'], $replacements);
1428 if ($custom_replacements[
'print_commit_button']) {
1429 $print_commit_button = TRUE;
1438 if (!isset($keywords[
'layout'])) {
1439 $keywords[
'layout'] = Array();
1444 foreach ($keywords[
'layout'] as $keyword) {
1445 if (($keyword ==
'commit_button') && $print_commit_button) {
1447 $o->commitButton(
'', FALSE);
1448 $this->_tmp[
'layout_keyword_replacements'][
'commit_button'] = ob_get_contents();
1452 }
else if (($keyword ==
'commit_button_clean') && $print_commit_button) {
1454 $o->commitButton(
'', FALSE, FALSE);
1455 $this->_tmp[
'layout_keyword_replacements'][
'commit_button_clean'] = ob_get_contents();
1459 }
else if (($keyword ==
'release_locks_button')) {
1461 submit_button(
'sq_lock_release_manual', translate(
'release_lock_button'),
'',
'accesskey="r"');
1462 $this->_tmp[
'layout_keyword_replacements'][
'release_locks_button'] = ob_get_contents();
1466 }
else if ($keyword ==
'screen_menu') {
1467 $lm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'layout_manager');
1470 if (SQ_IN_LIMBO && isset($_REQUEST[
'limbo_assetid'])) {
1471 $o->addFormActionGetVar(
'limbo_assetid', $_REQUEST[
'limbo_assetid'], TRUE);
1473 $current_location = $o->getCurrentLocation();
1474 list($current_loc_base, $current_loc_query) = explode(
'?', $current_location);
1476 for (reset($this->_screens); NULL !== ($code = key($this->_screens)); next($this->_screens)) {
1477 if (!$lm->hasLayout($owner, $code))
continue;
1478 $url = replace_query_string_vars(Array(
'asset_ei_screen' => rawurlencode($code)), $current_loc_base, $current_loc_query);
1479 $o->addScreen($url, $this->_screens[$code][
'name']);
1481 foreach ($this->_edit_fns->static_screens as $code_name => $data) {
1482 if (!$lm->hasLayout($owner, $code_name)) {
1485 $url = replace_query_string_vars(Array(
'asset_ei_screen' => rawurlencode($code_name)), $current_loc_base, $current_loc_query);
1486 $o->addStaticScreen($url, $data[
'name']);
1489 $o->printScreenMenu();
1490 $this->_tmp[
'layout_keyword_replacements'][
'screen_menu'] = ob_get_contents();
1494 $o->printSimpleContextSwitcher();
1495 $this->_tmp[
'layout_keyword_replacements'][
'context_switcher'] = ob_get_contents();
1500 $this->_tmp[
'layout_keyword_replacements'][$keyword] = $owner->getKeywordReplacement($keyword);
1503 if (strpos($this->_tmp[
'layout_keyword_replacements'][$keyword],
'%globals_') === 0) {
1504 replace_global_keywords($this->_tmp[
'layout_keyword_replacements'][$keyword]);
1510 $o->setBuffering(TRUE);
1512 if (!$print_commit_button) {
1513 $this->_tmp[
'layout_keyword_replacements'][
'commit_button'] =
'';
1514 $this->_tmp[
'layout_keyword_replacements'][
'commit_button_clean'] =
'';
1517 if (!$set_keywords_replacement)
return $this->_tmp[
'layout_keyword_replacements'] ;
1520 $layout->setKeywordReplacements($this->_tmp[
'layout_keyword_replacements']);
1538 function _getStaticScreenKeywordReplacements(&$owner, &$o, $screen, $static_keywords, $get_screen=FALSE, Array $layout_options=Array())
1540 $this->includeStaticScreen($screen);
1541 $print_commit_button = FALSE;
1544 $paint_function =
'paint'.$screen;
1545 if ($paint_function($owner, $o, $this, $static_keywords, $layout_options)) {
1546 $print_commit_button = TRUE;
1550 if ($screen ==
'metadataSchemas') {
1551 $this->_tmp[
'layout_keyword_replacements'][
'metadataschemas-'] = ob_get_contents();
1552 }
else if ($screen ==
'lookupValues') {
1553 $this->_tmp[
'layout_keyword_replacements'][
'lookupvalues-'] = ob_get_contents();
1555 $this->_tmp[
'layout_keyword_replacements'][$screen.
'-'] = ob_get_contents();
1560 return $print_commit_button;
1578 function _getLayoutKeywordReplacements(&$root, &$o, &$owner, $layout_keywords, $screen=
'details', $get_screen=FALSE)
1580 $prefix = $owner->getPrefix();
1581 $print_commit_button = FALSE;
1584 foreach ($root->section as $section) {
1587 $limbo_access = (isset($section->attributes()->limbo_access) && (
int) $section->attributes()->limbo_access == 1) ? TRUE : FALSE;
1588 if ($limbo_access == FALSE)
continue;
1591 $get_section = FALSE;
1592 $section_name = strtolower(str_replace(
' ',
'_', (
string)$section->attributes()->name));
1593 if (isset($layout_keywords[
'screens'][$screen][
'sections'][$section_name])) {
1594 $get_section = TRUE;
1595 $section_keyword = $layout_keywords[
'screens'][$screen][
'sections'][$section_name];
1598 if (!($num_fields = count($section->children()))) {
1602 $section_access = $this->_getAccess($owner, $section, $prefix);
1603 if (!($section_access & SQ_EI_READ)) {
1608 if ($get_section) ob_start();
1609 if ($get_section || $get_screen) {
1610 $o->openSection((
string)$section->attributes()->name);
1613 if (isset($section->function_call)) {
1614 if ($get_section || $get_screen) {
1615 $paint_node = $section->children[0]->children[0];
1617 if (empty($paint_node->attributes[
'name']) || !method_exists($this->_edit_fns, $paint_node->attributes[
'name'])) {
1619 echo translate(
'section_not_found', $section->attributes[
'name']);
1622 if ($this->_edit_fns->{$paint_node->attributes[
'name']}($owner, $o, $prefix)) {
1623 $print_commit_button = TRUE;
1628 for ($j = 0; $j < count($section->children); $j++) {
1629 switch ($section->children[$j]->name) {
1632 if (!empty($section->children[$j]->content)) {
1633 $section_note = $section->children[$j]->content;
1642 $section_note = NULL;
1645 foreach ($section->children() as $field) {
1646 switch ($field->getName()) {
1652 foreach ($field->children() as $sub_field) {
1653 switch ($sub_field->getName()) {
1654 case 'display_name':
1655 $display_name = (string)$sub_field;
1659 $field_note = (string)$sub_field;
1663 if (!is_null($attr_tag)) {
1664 trigger_localised_error(
'SYS0194', E_USER_WARNING);
1666 $attr_tag = $sub_field;
1672 $field_access = $this->_getAccess($owner, $field, $prefix, $section_access);
1673 if (!($field_access & SQ_EI_READ)) {
1677 if (!isset($field->attributes()->format)) {
1678 $field->attributes()->format =
'';
1684 if (isset($field->attributes()->attribute)) {
1686 if (isset($layout_keywords[
'screens'][$screen][
'fields'][(
string)$field->attributes()->attribute])) {
1688 $field_keyword = $layout_keywords[
'screens'][$screen][
'fields'][(string)$field->attributes()->attribute];
1691 if (!$get_field && !$get_section && !$get_screen) {
1695 if ($field->getName() !=
'field')
continue;
1696 $o->openField($display_name, (
string)$field->attributes()->format,
'', isset($field->attributes()->hidden));
1698 $attr = $owner->getAttribute((
string)$field->attributes()->attribute);
1700 if (is_null($attr))
continue;
1701 if (!$attr->setEditParams($attr_tag))
continue;
1703 if (isset($layout_keywords[
'screens'][$screen][
'fields'][(
string)$field->attributes()->attribute]))
1706 if ($get_field) ob_start();
1708 $attr->paint($prefix.
'_'.$attr->id, !(($field_access & SQ_EI_WRITE) && $limbo_access));
1709 if (($field_access & SQ_EI_WRITE) && $limbo_access) {
1710 $print_commit_button = TRUE;
1713 if (!empty($field_note)) {
1715 $field_note = str_replace(
'%description%', $attr->description, $field_note);
1716 $o->note($field_note);
1721 $this->_tmp[
'layout_keyword_replacements'][$field_keyword] = ob_get_contents();
1726 }
else if ($attr_tag->getName() ==
'function_call') {
1728 if (isset($field->attributes()->keyword)) {
1730 if (isset($layout_keywords[
'screens'][$screen][
'fields'][(
string)$field->attributes()->keyword])) {
1732 $field_keyword = $layout_keywords[
'screens'][$screen][
'fields'][(string)$field->attributes()->keyword];
1736 $paint_node = $attr_tag->paint_function;
1737 if ($field->getName() !=
'field')
continue;
1739 $o->openField($display_name, (
string)$field->attributes()->format,
'', isset($field->attributes()->hidden));
1741 if ((!isset($paint_node->attributes()->name)) || !method_exists($this->_edit_fns, (
string)$paint_node->attributes()->name)) {
1742 echo translate(
'painting_funtion_not_found');
1744 if ($get_field) ob_start();
1746 if ($this->_edit_fns->{(
string)$paint_node->attributes()->name}($owner, $o, $prefix)) {
1747 $print_commit_button = TRUE;
1751 $this->_tmp[
'layout_keyword_replacements'][$field_keyword] = ob_get_contents();
1763 if (!empty($field->note)) {
1764 $section_note = (string)$field->note;
1771 if ($get_section || $get_screen) {
1772 if (!empty($section_note)) {
1773 $o->sectionNote($section_note);
1779 $this->_tmp[
'layout_keyword_replacements'][$section_keyword] = ob_get_contents();
1786 if (!isset($this->_tmp[
'layout_keyword_replacements'][$screen.
'-'])) {
1787 $this->_tmp[
'layout_keyword_replacements'][$screen.
'-'] =
'';
1789 $this->_tmp[
'layout_keyword_replacements'][$screen.
'-'] .= ob_get_contents();
1795 return $print_commit_button;
1810 function process(&$owner, &$o, $creating)
1814 $this->_determinePreviewUrl($owner, $o);
1816 $current_screen = (empty($_REQUEST[
'asset_ei_screen'])) ?
'details' : $_REQUEST[
'asset_ei_screen'];
1818 return $this->processInline($owner, $o, $creating, $current_screen);
1834 function processInline(&$owner, &$o, $creating, $current_screen)
1840 if (!count($this->_screens) && empty($this->_edit_fns->static_screens)) {
1847 list($create_sections, $current_screen) = $this->_getCreateSections(FALSE);
1848 if (!count($create_sections))
return FALSE;
1850 $screens = Array($current_screen);
1855 $screens = Array($current_screen);
1857 $lm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'layout_manager');
1858 $layout = $lm->getLayout($owner, $current_screen);
1862 if (!is_null($layout)) {
1863 $keywords = $layout->getLayoutKeywords();
1865 if (isset($keywords[
'screens']) && !empty($keywords[
'screens'])) {
1866 $screens = array_unique(array_merge(array_keys($keywords[
'screens']), $screens));
1869 if (isset($keywords[
'entire_screens']) && !empty($keywords[
'entire_screens'])) {
1870 $screens = array_unique(array_merge(array_keys($keywords[
'entire_screens']), $screens));
1874 if (isset($keywords[
'custom']) && !empty($keywords[
'custom'])) {
1875 $owner->processCustomKeywords($keywords[
'custom']);
1880 foreach ($screens as $active_screen) {
1888 if (!$owner->adminAccess(
'')) {
1889 $allowed_screens = $this->getAllowedScreens($owner);
1891 if (!empty($allowed_screens)) {
1892 $user_is_not_allowed = TRUE;
1893 foreach ($allowed_screens as $allowed_screen) {
1894 if (isset($allowed_screen[
'screen']) && ($allowed_screen[
'screen'] == $active_screen)) {
1895 $user_is_not_allowed = FALSE;
1899 if ($user_is_not_allowed) {
1901 $GLOBALS[
'SQ_SYSTEM']->paintLogin(translate(
'login'), translate(
'cannot_access_asset', htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)));
1911 if (isset($this->_edit_fns->static_screens[$active_screen])) {
1914 $old_status = $owner->status;
1919 $process_function =
'process'.$active_screen;
1920 $this->includeStaticScreen($active_screen);
1921 if ($process_function($owner, $o, $this)) {
1928 if (isset($owner->_tmp[
'reverting_to_system_version']) && $owner->_tmp[
'reverting_to_system_version']) {
1932 $file = @$this->findLanguageFile(
'screen_'.$active_screen);
1936 $file = @$this->findFile(
'screen_'.$active_screen);
1943 $root =
new SimpleXMLElement($file, LIBXML_NOCDATA, TRUE);
1944 }
catch (Exception $e) {
1945 throw new Exception(
'Unsable to find static screen "'.$active_screen.
'" for asset type "'.$owner->type().
'": '.$e->getMessage());
1949 $root_from_file = file_get_contents($file);
1950 $root = $output = simplexml_load_string($root_from_file);
1955 if (empty($this->_screens[$active_screen])) {
1956 trigger_localised_error(
'SYS0076', E_USER_WARNING, $active_screen);
1961 $root = $this->findScreen(
'screen_'.$active_screen);
1965 if (!is_null($root) && $owner->writeAccess(
'')) {
1968 $prefix = $owner->getPrefix();
1972 foreach ($root->section as $section) {
1975 if (SQ_IN_LIMBO && (!isset($section->attributes()->limbo_access) || (
int)$section->attributes()->limbo_access == 0)) {
1981 if ($creating && empty($create_sections[(
string)$section->attributes()->name])) {
1985 if (!($num_fields = count($section->children()))) {
1989 $section_access = $this->_getAccess($owner, $section, $prefix);
1990 if (!($section_access & SQ_EI_READ)) {
1995 if ($section->function_call) {
1997 $process_node = $section->function_call->process_function;
2000 if (empty($process_node) || empty($process_node->attributes()->name)) {
2003 }
else if (!method_exists($this->_edit_fns, (
string)$process_node->attributes()->name)) {
2004 trigger_localised_error(
'SYS0188', E_USER_WARNING, $section->attributes()->name);
2007 if ($creating && !in_array((
string)$process_node->attributes()->name, $create_sections[(string)$section->attributes()->name])) {
2011 if ($this->_edit_fns->{(
string)$process_node->attributes()->name}($owner, $o, $prefix)) {
2020 foreach ($section->field as $field) {
2021 if ($field->getName() ==
'note')
continue;
2023 $child_fields = $field->children();
2031 foreach ($child_fields as $child) {
2032 $child_name = $child->getName();
2033 if (($child_name !=
'display_name') && ($child_name !=
'note')) {
2034 $last_child = $child;
2039 $field_access = $this->_getAccess($owner, $field, $prefix, $section_access);
2040 if (!($field_access & SQ_EI_WRITE)) {
2044 if (!empty($field->attributes()->attribute)) {
2046 if ($field->getName() !=
'field' || ($creating && (empty($field->attributes()->attribute) || !in_array((
string)$field->attributes()->attribute, $create_sections[(string)$section->attributes()->name])))) {
2050 $attr = $owner->getAttribute((
string)$field->attributes()->attribute);
2051 if (is_null($attr))
continue;
2052 if (!$attr->setEditParams($last_child))
continue;
2054 $revert_attr = $attr;
2055 $attr->process($prefix.
'_'.$attr->id, $owner->id);
2056 if ($attr->processed && $owner->setAttrValue($attr->name, $attr->value)) {
2060 $attr = $revert_attr;
2062 unset($revert_attr);
2064 }
else if ($last_child->getName() ==
'function_call') {
2067 if (!isset($last_child->process_function))
continue;
2069 $process_node = $last_child->process_function;
2072 if ($field->getName() !=
'field' || ($creating && !in_array((
string)$process_node->attributes()->name, $create_sections[(string)$section->attributes()->name]))) {
2077 if (!isset($process_node->attributes()->name)) {
2080 }
else if (!method_exists($this->_edit_fns, (
string)$process_node->attributes()->name)) {
2081 trigger_localised_error(
'SYS0187', E_USER_WARNING, (
string)$section->attributes()->name, (string)$last_child);
2083 if ($this->_edit_fns->{(
string)$process_node->attributes()->name}($owner, $o, $prefix)) {
2100 if ($owner->saveAttributes()) $saved = TRUE;
2122 function _getAccess(&$owner, $node, $prefix, $inherit_access=NULL)
2127 if (isset($node->attributes()->show_if)) {
2128 $show_if_fn = (string)$node->attributes()->show_if;
2129 $edit_fns = $owner->getEditFns();
2131 if (method_exists($edit_fns, $show_if_fn)) {
2132 if (!$edit_fns->$show_if_fn($owner, $prefix))
return 0;
2135 trigger_localised_error(
'SYS0136', E_USER_WARNING, $show_if_fn, $node->name);
2141 if (!isset($node->attributes()->write_access) && !is_null($inherit_access)) {
2142 if ($inherit_access & SQ_EI_WRITE) {
2143 $access |= SQ_EI_WRITE;
2148 $wa = (!isset($node->attributes()->write_access)) ?
'write:all' : (string)$node->attributes()->write_access;
2150 if (preg_match(
'/^(.+):(.*)$/', $wa, $matches)) {
2152 if ($owner->writeAccess($matches[2])) {
2153 switch ($matches[1]) {
2155 if ($GLOBALS[
'SQ_SYSTEM']->userRoot()) {
2156 $access |= SQ_EI_WRITE;
2160 if ($GLOBALS[
'SQ_SYSTEM']->userRoot() || $GLOBALS[
'SQ_SYSTEM']->userSystemAdmin()) {
2161 $access |= SQ_EI_WRITE;
2165 if ($owner->adminAccess($matches[2])) {
2166 $access |= SQ_EI_WRITE;
2170 $access |= SQ_EI_WRITE;
2184 if ($access & SQ_EI_WRITE) {
2185 $access |= SQ_EI_READ;
2189 if (!isset($node->attributes()->read_access) && !is_null($inherit_access)) {
2190 if ($inherit_access & SQ_EI_READ) {
2191 $access |= SQ_EI_READ;
2196 $ra = (!isset($node->attributes()->read_access)) ?
'read' : (string)$node->attributes()->read_access;
2199 if ($GLOBALS[
'SQ_SYSTEM']->userRoot()) {
2200 $access |= SQ_EI_READ;
2204 if ($GLOBALS[
'SQ_SYSTEM']->userRoot() || $GLOBALS[
'SQ_SYSTEM']->userSystemAdmin()) {
2205 $access |= SQ_EI_READ;
2209 if ($owner->readAccess()) $access |= SQ_EI_READ;
2213 if (preg_match(
'/^(admin|write):(.*)$/', $ra, $matches)) {
2214 if ($matches[1] ==
'admin') {
2215 if ($owner->adminAccess($matches[2])) {
2216 $access |= SQ_EI_READ;
2219 if ($owner->writeAccess($matches[2])) {
2220 $access |= SQ_EI_READ;
2243 function getAllowedScreens(&$owner)
2248 $user =& $GLOBALS[
'SQ_SYSTEM']->am->getAsset($GLOBALS[
'SQ_SYSTEM']->currentUserId());
2249 $groups = $user->getUserGroups();
2250 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($user);
2252 if (empty($groups))
return Array();
2254 $bind_vars = Array();
2255 foreach ($groups as $key => $group) {
2256 $bind_vars[
'group_'.$key] = (string) $group;
2259 $sql =
'SELECT screen, section
2260 FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_edit_access ';
2261 $where =
'userid IN (:'.implode(
', :', array_keys($bind_vars)).
')';
2263 require_once SQ_FUDGE_PATH.
'/db_extras/db_extras.inc';
2264 $where .=
' AND (type_code = :null_type_code
2266 SELECT inhd_type_code
2267 FROM sq_ast_typ_inhd
2268 WHERE type_code = :type_code
2270 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where);
2274 foreach ($bind_vars as $bind_var => $bind_value) {
2280 }
catch (Exception $e) {
2281 throw new Exception(
'Unable to get allowed screens for type code: '.$owner->type().
' due to database error: '.$e->getMessage());
2283 return $allowed_screens;
2298 function findFile($file_name, $throw_error=TRUE)
2300 $file_name =
'edit_interface_'.$file_name.
'.xml';
2303 for ($i = 0; $i < count($this->_dirs); $i++) {
2304 if (file_exists($this->_dirs[$i].
'/'.$file_name)) {
2305 $file = $this->_dirs[$i].
'/'.$file_name;
2309 if ( (!$file) && $throw_error) {
2310 trigger_localised_error(
'SYS0065', E_USER_WARNING, $file_name, $this->_type_code);
2331 function findLanguageFile($file_name, $include_asset=TRUE)
2333 $type_parents = $GLOBALS[
'SQ_SYSTEM']->am->getTypeAncestors($this->_type_code, $include_asset);
2334 array_unshift($type_parents, $this->_type_code);
2337 $test_locales = Array();
2338 foreach ($GLOBALS[
'SQ_SYSTEM']->lm->locale_stack as $locale) {
2339 list($lang, $country, $variant) = $GLOBALS[
'SQ_SYSTEM']->lm->getLocaleParts($locale);
2341 if (!is_null($variant)) {
2342 $test_locales[] = $lang.
'_'.$country.
'@'.$variant;
2344 if (!is_null($country)) {
2345 $test_locales[] = $lang.
'_'.$country;
2347 $test_locales[] = $lang;
2350 foreach ($test_locales as $locale) {
2352 foreach ($type_parents as $type_code) {
2353 $file_path = SQ_DATA_PATH.
'/private/asset_types/'.$type_code.
'/localised_screens/'.$file_name.
'.'.$locale;
2354 if (file_exists($file_path)) {
2360 if (!empty($file))
break;
2385 function &findScreen($screen_name)
2389 if (($file = $this->findFile($screen_name))) {
2391 $root =
new SimpleXMLElement($file, LIBXML_NOCDATA, TRUE);
2392 }
catch (Exception $e) {
2393 throw new Exception(
'Unable to parse screen file "'.$file.
'": '.$e->getMessage());
2398 if (!empty($root) && (count($root->children()) > 0)) {
2399 $lang_file = $this->findLanguageFile($screen_name);
2400 if (empty($lang_file)) {
2401 trigger_localised_error(
'SYS0197', E_USER_WARNING, $screen_name);
2405 $root_xml = file_get_contents($lang_file);
2406 $root = simplexml_load_string($root_xml);
2425 function _getCreateSections($painting)
2427 $create_sections = Array();
2429 if (!($create_file = $this->findFile(
'create'))) {
2430 return Array($create_sections,
'');
2434 $root = simplexml_load_file($create_file);
2435 }
catch (Exception $e) {
2436 throw new Exception(
'Unable to parse Create screen file "'.$create_file.
'": '.$e->getMessage());
2440 foreach ($root->section as $section) {
2442 $create_sections[(string)$section->attributes()->name] = Array();
2445 foreach ($section->children() as $field) {
2446 switch ($field->getName()) {
2447 case 'function_call' :
2449 $node_name =
'paint_function';
2451 $node_name =
'process_function';
2453 $fn_node = $field->{$node_name};
2454 $create_sections[(string)$section->attributes()->name][] = (string)$fn_node->attributes()->name;
2458 if (isset($field->attributes()->attribute)) {
2459 $create_sections[(string)$section->attributes()->name][] = (string)$field->attributes()->attribute;
2460 }
else if (isset($field->function_call)) {
2463 $node_name =
'paint_function';
2465 $node_name =
'process_function';
2467 $fn_node = $field->function_call->{$node_name};
2468 if (isset($fn_node[
'name'])) {
2469 $create_sections[(string)$section->attributes()->name][] = (string)$fn_node->attributes()->name;
2472 throw new Exception(
'Unable to parse Create screen file "'.$create_file.
'": it contains a field tag without an attribute or function call specified:'.$field->asXml());
2482 return Array($create_sections, (
string)$root->attributes()->screen);
2496 function includeStaticScreen($screen)
2498 require_once SQ_INCLUDE_PATH.
'/asset_static_screens/'.$screen.
'.inc';
2513 function findSpecificFile($file_name, $throw_error=TRUE)
2515 if (file_exists($file_name))
return $file_name;
2517 trigger_localised_error(
'SYS0065', E_USER_WARNING, $file_name, $this->_type_code);
2533 function &findSpecificScreen($specific_file)
2536 if (($file = $this->findSpecificFile($specific_file))) {
2538 $root =
new SimpleXMLElement($file, LIBXML_NOCDATA, TRUE);
2540 }
catch (Exception $e) {
2541 throw new Exception(
'Unable to parse specific screen file "'.$file.
'": '.$e->getMessage());
2548 if (!empty($root) && (count($root->children()) > 0)) {
2549 $lang_file = $this->findLanguageFile($screen_name, FALSE);
2550 if (empty($lang_file)) {
2554 $root = unserialize(file_get_contents($lang_file));
2579 function getSimpleEditKeywords($asset_type=
'page_standard', &$o)
2584 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($asset_type);
2585 $as =
new $asset_type();
2586 $asset_info = $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($asset_type);
2587 $asset_dir = SQ_SYSTEM_ROOT.
'/'.$asset_info[
'dir'];
2588 $ef = $as->getEditFns();
2590 $screens_static = Array();
2591 $screens_specific = Array();
2593 foreach ($ef->static_screens as $key => $screen) {
2594 $screens_static[$screen[
'name']] = $key;
2597 $screens_all = $screens_static;
2598 foreach ($ei->getScreens() as $key => $screen) {
2599 $screens_specific[$screen[
'name']] = $key;
2600 $screens_all[$screen[
'name']] = $key;
2605 <div><h1 style=
"font-size:1.7em;">General Screens</h1></div>
2610 foreach ($screens_all as $current_screen_name => $current_screen) {
2615 if ($current_screen ==
'dependants')
continue;
2616 $section_array = Array();
2618 if ($this->findFile(
'static_screen_'.$current_screen, FALSE)) {
2619 $root = $this->findScreen(
'static_screen_'.$current_screen);
2621 foreach ($root->section as $section) {
2624 if ((isset($section->attributes()->limbo_access)) && (((int) $section->attributes()->limbo_access) === 0)) {
2628 $current_section_name = (string) $section->attributes()->name;
2630 if (!isset($section_array[$current_section_name])) {
2631 $section_array[$current_section_name] = Array();
2634 foreach ($section->children() as $field) {
2635 $keyword = (string) $field->attributes()->code;
2636 if (!empty($keyword)) {
2637 $section_array[$current_section_name][] = $keyword;
2644 if ($this->findFile(
'screen_'.$current_screen, FALSE)) {
2645 $root = $this->findScreen(
'screen_'.$current_screen);
2647 foreach ($root->section as $section) {
2650 if ((isset($section->attributes()->limbo_access)) && (((int) $section->attributes()->limbo_access) === 0)) {
2654 $current_section_name = (string) $section->attributes()->name;
2655 if (!isset($section_array[$current_section_name])) {
2656 $section_array[$current_section_name] = Array();
2659 foreach ($section->children() as $field) {
2660 $keyword = (string) $field->attributes()->attribute;
2661 if (!empty($keyword)) {
2662 $section_array[$current_section_name][] = $keyword;
2669 if ($tmpFile=$this->findSpecificFile($asset_dir.
'/edit_interface_screen_'.$current_screen.
'.xml', FALSE)) {
2671 $root = $this->findSpecificScreen($tmpFile);
2673 foreach ($root->section as $section) {
2676 if ((isset($section->attributes()->limbo_access)) && ((int) $section->attributes()->limbo_access === 0)) {
2680 $current_section_name = (string) $section->attributes()->name;
2682 if (!isset($section_array[$current_section_name])) {
2683 $section_array[$current_section_name] = Array();
2686 foreach ($section->children() as $field) {
2687 $keyword = (string) $field->attributes()->attribute;
2688 if (empty($keyword)) {
2689 $keyword = $field->attributes()->keyword;
2691 if (!empty($keyword)) {
2692 $section_array[$current_section_name][] = $keyword;
2699 foreach ($section_array as $key => $value) {
2700 $value = (array_unique($value));
2701 $section_array[$key]= $value;
2707 <style type=
"text/css">
2708 .screen_kw, .section_kw, .field_kw {
2716 .section_title, .field_title {
2725 #limbo_keywords .sq-backend-field {
2729 <div
id=
"limbo_keywords">
2734 reset($screens_specific);
2736 if (!strcmp($current_screen, current($screens_specific))) {
2740 <div><h1 style=
"font-size:1.7em;">
Asset Specific Screens</h1></div>
2749 if ($current_screen ==
'formats')
continue;
2751 if (strtolower($current_screen) !=
'contents') {
2752 $o->openSection($current_screen_name.
' screen'.
' <span class="screen_kw">(%'.str_replace(
' ',
'_', strtolower($current_screen)).
'-%)</span>');
2754 if (in_array($asset_type, Array(
'page_standard',
'calendar_event_multi_date'))) {
2755 $o->openSection($current_screen_name.
' screen'.
' <span class="screen_kw">(%__custom-'.str_replace(
' ',
'_', strtolower($current_screen)).
'%)</span>');
2760 $filter_list = Array(
'image');
2761 if (!in_array($asset_type, $filter_list)) {
2762 $o->openSection($current_screen_name.
' screen'.
' <span class="screen_kw">(%'.str_replace(
' ',
'_', strtolower($current_screen)).
'-%)</span>');
2769 foreach ($section_array as $tmp_section => $tmp_fields) {
2771 if (strlen($tmp_section) > 0) {
2772 $o->openSection(
'<span class="section_title">Section <strong>"'.$tmp_section.
'"</strong></span> <span class="section_kw">(%'.$current_screen.
'-S_'.strtolower(str_replace(
' ',
'_', $tmp_section)).
'%)</span>');
2774 $o->openSection(
' ');
2778 foreach ($tmp_fields as $tmp_field) {
2779 $o->openField(
'<span class="field_title">Field <strong>"'.$tmp_field.
'"</strong></span>');
2780 echo
'<span class="field_kw">%'.$current_screen.
'-F_'.$tmp_field.
'%</span>';
2787 if (!strcmp(strtolower($current_screen_name),
'metadata')) {
2788 $o->openField(
'<span class="field_title"><strong>Print a specific metadata section name</strong></span> ');
2789 echo
'<span class="field_kw">%metadata-F_section_{metadata section id}_name%</span>';
2791 $o->openField(
'<span class="field_title"><strong>Print a specific metadata section description</strong></span> ');
2792 echo
'<span class="field_kw">%metadata-F_section_{metadata section id}_description%</span>';
2794 $o->openField(
'<span class="field_title"><strong>Print a specific metadata section interface</strong></span> ');
2795 echo
'<span class="field_kw">%metadata-F_section_{metadata section id}_values%</span>';
2797 $o->openField(
'<span class="field_title"><strong>Print a specific metadata schema field</strong></span> ');
2798 echo
'<span class="field_kw">%metadata-F_{metadata schema field id}%</span>';
2801 echo
'<span class="field_title">For example: %metadata-F_99999%</span>';
2822 function _getLayoutKeywordsOrder($layout)
2826 $custom_pos = FALSE;
2827 $screen_pos = FALSE;
2830 $layout_keywords_order = Array(
2835 $containers = $layout->getContainers();
2837 foreach (array_keys($containers) as $key) {
2839 $container = $containers[$key];
2841 $container->getEditFns()->paint($container, FALSE, FALSE);
2842 $raw_content = ob_get_contents();
2845 $custom_pos = strpos($raw_content,
'%__custom');
2847 $screen_pos_metadata = strpos($raw_content,
'%metadata');
2848 $screen_pos_lookups = strpos($raw_content,
'%lookupvalues-');
2850 if ($screen_pos_metadata !== FALSE) $screen_pos = $screen_pos_metadata;
2852 if (($screen_pos_lookups !== FALSE) && ($screen_pos_metadata > $screen_pos_lookups)) $screen_pos = $screen_pos_lookups;
2855 if ($custom_pos || $screen_pos) {
2864 if (($screen_pos > $custom_pos && $custom_pos !== FALSE) || ($custom_pos !== FALSE && $screen_pos === FALSE)) {
2865 $layout_keywords_order = Array(
2871 return $layout_keywords_order;