17 require_once SQ_CORE_PACKAGE_PATH.
'/system/triggers/trigger_condition/trigger_condition.inc';
18 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
55 public static function evaluate($settings, &$state)
57 if (!empty($state[
'assetid'])) {
58 $assetid = $state[
'assetid'];
60 if (!empty($state[
'asset'])) {
61 $assetid = $state[
'asset']->id;
68 if (empty($settings[
'treeids'])) {
69 if (empty($settings[
'assetids'])) {
72 $settings[
'treeids'] = Array();
73 foreach ($settings[
'assetids'] as $tree_asset_id) {
74 if ($GLOBALS[
'SQ_SYSTEM']->am->assetExists($tree_asset_id)) {
75 $settings[
'treeids'][$tree_asset_id] = $GLOBALS[
'SQ_SYSTEM']->am->getAssetTreeids($tree_asset_id);
81 if (empty($settings[
'immed_child']))
return FALSE;
85 if (empty($state[
'treeid'])) {
87 $state[
'treeid'] = $GLOBALS[
'SQ_SYSTEM']->am->getAssetTreeids($assetid);
88 if (empty($state[
'treeid'])) trigger_localised_error(
'TRIG0006', E_USER_WARNING);
91 if (!is_array($state[
'treeid'])) {
92 $state[
'treeid'] = Array($state[
'treeid']);
96 foreach ($state[
'treeid'] as $state_tree) {
97 foreach ($settings[
'treeids'] as $tree_asset_id => $treeids) {
98 foreach ($treeids as $settings_tree) {
100 if ($settings_tree === $state_tree) {
103 if ($settings[
'immed_child'][$tree_asset_id]) {
104 if (strlen($settings_tree) == strlen($state_tree) - SQ_CONF_ASSET_TREE_SIZE &&
105 substr($state_tree, 0, strlen($settings_tree)) == $settings_tree) {
109 if (substr($state_tree, 0, strlen($settings_tree)) == $settings_tree) {
133 public static function getInterface($settings, $prefix, $write_access=FALSE)
136 $selected_assetids = array_get_index($settings,
'assetids', Array());
139 foreach ($selected_assetids as $selected_assetid){
140 if ($selected_assetid && !$GLOBALS[
'SQ_SYSTEM']->am->assetExists($selected_assetid)) {
141 unset($selected_assetids[$selected_assetid]);
145 $immed_child = array_get_index($settings,
'immed_child', Array());
151 ?><script
type=
"text/javascript" src=
"<?php echo sq_web_path('lib')?>/html_form/html_form.js"></script><?php
153 $name = $prefix.
'[assetids]';
154 foreach (array_values($selected_assetids) as $index => $selected_assetid){
155 asset_finder($name.
'['.$index.
']', $selected_assetid, Array(),
'sq_sidenav', FALSE,
'null', Array(
'clear'));
156 echo
'<span style="margin-left:10px;">';
157 echo translate(
'immediate_child_only');
158 check_box($prefix.
'[immed_child]['.$index.
']',
'1', (!empty($immed_child[$selected_assetid])),
'',
'style="margin-left:10px;"');
163 asset_finder($name.
'['.count($selected_assetids).
']', 0, Array(),
'sq_sidenav', FALSE,
'null', Array(
'clear'));
164 echo
'<span id="trigger_condition_tree_location_check_box" style="margin-left:10px;">';
165 echo translate(
'immediate_child_only');
166 check_box($prefix.
'[immed_child]['.count($selected_assetids).
']',
'1', FALSE,
'',
'style="margin-left:10px;"');
169 $map_frame_exp = trim(
'parent.frames["sq_sidenav"]',
'.');
170 $safe_name =
'sq_asset_finder_'.preg_replace(
'/[^A-Za-z0-9]/',
'_', $name);
173 <script type=
"text/javascript">
175 var immed_child_index = <?php echo count($selected_assetids)+ 1; ?>;
176 function addParentNode(node) {
177 var new_span = document.getElementById(
'trigger_condition_tree_location_check_box').cloneNode(
true);
178 new_span.removeAttribute(
'id');
179 new_span.lastChild.setAttribute(
'id',
'<?php echo $prefix; ?>' +
'[immed_child][' + immed_child_index +
']');
180 new_span.lastChild.setAttribute(
'name',
'<?php echo $prefix; ?>' +
'[immed_child][' + immed_child_index +
']');
181 node.parentNode.insertBefore(new_span, node);
182 immed_child_index = immed_child_index + 1;
187 echo
'<input type="button" name="'.htmlspecialchars($safe_name.
'_more_btn').
'" id="'.htmlspecialchars($safe_name.
'_more_btn').
'" value="'.translate(
'more').
'..." onclick="addNewAssetFinder(this, \''.$name.
'\', \
''.$safe_name.
'\', \
'\', \
''.htmlentities($map_frame_exp, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET).
'\', \
'null\', true); addParentNode(this);" style="margin-left:10px;"/>';
191 if ($selected_assetids) {
192 foreach ($selected_assetids as $selected_assetid){
193 echo get_asset_tag_line($selected_assetid);
194 if (!empty($immed_child[$selected_assetid])) {
195 echo
'<b> '.translate(
'as_an_immediate_child_only').
'</b>';
200 echo
'<b>['.translate(
'no_asset_selected').
']</b>';
204 $basic_part_1 = ob_get_contents();
207 return translate(
'trigger_tree_location_basic', $basic_part_1);
223 $settings[
'assetids'] = $settings[
'propagate'] = $settings[
'immed_child'] = Array();
224 $immed_child = array_get_index($request_data,
'immed_child', Array());
225 $assetids = array_get_index($request_data,
'assetids', Array());
226 foreach ($assetids as $index => $tree_location){
227 if (!empty($tree_location[
'assetid'])) {
228 if ($GLOBALS[
'SQ_SYSTEM']->am->assetExists($tree_location[
'assetid'])) {
229 $settings[
'assetids'][] = $tree_location[
'assetid'];
230 if (empty($immed_child[$index])) {
231 $settings[
'propagate'][$tree_location[
'assetid']] = SQ_TRIG_TREE_PROPAGATE;
232 $settings[
'immed_child'][$tree_location[
'assetid']] =
'0';
234 $settings[
'propagate'][$tree_location[
'assetid']] = SQ_TRIG_TREE_NO_PROPAGATE;
235 $settings[
'immed_child'][$tree_location[
'assetid']] =
'1';
238 trigger_error(translate(
'selected_asset_does_not_exist'), E_USER_NOTICE);
243 if (empty($settings[
'assetids']))
return translate(
'triger_no_tree_location');
260 public static function setHash(&$settings, &$hash)
262 if (isset($settings[
'assetids']) && isset($settings[
'propagate'])) {
264 foreach ($settings[
'assetids'] as $assetid){
265 $hash->setLinkTree($GLOBALS[
'SQ_SYSTEM']->am->getAssetTreeids($assetid), $settings[
'propagate'][$assetid]);