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