noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_document.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of NOALYSS.
00004  *
00005  *   NOALYSS 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  *   NOALYSS 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 NOALYSS; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00020 require_once('class_own.php');
00021 require_once('class_acc_account_ledger.php');
00022 require_once('class_follow_up.php');
00023 require_once('class_acc_tva.php');
00024 require_once('class_user.php');
00025 require_once('class_zip_extended.php');
00026 
00027 /*! \file
00028  * \brief Class Document corresponds to the table document
00029  */
00030 /*! \brief Class Document corresponds to the table document
00031  */
00032 class Document
00033 {
00034     var $db;          /*!< $db Database connexion*/
00035     var $d_id;        /*!< $d_id Document id */
00036     var $ag_id;       /*!< $ag_id action_gestion.ag_id (pk) */
00037     var $d_mimetype;  /*!< $d_mimetype  */
00038     var $d_filename;  /*!< $d_filename */
00039     var $d_lob;       /*!< $d_lob the oid of the lob */
00040     var $d_description;       /*!< Description of the file*/
00041     var $d_number;    /*!< $d_number number of the document */
00042     var $md_id;       /*!< $md_id document's template */
00043     /* Constructor
00044      * \param $p_cn Database connection
00045      */
00046     function Document($p_cn,$p_d_id=0)
00047     {
00048         $this->db=$p_cn;
00049         $this->d_id=$p_d_id;
00050         $this->counter=0;
00051     }
00052     /*!\brief insert a minimal document and set the d_id
00053      */
00054     function blank()
00055     {
00056         $this->d_id=$this->db->get_next_seq("document_d_id_seq");
00057         // affect a number
00058         $this->d_number=$this->db->get_next_seq("seq_doc_type_".$this->md_type);
00059         $sql=sprintf('insert into document(d_id,ag_id,d_number) values(%d,%d,%d)',
00060                      $this->d_id,
00061                      $this->ag_id,
00062                      $this->d_number);
00063         $this->db->exec_sql($sql);
00064 
00065     }
00066         function compute_filename($pj,$filename)
00067         {
00068                 foreach (array('/','*','<','>',';',',','\\','.',':') as $i) {
00069                         $pj= str_replace($i, "-",$pj);
00070                 }
00071                 // save the suffix
00072                 $pos_prefix=strrpos($filename,".");
00073                 if ($pos_prefix == 0) $pos_prefix=strlen($filename);
00074                 $filename_no=substr($filename,0,$pos_prefix);
00075                 $filename_suff=substr($filename,$pos_prefix,strlen($filename));
00076                 $new_filename=  strtolower($filename_no."-".$pj.$filename_suff);
00077                 return $new_filename;
00078         }
00079     /*!
00080      * \brief Generate the document, Call $this->Replace to replace
00081      *        tag by value
00082      *@param p_array contains the data normally it is the $_POST
00083      *@param contains the new filename
00084      * \return an array : the url where the generated doc can be found, the name
00085      * of the file and his mimetype
00086      */
00087     function Generate($p_array,$p_filename="")
00088     {
00089         // create a temp directory in /tmp to unpack file and to parse it
00090         $dirname=tempnam($_ENV['TMP'],'doc_');
00091 
00092 
00093         unlink($dirname);
00094         mkdir ($dirname);
00095         // Retrieve the lob and save it into $dirname
00096         $this->db->start();
00097         $dm_info="select md_name,md_type,md_lob,md_filename,md_mimetype
00098                  from document_modele where md_id=".$this->md_id;
00099         $Res=$this->db->exec_sql($dm_info);
00100 
00101         $row=Database::fetch_array($Res,0);
00102         $this->d_lob=$row['md_lob'];
00103         $this->d_filename=$row['md_filename'];
00104         $this->d_mimetype=$row['md_mimetype'];
00105         $this->d_name=$row['md_name'];
00106 
00107 
00108         chdir($dirname);
00109         $filename=$row['md_filename'];
00110         $exp=$this->db->lo_export($row['md_lob'],$dirname.DIRECTORY_SEPARATOR.$filename);
00111         if ( $exp === false ) echo_warning( __FILE__.":".__LINE__."Export NOK $filename");
00112 
00113         $type="n";
00114         // if the doc is a OOo, we need to unzip it first
00115         // and the name of the file to change is always content.xml
00116         if ( strpos($row['md_mimetype'],'vnd.oasis') != 0 )
00117         {
00118             ob_start();
00119             $zip = new Zip_Extended;
00120             if ($zip->open($filename) === TRUE) {
00121               $zip->extractTo($dirname.DIRECTORY_SEPARATOR);
00122               $zip->close();
00123             } else {
00124               echo __FILE__.":".__LINE__."cannot unzip model ".$filename;
00125             }
00126 
00127             // Remove the file we do  not need anymore
00128             unlink($filename);
00129             ob_end_clean();
00130             $file_to_parse="content.xml";
00131             $type="OOo";
00132         }
00133         else
00134             $file_to_parse=$filename;
00135         // affect a number
00136         $this->d_number=$this->db->get_next_seq("seq_doc_type_".$row['md_type']);
00137 
00138         // parse the document - return the doc number ?
00139         $this->ParseDocument($dirname,$file_to_parse,$type,$p_array);
00140 
00141         $this->db->commit();
00142         // if the doc is a OOo, we need to re-zip it
00143         if ( strpos($row['md_mimetype'],'vnd.oasis') != 0 )
00144         {
00145             ob_start();
00146             $zip = new Zip_Extended;
00147             $res = $zip->open($filename, ZipArchive::CREATE);
00148             if($res !== TRUE)
00149               {
00150                 throw new Exception ( __FILE__.":".__LINE__."cannot recreate zip");
00151               }
00152             $zip->add_recurse_folder($dirname.DIRECTORY_SEPARATOR);
00153             $zip->close();
00154 
00155             ob_end_clean();
00156 
00157             $file_to_parse=$filename;
00158         }
00159                 if ( $p_filename !="") {
00160 
00161                         $this->d_filename=$this->compute_filename($p_filename, $this->d_filename);
00162                 }
00163         $this->SaveGenerated($dirname.DIRECTORY_SEPARATOR.$file_to_parse);
00164         // Invoice
00165         $ret='<A class="mtitle" HREF="show_document.php?d_id='.$this->d_id.'&'.dossier::get().'">Document g&eacute;n&eacute;r&eacute;</A>';
00166         @rmdir($dirname);
00167         return $ret;
00168     }
00169 
00170     /*! ParseDocument
00171      * \brief This function parse a document and replace all
00172      *        the predefined tags by a value. This functions
00173      *        generate diffent documents (invoice, order, letter)
00174      *        with the info from the database
00175      *
00176      * \param $p_dir directory name
00177      * \param $p_file filename
00178      * \param $p_type For the OOo document the tag are &lt and &gt instead of < and >
00179      * \param $p_array variable from $_POST
00180      */
00181     function ParseDocument($p_dir,$p_file,$p_type,$p_array)
00182     {
00183 
00184         /*!\note Replace in the doc the tags by their values.
00185          *  - MY_*   table parameter
00186          *  - ART_VEN* table quant_sold for invoice
00187          *  - CUST_* table quant_sold and fiche for invoice
00188          *  - e_* for the invoice in the $_POST
00189          */
00190         // open the document
00191         $infile_name=$p_dir.DIRECTORY_SEPARATOR.$p_file;
00192         $h=fopen($infile_name,"r");
00193 
00194         // check if tmpdir exist otherwise create it
00195         $temp_dir=$_SERVER["DOCUMENT_ROOT"].DIRECTORY_SEPARATOR.'tmp';
00196         if ( is_dir($temp_dir) == false )
00197         {
00198             if ( mkdir($temp_dir) == false )
00199             {
00200                 $msg=_("Ne peut pas créer le répertoire ".$temp_dir); 
00201                 throw new Exception($msg);
00202             }
00203         }
00204         // Compute output_name
00205         $output_name=tempnam($temp_dir,"gen_doc_");
00206         $output_file=fopen($output_name,"w+");
00207         // check if the opening is sucessfull
00208         if (  $h === false )
00209         {
00210             echo __FILE__.":".__LINE__."cannot open $p_dir $p_file ";
00211             $msg=_("Ne peut pas ouvrir $p_dir $p_file"); 
00212             throw new Exception($msg);
00213         }
00214         if ( $output_file == false)
00215         {
00216             $msg=_("Ne peut pas ouvrir $p_dir $p_file"); 
00217             echo $msg;
00218             throw new Exception($msg);
00219         }
00220         // compute the regex
00221         if ( $p_type=='OOo')
00222         {
00223             $regex="/=*&lt;&lt;[A-Z]+_*[A-Z]*_*[A-Z]*_*[A-Z]*_*[0-9]*&gt;&gt;/i";
00224             $lt="&lt;";
00225             $gt="&gt;";
00226         }
00227         else
00228         {
00229             $regex="/=*<<[A-Z]+_*[A-Z]*_*[A-Z]*_*[A-Z]*_*[0-9]*>>/i";
00230             $lt="<";
00231             $gt=">";
00232         }
00233 
00234         //read the file
00235         while(! feof($h))
00236           {
00237             // replace the tag
00238             $buffer=fgets($h);
00239             // search in the buffer the magic << and >>
00240             // while preg_match_all finds something to replace
00241             while ( preg_match_all ($regex,$buffer,$f) >0  )
00242               {
00243 
00244 
00245                 foreach ( $f as $apattern )
00246                   {
00247 
00248 
00249                     foreach($apattern as $pattern)
00250                       {
00251 
00252 
00253                         $to_remove=$pattern;
00254                         // we remove the < and > from the pattern
00255                         $tag=str_replace($lt,'',$pattern);
00256                         $tag=str_replace($gt,'',$tag);
00257 
00258 
00259                         // if the pattern if found we replace it
00260                         $value=$this->Replace($tag,$p_array);
00261                         if ( strpos($value,'ERROR') != false )            $value="";
00262                         /*
00263                          * Change type of cell to numeric
00264                          *  allow numeric cel in ODT for the formatting and formula
00265                          */
00266                         if ( is_numeric($value) && $p_type=='OOo')
00267                           {
00268                             $searched='/office:value-type="string"><text:p>'.$pattern.'/';
00269                             $replaced='office:value-type="float" office:value="'.$value.'"><text:p>'.$pattern;
00270                             $buffer=preg_replace($searched, $replaced, $buffer,1);
00271                           }
00272                         // replace into the $buffer
00273                         // take the position in the buffer
00274                         $pos=strpos($buffer,$to_remove);
00275                         // get the length of the string to remove
00276                         $len=strlen($to_remove);
00277                         if ( $p_type=='OOo' )
00278                           {
00279                             $value=str_replace('&','&amp;',$value);
00280                             $value=str_replace('<','&lt;',$value);
00281                             $value=str_replace('>','&gt;',$value);
00282                             $value=str_replace('"','&quot;',$value);
00283                             $value=str_replace("'",'&apos;',$value);
00284                           }
00285                         $buffer=substr_replace($buffer,$value,$pos,$len);
00286 
00287                         // if the pattern if found we replace it
00288                       }
00289                   }
00290               }
00291             // write into the output_file
00292             fwrite($output_file,$buffer);
00293 
00294           }
00295         fclose($h);
00296         fclose($output_file);
00297         if ( ($ret=copy ($output_name,$infile_name)) == FALSE )
00298         {
00299             echo _('Ne peut pas sauver '.$output_name.' vers '.$infile_name.' code d\'erreur ='.$ret);
00300         }
00301 
00302 
00303     }
00304     /*! SaveGenerated
00305      * \brief Save the generated Document
00306      * \param $p_file is the generated file
00307      *
00308      *
00309      * \return 0 if no error otherwise 1
00310      */
00311     function SaveGenerated($p_file)
00312     {
00313         // We save the generated file
00314         $doc=new Document($this->db);
00315         $this->db->start();
00316         $this->d_lob=$this->db->lo_import($p_file);
00317         if ( $this->d_lob == false )
00318         {
00319             echo "ne peut pas importer [$p_file]";
00320             return 1;
00321         }
00322 
00323         $sql="insert into document(ag_id,d_lob,d_number,d_filename,d_mimetype)
00324              values ($1,$2,$3,$4,$5)";
00325 
00326         $this->db->exec_sql($sql,      array($this->ag_id,
00327                                              $this->d_lob,
00328                                              $this->d_number,
00329                                              $this->d_filename,
00330                                              $this->d_mimetype));
00331         $this->d_id=$this->db->get_current_seq("document_d_id_seq");
00332         // Clean the file
00333         unlink ($p_file);
00334         $this->db->commit();
00335         return 0;
00336     }
00337     /*! Upload
00338      * \brief Upload a file into document
00339      *  all the needed data are in $_FILES we don't increment the seq
00340      * \param $p_file : array containing by default $_FILES
00341      *
00342      * \return
00343      */
00344     function Upload($p_ag_id)
00345     {
00346         // nothing to save
00347         if ( sizeof($_FILES) == 0 ) return;
00348 
00349         /* for several files  */
00350         /* $_FILES is now an array */
00351         // Start Transaction
00352         $this->db->start();
00353         $name=$_FILES['file_upload']['name'];
00354         for ($i = 0; $i < sizeof($name);$i++)
00355         {
00356             $new_name=tempnam($_ENV['TMP'],'doc_');
00357             // check if a file is submitted
00358             if ( strlen($_FILES['file_upload']['tmp_name'][$i]) != 0 )
00359             {
00360                 // upload the file and move it to temp directory
00361                 if ( move_uploaded_file($_FILES['file_upload']['tmp_name'][$i],$new_name))
00362                 {
00363                     $oid=$this->db->lo_import($new_name);
00364                     // check if the lob is in the database
00365                     if ( $oid == false )
00366                     {
00367                         $this->db->rollback();
00368                         return 1;
00369                     }
00370                 }
00371                 // the upload in the database is successfull
00372                 $this->d_lob=$oid;
00373                 $this->d_filename=$_FILES['file_upload']['name'][$i];
00374                 $this->d_mimetype=$_FILES['file_upload']['type'][$i];
00375                 $this->d_description=  strip_tags($_POST['input_desc'][$i]);
00376                 // insert into  the table
00377                 $sql="insert into document (ag_id, d_lob,d_filename,d_mimetype,d_number,d_description) values ($1,$2,$3,$4,$5,$6)";
00378                 $this->db->exec_sql($sql,array($p_ag_id,$this->d_lob,$this->d_filename,$this->d_mimetype,1,$this->d_description));
00379             }
00380         } /* end for */
00381         $this->db->commit();
00382 
00383     }
00384     /**
00385      * Copy a existing OID (LOB) into the table document
00386      * @note  use of global variable $cn which is the db connx to the current folder
00387      * @param type $p_ag_id Follow_Up::ag_id
00388      * @param type $p_lob oid of existing document
00389      * @param type $p_filename filename of existing document
00390      * @param type $p_mimetype mimetype of existing document
00391      * @param type $p_description Description of existing document (default empty)
00392      */
00393     static function insert_existing_document($p_ag_id, $p_lob, $p_filename, $p_mimetype, $p_description = "")
00394     {
00395         global $cn;
00396         // insert into  the table
00397         $sql = "insert into document (ag_id, d_lob,d_filename,d_mimetype,d_number,d_description) values ($1,$2,$3,$4,$5,$6)";
00398         $cn->exec_sql($sql, array($p_ag_id, $p_lob, $p_filename, $p_mimetype, 1, $p_description));
00399     }
00400 
00401     /*! a_ref
00402      * \brief create and compute a string for reference the doc <A ...>
00403      *
00404      * \return a string
00405      */
00406     function anchor()
00407     {
00408         if ( $this->d_id == 0 )
00409             return '';
00410         $image='<IMG SRC="image/insert_table.gif" title="'.$this->d_filename.'" border="0">';
00411         $r="";
00412         $r='<A class="mtitle" HREF="show_document.php?d_id='.$this->d_id.'&'.dossier::get().'">'.$image.'</A>';
00413         return $r;
00414     }
00415     /** Get
00416      * \brief Send the document
00417      */
00418     function Send()
00419     {
00420         // retrieve the template and generate document
00421         $this->db->start();
00422         $ret=$this->db->exec_sql(
00423                  "select d_id,d_lob,d_filename,d_mimetype from document where d_id=".$this->d_id );
00424         if ( Database::num_row ($ret) == 0 )
00425             return;
00426         $row=Database::fetch_array($ret,0);
00427         //the document  is saved into file $tmp
00428         $tmp=tempnam($_ENV['TMP'],'document_');
00429         $this->db->lo_export($row['d_lob'],$tmp);
00430         $this->d_mimetype=$row['d_mimetype'];
00431         $this->d_filename=$row['d_filename'];
00432 
00433         // send it to stdout
00434         ini_set('zlib.output_compression','Off');
00435         header("Pragma: public");
00436         header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
00437         header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
00438         header("Cache-Control: must-revalidate");
00439         header('Content-type: '.$this->d_mimetype);
00440         header('Content-Disposition: attachment;filename="'.$this->d_filename.'"',FALSE);
00441         header("Accept-Ranges: bytes");
00442         $file=fopen($tmp,'r');
00443         while ( !feof ($file) )
00444         {
00445             echo fread($file,8192);
00446         }
00447         fclose($file);
00448 
00449         unlink ($tmp);
00450 
00451         $this->db->commit();
00452 
00453     }
00454     /*!\brief get all the document of a given action
00455      *\param $ag_id the ag_id from action::ag_id (primary key)
00456      *\return an array of objects document or an empty array if nothing found
00457      */
00458     function get_all($ag_id)
00459     {
00460         $res=$this->db->get_array('select d_id, ag_id, d_lob, d_number, d_filename,'.
00461                                   ' d_mimetype,d_description from document where ag_id=$1',array($ag_id));
00462         $a=array();
00463         for ($i=0;$i<sizeof($res); $i++ )
00464         {
00465             $doc=new Document($this->db);
00466             $doc->d_id=$res[$i]['d_id'];
00467             $doc->ag_id=$res[$i]['ag_id'];
00468             $doc->d_lob=$res[$i]['d_lob'];
00469             $doc->d_number=$res[$i]['d_number'];
00470             $doc->d_filename=$res[$i]['d_filename'];
00471             $doc->d_mimetype=$res[$i]['d_mimetype'];
00472             $doc->d_description=$row['d_description'];
00473             $a[$i]=clone $doc;
00474         }
00475         return $a;
00476     }
00477 
00478     /*!\brief Get  complete all the data member thx info from the database
00479      */
00480     function get()
00481     {
00482         $sql="select * from document where d_id=".$this->d_id;
00483         $ret=$this->db->exec_sql($sql);
00484         if ( Database::num_row($ret) == 0 )
00485             return;
00486         $row=Database::fetch_array($ret,0);
00487         $this->ag_id=$row['ag_id'];
00488         $this->d_mimetype=$row['d_mimetype'];
00489         $this->d_filename=$row['d_filename'];
00490         $this->d_lob=$row['d_lob'];
00491         $this->d_number=$row['d_number'];
00492         $this->d_description=$row['d_description'];
00493 
00494     }
00495     /*!
00496      * \brief replace the TAG by the real value, this value can be into
00497      * the database or in $_POST
00498      * The possible tags are
00499      *  - [CUST_NAME] customer's name
00500      *  - [CUST_ADDR_1] customer's address line 1
00501      *  - [CUST_CP] customer's ZIP code
00502      *  - [CUST_CO] customer's country
00503      *  - [CUST_CITY] customer's city
00504      *  - [CUST_VAT] customer's VAT
00505      *  - [MARCH_NEXT]   end this item and increment the counter $i
00506      *  - [DATE_LIMIT]
00507      *  - [VEN_ART_NAME]
00508      *  - [VEN_ART_PRICE]
00509      *  - [VEN_ART_QUANT]
00510      *  - [VEN_ART_TVA_CODE]
00511      *  - [VEN_ART_STOCK_CODE]
00512      *  - [VEN_HTVA]
00513      *  - [VEN_TVAC]
00514      *  - [VEN_TVA]
00515      *  - [TOTAL_VEN_HTVA]
00516      *  - [DATE_CALC]
00517      *  - [DATE]
00518      *  - [DATE_LIMIT]
00519      *  - [DATE_LIMIT_CALC]
00520      *  - [NUMBER]
00521      *  - [MY_NAME]
00522      *  - [MY_CP]
00523      *  - [MY_COMMUNE]
00524      *  - [MY_TVA]
00525      *  - [MY_STREET]
00526      *  - [MY_NUMBER]
00527      *  - [TVA_CODE]
00528      *  - [TVA_RATE]
00529      *  - [BON_COMMANDE]
00530      *  - [OTHER_INFO]
00531      *  - [CUST_NUM]
00532      *  - [CUST_BANQUE_NAME]
00533      *  - [CUST_BANQUE_NO]
00534      *  - [USER]
00535      *  - [REFERENCE]
00536      *  - [BENEF_NAME]
00537      *  - [BENEF_BANQUE_NAME]
00538      *  - [BENEF_BANQUE_NO]
00539      *  - [BENEF_ADDR_1]
00540      *  - [BENEF_CP]
00541      *  - [BENEF_CO]
00542      *  - [BENEF_CITY]
00543      *  - [BENEF_VAT]
00544      *  - [ACOMPTE]
00545      *  - [TITLE]
00546      *  - [DESCRIPTION]
00547      *
00548      * \param $p_tag TAG
00549      * \param $p_array data from $_POST
00550      * \return String which must replace the tag
00551      */
00552     function Replace($p_tag,$p_array)
00553     {
00554                 global $g_parameter;
00555         $p_tag=strtoupper($p_tag);
00556         $p_tag=str_replace('=','',$p_tag);
00557         $r="Tag inconnu";
00558 
00559         switch ($p_tag)
00560         {
00561                 case 'DATE':
00562                         $r=(isset ($p_array['ag_timestamp']))?$p_array['ag_timestamp']:$p_array['e_date'];
00563                         break;
00564         case 'DATE_CALC':
00565                 $r=' Date inconnue ';
00566             // Date are in $p_array['ag_date']
00567             // or $p_array['e_date']
00568             if ( isset ($p_array['ag_timestamp'])) {
00569                 $date=format_date($p_array['ag_timestamp'],'DD.MM.YYYY','YYYY-MM-DD');
00570                 $r=$date;
00571             }
00572             if ( isset ($p_array['e_date'])) {
00573                 $date=format_date($p_array['e_date'],'DD.MM.YYYY','YYYY-MM-DD');
00574                 $r=$date;
00575             }
00576             break;
00577             //
00578             //  the company priv
00579 
00580         case 'MY_NAME':
00581             $r=$g_parameter->MY_NAME;
00582             break;
00583         case 'MY_CP':
00584             $r=$g_parameter->MY_CP;
00585             break;
00586         case 'MY_COMMUNE':
00587             $r=$g_parameter->MY_COMMUNE;
00588             break;
00589         case 'MY_TVA':
00590             $r=$g_parameter->MY_TVA;
00591             break;
00592         case 'MY_STREET':
00593             $r=$g_parameter->MY_STREET;
00594             break;
00595         case 'MY_NUMBER':
00596             $r=$g_parameter->MY_NUMBER;
00597             break;
00598         case 'MY_TEL':
00599             $r=$g_parameter->MY_TEL;
00600             break;
00601         case 'MY_FAX':
00602             $r=$g_parameter->MY_FAX;
00603             break;
00604         case 'MY_PAYS':
00605             $r=$g_parameter->MY_PAYS;
00606             break;
00607 
00608             // customer
00609             /*\note The CUST_* are retrieved thx the $p_array['tiers']
00610              * which contains the quick_code
00611              */
00612         case 'SOLDE':
00613             $tiers=new Fiche($this->db);
00614             $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
00615             $tiers->get_by_qcode($qcode,false);
00616             $p=$tiers->strAttribut(ATTR_DEF_ACCOUNT);
00617             $poste=new Acc_Account_Ledger($this->db,$p);
00618             $r=$poste->get_solde(' true' );
00619             break;
00620         case 'CUST_NAME':
00621             $tiers=new Fiche($this->db);
00622             $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
00623             $tiers->get_by_qcode($qcode,false);
00624             $r=$tiers->strAttribut(ATTR_DEF_NAME);
00625             break;
00626         case 'CUST_ADDR_1':
00627             $tiers=new Fiche($this->db);
00628             $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
00629             $tiers->get_by_qcode($qcode,false);
00630             $r=$tiers->strAttribut(ATTR_DEF_ADRESS);
00631 
00632             break ;
00633         case 'CUST_CP':
00634             $tiers=new Fiche($this->db);
00635 
00636             $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
00637             $tiers->get_by_qcode($qcode,false);
00638             $r=$tiers->strAttribut(ATTR_DEF_CP);
00639 
00640             break;
00641         case 'CUST_CITY':
00642             $tiers=new Fiche($this->db);
00643 
00644             $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
00645             $tiers->get_by_qcode($qcode,false);
00646             $r=$tiers->strAttribut(ATTR_DEF_CITY);
00647 
00648             break;
00649 
00650         case 'CUST_CO':
00651             $tiers=new Fiche($this->db);
00652 
00653             $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
00654             $tiers->get_by_qcode($qcode,false);
00655             $r=$tiers->strAttribut(ATTR_DEF_PAYS);
00656 
00657             break;
00658             // Marchandise in $p_array['e_march*']
00659             // \see user_form_achat.php or user_form_ven.php
00660         case 'CUST_VAT':
00661             $tiers=new Fiche($this->db);
00662 
00663             $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
00664             $tiers->get_by_qcode($qcode,false);
00665             $r=$tiers->strAttribut(ATTR_DEF_NUMTVA);
00666             break;
00667         case 'CUST_NUM':
00668             $tiers=new Fiche($this->db);
00669             $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
00670             $tiers->get_by_qcode($qcode,false);
00671             $r=$tiers->strAttribut(ATTR_DEF_NUMBER_CUSTOMER);
00672             break;
00673         case 'CUST_BANQUE_NO':
00674             $tiers=new Fiche($this->db);
00675             $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
00676             $tiers->get_by_qcode($qcode,false);
00677             $r=$tiers->strAttribut(ATTR_DEF_BQ_NO);
00678             break;
00679         case 'CUST_BANQUE_NAME':
00680             $tiers=new Fiche($this->db);
00681             $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
00682             $tiers->get_by_qcode($qcode,false);
00683             $r=$tiers->strAttribut(ATTR_DEF_BQ_NAME);
00684             break;
00685             /* -------------------------------------------------------------------------------- */
00686             /* BENEFIT (fee notes */
00687         case 'BENEF_NAME':
00688             $tiers=new Fiche($this->db);
00689             $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
00690             if ( $qcode=='')
00691             {
00692                 $r='';
00693                 break;
00694             }
00695             $tiers->get_by_qcode($qcode,false);
00696             $r=$tiers->strAttribut(ATTR_DEF_NAME);
00697             break;
00698         case 'BENEF_ADDR_1':
00699             $tiers=new Fiche($this->db);
00700             $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
00701             if ( $qcode=='')
00702             {
00703                 $r='';
00704                 break;
00705             }
00706             $tiers->get_by_qcode($qcode,false);
00707             $r=$tiers->strAttribut(ATTR_DEF_ADRESS);
00708 
00709             break ;
00710         case 'BENEF_CP':
00711             $tiers=new Fiche($this->db);
00712 
00713             $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
00714             if ( $qcode=='')
00715             {
00716                 $r='';
00717                 break;
00718             }
00719             $tiers->get_by_qcode($qcode,false);
00720             $r=$tiers->strAttribut(ATTR_DEF_CP);
00721 
00722             break;
00723         case 'BENEF_CITY':
00724             $tiers=new Fiche($this->db);
00725 
00726             $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
00727             if ( $qcode=='')
00728             {
00729                 $r='';
00730                 break;
00731             }
00732             $tiers->get_by_qcode($qcode,false);
00733             $r=$tiers->strAttribut(ATTR_DEF_CITY);
00734 
00735             break;
00736 
00737         case 'BENEF_CO':
00738             $tiers=new Fiche($this->db);
00739 
00740             $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
00741             if ( $qcode=='')
00742             {
00743                 $r='';
00744                 break;
00745             }
00746             $tiers->get_by_qcode($qcode,false);
00747             $r=$tiers->strAttribut(ATTR_DEF_PAYS);
00748 
00749             break;
00750             // Marchandise in $p_array['e_march*']
00751             // \see user_form_achat.php or user_form_ven.php
00752         case 'BENEF_VAT':
00753             $tiers=new Fiche($this->db);
00754 
00755             $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
00756             if ( $qcode=='')
00757             {
00758                 $r='';
00759                 break;
00760             }
00761             $tiers->get_by_qcode($qcode,false);
00762             $r=$tiers->strAttribut(ATTR_DEF_NUMTVA);
00763             break;
00764         case 'BENEF_NUM':
00765             $tiers=new Fiche($this->db);
00766             $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
00767             if ( $qcode=='')
00768             {
00769                 $r='';
00770                 break;
00771             }
00772             $tiers->get_by_qcode($qcode,false);
00773             $r=$tiers->strAttribut(ATTR_DEF_NUMBER_CUSTOMER);
00774             break;
00775         case 'BENEF_BANQUE_NO':
00776             $tiers=new Fiche($this->db);
00777             $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
00778             if ( $qcode=='')
00779             {
00780                 $r='';
00781                 break;
00782             }
00783             $tiers->get_by_qcode($qcode,false);
00784             $r=$tiers->strAttribut(ATTR_DEF_BQ_NO);
00785             break;
00786         case 'BENEF_BANQUE_NAME':
00787             $tiers=new Fiche($this->db);
00788             $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
00789             if ( $qcode=='')
00790             {
00791                 $r='';
00792                 break;
00793             }
00794             $tiers->get_by_qcode($qcode,false);
00795             $r=$tiers->strAttribut(ATTR_DEF_BQ_NAME);
00796             break;
00797 
00798             // Marchandise in $p_array['e_march*']
00799             // \see user_form_achat.php or user_form_ven.php
00800         case 'NUMBER':
00801             $r=$this->d_number;
00802             break;
00803 
00804         case 'USER' :
00805             return $_SESSION['use_name'].', '.$_SESSION['use_first_name'];
00806 
00807             break;
00808         case 'REFERENCE':
00809             $act=new Follow_Up($this->db);
00810             $act->ag_id=$this->ag_id;
00811             $act->get();
00812             $r=$act->ag_ref;
00813             break;
00814 
00815             /*
00816              *  - [VEN_ART_NAME]
00817              *  - [VEN_ART_PRICE]
00818              *  - [VEN_ART_QUANT]
00819              *  - [VEN_ART_TVA_CODE]
00820              *  - [VEN_ART_STOCK_CODE]
00821              *  - [VEN_HTVA]
00822              *  - [VEN_TVAC]
00823              *  - [VEN_TVA]
00824              *  - [TOTAL_VEN_HTVA]
00825              *  - [DATE_LIMIT]
00826              */
00827         case 'DATE_LIMIT_CALC':
00828             extract ($p_array);
00829             $id='e_ech' ;
00830             if ( !isset (${$id}) ) return "";
00831             $r=format_date(${$id},'DD.MM.YYYY','YYYY-MM-DD');
00832             break;
00833       case 'DATE_LIMIT':
00834             extract ($p_array);
00835             $id='e_ech' ;
00836             if ( !isset (${$id}) ) return "";
00837             $r=${$id};
00838             break;
00839         case 'MARCH_NEXT':
00840             $this->counter++;
00841             $r='';
00842             break;
00843 
00844         case 'VEN_ART_NAME':
00845             extract ($p_array);
00846             $id='e_march'.$this->counter;
00847             // check if the march exists
00848             if ( ! isset (${$id})) return "";
00849             // check that something is sold
00850             if ( ${'e_march'.$this->counter.'_price'} != 0 && ${'e_quant'.$this->counter} != 0 )
00851             {
00852                 $f=new Fiche($this->db);
00853                 $f->get_by_qcode(${$id},false);
00854                 $r=$f->strAttribut(ATTR_DEF_NAME);
00855             }
00856             else $r = "";
00857             break;
00858        case 'VEN_ART_LABEL':
00859             extract ($p_array);
00860             $id='e_march'.$this->counter."_label";
00861             // check if the march exists
00862 
00863             if (! isset (${$id}) || (isset (${$id}) && strlen(trim(${$id})) == 0))
00864                 {
00865                     $id = 'e_march' . $this->counter;
00866                     // check if the march exists
00867                     if (!isset(${$id}))
00868                         $r= "";
00869                     else 
00870                     {
00871                     // check that something is sold
00872                         if (${'e_march' . $this->counter . '_price'} != 0 && ${'e_quant' . $this->counter} != 0)
00873                         {
00874                             $f = new Fiche($this->db);
00875                             $f->get_by_qcode(${$id}, false);
00876                             $r = $f->strAttribut(ATTR_DEF_NAME);
00877                         } else
00878                             $r = "";
00879                     }
00880                 }
00881                 else
00882                     $r=${'e_march'.$this->counter.'_label'};
00883             break;
00884         case 'VEN_ART_STOCK_CODE':
00885             extract ($p_array);
00886                     $id = 'e_march' . $this->counter;
00887                     // check if the march exists
00888                     if (!isset(${$id}))
00889                         $r= "";
00890                     else 
00891                     {
00892                     // check that something is sold
00893                         if (${'e_march' . $this->counter . '_price'} != 0 && ${'e_quant' . $this->counter} != 0)
00894                         {
00895                             $f = new Fiche($this->db);
00896                             $f->get_by_qcode(${$id}, false);
00897                             $r = $f->strAttribut(ATTR_DEF_STOCK);
00898                             $r=($r == NOTFOUND)?'':$r;
00899                         } 
00900                     }
00901             break;
00902         case 'VEN_ART_PRICE':
00903             extract ($p_array);
00904             $id='e_march'.$this->counter.'_price' ;
00905             if ( !isset (${$id}) ) return "";
00906                         if (${$id} == 0 ) return "";
00907             $r=${$id};
00908             break;
00909 
00910         case 'TVA_RATE':
00911         case 'VEN_ART_TVA_RATE':
00912             extract ($p_array);
00913             $id='e_march'.$this->counter.'_tva_id';
00914             if ( !isset (${$id}) ) return "";
00915             if ( ${$id} == -1 || ${$id}=='' ) return "";
00916             $march_id='e_march'.$this->counter.'_price' ;
00917             if ( ! isset (${$march_id})) return '';
00918             $tva=new Acc_Tva($this->db);
00919             $tva->set_parameter("id",${$id});
00920             if ( $tva->load() == -1) return '';
00921             return $tva->get_parameter("rate");
00922             break;
00923 
00924         case 'TVA_CODE':
00925         case 'VEN_ART_TVA_CODE':
00926             extract ($p_array);
00927             $id='e_march'.$this->counter.'_tva_id';
00928             if ( !isset (${$id}) ) return "";
00929             if ( ${$id} == -1 ) return "";
00930             $qt='e_quant'.$this->counter;
00931             $price='e_march'.$this->counter.'_price' ;
00932             if ( ${$price} == 0 || ${$qt} == 0
00933                     || strlen(trim( $price )) ==0
00934                     || strlen(trim($qt)) ==0)
00935                 return "";
00936 
00937             $r=${$id};
00938             break;
00939 
00940         case 'TVA_LABEL':
00941             extract ($p_array);
00942             $id='e_march'.$this->counter.'_tva_id';
00943             if ( !isset (${$id}) ) return "";
00944             $march_id='e_march'.$this->counter.'_price' ;
00945             if ( ! isset (${$march_id})) return '';
00946             if ( ${$march_id} == 0) return '';
00947             $tva=new Acc_Tva($this->db,${$id});
00948             if ($tva->load() == -1 ) return "";
00949             $r=$tva->get_parameter('label');
00950 
00951             break;
00952 
00953             /* total VAT for one sold */
00954         case 'TVA_AMOUNT':
00955         case 'VEN_TVA':
00956             extract ($p_array);
00957             $qt='e_quant'.$this->counter;
00958             $price='e_march'.$this->counter.'_price' ;
00959             $tva='e_march'.$this->counter.'_tva_id';
00960             /* if we do not use vat this var. is not set */
00961             if ( !isset(${$tva}) ) return '';
00962             if ( !isset (${'e_march'.$this->counter}) ) return "";
00963             // check that something is sold
00964             if ( ${$price} == 0 || ${$qt} == 0
00965                     || strlen(trim( $price )) ==0
00966                     || strlen(trim($qt)) ==0)
00967                 return "";
00968             $r=${'e_march'.$this->counter.'_tva_amount'};
00969             break;
00970             /* TVA automatically computed */
00971         case 'VEN_ART_TVA':
00972         
00973             extract ($p_array);
00974             $qt='e_quant'.$this->counter;
00975             $price='e_march'.$this->counter.'_price' ;
00976             $tva='e_march'.$this->counter.'_tva_id';
00977             if ( !isset (${'e_march'.$this->counter}) ) return "";
00978             // check that something is sold
00979             if ( ${$price} == 0 || ${$qt} == 0
00980                     || strlen(trim( $price )) ==0
00981                     || strlen(trim($qt)) ==0)
00982                 return "";
00983             $oTva=new Acc_Tva($this->db,${$tva});
00984             if ($oTva->load() == -1 ) return "";
00985             $r=round(${$price},2)*$oTva->get_parameter('rate');
00986             $r=round($r,2);
00987             break;
00988 
00989         case 'VEN_ART_TVAC':
00990             extract ($p_array);
00991             $qt='e_quant'.$this->counter;
00992             $price='e_march'.$this->counter.'_price' ;
00993             $tva='e_march'.$this->counter.'_tva_id';
00994             if ( !isset (${'e_march'.$this->counter}) ) return "";
00995             // check that something is sold
00996             if ( ${$price} == 0 || ${$qt} == 0
00997                     || strlen(trim( $price )) ==0
00998                     || strlen(trim($qt)) ==0)
00999                 return "";
01000             if ( ! isset (${$tva}) ) return '';
01001             $tva=new Acc_Tva($this->db,${$tva});
01002             if ($tva->load() == -1 )
01003             {
01004                 $r=round(${$price},2);
01005             }
01006             else
01007             {
01008                 $r=round(${$price}*$tva->get_parameter('rate')+${$price},2);
01009             }
01010 
01011             break;
01012 
01013         case 'VEN_ART_QUANT':
01014             extract ($p_array);
01015             $id='e_quant'.$this->counter;
01016             if ( !isset (${$id}) ) return "";
01017             // check that something is sold
01018             if ( ${'e_march'.$this->counter.'_price'} == 0
01019                     || ${'e_quant'.$this->counter} == 0
01020                     || strlen(trim( ${'e_march'.$this->counter.'_price'} )) ==0
01021                     || strlen(trim(${'e_quant'.$this->counter})) ==0 )
01022                 return "";
01023             $r=${$id};
01024             break;
01025 
01026         case 'VEN_HTVA':
01027             extract ($p_array);
01028             $id='e_march'.$this->counter.'_price' ;
01029             $quant='e_quant'.$this->counter;
01030             if ( !isset (${$id}) ) return "";
01031 
01032             // check that something is sold
01033             if ( ${'e_march'.$this->counter.'_price'} == 0 || ${'e_quant'.$this->counter} == 0
01034                     || strlen(trim( ${'e_march'.$this->counter.'_price'} )) ==0
01035                     || strlen(trim(${'e_quant'.$this->counter})) ==0)
01036                 return "";
01037                         bcscale(4);
01038             $r=bcmul(${$id},${$quant});
01039                         $r=round($r,2);
01040             break;
01041 
01042         case 'VEN_TVAC':
01043             extract ($p_array);
01044             $id='e_march'.$this->counter.'_tva_amount' ;
01045             $price='e_march'.$this->counter.'_price' ;
01046             $quant='e_quant'.$this->counter;
01047             if ( ! isset(${'e_march'.$this->counter.'_price'})|| !isset(${'e_quant'.$this->counter}))     return "";
01048             // check that something is sold
01049             if ( ${'e_march'.$this->counter.'_price'} == 0 || ${'e_quant'.$this->counter} == 0 ) return "";
01050                         bcscale(4);
01051             // if TVA not exist
01052             if ( ! isset(${$id}))
01053                 $r=  bcmul(${$price},${$quant});
01054             else{
01055                 $r=  bcmul(${$price},${$quant});
01056                 $r=bcadd($r,${$id});
01057                         }
01058                         $r=round($r,2);
01059                         return $r;
01060             break;
01061 
01062         case 'TOTAL_VEN_HTVA':
01063             extract($p_array);
01064                         bcscale(4);
01065             $sum=0.0;
01066             for ($i=0;$i<$nb_item;$i++)
01067             {
01068                 $sell='e_march'.$i.'_price';
01069                 $qt='e_quant'.$i;
01070 
01071                 if ( ! isset (${$sell}) ) break;
01072 
01073                 if ( strlen(trim(${$sell})) == 0 ||
01074                         strlen(trim(${$qt})) == 0 ||
01075                         ${$qt}==0 || ${$sell}==0)
01076                     continue;
01077                 $tmp1=bcmul(${$sell},${$qt});
01078                 $sum=bcadd($sum,$tmp1);
01079 
01080 
01081             }
01082             $r=round($sum,2);
01083             break;
01084         case 'TOTAL_VEN_TVAC':
01085             extract($p_array);
01086             $sum=0.0;
01087                         bcscale(4);
01088             for ($i=0;$i<$nb_item;$i++)
01089             {
01090                 $tva='e_march'.$i.'_tva_amount';
01091                 $tva_amount=0;
01092                 /* if we do not use vat this var. is not set */
01093                 if ( isset(${$tva}) )
01094                 {
01095                     $tva_amount=${$tva};
01096                 }
01097                 $sell=${'e_march'.$i.'_price'};
01098                 $qt=${'e_quant'.$i};
01099                                 $tot=bcmul($sell,$qt);
01100                                 $tot=bcadd($tot,$tva_amount);
01101                                 $sum=bcadd($sum,$tot);
01102             }
01103             $r=round($sum,2);
01104 
01105             break;
01106         case 'TOTAL_TVA':
01107             extract($p_array);
01108             $sum=0.0;
01109             for ($i=0;$i<$nb_item;$i++)
01110             {
01111                 $tva='e_march'.$i.'_tva_amount';
01112                 if (! isset(${$tva})) $tva_amount=0.0;
01113                 else $tva_amount=$
01114                                      {
01115                                          $tva
01116                                      };
01117                 $sum+=$tva_amount;
01118                 $sum=round($sum,2);
01119             }
01120             $r=$sum;
01121 
01122             break;
01123         case 'BON_COMMANDE':
01124             if ( isset($p_array['bon_comm']))
01125                 return $p_array['bon_comm'];
01126             else
01127                 return "";
01128             break;
01129         case 'PJ':
01130             if ( isset($p_array['e_pj']))
01131                 return $p_array['e_pj'];
01132             else
01133                 return "";
01134 
01135         case 'OTHER_INFO':
01136             if ( isset($p_array['other_info']))
01137                 return $p_array['other_info'];
01138             else
01139                 return "";
01140             break;
01141         case 'COMMENT':
01142             if ( isset($p_array['e_comm']))
01143                 return $p_array['e_comm'];
01144             break;
01145         case 'ACOMPTE':
01146             if ( isset($p_array['acompte']))
01147                 return $p_array['acompte'];
01148                         return "0";
01149             break;
01150         case 'STOCK_NAME':
01151                 if ( ! isset ($p_array['repo'])) return "";
01152                 $ret=$this->db->get_value('select r_name from public.stock_repository where r_id=$1',array($p_array['repo']));
01153                 return $ret;
01154         case 'STOCK_ADRESS':
01155                 if ( ! isset ($p_array['repo'])) return "";
01156                 $ret=$this->db->get_value('select r_adress from public.stock_repository where r_id=$1',array($p_array['repo']));
01157                 return $ret;
01158         case 'STOCK_COUNTRY':
01159                 if ( ! isset ($p_array['repo'])) return "";
01160                 $ret=$this->db->get_value('select r_country from public.stock_repository where r_id=$1',array($p_array['repo']));
01161                 return $ret;
01162         case 'STOCK_CITY':
01163                 if ( ! isset ($p_array['repo'])) return "";
01164                 $ret=$this->db->get_value('select r_city from public.stock_repository where r_id=$1',array($p_array['repo']));
01165                 return $ret;
01166         case 'STOCK_PHONE':
01167                 if ( ! isset ($p_array['repo'])) return "";
01168                 $ret=$this->db->get_value('select r_phone from public.stock_repository where r_id=$1',array($p_array['repo']));
01169                 return $ret;
01170         case 'TITLE':
01171             $title=HtmlInput::default_value_request("ag_title", "");
01172             return $title;
01173 
01174                 }
01175         /*
01176          * retrieve the value of ATTR for e_march
01177          */
01178         if (preg_match('/^ATTR/', $p_tag) == 1)
01179         {
01180             // Retrieve f_id
01181             if ( isset ($p_array['e_march'.$this->counter]))
01182             {
01183                 $id = $p_array['e_march' . $this->counter];
01184                 $r=$this->replace_special_tag($id,$p_tag);
01185             }
01186         }
01187         /*
01188          * retrieve the value of ATTR for e_march
01189          */
01190         if (preg_match('/^BENEFATTR/', $p_tag) == 1)
01191         {
01192             $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
01193             // Retrieve f_id
01194              $r=$this->replace_special_tag($qcode,$p_tag);
01195         }
01196         if (preg_match('/^CUSTATTR/', $p_tag) == 1)
01197         {
01198             if ( isset($p_array['qcode_dest']) || isset($p_array['e_client']) )
01199             {
01200                 $qcode=(isset($p_array['qcode_dest']))?$p_array['qcode_dest']:$p_array['e_client'];
01201                 $r=$this->replace_special_tag($qcode,$p_tag);
01202             }
01203         }
01204         return $r;
01205     }
01206     /*!\brief remove a row from the table document, the lob object is not deleted
01207      *        because can be linked elsewhere
01208      */
01209     function remove()
01210     {
01211       $d_lob=$this->db->get_value('select d_lob from document where d_id=$1',
01212                                   array($this->d_id));
01213         $sql='delete from document where d_id='.$this->d_id;
01214         $this->db->exec_sql($sql);
01215         if ( $d_lob != 0 )
01216             $this->db->lo_unlink($d_lob);
01217     }
01218     /*!\brief Move a document from the table document into the concerned row
01219      *        the document is not copied : it is only a link
01220      *
01221      * \param $p_internal internal code
01222      *
01223      */
01224     function MoveDocumentPj($p_internal)
01225     {
01226         $sql="update jrn set jr_pj=$1,jr_pj_name=$2,jr_pj_type=$3 where jr_internal=$4";
01227 
01228         $this->db->exec_sql($sql,array($this->d_lob,$this->d_filename,$this->d_mimetype,$p_internal));
01229         // clean the table document
01230         $sql='delete from document where d_id='.$this->d_id;
01231         $this->db->exec_sql($sql);
01232 
01233 
01234     }
01235     /**
01236      *Replace a special tag *TAGxxxx with the value from fiche_detail, the xxxx
01237      * is the ad_value
01238      * @param $p_qcode qcode of the card
01239      * @param $p_tag tag to parse
01240      * @return  the ad_value contained in fiche_detail or for the type "select" the
01241      *          label
01242      */
01243     function replace_special_tag($p_qcode, $p_tag)
01244     {
01245         // check if the march exists
01246         if ($p_qcode == "")
01247             return "";
01248 
01249         $f = new Fiche($this->db);
01250         $found = $f->get_by_qcode($p_qcode, false);
01251         // if not found exit
01252         if ($found == 1)
01253             return "";
01254 
01255         // get the ad_id
01256         $attr=preg_replace("/^.*ATTR/","",$p_tag);
01257 
01258         if (isNumber($attr) == 0) return "";
01259         $ad_type=$this->db->get_value("select ad_type from attr_def where ad_id=$1",array($attr));
01260 
01261         // get ad_value
01262         $ad_value=$this->db->get_value("select ad_value from fiche_detail where f_id=$1 and ad_id=$2",array($f->id,$attr));
01263 
01264         // if ad_id is type select execute select and get value
01265         if ( $ad_type=="select")
01266         {
01267             $sql=$this->db->get_value("select ad_extra from attr_def where ad_id=$1",array($attr));
01268             $array= $this->db->make_array($sql);
01269             for ($a=0;$a<count ($array);$a++)
01270             {
01271                 if ($array[$a]['value']==$ad_value)
01272                     return $array[$a]['label'];
01273             }
01274 
01275         }
01276         // if ad_id is not type select get value
01277         return $ad_value;
01278     }
01279     function update_description ($p_desc)
01280     {
01281         $this->db->exec_sql('update document set d_description = $1 where d_id=$2',
01282                 array($p_desc,$this->d_id));
01283     }
01284 
01285 }
 All Data Structures Namespaces Files Functions Variables Enumerations