From b2af9acfe4b6f999a28cbb4e8c6df2abc84bba06 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Mon, 23 Sep 2013 16:25:46 +0000 Subject: [PATCH] Tag : gestion Tag dans document : ajout, enlever --- include/ajax_tag_add_action.php | 46 ++++++++++++++++++++++ include/ajax_tag_detail.php | 38 ++++++++++++++++++ include/ajax_tag_list.php | 42 ++++++++++++++++++++ include/ajax_tag_remove_action.php | 46 ++++++++++++++++++++++ include/cfgtags.inc.php | 27 +++++++++++++ include/class_follow_up.php | 62 ++++++++++++++++++++++++++++++ include/class_tag.php | 26 ++++++++++++- include/class_tag_sql.php | 2 +- include/template/detail-action.php | 9 +++++ include/template/tag_detail.php | 16 ++++++++ include/template/tag_list.php | 35 +++++++++++++++++ include/template/tag_select.php | 36 +++++++++++++++++ 12 files changed, 383 insertions(+), 2 deletions(-) create mode 100644 include/ajax_tag_add_action.php create mode 100644 include/ajax_tag_detail.php create mode 100644 include/ajax_tag_list.php create mode 100644 include/ajax_tag_remove_action.php create mode 100644 include/template/tag_detail.php create mode 100644 include/template/tag_list.php create mode 100644 include/template/tag_select.php diff --git a/include/ajax_tag_add_action.php b/include/ajax_tag_add_action.php new file mode 100644 index 000000000..1838394e8 --- /dev/null +++ b/include/ajax_tag_add_action.php @@ -0,0 +1,46 @@ +ag_id=$_REQUEST['ag_id']; +if ( $g_user->can_write_action($fl->ag_id) == TRUE ) + $fl->tag_add($_REQUEST['t_id']); + +ob_start(); + +$fl->tag_cell(); + +$response= ob_get_clean(); +ob_end_clean(); +$html=escape_xml($response); +header('Content-type: text/xml; charset=UTF-8'); +echo << + + +$html + +EOF; +exit(); + + +?> diff --git a/include/ajax_tag_detail.php b/include/ajax_tag_detail.php new file mode 100644 index 000000000..7a7fa1f06 --- /dev/null +++ b/include/ajax_tag_detail.php @@ -0,0 +1,38 @@ +data->t_id=$_GET['tag']; +$tag->data->load(); +echo HtmlInput::title_box("Détail du dossier / tag", "tag_div"); + +?> +
+ data; + require_once 'template/tag_detail.php'; + echo HtmlInput::submit("save_tag", "Valider"); + ?> +
+ + + +$html + +EOF; + exit(); + ?> \ No newline at end of file diff --git a/include/ajax_tag_list.php b/include/ajax_tag_list.php new file mode 100644 index 000000000..87b867ccd --- /dev/null +++ b/include/ajax_tag_list.php @@ -0,0 +1,42 @@ +select(); + +$response= ob_get_clean(); +ob_end_clean(); +$html=escape_xml($response); +header('Content-type: text/xml; charset=UTF-8'); +echo << + + +$html + +EOF; +exit(); + + +?> diff --git a/include/ajax_tag_remove_action.php b/include/ajax_tag_remove_action.php new file mode 100644 index 000000000..e6d0a3568 --- /dev/null +++ b/include/ajax_tag_remove_action.php @@ -0,0 +1,46 @@ +ag_id=$_REQUEST['ag_id']; + +if ( $g_user->can_write_action($fl->ag_id) == TRUE ) $fl->tag_remove($_REQUEST['t_id']); + +ob_start(); + +$fl->tag_cell(); + +$response= ob_get_clean(); +ob_end_clean(); +$html=escape_xml($response); +header('Content-type: text/xml; charset=UTF-8'); +echo << + + +$html + +EOF; +exit(); + + +?> diff --git a/include/cfgtags.inc.php b/include/cfgtags.inc.php index 01f7c166a..128e4ae52 100644 --- a/include/cfgtags.inc.php +++ b/include/cfgtags.inc.php @@ -24,4 +24,31 @@ * @brief Manage the tags * */ +require_once 'class_tag.php'; +require_once 'class_tool_uos.php'; + +$tag=new Tag($cn); +$uos=new Tool_Uos('tag'); +if ( isset ($_POST['save_tag'])) +{ + try { + $uos->check(); + $tag->save($_POST); + $uos->save(); + } catch (Exception $e) + { + alert("déjà sauvé"); + } +} ?> +
+

+ Vous pouvez utiliser ceci comme des tags pour marquer des documents ou + comme des dossiers pour rassembler des documents. Un document peut appartenir + à plusieurs dossiers ou avoir plusieurs tags. +

+ show_list(); + $js=sprintf("onclick=\"show_tag('%s','%s','%s')\"",Dossier::id(),$_REQUEST['ac'],'-1'); + echo HtmlInput::button("tag_add", "Ajout d'un dossier", $js); + ?> \ No newline at end of file diff --git a/include/class_follow_up.php b/include/class_follow_up.php index cdc074eb3..2c257d989 100644 --- a/include/class_follow_up.php +++ b/include/class_follow_up.php @@ -37,6 +37,7 @@ require_once('class_follow_up_detail.php'); require_once('class_inum.php'); require_once 'class_sort_table.php'; require_once 'class_irelated_action.php'; +require_once 'class_tag.php'; /** * \file @@ -509,6 +510,7 @@ class Follow_Up $Hid = new IHidden(); $r.=$Hid->input("nb_item", MAX_ARTICLE); $r.=HtmlInput::request_to_hidden(array("closed_action","remind_date_end","remind_date","sag_ref","only_internal","state","qcode", "ag_dest_query", "query", "tdoc", "date_start", "date_end", "hsstate")); + $a_tag=$this->tag_get(); /* get template */ ob_start(); require_once 'template/detail-action.php'; @@ -1409,4 +1411,64 @@ class Follow_Up jr_id=$1",array($p_jr_id)); return $array; } + /** + * @brief get the tags of the current objet + * @return an array idx [ag_id,t_id,at_id,t_tag] + */ + function tag_get() + { + if ($this->ag_id==0)return; + $sql='select b.ag_id,b.t_id,b.at_id,a.t_tag' + . ' from ' + .' tags as a join action_tags as b on (a.t_id=b.t_id)' + . ' where ag_id=$1 ' + .' order by a.t_tag'; + $array=$this->db->get_array($sql,array($this->ag_id)); + return $array; + } + /** + * @brief show the tags of the current objet + * normally used by ajax. The same tag cannot be added twice + * + */ + function tag_add($p_t_id) + { + if ($this->ag_id==0)return; + $count=$this->db->get_value('select count(*) from action_tags'. + ' where ag_id=$1 and t_id=$2', + array($this->ag_id,$p_t_id)); + if ( $count > 0 ) return; + $sql=' insert into action_tags (ag_id,t_id) values ($1,$2)'; + $this->db->exec_sql($sql,array($this->ag_id,$p_t_id)); + + } + /** + * @brief remove the tags of the current objet + * normally used by ajax + */ + function tag_remove($p_t_id) + { + if ($this->ag_id==0)return; + $sql=' delete from action_tags where ag_id=$1 and t_id=$2'; + $this->db->exec_sql($sql,array($this->ag_id,$p_t_id)); + } + function tag_cell() + { + $a_tag=$this->tag_get(); + $c=count($a_tag); + for ($e=0;$e<$c;$e++) { + $js_remove=sprintf("onclick=\"action_tag_remove('%s','%s','%s')\"",dossier::id(),$this->ag_id, + $a_tag[$e]['t_id']); + echo ''; + echo $a_tag[$e]['t_tag']; + echo ''; + echo ''; + echo HtmlInput::anchor("X", "javascript:void(0)", $js_remove).'  '; + echo ''; + echo ' '; + } + $js=sprintf("onclick=\"action_tag_select('%s','%s')\"",dossier::id(),$this->ag_id); + echo HtmlInput::button('tag_bt', 'Ajout tag',$js, 'smallbutton'); + + } } diff --git a/include/class_tag.php b/include/class_tag.php index ea438bfd7..80a5d5f00 100644 --- a/include/class_tag.php +++ b/include/class_tag.php @@ -31,7 +31,31 @@ class Tag { $ret=$this->data->seek(' order by t_tag'); if ( $this->cn->count($ret) == 0) return ""; - + require_once 'template/tag_list.php'; + } + function select() + { + $ret=$this->data->seek(' order by t_tag'); + if ( $this->cn->count($ret) == 0) return "aucun tag trouvé"; + require_once 'template/tag_select.php'; + } + function form_add() + { + $data=$this->data; + require_once 'template/tag_detail.php'; + } + function show_form_add() + { + echo '

'.' Ajout d\'un dossier (ou tag)'.'

'; + + $this->form_add(); + } + function save($p_array) + { + $this->data->t_id=$p_array['t_id']; + $this->data->t_tag=str_ireplace('