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 }
00094 function Display($p_view)
00095 {
00096
00097
00098
00099 $date=new widget("text");
00100 $date->readonly=$p_view;
00101 $date->name="ag_timestamp";
00102 $date->value=$this->ag_timestamp;
00103
00104
00105 $doc_type=new widget("hidden");
00106 $doc_type->name="dt_id";
00107 $doc_type->value=$this->dt_id;
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 $desc=new widget('RICHTEXT');
00119 $desc->width=540;
00120 $desc->heigh=200;
00121 $desc->name="ag_comment";
00122 $desc->readonly=$p_view;
00123 $desc->value=urldecode($this->ag_comment);
00124
00125
00126
00127 $a=make_array($this->db,"select s_id,s_value from document_state ");
00128 $state=new widget("select");
00129 $state->name="d_state";
00130 $state->value=$a;
00131 $state->selected=$this->d_state;
00132
00133
00134 $doc_ref="";
00135
00136 $this->d_id=(isset($this->d_id))?isset($this->d_id):0;
00137 if ( $this->d_id != 0 )
00138 {
00139 $h2=new widget("hidden");
00140 $h2->name="d_id";
00141 $h2->value=$this->d_id;
00142 $doc=new Document($this->db,$this->d_id);
00143 $doc_ref="<p> Document ".$doc->a_ref().'</p>';
00144 $doc_ref.=$h2->IOValue();
00145 }
00146
00147
00148
00149 $title=new widget("text");
00150 $title->readonly=$p_view;
00151 $title->name="ag_title";
00152 $title->value=FormatString($this->ag_title);
00153
00154
00155
00156 $ag_ref=new widget("text");
00157 $ag_ref->readonly=true;
00158 $ag_ref->name="ag_ref";
00159 $ag_ref->value=FormatString($this->ag_ref);
00160
00161
00162 $gen=new widget ("checkbox");
00163 $gen->name="p_gen";
00164 $doc_gen=new widget("select");
00165 $doc_gen->name="gen_doc";
00166 $doc_gen->value=make_array($this->db,
00167 "select md_id,md_name from document_modele where md_type=".$this->dt_id);
00168
00169 $tiers=new fiche($this->db);
00170 $tiers->GetByQCode($this->qcode);
00171
00172
00173 $w=new widget('js_search_only');
00174 $w->name='qcode';
00175 $w->value=$this->qcode;
00176 $w->label="";
00177 $w->extra='4,8,9,14';
00178 $sp= new widget("span");
00179
00180
00181 $r="";
00182 $r.=JS_SEARCH_CARD;
00183 $r.= "<p>Date : ".$date->IOValue()." Reference ". $this->ag_ref."</p>";
00184
00185 $r.= 'Type d\' action';
00186 $r.= $doc_type->IOValue();
00187
00188
00189 $r.="<p>Etat :".$state->IOValue();
00190
00191
00192 $r.= "<p> ";
00193 $r.=$sp->IOValue("qcode_label",$tiers->strAttribut(1))."</TD></TR>";
00194 $r.=$w->IOValue();
00195 $r.="</p>";
00196
00197 $r.= "<p> Titre : ".$title->IOValue().' Ref :'.$ag_ref->IOValue();
00198 $r.= $doc_ref;
00199 $r.= "<p>Description :".$desc->IOValue()."</p>";
00200
00201 return $r;
00202
00203 }
00206 function get()
00207 {
00208 echo_debug('class_action',__LINE__,'Action::Get() ');
00209 $sql="select ag_id, ag_comment,to_char (ag_timestamp,'DD-MM-YYYY') as ag_timestamp,".
00210 " f_id,ag_title,ag_comment,ag_ref,d_id,ag_type,d_state ".
00211 " from action_gestion left join document using (ag_id) where ag_id=".$this->ag_id;
00212 $r=ExecSql($this->db,$sql);
00213 $row=pg_fetch_all($r);
00214 if ( $row==false) return;
00215 $this->ag_comment=$row[0]['ag_comment'];
00216 $this->ag_timestamp=$row[0]['ag_timestamp'];
00217 $this->f_id=$row[0]['f_id'];
00218 $this->ag_title=$row[0]['ag_title'];
00219 $this->ag_type=$row[0]['ag_type'];
00220 $this->ag_ref=$row[0]['ag_ref'];
00221 $this->d_id=$row[0]['d_id'];
00222
00223 echo_debug('class_action',__LINE__,' Document id = '.$this->d_id);
00224
00225 if ( $this->d_id == "" )
00226 $this->d_id=0;
00227
00228 if ($this->d_id != 0 )
00229 {
00230 $this->state=$row['0']['d_state'];
00231 $this->d_state=$row[0]['d_state'];
00232 }
00233 echo_debug('class_action',__LINE__,' After test Document id = '.$this->d_id);
00234 $this->dt_id=$this->ag_type;
00235 $a=new fiche($this->db,$this->f_id);
00236 $this->qcode=$a->strAttribut(ATTR_DEF_QUICKCODE);
00237
00238 }
00247 function Confirm()
00248 {
00250 if ( isDate($this->ag_timestamp) == NULL )
00251 {
00252
00253 $this->ag_timestamp=date("d.m.Y");
00254 }
00255
00256
00257 $date=new widget("text");
00258 $date->readonly=true;
00259 $date->name="ag_timestamp";
00260 $date->value=$this->ag_timestamp;
00261
00262 $doc_type=new widget("hidden");
00263 $doc_type->name="dt_id";
00264 $doc_type->value=$this->dt_id;
00265 $a=ExecSql($this->db,"select dt_value from document_type where dt_id=".$this->dt_id);
00266 $v=pg_fetch_array($a,0);
00267 $str_type=$v[0];
00268 if ( isset ($_REQUEST['url']))
00269 {
00270 $retour=sprintf('<A HREF="%s"><input type="button" value="Retour"></A>',urldecode($_REQUEST['url']));
00271 $h_url=sprintf('<input type="hidden" name="url" value="%s">',urldecode($_REQUEST['url']));
00272 }
00273 else
00274 {
00275 $retour="";
00276 $h_url="";
00277 }
00278
00279
00280 $a=ExecSql($this->db,"select s_value from document_state where s_id=".$this->d_state);
00281 $v=pg_fetch_array($a,0);
00282 $str_state=$v[0];
00283 $state=new widget("hidden");
00284 $state->name="d_state";
00285 $state->value=$this->d_state;
00286
00287
00288 $title=new widget("text");
00289 $title->readonly=true;
00290 $title->name="ag_title";
00291 $title->value=FormatString($this->ag_title);
00292
00293
00294 $desc=new widget('textarea');
00295 $desc->name="ag_comment";
00296 $desc->readonly=" disabled ";
00297 $desc->value=$this->ag_comment;
00298
00299 $gen=new widget ("checkbox");
00300 $gen->name="p_gen";
00301 $doc_gen=new widget("select");
00302 $doc_gen->name="gen_doc";
00303 $doc_gen->value=make_array($this->db,
00304 "select md_id,md_name from document_modele where md_type=".$this->dt_id);
00305
00306
00307 if ( trim($this->qcode) =="" && $this->dt_id==1)
00308 {
00309
00310 $f_id=0;
00311 $name="interne";
00312 }
00313 elseif ( trim($this->qcode) !="" && $this->dt_id != 1 )
00314 {
00315 $tiers=new fiche($this->db);
00316 $tiers->GetByQCode($this->qcode);
00317 $f_id=$tiers->id;
00318 $name=$tiers->strAttribut(1);
00319 }
00320 else {
00321 $name="ERROR";
00322 $f_id=-1;
00323 }
00324
00325
00326 $r=$retour."<form method=\"post\">";
00327 $r.="<p>Date : ".$date->IOValue()."</p>";
00328 $r.="<p>Etat $str_state".$state->IOValue()."</p>";
00329 $r.="<p>Type du document $str_type".$doc_type->IOValue()."</p>";
00330 $r.="<p> Tiers : ".$this->qcode." ".$name.'</p>';
00331 $r.="<p> Titre : ".$title->IOValue();
00332 $r.="<p>Description :".$desc->IOValue()."</p>";
00333
00334
00335 if ( sizeof($doc_gen->value) != 0)
00336 $r.="<p> Générer un document ".$gen->IOValue()." ".$doc_gen->IOValue()."</p>";
00337
00338
00339 $r.='<input type="hidden" name="sa" value="save_action_st2">';
00340 $r.='<input type="hidden" name="p_action" value="suivi_courrier">';
00341 $r.='<input type="hidden" name="tiers" value="'.$this->qcode.'">';
00342
00343
00344
00345 if ( $f_id != -1 )
00346 $r.=$desc->Submit("Save","Sauve");
00347 $r.=$desc->Submit("corr","Corrige");
00348
00349 $r.=$h_url."</form>";
00350 return $r;
00351 }
00359 function SaveStage2()
00360 {
00361
00362 $seq_name="seq_doc_type_".$this->dt_id;
00363 $str_file="";
00364 $add_file='';
00365
00366 $tiers=new fiche($this->db);
00367 $tiers->GetByQCode($this->qcode);
00368 if ( trim($this->ag_title) == "") {
00369 $doc_mod=new document_type($this->db);
00370 $doc_mod->dt_id=$this->dt_id;
00371 $doc_mod->get();
00372 $this->ag_title=$doc_mod->dt_value;
00373 }
00374 echo_debug('class_action',__LINE__," tiers->id ".$tiers->id);
00375 $this->ag_id=NextSequence($this->db,'action_gestion_ag_id_seq');
00376
00377 $ref=$this->dt_id.'/'.$this->ag_id;
00378 $this->ag_ref=$ref;
00381
00382 $this->ag_comment=str_replace("%OA","",$this->ag_comment);
00383 $this->ag_comment=str_replace("%OD","",$this->ag_comment);
00384
00385 $sql=sprintf("insert into action_gestion(ag_id,ag_timestamp,ag_type,ag_title,f_id,ag_comment,ag_ref) ".
00386 " values (%d,to_date('%s','DD-MM-YYYY'),'%d','%s',%d,'%s','%s')",
00387 $this->ag_id,
00388 $this->ag_timestamp,
00389 $this->dt_id,
00390 FormatString($this->ag_title),
00391 $tiers->id,
00392 $this->ag_comment,
00393 $ref
00394 );
00395 ExecSql($this->db,$sql);
00396
00397
00398
00399
00400 if ( $this->gen == 'on' )
00401 {
00402 $doc=new Document($this->db);
00403 $doc->f_id=$tiers->id;
00404 $doc->md_id=$this->md_id;
00405 $doc->ag_id=$this->ag_id;
00406 $doc->d_state=$this->d_state;
00407 $str_file=$doc->Generate();
00408 $d='<input type="hidden" name="d_id" value="'.$doc->d_id.'">';
00409 }
00410
00411 $r=$this->Display(false);
00412 $r.="<hr>";
00413 $r.='<form enctype="multipart/form-data" method="post">';
00414
00415 $r.='<input type="hidden" name="sa" value="save_action_st3">';
00416 $r.='<input type="hidden" name="p_action" value="suivi_courrier">';
00417 $r.='<input type="hidden" name="ag_id" value="'.$this->ag_id.'">';
00418
00419 $r.='<input type="hidden" name="ag_id" value="'.$this->d_id.'">';
00420
00421
00422 if ( $this->gen == 'on' )
00423 {
00424 $r.='<input type="hidden" name="d_id" value="'.$doc->d_id.'">';
00425 $r.="Sauver le document généré :";
00426 $r.=$str_file;
00427 $checkbox=new widget("checkbox");
00428 $checkbox->name="save_generate";
00429 $r.=$checkbox->IOValue();
00430 $r.="<hr>";
00431 }
00432 $upload=new widget("file");
00433 $upload->name="file_upload";
00434 $upload->value="";
00435 $r.="Enregistrer le fichier ".$upload->IOValue();
00436 $r.=$upload->Submit("save","Sauve le fichier");
00437 $r.="</form>";
00438 return $r;
00439 }
00445 function SaveStage3($d_id)
00446 {
00447
00448 if ( $d_id == 0 ) return;
00449
00450 if ( isset($_POST['save_generate']))
00451 {
00452 return;
00453 }
00454
00455
00456 $doc=new Document($this->db);
00457 $doc->d_id=$d_id;
00458 $doc->Upload($this->ag_id);
00459 }
00468 function myList($p_filter="",$p_search="")
00469 {
00470 $sql="
00471 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
00472 from action_gestion
00473 left outer join document using (ag_id)
00474 left outer join document_modele on (ag_type=md_type)
00475 join document_type on (ag_type=dt_id)
00476 where dt_id in ($p_filter) $p_search order by ag_timestamp desc,ag_ref desc";
00477 $max_line=CountSql($this->db,$sql);
00478 $step=$_SESSION['g_pagesize'];
00479 $page=(isset($_GET['offset']))?$_GET['page']:1;
00480 $offset=(isset($_GET['offset']))?$_GET['offset']:0;
00481 $limit=" LIMIT $step OFFSET $offset ";
00482 $bar=jrn_navigation_bar($offset,$max_line,$step,$page);
00483
00484 $Res=ExecSql($this->db,$sql.$limit);
00485 $a_row=pg_fetch_all($Res);
00486 $r='<div class="u_redcontent">';
00487 $r.=$bar;
00488 $r.="<table>";
00489 $r.="<tr>";
00490 $r.="<th>Date</th>";
00491 $r.="<th>Société</th>";
00492 $r.="<th>Titre</th>";
00493 $r.="<th>type</th>";
00494 $r.="<th>Référence</th>";
00495 $r.="<th>Document</th>";
00496 $r.="</tr>";
00497
00498
00499 if ( sizeof ($a_row) == 0 or $a_row == false )
00500 {
00501 $r='<div class="u_redcontent">';
00502 $r.='<hr>Aucun enregistrement trouvé';
00503 $r.="</div>";
00504 return $r;
00505
00506 }
00507 echo JS_SEARCH_CARD;
00508 foreach ($a_row as $row )
00509 {
00510 $r.="<tr>";
00511 $r.="<td>".$row['my_date']."</td>";
00512 $f=new fiche($this->db);
00513 $f->id=$row['f_id'];
00514 $q=$f->strAttribut(ATTR_DEF_QUICKCODE);
00515 $js=sprintf("javascript:showfiche('%s','%s')",
00516 $_REQUEST['PHPSESSID'],$q);
00517 $r.="<td>".'<A HREF="'.$js.'">'.$q." : ".$f->getName().'</A></td>';
00518 $r.='<td><A HREF="commercial.php?p_action=suivi_courrier&sa=detail&ag_id='.$row['ag_id'].'">'.
00519 $row['ag_title']."</A></td>";
00520 $r.="<td>".$row['dt_value']."</td>";
00521 $r.="<td>".$row['ag_ref']."</td>";
00522
00523 $doc=new Document($this->db,$row['d_id']);
00524 $r.="<td>".$doc->a_ref()."</td>";
00525 $r.="</tr>";
00526
00527 }
00528 $r.="</table>";
00529 $r.=$bar;
00530 $r.="</div>";
00531 return $r;
00532 }
00533
00538 function Update()
00539 {
00540
00541 if ( $this->ag_id == 0 ) return ;
00542
00543
00544
00545
00546 if ( trim($this->qcode) =="" && $this->dt_id==1)
00547 {
00548
00549 $f_id=0;
00550 }
00551 elseif ( trim($this->qcode) !="" && $this->dt_id!=1 )
00552 {
00553 $tiers=new fiche($this->db);
00554 $tiers->GetByQCode($this->qcode);
00555 $f_id=$tiers->id;
00556
00557 }
00558 else {
00559 return false;
00560 }
00561
00562
00563 $this->ag_comment=str_replace("\n","",$this->ag_comment);
00564 $this->ag_comment=str_replace("\r","",$this->ag_comment);
00565
00566
00567 $this->ag_comment=urlencode($this->ag_comment);
00568
00569
00570 $this->ag_comment=str_replace("%A0","",$this->ag_comment);
00571 $this->ag_comment=str_replace("%0D","",$this->ag_comment);
00572
00573
00574 $sql=sprintf("update action_gestion set ag_comment='%s',".
00575 "ag_timestamp=to_date('%s','DD.MM.YYYY'),".
00576 "ag_title='%s',".
00577 "ag_type=%d".
00578 " where ag_id = %d",
00579 $this->ag_comment,
00580 $this->ag_timestamp,
00581 FormatString($this->ag_title),
00582 $this->dt_id,
00583 $f_id);
00584 ExecSql($this->db,$sql);
00585
00586 if ( sizeof($_FILES) !=0 )
00587 {
00588
00589 $doc=new Document($this->db);
00590 if ( isset ($_POST['d_id'] ) )
00591 {
00592 $doc->d_id=$this->d_id;
00593 } else {
00594
00595 $doc->ag_id=$this->ag_id;
00596 $doc->md_type=$this->dt_id;
00597 $doc->blank();
00598 }
00599 $doc->Upload($this->ag_id);
00600
00601 }
00602
00603 return true;
00604 }
00605
00606
00607 }