17 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
39 function paintLayouts(&$owner, &$o, &$ei, $keywords=NULL)
41 $root = $ei->findScreen(
'static_screen_layouts');
42 $prefix = $owner->getPrefix();
43 $write_access = $owner->writeAccess(
'attributes');
45 $lookups = $owner->getLookups(
'url');
46 $lookup_values = $owner->getLookupValues();
48 $return_lookup = FALSE;
50 $current_value = Array();
51 $current_value = _formatLayoutCode($lookup_values);
53 foreach ($root->section as $section) {
54 $o->openSection((is_null($section[
'display_name'])) ? $section[
'name'] : $section[
'display_name']);
57 if (is_null($keywords)) {
58 if (SQ_IN_LIMBO && ((
string) $section[
'name'] ===
'limbo_access' || (
int) $section[
'limbo_access'] === 0)) {
63 if (!is_null($keywords) && isset($keywords[
'sections'][strtolower($section->attributes()->name)])) {
67 foreach ($section->children() as $field) {
71 $child = strtolower((
string) $field[
'code']);
75 if ($owner->adminAccess(
'settings')) {
76 $return_lookup = TRUE;
80 $types = $GLOBALS[
'SQ_SYSTEM']->am->getTypeList();
81 asset_type_chooser($prefix.
'_add_layouts', TRUE, Array());
85 $return_lookup = TRUE;
91 if (!is_null($current_value)) {
92 foreach ($current_value as $type_code => $values) {
96 $uc_type_code = ucwords(str_replace(
'_',
' ', $type_code));
97 $o->openSection($uc_type_code);
100 $return_lookup = TRUE;
105 check_box($prefix.
'_remove['.$type_code.
']');
106 label(translate(
'remove_customisations_for', $uc_type_code), $prefix.
'_remove['.$type_code.
']');
111 $defined_screens = 0;
112 foreach ($values as $screen_key => $assetid) {
113 if ($screen_key !=
'noscreen') {
116 <table
class=
"sq-backend-table">
118 <td
class=
"sq-backend-table-header" width=
"33%"><?php echo translate(
'screen_name'); ?></td>
119 <td
class=
"sq-backend-table-header" width=
"33%"><?php echo translate(
'layout'); ?></td>
120 <?php
if ($write_access) {
122 <td align=
"center" class=
"sq-backend-table-header" width=
"33%"><?php echo translate(
'remove'); ?></td>
127 <td
class=
"sq-backend-table-cell">
128 <?php echo ucfirst($screen_key) ?>
130 <td
class=
"sq-backend-table-cell">
133 asset_finder($prefix.
'_find['.$type_code.
'@'.$screen_key.
']', $assetid, Array(
'layout' =>
'I'));
135 if (empty($assetid)) {
136 echo
'<em>'.translate(
'none').
'</em>';
138 echo get_asset_tag_line($assetid);
143 <?php
if ($write_access) {
145 <td align=
"center" class=
"sq-backend-table-cell">
146 <?php check_box($prefix.
'_remove_screen['.$type_code.
'@'.$screen_key.
']'); ?>
158 if (!($defined_screens > 0)) {
159 if (!$owner->adminAccess(
'settings')) {
160 $o->openField(
' ');
161 echo
'No layouts defined for any of '.$uc_type_code.
"'s screens";
172 echo translate(
'add_layout');
177 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($type_code);
178 $as =
new $type_code();
179 $ef = $as->getEditFns();
181 $screens = Array(
'');
182 foreach (array_keys($ef->static_screens) as $screen) {
183 $screens[] = $screen;
185 foreach (array_keys($ei->getScreens()) as $screen) {
186 $screens[] = $screen;
190 $screens = array_unique(array_diff($screens, array_keys($values)));
192 $uc_screens = Array();
193 foreach ($screens as $screen) {
194 $uc_screens[$screen] = ucfirst($screen);
197 combo_box($prefix.
'_screens['.$type_code.
']', $uc_screens, FALSE, Array());
210 if (!is_null($keywords) && isset($keywords[
'fields'][strtolower((
string) $field[
'code'])])) {
214 if ($print_note && (!is_null($field->note)) && (strlen((
string)$field->note) > 0)) {
215 $o->openField(
' ');
216 $o->note((
string) $field->note);
222 return $return_lookup;
237 function processLayouts(&$owner, &$o, &$ei)
239 $prefix = $owner->getPrefix();
240 $write_access = $owner->writeAccess(
'lookups');
243 if (!$write_access)
return FALSE;
246 $layouts = $owner->getLookupValues();
249 if (!empty($layouts)) {
250 $urls = array_keys($layouts);
252 $all_urls = $owner->getURLs();
255 foreach ($all_urls as $url) {
256 $urls[] = $url[
'url'];
262 trigger_localised_error(
'SYS0330', E_USER_WARNING);
266 if (isset($_POST[$prefix.
'_add_layouts']) && !empty($_POST[$prefix.
'_add_layouts'])) {
267 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
268 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
271 $layout_schemas = Array();
272 foreach ($layouts as $layout_designs) {
273 $layout_schemas[] = key($layout_designs);
277 $prev_post = Array();
279 foreach ($_POST[$prefix.
'_add_layouts'] as $type_code) {
281 if (in_array($type_code, $prev_post)) {
284 $prev_post[] = $type_code;
288 if (!empty($type_code)) {
289 $layout_schema =
'layout::'.$type_code.
'::noscreen';
290 foreach ($urls as $url) {
291 $layouts[$url][$layout_schema] = Array();
292 $layouts[$url][$layout_schema][
'value'] = 0;
297 if (!$owner->setLookupValues($layouts)) {
298 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
299 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
302 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
303 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
308 if (isset($_POST[$prefix.
'_find']) && !empty($_POST[$prefix.
'_find'])) {
309 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
310 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
311 foreach ($_POST[$prefix.
'_find'] as $key => $value) {
312 $details = explode(
'@', $key);
315 if (!isset($value[
'assetid']) || empty($value[
'assetid'])) {
318 $assetid = $value[
'assetid'];
322 $lookup =
'layout::'.$details[0].
'::'.$details[1];
325 foreach ($urls as $url) {
326 if (in_array($lookup, $layouts[$url])) {
327 unset($layouts[$url][$lookup]);
331 if (!isset($layouts[$url][$lookup])) {
332 $layouts[$url][$lookup] = Array();
334 $layouts[$url][$lookup][
'value'] = $assetid;
338 if (!$owner->setLookupValues($layouts)) {
339 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
340 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
343 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
344 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
348 if (isset($_POST[$prefix.
'_screens']) && !empty($_POST[$prefix.
'_screens'])) {
349 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
350 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
351 foreach ($_POST[$prefix.
'_screens'] as $type_code => $screen) {
353 if (empty($screen))
continue;
356 $lookup =
'layout::'.$type_code.
'::'.$screen;
358 foreach ($urls as $url) {
360 if (in_array($lookup, $layouts[$url]))
continue;
362 $layouts[$url][$lookup] = Array();
363 $layouts[$url][$lookup][
'value'] = 0;
364 if (!empty($screen)) {
366 unset($layouts[$url][
'layout::'.$type_code.
'::noscreen']);
371 if (!$owner->setLookupValues($layouts)) {
372 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
373 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
376 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
377 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
381 if (isset($_POST[$prefix.
'_remove_screen']) && !empty($_POST[$prefix.
'_remove_screen'])) {
382 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
383 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
384 foreach ($_POST[$prefix.
'_remove_screen'] as $key => $value) {
385 $details = explode(
'@', $key);
387 foreach ($urls as $url) {
389 unset($layouts[$url][
'layout::'.$details[0].
'::'.$details[1]]);
395 foreach ($layouts[$url] as $looking_key => $looking_value) {
396 $search_string =
'/^layout::'.$details[0].
'::/i';
397 if (preg_match($search_string, $looking_key)) {
401 if (!$another_entry) {
402 $layouts[$url][
'layout::'.$details[0].
'::noscreen'] = Array();
403 $layouts[$url][
'layout::'.$details[0].
'::noscreen'][
'value'] = 0;
408 if (!$owner->setLookupValues($layouts)) {
409 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
410 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
413 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
414 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
418 if (isset($_POST[$prefix.
'_remove']) && !empty($_POST[$prefix.
'_remove'])) {
419 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
420 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
422 foreach ($_POST[$prefix.
'_remove'] as $type_code => $value) {
424 foreach ($urls as $url) {
425 foreach ($layouts[$url] as $lookup_key => $lookup_value) {
426 $search_string =
'/^layout::'.$type_code.
'::/i';
427 if (preg_match($search_string, $lookup_key)) {
428 unset($layouts[$url][$lookup_key]);
435 if (!$owner->setLookupValues($layouts)) {
436 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
437 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
440 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
441 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
457 function _formatLayoutCode($lookup_values)
459 $return_value = Array();
462 if (empty($lookup_values))
return $return_value;
464 foreach ($lookup_values as $item) {
466 foreach ($item as $lookup => $value) {
467 if (preg_match(
'/^layout::/i', $lookup)) {
468 $layout_format = explode(
'::', $lookup);
469 if (!isset($return_value[$layout_format[1]])) {
470 $return_value[$layout_format[1]] = Array();
472 $return_value[$layout_format[1]][$layout_format[2]] = $value[
'value'];
477 return $return_value;