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';
20 require_once SQ_SYSTEM_ROOT.
'/core/attributes/parameter_map/parameter_map.inc';
50 public static function execute($settings, &$state)
53 if ($settings[
'image_assetid'] ==
'0' && !$settings[
'use_current'])
return FALSE;
55 if (empty($state[
'asset'])) {
57 if (empty($state[
'assetid'])) {
60 $state[
'asset'] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($state[
'assetid']);
64 if (is_null($state[
'asset']))
return FALSE;
66 $old_current_asset = $GLOBALS[
'SQ_SYSTEM']->getGlobalDefine(
'CURRENT_ASSET', NULL);
67 $GLOBALS[
'SQ_SYSTEM']->setGlobalDefine(
'CURRENT_ASSET', $state[
'asset']);
69 $parameter_map_value = array_get_index($settings,
'value_map', serialize(Array()));
71 $param_map_value = $atr_parameter_map->getParameterValue(
'image_var');
73 if (is_null($old_current_asset)) {
74 $GLOBALS[
'SQ_SYSTEM']->unsetGlobalDefine(
'CURRENT_ASSET');
76 $GLOBALS[
'SQ_SYSTEM']->setGlobalDefine(
'CURRENT_ASSET', $old_current_asset);
80 if (empty($param_map_value) && empty($settings[
'variety_name']) && !$settings[
'delete_all'])
return FALSE;
83 if ($settings[
'use_current']) {
84 $settings[
'image_assetid'] = $state[
'asset']->id;
85 $image_to_use = $state[
'asset'];
88 $image_to_use = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($settings[
'image_assetid']);
92 if (!$GLOBALS[
'SQ_SYSTEM']->am->assetExists($image_to_use->id))
return FALSE;
95 $varieties = $image_to_use->attr(
'varieties');
98 if (empty($varieties))
return FALSE;
101 $variety_deleted = Array();
102 if ($settings[
'delete_all']) {
103 foreach ($varieties[
'data'] as $varid => $data) {
104 if (!$image_to_use->deleteVariety($image_to_use->id.
':'.$varid))
return FALSE;
105 $variety_deleted[] = $image_to_use->id.
':'.$varid;
110 if (!empty($param_map_value)) $settings[
'variety_name'] = $param_map_value;
112 $match_found = FALSE;
113 foreach ($varieties[
'data'] as $varid => $data) {
114 if ($data[
'name'] == $settings[
'variety_name']) {
116 if (!$image_to_use->deleteVariety($image_to_use->id.
':'.$varid))
return FALSE;
117 $variety_deleted[] = $image_to_use->id.
':'.$varid;
122 $return_array = Array(
'majorid' => $image_to_use->id);
123 foreach ($variety_deleted as $var) {
124 $return_array[
'variety_deleted'][] = $var;
127 return $return_array;
144 public static function getInterface($settings, $prefix, $write_access=FALSE)
147 $selected_image = array_get_index($settings,
'image_assetid', 0);
148 $variety_name = array_get_index($settings,
'variety_name',
'');
149 $delete_all = array_get_index($settings,
'delete_all', FALSE);
150 $use_current = array_get_index($settings,
'use_current', FALSE);
156 <td valign=
"top"><?php echo translate(
'trigger_action_delete_image_variety_image_under') ?></td>
160 asset_finder($prefix.
'[image_assetid]', $selected_image, Array(
'image' =>
'I'));
162 if ($selected_image != 0) {
163 echo get_asset_tag_line($selected_image);
165 echo translate(
'trigger_action_delete_image_variety_no_image');
172 <td valign=
"top"><?php echo
"<b><i>OR</i></b>"; ?></td>
176 <td valign=
"top"><?php echo translate(
'trigger_action_delete_image_variety_use_self') ?></td>
180 check_box($prefix.
'[use_current]',
'1', $use_current,
'', ($write_access ?
'' :
'disabled="disabled"'));
182 echo
'<img src="'.sq_web_path(
'lib').
'/web/images/'.($use_current ?
'tick' :
'cross').
'.gif" alt="'.($use_current ? translate(
'yes') : translate(
'no')).
'" /> ';
184 echo translate(
'trigger_action_delete_image_variety_note_use_self');
188 <td align=
"Left" valign=
"top" colspan=
"2"><br /><b><?php echo translate(
'trigger_action_delete_image_variety_details'); ?></b><br /></td>
192 <td valign=
"top"><?php echo translate(
'trigger_action_delete_image_variety_var_name'); ?></td>
196 text_box($prefix.
'[variety_name]', $variety_name, 25);
204 <td valign=
"top"><?php echo translate(
'trigger_action_delete_image_variety_del_all'); ?></td>
208 check_box($prefix.
'[delete_all]',
'1', $delete_all,
'', ($write_access ?
'' :
'disabled="disabled"'));
210 echo
'<img src="'.sq_web_path(
'lib').
'/web/images/'.($delete_all ?
'tick' :
'cross').
'.gif" alt="'.($delete_all ? translate(
'yes') : translate(
'no')).
'" /> ';
212 echo translate(
'trigger_action_delete_image_variety_del_all_note');
219 $new_prefix = str_replace(array(
'[',
']'),
'_', $prefix);
220 hidden_field($prefix.
'[new_prefix]', $new_prefix);
223 $parameter_map_value = array_get_index($settings,
'value_map', serialize(Array()));
227 $atr_parameter_map->setParameter(
'image_var',
'Image Variety');
228 echo $atr_parameter_map->paint($new_prefix.
'_parameter_map', !$write_access);
231 $contents = ob_get_clean();
250 $settings[
'image_assetid'] = $request_data[
'image_assetid'][
'assetid'];
251 $settings[
'variety_name'] = array_get_index($request_data,
'variety_name',
'');
252 $settings[
'delete_all'] = array_get_index($request_data,
'delete_all', FALSE);
253 $settings[
'use_current'] = array_get_index($request_data,
'use_current', FALSE);
256 $new_prefix = str_replace(array(
'[',
']'),
'_', array_get_index($request_data,
'new_prefix',
''));
258 $atr_parameter_map->process($new_prefix.
'_parameter_map');
260 $settings[
'value_map'] = $atr_parameter_map->value;