uid = $_uid; $this->rules = array(); $sql = mysql_query("SELECT rank,rid,flags,name FROM rules WHERE uid='$_uid' ORDER BY rank"); while(list($_rank,$_rid,$_flags,$_name) = mysql_fetch_row($sql)) { $this->rules[$_rid] = new Rule($_rank,$_flags,$_name,true); $this->rules[$_rid]->sql_get_matches($_uid,$_rid); $this->rules[$_rid]->sql_get_actions($_uid,$_rid); } } function to_string() { return ""; } function delete_rule($_rid) { $rk = $this->rules[$_rid]->rank; $this->rules[$_rid]->sql_clean($this->uid, $_rid); unset($this->rules[$_rid]); mysql_query("UPDATE rules SET rank=rank-1 WHERE uid='{$this->uid}' and rank>$rk"); } function new_rule_id() { $i=1; while(array_key_exists($i,$this->rules)) $i++; return $i; } function handle_form() { global $philter; $rule_id = ($_POST['rule']['id'] ? $_POST['rule']['id'] : $this->new_rule_id()); $rank = (isset($this->rules[$rule_id]) ? $this->rules[$rule_id]->rank : count($this->rules)+1); $flags = Array(); if($_POST['rule']['all']) $flags[] = 'all'; if(isset($_POST['rule']['block'])) $flags[] = 'block'; $flags = implode(',', $flags); $my_rule = new Rule($rank,$flags,$_POST['rule']['name']); // we create the $matches real array if(isset($_POST['rule']['matches'])) foreach($_POST['rule']['matches'] as $data) if(array_key_exists(0, $data)) $my_rule->matches[] = $data; // we create the $actions real array if(isset($_POST['rule']['actions'])) foreach($_POST['rule']['actions'] as $data) if(array_key_exists(0, $data)) $my_rule->actions[] = $data; if(!count($my_rule->actions) && !count($my_rule->matches)) { $philter->set_error("You cannot add an empty rule"); return false; } $my_rule->sql_store(get_user_id(),$rule_id); $_POST['rule']['id'] = $rule_id; $this->rules[$rule_id] = $my_rule; return true; } function to_js() { $res = "filter[0] = { all: 1, block:1, name:'"._i18n('new_rule')."', matches: [], actions: [] };\n"; foreach($this->rules as $id=>$rule) $res .= "filter[$id] = ".$rule->to_js().";\n"; return $res; } } /******************************************************************************** * $Id$ * vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100: ********************************************************************************/ ?>