function addFieldRule(&$group, &$field, &$logic, &$values, $type = 0) { global $pommo; $dbo =& Pommo::$_dbo; $type = $type == 'or' ? 1 : 0; // remove previous filters Pommo_Rules::deleteRule($group, $field, $logic); // get the field require_once Pommo::$_baseDir . 'classes/Pommo_Fields.php'; $field = current(Pommo_Fields::get(array('id' => $field))); foreach ($values as $value) { // if this is a date type field, convert the values from human readable date // strings to timestamps appropriate for matching if ($field['type'] == 'date') { $value = Pommo_Helper::timeFromStr($value); } $v[] = $dbo->prepare("(%i,%i,'%s','%s',%i)", array($group, $field['id'], $logic, $value, $type)); } $query = "\n\t\t\tINSERT INTO " . $dbo->table['group_rules'] . "\n\t\t\t(group_id, field_id, logic, value, type)\n\t\t\tVALUES " . implode(',', $v); return $dbo->affected($query); }
$json->serve(); break; case 'updateRule': require_once Pommo::$_baseDir . 'classes/Pommo_Sql.php'; $group =& current(Pommo_Groups::get(array('id' => $state['group']))); $rules = Pommo_Sql::sortRules($group['rules']); switch ($_REQUEST['request']) { case 'update': if ($_REQUEST['type'] == 'or' && count($rules['and']) < 2) { $json->add('callbackFunction', 'resume'); $json->success(Pommo::_T('At least 1 "and" rule must exist before an "or" rule takes effect.')); } Pommo_Rules::changeType($group['id'], $_REQUEST['fieldID'], $_REQUEST['logic'], $_REQUEST['type']); break; case 'delete': Pommo_Rules::deleteRule($group['id'], $_REQUEST['fieldID'], $_REQUEST['logic']); break; } $json->add('callbackFunction', 'redirect'); $json->add('callbackParams', Pommo::$_baseUrl . 'groups_edit.php'); $json->serve(); break; case 'renameGroup': if (!empty($_REQUEST['group_name'])) { if (Pommo_Groups::nameChange($state['group'], $_REQUEST['group_name'])) { $json->success(Pommo::_T('Group Renamed')); } } $json->fail('invalid group name'); break; default: