17 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
18 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
19 require_once SQ_SYSTEM_ROOT.
'/core/attributes/parameter_map/parameter_map.inc';
60 public static function execute($settings, &$state)
64 if (empty($state[
'asset'])) {
66 if (empty($state[
'assetid'])) {
69 $state[
'asset'] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($state[
'assetid']);
76 $value_map = array_get_index($settings,
'value_map', serialize(Array()));
78 $param_map_value = $param_map_attr->getParameterValue(
'tag_id');
79 if (!empty($param_map_value)) {
81 if (is_array($param_map_value)) $tmp_ids = $param_map_value;
82 else $tmp_ids = explode(
',', $param_map_value);
84 foreach ($tmp_ids as $tmp_id) {
85 if ($GLOBALS[
'SQ_SYSTEM']->am->assetExists($tmp_id)) {
89 trigger_localised_error(
'SYS0087', E_USER_WARNING, $tmp_id);
95 if (!empty($settings[
'tagid']) && $GLOBALS[
'SQ_SYSTEM']->am->assetExists($settings[
'tagid'])) {
96 $tagid = $settings[
'tagid'];
99 if (!empty($settings[
'thesaurusid'])) {
100 $thesaurus = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($settings[
'thesaurusid']);
101 if (!is_null($thesaurus)) {
102 $termid = $thesaurus->getTermIdByName($settings[
'term_name']);
103 if (!empty($termid)) {
104 $tagid = $thesaurus->id.
':'.$termid;
106 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($thesaurus);
111 if (empty($tagid))
return FALSE;
113 $action = array_get_index($settings,
'action',
'add');
114 if ($action ==
'delete') {
117 $weighting = array_get_index($settings,
'weighting', NULL);
120 $manual_cascade = array_get_index($settings,
'manual_cascade', FALSE);
121 if ($manual_cascade) {
125 $cascade = array_get_index($settings,
'cascade', FALSE);
129 $tag_manager = $GLOBALS[
'SQ_SYSTEM']->getTagManager();
139 'weight' => (!$weighting ? 1 : $weighting),
142 $result = $tag_manager->setTag($state[
'assetid'], $tagid, $weighting);
153 $result = $tag_manager->deleteTag($state[
'assetid'], $tagid);
158 if ($manual_cascade) {
161 $current_tag_links = $tag_manager->getTagLinks($state[
'assetid']);
163 foreach ($current_tag_links as $link) {
165 'tag_id' => $link[
'minorid'],
167 'weight' => $link[
'value'],
172 if (!empty($tag_vars)) {
173 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
176 $state[
'asset']->
id => Array(
177 'type_code' => $state[
'asset']->
type(),
180 'tag_changes' => $tag_vars,
182 $errors = $hh->freestyleHIPO(
'hipo_job_edit_tags', $vars);
183 $result = empty($errors);
190 'assetid' => $state[
'asset']->
id,
192 'weighting' => $weighting,
210 public static function getInterface($settings, $prefix, $write_access=FALSE)
216 function toggleWeighting(value) {
217 var prefix =
'<?php echo $prefix; ?>';
218 var
id = prefix +
'[weighting]';
219 var element = document.getElementById(
id);
221 element.disabled =
'disabled';
223 element.disabled =
'';
227 function toggleExclusiveCheckboxes(check_clicked) {
228 var checkboxes =
new Array();
229 checkboxes[0] =
'cascade';
230 checkboxes[1] =
'manual_cascade';
232 var prefix =
'<?php echo $prefix; ?>';
236 for (ii = 0; ii < checkboxes.length; ii++) {
237 if (checkboxes[ii] != check_clicked) {
238 id = prefix +
'[' + checkboxes[ii] +
']';
239 document.getElementById(
id).checked =
false;
247 $tagid = array_get_index($settings,
'tagid', 0);
248 $action = array_get_index($settings,
'action',
'add');
249 $weighting = array_get_index($settings,
'weighting', ($action ==
'delete' ? NULL : 1));
251 $manual_cascade = array_get_index($settings,
'manual_cascade', FALSE);
252 if ($manual_cascade) {
256 $cascade = array_get_index($settings,
'cascade', FALSE);
261 if ($tagid && !$GLOBALS[
'SQ_SYSTEM']->am->assetExists($tagid)) {
267 asset_finder($prefix.
'[tag]', $tagid, Array(
'thesaurus_term' =>
'D'));
271 $tag = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($tagid);
272 if (!is_null($tag)) {
273 echo
'<b>'.$tag->name.
' (#'.$tag->id.
')</b>';
276 echo
'<b>['.translate(
'trigger_set_tag_no_tag_selected').
']</b>';
279 $tag_part = ob_get_contents();
284 $disabled = ($action ==
'add') ?
'' :
'disabled="disabled"';
285 int_text_box($prefix.
'[weighting]', $weighting, TRUE, 5, NULL, NULL,
'', FALSE, FALSE, $disabled);
287 echo
'<b>'.$weighting.
'</b>';
289 $weighting_part = ob_get_contents();
293 $action_checked = ($action ==
'add' ? FALSE : TRUE);
295 check_box($prefix.
'[action]',
'1', $action_checked,
'toggleWeighting(!this.checked)');
297 ?><img src=
"<?php echo sq_web_path('lib').'/web/images/'.($action_checked ? 'tick' : 'cross').'.gif'; ?>" alt=
"<?php echo ($action_checked ? translate('yes') : translate('no')); ?>"><?php
299 label(translate(
'trigger_set_tag_label_remove_tag'), $prefix.
'[action]');
300 $delete_part = ob_get_contents();
305 check_box($prefix.
'[cascade]',
'1', $cascade,
'toggleExclusiveCheckboxes(\'cascade\')');
307 ?><img src=
"<?php echo sq_web_path('lib').'/web/images/'.($cascade ? 'tick' : 'cross').'.gif'; ?>" alt=
"<?php echo ($cascade ? translate('yes') : translate('no')); ?>"><?php
309 label(translate(
'cascade_tag_changes'), $prefix.
'[cascade]');
310 $cascade_part = ob_get_contents();
315 check_box($prefix.
'[manual_cascade]',
'1', $manual_cascade,
'toggleExclusiveCheckboxes(\'manual_cascade\')');
317 ?><img src=
"<?php echo sq_web_path('lib').'/web/images/'.($manual_cascade ? 'tick' : 'cross').'.gif'; ?>" alt=
"<?php echo ($manual_cascade ? translate('yes') : translate('no')); ?>"><?php
319 label(translate(
'manually_cascade_all_tags'), $prefix.
'[manual_cascade]');
320 $manual_cascade_part = ob_get_contents();
323 echo translate(
'trigger_set_tag_select_tag').
' '.$tag_part;
324 if ($write_access || $action ==
'add') {
325 echo
'<br />'.translate(
'trigger_set_tag_set_weighting').
' '.$weighting_part;
327 echo
'<br />'.$delete_part;
328 echo
'<br /><br />'.$cascade_part;
329 echo
'<br />'.$manual_cascade_part;
334 $new_prefix = str_replace(array(
'[',
']'),
'_', $prefix);
335 hidden_field($prefix.
'[new_prefix]', $new_prefix);
336 $param_map_value = array_get_index($settings,
'value_map', serialize(Array()));
338 $param_map_attr->setParameter(
'tag_id',
'Tag ID');
339 echo $param_map_attr->paint($new_prefix.
'_parameter_map');
341 $contents = ob_get_contents();
363 if (!empty($request_data[
'tag'][
'assetid'])) {
364 $tagid = $request_data[
'tag'][
'assetid'];
366 return translate(
'no_tags_set');
369 $settings[
'tagid'] = $tagid;
370 $settings[
'weighting'] = array_get_index($request_data,
'weighting', NULL);
371 $settings[
'action'] = (array_get_index($request_data,
'action') ?
'delete' :
'add');
373 $settings[
'cascade'] = (bool) array_get_index($request_data,
'cascade', FALSE);
374 $settings[
'manual_cascade'] = (bool) array_get_index($request_data,
'manual_cascade', FALSE);
377 $new_prefix = str_replace(array(
'[',
']'),
'_', array_get_index($request_data,
'new_prefix',
''));
380 $param_map_attr->process($new_prefix.
'_parameter_map');
381 $settings[
'value_map'] = $param_map_attr->value;
398 public static function getLocks($settings, &$state)
401 $state[
'assetid'] => Array(
'all'),