00001 <?
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00024
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
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
00046 if ( $User->CheckAction($cn,EXP_IMP_ECR) == 0 ) {
00047
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
00064
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ériode : '.$w->IOValue();
00074 echo $w->Submit('export','Export');
00075 echo "</form>";
00076 exit(0);
00077 }
00079 if ( isset ($_GET['import'])) {
00080
00081
00082
00083
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
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
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
00112 $h_file=fopen($new_name,'r') ;
00113
00114 if ( $h_file == false) { echo 'Je ne peux ouvrir pas ce fichier';exit(-1);}
00115
00116 $valid=false;
00117 $idx=0;
00118 while ( !feof($h_file) ) {
00119
00120 $line=fgets($h_file);
00121
00122 if ( $valid ) {
00123
00124 if (strlen (trim($line)) == 0 ) continue;
00125
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 }
00133
00134 if ( ! $valid) { echo 'Aucun enregistrement valide'; return ;}
00135
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
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 }
00158 }
00159
00160 echo '</div>';
00161 html_page_stop();
00162 ?>