id) return 'NAME_EXIST'; else return 'NAME_NOT_EXIST'; } function verify_rule($rule_or_condition,$ID){ $sql="select id from download_affect_rules where %s='%s'"; $arg=array($rule_or_condition,$ID); $result_id = mysql2_query_secure($sql,$_SESSION['OCS']["readServer"],$arg); $id_exist = mysql_fetch_object($result_id); if ($id_exist->id) return 'RULE_EXIST'; else return 'RULE_NOT_EXIST'; } function delete_rule($ID_RULE){ global $l; $id_exist=verify_rule('rule',$ID_RULE); if ($id_exist == "RULE_EXIST"){ $sql_del_rule="delete from download_affect_rules where rule='%s'"; $arg=$ID_RULE; mysql2_query_secure($sql_del_rule, $_SESSION['OCS']["writeServer"],$arg); }else echo msg_error($l->g(672)); } function delete_condition_rule($ID){ global $l; $id_exist=verify_rule('id',$ID); if ($id_exist == "RULE_EXIST"){ $sql_del_rule="delete from download_affect_rules where id='%s'"; $arg=$ID; mysql2_query_secure($sql_del_rule, $_SESSION['OCS']["writeServer"],$arg); }else echo msg_error($l->g(672)); } /* * Function for add new rule for redistribution server * * $RULE_NAME= Name of the rule * $RULE_VALUES = array with condition values * => ex: $RULE_VALUES['PRIORITE_1'],$RULE_VALUES['CFIELD_1'], * $RULE_VALUES['OP_1'],$RULE_VALUES['COMPTO_1'],$RULE_VALUES['COMPTO_TEXT_1'], * $RULE_VALUES['PRIORITE_2'],$RULE_VALUES['CFIELD_2'], * $RULE_VALUES['OP_2'],$RULE_VALUES['COMPTO_2'],$RULE_VALUES['COMPTO_TEXT_2'] * $ID_RULE= Id of the rule. It can't exist before * */ function add_rule($RULE_NAME,$RULE_VALUES,$ID_RULE=''){ global $l,$protectedPost; $rule_exist=verify_name($RULE_NAME); if ($rule_exist == 'NAME_NOT_EXIST'){ //verify this id is new $sql="select id from download_affect_rules where id='%s'"; $arg=$ID_RULE; $result_id = mysql2_query_secure($sql,$_SESSION['OCS']["readServer"],$arg); $id_exist = mysql_fetch_object($result_id); //generate id if (!is_numeric($ID_RULE) or $ID_RULE == '' or isset($id_exist->id)){ $sql_new_id="select max(RULE) as ID_RULE from download_affect_rules"; $result_new_id = mysql2_query_secure($sql_new_id, $_SESSION['OCS']["readServer"]); $new_id = mysql_fetch_object($result_new_id); $ID_RULE=$new_id -> ID_RULE; $ID_RULE++; } //insert new rule $i=1; while ($RULE_VALUES['PRIORITE_'.$i]){ if ($RULE_VALUES['CFIELD_'.$i] != "") { $sql_insert_rule="insert into download_affect_rules (RULE,RULE_NAME,PRIORITY,CFIELD,OP,COMPTO,SERV_VALUE) value (%s,'%s',%s,'%s','%s','%s','%s')"; $arg=array($ID_RULE,$protectedPost['RULE_NAME'], $RULE_VALUES['PRIORITE_'.$i],$RULE_VALUES['CFIELD_'.$i], $RULE_VALUES['OP_'.$i],$RULE_VALUES['COMPTO_'.$i],$RULE_VALUES['COMPTO_TEXT_'.$i]); mysql2_query_secure($sql_insert_rule, $_SESSION['OCS']["writeServer"],$arg); } $i++; } } else{ echo msg_error($l->g(670)); } } /* * HTML fields for condition of rule * */ function fields_conditions_rules($num,$entete='NO'){ global $l,$protectedPost; if ($entete != 'NO') $tab.="