function test_form(form) {
if(form.f_proc_name.value.length == 0) {
alert(\"$msg[702]\");
form.f_proc_name.focus();
return false;
}
if(form.f_proc_code.value.length == 0) {
alert(\"$msg[703]\");
form.f_proc_code.focus();
return false;
}
return true;
}
";
function check_param($requete) {
$query_parameters=array();
//S'il y a des termes !!*!! dans la requête alors il y a des paramètres
if (preg_match_all("|!!(.*)!!|U",$requete,$query_parameters)) {
for ($i=0; $i
";
// affichage du tableau des procédures
if ($PMBuserid!=1) $where=" where (autorisations='$PMBuserid' or autorisations like '$PMBuserid %' or autorisations like '% $PMBuserid %' or autorisations like '% $PMBuserid') ";
$requete = "SELECT idproc, type, name, requete, comment, autorisations FROM empr_caddie_procs $where ORDER BY type, name ";
$res = mysql_query($requete, $dbh) or die(mysql_error().$requete) ;
$nbr = mysql_num_rows($res);
$parity=1;
for($i=0;$i<$nbr;$i++) {
$row=mysql_fetch_row($res);
$rqt_autorisation=explode(" ",$row[5]);
if (array_search ($PMBuserid, $rqt_autorisation)!==FALSE || $PMBuserid == 1) {
if ($parity % 2) {
$pair_impair = "even";
} else {
$pair_impair = "odd";
}
$parity += 1;
$tr_javascript=" onmouseover=\"this.className='surbrillance'\" onmouseout=\"this.className='$pair_impair'\" onmousedown=\"document.location='./circ.php?categ=caddie&sub=gestion&quoi=procs&action=modif&id=$row[0]';\" ";
print "
";
if ($row[1]!="ACTION") print " "; else print " ";
print "
$row[1]
$row[2]
$row[4]
";
if (preg_match_all("|!!(.*)!!|U",$row[3],$query_parameters)) print "$msg[procs_options_config_param] ";
print " " ;
print "
";
}
}
print "
";
}
function proc_form($name='', $code='', $comment='', $id=0, $autorisations=array(), $type="SELECT" ) {
global $msg;
global $empr_cart_procs_form;
global $empr_cart_procs_edit_form ;
global $charset;
if ($id) {
$empr_cart_procs_form = $empr_cart_procs_edit_form ;
if ($type!="ACTION") $empr_cart_procs_form=str_replace("!!exec_button!!"," ",$empr_cart_procs_form);
else $empr_cart_procs_form=str_replace("!!exec_button!!","",$empr_cart_procs_form);
}
$empr_cart_procs_form = str_replace('!!id!!', $id, $empr_cart_procs_form);
if(!$id) $empr_cart_procs_form = str_replace('!!form_title!!', $msg[704], $empr_cart_procs_form);
else $empr_cart_procs_form = str_replace('!!form_title!!', $msg["procs_modification"], $empr_cart_procs_form);
if($id && $name && $code) $action = "./circ.php?categ=caddie&sub=gestion&quoi=procs&action=modif&id=$id";
else $action = "./circ.php?categ=caddie&sub=gestion&quoi=procs&action=add";
$empr_cart_procs_form = str_replace('!!action!!', $action, $empr_cart_procs_form);
$empr_cart_procs_form = str_replace('!!type!!', htmlentities($msg["caddie_procs_type_".$type],ENT_QUOTES, $charset), $empr_cart_procs_form);
$empr_cart_procs_form = str_replace('!!name!!', htmlentities($name,ENT_QUOTES, $charset), $empr_cart_procs_form);
$empr_cart_procs_form = str_replace('!!name_suppr!!', htmlentities(addslashes($name),ENT_QUOTES, $charset), $empr_cart_procs_form);
$empr_cart_procs_form = str_replace('!!code!!', htmlentities($code,ENT_QUOTES, $charset), $empr_cart_procs_form);
$empr_cart_procs_form = str_replace('!!comment!!', htmlentities($comment,ENT_QUOTES, $charset), $empr_cart_procs_form);
$autorisations_users="";
$id_check_list='';
while (list($row_number, $row_data) = each($autorisations)) {
$id_check="auto_".$row_data[1];
if($id_check_list)$id_check_list.='|';
$id_check_list.=$id_check;
if ($row_data[0]) $autorisations_users.=" ".$row_data[2]." ";
else $autorisations_users.=" ".$row_data[2]." ";
}
$autorisations_users.=" ";
$empr_cart_procs_form = str_replace('!!autorisations_users!!', $autorisations_users, $empr_cart_procs_form);
print confirmation_delete("./circ.php?categ=caddie&sub=gestion&quoi=procs&action=del&id=");
print $empr_cart_procs_form;
}
function run_form($id, $dbh) {
global $msg;
global $charset;
$hp=new parameters($id,"empr_caddie_procs");
if (preg_match_all("|!!(.*)!!|U",$hp->proc->requete,$query_parameters))
$hp->gen_form("circ.php?categ=caddie&sub=gestion&quoi=procs&action=final&id=$id");
else echo "";
}
switch($action) {
case 'configure':
$hp=new parameters($id_query,"empr_caddie_procs");
$hp->show_config_screen("circ.php?categ=caddie&sub=gestion&quoi=procs&action=update_config","circ.php?categ=caddie&sub=gestion&quoi=procs");
break;
case 'update_config':
$hp=new parameters($id_query,"empr_caddie_procs");
$hp->update_config("circ.php?categ=caddie&sub=gestion&quoi=procs");
break;
case 'final':
$hp=new parameters($id_query,"empr_caddie_procs");
if (preg_match_all("|!!(.*)!!|U",$hp->proc->requete,$query_parameters)) {
$hp->get_final_query();
$code=$hp->final_query;
$id=$id_query;
}
include("./circ/caddie/gestion/execute.inc.php");
break;
case 'execute':
// form pour params et validation
run_form($id, $dbh);
break;
case 'modif':
if($id) {
if($f_proc_name && $f_proc_code) {
// faire la modification
if (is_array($userautorisation)) $autorisations=implode(" ",$userautorisation);
else $autorisations="";
$param_name=check_param($f_proc_code);
if ($param_name!==true) {
error_message_history($param_name, sprintf($msg["proc_param_check_field_name"],$param_name), 1);
exit();
}
$requete = "UPDATE empr_caddie_procs SET name='$f_proc_name',requete='$f_proc_code',comment='$f_proc_comment' , autorisations='$autorisations' WHERE idproc=$id ";
$res = mysql_query($requete, $dbh);
show_procs($dbh);
} else {
// afficher le form avec les bonnes valeurs
$requete = "SELECT idproc, name, requete, comment, autorisations, type FROM empr_caddie_procs WHERE idproc=$id LIMIT 1 ";
$res = mysql_query($requete, $dbh);
$requete_users = "SELECT userid, username FROM users order by username ";
$res_users = mysql_query($requete_users, $dbh);
$all_users=array();
while (list($all_userid,$all_username)=mysql_fetch_row($res_users)) {
$all_users[]=array($all_userid,$all_username);
}
if(mysql_num_rows($res)) {
$row = mysql_fetch_row($res);
$autorisations_donnees=explode(" ",$row[4]);
for ($i=0 ; $ialert(\"$msg[709]\");";
}
show_procs($dbh);
} else {
$requete_users = "SELECT userid, username FROM users order by username ";
$res_users = mysql_query($requete_users, $dbh);
$autorisation=array();
while (list($all_userid,$all_username)=mysql_fetch_row($res_users)) {
if ($all_userid==1 or $all_userid==$PMBuserid) $autorisation[]=array(1,$all_userid,$all_username);
else $autorisation[]=array(0,$all_userid,$all_username);
}
proc_form("", "", "", 0, $autorisation);
}
break;
case 'import':
$import_proc_tmpl = str_replace("!!action!!", "./circ.php?categ=caddie&sub=gestion&quoi=procs&action=importsuite", $import_proc_tmpl);
print $import_proc_tmpl ;
break;
case 'importsuite':
procs_create ("EMPRCADDIE", "./circ.php?categ=caddie&sub=gestion&quoi=procs&action=modif&id=!!id!!", "./circ.php?categ=caddie&sub=gestion&quoi=procs&action=import") ;
break;
case 'del':
if($id) {
$requete = "DELETE FROM empr_caddie_procs WHERE idproc=$id ";
$res = mysql_query($requete, $dbh);
show_procs($dbh);
}
break;
default:
show_procs($dbh);
break;
}