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.="
";
$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;
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
$datatype_list=array("small_text"=>"Texte","text"=>"Texte large","integer"=>"Entier","date"=>"Date","datetime"=>"Date/Heure","float"=>"Nombre à virgule");
$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
$datatype_list=array("small_text"=>"Texte","text"=>"Texte large","integer"=>"Entier","date"=>"Date","datetime"=>"Date/Heure","float"=>"Nombre à virgule");
$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,date_consolidation) VALUES ('".$view_name."', '".$view_comment."',now())";
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);
}
}
/**
* 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="DELETE FROM statopac_vues_col where id_col='".$id_col."'";
$resultat=mysql_query($req);
}
}
/**
* 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