$row->idproc,
'name' => utf8_normalize($row->name),
'requete' => utf8_normalize($row->requete),
'comment' => utf8_normalize($row->comment),
);
}
return $result;
} else {
return array();
}
}
/*
*
*/
public function executeProc($procedure, $idProc, $tparams) {
global $msg,$dbh, $charset, $PMBuserid;
global $pmb_procedure_server_credentials,$pmb_procedure_server_address;
if (SESSrights & ADMINISTRATION_AUTH) {
$name = '';
$report = '';
if ($tparams['envt']) {
foreach ($tparams['envt'] as $aparam=>$vparam) {
global ${$aparam};
${$aparam} = $vparam;
}
}
switch ($procedure) {
case INTERNAL:
$hp=new parameters($idProc,'procs');
$hp->get_final_query();
$code_sql=$hp->final_query;
$autorisations = $hp->proc->autorisations;
break;
case EXTERNAL:
$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]));
$procedure = $aremote_procedure_client->get_proc($idProc,"AP");
$the_procedure = $procedure['procedure'];
if ($procedure['error_message']) {
$report = htmlentities($msg['remote_procedures_error_server'], ENT_QUOTES, $charset).':
'.$procedure['error_message'].'';
$result = array(
'name' => utf8_normalize($the_procedure->name),
'report' => utf8_normalize($report)
);
return $result;
} else if ($the_procedure->params && ($the_procedure->params != 'NULL')) {
$sql = 'CREATE TEMPORARY TABLE remote_proc LIKE procs';
pmb_mysql_query($sql, $dbh) or die(pmb_mysql_error());
$sql = "INSERT INTO remote_proc (idproc, name, requete, comment, autorisations, parameters, num_classement) VALUES (0, '".pmb_mysql_escape_string($the_procedure->name)."', '".pmb_mysql_escape_string($the_procedure->sql)."', '".pmb_mysql_escape_string($the_procedure->comment)."', '', '".pmb_mysql_escape_string($the_procedure->params)."', 0)";
pmb_mysql_query($sql, $dbh) or die(pmb_mysql_error());
$idproc = pmb_mysql_insert_id($dbh);
$hp=new parameters($idproc,'remote_proc');
$hp->get_final_query();
$the_procedure->sql = $hp->final_query;
$name = $the_procedure->name;
$code_sql = $the_procedure->sql;
$commentaire = $the_procedure->comment;
}
}
break;
}
$linetemp = explode(';', $code_sql);
if($autorisations) {
$temp_autorisation = explode(' ', $autorisations);
}
$allow=false;
if ($temp_autorisation) {
foreach ($temp_autorisation as $userid) {
if ($userid == $PMBuserid) {
$allow = true;
}
}
if (!$allow) {
$report = $msg[11];
// throw new Exception($message, $code);
$result = array(
'name' => utf8_normalize($name),
'report' => utf8_normalize($report)
);
return $result;
}
}
$line=array();
for ($i=0;$i $valeur) {
if($valeur) {
$report .= "".$msg['procs_ligne']." $cle : $valeur
";
$er=explain_requete($valeur);
if ($er) {
$res = @pmb_mysql_query($valeur, $dbh);
$report .= pmb_mysql_error();
$nbr_lignes = @pmb_mysql_num_rows($res);
$nbr_champs = @pmb_mysql_num_fields($res);
if($nbr_lignes) {
$report .= "";
for($i=0; $i < $nbr_champs; $i++) {
$fieldname = pmb_mysql_field_name($res, $i);
$report .= "".$fieldname." | ";
}
for($i=0; $i < $nbr_lignes; $i++) {
$row = pmb_mysql_fetch_row($res);
$report .= "";
foreach($row as $dummykey=>$col) {
if(trim($col)=='') $col = ' ';
$report .= ''.$col.' | ';
}
$report .= "
";
}
$report .= "
";
$report .= "".$msg['admin_misc_lignes']." ".pmb_mysql_affected_rows($dbh)."";
} else {
$report .= "
".$msg['admin_misc_lignes']." ".pmb_mysql_affected_rows($dbh);
$err = pmb_mysql_error($dbh);
if ($err) $report .= "
$err";
$report .= "
";
}
} else {
// erreur explain_requete
$report .= $valeur."
".$msg['proc_param_explain_failed']."
".$erreur_explain_rqt;
}
}
} // fin while
//Export CSV sur le resultat de la derniere requete
if ($er && $nbr_lignes && $tparams['tocsv']['checked']=='1' && $tparams['tocsv']['filepath']) {
if(!$tparams['tocsv']['sep']) {
$tparams['tocsv']['sep']=',';
}
$trow=array();
if($tparams['tocsv']['enclosure']) {
for($i=0; $i < $nbr_champs; $i++) {
$trow[] = addcslashes(pmb_mysql_field_name($res, $i),$tparams['tocsv']['enclosure']);
}
$row = $tparams['tocsv']['enclosure'].implode($tparams['tocsv']['enclosure'].$tparams['tocsv']['sep'].$tparams['tocsv']['enclosure'],$trow).$tparams['tocsv']['enclosure']."\r\n";
} else {
$row = implode($tparams['tocsv']['sep'],$trow)."\r\n";
}
file_put_contents($tparams['tocsv']['filepath'], $row);
pmb_mysql_data_seek($res, 0);
for($i=0; $i < $nbr_lignes; $i++) {
$trow = pmb_mysql_fetch_row($res);
if($tparams['tocsv']['enclosure']) {
foreach($trow as $k=>$v){
$trow[$k]=addcslashes($v,$tparams['tocsv']['enclosure']);
}
$row = $tparams['tocsv']['enclosure'].implode($tparams['tocsv']['enclosure'].$tparams['tocsv']['sep'].$tparams['tocsv']['enclosure'],$trow).$tparams['tocsv']['enclosure']."\r\n";
} else {
$row = implode($tparams['tocsv']['sep'],$trow)."\r\n";
}
file_put_contents($tparams['tocsv']['filepath'], $row, FILE_APPEND);
}
}
$result = array(
'name' => utf8_normalize($name),
'report' => utf8_normalize($report)
);
return $result;
}
return array();
}
}