00001 <?
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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 {
00061 var $db;
00062 var $ag_comment;
00063 var $ag_timestamp;
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
00089
00090 $date=new widget("text");
00091 $date->readonly=true;
00092 $date->name="ag_timestamp";
00093 $date->value=$this->ag_timestamp;
00094
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
00103
00104
00105 $doc_ref="";
00106 if ( strlen ($this->d_state) > 0 )
00107 {
00108 $a=ExecSql($this->db,"select s_value from document_state where s_id=".$this->d_state);
00109 $v=pg_fetch_array($a,0);
00110 $str_state=$v[0];
00111 $state=new widget("hidden");
00112 $state->name="d_state";
00113 $state->value=$this->d_state;
00114 $doc=new Document($this->db,$this->d_id);
00115 $doc_ref="<p> Document ".$doc->a_ref().'</p>';
00116 }
00117 else
00118 $str_state="";
00119
00120 $title=new widget("text");
00121 $title->readonly=true;
00122 $title->name="ag_title";
00123 $title->value=FormatString($this->ag_title);
00124
00125
00126 $ag_ref=new widget("text");
00127 $ag_ref->readonly=true;
00128 $ag_ref->name="ag_ref";
00129 $ag_ref->value=FormatString($this->ag_ref);
00130
00131
00132
00133 $desc=new widget('textarea');
00134 $desc->name="ag_comment";
00135 $desc->readonly=" disabled ";
00136 $desc->value=$this->ag_comment;
00137
00138 $gen=new widget ("checkbox");
00139 $gen->name="p_gen";
00140 $doc_gen=new widget("select");
00141 $doc_gen->name="gen_doc";
00142 $doc_gen->value=make_array($this->db,
00143 "select md_id,md_name from document_modele where md_type=".$this->dt_id);
00144
00145 $tiers=new fiche($this->db);
00146 $tiers->GetByQCode($this->qcode);
00147
00148
00149 $r.="<p>Date : ".$date->IOValue()."</p>";
00150 if ( $str_type != "" )
00151 $r.="<p>Type du document $str_type".$doc_type->IOValue()."</p>";
00152 $r.="<p> Tiers : ".$this->qcode." ".$tiers->strAttribut(1).'</p>';
00153 $r.="<p> Titre : ".$title->IOValue().' Ref :'.$ag_ref->IOValue();
00154 $r.=$doc_ref;
00155 $r.="<p>Description :".urldecode(urldecode($desc->IOValue()))."</p>";
00156
00157 return $r;
00158
00159 }
00162 function get()
00163 {
00164 echo_debug('class_action',__LINE__,'Action::Get() ');
00165 $sql="select * from action_gestion left join document using (ag_id) where ag_id=".$this->ag_id;
00166 $r=ExecSql($this->db,$sql);
00167 $row=pg_fetch_all($r);
00168 if ( $row==false) return;
00169 $this->ag_comment=$row[0]['ag_comment'];
00170 $this->ag_timestamp=$row[0]['ag_timestamp'];
00171 $this->f_id=$row[0]['f_id'];
00172 $this->ag_title=$row[0]['ag_title'];
00173 $this->ag_type=$row[0]['ag_type'];
00174 $this->ag_ref=$row[0]['ag_ref'];
00175 $this->d_id=$row[0]['d_id'];
00176 echo_debug('class_action',__LINE__,' Document id = '.$this->d_id);
00177
00178 if ( $this->d_id == "" )
00179 $this->d_id=0;
00180
00181 if ($this->d_id != 0 )
00182 {
00183 $this->d_state=$row[0]['d_state'];
00184 }
00185 echo_debug('class_action',__LINE__,' After test Document id = '.$this->d_id);
00186 $this->dt_id=$this->ag_type;
00187 $a=new fiche($this->db,$this->f_id);
00188 $this->qcode=$a->strAttribut(ATTR_DEF_QUICKCODE);
00189
00190 }
00199 function Confirm()
00200 {
00202 if ( isDate($this->ag_timestamp) == NULL )
00203 {
00204
00205 $this->ag_timestamp=date("d.m.Y");
00206 }
00207
00208
00209 $date=new widget("text");
00210 $date->readonly=true;
00211 $date->name="ag_timestamp";
00212 $date->value=$this->ag_timestamp;
00213
00214 $doc_type=new widget("hidden");
00215 $doc_type->name="dt_id";
00216 $doc_type->value=$this->dt_id;
00217 $a=ExecSql($this->db,"select dt_value from document_type where dt_id=".$this->dt_id);
00218 $v=pg_fetch_array($a,0);
00219 $str_type=$v[0];
00220 if ( isset ($_REQUEST['url']))
00221 {
00222 $retour=sprintf('<A HREF="%s"><input type="button" value="Retour"></A>',urldecode($_REQUEST['url']));
00223 $h_url=sprintf('<input type="hidden" name="url" value="%s">',urldecode($_REQUEST['url']));
00224 }
00225 else
00226 {
00227 $retour="";
00228 $h_url="";
00229 }
00230
00231
00232 $a=ExecSql($this->db,"select s_value from document_state where s_id=".$this->d_state);
00233 $v=pg_fetch_array($a,0);
00234 $str_state=$v[0];
00235 $state=new widget("hidden");
00236 $state->name="d_state";
00237 $state->value=$this->d_state;
00238
00239
00240 $title=new widget("text");
00241 $title->readonly=true;
00242 $title->name="ag_title";
00243 $title->value=FormatString($this->ag_title);
00244
00245
00246 $desc=new widget('textarea');
00247 $desc->name="ag_comment";
00248 $desc->readonly=" disabled ";
00249 $desc->value=$this->ag_comment;
00250
00251 $gen=new widget ("checkbox");
00252 $gen->name="p_gen";
00253 $doc_gen=new widget("select");
00254 $doc_gen->name="gen_doc";
00255 $doc_gen->value=make_array($this->db,
00256 "select md_id,md_name from document_modele where md_type=".$this->dt_id);
00257
00258 $tiers=new fiche($this->db);
00259 $tiers->GetByQCode($this->qcode);
00260
00261 $r=$retour."<form method=\"post\">";
00262 $r.="<p>Date : ".$date->IOValue()."</p>";
00263 $r.="<p>Etat $str_state".$state->IOValue()."</p>";
00264 $r.="<p>Type du document $str_type".$doc_type->IOValue()."</p>";
00265 $r.="<p> Tiers : ".$this->qcode." ".$tiers->strAttribut(1).'</p>';
00266 $r.="<p> Titre : ".$title->IOValue();
00267 $r.="<p>Description :".$desc->IOValue()."</p>";
00268
00269
00270 if ( sizeof($doc_gen->value) != 0)
00271 $r.="<p> Générer un document ".$gen->IOValue()." ".$doc_gen->IOValue()."</p>";
00272
00273
00274 $r.='<input type="hidden" name="sa" value="save_action_st2">';
00275 $r.='<input type="hidden" name="p_action" value="suivi_courrier">';
00276 $r.='<input type="hidden" name="tiers" value="'.$this->qcode.'">';
00277 if ( $tiers->strAttribut(1) != "- ERROR -")
00278 $r.=$desc->Submit("Save","Sauve");
00279 $r.=$desc->Submit("corr","Corrige");
00280
00281 $r.=$h_url."</form>";
00282 return $r;
00283 }
00291 function SaveStage2()
00292 {
00293
00294 $seq_name="seq_doc_type_".$this->dt_id;
00295 $str_file="";
00296 $add_file='';
00297
00298 $tiers=new fiche($this->db);
00299 $tiers->GetByQCode($this->qcode);
00300 if ( trim($this->ag_title) == "") {
00301 $doc_mod=new document_type($this->db);
00302 $doc_mod->dt_id=$this->dt_id;
00303 $doc_mod->get();
00304 $this->ag_title=$doc_mod->dt_value;
00305 }
00306 echo_debug('class_action',__LINE__," tiers->id ".$tiers->id);
00307 $this->ag_id=NextSequence($this->db,'action_gestion_ag_id_seq');
00308
00309 $ref=$this->dt_id.'/'.$this->ag_id;
00310 $this->ag_ref=$ref;
00311
00312 $sql=sprintf("insert into action_gestion(ag_id,ag_type,ag_title,f_id,ag_comment,ag_ref) values (%d,'%s','%s',%d,'%s','%s')",
00313 $this->ag_id,
00314 $this->dt_id,
00315 FormatString($this->ag_title),
00316 $tiers->id,
00317 FormatString(urlencode($this->ag_comment)),
00318 $ref
00319 );
00320 ExecSql($this->db,$sql);
00321
00322
00323
00324
00325 if ( $this->gen == 'on' )
00326 {
00327 $doc=new Document($this->db);
00328 $doc->f_id=$tiers->id;
00329 $doc->md_id=$this->md_id;
00330 $doc->ag_id=$this->ag_id;
00331 $doc->d_state=$this->d_state;
00332 $str_file=$doc->Generate();
00333 $d='<input type="hidden" name="d_id" value="'.$doc->d_id.'">';
00334 }
00335
00336 $r=$this->Display();
00337 $r.="<hr>";
00338 $r.='<form enctype="multipart/form-data" method="post">';
00339
00340 $r.='<input type="hidden" name="sa" value="save_action_st3">';
00341 $r.='<input type="hidden" name="p_action" value="suivi_courrier">';
00342 $r.='<input type="hidden" name="ag_id" value="'.$this->ag_id.'">';
00343
00344 $r.=$d;
00345
00346
00347 if ( $this->gen == 'on' )
00348 {
00349 $r.='<input type="hidden" name="d_id" value="'.$doc->d_id.'">';
00350 $r.="Sauver le document généré :";
00351 $r.=$str_file;
00352 $checkbox=new widget("checkbox");
00353 $checkbox->name="save_generate";
00354 $r.=$checkbox->IOValue();
00355 $r.="<hr>";
00356 }
00357 $upload=new widget("file");
00358 $upload->name="file_upload";
00359 $upload->value="";
00360 $r.="Enregistrer le fichier ".$upload->IOValue();
00361 $r.=$upload->Submit("save","Sauve le fichier");
00362 $r.="</form>";
00363 return $r;
00364 }
00370 function SaveStage3($d_id)
00371 {
00372
00373 if ( $d_id == 0 ) return;
00374
00375 if ( isset($_POST['save_generate']))
00376 {
00377 return;
00378 }
00379
00380
00381 $doc=new Document($this->db);
00382 $doc->d_id=$d_id;
00383 $doc->Upload($this->ag_id);
00384 }
00393 function myList($p_filter="",$p_search="")
00394 {
00395 $sql="
00396 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,ag_ref
00397 from action_gestion
00398 left outer join document using (ag_id)
00399 left outer join document_modele on (ag_type=md_type)
00400 join document_type on (ag_type=dt_id)
00401 where dt_id in ($p_filter) $p_search";
00402 $max_line=CountSql($this->db,$sql);
00403 $step=$_SESSION['g_pagesize'];
00404 $page=(isset($_GET['offset']))?$_GET['page']:1;
00405 $offset=(isset($_GET['offset']))?$_GET['offset']:0;
00406 $limit=" LIMIT $step OFFSET $offset ";
00407 $bar=jrn_navigation_bar($offset,$max_line,$step,$page);
00408
00409 $Res=ExecSql($this->db,$sql.$limit);
00410 $a_row=pg_fetch_all($Res);
00411 $r='<div class="u_redcontent">';
00412 $r.=$bar;
00413 $r.="<table>";
00414 $r.="<tr>";
00415 $r.="<th>Date</th>";
00416 $r.="<th>Société</th>";
00417 $r.="<th>Titre</th>";
00418 $r.="<th>type</th>";
00419 $r.="<th>Référence</th>";
00420 $r.="<th>Document</th>";
00421 $r.="</tr>";
00422
00423
00424 if ( sizeof ($a_row) == 0 or $a_row == false )
00425 {
00426 $r='<div class="u_redcontent">';
00427 $r.='<hr>Aucun enregistrement trouvé';
00428 $r.="</div>";
00429 return $r;
00430
00431 }
00432 echo JS_SEARCH_CARD;
00433 foreach ($a_row as $row )
00434 {
00435 $r.="<tr>";
00436 $r.="<td>".$row['my_date']."</td>";
00437 $f=new fiche($this->db);
00438 $f->id=$row['f_id'];
00439 $q=$f->strAttribut(ATTR_DEF_QUICKCODE);
00440 $js=sprintf("javascript:showfiche('%s','%s')",
00441 $_REQUEST['PHPSESSID'],$q);
00442 $r.="<td>".'<A HREF="'.$js.'">'.$q." : ".$f->getName().'</A></td>';
00443 $r.='<td><A HREF="commercial.php?p_action=suivi_courrier&sa=detail&ag_id='.$row['ag_id'].'">'.
00444 $row['ag_title']."</A></td>";
00445 $r.="<td>".$row['dt_value']."</td>";
00446 $r.="<td>".$row['ag_ref']."</td>";
00447
00448 $doc=new Document($this->db,$row['d_id']);
00449 $r.="<td>".$doc->a_ref()."</td>";
00450 $r.="</tr>";
00451
00452 }
00453 $r.="</table>";
00454 $r.=$bar;
00455 $r.="</div>";
00456 return $r;
00457 }
00458
00459
00460
00461 }