17 define(
'SQ_KEYWORD_CONDITION_BEGIN',
'begin');
18 define(
'SQ_KEYWORD_CONDITION_END',
'end');
19 define(
'SQ_KEYWORD_CONDITION_ELSE',
'else');
45 var $host_asset = NULL;
64 var $conditions_attribute_name =
'';
74 $this->
setHost($host_asset, $conditions_attribute_name);
88 function setHost(&$host_asset, $conditions_attribute_name)
90 $this->host_asset = $host_asset;
91 $this->conditions_attribute_name = $conditions_attribute_name;
111 function evaluate(&$asset_being_painted, $condition_names, &$logical_keywords, $boolean_values=Array(0, 1))
116 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'condition');
120 $condition_names = array_intersect($condition_names, array_keys($conditions_info));
122 if (!empty($condition_names)) {
125 foreach ($condition_names as $condition_name) {
128 $merge_result = array_merge($logical_keywords, $ret);
131 $ret[$condition_name] = $boolean_values[
Condition::evaluateRestriction($asset_being_painted, $conditions_info[$condition_name][
'restriction'], $conditions_info[$condition_name][
'type_code']) ? 1 : 0];
157 $type_code = $condition_parameters[
'type_code'];
158 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($type_code);
160 call_user_func_array(Array($type_code,
'updateKeywords'), Array($logical_keywords, &$condition_parameters[
'restriction'][
'condition_data']));
175 return (array_keys($conditions_info));
198 if (!empty($conditions[$condition_name])) {
199 $type_code = $conditions[$condition_name][
'type_code'];
200 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($type_code);
201 $ret = call_user_func(Array($type_code,
'getRequiredKeywords'), $conditions[$condition_name][
'restriction'][
'condition_data']);
236 $included_file = SQ_SYSTEM_ROOT.
'/'.$GLOBALS[
'SQ_SYSTEM']->am->_asset_types[$condition_type][
'dir'].
'/';
237 if ($edit_fns) $condition_type .=
'_edit_fns';
238 $included_file .= $condition_type.
'.inc';
239 require_once $included_file;
241 $new_condition =
new $condition_type();
242 return $new_condition;
266 if (!empty($conditions_parameters) && isset($conditions_parameters[$condition_name])) {
267 $ret = $conditions_parameters[$condition_name];
270 if (!empty($ret) && !empty($key)) {
271 $ret = isset($ret[$key]) ? $ret[$key] : $default;
290 $ret = $host_asset->attr($this->conditions_attribute_name);
305 return $this->host_asset;
318 $userid = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
319 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($userid);
334 return (!empty($this->host_asset) && !empty($this->conditions_attribute_name));
360 foreach ($conditions_parameters as $condition_name => $parameters) {
361 $condition_prefix = $prefix.$condition_name;
363 $o->openSection(ucwords(str_replace(
'_',
' ', $parameters[
'type_code'])));
366 $o->openField(translate(
'keyword_name'));
368 text_box($condition_prefix.
'_keyword_name', $condition_name, 30);
370 echo $condition_name;
375 $condition_type = $parameters[
'type_code'];
380 $o->openField(
'Keyword is true if: ');
381 $match_options = call_user_func(Array($condition_type,
'getMatchKeywords'), $condition_type);
383 combo_box($condition_prefix.
'_match', $match_options, FALSE, $parameters[
'restriction'][
'match']);
385 echo $match_options[$parameters[
'restriction'][
'match']];
388 if (isset($parameters[
'restriction']) && empty($parameters[
'restriction'][
'condition_data'])) {
389 $parameters[
'restriction'][
'condition_data'] = Array();
393 $condition_edit_fns->paintEditInterface($parameters[
'restriction'][
'condition_data'], $o, $condition_prefix, $write_access, $allowed_keywords);
394 $condition_interface = ob_get_contents();
397 if (!empty($condition_interface)) {
398 $o->openField(translate(
'options'));
399 echo $condition_interface;
404 $o->openField(translate(
'delete'));
405 check_box($condition_prefix.
'_delete', $value=
'1', $checked=FALSE);
409 unset($condition_edit_fns);
418 $options = Array(
'' =>
'- '.translate(
'select_condition_type').
' -');
420 $conditions_type_code = $GLOBALS[
'SQ_SYSTEM']->am->getTypeDescendants(
'condition', FALSE);
421 foreach ($conditions_type_code as $type_code) {
422 $options[$type_code] = $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($type_code,
'name');
425 $o->openSection(translate(
'new_conditions'));
427 $o->openField(translate(
'condition_type').
':');
428 combo_box($prefix.
'_new_condition_type', $options, FALSE,
'');
459 $conditions_parameters_new = Array();
462 foreach ($conditions_parameters as $condition_name => $parameters) {
463 $condition_prefix = $prefix.$condition_name;
465 if (empty($_REQUEST[$condition_prefix.
'_delete']) || $_REQUEST[$condition_prefix.
'_delete'] != 1) {
467 $new_name = trim($_REQUEST[$condition_prefix.
'_keyword_name']);
468 if (preg_match(
'/^('.SQ_KEYWORD_CONDITION_BEGIN.
'|'.SQ_KEYWORD_CONDITION_END.
'|'.SQ_KEYWORD_CONDITION_ELSE.
')_(.*)$/', $new_name)) {
469 trigger_error(
'Incorrect keyword name: keyword names cannot begin with "begin_", "end_" or "else_" ('.$new_name.
').', E_USER_WARNING);
470 $new_name = $condition_name;
475 $condition_type = $parameters[
'type_code'];
478 $conditions_parameters_new[$new_name][
'restriction'][
'condition_data'] = $condition_edit_fns->processEditInterface($o, $condition_prefix, $allowed_keywords);
479 $conditions_parameters_new[$new_name][
'type_code'] = $condition_type;
480 $conditions_parameters_new[$new_name][
'restriction'][
'match'] = array_get_index($_POST, $condition_prefix.
'_match', TRUE);
485 if (!empty($_REQUEST[$prefix.
'_new_condition_type'])) {
486 $new_condition_type = $_REQUEST[$prefix.
'_new_condition_type'];
489 $conditions_parameters_new[$this->
_generateUniqueName(
'', $conditions_parameters_new)] = Array(
'type_code' => $new_condition_type,
'restriction' => Array(
'match' => 1,
'condition_data' => Array()));
493 $asset->setAttrValue($this->conditions_attribute_name, $conditions_parameters_new);
494 $asset->saveAttributes();
516 $desired_name = trim($desired_name);
517 $desired_name = preg_replace(
'/ /' ,
'_',$desired_name);
518 if (empty($desired_name)) {
519 $desired_name =
'condition_1';
522 $ret = $desired_name;
524 if (!empty($reserved_names[$ret])) {
525 $desired_name = preg_replace(
'/_\d*^/' ,
'', $desired_name);
526 for ($i = 2; $i < 1000; $i++) {
527 $ret = $desired_name.
'_'.$i;
528 if (empty($reserved_names[$ret]))
break;