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