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';
60 public static function execute($settings, &$state)
63 if (empty($settings[
'type_code']))
return FALSE;
64 if (empty($settings[
'parentid']))
return FALSE;
65 if (empty($settings[
'link_type']))
return FALSE;
66 if (empty($settings[
'file_path']))
return FALSE;
67 if (!is_readable($settings[
'file_path'])) {
68 trigger_localised_error(
'CORE0276', E_USER_WARNING, htmlentities($settings[
'file_path'], ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
72 if ($settings[
'parentid'] ==
'current_asset') {
73 $settings[
'parentid'] = $state[
'assetid'];
75 $attributes = Array();
76 if (!empty($settings[
'attributes'])) {
77 $attributes = $settings[
'attributes'];
79 $parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($settings[
'parentid']);
80 if (is_null($parent))
return FALSE;
83 $is_dependant = array_get_index($settings,
'is_dependant', 0);
84 $is_exclusive = array_get_index($settings,
'is_exclusive', 0);
85 $value = array_get_index($settings,
'value',
'');
90 'link_type' => $settings[
'link_type'],
93 'is_dependant' => (
bool) $is_dependant,
94 'is_exclusive' => (
bool) $is_exclusive,
97 if (isset($settings[
'file_name']) ===
false) {
98 $settings[
'file_name'] = basename($settings[
'file_path']);
102 'name' => $settings[
'file_name'],
103 'tmp_name' => $settings[
'file_path'],
104 'non_uploaded_file' => TRUE,
107 $type_code = $settings[
'type_code'];
108 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($type_code);
109 $new_asset =
new $type_code();
110 $new_asset->_tmp[
'uploading_file'] = TRUE;
113 if (!empty($attributes)) {
114 foreach ($attributes as $index => $val) {
115 $new_asset->setAttrValue($val[
'attribute'], $val[
'value']);
119 $linkid = $new_asset->create($link, $info);
120 if (!$linkid)
return FALSE;
123 if (!$GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_INTEGRITY)) {
124 if (!$new_asset->createAdditional($link)) {
130 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($linkid);
133 'assetid' => $link[
'minorid'],
134 'parentid' => $link[
'majorid'],
135 'linkid' => $link[
'linkid'],
136 'link_type' => $link[
'link_type'],
137 'value' => $link[
'value'],
138 'sort_order' => $link[
'sort_order'],
139 'is_dependant' => $link[
'is_dependant'],
140 'is_exclusive' => $link[
'is_exclusive'],
156 public static function getInterface($settings, $prefix, $write_access=FALSE)
159 $parentid = array_get_index($settings,
'parentid', 0);
160 $type_code = array_get_index($settings,
'type_code', 0);
161 $link_type = array_get_index($settings,
'link_type', SQ_LINK_TYPE_1);
162 $value = array_get_index($settings,
'value',
'');
163 $is_dependant = array_get_index($settings,
'is_dependant', 0);
164 $is_exclusive = array_get_index($settings,
'is_exclusive', 0);
165 $selected = array_get_index($settings,
'attributes', 0);
168 $attributes = Array();
169 if (!empty($type_code)) {
171 $attrs = $GLOBALS[
'SQ_SYSTEM']->am->getAssetTypeAttributes($type_code);
172 foreach ($attrs as $attr => $type) {
173 $attributes[$attr] = ucwords(str_replace(
'_',
' ', $attr)).
' - '.ucwords($type[
'type']);
175 $attributes[
''] =
'--SELECT ATTRIBUTE--';
179 $parent_broadcasted = FALSE;
180 if ($parentid ==
'current_asset') {
181 $parent_broadcasted = TRUE;
184 if ($parentid && !$GLOBALS[
'SQ_SYSTEM']->am->assetExists($parentid)) {
192 asset_type_chooser($prefix.
'[type_code]', FALSE, Array($type_code), TRUE, FALSE, FALSE, Array(
'file'));
194 echo
'<b>'.$type_code.
'</b>';
197 $basic_part_1 = ob_get_contents();
203 radio_button($prefix.
'[parent_type]',
'explicit', !$parent_broadcasted,
'',
'id="parent_type_explicit"');
204 label(translate(
'under'),
'parent_type_explicit');
206 asset_finder($prefix.
'[parentid]', $parentid, Array(
'asset' =>
'D'));
208 radio_button($prefix.
'[parent_type]',
'broadcaster', $parent_broadcasted,
'',
'id="parent_type_broadcaster"');
209 label(translate(
'trigger_create_under_broadcaster'),
'parent_type_broadcaster');
211 if ($parent_broadcasted) {
212 echo translate(
'trigger_create_under_broadcaster');
214 echo translate(
'under').
' ';
215 if (!empty($parentid)) {
216 echo
'<b>'.get_asset_tag_line($parentid).
'</b>';
218 echo
'<b>['.translate(
'no_parent_selected').
']</b>';
223 $basic_part_2 = ob_get_contents();
227 $link_type_list = get_link_type_names();
228 unset($link_type_list[SQ_LINK_NOTICE]);
230 combo_box($prefix.
'[link_type]', $link_type_list, FALSE, $link_type);
232 echo
'<b>'.$link_type_list[$link_type].
'</b>';
235 $basic_part_3 = ob_get_contents();
240 text_box($prefix.
'[file_path]', array_get_index($settings,
'file_path',
''), 40);
242 echo array_get_index($settings,
'file_path',
'');
244 $basic_part_4 = ob_get_contents();
250 text_box($prefix.
'[value]', $value,
'',
'');
253 $value =
'['.translate(
'no_value_entered').
']';
255 echo
'<b>'.$value.
'</b>';
257 $advanced_part_1 = ob_get_contents();
261 $is_dependant_list = Array(
262 0 => translate(
'non_dependently'),
263 1 => translate(
'dependently'),
266 combo_box($prefix.
'[is_dependant]', $is_dependant_list, FALSE, $is_dependant);
268 echo
'<b>'.$is_dependant_list[$is_dependant].
'</b>';
271 $advanced_part_2 = ob_get_contents();
275 $is_exclusive_list = Array(
276 0 => translate(
'non_exclusively'),
277 1 => translate(
'exclusively'),
280 combo_box($prefix.
'[is_exclusive]', $is_exclusive_list, FALSE, $is_exclusive);
282 echo
'<b>'.$is_exclusive_list[$is_exclusive].
'</b>';
285 $advanced_part_3 = ob_get_contents();
289 if (!empty($attributes)) {
291 if (!empty($selected)) {
292 $count = count($selected);
293 foreach ($selected as $index => $attr) {
295 combo_box($prefix.
'[attributes]['.$index.
'][attribute]', $attributes, FALSE, $attr[
'attribute']);
296 text_box($prefix.
'[attributes]['.$index.
'][value]', $attr[
'value']);
297 check_box($prefix.
'[attributes]['.$index.
'][delete]',
'delete', FALSE);
298 echo translate(
'delete_question');
301 echo ucwords($attr[
'attribute']).
': '.$attr[
'value'].
'<br />';
305 if (!$write_access) {
306 echo
'<i>('.translate(
'none').
')</i>';
310 combo_box($prefix.
'[attributes]['.$count.
'][attribute]', $attributes, FALSE,
'');
311 text_box($prefix.
'[attributes]['.$count.
'][value]',
'');
315 $attributes = ob_get_contents();
319 $contents = translate(
'trigger_new_asset_basic', $basic_part_1, $basic_part_2, $basic_part_3).
320 '<br />and populate it with the file located on the server at '.$basic_part_4.
322 '<b>'.translate(
'triggers_advanced_user_options').
'</b><br />'.
323 translate(
'trigger_new_asset_advanced', $advanced_part_1, $advanced_part_2, $advanced_part_3).
'<br />'.
324 translate(
'set_attributes').
':<br />'.$attributes;
326 $contents .=
'<p class="sq-backend-warning"><b>'.translate(
'trigger_create_file_required_attrs_warning').
'</b></p>';
348 if (($request_data[
'parent_type'] !=
'broadcaster') && empty($request_data[
'parentid'][
'assetid'])) {
349 return translate(
'parent_to_create_under_is_missing');
352 if (!isset($request_data[
'file_path']) || empty($request_data[
'file_path'])) {
353 return translate(
'trigger_action_create_file_asset_file_path_not_set');
356 $link_type_list = get_link_type_names();
357 if (empty($request_data[
'link_type']) || !isset($link_type_list[$request_data[
'link_type']])) {
358 return translate(
'link_type_missing');
361 if (($request_data[
'parent_type'] ==
'explicit')) {
362 $settings[
'parentid'] = $request_data[
'parentid'][
'assetid'];
364 $settings[
'parentid'] =
'current_asset';
366 $settings[
'link_type'] = $request_data[
'link_type'];
368 $type_code = array_get_index($request_data,
'type_code', FALSE);
370 return translate(
'asset_type_not_specified');
373 $settings[
'type_code'] = $type_code;
374 $settings[
'file_path'] = $request_data[
'file_path'];
377 $settings[
'value'] = array_get_index($request_data,
'value',
'');
378 $settings[
'is_dependant'] = array_get_index($request_data,
'is_dependant', 0);
379 $settings[
'is_exclusive'] = array_get_index($request_data,
'is_exclusive', 0);
382 if (isset($request_data[
'attributes']) && !empty($request_data[
'attributes'])) {
383 $attribute = $request_data[
'attributes'];
385 foreach ($attribute as $index => $val) {
386 if (empty($val[
'attribute']) || empty($val[
'value'])) {
389 if (isset($val[
'delete']))
continue;
392 $settings[
'attributes'] = $new_attr;