00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 require_once('class_itextarea.php');
00022 require_once("class_idate.php");
00023 require_once("class_iselect.php");
00024 require_once("class_ihidden.php");
00025 require_once("class_itext.php");
00026 require_once("class_ispan.php");
00027 require_once("class_icard.php");
00028 require_once("class_icheckbox.php");
00029 require_once("class_ifile.php");
00030 require_once("class_fiche.php");
00031 require_once("class_document.php");
00032 require_once("class_document_type.php");
00033 require_once("class_document_modele.php");
00034 require_once("user_common.php");
00035 require_once('class_follow_up_detail.php');
00036 require_once('class_inum.php');
00037 require_once 'class_sort_table.php';
00038 require_once 'class_irelated_action.php';
00039 require_once 'class_tag.php';
00040 require_once 'class_default_menu.php';
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 class Follow_Up
00065 {
00066
00067
00068 var $db;
00069 var $ag_timestamp;
00070 var $dt_id;
00071 var $ag_state;
00072 var $d_number;
00073 var $d_filename;
00074 var $d_mimetype;
00075 var $ag_title;
00076 var $f_id;
00077 var $ag_ref;
00078 var $ag_hour;
00079 var $ag_priority;
00080 var $ag_dest;
00081 var $ag_contact;
00082 var $ag_remind_date;
00083
00084
00085
00086 var $operation;
00087
00088
00089
00090 var $action;
00091
00092
00093
00094
00095
00096
00097 function __construct($p_cn,$p_id=0)
00098 {
00099 $this->db = $p_cn;
00100 $this->ag_id=$p_id;
00101 $this->f_id = 0;
00102 $this->aAction_detail=array();
00103 $this->operation="";
00104 $this->action="";
00105
00106 }
00107 static function sql_security_filter($cn,$p_mode)
00108 {
00109 global $g_user;
00110 $profile=$cn->get_value("select p_id from profile_user where user_name=$1",array($g_user->login));
00111 if ($profile == '') die ("Security");
00112 if ($p_mode == 'R')
00113 {
00114 $sql=" (ag_dest in (select p_granted from user_sec_action_profile where p_id=$profile ) ) ";
00115 }
00116 if ($p_mode == 'W')
00117 {
00118 $sql=" ( ag_dest in (select p_granted from user_sec_action_profile where p_id=$profile and ua_right='W' ) )";
00119 }
00120 return $sql;
00121 }
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 function Display($p_view, $p_gen, $p_base, $retour = "")
00141 {
00142 global $g_user;
00143 if ($p_view == 'UPD')
00144 {
00145 $upd = true;
00146 $readonly = false;
00147 }
00148 elseif ($p_view == "NEW")
00149 {
00150 $upd = false;
00151 $readonly = false;
00152 $this->ag_ref=_("Nouveau");
00153 }
00154 elseif ($p_view == 'READ')
00155 {
00156 $upd = true;
00157 $readonly = true;
00158 }
00159 else
00160 {
00161 exit('class_action' . __LINE__ . 'Follow_Up::Display error unknown parameter' . $p_view);
00162 }
00163
00164
00165 $date = new IDate();
00166 $date->readOnly = $readonly;
00167 $date->name = "ag_timestamp";
00168 $date->value = $this->ag_timestamp;
00169
00170 $remind_date = new IDate();
00171 $remind_date->readOnly = $readonly;
00172 $remind_date->name = "ag_remind_date";
00173 $remind_date->value = $this->ag_remind_date;
00174
00175
00176
00177 $doc_type = new ISelect();
00178 $doc_type->name = "dt_id";
00179 $doc_type->value = $this->db->make_array("select dt_id,dt_value from document_type order by dt_value");
00180 $doc_type->selected = $this->dt_id;
00181 $doc_type->readOnly = $readonly;
00182 $str_doc_type = $doc_type->input();
00183
00184
00185 $desc = new ITextArea();
00186 $desc->style=' class="itextarea" style="width:80%;margin-left:0px"';
00187 $desc->name = "ag_comment";
00188 $desc->readOnly = $readonly;
00189 $acomment = $this->db->get_array("SELECT agc_id, ag_id, to_char(agc_date,'DD.MM.YYYY HH24:MI') as str_agc_date, agc_comment, tech_user
00190 FROM action_gestion_comment where ag_id=$1 order by agc_id;", array($this->ag_id)
00191 );
00192
00193
00194 $operation = $this->db->get_array("select ago_id,j.jr_id,j.jr_internal,j.jr_comment,to_char(j.jr_date,'DD.MM.YY') as str_date
00195 from jrn as j join action_gestion_operation as ago on (j.jr_id=ago.jr_id)
00196 where ag_id=$1 order by jr_date", array($this->ag_id));
00197 $iconcerned = new IConcerned('operation');
00198
00199
00200 $action = $this->db->get_array("
00201 select ag_id,ag_ref,substr(ag_title,1,40) as sub_title,to_char(ag_timestamp,'DD.MM.YY') as str_date ,
00202 ag_timestamp,dt_value
00203 from action_gestion
00204 join document_type on (ag_type=dt_id)
00205 where
00206 ag_id in (select aga_greatest from action_gestion_related where aga_least =$1)
00207 or
00208 ag_id in (select aga_least from action_gestion_related where aga_greatest =$1)
00209 order by ag_timestamp", array($this->ag_id));
00210 $iaction = new IRelated_Action('action');
00211 $iaction->value = (isset($this->action)) ? $this->action : "";
00212
00213
00214
00215 $a = $this->db->make_array("select s_id,s_value from document_state ");
00216 $state = new ISelect();
00217 $state->readOnly = $readonly;
00218 $state->name = "ag_state";
00219 $state->value = $a;
00220 $state->selected = $this->ag_state;
00221 $str_state = $state->input();
00222
00223
00224 $doc_ref = "";
00225
00226
00227 $h2 = new IHidden();
00228 $h2->name = "d_id";
00229 $h2->value = $this->d_id;
00230
00231 if ($this->d_id != 0 && $this->d_id != "")
00232 {
00233 $h2->readonly = ($p_view == 'NEW') ? false : true;
00234 $doc = new Document($this->db, $this->d_id);
00235 $doc->get();
00236 if (strlen(trim($doc->d_lob)) != 0)
00237 {
00238 $d_id = new IHidden();
00239 $doc_ref = "<p> Document " . $doc->anchor() . '</p>';
00240 $doc_ref.=$h2->input() . $d_id->input('d_id', $this->d_id);
00241 }
00242 }
00243
00244
00245
00246 $title = new IText();
00247 $title->readOnly = $readonly;
00248 $title->name = "ag_title";
00249 $title->value = $this->ag_title;
00250 $title->size = 60;
00251
00252
00253
00254 $ag_priority = new ISelect();
00255 $ag_priority->readOnly = $readonly;
00256 $ag_priority->name = "ag_priority";
00257 $ag_priority->selected = $this->ag_priority;
00258 $ag_priority->value = array(array('value' => 1, 'label' => 'Haute'),
00259 array('value' => 2, 'label' => 'Moyenne'),
00260 array('value' => 3, 'label' => 'Basse')
00261 );
00262 $str_ag_priority = $ag_priority->input();
00263
00264
00265 $ag_hour = new IText();
00266 $ag_hour->readOnly = $readonly;
00267 $ag_hour->name = "ag_hour";
00268 $ag_hour->value = $this->ag_hour;
00269 $ag_hour->size = 6;
00270 $ag_hour->javascript = " onblur=check_hour('ag_hour');";
00271 $str_ag_hour = $ag_hour->input();
00272
00273
00274 $ag_dest = new ISelect();
00275 $ag_dest->readOnly = $readonly;
00276 $ag_dest->name = "ag_dest";
00277
00278 $aAg_dest = $this->db->make_array("select p_id as value, " .
00279 "p_name as label " .
00280 " from profile where p_id in (select p_granted from user_sec_action_profile where ua_right='W' and p_id=".$g_user->get_profile().") order by 2");
00281
00282 $ag_dest->value = $aAg_dest;
00283 $ag_dest->selected = $this->ag_dest;
00284 $str_ag_dest = $ag_dest->input();
00285
00286
00287
00288
00289 $client_label = new ISpan();
00290
00291
00292 $f_add_button = new IButton('add_card');
00293 $f_add_button->label = _('Créer une nouvelle fiche');
00294 $f_add_button->set_attribute('ipopup', 'ipop_newcard');
00295 $filter = $this->db->make_list('select fd_id from fiche_def ');
00296 $f_add_button->set_attribute('filter', $filter);
00297
00298 $f_add_button->javascript = " select_card_type(this);";
00299 $str_add_button = $f_add_button->input();
00300
00301
00302 if ($this->qcode_dest != NOTFOUND && strlen(trim($this->qcode_dest)) != 0)
00303 {
00304 $tiers = new Fiche($this->db);
00305 $tiers->get_by_qcode($this->qcode_dest);
00306 $qcode_dest_label = $tiers->strAttribut(1);
00307 $this->f_id_dest = $tiers->id;
00308 }
00309 else
00310 {
00311 $qcode_dest_label = ($this->f_id_dest == 0 || trim($this->qcode_dest) == "") ? 'Interne ' : 'Error';
00312 }
00313
00314 $h_ag_id = new IHidden();
00315
00316
00317
00318 $w = new ICard();
00319 $w->readOnly = $readonly;
00320 $w->jrn = 0;
00321 $w->name = 'qcode_dest';
00322 $w->value = ($this->f_id_dest != 0) ? $this->qcode_dest : "";
00323 $w->label = "";
00324 $list_recipient = $this->db->make_list('select fd_id from fiche_def where frd_id in (14,25,8,9,16)');
00325 $w->extra = $list_recipient;
00326 $w->set_attribute('typecard', $list_recipient);
00327 $w->set_dblclick("fill_ipopcard(this);");
00328 $w->set_attribute('ipopup', 'ipopcard');
00329
00330
00331 $w->set_attribute('label', 'qcode_dest_label');
00332
00333 $w->set_attribute('typecard', $w->extra);
00334 $w->set_function('fill_data');
00335 $w->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" ', $w->name);
00336
00337 $sp = new ISpan();
00338 $sp->name = 'qcode_dest_label';
00339 $sp->value = $qcode_dest_label;
00340
00341
00342 $ag_contact = new ICard();
00343 $ag_contact->readOnly = $readonly;
00344 $ag_contact->jrn = 0;
00345 $ag_contact->name = 'ag_contact';
00346 $ag_contact->value = '';
00347 $ag_contact->set_attribute('ipopup', 'ipopcard');
00348
00349 if ($this->ag_contact != 0)
00350 {
00351 $contact = new Fiche($this->db, $this->ag_contact);
00352 $ag_contact->value = $contact->get_quick_code();
00353 }
00354
00355 $ag_contact->label = "";
00356
00357 $list_contact = $this->db->make_list('select fd_id from fiche_def where frd_id=16');
00358 $ag_contact->extra = $list_contact;
00359
00360 $ag_contact->set_dblclick("fill_ipopcard(this);");
00361
00362 $ag_contact->set_attribute('label', 'ag_contact_label');
00363
00364 $ag_contact->set_attribute('typecard', $list_contact);
00365 $ag_contact->set_function('fill_data');
00366 $ag_contact->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" ', $ag_contact->name);
00367
00368 $spcontact = new ISpan();
00369 $spcontact->name = 'ag_contact_label';
00370 $spcontact->value = '';
00371 $fiche_contact = new Fiche($this->db);
00372 $fiche_contact->get_by_qcode($this->ag_contact);
00373 if ($fiche_contact->id != 0)
00374 {
00375 $spcontact->value = $fiche_contact->strAttribut(ATTR_DEF_NAME);
00376 }
00377
00378
00379 $h_agrefid = new IHidden();
00380 $iag_ref=new IText("ag_ref");
00381 $iag_ref->value=$this->ag_ref;
00382 $iag_ref->readOnly = ($p_view == "NEW" ||$p_view == 'READ')?true:false;
00383 $str_ag_ref =$iag_ref->input();
00384
00385 $r = "";
00386
00387
00388 $upload = new IFile();
00389 $upload->name = "file_upload[]";
00390 $upload->readOnly=$readonly;
00391 $upload->value = "";
00392 $aAttachedFile = $this->db->get_array('select d_id,d_filename,d_description,d_mimetype,' .
00393 '\'show_document.php?' .
00394 Dossier::get() . '&d_id=\'||d_id as link' .
00395 ' from document where ag_id=$1', array($this->ag_id));
00396
00397 $aDocMod = new ISelect();
00398 $aDocMod->name = 'doc_mod';
00399 $aDocMod->value = $this->db->make_array('select md_id,dt_value||\' : \'||md_name as md_name' .
00400 ' from document_modele join document_type on (md_type=dt_id)' .
00401 ' order by md_name');
00402 $str_select_doc = $aDocMod->input();
00403
00404 if (empty($aDocMod->value) )
00405 $str_submit_generate = "";
00406 else
00407 $str_submit_generate = HtmlInput::submit("generate", _("Génére le document"));
00408
00409 $ag_id = $this->ag_id;
00410
00411
00412 $icard = new ICard();
00413 $icard->jrn = 0;
00414 $icard->table = 0;
00415 $icard->extra2 = 'QuickCode';
00416 $icard->noadd = "no";
00417 $icard->extra = 'all';
00418
00419
00420 $text = new IText();
00421 $num = new INum();
00422
00423
00424 $itva = new ITva_Popup($this->db);
00425 $itva->in_table = true;
00426 $aCard=array();
00427
00428 $article_count=(count($this->aAction_detail)==0)?MAX_ARTICLE:count($this->aAction_detail);
00429
00430 for ($i = 0; $i < $article_count; $i++)
00431 {
00432
00433 $icard = new ICard();
00434 $icard->jrn = 0;
00435 $icard->table = 0;
00436 $icard->noadd = "no";
00437 $icard->extra = 'all';
00438 $icard->name = "e_march" . $i;
00439 $tmp_ad = (isset($this->aAction_detail[$i])) ? $this->aAction_detail[$i] : false;
00440 $icard->readOnly=$readonly;
00441 $icard->value = '';
00442 $aCard[$i]=0;
00443 if ($tmp_ad)
00444 {
00445 $march = new Fiche($this->db);
00446 $f = $tmp_ad->get_parameter('qcode');
00447 if ($f != 0)
00448 {
00449 $march->id = $f;
00450 $icard->value = $march->get_quick_code();
00451 $aCard[$i]=$f;
00452 }
00453 }
00454 $icard->set_dblclick("fill_ipopcard(this);");
00455
00456 $icard->set_attribute('label', "e_march" . $i . "_label");
00457
00458 $icard->set_attribute('typecard', $icard->extra);
00459 $icard->set_attribute('ipopup', 'ipopcard');
00460 $icard->set_function('fill_data');
00461 $icard->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" ', $icard->name);
00462
00463 $aArticle[$i]['fid'] = $icard->search() . $icard->input();
00464
00465 $text->javascript = ' onchange="clean_tva(' . $i . ');compute_ledger(' . $i . ')"';
00466 $text->css_size="100%";
00467 $text->name = "e_march" . $i . "_label";
00468 $text->id = "e_march" . $i . "_label";
00469 $text->size = 40;
00470 $text->value = ($tmp_ad) ? $tmp_ad->get_parameter('text') : "";
00471 $text->readOnly=$readonly;
00472 $aArticle[$i]['desc'] = $text->input();
00473
00474 $num->javascript = ' onchange="format_number(this);clean_tva(' . $i . ');compute_ledger(' . $i . ')"';
00475 $num->name = "e_march" . $i . "_price";
00476 $num->id = "e_march" . $i . "_price";
00477 $num->size = 8;
00478 $num->readOnly=$readonly;
00479 $num->value = ($tmp_ad) ? $tmp_ad->get_parameter('price_unit') : 0;
00480 $aArticle[$i]['pu'] = $num->input();
00481
00482 $num->name = "e_quant" . $i;
00483 $num->id = "e_quant" . $i;
00484 $num->size = 8;
00485 $num->value = ($tmp_ad) ? $tmp_ad->get_parameter('quantity') : 0;
00486 $aArticle[$i]['quant'] = $num->input();
00487
00488 $itva->name = 'e_march' . $i . '_tva_id';
00489 $itva->id = 'e_march' . $i . '_tva_id';
00490 $itva->value = ($tmp_ad) ? $tmp_ad->get_parameter('tva_id') : 0;
00491 $itva->readOnly=$readonly;
00492 $itva->js = ' onchange="format_number(this);clean_tva(' . $i . ');compute_ledger(' . $i . ')"';
00493 $itva->set_attribute('compute', $i);
00494
00495 $aArticle[$i]['tvaid'] = $itva->input();
00496
00497 $num->name = "e_march" . $i . "_tva_amount";
00498 $num->id = "e_march" . $i . "_tva_amount";
00499 $num->value = ($tmp_ad) ? $tmp_ad->get_parameter('tva_amount') : 0;
00500 $num->javascript = " onchange=\"compute_ledger('" . $i ." ')\"";
00501 $num->size = 8;
00502 $aArticle[$i]['tva'] = $num->input();
00503
00504 $num->name = "tvac_march" . $i;
00505 $num->id = "tvac_march" . $i;
00506 $num->value = ($tmp_ad) ? $tmp_ad->get_parameter('total') : 0;
00507 $num->size = 8;
00508 $aArticle[$i]['tvac'] = $num->input();
00509
00510 $aArticle[$i]['hidden_htva'] = HtmlInput::hidden('htva_march' . $i, 0);
00511 $aArticle[$i]['hidden_tva'] = HtmlInput::hidden('tva_march' . $i, 0);
00512 $aArticle[$i]['ad_id'] = ($tmp_ad) ? HtmlInput::hidden('ad_id' . $i, $tmp_ad->get_parameter('id')) : HtmlInput::hidden('ad_id' . $i, 0);
00513 }
00514
00515
00516 $r.=dossier::hidden();
00517
00518
00519 $Hid = new IHidden();
00520 $r.=$Hid->input("nb_item", $article_count);
00521 $r.=HtmlInput::request_to_hidden(array("closed_action","remind_date_end","remind_date","sag_ref","only_internal","state","qcode", "ag_dest_query", "action_query", "tdoc", "date_start", "date_end", "hsstate","searchtag"));
00522 $a_tag=$this->tag_get();
00523 $menu=new Default_Menu();
00524
00525 ob_start();
00526 require 'template/detail-action.php';
00527 $content = ob_get_contents();
00528 ob_end_clean();
00529 $r.=$content;
00530
00531
00532 $r.="<p>";
00533 $r.=$h2->input();
00534 $r.=$h_ag_id->input('ag_id', $this->ag_id);
00535 $hidden2 = new IHidden();
00536 $r.=$hidden2->input('f_id_dest', $this->f_id_dest);
00537 $r.="</p>";
00538
00539 return $r;
00540 }
00541
00542
00543
00544
00545 function get()
00546 {
00547 $sql = "select ag_id,to_char (ag_timestamp,'DD.MM.YYYY') as ag_timestamp," .
00548 " f_id_dest,ag_title,ag_ref,d_id,ag_type,ag_state, ag_owner, " .
00549 " ag_dest, ag_hour, ag_priority, ag_contact,to_char (ag_remind_date,'DD.MM.YYYY') as ag_remind_date " .
00550 " from action_gestion left join document using (ag_id) where ag_id=" . $this->ag_id;
00551 $r = $this->db->exec_sql($sql);
00552 $row = Database::fetch_all($r);
00553 if ($row == false){
00554 $this->ag_id=0;
00555 return;
00556 }
00557 $this->ag_timestamp = $row[0]['ag_timestamp'];
00558 $this->ag_contact = $row[0]['ag_contact'];
00559 $this->f_id_dest = $row[0]['f_id_dest'];
00560 $this->ag_title = $row[0]['ag_title'];
00561 $this->ag_type = $row[0]['ag_type'];
00562 $this->ag_ref = $row[0]['ag_ref'];
00563 $this->ag_state = $row[0]['ag_state'];
00564 $this->d_id = $row[0]['d_id'];
00565 $this->ag_dest = $row[0]['ag_dest'];
00566 $this->ag_hour = $row[0]['ag_hour'];
00567 $this->ag_priority = $row[0]['ag_priority'];
00568 $this->ag_remind_date = $row[0]['ag_remind_date'];
00569 $this->ag_owner= $row[0]['ag_owner'];
00570
00571 $action_detail = new Follow_Up_Detail($this->db);
00572 $action_detail->set_parameter('ag_id', $this->ag_id);
00573 $this->aAction_detail = $action_detail->load_all();
00574
00575
00576
00577 if ($this->d_id == "")
00578 $this->d_id = 0;
00579
00580 if ($this->d_id != 0)
00581 {
00582 $this->state = $row['0']['ag_state'];
00583 $this->ag_state = $row[0]['ag_state'];
00584 }
00585 $this->dt_id = $this->ag_type;
00586 $aexp = new Fiche($this->db, $this->f_id_dest);
00587 $this->qcode_dest = $aexp->strAttribut(ATTR_DEF_QUICKCODE);
00588 }
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601 function save()
00602 {
00603
00604
00605 $seq_name = "seq_doc_type_" . $this->dt_id;
00606 $str_file = "";
00607 $add_file = '';
00608
00609
00610 $exp = new Fiche($this->db);
00611 $exp->get_by_qcode($this->qcode_dest);
00612
00613 $contact = new Fiche($this->db);
00614 $contact->get_by_qcode($this->ag_contact);
00615
00616 if (trim($this->ag_title) == "")
00617 {
00618 $doc_mod = new document_type($this->db);
00619 $doc_mod->dt_id = $this->dt_id;
00620 $doc_mod->get();
00621 $this->ag_title = $doc_mod->dt_value;
00622 }
00623 $this->ag_id = $this->db->get_next_seq('action_gestion_ag_id_seq');
00624
00625
00626 $ag_ref=$this->db->get_value('select dt_prefix from document_type where dt_id=$1',array($this->dt_id)).'-'.$this->db->get_next_seq($seq_name);
00627 $this->ag_ref = $ag_ref;
00628
00629
00630 if ($this->ag_remind_date != null || $this->ag_remind_date != '')
00631 {
00632 $sql = "insert into action_gestion" .
00633 "(ag_id,ag_timestamp,ag_type,ag_title,f_id_dest,ag_ref, ag_dest, " .
00634 " ag_hour, ag_priority,ag_owner,ag_contact,ag_state,ag_remind_date) " .
00635 " values ($1,to_date($2,'DD.MM.YYYY'),$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,to_date($13,'DD.MM.YYYY'))";
00636 }
00637 else
00638 {
00639 $this->ag_remind_date = null;
00640 $sql = "insert into action_gestion" .
00641 "(ag_id,ag_timestamp,ag_type,ag_title,f_id_dest,ag_ref, ag_dest, " .
00642 " ag_hour, ag_priority,ag_owner,ag_contact,ag_state,ag_remind_date) " .
00643 " values ($1,to_date($2,'DD.MM.YYYY'),$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13)";
00644 }
00645 $this->db->exec_sql($sql, array($this->ag_id,
00646 $this->ag_timestamp,
00647 $this->dt_id,
00648 $this->ag_title,
00649 $exp->id,
00650 $ag_ref,
00651 $this->ag_dest,
00652 $this->ag_hour,
00653 $this->ag_priority,
00654 $_SESSION['g_user'],
00655 $contact->id,
00656 $this->ag_state,
00657 $this->ag_remind_date
00658 )
00659 );
00660
00661
00662 for ($i = 0; $i < $_POST['nb_item']; $i++)
00663 {
00664 $act = new Follow_Up_Detail($this->db);
00665 $act->from_array($_POST, $i);
00666 if ($act->f_id == 0)
00667 continue;
00668 $act->ag_id = $this->ag_id;
00669 $act->save();
00670 }
00671
00672
00673 $doc = new Document($this->db);
00674 $doc->Upload($this->ag_id);
00675 if (trim($this->ag_comment) != '')
00676 {
00677 $this->db->exec_sql("insert into action_gestion_comment (ag_id,tech_user,agc_comment) values ($1,$2,$3)"
00678 , array($this->ag_id, $_SESSION['g_user'], $this->ag_comment));
00679 }
00680 $this->insert_operation();
00681 $this->insert_action();
00682 }
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693 function myList($p_base, $p_filter = "", $p_search = "")
00694 {
00695
00696 $url = HtmlInput::get_to_string(array("closed_action","remind_date_end","remind_date","sag_ref","only_internal","state","qcode", "ag_dest_query", "action_query", "tdoc", "date_start", "date_end", "hsstate","searchtag")) . '&' . $p_base;
00697
00698 $table = new Sort_Table();
00699 $table->add('Date Doc.', $url, 'order by ag_timestamp asc', 'order by ag_timestamp desc', 'da', 'dd');
00700 $table->add('Date Comm.', $url, 'order by last_comment', 'order by last_comment desc', 'dca', 'dcd');
00701 $table->add('Date Limite', $url, 'order by ag_remind_date asc', 'order by ag_remind_date desc', 'ra', 'rd');
00702 $table->add('Tag', $url, 'order by tags asc', 'order by tags desc', 'taa', 'tad');
00703 $table->add('Réf.', $url, 'order by ag_ref asc', 'order by ag_ref desc', 'ra', 'rd');
00704 $table->add('Groupe', $url, "order by coalesce((select p_name from profile where p_id=ag_dest),'Aucun groupe')", "order by coalesce((select p_name from profile where p_id=ag_dest),'Aucun groupe') desc", 'dea', 'ded');
00705 $table->add('Dest/Exp', $url, 'order by name asc', 'order by name desc', 'ea', 'ed');
00706 $table->add('Titre', $url, 'order by ag_title asc', 'order by ag_title desc', 'ta', 'td');
00707
00708 $ord = (!isset($_GET['ord'])) ? "dcd" : $_GET['ord'];
00709 $sort = $table->get_sql_order($ord);
00710
00711 if (strlen(trim($p_filter)) != 0)
00712 $p_filter_doc = " dt_id in ( $p_filter )";
00713 else
00714 $p_filter_doc = " 1=1 ";
00715
00716 $sql = "
00717 select ag_id,to_char(ag_timestamp,'DD.MM.YYYY') as my_date,
00718 to_char(ag_remind_date,'DD.MM.YYYY') as my_remind,
00719 to_char(coalesce((select max(agc_date) from action_gestion_comment as agc where agc.ag_id=ag.ag_id),ag_timestamp),'DD.MM.YY') as str_last_comment,
00720 coalesce((select max(agc_date) from action_gestion_comment as agc where agc.ag_id=ag.ag_id),ag_timestamp) as last_comment,
00721 f_id_dest,
00722 s_value,
00723 ag_title,dt_value,ag_ref, ag_priority,ag_state,
00724 coalesce((select p_name from profile where p_id=ag_dest),'Aucun groupe') as dest,
00725 (select ad_value from fiche_Detail where f_id=ag.f_id_dest and ad_id=1) as name,
00726 array_to_string((select array_agg(t1.t_tag) from action_tags as a1 join tags as t1 on (a1.t_id=t1.t_id) where a1.ag_id=ag.ag_id ),',') as tags
00727 from action_gestion as ag
00728 join document_type on (ag_type=dt_id)
00729 join document_state on (ag_state=s_id)
00730 where $p_filter_doc $p_search $sort";
00731 $max_line = $this->db->count_sql($sql);
00732 $step = $_SESSION['g_pagesize'];
00733 $page = (isset($_GET['offset'])) ? $_GET['page'] : 1;
00734 $offset = (isset($_GET['offset'])) ? Database::escape_string($_GET['offset']) : 0;
00735 if ($step != -1)
00736 $limit = " LIMIT $step OFFSET $offset ";
00737 else
00738 $limit = '';
00739 $bar = navigation_bar($offset, $max_line, $step, $page);
00740
00741 $Res = $this->db->exec_sql($sql . $limit);
00742 $a_row = Database::fetch_all($Res);
00743
00744 $r = "";
00745 $r.='<p>'.$bar.'</p>';
00746 $r.='<table class="document">';
00747 $r.="<tr>";
00748 $r.='<th name="ag_id_td" style="display:none" >'. ICheckBox::toggle_checkbox('ag','list_ag_frm').'</th>';
00749 $r.='<th>' . $table->get_header(0) . '</th>';
00750 $r.='<th>' . $table->get_header(1) . '</th>';
00751 $r.='<th>' . $table->get_header(2) . '</th>';
00752 $r.='<th>' . $table->get_header(3) . '</th>';
00753 $r.='<th>' . $table->get_header(4) . '</th>';
00754 $r.='<th>' . $table->get_header(5) . '</th>';
00755 $r.='<th>' . $table->get_header(6) . '</th>';
00756 $r.='<th>' . $table->get_header(7) . '</th>';
00757 $r.=th('Priorité');
00758 $r.="</tr>";
00759
00760
00761
00762 if (sizeof($a_row) == 0 or $a_row == false)
00763 {
00764 $r = '<div style="clear:both">';
00765 $r.='<hr>Aucun enregistrement trouvé';
00766 $r.="</div>";
00767 return $r;
00768 }
00769 $today = date('d.m.Y');
00770 $i = 0;
00771 $checkbox=new ICheckBox("mag_id[]");
00772
00773 foreach ($a_row as $row)
00774 {
00775 $href = '<A class="document" HREF="do.php?' . $p_base .HtmlInput::get_to_string(array("closed_action","remind_date_end","remind_date","sag_ref","only_internal","state","gDossier", "qcode", "ag_dest_query", "action_query", "tdoc", "date_start", "date_end", "hsstate", "searchtag","ac"),"&") . '&sa=detail&ag_id=' . $row['ag_id'] . '">';
00776 $i++;
00777 $tr = ($i % 2 == 0) ? 'even' : 'odd';
00778 if ($row['ag_priority'] < 2)
00779 $tr = 'priority1';
00780 $st = '';
00781 if ($row['my_date'] == $today)
00782 $st = ' style="font-weight:bold; border:2px solid orange;"';
00783 $date_remind = format_date($row['my_remind'], 'DD.MM.YYYY', 'YYYYMMDD');
00784 $date_today = date('Ymd');
00785 if ($date_remind != "" && $date_remind == $date_today && $row['ag_state']!=1 && $row['ag_state']!=3)
00786 $st = ' style="font-weight:bold;background:orange"';
00787 if ($date_remind != "" && $date_remind < $date_today && $row['ag_state']!=1 && $row['ag_state']!=3)
00788 $st = ' style="font-weight:bold;background:#FF0000;color:white;"';
00789 $r.="<tr class=\"$tr\" $st>";
00790 $checkbox->value=$row['ag_id'];
00791 $r.='<td name="ag_id_td" style="display:none">'.$checkbox->input().'</td>';
00792 $r.="<td>" . $href . smaller_date($row['my_date']) . '</a>' . "</td>";
00793 $r.="<td>" . $href . $row['str_last_comment'] . '</a>' . "</td>";
00794 $r.="<td>" . $href . smaller_date($row['my_remind']) . '</a>' . "</td>";
00795 $r.="<td>" . $href . h($row['tags']). '</a>' . "</td>";
00796 $r.="<td>" . $href . $row['ag_ref'] . '</a>' . "</td>";
00797 $r.="<td>" . $href . h($row['dest']) . '</a>' . "</td>";
00798
00799
00800 $fexp = new Fiche($this->db);
00801 $fexp->id = $row['f_id_dest'];
00802 $qcode_dest = $fexp->strAttribut(ATTR_DEF_QUICKCODE);
00803
00804 $qexp = ($qcode_dest == NOTFOUND) ? "Interne" : $qcode_dest;
00805 $jsexp = sprintf("javascript:showfiche('%s')", $qexp);
00806 if ($qexp != 'Interne')
00807 {
00808 $r.="<td>$href" . $qexp . " : " . $fexp->getName() . '</a></td>';
00809 }
00810 else
00811 $r.="<td>$href Interne </a></td>";
00812
00813 $ref = "";
00814
00815
00816 $r.='<td>' . $href .
00817 h($row['ag_title']) . "</A></td>";
00818
00819
00820
00821
00822 switch ($row['ag_priority'])
00823 {
00824 case 1:
00825 $priority = 'Haute';
00826 break;
00827 case 2:
00828 $priority = "Moyenne";
00829 break;
00830 case 3:
00831 $priority = "Important";
00832 break;
00833 }
00834 $r.=td($priority);
00835
00836 $r.="<td>" . $ref . "</td>";
00837 $r.="</tr>";
00838 }
00839
00840 $r.="</table>";
00841
00842 $r.='<p>'.$bar.'</p>';
00843 return $r;
00844 }
00845
00846
00847
00848
00849
00850
00851 function Update()
00852 {
00853
00854
00855 if ($this->ag_id == 0)
00856 return;
00857
00858
00859
00860 if (trim($this->qcode_dest) == "")
00861 {
00862
00863 $this->f_id_dest = 0;
00864 }
00865 else
00866 {
00867 $tiers = new Fiche($this->db);
00868 if ($tiers->get_by_qcode($this->qcode_dest) == -1)
00869 return false;
00870 else
00871 $this->f_id_dest = $tiers->id;
00872 }
00873 $contact = new Fiche($this->db);
00874 if ($contact->get_by_qcode($this->ag_contact) == -1)
00875 $contact->id = 0;
00876
00877
00878 $old=new Follow_Up($this->db);
00879 $old->ag_id=$this->ag_id;
00880 $old->get();
00881
00882
00883 if ($old->ag_ref != $this->ag_ref)
00884 {
00885 $nAg_ref=$this->db->get_value("select count(*) from action_gestion where ag_ref=$1",array($this->ag_ref));
00886 if ($nAg_ref != 0 )
00887 {
00888 echo h2("Référence en double, référence non sauvée",'class="error"');
00889 $this->ag_ref=$old->ag_ref;
00890 }
00891 }
00892
00893
00894 if ($this->ag_remind_date != null)
00895 {
00896 $this->db->exec_sql("update action_gestion set " .
00897 " ag_timestamp=to_date($1,'DD.MM.YYYY')," .
00898 " ag_title=$2," .
00899 " ag_type=$3, " .
00900 " f_id_dest=$4, " .
00901 "ag_state=$5," .
00902 " ag_hour = $7 ," .
00903 " ag_priority = $8 ," .
00904 " ag_dest = $9 , " .
00905 " ag_contact = $10, " .
00906 " ag_ref = $11, " .
00907 " ag_remind_date=to_date($12,'DD.MM.YYYY') " .
00908 " where ag_id = $6", array(
00909 $this->ag_timestamp,
00910 $this->ag_title,
00911 $this->dt_id,
00912 $this->f_id_dest,
00913 $this->ag_state,
00914 $this->ag_id,
00915 $this->ag_hour,
00916 $this->ag_priority,
00917 $this->ag_dest,
00918 $contact->id,
00919 $this->ag_ref,
00920 $this->ag_remind_date
00921 ));
00922 }
00923 else
00924 {
00925 $this->db->exec_sql("update action_gestion set " .
00926 " ag_timestamp=to_date($1,'DD.MM.YYYY')," .
00927 " ag_title=$2," .
00928 " ag_type=$3, " .
00929 " f_id_dest=$4, " .
00930 "ag_state=$5," .
00931 " ag_hour = $7 ," .
00932 " ag_priority = $8 ," .
00933 " ag_dest = $9 , " .
00934 " ag_contact = $10, " .
00935 " ag_ref = $11, " .
00936 " ag_remind_date=null " .
00937 " where ag_id = $6", array(
00938 $this->ag_timestamp,
00939 $this->ag_title,
00940 $this->dt_id,
00941 $this->f_id_dest,
00942 $this->ag_state,
00943 $this->ag_id,
00944 $this->ag_hour,
00945 $this->ag_priority,
00946 $this->ag_dest,
00947 $contact->id,
00948 $this->ag_ref
00949 ));
00950 }
00951
00952 $doc = new Document($this->db);
00953 $doc->Upload($this->ag_id);
00954
00955
00956 for ($i = 0; $i < $_POST['nb_item']; $i++)
00957 {
00958 $act = new Follow_Up_Detail($this->db);
00959 $act->from_array($_POST, $i);
00960 if ($act->f_id == 0 && $act->ad_id != 0)
00961 $act->delete();
00962 if ($act->f_id == 0)
00963 continue;
00964 $act->save();
00965 }
00966 if (trim($this->ag_comment) != '')
00967 {
00968 $this->db->exec_sql("insert into action_gestion_comment (ag_id,tech_user,agc_comment) values ($1,$2,$3)"
00969 , array($this->ag_id, $_SESSION['g_user'], $this->ag_comment));
00970 }
00971 $this->insert_operation();
00972 $this->insert_action();
00973 return true;
00974 }
00975
00976
00977
00978
00979
00980
00981 function generate_document($md_id, $p_array)
00982 {
00983 $doc = new Document($this->db);
00984 $mod = new Document_Modele($this->db, $md_id);
00985 $mod->load();
00986 $doc->f_id = $this->f_id_dest;
00987 $doc->md_id = $md_id;
00988 $doc->ag_id = $this->ag_id;
00989 $doc->Generate($p_array);
00990 }
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012 function fromArray($p_array)
01013 {
01014 global $g_user;
01015 $this->ag_id = (isset($p_array['ag_id'])) ? $p_array['ag_id'] : "";
01016 $this->ag_ref = (isset($p_array['ag_ref'])) ? $p_array['ag_ref'] : "";
01017 $this->qcode_dest = (isset($p_array['qcode_dest'])) ? $p_array['qcode_dest'] : "";
01018 $this->f_id_dest = (isset($p_array['f_id_dest'])) ? $p_array['f_id_dest'] : 0;
01019 $this->ag_timestamp = (isset($p_array['ag_timestamp'])) ? $p_array['ag_timestamp'] : date('d.m.Y');
01020 $this->qcode_dest = (isset($p_array['qcode_dest'])) ? $p_array['qcode_dest'] : "";
01021 $this->dt_id = (isset($p_array['dt_id'])) ? $p_array['dt_id'] : "";
01022 $this->ag_state = (isset($p_array['ag_state'])) ? $p_array['ag_state'] : 2;
01023 $this->ag_ref = (isset($p_array['ag_ref'])) ? $p_array['ag_ref'] : "";
01024 $this->ag_title = (isset($p_array['ag_title'])) ? $p_array['ag_title'] : "";
01025 $this->ag_hour = (isset($p_array['ag_hour'])) ? $p_array['ag_hour'] : "";
01026 $this->ag_dest = (isset($p_array['ag_dest'])) ? $p_array['ag_dest'] : $g_user->get_profile();
01027 $this->ag_priority = (isset($p_array['ag_priority'])) ? $p_array['ag_priority'] : 2;
01028 $this->ag_contact = (isset($p_array['ag_contact'])) ? $p_array['ag_contact'] : "";
01029 $this->ag_comment = (isset($p_array['ag_comment'])) ? $p_array['ag_comment'] : "";
01030 $this->ag_remind_date = (isset($p_array['ag_remind_date'])) ? $p_array['ag_remind_date'] : null;
01031 $this->operation = (isset($p_array['operation'])) ? $p_array['operation'] : null;
01032
01033
01034
01035
01036
01037 $this->action = (isset($p_array['action'])) ? $p_array['action'] : null;
01038 }
01039
01040
01041
01042
01043
01044 function remove()
01045 {
01046 $this->get();
01047
01048 $sql = "delete from action_gestion where ag_id=$1";
01049 $this->db->exec_sql($sql, array($this->ag_id));
01050
01051
01052 $doc = new Document($this->db);
01053 $aDoc = $doc->get_all($this->ag_id);
01054 if (!empty($aDoc))
01055 {
01056
01057 for ($i = 0; $i < sizeof($aDoc); $i++)
01058 {
01059 $aDoc[$i]->remove();
01060 }
01061 }
01062 }
01063
01064
01065
01066
01067
01068
01069 function get_last($p_limit)
01070 {
01071 $sql = "select coalesce(vw_name,'Interne') as vw_name,ag_id,ag_title,ag_ref, dt_value,to_char(ag_timestamp,'DD.MM.YYYY') as ag_timestamp_fmt,ag_timestamp " .
01072 " from action_gestion join document_type " .
01073 " on (ag_type=dt_id) left join vw_fiche_attr on (f_id=f_id_dest) where ag_state in (2,3) order by ag_timestamp desc limit $p_limit";
01074 $array = $this->db->get_array($sql);
01075 return $array;
01076 }
01077
01078
01079
01080
01081 function get_today()
01082 {
01083 $sql = "select ag_ref,coalesce(vw_name,'Interne') as vw_name,ag_id,ag_title,ag_ref, dt_value,to_char(ag_remind_date,'DD.MM.YYYY') as ag_timestamp_fmt,ag_timestamp " .
01084 " from action_gestion join document_type " .
01085 " on (ag_type=dt_id) left join vw_fiche_attr on (f_id=f_id_dest) where ag_state not in (1,4)
01086 and to_char(ag_remind_date,'DDMMYYYY')=to_char(now(),'DDMMYYYY') ";
01087 $array = $this->db->get_array($sql);
01088 return $array;
01089 }
01090
01091
01092
01093
01094 function get_late()
01095 {
01096 $sql = "select ag_ref,coalesce(vw_name,'Interne') as vw_name,ag_id,ag_title,ag_ref, dt_value,to_char(ag_remind_date,'DD.MM.YYYY') as ag_timestamp_fmt,ag_timestamp " .
01097 " from action_gestion join document_type " .
01098 " on (ag_type=dt_id) left join vw_fiche_attr on (f_id=f_id_dest) where ag_state not in (1,4)
01099 and ag_remind_date < now() ";
01100 $array = $this->db->get_array($sql);
01101 return $array;
01102 }
01103
01104
01105
01106 function insert_operation()
01107 {
01108 if (trim($this->operation) == '')
01109 return;
01110 $array = explode(",", $this->operation);
01111 for ($i = 0; $i < count($array); $i++)
01112 {
01113 if ($this->db->get_value("select count(*) from action_gestion_operation
01114 where ag_id=$1 and jr_id=$2", array($this->ag_id, $array[$i])) == 0)
01115 {
01116 $this->db->exec_sql("insert into action_gestion_operation (ag_id,jr_id) values ($1,$2)", array($this->ag_id, $array[$i]));
01117 }
01118 }
01119 }
01120
01121
01122
01123
01124
01125
01126 function remove_operation_deprecated()
01127 {
01128 if ($this->op == null)
01129 return;
01130 $op = $this->op;
01131 for ($i = 0; $i < count($op); $i++)
01132 {
01133 $this->db->exec_sql("delete from action_gestion_operation where ago_id=$1", array($op[$i]));
01134 }
01135 }
01136
01137
01138
01139
01140
01141 static function display_search($cn, $inner = false)
01142 {
01143 $a = (isset($_GET['action_query'])) ? $_GET['action_query'] : "";
01144 $qcode = (isset($_GET['qcode'])) ? $_GET['qcode'] : "";
01145
01146 $supl_hidden = '';
01147 if (isset($_REQUEST['sc']))
01148 $supl_hidden.=HtmlInput::hidden('sc', $_REQUEST['sc']);
01149 if (isset($_REQUEST['f_id']))
01150 {
01151 $supl_hidden.=HtmlInput::hidden('f_id', $_REQUEST['f_id']);
01152 $f = new Fiche($cn, $_REQUEST['f_id']);
01153 $supl_hidden.=HtmlInput::hidden('qcode_dest', $f->get_quick_code());
01154 }
01155 if (isset($_REQUEST['sb']))
01156 $supl_hidden.=HtmlInput::hidden('sb', $_REQUEST['sb']);
01157 $supl_hidden.=HtmlInput::hidden('ac', $_REQUEST['ac']);
01158
01159
01160
01161
01162 if (!$inner)
01163 require_once 'template/action_button.php';
01164
01165 $w = new ICard();
01166 $w->name = 'qcode';
01167 $w->id = $w->generate_id($w->name);
01168 $w->value = $qcode;
01169 $w->extra = "all";
01170 $w->typecard = 'all';
01171 $w->jrn = 0;
01172 $w->table = 0;
01173 $list = $cn->make_list("select fd_id from fiche_def where frd_id in (4,8,9,14,15,16,25)");
01174 $w->extra = $list;
01175
01176
01177
01178 $type_doc = new ISelect('tdoc');
01179 $aTDoc = $cn->make_array('select dt_id,dt_value from document_type order by dt_value');
01180 $aTDoc[] = array('value' => '-1', 'label' => _('Tous les types'));
01181 $type_doc->value = $aTDoc;
01182 $type_doc->selected = (isset($_GET['tdoc'])) ? $_GET['tdoc'] : -1;
01183
01184
01185 $type_state= new ISelect('state');
01186 $aState = $cn->make_array('select s_id,s_value from document_state order by s_value');
01187 $aState[] = array('value' => '-1', 'label' => _('Tous les Etats'));
01188 $type_state->value = $aState;
01189 $type_state->selected = (isset($_GET['state'])) ? $_GET['state'] : -1;
01190
01191
01192
01193
01194 $hsExcptype_state= new ISelect('hsstate');
01195 $aExcpState = $cn->make_array('select s_id,s_value from document_state order by s_value');
01196 $aExcpState[] = array('value' => '-1', 'label' => _('Aucun'));
01197 $hsExcptype_state->value = $aExcpState;
01198 $hsExcptype_state->selected = (isset($_GET['hsstate'])) ? $_GET['hsstate'] : -1;
01199
01200
01201
01202 $start = new IDate('date_start');
01203 $start->value = (isset($_GET['date_start'])) ? $_GET['date_start'] : "";
01204 $end = new IDate('date_end');
01205 $end->value = (isset($_GET['date_end'])) ? $_GET['date_end'] : "";
01206
01207
01208 $closed_action=new ICheckBox('closed_action');
01209 $closed_action->selected=(isset($_GET['closed_action']))?true:false;
01210
01211
01212 $only_internal= new ICheckBox('only_internal');
01213 $only_internal->selected = (isset($_GET['only_internal'])) ? true : false;
01214
01215 $aAg_dest = $cn->make_array("select p_id as value, " .
01216 "p_name as label " .
01217 " from profile order by 2");
01218 $aAg_dest[] = array('value' => '-2', 'label' => _('Tous les profiles'));
01219 $ag_dest = new ISelect();
01220 $ag_dest->name = "ag_dest_query";
01221 $ag_dest->value = $aAg_dest;
01222 $ag_dest->selected = (isset($_GET["ag_dest_query"])) ? $_GET["ag_dest_query"] : -2;
01223 $str_ag_dest = $ag_dest->input();
01224 $osag_ref=new IText("sag_ref");
01225 $osag_ref->value=(isset($_GET['sag_ref']))?$_GET['sag_ref']:"";
01226 $remind_date=new IDate('remind_date');
01227 $remind_date->value=(isset($_GET['remind_date']))?$_GET['remind_date']:"";
01228 $remind_date_end=new IDate('remind_date_end');
01229 $remind_date_end->value=(isset($_GET['remind_date_end']))?$_GET['remind_date_end']:"";
01230 $otag=new Tag($cn);
01231
01232
01233 require_once 'template/action_search.php';
01234 }
01235
01236
01237
01238
01239
01240 static function show_action_list($cn, $p_base)
01241 {
01242
01243 Follow_Up::display_search($cn);
01244
01245 $act = new Follow_Up($cn);
01246
01247
01248
01249 $query = Follow_Up::create_query($cn);
01250
01251 echo '<form method="POST" id="list_ag_frm" style="display:inline">';
01252 echo HtmlInput::request_to_hidden(array("gDossier","ac","sb","sc","f_id"));
01253 require_once 'template/action_other_action.php';
01254 echo $act->myList($p_base, "", $query);
01255 echo '</form>';
01256 }
01257
01258
01259
01260
01261
01262
01263 static function filter_by_tag ($cn, $p_array = null)
01264 {
01265 if ($p_array == null)
01266 $p_array = $_GET;
01267
01268 extract($p_array);
01269 $query = "";
01270 if ( count($searchtag) == 0 )return "";
01271 for ($i=0;$i<count($searchtag);$i++) {
01272 if (isNumber($searchtag[$i])==1)
01273 $query .= ' and ag_id in (select ag_id from action_tags where t_id= '. sql_string($searchtag[$i]).')';
01274 }
01275 return $query;
01276 }
01277
01278
01279
01280
01281
01282
01283 static function create_query($cn, $p_array = null)
01284 {
01285 if ($p_array == null)
01286 $p_array = $_GET;
01287
01288 extract($p_array);
01289 $action_query = "";
01290
01291
01292 if (isset($_REQUEST['action_query']))
01293 {
01294
01295 $action_query = "and (ag_title ~* '" . sql_string($_REQUEST['action_query']) . "' " .
01296 "or ag_ref ='" . trim(sql_string($_REQUEST['action_query'])) .
01297 "' or ag_id in (select ag_id from action_gestion_comment where agc_comment ~* '" . trim(sql_string($_REQUEST['action_query'])) . "')" .
01298 ")";
01299 }
01300
01301 $str = "";
01302 if (isset($qcode))
01303 {
01304
01305 if (strlen(trim($qcode)) != 0)
01306 {
01307
01308 $fiche = new Fiche($cn);
01309 $fiche->get_by_qcode($_REQUEST['qcode']);
01310
01311 if ($fiche->id == 0)
01312 $str = ' and false ';
01313 else
01314 $str = " and (f_id_dest= " . $fiche->id . " ) ";
01315 }
01316 }
01317 if (isset($tdoc) && $tdoc != -1)
01318 {
01319 $action_query .= ' and dt_id = ' . sql_string($tdoc);
01320 }
01321 if (isset($state) && $state!= -1)
01322 {
01323 $action_query .= ' and ag_state= ' . sql_string($state);
01324 }
01325 if (isset($hsstate) && $hsstate!= -1)
01326 {
01327 $action_query .= ' and ag_state <> ' . sql_string($hsstate);
01328 }
01329 if (isset($sag_ref) && trim($sag_ref) != "")
01330 {
01331 $query .= ' and ag_ref= \'' . sql_string($sag_ref)."'";
01332 }
01333
01334 if (isset($_GET['only_internal']))
01335 $action_query .= ' and f_id_dest=0 ';
01336
01337 if (isset($date_start) && isDate($date_start) != null)
01338 {
01339 $action_query.=" and ag_timestamp >= to_date('$date_start','DD.MM.YYYY')";
01340 }
01341 if (isset($date_end) && isDate($date_end) != null)
01342 {
01343 $action_query.=" and ag_timestamp <= to_date('$date_end','DD.MM.YYYY')";
01344 }
01345 if (isset($ag_dest_query) && $ag_dest_query != -2 )
01346 {
01347 $action_query.= " and ((ag_dest = " . sql_string($ag_dest_query)." and ".self::sql_security_filter($cn, "R").") or ".
01348 "(ag_dest = " . sql_string($ag_dest_query)." and ".self::sql_security_filter($cn, "R")." and ".
01349 " ag_owner='" . $_SESSION['g_user'] . "'))";
01350 }
01351 else
01352 {
01353 $action_query .=" and (ag_owner='" . $_SESSION['g_user'] . "' or ".self::sql_security_filter($cn, "R")." or ag_dest=-1 )";
01354 }
01355
01356
01357 if (isNumber($ag_id) == 1 && $ag_id != 0)
01358 {
01359 $action_query = " and ag_id= " . sql_string($ag_id);
01360 }
01361 if ( isset($remind_date) && $remind_date != "" && isDate($remind_date)==$remind_date)
01362 {
01363 $action_query .= " and to_date('".sql_string($remind_date)."','DD.MM.YYYY')<= ag_remind_date";
01364 }
01365 if ( isset($remind_date_end) && $remind_date_end != "" && isDate($remind_date_end)==$remind_date_end)
01366 {
01367 $action_query .= " and to_date('".sql_string($remind_date_end)."','DD.MM.YYYY')>= ag_remind_date";
01368 }
01369 if ( ! isset ($closed_action)) {
01370 $action_query.=" and s_status is null ";
01371 }
01372 if ( isset ($searchtag)) {
01373 $action_query .= Follow_Up::filter_by_tag($cn,$p_array);
01374 }
01375 return $action_query . $str;
01376 }
01377
01378
01379
01380
01381
01382
01383 static function short_list($cn, $p_sql)
01384 {
01385 $sql = "
01386 select ag_id,to_char(ag_timestamp,'DD.MM.YY') as my_date,
01387 f_id_dest,
01388 substr(ag_title,1,40) as sub_ag_title,dt_value,ag_ref, ag_priority,ag_state,
01389 coalesce((select p_name from profile where p_id=ag_dest),'Aucun groupe') as dest,
01390 (select ad_value from fiche_Detail where f_id=action_gestion.f_id_dest and ad_id=1) as name
01391 from action_gestion
01392 join document_type on (ag_type=dt_id)
01393 join document_state on (s_id=ag_state)
01394 where $p_sql";
01395 $max_line = $cn->count_sql($sql);
01396
01397 $limit = ($max_line > 25) ? 25 : $max_line;
01398 $Res = $cn->exec_sql($sql . "limit " . $limit);
01399 $a_row = Database::fetch_all($Res);
01400 require_once 'template/action_search_result.php';
01401 }
01402
01403
01404
01405
01406 function insert_action()
01407 {
01408 if (trim($this->action) == '')
01409 return;
01410 $array = explode(",", $this->action);
01411 for ($i = 0; $i < count($array); $i++)
01412 {
01413 if ($this->db->get_value("select count(*) from action_gestion_related
01414 where (aga_least=$1 and aga_greatest=$2) or (aga_greatest=$1 and aga_least=$2)", array($array[$i], $this->ag_id)) == 0 && $this->ag_id != $array[$i])
01415 {
01416 $this->db->exec_sql("insert into action_gestion_related(aga_least,aga_greatest) values ($1,$2)", array($this->ag_id, $array[$i]));
01417 }
01418 }
01419 }
01420
01421
01422
01423
01424
01425 function export_csv($p_array)
01426 {
01427 extract($p_array);
01428
01429
01430 $p_search=self::create_query($this->db, $p_array);
01431 $sql = "
01432 select ag_id,
01433 to_char(ag_timestamp,'DD.MM.YYYY') as my_date,
01434 to_char(ag_remind_date,'DD.MM.YYYY') as my_remind,
01435 to_char(coalesce((select max(agc_date) from action_gestion_comment as agc where agc.ag_id=ag_id),ag_timestamp),'DD.MM.YY') as last_comment,
01436 array_to_string((select array_agg(t1.t_tag) from action_tags as a1 join tags as t1 on (a1.t_id=t1.t_id) where a1.ag_id=ag.ag_id ),',') as tags,
01437 (select ad_value from fiche_Detail where f_id=ag.f_id_dest and ad_id=1) as name,
01438 ag_title,
01439 dt_value,
01440 ag_ref,
01441 ag_priority,
01442 ag_state,
01443
01444 coalesce((select p_name from profile where p_id=ag_dest),'Aucun groupe') as dest
01445 from action_gestion as ag
01446 join document_type on (ag.ag_type=dt_id)
01447 join document_state on(ag.ag_state=s_id)
01448 where true $p_search order by ag.ag_timestamp,ag.ag_id";
01449 $ret=$this->db->exec_sql($sql);
01450
01451 if ( Database::num_row($ret)==0)exit();
01452 $this->db->query_to_csv($ret,array(
01453 array("title"=>"doc id","type"=>"string"),
01454 array("title"=>"date","type"=>"date"),
01455 array("title"=>"rappel","type"=>"date"),
01456 array("title"=>"date dernier commentaire","type"=>"date"),
01457 array("title"=>"tags","type"=>"string"),
01458 array("title"=>"nom","type"=>"string"),
01459 array("title"=>"titre","type"=>"string"),
01460 array("title"=>"type document","type"=>"string"),
01461 array("title"=>"ref","type"=>"string"),
01462 array("title"=>"priorite","type"=>"string"),
01463 array("title"=>"etat","type"=>"string"),
01464 array("title"=>"profil","type"=>"string")
01465 )
01466 );
01467 }
01468 static function get_all_operation($p_jr_id)
01469 {
01470 global $cn;
01471 $array=$cn->get_array("
01472 select ag_id,ag_ref,
01473 ag_title
01474 from action_gestion
01475 join action_gestion_operation using(ag_id)
01476 where
01477 jr_id=$1",array($p_jr_id));
01478 return $array;
01479 }
01480
01481
01482
01483
01484 function tag_get()
01485 {
01486 if ($this->ag_id==0)return;
01487 $sql='select b.ag_id,b.t_id,b.at_id,a.t_tag'
01488 . ' from '
01489 .' tags as a join action_tags as b on (a.t_id=b.t_id)'
01490 . ' where ag_id=$1 '
01491 .' order by a.t_tag';
01492 $array=$this->db->get_array($sql,array($this->ag_id));
01493 return $array;
01494 }
01495
01496
01497
01498
01499
01500 function tag_add($p_t_id)
01501 {
01502 if ($this->ag_id==0)return;
01503 $count=$this->db->get_value('select count(*) from action_tags'.
01504 ' where ag_id=$1 and t_id=$2',
01505 array($this->ag_id,$p_t_id));
01506 if ( $count > 0 ) return;
01507 $sql=' insert into action_tags (ag_id,t_id) values ($1,$2)';
01508 $this->db->exec_sql($sql,array($this->ag_id,$p_t_id));
01509
01510 }
01511
01512
01513
01514
01515 function tag_remove($p_t_id)
01516 {
01517 if ($this->ag_id==0)return;
01518 $sql=' delete from action_tags where ag_id=$1 and t_id=$2';
01519 $this->db->exec_sql($sql,array($this->ag_id,$p_t_id));
01520 }
01521
01522
01523
01524
01525 function tag_cell()
01526 {
01527 $a_tag=$this->tag_get();
01528 $c=count($a_tag);
01529 for ($e=0;$e<$c;$e++) {
01530 $js_remove=sprintf("onclick=\"action_tag_remove('%s','%s','%s')\"",dossier::id(),$this->ag_id,
01531 $a_tag[$e]['t_id']);
01532 echo '<span style="border:1px solid black;margin-right:5px;">';
01533 echo $a_tag[$e]['t_tag'];
01534 echo '</span>';
01535 echo '<span style="background-color:red;text-align:center;border-top:1px solid black; border-right:1px solid black;border-bottom:1px solid black;">';
01536 echo HtmlInput::anchor("X", "javascript:void(0)", $js_remove);
01537 echo '</span>';
01538 echo ' ';
01539 echo ' ';
01540 }
01541 $js=sprintf("onclick=\"action_tag_select('%s','%s')\"",dossier::id(),$this->ag_id);
01542 echo HtmlInput::button('tag_bt', 'Ajout tag',$js, 'smallbutton');
01543
01544 }
01545 static function action_tag_remove($cn,$p_array)
01546 {
01547 global $g_user;
01548 $mag_id=$p_array['mag_id'];
01549 $remtag=$p_array['remtag'];
01550 for ($i=0;$i< count($mag_id);$i++)
01551 {
01552 if ($g_user->can_write_action($mag_id[$i]) == false) continue;
01553 for ($e=0;$e<count($remtag);$e++)
01554 {
01555 $a=new Follow_Up($cn,$mag_id[$i]);
01556 $a->tag_remove($remtag[$e]);
01557 }
01558 }
01559
01560 }
01561 static function action_tag_add($cn,$p_array)
01562 {
01563 global $g_user;
01564 $mag_id=$p_array['mag_id'];
01565 $addtag=$p_array['addtag'];
01566 for ($i=0;$i< count($mag_id);$i++)
01567 {
01568 if ($g_user->can_write_action($mag_id[$i]) == false) continue;
01569 for ($e=0;$e<count($addtag);$e++)
01570 {
01571 $a=new Follow_Up($cn,$mag_id[$i]);
01572 $a->tag_add($addtag[$e]);
01573 }
01574 }
01575 }
01576 static function action_tag_clear($cn,$p_array)
01577 {
01578 global $g_user;
01579 $mag_id=$p_array['mag_id'];
01580 for ($i=0;$i< count($mag_id);$i++)
01581 {
01582 if ($g_user->can_write_action($mag_id[$i]) == false) continue;
01583 $a=new Follow_Up($cn,$mag_id[$i]);
01584 $a->tag_clear();
01585 }
01586 }
01587 static function action_print($cn,$p_array)
01588 {
01589 global $g_user;
01590 $mag_id=$p_array['mag_id'];
01591 for ($i=0;$i< count($mag_id);$i++)
01592 {
01593 if ($g_user->can_read_action($mag_id[$i]) == false) continue;
01594 $a=new Follow_Up($cn,$mag_id[$i]);
01595 $a->get();
01596 echo $a->Display("READ", false, "");
01597 echo '<P id="breakhere"> - - </p>';
01598 }
01599 }
01600 function tag_clear() {
01601 $this->db->exec_sql('delete from action_tags where ag_id=$1',array($this->ag_id));
01602 }
01603 static function action_set_state($cn,$p_array)
01604 {
01605
01606 global $g_user;
01607 $mag_id=$p_array['mag_id'];
01608 $state=$p_array['ag_state'];
01609 for ($i=0;$i< count($mag_id);$i++)
01610 {
01611 if ($g_user->can_write_action($mag_id[$i]) == false) continue;
01612 $cn->exec_sql('update action_gestion set ag_state=$1 where ag_id=$2',
01613 array($state,$mag_id[$i]));
01614 }
01615 }
01616 static function action_remove($cn,$p_array)
01617 {
01618 global $g_user;
01619
01620 $mag_id=$p_array['mag_id'];
01621 for ($i=0;$i< count($mag_id);$i++)
01622 {
01623 if ($g_user->can_write_action($mag_id[$i]) == false) continue;
01624 $cn->exec_sql('delete from action_gestion where ag_id=$1',
01625 array($mag_id[$i]));
01626 }
01627 }
01628 }