nom_proc = $nom_proc; $this->comment = $comment; $this->userautorisation = $userautorisation; $this->print_field = $print_field; $this->fixed_params = $fixed_params; $this->op_param = $op_param; $this->val_param = $val_param; $this->dynamic_params = $dynamic_params; $this->op_var = $op_var; $this->val_var = $val_var; $this->parse_config(); $this->pp=new parametres_perso("notices"); $this->r=""; $this->sf=""; $this->url=""; $this->url_next=""; } // parser du fichier de configuration function parse_config(){ global $include_path; global $lang; $fp=fopen($include_path."/create_proc/$lang.xml","r") or die("Can't find XML file"); $xml=fread($fp,filesize($include_path."/create_proc/$lang.xml")); fclose($fp); $param=_parser_text_no_function_($xml, "PMBFIELDS"); for($i=0; $ilist_fields[$param["LISTFIELDS"][0]["ITEM"][$i]["ID"]]["TITLE"]=$param["LISTFIELDS"][0]["ITEM"][$i]["TITRE"]; $this->list_fields[$param["LISTFIELDS"][0]["ITEM"][$i]["ID"]]["SEPARATOR"]=$param["LISTFIELDS"][0]["ITEM"][$i]["SEPARATEUR"]; $this->list_fields[$param["LISTFIELDS"][0]["ITEM"][$i]["ID"]]["DATATYPE"]=$param["LISTFIELDS"][0]["ITEM"][$i]["TYPE"]; $this->list_fields[$param["LISTFIELDS"][0]["ITEM"][$i]["ID"]]["CHAMP"]=$param["LISTFIELDS"][0]["ITEM"][$i]["CHAMP"]; $this->list_fields[$param["LISTFIELDS"][0]["ITEM"][$i]["ID"]]["TABLE"]=$param["LISTFIELDS"][0]["ITEM"][$i]["TABLE"]; $this->list_fields[$param["LISTFIELDS"][0]["ITEM"][$i]["ID"]]["JOINTURE"]=$param["LISTFIELDS"][0]["ITEM"][$i]["JOINTURE"]; $this->list_fields[$param["LISTFIELDS"][0]["ITEM"][$i]["ID"]]["INDEX"]=$param["LISTFIELDS"][0]["ITEM"][$i]["INDEX"]; } for($i=0; $iop_type[$param["TYPEFIELDS"][0]["FIELD"][$i]["DATATYPE"]][$j]=$param["TYPEFIELDS"][0]["FIELD"][$i]["QUERY"][$j]["FOR"]; } } for($i=0; $ioperateur[$param["OPERATORS"][0]["OPERATOR"][$i]["NAME"]]["TITRE"]=$param["OPERATORS"][0]["OPERATOR"][$i]["value"]; $this->operateur[$param["OPERATORS"][0]["OPERATOR"][$i]["NAME"]]["DEB"]=$param["OPERATORS"][0]["OPERATOR"][$i]["DEB"]; $this->operateur[$param["OPERATORS"][0]["OPERATOR"][$i]["NAME"]]["FIN"]=$param["OPERATORS"][0]["OPERATOR"][$i]["END"]; } } // modification de la priorité d'affichage function mod_prio($up){ $tmp = $this->print_field[$up-1]; $this->print_field[$up-1]=$this->print_field[$up]; $this->print_field[$up]=$tmp; unset($tmp); } // formulaire du choix des paramètres fixes function choix_param() { global $charset; global $msg; // données provenant du formulaire global $add_param; global $delete_param; // ajout d'un paramètre if (($add_param)&&($delete_param==="")){ $this->fixed_params[]=$add_param; } //Génération de la liste des champs possibles $this->r=""; //Affichage des champs déjà saisis $n=0; $this->sf="\n"; if(!((count($this->fixed_params)==0) || ((count($this->fixed_params)==1)&&($delete_param!="")))) $this->sf.=""; for ($i=0; $ifixed_params); $i++) { if ((string)$i!=$delete_param) { $this->sf.=""; $this->sf.=""; // Affichage du type de condition $this->sf.=""; // Affichage de la valeur de condition $this->sf.=""; // Boutton de supression $this->sf.=""; $this->sf.="\n"; $n++; } } $this->sf.="
".$msg["crit"]."".$msg["type_op"]."".$msg[1604]."".$msg[63]."
"; $this->sf.=""; $f=explode("_",$this->fixed_params[$i]); // Affichage du nom du champ if ($f[0]=="f") { $this->sf.=htmlentities($this->list_fields[$f[1]]["TITLE"],ENT_QUOTES,$charset); } else { $this->sf.=htmlentities($this->pp->t_fields[$f[1]]["TITRE"],ENT_QUOTES,$charset); } $this->sf.=""; $this->sf.="\n"; $this->sf.=""; $this->sf.=""; $this->sf.="
\n"; // Champs cachés $this->sf.=""; $this->sf.=""; for($i=0; $iuserautorisation); $i++) { $this->sf.=""; } for($i=0; $iprint_field); $i++) { $this->sf.=""; } for($i=0; $idynamic_params); $i++) { $this->sf.=""; } for($i=0; $iop_var); $i++) { $this->sf.=""; } for($i=0; $ival_var); $i++) { $this->sf.=""; } $this->sf.=""; } // formulaire du choix des paramètres variables function choix_var(){ global $charset; global $msg; // données provenant du formulaire global $add_var; global $delete_var; // ajout d'un paramètre if (($add_var)&&($delete_var==="")){ $this->dynamic_params[]=$add_var; } //Génération de la liste des champs possibles $this->r=""; //Affichage des champs déjà saisis $n=0; $this->sf="\n"; if(!((count($this->dynamic_params)==0) || ((count($this->dynamic_params)==1)&&($delete_var!="")))) $this->sf.=""; for ($i=0; $idynamic_params); $i++) { if ((string)$i!=$delete_var) { $this->sf.=""; $this->sf.=""; // Affichage du type de condition $this->sf.=""; // Affichage de la valeur de condition $this->sf.=""; // Boutton de supression $this->sf.=""; $this->sf.="\n"; $n++; } } $this->sf.="
".$msg["crit"]."".$msg["type_op"]."".$msg[103]."".$msg[63]."
"; $this->sf.=""; $f=explode("_",$this->dynamic_params[$i]); // Affichage du nom du champ if ($f[0]=="f") { $this->sf.=htmlentities($this->list_fields[$f[1]]["TITLE"],ENT_QUOTES,$charset); } else { $this->sf.=htmlentities($this->pp->t_fields[$f[1]]["TITRE"],ENT_QUOTES,$charset); } $this->sf.=""; $this->sf.="\n"; $this->sf.=""; $this->sf.=""; $this->sf.="
\n"; // Champs cachés $this->sf.=""; $this->sf.=""; for($i=0; $iuserautorisation); $i++) { $this->sf.=""; } for($i=0; $iprint_field); $i++) { $this->sf.=""; } for($i=0; $ifixed_params); $i++) { $this->sf.=""; } for($i=0; $iop_param); $i++) { $this->sf.=""; } for($i=0; $ival_param); $i++) { $this->sf.=""; } $this->sf.=""; } // formulaire du choix des champs à afficher function choix_champ() { global $charset; global $msg; // données provenant du formulaire global $add_field; global $delete_field; global $add_prio; global $min_prio; // ajout d'un champ if (($add_field)&&($delete_field==="")&&($add_prio==="")&&($min_prio==="")){ $this->print_field[]=$add_field; } // Identifiant du champ supprimé for($i=0; $iprint_field); $i++) { if ((string)$i==$delete_field) $delete_id = $this->print_field[$i]; } // Changement de priorité if($add_prio!="") $this->mod_prio($add_prio); if($min_prio!="") $this->mod_prio($min_prio+1); //Génération de la liste des champs possibles $this->r=""; //Affichage des champs déjà saisis $n=0; $this->sf="\n"; for ($i=0; $iprint_field); $i++) { if ((string)$i!=$delete_field) { $this->sf.=""; $this->sf.=""; // Boutton de supression $this->sf.=""; // Bouttons de priorités if( ($i==0) || (($i==1)&&($delete_field=="0")) ) $this->sf .=""; else $this->sf.=""; if( ($i==count($this->print_field)-1) || (($i==count($this->print_field)-2)&&($delete_field==count($this->print_field)-1)) ) $this->sf .=""; else $this->sf.=""; $this->sf.="\n"; $n++; } } $this->sf.="
"; $this->sf.=""; $f=explode("_",$this->print_field[$i]); // Affichage du nom du champ if ($f[0]=="f") { $this->sf.=htmlentities($this->list_fields[$f[1]]["TITLE"],ENT_QUOTES,$charset); } else { $this->sf.=htmlentities($this->pp->t_fields[$f[1]]["TITRE"],ENT_QUOTES,$charset); } $this->sf.="  
\n"; // Champs cachés $this->sf.=""; $this->sf.=""; for($i=0; $iuserautorisation); $i++) { $this->sf.=""; } for($i=0; $ifixed_params); $i++) { $this->sf.=""; } for($i=0; $iop_param); $i++) { $this->sf.=""; } for($i=0; $ival_param); $i++) { $this->sf.=""; } for($i=0; $idynamic_params); $i++) { $this->sf.=""; } for($i=0; $iop_var); $i++) { $this->sf.=""; } for($i=0; $ival_var); $i++) { $this->sf.=""; } $this->sf.=""; $this->sf.=""; $this->sf.=""; } // création de la requête SQL function make_proc() { global $msg; global $current_module; global $base_path; // récupération des champs à afficher if(count($this->print_field)==0) return "erreur"; // gestion de l'erreur a améliorer $champs = array(); for($i=0; $iprint_field); $i++) { if(substr($this->print_field[$i],0,1)=="f") { if($this->list_fields[substr($this->print_field[$i],2)]["TABLE"] == "notices") $latable = "notices"; else $latable = "ta_".$i; $champs[] =$latable.".".$this->list_fields[substr($this->print_field[$i],2)]["CHAMP"]." AS '".addslashes($this->list_fields[substr($this->print_field[0],2)]["TITLE"])."'"; } else { $champs[] ="ncva_".$i.".notices_custom_".$this->pp->t_fields[substr($this->print_field[$i],2)]["DATATYPE"]." AS '".addslashes($this->pp->t_fields[substr($this->print_field[$i],2)]["TITRE"])."'"; } } $liste_champs = implode(", ", $champs); // récupération des tables $tables = array(); $param = array("print_field" => "a", "fixed_params" => "f", "dynamic_params" => "d"); foreach($param as $key => $value) { for($i=0; $i$key); $i++) { if(substr($this->{$key}[$i],0,1)=="f") { // champs du fichier de configuration // table principale if($this->list_fields[substr($this->{$key}[$i],2)]["TABLE"]=="notices") { $tables[]="notices"; } else { $tables[]=$this->list_fields[substr($this->{$key}[$i],2)]["TABLE"]." AS t".$value."_".$i; } // jointures for($j=0; $jlist_fields[substr($this->{$key}[$i],2)]["JOINTURE"]); $j++) { for($k=0; $klist_fields[substr($this->{$key}[$i],2)]["JOINTURE"][$j]["TABLE"]); $k++) { if($this->list_fields[substr($this->{$key}[$i],2)]["JOINTURE"][$j]["TABLE"][$k]["NAME"]=="notices") { $tables[]="notices"; } else if($this->list_fields[substr($this->{$key}[$i],2)]["JOINTURE"][$j]["TABLE"][$k]["NAME"] != $this->list_fields[substr($this->{$key}[$i],2)]["TABLE"]) { $tables[]=$this->list_fields[substr($this->{$key}[$i],2)]["JOINTURE"][$j]["TABLE"][$k]["NAME"]." AS t".$value."_j_".$i; } } } } else { // champs perso $tables[]="notices_custom_values AS ncv".$value."_".$i; } } } // éliminer les doublons $tables = array_unique($tables); $liste_tables = implode(", ", $tables); // construction des clauses $where = ""; // jointures pour les champs a afficher $jointure = array(); for($i=0; $iprint_field); $i++) { if(substr($this->print_field[$i],0,1)=="f") { for($j=0; $jlist_fields[substr($this->print_field[$i],2)]["JOINTURE"]); $j++) { if($this->list_fields[substr($this->print_field[$i],2)]["JOINTURE"][$j]["TABLE"][0]["NAME"] == $this->list_fields[substr($this->print_field[$i],2)]["TABLE"]) $tleft="ta_".$i; else if($this->list_fields[substr($this->print_field[$i],2)]["JOINTURE"][$j]["TABLE"][0]["NAME"] == "notices") $tleft="notices"; else $tleft="ta_j_".$i; if($this->list_fields[substr($this->print_field[$i],2)]["JOINTURE"][$j]["TABLE"][1]["NAME"] == $this->list_fields[substr($this->print_field[$i],2)]["TABLE"]) $tright="ta_".$i; if($this->list_fields[substr($this->print_field[$i],2)]["JOINTURE"][$j]["TABLE"][1]["NAME"] == "notices") $tright="notices"; else $tright="ta_j_".$i; $jointure[] = $tleft.".".$this->list_fields[substr($this->print_field[$i],2)]["JOINTURE"][$j]["TABLE"][0]["ID"][0]["value"]."=".$tright.".".$this->list_fields[substr($this->print_field[$i],2)]["JOINTURE"][$j]["TABLE"][1]["ID"][0]["value"]; } } else { // champs perso $jointure[] = "ncva_".$i.".notices_custom_origine = notices.notice_id"; $jointure[] = "ncva_".$i.".notices_custom_champ = ".substr($this->print_field[$i],2); } } // conditions fixes for($i=0; $ifixed_params); $i++) { if(substr($this->fixed_params[$i],0,1)=="f") { for($j=0; $jlist_fields[substr($this->fixed_params[$i],2)]["JOINTURE"]); $j++) { if($this->list_fields[substr($this->fixed_params[$i],2)]["JOINTURE"][$j]["TABLE"][0]["NAME"] == $this->list_fields[substr($this->fixed_params[$i],2)]["TABLE"]) $tleft="tf_".$i; else if($this->list_fields[substr($this->fixed_params[$i],2)]["JOINTURE"][$j]["TABLE"][0]["NAME"] == "notices") $tleft="notices"; else $tleft="tf_j_".$i; if($this->list_fields[substr($this->fixed_params[$i],2)]["JOINTURE"][$j]["TABLE"][1]["NAME"] == $this->list_fields[substr($this->fixed_params[$i],2)]["TABLE"]) $tright="tf_".$i; if($this->list_fields[substr($this->fixed_params[$i],2)]["JOINTURE"][$j]["TABLE"][1]["NAME"] == "notices") $tright="notices"; else $tright="tf_j_".$i; $jointure[] = $tleft.".".$this->list_fields[substr($this->fixed_params[$i],2)]["JOINTURE"][$j]["TABLE"][0]["ID"][0]["value"]."=".$tright.".".$this->list_fields[substr($this->fixed_params[$i],2)]["JOINTURE"][$j]["TABLE"][1]["ID"][0]["value"]; } if($this->list_fields[substr($this->fixed_params[$i],2)]["TABLE"] == "notices") $tf = "notices"; else $tf = "tf_".$i; switch($this->op_param[$i]) { case "CONTAINS_ALL" : $op=" AND "; $argu = explode(" ",$this->val_param[$i]); for($j=0; $jlist_fields[substr($this->fixed_params[$i],2)]["INDEX"].$this->operateur[$this->op_param[$i]]["DEB"].pmb_strtolower(convert_diacrit($argu[$j])).$this->operateur[$this->op_param[$i]]["FIN"]; } $jointure[] =" (".implode($op,$argu).") "; break; case "CONTAINS_AT_LEAST" : $op=" OR "; $argu = explode(" ",$this->val_param[$i]); for($j=0; $jlist_fields[substr($this->fixed_params[$i],2)]["INDEX"].$this->operateur[$this->op_param[$i]]["DEB"].pmb_strtolower(convert_diacrit($argu[$j])).$this->operateur[$this->op_param[$i]]["FIN"]; } $jointure[] =" (".implode($op,$argu).") "; break; default : $jointure[] = $tf.".".$this->list_fields[substr($this->fixed_params[$i],2)]["INDEX"].$this->operateur[$this->op_param[$i]]["DEB"].pmb_strtolower(convert_diacrit($this->val_param[$i])).$this->operateur[$this->op_param[$i]]["FIN"]; } } else { // champs perso $jointure[] = "ncvf_".$i.".notices_custom_origine = notices.notice_id"; $jointure[] = "ncvf_".$i.".notices_custom_champ = ".substr($this->fixed_params[$i],2); switch($this->op_param[$i]) { case "CONTAINS_ALL" : $op=" AND "; $argu = explode(" ",$this->val_param[$i]); for($j=0; $jpp->t_fields[substr($this->fixed_params[$i],2)]["DATATYPE"].$this->operateur[$this->op_param[$i]]["DEB"].$argu[$j].$this->operateur[$this->op_param[$i]]["FIN"]; } $jointure[] =" (".implode($op,$argu).") "; break; case "CONTAINS_AT_LEAST" : $op=" OR "; $argu = explode(" ",$this->val_param[$i]); for($j=0; $jpp->t_fields[substr($this->fixed_params[$i],2)]["DATATYPE"].$this->operateur[$this->op_param[$i]]["DEB"].$argu[$j].$this->operateur[$this->op_param[$i]]["FIN"]; } $jointure[] =" (".implode($op,$argu).") "; break; default : $jointure[] = "ncvf_".$i.".notices_custom_".$this->pp->t_fields[substr($this->fixed_params[$i],2)]["DATATYPE"].$this->operateur[$this->op_param[$i]]["DEB"].$this->val_param[$i].$this->operateur[$this->op_param[$i]]["FIN"]; } } } // conditions dynamiques for($i=0; $idynamic_params); $i++) { if(substr($this->dynamic_params[$i],0,1)=="f") { for($j=0; $jlist_fields[substr($this->dynamic_params[$i],2)]["JOINTURE"]); $j++) { if($this->list_fields[substr($this->dynamic_params[$i],2)]["JOINTURE"][$j]["TABLE"][0]["NAME"] == $this->list_fields[substr($this->dynamic_params[$i],2)]["TABLE"]) $tleft="td_".$i; else if($this->list_fields[substr($this->dynamic_params[$i],2)]["JOINTURE"][$j]["TABLE"][0]["NAME"] == "notices") $tleft="notices"; else $tleft="td_j_".$i; if($this->list_fields[substr($this->dynamic_params[$i],2)]["JOINTURE"][$j]["TABLE"][1]["NAME"] == $this->list_fields[substr($this->dynamic_params[$i],2)]["TABLE"]) $tright="td_".$i; if($this->list_fields[substr($this->dynamic_params[$i],2)]["JOINTURE"][$j]["TABLE"][1]["NAME"] == "notices") $tright="notices"; else $tright="td_j_".$i; $jointure[] = $tleft.".".$this->list_fields[substr($this->dynamic_params[$i],2)]["JOINTURE"][$j]["TABLE"][0]["ID"][0]["value"]."=".$tright.".".$this->list_fields[substr($this->dynamic_params[$i],2)]["JOINTURE"][$j]["TABLE"][1]["ID"][0]["value"]; } if($this->list_fields[substr($this->dynamic_params[$i],2)]["TABLE"] == "notices") $td = "notices"; else $td = "td_".$i; $jointure[] = $td.".".$this->list_fields[substr($this->dynamic_params[$i],2)]["INDEX"].$this->operateur[$this->op_var[$i]]["DEB"]."!!d_".$i."!!".$this->operateur[$this->op_var[$i]]["FIN"]; } else { // champs perso $jointure[] = "ncvd_".$i.".notices_custom_origine = notices.notice_id"; $jointure[] = "ncvd_".$i.".notices_custom_champ = ".substr($this->dynamic_params[$i],2); $jointure[] = "ncvd_".$i.".notices_custom_".$this->pp->t_fields[substr($this->dynamic_params[$i],2)]["DATATYPE"].$this->operateur[$this->op_var[$i]]["DEB"]."!!d_".$i."!!".$this->operateur[$this->op_var[$i]]["FIN"]; } } $where .= implode(" AND ", $jointure); $requete = html_entity_decode("SELECT ".$liste_champs." FROM ".$liste_tables." WHERE ".$where); $param_var = "\n"; $param_var .= "\n"; for($i=0; $idynamic_params); $i++) { // A améliorer, pour l'instant tout est mis en type text !!! $param_var .= "\n"; $param_var .= " val_var[$i]."]]>\n"; $param_var .= " text\n"; $param_var .= " \n"; $param_var .= " 20\n"; $param_var .= " 20\n"; $param_var .= " \n"; $param_var .= " \n"; } $param_var .= ""; // insertion de la procédure dans la base de données $dbh = connection_mysql(); $req = "INSERT INTO procs (name, requete, comment, autorisations, parameters) VALUES ('".$this->nom_proc."', '".addslashes($requete)."', '".$this->comment."', '".implode(" ",$this->userautorisation)."', '".addslashes($param_var)."')"; $result = mysql_query($req, $dbh); // on n'utilse pas le template prévu pour cette étape $create_proc_form="

".$msg["create_proc"]." (!!etape!!/5)

!!resultat!!
"; if($result) { $resultat = $msg["proc_ok"]; } else { $resultat = $msg["proc_fail"]; } $create_proc_form=str_replace("!!resultat!!",$resultat,$create_proc_form); return $create_proc_form; } function choix_info() { global $msg; global $current_module; global $base_path; // on n'utilse pas le template prévu pour cette étape $create_proc_form="

".$msg["create_proc"]." (!!etape!!/5)

".$msg["warn_create_proc"]."

!!autorisations_users!!
"; // récupération des utilisateurs $dbh = connection_mysql(); $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)) { $autorisation[]=array(0,$all_userid,$all_username); } $autorisations_users=""; while (list($row_number, $row_data) = each($autorisation)) { if ($row_data[0]) $autorisations_users.=" ".$row_data[2]."  "; else $autorisations_users.=" ".$row_data[2]."  "; } $create_proc_form = str_replace('!!autorisations_users!!', $autorisations_users, $create_proc_form); return $create_proc_form; } // Gestion de l'affichage function show_form($url,$url_next, $etape=1) { // $url : url courrante // $url_next : url pour l'étape suivante global $create_proc_form; global $msg; $this->url = $url; $this->url_next = $url_next; $this->etape = $etape; switch($this->etape) { case 1: $create_proc_form = $this->choix_info(); break; case 2: $this->choix_param(); $txtmsg=$msg["choix_param"]; break; case 3: $this->choix_var(); $txtmsg=$msg["choix_var"]; break; case 4: $this->choix_champ(); $txtmsg=$msg["choix_champ"]; break; case 5: $create_proc_form = $this->make_proc(); break; default : $create_proc_form = $this->etape =1; $this->choix_info(); break; } // Modification du template $create_proc_form=str_replace("!!txtmsg!!",$txtmsg,$create_proc_form); $create_proc_form=str_replace("!!field_list!!",$this->r,$create_proc_form); $create_proc_form=str_replace("!!already_selected_fields!!",$this->sf,$create_proc_form); $create_proc_form=str_replace("!!url!!",$this->url,$create_proc_form); $create_proc_form=str_replace("!!url_next!!",$this->url_next,$create_proc_form); $create_proc_form=str_replace("!!etape!!",$this->etape,$create_proc_form); $create_proc_form=str_replace("!!etape_next!!",$this->etape+1,$create_proc_form); return $create_proc_form; } } ?>