17 require_once dirname(dirname(__FILE__)).
'/trigger_condition_asset_type/trigger_condition_asset_type.inc';
43 '=' => strtolower(translate(
'equals')),
44 '!=' => strtolower(translate(
'does_not_equal')),
67 public static function evaluate($settings, &$state)
69 if (empty($settings[
'asset_type']))
return FALSE;
70 if (empty($settings[
'attribute']))
return FALSE;
72 if ((!$settings[
'inherit']) && (array_get_index($state,
'asset_type') != $settings[
'asset_type'])) {
77 if (empty($state[
'asset'])) {
78 $state[
'asset'] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($state[
'assetid']);
81 if (!isset($state[
'asset_type'])) {
82 $state[
'asset_type'] = $state[
'asset']->type();
85 $value = $settings[
'value'];
87 if ($settings[
'inherit']) {
88 if ($state[
'asset'] instanceof $settings[
'asset_type']) {
89 return ($state[
'asset']->
attr($settings[
'attribute']) == $value) == (array_get_index($settings,
'operator',
'=') ==
'=');
92 if ($state[
'asset_type'] == $settings[
'asset_type']) {
93 return ($state[
'asset']->
attr($settings[
'attribute']) == $value) == (array_get_index($settings,
'operator',
'=') ==
'=');
111 public static function getInterface($settings, $prefix, $write_access=FALSE)
113 $selected_type = array_get_index($settings,
'asset_type',
'page');
114 $am = $GLOBALS[
'SQ_SYSTEM']->am;
119 asset_type_chooser($prefix.
'[type_code]', FALSE, Array(
'type_code' => $selected_type), NULL, FALSE, FALSE);
121 check_box($prefix.
'[inherit]', 1, array_get_index($settings,
'inherit'),
'',
'id="'.$prefix.
'_inherit" style="margin: 0px"');
123 label(translate(
'or_inherited_types'), $prefix.
'_inherit');
126 echo
'<b>'.$selected_type.
'</b>';
127 if (array_get_index($settings,
'inherit')) {
128 echo
' '.translate(
'or_inherited_types').
' ';
131 $asset_type_component = ob_get_contents();
136 $attribute = array_get_index($settings,
'attribute',
'');
137 if ($selected_type ==
'') {
138 echo
'<b>['.translate(
'asset_type_not_selected').
']</b>';
140 $attrs = $GLOBALS[
'SQ_SYSTEM']->am->getAssetTypeAttributes($selected_type, Array(
'name'));
142 echo
'<b>['.translate(
'asset_type_no_attributes_found').
']</b>';
145 $attr_options = Array(
'' =>
'');
146 foreach ($attrs as $attr_name) {
147 $attr_options[$attr_name] = $attr_name;
149 combo_box($prefix.
'[attribute]', $attr_options, FALSE, $attribute);
151 echo
'<b>'.$attribute.
'</b>';
155 $attribute_component = ob_get_contents();
161 $operator = array_get_index($settings,
'operator',
'=');
163 combo_box($prefix.
'[operator]', $operator_options, FALSE, $operator);
165 echo
'<b>'.$operator_options[$operator].
'</b>';
167 $operator_component = ob_get_contents();
173 $value = array_get_index($settings,
'text_value',
'');
176 text_area($prefix.
'[value]', $value, 80, 5);
178 echo
'<b>'.$value.
'</b>';
180 $value_component = ob_get_contents();
183 return translate(
'trigger_attribute_value', $asset_type_component, $attribute_component, $operator_component, $value_component);
200 if (empty($request_data)) {
201 return translate(
'trigger_input_data_error');
204 $asset_type = array_get_index($request_data,
'type_code', FALSE);
206 return translate(
'trigger_type_code_not_supplied');
209 $settings[
'asset_type'] = $asset_type;
210 $settings[
'inherit'] = !empty($request_data[
'inherit']);
211 $settings[
'attribute'] = array_get_index($request_data,
'attribute', FALSE);
212 $settings[
'operator'] = array_get_index($request_data,
'operator',
'=');
214 $value = array_get_index($request_data,
'value', FALSE);
215 $settings[
'text_value'] = $value;
218 if (!empty($settings[
'asset_type']) && !empty($settings[
'attribute'])) {
219 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($settings[
'asset_type']);
220 $fake_asset =
new $settings[
'asset_type'];
221 $attr = $fake_asset->getAttribute($settings[
'attribute'], TRUE);
222 if (!is_null($attr)) {
224 $value = str_replace(
';',
'', $value);
225 eval(
'$value = '.$value.
';');
229 $settings[
'value'] = $value;