Main Page | Namespace List | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

class_action.php

Go to the documentation of this file.
00001 <?
00002 /*
00003  *   This file is part of PhpCompta.
00004  *
00005  *   PhpCompta 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  *   PhpCompta 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 PhpCompta; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 /* $Revision: 1.13 $ */
00020 // Copyright Author Dany De Bontridder ddebontridder@yahoo.f
00021 
00022 require_once("class_fiche.php");
00023 require_once("class_document.php");
00024 require_once("class_document_type.php");
00025 require_once("user_common.php");
00046 class action 
00047 {
00063   var $db;
00064   var $ag_comment;
00065   var $ag_timestamp;
00066   var $dt_id;
00067   var $d_state;
00068   var $d_number;
00069   var $d_filename;
00070   var $d_mimetype;
00071   var $ag_title;
00072   var $f_id;
00073   var $ag_ref_ag_id;
00078   function action ($p_cn)
00079     {
00080       $this->db=$p_cn;
00081       $this->f_id=0;
00082 
00083     }
00084   //----------------------------------------------------------------------
00101   function Display($p_view,$p_gen) 
00102     {
00103       echo_debug('class_action',__LINE__,'Display()  :'.var_export($_POST,true));
00104       echo_debug('class_action',__LINE__,'Display $this  :'.var_export($this,true));
00105 
00106 
00107       if ( $p_view=='UPD')
00108         {
00109           $upd=true;    
00110           $readonly=false;
00111         }
00112       elseif ($p_view=="NEW")
00113         {
00114           $upd=false;
00115           $readonly=false;
00116         }
00117       elseif ($p_view=='READ')
00118         {
00119           $upd=true;
00120           $readonly=true;
00121         }
00122       else
00123         {
00124           exit('class_action'.__LINE__.'Action::Display error unknown parameter'.$p_view);
00125 
00126         }
00127       // Compute the widget
00128       // Date 
00129       $date=new widget("text");
00130       $date->readonly=$readonly;
00131       $date->name="ag_timestamp";
00132       $date->value=$this->ag_timestamp;
00133       
00134       
00135       // for insert mode only
00136       if ( $upd == false )
00137         {
00138           // Doc Type
00139           $doc_type=new widget("select");
00140           $doc_type->name="dt_id";
00141           $doc_type->value=make_array($this->db,"select dt_id,dt_value from document_type where dt_id in (".ACTION.")");
00142           $doc_type->selected=$this->dt_id;
00143           $doc_type->readonly=false;
00144           $str_doc_type=$doc_type->IOValue();
00145           echo_debug('class_action',__LINE__,var_export($doc_type,true));
00146         }
00147       else {
00148         // Doc Type
00149         $doc_type=new widget("hidden");
00150         $doc_type->name="dt_id";
00151         $doc_type->value=$this->dt_id;
00152         $str_doc_type=$doc_type->IOValue()." ".getDbValue($this->db,"select dt_value from document_type where dt_id=".$this->dt_id);
00153       }
00154 
00155       // Description
00156       $desc=new widget('RICHTEXT');
00157       $desc->width=500;
00158       $desc->heigh=250;
00159       $desc->name="ag_comment";
00160       $desc->readonly=$readonly;
00161       $desc->value=FormatString(urldecode($this->ag_comment));
00162 
00163       // state
00164       // Retrieve the value
00165       if ( $p_view != 'READ' )
00166         {
00167           $a=make_array($this->db,"select s_id,s_value from document_state ");
00168           $state=new widget("select");
00169           $state->readonly=$readonly;
00170           $state->name="d_state";
00171           $state->value=$a;
00172           $state->selected=$this->d_state;
00173           $str_state=$state->IOValue();
00174         } else {
00175           $str_state=getDbValue($this->db,"select s_value from document_state where s_id=".$this->d_state);
00176           $g=new widget("hidden");
00177           $str_state.=$g->IOValue('d_state',$this->d_state);
00178         }
00179       // Retrieve the value if there is an attached doc
00180       $doc_ref="";
00181       // Document id
00182 
00183       $h2=new widget("hidden");
00184       $h2->name="d_id";
00185       $h2->value=$this->d_id;
00186       
00187       if ( $this->d_id != 0 && $this->d_id != "" )
00188         {
00189           $h2->readonly=($p_view=='NEW')?false:true;
00190           $doc=new Document($this->db,$this->d_id);
00191           $d_id=new widget("hidden");
00192           $doc_ref="<p> Document ".$doc->a_ref().'</p>';
00193           $doc_ref.=$h2->IOValue().$d_id->IOValue('d_id',$this->d_id);
00194           
00195         }
00196 
00197 
00198       // title
00199       $title=new widget("text");
00200       $title->readonly=$readonly;
00201       $title->name="ag_title";
00202       $title->value=FormatString($this->ag_title);
00203       $title->size=80;
00204 
00205       // ag_ref
00206       // Always false for update
00207       $ag_ref=new widget("text");
00208       $ag_ref->readonly=$upd;
00209       $ag_ref->name="ag_ref";
00210       $ag_ref->value=FormatString($this->ag_ref);
00211       $client_label=new widget("span");
00212 
00213       // f_id_dest destination
00214       if ( $this->qcode_dest != '- ERROR -' && strlen(trim($this->qcode_dest)) != 0)
00215         {
00216           $tiers=new fiche($this->db);
00217           $tiers->GetByQCode($this->qcode_dest);
00218           $qcode_dest_label=$tiers->strAttribut(1);
00219         } else {
00220           //      echo "f_id $this->f_id";
00221           $qcode_dest_label=($this->f_id_dest==0 || trim($this->qcode_dest)=="")?'Interne ':'Error';
00222         }
00223 
00224       // f_id_exp sender
00225       if ( $this->qcode_exp != '- ERROR -' && strlen(trim($this->qcode_exp)) != 0)
00226         {
00227           $tiers=new fiche($this->db);
00228           $tiers->GetByQCode($this->qcode_exp);
00229           $qcode_exp_label=$tiers->strAttribut(1);
00230         } else {
00231           $qcode_exp_label=($this->f_id_exp==0 || trim($this->qcode_exp)=="")?'Interne ':'Error';
00232         }
00233 
00234       $h_ag_id=new widget("hidden");
00235       // if concerns another action : show the link otherwise nothing
00236       $lag_ref_ag_id=" X / XX ";
00237       
00238       if ( $this->ag_ref_ag_id != 0 )
00239         {
00240     //      $this->GetAgRef("ag_ref_ag_id")."</A>";
00241 
00242           $lag_ref_ag_id='<a class="mtitle" href="commercial.php?p_action=suivi_courrier&sa=detail&ag_id='.
00243             $this->ag_ref_ag_id.'">'.
00244             getDbValue($this->db,"select ag_ref from action_gestion where ag_id=".$this->ag_ref_ag_id).
00245             "</A>";
00246         } 
00247       // sender
00248       $w=new widget('js_search_only');
00249       $w->readonly=$readonly;
00250       $w->name='qcode_exp';
00251       $w->value=($this->f_id_exp != 0)?$this->qcode_exp:"";
00252       $w->label="";
00253       $w->extra='4,8,9,14,16';
00254       $sp= new widget("span");
00255       $h_agrefid=new widget('hidden');
00256       // destination
00257       $wdest=new widget('js_search_only');
00258       $wdest->readonly=$readonly;
00259       $wdest->name='qcode_dest';
00260       $wdest->value=($this->f_id_dest != 0)?$this->qcode_dest:"";
00261       $wdest->label="";
00262       $wdest->extra='4,8,9,14,16';
00263       $spdest= new widget("span");
00264       $h_agrefid=new widget('hidden');
00265       $str_ag_ref="<b>".(($this->ag_ref != "")?$this->ag_ref:" Nouveau ")."</b>";
00266       // Preparing the return string
00267       $r="";
00268       $r.=JS_SEARCH_CARD;
00269       $r.= '<p>Date :'.$date->IOValue()." Reference  ".$str_ag_ref; 
00270       $r.="&nbsp;         Concerne :".$lag_ref_ag_id.
00271       '   Type d\' action';
00272       echo_debug('class_action',__LINE__,"str_doc_type $str_doc_type");
00273       $r.= $str_doc_type;
00274 
00275       // state
00276       $r.="     Etat :".$str_state."</p>";
00277 
00278 
00279       $r.= "<p> ";
00280       $r.="Exp&eacute;diteur : ".$w->IOValue();
00281       $r.=$sp->IOValue('qcode_exp_label',$qcode_exp_label)."</TD></TR>";
00282  
00283       $r.="Destinataire :".$wdest->IOValue();
00284       $r.=$spdest->IOValue('qcode_dest_label',$qcode_dest_label)."</TD></TR>";
00285 
00286       //      $r.=' Ref :'.$ag_ref->IOValue();
00287       $r.="</p>";
00288       echo_debug('class_action',__LINE__,' ag_id is '.$this->ag_id);
00289 
00290       $r.= "<p> Titre : ".$title->IOValue();
00291       $r.= $doc_ref;
00292       $r.= "<p>".$desc->IOValue()."</p>";
00293 
00294       //hidden
00295       $r.="<p>";
00296       $r.=$h2->IOValue();
00297       $r.=$h_agrefid->IOValue("ag_ref_ag_id",$this->ag_ref_ag_id); 
00298       $r.=$h_ag_id->IOValue('ag_id',$this->ag_id);
00299       $hidden=new widget('hidden');
00300       $r.=$hidden->IOValue('f_id_dest',$this->f_id_dest);
00301       $hidden2=new widget('hidden');
00302       $r.=$hidden2->IOValue('f_id_exp',$this->f_id_exp);
00303       $r.="</p>";
00304 
00305       // show the list of the concern operation
00306       if ( CountSql($this->db,'select * from action_gestion where ag_ref_ag_id!=0 and ag_ref_ag_id='.$this->ag_id.
00307                     " limit 2") > 0 )
00308         $r.=$this->myList(ACTION," and ag_ref_ag_id=".$this->ag_id);
00309       return $r;
00310  
00311     }
00312   //----------------------------------------------------------------------
00315   function get()
00316     {
00317       echo_debug('class_action',__LINE__,'Action::Get() ');
00318       $sql="select ag_id, ag_comment,to_char (ag_timestamp,'DD-MM-YYYY') as ag_timestamp,".
00319         " f_id_dest,f_id_exp,ag_title,ag_comment,ag_ref,d_id,ag_type,d_state,  ".
00320         " ag_ref_ag_id ".
00321         " from action_gestion left join document using (ag_id) where ag_id=".$this->ag_id;
00322       $r=ExecSql($this->db,$sql);
00323       $row=pg_fetch_all($r);
00324       if ( $row==false) return;
00325       $this->ag_comment=$row[0]['ag_comment'];
00326       $this->ag_timestamp=$row[0]['ag_timestamp'];
00327       $this->f_id_dest=$row[0]['f_id_dest'];
00328       $this->f_id_exp=$row[0]['f_id_exp'];
00329       $this->ag_title=$row[0]['ag_title'];
00330       $this->ag_type=$row[0]['ag_type'];
00331       $this->ag_ref=$row[0]['ag_ref'];
00332       $this->ag_ref_ag_id=$row[0]['ag_ref_ag_id'];
00333       $this->d_id=$row[0]['d_id'];
00334       //
00335       echo_debug('class_action',__LINE__,' Document id = '.$this->d_id);
00336       // if there is no document set 0 to d_id
00337       if ( $this->d_id == "" ) 
00338         $this->d_id=0;
00339       // if there is a document fill the object
00340       if ($this->d_id != 0 )
00341         {
00342           $this->state=$row['0']['d_state'];
00343           $this->d_state=$row[0]['d_state'];
00344         }
00345       echo_debug('class_action',__LINE__,' After test Document id = '.$this->d_id);
00346       $this->dt_id=$this->ag_type;
00347       $adest=new fiche($this->db,$this->f_id_dest);
00348       $this->qcode_dest=$adest->strAttribut(ATTR_DEF_QUICKCODE);
00349       $aexp=new fiche($this->db,$this->f_id_exp);
00350       $this->qcode_exp=$aexp->strAttribut(ATTR_DEF_QUICKCODE);
00351 
00352       echo_debug('class_action',__LINE__,'Detail end ()  :'.var_export($_POST,true));
00353       echo_debug('class_action',__LINE__,'Detail $this  :'.var_export($this,true));
00354 
00355     }
00364   function Confirm()
00365     {
00366       echo_debug('class_action',__LINE__,'confirm()  :'.var_export($_POST,true));
00367       echo_debug('class_action',__LINE__,'confirm $this  :'.var_export($this,true));
00369       if ( isDate($this->ag_timestamp) == null )
00370         {
00371           // if the date is invalid, default date is today
00372           $this->ag_timestamp=date("d.m.Y");
00373         }
00374       // Compute the widget
00375       // Date 
00376       $date=new widget("text");
00377       $date->readonly=true;
00378       $date->name="ag_timestamp";
00379       $date->value=$this->ag_timestamp;
00380       // Doc Type
00381       $doc_type=new widget("hidden");
00382       $doc_type->name="dt_id";
00383       $doc_type->value=$this->dt_id;
00384       $a=ExecSql($this->db,"select dt_value from document_type where dt_id=".$this->dt_id);
00385       $v=pg_fetch_array($a,0);
00386       $str_type=$v[0];
00387       if ( isset ($_REQUEST['url'])) 
00388         {
00389           $retour=sprintf('<A HREF="%s"><input type="button" value="Retour"></A>',urldecode($_REQUEST['url']));
00390           $h_url=sprintf('<input type="hidden" name="url" value="%s">',urldecode($_REQUEST['url']));
00391         }
00392       else 
00393         { 
00394           $retour="";
00395           $h_url="";
00396         }
00397 
00398       // state
00399       $a=ExecSql($this->db,"select s_value from document_state where s_id=".$this->d_state);
00400       $v=pg_fetch_array($a,0);
00401       $str_state=$v[0];
00402       $state=new widget("hidden");
00403       $state->name="d_state";
00404       $state->value=$this->d_state;
00405         
00406       // title
00407       $title=new widget("text");
00408       $title->readonly=true;
00409       $title->name="ag_title";
00410       $title->value=FormatString($this->ag_title);
00411 
00412       // Description
00413       $desc=new widget('textarea');
00414       $desc->name="ag_comment";
00415       $desc->readonly=" disabled ";
00416       $desc->value=$this->ag_comment;
00417       // Propose to generate a document
00418       $gen=new widget ("checkbox");
00419       $gen->name="p_gen";
00420       $doc_gen=new widget("select");
00421       $doc_gen->name="gen_doc";
00422       $doc_gen->value=make_array($this->db,
00423                                  "select md_id,md_name from document_modele where md_type=".$this->dt_id);
00424 
00425       $h_agrefid=new widget('hidden');
00426 
00427        // f_id
00428        if ( trim($this->qcode_dest) =="")
00429          {
00430            // internal document
00431            $this->f_id_dest=0; // internal document
00432            $namedest="interne";
00433          }
00434        else // ( trim($this->qcode_dest) !=""  )
00435          {
00436            $tiers=new fiche($this->db);
00437            $tiers->GetByQCode($this->qcode_dest);
00438            $this->f_id_dest=$tiers->id;
00439            $namedest=$tiers->strAttribut(1);
00440                 if ( $namedest == '- ERROR  -') $this->f_id_dest=-1;    
00441          }
00442  
00443        // f_id
00444        if ( trim($this->qcode_exp) =="")
00445          {
00446            // internal document
00447            $this->f_id_exp=0; // internal document
00448            $nameexp="interne";
00449          }
00450        else // ( trim($this->qcode_exp) !=""  )
00451          {
00452            $tiers=new fiche($this->db);
00453            $tiers->GetByQCode($this->qcode_exp);
00454            $this->f_id_exp=$tiers->id;
00455            $nameexp=$tiers->strAttribut(1);
00456                 if ( $nameexp == '- ERROR  -') $this->f_id_exp=-1;      
00457          }
00458  
00459 
00460 
00461       // Preparing the return string
00462       $r=$retour."<form method=\"post\">";
00463       $r.="<p>Date : ".$date->IOValue()."</p>";
00464       $r.="<p>Etat $str_state".$state->IOValue()."</p>";
00465       $r.="<p>Type du document $str_type".$doc_type->IOValue()."</p>";
00466       $r.="<p> Expediteur : ".$this->qcode_exp." ".$nameexp.'</p>';
00467       $r.="<p> Destinataire : ".$this->qcode_dest." ".$namedest.'</p>';
00468       $r.="<p> Titre : ".$title->IOValue();
00469       $r.="<p>Description :".$desc->IOValue()."</p>";
00470 
00471       // if no document exist for this type then do not display the question
00472       if ( sizeof($doc_gen->value) != 0) 
00473         $r.="<p> G&eacute;n&eacute;rer un document ".$gen->IOValue()." ".$doc_gen->IOValue()."</p>";
00474         
00475 
00476       // Add the hidden tag
00477       $r.='<input type="hidden" name="sa" value="save_action_st2">';
00478       $r.='<input type="hidden" name="p_action" value="suivi_courrier">';
00479       $r.='<input type="hidden" name="f_id_dest" value="'.$this->f_id_dest.'">';
00480       $r.='<input type="hidden" name="f_id_exp" value="'.$this->f_id_exp.'">';
00481       $r.='<input type="hidden" name="qcode_dest" value="'.$this->qcode_dest.'">';
00482       $r.='<input type="hidden" name="qcode_exp" value="'.$this->qcode_exp.'">';
00483 
00484 
00485       $r.=      $h_agrefid->IOValue("ag_ref_ag_id",$this->ag_ref_ag_id);
00486         
00487       // retrieve customer
00488 
00489 
00490       if ( $this->f_id_dest != -1 && $this->f_id_exp !=-1 )
00491         $r.=$desc->Submit("Save","Sauve");
00492       $r.=$desc->Submit("corr","Corrige");
00493 
00494       $r.=$h_url."</form>";
00495       return $r;
00496     }
00504   function SaveStage2() 
00505     {
00506       echo_debug('class_action',__LINE__,'saveStage2()  :'.var_export($_POST,true));
00507       echo_debug('class_action',__LINE__,' saveStage2()  $this  :'.var_export($this,true));
00508 
00509       // Get The sequence id, 
00510       $seq_name="seq_doc_type_".$this->dt_id;
00511       $str_file="";
00512       $add_file='';
00513       // f_id dest
00514       $tiers=new fiche($this->db);
00515       $tiers->GetByQCode($this->qcode_dest);
00516 
00517       // f_id exp
00518       $exp=new fiche($this->db);
00519       $exp->GetByQCode($this->qcode_exp);
00520 
00521       if ( trim($this->ag_title) == "") 
00522         {
00523           $doc_mod=new document_type($this->db);
00524           $doc_mod->dt_id=$this->dt_id;
00525           $doc_mod->get();
00526           $this->ag_title=$doc_mod->dt_value;
00527         }
00528       echo_debug('class_action',__LINE__," tiers->id  ".$tiers->id);
00529       $this->ag_id=NextSequence($this->db,'action_gestion_ag_id_seq');
00530       // Create the reference 
00531       $ref=$this->dt_id.'/'.$this->ag_id;
00532       $this->ag_ref=$ref;
00535       //we remove newline 
00536       $this->ag_comment=str_replace("%OD","",$this->ag_comment);
00537       $this->ag_comment=str_replace("%OA","",$this->ag_comment);
00538       // save into the database
00539       $sql=sprintf("insert into action_gestion".
00540                    "(ag_id,ag_timestamp,ag_type,ag_title,f_id_dest,f_id_exp,ag_comment,ag_ref,ag_ref_ag_id) ".
00541                    " values (%d,to_date('%s','DD-MM-YYYY'),'%d','%s',%d,%d,'%s','%s',%d)",
00542                    $this->ag_id,
00543                    $this->ag_timestamp,
00544                    $this->dt_id,
00545                    FormatString($this->ag_title),
00546                    $tiers->id,
00547                    $exp->id,
00548                    $this->ag_comment,
00549                    $ref,
00550                    $this->ag_ref_ag_id
00551                    );
00552       ExecSql($this->db,$sql);
00553 
00554 
00555 
00556       // the lob filename and the mimetype needed if we want to generate a doc.
00557       if ( $this->gen == 'on' ) 
00558         {
00559           $doc=new Document($this->db);
00560           $doc->f_id=$tiers->id;
00561           $doc->md_id=$this->md_id;
00562           $doc->ag_id=$this->ag_id;
00563           $doc->d_state=$this->d_state;
00564           $str_file=$doc->Generate();
00565           $d='<input type="hidden" name="d_id" value="'.$doc->d_id.'">';
00566         }
00567       $r="";
00568       // readonly and upload of a file
00569       $r.="<hr>";
00570       $r.='<form enctype="multipart/form-data" method="post">';
00571       echo_debug("class_action",__LINE__,"call display");
00572       $r.=$this->Display('READ',false);
00573       // Add the hidden tag
00574       $r.='<input type="hidden" name="sa" value="save_action_st3">';
00575       $r.='<input type="hidden" name="p_action" value="suivi_courrier">';
00576       // add the d_id
00577       $r.='<input type="hidden" name="d_id" value="'.$this->d_id.'">'; 
00578       // ag_comment must be saved in urlcode
00579       $r.='<input type="hidden" name="ag_comment" value="'.urlencode($this->ag_comment).'">';
00580       // Value for the generated document
00581       if ( $this->gen == 'on' ) 
00582         {
00583           $r.='<input type="hidden" name="d_id" value="'.$doc->d_id.'">';
00584           $r.="Sauver le document généré :";
00585           $r.=$str_file;
00586           $checkbox=new widget("checkbox");
00587           $checkbox->name="save_generate";
00588           $r.=$checkbox->IOValue();
00589           $r.="<hr>";
00590         }
00591       $upload=new widget("file");
00592       $upload->name="file_upload";
00593       $upload->value="";
00594       $r.="Enregistrer le fichier ".$upload->IOValue();
00595       $r.=$upload->Submit("save","Sauve le fichier");
00596       $r.="</form>";
00597       return $r;
00598     }
00604   function SaveStage3($d_id) 
00605     {
00606       echo_debug('class_action',__LINE__,'SaveStage3()  :'.var_export($_POST,true));
00607       echo_debug('class_action',__LINE__,'SaveStage3  :'.var_export($this,true));
00608 
00609       // if we save the generated doc
00610       if ( isset($_POST['save_generate']))
00611         {
00612           return;
00613         }
00614 
00615       // Upload a new document
00616       $doc=new Document($this->db);
00617       $doc->ag_id=$this->ag_id;
00618       // if there is a document and it is not an update
00619       if ( sizeof($_FILES) !=0 && $d_id==0) 
00620         {
00621           $doc->md_type=$this->dt_id;
00622           $doc->blank();
00623         }
00624       else 
00625         $doc->d_id=$d_id;
00626 
00627       $doc->Upload($this->ag_id);
00628     }
00629 
00638   function myList($p_filter="",$p_search="")
00639     {
00640       // for the sort
00641       $sort="";
00642       if ( isset($_GET['s'])){
00643         {
00644           switch ($_GET['s']) {
00645           case "date":
00646             $sort=" ag_timestamp";
00647             break;
00648           case "exp":
00649             $sort=" f_id_exp";
00650             break;
00651           case "dest":
00652             $sort=" f_id_dest";
00653             break;
00654           case "ti":
00655             $sort=" ag_title";
00656             break;
00657           case "type":
00658             $sort=" ag_type";
00659             break;
00660           case "ref":
00661             $sort=" ag_ref";
00662             break;
00663           case "conc":
00664             $sort=" ag_ref_ag_id";
00665             break;
00666           }
00667           $sort=" order by ".$sort." desc ";
00668         }
00669       }
00670       $sql="
00671    select ag_id,to_char(ag_timestamp,'DD-MM-YYYY') as my_date,ag_ref_ag_id,f_id_dest,f_id_exp".
00672         ",ag_title,d_id,md_type,dt_value,ag_ref 
00673    from action_gestion 
00674       left outer join document using (ag_id)
00675       left outer join document_modele on (ag_type=md_type) 
00676       join document_type on (ag_type=dt_id)
00677    where dt_id in ($p_filter) $p_search $sort";
00678       $max_line=CountSql($this->db,$sql);
00679       $step=$_SESSION['g_pagesize'];
00680       $page=(isset($_GET['offset']))?$_GET['page']:1;
00681       $offset=(isset($_GET['offset']))?$_GET['offset']:0;
00682       $limit=" LIMIT $step OFFSET $offset ";  
00683       $bar=jrn_navigation_bar($offset,$max_line,$step,$page);
00684 
00685       $Res=ExecSql($this->db,$sql.$limit);
00686       $a_row=pg_fetch_all($Res);
00687       //      $r='<div class="u_redcontent">';
00688       $query="";
00689       if ( isset ($_GET['query'])) 
00690         $query.="query=".$_GET['query'];
00691       else 
00692         $query="1";
00693 
00694       if ( isset ($_GET['qcode_query'])) $query.='&qcode_query='.$_GET['qcode_query'];
00695       echo_debug('class_action',__LINE__,"jrn bar = $bar");
00696       echo_debug('class_action',__LINE__,'$_SESSION='.var_export($_SESSION,true));
00697       $r="";
00698       $r.=$bar;
00699       $r.='<table class="document">';
00700       $r.="<tr>";
00713       $r.='<th> Date</th>';
00714       $r.='<th>Destinataire</th>';
00715       $r.='<th>Expéditeur</th>';
00716       $r.='<th>Titre</th>';
00717       $r.='<th>type</th>';
00718       $r.='<th>Référence</th>';
00719       $r.='<th>concerne</th>';
00720       $r.='<th>Document</th>';
00721       $r.="</tr>";
00722 
00723       // if there are no records return a message
00724       if ( sizeof ($a_row) == 0 or $a_row == false ) 
00725         {
00726           $r='<div class="u_redcontent">';
00727           $r.='<hr>Aucun enregistrement trouvé';
00728           $r.="</div>";
00729           return $r;
00730 
00731         }
00732       $r.=JS_SEARCH_CARD;
00733       foreach ($a_row as $row )
00734         {
00735 
00736           $r.="<tr>";
00737           $r.="<td>".$row['my_date']."</td>";
00738           // Destinataire
00739           $fdest=new fiche($this->db);
00740           $fdest->id=$row['f_id_dest'];
00741           $qcode_dest=$fdest->strAttribut(ATTR_DEF_QUICKCODE);
00742 
00743           $qdest=($qcode_dest=="- ERROR -")?"Interne":$qcode_dest;
00744           $jsdest=sprintf("javascript:showfiche('%s','%s')",
00745                       $_REQUEST['PHPSESSID'],$qdest);
00746           if ( $qdest != 'Interne' )
00747             {
00748               $r.="<td>".'<A HREF="'.$jsdest.'">'.$qdest." : ".$fdest->getName().'</A></td>';
00749             }
00750           else
00751             $r.="<td>Interne </td>";
00752 
00753           // Expediteur
00754           $fexp=new fiche($this->db);
00755           $fexp->id=$row['f_id_exp'];
00756           $qcode_exp=$fexp->strAttribut(ATTR_DEF_QUICKCODE);
00757 
00758           $qexp=($qcode_exp=="- ERROR -")?"Interne":$qcode_exp;
00759           $jsexp=sprintf("javascript:showfiche('%s','%s')",
00760                       $_REQUEST['PHPSESSID'],$qexp);
00761           if ( $qexp != 'Interne' )
00762             {
00763               $r.="<td>".'<A HREF="'.$jsexp.'">'.$qexp." : ".$fexp->getName().'</A></td>';
00764             }
00765           else
00766             $r.="<td>Interne </td>";
00767 
00768           $ref="";
00769 
00770           // show reference
00771           if ( $row['ag_ref_ag_id'] != 0 ) 
00772             {
00773               $retSqlStmt=ExecSql($this->db,
00774                                   "select ag_ref from action_gestion where ag_id=".$row['ag_ref_ag_id']);
00775               $retSql=pg_fetch_all($retSqlStmt);
00776               if ( $retSql != null )
00777                 {
00778                   foreach ($retSql as $line) 
00779                     {
00780                       $ref.='<A  href="commercial.php?p_action=suivi_courrier&query='.$line['ag_ref'].'">'.
00781                         $line['ag_ref']."<A>";
00782                     }
00783                 }
00784             }
00785 
00786           $r.='<td><A HREF="commercial.php?p_action=suivi_courrier&sa=detail&ag_id='.$row['ag_id'].'">'.
00787             $row['ag_title']."</A></td>";
00788           $r.="<td>".$row['dt_value']."</td>";
00789           $r.="<td>".$row['ag_ref']."</td>";
00790           $r.="<td>".$ref."</td>";
00791           $doc=new Document($this->db,$row['d_id']);
00792           $r.="<td>".$doc->a_ref()."</td>";
00793           $r.="</tr>";
00794 
00795         }
00796       $r.="</table>";
00797 
00798       $r.=$bar;
00799       //$r.="</div>";
00800       return $r;
00801     }
00802   //----------------------------------------------------------------------
00807   function Update()
00808     {
00809       echo_debug('class_action',__LINE__,'Update() $_POST()  :'.var_export($_POST,true));
00810       echo_debug('class_action',__LINE__,'Update()  $this  :'.var_export($this,true));
00811 
00812       // if ag_id == 0 nothing to do
00813       if ( $this->ag_id == 0 ) return ;
00814 
00815 
00816       // retrieve customer
00817       // f_id
00818      
00819       if ( trim($this->qcode_exp) =="" )
00820         {
00821           // internal document
00822           $this->f_id_exp=0; // internal document
00823         }
00824       else
00825         {
00826           $tiers=new fiche($this->db);
00827           if ( $tiers->GetByQCode($this->qcode_exp) == -1 ) // Error we cannot retrieve this qcode
00828             return false; 
00829           else
00830             $this->f_id_exp=$tiers->id;
00831 
00832         }
00833       if ( trim($this->qcode_dest) =="" )
00834         {
00835           // internal document
00836           $this->f_id_dest=0; // internal document
00837         }
00838       else
00839         {
00840           $tiers=new fiche($this->db);
00841           if ( $tiers->GetByQCode($this->qcode_dest) == -1 ) // Error we cannot retrieve this qcode
00842             return false; 
00843           else
00844             $this->f_id_dest=$tiers->id;
00845 
00846         }
00847 
00848 
00849       //remove newline from ag_comment
00850       $this->ag_comment=str_replace("\n","",$this->ag_comment);
00851       $this->ag_comment=str_replace("\r","",$this->ag_comment);
00852 
00853       // url encoded
00854       $this->ag_comment=urlencode($this->ag_comment);
00855 
00856       // bug PHP : sometimes the newline remains
00857       $this->ag_comment=str_replace("%A0","",$this->ag_comment);
00858       $this->ag_comment=str_replace("%0D","",$this->ag_comment);
00859       $this->ag_comment=str_replace("+%A0+","",$this->ag_comment);
00860       $this->ag_comment=str_replace("+%0D+","",$this->ag_comment);
00861 
00862 
00863       $sql=sprintf("update action_gestion set ag_comment='%s',".
00864                    " ag_timestamp=to_date('%s','DD.MM.YYYY'),".
00865                    " ag_title='%s',".
00866                    " ag_type=%d, ".
00867                    " f_id_exp=%d, ".
00868                    " f_id_dest=%d, ".
00869                    " ag_ref_ag_id=%d".
00870                    " where ag_id = %d",
00871                    $this->ag_comment,
00872                    $this->ag_timestamp,
00873                    FormatString($this->ag_title),
00874                    $this->dt_id,
00875                    $this->f_id_exp,
00876                    $this->f_id_dest,
00877                    $this->ag_ref_ag_id,
00878                    $this->ag_id);
00879       ExecSql($this->db,$sql);
00880       
00881       if ( sizeof($_FILES) !=0 ) 
00882         {
00883           // Upload a new document
00884           $doc=new Document($this->db);
00885           if ( $this->d_id !=0 )
00886             {
00887               $doc->d_id=$this->d_id;
00888             } else {
00889               // we need to increment the counter 
00890               $doc->ag_id=$this->ag_id;
00891               $doc->md_type=$this->dt_id;
00892               $doc->blank();
00893             }
00894           $doc->Upload($this->ag_id);
00895       
00896         }
00897       if ( $this->d_id != 0 )
00898         {
00899           $doc=new Document($this->db);
00900           $doc->d_id=$this->d_id ;
00901           $doc->d_state=$this->d_state;
00902           $doc->save();
00903         }
00904       return true;
00905     }
00906 
00907 }