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

bilan.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: 1.5 $ */
00020 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00024 include_once("ac_common.php");
00025 include_once("impress_inc.php");
00026 include_once("postgres.php");
00027 
00028 
00029 include ('class_user.php');
00030 /* Admin. Dossier */
00031 $cn=DbConnect($_SESSION['g_dossier']);
00032 
00033 $User=new cl_user($cn);
00034 $User->Check();
00035 
00036 // TODO a specific level of security for the "bilan" ???
00037 // Change must be done here
00038 if ( $User->admin == 0 ) {
00039   if ($User->CheckAction($cn,IMP) 
00040                                                                   ==0
00041      )
00042   {
00043     /* Cannot Access */
00044     NoAccess();
00045   }
00046 
00047 }
00048 
00049 // A rtf file is generated
00050 header('Content-type: application/rtf');
00051  
00052  // It will be called downloaded.pdf
00053 header('Content-Disposition: attachment; filename="bilan.rtf"');
00054  
00055 
00056 // Variable
00057 // Start periode 
00058 $start=( isset ($_POST['from_periode']))?$_POST['from_periode']:-1;
00059 $end=( isset ($_POST['to_periode']))?$_POST['to_periode']:-1;
00060 
00061 // Variable if ok ?
00062 if ( $start*$end < 0 ) {
00063   echo_error("Missing Variable start = $start end=$end");
00064   exit (-1);
00065  }
00066 // Open forms
00067 $bnb_form=fopen('document/fr_be/bnb.form','r');
00068 if ( $bnb_form == false) {
00069   echo 'Cannot Open';
00070   exit();
00071  }
00072 $col=array();
00073 
00074 // read forms line per line
00075 while (! feof ($bnb_form)) {
00076   $buffer=trim(fgets($bnb_form));
00077   // $a=(CheckFormula($buffer)  == true)?"$buffer ok<br>":'<font color="red">'.'Pas ok '.$buffer."</font><br>";
00078   // echo $a;
00079   // blank line are skipped
00080   if (strlen(trim($buffer))==0) 
00081     continue;
00082 
00083   // buffer contains a formula A$=....
00084   // We need to eval it 
00085   //ereg("\\$[a-zA-Z]+[0-9]*=",$buffer,$e);
00086   //  echo $e[0];
00087   //echo "<br>".$form;
00088   $a=ParseFormula($cn,"$buffer",$buffer,$start,$end,false);
00089   $b=str_replace("$","\$",$a);
00090 
00091   // echo "Formule to eval".$b.'<hr>';
00092   eval("$b;");
00093   // var_dump($b);
00094   
00095  }// end read form line per line
00096 // echo "<hr>";
00097 fclose ($bnb_form);
00098 //-----------------------------------------------------
00099 // Open the rtf document in order to read it and to 
00100 // replace the <<>> by the appropriate values
00101 //
00102 // Open the rtf template
00103 $bnb_rtf=fopen('document/fr_be/bnb.rtf','r');
00104 // $out=fopen('tmp/a.rtf','w+');
00105 // if ( $bnb_rtf == false) {
00106 //   echo 'Cannot Open rtf';
00107 //   exit();
00108 //  }
00109 // Read it until the end
00110 while ( !feof($bnb_rtf) ) {
00111   $line_rtf=fgets($bnb_rtf);
00112   // the line contains the magic <<
00113   if (ereg("<<\\$[a-zA-Z]*[0-9]*>>",$line_rtf,$f2) == true) {
00114     // DEBUG
00115     //    echo $line_rtf.'<br>';
00116 
00117     // the f2 array contains all the magic << in the line
00118     foreach ($f2 as $f2_str) {
00119       // DEBUG
00120       // echo "single_f2 = $f2_str <br>";
00121       // replace single_f2 by its value
00122       $f2_value=str_replace("<<","",$f2_str);
00123       $f2_value=str_replace(">>","",$f2_value);
00124       $f2_value=str_replace("$","",$f2_value);
00125       // DEBUG
00126       //echo "f2_value=$f2_value";
00127       $a=${"$f2_value"};
00128       // DEBUG      echo " a = $a";
00129       $line_rtf=str_replace($f2_str,$a,$line_rtf);
00130 
00131     }// foreach end
00132   }
00133   // DEBUG
00134   //  fwrite($out,$line_rtf);
00135   echo $line_rtf;
00136 
00137 
00138  }// rtf file is read
00139 ?>