noalyss Version-9
Public Member Functions | Static Public Member Functions | Data Fields | Private Attributes
Document Class Reference

Class Document corresponds to the table document. More...

+ Collaboration diagram for Document:

Public Member Functions

 __construct ($p_cn, $p_d_id=0)
 Constructor. More...
 
 anchor ()
 create and compute a string for reference the doc <A ...> More...
 
 blank ()
 insert a minimal document and set the d_id More...
 
 compute_filename ($pj, $filename)
 Insert the receipt number into the filename , each generated file will have the name of the template (model) + receipt number) More...
 
 download ($aDocument)
 Download all documents in a ZIP files. More...
 
 export_file ($p_destination_file)
 export the file to the file system and complet $this->d_mimetype, d_filename and More...
 
 generate ($p_array, $p_filename="")
 Generate the document, Call $this->replace to replace tag by value. More...
 
 get ()
 Get complete all the data member thx info from the database. More...
 
 get_all ($ag_id)
 get all the document of a given action More...
 
 moveDocumentPj ($p_internal)
 Move a document from the table document into the concerned row the document is not copied : it is only a link. More...
 
 parseDocument ($p_dir, $p_file, $p_type, $p_array)
 This function parse a document and replace all the predefined tags by a value. More...
 
 remove ()
 remove a row from the table document, the lob object is not deleted because can be linked elsewhere More...
 
 replace ($p_tag, $p_array)
 replace the TAG by the real value, this value can be into the database or in $_POST The possible tags are More...
 
 replace_special_tag ($p_qcode, $p_tag)
 replace a special tag *TAGxxxx with the value from fiche_detail, the xxxx is the ad_value More...
 
 saveGenerated ($p_file)
 Save the generated Document. More...
 
 send ()
 send the document More...
 
 transform2pdf ()
 transform the current Document to a PDF, returns the full path of the PDF from the TMP folder More...
 
 update_description ($p_desc)
 
 upload ($p_ag_id)
 upload a file into document all the needed data are in $_FILES we don't increment the seq $_FILES : array containing by default $_FILES More...
 

Static Public Member Functions

static insert_existing_document ($p_ag_id, $p_lob, $p_filename, $p_mimetype, $p_description="")
 Copy a existing OID (LOB) into the table document. More...
 
static replace_value ($p_buffer, $p_pattern, $p_value, $p_limit=-1, $p_type='OOo')
 replace a pattern with a value in the buffer , handle the change for OOo type file and amount More...
 

Data Fields

 $ag_id
 
 $d_description
 
 $d_filename
 
 $d_id
 
 $d_lob
 
 $d_mimetype
 
 $d_number
 
 $db
 
 $md_id
 

Private Attributes

 $counter
 

Detailed Description

Class Document corresponds to the table document.

Definition at line 28 of file document.class.php.

Constructor & Destructor Documentation

◆ __construct()

Document::__construct (   $p_cn,
  $p_d_id = 0 
)

Constructor.

Parameters
$p_cnDatabase connection

Definition at line 47 of file document.class.php.

48 {
49 $this->db=$p_cn;
50 $this->d_id=$p_d_id;
51
52 // counter for MARCH_NEXT
53 $this->counter=0;
54 }
$SecUser db

References db.

Member Function Documentation

◆ anchor()

Document::anchor ( )

create and compute a string for reference the doc <A ...>

Returns
a string

Definition at line 536 of file document.class.php.

537 {
538 if ($this->d_id==0)
539 return '';
540 $image='<IMG SRC="image/insert_table.gif" title="'.$this->d_filename.'" border="0">';
541 $r="";
542 $href=http_build_query(array('gDossier'=>Dossier::id(), "d_id"=>$this->d_id, 'act'=>'RAW:document'));
543
544 $r='<A class="mtitle" HREF="export.php?'.$href.'">'.$image.'</A>';
545 return $r;
546 }
$href
Definition: adm.inc.php:31
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
static id()
return the 'gDossier' value after a check

References $href, $r, and Dossier\id().

+ Here is the call graph for this function:

◆ blank()

Document::blank ( )

insert a minimal document and set the d_id

Definition at line 59 of file document.class.php.

60 {
61 $this->d_id=$this->db->get_next_seq("document_d_id_seq");
62 // affect a number
63 $this->d_number=$this->db->get_next_seq("seq_doc_type_".$this->md_type);
64 $sql='insert into document(d_id,ag_id,d_number) values($1,$2,$3)';
65
66 $this->db->exec_sql($sql,
67 array
68 ($this->d_id,
69 $this->ag_id,
70 $this->d_number));
71 }
$fl ag_id

References $sql, ag_id, and db.

◆ compute_filename()

Document::compute_filename (   $pj,
  $filename 
)

Insert the receipt number into the filename , each generated file will have the name of the template (model) + receipt number)

Parameters
type$pjthe receipt number
type$filenamethe name of the file
Returns
string

Definition at line 80 of file document.class.php.

81 {
82 $pos_prefix=strrpos($filename, ".");
83 if ($pos_prefix==0)
84 $pos_prefix=strlen($filename);
85 $filename_no=substr($filename, 0, $pos_prefix);
86 $filename_suff=substr($filename, $pos_prefix, strlen($filename));
87
88 foreach (array('/', '*', '<', '>', ';', ',', '\\', '.', ':', '(', ')', ' ', '[', ']',"'") as $i)
89 {
90 $pj=noalyss_str_replace($i, "-", $pj);
91 $filename_no=noalyss_str_replace($i,"-",$filename_no);
92 }
93
94
95 $new_filename=strtolower($filename_no."-".$pj.$filename_suff);
96 $pj=noalyss_str_replace("---","-",$pj);
97 $pj=noalyss_str_replace("--","-",$pj);
98 $new_filename=noalyss_str_replace("---","-",$new_filename);
99 $new_filename=noalyss_str_replace("--","-",$new_filename);
100 return $new_filename;
101 }
noalyss_str_replace($search, $replace, $string)
Definition: ac_common.php:1553

References $i, and noalyss_str_replace().

Referenced by generate().

+ Here is the call graph for this function:

◆ download()

Document::download (   $aDocument)

Download all documents in a ZIP files.

The parameters is an array of Document, see DOcument::get_all

Parameters
arrayof Document $aDocument
See also
Document::get_all()

Definition at line 377 of file document.class.php.

378 {
379
380 if (empty($aDocument)||is_array($aDocument)==false)
381 {
382 throw new Exception("Document.download expects an array");
383 }
384 // make a temp folder
385 $dirname=tempnam($_ENV['TMP'], 'document_dwnall');
386 unlink($dirname);
387 mkdir($dirname);
388
389 // download each file into that folder
390 $nb_document=count($aDocument);
391 $nCopy=0;
392
393 // start a transaction to be able to export LOB
394 $this->db->start();
395 for ($i=0; $i<$nb_document; $i++)
396 {
397 // check that aDocument elt is a document object
398 if ( ! $aDocument[$i] instanceof Document ) {
399 throw new Exception("Document.download.2 element is not a document object");
400 }
401 $filename=$dirname.DIRECTORY_SEPARATOR.$aDocument[$i]->d_filename;
402 // if file exists then add a number
403 if (file_exists($filename))
404 {
405
406 while (true)
407 {
408 $nCopy++;
409 $filename=$dirname.DIRECTORY_SEPARATOR.$nCopy."-".$aDocument[$i]->d_filename;
410 if (!file_exists($filename))
411 {
412 $nCopy=0;
413 break;
414 }
415 } // end while true
416 } // end if fileexist
417 // export file
418 $this->db->lo_export($aDocument[$i]->d_lob,$filename);
419 } // end for $i
420 // make a large PDF and send it
421 $zip=new Zip_Extended();
422 $name="document-".date ("Ymd-His").".zip";
423 if ( $zip->open($_ENV['TMP'].DIRECTORY_SEPARATOR.$name , ZipArchive::CREATE) != true)
424 {
425 die("Cannot create zip file");
426 }
427 $zip->add_recurse_folder($dirname . "/");
428 $zip->close();
429 // send it to stdout
430 ini_set('zlib.output_compression', 'off');
431 header("Pragma: public");
432 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
433 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
434 header("Cache-Control: must-revalidate");
435 header('Content-type: zip/application');
436 header('Content-Disposition: attachment;filename="'.$name.'"', FALSE);
437 header("Accept-Ranges: bytes");
438 $file=fopen($_ENV['TMP'].DIRECTORY_SEPARATOR.$name, 'r');
439 while (!feof($file))
440 {
441 echo fread($file, 8192);
442 }
443 fclose($file);
444
445 $this->db->commit();
446
447 }
Class Document corresponds to the table document.
extends the Zip object
$dirname
Definition: constant.php:42

References $dirname, $file, $i, $name, $nb_document, and db.

◆ export_file()

Document::export_file (   $p_destination_file)

export the file to the file system and complet $this->d_mimetype, d_filename and

Parameters
string$p_destination_filepath
Returns
bool false for failure and true for success

Definition at line 1868 of file document.class.php.

1869 {
1870 if ($this->d_id==0) {
1871 return;
1872 }
1873 $this->db->start();
1874 $ret=$this->db->exec_sql(
1875 "select d_id,d_lob,d_filename,d_mimetype from document where d_id=$1", [$this->d_id]);
1876 if (Database::num_row($ret)==0)
1877 {
1878 return;
1879 }
1881 //the document is saved into file $tmp
1882 $tmp=$p_destination_file;
1883 if ( $this->db->lo_export($row['d_lob'], $tmp) == true) {
1884 $this->d_mimetype=$row['d_mimetype'];
1885 $this->d_filename=$row['d_filename'];
1886 $this->db->commit();
1887 return true;
1888 } else {
1889 $this->db->commit();
1890 return false;
1891
1892 }
1893
1894 }
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static num_row($ret)
wrapper for the function pg_num_rows

References $ret, $row, $tmp, db, DatabaseCore\fetch_array(), and DatabaseCore\num_row().

Referenced by transform2pdf().

+ Here is the call graph for this function:

◆ generate()

Document::generate (   $p_array,
  $p_filename = "" 
)

Generate the document, Call $this->replace to replace tag by value.

Parameters
p_arraycontains the data normally it is the $_POST
$p_filenamecontains the new filename
Returns
an string : the url where the generated doc can be found, the name of the file and his mimetype

Definition at line 112 of file document.class.php.

113 {
114 try {
115 // create a temp directory in /tmp to unpack file and to parse it
116 $dirname=tempnam($_ENV['TMP'], 'doc_');
117 if ($dirname == false) {
118 throw new Exception ('DC117 cannot create tmp file',5000);
119 }
120
121 unlink($dirname);
122 if ( mkdir($dirname) == false ) {
123 throw new Exception ("DC121 cannot create $dirname directory",5000);
124 }
125 // Retrieve the lob and save it into $dirname
126 $this->db->start();
127 $dm_info="select md_name,md_type,md_lob,md_filename,md_mimetype
128 from document_modele where md_id=$1";
129 $Res=$this->db->exec_sql($dm_info, [$this->md_id]);
130
132 $this->d_lob=$row['md_lob'];
133 $this->d_filename=$row['md_filename'];
134 $this->d_mimetype=$row['md_mimetype'];
135 $this->d_name=$row['md_name'];
136
137
138 chdir($dirname);
139 $filename=$row['md_filename'];
140 $exp=$this->db->lo_export($row['md_lob'], $dirname.DIRECTORY_SEPARATOR.$filename);
141 if ($exp===false)
142 {
143 record_log(sprintf('DOCUMENT.GENERATE.D1 , export failed %s %s',$dirname, $filename));
144 throw new Exception(sprintf(_("Export a échoué pour %s"), $filename));
145 }
146
147 $type="n";
148 // if the doc is a OOo, we need to unzip it first
149 // and the name of the file to change is always content.xml
150 if (strpos($row['md_mimetype'], 'vnd.oasis')!=0)
151 {
152 ob_start();
153 $zip=new Zip_Extended;
154 if ($zip->open($filename)===TRUE)
155 {
156 $zip->extractTo($dirname.DIRECTORY_SEPARATOR);
157 $zip->close();
158 }
159 else
160 {
161 record_log(sprintf('DOCUMENT.GENERATE.D2 unzip failed %s', $filename));
162 throw new Exception(sprintf(_("Décompression a échoué %s", $filename)));
163 }
164
165 // Remove the file we do not need anymore
166 unlink($filename);
167 ob_end_clean();
168 $file_to_parse="content.xml";
169 $type="OOo";
170 }
171 else
172 {
173 $file_to_parse=$filename;
174 }
175 // affect a number
176 $this->d_number=$this->db->get_next_seq("seq_doc_type_".$row['md_type']);
177
178 // parse the document - return the doc number ?
179 $this->parseDocument($dirname, $file_to_parse, $type, $p_array);
180
181 $this->db->commit();
182 // if the doc is a OOo, we need to re-zip it
183 if (strpos($row['md_mimetype'], 'vnd.oasis')!=0)
184 {
185 ob_start();
186 $zip=new Zip_Extended;
187 $res=$zip->open($filename, ZipArchive::CREATE);
188 if ($res!==TRUE)
189 {
190 record_log(sprintf('DOCUMENT.GENERATE.D3 zip failed %s', $filename));
191 throw new Exception(_('Echec compression'),5000);
192 }
193 $zip->add_recurse_folder($dirname.DIRECTORY_SEPARATOR);
194 $zip->close();
195
196 ob_end_clean();
197
198 $file_to_parse=$filename;
199 }
200 if ($p_filename!="")
201 {
202 $this->d_filename=$this->compute_filename($p_filename, $this->d_filename);
203 }
204 $this->saveGenerated($dirname.DIRECTORY_SEPARATOR.$file_to_parse);
205 // Invoice
206 $href=http_build_query(array('gDossier'=>Dossier::id(), "d_id"=>$this->d_id, 'act'=>'RAW:document'));
207 $ret='<A class="mtitle" HREF="export.php?'.$href.'">'._('Document').'</A>';
208
209 return $ret;
210 } catch (Exception $e) {
211 record_log($e->getMessage());
212 record_log($e->getTraceAsString());
213 return span(_("Génération du document a échoué"),'class="notice"');
214 }
215 }
span($p_string, $p_extra='')
Definition: ac_common.php:43
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1342
compute_filename($pj, $filename)
Insert the receipt number into the filename , each generated file will have the name of the template ...
parseDocument($p_dir, $p_file, $p_type, $p_array)
This function parse a document and replace all the predefined tags by a value.
saveGenerated($p_file)
Save the generated Document.
$Res

References $dirname, $e, $href, $p_array, $res, $Res, $ret, $row, $type, compute_filename(), db, DatabaseCore\fetch_array(), Dossier\id(), parseDocument(), record_log(), saveGenerated(), and span().

+ Here is the call graph for this function:

◆ get()

Document::get ( )

Get complete all the data member thx info from the database.

Definition at line 629 of file document.class.php.

630 {
631 $sql="select * from document where d_id=$1";
632 $ret=$this->db->exec_sql($sql,[$this->d_id]);
633 if (Database::num_row($ret)==0)
634 {
635 return;
636 }
638 $this->ag_id=$row['ag_id'];
639 $this->d_mimetype=$row['d_mimetype'];
640 $this->d_filename=$row['d_filename'];
641 $this->d_lob=$row['d_lob'];
642 $this->d_number=$row['d_number'];
643 $this->d_description=$row['d_description'];
644 }

References $ret, $row, $sql, ag_id, db, DatabaseCore\fetch_array(), and DatabaseCore\num_row().

+ Here is the call graph for this function:

◆ get_all()

Document::get_all (   $ag_id)

get all the document of a given action

Parameters
$ag_idthe ag_id from action::ag_id (primary key)
Returns
an array of objects document or an empty array if nothing found

Definition at line 604 of file document.class.php.

605 {
606 $res=$this->db->get_array('select d_id, ag_id, d_lob, d_number, d_filename,'.
607 ' d_mimetype,d_description from document where ag_id=$1', array($ag_id));
608 $a=array();
609 for ($i=0; $i<sizeof($res); $i++)
610 {
611 $doc=new Document($this->db);
612 $doc->d_id=$res[$i]['d_id'];
613 $doc->ag_id=$res[$i]['ag_id'];
614 $doc->d_lob=$res[$i]['d_lob'];
615 $doc->d_number=$res[$i]['d_number'];
616 $doc->d_filename=$res[$i]['d_filename'];
617 $doc->d_mimetype=$res[$i]['d_mimetype'];
618 $doc->d_description=$res[$i]['d_description'];
619 $a[$i]=clone $doc;
620 }
621 return $a;
622 }
global $doc

References $a, $ag_id, $doc, $i, $res, and db.

◆ insert_existing_document()

static Document::insert_existing_document (   $p_ag_id,
  $p_lob,
  $p_filename,
  $p_mimetype,
  $p_description = "" 
)
static

Copy a existing OID (LOB) into the table document.

Note
use of global variable $cn which is the db connx to the current folder
Parameters
type$p_ag_idFollow_Up::ag_id
type$p_loboid of existing document
type$p_filenamefilename of existing document
type$p_mimetypemimetype of existing document
type$p_descriptionDescription of existing document (default empty)

Definition at line 521 of file document.class.php.

522 {
523 global $cn;
524 // insert into the table
525 $sql="insert into document (ag_id, d_lob,d_filename,d_mimetype,d_number,d_description) "
526 . "values ($1,$2,$3,$4,$5,$6)";
527 $cn->exec_sql($sql, array($p_ag_id, $p_lob, $p_filename, $p_mimetype, 1, $p_description));
528 }

References $cn, and $sql.

◆ moveDocumentPj()

Document::moveDocumentPj (   $p_internal)

Move a document from the table document into the concerned row the document is not copied : it is only a link.

Parameters
$p_internalinternal code

Definition at line 1757 of file document.class.php.

1758 {
1759 $sql="update jrn set jr_pj=$1,jr_pj_name=$2,jr_pj_type=$3 where jr_internal=$4";
1760
1761 $this->db->exec_sql($sql, array($this->d_lob, $this->d_filename, $this->d_mimetype, $p_internal));
1762 // clean the table document
1763 $sql='delete from document where d_id='.$this->d_id;
1764 $this->db->exec_sql($sql);
1765 }

References $sql, and db.

◆ parseDocument()

Document::parseDocument (   $p_dir,
  $p_file,
  $p_type,
  $p_array 
)

This function parse a document and replace all the predefined tags by a value.

This functions generate diffent documents (invoice, order, letter) with the info from the database

Parameters
$p_dirdirectory name
$p_filefilename
$p_typeFor the OOo document the tag are &lt and &gt instead of < and >
$p_arrayvariable from $_POST
Note
replace in the doc the tags by their values.
  • MY_* table parameter
  • ART_VEN* table quant_sold for invoice
  • CUST_* table quant_sold and fiche for invoice
  • e_* for the invoice in the $_POST

Definition at line 230 of file document.class.php.

231 {
232
233 /*!\note replace in the doc the tags by their values.
234 * - MY_* table parameter
235 * - ART_VEN* table quant_sold for invoice
236 * - CUST_* table quant_sold and fiche for invoice
237 * - e_* for the invoice in the $_POST
238 */
239 // open the document
240 $infile_name=$p_dir.DIRECTORY_SEPARATOR.$p_file;
241 $h=fopen($infile_name, "r");
242
243 // check if tmpdir exist otherwise create it
244 $temp_dir=$_ENV['TMP'];
245 if (is_dir($temp_dir)==false)
246 {
247 if (mkdir($temp_dir)==false)
248 {
249 $msg=sprintf("D221."._("Ne peut pas créer le répertoire %s", $temp_dir));
250 record_log("D221".$msg);
251 throw new Exception($msg);
252 }
253 }
254 // Compute output_name
255 $output_name=tempnam($temp_dir, "gen_doc_");
256 $output_file=fopen($output_name, "w+");
257 // check if the opening is sucessfull
258 if ($h===false)
259 {
260 $msg=sprintf("D232"._("Ne peut pas ouvrir [%s] [%s]"), $p_dir, $p_file);
261 record_log("D232".$msg);
262 throw new Exception($msg);
263 }
264 if ($output_file==false)
265 {
266 $msg=sprintf("D264."._("Ne peut pas ouvrir [%s] [%s]"), $p_dir, $output_name);
268 throw new Exception($msg);
269 }
270 // compute the regex
271 if ($p_type=='OOo')
272 {
273 $regex="/=*&lt;&lt;[A-Z]+_*[A-Z]*_*[A-Z]*_*[A-Z]*_*[0-9]*&gt;&gt;/i";
274 $lt="&lt;";
275 $gt="&gt;";
276 }
277 else
278 {
279 $regex="/=*<<[A-Z]+_*[A-Z]*_*[A-Z]*_*[A-Z]*_*[0-9]*>>/i";
280 $lt="<";
281 $gt=">";
282 }
283 //read the file
284 while (!feof($h))
285 {
286 // replace the tag
287 $buffer=fgets($h);
288 // search in the buffer the magic << and >>
289 // while preg_match_all finds something to replace
290 while (preg_match_all($regex, $buffer, $f)>0)
291 {
292
293 foreach ($f as $apattern)
294 {
295
296 foreach ($apattern as $pattern)
297 {
298
299
300 $to_remove=$pattern;
301 // we remove the < and > from the pattern
302 $tag=noalyss_str_replace($lt, '', $pattern);
303 $tag=noalyss_str_replace($gt, '', $tag);
304
305
306 // if the pattern if found we replace it
307 $value=$this->replace($tag, $p_array);
308 if (strpos($value??"", 'ERROR')!=false)
309 $value="";
310 /*
311 * Change type of cell to numeric
312 * allow numeric cel in ODT for the formatting and formula
313 */
314
315 $buffer=\Document::replace_value($buffer, $pattern, $value, 1, $p_type);
316 }
317 }
318 }
319 // write into the output_file
320 fwrite($output_file, $buffer);
321 }
322 fclose($h);
323 fclose($output_file);
324 if (($ret=copy($output_name, $infile_name))==FALSE)
325 {
326 $msg="D299 ".sprintf(_('Ne peut pas sauver [%s] vers [%s] code erreur = [%s]'), $output_name, $infile_name,
327 $ret);
329 throw new Exception($msg);
330 }
331 }
static replace_value($p_buffer, $p_pattern, $p_value, $p_limit=-1, $p_type='OOo')
replace a pattern with a value in the buffer , handle the change for OOo type file and amount
replace($p_tag, $p_array)
replace the TAG by the real value, this value can be into the database or in $_POST The possible tags...

References $f, $msg, $p_array, $p_type, $ret, $tag, $value, noalyss_str_replace(), record_log(), replace(), and replace_value().

Referenced by generate().

+ Here is the call graph for this function:

◆ remove()

Document::remove ( )

remove a row from the table document, the lob object is not deleted because can be linked elsewhere

Definition at line 1740 of file document.class.php.

1741 {
1742 $d_lob=$this->db->get_value('select d_lob from document where d_id=$1', array($this->d_id));
1743 $sql='delete from document where d_id='.$this->d_id;
1744 $this->db->exec_sql($sql);
1745 if ($d_lob!=0)
1746 $this->db->lo_unlink($d_lob);
1747 }

References $d_lob, $sql, and db.

◆ replace()

Document::replace (   $p_tag,
  $p_array 
)

replace the TAG by the real value, this value can be into the database or in $_POST The possible tags are

  • [CUST_NAME] customer's name
  • [CUST_ADDR_1] customer's address line 1
  • [CUST_CP] customer's ZIP code
  • [CUST_CO] customer's country
  • [CUST_CITY] customer's city
  • [CUST_VAT] customer's VAT
  • [MARCH_NEXT] end this item and increment the counter $i
  • [DATE_LIMIT]
  • [VEN_ART_NAME]
  • [VEN_ART_PRICE]
  • [VEN_ART_QUANT]
  • [VEN_ART_TVA_CODE]
  • [VEN_ART_STOCK_CODE]
  • [VEN_HTVA]
  • [VEN_TVAC]
  • [VEN_TVA]
  • [TOTAL_VEN_HTVA]
  • [DATE_CALC]
  • [DATE]
  • [DATE_LIMIT]
  • [DATE_LIMIT_CALC]
  • [NUMBER]
  • [MY_NAME]
  • [MY_CP]
  • [MY_COMMUNE]
  • [MY_TVA]
  • [MY_STREET]
  • [MY_NUMBER]
  • [TVA_CODE]
  • [TVA_RATE]
  • [BON_COMMANDE]
  • [OTHER_INFO]
  • [CUST_NUM]
  • [CUST_BANQUE_NAME]
  • [CUST_BANQUE_NO]
  • [USER]
  • [REFERENCE]
  • [BENEF_NAME]
  • [BENEF_BANQUE_NAME]
  • [BENEF_BANQUE_NO]
  • [BENEF_ADDR_1]
  • [BENEF_CP]
  • [BENEF_CO]
  • [BENEF_CITY]
  • [BENEF_VAT]
  • [ACOMPTE]
  • [TITLE]
  • [DESCRIPTION]
  • [COMM_PAYMENT]
  • [LABELOP]
  • [COMMENT]
  • [DESCRIPTION]
  • [DOCUMENT_ID]
  • [DATE_PAID]
  • [NOTE]
Parameters
$p_tagTAG
$p_arraydata from $_POST
Returns
String which must replace the tag
Note
The CUST_* are retrieved thx the $p_array['tiers'] which contains the quick_code

Definition at line 711 of file document.class.php.

712 {
713 global $g_parameter;
714 $p_tag=strtoupper($p_tag);
715 $p_tag=noalyss_str_replace('=', '', $p_tag);
716 $r="Tag inconnu";
717 static $aComment=NULL;
718 static $counter_comment=1; /* <! counter for the comment , skip the first one which is the descrition */
719
720 static $aRelatedAction=NULL;
721 static $counter_related_action=0; /* <! counter for the related action */
722
723 static $aRelatedOperation=NULL;
724 static $counter_related_operation=0; /* <! counter for the related operation */
725
726 static $aFileAttached=NULL;
727 static $counter_file=0; /* <! counter for the file */
728
729 static $aOtherCard=NULL;
730 static $counter_other_card=0; /* <! counter for the other card */
731
732 static $aTag=NULL;
733 static $counter_tag=0; /* <! counter for the tags */
734
735 static $aParameterExtra=NULL; // Extra parameter for the company
736 switch ($p_tag)
737 {
738 case 'DATE':
739 $r=(isset($p_array['ag_timestamp']))?$p_array['ag_timestamp']:$p_array['e_date'];
740 break;
741 case 'DATE_CALC':
742 $r=' ';
743 // Date are in $p_array['ag_date']
744 // or $p_array['e_date']
745 if (isset($p_array['ag_timestamp']))
746 {
747 $date=format_date($p_array['ag_timestamp'], 'DD.MM.YYYY', 'YYYY-MM-DD');
748 $r=$date;
749 }
750 if (isset($p_array['e_date']))
751 {
752 $date=format_date($p_array['e_date'], 'DD.MM.YYYY', 'YYYY-MM-DD');
753 $r=$date;
754 }
755 return $r;
756 break;
757 //
758 // the company priv
759
760 case 'MY_NAME':
761 $r=$g_parameter->MY_NAME;
762 break;
763 case 'MY_CP':
764 $r=$g_parameter->MY_CP;
765 break;
766 case 'MY_COMMUNE':
767 $r=$g_parameter->MY_COMMUNE;
768 break;
769 case 'MY_TVA':
770 $r=$g_parameter->MY_TVA;
771 break;
772 case 'MY_STREET':
773 $r=$g_parameter->MY_STREET;
774 break;
775 case 'MY_NUMBER':
776 $r=$g_parameter->MY_NUMBER;
777 break;
778 case 'MY_TEL':
779 $r=$g_parameter->MY_TEL;
780 break;
781 case 'MY_FAX':
782 $r=$g_parameter->MY_FAX;
783 break;
784 case 'MY_PAYS':
785 $r=$g_parameter->MY_PAYS;
786 break;
787
788
789
790 // customer
791 /**
792 * \note The CUST_* are retrieved thx the $p_array['tiers']
793 * which contains the quick_code
794 */
795 case 'SOLDE':
796 $tiers=new Fiche($this->db);
797 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
798 $tiers->get_by_qcode($qcode, false);
799 $p=$tiers->strAttribut(ATTR_DEF_ACCOUNT,0);
800 $poste=new Acc_Account_Ledger($this->db, $p);
801 $r=$poste->get_solde(' true');
802 break;
803 case 'CUST_NAME':
804 $tiers=new Fiche($this->db);
805 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
806 $tiers->get_by_qcode($qcode, false);
807 $r=$tiers->strAttribut(ATTR_DEF_NAME,0);
808 break;
809 case 'CUST_ADDR_1':
810 $tiers=new Fiche($this->db);
811 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
812 $tiers->get_by_qcode($qcode, false);
813 $r=$tiers->strAttribut(ATTR_DEF_ADRESS,0);
814
815 break;
816 case 'CUST_CP':
817 $tiers=new Fiche($this->db);
818
819 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
820 $tiers->get_by_qcode($qcode, false);
821 $r=$tiers->strAttribut(ATTR_DEF_CP,0);
822
823 break;
824 case 'CUST_CITY':
825 $tiers=new Fiche($this->db);
826
827 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
828 $tiers->get_by_qcode($qcode, false);
829 $r=$tiers->strAttribut(ATTR_DEF_CITY,0);
830
831 break;
832
833 case 'CUST_CO':
834 $tiers=new Fiche($this->db);
835
836 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
837 $tiers->get_by_qcode($qcode, false);
838 $r=$tiers->strAttribut(ATTR_DEF_PAYS,0);
839
840 break;
841 // Marchandise in $p_array['e_march*']
842 // \see user_form_achat.php or user_form_ven.php
843 case 'CUST_VAT':
844 $tiers=new Fiche($this->db);
845
846 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
847 $tiers->get_by_qcode($qcode, false);
848 $r=$tiers->strAttribut(ATTR_DEF_NUMTVA,0);
849 break;
850 case 'CUST_NUM':
851 $tiers=new Fiche($this->db);
852 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
853 $tiers->get_by_qcode($qcode, false);
854 $r=$tiers->strAttribut(ATTR_DEF_NUMBER_CUSTOMER,0);
855 break;
856 case 'CUST_BANQUE_NO':
857 $tiers=new Fiche($this->db);
858 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
859 $tiers->get_by_qcode($qcode, false);
860 $r=$tiers->strAttribut(ATTR_DEF_BQ_NO,0);
861 break;
862 case 'CUST_BANQUE_NAME':
863 $tiers=new Fiche($this->db);
864 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
865 $tiers->get_by_qcode($qcode, false);
866 $r=$tiers->strAttribut(ATTR_DEF_BQ_NAME,0);
867 break;
868 /* -------------------------------------------------------------------------------- */
869 /* BENEFIT (fee notes */
870 case 'BENEF_NAME':
871 $tiers=new Fiche($this->db);
872 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
873 if ($qcode=='')
874 {
875 $r='';
876 break;
877 }
878 $tiers->get_by_qcode($qcode, false);
879 $r=$tiers->strAttribut(ATTR_DEF_NAME,0);
880 break;
881 case 'BENEF_ADDR_1':
882 $tiers=new Fiche($this->db);
883 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
884 if ($qcode=='')
885 {
886 $r='';
887 break;
888 }
889 $tiers->get_by_qcode($qcode, false);
890 $r=$tiers->strAttribut(ATTR_DEF_ADRESS,0);
891
892 break;
893 case 'BENEF_CP':
894 $tiers=new Fiche($this->db);
895
896 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
897 if ($qcode=='')
898 {
899 $r='';
900 break;
901 }
902 $tiers->get_by_qcode($qcode, false);
903 $r=$tiers->strAttribut(ATTR_DEF_CP,0);
904
905 break;
906 case 'BENEF_CITY':
907 $tiers=new Fiche($this->db);
908
909 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
910 if ($qcode=='')
911 {
912 $r='';
913 break;
914 }
915 $tiers->get_by_qcode($qcode, false);
916 $r=$tiers->strAttribut(ATTR_DEF_CITY,0);
917
918 break;
919
920 case 'BENEF_CO':
921 $tiers=new Fiche($this->db);
922
923 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
924 if ($qcode=='')
925 {
926 $r='';
927 break;
928 }
929 $tiers->get_by_qcode($qcode, false);
930 $r=$tiers->strAttribut(ATTR_DEF_PAYS,0);
931
932 break;
933 // Marchandise in $p_array['e_march*']
934 // \see user_form_achat.php or user_form_ven.php
935 case 'BENEF_VAT':
936 $tiers=new Fiche($this->db);
937
938 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
939 if ($qcode=='')
940 {
941 $r='';
942 break;
943 }
944 $tiers->get_by_qcode($qcode, false);
945 $r=$tiers->strAttribut(ATTR_DEF_NUMTVA,0);
946 break;
947 case 'BENEF_NUM':
948 $tiers=new Fiche($this->db);
949 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
950 if ($qcode=='')
951 {
952 $r='';
953 break;
954 }
955 $tiers->get_by_qcode($qcode, false);
956 $r=$tiers->strAttribut(ATTR_DEF_NUMBER_CUSTOMER,0);
957 break;
958 case 'BENEF_BANQUE_NO':
959 $tiers=new Fiche($this->db);
960 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
961 if ($qcode=='')
962 {
963 $r='';
964 break;
965 }
966 $tiers->get_by_qcode($qcode, false);
967 $r=$tiers->strAttribut(ATTR_DEF_BQ_NO,0);
968 break;
969 case 'BENEF_BANQUE_NAME':
970 $tiers=new Fiche($this->db);
971 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
972 if ($qcode=='')
973 {
974 $r='';
975 break;
976 }
977 $tiers->get_by_qcode($qcode, false);
978 $r=$tiers->strAttribut(ATTR_DEF_BQ_NAME,0);
979 break;
980
981 // Marchandise in $p_array['e_march*']
982 // \see user_form_achat.php or user_form_ven.php
983 case 'NUMBER':
985 break;
986 case "DOCUMENT_ID":
987 if (isset($p_array['ag_id']))
988 return $p_array['ag_id'];
989 return "";
990 break;
991
992 case 'USER' :
993 return $_SESSION[SESSION_KEY.'use_name'].', '.$_SESSION[SESSION_KEY.'use_first_name'];
994
995 break;
996 case 'REFERENCE':
997 $act=new Follow_Up($this->db);
998 $act->ag_id=$this->ag_id;
999 $act->get();
1000 $r=$act->ag_ref;
1001 break;
1002
1003 /*
1004 * - [VEN_ART_NAME]
1005 * - [VEN_ART_PRICE]
1006 * - [VEN_ART_QUANT]
1007 * - [VEN_ART_TVA_CODE]
1008 * - [VEN_ART_STOCK_CODE]
1009 * - [VEN_HTVA]
1010 * - [VEN_TVAC]
1011 * - [VEN_TVA]
1012 * - [TOTAL_VEN_HTVA]
1013 * - [DATE_LIMIT]
1014 * - [DATE_PAID]
1015 */
1016 case 'DATE_LIMIT_CALC':
1017 if (isset($p_array["e_ech"]))
1018 return format_date($p_array["e_ech"], 'DD.MM.YYYY', 'YYYY-MM-DD');
1019 if (isset($p_array["ech"]))
1020 return format_date($p_array["ech"], 'DD.MM.YYYY', 'YYYY-MM-DD');
1021 if (isset($p_array["ag_remind_date"]))
1022 return format_date($p_array["ag_remind_date"], 'DD.MM.YYYY', 'YYYY-MM-DD');
1023 return "";
1024 break;
1025 case 'DATE_LIMIT':
1026 if (isset($p_array["ech"]))
1027 return $p_array["ech"];
1028 if (isset($p_array["e_ech"]))
1029 return $p_array["e_ech"];
1030 if (isset($p_array["ag_remind_date"]))
1031 return $p_array["ag_remind_date"];
1032 return "";
1033 break;
1034 case 'DATE_PAID':
1035 if ( isset ($p_array['jr_date_paid']) ) { return $p_array['jr_date_paid'];}
1036 break;
1037 case 'MARCH_NEXT':
1038 $this->counter++;
1039 $r='';
1040 break;
1041
1042 case 'VEN_ART_NAME':
1043 // check if the march exists
1044 if (!isset($p_array["e_march".$this->counter]))
1045 return "";
1046 // check that something is sold
1047 if ($p_array['e_march'.$this->counter.'_price']!=0&&$p_array['e_quant'.$this->counter]!=0)
1048 {
1049 $f=new Fiche($this->db);
1050 $f->get_by_qcode($p_array["e_march".$this->counter], false);
1051 $r=$f->strAttribut(ATTR_DEF_NAME,0);
1052 }
1053 else
1054 $r="";
1055 break;
1056 case 'VEN_ART_LABEL':
1057 $id='e_march'.$this->counter."_label";
1058 // check if the march exists
1059
1060 if (!isset($p_array[$id])||(isset($p_array[$id])&&noalyss_strlentrim($p_array[$id])==0))
1061 {
1062 $id='e_march'.$this->counter;
1063 // check if the march exists
1064 if (!isset($p_array[$id]))
1065 $r="";
1066 else
1067 {
1068 // check that something is sold
1069 if ($p_array['e_march'.$this->counter.'_price']!=0&&$p_array['e_quant'.$this->counter]!=0)
1070 {
1071 $f=new Fiche($this->db);
1072 $f->get_by_qcode($p_array[$id], false);
1073 $r=$f->strAttribut(ATTR_DEF_NAME,0);
1074 }
1075 else
1076 $r="";
1077 }
1078 }
1079 else
1080 $r=$p_array[$id];
1081 break;
1082 case 'VEN_ART_STOCK_CODE':
1083 $id='e_march'.$this->counter;
1084 // check if the march exists
1085 if (!isset($p_array[$id]))
1086 $r="";
1087 else
1088 {
1089 // check that something is sold
1090 if ($p_array['e_march'.$this->counter.'_price']!=0&&$p_array['e_quant'.$this->counter]!=0)
1091 {
1092 $f=new Fiche($this->db);
1093 $f->get_by_qcode($p_array[$id], false);
1094 $r=$f->strAttribut(ATTR_DEF_STOCK,0);
1095 $r=($r==NOTFOUND)?'':$r;
1096 }
1097 }
1098 break;
1099 case 'VEN_QCODE':
1100 $id='e_march'.$this->counter;
1101 if (!isset($p_array[$id]))
1102 return "";
1103 return $p_array[$id];
1104 break;
1105 case 'VEN_ART_PRICE':
1106 $id='e_march'.$this->counter.'_price';
1107 if (!isset($p_array[$id]))
1108 return "";
1109 if ($p_array[$id]==0)
1110 return "";
1111 $r=$p_array[$id];
1112 break;
1113
1114 case 'TVA_RATE':
1115 case 'VEN_ART_TVA_RATE':
1116 $id='e_march'.$this->counter.'_tva_id';
1117 if (!isset($p_array[$id]))
1118 return "";
1119 if ($p_array[$id]==-1||$p_array[$id]=='')
1120 return "";
1121 $march_id='e_march'.$this->counter.'_price';
1122 if (!isset($p_array[$march_id]))
1123 return '';
1124 $tva=new Acc_Tva($this->db);
1125 $tva->set_parameter("id", $p_array[$id]);
1126 if ($tva->load()==-1)
1127 return '';
1128 return $tva->get_parameter("rate");
1129 break;
1130
1131 case 'TVA_CODE':
1132 case 'VEN_ART_TVA_CODE':
1133 $id='e_march'.$this->counter.'_tva_id';
1134 if (!isset($p_array[$id]))
1135 return "";
1136 if ($p_array[$id]==-1)
1137 return "";
1138 $qt='e_quant'.$this->counter;
1139 $price='e_march'.$this->counter.'_price';
1140 if ($p_array[$price]==0||$p_array[$qt]==0||noalyss_strlentrim($p_array[$price])==0||noalyss_strlentrim($p_array[$qt])==0)
1141 return "";
1142
1143 $r=$p_array[$id];
1144 break;
1145
1146 case 'TVA_LABEL':
1147 $id='e_march'.$this->counter.'_tva_id';
1148 if (!isset($p_array[$id]))
1149 return "";
1150 $march_id='e_march'.$this->counter.'_price';
1151 if (!isset($p_array[$march_id]))
1152 return '';
1153 if ($p_array[$march_id]==0)
1154 return '';
1155 $tva=new Acc_Tva($this->db, $p_array[$id]);
1156 if ($tva->load()==-1)
1157 return "";
1158 $r=$tva->get_parameter('label');
1159
1160 break;
1161
1162 /* total VAT for one sold */
1163 case 'TVA_AMOUNT':
1164 case 'VEN_TVA':
1165 $qt='e_quant'.$this->counter;
1166 $price='e_march'.$this->counter.'_price';
1167 $tva='e_march'.$this->counter.'_tva_id';
1168 /* if we do not use vat this var. is not set */
1169 if (!isset($p_array[$tva]))
1170 return '';
1171 if (!isset($p_array ['e_march'.$this->counter]))
1172 return "";
1173 if (!isset($p_array[$tva]))
1174 return "";
1175 // check that something is sold
1176 if ($p_array[$price]==0||$p_array[$qt]==0||noalyss_strlentrim($p_array[$price])==0||noalyss_strlentrim($p_array[$qt])==0)
1177 return "";
1178 $r=$p_array['e_march'.$this->counter.'_tva_amount'];
1179 break;
1180 /* TVA automatically computed */
1181 case 'VEN_ART_TVA':
1182
1183 $qt='e_quant'.$this->counter;
1184 $price='e_march'.$this->counter.'_price';
1185 $tva='e_march'.$this->counter.'_tva_id';
1186 if (!isset($p_array['e_march'.$this->counter]))
1187 return "";
1188 if (!isset($p_array[$tva]))
1189 return "";
1190 // check that something is sold
1191 if ($p_array[$price]==0||$p_array[$qt]==0||noalyss_strlentrim($p_array[$price])==0||noalyss_strlentrim($p_array[$qt])==0)
1192 return "";
1193 $oTva=new Acc_Tva($this->db, $p_array[$tva]);
1194 if ($oTva->load()==-1)
1195 return "";
1196 $r=noalyss_round($p_array[$price], 2)*$oTva->get_parameter('rate');
1197 $r=noalyss_round($r, 2);
1198 break;
1199
1200 case 'VEN_ART_TVAC':
1201 $qt='e_quant'.$this->counter;
1202 $price='e_march'.$this->counter.'_price';
1203 if (!isset($p_array['e_march'.$this->counter]))
1204 return "";
1205 if (!isset($p_array['e_march'.$this->counter.'_tva_id']))
1206 return "";
1207 // check that something is sold
1208 if ($p_array[$price]==0||$p_array[$qt]==0||noalyss_strlentrim($p_array[$price])==0||noalyss_strlentrim($p_array[$qt])==0)
1209 return "";
1210 if (!isset($p_array['e_march'.$this->counter.'_tva_id']))
1211 return '';
1212 $tva=new Acc_Tva($this->db, $p_array['e_march'.$this->counter.'_tva_id']);
1213 if ($tva->load()==-1)
1214 {
1215 $r=noalyss_round($p_array[$price], 2);
1216 }
1217 else
1218 {
1219 $r=noalyss_round($p_array[$price]*$tva->get_parameter('rate')+$p_array[$price], 2);
1220 }
1221
1222 break;
1223
1224 case 'VEN_ART_QUANT':
1225 $id='e_quant'.$this->counter;
1226 if (!isset($p_array[$id]))
1227 return "";
1228 // check that something is sold
1229 if ($p_array['e_march'.$this->counter.'_price']==0||$p_array['e_quant'.$this->counter]==0||noalyss_strlentrim($p_array['e_march'.$this->counter.'_price'])==0||noalyss_strlentrim($p_array['e_quant'.$this->counter])==0)
1230 return "";
1231 $r=$p_array[$id];
1232 break;
1233
1234 case 'VEN_HTVA':
1235 $id='e_march'.$this->counter.'_price';
1236 $quant='e_quant'.$this->counter;
1237 if (!isset($p_array[$id]))
1238 return "";
1239
1240 // check that something is sold
1241 if ($p_array['e_march'.$this->counter.'_price']==0||$p_array['e_quant'.$this->counter]==0||noalyss_strlentrim($p_array['e_march'.$this->counter.'_price'])==0||noalyss_strlentrim($p_array['e_quant'.$this->counter])==0)
1242 return "";
1243 bcscale(4);
1245 $r=noalyss_round($r, 2);
1246 break;
1247
1248 case 'VEN_TVAC':
1249 $id='e_march'.$this->counter.'_tva_amount';
1250 $price='e_march'.$this->counter.'_price';
1251 $quant='e_quant'.$this->counter;
1252 if (!isset($p_array['e_march'.$this->counter.'_price'])||!isset($p_array['e_quant'.$this->counter]))
1253 {
1254 return "";
1255 }
1256 // check that something is sold
1257 if ($p_array['e_march'.$this->counter.'_price']==0||$p_array['e_quant'.$this->counter]==0)
1258 {
1259 return "";
1260 }
1261 bcscale(4);
1262 // if TVA not exist
1263 if (!isset($p_array[$id]))
1264 $r=noalyss_bcmul($p_array[$price], $p_array[$quant]);
1265 else
1266 {
1267 $r=noalyss_bcmul($p_array[$price], $p_array[$quant]);
1269 }
1270 $r=noalyss_round($r, 2);
1271 return $r;
1272 break;
1273
1274 case 'TOTAL_VEN_HTVA':
1275 bcscale(4);
1276 $sum=0.0;
1277 if (!isset($p_array["nb_item"]))
1278 return "";
1279 for ($i=0; $i<$p_array["nb_item"]; $i++)
1280 {
1281 $sell='e_march'.$i.'_price';
1282 $qt='e_quant'.$i;
1283
1284 if (!isset($p_array[$sell]))
1285 break;
1286
1287 if (noalyss_strlentrim($p_array[$sell])==0||
1288 noalyss_strlentrim($p_array[$qt])==0||
1289 $p_array[$qt]==0||$p_array[$sell]==0)
1290 continue;
1291 $tmp1=noalyss_bcmul($p_array[$sell], $p_array[$qt]);
1292 $sum=noalyss_bcadd($sum, $tmp1);
1293 }
1294 $r=noalyss_round($sum, 2);
1295 break;
1296 case 'TOTAL_VEN_TVAC':
1297 if (!isset($p_array["nb_item"]))
1298 return "";
1299 $sum=0.0;
1300 bcscale(4);
1301 for ($i=0; $i<$p_array["nb_item"]; $i++)
1302 {
1303 $tva='e_march'.$i.'_tva_amount';
1304 $tva_amount=0;
1305 /* if we do not use vat this var. is not set */
1306 if (isset($p_array[$tva]))
1307 {
1308 $tva_amount=$p_array[$tva];
1309 }
1310
1311 $sell=$p_array['e_march'.$i.'_price'];
1312 $qt=$p_array['e_quant'.$i];
1313 $tot=noalyss_bcmul($sell, $qt);
1314 $tva_amount=noalyss_round($tva_amount,2);
1316 $tot=noalyss_bcadd($tot, $tva_amount);
1317 $sum=noalyss_bcadd($sum, $tot??0);
1318 }
1319 $r=noalyss_round($sum??0, 2);
1320
1321 break;
1322 case 'TOTAL_TVA':
1323 if (!isset($p_array["nb_item"]))
1324 return "";
1325 $sum=0.0;
1326 for ($i=0; $i<$p_array["nb_item"]; $i++)
1327 {
1328 $tva='e_march'.$i.'_tva_amount';
1329 if (!isset($p_array[$tva]))
1330 $tva_amount=0.0;
1331 else
1332 {
1333 $tva_amount=$p_array[$tva];
1334 $tva_amount=($tva_amount=="")?0:$tva_amount;
1335 }
1336 $sum+=$tva_amount;
1337 $sum=noalyss_round($sum, 2);
1338 }
1339 $r=$sum;
1340
1341 break;
1342 case 'BON_COMMANDE':
1343 if (isset($p_array['bon_comm']))
1344 return $p_array['bon_comm'];
1345 else
1346 return "";
1347 break;
1348 case 'PJ':
1349 if (isset($p_array['e_pj']))
1350 return $p_array['e_pj'];
1351 else
1352 return "";
1353
1354 case 'OTHER_INFO':
1355 if (isset($p_array['other_info']))
1356 return $p_array['other_info'];
1357 else
1358 return "";
1359 break;
1360 case 'LABELOP':
1361 if (isset($p_array['e_comm']))
1362 return $p_array['e_comm'];
1363 break;
1364 case 'ACOMPTE':
1365 if (isset($p_array['acompte']))
1366 return $p_array['acompte'];
1367 return "0";
1368 break;
1369 case 'STOCK_NAME':
1370 if (!isset($p_array['repo']))
1371 return "";
1372 $ret=$this->db->get_value('select r_name from public.stock_repository where r_id=$1',
1373 array($p_array['repo']));
1374 return $ret;
1375 case 'STOCK_ADRESS':
1376 if (!isset($p_array['repo']))
1377 return "";
1378 $ret=$this->db->get_value('select r_adress from public.stock_repository where r_id=$1',
1379 array($p_array['repo']));
1380 return $ret;
1381 case 'STOCK_COUNTRY':
1382 if (!isset($p_array['repo']))
1383 return "";
1384 $ret=$this->db->get_value('select r_country from public.stock_repository where r_id=$1',
1385 array($p_array['repo']));
1386 return $ret;
1387 case 'STOCK_CITY':
1388 if (!isset($p_array['repo']))
1389 return "";
1390 $ret=$this->db->get_value('select r_city from public.stock_repository where r_id=$1',
1391 array($p_array['repo']));
1392 return $ret;
1393 case 'STOCK_PHONE':
1394 if (!isset($p_array['repo']))
1395 return "";
1396 $ret=$this->db->get_value('select r_phone from public.stock_repository where r_id=$1',
1397 array($p_array['repo']));
1398 return $ret;
1399 // Follow up
1400 //Title
1401 case 'TITLE':
1402 if (isset($p_array['ag_title']))
1403 return $p_array['ag_title'];
1404 return "";
1405 break;
1406 // Description is the first comment
1407 case 'DESCRIPTION':
1408 if (isset($p_array['ag_id']))
1409 {
1410 // retrieve first comment
1411 $description=$this->db->get_value("select agc_comment "
1412 ." from action_gestion_comment "
1413 ."where ag_id=$1 order by AGC_ID asc limit 1"
1414 , [$p_array['ag_id']]);
1415 return $description;
1416 }
1417 if ( isset($p_array['e_comm'])) {return $p_array['e_comm'] ; }
1418
1419 return "";
1420 break;
1421
1422
1423 // Comments, use a counter to move to the next comment, only for Follow-Up
1424 //
1425 case 'COMMENT':
1426 if (isset($p_array['ag_id']))
1427 {
1428 // Static value, if null the retrieve all of them
1429 if ($aComment==NULL)
1430 {
1431 // retrieve comments
1432 $aComment=$this->db->get_array("select AGC_ID,agc_comment ,"
1433 ." to_char(agc_date,'DD-MM-YY HH24:MI') as str_date ,"
1434 ." tech_user "
1435 ." from action_gestion_comment "
1436 ."where ag_id=$1 order by 1"
1437 , [$p_array['ag_id']]);
1438 }
1439 $nb_comment=count($aComment);
1440 $description="";
1441 if (count($aComment)>$counter_comment)
1442 {
1443 $description.=sprintf(_('le %s , %s écrit %s'), $aComment[$counter_comment]['str_date'],
1444 $aComment[$counter_comment]['tech_user'], $aComment[$counter_comment]['agc_comment']);
1445 $counter_comment++;
1446 }
1447 return $description;
1448 }
1449 return "";
1450 break;
1451 // Related Action, use a counter to move to the next related action, only for Follow-Up
1452 //
1453 case 'RELATED_ACTION':
1454 if (isset($p_array['ag_id']))
1455 {
1456 // Static value, if null the retrieve all of them
1457 if ($aRelatedAction==NULL)
1458 {
1459 // retrieve parent
1460 $followup=new Follow_Up($this->db, $p_array["ag_id"]);
1461 $aRelatedAction=array();
1462 $aParent=$followup->get_parent();
1463 if ($aParent==-1)
1464 return "";
1465 $nb_parent=count($aParent);
1466 $sql_related_action="
1467 select ag_id,
1468 f_id_dest,
1469 (select ad_value from fiche_detail fd1 where fd1.ad_id=23 and fd1.f_id=f_id_dest) as qcode,
1470 (select ad_value from fiche_detail fd1 where fd1.ad_id=1 and fd1.f_id=f_id_dest) as card_name,
1471 (select ad_value from fiche_detail fd1 where fd1.ad_id=32 and fd1.f_id=f_id_dest) as card_fname,
1472 ag_title,
1473 to_char(ag_timestamp,'DD.MM.YYYY') as strdate,
1474 ag_ref
1475 from action_gestion ag where ag_id=$1 ";
1476
1477 for ($x=0; $x<$nb_parent; $x++)
1478 {
1479 $aRelatedAction[]=$this->db->get_row($sql_related_action, [$aParent[$x]['aga_least']]);
1480 $aChild=$followup->get_children($aParent[$x]['aga_least']);
1481 $nb_child=count($aChild);
1482 for ($y=0; $y<$nb_child; $y++)
1483 {
1484 $aRelatedAction[]=$this->db->get_row($sql_related_action,
1485 [$aChild[$y]['aga_greatest']]);
1486 }
1487 }
1488 }
1489 $description="";
1490 if (count($aRelatedAction)>$counter_related_action)
1491 {
1492 $description=sprintf("docid %s %s %s %s %s %s %s",
1493 $aRelatedAction[$counter_related_action]['ag_id'],
1494 $aRelatedAction[$counter_related_action]['ag_ref'],
1495 $aRelatedAction[$counter_related_action]['strdate'],
1496 $aRelatedAction[$counter_related_action]['qcode'],
1497 $aRelatedAction[$counter_related_action]['card_fname'],
1498 $aRelatedAction[$counter_related_action]['card_name'],
1499 $aRelatedAction[$counter_related_action]['ag_title']
1500 );
1501
1502 $counter_related_action++;
1503 }
1504 return $description;
1505 }
1506 return "";
1507 break;
1508
1509 // Concerned operation, use a counter to move to the next one, only for Follow-Up
1510 //
1511 case 'CONCERNED_OPERATION':
1512 if (isset($p_array['ag_id']))
1513 {
1514 // Static value, if null the retrieve all of them
1515 if ($aRelatedOperation==NULL)
1516 {
1517 // retrieve comments
1518 $aRelatedOperation=$this->db->get_array("select ago_id,
1519 j.jr_id,
1520 j.jr_internal,
1521 j.jr_comment,
1522 j.jr_pj_number,
1523 to_char(j.jr_date,'DD.MM.YY') as str_date
1524 from jrn as j
1525 join action_gestion_operation as ago on (j.jr_id=ago.jr_id)
1526 where ag_id=$1 order by jr_date,jr_id"
1527 , [$p_array['ag_id']]);
1528 }
1529 $description="";
1530 if (count($aRelatedOperation)>$counter_related_operation)
1531 {
1532 $description.=sprintf('%s %s %s %s ',
1533 $aRelatedOperation[$counter_related_operation]['str_date'],
1534 $aRelatedOperation[$counter_related_operation]['jr_internal'],
1535 $aRelatedOperation[$counter_related_operation]['jr_comment'],
1536 $aRelatedOperation[$counter_related_operation]['jr_pj_number']
1537 );
1538 $counter_related_operation++;
1539 }
1540 return $description;
1541 }
1542 return "";
1543 break;
1544 // Other card, use a counter to move to the next one, only for Follow-Up
1545 //
1546 case 'OTHER_CARDS':
1547 if (isset($p_array['ag_id']))
1548 {
1549 // Static value, if null the retrieve all of them
1550 if ($aOtherCard==NULL)
1551 {
1552 // retrieve comments
1553 $aOtherCard=$this->db->get_array("
1554 select
1555 (select ad_value from fiche_detail where f_id = ap.f_id and ad_id = 1) as cname,
1556 (select ad_value from fiche_detail where f_id = ap.f_id and ad_id = 32) as cfname,
1557 (select ad_value from fiche_detail where f_id = ap.f_id and ad_id = 23) as qcode,
1558 (select ad_value from fiche_detail where f_id = ap.f_id and ad_id = 18 ) as email,
1559 (select ad_value from fiche_detail where f_id = ap.f_id and ad_id = 27 ) as mobile,
1560 (select ad_value from fiche_detail where f_id = ap.f_id and ad_id = 17 ) as phone
1561 from action_person ap
1562 where ag_id=$1
1563 "
1564 , [$p_array['ag_id']]);
1565 }
1566 $description="";
1567 if (count($aOtherCard)>$counter_other_card)
1568 {
1569 $description.=sprintf('%s %s %s %s %s %s ', $aOtherCard[$counter_other_card]['cname'],
1570 $aOtherCard[$counter_other_card]['cfname'], $aOtherCard[$counter_other_card]['qcode'],
1571 $aOtherCard[$counter_other_card]['email'], $aOtherCard[$counter_other_card]['phone'],
1572 $aOtherCard[$counter_other_card]['mobile']);
1573 $counter_other_card++;
1574 }
1575 return $description;
1576 }
1577 return "";
1578 break;
1579 // Attachment , use a counter to move to the next one, only for Follow-Up
1580 //
1581 case 'ATTACHED_FILES':
1582 if (isset($p_array['ag_id']))
1583 {
1584 // Static value, if null the retrieve all of them
1585 if ($aFileAttached==NULL)
1586 {
1587 // retrieve comments
1588 $aFileAttached=$this->db->get_array("
1589 select d_filename,d_description from document d where ag_id=$1
1590 "
1591 , [$p_array['ag_id']]);
1592 }
1593 $nb_comment=count($aFileAttached);
1594 $description="";
1595 if (count($aFileAttached)>$counter_file)
1596 {
1597 $description.=sprintf("%s %s ", $aFileAttached[$counter_file]['d_filename'],
1598 $aFileAttached [$counter_file]['d_description']);
1599 $counter_file++;
1600 }
1601 return $description;
1602 }
1603 return "";
1604 break;
1605 // Tag , use a counter to move to the next one
1606 case 'TAGS':
1607 if (isset($p_array['ag_id']))
1608 {
1609 // Static value, if null the retrieve all of them
1610 if ($aTag==NULL)
1611 {
1612 // retrieve comments
1613 $aTag=$this->db->get_array("
1614 select t_tag from action_tags at2 join tags t using(t_id) where ag_id=$1 order by upper(t_tag)
1615 "
1616 , [$p_array['ag_id']]);
1617 }
1618 $description="";
1619 if (count($aTag)>$counter_tag)
1620 {
1621 $description.=sprintf("%s ", $aTag [$counter_tag]['t_tag']);
1622 $counter_tag++;
1623 }
1624 return $description;
1625 }
1626
1627 return "";
1628 break;
1629 case 'COMM_PAYMENT':
1630 if (isset($p_array["e_comm_paiement"]))
1631 {
1632 return $p_array["e_comm_paiement"];
1633 }
1634 else
1635 {
1636 return "";
1637 }
1638
1639 // priority of the follow up document
1640 case 'PRIORITY':
1641 if (isset($p_array['ag_priority']))
1642 {
1643 $aPriority=array(1=>_("Haute"), 2=>_("Normale"), 3=>_("Basse"));
1644 return $aPriority[$p_array["ag_priority"]];
1645 }
1646 return "";
1647 // Priority of the follow up document
1648 case 'GROUPMGT':
1649 if (isset($p_array['ag_dest']))
1650 {
1651 $profile=$this->db->get_value("select p_name from profile where p_id=$1", array($p_array['ag_dest']));
1652 return $profile;
1653 }
1654 return "";
1655 // Hour in the follow up document
1656 case 'HOUR':
1657 if (isset($p_array['ag_hour']))
1658 {
1659 return $p_array["ag_hour"];
1660 }
1661 return "";
1662 // State in the follow up document
1663 case 'STATUS':
1664 if (isset($p_array['ag_state']))
1665 {
1666 $status=$this->db->get_value("
1667 select s_value from document_state where s_id=$1", array($p_array['ag_state']));
1668 return $status;
1669 }
1670 return "";
1671 // type of document
1672 case 'DOCUMENT_TYPE':
1673 $ret="";
1674 if (isset($p_array['ag_id']))
1675 {
1676 $ret=$this->db->get_value("select dt_value
1677 from action_gestion
1678 join document_type dt on (ag_type=dt.dt_id)
1679 where ag_id=$1", array($p_array["ag_id"]));
1680 } elseif (isset($p_array['gen_doc'])) {
1681 $ret = $this->db->get_value("
1682 select md_name from public.document_modele where md_id=$1",
1683 [$p_array['gen_doc']]);
1684 }
1685 return $ret;
1686 case 'NOTE':
1687 return $p_array['jrn_note_input']??"";
1688
1689
1690
1691 } // end switch
1692 /*
1693 * retrieve the value of ATTR for e_march
1694 */
1695 if (preg_match('/^ATTR/', $p_tag)==1)
1696 {
1697 $r="";
1698 // Retrieve f_id
1699 if (isset($p_array['e_march'.$this->counter]))
1700 {
1701 $id=$p_array['e_march'.$this->counter];
1702 $r=$this->replace_special_tag($id, $p_tag);
1703 return $r;
1704 }
1705 }
1706 /*
1707 * @brief retrieve the value of ATTR for e_march
1708 */
1709 if (preg_match('/^BENEFATTR/', $p_tag)==1)
1710 {
1711 $r="";
1712 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
1713 // Retrieve f_id
1714 $r=$this->replace_special_tag($qcode, $p_tag);
1715 return $r;
1716 }
1717 if (preg_match('/^CUSTATTR/', $p_tag)==1)
1718 {
1719 $r="";
1720 if (isset($p_array['qcode_dest'])||isset($p_array['e_client']))
1721 {
1722 $qcode=(isset($p_array['qcode_dest']))?$p_array['qcode_dest']:$p_array['e_client'];
1723 $r=$this->replace_special_tag($qcode, $p_tag);
1724 }
1725 return $r;
1726 }
1727
1728 // check also if the tag does exist in parameter_extra table
1729 $pe_value=$this->db->get_value("select pe_value from parameter_extra where pe_code=$1",[$p_tag]);
1730 if ( $this->db->count() > 0 ) { return $pe_value;}
1731
1732 return $r;
1733 }
noalyss_round($p_first, $p_second)
Definition: ac_common.php:1580
format_date($p_date, $p_from_format='YYYY-MM-DD', $p_to_format='DD.MM.YYYY')
format the date, when taken from the database the format is MM-DD-YYYY
Definition: ac_common.php:852
noalyss_bcadd($p_first, $p_second, $p_decimal=4)
Definition: ac_common.php:1563
noalyss_strlentrim($p_string)
Definition: ac_common.php:1549
noalyss_bcmul($p_first, $p_second)
Definition: ac_common.php:1574
global $g_parameter
$p
Definition: array.php:34
Manage the account from the table jrn, jrnx or tmp_pcmn.
Acc_Tva is used for to map the table tva_rate parameter are.
replace_special_tag($p_qcode, $p_tag)
replace a special tag *TAGxxxx with the value from fiche_detail, the xxxx is the ad_value
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Definition: fiche.class.php:38
const NOTFOUND(!defined("SYSINFO_DISPLAY"))
Definition: constant.php:131
const ATTR_DEF_ADRESS
Definition: constant.php:223
const ATTR_DEF_NUMTVA
Definition: constant.php:222
const ATTR_DEF_NAME
Definition: constant.php:216
const ATTR_DEF_CP
Definition: constant.php:224
const ATTR_DEF_BQ_NO
Definition: constant.php:217
const ATTR_DEF_CITY
Definition: constant.php:229
const ATTR_DEF_NUMBER_CUSTOMER
Definition: constant.php:232
const ATTR_DEF_ACCOUNT
Definition: constant.php:215
const ATTR_DEF_BQ_NAME
Definition: constant.php:218
const ATTR_DEF_PAYS
Definition: constant.php:225
const ATTR_DEF_STOCK
Definition: constant.php:226
if( $delta< 0) elseif( $delta==0)

References $act, $ag_id, $aTag, $d_number, $date, $description, $f, $g_parameter, $i, $id, $p, $p_array, $poste, $profile, $qcode, $r, $ret, $status, $tiers, $tot, ATTR_DEF_ACCOUNT, ATTR_DEF_ADRESS, ATTR_DEF_BQ_NAME, ATTR_DEF_BQ_NO, ATTR_DEF_CITY, ATTR_DEF_CP, ATTR_DEF_NAME, ATTR_DEF_NUMBER_CUSTOMER, ATTR_DEF_NUMTVA, ATTR_DEF_PAYS, ATTR_DEF_STOCK, db, elseif, format_date(), noalyss_bcadd(), noalyss_bcmul(), noalyss_round(), noalyss_str_replace(), noalyss_strlentrim(), NOTFOUND, and replace_special_tag().

Referenced by parseDocument().

+ Here is the call graph for this function:

◆ replace_special_tag()

Document::replace_special_tag (   $p_qcode,
  $p_tag 
)

replace a special tag *TAGxxxx with the value from fiche_detail, the xxxx is the ad_value

Parameters
$p_qcodeqcode of the card
$p_tagtag to parse
Returns
the ad_value contained in fiche_detail or for the type "select" the label

Definition at line 1775 of file document.class.php.

1776 {
1777 // check if the march exists
1778 if ($p_qcode=="") return "";
1779
1780 $f=new Fiche($this->db);
1781 $found=$f->get_by_qcode($p_qcode, false);
1782 // if not found exit
1783 if ($found==1) return "";
1784
1785 // get the ad_id
1786 $attr=preg_replace("/^.*ATTR/", "", $p_tag);
1787
1788 if (isNumber($attr)==0) return "";
1789
1790 $ad_type=$this->db->get_value("select ad_type from attr_def where ad_id=$1", array($attr));
1791
1792 // get ad_value
1793 $ad_value=$this->db->get_value("select ad_value from fiche_detail where f_id=$1 and ad_id=$2",
1794 array($f->id, $attr));
1795
1796 // if ad_id is type select execute select and get value
1797 if ($ad_type=="select")
1798 {
1799 $sql=$this->db->get_value("select ad_extra from attr_def where ad_id=$1", array($attr));
1800 $array=$this->db->make_array($sql);
1801 for ($a=0; $a<count($array); $a++)
1802 {
1803 if ($array[$a]['value']==$ad_value)
1804 return $array[$a]['label'];
1805 }
1806 }
1807 // if ad_id is not type select get value
1808 return $ad_value;
1809 }
isNumber($p_int)
Definition: ac_common.php:215

References $a, $array, $attr, $f, $sql, db, and isNumber().

Referenced by replace().

+ Here is the call graph for this function:

◆ replace_value()

static Document::replace_value (   $p_buffer,
  $p_pattern,
  $p_value,
  $p_limit = -1,
  $p_type = 'OOo' 
)
static

replace a pattern with a value in the buffer , handle the change for OOo type file and amount

Parameters
string$p_buffer
string$_pattern
mixed$p_value

Definition at line 1823 of file document.class.php.

1824 {
1825 $check=$p_pattern;
1826 $p_value=$p_value??'';
1827 $check=str_replace(['&lt;', '&gt;', '<', '>', '='], "", $check);
1828 if (preg_replace('/[^[:alnum:]^_]/', '', $check)!=$check)
1829 {
1830 throw new Exception(sprintf(_("chaine à remplacer [%s] contient un caractère interdit"), $p_pattern));
1831 }
1832 $count=0;
1833 if (is_numeric($p_value)&&$p_type=='OOo')
1834 {
1835 /* -- works only with OOo Calc -- */
1836 $searched='/office:value-type="string"><text:p>'.$p_pattern.'/i';
1837 $replaced='office:value-type="float" office:value="'.$p_value.'"><text:p>'.$p_value;
1838 $p_buffer=preg_replace($searched, $replaced, $p_buffer, $p_limit, $count);
1839 if ($count==0)
1840 {
1841 /* -- work with libreOffice > 5 -- */
1842 $searched='/office:value-type="string" calcext:value-type="string"><text:p>(<text:s\/>)*'.$p_pattern.'/i';
1843 $replaced='office:value-type="float" office:value="'.$p_value.'" calcext:value-type="float"><text:p>'.$p_value;
1844 $p_buffer=preg_replace($searched, $replaced, $p_buffer, $p_limit, $count);
1845 }
1846 }
1847 if ($count==0)
1848 {
1849
1850 if ($p_type=='OOo')
1851 {
1852 $p_value=noalyss_str_replace('&', '&amp;', $p_value);
1853 $p_value=noalyss_str_replace('<', '&lt;', $p_value);
1854 $p_value=noalyss_str_replace('>', '&gt;', $p_value);
1855 $p_value=noalyss_str_replace('"', '&quot;', $p_value);
1856 $p_value=noalyss_str_replace("'", '&apos;', $p_value);
1857 }
1858 $p_buffer=preg_replace('/'.$p_pattern.'/i', $p_value, $p_buffer, $p_limit);
1859 }
1860 return $p_buffer;
1861 }
$count
$check

References $check, $count, $p_type, and noalyss_str_replace().

Referenced by parseDocument().

+ Here is the call graph for this function:

◆ saveGenerated()

Document::saveGenerated (   $p_file)

Save the generated Document.

Parameters
$p_fileis the generated file
Returns
0 if no error otherwise 1

Definition at line 341 of file document.class.php.

342 {
343 // We save the generated file
344 $doc=new Document($this->db);
345 $this->db->start();
346 $this->d_lob=$this->db->lo_import($p_file);
347 if ($this->d_lob==false)
348 {
349 echo "ne peut pas importer [$p_file]";
350 return 1;
351 }
352
353 $sql="insert into document(ag_id,d_lob,d_number,d_filename,d_mimetype)
354 values ($1,$2,$3,$4,$5)";
355
356 $this->db->exec_sql($sql,
357 array($this->ag_id,
358 $this->d_lob,
359 $this->d_number,
360 $this->d_filename,
361 $this->d_mimetype));
362 $this->d_id=$this->db->get_current_seq("document_d_id_seq");
363 // Clean the file
364 unlink($p_file);
365 $this->db->commit();
366 return 0;
367 }

References $doc, $sql, ag_id, and db.

Referenced by generate().

◆ send()

Document::send ( )

send the document

Definition at line 551 of file document.class.php.

552 {
553 // retrieve the template and generate document
554 $this->db->start();
555 $ret=$this->db->exec_sql(
556 "select d_id,d_lob,d_filename,d_mimetype from document where d_id=$1", [$this->d_id]);
557
558 if (Database::num_row($ret)==0)
559 {
560 // send it to stdout
561 ini_set('zlib.output_compression', 'Off');
562 header("Pragma: public");
563 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
564 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
565 header("Cache-Control: must-revalidate");
566 header('Content-type: text');
567 header('Content-Disposition: attachment;filename="vide.txt"', FALSE);
568 header("Accept-Ranges: bytes");
569 echo "VIDE-EMPTY";
570 return;
571 }
573 //the document is saved into file $tmp
574 $tmp=tempnam($_ENV['TMP'], 'document_');
575 $this->db->lo_export($row['d_lob'], $tmp);
576 $this->d_mimetype=$row['d_mimetype'];
577 $this->d_filename=$row['d_filename'];
578 $file=fopen($tmp, 'r');
579 // send it to stdout
580 ini_set('zlib.output_compression', 'Off');
581 header("Pragma: public");
582 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
583 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
584 header("Cache-Control: must-revalidate");
585 header('Content-type: '.$this->d_mimetype);
586 header('Content-Disposition: attachment;filename="'.$this->d_filename.'"', FALSE);
587 header("Accept-Ranges: bytes");
588 while (!feof($file))
589 {
590 echo fread($file, 8192);
591 }
592 fclose($file);
593
594 unlink($tmp);
595 $this->db->commit();
596 }

References $file, $ret, $row, $tmp, db, DatabaseCore\fetch_array(), and DatabaseCore\num_row().

+ Here is the call graph for this function:

◆ transform2pdf()

Document::transform2pdf ( )

transform the current Document to a PDF, returns the full path of the PDF from the TMP folder

Returns
string full path to the PDF file

Definition at line 1899 of file document.class.php.

1900 {
1901 if (GENERATE_PDF == 'NO' ) {
1902 \record_log(__FILE__."D1857 PDF not available");
1903 throw new \Exception("Cannot not transform to PDF",5000);
1904 }
1905 // Extract from public.document
1906 $dirname=tempnam($_ENV['TMP'],"document");
1907
1908 if ( $dirname == false ) {
1909 throw new Exception("D1862.cannot create tmp file",5000);
1910 }
1911 unlink($dirname);
1912 umask(0);
1913 if ( mkdir($dirname) == false ) {
1914 throw new Exception("D1868.cannot create tmp directory",5000);
1915 }
1916
1917 $destination_file=$dirname."/".$this->d_filename;
1918 $this->export_file($destination_file);
1919 ob_start();
1920 passthru(OFFICE . escapeshellarg($destination_file), $status);
1921 $result =ob_get_contents();
1922 ob_end_clean();
1923 if ($status != 0) {
1924 \record_log(__FILE__."D1879 Error cannot transform into PDF"." output [$result]");
1925 throw new \Exception("D1879 Cannot not transform to PDF");
1926 }
1927 // remove extension
1928 $ext = strrpos($this->d_filename, ".");
1929 $pdf_file = substr($this->d_filename, 0, $ext);
1930 $pdf_file .=".pdf";
1931 return $dirname."/".$pdf_file;
1932 }
export_file($p_destination_file)
export the file to the file system and complet $this->d_mimetype, d_filename and

References $d_filename, $dirname, $ext, $result, $status, export_file(), and record_log().

+ Here is the call graph for this function:

◆ update_description()

Document::update_description (   $p_desc)

Definition at line 1811 of file document.class.php.

1812 {
1813 $this->db->exec_sql('update document set d_description = $1 where d_id=$2', array($p_desc, $this->d_id));
1814 }

References db.

◆ upload()

Document::upload (   $p_ag_id)

upload a file into document all the needed data are in $_FILES we don't increment the seq $_FILES : array containing by default $_FILES

Parameters
int$p_ag_idACTION_GESTION.AG_ID
Returns
array of int DOCUMENT.D_ID (id of saved documents )

Definition at line 457 of file document.class.php.

458 {
459 // nothing to save
460 if (sizeof($_FILES)==0)
461 return;
462
463 /* for several files */
464 /* $_FILES is now an array */
465 // Start Transaction
466 $this->db->start();
467 $name=$_FILES['file_upload']['name'];
468 $document_saved=array();
469 $http=new HttpInput();
470 $aDescription=$http->post("input_desc","array",array());
471 $description="";
472 for ($i=0; $i<sizeof($name); $i++)
473 {
474 $new_name=tempnam($_ENV['TMP'], 'doc_');
475 // check if a file is submitted
476 if (strlen($_FILES['file_upload']['tmp_name'][$i])!=0)
477 {
478 // upload the file and move it to temp directory
479 if (move_uploaded_file($_FILES['file_upload']['tmp_name'][$i], $new_name))
480 {
481 $oid=$this->db->lo_import($new_name);
482 // check if the lob is in the database
483 if ($oid==false)
484 {
485 $this->db->rollback();
486 return 1;
487 }
488 }
489 // the upload in the database is successfull
490 $this->d_lob=$oid;
491 $this->d_filename=$_FILES['file_upload']['name'][$i];
492 $this->d_mimetype=$_FILES['file_upload']['type'][$i];
493 if ( isset($aDescription[$i])) {
494 $description=strip_tags($aDescription[$i]??"");
495 }
496 $this->d_description=$description;
497 // insert into the table
498 $sql="insert into document (ag_id, d_lob,d_filename,d_mimetype,d_number,d_description)"
499 . " values ($1,$2,$3,$4,$5,$6) returning d_id";
500 $document_id=$this->db->get_value($sql,
501 array($p_ag_id, $this->d_lob, $this->d_filename, $this->d_mimetype, 1, $this->d_description));
502
503
504 $document_saved[]=$document_id;
505
506 }
507 } /* end for */
508 $this->db->commit();
509 return $document_saved;
510 }
manage the http input (get , post, request) and extract from an array
$new_name

References $description, $http, $i, $name, $new_name, $sql, and db.

Field Documentation

◆ $ag_id

Document::$ag_id

$ag_id action_gestion.ag_id (pk)

Definition at line 33 of file document.class.php.

Referenced by get_all(), and replace().

◆ $counter

Document::$counter
private

counter for the items ( goods )

Definition at line 40 of file document.class.php.

◆ $d_description

Document::$d_description

Description of the file

Definition at line 37 of file document.class.php.

◆ $d_filename

Document::$d_filename

$d_filename

Definition at line 35 of file document.class.php.

Referenced by transform2pdf().

◆ $d_id

Document::$d_id

$d_id Document id

Definition at line 32 of file document.class.php.

◆ $d_lob

Document::$d_lob

$d_lob the oid of the lob

Definition at line 36 of file document.class.php.

Referenced by remove().

◆ $d_mimetype

Document::$d_mimetype

$d_mimetype

Definition at line 34 of file document.class.php.

◆ $d_number

Document::$d_number

$d_number number of the document

Definition at line 38 of file document.class.php.

Referenced by replace().

◆ $db

Document::$db

$db Database connexion

Definition at line 31 of file document.class.php.

◆ $md_id

Document::$md_id

$md_id document's template

Definition at line 39 of file document.class.php.


The documentation for this class was generated from the following file: