17 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
18 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
19 require_once SQ_CORE_PACKAGE_PATH.
'/system/triggers/trigger_action/trigger_action.inc';
20 require_once SQ_SYSTEM_ROOT.
'/core/attributes/parameter_map/parameter_map.inc';
61 public static function execute($settings, &$state)
64 if (!isset($settings[
'is_major']) || empty($settings[
'link_type'])) {
68 $parameter_map_value = array_get_index($settings,
'parameter_map_target_asset', serialize(Array()));
70 $map_assetid = $atr_parameter_map->getParameterValue(
'asset');
72 if (empty($settings[
'assetid']) && empty($map_assetid)) {
76 if (!$GLOBALS[
'SQ_SYSTEM']->am->assetExists($settings[
'assetid'])) {
80 if (!is_null($map_assetid) && !$GLOBALS[
'SQ_SYSTEM']->am->assetExists($map_assetid)) {
85 $is_dependant = array_get_index($settings,
'is_dependant', 0);
86 $is_exclusive = array_get_index($settings,
'is_exclusive', 0);
87 $value = array_get_index($settings,
'value',
'');
89 $remove_other_links = array_get_index($settings,
'link_exclusively', 0) && ($settings[
'link_type'] & SQ_SC_LINK_SIGNIFICANT);
91 if (empty($state[
'asset'])) {
93 if (empty($state[
'assetid'])) {
96 $state[
'asset'] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($state[
'assetid']);
100 $am = $GLOBALS[
'SQ_SYSTEM']->am;
102 if ($remove_other_links) {
104 $old_links = $am->getLinks($state[
'assetid'], SQ_SC_LINK_ALL,
'', TRUE,
'minor');
108 $assetid = is_null($map_assetid) ? $settings[
'assetid'] : $map_assetid;
111 if ($settings[
'is_major']) {
112 $major = $state[
'asset'];
113 $minor = $am->getAsset($assetid);
115 $major = $am->getAsset($assetid);
116 $minor = $state[
'asset'];
119 $side_of_link = ($settings[
'is_major']) ?
'major' :
'minor';
120 if (!empty($settings[
'value'])) {
121 $link_info = $am->getLinkByAsset($state[
'assetid'], $assetid, $settings[
'link_type'], $settings[
'value'], $side_of_link, TRUE);
123 $link_info = $am->getLinkByAsset($state[
'assetid'], $assetid, $settings[
'link_type'], NULL, $side_of_link, TRUE);
126 $action_link = array_shift($link_info);
129 if (empty($action_link)) {
130 $linkid = $am->createAssetLink($major, $minor, $settings[
'link_type'], $value, NULL, $is_dependant, $is_exclusive);
131 if (!$linkid)
return FALSE;
132 $action_link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($linkid);
135 if ($remove_other_links) {
136 foreach ($old_links as $old_link) {
138 if ($action_link[
'linkid'] != $old_link[
'linkid']) {
139 $am->deleteAssetLink($old_link[
'linkid']);
145 $rm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'remap_manager');
146 $auto_add_remaps = $rm->attr(
'remap_upon_webpath_change');
149 $major->updateLookups($auto_add_remaps);
150 $minor->updateLookups($auto_add_remaps);
153 'linkid' => $action_link[
'linkid'],
154 'majorid' => array_get_index($action_link,
'majorid', 0),
155 'minorid' => array_get_index($action_link,
'minorid', 0),
156 'link_type' => $action_link[
'link_type'],
157 'value' => $action_link[
'value'],
158 'sort_order' => $action_link[
'sort_order'],
159 'is_dependant' => $action_link[
'is_dependant'],
160 'is_exclusive' => $action_link[
'is_exclusive'],
176 public static function getInterface($settings, $prefix, $write_access=FALSE)
179 $selected_assetid = array_get_index($settings,
'assetid', 0);
180 $is_major = array_get_index($settings,
'is_major', 0);
181 $selected_link_type = array_get_index($settings,
'link_type', SQ_LINK_TYPE_1);
182 $value = array_get_index($settings,
'value',
'');
183 $is_dependant = array_get_index($settings,
'is_dependant', 0);
184 $is_exclusive = array_get_index($settings,
'is_exclusive', 0);
185 $link_exclusively = array_get_index($settings,
'link_exclusively', 0);
188 if ($selected_assetid && !$GLOBALS[
'SQ_SYSTEM']->am->assetExists($selected_assetid)) {
189 $selected_assetid = 0;
192 $is_major_list = Array(0 =>
'Child', 1 =>
'Parent');
194 $link_type_list = get_link_type_names();
196 if (!$write_access) {
197 $form_element_extras =
'disabled="disabled"';
199 $form_element_extras =
'';
205 combo_box($prefix.
'[is_major]', $is_major_list, FALSE, $is_major, NULL, $form_element_extras);
206 $basic_part_1 = ob_get_contents();
211 asset_finder($prefix.
'[assetid]', $selected_assetid);
213 if ($selected_assetid) {
214 $selected_assetname = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($selected_assetid), Array(), TRUE,
'name');
215 text_box($prefix.
'[assetid]', $selected_assetname[$selected_assetid].
' (#'.$selected_assetid.
')',
'',
'', FALSE, $form_element_extras);
217 text_box($prefix.
'[assetid]',
'',
'',
'', FALSE, $form_element_extras);
221 $basic_part_2 = ob_get_contents();
225 combo_box($prefix.
'[link_type]', $link_type_list, FALSE, $selected_link_type, NULL, $form_element_extras);
226 $basic_part_3 = ob_get_contents();
233 $new_prefix = str_replace(array(
'[',
']'),
'_', $prefix);
234 hidden_field($prefix.
'[new_prefix]', $new_prefix);
238 $parameter_map_value = array_get_index($settings,
'parameter_map_target_asset', serialize(Array()));
240 $atr_parameter_map->setParameter(
'asset',
'Target Asset');
241 echo $atr_parameter_map->paint($new_prefix.
'_parameter_map', !$write_access);
242 $basic_part_4 = ob_get_contents();
246 text_box($prefix.
'[value]', $value,
'',
'', FALSE, $form_element_extras);
247 $advanced_part_1 = ob_get_contents();
251 $is_dependant_list = Array(
252 0 => translate(
'non_dependently'),
253 1 => translate(
'dependently'),
255 combo_box($prefix.
'[is_dependant]', $is_dependant_list, FALSE, $is_dependant, NULL, $form_element_extras);
256 $advanced_part_2 = ob_get_contents();
260 $is_exclusive_list = Array(
261 0 => translate(
'non_exclusively'),
262 1 => translate(
'exclusively'),
264 combo_box($prefix.
'[is_exclusive]', $is_exclusive_list, FALSE, $is_exclusive, NULL, $form_element_extras);
265 $advanced_part_3 = ob_get_contents();
270 check_box($prefix.
'[link_exclusively]',
'1', $link_exclusively,
'',
'id="'.$prefix.
'_link_exclusively"');
271 label(translate(
'trigger_create_link_remove_others'), $prefix.
'_link_exclusively');
273 echo
'<img src="'.sq_web_path(
'lib').
'/web/images/'.($link_exclusively ?
'tick' :
'cross').
'.gif" />';
274 echo translate(
'trigger_create_link_remove_others');
276 $advanced_part_4 = ob_get_contents();
279 $contents = translate(
'trigger_create_link_basic', $basic_part_1, $basic_part_2, $basic_part_3).
280 '<br />'.$basic_part_4.
'<br />'.
281 '<b>'.translate(
'triggers_advanced_user_options').
'</b><br />'.
282 translate(
'trigger_create_link_advanced', $advanced_part_1, $advanced_part_2, $advanced_part_3).
283 '<br />'.$advanced_part_4;
303 $is_major_list = Array(0 =>
'Child', 1 =>
'Parent');
305 $link_type_list = get_link_type_names();
308 if (empty($request_data[
'assetid'][
'assetid'])) {
309 return 'Asset ID not specified';
312 if (!isset($request_data[
'is_major']) || !isset($is_major_list[$request_data[
'is_major']])) {
313 return 'Parent or Child link not specified';
316 if (empty($request_data[
'link_type']) || !isset($link_type_list[$request_data[
'link_type']])) {
317 return 'Link Type not specified';
320 $new_prefix = str_replace(array(
'[',
']'),
'_', array_get_index($request_data,
'new_prefix',
''));
322 $atr_parameter_map->process($new_prefix.
'_parameter_map');
323 $settings[
'parameter_map_target_asset'] = $atr_parameter_map->value;
325 $settings[
'assetid'] = $request_data[
'assetid'][
'assetid'];
326 $settings[
'is_major'] = $request_data[
'is_major'];
327 $settings[
'link_type'] = $request_data[
'link_type'];
330 $settings[
'value'] = array_get_index($request_data,
'value',
'');
331 $settings[
'is_dependant'] = array_get_index($request_data,
'is_dependant', 0);
332 $settings[
'is_exclusive'] = array_get_index($request_data,
'is_exclusive', 0);
333 $settings[
'link_exclusively'] = array_get_index($request_data,
'link_exclusively', 0);