17 require_once SQ_CORE_PACKAGE_PATH.
'/system/triggers/trigger_action/trigger_action.inc';
56 public static function execute($settings, &$state)
58 $am = $GLOBALS[
'SQ_SYSTEM']->am;
60 if (empty($state[
'asset'])) {
62 if (empty($state[
'assetid'])) {
65 $state[
'asset'] = $am->getAsset($state[
'assetid']);
69 if (is_null($state[
'asset']))
return FALSE;
71 $linkid = array_get_index($settings,
'linkid',
'');
73 $new_value = array_get_index($settings,
'new_value', NULL);
74 $new_link_type = array_get_index($settings,
'new_link_type', NULL);
78 $result = $am->updateLink($linkid, $new_link_type, $new_value);
80 $type_code = array_get_index($settings,
'type_code',
'');
81 if (empty($type_code))
return FALSE;
83 $link_type = array_get_index($settings,
'link_type', 0);
84 if (empty($link_type))
return FALSE;
86 $side_of_link = array_get_index($settings,
'side_of_link',
'');
87 if (!in_array($side_of_link, Array(
'minor',
'major')))
return FALSE;
89 $value = array_get_index($settings,
'value', NULL);
91 $links = $am->getLinks($state[
'asset']->
id, $link_type, $type_code, TRUE, $side_of_link, $value, FALSE, FALSE);
92 if (count($links) == 1){
93 $linkid = $links[0][
'linkid'];
94 $result = $am->updateLink($linkid, $new_link_type, $new_value);
96 trigger_localised_error(
'TRIG0007', E_USER_NOTICE);
116 public static function getInterface($settings, $prefix, $write_access=FALSE)
118 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
119 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
121 $link_type_names = get_link_type_names();
123 $linkid = array_get_index($settings,
'linkid',
'');
124 $type_code = array_get_index($settings,
'type_code',
'');
125 $link_type = array_get_index($settings,
'link_type', key($link_type_names));
126 $side_of_link = array_get_index($settings,
'side_of_link',
'major');
127 $value = array_get_index($settings,
'value',
'');
129 $new_value = array_get_index($settings,
'new_value',
'');
130 $new_link_type = array_get_index($settings,
'new_link_type', key($link_type_names));
134 <div style=
"padding: 10px">
135 <p
class=
"sq-backend-section-subheading"><?php echo translate(
'link_characteristics'); ?></p>
136 <p><?php echo translate(
'link_characteristics_note');?></p>
140 int_text_box($prefix.
'[linkid]', $linkid, FALSE,
'', NULL, NULL,
'', FALSE, TRUE);
142 if (!empty($linkid)){
145 echo
'<i>Not specified</i>';
148 echo
' <span style="color:red; font-weight:bold;"> OR </span><br /><br />';
151 <table
class=
"sq-backend-table">
157 <th><?php echo translate(
'link_type'); ?>:</th>
160 combo_box($prefix.
'[link_type]', $link_type_names, FALSE, $link_type);
162 echo $link_type_names[$link_type];
165 <th><?php echo translate(
'side_of_link'); ?>:</th>
167 $side_of_link_options = Array(
'major' =>
'Parent',
'minor' =>
'Child');
169 combo_box($prefix.
'[side_of_link]', $side_of_link_options, FALSE, $side_of_link);
171 echo $side_of_link_options[$side_of_link];
176 <th><?php echo translate(
'link_value'); ?>:</th>
179 text_box($prefix.
'[value]', $value);
184 <th><?php echo translate(
'asset_type'); ?>:</th>
187 asset_type_chooser($prefix.
'[type_code]', FALSE, $type_code, TRUE);
189 echo ucwords(str_replace(
'_',
' ',$type_code));
195 <div style=
"padding: 10px">
196 <p
class=
"sq-backend-section-subheading"><?php echo translate(
'new_link_characteristics'); ?></p>
197 <p><?php echo translate(
'new_link_characteristics_note');?></p>
198 <table
class=
"sq-backend-table" style=
"width:50%;">
202 <th><?php echo translate(
'link_type'); ?>:</th>
205 combo_box($prefix.
'[new_link_type]', $link_type_names, FALSE, $new_link_type);
207 echo $link_type_names[$new_link_type];
212 <th><?php echo translate(
'link_value'); ?>:</th>
215 text_box($prefix.
'[new_value]', $new_value);
225 $output = ob_get_contents();
246 $settings[
'linkid'] = array_get_index($request_data,
'linkid',
'');
247 $settings[
'side_of_link'] = array_get_index($request_data,
'side_of_link',
'');
248 $settings[
'link_type'] = array_get_index($request_data,
'link_type', 0);
249 $settings[
'link_type'] = (int)$settings[
'link_type'];
251 $settings[
'type_code'] = array_get_index($request_data,
'type_code',
'');
252 if (empty($settings[
'type_code']))
return 'You must specify an Asset Type';
254 $settings[
'value'] = array_get_index($request_data,
'value', NULL);
255 $settings[
'value'] = trim($settings[
'value']);
256 if (empty($settings[
'value'])) $settings[
'value'] = NULL;
258 $settings[
'new_value'] = array_get_index($request_data,
'new_value', NULL);
259 $settings[
'new_link_type'] = array_get_index($request_data,
'new_link_type', NULL);
260 if (!is_null($settings[
'new_link_type'])) $settings[
'new_link_type'] = (int)$settings[
'new_link_type'];
276 public static function getLocks($settings, &$state)
278 return Array($state[
'assetid'] => Array(
'links'));