00001 <?
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00030 class Invoice {
00031 var $cn;
00032 var $id;
00033 var $template;
00035
00036 function Invoice($p_cn) {
00037 $this->cn=$p_cn;
00038 }
00039
00040 function myList() {
00041 $sql="select iv_id,iv_name from invoice";
00042 $Res=ExecSql($this->cn,$sql);
00043 $all=pg_fetch_all($Res);
00044 if ( pg_NumRows($Res) == 0 ) return "";
00045 foreach ( $all as $row) {
00046 var_dump($row);
00047 }
00048 }
00049
00050 function Save() {
00051
00052 StartSql($this->cn);
00053
00054
00055
00056 $new_name=tempnam('/tmp','invoice_');
00057 echo_debug('class_invoice.php',__LINE__,"new name=".$new_name);
00058 if ( strlen ($_FILES['pj']['tmp_name']) != 0 )
00059 {
00060 if (move_uploaded_file($_FILES['invoice']['tmp_name'],
00061 $new_name))
00062 {
00063
00064 $oid= pg_lo_import($this->cn,$new_name);
00065 if ( $oid == false )
00066 {
00067 echo_error('class_invoice.php',__LINE__,"cannot upload document");
00068 Rollback($cn);
00069 return;
00070 }
00071 echo_debug('class_invoice.php',__LINE__,"Loading document");
00072
00073 $ret=ExecSql($this->cn,"select iv_file from invoice where iv_id=".$this->id);
00074 if (pg_num_rows($ret) != 0)
00075 {
00076 $r=pg_fetch_array($ret,0);
00077 $old_oid=$r['iv_file'];
00078 if (strlen($old_oid) != 0)
00079 pg_lo_unlink($this->cn,$old_oid);
00080 }
00081
00082 ExecSql($this->cn,"update invoice set iv_file where iv_id=".$this->id);
00083 }
00084 else
00085 {
00086 echo "<H1>Error</H1>";
00087 Rollback($this->cn);
00088 exit;
00089 }
00090 }
00091 }
00092
00093 function Delete() {
00094 }
00095
00096
00097 function FormAdd() {
00098 $r="";
00099 $r='<FORM METHOD="POST" ACTION="dossier_prefs.php">';
00100 $r.="</FORM>";
00101 return $r;
00102 }
00103
00104
00105 function FormDelete() {
00106 }
00107
00108
00109
00110
00111 function Get($p_id,$p_internal)
00112 {
00113
00114
00115
00116 StartSql($this->cn);
00117 $ret=ExecSql($cn,"select iv_name,iv_file from invoice where iv_id".$this->iv_id);
00118 if ( pg_num_rows ($ret) == 0 )
00119 return;
00120 $row=pg_fetch_array($ret,0);
00121
00122 $tmp=tempnam('/tmp/','invoice_');
00123 pg_lo_export($cn,$row['iv_file'],$tmp);
00124
00125
00126
00127
00128
00129
00130 ini_set('zlib.output_compression','Off');
00131 header("Pragma: public");
00132 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
00133 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
00134 header("Cache-Control: must-revalidate");
00135 header('Content-type: rtf/x-application');
00136 header('Content-Disposition: attachment;filename="invoice'.$p_internal.'.rtf"',FALSE);
00137 header("Accept-Ranges: bytes");
00138 $file=fopen($tmp,'r');
00139 while ( !feof ($file) )
00140 {
00141 echo fread($file,8192);
00142 }
00143 fclose($file);
00144
00145 unlink ($tmp);
00146
00147 Commit($cn);
00148
00149 }
00150 }
00151 ?>