Public Member Functions | |
Document_modele ($p_cn, $p_id=-1) | |
myList () | |
: show all the stored document_modele. return a string containing all the data separate by TD & TR tag | |
Save () | |
: Save a document_modele in the database, if the document_modele doesn't exist yet it will be first created (-> insert into document_modele) in that case the name and the type must be set set before calling Save, the name will be modified with FormatString | |
Delete () | |
Remove a template. | |
Get ($p_id, $p_internal) | |
Parse and remplace the tag in the invoice By the value found in quant_sold. | |
form ($p_action) | |
show the form for loading a template | |
Data Fields | |
$cn | |
$md_id | |
$md_name | |
$md_type | |
$md_lob | |
$md_sequence | |
$sequence |
Definition at line 28 of file class_document_modele.php.
|
Definition at line 37 of file class_document_modele.php.
|
|
Remove a template.
Definition at line 179 of file class_document_modele.php. References $r, $res, $sql, Commit(), ExecSql(), and StartSql(). 00180 { 00181 StartSql($this->cn); 00182 // first we unlink the document 00183 $sql="select md_lob from document_modele where md_id=".$this->md_id; 00184 $res=ExecSql($this->cn,$sql); 00185 $r=pg_fetch_array($res,0); 00186 // if a lob is found 00187 if ( strlen ($r['md_lob']) != 0 ) 00188 { 00189 // we remove it first 00190 pg_lo_unlink($r['md_lob']); 00191 } 00192 // now we can delete the row 00193 $sql="delete from document_modele where md_id =".$this->md_id; 00194 $sql=ExecSql($this->cn,$sql); 00195 Commit($this->cn); 00196 }
|
|
show the form for loading a template
Definition at line 252 of file class_document_modele.php. References $h, $r, $start, $t, $w, dt_id, and make_array(). Referenced by myList(). 00253 { 00254 $r="<p>"; 00255 $r.='<form enctype="multipart/form-data" action="'.$p_action.'" method="post">'; 00256 $t=new widget("text"); 00257 $t->name="md_name"; 00258 $r.=" Nom ".$t->IOValue().""; 00259 $r.="Type de document "; 00260 $w=new widget("select"); 00261 $w->name="md_type"; 00262 $w->value=make_array($this->cn,'select dt_id,dt_value from document_type'); 00263 $r.=$w->IOValue(); 00264 $r.="</p><p>"; 00265 $f=new widget("file"); 00266 $f->name="doc"; 00267 $r.="fichier ".$f->IOValue().""; 00268 // we need to add the sub action as hidden 00269 $h=new widget("hidden"); 00270 $h->name="sa"; 00271 $h->value="add_document"; 00272 $r.=$h->IOValue(); 00273 $start=new widget("text"); 00274 $start->name="start_seq"; 00275 $start->size=9; 00276 $start->value="0"; 00277 $r.=" Numerotation commence a ".$start->IOValue().""; 00278 $r.=$w->Submit('add_document','Ajout'); 00279 $r.="</form></p>"; 00280 return $r; 00281 }
|
|
Parse and remplace the tag in the invoice By the value found in quant_sold.
Definition at line 204 of file class_document_modele.php. References $file, $ret, $row, $tmp, Commit(), ExecSql(), and StartSql(). 00205 { 00206 // retrieve info from the table invoice 00207 00208 // retrieve the template and generate document 00209 StartSql($this->cn); 00210 $ret=ExecSql($cn,"select iv_name,iv_file from invoice where iv_id".$this->iv_id); 00211 if ( pg_num_rows ($ret) == 0 ) 00212 return; 00213 $row=pg_fetch_array($ret,0); 00214 //the template is saved into file $tmp 00215 $tmp=tempnam('/tmp/','invoice_'); 00216 pg_lo_export($cn,$row['iv_file'],$tmp); 00217 // Parse the file 00218 00219 00220 00221 00222 // send it to stdout 00223 ini_set('zlib.output_compression','Off'); 00224 header("Pragma: public"); 00225 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 00226 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 00227 header("Cache-Control: must-revalidate"); 00228 header('Content-type: rtf/x-application'); 00229 header('Content-Disposition: attachment;filename="invoice'.$p_internal.'.rtf"',FALSE); 00230 header("Accept-Ranges: bytes"); 00231 $file=fopen($tmp,'r'); 00232 while ( !feof ($file) ) 00233 { 00234 echo fread($file,8192); 00235 } 00236 fclose($file); 00237 00238 unlink ($tmp); 00239 00240 Commit($cn); 00241 00242 }
|
|
: show all the stored document_modele. return a string containing all the data separate by TD & TR tag
Definition at line 49 of file class_document_modele.php. References $a, $all, $c, $r, $Res, $row, $sql, ExecSql(), form(), md_id, and md_name. 00049 { 00050 $sql="select md_id,md_name,dt_value from document_modele join document_type on(dt_id=md_type)"; 00051 $Res=ExecSql($this->cn,$sql); 00052 $all=pg_fetch_all($Res); 00053 if ( pg_NumRows($Res) == 0 ) return ""; 00054 $r='<p><form method="post">'; 00055 $r.="<table>"; 00056 $r.="<tr> <th> Nom </th> <th>Type</Th><th>Fichier</th><th> Effacer</th>"; 00057 $r.="</tr>"; 00058 foreach ( $all as $row) { 00059 $r.="<tr>"; 00060 $r.="<td>"; 00061 $r.=$row['md_name']; 00062 $r.="</td>"; 00063 $r.="<td>"; 00064 $r.=$row['dt_value']; 00065 $r.="</td>"; 00066 $r.="<td>"; 00067 $r.='<A HREF="show_document_modele.php?md_id='.$row['md_id'].'">Document</a>'; 00068 $r.="</td>"; 00069 $r.="<TD>"; 00070 $c=new widget("checkbox"); 00071 $c->name="dm_remove_".$row['md_id']; 00072 $r.=$c->IOValue(); 00073 $r.="</td>"; 00074 $r.="</tr>"; 00075 } 00076 $r.="</table>"; 00077 00078 // need hidden parameter for subaction 00079 $a=new widget("hidden"); 00080 $a->name="sa"; 00081 $a->value="rm_template"; 00082 $r.=$a->IOValue(); 00083 $r.=$a->Submit("rm_template","Effacer la sélection"); 00084 $r.="</form></p>"; 00085 return $r; 00086 }
|
|
: Save a document_modele in the database, if the document_modele doesn't exist yet it will be first created (-> insert into document_modele) in that case the name and the type must be set set before calling Save, the name will be modified with FormatString Save parm :
none Definition at line 103 of file class_document_modele.php. References $old_oid, $r, $ret, $Ret, $sql, Commit(), echo_debug(), echo_error(), ExecSql(), exit, FormatString(), isNumber(), md_id, name, NextSequence(), Rollback(), start, and StartSql(). 00104 { 00105 // if name is empty return immediately 00106 if ( trim(strlen($this->md_name))==0) 00107 return; 00108 // Start transaction 00109 StartSql($this->cn); 00110 // Save data into the table invoice 00111 // if $this->md_id == -1 it means it is a new document model 00112 // so first we have to insert it 00113 // the name and the type must be set before calling save 00114 if ( $this->md_id == -1) 00115 { 00116 00117 // insert into the table document_modele 00118 $this->name=FormatString($this->md_name); 00119 $this->md_id=NextSequence($this->cn,'document_modele_md_id_seq'); 00120 $sql=sprintf("insert into document_modele(md_id,md_name,md_type) 00121 values (%d,'%s',%d)", 00122 $this->md_id,$this->name,$this->md_type); 00123 $Ret=ExecSql($this->cn,$sql); 00124 // create the sequence for this modele of document 00125 $this->md_sequence="document_".NextSequence($this->cn,"document_seq"); 00126 // if start is not equal to 0 and he's a number than the user 00127 // request a number change 00128 echo_debug('class_document_modele',__LINE__, "this->start ".$this->start." a number ".isNumber($this->start)); 00129 00130 if ( $this->start != 0 && isNumber($this->start) == 1 ) 00131 { 00132 $sql="alter sequence seq_doc_type_".$this->md_type." restart ".$this->start; 00133 ExecSql($this->cn,$sql); 00134 } 00135 00136 } 00137 // Save the file 00138 $new_name=tempnam('/tmp','document_'); 00139 echo_debug('class_document_modele.php',__LINE__,"new name=".$new_name); 00140 if ( strlen ($_FILES['doc']['tmp_name']) != 0 ) 00141 { 00142 if (move_uploaded_file($_FILES['doc']['tmp_name'], 00143 $new_name)) 00144 { 00145 // echo "Image saved"; 00146 $oid= pg_lo_import($this->cn,$new_name); 00147 if ( $oid == false ) 00148 { 00149 echo_error('class_document_modele.php',__LINE__,"cannot upload document"); 00150 Rollback($cn); 00151 return; 00152 } 00153 echo_debug('class_document_modele.php',__LINE__,"Loading document"); 00154 // Remove old document 00155 $ret=ExecSql($this->cn,"select md_lob from document_modele where md_id=".$this->md_id); 00156 if (pg_num_rows($ret) != 0) 00157 { 00158 $r=pg_fetch_array($ret,0); 00159 $old_oid=$r['md_lob']; 00160 if (strlen($old_oid) != 0) 00161 pg_lo_unlink($this->cn,$old_oid); 00162 } 00163 // Load new document 00164 ExecSql($this->cn,"update document_modele set md_lob=".$oid.", md_mimetype='".$_FILES['doc']['type']."' ,md_filename='".$_FILES['doc']['name']."' where md_id=".$this->md_id); 00165 Commit($this->cn); 00166 } 00167 else 00168 { 00169 echo "<H1>Error</H1>"; 00170 Rollback($this->cn); 00171 exit; 00172 } 00173 } 00174 }
|
|
database connection Definition at line 29 of file class_document_modele.php. |
|
pk Definition at line 30 of file class_document_modele.php. |
|
Document file Definition at line 33 of file class_document_modele.php. |
|
template's name Definition at line 31 of file class_document_modele.php. |
|
sequence name (autogenerate) Definition at line 34 of file class_document_modele.php. |
|
template's type (letter, invoice, order...) Definition at line 32 of file class_document_modele.php. |
|
sequence number used by the create sequence start with Definition at line 35 of file class_document_modele.php. |