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$ */
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   if ( $_GET['action']=="del" ) {
00074     if ( isset ($_GET['l']) ) {
00075       /* Ligne a enfant*/
00076       $R=ExecSql($cn,"select pcm_val from tmp_pcmn where pcm_val_parent=".$_GET['l']);
00077       if ( pg_NumRows($R) != 0 ) {
00078         echo "<SCRIPT> alert(\"Ne peut pas effacer le poste: d'autres postes en dépendent\");</SCRIPT>";
00079       } else {
00080         /* Vérifier que le poste n'est pas utilisé qq part dans les journaux */
00081         $Res=ExecSql($cn,"select * from jrnx where j_poste=".$_GET['l']);
00082         if ( pg_NumRows($R) != 0 ) {
00083           echo "<SCRIPT> alert(\"Ne peut pas effacer le poste: il est utilisé dans les journaux\");</SCRIPT>";
00084         }
00085         else {
00086           $Del=ExecSql($cn,"delete from tmp_pcmn where pcm_val=".$_GET['l']);
00087         } // if pg_NumRows
00088       } // if pg_NumRows
00089     } // isset ($l)
00090   } //$action == del
00091 } // isset action
00092 /* Ajout d'une ligne */
00093 if ( isset ( $_POST["Add"] ) ) {
00094         extract ($_POST);
00095   if ( isset ( $p_val) && isset ( $p_lib ) ) {
00096     $p_val=trim($p_val);
00097     $p_lib=FormatString(trim($p_lib));
00098     $p_parent=$_POST["p_parent"];
00099     if ( strlen ($p_val) != 0 && strlen ($p_lib) != 0 ) {
00100       if (strlen ($p_val) == 1 ) {
00101         $p_parent=0;
00102       } else {
00103         if ( strlen(trim($p_parent))==0 && 
00104              (string) $p_parent != (string)(int) $p_parent) {
00105           $p_parent=substr($p_val,0,strlen($p_val)-1);
00106         }
00107         echo_debug('pcmn_update.php',__LINE__,"Ajout valeur = $p_val parent = $p_parent");
00108       }
00109       /* Parent existe */
00110       $Ret=ExecSql($cn,"select pcm_val from tmp_pcmn where pcm_val=$p_parent");
00111       if ( pg_NumRows($Ret) == 0 ) {
00112         echo '<SCRIPT> alert(" Ne peut pas modifier; aucune poste parent"); </SCRIPT>';
00113       } else {
00114         $Ret=ExecSql($cn,"insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent) values ('$p_val','$p_lib',$p_parent)");
00115       }
00116     } else {
00117       echo '<H2 class="error"> Valeurs invalides </H3>';
00118     }
00119   }
00120 }
00121 
00122 $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");
00123 $MaxRow=pg_NumRows($Ret);
00124 
00125 ?>
00126 
00127 <FORM ACTION="pcmn_update.php" METHOD="POST">
00128 <TABLE ALIGN="center" BORDER=0 CELLPADDING=0 CELLSPACING=0> 
00129 <TR>
00130 <TH> Classe </TH>
00131 <TH> Libellé </TH>
00132 <TH> Parent </TH>
00133 </TR>
00134 <TR>
00135 <TD>
00136 <INPUT TYPE="TEXT" NAME="p_val" SIZE=7>
00137 </TD>
00138 <TD>
00139 <INPUT TYPE="TEXT" NAME="p_lib" size=50>
00140 </TD>
00141 <TD>
00142 <INPUT TYPE="TEXT" NAME="p_parent" size=5>
00143 </TD>
00144 <TD>
00145 <INPUT TYPE="SUBMIT" Value="Add" Name="Add">
00146 </TD>
00147 </TR>
00148 <?
00149 for ($i=0; $i <$MaxRow; $i++) {
00150   $A=pg_fetch_array($Ret,$i);
00151 
00152   if ( $i%2 == 0 ) {
00153     $td ='<TD class="odd">';
00154   } else {
00155     $td='<TD class="even">';
00156   }
00157   echo "<TR> $td";
00158   echo $A['pcm_val'];
00159 
00160   echo "</td> $td";
00161   //  printf ("<A HREF=line_update.php?l=%d&n=%s&p=%s>",$A['pcm_val'],urlencode($A['pcm_lib']),$A['pcm_val_parent']);
00162   printf ("<A HREF=\"javascript:PcmnUpdate(%d,'%s','%s','%s')\">",
00163           $A['pcm_val'],
00164           FormatString($A['pcm_lib']),
00165           $A['pcm_val_parent'],
00166           $_REQUEST['PHPSESSID']);
00167   echo $A['pcm_lib'];
00168   echo '</A>';
00169   echo "</TD>";
00170 
00171   echo $td;
00172   echo $A['pcm_val_parent'];
00173   echo '</TD>';
00174 
00175   echo $td;
00176   printf ('<A href="pcmn_update.php?l=%d&action=del">Delete</A>',$A['pcm_val']);
00177   echo "</TD>";
00178   
00179   echo "</TR>";
00180 }
00181 echo "</TABLE>";
00182 echo "</FORM>";
00183 echo "</DIV>";
00184 html_page_stop();
00185 ?>

Generated on Fri Jun 23 00:12:45 2006 for phpcompta by  doxygen 1.4.4