17 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
18 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
59 public static function execute($settings, &$state)
61 $clone_broadcaster = array_get_index($settings,
'clone_broadcaster', 1);
62 $link_to_broadcaster = array_get_index($settings,
'link_to_broadcaster', 0);
64 if (($clone_broadcaster == 0) && (empty($settings[
'clone_assetid']) || !$GLOBALS[
'SQ_SYSTEM']->am->assetExists($settings[
'clone_assetid']))) {
68 if (($link_to_broadcaster == 0) && (empty($settings[
'assetid']) || !$GLOBALS[
'SQ_SYSTEM']->am->assetExists($settings[
'assetid']))) {
72 if (empty($settings[
'link_type'])) {
77 $is_dependant = array_get_index($settings,
'is_dependant', 0);
78 $is_exclusive = array_get_index($settings,
'is_exclusive', 0);
79 $disallow_duplicates = array_get_index($settings,
'disallow_duplicates', 0);
81 if (empty($state[
'asset'])) {
83 if (empty($state[
'assetid'])) {
86 $state[
'asset'] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($state[
'assetid']);
90 $am = $GLOBALS[
'SQ_SYSTEM']->am;
93 if ($link_to_broadcaster == 1) {
94 $major = $state[
'asset'];
96 $major = $am->getAsset($settings[
'assetid']);
100 if ($clone_broadcaster == 1) {
101 $minor = $state[
'asset'];
103 $minor = $am->getAsset($settings[
'clone_assetid']);
106 if ($disallow_duplicates) {
109 $children = $am->getChildren($major->id);
110 foreach ($children as $childid => $child_type) {
111 $name = $am->getAssetInfo(Array($childid), Array(), TRUE,
'name');
112 $short_name = $am->getAssetInfo(Array($childid), Array(), TRUE,
'short_name');
113 $type_code = $am->getAssetInfo(Array($childid), Array(), TRUE,
'type_code');
114 if ($name[$childid] == $minor->name && $short_name[$childid] == $minor->short_name && $type_code[$childid] == $minor->type()) {
117 'assetid' => $childid,
118 'parentid' => $major->id,
119 'link_type' => $settings[
'link_type'],
120 'value' => $settings[
'value'],
121 'is_dependant' => $is_dependant,
122 'is_exclusive' => $is_exclusive,
131 'link_type' => $settings[
'link_type'],
132 'value' => $settings[
'value'],
133 'sort_order' => NULL,
134 'is_dependant' => $is_dependant,
135 'is_exclusive' => $is_exclusive,
139 $clone_map = Array();
151 $clone = $am->cloneAsset($minor, $link, $clone_map, $components);
153 if (is_null($clone)) {
154 trigger_localised_error(
'CORE0138', E_USER_WARNING);
158 $valid_paths = make_valid_web_paths($minor->getWebPaths());
159 $good_paths = $GLOBALS[
'SQ_SYSTEM']->am->webPathsInUse($link[
'asset'], $valid_paths, $clone->id, TRUE);
161 $clone->saveWebPaths($good_paths);
162 $clone->remapAssetids($clone_map);
165 'assetid' => $clone->id,
166 'parentid' => $major->id,
167 'link_type' => $settings[
'link_type'],
168 'value' => $settings[
'value'],
169 'is_dependant' => $is_dependant,
170 'is_exclusive' => $is_exclusive,
186 public static function getInterface($settings, $prefix, $write_access=FALSE)
189 $clone_assetid = array_get_index($settings,
'clone_assetid', 0);
190 $selected_assetid = array_get_index($settings,
'assetid', 0);
191 $selected_link_type = array_get_index($settings,
'link_type', SQ_LINK_TYPE_1);
192 $value = array_get_index($settings,
'value',
'');
193 $is_dependant = array_get_index($settings,
'is_dependant', 0);
194 $is_exclusive = array_get_index($settings,
'is_exclusive', 0);
195 $disallow_duplicates = array_get_index($settings,
'disallow_duplicates', 0);
196 $clone_broadcaster = array_get_index($settings,
'clone_broadcaster', 1);
197 $link_to_broadcaster = array_get_index($settings,
'link_to_broadcaster', 0);
200 if ($clone_assetid && !$GLOBALS[
'SQ_SYSTEM']->am->assetExists($clone_assetid)) {
205 if ($selected_assetid && !$GLOBALS[
'SQ_SYSTEM']->am->assetExists($selected_assetid)) {
206 $selected_assetid = 0;
209 $link_type_list = get_link_type_names();
210 unset($link_type_list[SQ_LINK_NOTICE]);
212 if (!$write_access) {
213 $form_element_extras =
'disabled="disabled"';
215 $form_element_extras =
'';
221 asset_finder($prefix.
'[clone_assetid]', $clone_assetid);
223 if ($clone_assetid) {
224 $clone_assetname = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($clone_assetid), Array(), TRUE,
'name');
225 text_box($prefix.
'[clone_assetid]', $clone_assetname[$clone_assetid].
' (#'.$clone_assetid.
')',
'',
'', FALSE, $form_element_extras);
227 text_box($prefix.
'[clone_assetid]',
'',
'',
'', FALSE, $form_element_extras);
231 $basic_part_1 = ob_get_contents();
236 asset_finder($prefix.
'[assetid]', $selected_assetid);
238 if ($selected_assetid) {
239 $selected_assetname = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($selected_assetid), Array(), TRUE,
'name');
240 text_box($prefix.
'[assetid]', $selected_assetname[$selected_assetid].
' (#'.$selected_assetid.
')',
'',
'', FALSE, $form_element_extras);
242 text_box($prefix.
'[assetid]',
'',
'',
'', FALSE, $form_element_extras);
246 $basic_part_2 = ob_get_contents();
250 combo_box($prefix.
'[link_type]', $link_type_list, FALSE, $selected_link_type, NULL, $form_element_extras);
251 $basic_part_3 = ob_get_contents();
256 text_box($prefix.
'[value]', $value,
'',
'', FALSE, $form_element_extras);
257 $advanced_part_1 = ob_get_contents();
261 $is_dependant_list = Array(
262 0 => translate(
'non_dependently'),
263 1 => translate(
'dependently'),
265 combo_box($prefix.
'[is_dependant]', $is_dependant_list, FALSE, $is_dependant, NULL, $form_element_extras);
266 $advanced_part_2 = ob_get_contents();
270 $is_exclusive_list = Array(
271 0 => translate(
'non_exclusively'),
272 1 => translate(
'exclusivly'),
274 combo_box($prefix.
'[is_exclusive]', $is_exclusive_list, FALSE, $is_exclusive, NULL, $form_element_extras);
275 $advanced_part_3 = ob_get_contents();
279 check_box($prefix.
'[disallow_duplicates]',
'1', $disallow_duplicates, NULL, $form_element_extras);
280 label(translate(
'do_not_create_clone_if_same_name_exists'), $prefix.
'[disallow_duplicates]');
281 $advanced_part_4 = ob_get_contents();
285 check_box($prefix.
'[clone_broadcaster]',
'1', $clone_broadcaster, NULL, $form_element_extras);
286 label(translate(
'clone_broadcasting_asset'), $prefix.
'[clone_broadcaster]');
287 $advanced_part_5 = ob_get_contents();
291 check_box($prefix.
'[link_to_broadcaster]',
'1', $link_to_broadcaster, NULL, $form_element_extras);
292 label(translate(
'link_to_broadcasting_asset'), $prefix.
'[link_to_broadcaster]');
293 $advanced_part_6 = ob_get_contents();
298 $contents = translate(
'trigger_create_clone_basic', $basic_part_1, $basic_part_2, $basic_part_3).
300 '<b>'.translate(
'triggers_advanced_user_options').
'</b><br />'.
301 translate(
'trigger_create_clone_advanced', $advanced_part_1, $advanced_part_2, $advanced_part_3, $advanced_part_4, $advanced_part_5, $advanced_part_6);
321 $link_type_list = get_link_type_names();
323 $clone_broadcaster = array_get_index($request_data,
'clone_broadcaster', 0);
324 $link_to_broadcaster = array_get_index($request_data,
'link_to_broadcaster', 0);
327 if (($clone_broadcaster == 0) && empty($request_data[
'clone_assetid'][
'assetid'])) {
328 return translate(
'trigger_clone_asset_missing');
332 if (($link_to_broadcaster == 0) && empty($request_data[
'assetid'][
'assetid'])) {
333 return translate(
'trigger_clone_parent_missing');
336 if (empty($request_data[
'link_type']) || !isset($link_type_list[$request_data[
'link_type']])) {
337 return translate(
'trigger_link_type_missing');
340 $settings[
'clone_assetid'] = $request_data[
'clone_assetid'][
'assetid'];
341 $settings[
'assetid'] = $request_data[
'assetid'][
'assetid'];
342 $settings[
'link_type'] = $request_data[
'link_type'];
343 $settings[
'value'] = array_get_index($request_data,
'value',
'');
344 $settings[
'is_dependant'] = array_get_index($request_data,
'is_dependant', 0);
345 $settings[
'is_exclusive'] = array_get_index($request_data,
'is_exclusive', 0);
346 $settings[
'disallow_duplicates'] = array_get_index($request_data,
'disallow_duplicates', 0);
347 $settings[
'clone_broadcaster'] = $clone_broadcaster;
348 $settings[
'link_to_broadcaster'] = $link_to_broadcaster;
364 public static function getLocks($settings, &$state)
367 $state[
'assetid'] => Array(
'all'),