noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
card_attribut_mtable.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
22/**
23 * @file
24 * @brief manage the table attr_def
25 * @see card_attr.inc.php
26 */
27
28/**
29 * @class Card_Attribut_MTable
30 * @brief manage the table attr_def
31 * @see card_attr.inc.php
32 */
34{
36 function __construct(\Data_SQL $p_table)
37 {
38 parent::__construct($p_table);
39 $this->set_property_visible("ad_id", TRUE);
40 $this->set_property_updatable("ad_id", FALSE);
41 $this->set_col_label("ad_text", _("Nom"));
42 $this->set_col_label("ad_type", _("Type"));
43 $this->set_col_label("ad_size", _("Taille"));
44 $this->set_col_label('ad_default_order', _("Ordre"));
45 $this->set_col_label("ad_extra", _("Option sup."));
46 $this->set_col_label("ad_search_followup", _("Recherche suivi"));
47
48 $this->set_col_type("ad_search_followup", "custom");
49 $this->set_col_type("ad_text", "custom");
50 $this->set_col_type("ad_size", "numeric");
51 $this->set_col_type("ad_extra", "custom");
52 $this->set_col_type("ad_type", "select",
53 array(
54 ["value"=>"text", "label"=>_("Texte")],
55 ["value"=>"date", "label"=>_("Date")],
56 ["value"=>"numeric", "label"=>_("Nombre")],
57 ["value"=>"select", "label"=>_("Choix")],
58 ["value"=>"card", "label"=>_("Fiche")],
59 ["value"=>"zone", "label"=>_("Zone de texte")],
60 ["value"=>"check", "label"=>_("Coche")],
61 ["value"=>"poste", "label"=>_("Poste comptable")]
62 ));
63 $this->set_col_tips("ad_search_followup", 77);
64 // to prevent a call to this function for each row
65 $this->dossier_id=Dossier::id();
66 $this->set_order(['ad_id','ad_text',"ad_type","ad_default_order","ad_size","ad_extra","ad_search_followup"]);
67 $this->set_col_sort(1);
68 $this->setCssClass("inner_box2");
69 }
70
71 /**
72 * @brief Display row of table attr_def
73 * @param array $row
74 */
75 function display_row($row)
76 {
77 tracedebug("card_attribute.log", $row);
78 if ($row['ad_id']>=9000)
79 {
80 $this->set_delete_row(TRUE);
81 $this->set_update_row(TRUE);
82 }
83 else
84 {
85 $this->set_delete_row(FALSE);
86 $this->set_update_row(FALSE);
87 }
88
89 parent::display_row($row);
90 }
91
92 /**
93 * @brief For the type custom , we can call a function to display properly the value
94 * @param $p_key string key name
95 * @param $p_value string value
96 * @see input_custom
97 * @see set_type
98 * @note must return a string which will be in surrounded by td in the function display_row
99 * @return string
100 */
101 function display_row_custom($p_key, $p_value, $p_id=0)
102 {
103 if ($p_key=="ad_search_followup")
104 {
105 $ic=new Inplace_Switch(uniqid("search_follow_up"), $p_value);
106 $ic->set_callback("ajax_misc.php");
107 $ic->add_json_param("op", "card");
108 $ic->add_json_param("gDossier", $this->dossier_id);
109 $ic->add_json_param("op2", "attribute");
110 $ic->add_json_param("action", "enable_search");
111 $ic->add_json_param("ad_id", $p_id);
112 $ic->add_json_param("ctl", $p_id);
113 $ret=$ic->input();
114
115 return td($ret);
116 }
117 if ($p_key=="ad_text")
118 {
119 return td($p_value);
120 }
121 if ($p_key=="ad_extra")
122 {
123 return td($p_value);
124 }
125 return;
126 }
127
128 /**
129 * @brief For the type custom , we can call a function to display properly the value
130 * @param $p_key string key name
131 * @param $p_value string value
132 * @see input_custom
133 * @see set_type
134 * @note must return a string which will be in surrounded by td in the function display_row
135 * @return string
136 */
137 function input_custom($p_key, $p_value)
138 {
139 if ($p_key=="ad_search_followup")
140 {
141 $p_id=$this->get_table()->get("ad_id");
142 $ic=new InputSwitch("ad_search_followup", $p_value);
143 echo $ic->input();
144 }
145 elseif ($p_key=="ad_text")
146 {
147 /**
148 * Bug in firefox if id=ad_text , the widget is not displaid
149 */
150 $text=new IText("ad_text", $p_value);
151 $text->id=uniqid();
152 echo $text->input();
153 }
154 elseif ($p_key=="ad_extra")
155 {
156 $text=new ITextarea("ad_extra", $p_value);
157 $text->id=uniqid();
158 echo $text->input();
159 }
160 echo "";
161 return;
162 }
163
164 function check()
165 {
166 $object_sql=$this->get_table();
167
168 if ($object_sql->get("ad_id")<9000&&$object_sql->get("ad_id")!=-1)
169 {
170 $this->set_error("ad_id", _("Bloqué"));
171 }
172
173 // Duplicate
174 $count="select count(*)
175 from attr_def as ad1
176 where
177 upper(trim(ad1.ad_text)) = upper(trim($1))
178 and ad1.ad_id != $2
179 ";
180 $count_duplicate=$object_sql->cn->get_value($count, [$object_sql->ad_text, $object_sql->ad_id]);
181 if ($count_duplicate>0)
182 {
183 $this->set_error("ad_text", _("Doublon"));
184 }
185 // type
186 if (in_array($object_sql->get("ad_type"),
187 array('date', 'text', 'numeric', 'zone', 'poste', 'card', 'select', 'check'))==false)
188 {
189 $this->set_error("ad_type", _("Type invalide"));
190 }
191
192 // Name empty
193 if (trim($object_sql->ad_text)=="")
194 {
195 $this->set_error("ad_text", _("Description ne peut pas être vide"));
196 }
197 // select protect
198 if ($object_sql->ad_size=="")
199 {
200 $object_sql->ad_size=22;
201 }
202 if ($object_sql->ad_type=='numeric')
203 {
204 $object_sql->ad_extra=(trim($object_sql->ad_extra)=='')?'2':$object_sql->ad_extra;
205 if (isNumber($object_sql->ad_extra)==0)
206 {
207 $this->set_error("ad_text", _("La précision doit être un chiffre"));
208 }
209 }
210
211 if ($object_sql->ad_type=='select')
212 {
213 if (trim($object_sql->ad_extra)=="")
214 {
215
216 $this->set_error("ad_extra", _("La requête SQL est vide "));
217 }
218 $cn= $this->get_table()->cn;
219 $cn->start();
220 try {
221 // remove SQL command like insert , delete , update, truncate , drop
222 $sql=$object_sql->ad_extra;
223 $sql=str_ireplace("delete", "del.ete", $sql);
224 $sql=str_ireplace("insert", "del.ete", $sql);
225 $sql=str_ireplace("update", "del.ete", $sql);
226 $sql=str_ireplace("truncate", "del.ete", $sql);
227 $sql=str_ireplace("drop", "del.ete", $sql);
228 $cn->exec_sql($sql);
229
230 } catch (\Exception $e) {
231 $this->set_error("ad_extra", _("ERREUR SQL : ")
232 .$object_sql->ad_extra);
233 } finally {
234 $cn->rollback();
235 }
236
237
238 if (preg_match('/^\h*select/i', $object_sql->ad_extra)==0)
239 {
240
241 }
242 }
243 if ( $object_sql->ad_default_order < 11 || $object_sql->ad_default_order > 9998) {
244 $this->set_error("ad_default_order",_("Valeur entre 11 et 9998"));
245 }
246 if ($this->count_error()>0)
247 {
248 return false;
249 }
250 return true;
251 }
252
253 function delete()
254 {
255 $object_sql=$this->get_table();
256
257 if ($object_sql->getp("ad_id")<9000)
258 {
259 throw new Exception(_("Effacement bloqué"));
260 }
261
262 $db=$object_sql->cn;
263 try
264 {
265 $db->start();
266 $sql=$db->exec_sql("delete from fiche_detail where ad_id=$1 ", array($object_sql->ad_id));
267
268 $sql="delete from jnt_fic_attr where ad_id=$1";
269 $res=$db->exec_sql($sql, array($object_sql->ad_id));
270
271 $sql="delete from attr_def where ad_id=$1";
272 $res=$db->exec_sql($sql, array($object_sql->ad_id));
273
274 $object_sql=$this->get_table()->delete();
275 $db->commit();
276 }
277 catch (Exception $ex)
278 {
279 $db->rollback();
280 throw new Exception(_("Effacement bloqué : attribut utilisé"));
281 }
282 }
283
284}
isNumber($p_int)
td($p_string='', $p_extra='')
surround the string with td
Definition ac_common.php:83
_("actif, passif,charge,...")
$ex
manage the table attr_def
input_custom($p_key, $p_value)
For the type custom , we can call a function to display properly the value.
display_row_custom($p_key, $p_value, $p_id=0)
For the type custom , we can call a function to display properly the value.
display_row($row)
Display row of table attr_def.
this an abstract class , all the SQL class, like noalyss_sql (table), Acc_Plan_SQL (based on a SQL no...
Html Input Text member :
Manage the TEXTAREA html element.
A switch let you switch between 2 values : 0 and 1, it is used to replace the check.
show a switch, when you click on it an hidden field is changed, the value is 1 or 0
Purpose is to propose a librairy to display a table content and allow to update and delete row ,...
count_error()
returns the nb of errors found
set_delete_row($p_value)
Enable or disable the deletion of rows.
set_col_sort($p_num)
When adding an element ,we place it thanks the DOM Attribute sort_value set it to -1 if you want one ...
set_property_updatable($p_key, $p_value)
set a column of the data row updatable or not
set_col_tips($p_key, $p_comment)
Set the info for a column, use Icon_Action\infobulle the message are in message_javascript....
set_col_type($p_key, $p_value, $p_array=NULL)
set the type of a column , it will change in the input db box , the select must supply an array of po...
set_update_row($p_value)
Enable or disable the updating of rows.
set_property_visible($p_key, $p_value)
set a column of the data row visible or not
set_error($p_col, $p_message)
set the error message for a wrong input
set_col_label($p_key, $p_display)
set the name to display for a column
$count
if( $delta< 0) elseif( $delta==0)