noalyss Version-9
tag_operation.class.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * PhpCompta is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * PhpCompta is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with PhpCompta; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20// Copyright (2002-2020) Author Dany De Bontridder <danydb@noalyss.eu>
21
22if (!defined('ALLOWED'))
23 die('Appel direct ne sont pas permis');
24
25/**
26 * @file
27 * @brief concerns the tags linked to an accountancy writing
28 */
29
30/**
31 * @class Tag_Operation
32 * @brief concerns the tags linked to an accountancy writing
33 */
34class Tag_Operation extends Tag
35{
36
37 private $jrn_id=-1;
38
39 function __construct($p_cn, $p_id=-1)
40 {
41 parent::__construct($p_cn, $p_id);
42 }
43
44 public function get_jrn_id()
45 {
46 return $this->jrn_id;
47 }
48
49 public function set_jrn_id($jrn_id)
50 {
51 $this->jrn_id=$jrn_id;
52 return $this;
53 }
54
55 /**
56 * let select a tag to add
57 */
58 function select($p_prefix="")
59 {
60 $ret=parent::query_active_tag();
61 require_once NOALYSS_TEMPLATE.'/tag_select.php';
62 }
63
64 /**
65 * Show a button to select tag for Search
66 * @param $p_jr jr_id of the operation
67 * @param $p_div prefix of the dialog box
68 * @return HTML
69 */
70 static function button_search($p_jr, $p_div)
71 {
72 $r="";
73 $js=sprintf("onclick=\"new operation_tag('%s').select('%s','%s')\"", $p_div, dossier::id(), $p_jr);
74 $r.=HtmlInput::button('tag_bt', _('Ajout étiquette'), $js, 'smallbutton');
75 return $r;
76 }
77
78 /**
79 * clear the search cell
80 */
81 static function add_clear_button($p_prefix)
82 {
83 $clear=HtmlInput::button('clear', 'X', 'onclick="search_clear_tag('.Dossier::id().',\''.$p_prefix.'\');"',
84 'smallbutton');
85 return $clear;
86 }
87
88 /**
89 * In the screen search add this data to the cell
90 */
91 function update_search_cell($p_prefix)
92 {
93 $data=$this->get_data();
94 echo '<span id="sp_'.$p_prefix.$data->t_id.'" class="tagcell">';
95 echo h($data->t_tag);
96 echo HtmlInput::hidden($p_prefix.'tag[]', $data->t_id);
97 $js=sprintf("$('sp_".$p_prefix.$data->t_id."').remove();");
98 echo Icon_Action::trash(uniqid(), $js);
99 echo '</span>';
100 }
101
102 /**
103 * Links a tag to an operation
104 * @param int $p_tag_id tag.t_id
105 */
106 function tag_add($p_tag_id)
107 {
108 if ($this->jrn_id==-1)
109 {
110 throw new Exception("TO99 jrn_id unset");
111 }
112 $count=$this->cn->get_value('select count(*) from operation_tag'.
113 ' where jrn_id=$1 and tag_id=$2', array($this->jrn_id, $p_tag_id));
114 if ($count>0)
115 return;
116 $sql=' insert into operation_tag (jrn_id,tag_id) values ($1,$2)';
117 $this->cn->exec_sql($sql, array($this->jrn_id, $p_tag_id));
118 }
119
120 /**
121 * @brief show the cell content in Display for the tags
122 * @param $div prefix of the DOM id
123 * called also by ajax
124 */
125 function tag_cell($p_div)
126 {
127 global $g_user;
128 $a_tag=$this->tag_get();
129 $c=count($a_tag);
130 $ledger=$this->cn->get_value("select jr_def_id from jrn where jr_id=$1", [$this->jrn_id]);
131 $access=$g_user->get_ledger_access($ledger);
132 for ($e=0; $e<$c; $e++)
133 {
134 echo '<span class="tagcell tagcell-color'.$a_tag[$e]['t_color'].'">';
135 echo $a_tag[$e]['t_tag'];
136 if ($access=='W')
137 {
138 $js_remove=sprintf("new operation_tag('%s').remove('%s','%s','%s')", $p_div, dossier::id(),
139 $this->jrn_id, $a_tag[$e]['t_id']);
140 echo Icon_Action::trash(uniqid(), $js_remove);
141 }
142 echo '</span>';
143 echo '&nbsp;';
144 echo '&nbsp;';
145 }
146 }
147
148 /**
149 * @brief get the tags of the current objet
150 * @return an array idx [ag_id,t_id,at_id,t_tag]
151 */
152 function tag_get()
153 {
154 if ($this->jrn_id==-1)
155 {
156 throw new Exception("TO01 jrn_id unset");
157 }
158 $sql='select b.jrn_id,a.t_id,a.t_id,a.t_tag,a.t_color'
159 .' from '
160 .' tags as a join operation_tag as b on (a.t_id=b.tag_id)'
161 .' where jrn_id=$1 '
162 .' order by a.t_tag';
163 $array=$this->cn->get_array($sql, array($this->jrn_id));
164 return $array;
165 }
166
167 /**
168 * Remove a tag
169 * @param int $p_tag_id tag id
170 */
171 function tag_remove($p_tag_id)
172 {
173 if ($this->jrn_id==-1)
174 {
175 throw new Exception("TO01 jrn_id unset");
176 }
177 $this->cn->exec_sql("delete from operation_tag where jrn_id=$1 and tag_id=$2", [$this->jrn_id, $p_tag_id]);
178 }
179
180 /**
181 * let select a tag to add to the search
182 */
183 function select_search($p_prefix)
184 {
185 $res="";
186 $ret=$this->get_data()->seek(' order by t_tag');
187 require_once NOALYSS_TEMPLATE.'/tag_search_select.php';
188 return HtmlInput::title_box('Tag', $p_prefix.'tag_div').$res;
189 }
190 /**
191 * Show a button to select tag for Search
192 * @return HTML
193 */
194 static function select_tag_search($p_prefix)
195 {
196 $r="";
197 $r.=HtmlInput::button("choose_tag", _("Etiquette"),
198 'onclick="search_display_tag('.Dossier::id().',\''.$p_prefix.'\',\'Tag_Operation\')"', "smallbutton");
199 return $r;
200 }
201
202}
203
204?>
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$anc_grandlivre from
$op jr_id
Definition: ajax_ledger.php:83
$input_from id
Definition: balance.inc.php:63
static id()
return the 'gDossier' value after a check
static button($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
concerns the tags linked to an accountancy writing
__construct($p_cn, $p_id=-1)
static add_clear_button($p_prefix)
clear the search cell
select($p_prefix="")
let select a tag to add
static button_search($p_jr, $p_div)
Show a button to select tag for Search.
Tag operations or actions to linked them together.
Definition: tag.class.php:32
$bal jrn