noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_acc_bilan.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of NOALYSS.
00004  *
00005  *   NOALYSS 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  *   NOALYSS 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 NOALYSS; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00021 
00022 /*!\file
00023  * \brief this class handle the different bilan, from the table bilan
00024  *
00025  */
00026 require_once("class_iselect.php");
00027 require_once ('class_database.php');
00028 require_once ('class_dossier.php');
00029 require_once ('class_impress.php');
00030 require_once ('header_print.php');
00031 require_once ('class_acc_account_ledger.php');
00032 
00033 /*!
00034  * \brief this class handle the different bilan, from the table bilan, parse the form and replace
00035  * in the template
00036  */
00037 class Acc_Bilan
00038 {
00039     var $db;                                            /*!< database connection */
00040     var $b_id;                                  /*!< id of the bilan (bilan.b_id) */
00041     var $from;                                  /*!< from periode */
00042     var $to;                                    /*!< end periode */
00043 
00044     function Acc_Bilan($p_cn)
00045     {
00046         $this->db=$p_cn;
00047     }
00048     /*!
00049      * \brief return a string with the form for selecting the periode and
00050      * the type of bilan
00051      * \param $p_filter_year filter on a year
00052      *
00053      * \return a string
00054      */
00055     function display_form($p_filter_year="")
00056     {
00057         $r="";
00058         $r.=dossier::hidden();
00059         $r.= '<TABLE>';
00060 
00061         $r.='<TR>';
00062 // filter on the current year
00063         $w=new ISelect();
00064         $w->table=1;
00065 
00066         $periode_start=$this->db->make_array("select p_id,to_char(p_start,'DD-MM-YYYY') from parm_periode $p_filter_year order by p_start,p_end");
00067 
00068         $periode_end=$this->db->make_array("select p_id,to_char(p_end,'DD-MM-YYYY') from parm_periode $p_filter_year order by p_end,p_start");
00069 
00070         $w->label=_("Depuis");
00071         $w->value=$this->from;
00072         $w->selected=$this->from;
00073         $r.= td($w->input('from_periode',$periode_start));
00074         $w->label=_(" jusque ");
00075         $w->value=$this->to;
00076         $w->selected=$this->to;
00077         $r.= td($w->input('to_periode',$periode_end));
00078         $r.= "</TR>";
00079         $r.="<tr>";
00080         $mod=new ISelect();
00081         $mod->table=1;
00082         $mod->value=$this->db->make_array("select b_id, b_name from bilan order by b_name");
00083         $mod->label=_("Choix du bilan");
00084         $r.=td($mod->input('b_id'));
00085         $r.="</tr>";
00086         $r.= '</TABLE>';
00087         return $r;
00088     }
00089     /*!\brief check and warn if an accound has the wrong saldo
00090      * \param $p_message legend of the fieldset
00091      * \param $p_type type of the Acccount ACT actif, ACTINV...
00092      * \param $p_type the saldo must debit or credit
00093      */
00094     private function warning($p_message,$p_type,$p_deb)
00095     {
00096         $sql="select pcm_val,pcm_lib from tmp_pcmn where pcm_type='$p_type'";
00097         $res=$this->db->exec_sql($sql);
00098         if ( Database::num_row($res) ==0 )
00099             return;
00100         $count=0;
00101         $nRow=Database::num_row($res);
00102 
00103         $ret="";
00104         $obj=new Acc_Account_Ledger($this->db,0);
00105         for ($i=0;$i<$nRow;$i++)
00106         {
00107 
00108             $line=Database::fetch_array($res,$i);
00109             /* set the periode filter */
00110             $sql=sql_filter_per($this->db,$this->from,$this->to,'p_id','j_tech_per');
00111             $obj->id=$line['pcm_val'];
00112 
00113             $solde=$obj->get_solde_detail($sql);
00114             $solde_signed=$solde['debit']-$solde['credit'];
00115 
00116             if (
00117                 ($solde_signed < 0 && $p_deb == 'D' ) ||
00118                 ($solde_signed > 0 && $p_deb == 'C' )
00119             )
00120             {
00121                 $ret.= '<li> '.HtmlInput::history_account($line['pcm_val'],'Anomalie pour le compte '.$line['pcm_val'].' '.h($line['pcm_lib']).
00122                        "  D: ".$solde['debit'].
00123                        "  C: ".$solde['credit']." diff ".$solde['solde']);
00124                 $count++;
00125             }
00126 
00127         }
00128 
00129         echo '<fieldset>';
00130         echo '<legend>'.$p_message.'</legend>';
00131         if ( $count <> 0 )
00132         {
00133             echo '<ol>'.$ret.'</ol>';
00134             echo '<span class="error">'._("Nbres anomalies").' : '.$count.'</span>';
00135         }
00136         else
00137             echo _("Pas d'anomalie détectée");
00138         echo '</fieldset>';
00139 
00140 
00141     }
00142     /*!\brief verify that the saldo is good for the type of account */
00143     function verify()
00144     {
00145                 bcscale(2);
00146         echo '<h3>'._("Comptes normaux").'</h3>';
00147         $this->warning(_('Actif avec un solde crediteur'),'ACT','D');
00148         $this->warning(_('Passif avec un solde debiteur'),'PAS','C');
00149         $this->warning(_('Compte de resultat : Charge avec un solde crediteur'),'CHA','D');
00150         $this->warning(_('Compte de resultat : produit avec un solde debiteur'),'PRO','C');
00151         echo '<hr>';
00152         echo '<h3>'._("Comptes inverses").' </h3>';
00153         $this->warning(_('Compte inverse : actif avec un solde debiteur'),'ACTINV','C');
00154         $this->warning(_('Compte inverse : passif avec un solde crediteur'),'PASINV','D');
00155         $this->warning(_('Compte inverse : Charge avec un solde debiteur'),'CHAINV','C');
00156         $this->warning(_('Compte inverse : produit avec un solde crediteur'),'PROINV','D');
00157         echo '<h3'._("Solde").' </h3>';
00158         /* set the periode filter */
00159         $sql_periode=sql_filter_per($this->db,$this->from,$this->to,'p_id','j_tech_per');
00160         /* debit Actif */
00161         $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)".
00162              " where j_debit='t' and (pcm_type='ACT' or pcm_type='ACTINV')";
00163         $sql.="and $sql_periode";
00164         $debit_actif=$this->db->get_value($sql);
00165 
00166         /* Credit Actif */
00167         $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)".
00168              " where j_debit='f' and (pcm_type='ACT' or pcm_type='ACTINV')";
00169 
00170         $sql.="and $sql_periode";
00171 
00172         $credit_actif=$this->db->get_value($sql);
00173         $total_actif=abs(bcsub($debit_actif,$credit_actif));
00174         echo '<table >';
00175         echo tr(td(_('Total actif')).td($total_actif,'style="text-align:right"'));
00176 
00177         /* debit passif */
00178         $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)".
00179              " where j_debit='t' and (pcm_type='PAS' or pcm_type='PASINV') ";
00180         $sql.="and $sql_periode";
00181 
00182         $debit_passif=$this->db->get_value($sql);
00183 
00184         /* Credit Actif */
00185         $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)".
00186              " where j_debit='f' and (pcm_type='PAS' or pcm_type='PASINV') ";
00187         $sql.="and $sql_periode";
00188         $credit_passif=$this->db->get_value($sql);
00189         $total_passif=abs(bcsub($debit_passif,$credit_passif));
00190 
00191         /* diff actif / passif */
00192         echo tr(td(_('Total passif')).td($total_passif,'style="text-align:right"'));
00193         if ( $total_actif != $total_passif )
00194         {
00195             $diff=bcsub($total_actif,$total_passif);
00196             echo tr(td(' Difference Actif - Passif ').td($diff,'style="text-align:right"'),'style="font-weight:bolder"');
00197         }
00198 
00199         /* debit charge */
00200         $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)".
00201              " where j_debit='t' and (pcm_type='CHA' or pcm_type='CHAINV')";
00202         $sql.="and $sql_periode";
00203         $debit_charge=$this->db->get_value($sql);
00204 
00205         /* Credit charge */
00206         $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)".
00207              " where j_debit='f' and (pcm_type='CHA' or pcm_type='CHAINV')";
00208         $sql.="and $sql_periode";
00209         $credit_charge=$this->db->get_value($sql);
00210         $total_charge=abs(bcsub($debit_charge,$credit_charge));
00211         echo tr(td(_('Total charge ')).td($total_charge,'style="text-align:right"'));
00212 
00213 
00214         /* debit prod */
00215         $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)".
00216              " where j_debit='t' and (pcm_type='PRO' or pcm_type='PROINV')";
00217         $sql.="and $sql_periode";
00218         $debit_pro=$this->db->get_value($sql);
00219 
00220         /* Credit prod */
00221         $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)".
00222              " where j_debit='f' and (pcm_type='PRO' or pcm_type='PROINV')";
00223         $sql.="and $sql_periode";
00224         $credit_pro=$this->db->get_value($sql);
00225         $total_pro=abs(bcsub($debit_pro,$credit_pro));
00226         echo tr(td(_('Total produit')).td($total_pro,'style="text-align:right"'));
00227 
00228         $diff=bcsub($total_pro,$total_charge);
00229 
00230         echo tr( td(_("Difference Produit - Charge"),'style="padding-right:20px"').td($diff,'style="text-align:right"'),'style="font-weight:bolder"');
00231         echo '</table>';
00232     }
00233     /*!
00234      * \brief get data from the $_GET
00235      *
00236      */
00237     function get_request_get()
00238     {
00239         $this->b_id=(isset($_GET['b_id']))?$_GET['b_id']:"";
00240         $this->from=( isset ($_GET['from_periode']))?$_GET['from_periode']:-1;
00241         $this->to=( isset ($_GET['to_periode']))?$_GET['to_periode']:-1;
00242     }
00243     /*!\brief load from the database the document data  */
00244     function load()
00245     {
00246         try
00247         {
00248             if ( $this->b_id=="")
00249                 throw new Exception("le formulaire id n'est pas donnee");
00250 
00251             $sql="select b_name,b_file_template,b_file_form,lower(b_type) as b_type from bilan where".
00252                  " b_id = ".$this->b_id;
00253             $res=$this->db->exec_sql($sql);
00254 
00255             if ( Database::num_row($res)==0)
00256                 throw new Exception (_('Aucun enregistrement trouve'));
00257             $array=Database::fetch_array($res,0);
00258             foreach ($array as $name=>$value)
00259             $this->$name=$value;
00260 
00261         }
00262         catch(Exception $Ex)
00263         {
00264             echo $Ex->getMessage();
00265             exit();
00266         }
00267     }
00268     /*!\brief open the file of the form */
00269     /*\return an handle to this file */
00270     function file_open_form()
00271     {
00272         $form=fopen($this->b_file_form,'r');
00273         if ( $form == false)
00274         {
00275             echo 'Cannot Open';
00276             exit();
00277         }
00278         return $form;
00279     }
00280     /*!\brief open the file with the template */
00281     /*\return an handle to this file */
00282     function file_open_template()
00283     {
00284         $templ=fopen($this->b_file_template,'r');
00285         if ( $templ == false)
00286         {
00287             echo 'Cannot Open';
00288             exit();
00289         }
00290         return $templ;
00291 
00292     }
00293     /*!
00294      * \brief Compute all the formula
00295      * \param $p_handle the handle to the file
00296      * \param
00297      * \param
00298      *
00299      *
00300      * \return
00301      */
00302     function compute_formula($p_handle)
00303     {
00304         while (! feof ($p_handle))
00305         {
00306             $buffer=trim(fgets($p_handle));
00307             // $a=(Impress::check_formula($buffer)  == true)?"$buffer ok<br>":'<font color="red">'.'Pas ok '.$buffer."</font><br>";
00308             // echo $a;
00309             // blank line are skipped
00310             if (strlen(trim($buffer))==0)
00311                 continue;
00312             // skip comment
00313             if ( strpos($buffer,'#') === true )
00314                 continue;
00315             // buffer contains a formula A$=....
00316             // We need to eval it
00317             $a=Impress::parse_formula($this->db,"$buffer",$buffer,$this->from,$this->to,false);
00318             $b=str_replace("$","\$this->",$a);
00319             if ( eval("$b;") === false )
00320                 echo_debug(__FILE__,__LINE__,"Code failed with $b");
00321 
00322 
00323         }// end read form line per line
00324     }
00325     /*!\brief generate the ods document
00326     * \param the handle to the template file
00327     * \return the xml
00328     *@note
00329     * Sur une seule ligne il y a plusieurs données, donc il y a plusieurs boucles, pour les autres documents
00330     * cela devrait être fait aussi, actuellement ces documents, n'acceptent qu'une formule par ligne.
00331     *@note
00332     * Pas de header dans les entêtes car n'est pas compris dans le document qu'on utilise
00333     */
00334     function generate_odt()
00335     {
00336         // create a temp directory in /tmp to unpack file and to parse it
00337         $dirname=tempnam($_ENV['TMP'],'bilan_');
00338 
00339 
00340         unlink($dirname);
00341         mkdir ($dirname);
00342         chdir($dirname);
00343 
00344         $file_base=dirname($_SERVER['SCRIPT_FILENAME']).DIRECTORY_SEPARATOR.$this->b_file_template;
00345         $work_file=basename($file_base);
00346         if ( copy ($file_base,$work_file) == false )
00347         {
00348             echo _("erreur Ouverture fichier");
00349             exit();
00350         }
00351         ob_start();
00352         /* unzip the document */
00353         $zip = new Zip_Extended;
00354         if ($zip->open($work_file) === TRUE)
00355           {
00356             $zip->extractTo($dirname.DIRECTORY_SEPARATOR);
00357             $zip->close();
00358           } else
00359           {
00360             echo __FILE__.":".__LINE__."cannot unzip model ".$filename;
00361           }
00362 
00363         ob_end_clean();
00364         unlink($work_file);
00365         // remove the zip file
00366         $p_file=fopen('content.xml','r');
00367 
00368         if ( $p_file == false)
00369         {
00370             echo 'Cannot Open';
00371             exit();
00372         }
00373 
00374         $r="";
00375         $regex="/&lt;&lt;\\$[A-Z]*[0-9]*&gt;&gt;/";
00376         $lt="&lt;";
00377         $gt="&gt;";
00378         $header_txt=header_txt($this->db);
00379 
00380         while ( !feof($p_file) )
00381         {
00382             $line_rtf=fgets($p_file);
00383 
00384             /*
00385              * replace the header tag, doesn't work if inside header
00386              */
00387             $line_rtf=preg_replace('/&lt;&lt;header&gt;&gt;/',$header_txt,$line_rtf);
00388 
00389 
00390             // the line contains the magic <<
00391             $tmp="";
00392 
00393 
00394             while (preg_match_all($regex,$line_rtf,$f2) > 0 )
00395               {
00396                 // the f2 array contains all the magic << in the line
00397                 foreach ($f2 as $f2_array)
00398                   {
00399                     foreach ($f2_array as $f2_str)
00400                       {
00401                         $to_remove=$f2_str;
00402                         $f2_value=str_replace("&lt;","",$f2_str);
00403                         $f2_value=str_replace("&gt;","",$f2_value);
00404                         $f2_value=str_replace("$","",$f2_value);
00405 
00406 
00407 
00408                         // check for missing variables and labels (N vars)
00409                         if( ! isset($this->$f2_value))
00410                           {
00411 
00412                             $a = "!!".$f2_value."!!";
00413                             if( substr($f2_value, 0, 1) == "N" )
00414                               {
00415                                 $ret = $this->db->get_array("SELECT pcm_lib AS acct_name FROM tmp_pcmn WHERE pcm_val::text LIKE ".
00416                                                             " substr($1, 2)||'%' ORDER BY pcm_val ASC LIMIT 1",array($f2_value));
00417                                 if($ret[0]['acct_name'])
00418                                   {
00419                                     $a = $ret[0]['acct_name'];
00420                                     $a=str_replace('<','&lt;',$a);
00421                                     $a=str_replace('>','&gt;',$a);
00422                                   }
00423                               }
00424                           }
00425                         else
00426                           {
00427                             $a=$this->$f2_value;
00428                           }
00429                         if ( $a=='-0' ) $a=0;
00430 
00431                         /*  allow numeric cel in ODT for the formatting and formula */
00432                         if ( is_numeric($a) )
00433                           {
00434                             $searched='office:value-type="string"><text:p>'.$f2_str;
00435                             $replaced='office:value-type="float" office:value="'.$a.'"><text:p>'.$f2_str;
00436                             $line_rtf=str_replace($searched, $replaced, $line_rtf);
00437                           }
00438 
00439 
00440                         $line_rtf=str_replace($f2_str,$a,$line_rtf);
00441 
00442                       }// foreach end
00443                   } // foreach
00444               } // preg_match_all
00445             $r.=$line_rtf;
00446 
00447         }// odt file is read
00448 
00449         return $r;
00450 
00451     }
00452 
00453     /*!
00454      * \brief generate the plain  file (rtf,txt, or html)
00455      * \param the handle to the template file
00456      */
00457     function generate_plain($p_file)
00458     {
00459         $r="";
00460         if ( $this->b_type=='html')
00461         {
00462             $lt='&lt;';
00463             $gt='&gt;';
00464             $pattern='/&lt;&lt;header&gt;&gt;/';
00465         }
00466         else
00467         {
00468             $lt='<';
00469             $gt='>';
00470             $pattern='/<<header>>/';
00471         }
00472 
00473         $header_txt=header_txt($this->db);
00474 
00475         while ( !feof($p_file) )
00476         {
00477             $line_rtf=fgets($p_file);
00478 
00479             $line_rtf=preg_replace($pattern,$header_txt,$line_rtf);
00480 
00481 
00482             // the line contains the magic <<
00483             if (preg_match_all("/".$lt.$lt."\\$[a-zA-Z]*[0-9]*".$gt.$gt."/",$line_rtf,$f2) > 0)
00484             {
00485                 // DEBUG
00486                 //    echo $r.'<br>';
00487                 // the f2 array contains all the magic << in the line
00488                 foreach ($f2 as $f2_str)
00489                 {
00490                     // DEBUG
00491                     // echo "single_f2 = $f2_str <br>";
00492                     // replace single_f2 by its value
00493                     $f2_value=str_replace($lt,"",$f2_str);
00494                     $f2_value=str_replace($gt,"",$f2_value);
00495                     $f2_value=str_replace("$","",$f2_value);
00496                     $f2_value=$f2_value[0];
00497 
00498                     // check for missing variables and labels (N vars)
00499                     if( ! isset($this->$f2_value))
00500                     {
00501                         $a = "!!".$f2_value."!!";
00502                         if( substr($f2_value, 0, 1) == "N" )
00503                         {
00504                             $ret = $this->db->get_array("SELECT pcm_lib AS acct_name FROM tmp_pcmn WHERE ".
00505                                                         " pcm_val::text LIKE substr($1, 2)||'%' ORDER BY pcm_val ASC LIMIT 1",
00506                                                         array($f2_value));
00507                             if($ret[0]['acct_name'])
00508                             {
00509                                 /* for rtf we have the string to put it in latin1 */
00510                                 $a = utf8_decode($ret[0]['acct_name']);
00511                             }
00512                         }
00513                     }
00514                     else
00515                     {
00516                         // DEBUG
00517                         //echo "f2_value=$f2_value";
00518                         //                $a=${"$f2_value"};
00519                         $a=$this->$f2_value;
00520                     }
00521                     // DEBUG      echo " a = $a";
00522                     if ( $a=='-0' ) $a=0;
00523                     $line_rtf=str_replace($f2_str,$a,$line_rtf);
00524 
00525                 }// foreach end
00526             }
00527             $r.=$line_rtf;
00528 
00529         }// rtf file is read
00530         // DEBUG
00531         //  fwrite($out,$r);
00532 
00533         return $r;
00534 
00535 
00536 
00537 
00538     }
00539     /*!\brief generate the document and send it to the browser
00540      */
00541     function generate()
00542     {
00543         // Load the data
00544         $this->load();
00545         // Open the files
00546         $form=$this->file_open_form();
00547 
00548         // Compute all the formula and add the value to this
00549         $this->compute_formula($form);
00550         fclose($form);
00551         // open the form
00552         $templ=$this->file_open_template();
00553         switch ($this->b_type)
00554         {
00555         case 'rtf':
00556             $result=$this->generate_plain($templ);
00557             $this->send($result);
00558             break;
00559         case 'txt':
00560             $result=$this->generate_plain($templ);
00561             $this->send($result);
00562         case 'html':
00563             $result=$this->generate_plain($templ);
00564             $this->send($result);
00565 
00566             break;
00567         case 'odt':
00568         case 'ods':
00569             $result=$this->generate_odt($templ);
00570             $this->send($result);
00571             break;
00572 
00573         }
00574         fclose($templ);
00575     }
00576     /*!\brief send the result of generate plain to the browser
00577      * \param $p_result is the string returned by generate_...
00578      */
00579     function send($p_result)
00580     {
00581         switch ($this->b_type)
00582         {
00583         case 'rtf':
00584             // A rtf file is generated
00585             header('Content-type: application/rtf');
00586             header('Content-Disposition: attachment; filename="'.$this->b_name.'.rtf"');
00587             echo $p_result;
00588             break;
00589 
00590         case 'txt':
00591             // A txt file is generated
00592             header('Content-type: application/txt');
00593             header('Content-Disposition: attachment; filename="'.$this->b_name.'.txt"');
00594 
00595             echo $p_result;
00596             break;
00597         case 'html':
00598             // A txt file is generated
00599             header('Content-type: application/html');
00600             header('Content-Disposition: attachment; filename="'.$this->b_name.'.html"');
00601 
00602             echo $p_result;
00603             break;
00604         case 'odt':
00605         case 'ods':
00606             /*   header("Pragma: public");
00607             header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
00608             header("Cache-Control: must-revalidate");
00609             if ( $this->b_type == 'odt' )
00610             header('Content-type: application/vnd.oasis.opendocument.text');
00611             if ( $this->b_type == 'ods' )
00612             header('Content-type: application/vnd.oasis.opendocument.spreadsheet');
00613             header('Content-Disposition: attachment;filename="'.$this->b_name.'.odt"',FALSE);
00614             header("Accept-Ranges: bytes");
00615             */
00616             ob_start();
00617             // save the file in a temp folder
00618             // create a temp directory in /tmp to unpack file and to parse it
00619             $dirname=tempnam($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'tmp','bilan_');
00620 
00621 
00622             unlink($dirname);
00623             mkdir ($dirname);
00624             chdir($dirname);
00625             // create a temp directory in /tmp to unpack file and to parse it
00626             $file_base=dirname($_SERVER['SCRIPT_FILENAME']).DIRECTORY_SEPARATOR.$this->b_file_template;
00627             $work_file=basename($file_base);
00628             if ( copy ($file_base,$work_file) == false )
00629             {
00630                 echo "Je ne peux pas ouvrir ce fichier ";
00631                 exit();
00632             }
00633             /*
00634              * unzip the document
00635              */
00636             ob_start();
00637             $zip = new Zip_Extended;
00638             if ($zip->open($work_file) === TRUE)
00639               {
00640                 $zip->extractTo($dirname.DIRECTORY_SEPARATOR);
00641                 $zip->close();
00642               }
00643             else
00644               {
00645                 echo __FILE__.":".__LINE__."cannot unzip model ".$filename;
00646               }
00647 
00648             // Remove the file we do  not need anymore
00649             unlink ($work_file);
00650 
00651 
00652             // replace the file
00653             $p_file=fopen($dirname.DIRECTORY_SEPARATOR.'content.xml','wb');
00654             if ( $p_file == false )
00655             {
00656                 exit ( _("erreur Ouverture fichier").' content.xml');
00657 
00658             }
00659             $a=fwrite($p_file,$p_result);
00660             if ( $a==false)
00661             {
00662                 echo _("erreur écriture fichier").' content.xml';
00663                 exit();
00664             }
00665             // repack
00666             $zip = new Zip_Extended;
00667             $res = $zip->open($this->b_name.".".$this->b_type, ZipArchive::CREATE);
00668             if($res !== TRUE)
00669               {
00670                 echo __FILE__.":".__LINE__."cannot recreate zip";
00671                 exit;
00672               }
00673             $zip->add_recurse_folder($dirname.DIRECTORY_SEPARATOR);
00674             $zip->close();
00675 
00676             ob_end_clean();
00677             fclose($p_file);
00678             $fdoc=fopen($dirname.DIRECTORY_SEPARATOR.$this->b_name.'.'.$this->b_type,'r');
00679             if ( $fdoc == false )
00680             {
00681                 exit  (_("erreur Ouverture fichier"));
00682             }
00683             $buffer=fread ($fdoc,filesize($dirname.DIRECTORY_SEPARATOR.$this->b_name.'.'.$this->b_type));
00684             echo $buffer;
00685 
00686             break;
00687             // and send
00688         }
00689 
00690     }
00691     static function test_me()
00692     {
00693 
00694         if ( isset($_GET['result']))
00695         {
00696             ob_start();
00697             $cn=new Database(dossier::id());
00698             $a=new Acc_Bilan($cn);
00699             $a->get_request_get();
00700 
00701             $a->load();
00702             $form=$a->file_open_form();
00703             $a->compute_formula($form);
00704             fclose($form);
00705             // open the form
00706             $templ=$a->file_open_template();
00707             $r=$a->generate_odt($templ);
00708             fclose($templ);
00709             ob_end_clean();
00710 
00711             $a->send($r);
00712         }
00713         else
00714         {
00715             $cn=new Database(dossier::id());
00716             $a=new Acc_Bilan($cn);
00717             $a->get_request_get();
00718 
00719             echo '<form method="get">';
00720             echo $a->display_form();
00721             echo HtmlInput::hidden('test_select',$_GET['test_select']).dossier::hidden();
00722             echo HtmlInput::submit('result','Sauve');
00723             echo '</form>';
00724         }
00725     }
00726 }
00727 
 All Data Structures Namespaces Files Functions Variables Enumerations