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$ */
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");
00047 class action 
00048 {
00060   var $db;
00061   var $ag_desc;
00062   var $ag_date;
00063   var $d_lob;
00064   var $dt_id;
00065   var $d_state;
00066   var $d_number;
00067   var $d_filename;
00068   var $d_mimetype;
00069   var $ag_title;
00070   var $f_id;
00075   function action ($p_cn)
00076     {
00077       $this->db=$p_cn;
00078       $this->f_id=0;
00079     }
00085   function Display() 
00086     {
00087       $r="";
00088       // Compute the widget
00089       // Date 
00090       $date=new widget("text");
00091       $date->readonly=true;
00092       $date->name="ag_date";
00093       $date->value=$this->ag_date;
00094       // Doc Type
00095       $doc_type=new widget("hidden");
00096       $doc_type->name="dt_id";
00097       $doc_type->value=$this->dt_id;
00098       $a=ExecSql($this->db,"select dt_value from document_type where dt_id=".$this->dt_id);
00099       $v=pg_fetch_array($a,0);
00100       $str_type=$v[0];
00101 
00102       // state
00103       // Retrieve the value
00104       $a=ExecSql($this->db,"select s_value from document_state where s_id=".$this->d_state);
00105       $v=pg_fetch_array($a,0);
00106       $str_state=$v[0];
00107       $state=new widget("hidden");
00108       $state->name="d_state";
00109       $state->value=$this->d_state;
00110       // title
00111       $title=new widget("text");
00112       $title->readonly=true;
00113       $title->name="ag_title";
00114       $title->value=FormatString($this->ag_title);
00115 
00116       // Description
00117       $desc=new widget('textarea');
00118       $desc->name="ag_desc";
00119       $desc->readonly=" disabled ";
00120       $desc->value=$this->ag_desc;
00121       // Propose to generate a document
00122       $gen=new widget ("checkbox");
00123       $gen->name="p_gen";
00124       $doc_gen=new widget("select");
00125       $doc_gen->name="gen_doc";
00126       $doc_gen->value=make_array($this->db,
00127                                  "select md_id,md_name from document_modele where md_type=".$this->dt_id);
00128       // f_id
00129       $tiers=new fiche($this->db);
00130       $tiers->GetByQCode($this->qcode);
00131       // Preparing the return string
00132 
00133       $r.="<p>Date : ".$date->IOValue()."</p>";
00134       $r.="<p>Etat $str_state".$state->IOValue()."</p>";
00135       $r.="<p>Type du document $str_type".$doc_type->IOValue()."</p>";
00136       $r.="<p> Tiers : ".$this->qcode." ".$tiers->strAttribut(1).'</p>';
00137       $r.="<p> Titre : ".$title->IOValue();
00138       $r.="<p>Description :".urldecode($desc->IOValue())."</p>";
00139       return $r;
00140  
00141     }
00142 
00151   function Confirm()
00152     {
00153       if ( isDate($this->ag_date) == NULL )
00154         {
00155           // if the date is invalid, default date is today
00156           $this->ag_date=date("d.m.Y");
00157         }
00158       // Compute the widget
00159       // Date 
00160       $date=new widget("text");
00161       $date->readonly=true;
00162       $date->name="ag_date";
00163       $date->value=$this->ag_date;
00164       // Doc Type
00165       $doc_type=new widget("hidden");
00166       $doc_type->name="dt_id";
00167       $doc_type->value=$this->dt_id;
00168       $a=ExecSql($this->db,"select dt_value from document_type where dt_id=".$this->dt_id);
00169       $v=pg_fetch_array($a,0);
00170       $str_type=$v[0];
00171       if ( isset ($_REQUEST['url'])) 
00172         {
00173           $retour=sprintf('<A HREF="%s"><input type="button" value="Retour"></A>',urldecode($_REQUEST['url']));
00174           $h_url=sprintf('<input type="hidden" name="url" value="%s">',urldecode($_REQUEST['url']));
00175         }
00176       else 
00177         { 
00178           $retour="";
00179           $h_url="";
00180         }
00181 
00182       // state
00183       // Retrieve the value
00184       $a=ExecSql($this->db,"select s_value from document_state where s_id=".$this->d_state);
00185       $v=pg_fetch_array($a,0);
00186       $str_state=$v[0];
00187       $state=new widget("hidden");
00188       $state->name="d_state";
00189       $state->value=$this->d_state;
00190       // title
00191       $title=new widget("text");
00192       $title->readonly=true;
00193       $title->name="ag_title";
00194       $title->value=FormatString($this->ag_title);
00195 
00196       // Description
00197       $desc=new widget('textarea');
00198       $desc->name="ag_desc";
00199       $desc->readonly=" disabled ";
00200       $desc->value=$this->ag_desc;
00201       // Propose to generate a document
00202       $gen=new widget ("checkbox");
00203       $gen->name="p_gen";
00204       $doc_gen=new widget("select");
00205       $doc_gen->name="gen_doc";
00206       $doc_gen->value=make_array($this->db,
00207                                  "select md_id,md_name from document_modele where md_type=".$this->dt_id);
00208       // f_id
00209       $tiers=new fiche($this->db);
00210       $tiers->GetByQCode($this->qcode);
00211       // Preparing the return string
00212       $r=$retour."<form method=\"post\">";
00213       $r.="<p>Date : ".$date->IOValue()."</p>";
00214       $r.="<p>Etat $str_state".$state->IOValue()."</p>";
00215       $r.="<p>Type du document $str_type".$doc_type->IOValue()."</p>";
00216       $r.="<p> Tiers : ".$this->qcode." ".$tiers->strAttribut(1).'</p>';
00217       $r.="<p> Titre : ".$title->IOValue();
00218       $r.="<p>Description :".$desc->IOValue()."</p>";
00219       // if no document exist for this type then do not display the question
00220       if ( sizeof($doc_gen->value) != 0) 
00221         $r.="<p> G&eacute;n&eacute;rer un document ".$gen->IOValue()." ".$doc_gen->IOValue()."</p>";
00222 
00223       // Add the hidden tag
00224       $r.='<input type="hidden" name="sa" value="save_action_st2">';
00225       $r.='<input type="hidden" name="p_action" value="suivi_courrier">';
00226       $r.='<input type="hidden" name="tiers" value="'.$this->qcode.'">';
00227       if ( $tiers->strAttribut(1) != "- ERROR -")
00228         $r.=$desc->Submit("Save","Sauve");
00229       $r.=$desc->Submit("corr","Corrige");
00230 
00231       $r.=$h_url."</form>";
00232       return $r;
00233     }
00241   function SaveStage2() 
00242     {
00243       // Get The sequence id, 
00244       $seq_name="seq_doc_type_".$this->dt_id;
00245       $str_file="";
00246       $add_file='';
00247       // f_id
00248       $tiers=new fiche($this->db);
00249       $tiers->GetByQCode($this->qcode);
00250       if ( trim($this->ag_title) == "") {
00251         $doc_mod=new document_type($this->db);
00252         $doc_mod->dt_id=$this->dt_id;
00253         $doc_mod->get();
00254         $this->ag_title=$doc_mod->dt_value;
00255       }
00256       echo_debug('class_action',__LINE__," tiers->id  ".$tiers->id);
00257       $sql=sprintf("insert into action_gestion(ag_type,ag_title,f_id,ag_comment) values ('%s','%s',%d,'%s')",              $this->dt_id,
00258                    FormatString($this->ag_title),
00259                    $tiers->id,
00260                    FormatString(urlencode($this->ag_desc)));
00261       ExecSql($this->db,$sql);
00262       $this->ag_id=GetSequence($this->db,'action_gestion_ag_id_seq');
00263 
00264       // the lob filename and the mimetype needed if we want to generate a doc.
00265       if ( $this->gen == 'on' ) 
00266         {
00267           $doc=new Document($this->db);
00268           $doc->f_id=$tiers->id;
00269           $doc->md_id=$this->md_id;
00270           $doc->ag_id=$this->ag_id;
00271           $str_file=$doc->Generate();
00272         }
00273 
00274       $r=$this->Display();
00275       $r.="<hr>";
00276       $r.='<form enctype="multipart/form-data" method="post">';
00277       // Add the hidden tag
00278       $r.='<input type="hidden" name="sa" value="save_action_st3">';
00279       $r.='<input type="hidden" name="p_action" value="suivi_courrier">';
00280       $r.='<input type="hidden" name="ag_id" value="'.$this->ag_id.'">';
00281 
00282       // Value for the generated document
00283       if ( $this->gen == 'on' ) 
00284         {
00285           $r.='<input type="hidden" name="d_id" value="'.$doc->d_id.'">';
00286           $r.="Sauver le document généré :";
00287           $r.=$str_file;
00288           $checkbox=new widget("checkbox");
00289           $checkbox->name="save_generate";
00290           $r.=$checkbox->IOValue();
00291           $r.="<hr>";
00292         }
00293       $upload=new widget("file");
00294       $upload->name="file_upload";
00295       $upload->value="";
00296       $r.="Enregistrer le fichier ".$upload->IOValue();
00297       $r.=$upload->Submit("save","Sauve le fichier");
00298       $r.="</form>";
00299       return $r;
00300     }
00306   function SaveStage3($d_id) 
00307     {
00308       // no generated doc
00309       if ( $d_id == 0 ) return;
00310       // if we save the generated doc
00311       if ( isset($_POST['save_generate']))
00312         {
00313           return;
00314         }
00315 
00316       // Upload a new document
00317       $doc=new Document($this->db);
00318       $doc->d_id=$d_id;
00319       $doc->Upload($this->ag_id);
00320     }
00329   function myList($p_filter="",$p_search="")
00330     {
00331       $sql="
00332    select ag_id,to_char(ag_timestamp,'DD-MM-YYYY HH:MI') as my_date,f_id,ag_title,d_id,md_type,dt_value 
00333    from action_gestion 
00334       left outer join document using (ag_id)
00335       left outer join document_modele on (ag_type=md_type) 
00336       join document_type on (ag_type=dt_id)
00337    where dt_id in ($p_filter) $p_search";
00338       $max_line=CountSql($this->db,$sql);
00339       $step=$_SESSION['g_pagesize'];
00340       $page=(isset($_GET['offset']))?$_GET['page']:1;
00341       $offset=(isset($_GET['offset']))?$_GET['offset']:0;
00342       $limit=" LIMIT $step OFFSET $offset ";  
00343       $bar=jrn_navigation_bar($offset,$max_line,$step,$page);
00344 
00345       $Res=ExecSql($this->db,$sql.$limit);
00346       $a_row=pg_fetch_all($Res);
00347       $r='<div class="u_redcontent">';
00348       $r.=$bar;
00349       $r.="<table>";
00350       $r.="<tr>";
00351       $r.="<th>Date</th>";
00352       $r.="<th>Société</th>";
00353       $r.="<th>Titre</th>";
00354       $r.="<th>type</th>";
00355       $r.="<th>Document</th>";
00356       $r.="</tr>";
00357 
00358       // if there are no records return a message
00359       if ( sizeof ($a_row) == 0 or $a_row == false ) 
00360         {
00361           $r='<div class="u_redcontent">';
00362           $r.='<hr>Aucun enregistrement trouvé';
00363           $r.="</div>";
00364           return $r;
00365 
00366         }
00367       foreach ($a_row as $row )
00368         {
00369           $r.="<tr>";
00370           $r.="<td>".$row['my_date']."</td>";
00371           $f=new fiche($this->db);
00372           $f->id=$row['f_id'];
00373           $r.="<td>".$f->getName()."</td>";
00374           $r.="<td>".$row['ag_title']."</td>";
00375           $r.="<td>".$row['dt_value']."</td>";
00376 
00377           $doc=new Document($this->db,$row['d_id']);
00378           $r.="<td>".$doc->a_ref()."</td>";
00379           $r.="</tr>";
00380 
00381         }
00382       $r.="</table>";
00383       $r.=$bar;
00384       $r.="</div>";
00385       return $r;
00386     }
00387 
00388 
00389 
00390 }

Generated on Fri Jun 23 00:12:45 2006 for phpcompta by  doxygen 1.4.4