Main Page | Namespace List | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

admin_repo.php

Go to the documentation of this file.
00001 <?
00002 
00003 /*
00004  *   This file is part of PhpCompta.
00005  *
00006  *   PhpCompta is free software; you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation; either version 2 of the License, or
00009  *   (at your option) any later version.
00010  *
00011  *   PhpCompta is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with PhpCompta; if not, write to the Free Software
00018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  * $Revision: 1.23 $
00020 */
00021 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00027 include_once("ac_common.php");
00028 include_once("postgres.php");
00029 include_once("debug.php");
00030 include_once("user_menu.php");
00031 $rep=DbConnect();
00032 include_once ("class_user.php");
00033 $User=new cl_user($rep);
00034 $User->Check();
00035 
00036 
00037 html_page_start($User->theme);
00038 echo_debug('admin_repo.php',__LINE__,"entering admin_repo");
00039 
00040 if ($User->admin != 1) {
00041   html_page_stop();
00042   return;
00043 }
00044 
00045 echo '<H2 class="info"> Administration Globale</H2>';
00046 echo "<div>".MenuAdmin()."</div>";
00047 
00048 
00049 
00050 
00051 ?>
00052 <DIV >
00053 <?
00054 if ( isset ($_GET["action"]) ) {
00055   if ( $_GET["action"]=="user_mgt" ) {
00056     // Add user
00057     if ( isset ($_POST["LOGIN"]) ) {
00058       $cn=DbConnect();
00059       $pass5=md5($_POST['PASS']);
00060       $Res=ExecSql($cn,"insert into ac_users(use_first_name,use_name,use_login,use_active,use_pass)
00061                     values ('".$_POST["FNAME"]."','".$_POST["LNAME"]."','".$_POST["LOGIN"]."',1,'$pass5')");
00062     } //SET login
00063 
00064     // Show all the existing user on 7 columns
00065     $cn=GetAllUser();
00066     echo_debug('admin_repo.php',__LINE__,"Array = $cn");
00067     $compteur=0;
00068 ?>
00069 <h2>Gestion Utilisateurs</h2>
00070 <TABLE><TR>
00071 <?
00072     if ( $cn != null ) {
00073       foreach ( $cn as $rUser) {
00074         $compteur++;
00075         if ( $compteur==0 ) echo "<TR>";
00076         if ( $compteur%3 == 0)     echo "</TR><TR>";
00077         if ( $rUser['use_active'] == 0 ) {
00078           $Active="not actif";
00079         } else {
00080           $Active="";
00081         }
00082         printf('<TD><A HREF=priv_user.php?UID=%s> %s %s ( %s )</A> %s </TD>',
00083                $rUser['use_id'],
00084                $rUser['use_first_name'],
00085                $rUser['use_name'],
00086                $rUser['use_login'],
00087                $Active);
00088       }// foreach
00089     } // $cn != null
00090 ?>
00091 </TABLE>
00092 <TABLE> <TR> 
00093 <form action="admin_repo.php?action=user_mgt" method="POST">
00094 <TD><H3>Ajout d'utilisateur<H3></TD></TR>
00095 <? //'
00096     echo '<TR><TD> First Name </TD><TD><INPUT TYPE="TEXT" NAME="FNAME"></TD>';
00097     echo '<TD> Last Name </TD><TD><INPUT TYPE="TEXT" NAME="LNAME"></TD></TR>';
00098     echo '<TR><TD> login </TD><TD><INPUT TYPE="TEXT" NAME="LOGIN"></TD>';
00099     echo '<TD> password </TD><TD> <INPUT TYPE="TEXT" NAME="PASS"></TD></TR>';
00100     echo '<TD> <INPUT TYPE="SUBMIT" Value="Create user" NAME="ADD"></TD>';
00101     echo '</TABLE>';
00102 
00103 ?>
00104 </FORM>
00105 
00106 <?
00107     // check and add an user (see form below)
00108 
00109   } // action=user_mgt
00110   if ( $_GET["action"]=="dossier_mgt") {
00111     // check and add an new folder
00112     if ( isset ($_POST["DATABASE"]) ) {
00113       $cn=DbConnect();
00114       $dos=trim($_POST["DATABASE"]);
00115       if (strlen($dos)==0) {
00116         echo ("Dataname name is empty");
00117         exit -1;
00118       }
00119       $desc=FormatString($_POST["DESCRIPTION"]);
00120       $Res=ExecSql($cn,"insert into ac_dossier(dos_name,dos_description)
00121                     values ('".$dos."','$desc')");
00122       // If the id is not null, name successfully inserted
00123       // Database created
00124       $l_id=GetDbId($dos);
00125       if ( $l_id != 0) {
00126         $Sql=sprintf("CREATE DATABASE %sDOSSIER%d encoding='ISO8859-1' TEMPLATE %sMOD%d",domaine,$l_id,domaine,$_POST["FMOD_ID"]);
00127         echo_debug($Sql);
00128         ExecSql($cn,$Sql);
00129         $Res=ExecSql($cn,"insert into jnt_use_dos (use_id,dos_id) values (1,$l_id)");
00130       } // if $l_id != 0
00131     } // $_POST[DATABASE]
00132 ?>
00133    <h2> Dossier Management</h2>
00134 
00135 <TABLE BORDER=1>
00136 <?
00137 $cn=DbConnect();
00138 $Res=ShowDossier('all');
00139 $compteur=1;
00140 $template="";
00141 
00142  // show all dossiers
00143 if ( $Res != null ) {
00144   foreach ( $Res as $Dossier) {
00145     
00146     if ( $compteur%2 == 0 ) 
00147         $cl='class="odd"';
00148         else
00149         $cl='class="even"';
00150 
00151     echo "<TR $cl><TD VALIGN=\"TOP\"> <B>$Dossier[dos_name]</B> </TD><TD><I>  $Dossier[dos_description]</I></TD></TR>";
00152     $compteur++;
00153     
00154   }
00155 
00156   echo "</TR>";
00157 
00158 }
00159 
00160   // Load the available Templates
00161 $Res=ExecSql($cn,"select mod_id,mod_name,mod_desc from 
00162                       modeledef order by mod_name");
00163 $count=pg_NumRows($Res);
00164 
00165 if ( $count == 0 ) {
00166     echo "No template available";
00167   } else {
00168     $template='<SELECT NAME=FMOD_ID>';
00169       for ($i=0;$i<$count;$i++) {
00170         $mod=pg_fetch_array($Res,$i);
00171         $template.='<OPTION VALUE="'.$mod['mod_id'].'"> '.$mod['mod_name']." - ".substr($mod['mod_desc'],0,30);
00172       }// for
00173       $template.="</SELECT>";
00174     }// if count = 0
00175 
00176 // Add a new folder
00177 ?>
00178 </TABLE>
00179  <FORM ACTION="admin_repo.php?action=dossier_mgt" METHOD="POST">
00180     <TABLE>
00181     <TR>
00182     <TD> Name</td><td>  <INPUT TYPE="TEXT" NAME="DATABASE"> </TD>
00183     </TR><TR>
00184     <TD> Description</td><td>  <TEXTAREA COLS="60" ROWS="2" NAME="DESCRIPTION" ></TEXTAREA> </TD>
00185     </TR>
00186     <TR> <TD> Modèle</td><td>  <? echo $template; ?> </TD></TR>
00187 
00188     <TR>
00189     <TD> <INPUT TYPE=SUBMIT VALUE="Create Folder"></TD>
00190     </TR>
00191     </TABLE>
00192  </FORM>
00193 
00194 <?
00195 
00196   } // action = dossier_mgt
00197   if ( $_GET["action"] == "modele_mgt" ) {
00198     $cn=DbConnect();
00199 
00200     // IF FMOD_NAME is posted then must add a template
00201     if ( isset ($_POST["FMOD_NAME"]) ) {
00202       $mod_name=FormatString($_POST["FMOD_NAME"]);
00203       $mod_desc=FormatString($_POST["FMOD_DESC"]);
00204       if ( $mod_name != null) {
00205         $Res=ExecSql($cn,"insert into modeledef(mod_name,mod_desc)
00206                         values ('".$mod_name."',".
00207                      "'".$mod_desc."')");
00208         
00209         // get the mod_id
00210         $l_id=GetSequence($cn,'s_modid');
00211         if ( $l_id != 0 ) {
00212            $Sql=sprintf("CREATE DATABASE %sMOD%d encoding='ISO8859-1' TEMPLATE %sDOSSIER%s",domaine,$l_id,domaine,$_POST["FMOD_DBID"]);
00213            ExecSql($cn,$Sql);
00214         }
00215       }// if $mod_name != null
00216 
00217       $cn_mod=dbconnect($l_id,'mod');
00218       // Clean some tables 
00219       $Res=ExecSql($cn_mod,"truncate table jrn");
00220       $Res=ExecSql($cn_mod,"truncate table jrnx");
00221       $Res=ExecSql($cn_mod,"truncate table centralized");
00222       $Res=ExecSql($cn_mod,"truncate table stock_goods");
00223 //      Reset the closed periode
00224       $Res=ExecSql($cn_mod,"update parm_periode set p_closed='f'");
00225       // Reset Sequence
00226       $a_seq=array('s_jrn','s_jrn_op','s_centralized','s_stock_goods');
00227       foreach ($a_seq as $seq ) {
00228         $sql=sprintf("select setval('%s',1,false)",$seq);
00229         $Res=ExecSql($cn_mod,$sql);
00230         }
00231         $sql="select jrn_def_id from jrn_def ";
00232         $Res=ExecSql($cn_mod,$sql);
00233         $Max=pg_NumRows($Res);
00234         for ($seq=0;$seq<$Max;$seq++) {
00235             $row=pg_fetch_array($Res,$seq);
00236             $sql=sprintf ("select setval('s_jrn_%d',1,false)",$row['jrn_def_id']);
00237             ExecSql($cn_mod,$sql);
00238         }
00239       
00240       
00241     }
00242     // Show all available templates
00243 
00244     $Res=ExecSql($cn,"select mod_id,mod_name,mod_desc from 
00245                       modeledef order by mod_name");
00246     $count=pg_NumRows($Res);
00247     if ( $count == 0 ) {
00248       echo "No template available";
00249     } else {
00250       echo "<H2>Modèles</H2>";
00251 
00252       echo '<table width="100%" border="1">';
00253       echo "<TR><TH>Nom</TH>".
00254         "<TH>Description</TH>".
00255         "</TR>";
00256 
00257       for ($i=0;$i<$count;$i++) {
00258         $mod=pg_fetch_array($Res,$i);
00259         printf('<TR>'.
00260                '<TD><b> %s</b> </TD>'.
00261                '<TD><I> %s </I></TD>'.
00262                '</TR>',
00263                $mod['mod_name'],
00264                $mod['mod_desc']);
00265 
00266       }// for
00267       echo "</table>";
00268     }// if count = 0
00269       echo "Si vous voulez récupérer toutes les adaptations d'un dossier ".
00270         " dans un autre dossier, vous pouvez en faire un modèle.".
00271         " Seules les fiches, la structure des journaux, les périodes,... seront reprises ".
00272         "et aucune données du dossier sur lequel le dossier est basé.";
00273 
00274     // Show All available folder
00275     $Res=ExecSql($cn,"select dos_id, dos_name,dos_description from ac_dossier
00276                       order by dos_name");
00277     $count=pg_NumRows($Res);
00278     $available="";
00279     if ( $count != 0 ) {
00280       $available='<SELECT NAME="FMOD_DBID">';
00281       for ($i=0;$i<$count;$i++) {
00282         $db=pg_fetch_array($Res,$i);
00283         $available.='<OPTION VALUE="'.$db['dos_id'].'">'.$db['dos_name'].':'.$db['dos_description'];
00284       }//for i
00285       $available.='</SELECT>';
00286     }//if count !=0
00287 ?>
00288 <form action="admin_repo.php?action=modele_mgt" METHOD="post">
00289 <TABLE>
00290 <tr>
00291     <td>Nom </TD>
00292     <TD><INPUT TYPE="TEXT" VALUE="" NAME="FMOD_NAME"></TD>
00293 </TR>
00294 <TR>
00295     <TD>Description</TD>
00296     <TD><TEXTAREA ROWS="2" COLS="60" NAME="FMOD_DESC"></Textarea></TD>
00297 </TR>
00298 <TR>
00299     <TD> Basé sur </TD>
00300     <TD> <? echo $available ?></TD>
00301 </TR>
00302 <TR>
00303     <td colspan="2"> <INPUT TYPE="SUBMIT" VALUE="Add a template"></TD>
00304 </TR>
00305 </TABLE>
00306 </form>
00307 <?
00308 
00309   }// action = modele_mgt
00310 } // action is set
00311 ?>
00312 </DIV>
00313 <?
00314 
00315 html_page_stop();
00316 ?>