altocompta/doc/developper/html/ecrit__ouv_8php-source.html

170 lines
19 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>phpcompta: /home/dany/developpement/phpcompta-dev/phpcompta/html/ecrit_ouv.php Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.4 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
<div class="nav">
<a class="el" href="dir_000000.html">developpement</a>&nbsp;&raquo&nbsp;<a class="el" href="dir_000001.html">phpcompta-dev</a>&nbsp;&raquo&nbsp;<a class="el" href="dir_000002.html">phpcompta</a>&nbsp;&raquo&nbsp;<a class="el" href="dir_000003.html">html</a></div>
<h1>ecrit_ouv.php</h1><a href="ecrit__ouv_8php.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 &lt;?
<a name="l00002"></a>00002 <span class="comment">/*</span>
<a name="l00003"></a>00003 <span class="comment"> * This file is part of PhpCompta.</span>
<a name="l00004"></a>00004 <span class="comment"> *</span>
<a name="l00005"></a>00005 <span class="comment"> * PhpCompta is free software; you can redistribute it and/or modify</span>
<a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
<a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
<a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
<a name="l00009"></a>00009 <span class="comment"> *</span>
<a name="l00010"></a>00010 <span class="comment"> * PhpCompta is distributed in the hope that it will be useful,</span>
<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span>
<a name="l00014"></a>00014 <span class="comment"> *</span>
<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
<a name="l00016"></a>00016 <span class="comment"> * along with PhpCompta; if not, write to the Free Software</span>
<a name="l00017"></a>00017 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span>
<a name="l00018"></a>00018 <span class="comment">*/</span>
<a name="l00019"></a>00019 <span class="comment">/* $Revision$ */</span>
<a name="l00024"></a>00024 <span class="comment">// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr</span>
<a name="l00025"></a>00025 include_once (<span class="stringliteral">"ac_common.php"</span>);
<a name="l00026"></a>00026 require_once('class_widget.php');
<a name="l00027"></a>00027 <a class="code" href="ac__common_8php.html#a5">html_page_start</a>($_SESSION['g_theme']);
<a name="l00028"></a>00028 <span class="keywordflow">if</span> ( ! isset ( $_SESSION['g_dossier'] ) ) {
<a name="l00029"></a>00029 echo <span class="stringliteral">"You must choose a Dossier "</span>;
<a name="l00030"></a>00030 <a class="code" href="balance_8php.html#a0">exit</a> -2;
<a name="l00031"></a>00031 }
<a name="l00032"></a>00032 include_once (<span class="stringliteral">"postgres.php"</span>);
<a name="l00033"></a>00033 <span class="comment">/* Admin. Dossier */</span>
<a name="l00034"></a>00034 include_once (<span class="stringliteral">"class_user.php"</span>);
<a name="l00035"></a><a class="code" href="ecrit__ouv_8php.html#a0">00035</a> <a class="code" href="impress__fiche_8php.html#a0">$cn</a>=<a class="code" href="postgres_8php.html#a1">DbConnect</a>($_SESSION['g_dossier']);
<a name="l00036"></a><a class="code" href="ecrit__ouv_8php.html#a1">00036</a> <a class="code" href="user__action__ach_8php.html#a9">$User</a>=<span class="keyword">new</span> <a class="code" href="classcl__user.html">cl_user</a>($cn);
<a name="l00037"></a>00037 <a class="code" href="user__action__ach_8php.html#a9">$User</a>-&gt;Check();
<a name="l00038"></a>00038
<a name="l00039"></a>00039 include_once (<span class="stringliteral">"check_priv.php"</span>);
<a name="l00040"></a>00040
<a name="l00041"></a>00041 include_once (<span class="stringliteral">"user_menu.php"</span>);
<a name="l00042"></a>00042 echo '&lt;div <span class="keyword">class</span>=<span class="stringliteral">"u_tmenu"</span>&gt;';
<a name="l00043"></a>00043 echo <a class="code" href="user__menu_8php.html#a3">ShowMenuCompta</a>($_SESSION['g_dossier'],<span class="stringliteral">"user_advanced.php"</span>);
<a name="l00044"></a>00044 echo '&lt;/div&gt;';
<a name="l00045"></a>00045 <span class="comment">// TODO : add a check for permission</span>
<a name="l00046"></a>00046 <span class="keywordflow">if</span> ( $User-&gt;CheckAction($cn,<a class="code" href="constant_8php.html#a22">EXP_IMP_ECR</a>) == 0 ) {
<a name="l00047"></a>00047 <span class="comment">/* Cannot Access */</span>
<a name="l00048"></a>00048 <a class="code" href="ac__common_8php.html#a8">NoAccess</a>();
<a name="l00049"></a><a class="code" href="ecrit__ouv_8php.html#a2">00049</a> <a class="code" href="balance_8php.html#a0">exit</a> -1;
<a name="l00050"></a>00050 }
<a name="l00051"></a>00051
<a name="l00052"></a>00052 echo <a class="code" href="user__menu_8php.html#a9">ShowMenuAdvanced</a>(<span class="stringliteral">"ecrit_ouv.php"</span>);
<a name="l00053"></a>00053 echo '&lt;div <span class="keyword">class</span>=<span class="stringliteral">"lmenu"</span>&gt;';
<a name="l00054"></a>00054
<a name="l00055"></a>00055 echo <a class="code" href="ac__common_8php.html#a10">ShowItem</a> ( array (
<a name="l00056"></a>00056 array (<span class="stringliteral">"ecrit_ouv.php?export"</span>,<span class="stringliteral">"Export"</span>),
<a name="l00057"></a>00057 array (<span class="stringliteral">"ecrit_ouv.php?import"</span>,<span class="stringliteral">"Import"</span>)
<a name="l00058"></a>00058 ),<span class="charliteral">'V'</span>);
<a name="l00059"></a>00059 echo '&lt;/div&gt;';
<a name="l00060"></a>00060 echo '&lt;div <span class="keyword">class</span>=<span class="stringliteral">"redcontent"</span>&gt;';
<a name="l00062"></a>00062 <span class="keywordflow">if</span> ( isset ($_GET['export'])) {
<a name="l00063"></a>00063 <span class="comment">// if the year is not set, ask it</span>
<a name="l00064"></a>00064 <span class="comment">// ask the exercice and do the export</span>
<a name="l00065"></a>00065 $periode=<a class="code" href="ac__common_8php.html#a12">make_array</a>($cn,<span class="stringliteral">"select distinct p_exercice,p_exercice from parm_periode order by p_exercice"</span>);
<a name="l00066"></a>00066 echo '&lt;form method=<span class="stringliteral">"GET"</span> ACTION=<span class="stringliteral">"export_ouv.php"</span>&gt;';
<a name="l00067"></a><a class="code" href="ecrit__ouv_8php.html#a3">00067</a> <a class="code" href="balance_8php.html#a2">$w</a>=<span class="keyword">new</span> <a class="code" href="classwidget.html">widget</a>('select');
<a name="l00068"></a><a class="code" href="ecrit__ouv_8php.html#a4">00068</a> <a class="code" href="balance_8php.html#a2">$w</a>-&gt;table=0;
<a name="l00069"></a><a class="code" href="ecrit__ouv_8php.html#a5">00069</a> <a class="code" href="balance_8php.html#a2">$w</a>-&gt;label='Periode';
<a name="l00070"></a><a class="code" href="ecrit__ouv_8php.html#a6">00070</a> <a class="code" href="balance_8php.html#a2">$w</a>-&gt;readonly=<span class="keyword">false</span>;
<a name="l00071"></a><a class="code" href="ecrit__ouv_8php.html#a7">00071</a> <a class="code" href="balance_8php.html#a2">$w</a>-&gt;value=$periode;
<a name="l00072"></a><a class="code" href="ecrit__ouv_8php.html#a8">00072</a> <a class="code" href="balance_8php.html#a2">$w</a>-&gt;name=<span class="stringliteral">"p_periode"</span>;
<a name="l00073"></a>00073 echo 'P&amp;eacute;riode : '.$w-&gt;IOValue();
<a name="l00074"></a>00074 echo <a class="code" href="balance_8php.html#a2">$w</a>-&gt;Submit('export<span class="charliteral">','</span>Export');
<a name="l00075"></a>00075 echo <span class="stringliteral">"&lt;/form&gt;"</span>;
<a name="l00076"></a>00076 <a class="code" href="balance_8php.html#a0">exit</a>(0);
<a name="l00077"></a>00077 }
<a name="l00079"></a>00079 <span class="keywordflow">if</span> ( isset ($_GET['<span class="keyword">import</span>'])) {
<a name="l00080"></a>00080 <span class="comment">// show a form to upload the file</span>
<a name="l00081"></a>00081 <span class="comment">// that form will parse the file, create an ods operation</span>
<a name="l00082"></a>00082 <span class="comment">// and ask you to validate it</span>
<a name="l00083"></a>00083 <span class="comment">// if no file is given</span>
<a name="l00084"></a>00084 <span class="keywordflow">if</span> ( ! isset ($_REQUEST['p_submit']) ) {
<a name="l00085"></a>00085 ?&gt;
<a name="l00086"></a>00086 &lt;<a class="code" href="constant_8php.html#a7">FORM</a> NAME=<span class="stringliteral">"form_detail"</span> enctype=<span class="stringliteral">"multipart/form-data"</span> ACTION=<span class="stringliteral">"ecrit_ouv.php?import"</span> <a class="code" href="pref_8inc_8php.html#a0">METHOD</a>=<span class="stringliteral">"POST"</span>&gt;
<a name="l00087"></a>00087 &lt;?
<a name="l00088"></a>00088 <span class="comment">// TODO propose ODS ledger </span>
<a name="l00089"></a>00089 $ods=<a class="code" href="ac__common_8php.html#a12">make_array</a>($cn,<span class="stringliteral">"select jrn_def_id,jrn_def_name from jrn_def where jrn_def_type = 'OD'"</span>);
<a name="l00090"></a><a class="code" href="ecrit__ouv_8php.html#a9">00090</a> <a class="code" href="ecrit__ouv_8php.html#a9">$x</a>=<span class="keyword">new</span> <a class="code" href="classwidget.html">widget</a>(<span class="stringliteral">"select"</span>);
<a name="l00091"></a>00091 <a class="code" href="ecrit__ouv_8php.html#a9">$x</a>-&gt;name='p_jrn';
<a name="l00092"></a>00092 <a class="code" href="ecrit__ouv_8php.html#a9">$x</a>-&gt;value=$ods;
<a name="l00093"></a>00093 echo <span class="stringliteral">"Choississez votre journal "</span>.$x-&gt;IOValue();
<a name="l00094"></a>00094
<a name="l00095"></a>00095 <a class="code" href="balance_8php.html#a2">$w</a>=<span class="keyword">new</span> <a class="code" href="classwidget.html">widget</a>(<span class="stringliteral">"file"</span>);
<a name="l00096"></a>00096 <a class="code" href="balance_8php.html#a2">$w</a>-&gt;name='import_file';
<a name="l00097"></a>00097 <a class="code" href="balance_8php.html#a2">$w</a>-&gt;label='p_file';
<a name="l00098"></a>00098 echo <a class="code" href="balance_8php.html#a2">$w</a>-&gt;IOValue();
<a name="l00099"></a>00099 echo <a class="code" href="balance_8php.html#a2">$w</a>-&gt;Submit('p_submit<span class="charliteral">','</span>Charger le fichier');
<a name="l00100"></a>00100 ?&gt;
<a name="l00101"></a>00101 &lt;/<a class="code" href="constant_8php.html#a7">FORM</a>&gt;
<a name="l00102"></a>00102 &lt;?
<a name="l00103"></a>00103 <a class="code" href="balance_8php.html#a0">exit</a>(0);
<a name="l00104"></a>00104 } <span class="keywordflow">else</span> {
<a name="l00105"></a>00105 require_once(<span class="stringliteral">"user_form_ods.php"</span>);
<a name="l00106"></a>00106 require_once(<span class="stringliteral">"jrn.php"</span>);
<a name="l00107"></a>00107 <span class="comment">// a file is given, so we upload it</span>
<a name="l00108"></a>00108 $new_name=tempnam('/tmp<span class="charliteral">','</span><span class="keyword">import</span>');
<a name="l00109"></a>00109 <span class="keywordflow">if</span> ( strlen ( $_FILES['import_file']['tmp_name']) != 0 ) {
<a name="l00110"></a>00110 <span class="keywordflow">if</span> ( move_uploaded_file($_FILES['import_file']['tmp_name'],$new_name) ) {
<a name="l00111"></a>00111 <span class="comment">// upload succeed</span>
<a name="l00112"></a>00112 $h_file=fopen($new_name,<span class="charliteral">'r'</span>) ;
<a name="l00113"></a>00113 <span class="comment">// test if the file is opened</span>
<a name="l00114"></a>00114 <span class="keywordflow">if</span> ( $h_file == <span class="keyword">false</span>) { echo 'Je ne peux ouvrir pas ce fichier';<a class="code" href="balance_8php.html#a0">exit</a>(-1);}
<a name="l00115"></a>00115 <span class="comment">// Analyze the file and store result into array</span>
<a name="l00116"></a>00116 $valid=<span class="keyword">false</span>;
<a name="l00117"></a>00117 <a class="code" href="fiche__def_8inc_8php.html#a7">$idx</a>=0;
<a name="l00118"></a>00118 <span class="keywordflow">while</span> ( !feof($h_file) ) {
<a name="l00119"></a>00119
<a name="l00120"></a>00120 $line=fgets($h_file);
<a name="l00121"></a>00121 <span class="comment">// check if the first line contains the signature</span>
<a name="l00122"></a>00122 <span class="keywordflow">if</span> ( $valid ) {
<a name="l00123"></a>00123 <span class="comment">// skip blank line</span>
<a name="l00124"></a>00124 <span class="keywordflow">if</span> (strlen (trim($line)) == 0 ) <span class="keywordflow">continue</span>;
<a name="l00125"></a>00125 <span class="comment">// put the line into an array</span>
<a name="l00126"></a>00126 list($sign,$<a class="code" href="classposte.html">poste</a>,$amount)=explode(<span class="stringliteral">";"</span>,$line);
<a name="l00127"></a>00127 $asign[<a class="code" href="fiche__def_8inc_8php.html#a7">$idx</a>]=$sign; $aposte[<a class="code" href="fiche__def_8inc_8php.html#a7">$idx</a>]=<a class="code" href="send__poste__pdf_8php.html#a2">$poste</a>;$aamount[<a class="code" href="fiche__def_8inc_8php.html#a7">$idx</a>]=<a class="code" href="print__invoice_8php.html#a1">$amount</a>;
<a name="l00128"></a>00128 <a class="code" href="fiche__def_8inc_8php.html#a7">$idx</a>++;
<a name="l00129"></a>00129 }
<a name="l00130"></a>00130 $valid=(($line==<span class="stringliteral">"OUVERTURE\n"</span> &amp;&amp; $valid==<span class="keyword">false</span>) || $valid)?<span class="keyword">true</span>:<span class="keyword">false</span>;
<a name="l00131"></a>00131
<a name="l00132"></a>00132 } <span class="comment">// read the file</span>
<a name="l00133"></a>00133 <span class="comment">// if valid is still false then there is nothing to do</span>
<a name="l00134"></a>00134 <span class="keywordflow">if</span> ( ! $valid) { echo 'Aucun enregistrement valide'; <a class="code" href="impress__listing__client_8php.html#a2">return</a> ;}
<a name="l00135"></a>00135 <span class="comment">// compose the array for the function FormODS</span>
<a name="l00136"></a>00136 $array_ods['e_comm']='Ecriture d\'ouverture';
<a name="l00137"></a>00137 <span class="keywordflow">for</span> ($i=0;$i&lt;$idx;$i++) {
<a name="l00138"></a>00138 <a class="code" href="fiche__new_8php.html#a5">$n</a>=<span class="stringliteral">"e_account$i"</span>;
<a name="l00139"></a>00139 $array_ods[<a class="code" href="fiche__new_8php.html#a5">$n</a>]=$aposte[<a class="code" href="balance_8php.html#a11">$i</a>];
<a name="l00140"></a>00140 <a class="code" href="fiche__new_8php.html#a5">$n</a>=<span class="stringliteral">"e_account"</span>.$i.<span class="stringliteral">"_type"</span>;
<a name="l00141"></a>00141 $array_ods[<a class="code" href="fiche__new_8php.html#a5">$n</a>]=$asign[<a class="code" href="balance_8php.html#a11">$i</a>];
<a name="l00142"></a>00142 <a class="code" href="fiche__new_8php.html#a5">$n</a>=<span class="stringliteral">"e_account"</span>.$i.<span class="stringliteral">"_amount"</span>;
<a name="l00143"></a>00143 $array_ods[<a class="code" href="fiche__new_8php.html#a5">$n</a>]=$aamount[<a class="code" href="balance_8php.html#a11">$i</a>];
<a name="l00144"></a>00144 }
<a name="l00145"></a>00145
<a name="l00146"></a>00146 <span class="comment">// submit button in the form </span>
<a name="l00147"></a>00147 <a class="code" href="impress__fiche_8php.html#a1">$submit</a>='&lt;INPUT TYPE=<span class="stringliteral">"SUBMIT"</span> NAME=<span class="stringliteral">"add_item"</span> VALUE=<span class="stringliteral">"Ajout Poste"</span>&gt;
<a name="l00148"></a>00148 &lt;INPUT TYPE=<span class="stringliteral">"SUBMIT"</span> NAME=<span class="stringliteral">"view_invoice"</span> VALUE=<span class="stringliteral">"Sauver"</span>&gt;';
<a name="l00149"></a>00149 <a class="code" href="user__action__ach_8php.html#a2">$r</a>=<a class="code" href="user__form__ods_8php.html#a0">FormODS</a>($cn,$_POST['p_jrn'],$User-&gt;GetPeriode(),<a class="code" href="impress__fiche_8php.html#a1">$submit</a>,
<a name="l00150"></a>00150 $array_ods,<span class="keyword">false</span>,<a class="code" href="fiche__def_8inc_8php.html#a7">$idx</a>,$p_saved=<span class="keyword">false</span>);
<a name="l00151"></a>00151
<a name="l00152"></a>00152 echo <a class="code" href="user__action__ach_8php.html#a2">$r</a>;
<a name="l00153"></a>00153 echo <span class="stringliteral">"&lt;div&gt;&lt;h4&gt;On-line calculator&lt;/h4&gt;"</span>.JS_CALC_LINE.<span class="stringliteral">"&lt;div&gt;"</span>;
<a name="l00154"></a>00154
<a name="l00155"></a>00155 }
<a name="l00156"></a>00156 }
<a name="l00157"></a>00157 } <span class="comment">// else -&gt; a file is given</span>
<a name="l00158"></a>00158 }<span class="comment">// if import</span>
<a name="l00159"></a>00159 <span class="comment">// IF import and export are not set then the choice is proposed</span>
<a name="l00160"></a>00160 echo '&lt;/div&gt;';
<a name="l00161"></a>00161 <a class="code" href="ac__common_8php.html#a6">html_page_stop</a>();
<a name="l00162"></a>00162 ?&gt;
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Fri Jun 23 00:12:45 2006 for phpcompta by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.4 </small></address>
</body>
</html>