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

fiche_new.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 // Auteur Dany De Bontridder ddebontridder@yahoo.fr
00020 include_once ("ac_common.php");
00021 include_once ("postgres.php");
00022 include_once ("check_priv.php");
00027 /* $Revision: 1.14 $ */
00028 /* Admin. Dossier */
00029 $rep=DbConnect();
00030 include_once ("class_user.php");
00031 $User=new cl_user($rep);
00032 $User->Check();
00033 
00034 html_page_start($User->theme,"onLoad='window.focus();'");
00035 
00036 if ( ! isset ( $_SESSION['g_dossier'] ) ) {
00037   echo "You must choose a Dossier ";
00038   exit -2;
00039 }
00040 
00041 $cn=DbConnect($_SESSION['g_dossier']);
00042 // TODO add security here
00043 // Get The priv on the selected folder
00044 if ( $User->CheckAction($cn,FICHE_WRITE)== 0) {
00045     /* Cannot Access */
00046     echo '<h2 class="error"> Vous  ne pouvez pas ajouter de fiche</h2>';
00047     return;
00048 }
00049 
00050 include_once("fiche_inc.php");
00051 
00052 
00053 foreach ($HTTP_GET_VARS as $key=>$element) {
00054   // The value are e_name e_type e_PHPSESSID
00055   ${"e_$key"}=$element;
00056   echo_debug('fiche_new.php',__LINE__,"e_$key =$element<br>");
00057 
00058 }
00059 
00060 function new_fiche($p_cn,$p_type) {
00061   $ch_col="</TD><TD>";
00062   $ch_li='</TR><TR>';
00063   $r='<FORM action="fiche_new.php" method="post">';
00064   $r.='<INPUT TYPE="HIDDEN" name="fiche" value="'.$p_type.'">';
00065   $l_sessid=(isset ($_POST["PHPSESSID"]))?$_POST["PHPSESSID"]:$_GET["PHPSESSID"];
00066 
00067   $r.=JS_SHOW_TVA;
00068   $r.=JS_SEARCH_POSTE;
00069   $r.="<TABLE>";
00070   echo '<H2 class="info">New </H2>';
00071   $p_f_id="";
00072   echo_debug('fiche_new.php',__LINE__,"Array is null");
00073   // Find all the attribute of the existing cards
00074   // --> Get_attr_def 
00075     $sql="select frd_id,ad_id,ad_text from  fiche_def join jnt_fic_attr using (fd_id)
00076            join attr_def using (ad_id) where fd_id=".$p_type." order by ad_id";
00077 
00078     $Res=ExecSql($p_cn,$sql);
00079     $Max=pg_NumRows($Res);
00080     // Put the card modele id (fiche_def.fd_id)
00081     $r.='<INPUT TYPE="HIDDEN" name="fd_id" value="'.$p_type.'">';
00082     for ($i=0;$i < $Max;$i++) {
00083       $l_line=pg_fetch_array($Res,$i);
00084 
00085       // The number of the attribute
00086       $Hid=sprintf('<INPUT TYPE="HIDDEN" name="ad_id%d" value="%s">',
00087                    $i,$l_line['ad_id']);
00088 
00089       $but_search_poste="";
00090       // Javascript for searching the account
00091       if ( $l_line ['ad_id'] == ATTR_DEF_ACCOUNT ) {
00092         $but_search_poste='<INPUT TYPE="BUTTON" VALUE="Cherche" OnClick="SearchPoste(\''.$l_sessid.'\',\'av_text'.$i.'\')">';
00093       } 
00094       // Javascript for showing the tva
00095       if ( $l_line ['ad_id'] == ATTR_DEF_TVA ) {
00096         $but_search_poste='<INPUT TYPE="BUTTON" VALUE="Montre" OnClick="ShowTva(\''.$l_sessid.'\',\'av_text'.$i.'\')">';
00097       }
00098       // content of the attribute
00099       $r.= sprintf('<TR><TD> %s </TD><TD><INPUT TYPE="TEXT" NAME="av_text%d">%s %s</TD></TR>',
00100               $l_line['ad_text'], $i,$Hid,$but_search_poste);
00101    }  
00102     $r.="</TABLE>";
00103     $r.='<INPUT TYPE="SUBMIT" name="add_fiche" value="Mis à jour">';
00104     $r.= '<INPUT TYPE="HIDDEN" name="inc" value="'.$Max.'">';
00105     $r.='</FORM>';
00106     return $r;
00107 }
00108 if ( isset($_POST['add_fiche'])) {
00109   AddFiche($cn,$_POST["fiche"],$HTTP_POST_VARS);
00110 ?>
00111 <SCRIPT>
00112 
00113   window.close();
00114 </SCRIPT>
00115 <?
00116     return;
00117 }
00118 // Prob : ajout de fiche mais si plusieur cat possible ???
00119  // Get the field from database
00120   // if e_type contains a list of value
00121   if ( $e_type != 'cred' and $e_type != 'deb')     {
00122     //    $list['fiche']=$e_type;
00123     $sql="select fd_id from fiche_def where frd_id in ($e_type)";
00124     $Res=ExecSql($cn,$sql);
00125     // fetch it
00126     $Max=pg_NumRows($Res);
00127     if ( $Max==0) {
00128       echo_warning("No rows");
00129     exit();
00130     }
00131     $n=pg_NumRows($Res);
00132     for ($i=0;$i <$n;$i++) {
00133       $f=pg_fetch_array($Res,$i);
00134       $e[$i]=$f['fd_id'];
00135     }
00136     $list['fiche']=join(',',$e);
00137   } else { // We have to find it from the database
00138     if ( $e_type == 'deb' ) {
00139       $get='jrn_def_fiche_deb';
00140       $sql="select $get as fiche from jrn_def where jrn_def_id=".$_GET['p_jrn'];
00141     }
00142     if ( $e_type == 'cred' ) {
00143       $get='jrn_def_fiche_cred';
00144     $sql="select $get as fiche from jrn_def where jrn_def_id=".$_GET['p_jrn'];
00145     }
00146     
00147     
00148 
00149     $Res=ExecSql($cn,$sql);
00150     
00151   // fetch it
00152     $Max=pg_NumRows($Res);
00153     if ( $Max==0) {
00154       echo_warning("No rows");
00155     exit();
00156     }
00157     // Normally Max must be == 1
00158     $list=pg_fetch_array($Res,0);
00159     if ( $list['fiche']=="") {
00160       echo_warning("Journal mal paramètré");
00161       return;
00162     }
00163   }
00164 
00165 
00166 // Compter le nombre de cat. possible
00167 $a=explode(",",$list['fiche']);
00168 
00169 // sinon si cat = 1 ou si var. cat vaut qq chose
00170 // Montrer le contenu de fiche
00171 if ( sizeof($a) == 1 ) {
00172   if ( strlen(trim($a[0])) != 0)
00173  // Display a blank  card from the selected category
00174         $f=new_fiche($cn,$a[0]);
00175   echo $f;
00176 }
00177  
00178 if ( isset($_POST['cat'])) {
00179         $f=new_fiche($cn,$_POST['cat']);
00180         echo $f;
00181 }
00182 
00183 // si cat > 1 proposer choix cat
00184 //      recharger avec var. cat
00185 if ( sizeof($a)>1 and !isset ($_POST['cat']))
00186   {
00187     echo "Choix catégories fiche";
00188     echo '<FORM METHOD="POST" ACTION="'.$_SERVER['REQUEST_URI'].'">';
00189     foreach ($a as $element) {
00190       printf('<INPUT TYPE="RADIO" NAME="cat" value="%s">%s<br>',
00191              $element,GetFicheDefName($cn,$element));
00192     
00193   }
00194     echo '<INPUT TYPE="SUBMIT" value="Choisir">';
00195     echo "<FORM>";
00196   }
00197 ?>