".htmlentities($commentaire, ENT_QUOTES, $charset)." ";
}
return $form;
}
public static function run_query($query_code) {
global $msg;
global $pmb_procs_force_execution;
global $force_exec, $PMBuserid;
global $urlbase;
global $erreur_explain_rqt;
global $sortfield;
$linetemp = explode(";", $query_code);
for ($i=0;$i $valeur) {
if($valeur) {
// traitement tri des colonnes
if ($sortfield != "") {
// on cherche à trier sur le champ $trifield
// compose la chaîne de tri
$tri = $sortfield;
if ($desc == 1) $tri .= " DESC";
else $tri .= " ASC";
// on enlève les doubles espaces dans la procédure
$valeur = preg_replace("/\s+/", " ", $valeur);
// supprime un éventuel ; à la fin de la requête
$valeur = preg_replace("/;$/", "", $valeur);
// on recherche la première occurence de ORDER BY
$s = stristr($valeur, "order by");
if ($s) {
// y'a déjà une clause order by... moins facile...
// il faut qu'on sache si on aura besoin de mettre une virgule ou pas
if ( preg_match("#,#", $s) ) {
$virgule = true;
} else if ( ! preg_match("${sortfield}", $s)) {
$virgule = true;
} else {
$virgule = false;
}
if ($virgule) {
$tri .= ", ";
}
// regarde si le champ est déjà dans la liste des champs à trier et le remplace si besoin
$new_s = preg_replace("/$sortfield, /", "", $s);
$new_s = preg_replace("/$sortfield/", "", $new_s);
// ajoute la clause order by correcte
$new_s = preg_replace("/order\s+by\s+/i", "order by $tri", $new_s);
// replace l'ancienne chaîne par la nouvelle
$valeur = str_replace($s, $new_s, $valeur);
} else {
$valeur .= " order by $tri";
}
}
print "".$msg['procs_ligne']." ".$cle." : ".$valeur."
";
}
return array('state' => true, 'message' => '');
}
public static function proceed() {
global $msg;
global $action;
global $id_query;
global $id;
global $f_proc_name;
global $f_proc_code;
global $import_proc_tmpl;
global $num_classement;
print "
";
switch($action) {
case 'configure':
$hp=new parameters($id_query,static::$table);
$hp->show_config_screen(static::format_url("&action=update_config"),static::format_url());
break;
case 'update_config':
$hp=new parameters($id_query,static::$table);
$hp->update_config(static::format_url());
break;
case 'final':
static::final_execute();
break;
case 'execute':
// form pour params et validation
static::run_form($id);
break;
case 'modif':
if($id) {
if($f_proc_name && $f_proc_code) {
// faire la modification
static::update($id);
show_procs();
} else {
// afficher le form avec les bonnes valeurs
print static::get_proc_form($id);
}
} else {
show_procs();
}
break;
case 'add':
if($f_proc_name && $f_proc_code) {
static::create();
show_procs();
} else {
print static::get_proc_form();
}
break;
case 'update':
if($f_proc_name && $f_proc_code) {
if($id) {
// faire la modification
static::update($id);
} else {
static::create();
}
show_procs();
}
break;
case 'import':
$import_proc_tmpl = str_replace("!!action!!", static::format_url("&action=importsuite".(!empty($num_classement) ? "&num_classement=".$num_classement : "")), $import_proc_tmpl);
print $import_proc_tmpl ;
break;
case 'importsuite':
static::importsuite(static::format_url("&action=modif&id=!!id!!"), static::format_url("&action=importsuite")) ;
break;
case 'del':
if($id) {
static::delete($id);
static::optimize();
}
show_procs();
break;
default:
show_procs();
break;
}
}
public static function proceed_remote() {
global $msg;
global $action;
global $do_import;
global $id;
global $pmb_procedure_server_address;
switch($action) {
case 'view_remote':
if ($id) {
$remote_procedure = new remote_procedure($id, static::$module, static::$table);
$remote_procedure->display();
}
break;
case 'import_remote':
if ($id) {
if($do_import) {
$remote_procedure = new remote_procedure($id, static::$module, static::$table);
$remote_procedure->import();
if(static::class == 'procs') {
show_procs();
} else {
static::get_display_remote_lists();
}
} else {
$remote_procedure = new remote_procedure($id, static::$module, static::$table);
print $remote_procedure->get_import_form();
}
}
break;
case 'execute_remote':
if ($id) {
$remote_procedure = new remote_procedure($id, static::$module, static::$table);
$remote_procedure->execute();
}
break;
case 'final_remote':
if ($id) {
$remote_procedure = new remote_procedure($id, static::$module, static::$table);
$remote_procedure->final_execution();
//$execute_external <=> globale dans remote_procedure->final_execution
//$execute_external_procedure <=> globale dans remote_procedure->final_execution
//$param_proc_hidden <=> paramêtres en champ caché en cas de forçage
static::final_execute();
}
break;
default:
if (!$pmb_procedure_server_address) {
echo $msg["remote_procedures_error_noaddress"];
break;
}
if(static::class == 'procs') {
show_procs();
} else {
static::get_display_remote_lists();
}
break;
}
}
public static function importsuite($retour, $retour_erreur) {
global $msg, $current_module, $charset;
global $PMBuserid, $num_classement;
print "
".$msg['procs_title_form_import']."
";
$erreur=0;
$userfile_name = $_FILES['f_fichier']['name'];
$userfile_temp = $_FILES['f_fichier']['tmp_name'];
$userfile_moved = basename($userfile_temp);
$userfile_name = preg_replace("/ |'|\\|\"|\//m", "_", $userfile_name);
// création
if (move_uploaded_file($userfile_temp,'./temp/'.$userfile_moved)) {
$fic=1;
}
if (!$fic) {
$erreur=$erreur+10;
}
if ($fic) {
$fp = fopen('./temp/'.$userfile_moved , "r" );
$contenu = fread ($fp, filesize('./temp/'.$userfile_moved));
if (!$fp || $contenu=="") $erreur=$erreur+100; ;
fclose ($fp) ;
}
//import avec encodage taggé
if(strpos($contenu,'#charset=iso-8859-1')!==false && $charset=='utf-8'){
//mise à jour de l'encodage du contenu
$contenu = utf8_encode($contenu);
//mise à jour de l'entête des paramètres
$contenu = str_replace('', '', $contenu) ;
}elseif(strpos($contenu,'#charset=utf-8')!==false && $charset=='iso-8859-1'){
//mise à jour de l'encodage du contenu
$contenu = utf8_decode($contenu);
//mise à jour de l'entête des paramètres
$contenu = str_replace('', '', $contenu) ;
}
if ($userfile_name) {
unlink('./temp/'.$userfile_moved);
}
$pos = strpos($contenu,'INSERT INTO '.static::$table.' set ');
if (($pos === false) || ($pos>0)) {
$erreur=$erreur+1000; ;
}
if (!$erreur) {
// ajouter les droits pour celui qui importe
if ($PMBuserid!=1) $contenu = str_replace("autorisations='1'", "autorisations='1 ".$PMBuserid."'", $contenu) ;
pmb_mysql_query($contenu) ;
if (pmb_mysql_error()) {
echo pmb_mysql_error()."
".htmlentities($contenu,ENT_QUOTES, $charset)."
" ;
die ();
}
$new_proc_id = pmb_mysql_insert_id();
//on importe au sein d'un classement
$num_classement = intval($num_classement);
if($num_classement) {
pmb_mysql_query('UPDATE '.static::$table.' SET num_classement = "'.$num_classement.'" WHERE idproc = '.$new_proc_id);
}
$retour = str_replace("!!id!!",$new_proc_id,$retour);
print "";
print "";
} else {
print "
".$msg['procs_import_invalide']."
";
}
print "
";
}
public static function final_execute() {
global $msg, $charset;
global $id_query;
global $query_parameters;
global $execute_external;
global $id;
global $execute_external_procedure;
global $force_exec;
global $current_module;
$is_external = isset($execute_external) && $execute_external;
if ($is_external) {
$nbr_lignes = 1;
$idp = $id;
$name = $execute_external_procedure->name;
$code = $execute_external_procedure->sql;
$commentaire = $execute_external_procedure->comment;
} else {
if(!$id_query) $id_query = 0;
$hp=new parameters($id_query,static::$table);
$param_proc_hidden="";
if (isset($hp->proc) && preg_match_all("|!!(.*)!!|U",$hp->proc->requete,$query_parameters)) {
$hp->get_final_query();
$code=$hp->final_query;
$id=$id_query;
$param_proc_hidden=$hp->get_hidden_values();//Je mets les paramêtres en champ caché en cas de forçage
$param_proc_hidden.="";
} else {
$code = '';
}
$requete = "SELECT * FROM ".static::$table." WHERE idproc=$id ";
$res = pmb_mysql_query($requete);
$nbr_lignes = pmb_mysql_num_rows($res);
if($nbr_lignes) {
$row = pmb_mysql_fetch_object($res);
$idp = $row->idproc;
$name = $row->name;
if (!$code) $code = $row->requete;
$commentaire = $row->comment;
}
$urlbase = static::format_url("&action=final&id=$id");
}
if($nbr_lignes) {
// récupération du résultat
print "";
} else {
print $msg["proc_param_query_failed"];
}
}
public static function final_explain_failed($id) {
global $msg;
global $execute_external;
global $pmb_procs_force_execution;
global $PMBuserid;
if ($pmb_procs_force_execution || ($PMBuserid == 1)) {
$is_external = isset($execute_external) && $execute_external;
if(!$is_external){
$lien_force= static::format_url("&action=final&id=".$id."&force_exec=1");
}else{
$lien_force= static::format_url("&action=final_remote&id=".$id."&force_exec=1");
}
print "
";
}
}
public static function get_parameters_remote() {
$allowed_proc_types = array("AP");
$types_selectaction = array(
"AP" => '');
$testable_types = array(
"AP" => true
);
$type_titles = array(
"AP" => "remote_procedures"
);
return array(
'allowed_proc_types' => $allowed_proc_types,
'types_selectaction' => $types_selectaction,
'testable_types' => $testable_types,
'type_titles' => $type_titles
);
}
public static function get_display_remote_list($type="AP") {
global $pmb_procedure_server_credentials, $pmb_procedure_server_address;
global $msg;
global $charset;
$display = '';
$pmb_procedure_server_credentials_exploded = explode("\n", $pmb_procedure_server_credentials);
if ($pmb_procedure_server_address && (count($pmb_procedure_server_credentials_exploded) == 2)) {
$aremote_procedure_client = new remote_procedure_client($pmb_procedure_server_address, trim($pmb_procedure_server_credentials_exploded[0]), trim($pmb_procedure_server_credentials_exploded[1]));
$procedures = $aremote_procedure_client->get_procs($type);
if ($procedures) {
$buf_contenu="";
if ($procedures->error_information->error_code) {
$buf_contenu=$msg['remote_procedures_error_server'].": ".$procedures->error_information->error_string."";
$display .= gen_plus("procclass_remote",$msg["remote_procedures"],$buf_contenu);
} else if (isset($procedures->elements)){
$current_set="";
foreach ($procedures->elements as $aprocedure) {
if ($aprocedure->current_attached_set != $current_set) {
$parity=0;
$current_set = $aprocedure->current_attached_set;
$buf_contenu .= '
";
$display .= gen_plus("procclass_remote",$msg["remote_procedures"],$buf_contenu);
}
}
}
print $display;
}
public static function get_display_remote_lists() {
static::get_display_remote_list();
}
public static function format_url($url='') {
global $base_path;
return $base_path."/".static::$module.".php?categ=proc&sub=proc".$url;
}
public static function get_name($id) {
$query = "SELECT name FROM ".static::$table." WHERE idproc=".$id;
$result = pmb_mysql_query($query);
return pmb_mysql_result($result, 0, 0);
}
}