action = $act; $this->section = $section; } /** * Execution des différentes actions */ function proceed(){ global $msg, $id_col, $col_name, $expr_col, $expr_filtre, $view_name, $view_comment, $id_view; global $id, $id_req, $move, $conso, $date_deb,$date_fin,$date_ech, $list_ck,$remove_data; if($id) $id_req=$id; switch($this->section){ case 'view_list': switch($this->action){ case 'save_view': //Enregistrement/Insertion d'une vue $this->save_view($id_view,$view_name,$view_comment); print $this->do_form(); break; case 'suppr_view': //Suppression d'une vue $this->delete_view($id_view); print $this->do_form(); break; case 'consolide_view': if($date_deb>$date_fin) error_form_message($msg['stat_wrong_date_interval']); elseif(!$list_ck) error_form_message($msg['stat_no_view_selected']); else { $consolidation = new consolidation($conso,$date_deb,$date_fin,$date_ech, $list_ck,$remove_data); $consolidation->make_consolidation(); } print $this->do_form(); break; case 'reinit': //Réinitialisation de la vue $this->reinitialiser_view($id_view); print $this->do_form(); break; //Actions liées aux requêtes case 'configure': case 'update_config': case 'update_request': case 'exec_req': case 'final': //Actions liées aux requêtes $stq = new stat_query($id_req,$this->action,$id_view); $stq->proceed(); break; case 'save_request': case 'suppr_request': $stq = new stat_query($id_req,$this->action,$id_view); $stq->proceed(); print $this->do_form(); break; default: print $this->do_form(); break; } break; case 'view_gestion': switch($this->action){ case 'add_view': //ajout d'une vue //print $this->do_addview_form(); break; case 'update_view': //MaJ vue switch($move){ case 'up': //Déplacer un élément dans la liste des colonnes $this->monter_element($id_col); break; case 'down': //Déplacer un élément dans la liste des colonnes $this->descendre_element($id_col); break; } break; case 'save_col': //Enregistrement/Insertion d'une colonne $this->save_col($id_col,$col_name,$expr_col,$expr_filtre,$id_view); break; case 'suppr_col': //Suppression d'une colonne $this->delete_col($id_col); break; } print $this->do_addview_form($id_view); break; case 'colonne': switch($this->action){ case 'add_col': //ajout d'une colonne print $this->do_col_form(); break; case 'save_col': //Enregistrement/Insertion d'une colonne $this->save_col($id_col,$col_name,$expr_col,$expr_filtre,$id_view); print $this->do_addview_form($id_view); break; case 'update_col': //MaJ colonne print $this->do_col_form($id_col); break; case 'suppr_col': //Suppression d'une colonne $this->delete_col($id_col); print $this->do_addview_form($id_view); break; } break; case 'query': //Actions liées aux requêtes $stq = new stat_query($id_req,$this->action,$id_view); $stq->proceed(); break; default: break; } } /** * On fait appel au formulaire qui affiche la liste des vues */ function do_form(){ global $stat_opac_view_form, $msg; global $msg, $dbh; global $charset; global $javascript_path; print " "; $requete_vue = "select * from statopac_vues order by date_consolidation desc"; $res = mysql_query($requete_vue,$dbh); $vue_affichage=""; if(mysql_num_rows($res) == 0){ $stat_opac_view_form = str_replace('!!liste_vues!!',$msg['stat_no_view_created'],$stat_opac_view_form); $stat_opac_view_form = str_replace('!!options_conso!!','',$stat_opac_view_form); $stat_opac_view_form = str_replace('!!btn_consolide!!','',$stat_opac_view_form); return $stat_opac_view_form; } else { $vue_affichage=""; $parity=1; $btn_consolide= ""; while(($vue = mysql_fetch_object($res))){ $min_date=''; $max_date=''; $view_scope = htmlentities($msg['stat_view_no_scope'],ENT_QUOTES,$charset); $min_date=$vue->date_debut_log; $max_date=$vue->date_fin_log; if ($min_date!='0000-00-00 00:00:00' && $max_date!='0000-00-00 00:00:00') { $view_scope = sprintf(htmlentities($msg['stat_view_scope'],ENT_QUOTES,$charset),formatdate($min_date),formatdate($max_date)); } $rqt="select * from statopac_request where num_vue='".addslashes($vue->id_vue)."' order by name"; $result = mysql_query($rqt); $liste_requete =""; while(($request = mysql_fetch_object($result))){ if ($parity % 2) { $pair_impair = "even"; } else { $pair_impair = "odd"; } $parity++; $tr_javascript=" onmouseover=\"this.className='surbrillance'\" onmouseout=\"this.className='$pair_impair'\" "; $td_action = " onmousedown=\"document.location='./admin.php?categ=opac&sub=stat§ion=query&act=update_request&id_req=$request->idproc&id_view=$vue->id_vue';\" "; $btn_exec = ""; $liste_requete.=" $btn_exec $request->name
$request->comment "; if (preg_match_all("|!!(.*)!!|U",$request->requete,$query_parameters)) $liste_requete.="".$msg["procs_options_config_param"].""; $liste_requete.=""; } $tab_list="".$liste_requete."
".htmlentities($vue->nom_vue,ENT_QUOTES, $charset)."
"; $lien = "".htmlentities($vue->nom_vue,ENT_QUOTES, $charset) .""; $space = ""; $checkbox = ""; $btn = "
id_vue';\" />
"; $date_conso=''; if ($vue->date_consolidation!=='0000-00-00 00:00:00') { $date_conso = sprintf($msg['stat_view_date_conso'],formatdate($vue->date_consolidation),$view_scope); } $libelle_titre = $space.$checkbox.$space.$lien.$space.$date_conso; $vue_affichage.=gen_plus($vue->id_vue,$libelle_titre,$tab_list.$btn); } //Liste des options de consolidation $min_date=''; $max_date=''; $stat_scope = htmlentities($msg['stat_no_scope'],ENT_QUOTES,$charset); $q_sc = 'select min(date_log) as min_date, max(date_log) as max_date from statopac'; $r_sc = mysql_query($q_sc,$dbh); if ($r_sc && mysql_num_rows($r_sc)) { $res_sc=mysql_fetch_object($r_sc); $min_date=$res_sc->min_date; $max_date=$res_sc->max_date; if ($min_date!='0000-00-00 00:00:00' && $min_date!='0000-00-00 00:00:00') { $stat_scope = sprintf(htmlentities($msg['stat_scope'],ENT_QUOTES,$charset),formatdate($res_sc->min_date),formatdate($res_sc->max_date)); } } $options = "
"; $options .= ""; $options .= "$space ".htmlentities($msg[stat_options_consolidation],ENT_QUOTES,$charset).""; $options .= "$space $stat_scope"; $options .= "
"; $options_contenu ="







"; $options.=""; $stat_opac_view_form=str_replace("!!options_conso!!",$options,$stat_opac_view_form); $stat_opac_view_form=str_replace("!!liste_vues!!",$vue_affichage,$stat_opac_view_form); $stat_opac_view_form=str_replace("!!btn_consolide!!",$btn_consolide,$stat_opac_view_form); $btn_date_deb = ""; $btn_date_fin = ""; $btn_date_echeance = ""; $date_debut = strftime("%Y-%m-%d", mktime(0, 0, 0, date('m'), date('d')-1, date('y'))); $btn_date_deb=str_replace("!!date_deb!!",$date_debut,$btn_date_deb); $btn_date_deb=str_replace("!!date_deb_lib!!",formatdate($date_debut),$btn_date_deb); $date_fin = today(); $btn_date_fin=str_replace("!!date_fin!!",$date_fin,$btn_date_fin); $btn_date_fin=str_replace("!!date_fin_lib!!",formatdate($date_fin),$btn_date_fin); $date_echeance = today(); $btn_date_echeance=str_replace("!!date_ech!!",$date_echeance,$btn_date_echeance); $btn_date_echeance=str_replace("!!date_ech_lib!!",formatdate($date_echeance),$btn_date_echeance); $stat_opac_view_form=str_replace("!!date_deb_btn!!",$btn_date_deb,$stat_opac_view_form); $stat_opac_view_form=str_replace("!!date_fin_btn!!",$btn_date_fin,$stat_opac_view_form); $stat_opac_view_form=str_replace("!!echeance_btn!!",$btn_date_echeance,$stat_opac_view_form); } return $stat_opac_view_form; } /** * On fait appel au formulaire d'ajout d'une vue */ function do_addview_form($vue_id=''){ global $stat_view_addview_form; global $msg, $charset; if(!$vue_id){ $stat_view_addview_form=str_replace("!!name_view!!",'',$stat_view_addview_form); $stat_view_addview_form=str_replace("!!view_comment!!",'',$stat_view_addview_form); $stat_view_addview_form=str_replace("!!table_colonne!!",'',$stat_view_addview_form); $stat_view_addview_form=str_replace("!!bouton_add_col!!",'',$stat_view_addview_form); $stat_view_addview_form=str_replace("!!bouton_reinit_view!!",'',$stat_view_addview_form); $stat_view_addview_form=str_replace("!!btn_suppr!!",'',$stat_view_addview_form); $stat_view_addview_form=str_replace("!!view_title!!",$msg["stat_view_create_title"],$stat_view_addview_form); $stat_view_addview_form=str_replace("!!id_view!!",'',$stat_view_addview_form); return $stat_view_addview_form; } else { $btn_add_col = ""; $bouton_reinit_view=""; $btn_suppr = ""; $requete = "select nom_vue, comment from statopac_vues where id_vue='".addslashes($vue_id)."'"; $resultat = mysql_query($requete); while(($vue=mysql_fetch_object($resultat))){ $stat_view_addview_form=str_replace("!!name_view!!",htmlentities($vue->nom_vue,ENT_QUOTES,$charset),$stat_view_addview_form); $stat_view_addview_form=str_replace("!!view_comment!!",htmlentities($vue->comment,ENT_QUOTES, $charset),$stat_view_addview_form); } $stat_view_addview_form=str_replace("!!bouton_add_col!!",$btn_add_col,$stat_view_addview_form); $stat_view_addview_form=str_replace("!!bouton_reinit_view!!",$bouton_reinit_view,$stat_view_addview_form); $stat_view_addview_form=str_replace("!!btn_suppr!!",$btn_suppr,$stat_view_addview_form); $stat_view_addview_form=str_replace("!!id_view!!",$vue_id,$stat_view_addview_form); $res=""; $requete="select id_col, nom_col, expression, filtre, ordre, datatype from statopac_vues_col where num_vue='".$vue_id."' order by ordre"; $resultat=mysql_query($requete); if(mysql_num_rows($resultat) == 0){ $res="
".$msg["stat_no_col_associate"]."
"; $stat_view_addview_form=str_replace("!!table_colonne!!",$res,$stat_view_addview_form); $stat_view_addview_form=str_replace("!!view_title!!",$msg["stat_view_modif_title"],$stat_view_addview_form); return $stat_view_addview_form; } else { $res="\n"; $res.=""; $parity=1; $n=0; while ($r=mysql_fetch_object($resultat)) { if ($parity % 2) { $pair_impair = "even"; } else { $pair_impair = "odd"; } $parity+=1; $tr_javascript=" onmouseover=\"this.className='surbrillance'\" onmouseout=\"this.className='$pair_impair'\" "; $action_td=" onmousedown=\"document.location='./admin.php?categ=opac&sub=stat§ion=colonne&act=update_col&id_col=$r->id_col&id_view=$vue_id';\" "; $res.=""; $res.=""; $res.=""; } $res.="
".$msg["stat_col_order"]."".$msg["stat_col_name"]."".$msg["stat_col_expr"]."".$msg["stat_col_filtre"]."".$msg['stat_col_type']."
"; $res.=""; $res .= ""; $res.="".htmlentities($r->nom_col,ENT_QUOTES,$charset)." ".htmlentities($r->expression,ENT_QUOTES,$charset)." ".htmlentities($r->filtre,ENT_QUOTES,$charset)." ".htmlentities($r->datatype,ENT_QUOTES,$charset)."
"; $stat_view_addview_form=str_replace("!!table_colonne!!",$res,$stat_view_addview_form); $stat_view_addview_form=str_replace("!!view_title!!",$msg["stat_view_modif_title"],$stat_view_addview_form); } } return $stat_view_addview_form; } /** * On fait appel au formulaire d'ajout de colonne */ function do_col_form($id_col=''){ global $stat_view_addcol_form, $msg, $charset, $id_view; $datatype_list=array("small_text"=>"Texte","text"=>"Texte large","integer"=>"Entier","date"=>"Date","datetime"=>"Date/Heure","float"=>"Nombre à virgule"); if(!$id_col) { $stat_view_addcol_form=str_replace("!!col_name!!",'',$stat_view_addcol_form); $stat_view_addcol_form=str_replace("!!expr_col!!",'',$stat_view_addcol_form); $stat_view_addcol_form=str_replace("!!btn_suppr!!",'',$stat_view_addcol_form); $stat_view_addcol_form=str_replace("!!expr_filtre!!",'',$stat_view_addcol_form); $stat_view_addcol_form=str_replace("!!id_view!!",$id_view,$stat_view_addcol_form); $stat_view_addcol_form=str_replace("!!id_col!!",$id_col,$stat_view_addcol_form); $stat_view_addcol_form=str_replace("!!col_title!!",$msg["stat_col_create_title"],$stat_view_addcol_form); //liste des type de données $t_list="\n"; $stat_view_addcol_form=str_replace("!!datatype!!",$t_list,$stat_view_addcol_form); return $stat_view_addcol_form; } else { $requete="select nom_col, expression, filtre, datatype from statopac_vues_col where id_col='".$id_col."'"; $resultat=mysql_query($requete); while (($col=mysql_fetch_object($resultat))){ $col_name = htmlentities($col->nom_col,ENT_QUOTES,$charset); $expr = htmlentities($col->expression,ENT_QUOTES,$charset); $filtre = htmlentities($col->filtre,ENT_QUOTES,$charset); $datatype = htmlentities($col->datatype,ENT_QUOTES,$charset); } $stat_view_addcol_form=str_replace("!!col_name!!",$col_name,$stat_view_addcol_form); $stat_view_addcol_form=str_replace("!!expr_col!!",$expr,$stat_view_addcol_form); $stat_view_addcol_form=str_replace("!!expr_filtre!!",$filtre,$stat_view_addcol_form); $btn_suppr = ""; $stat_view_addcol_form=str_replace("!!btn_suppr!!",$btn_suppr,$stat_view_addcol_form); $stat_view_addcol_form=str_replace("!!col_title!!",$msg["stat_col_modif_title"],$stat_view_addcol_form); $stat_view_addcol_form=str_replace("!!id_view!!",$id_view,$stat_view_addcol_form); $stat_view_addcol_form=str_replace("!!id_col!!",$id_col,$stat_view_addcol_form); //liste des types de données $t_list="\n"; $stat_view_addcol_form=str_replace("!!datatype!!",$t_list,$stat_view_addcol_form); } return $stat_view_addcol_form; } /** * On insere ou enregistre une colonne */ function save_col($id_col='', $col_name='',$expr_col='',$expr_filtre='', $vue_id=''){ global $datatype; if((!$id_col) && $vue_id){ $req_ordre = "select max(ordre) from statopac_vues_col where num_vue='".addslashes($vue_id)."'"; $resultat = mysql_query($req_ordre); if($resultat) $order = mysql_result($resultat,0,0); else $order=0; $ordre = $order+1; $req = "INSERT INTO statopac_vues_col(nom_col,expression,filtre,num_vue, ordre,datatype) VALUES ('".$col_name."', '".$expr_col."','".$expr_filtre."','".$vue_id."','".$ordre."', '".$datatype."')"; $resultat=mysql_query($req); } else { $rqt="select * from statopac_vues_col where nom_col='".$col_name."' and expression='".$expr_col."' and num_vue='".$vue_id."' and filtre='".$expr_filtre."' and datatype='".$datatype."'"; $res_exist = mysql_query($rqt); if(mysql_num_rows($res_exist)){ $modif=0; } else $modif=1; $req = "UPDATE statopac_vues_col SET nom_col='".$col_name."', expression='".$expr_col."', num_vue='".$vue_id."', filtre='".$expr_filtre."', datatype='".$datatype."', maj_flag=$modif WHERE id_col='".$id_col."'"; $resultat=mysql_query($req); } } /** * On insere ou enregistre une vue */ function save_view($vue_id='', $view_name='',$view_comment=''){ if(!$vue_id){ $req = "INSERT INTO statopac_vues(nom_vue,comment) VALUES ('".$view_name."', '".$view_comment."')"; mysql_query($req); } else { $req = "UPDATE statopac_vues SET nom_vue='".$view_name."', comment='".$view_comment."' WHERE id_vue='".$vue_id."'"; mysql_query($req); } } /** * Supprime une vue et ces colonnes associées */ function delete_view($vue_id){ if($vue_id){ $req="DELETE FROM statopac_vues where id_vue='".$vue_id."'"; $resultat=mysql_query($req); $req="DELETE FROM statopac_vues_col where num_vue='".$vue_id."'"; $resultat=mysql_query($req); $req="DELETE FROM statopac_request where num_vue='".$vue_id."'"; $resultat=mysql_query($req); $req="DROP TABLE statopac_vue_".$vue_id; $resultat=mysql_query($req); } } /** * Réinitialise la vue à zéro */ function reinitialiser_view($vue_id=''){ if($vue_id){ $req="DELETE FROM statopac_vues_col where num_vue='".$vue_id."'"; $resultat=mysql_query($req); $req="DELETE FROM statopac_request where num_vue='".$vue_id."'"; $resultat=mysql_query($req); $req="DELETE FROM statopac_vue_".$vue_id; $resultat=mysql_query($req); $req="update statopac_vues set date_consolidation='0000-00-00 00:00:00', date_debut_log='0000-00-00 00:00:00', date_fin_log='0000-00-00 00:00:00' where num_vue='".$vue_id."'"; $resultat=mysql_query($req); } } /** * Supprime une colonne */ function delete_col($id_col){ if($id_col){ $req="SELECT nom_col,num_vue FROM statopac_vues_col WHERE id_col='".$id_col."'"; $res=mysql_query($req); if(mysql_num_rows($res)){ //On supprime la colonne de la vue $id_vue=mysql_result($res,0,1); mysql_query("ALTER TABLE statopac_vue_".$id_vue." DROP `".mysql_result($res,0,0)."`"); $req="DELETE FROM statopac_vues_col where id_col='".$id_col."'"; $resultat=mysql_query($req); //On recalcule l'ordre des colonnes $req="SELECT id_col FROM statopac_vues_col WHERE num_vue ='".$id_vue."' ORDER BY ordre"; $res=mysql_query($req); if(mysql_num_rows($res)){ $ordre=1; while ($ligne=mysql_fetch_object($res)) { mysql_query("UPDATE statopac_vues_col SET ordre='".$ordre."' WHERE id_col='".$ligne->id_col."'"); $ordre++; } } } } } /** * Changer l'ordre dans la liste en montant un élément */ function monter_element($col_id=''){ $requete="select ordre from statopac_vues_col where id_col='".$col_id."'"; $resultat=mysql_query($requete); $ordre=mysql_result($resultat,0,0); $requete="select max(ordre) as ordre from statopac_vues_col where ordre<".addslashes($ordre); $resultat=mysql_query($requete); $ordre_max=@mysql_result($resultat,0,0); if ($ordre_max) { $requete="select id_col from statopac_vues_col where ordre='".addslashes($ordre_max)."' limit 1"; $resultat=mysql_query($requete); $idcol_max=mysql_result($resultat,0,0); $requete="update statopac_vues_col set ordre='".addslashes($ordre_max)."' where id_col='".$col_id."'"; mysql_query($requete); $requete="update statopac_vues_col set ordre='".addslashes($ordre)."' where id_col='".addslashes($idcol_max)."'"; mysql_query($requete); } } /** * Changer l'ordre dans la liste en descendant un élément */ function descendre_element($col_id=''){ $requete="select ordre from statopac_vues_col where id_col='".$col_id."'"; $resultat=mysql_query($requete); $ordre=mysql_result($resultat,0,0); $requete="select min(ordre) as ordre from statopac_vues_col where ordre>".addslashes($ordre); $resultat=mysql_query($requete); $ordre_min=@mysql_result($resultat,0,0); if ($ordre_min) { $requete="select id_col from statopac_vues_col where ordre='".addslashes($ordre_min)."' limit 1"; $resultat=mysql_query($requete); $idcol_min=mysql_result($resultat,0,0); $requete="update statopac_vues_col set ordre='".addslashes($ordre_min)."' where id_col='".$col_id."'"; mysql_query($requete); $requete="update statopac_vues_col set ordre='".addslashes($ordre)."' where id_col='".addslashes($idcol_min)."'"; mysql_query($requete); } } /** * Verification de la presence et de la syntaxe des parametres de la requete * retourne true si OK, le nom du parametre entre parentheses sinon */ 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