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

pcmn_update.php

Go to the documentation of this file.
00001 <?
00002 /*
00003  *   This file is part of PhpCompta.
00004  *
00005  *   PhpCompta 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  *   PhpCompta 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 PhpCompta; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00020 /* $Revision: 1.25 $ */
00024 include_once ("ac_common.php");
00025 html_page_start($_SESSION['g_theme']);
00026 require_once("constant.php");
00027 
00028 if ( ! isset ( $_SESSION['g_dossier'] ) ) {
00029   echo "You must choose a Dossier ";
00030   exit -2;
00031 }
00032 include_once ("postgres.php");
00033 /* Admin. Dossier */
00034 $rep=DbConnect();
00035 include_once ("class_user.php");
00036 $User=new cl_user($rep);
00037 $User->Check();
00038 
00039 
00040 include_once ("user_menu.php");
00041 include_once ("check_priv.php");
00042 
00043 echo ShowMenuCompta($_SESSION['g_dossier'],"user_advanced.php");
00044 
00045 $cn=DbConnect($_SESSION['g_dossier']);
00046 if ( $User->CheckAction($cn,MPCMN) == 0 ) {
00047   /* Cannot Access */
00048   NoAccess();
00049   exit -1;                      
00050  }
00051 echo JS_UPDATE_PCMN;
00052 /* Store the p_start parameter */
00053 if ( ! isset ( $_SESSION['g_start']) ) {
00054   $_SESSION['g_start']="";
00055 
00056 }
00057 if ( isset ($_GET['p_start'])) { 
00058   $g_start=$_GET['p_start'];
00059   $_SESSION["g_start"]=$g_start; 
00060 
00061 }
00062 
00063 echo '<div class="u_subtmenu">';
00064 echo ShowMenuAdvanced("pcmn_update.php?p_start=1");
00065 echo '</div>';
00066 echo '<div class="lmenu">';
00067 ShowMenuPcmn($_SESSION['g_start']);
00068 echo '</div>';
00069 echo '<DIV CLASS="u_redcontent">';
00070 /* Analyse ce qui est demandé */
00071 /* Effacement d'une ligne */
00072 if (isset ($_GET['action'])) {
00073 //-----------------------------------------------------
00074 // Action == remove a line
00075   if ( $_GET['action']=="del" ) {
00076     if ( isset ($_GET['l']) ) {
00077       /* Ligne a enfant*/
00078       $R=ExecSql($cn,"select pcm_val from tmp_pcmn where pcm_val_parent=".$_GET['l']);
00079       if ( pg_NumRows($R) != 0 ) {
00080         echo "<SCRIPT> alert(\"Ne peut pas effacer le poste: d'autres postes en dépendent\");</SCRIPT>";
00081       } else {
00082         /* Vérifier que le poste n'est pas utilisé qq part dans les journaux */
00083         $Res=ExecSql($cn,"select * from jrnx where j_poste=".$_GET['l']);
00084         if ( pg_NumRows($R) != 0 ) {
00085           echo "<SCRIPT> alert(\"Ne peut pas effacer le poste: il est utilisé dans les journaux\");</SCRIPT>";
00086         }
00087         else {
00088           $Del=ExecSql($cn,"delete from tmp_pcmn where pcm_val=".$_GET['l']);
00089         } // if pg_NumRows
00090       } // if pg_NumRows
00091     } // isset ($l)
00092   } //$action == del
00093 } // isset action
00094 //-----------------------------------------------------
00095 /* Ajout d'une ligne */
00096 if ( isset ( $_POST["Add"] ) ) {
00097         extract ($_POST);
00098   if ( isset ( $p_val) && isset ( $p_lib ) && isNumber(trim($p_val)) && isNumber(trim($p_parent)) ) {
00099     $p_val=trim($p_val);
00100     $p_lib=FormatString(trim($p_lib));
00101     $p_parent=$_POST["p_parent"];
00102     if ( strlen ($p_val) != 0 && strlen ($p_lib) != 0 ) {
00103       if (strlen ($p_val) == 1 ) {
00104         $p_parent=0;
00105       } else {
00106         if ( strlen(trim($p_parent))==0 && 
00107              (string) $p_parent != (string)(int) $p_parent) {
00108           $p_parent=substr($p_val,0,strlen($p_val)-1);
00109         }
00110         echo_debug('pcmn_update.php',__LINE__,"Ajout valeur = $p_val parent = $p_parent");
00111       }
00112       /* Parent existe */
00113       $Ret=ExecSql($cn,"select pcm_val from tmp_pcmn where pcm_val=$p_parent");
00114       if ( pg_NumRows($Ret) == 0 ) {
00115         echo '<SCRIPT> alert(" Ne peut pas modifier; aucune poste parent"); </SCRIPT>';
00116       } else {
00117         // Check if the account already exists
00118 
00119         $Count=CountSql($cn,"select * from tmp_pcmn where pcm_val='".$p_val."'");
00120         if ( $Count != 0 ) 
00121           {
00122             // Alert message account already exists
00123             echo '<SCRIPT> alert(" Ce poste existe déjà "); </SCRIPT>';
00124 
00125           } else 
00126             {
00127               $Ret=ExecSql($cn,"insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent) values ('$p_val','$p_lib',$p_parent)");
00128             }
00129       }
00130     } else {
00131       echo '<H2 class="error"> Valeurs invalides </H3>';
00132     }
00133   }
00134 }
00135 
00136 $Ret=ExecSql($cn,"select pcm_val,pcm_lib,pcm_val_parent from tmp_pcmn where substr(pcm_val::text,1,1)='".$_SESSION['g_start']."' order by pcm_val::text");
00137 $MaxRow=pg_NumRows($Ret);
00138 
00139 ?>
00140 
00141 <FORM ACTION="pcmn_update.php" METHOD="POST">
00142 <TABLE ALIGN="center" BORDER=0 CELLPADDING=0 CELLSPACING=0> 
00143 <TR>
00144 <TH> Classe </TH>
00145 <TH> Libellé </TH>
00146 <TH> Parent </TH>
00147 </TR>
00148 <TR>
00149 <TD>
00150 <INPUT TYPE="TEXT" NAME="p_val" SIZE=7>
00151 </TD>
00152 <TD>
00153 <INPUT TYPE="TEXT" NAME="p_lib" size=50>
00154 </TD>
00155 <TD>
00156 <INPUT TYPE="TEXT" NAME="p_parent" size=5>
00157 </TD>
00158 <TD>
00159 <INPUT TYPE="SUBMIT" Value="Add" Name="Add">
00160 </TD>
00161 </TR>
00162 <?
00163 for ($i=0; $i <$MaxRow; $i++) {
00164   $A=pg_fetch_array($Ret,$i);
00165 
00166   if ( $i%2 == 0 ) {
00167     $td ='<TD class="odd">';
00168   } else {
00169     $td='<TD class="even">';
00170   }
00171   echo "<TR> $td";
00172   echo $A['pcm_val'];
00173 
00174   echo "</td> $td";
00175   //  printf ("<A HREF=line_update.php?l=%d&n=%s&p=%s>",$A['pcm_val'],urlencode($A['pcm_lib']),$A['pcm_val_parent']);
00176   printf ("<A HREF=\"javascript:PcmnUpdate(%d,'%s','%s','%s')\">",
00177           $A['pcm_val'],
00178           FormatString($A['pcm_lib']),
00179           $A['pcm_val_parent'],
00180           $_REQUEST['PHPSESSID']);
00181   echo $A['pcm_lib'];
00182   echo '</A>';
00183   echo "</TD>";
00184 
00185   echo $td;
00186   echo $A['pcm_val_parent'];
00187   echo '</TD>';
00188 
00189   echo $td;
00190   printf ('<A href="pcmn_update.php?l=%d&action=del">Delete</A>',$A['pcm_val']);
00191   echo "</TD>";
00192   
00193   echo "</TR>";
00194 }
00195 echo "</TABLE>";
00196 echo "</FORM>";
00197 echo "</DIV>";
00198 html_page_stop();
00199 ?>