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
00080 }
00081
00098 function Display($p_view,$p_gen)
00099 {
00100 echo_debug('class_action',__LINE__,'Display() :'.var_export($_POST,true));
00101 echo_debug('class_action',__LINE__,'Display $this :'.var_export($this,true));
00102
00103
00104 if ( $p_view=='UPD')
00105 {
00106 $upd=true;
00107 $readonly=false;
00108 }
00109 elseif ($p_view=="NEW")
00110 {
00111 $upd=false;
00112 $readonly=false;
00113 }
00114 elseif ($p_view=='READ')
00115 {
00116 $upd=true;
00117 $readonly=true;
00118 }
00119 else
00120 {
00121 exit('class_action'.__LINE__.'action::Display error unknown parameter'.$p_view);
00122
00123 }
00124
00125
00126 $date=new widget("text");
00127 $date->readonly=$readonly;
00128 $date->name="ag_timestamp";
00129 $date->value=$this->ag_timestamp;
00130
00131
00132
00133 if ( $upd == false )
00134 {
00135
00136 $doc_type=new widget("select");
00137 $doc_type->name="dt_id";
00138 $doc_type->value=make_array($this->db,"select dt_id,dt_value from document_type where dt_id in (".ACTION.")");
00139 $doc_type->selected=$this->dt_id;
00140 $doc_type->readonly=false;
00141 $str_doc_type=$doc_type->IOValue();
00142 echo_debug('class_action',__LINE__,var_export($doc_type,true));
00143 }
00144 else {
00145
00146 $doc_type=new widget("hidden");
00147 $doc_type->name="dt_id";
00148 $doc_type->value=$this->dt_id;
00149 $str_doc_type=$doc_type->IOValue().getDbValue($this->db,"select dt_id,dt_value from document_type where dt_id=".$this->dt_id);
00150 }
00151
00152
00153 $desc=new widget('RICHTEXT');
00154 $desc->width=540;
00155 $desc->heigh=200;
00156 $desc->name="ag_comment";
00157 $desc->readonly=$readonly;
00158 $desc->value=urldecode($this->ag_comment);
00159
00160
00161
00162 if ( $p_view != 'READ' )
00163 {
00164 $a=make_array($this->db,"select s_id,s_value from document_state ");
00165 $state=new widget("select");
00166 $state->readonly=$readonly;
00167 $state->name="d_state";
00168 $state->value=$a;
00169 $state->selected=$this->d_state;
00170 $str_state=$state->IOValue();
00171 } else {
00172 $str_state=getDbValue($this->db,"select s_value from document_state where s_id=".$this->d_state);
00173 $g=new widget("hidden");
00174 $str_state.=$g->IOValue('d_state',$this->d_state);
00175 }
00176
00177 $doc_ref="";
00178
00179
00180 $h2=new widget("hidden");
00181 $h2->name="d_id";
00182 $h2->value=$this->d_id;
00183
00184 if ( $this->d_id != 0 && $this->d_id != "" )
00185 {
00186 $h2->readonly=($p_view=='NEW')?false:true;
00187 $doc=new Document($this->db,$this->d_id);
00188 $d_id=new widget("hidden");
00189 $doc_ref="<p> Document ".$doc->a_ref().'</p>';
00190 $doc_ref.=$h2->IOValue().$d_id->IOValue('d_id',$this->d_id);
00191
00192 }
00193
00194
00195
00196 $title=new widget("text");
00197 $title->readonly=$readonly;
00198 $title->name="ag_title";
00199 $title->value=FormatString($this->ag_title);
00200
00201
00202
00203 $ag_ref=new widget("text");
00204 $ag_ref->readonly=true;
00205 $ag_ref->name="ag_ref";
00206 $ag_ref->value=FormatString($this->ag_ref);
00207 $client_label=new widget("span");
00208
00209
00210 if ( $this->qcode != '- ERROR -' && trim($this->qcode) != "")
00211 {
00212 $tiers=new fiche($this->db);
00213 $tiers->GetByQCode($this->qcode);
00214 $qcode_label=$tiers->strAttribut(1);
00215 } else {
00216 echo "f_id $this->f_id";
00217 $qcode_label=($this->f_id==0 || trim($this->qcode)=="")?'Interne ':'Error';
00218 }
00219 $h_ag_id=new widget("hidden");
00220
00221
00222 $w=new widget('js_search_only');
00223 $w->readonly=$readonly;
00224 $w->name='qcode';
00225 $w->value=($this->f_id != 0)?$this->qcode:"";
00226 $w->label="";
00227 $w->extra='4,8,9,14,16';
00228 $sp= new widget("span");
00229
00230
00231 $r="";
00232 $r.=JS_SEARCH_CARD;
00233 $r.= "<p>Date : ".$date->IOValue()." Reference ". $this->ag_ref."</p>";
00234
00235 $r.= 'Type d\' action';
00236 echo_debug('class_action',__LINE__,"str_doc_type $str_doc_type");
00237 $r.= $str_doc_type;
00238
00239
00240 $r.="<p>Etat :".$str_state;
00241
00242
00243 $r.= "<p> ";
00244 $r.=$w->IOValue();
00245 $r.=$sp->IOValue('qcode_label',$qcode_label)."</TD></TR>";
00246
00247 $r.="</p>".$h_ag_id->IOValue('ag_id',$this->ag_id);
00248 echo_debug('class_action',__LINE__,' ag_id is '.$this->ag_id);
00249
00250 $r.= "<p> Titre : ".$title->IOValue().' Ref :'.$ag_ref->IOValue();
00251 $r.= $doc_ref;
00252 $r.= "<p>Description :".$desc->IOValue()."</p>";
00253 $r.=$h2->IOValue();
00254 return $r;
00255
00256 }
00257
00260 function get()
00261 {
00262 echo_debug('class_action',__LINE__,'Action::Get() ');
00263 $sql="select ag_id, ag_comment,to_char (ag_timestamp,'DD-MM-YYYY') as ag_timestamp,".
00264 " f_id,ag_title,ag_comment,ag_ref,d_id,ag_type,d_state ".
00265 " from action_gestion left join document using (ag_id) where ag_id=".$this->ag_id;
00266 $r=ExecSql($this->db,$sql);
00267 $row=pg_fetch_all($r);
00268 if ( $row==false) return;
00269 $this->ag_comment=$row[0]['ag_comment'];
00270 $this->ag_timestamp=$row[0]['ag_timestamp'];
00271 $this->f_id=$row[0]['f_id'];
00272 $this->ag_title=$row[0]['ag_title'];
00273 $this->ag_type=$row[0]['ag_type'];
00274 $this->ag_ref=$row[0]['ag_ref'];
00275 $this->d_id=$row[0]['d_id'];
00276
00277 echo_debug('class_action',__LINE__,' Document id = '.$this->d_id);
00278
00279 if ( $this->d_id == "" )
00280 $this->d_id=0;
00281
00282 if ($this->d_id != 0 )
00283 {
00284 $this->state=$row['0']['d_state'];
00285 $this->d_state=$row[0]['d_state'];
00286 }
00287 echo_debug('class_action',__LINE__,' After test Document id = '.$this->d_id);
00288 $this->dt_id=$this->ag_type;
00289 $a=new fiche($this->db,$this->f_id);
00290 $this->qcode=$a->strAttribut(ATTR_DEF_QUICKCODE);
00291 echo_debug('class_action',__LINE__,'Detail end () :'.var_export($_POST,true));
00292 echo_debug('class_action',__LINE__,'Detail $this :'.var_export($this,true));
00293
00294 }
00303 function Confirm()
00304 {
00305 echo_debug('class_action',__LINE__,'confirm() :'.var_export($_POST,true));
00306 echo_debug('class_action',__LINE__,'confirm $this :'.var_export($this,true));
00308 if ( isDate($this->ag_timestamp) == null )
00309 {
00310
00311 $this->ag_timestamp=date("d.m.Y");
00312 }
00313
00314
00315 $date=new widget("text");
00316 $date->readonly=true;
00317 $date->name="ag_timestamp";
00318 $date->value=$this->ag_timestamp;
00319
00320 $doc_type=new widget("hidden");
00321 $doc_type->name="dt_id";
00322 $doc_type->value=$this->dt_id;
00323 $a=ExecSql($this->db,"select dt_value from document_type where dt_id=".$this->dt_id);
00324 $v=pg_fetch_array($a,0);
00325 $str_type=$v[0];
00326 if ( isset ($_REQUEST['url']))
00327 {
00328 $retour=sprintf('<A HREF="%s"><input type="button" value="Retour"></A>',urldecode($_REQUEST['url']));
00329 $h_url=sprintf('<input type="hidden" name="url" value="%s">',urldecode($_REQUEST['url']));
00330 }
00331 else
00332 {
00333 $retour="";
00334 $h_url="";
00335 }
00336
00337
00338 $a=ExecSql($this->db,"select s_value from document_state where s_id=".$this->d_state);
00339 $v=pg_fetch_array($a,0);
00340 $str_state=$v[0];
00341 $state=new widget("hidden");
00342 $state->name="d_state";
00343 $state->value=$this->d_state;
00344
00345
00346 $title=new widget("text");
00347 $title->readonly=true;
00348 $title->name="ag_title";
00349 $title->value=FormatString($this->ag_title);
00350
00351
00352 $desc=new widget('textarea');
00353 $desc->name="ag_comment";
00354 $desc->readonly=" disabled ";
00355 $desc->value=$this->ag_comment;
00356
00357 $gen=new widget ("checkbox");
00358 $gen->name="p_gen";
00359 $doc_gen=new widget("select");
00360 $doc_gen->name="gen_doc";
00361 $doc_gen->value=make_array($this->db,
00362 "select md_id,md_name from document_modele where md_type=".$this->dt_id);
00363
00364
00365 if ( trim($this->qcode) =="" && $this->dt_id==1)
00366 {
00367
00368 $f_id=0;
00369 $name="interne";
00370 }
00371 elseif ( trim($this->qcode) !="" && $this->dt_id != 1 )
00372 {
00373 $tiers=new fiche($this->db);
00374 $tiers->GetByQCode($this->qcode);
00375 $f_id=$tiers->id;
00376 $name=$tiers->strAttribut(1);
00377 }
00378 else {
00379 $name="ERROR";
00380 $f_id=-1;
00381 }
00382
00383
00384 $r=$retour."<form method=\"post\">";
00385 $r.="<p>Date : ".$date->IOValue()."</p>";
00386 $r.="<p>Etat $str_state".$state->IOValue()."</p>";
00387 $r.="<p>Type du document $str_type".$doc_type->IOValue()."</p>";
00388 $r.="<p> Tiers : ".$this->qcode." ".$name.'</p>';
00389 $r.="<p> Titre : ".$title->IOValue();
00390 $r.="<p>Description :".$desc->IOValue()."</p>";
00391
00392
00393 if ( sizeof($doc_gen->value) != 0)
00394 $r.="<p> Générer un document ".$gen->IOValue()." ".$doc_gen->IOValue()."</p>";
00395
00396
00397
00398 $r.='<input type="hidden" name="sa" value="save_action_st2">';
00399 $r.='<input type="hidden" name="p_action" value="suivi_courrier">';
00400 $r.='<input type="hidden" name="tiers" value="'.$this->qcode.'">';
00401
00402
00403
00404 if ( $f_id != -1 )
00405 $r.=$desc->Submit("Save","Sauve");
00406 $r.=$desc->Submit("corr","Corrige");
00407
00408 $r.=$h_url."</form>";
00409 return $r;
00410 }
00418 function SaveStage2()
00419 {
00420 echo_debug('class_action',__LINE__,'saveStage2() :'.var_export($_POST,true));
00421 echo_debug('class_action',__LINE__,' saveStage2() $this :'.var_export($this,true));
00422
00423
00424 $seq_name="seq_doc_type_".$this->dt_id;
00425 $str_file="";
00426 $add_file='';
00427
00428 $tiers=new fiche($this->db);
00429 $tiers->GetByQCode($this->qcode);
00430 if ( trim($this->ag_title) == "")
00431 {
00432 $doc_mod=new document_type($this->db);
00433 $doc_mod->dt_id=$this->dt_id;
00434 $doc_mod->get();
00435 $this->ag_title=$doc_mod->dt_value;
00436 }
00437 echo_debug('class_action',__LINE__," tiers->id ".$tiers->id);
00438 $this->ag_id=NextSequence($this->db,'action_gestion_ag_id_seq');
00439
00440 $ref=$this->dt_id.'/'.$this->ag_id;
00441 $this->ag_ref=$ref;
00444
00445 $this->ag_comment=str_replace("+%OA+","",$this->ag_comment);
00446 $this->ag_comment=str_replace("+%OD+","",$this->ag_comment);
00447 $this->ag_comment=str_replace("%OD","",$this->ag_comment);
00448 $this->ag_comment=str_replace("%OA","",$this->ag_comment);
00449
00450 $sql=sprintf("insert into action_gestion(ag_id,ag_timestamp,ag_type,ag_title,f_id,ag_comment,ag_ref) ".
00451 " values (%d,to_date('%s','DD-MM-YYYY'),'%d','%s',%d,'%s','%s')",
00452 $this->ag_id,
00453 $this->ag_timestamp,
00454 $this->dt_id,
00455 FormatString($this->ag_title),
00456 $tiers->id,
00457 $this->ag_comment,
00458 $ref
00459 );
00460 ExecSql($this->db,$sql);
00461
00462
00463
00464
00465 if ( $this->gen == 'on' )
00466 {
00467 $doc=new Document($this->db);
00468 $doc->f_id=$tiers->id;
00469 $doc->md_id=$this->md_id;
00470 $doc->ag_id=$this->ag_id;
00471 $doc->d_state=$this->d_state;
00472 $str_file=$doc->Generate();
00473 $d='<input type="hidden" name="d_id" value="'.$doc->d_id.'">';
00474 }
00475 $r="";
00476
00477 $r.="<hr>";
00478 $r.='<form enctype="multipart/form-data" method="post">';
00479 $r.=$this->Display('READ',false);
00480
00481 $r.='<input type="hidden" name="sa" value="save_action_st3">';
00482 $r.='<input type="hidden" name="p_action" value="suivi_courrier">';
00483
00484 $r.='<input type="hidden" name="d_id" value="'.$this->d_id.'">';
00485
00486 $r.='<input type="hidden" name="ag_comment" value="'.rawurlencode($this->ag_comment).'">';
00487
00488 if ( $this->gen == 'on' )
00489 {
00490 $r.='<input type="hidden" name="d_id" value="'.$doc->d_id.'">';
00491 $r.="Sauver le document généré :";
00492 $r.=$str_file;
00493 $checkbox=new widget("checkbox");
00494 $checkbox->name="save_generate";
00495 $r.=$checkbox->IOValue();
00496 $r.="<hr>";
00497 }
00498 $upload=new widget("file");
00499 $upload->name="file_upload";
00500 $upload->value="";
00501 $r.="Enregistrer le fichier ".$upload->IOValue();
00502 $r.=$upload->Submit("save","Sauve le fichier");
00503 $r.="</form>";
00504 return $r;
00505 }
00511 function SaveStage3($d_id)
00512 {
00513 echo_debug('class_action',__LINE__,'SaveStage3() :'.var_export($_POST,true));
00514 echo_debug('class_action',__LINE__,'SaveStage3 :'.var_export($this,true));
00515
00516
00517 if ( isset($_POST['save_generate']))
00518 {
00519 return;
00520 }
00521
00522
00523 $doc=new Document($this->db);
00524 $doc->ag_id=$this->ag_id;
00525
00526 if ( sizeof($_FILES) !=0 && $d_id==0)
00527 {
00528 $doc->md_type=$this->dt_id;
00529 $doc->blank();
00530 }
00531 else
00532 $doc->d_id=$d_id;
00533
00534 $doc->Upload($this->ag_id);
00535 }
00536
00545 function myList($p_filter="",$p_search="")
00546 {
00547 $sql="
00548 select ag_id,to_char(ag_timestamp,'DD-MM-YYYY') as my_date,f_id,ag_title,d_id,md_type,dt_value,ag_ref
00549 from action_gestion
00550 left outer join document using (ag_id)
00551 left outer join document_modele on (ag_type=md_type)
00552 join document_type on (ag_type=dt_id)
00553 where dt_id in ($p_filter) $p_search order by ag_timestamp desc,ag_ref desc";
00554 $max_line=CountSql($this->db,$sql);
00555 $step=$_SESSION['g_pagesize'];
00556 $page=(isset($_GET['offset']))?$_GET['page']:1;
00557 $offset=(isset($_GET['offset']))?$_GET['offset']:0;
00558 $limit=" LIMIT $step OFFSET $offset ";
00559 $bar=jrn_navigation_bar($offset,$max_line,$step,$page);
00560
00561 $Res=ExecSql($this->db,$sql.$limit);
00562 $a_row=pg_fetch_all($Res);
00563 $r='<div class="u_redcontent">';
00564 $r.=$bar;
00565 $r.="<table>";
00566 $r.="<tr>";
00567 $r.="<th>Date</th>";
00568 $r.="<th>Société</th>";
00569 $r.="<th>Titre</th>";
00570 $r.="<th>type</th>";
00571 $r.="<th>Référence</th>";
00572 $r.="<th>Document</th>";
00573 $r.="</tr>";
00574
00575
00576 if ( sizeof ($a_row) == 0 or $a_row == false )
00577 {
00578 $r='<div class="u_redcontent">';
00579 $r.='<hr>Aucun enregistrement trouvé';
00580 $r.="</div>";
00581 return $r;
00582
00583 }
00584 echo JS_SEARCH_CARD;
00585 foreach ($a_row as $row )
00586 {
00587 $f=new fiche($this->db);
00588 $f->id=$row['f_id'];
00589 $qcode=$f->strAttribut(ATTR_DEF_QUICKCODE);
00590
00591 $r.="<tr>";
00592 $r.="<td>".$row['my_date']."</td>";
00593 $q=($qcode=="- ERROR -")?"Interne":$qcode;
00594 $js=sprintf("javascript:showfiche('%s','%s')",
00595 $_REQUEST['PHPSESSID'],$q);
00596 if ( $q != 'Interne' )
00597 {
00598 $r.="<td>".'<A HREF="'.$js.'">'.$q." : ".$f->getName().'</A></td>';
00599 }
00600 else
00601 $r.="<td>Interne </td>";
00602
00603 $r.='<td><A HREF="commercial.php?p_action=suivi_courrier&sa=detail&ag_id='.$row['ag_id'].'">'.
00604 $row['ag_title']."</A></td>";
00605 $r.="<td>".$row['dt_value']."</td>";
00606 $r.="<td>".$row['ag_ref']."</td>";
00607
00608 $doc=new Document($this->db,$row['d_id']);
00609 $r.="<td>".$doc->a_ref()."</td>";
00610 $r.="</tr>";
00611
00612 }
00613 $r.="</table>";
00614 $r.=$bar;
00615 $r.="</div>";
00616 return $r;
00617 }
00618
00623 function Update()
00624 {
00625 echo_debug('class_action',__LINE__,'Update() $_POST() :'.var_export($_POST,true));
00626 echo_debug('class_action',__LINE__,'Update() $this :'.var_export($this,true));
00627
00628
00629 if ( $this->ag_id == 0 ) return ;
00630
00631
00632
00633
00634
00635 if ( trim($this->qcode) =="" )
00636 {
00637
00638 $this->f_id=0;
00639 }
00640 else
00641 {
00642 $tiers=new fiche($this->db);
00643 if ( $tiers->GetByQCode($this->qcode) ==1 )
00644 return false;
00645 else
00646 $this->f_id=$tiers->id;
00647
00648 }
00649
00650
00651 $this->ag_comment=str_replace("\n","",$this->ag_comment);
00652 $this->ag_comment=str_replace("\r","",$this->ag_comment);
00653
00654
00655 $this->ag_comment=urlencode($this->ag_comment);
00656
00657
00658 $this->ag_comment=str_replace("%A0","",$this->ag_comment);
00659 $this->ag_comment=str_replace("%0D","",$this->ag_comment);
00660 $this->ag_comment=str_replace("+%A0+","",$this->ag_comment);
00661 $this->ag_comment=str_replace("+%0D+","",$this->ag_comment);
00662
00663
00664 $sql=sprintf("update action_gestion set ag_comment='%s',".
00665 "ag_timestamp=to_date('%s','DD.MM.YYYY'),".
00666 "ag_title='%s',".
00667 "ag_type=%d, ".
00668 "f_id=%d ".
00669 " where ag_id = %d",
00670 $this->ag_comment,
00671 $this->ag_timestamp,
00672 FormatString($this->ag_title),
00673 $this->dt_id,
00674 $this->f_id,
00675 $this->ag_id);
00676 ExecSql($this->db,$sql);
00677
00678 if ( sizeof($_FILES) !=0 )
00679 {
00680
00681 $doc=new Document($this->db);
00682 if ( $this->d_id !=0 )
00683 {
00684 $doc->d_id=$this->d_id;
00685 } else {
00686
00687 $doc->ag_id=$this->ag_id;
00688 $doc->md_type=$this->dt_id;
00689 $doc->blank();
00690 }
00691 $doc->Upload($this->ag_id);
00692
00693 }
00694
00695 return true;
00696 }
00697
00698
00699 }