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

ecrit_ouv.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 /* $Revision$ */
00024 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00025 include_once ("ac_common.php");
00026 require_once('class_widget.php');
00027 html_page_start($_SESSION['g_theme']);
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 include_once ("class_user.php");
00035 $cn=DbConnect($_SESSION['g_dossier']);
00036 $User=new cl_user($cn);
00037 $User->Check();
00038 
00039 include_once ("check_priv.php");
00040 
00041 include_once ("user_menu.php");
00042 echo '<div class="u_tmenu">';
00043 echo ShowMenuCompta($_SESSION['g_dossier'],"user_advanced.php");
00044 echo '</div>';
00045 // TODO : add a check for permission
00046 if ( $User->CheckAction($cn,EXP_IMP_ECR) == 0 ) {
00047   /* Cannot Access */
00048   NoAccess();
00049   exit -1;                      
00050  }
00051 
00052 echo ShowMenuAdvanced("ecrit_ouv.php");
00053 echo '<div class="lmenu">';
00054 
00055 echo ShowItem ( array (
00056                         array ("ecrit_ouv.php?export","Export"),
00057                         array ("ecrit_ouv.php?import","Import")
00058                         ),'V');
00059 echo '</div>';
00060 echo '<div class="redcontent">';
00062 if ( isset ($_GET['export'])) {
00063 // if the year is not set, ask it
00064         // ask the exercice and do the export
00065         $periode=make_array($cn,"select distinct p_exercice,p_exercice from parm_periode order by p_exercice");
00066         echo '<form method="GET" ACTION="export_ouv.php">';
00067         $w=new widget('select');
00068         $w->table=0;
00069         $w->label='Periode';
00070         $w->readonly=false;
00071         $w->value=$periode;
00072         $w->name="p_periode";
00073         echo 'P&eacute;riode : '.$w->IOValue();
00074         echo $w->Submit('export','Export');
00075         echo "</form>";
00076         exit(0);
00077 }
00079 if ( isset ($_GET['import'])) {
00080         // show a form to upload the file
00081         // that form will parse the file, create an ods operation
00082         // and ask you to validate it
00083   // if no file is given
00084   if ( ! isset ($_REQUEST['p_submit']) ) {
00085 ?>
00086 <FORM NAME="form_detail" enctype="multipart/form-data" ACTION="ecrit_ouv.php?import" METHOD="POST">
00087 <?
00088   // TODO propose  ODS ledger 
00089   $ods=make_array($cn,"select jrn_def_id,jrn_def_name from jrn_def where jrn_def_type = 'OD'");
00090   $x=new widget("select");
00091   $x->name='p_jrn';
00092   $x->value=$ods;
00093   echo "Choississez votre journal ".$x->IOValue();
00094 
00095         $w=new widget("file");
00096   $w->name='import_file';
00097   $w->label='p_file';
00098   echo $w->IOValue();
00099   echo $w->Submit('p_submit','Charger le fichier');
00100 ?>
00101 </FORM>
00102 <?
00103         exit(0);
00104   } else { 
00105     require_once("user_form_ods.php");
00106     require_once("jrn.php");
00107     // a file is given, so we upload it
00108     $new_name=tempnam('/tmp','import');
00109     if ( strlen ( $_FILES['import_file']['tmp_name']) != 0 ) {
00110       if ( move_uploaded_file($_FILES['import_file']['tmp_name'],$new_name) ) {
00111         // upload succeed
00112         $h_file=fopen($new_name,'r') ;
00113         // test if the file is opened
00114         if ( $h_file == false) { echo 'Je ne peux ouvrir pas ce fichier';exit(-1);}
00115         // Analyze the file and store result into array
00116         $valid=false;
00117         $idx=0;
00118         while ( !feof($h_file) ) {
00119 
00120           $line=fgets($h_file);
00121           // check if the first line contains the signature
00122           if ( $valid  ) {
00123             // skip blank line
00124             if (strlen (trim($line)) == 0 ) continue;
00125             // put the line into an array
00126             list($sign,$poste,$amount)=explode(";",$line);
00127             $asign[$idx]=$sign; $aposte[$idx]=$poste;$aamount[$idx]=$amount;
00128             $idx++;
00129             }
00130           $valid=(($line=="OUVERTURE\n" && $valid==false) || $valid)?true:false;
00131           
00132         } // read the file
00133         // if valid is still false then there is nothing to do
00134         if ( ! $valid) { echo 'Aucun enregistrement valide'; return ;}
00135         // compose the array for the function FormODS
00136         $array_ods['e_comm']='Ecriture d\'ouverture';
00137         for ($i=0;$i<$idx;$i++) {
00138                 $n="e_account$i";
00139                 $array_ods[$n]=$aposte[$i];
00140                 $n="e_account".$i."_type";
00141                 $array_ods[$n]=$asign[$i];
00142                 $n="e_account".$i."_amount";
00143                 $array_ods[$n]=$aamount[$i];
00144         }
00145         
00146         // submit button in the form    
00147         $submit='<INPUT TYPE="SUBMIT" NAME="add_item" VALUE="Ajout Poste">
00148                     <INPUT TYPE="SUBMIT" NAME="view_invoice" VALUE="Sauver">';
00149          $r=FormODS($cn,$_POST['p_jrn'],$User->GetPeriode(),$submit,
00150                         $array_ods,false,$idx,$p_saved=false);
00151         
00152           echo $r;
00153           echo "<div><h4>On-line calculator</h4>".JS_CALC_LINE."<div>";
00154         
00155       } 
00156     }
00157   } // else -> a file is given
00158  }// if import
00159 // IF import and export are not set then the choice is proposed
00160 echo '</div>';
00161 html_page_stop(); 
00162 ?>

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