noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 47/119: Tag and Group Tag


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 47/119: Tag and Group Tag
Date: Mon, 26 Oct 2020 18:27:16 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 037a423a3ba4746bfc71262ba0d02f55cabac8b3
Author: Dany De Bontridder <danydb@noalyss.eu>
AuthorDate: Sun Oct 4 20:34:09 2020 +0200

    Tag and Group Tag
    
    new : Tag and Group : available in search
    new : all tags or only one,
---
 html/ajax_misc.php                                 |  6 +-
 html/js/scripts.js                                 | 11 ++-
 html/js/taggroup.js                                | 70 +++++++++++++++++
 include/ajax/ajax_search_add_tag.php               | 40 +++++++---
 include/ajax/ajax_search_display_tag.php           |  5 +-
 include/ajax/ajax_tag_detail.php                   |  2 +-
 include/ajax/ajax_tag_group.php                    | 64 +++++++++++++++
 include/ajax/ajax_tag_set_group.php                | 77 ++++++++++++++++++
 include/cfgtags.inc.php                            | 81 +++++++++++++++----
 include/class/follow_up.class.php                  | 25 ++++--
 include/class/tag.class.php                        |  6 +-
 include/class/tag_group_mtable.class.php           | 91 ++++++++++++++++++++++
 .../tag_group_sql.class.php}                       | 68 +++++++++-------
 include/lib/function_javascript.php                |  1 +
 include/lib/html_input.class.php                   | 14 ++--
 include/template/action_search.php                 | 12 +++
 include/template/tag_list.php                      | 14 +++-
 include/template/tag_search_select.php             | 61 +++++++++++++--
 sql/upgrade.sql                                    | 35 ++++++++-
 19 files changed, 595 insertions(+), 88 deletions(-)

diff --git a/html/ajax_misc.php b/html/ajax_misc.php
index 3ac6686..9a74ce0 100644
--- a/html/ajax_misc.php
+++ b/html/ajax_misc.php
@@ -261,7 +261,11 @@ $path = array(
     // cfgaction type of document
     "cfgaction"=>'ajax_cfgaction',
     // list options for multiple contact
-    "contact_option_list"=>'ajax_contact_option_list'
+    "contact_option_list"=>'ajax_contact_option_list',
+    // Add group of tags
+   'tag_group'=>'ajax_tag_group',
+    // set the group for a tag
+    'tag_set_group'=>"ajax_tag_set_group"
 )    ;
 
 if (array_key_exists($op, $path)) {
diff --git a/html/js/scripts.js b/html/js/scripts.js
index 0961481..b29f056 100644
--- a/html/js/scripts.js
+++ b/html/js/scripts.js
@@ -24,7 +24,8 @@
  *
  */
 var ask_reload = 0;
-var tag_choose = '';
+// tag_choose Element  which contains all the selected tags 
+var tag_choose = ''; 
 var aDraggableElement = new Array();
 /**
  * return undefined if nothing is found , otherwise return the DOM elemnt
@@ -2487,7 +2488,7 @@ function show_tag(p_dossier, p_ac, p_tag_id, p_post)
                         code_html = unescape_xml(code_html);
                         remove_waiting_box();
                         var posy = calcy(250);
-                        add_div({id: 'tag_div', cssclass: 'inner_box', drag: 
0, style: "position:fixed;top:" + posy + "px"});
+                        add_div({id: 'tag_div', cssclass: 'inner_box', drag: 
0, style: "position:fixed;top:15%;"});
                         $('tag_div').innerHTML = code_html;
                         try
                         {
@@ -2711,8 +2712,10 @@ function search_display_tag(p_dossier, p_prefix)
  * in the search screen
  * @param {type} p_dossier
  * @param {type} p_tag_id
+ * @param p_prefix is the prefix of the widget 
+ * @param p_obj is either g for group of tag or t for a single tag
  */
-function search_add_tag(p_dossier, p_tag_id, p_prefix)
+function search_add_tag(p_dossier, p_tag_id, p_prefix,p_obj)
 {
     try {
         var clear_button = 0;
@@ -2721,7 +2724,7 @@ function search_add_tag(p_dossier, p_tag_id, p_prefix)
             clear_button = 1;
         }
         waiting_box();
-        var queryString = "op=search_add_tag&gDossier=" + p_dossier + "&id=" + 
p_tag_id + "&clear=" + clear_button + '&pref=' + p_prefix;
+        var queryString = "op=search_add_tag&gDossier=" + p_dossier + "&id=" + 
p_tag_id + "&clear=" + clear_button + '&pref=' + p_prefix+"&obj="+p_obj;
         var action = new Ajax.Request(
                 "ajax_misc.php",
                 {
diff --git a/html/js/taggroup.js b/html/js/taggroup.js
new file mode 100644
index 0000000..b159a0f
--- /dev/null
+++ b/html/js/taggroup.js
@@ -0,0 +1,70 @@
+/* 
+ * Copyright (C) 2020 Dany De Bontridder <dany@alchimerys.be>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+// Copyright (2002-2020) Author Dany De Bontridder <danydb@noalyss.eu>
+
+
+var TagGroup = function ()
+{
+    this.callback = "ajax_misc.php";
+    this.param_operation = "tag_set_group";
+    this.list_tag = "ol_tag_group";
+    this.div_tag_add = "d_tag_group_add";
+    /**
+     * Add a tag to group and redraw the div "div_tag_add"
+     * @param {int} p_tag_group_id
+     * @param {int} p_tag_id
+     * @param {int} p_dossier
+     */
+    this.add_tag = function (p_tag_group_id, p_select, p_dossier) {
+        waiting_box();
+         // retrieve value from p_select
+        var p_tag_id = $(p_select).value;
+        new Ajax.Request(this.callback, {
+            method: "get",
+            parameters: {op: this.param_operation, gDossier: p_dossier, act: 
"add", tag_group: p_tag_group_id, tag: p_tag_id},
+            onSuccess: function (req) {
+                remove_waiting_box();
+                // redraw div_tag_add
+                $("d_tag_group_add").update(req.responseText);
+            }
+        });
+    };
+    /**
+     * removing a tag from a group and redraw the div "div_tag_add"
+     * @param {int} p_tag_group_id
+     * @param {int} p_tag_id
+     * @param {int} p_dossier
+     */
+    this.remove = function (p_jt_tag, p_dossier) {
+        waiting_box();
+       
+        new Ajax.Request(this.callback, {
+            method: "get",
+            parameters: {op: this.param_operation, 
+                gDossier: p_dossier, 
+                act: "remove", 
+                jt_tag: p_jt_tag
+                },
+            onSuccess: function (req) {
+                remove_waiting_box();
+                // redraw div_tag_add
+                $("d_tag_group_add").update(req.responseText);
+            }
+        });
+    };
+};
\ No newline at end of file
diff --git a/include/ajax/ajax_search_add_tag.php 
b/include/ajax/ajax_search_add_tag.php
index 339b45c..2e5b2d2 100644
--- a/include/ajax/ajax_search_add_tag.php
+++ b/include/ajax/ajax_search_add_tag.php
@@ -1,4 +1,5 @@
 <?php
+
 /*
  *   This file is part of NOALYSS.
  *
@@ -17,23 +18,42 @@
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 // Copyright Author Dany De Bontridder danydb@aevalys.eu
-if ( !defined ('ALLOWED') )  die('Appel direct ne sont pas permis');
+if (!defined('ALLOWED'))
+    die('Appel direct ne sont pas permis');
 /**
- *@file
- *@brief add tag , used for follow up
- *@see Tag
+ * @file
+ * @brief add tag , used for follow up
+ * @see Tag
  */
-
 require_once NOALYSS_INCLUDE.'/class/tag.class.php';
+//Single Tag
 ob_start();
-if ($_GET['clear']==1) {
+if ($_GET['clear']==1)
+{
     /* Add a clear button */
     echo Tag::add_clear_button($_GET['pref']);
 }
-$tag=new Tag($cn,$_GET['id']);
-$tag->update_search_cell($_GET['pref']);
+if ($http->request("obj")=='t')
+{
 
-$response=  ob_get_clean();
+    $tag=new Tag($cn, $http->get("id", "number"));
+    $tag->update_search_cell($http->get("pref"));
+}
+elseif ($http->request("obj")=="g")
+{
+    // Add all the tag from the group 
+    $aTag=$cn->get_array("select t_id,t_tag from jnt_tag_group_tag jtgt  join 
tags on (tag_id=t_id) where tag_group_id=1 order by 2 ");
+    $nb_atag=count($aTag);
+    $pref=$http->get("pref");
+    if ( $nb_atag > 0) {
+        for ($i=0;$i<$nb_atag;$i++){
+            $tag=new Tag($cn,$aTag[$i]['t_id']);
+            $tag->update_search_cell($pref);
+        }
+    }
+    
+}
+$response=ob_get_clean();
 $html=escape_xml($response);
 header('Content-type: text/xml; charset=UTF-8');
 echo <<<EOF
@@ -44,7 +64,5 @@ echo <<<EOF
 </data>
 EOF;
 exit();
-
-
 ?>
 
diff --git a/include/ajax/ajax_search_display_tag.php 
b/include/ajax/ajax_search_display_tag.php
index 59d9627..b4295cc 100644
--- a/include/ajax/ajax_search_display_tag.php
+++ b/include/ajax/ajax_search_display_tag.php
@@ -25,11 +25,10 @@ if ( !defined ('ALLOWED') )  die('Appel direct ne sont pas 
permis');
  */
 
 require_once NOALYSS_INCLUDE.'/class/tag.class.php';
-ob_start();
 $tag=new Tag($cn);
-$tag->select_search($_GET['pref']);
 
-$response=  ob_get_clean();
+$response=  $tag->select_search($_GET['pref']);
+
 $html=escape_xml($response);
 header('Content-type: text/xml; charset=UTF-8');
 echo <<<EOF
diff --git a/include/ajax/ajax_tag_detail.php b/include/ajax/ajax_tag_detail.php
index 6e86e5f..cf6bec6 100644
--- a/include/ajax/ajax_tag_detail.php
+++ b/include/ajax/ajax_tag_detail.php
@@ -13,7 +13,7 @@ ob_start();
 $tag=new Tag($cn);
 $tag->data->t_id=$_GET['tag'];
 $tag->data->load();
-echo HtmlInput::title_box(_("Détail du dossier ou étiquette"), "tag_div");
+echo HtmlInput::title_box(_("Détail du dossier ou étiquette"), 
"tag_div","close","","y");
 
 ?>
 <?php
diff --git a/include/ajax/ajax_tag_group.php b/include/ajax/ajax_tag_group.php
new file mode 100644
index 0000000..dc13576
--- /dev/null
+++ b/include/ajax/ajax_tag_group.php
@@ -0,0 +1,64 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   PhpCompta is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   PhpCompta is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with PhpCompta; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright (2002-2020) Author Dany De Bontridder <danydb@noalyss.eu>
+
+if (!defined('ALLOWED'))
+    die('Appel direct ne sont pas permis');
+require_once NOALYSS_INCLUDE."/class/tag_group_mtable.class.php";
+/**
+ * @file
+ * @brief Manage the group of tags
+ */
+try {
+    $table=$http->request('table');
+    $action=$http->request('action');
+    $p_id=$http->request('p_id', "number");
+    $ctl_id=$http->request('ctl');
+
+} catch(Exception $e) {
+    echo $e->getMessage();
+    return;
+}
+$obj=new Tag_Group_SQL($cn,$p_id);
+$obj_manage=new Tag_Group_MTable($obj);
+$obj_manage->set_callback("ajax_misc.php");
+$obj_manage->add_json_param("op", "tag_group");
+$obj_manage->set_object_name($ctl_id);
+
+
+if ($action=="input")
+{
+   
+    header('Content-type: text/xml; charset=UTF-8');
+    echo $obj_manage->ajax_input()->saveXML();
+    return;
+}
+elseif ($action=="save")
+{
+    $xml=$obj_manage->ajax_save();
+    header('Content-type: text/xml; charset=UTF-8');
+    echo $xml->saveXML();
+}
+elseif ($action=="delete")
+{
+    $xml=$obj_manage->ajax_delete();
+    header('Content-type: text/xml; charset=UTF-8');
+    echo $xml->saveXML();
+}
\ No newline at end of file
diff --git a/include/ajax/ajax_tag_set_group.php 
b/include/ajax/ajax_tag_set_group.php
new file mode 100644
index 0000000..4d36348
--- /dev/null
+++ b/include/ajax/ajax_tag_set_group.php
@@ -0,0 +1,77 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   PhpCompta is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   PhpCompta is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with PhpCompta; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright (2002-2020) Author Dany De Bontridder <danydb@noalyss.eu>
+
+if (!defined('ALLOWED'))
+    die('Appel direct ne sont pas permis');
+
+require_once NOALYSS_INCLUDE."/class/tag_group_mtable.class.php";
+
+/**
+ * @file
+ * @brief 
+ */
+global $g_user;
+$g_user->can_request('CFGTAG');
+
+/*
+ * Received parameter
+ * gDossier
+ * act : action to perform
+ * tag_group : tag_group.tg_id
+ * tag=tags.t_id
+ * 
+ */
+try
+{
+    $act=$http->request("act");
+}
+catch (Exception $e)
+{
+
+    record_log(__FILE__.$e->getMessage()." ".$e->getTraceAsString());
+    echo $e->getMessage()." ".$e->getTraceAsString();
+}
+$obj=new Tag_Group_SQL($cn);
+$obj_manage=new Tag_Group_MTable($obj);
+$obj_manage->set_callback("ajax_misc.php");
+$obj_manage->add_json_param("op", "tag_group");
+if ($act=="add")
+{
+    $tag_group_id=$http->request("tag_group");
+    $tag=$http->request("tag");
+    $obj_manage->set_pk($tag_group_id);
+    // add tag to group tag
+    // protect against duplicate
+    if ($cn->get_value("select count (*) from  jnt_tag_group_tag where tag_id 
= $1 and tag_group_id = $2",
+                    [$tag, $tag_group_id])==0)
+    {
+        $cn->exec_sql("insert into jnt_tag_group_tag(tag_id,tag_group_id) 
values ($1,$2)", [$tag, $tag_group_id]);
+    }
+}
+elseif ($act=="remove")
+{
+    $tag=$http->request("jt_tag");
+    $tag_group_id=$cn->get_value("select tag_group_id from jnt_tag_group_tag 
where jt_id = $1",[$tag]);
+    $obj_manage->set_pk($tag_group_id);
+    // remove tag from tag_group
+    $cn->exec_sql("delete from jnt_tag_group_tag where jt_id=$1", [$tag]);
+}
+$obj_manage->input_tag();
diff --git a/include/cfgtags.inc.php b/include/cfgtags.inc.php
index e9aef77..9a61885 100644
--- a/include/cfgtags.inc.php
+++ b/include/cfgtags.inc.php
@@ -17,7 +17,8 @@
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 // Copyright Author Dany De Bontridder danydb@aevalys.eu
-if ( !defined ('ALLOWED') )  die('Appel direct ne sont pas permis');
+if (!defined('ALLOWED'))
+    die('Appel direct ne sont pas permis');
 
 /**
  * @file
@@ -26,34 +27,82 @@ if ( !defined ('ALLOWED') )  die('Appel direct ne sont pas 
permis');
  */
 require_once NOALYSS_INCLUDE.'/class/tag.class.php';
 require_once NOALYSS_INCLUDE.'/lib/single_record.class.php';
+require_once NOALYSS_INCLUDE."/lib/html_tab.class.php";
+require_once NOALYSS_INCLUDE."/lib/output_html_tab.class.php";
+require_once NOALYSS_INCLUDE."/class/tag_group_mtable.class.php";
 
+/* * 
*****************************************************************************
+ *  Tags
+ *
+ * 
***************************************************************************** */
+$tabs=new Html_Tab("tg", _("Etiquette"));
+
+ob_start();
 $tag=new Tag($cn);
 $uos=new Single_Record('tag');
-if ( isset ($_POST['save_tag_sb']))
+if (isset($_POST['save_tag_sb']))
 {
-    if ( ! isset ($_POST['remove']))
+    if (!isset($_POST['remove']))
     {
-        try {
+        try
+        {
             $uos->check();
             $tag->save($_POST);
             $uos->save();
-        } catch (Exception $e)
+        }
+        catch (Exception $e)
         {
             alert("déjà sauvé");
         }
-    } else {
+    }
+    else
+    {
         $tag->remove($_POST);
     }
 }
 ?>
-<div style="margin-left:10%;width:80%">
-     <p class="notice">
-        <?php echo _("Vous pouvez utiliser ceci comme des étiquettes pour 
marquer des documents ou 
+<div style="margin-left:5%;width:90%">
+    <p class="info">
+    <?php echo _("Vous pouvez utiliser ceci comme des étiquettes pour marquer 
des documents ou 
          comme des dossiers pour rassembler des documents. Un document peut 
appartenir
-         à plusieurs dossiers ou avoir plusieurs étiquettes.");?>
-     </p>
-    <?php
-        $tag->show_list();
-         
$js=sprintf("onclick=\"show_tag('%s','%s','%s','p')\"",Dossier::id(),$_REQUEST['ac'],'-1');
-        echo HtmlInput::button("tag_add", "Ajout d'un tag", $js);
-    ?>
\ No newline at end of file
+         à plusieurs dossiers ou avoir plusieurs étiquettes."); ?>
+    </p>
+<?php
+$tag->show_list();
+$js=sprintf("onclick=\"show_tag('%s','%s','%s','p')\"", Dossier::id(), 
$_REQUEST['ac'], '-1');
+echo HtmlInput::button("tag_add", "Ajout d'un tag", $js);
+?>
+</div>
+<?php
+$tabs->set_content(ob_get_contents());
+ob_end_clean();
+/* * 
*****************************************************************************
+ *  Group of Tags
+ *
+ * 
***************************************************************************** */
+$tag_group=new Html_Tab("grp_tg", _("Groupe étiquettes"));
+
+$obj=new Tag_Group_SQL($cn);
+$obj_manage=new Tag_Group_MTable($obj);
+$obj_manage->set_callback("ajax_misc.php");
+$obj_manage->add_json_param("op", "tag_group");
+ob_start();
+$obj_manage->display_table();
+$r=ob_get_contents();
+$tag_group->set_content($r);
+ob_end_clean();
+
+
+$out=new Output_Html_Tab();
+$out->add($tabs);
+$out->add($tag_group);
+$out->output();
+$obj_manage->create_js_script();
+?>
+<script>
+    $('divtg').show();
+    $('tabtg').className = 'tabs_selected';
+    $('divgrp_tg').hide();
+    $('tabgrp_tg').className = 'tabs';
+    var o_tagGroup=new TagGroup();
+</script>
\ No newline at end of file
diff --git a/include/class/follow_up.class.php 
b/include/class/follow_up.class.php
index e38f4a7..4ff340d 100644
--- a/include/class/follow_up.class.php
+++ b/include/class/follow_up.class.php
@@ -1202,15 +1202,26 @@ class Follow_Up
         if ($p_array==null)
             $p_array=$_GET;
 
-        $query="";
         if (count($p_array['searchtag'])==0)
             return "";
+        $query="";
+        $operand = "1 = 0 ";
+        if ($p_array['tag_option'] == 0 )
+        {
+            $operand=" and ";
+        } elseif ($p_array['tag_option']==1)
+        {
+            $operand=" or ";
+        }
+        $and=" ";
         for ($i=0; $i<count($p_array['searchtag']); $i++)
         {
-            if (isNumber($p_array['searchtag'][$i])==1)
-                $query .= ' and ag_id in (select ag_id from action_tags where 
t_id= '.sql_string($p_array['searchtag'][$i]).')';
+            if (isNumber($p_array['searchtag'][$i])==1) {
+                $query .= $and .' ag_id in (select ag_id from action_tags 
where t_id= '.sql_string($p_array['searchtag'][$i]).')';
+                $and = $operand;
+            }
         }
-        return $query;
+        return "and (".$query.")";
     }
 
     /**
@@ -1479,12 +1490,12 @@ class Follow_Up
         $c=count($a_tag);
         for ($e=0; $e<$c; $e++)
         {
-            echo '<span style="border:1px solid black;margin-right:5px;">';
+            echo '<span style="border-radius:3px;border:1px 
solid;padding:5px;margin:1px">';
             echo $a_tag[$e]['t_tag'];
             if ($g_user->can_write_action($this->ag_id)==true)
             {
-                
$js_remove=sprintf("onclick=\"action_tag_remove('%s','%s','%s')\"", 
dossier::id(), $this->ag_id, $a_tag[$e]['t_id']);
-                echo HtmlInput::anchor(SMALLX, "javascript:void(0)", 
$js_remove, ' class="smallbutton" style="padding:0px;display:inline" ');
+                $js_remove=sprintf("action_tag_remove('%s','%s','%s')", 
dossier::id(), $this->ag_id, $a_tag[$e]['t_id']);
+                echo Icon_Action::trash(uniqid(), $js_remove);
             }
             echo '</span>';
             echo '&nbsp;';
diff --git a/include/class/tag.class.php b/include/class/tag.class.php
index a6a6855..d35799b 100644
--- a/include/class/tag.class.php
+++ b/include/class/tag.class.php
@@ -90,18 +90,20 @@ class Tag
      */
     function select_search($p_prefix)
     {
+        $res="";
         $ret=$this->data->seek(' order by t_tag');
         require_once NOALYSS_TEMPLATE.'/tag_search_select.php';
+        return HtmlInput::title_box('Tag', $p_prefix.'tag_div').$res;
     }
     /**
      * In the screen search add this data to the cell
      */
     function update_search_cell($p_prefix) {
-        echo '<span id="sp_'.$p_prefix.$this->data->t_id.'" style="border:1px 
solid black;margin-right:5px;">';
+        echo '<span id="sp_'.$p_prefix.$this->data->t_id.'" 
style="border-radius:3px;border:1px solid;padding:5px;margin:1px">';
         echo h($this->data->t_tag);
         echo HtmlInput::hidden($p_prefix.'tag[]', $this->data->t_id);
         $js=sprintf("$('sp_".$p_prefix.$this->data->t_id."').remove();");
-        echo HtmlInput::anchor( SMALLX, "javascript:void(0)", 
"onclick=\"$js\"", ' class="smallbutton " style="padding:0px;display:inline" ');
+        echo Icon_Action::trash(uniqid(), $js);
         echo '</span>';
     }
     /**
diff --git a/include/class/tag_group_mtable.class.php 
b/include/class/tag_group_mtable.class.php
new file mode 100644
index 0000000..e225d62
--- /dev/null
+++ b/include/class/tag_group_mtable.class.php
@@ -0,0 +1,91 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   PhpCompta is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   PhpCompta is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with PhpCompta; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright (2002-2020) Author Dany De Bontridder <danydb@noalyss.eu>
+
+
+/**
+ * @file
+ * @brief manage tag_group table
+ * 
+ * 
+ */
+require_once NOALYSS_INCLUDE.'/lib/manage_table_sql.class.php';
+require_once NOALYSS_INCLUDE.'/database/tag_group_sql.class.php';
+
+class Tag_Group_MTable extends Manage_Table_SQL
+{
+
+    function __construct(Tag_Group_SQL $p_obj)
+    {
+        parent::__construct($p_obj);
+        $this->set_property_visible("tg_id", false);
+        $this->set_property_updatable("tg_id", false);
+        $this->set_col_label("tg_name", _('Nom'));
+    }
+
+    function input()
+    {
+
+
+        parent::input();
+
+
+        echo '<div id="d_tag_group_add">';
+        $this->input_tag();
+        echo '</div>';
+    }
+
+    /**
+     * Display a select widget for adding new tag 
+     */
+    function input_tag()
+    {
+        $cn=Dossier::connect();
+        $data_sql=$this->get_table();
+        
+        // Display containing tag_id 
+        $aTag=$cn->get_array("select jt_id,t_tag 
+                               from tags join jnt_tag_group_tag on 
(tag_id=t_id) 
+                               where tag_group_id=$1 order by 2", 
[$data_sql->tg_id]);
+        echo '<ol id="ol_tag_group">';
+        $nb=count($aTag);
+        $dossier_id=Dossier::id();
+        for ($i=0; $i<$nb; $i++)
+        {
+            // js to remove id
+            $js=Icon_Action::trash(uniqid(), 
sprintf("o_tagGroup.remove('%s','%s')", $aTag[$i]['jt_id'], $dossier_id));
+            printf('<li id="t%s"> %s %s %s</li>', 
$aTag[$i]['jt_id'],$aTag[$i]['t_tag'],$dossier_id,$js);
+        }
+        echo '</ol>';
+
+
+        // Add new tag
+        $select=new ISelect("is_tag", [], "s_tag_group");
+        $select->value=$cn->make_array("select t_id,t_tag 
+                               from tags 
+                               where 
+                                t_id not in (select tag_id from 
jnt_tag_group_tag 
+                               where tag_group_id=$1 ) order by 2", 
0,[$data_sql->tg_id]);
+        echo $select->input();
+        echo HtmlInput::button('b_add_group', _("Ajout"),
+                sprintf("onclick=\"o_tagGroup.add_tag('%s','%s','%s'); \"", 
$data_sql->tg_id, $select->id, $dossier_id));
+    }
+
+}
diff --git a/include/ajax/ajax_search_add_tag.php 
b/include/database/tag_group_sql.class.php
similarity index 52%
copy from include/ajax/ajax_search_add_tag.php
copy to include/database/tag_group_sql.class.php
index 339b45c..2792323 100644
--- a/include/ajax/ajax_search_add_tag.php
+++ b/include/database/tag_group_sql.class.php
@@ -1,5 +1,7 @@
 <?php
-/*
+
+/**
+ * Autogenerated file 
  *   This file is part of NOALYSS.
  *
  *   NOALYSS is free software; you can redistribute it and/or modify
@@ -15,36 +17,46 @@
  *   You should have received a copy of the GNU General Public License
  *   along with NOALYSS; if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright Author Dany De Bontridder danydb@aevalys.eu
-if ( !defined ('ALLOWED') )  die('Appel direct ne sont pas permis');
+*/
+require_once NOALYSS_INCLUDE.'/lib/noalyss_sql.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
+
+
 /**
+ * class_tag_group_sql.php
+ *
  *@file
- *@brief add tag , used for follow up
- *@see Tag
- */
-
-require_once NOALYSS_INCLUDE.'/class/tag.class.php';
-ob_start();
-if ($_GET['clear']==1) {
-    /* Add a clear button */
-    echo Tag::add_clear_button($_GET['pref']);
-}
-$tag=new Tag($cn,$_GET['id']);
-$tag->update_search_cell($_GET['pref']);
+ *@brief abstract of the table public.tag_group */
+class Tag_group_SQL extends Noalyss_SQL
+{
 
-$response=  ob_get_clean();
-$html=escape_xml($response);
-header('Content-type: text/xml; charset=UTF-8');
-echo <<<EOF
-<?xml version="1.0" encoding="UTF-8"?>
-<data>
-<ctl></ctl>
-<html>$html</html>
-</data>
-EOF;
-exit();
+function __construct(Database $p_cn,$p_id=-1)
+  {
+  $this->table = "public.tag_group";
+  $this->primary_key = "tg_id";
+/*
+ * List of columns
+ */
+  $this->name=array(
+       "tg_id"=>"tg_id"
+       ,"tg_name"=>"tg_name"
+        );
+/*
+ * Type of columns
+ */
+  $this->type = array(
+       "tg_id"=>"numeric"
+       ,"tg_name"=>"text"
+          );
+ 
 
+  $this->default = array(
+  "tg_id" => "auto"
+  );
 
-?>
+  $this->date_format = "DD.MM.YYYY";
+  parent::__construct($p_cn,$p_id);
+  }
+  
 
+}
\ No newline at end of file
diff --git a/include/lib/function_javascript.php 
b/include/lib/function_javascript.php
index 10079ac..b34b68c 100644
--- a/include/lib/function_javascript.php
+++ b/include/lib/function_javascript.php
@@ -2782,6 +2782,7 @@ function load_all_script()
     echo js_include('sorttable.js');
     echo js_include('nicEdit.js');
     echo js_include('managetable.js');
+    echo js_include('taggroup.js');
 
 
 }
diff --git a/include/lib/html_input.class.php b/include/lib/html_input.class.php
index 7dd1ccd..e7e22bf 100755
--- a/include/lib/html_input.class.php
+++ b/include/lib/html_input.class.php
@@ -828,12 +828,12 @@ class HtmlInput
     /**
      * Title for boxes, you can customize the symbol thanks symbol with
      * the mode "custom"
-     * @param type $name Title
-     * @param type $div element id, except for mode none or custom
-     * @param type $mod hide , close , zoom , custom or none, with
+     * @param string $p_name Title
+     * @param string $div element id, except for mode none or custom
+     * @param string $p_mod hide , close , zoom , custom or none, with
      * custom , the $name contains all the code
-     * @param type $p_js contains the javascript if mod = "custom" or "zoom" 
contains button + code 
-     * @param type $p_draggable , if set to yes the box will be draggable
+     * @param string $p_js contains the javascript if mod = "custom" or "zoom" 
contains button + code 
+     * @param char $p_draggable , y = yes n = no ,if set to yes the box will 
be draggable
      * @return type
      */
     static function title_box($p_name, $p_div, $p_mod="close", $p_js="",
@@ -868,7 +868,9 @@ class HtmlInput
             $r.="";
         }
         else
-            die(__FILE__.":".__LINE__._('Paramètre invaide'));
+        {
+            throw new Exception(__FILE__.":".__LINE__._("Paramètre invalide 
p_mod = '$p_mod'"));
+        }
 
 
         $r.='</div>';
diff --git a/include/template/action_search.php 
b/include/template/action_search.php
index e7bb169..657f5d9 100644
--- a/include/template/action_search.php
+++ b/include/template/action_search.php
@@ -140,6 +140,18 @@
                    ?>
                </span>
             </p>
+            <p>
+                <?php 
+                echo _("Option étiquettes");
+                $iselect= new ISelect("tag_option");
+                $iselect->value=array(
+                    array("value"=>0,"label"=>_("Toutes les étiquettes")),
+                    array("value"=>1,"label"=>_("Au moins une étiquette"))
+                    );
+                $iselect->set_value($http->request("tag_option","number",0));
+                echo $iselect->input(); 
+                       ?>
+            </p>
                         
                <input type="hidden" name="sa" value="list">
                <?php echo  $supl_hidden?>
diff --git a/include/template/tag_list.php b/include/template/tag_list.php
index 962e3ab..fb4802a 100644
--- a/include/template/tag_list.php
+++ b/include/template/tag_list.php
@@ -2,6 +2,7 @@
 //This file is part of NOALYSS and is under GPL 
 //see licence.txt
 ?><?php
+$http=new HttpInput();
 $max=$this->cn->count($ret);
 echo HtmlInput::filter_table("tag_tb", '0,1', '1');
 $nDossier=Dossier::id();
@@ -14,13 +15,19 @@ $nDossier=Dossier::id();
         <th>
             <?php echo _("Description")?>
         </th>
+            
+        <th>
+            <?php echo _("Actif")?>
+        </th>
+     
     </tr>
 <?php
 $gDossier=Dossier::id();
-$ac=$_REQUEST['ac'];
+$ac=$http->request('ac');
+    
     for ($i=0;$i<$max;$i++):
-        $row=Database::fetch_array($ret, $i);
-?>
+                $row=Database::fetch_array($ret, $i);
+        ?>
     <tr class="<?php echo (($i%2==0)?'even':'odd');?>">
         <td>
             <?php
@@ -33,6 +40,7 @@ $ac=$_REQUEST['ac'];
             echo $row['t_description'];
             ?>
         </td>
+        
         <td>
             <?php
             $id=sprintf("tag_onoff%d",$row['t_id']);
diff --git a/include/template/tag_search_select.php 
b/include/template/tag_search_select.php
index 5b50aaa..bfa67d5 100644
--- a/include/template/tag_search_select.php
+++ b/include/template/tag_search_select.php
@@ -2,12 +2,15 @@
 //This file is part of NOALYSS and is under GPL 
 //see licence.txt
 ?><?php
-echo HtmlInput::title_box('Tag', $p_prefix.'tag_div');
+
 $max=$this->cn->count($ret);
 if ( $max == 0 ) {
     echo h2(_("Aucune étiquette disponible"),' class="notice"');
     return;
 }
+require_once NOALYSS_INCLUDE."/lib/output_html_tab.class.php";
+$tab_tag=new Html_Tab($p_prefix."tab_tag",_("Etiquettes"));
+ob_start();
 ?>
 <?php echo _("Cherche")." ".HtmlInput::filter_table($p_prefix.'tag_tb_id', 
'0,1', 1); ?>
 <?php echo HtmlInput::button_action(_('Uniquement actif'), 
'show_only_row(\''.$p_prefix.'tag_tb_id'.'\',\'tag_status\',\'Y\')');?>
@@ -30,13 +33,13 @@ $gDossier=Dossier::id();
     <tr <?=$attr?> class="<?php echo (($i%2==0)?'even':'odd');?>">
         <td>
             <?php
-            
$js=sprintf("search_add_tag('%s','%s','%s')",$gDossier,$row['t_id'],$p_prefix);
+            
$js=sprintf("search_add_tag('%s','%s','%s','t')",$gDossier,$row['t_id'],$p_prefix);
             echo HtmlInput::anchor($row['t_tag'], "", "onclick=\"$js\"");
             ?>
         </td>
         <td>
             <?php
-            echo $row['t_description'];
+            echo h($row['t_description']);
             ?>
         </td>
          <td>
@@ -51,7 +54,55 @@ $gDossier=Dossier::id();
  endfor;
  ?>
 </table>
+ 
+<?php 
+    $tab_tag->set_content(ob_get_contents());
+    ob_end_clean();
+// Tab for the groups 
+//
+$tab_tag_group=new Html_Tab($p_prefix."tab_tag_group",_("Groupe"));
+$aGroup=$this->cn->get_array("select tg_id, tg_name from tag_group order by 2 
desc");
+$nb_agroup=count($aGroup);
+?>
+<table class="result">
+    <tr>
+        <th><?=_("Groupe")?></th>
+    </tr>
+    <?php for ($i=0;$i<$nb_agroup;$i++):?>
+    <tr>
+        <td>
+            <?php
+            
$js=sprintf("search_add_tag('%s','%s','%s','g')",$gDossier,$aGroup[$i]['tg_id'],$p_prefix);
+            echo HtmlInput::anchor($aGroup[$i]['tg_name'], "", 
"onclick=\"$js\"");
+            ?>
+        </td>
+            
+    </tr>
+   <?php endfor;?>
+</table>
+<?php
+
+
+$tab_tag_group->set_content(ob_get_contents());
+ob_end_clean();
+
+// Both tab
+$output=new Output_Html_Tab();
+$output->add($tab_tag);
+$output->add($tab_tag_group);
+ob_start();
+$output->output();
+
+?>
+
+<?=HtmlInput::button_close($p_prefix.'tag_div')?>
+
 <script>
     show_only_row('<?=$p_prefix?>tag_tb_id','tag_status','Y');
-</script>    
-<?=HtmlInput::button_close($p_prefix.'tag_div')?>
\ No newline at end of file
+    <?=$output->build_js($p_prefix."tab_tag");?>
+</script>   
+<?php 
+$res =ob_get_contents();
+ob_end_clean();
+return $res;
+?>
\ No newline at end of file
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index 1dae36d..f311690 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -139,4 +139,37 @@ ALTER TABLE public.contact_option_ref DROP COLUMN 
document_option_id;
 -- on utilise un varchar pour stocker les possibilités
 ALTER TABLE public.contact_option_ref DROP COLUMN cor_value_json;
 ALTER TABLE public.contact_option_ref ADD cor_value_select varchar NULL;
-COMMENT ON COLUMN public.contact_option_ref.cor_value_select IS 'Select 
values';
\ No newline at end of file
+COMMENT ON COLUMN public.contact_option_ref.cor_value_select IS 'Select 
values';
+
+
+CREATE TABLE public.tag_group (
+       tg_id bigserial NOT NULL,
+       tg_name varchar NOT NULL
+);
+COMMENT ON TABLE public.tag_group IS 'Group of tags';
+
+-- Column comments
+
+COMMENT ON COLUMN public.tag_group.tg_name IS 'Nom du groupe';
+ALTER TABLE public.tag_group ADD CONSTRAINT tag_group_pk PRIMARY KEY (tg_id);
+
+-- public.jnt_tag_group_tag definition
+
+-- Drop table
+
+-- DROP TABLE public.jnt_tag_group_tag;
+
+CREATE TABLE public.jnt_tag_group_tag (
+       tag_group_id int8 NOT NULL,
+       tag_id int8 NOT NULL,
+       jt_id serial NOT NULL,
+       CONSTRAINT jnt_tag_group_tag_pkey PRIMARY KEY (jt_id),
+       CONSTRAINT jnt_tag_group_tag_un UNIQUE (tag_id, tag_group_id)
+);
+COMMENT ON TABLE public.jnt_tag_group_tag IS 'Many to Many table betwwen tag 
and tag group';
+
+
+-- public.jnt_tag_group_tag foreign keys
+
+ALTER TABLE public.jnt_tag_group_tag ADD CONSTRAINT jnt_tag_group_tag_fk 
FOREIGN KEY (tag_id) REFERENCES tags(t_id) ON UPDATE CASCADE ON DELETE CASCADE;
+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;
\ No newline at end of file



reply via email to

[Prev in Thread] Current Thread [Next in Thread]