From 4e363895e6a1b048ef401923c869f36353510333 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Tue, 6 Oct 2020 19:02:57 +0200 Subject: [PATCH] Contact option , allow to use option for contact --- html/js/card.js | 120 ++++++++++++++++-- include/ajax/ajax_action_remove_concerned.php | 9 +- include/ajax/ajax_action_save_concerned.php | 29 ++++- include/ajax/ajax_add_concerned_card.php | 56 ++++++-- include/ajax/ajax_card.php | 21 ++- include/ajax/ajax_display_card_option.php | 44 +++++++ include/class/card_multiple.class.php | 102 +++++++++++++++ include/class/follow_up.class.php | 12 +- include/template/card_multiple_result.php | 46 +++++++ sql/upgrade.sql | 42 ++++-- 10 files changed, 435 insertions(+), 46 deletions(-) create mode 100644 include/ajax/ajax_display_card_option.php create mode 100644 include/class/card_multiple.class.php create mode 100644 include/template/card_multiple_result.php diff --git a/html/js/card.js b/html/js/card.js index 6212658a0..1eeedfda6 100644 --- a/html/js/card.js +++ b/html/js/card.js @@ -33,7 +33,7 @@ function boxsearch_card(p_dossier) { waiting_box(); removeDiv('boxsearch_card_div'); - var queryString="gDossier="+p_dossier+"&op=cardsearch"+"&card="+encodeURI($(card_search).value); + var queryString="gDossier="+p_dossier+"&op=cardsearch"+"&card="+encodeURI($("card_search").value); var action = new Ajax.Request( "ajax_misc.php" , { @@ -57,14 +57,15 @@ function boxsearch_card(p_dossier) /** * show the ipopup with the form to search a card * the properties - * - jrn for the ledger - * - fs for the action - * - price for the price of the card (field to update) - * - tvaid for the tvaid of the card (field to update) - * - inp input text to update with the quickcode - * - label field to update with the name - * - ctl the id to fill with the HTML answer (ending with _content) - * - acc 1 if accounting are visible + * @param obj + * @param {int} obj.jrn for the ledger + * @param {int} obj.fs route to the action + * @param {string} obj.price for the price of the card (field to update) + * @param {string} obj.tvaid for the tvaid of the card (field to update) + * @param {string} obj.inp input text to update with the quickcode + * @param {string} obj.label field to update with the name + * @param {string} obj.ctl the id to fill with the HTML answer (ending with _content) + * @param {int} obj.acc 1 if accounting are visible */ function search_card(obj) { @@ -122,10 +123,54 @@ function search_card(obj) } } /** - * Display form for select card to add to action : other_concerned - *action_add_concerned_card + * Display found card and let you select several to link them to an action-followup + * @param {obj} obj form object + * @param {obj} obj form object */ -function action_add_concerned_card(obj) +function action_concerned_save_card(obj) +{ + try { + waiting_box(); + // get all data from FORM + var query = obj.serialize(); + new Ajax.Request("ajax_misc.php", { + method: "POST", + parameters: query, + onSuccess: function (req) { + remove_waiting_box(); + var answer = req.responseXML; + var a = answer.getElementsByTagName('ctl'); + if (a.length == 0) + { + var rec = req.responseText; + alert_box('erreur :' + rec); + } + var html = answer.getElementsByTagName('code'); + var namectl = a[0].firstChild.nodeValue; + var nodeXml = html[0]; + var code_html = getNodeText(nodeXml); + code_html = unescape_xml(code_html); + $(namectl).update(code_html); + removeDiv('search_card'); + } + }); + } catch (e) + { + + alert_box('action_concerned_save_card' + e.message); + return false; + } + return false; +} +/** + * Display form for searching cards to add to action-follow-up + *@see ajax_add_concerned_card.php + *@param {object} obj form object + *@param obj.elements.ag_id id of the action (elements) + *@param obj.elements.gDossier folder id + *@param obj.elements.query + */ +function action_concerned_search_card(obj) { try { @@ -204,7 +249,7 @@ function action_add_concerned_card(obj) { sx = document.body.scrollTop + 60; } - var div_style = "top:" + sx + "px;height:80%"; + var div_style = "top:" + sx + "px;height:52rem"; if ( ! $('search_card')) { add_div({id: 'search_card', cssclass: 'inner_box', html: "", style: div_style, drag: true}); } $('search_card').innerHTML = code_html; $('query').focus(); @@ -951,7 +996,7 @@ try { * @param {type} p_action_id action_gestion.ag_id * @returns {undefined} nothing */ -function action_save_concerned(p_dossier, p_fiche_id, p_action_id) { +function action_save_concerned(p_form_id) { var query = encodeJSON({'gDossier': p_dossier, 'f_id': p_fiche_id, 'ag_id': p_action_id,'op':'card','op2':'action_save_concerned','ctl':'unused'}); var a=new Ajax.Request('ajax_misc.php', { @@ -1220,4 +1265,51 @@ function card_update_row(obj) alert_box(e.message); return false; } +} +/** + * Display the option of a contact linked in a action-followup + * @param {int} p_action_person_id action_person.ap_id + * @param {int} p_dossier current folder + */ +function linked_card_option(p_action_person_id,p_dossier) { + try { + waiting_box(); + new Ajax.Request("ajax_misc.php",{ + method:"get", + parameters: { + ap_id:p_action_person_id, + gDossier:p_dossier, + op:"card", + op2:"display_card_option", + ctl:"notused" + }, + onSuccess:function(req) { + remove_waiting_box(); + add_div({ "id":"d_linked_card_option",cssclass:"inner_box",style:"position:fixed;top:30%;min-width:20rem;width:auto;",drag:0}); + $("d_linked_card_option").update(req.responseText); + + } + }); + } catch (e) { + console.error(e.message); + } +} +/** + * Save option for the contact + * @param {object} obj form + * @see card_multiple_display_option.php + * @returns {undefined} + */ +function save_linked_card_option(obj) +{ + waiting_box(); + new Ajax.Request("ajax_misc.php",{ + method:"post", + parameters:obj.serialize(), + onSuccess:function(req) { + remove_waiting_box(); + removeDiv("d_linked_card_option"); + } + }); + return false; } \ No newline at end of file diff --git a/include/ajax/ajax_action_remove_concerned.php b/include/ajax/ajax_action_remove_concerned.php index 31112dff6..00d389490 100644 --- a/include/ajax/ajax_action_remove_concerned.php +++ b/include/ajax/ajax_action_remove_concerned.php @@ -37,6 +37,13 @@ catch (Exception $exc) error_log($exc->getTraceAsString()); return; } +/* + * security Who can do it ? + */ +if ( ! $g_user->can_read_action($ag_id) ) { + record_log(__FILE__."security : access refused"); + return; +} require_once 'class/follow_up.class.php'; $follow=new Follow_Up($cn,$ag_id); @@ -44,7 +51,7 @@ $follow=new Follow_Up($cn,$ag_id); ob_start(); $follow->remove_linked_card($f_id); echo $follow->display_linked(); -HtmlInput::button_action_add_concerned_card( $follow->ag_id); +echo HtmlInput::button_action_add_concerned_card( $follow->ag_id); $response = ob_get_clean(); diff --git a/include/ajax/ajax_action_save_concerned.php b/include/ajax/ajax_action_save_concerned.php index e799b09f1..25baf3008 100644 --- a/include/ajax/ajax_action_save_concerned.php +++ b/include/ajax/ajax_action_save_concerned.php @@ -28,9 +28,34 @@ if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis'); /** * Insert into follow-up the card (f_id) for the action_gestion (ag_id) */ +$http=new HttpInput(); +try { + // follow_up id + $ag_id=$http->request("ag_id","number"); + $ctl=$http->request("ctl"); + $selected_card=$http->request("selected_card","array",[]); +} catch (Exception $ex) { + record_log(__FILE__.$ex->getMessage().$ex->getTraceAsString()); + return; +} +/* + * security Who can do it ? + */ +if ( ! $g_user->can_write_action($ag_id) ) { + record_log(__FILE__."security : access refused"); + return; +} + require_once 'class/follow_up.class.php'; $follow=new Follow_Up($cn,$ag_id); -$follow->insert_linked_card($f_id); +$nb_card=count($selected_card); +for ($i=0;$i< $nb_card;$i++) +{ + $elt=$selected_card[$i]; + if (isNumber($elt)) { + $follow->insert_linked_card($elt); + } +} /** * Display all the linked card */ @@ -44,7 +69,7 @@ header('Content-type: text/xml; charset=UTF-8'); echo << -unused +$ctl $html EOF; diff --git a/include/ajax/ajax_add_concerned_card.php b/include/ajax/ajax_add_concerned_card.php index 4322b13a5..90f3281b4 100644 --- a/include/ajax/ajax_add_concerned_card.php +++ b/include/ajax/ajax_add_concerned_card.php @@ -29,6 +29,7 @@ if (!defined('ALLOWED')) die('Appel direct ne sont pas permis'); require_once NOALYSS_INCLUDE.'/lib/http_input.class.php'; +require_once NOALYSS_INCLUDE.'/class/card_multiple.class.php'; $http=new HttpInput(); ob_start(); @@ -42,49 +43,86 @@ catch (Exception $exc) error_log($exc->getTraceAsString()); return; } +/* + * security Who can do it ? + */ +if ( ! $g_user->can_write_action($ag_id) ) { + record_log(__FILE__."security : access refused"); + return; +} require_once NOALYSS_INCLUDE.'/class/acc_ledger.class.php'; $r=HtmlInput::title_box(_("Détail fiche"), 'search_card'); - -$r.='
'; +//-------------------------------------------------------------------------------------------------------------------- +// Form search +//-------------------------------------------------------------------------------------------------------------------- +$r.=''; $q=new IText('query'); $q->value=(isset($query))?$query:''; $r.=''; $r.=_('Fiche contenant').Icon_Action::infobulle(19); $r.=$q->input(); +// where to search +$select=new ISelect("search_in"); +$select->value=$cn->make_array("select ad_id, ad_text from attr_def order by 2 ",1); +$select->selected=$http->get("search_in","string",""); +$r.=_("limité aux champs ").$select->input(); $r.=HtmlInput::submit('fs', _('Recherche'), "", "smallbutton"); $r.=''; -$r.=dossier::hidden().HtmlInput::hidden('op', 'add_concerned_card'); +$r.=dossier::hidden().HtmlInput::hidden('op2', 'add_concerned_card'); $r.=HtmlInput::request_to_hidden(array('ag_id')); $r.='
'; + + $query=$http->get("query", "string",""); $sql_array['query']=$query; $sql_array['typecard']='all'; -$fiche=new Fiche($cn); +$fiche=new Card_Multiple($cn); /* Build the SQL and show result */ $sql=$fiche->build_sql($sql_array); +$count_card=$fiche->count_sql($sql_array); +//-------------------------------------------------------------------------------------------------------------------- +// Result +//-------------------------------------------------------------------------------------------------------------------- /* We limit the search to MAX_SEARCH_CARD records */ -$sql=$sql.' order by vw_name limit '.MAX_SEARCH_CARD; $a=$cn->get_array($sql); +$r.='
'; +$r.=HtmlInput::request_to_hidden(array('ag_id')); +$r.=dossier::hidden().HtmlInput::hidden('op2', 'link_concerned_card').HtmlInput::hidden("op","card"); +// element to update with the answer +$r.=HtmlInput::hidden("ctl","concerned_card_td"); for ($i=0; $ivalue=$a[$i]['f_id']; + $array[$i]['checkbox']=$ic->input(); $array[$i]['quick_code']=$a[$i]['quick_code']; $array[$i]['name']=h($a[$i]['vw_name']); $array[$i]['accounting']=$a[$i]['accounting']; $array[$i]['first_name']=h($a[$i]['vw_first_name']); $array[$i]['description']=h($a[$i]['vw_description']); - $array[$i]['javascript']=sprintf("action_save_concerned(%d,'%s','%s')",$gDossier,$a[$i]['f_id'],$ag_id); }//foreach - -echo $r; // No accountancy history $accvis=0; -require_once(NOALYSS_TEMPLATE.'/card_result.php'); +echo $r; +require_once(NOALYSS_TEMPLATE.'/card_multiple_result.php'); +echo '
    '; +echo '
  • '; +echo HtmlInput::submit("add_concerned_card",_("Ajouter")); +echo '
  • '; +echo '
  • '; +echo HtmlInput::button_close("search_card"); +echo '
  • '; +echo '
'; +echo ''; + + $response=ob_get_contents(); ob_end_clean(); diff --git a/include/ajax/ajax_card.php b/include/ajax/ajax_card.php index 74a3d5b8f..e493da288 100644 --- a/include/ajax/ajax_card.php +++ b/include/ajax/ajax_card.php @@ -518,9 +518,11 @@ case 'fs': require_once NOALYSS_INCLUDE.'/ajax/ajax_add_concerned_card.php'; return; break; - case 'action_save_concerned': +// add several card to an action follow⁻up + case 'link_concerned_card': require NOALYSS_INCLUDE.'/ajax/ajax_action_save_concerned.php'; return; +// remove card from an action follow⁻up case 'action_remove_concerned': require NOALYSS_INCLUDE.'/ajax/ajax_action_remove_concerned.php'; return; @@ -744,6 +746,23 @@ case 'upr': } } break; + //--------------------------------------------------------------------------------------------------------------- + // Display option of a contact in an action-followup + //--------------------------------------------------------------------------------------------------------------- + case 'display_card_option': + + require_once NOALYSS_INCLUDE.'/ajax/ajax_display_card_option.php'; + return; + break; + + //--------------------------------------------------------------------------------------------------------------- + // Save option of a contact in an action-followup + //--------------------------------------------------------------------------------------------------------------- + case 'save_card_option': + require_once NOALYSS_INCLUDE.'/ajax/ajax_save_card_option.php'; + return; + + break; } // switch $xml=escape_xml($html); diff --git a/include/ajax/ajax_display_card_option.php b/include/ajax/ajax_display_card_option.php new file mode 100644 index 000000000..464c2b574 --- /dev/null +++ b/include/ajax/ajax_display_card_option.php @@ -0,0 +1,44 @@ + + +if (!defined('ALLOWED')) + die('Appel direct ne sont pas permis'); + +/** + * @file + * @brief display the options of a card + */ +require_once NOALYSS_INCLUDE."/class/card_multiple.class.php"; + +$card_multiple=new Card_Multiple(); +try +{ + $ap_id=$http->get("ap_id"); +} +catch (Exception $exc) +{ + echo $exc->getMessage(); + record_log($exc->getMessage().$exc->getTraceAsString()); +} + +echo HtmlInput::title_box(_("Options contact"), "d_linked_card_option","close","","y"); +// display existing option +$card_multiple->display_option($ap_id); diff --git a/include/class/card_multiple.class.php b/include/class/card_multiple.class.php new file mode 100644 index 000000000..2296d8046 --- /dev/null +++ b/include/class/card_multiple.class.php @@ -0,0 +1,102 @@ + + +/** + * @file + * @brief in follow-up , add multiple cards to an event, an action + */ +class Card_Multiple +{ + + function __construct() + { + + } + + function build_sql($sql_array) + { + $cn=Dossier::connect(); + $query=sql_string($sql_array['query']); + + $string_sql="select * + from vw_fiche_attr + where + vw_name ilike '%$query%' + or quick_code ilike '%$query%' + order by vw_name + limit + ".MAX_CARD_SEARCH; + return $string_sql; + } + + function count_sql($sql_array) + { + $cn=Dossier::connect(); + $query=sql_string($sql_array['query']); + + $string_sql="select count(*) + from vw_fiche_attr + where + vw_name ilike '%$query%' + or quick_code ilike '%$query%'"; + + + return $cn->get_value($string_sql); ; + } + /** + * + * @global type $g_user + * @param type $ap_id + * @return type + */ + function display_option($p_action_person_id) + { + global $g_user; + $cn=Dossier::connect(); + // retrieve card id (fiche.f_id) and the ag_id (action_gestion.ag_id) + $tmp=$cn->get_row("select f_id,ag_id from action_person where ap_id=$1 ", [$p_action_person_id]); + if ($tmp==NULL) + { + record_log("CMDO.01nothing found ".var_export($_REQUEST, true)); + return; + } + $fiche_id=$tmp['f_id']; + $ag_id=$tmp['ag_id']; + if ( ! $g_user->can_read_action($ag_id)) { + throw new Exception (_("CMCDO01"."Security")); + } + $sql="select + cor.cor_id, + cor.cor_label, + cor.cor_type, + coalesce (apo.ap_id,-1) as ap_id, + ap_value, + cor_value_select +from +contact_option_ref cor +left join action_person_option apo on (cor.cor_id=apo.contact_option_ref_id) +where action_person_id is null or action_person_id=$1"; + $a_option=$cn->get_array($sql,[$p_action_person_id]); + require NOALYSS_TEMPLATE."/card_multiple_display_option.php"; + + } + +} diff --git a/include/class/follow_up.class.php b/include/class/follow_up.class.php index 6734dd238..11b5f3ca6 100644 --- a/include/class/follow_up.class.php +++ b/include/class/follow_up.class.php @@ -1493,7 +1493,7 @@ class Follow_Up $c=count($a_tag); for ($e=0; $e<$c; $e++) { - echo ''; + echo ''; echo $a_tag[$e]['t_tag']; if ($g_user->can_write_action($this->ag_id)==true) { @@ -1670,14 +1670,16 @@ class Follow_Up $a_linked=$this->db->get_array('select ap_id,f_id from action_person where ag_id=$1', array($this->ag_id)); if (count($a_linked)==0) return ""; + $dossier_id=Dossier::id(); for ($i=0; $idb, $a_linked[$i]['f_id']); $qc=$fiche->get_quick_code(); - $js_remove=sprintf("onclick=\"action_remove_concerned('%s','%s','%s')\"", dossier::id(), $a_linked[$i]['f_id'], $this->ag_id); - echo ''; - echo $qc; - echo HtmlInput::anchor(SMALLX, "javascript:void(0)", $js_remove, ' class="smallbutton" style="padding:0px;display:inline" '); + $js_remove=sprintf("action_remove_concerned('%s','%s','%s')", dossier::id(), $a_linked[$i]['f_id'], $this->ag_id); + echo ''; + echo HtmlInput::anchor($qc,"", sprintf("onclick=\"linked_card_option('%s','%s')\"", + $a_linked[$i]['ap_id'],$dossier_id)); + echo Icon_Action::trash(uniqid(), $js_remove); echo ''; echo ' '; echo ' '; diff --git a/include/template/card_multiple_result.php b/include/template/card_multiple_result.php new file mode 100644 index 000000000..cef4de134 --- /dev/null +++ b/include/template/card_multiple_result.php @@ -0,0 +1,46 @@ + +
+ +
+ 10) : + echo _("recherche rapide"); + echo HtmlInput::filter_table("card_list", '1,2,3', 0); + endif; + ?> + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + + +
+
+
diff --git a/sql/upgrade.sql b/sql/upgrade.sql index 1b20b7743..e664d79dc 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -96,20 +96,7 @@ COMMENT ON COLUMN public.contact_option_ref.cor_value_json IS 'json object if co COMMENT ON COLUMN public.contact_option_ref.document_option_id IS 'FK to document_option'; -CREATE TABLE public.action_person_option ( - ap_id bigserial NOT NULL, - ap_value varchar NULL, -- Value of the option - contact_option_ref_id int8 NOT NULL, - action_person_id int8 NOT NULL, - CONSTRAINT action_person_option_pk PRIMARY KEY (ap_id), - CONSTRAINT action_person_option_fk FOREIGN KEY (action_person_id) REFERENCES action_person(ap_id) ON UPDATE CASCADE ON DELETE CASCADE, - CONSTRAINT contact_option_ref_fk FOREIGN KEY (contact_option_ref_id) REFERENCES contact_option_ref(cor_id) ON UPDATE CASCADE ON DELETE CASCADE -); -COMMENT ON TABLE public.action_person_option IS 'option for each contact'; --- Column comments - -COMMENT ON COLUMN public.action_person_option.ap_value IS 'Value of the option'; -- renomme le menu update menu_ref set me_description = 'Configuration des documents dans le suivi' ,me_file='cfg_action.inc.php' , @@ -175,4 +162,31 @@ ALTER TABLE public.jnt_tag_group_tag ADD CONSTRAINT jnt_tag_group_tag_fk FOREIGN ALTER TABLE public.jnt_tag_group_tag ADD CONSTRAINT jnt_tag_group_tag_fk_1 FOREIGN KEY (tag_group_id) REFERENCES tag_group(tg_id) ON UPDATE CASCADE ON DELETE CASCADE; -insert into action values (1025,'Ajout d''étiquette','followup','TAGADD'); \ No newline at end of file +insert into action values (1025,'Ajout d''étiquette','followup','TAGADD'); + +-- public.action_person_option definition + +-- Drop table + +-- DROP TABLE public.action_person_option; + +CREATE TABLE public.action_person_option ( + ap_id bigserial NOT NULL, + ap_value varchar NULL, -- Value of the option + contact_option_ref_id int8 NOT NULL, -- FK to contact_option + action_person_id int8 NOT NULL, -- FK to action_person + CONSTRAINT action_person_option_pk PRIMARY KEY (ap_id) +); +COMMENT ON TABLE public.action_person_option IS 'option for each contact'; + +-- Column comments + +COMMENT ON COLUMN public.action_person_option.ap_value IS 'Value of the option'; +COMMENT ON COLUMN public.action_person_option.contact_option_ref_id IS 'FK to contact_option'; +COMMENT ON COLUMN public.action_person_option.action_person_id IS 'FK to action_person'; + + +-- public.action_person_option foreign keys + +ALTER TABLE public.action_person_option ADD CONSTRAINT action_person_option_fk FOREIGN KEY (action_person_id) REFERENCES action_person(ap_id) ON UPDATE CASCADE ON DELETE CASCADE; +ALTER TABLE public.action_person_option ADD CONSTRAINT contact_option_ref_fk FOREIGN KEY (contact_option_ref_id) REFERENCES contact_option_ref(cor_id) ON UPDATE CASCADE ON DELETE CASCADE;