18 require_once SQ_INCLUDE_PATH.
'/asset_edit/asset_edit_fns.inc';
42 $this->static_screens = Array();
45 $this->static_screens[
'details'][
'name'] = translate(
'details');
46 $this->static_screens[
'details'][
'force_unlock'] = FALSE;
63 $write_access = $asset->writeAccess(
'attributes');
67 ?><style type=
"text/css">
68 .sq-backend-triggers-component-header {
69 background-color: #666;
74 .sq-backend-triggers-component-global-options {
75 background-color: #eee;
77 border-bottom: 1px dotted black;
78 border-top: 1px dotted black;
81 .sq-backend-triggers-component-type-info{
87 .sq-backend-triggers-component-controls {
91 .sq-backend-triggers-component-block-wrapper {
95 .sq-backend-triggers-component-body {
98 background-color: #fff;
101 .sq-backend-triggers-
new-component-selector {
107 .sq-backend-triggers-component-wrapper {
108 background-color: #eee;
109 border: 1px solid black;
113 </style><script type=
"text/javascript">
117 function moveUp(div) {
118 previous = div.previousSibling;
119 if (previous == null) {
122 while (previous.className != div.className) {
123 previous = previous.previousSibling;
124 if (previous == null) {
128 div.parentNode.insertBefore(div, previous);
134 function moveDown(div) {
135 next = div.nextSibling;
136 while (next.className != div.className) {
137 next = next.nextSibling;
142 div.parentNode.insertBefore(next, div);
148 function deleteDiv(div) {
149 if(confirm(js_translate(
'confirm_delete_component'))) {
150 div.parentNode.removeChild(div);
166 componentOrderer =
function(field_id, count)
168 this.field_id = field_id;
170 this.values = Array();
173 count = parseInt(count);
174 for (i=0; i<count; i++) {
179 this.moveUp =
function(value)
181 var key = this.keys[value];
188 this.swap(key, new_key);
192 this.moveDown =
function(value)
194 var key = this.keys[value];
195 if (key == this.values.length-1) {
201 this.swap(key, new_key);
205 this.
remove =
function(value)
207 var key = this.keys[value];
208 this.values.splice(key,1);
209 this.keys[value] = null;
211 for (var i=0; i<this.values.length; i++) {
212 this.keys[this.values[i]] = i;
218 this.swap =
function(key1, key2)
220 var val1 = this.values[key1];
221 var val2 = this.values[key2];
223 this.values[key1] = val2;
224 this.values[key2] = val1;
226 this.keys[val1] = key2;
227 this.keys[val2] = key1;
231 this.update =
function()
233 var joined = this.values.join();
234 document.getElementById(this.field_id).value = joined;
242 if (is_null($tm))
return FALSE;
245 $event_type_list = $tm->_getEventList();
246 asort($event_type_list);
248 $events = $asset->attr(
'events');
251 $events_selected = FALSE;
252 $event_prefix = $prefix.
'[events]';
253 $event_count = count($event_type_list);
256 $events_per_column = floor($event_count / $event_columns);
257 $extra_in_columns = $event_count % $event_columns;
259 $current_event_no = 0;
262 echo
'<div style="margin-bottom: 2ex;">';
264 foreach ($event_type_list as $e_type => $e_name) {
266 if ($current_event_no == $max_this_col) {
268 $max_this_col = $max_this_col + $events_per_column;
269 if ($extra_in_columns) {
276 if (isset($events[$e_type])) {
282 $events_selected = $checked || $events_selected;
285 if ($current_column && $current_event_no) {
288 echo
'<td valign="top" style="padding-right: 3ex;">';
294 check_box($event_prefix.
'[]', $e_type, $checked,
'',
'id="'.$event_prefix.
'_'.$e_type.
'"');
295 label($e_name, $event_prefix.
'_'.$e_type);
298 if ($checked) echo
'<li>'.$e_name.
'</li>';
301 if ($current_event_no == $event_count) echo
'</td>';
305 echo
'</tr></table>';
308 if (!$write_access && !$events_selected) {
309 echo
'<strong>'.translate(
'no_event_selected').
'</strong>';
314 return $write_access;
331 $write_access = $asset->writeAccess(
'attributes');
332 if (!$write_access)
return FALSE;
334 $edit_data = array_get_index($_REQUEST, $prefix);
337 $raw_events = array_get_index($edit_data,
'events', Array());
338 $processed_events = Array();
339 foreach ($raw_events as $one_event_type) {
340 $processed_events[$one_event_type] = $one_event_type;
343 $asset->setAttrValue(
'events', $processed_events);
361 $write_access = $asset->writeAccess(
'attributes');
364 if (is_null($tm))
return FALSE;
367 $condition_type_list = $tm->_getConditionList();
368 ksort($condition_type_list);
370 $conditions = $asset->attr(
'conditions');
374 <div
class=
"sq-backend-triggers-component-block-wrapper">
375 <div
class=
"sq-backend-triggers-component-block">
378 $multiple_status = Array();
379 $type_instance_count = Array();
380 foreach ($condition_type_list as $type => $name) {
381 $multiple_status[$type] = $tm->_isMultipleConditionAllowed($type);
382 $type_instance_count[$type] = 0;
385 $condition_prefix = $prefix.
'[conditions]';
386 $condition_order_prefix = $prefix.
'[condition_order]';
389 foreach ($conditions as $condition) {
390 $type = $condition[
'type'];
395 if (!$multiple_status[$type] && $type_instance_count[$type] != 0) {
399 $type_instance_count[$type]++;
401 $data = $condition[
'data'];
402 $inverse_condition = array_get_index($condition,
'inverse_condition', FALSE);
404 $data_prefix = $condition_prefix.
'['.$i.
'][data]';
405 $type_prefix = $condition_prefix.
'['.$i.
'][type]';
406 $delete_prefix = $condition_prefix.
'['.$i.
'][delete]';
407 $inverse_condition_prefix = $condition_prefix.
'['.$i.
'][inverse_condition]';
409 $interface = $tm->_getComponentInterface($type, $data, $data_prefix, $write_access, $asset, $i);
410 $type_name = $tm->_getComponentName($type);
412 <div
class=
"sq-backend-triggers-component-wrapper">
413 <div
class=
"sq-backend-triggers-component-header">
414 <div
class=
"sq-backend-triggers-component-type-info">
415 <?php echo $type_name; ?>
417 <div
class=
"sq-backend-triggers-component-controls">
421 <input type=
"checkbox" name=
"<?php echo $delete_prefix; ?>" >
422 <?php echo label(translate(
'delete'), $delete_prefix); ?>
423
424 <a href=
"#" onclick=
"moveUp(this.parentNode.parentNode.parentNode); conditionOrdererObject.moveUp(<?php echo $i; ?>); return false;"><script language=
"JavaScript" type=
"text/javascript">sq_print_icon(
"<?php echo sq_web_path('lib').'/web/images/icons/up_arrow.png' ?>",
"16",
"16",
"Move Up");</script></a>
425 <a href=
"#" onclick=
"moveDown(this.parentNode.parentNode.parentNode); conditionOrdererObject.moveDown(<?php echo $i; ?>); return false;"><script language=
"JavaScript" type=
"text/javascript">sq_print_icon(
"<?php echo sq_web_path('lib').'/web/images/icons/down_arrow.png' ?>",
"16",
"16",
"Move Down");</script></a>
433 <div
class=
"sq-backend-triggers-component-global-options">
435 if (!$write_access) {
436 $extras =
'disabled="disabled"';
441 check_box($inverse_condition_prefix, 1, $inverse_condition, NULL, $extras);
442 label(translate(
'inverse_condition'), $inverse_condition_prefix);
445 <div
class=
"sq-backend-triggers-component-body">
446 <input type=
"hidden" name=
"<?php echo $type_prefix; ?>" value=
"<?php echo $type; ?>" />
447 <?php echo $interface; ?>
455 <?php
if ($write_access) {
457 <script type=
"text/javascript">var conditionOrdererObject =
new componentOrderer(
'conditionOrderer',<?php echo $i; ?>)</script>
458 <input type=
"hidden" id=
"conditionOrderer" name=
"<?php echo $condition_order_prefix; ?>" />
460 <div
class=
"sq-backend-triggers-new-component-selector">
461 <?php echo translate(
'add_new_condition_type'); ?>:
463 $select_list = Array(
' '=>
' ---- '.translate(
'select_to_add').
' ---- ');
465 foreach ($condition_type_list as $type => $name) {
466 if (!$multiple_status[$type] && $type_instance_count[$type] != 0) {
470 $select_list[$type] = $name;
473 combo_box($prefix.
'[new_condition]', $select_list, FALSE,
' ');
475 echo
' <span class="sq-backend-warning">'.translate(
'some_conditions_can_only_be_added_once').
'</span>';
481 if ($i < 0) echo translate(
'no_conditions_specified');
487 return $write_access;
504 $write_access = $asset->writeAccess(
'attributes');
505 if (!$write_access)
return FALSE;
508 if (is_null($tm))
return FALSE;
510 $edit_data = array_get_index($_REQUEST, $prefix);
513 $raw_conditions = array_get_index($edit_data,
'conditions');
514 $condition_order = array_get_index($edit_data,
'condition_order');
515 if (!empty($condition_order)) {
516 $order_array = explode(
',', $condition_order);
517 foreach ($order_array as $position) {
518 $new_raw_conditions[] = $raw_conditions[$position];
520 $raw_conditions = $new_raw_conditions;
522 $new_condition_type = array_get_index($edit_data,
'new_condition');
523 if (!empty($new_condition_type)) {
524 $new_condition[
'type'] = $new_condition_type;
525 $new_condition[
'new'] = TRUE;
527 $raw_conditions[] = $new_condition;
530 $asset->setAttrValue(
'conditions', $processed_conditions);
549 $processed_components = Array();
551 if (empty($raw_components)) {
552 return $processed_components;
556 foreach ($raw_components as $component) {
558 if (isset($component[
'delete']))
continue;
561 $type = array_get_index($component,
'type');
562 if (empty($type) || !$tm->_loadComponent($type)) {
567 $data = array_get_index($component,
'data', Array());
568 if (!array_get_index($component,
'new', FALSE)) {
569 eval(
'$error = '.$type.
'::processInterface($settings, $data);');
572 if (FALSE !== $error) {
573 trigger_localised_error(
'CORE0217', E_USER_NOTICE, $i, $type, $error);
576 $processed_components[] = Array(
579 'inverse_condition' => isset($component[
'inverse_condition']),
584 return $processed_components;
601 $write_access = $asset->writeAccess(
'attributes');
604 if (is_null($tm))
return FALSE;
607 $action_type_list = $tm->_getActionList();
608 ksort($action_type_list);
610 $actions = $asset->attr(
'actions');
614 <div
class=
"sq-backend-triggers-component-block-wrapper">
615 <div
class=
"sq-backend-triggers-component-block">
617 $action_prefix = $prefix.
'[actions]';
618 $action_order_prefix = $prefix.
'[action_order]';
620 foreach ($actions as $action) {
621 $this_prefix = $action_prefix.
'['.$i.
']';
623 $data_prefix = $this_prefix.
'[data]';
624 $type_prefix = $this_prefix.
'[type]';
625 $delete_prefix = $this_prefix.
'[delete]';
626 $ignore_permissions_prefix = $this_prefix.
'[ignore_permissions]';
627 $not_required_prefix = $this_prefix.
'[not_required]';
629 $type = $action[
'type'];
630 $data = $action[
'data'];
631 $not_required = array_get_index($action,
'not_required', FALSE);
632 $ignore_permissions = array_get_index($action,
'ignore_permissions', FALSE);
634 $interface = $tm->_getComponentInterface($type, $data, $data_prefix, $write_access, $asset, $i);
635 $type_name = $tm->_getComponentName($type);
637 <div
class=
"sq-backend-triggers-component-wrapper">
638 <div
class=
"sq-backend-triggers-component-header">
639 <div
class=
"sq-backend-triggers-component-type-info">
640 <?php echo $type_name; ?>
642 <div
class=
"sq-backend-triggers-component-controls">
646 <input type=
"checkbox" name=
"<?php echo $delete_prefix; ?>"><?php echo label(translate(
'delete')); ?>
647
648 <a href=
"#" onclick=
"moveUp(this.parentNode.parentNode.parentNode); actionOrdererObject.moveUp(<?php echo $i; ?>); return false;"><script language=
"JavaScript" type=
"text/javascript">sq_print_icon(
"<?php echo sq_web_path('lib').'/web/images/icons/up_arrow.png' ?>",
"16",
"16",
"Move Up");</script></a>
649 <a href=
"#" onclick=
"moveDown(this.parentNode.parentNode.parentNode); actionOrdererObject.moveDown(<?php echo $i; ?>); return false;"><script language=
"JavaScript" type=
"text/javascript">sq_print_icon(
"<?php echo sq_web_path('lib').'/web/images/icons/down_arrow.png' ?>",
"16",
"16",
"Move Down");</script></a>
657 <div
class=
"sq-backend-triggers-component-global-options">
659 if (!$write_access) {
660 $extras =
'disabled="disabled"';
665 check_box($ignore_permissions_prefix, 1, $ignore_permissions, NULL, $extras);
666 label(translate(
'ignore_permissions'), $ignore_permissions_prefix);
668 check_box($not_required_prefix, 1, $not_required, NULL, $extras);
669 label(translate(
'not_required'), $not_required_prefix);
672 <div
class=
"sq-backend-triggers-component-body">
673 <input type=
"hidden" name=
"<?php echo $type_prefix; ?>" value=
"<?php echo $type; ?>" />
674 <?php echo $interface; ?>
682 <script type=
"text/javascript">var actionOrdererObject =
new componentOrderer(
'actionOrderer',<?php echo $i; ?>)</script>
683 <input type=
"hidden" id=
"actionOrderer" name=
"<?php echo $action_order_prefix; ?>" />
684 <!-- Add a New Action -->
685 <div
class=
"sq-backend-triggers-new-component-selector">
686 <?php echo translate(
'add_new_action_type'); ?>:
687 <select name=
"<?php echo $prefix; ?>[new_action]" >
688 <option value=
"" > ---- <?php echo translate(
'select_to_add'); ?> ---- </option>
690 foreach ($action_type_list as $a_type => $a_name) {
691 echo
'<option value="'.$a_type.
'" >'.$a_name.
'</option>';
698 if ($i < 0) echo translate(
'no_action_specified');
706 return $write_access;
723 $write_access = $asset->writeAccess(
'attributes');
724 if (!$write_access)
return FALSE;
727 if (is_null($tm))
return FALSE;
729 $edit_data = array_get_index($_REQUEST, $prefix);
732 $raw_actions = array_get_index($edit_data,
'actions');
733 $action_order = array_get_index($edit_data,
'action_order');
734 if (!empty($action_order)) {
735 $order_array = explode(
',', $action_order);
736 foreach ($order_array as $position) {
737 $new_raw_actions[] = $raw_actions[$position];
739 $raw_actions = $new_raw_actions;
741 $new_action_type = array_get_index($edit_data,
'new_action');
742 if (!empty($new_action_type)) {
743 $new_action[
'type'] = $new_action_type;
744 $new_action[
'new'] = TRUE;
746 $raw_actions[] = $new_action;
750 $asset->setAttrValue(
'actions', $processed_actions);
770 $processed_components = Array();
772 if (empty($raw_components)) {
773 return $processed_components;
777 foreach ($raw_components as $component) {
779 if (isset($component[
'delete']))
continue;
783 $type = array_get_index($component,
'type');
784 if (empty($type) || !$tm->_loadComponent($type)) {
789 $data = array_get_index($component,
'data', Array());
790 if (!array_get_index($component,
'new', FALSE)) {
791 eval(
'$error = '.$type.
'::processInterface($settings, $data);');
794 $processed_components[] = Array(
797 'not_required' => isset($component[
'not_required']),
798 'ignore_permissions' => isset($component[
'ignore_permissions']),
801 if (FALSE !== $error) {
802 trigger_localised_error(
'CORE0130', E_USER_NOTICE, $i, $type, $error);
806 return $processed_components;
824 if (isset($asset->tmid) && !empty($asset->tmid)) {
826 $tmid = $asset->tmid;
829 $parent_assetid = array_get_index($_REQUEST,
'parent_assetid');
830 if (!is_null($parent_assetid)) {
832 if(is_numeric($parent_assetid)){
833 $tmid = $parent_assetid;
837 $id_parts = explode(
':', $parent_assetid);
838 $tmid = $id_parts[0];
843 $tm = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($tmid,
'trigger_manager');
844 if (!is_null($tm) && empty($asset->tmid)) {
845 $asset->setTriggerManager($tmid);