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

form_csv.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.7 $ */
00020 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00024 include_once("ac_common.php");
00025 include_once ("postgres.php");
00026 include ('class_user.php');
00027 include("class_rapport.php");
00028 include("impress_inc.php");
00029 header('Content-type: application/csv');
00030 header('Content-Disposition: attachment;filename="rapport.csv"',FALSE);
00031 
00032 /* Admin. Dossier */
00033 $cn=DbConnect($_SESSION['g_dossier']);
00034 
00035 
00036 $User=new cl_user($cn);
00037 $User->Check();
00038 
00039 
00040 $Form=new rapport($cn,$_POST['form_id']);
00041 $Form->GetName();
00042 // Step ?
00043 //--
00044 if ( $_POST['p_step'] == 0 )
00045   {
00046     $array=$Form->GetRow( $_POST['from_periode'],
00047                           $_POST['to_periode']
00048                           );
00049     if ( count($Form->row ) == 0 ) 
00050       exit;
00051     
00052     echo       "\"Mois,\"\t\"Description\"\t,".
00053       "\"Montant\"\t";
00054 
00055 
00056 
00057     foreach ( $Form->row as $op ) { 
00058       echo '"'.$op['desc'].'"'."\t,".
00059         sprintf("%8.2f",$op['montant'])."\t".
00060         "\n";
00061       
00062     }
00063   } 
00064  else 
00065    {
00066      // Gather all the data
00067      //---
00068      for ($e=$_POST['from_periode'];$e<=$_POST['to_periode'];$e+=$_POST['p_step'])
00069        {
00070         $periode=getPeriodeName($cn,$e);
00071         if ( $periode == null ) continue;
00072         $array[]=$Form->GetRow($e,$e);
00073         $periode_name[]=$periode;
00074        }
00075      // Display column heading
00076      //--
00077      $x="";
00078      foreach ($array[0] as $e) 
00079        {
00080          printf("%s%s",$x,$e['desc']);
00081          $x=";";
00082 
00083        }
00084      printf("\n");
00085      // Display value for each line 
00086      //--
00087      $a=0;
00088      foreach ($array as $e ) 
00089        {
00090          print $periode_name[$a];
00091          $a++;
00092          foreach ($e as $elt) 
00093            {
00094              printf(";%s",$elt['montant']);
00095            }
00096          printf("\n");
00097        }
00098    }
00099   exit;
00100 ?>