"; // 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' or autorisations_all=1) "; else $where=""; $query = "SELECT idproc, type, name, requete, comment, autorisations, autorisations_all FROM ".static::$table." $where ORDER BY type, name "; $result = pmb_mysql_query($query); if($result) { $parity=1; while($row = pmb_mysql_fetch_object($result)) { $autorisations=explode(" ",$row->autorisations); if ($row->autorisations_all || array_search ($PMBuserid, $autorisations)!==FALSE || $PMBuserid == 1) { if ($parity % 2) { $pair_impair = "even"; } else { $pair_impair = "odd"; } $parity += 1; $action=" onmousedown=\"document.location='".static::format_url("&action=modif&id=".$row->idproc)."';\""; $tr_javascript=" onmouseover=\"this.className='surbrillance'\" onmouseout=\"this.className='$pair_impair'\" "; $display .= ""; if ($row->type != "ACTION"){ $display .= " "; if (preg_match_all("|!!(.*)!!|U",$row->requete,$query_parameters)){ $display .= ""; } } } $display .= "
idproc)."'\" />"; }else{ $display .= "  "; } $display .= " ".$row->type." ".$row->name."
".$row->comment." 
".$msg['procs_options_config_param'].""; }else{ $display .= " "; } $display .= " " ; if(static::$module == 'catalog') { $display .= "idproc."'\" />"; } elseif(static::$module == 'circ') { $display .= "idproc."'\" />"; } elseif(static::$module == 'autorites') { $display .= "idproc."'\" />"; } $display .= "

"; return $display; } public static function create() { global $msg; global $f_proc_type; global $f_proc_name; global $f_proc_code; global $f_proc_comment; global $userautorisation; global $autorisations_all; if($f_proc_name && $f_proc_code) { $query = "SELECT count(1) FROM ".static::$table." WHERE name='$f_proc_name' "; $result = pmb_mysql_query($query); $nbr_lignes = pmb_mysql_result($result, 0, 0); if(!$nbr_lignes) { if (is_array($userautorisation)) { $autorisations=implode(" ",$userautorisation); } else { $autorisations=''; } $autorisations_all += 0; $param_name=parameters::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(); } $query = "INSERT INTO ".static::$table." (idproc,type,name,requete,comment,autorisations,autorisations_all) VALUES ('', '$f_proc_type', '$f_proc_name', '$f_proc_code', '$f_proc_comment', '$autorisations', '$autorisations_all' ) "; pmb_mysql_query($query); } else { print ""; print ""; } } } public static function update($id) { global $msg; global $f_proc_name; global $f_proc_code; global $f_proc_comment; global $userautorisation; global $autorisations_all; $id += 0; if($id) { if (is_array($userautorisation)) { $autorisations=implode(" ",$userautorisation); } else { $autorisations=""; } $autorisations_all += 0; $param_name=parameters::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(); } $query = "UPDATE ".static::$table." SET name='$f_proc_name',requete='$f_proc_code',comment='$f_proc_comment' , autorisations='$autorisations' , autorisations_all='$autorisations_all' WHERE idproc=$id "; pmb_mysql_query($query); return true; } return false; } public static function get_proc_form($id=0) { global $base_path, $msg; global $cart_procs_form; global $charset; global $PMBuserid; $id += 0; $form = $cart_procs_form; switch (static::$table) { case 'empr_caddie_procs': $example_code = $msg['cart_ex_selection']." select id_empr as object_id from empr where ...
".$msg['cart_ex_action']." update empr set empr_statut=!!nouveau_statut!! where id_empr in (CADDIE(EMPR))"; break; case 'authorities_caddie_procs': $example_code = $msg['cart_ex_selection']." select id_authority as object_id, 'AUTHORS' as object_type from authorities JOIN authors ON author_id=authorities.num_object and authorities.type_object = 1 where ...
".$msg['cart_ex_action']." update authorities set num_statut=!!nouveau_statut!! where id_authority in (CADDIE(AUTHORS))
MIXED / AUTHORS / CATEGORIES / PUBLISHERS / COLLECTIONS / SUBCOLLECTIONS / SERIES / TITRES_UNIFORMES / INDEXINT / AUTHPERSO"; break; case 'caddie_procs': default: $example_code = $msg['cart_ex_selection']." select notice_id as object_id, 'NOTI' as object_type from notices where ...
'NOTI' / 'EXPL' / 'BULL'
".$msg['cart_ex_action']." update exemplaires set expl_statut=!!nouveau_statut!! where expl_id in (CADDIE(EXPL))
EXPL / NOTI / BULL"; break; } $form = str_replace('!!example_code!!', $example_code, $form); $form = str_replace('!!cancel_link!!', static::format_url(), $form); $autorisations = array(); $autorisations_all = 0; if($id) { $query = "SELECT idproc, name, requete, comment, autorisations, autorisations_all, type FROM ".static::$table." WHERE idproc=".$id; $result = pmb_mysql_query($query); if(pmb_mysql_num_rows($result)) { $row = pmb_mysql_fetch_object($result); $autorisations_donnees=explode(" ",$row->autorisations); $autorisations_all = $row->autorisations_all; $query_users = "SELECT userid, username FROM users order by username "; $result_users = pmb_mysql_query($query_users); $all_users=array(); while (list($all_userid,$all_username)=pmb_mysql_fetch_row($result_users)) { $all_users[]=array($all_userid,$all_username); } for ($i=0 ; $itype != "ACTION") { $form=str_replace("!!exec_button!!"," ",$form); } else { $form=str_replace("!!exec_button!!","",$form); } $form = str_replace('!!form_title!!', $msg["procs_modification"], $form); $form = str_replace('!!action!!', static::format_url("&action=modif&id=".$id), $form); $form = str_replace('!!type!!', htmlentities($msg["caddie_procs_type_".$row->type],ENT_QUOTES, $charset), $form); $form = str_replace('!!name!!', htmlentities($row->name,ENT_QUOTES, $charset), $form); $form = str_replace('!!code!!', htmlentities($row->requete,ENT_QUOTES, $charset), $form); $form = str_replace('!!comment!!', htmlentities($row->comment,ENT_QUOTES, $charset), $form); $button_delete = "name), ENT_QUOTES, $charset)."')\" />"; $form=str_replace("!!button_delete!!",$button_delete,$form); } } else { $query_users = "SELECT userid, username FROM users order by username "; $result_users = pmb_mysql_query($query_users); $all_users=array(); while (list($all_userid,$all_username)=pmb_mysql_fetch_row($result_users)) { $autorise = 0; //On autorise l'utilisateur courant par défaut if ($all_userid == $PMBuserid) { $autorise = 1; } $autorisations[]=array($autorise, $all_userid,$all_username); } $form=str_replace("!!exec_button!!","",$form); $form = str_replace('!!form_title!!', $msg[704], $form); $form = str_replace('!!action!!', static::format_url("&action=add"), $form); $type_select = ""; $form = str_replace('!!type!!', $type_select, $form); $form = str_replace('!!name!!', '', $form); $form = str_replace('!!code!!', '', $form); $form = str_replace('!!comment!!', '', $form); $form=str_replace("!!button_delete!!","",$form); } $form = str_replace('!!id!!', $id, $form); $autorisations_users=""; $id_check_list=''; foreach ($autorisations as $row_number => $row_data) { $id_check="auto_".$row_data[1]; if($id_check_list)$id_check_list.='|'; $id_check_list.=$id_check; if ($row_data[0]) $autorisations_users.="  "; else $autorisations_users.="  "; } $autorisations_users.=""; $form = str_replace('!!autorisations_users!!', $autorisations_users, $form); $form = str_replace('!!autorisations_all!!', ($autorisations_all ? "checked='checked'" : ""), $form); $form .= confirmation_delete(static::format_url("&action=del&id=")); return $form; } public static function get_form_after_execution($id, $name, $code, $commentaire, $is_external = false) { global $msg; $form = ''; if (!$is_external) { $form .= "

$msg[procs_execute] \" $name \"  


$name : $commentaire
"; } else { $form .= "

".$msg["remote_procedures_executing"]." $name


$commentaire


"; } return $form; } // affichage du tableau des procédures public static function get_display_list_from_caddie($idcaddie, $args_url = 'categ=&sub=&quelle=', $type='ACTION', $action = "add_item") { global $msg,$charset; global $PMBuserid; $display = "
".$msg['caddie_select_proc']."
"; if ($PMBuserid!=1) $where=" and (autorisations='$PMBuserid' or autorisations like '$PMBuserid %' or autorisations like '% $PMBuserid %' or autorisations like '% $PMBuserid') "; else $where=""; $query = "SELECT idproc, type, name, requete, comment, autorisations, autorisations_all, parameters FROM ".static::$table." WHERE type='".$type."' $where ORDER BY name "; $result = pmb_mysql_query($query); $n_proc=0; if($result) { $parity=1; while($row = pmb_mysql_fetch_object($result)) { $autorisations=explode(" ",$row->autorisations); if (($row->autorisations_all || array_search ($PMBuserid, $autorisations)!==FALSE || $PMBuserid == 1)&&($type != 'ACTION' || static::is_for_cart($idcaddie, $row->requete))) { $n_proc++; if ($parity % 2) { $pair_impair = "even"; } else { $pair_impair = "odd"; } $parity += 1; if (preg_match_all("|!!(.*)!!|U",$row->requete,$query_parameters)) { $action = "form_proc" ; } // else $action = "add_item" ; if(static::$module == 'circ') { $link_suffix = "&idemprcaddie=".$idcaddie; } else { $link_suffix = "&idcaddie=".$idcaddie; } switch ($type) { case 'ACTION': $onmousedown = "if (confirm('".addslashes(str_replace("\"",""",sprintf($msg["caddie_action_proc_confirm"],$row->name)))."')) { url='./".static::$module.".php?".$args_url."&action=$action&id=".$row->idproc.$link_suffix."'; if (document.maj_proc.elt_flag.checked) url+='&elt_flag='+document.maj_proc.elt_flag.value; if (document.maj_proc.elt_no_flag.checked) url+='&elt_no_flag='+document.maj_proc.elt_no_flag.value; document.location=url; }"; break; case 'SELECT': $onmousedown = "document.location='./".static::$module.".php?".$args_url."&action=$action&id=".$row->idproc.$link_suffix."';"; break; } $tr_javascript=" onmouseover=\"this.className='surbrillance'\" onmouseout=\"this.className='$pair_impair'\" onmousedown=\"".$onmousedown."\" "; $display .= ""; } } } $display .= "
".htmlentities($row->name,ENT_QUOTES,$charset)."
".htmlentities($row->comment,ENT_QUOTES,$charset)." 
"; if ($n_proc==0) { switch ($type) { case 'ACTION': $display .= $msg["caddie_no_action_proc"]; break; case 'SELECT': $display .= $msg["caddie_no_select_proc"]; break; } } return $display; } public static function is_for_cart($idcaddie, $requete) { if (preg_match("/CADDIE\(([^\)]*)\)/",$requete,$match)) { $m=explode(",",$match[1]); if(static::$table == 'empr_caddie_procs') { $myCart = empr_caddie_controller::get_object_instance($idcaddie); } elseif(static::$table == 'authorities_caddie_procs') { $myCart = authorities_caddie_controller::get_object_instance($idcaddie); } else { $myCart = caddie_controller::get_object_instance($idcaddie); } $as=array_search($myCart->type,$m); if (($as!==NULL)&&($as!==false)) return true; else return false; } else return false; } public static function check_rights($id) { global $msg; global $PMBuserid; if ($id) { $requete = "SELECT autorisations, autorisations_all FROM ".static::$table." WHERE idproc='$id' "; $result = @pmb_mysql_query($requete); if(pmb_mysql_num_rows($result)) { $temp = pmb_mysql_fetch_object($result); if($temp->autorisations_all) return 1; $rqt_autorisation=explode(" ",$temp->autorisations); if (array_search ($PMBuserid, $rqt_autorisation)!==FALSE || $PMBuserid == 1) return 1 ; } } return 0 ; } 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; 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); print static::get_display_list(); } else { // afficher le form avec les bonnes valeurs print static::get_proc_form($id); } } else { print static::get_display_list(); } break; case 'add': if($f_proc_name && $f_proc_code) { static::create(); print static::get_display_list(); } else { print static::get_proc_form(); } break; case 'import': $import_proc_tmpl = str_replace("!!action!!", static::format_url("&action=importsuite"), $import_proc_tmpl); print $import_proc_tmpl ; break; case 'importsuite': static::importsuite(static::format_url("&action=modif&id=!!id!!"), static::format_url("&action=import")); break; case 'del': if($id) { static::delete($id); } print static::get_display_list(); break; default: print static::get_display_list(); break; } } public static function final_execute() { global $msg; global $id_query; global $query_parameters; global $execute_external; global $id; global $execute_external_procedure; global $PMBuserid; 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 (is_object($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 = ''; } if ($PMBuserid!=1) { $where=" and (autorisations='$PMBuserid' or autorisations like '$PMBuserid %' or autorisations like '% $PMBuserid %' or autorisations like '% $PMBuserid') "; } else { $where=""; } $requete = "SELECT idproc, name, requete, comment FROM ".static::$table." WHERE idproc=$id $where "; $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) { print "
"; print $param_proc_hidden; if($force_exec){ print "";//On a forcé la requete } print static::get_form_after_execution($idp, $name, $code, $commentaire, $is_external); // récupération du résultat $report = static::run_query($code); if($report['state'] == false && $report['message'] == 'explain_failed') { static::final_explain_failed($id); } print "
"; } else { print $msg["proc_param_query_failed"]; } } public static function get_parameters_remote() { //utilisées dans la classe remote_procedure en globale pour le module catalog global $allowed_proc_types; global $types_selectaction; global $testable_types; global $type_titles; $allowed_proc_types = array("PNS", "PNA", "PES", "PEA", "PBS", "PBA"); $types_selectaction = array("PNS" => "SELECT", "PNA" => 'ACTION', "PEA" => 'ACTION', "PES" => "SELECT", "PBS" => "SELECT", "PBA" => 'ACTION'); $testable_types = array("PNS" => true, "PNA" => false, "PEA" => false, "PES" => true, "PBS" => true, "PBA" => false); $type_titles = array("PNS" => "remote_procedures_catalog_caddienotice_select", "PNA" => "remote_procedures_catalog_caddienotice_action", "PEA" => "remote_procedures_catalog_caddieexpl_action", "PES" => "remote_procedures_catalog_caddieexpl_select", "PBS" => "remote_procedures_catalog_caddiebull_select", "PBA" => "remote_procedures_catalog_caddiebull_action"); 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="") { global $pmb_procedure_server_credentials, $pmb_procedure_server_address; global $msg; global $charset; $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) { $parameters_remote = static::get_parameters_remote(); if ($procedures->error_information->error_code) { $buf_contenu=$msg["remote_procedures_error_server"].":
".$procedures->error_information->error_string.""; print $buf_contenu; } else if (isset($procedures->elements)) { $current_set=""; $buf_contenu=""; foreach ($procedures->elements as $aprocedure) { if ($aprocedure->current_attached_set != $current_set) { $parity=0; $current_set = $aprocedure->current_attached_set; $buf_contenu .= ''.htmlentities($current_set, ENT_QUOTES, $charset).''; } 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='./".static::$module.".php?categ=caddie&sub=gestion&quoi=remote_procs&action=view_remote&id=$aprocedure->id&remote_type=$type';\" "; $buf_contenu.="\n ".($parameters_remote['testable_types'][$type] ? "id&remote_type=$type'\" />" : "")." ".($aprocedure->untested ? "[".$msg["remote_procedures_procedure_non_validated"]."]  " : '')."$aprocedure->name
$aprocedure->comment  "; $buf_contenu.="id&remote_type=$type'\" /> "; } $title = $msg[$parameters_remote['type_titles'][$type]]; $buf_contenu="

".$title."

"."".$buf_contenu."

"; print $buf_contenu; } else { $title = $msg[$parameters_remote['type_titles'][$type]]; $buf_contenu="

".$title."

".$msg['remote_procedures_no_procs']."

"; print $buf_contenu; } } } } public static function get_display_remote_lists() { static::get_display_remote_list("PNS"); static::get_display_remote_list("PNA"); static::get_display_remote_list("PES"); static::get_display_remote_list("PEA"); static::get_display_remote_list("PBS"); static::get_display_remote_list("PBA"); } public static function format_url($url='') { global $base_path; return $base_path."/".static::$module.".php?categ=caddie&sub=gestion&quoi=procs".$url; } }