noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
dossier.inc.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of NOALYSS.
00004  *
00005  *   NOALYSS is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   NOALYSS is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with NOALYSS; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00021 if ( !defined ('ALLOWED')) die('Forbidden');
00022 /*!\file
00023 * \brief Management of the folder
00024  *
00025  */
00026 require_once("class_itext.php");
00027 require_once("class_icheckbox.php");
00028 require_once("class_itextarea.php");
00029 
00030 $sa=(isset($_REQUEST['sa']))?$_REQUEST['sa']:'list';
00031 //---------------------------------------------------------------------------
00032 // Update
00033 if ( isset ($_POST['upd']) && isset ($_POST['d']))
00034 {
00035     $dos=new dossier($_POST['d']);
00036     $dos->set_parameter('name',$_POST['name']);
00037     $dos->set_parameter('desc',$_POST['desc']);
00038     $dos->save();
00039 }
00040 echo '<div class="content" style="width:80%;margin-left:10%">';
00041 // check and add an new folder
00042 if ( isset ($_POST["DATABASE"]) )
00043 {
00044     $repo=new Database();
00045     $dos=trim($_POST["DATABASE"]);
00046     $dos=sql_string($dos);
00047     if (strlen($dos)==0)
00048     {
00049         echo _("Le nom du dossier est vide");
00050         exit -1;
00051     }
00052     $encoding=$repo->get_value("select encoding from pg_database  where ".
00053                              " datname='".domaine.'mod'.sql_string($_POST["FMOD_ID"])."'");
00054     if ( $encoding != 6 )
00055     {
00056         alert(_('Désolé vous devez migrer ce modèle en unicode'));
00057         echo '<span class="error">';
00058         echo _('le modele ').domaine.'mod'.$_POST["FMOD_ID"]._(" doit être migré en unicode.");
00059         echo _('Pour le passer en unicode, faites-en un backup puis restaurez le fichier reçu').'</span>';
00060         echo HtmlInput::button_anchor('Retour','admin_repo.php?action=dossier_mgt');
00061         exit();
00062     }
00063 
00064     $desc=sql_string($_POST["DESCRIPTION"]);
00065     try
00066     {
00067         $repo->start();
00068 
00069         $Res=$repo->exec_sql("insert into ac_dossier(dos_name,dos_description)
00070                            values ('".$dos."','$desc')");
00071         $l_id=$repo->get_current_seq('dossier_id');
00072         $repo->commit();
00073     }
00074     catch (Exception $e)
00075     {
00076         $msg=_("Desole la creation de ce dossier a echoue,\n la cause la plus probable est".
00077                ' deux fois le même nom de dossier');
00078         alert($msg);
00079         $l_id=0;
00080         $repo->rollback();
00081 
00082     }
00083     // If the id is not null, name successfully inserted
00084     // Database created
00085 
00086     if ( $l_id != 0)
00087     {
00088         //--
00089         // setting the year
00090         //--
00091         $year=sql_string($_POST['YEAR']);
00092         if ( strlen($year) != 4 || isNumber($year) == 0 || $year > 2100 || $year < 2000 || $year != round($year,0))
00093         {
00094             echo "$year"._(" est une année invalide");
00095             $Res=$repo->exec_sql("delete from ac_dossier where dos_id=$l_id");
00096         }
00097         else
00098         {
00099             $Sql=sprintf("CREATE DATABASE %sDOSSIER%d encoding='UTF8' TEMPLATE %sMOD%d",
00100                          domaine,
00101                          $l_id,
00102                          domaine,
00103                          sql_string($_POST["FMOD_ID"]));
00104             ob_start();
00105             if ( $repo->exec_sql($Sql)==false)
00106             {
00107                 echo   "[".$Sql."]";
00108 
00109                 //ob_end_clean();
00110                 $repo->exec_sql("delete from ac_dossier where dos_id=$l_id");
00111                 echo "<h2 class=\"error\">"._(" Base de donnée ").domaine."mod".$_POST['FMOD_ID']."  ".
00112                 _("est accèdée, déconnectez-vous d'abord")."</h2>";
00113                 exit;
00114             }
00115             ob_flush();
00116             $Res=$repo->exec_sql("insert into jnt_use_dos (use_id,dos_id) values (1,$l_id)");
00117             // Connect to the new database
00118             $cn=new Database($l_id);
00119             //--year --
00120             $Res=$cn->exec_sql("delete from parm_periode");
00121             if ( ($year % 4 == 0 && $year % 100 != 0) || $year % 400 == 0 )
00122                 $fev=29;
00123             else
00124                 $fev=28;
00125             $Res=$cn->exec_sql("delete from user_local_pref where parameter_type='PERIODE'");
00126             $nb_day=array(31,$fev,31,30,31,30,31,31,30,31,30,31);
00127             $m=1;
00128             foreach ($nb_day as $day)
00129             {
00130                 $p_start=sprintf("01-%d-%s",$m,$year);
00131                 $p_end=sprintf("%d-%d-%s",$day,$m,$year);
00132                 $sql=sprintf("insert into parm_periode (p_start,p_end,p_exercice)
00133                              values (to_date('%s','DD-MM-YYYY'),to_date('%s','DD-MM-YYYY'),'%s')",
00134                              $p_start,$p_end,$year);
00135                 $Res=$cn->exec_sql($sql);
00136                 $m++;
00137             }
00138             $sql="      insert into jrn_periode(p_id,jrn_def_id,status) ".
00139                  "select p_id,jrn_def_id, 'OP'".
00140                  " from parm_periode cross join jrn_def";
00141             $Res=$cn->exec_sql($sql);
00142 
00143             Dossier::synchro_admin($l_id);
00144 
00145 
00146         }
00147     } // if $l_id != 0
00148 } // $_POST[DATABASE]
00149 ?>
00150 <h2> Dossier Management</h2>
00151 
00152 <?php
00153 //---------------------------------------------------------------------------
00154 // List of folder
00155 if ( $sa == 'list' )
00156 {
00157         require_once('class_sort_table.php');
00158         echo '<p>';
00159         echo HtmlInput::button_anchor(_('Rafraîchir'),'admin_repo.php?action=dossier_mgt');
00160         echo HtmlInput::button_anchor(_('Ajouter'),'admin_repo.php?action=dossier_mgt&sa=add');
00161         echo '</p>';
00162         $header=new Sort_Table();
00163         $url=$_SERVER['PHP_SELF']."?sa=list&action=".$_REQUEST['action'];
00164         $header->add("id",$url," order by dos_id asc"," order by dos_id desc","da","dd");
00165         $header->add("Nom",$url," order by dos_name asc"," order by dos_name desc","na","nd");
00166         $header->add("Description",$url," order by dos_description asc"," order by dos_description  desc","da","dd");
00167     $repo=new Dossier(0);
00168         $repocn=new Database();
00169         $ord=(isset($_REQUEST['ord']))?$_REQUEST['ord']:'na';
00170         $sql_order=$header->get_sql_order($ord);
00171         $Res=$repocn->get_array("select *  from ac_dossier $sql_order");
00172 
00173         $compteur=1;
00174     $template="";
00175         echo '<div class="content">';
00176         echo '<span style="display:block">';
00177         echo _('Filtre').HtmlInput::infobulle(23);
00178         echo HtmlInput::filter_table("t_dossier", "0,1,2","1");
00179         echo '</span>';
00180     echo '<TABLE id="t_dossier" class="table_large" >';
00181         $r="";
00182         $r.='<th>'.$header->get_header(0).'</td>';
00183         $r.='<th>'.$header->get_header(1).'</td>';
00184         $r.='<th>'.$header->get_header(2).'</td>';
00185     $r.=th('Taille').th('Nom base de données');
00186 
00187     $r=tr($r);
00188     echo $r;
00189     // show all dossiers
00190     if ( $Res != null )
00191     {
00192         foreach ( $Res as $Dossier)
00193         {
00194 
00195             if ( $compteur%2 == 0 )
00196                 $cl='class="odd"';
00197             else
00198                 $cl='class="even"';
00199 
00200             echo "<TR $cl><TD style=\"vertical-align:top\"> ".
00201               $Dossier['dos_id']."</td><td> <B>".h($Dossier['dos_name'])."</B> </TD>";
00202             $str_name=domaine.'dossier'.$Dossier['dos_id'];
00203 
00204             echo "<TD><I>  ".h($Dossier['dos_description'])."</I></td>";
00205 
00206             $database_exist=$repocn->exist_database($str_name);
00207 
00208             if ($database_exist > 0 )
00209             {
00210                 $size=$repocn->get_value("select pg_database_size($1)/(1024*1024)::float",
00211                                      array($str_name));
00212                 echo td(nbm($size)."MB",' style="text-align:right"');
00213             } else {
00214                 echo td(_("Dossier inexistant"),'style="color:red"');
00215             }
00216             echo td($str_name);
00217             echo "<TD>";
00218             if ( $database_exist > 0)
00219             {
00220                 echo td(HtmlInput::button_anchor(_('Effacer'),'?action=dossier_mgt&sa=del&d='.$Dossier['dos_id']));
00221 
00222                 echo td(HtmlInput::button_anchor(_('Modifier'),'?action=dossier_mgt&sa=mod&d='
00223                                                  .$Dossier['dos_id']));
00224 
00225                 echo td(HtmlInput::button_anchor(_('Backup'),'backup.php?action=backup&sa=b&t=d&d='
00226                                               .$Dossier['dos_id']));
00227                 echo '</td>';
00228             }
00229             echo '<tr>';
00230             $compteur++;
00231 
00232         }
00233 
00234         echo "</TR>";
00235 
00236     }
00237     echo '</table>';
00238 
00239 
00240 }
00241 
00242 //---------------------------------------------------------------------------
00243 // Add a new folder
00244 if ( $sa == 'add' )
00245 {
00246     $repo=new Database();
00247     // Load the available Templates
00248     $Res=$repo->exec_sql("select mod_id,mod_name,mod_desc from
00249                        modeledef order by mod_name");
00250     $count=Database::num_row($Res);
00251 
00252     if ( $count == 0 )
00253     {
00254         echo _("pas de modèle disponible");
00255     }
00256     else
00257     {
00258         $template='<SELECT NAME=FMOD_ID>';
00259         for ($i=0;$i<$count;$i++)
00260         {
00261             $mod=Database::fetch_array($Res,$i);
00262             $template.='<OPTION VALUE="'.$mod['mod_id'].'"> '.h($mod['mod_name']." - ".mb_substr($mod['mod_desc'],0,30));
00263         }// for
00264         $template.="</SELECT>";
00265     }// if count = 0
00266     $m_date=date('Y');
00267 
00268     ?>
00269 
00270     </TABLE>
00271 
00272     <FORM ACTION="admin_repo.php?action=dossier_mgt" METHOD="POST">
00273                  <TABLE>
00274                  <TR>
00275                  <TD><?php echo _('Nom du dossier');
00276     ?></td><td>  <INPUT TYPE="TEXT" NAME="DATABASE"> </TD>
00277                                          </TR><TR>
00278                                          <TD><?php echo _('Description');
00279     ?></td><td>  <TEXTAREA COLS="60" ROWS="2" NAME="DESCRIPTION" ></TEXTAREA> </TD>
00280                                           </TR>
00281                                           <TR> <TD><?php echo _('Modèle');
00282     ?></td><td>  <?php   echo $template;
00283     ?> </TD></TR>
00284     <TR><TD>Année </TD><TD><input type="text" size=4 name="YEAR" value=<?php  echo '"'.$m_date.'"'; ?>></TD></TR>
00285     <TR>
00286     <TD> <INPUT TYPE=SUBMIT class="button" VALUE="<?php echo _('Creation Dossier'); ?>"> </TD>
00287                                               <td>
00288                                               <?php  echo HtmlInput::button_anchor(_('Retour'),'admin_repo.php?action=dossier_mgt');
00289     ?>
00290     </td>
00291     </TR>
00292     </TABLE>
00293     </FORM>
00294     <?php
00295 }
00296 //---------------------------------------------------------------------------
00297 // action= mod
00298 if ( $sa == 'mod' )
00299 {
00300     require_once ('class_dossier.php');
00301     $dos=new dossier($_REQUEST['d']);
00302     $dos->load();
00303     $wText=new IText();
00304     echo '<form action="admin_repo.php" method="post">';
00305     echo HtmlInput::hidden('action','dossier_mgt');
00306     echo HtmlInput::hidden('d',$dos->get_parameter("id"));
00307     echo _('Nom').' : ';
00308     echo  $wText->input('name',$dos->get_parameter('name'));
00309     echo '<br>';
00310     $wDesc=new ITextArea();
00311     $wDesc->heigh=5;
00312     echo _('Description').' : <br>';
00313     echo  $wDesc->input('desc',$dos->get_parameter('desc'));
00314     echo '<br>';
00315     echo HtmlInput::submit('upd',_('Modifie'));
00316     echo HtmlInput::button_anchor(_('Retour'),'?action=dossier_mgt');
00317     echo '</form>';
00318 }
00319 //---------------------------------------------------------------------------
00320 // action = del
00321 //---------------------------------------------------------------------------
00322 if ( $sa == 'del' )
00323 {
00324     $d=new Dossier($_REQUEST ['d'] );
00325     $d->load();
00326     echo '<form method="post">';
00327     echo HtmlInput::hidden('d',$_REQUEST['d']);
00328     echo HtmlInput::hidden('sa','remove');
00329     echo '<h2 class="error">'._('Etes vous sûr et certain de vouloir effacer ').$d->dos_name.' ???</h2>';
00330     $confirm=new ICheckBox();
00331     $confirm->name="p_confirm";
00332     echo _('Cochez la case si vous êtes sûr de vouloir effacer ce dossier');
00333     echo $confirm->input();
00334     echo HtmlInput::submit('remove',_('Effacer'));
00335     echo HtmlInput::button_anchor(_('Retour'),'?action=dossier_mgt');
00336     echo '</form>';
00337 }
00338 //---------------------------------------------------------------------------
00339 // action = del
00340 //---------------------------------------------------------------------------
00341 if ( $sa == 'remove' )
00342 {
00343     if ( ! isset ($_REQUEST['p_confirm']))
00344     {
00345         echo _('Désolé, vous n\'avez pas coché la case');
00346         echo HtmlInput::button_anchor('Retour','?action=dossier_mgt');
00347         exit();
00348     }
00349 
00350     $cn=new Database();
00351     $msg="dossier";
00352     $name=$cn->get_value("select dos_name from ac_dossier where dos_id=$1",array($_REQUEST['d']));
00353     if ( strlen(trim($name)) == 0 )
00354     {
00355         echo "<h2 class=\"error\"> $msg "._('inexistant')."</h2>";
00356         exit();
00357     }
00358     $sql="drop database ".domaine."dossier".sql_string($_REQUEST['d']);
00359     ob_start();
00360     if ( $cn->exec_sql($sql)==false)
00361     {
00362         ob_end_clean();
00363 
00364         echo "<h2 class=\"error\"> ";
00365         echo _('Base de donnée ').domaine."dossier".$_REQUEST['d'].
00366         _("est accèdée, déconnectez-vous d'abord")."</h2>";
00367         exit;
00368     }
00369     ob_flush();
00370     $sql="delete from priv_user where priv_id in (select jnt_id from jnt_use_dos where dos_id=$1)";
00371     $cn->exec_sql($sql,array($_REQUEST['d']));
00372     $sql="delete from  jnt_use_dos where dos_id=$1";
00373     $cn->exec_sql($sql,array($_REQUEST['d']));
00374     $sql="delete from ac_dossier where dos_id=$1";
00375     $cn->exec_sql($sql,array($_REQUEST['d']));
00376     print '<h2 class="error">';
00377     print "Le dossier ".h($name)." est effacé</h2>";
00378     echo HtmlInput::button_anchor('Retour','?action=dossier_mgt');
00379 }
00380 ?>
00381 </div>
 All Data Structures Namespaces Files Functions Variables Enumerations