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';
58 public static function execute($settings, &$state)
61 if (empty($settings[
'type_code']))
return FALSE;
62 if (empty($settings[
'parentid']))
return FALSE;
63 if (empty($settings[
'link_type']))
return FALSE;
65 if ($settings[
'parentid'] ==
'current_asset') {
66 $settings[
'parentid'] = $state[
'assetid'];
68 $attributes = Array();
69 if (!empty($settings[
'attributes'])) {
70 $attributes = $settings[
'attributes'];
72 $parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($settings[
'parentid']);
73 if (is_null($parent))
return FALSE;
76 $is_dependant = array_get_index($settings,
'is_dependant', 0);
77 $is_exclusive = array_get_index($settings,
'is_exclusive', 0);
78 $value = array_get_index($settings,
'value',
'');
83 'link_type' => $settings[
'link_type'],
86 'is_dependant' => (
bool) $is_dependant,
87 'is_exclusive' => (
bool) $is_exclusive,
90 $type_code = $settings[
'type_code'];
91 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($type_code);
92 $new_asset =
new $type_code();
94 if (!empty($attributes)) {
95 foreach ($attributes as $index => $val) {
96 $value = $val[
'value'];
98 if (array_get_index($settings,
'replace_keywords', 0)) {
100 $old_current_asset = $GLOBALS[
'SQ_SYSTEM']->getGlobalDefine(
'CURRENT_ASSET', NULL);
101 $GLOBALS[
'SQ_SYSTEM']->setGlobalDefine(
'CURRENT_ASSET', $state[
'asset']);
103 replace_global_keywords($value);
105 if (is_null($old_current_asset)) {
106 $GLOBALS[
'SQ_SYSTEM']->unsetGlobalDefine(
'CURRENT_ASSET');
108 $GLOBALS[
'SQ_SYSTEM']->setGlobalDefine(
'CURRENT_ASSET', $old_current_asset);
112 $keywords = retrieve_keywords_replacements($value);
113 $replacements = Array();
114 foreach ($keywords as $keyword) {
115 $replacements[$keyword] = $state[
'asset']->getKeywordReplacement($keyword);
117 replace_keywords($value, $replacements);
119 $new_asset->setAttrValue($val[
'attribute'], $value);
122 $linkid = $new_asset->create($link);
123 if (!$linkid)
return FALSE;
125 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($linkid);
128 'assetid' => $link[
'minorid'],
129 'parentid' => $link[
'majorid'],
130 'linkid' => $link[
'linkid'],
131 'link_type' => $link[
'link_type'],
132 'value' => $link[
'value'],
133 'sort_order' => $link[
'sort_order'],
134 'is_dependant' => $link[
'is_dependant'],
135 'is_exclusive' => $link[
'is_exclusive'],
151 public static function getInterface($settings, $prefix, $write_access=FALSE)
154 $parentid = array_get_index($settings,
'parentid', 0);
155 $type_code = array_get_index($settings,
'type_code', 0);
156 $link_type = array_get_index($settings,
'link_type', SQ_LINK_TYPE_1);
157 $value = array_get_index($settings,
'value',
'');
158 $is_dependant = array_get_index($settings,
'is_dependant', 0);
159 $is_exclusive = array_get_index($settings,
'is_exclusive', 0);
160 $selected = array_get_index($settings,
'attributes', 0);
163 $attributes = Array();
164 if (!empty($type_code)) {
166 $attrs = $GLOBALS[
'SQ_SYSTEM']->am->getAssetTypeAttributes($type_code);
167 foreach ($attrs as $attr => $type) {
168 $attributes[$attr] = ucwords(str_replace(
'_',
' ', $attr)).
' - '.ucwords($type[
'type']);
170 $attributes[
''] =
'--SELECT ATTRIBUTE--';
174 $parent_broadcasted = FALSE;
175 if ($parentid ==
'current_asset') {
176 $parent_broadcasted = TRUE;
179 if ($parentid && !$GLOBALS[
'SQ_SYSTEM']->am->assetExists($parentid)) {
187 asset_type_chooser($prefix.
'[type_code]', FALSE, Array($type_code), TRUE);
189 echo
'<b>'.$type_code.
'</b>';
192 $basic_part_1 = ob_get_contents();
198 asset_finder($prefix.
'[parentid]', $parentid, Array(
'asset' =>
'D'));
199 echo
'<br /><b>'.translate(
'trigger_create_under_broadcaster').
'</b>';
200 check_box($prefix.
'[parentid]',
'current_asset', $parent_broadcasted);
204 $parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($parentid);
206 if (is_null($parent)) {
207 echo
'<b>['.translate(
'no_parent_selected').
']</b>';
209 echo
'<b>'.translate(
'asset_format', $parent->name, $parent->id).
'</b>';
213 $basic_part_2 = ob_get_contents();
216 $link_type_list = get_link_type_names();
217 unset($link_type_list[SQ_LINK_NOTICE]);
221 combo_box($prefix.
'[link_type]', $link_type_list, FALSE, $link_type);
223 echo
'<b>'.$link_type_list[$link_type].
'</b>';
226 $basic_part_3 = ob_get_contents();
232 text_box($prefix.
'[value]', $value,
'',
'');
235 $value =
'['.translate(
'no_value_entered').
']';
237 echo
'<b>'.$value.
'</b>';
239 $advanced_part_1 = ob_get_contents();
243 $is_dependant_list = Array(
244 0 => translate(
'non_dependently'),
245 1 => translate(
'dependently'),
248 combo_box($prefix.
'[is_dependant]', $is_dependant_list, FALSE, $is_dependant);
250 echo
'<b>'.$is_dependant_list[$is_dependant].
'</b>';
253 $advanced_part_2 = ob_get_contents();
257 $is_exclusive_list = Array(
258 0 => translate(
'non_exclusively'),
259 1 => translate(
'exclusively'),
262 combo_box($prefix.
'[is_exclusive]', $is_exclusive_list, FALSE, $is_exclusive);
264 echo
'<b>'.$is_exclusive_list[$is_exclusive].
'</b>';
267 $advanced_part_3 = ob_get_contents();
271 if (!empty($attributes)) {
273 if (!empty($selected)) {
274 $count = count($selected);
275 foreach ($selected as $index => $attr) {
277 combo_box($prefix.
'[attributes]['.$index.
'][attribute]', $attributes, FALSE, $attr[
'attribute']);
278 text_box($prefix.
'[attributes]['.$index.
'][value]', $attr[
'value']);
279 check_box($prefix.
'[attributes]['.$index.
'][delete]',
'delete', FALSE);
280 echo translate(
'delete_question');
283 echo ucwords($attr[
'attribute']).
': '.$attr[
'value'].
'<br />';
289 combo_box($prefix.
'[attributes]['.$count.
'][attribute]', $attributes, FALSE,
'');
290 text_box($prefix.
'[attributes]['.$count.
'][value]',
'');
293 $attributes = ob_get_contents();
298 check_box($prefix.
'[replace_keywords]',
'1', array_get_index($settings,
'replace_keywords', 0), NULL, ($write_access?
'' :
'disabled="disabled"'));
299 label(
'Replace keywords in the attribute value', $prefix.
'[replace_keywords]');
300 $replace_keywords =
'<br />'.ob_get_clean();
302 $attributes .= $replace_keywords;
305 $contents = translate(
'trigger_new_asset_basic', $basic_part_1, $basic_part_2, $basic_part_3).
307 '<b>'.translate(
'triggers_advanced_user_options').
'</b><br />'.
308 translate(
'trigger_new_asset_advanced', $advanced_part_1, $advanced_part_2, $advanced_part_3).
309 '<br /><br /><b>'.translate(
'set_attributes').
'</b><br />'.$attributes.
'<br /><br />'.
310 '<span class="sq-backend-warning"><b>'.translate(
'trigger_create_asset_required_attrs_warning').
'</b></span>';
331 if (($request_data[
'parentid'] !=
'current_asset') && empty($request_data[
'parentid'][
'assetid'])) {
332 return translate(
'parent_to_create_under_is_missing');
335 $link_type_list = get_link_type_names();
336 if (empty($request_data[
'link_type']) || !isset($link_type_list[$request_data[
'link_type']])) {
337 return translate(
'link_type_missing');
340 if (is_array($request_data[
'parentid'])) {
341 $settings[
'parentid'] = $request_data[
'parentid'][
'assetid'];
343 $settings[
'parentid'] = $request_data[
'parentid'];
345 $settings[
'link_type'] = $request_data[
'link_type'];
347 $type_code = array_get_index($request_data,
'type_code', FALSE);
349 return translate(
'asset_type_not_specified');
351 $settings[
'type_code'] = $type_code;
354 $settings[
'value'] = array_get_index($request_data,
'value',
'');
355 $settings[
'is_dependant'] = array_get_index($request_data,
'is_dependant', 0);
356 $settings[
'is_exclusive'] = array_get_index($request_data,
'is_exclusive', 0);
359 if (isset($request_data[
'attributes']) && !empty($request_data[
'attributes'])) {
360 $attribute = $request_data[
'attributes'];
362 foreach ($attribute as $index => $val) {
363 if (empty($val[
'attribute']) || empty($val[
'value'])) {
366 if (isset($val[
'delete']))
continue;
369 $settings[
'attributes'] = $new_attr;
372 $settings[
'replace_keywords'] = array_get_index($request_data,
'replace_keywords', 0);
401 foreach ($value[
'attribute'] as $attribute) {
402 $attr_name = $attribute[
'name'][0];
403 $attr_value = $attribute[
'value'][0];
404 $settings[
'attributes'][] = Array(
405 'attribute' => $attr_name,
406 'value' => $attr_value,