dolibarr  7.0.0-beta
dict.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
5  * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@capnetworks.com>
6  * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
7  * Copyright (C) 2011-2015 Philippe Grand <philippe.grand@atoo-net.com>
8  * Copyright (C) 2011 Remy Younes <ryounes@gmail.com>
9  * Copyright (C) 2012-2015 Marcos García <marcosgdf@gmail.com>
10  * Copyright (C) 2012 Christophe Battarel <christophe.battarel@ltairis.fr>
11  * Copyright (C) 2011-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
12  * Copyright (C) 2015 Ferran Marcet <fmarcet@2byte.es>
13  * Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
14  *
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program. If not, see <http://www.gnu.org/licenses/>.
27  */
28 
35 require '../main.inc.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
42 if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
43 
44 $langs->load("errors");
45 $langs->load("admin");
46 $langs->load("main");
47 $langs->load("companies");
48 $langs->load("resource");
49 $langs->load("holiday");
50 $langs->load("accountancy");
51 $langs->load("hrm");
52 
53 $action=GETPOST('action','alpha')?GETPOST('action','alpha'):'view';
54 $confirm=GETPOST('confirm','alpha');
55 $id=GETPOST('id','int');
56 $rowid=GETPOST('rowid','alpha');
57 $entity=GETPOST('entity','int');
58 $code=GETPOST('code','alpha');
59 
60 $allowed=$user->admin;
61 if ($id == 7 && ! empty($user->rights->accounting->chartofaccount)) $allowed=1; // Tax page allowed to manager of chart account
62 if ($id == 10 && ! empty($user->rights->accounting->chartofaccount)) $allowed=1; // Vat page allowed to manager of chart account
63 if (! $allowed) accessforbidden();
64 
65 $acts[0] = "activate";
66 $acts[1] = "disable";
67 $actl[0] = img_picto($langs->trans("Disabled"),'switch_off');
68 $actl[1] = img_picto($langs->trans("Activated"),'switch_on');
69 
70 $listoffset=GETPOST('listoffset');
71 $listlimit=GETPOST('listlimit')>0?GETPOST('listlimit'):1000; // To avoid too long dictionaries
72 $active = 1;
73 
74 $sortfield = GETPOST("sortfield",'alpha');
75 $sortorder = GETPOST("sortorder",'alpha');
76 $page = GETPOST("page",'int');
77 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
78 $offset = $listlimit * $page ;
79 $pageprev = $page - 1;
80 $pagenext = $page + 1;
81 
82 $search_country_id = GETPOST('search_country_id','int');
83 if ($search_country_id == '' && ($id == 2 || $id == 3 || $id == 10)) // Not a so good idea to force on current country for all dictionaries. Some tables have entries that are for all countries, we must be able to see them, so this is done for dedicated dictionaries only.
84 {
85  $search_country_id = $mysoc->country_id;
86 }
87 $search_code = GETPOST('search_code','alpha');
88 
89 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
90 $hookmanager->initHooks(array('admin'));
91 
92 // This page is a generic page to edit dictionaries
93 // Put here declaration of dictionaries properties
94 
95 // Sort order to show dictionary (0 is space). All other dictionaries (added by modules) will be at end of this.
96 $taborder=array(9,0,4,3,2,0,1,8,19,16,27,0,5,11,0,33,34,0,6,0,29,0,7,24,28,17,35,36,0,10,23,12,13,0,14,0,22,20,18,21,0,15,30,0,26,0,);
97 
98 // Name of SQL tables of dictionaries
99 $tabname=array();
100 $tabname[1] = MAIN_DB_PREFIX."c_forme_juridique";
101 $tabname[2] = MAIN_DB_PREFIX."c_departements";
102 $tabname[3] = MAIN_DB_PREFIX."c_regions";
103 $tabname[4] = MAIN_DB_PREFIX."c_country";
104 $tabname[5] = MAIN_DB_PREFIX."c_civility";
105 $tabname[6] = MAIN_DB_PREFIX."c_actioncomm";
106 $tabname[7] = MAIN_DB_PREFIX."c_chargesociales";
107 $tabname[8] = MAIN_DB_PREFIX."c_typent";
108 $tabname[9] = MAIN_DB_PREFIX."c_currencies";
109 $tabname[10]= MAIN_DB_PREFIX."c_tva";
110 $tabname[11]= MAIN_DB_PREFIX."c_type_contact";
111 $tabname[12]= MAIN_DB_PREFIX."c_payment_term";
112 $tabname[13]= MAIN_DB_PREFIX."c_paiement";
113 $tabname[14]= MAIN_DB_PREFIX."c_ecotaxe";
114 $tabname[15]= MAIN_DB_PREFIX."c_paper_format";
115 $tabname[16]= MAIN_DB_PREFIX."c_prospectlevel";
116 $tabname[17]= MAIN_DB_PREFIX."c_type_fees";
117 $tabname[18]= MAIN_DB_PREFIX."c_shipment_mode";
118 $tabname[19]= MAIN_DB_PREFIX."c_effectif";
119 $tabname[20]= MAIN_DB_PREFIX."c_input_method";
120 $tabname[21]= MAIN_DB_PREFIX."c_availability";
121 $tabname[22]= MAIN_DB_PREFIX."c_input_reason";
122 $tabname[23]= MAIN_DB_PREFIX."c_revenuestamp";
123 $tabname[24]= MAIN_DB_PREFIX."c_type_resource";
124 //$tabname[25]= MAIN_DB_PREFIX."c_email_templates";
125 $tabname[26]= MAIN_DB_PREFIX."c_units";
126 $tabname[27]= MAIN_DB_PREFIX."c_stcomm";
127 $tabname[28]= MAIN_DB_PREFIX."c_holiday_types";
128 $tabname[29]= MAIN_DB_PREFIX."c_lead_status";
129 $tabname[30]= MAIN_DB_PREFIX."c_format_cards";
130 //$tabname[31]= MAIN_DB_PREFIX."accounting_system";
131 //$tabname[32]= MAIN_DB_PREFIX."c_accounting_category";
132 $tabname[33]= MAIN_DB_PREFIX."c_hrm_department";
133 $tabname[34]= MAIN_DB_PREFIX."c_hrm_function";
134 $tabname[35]= MAIN_DB_PREFIX."c_exp_tax_cat";
135 $tabname[36]= MAIN_DB_PREFIX."c_exp_tax_range";
136 
137 // Dictionary labels
138 $tablib=array();
139 $tablib[1] = "DictionaryCompanyJuridicalType";
140 $tablib[2] = "DictionaryCanton";
141 $tablib[3] = "DictionaryRegion";
142 $tablib[4] = "DictionaryCountry";
143 $tablib[5] = "DictionaryCivility";
144 $tablib[6] = "DictionaryActions";
145 $tablib[7] = "DictionarySocialContributions";
146 $tablib[8] = "DictionaryCompanyType";
147 $tablib[9] = "DictionaryCurrency";
148 $tablib[10]= "DictionaryVAT";
149 $tablib[11]= "DictionaryTypeContact";
150 $tablib[12]= "DictionaryPaymentConditions";
151 $tablib[13]= "DictionaryPaymentModes";
152 $tablib[14]= "DictionaryEcotaxe";
153 $tablib[15]= "DictionaryPaperFormat";
154 $tablib[16]= "DictionaryProspectLevel";
155 $tablib[17]= "DictionaryFees";
156 $tablib[18]= "DictionarySendingMethods";
157 $tablib[19]= "DictionaryStaff";
158 $tablib[20]= "DictionaryOrderMethods";
159 $tablib[21]= "DictionaryAvailability";
160 $tablib[22]= "DictionarySource";
161 $tablib[23]= "DictionaryRevenueStamp";
162 $tablib[24]= "DictionaryResourceType";
163 //$tablib[25]= "DictionaryEMailTemplates";
164 $tablib[26]= "DictionaryUnits";
165 $tablib[27]= "DictionaryProspectStatus";
166 $tablib[28]= "DictionaryHolidayTypes";
167 $tablib[29]= "DictionaryOpportunityStatus";
168 $tablib[30]= "DictionaryFormatCards";
169 //$tablib[31]= "DictionaryAccountancysystem";
170 //$tablib[32]= "DictionaryAccountancyCategory";
171 $tablib[33]= "DictionaryDepartment";
172 $tablib[34]= "DictionaryFunction";
173 $tablib[35]= "DictionaryExpenseTaxCat";
174 $tablib[36]= "DictionaryExpenseTaxRange";
175 
176 // Requests to extract data
177 $tabsql=array();
178 $tabsql[1] = "SELECT f.rowid as rowid, f.code, f.libelle, c.code as country_code, c.label as country, f.active FROM ".MAIN_DB_PREFIX."c_forme_juridique as f, ".MAIN_DB_PREFIX."c_country as c WHERE f.fk_pays=c.rowid";
179 $tabsql[2] = "SELECT d.rowid as rowid, d.code_departement as code, d.nom as libelle, d.fk_region as region_id, r.nom as region, c.code as country_code, c.label as country, d.active FROM ".MAIN_DB_PREFIX."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_country as c WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid and r.active=1 and c.active=1";
180 $tabsql[3] = "SELECT r.rowid as rowid, r.code_region as code, r.nom as libelle, r.fk_pays as country_id, c.code as country_code, c.label as country, r.active FROM ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_country as c WHERE r.fk_pays=c.rowid and c.active=1";
181 $tabsql[4] = "SELECT c.rowid as rowid, c.code, c.label, c.active, c.favorite FROM ".MAIN_DB_PREFIX."c_country AS c";
182 $tabsql[5] = "SELECT c.rowid as rowid, c.code as code, c.label, c.active FROM ".MAIN_DB_PREFIX."c_civility AS c";
183 $tabsql[6] = "SELECT a.id as rowid, a.code as code, a.libelle AS libelle, a.type, a.active, a.module, a.color, a.position FROM ".MAIN_DB_PREFIX."c_actioncomm AS a";
184 $tabsql[7] = "SELECT a.id as rowid, a.code as code, a.libelle AS libelle, a.accountancy_code as accountancy_code, a.deductible, c.code as country_code, c.label as country, a.fk_pays as country_id, a.active FROM ".MAIN_DB_PREFIX."c_chargesociales AS a, ".MAIN_DB_PREFIX."c_country as c WHERE a.fk_pays=c.rowid and c.active=1";
185 $tabsql[8] = "SELECT t.id as rowid, t.code as code, t.libelle, t.fk_country as country_id, c.code as country_code, c.label as country, t.position, t.active FROM ".MAIN_DB_PREFIX."c_typent as t LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON t.fk_country=c.rowid";
186 $tabsql[9] = "SELECT c.code_iso as code, c.label, c.unicode, c.active FROM ".MAIN_DB_PREFIX."c_currencies AS c";
187 $tabsql[10]= "SELECT t.rowid, t.code, t.taux, t.localtax1_type, t.localtax1, t.localtax2_type, t.localtax2, c.label as country, c.code as country_code, t.fk_pays as country_id, t.recuperableonly, t.note, t.active, t.accountancy_code_sell, t.accountancy_code_buy FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c WHERE t.fk_pays=c.rowid";
188 $tabsql[11]= "SELECT t.rowid as rowid, t.element, t.source, t.code, t.libelle, t.position, t.active FROM ".MAIN_DB_PREFIX."c_type_contact AS t";
189 $tabsql[12]= "SELECT c.rowid as rowid, c.code, c.libelle, c.libelle_facture, c.nbjour, c.type_cdr, c.decalage, c.active, c.sortorder, c.entity FROM ".MAIN_DB_PREFIX."c_payment_term AS c WHERE c.entity = " . getEntity($tabname[12]);
190 $tabsql[13]= "SELECT c.id as rowid, c.code, c.libelle, c.type, c.active, c.accountancy_code, c.entity FROM ".MAIN_DB_PREFIX."c_paiement AS c WHERE c.entity = " . getEntity($tabname[13]);
191 $tabsql[14]= "SELECT e.rowid as rowid, e.code as code, e.libelle, e.price, e.organization, e.fk_pays as country_id, c.code as country_code, c.label as country, e.active FROM ".MAIN_DB_PREFIX."c_ecotaxe AS e, ".MAIN_DB_PREFIX."c_country as c WHERE e.fk_pays=c.rowid and c.active=1";
192 $tabsql[15]= "SELECT rowid as rowid, code, label as libelle, width, height, unit, active FROM ".MAIN_DB_PREFIX."c_paper_format";
193 $tabsql[16]= "SELECT code, label as libelle, sortorder, active FROM ".MAIN_DB_PREFIX."c_prospectlevel";
194 $tabsql[17]= "SELECT id as rowid, code, label, accountancy_code, active FROM ".MAIN_DB_PREFIX."c_type_fees";
195 $tabsql[18]= "SELECT rowid as rowid, code, libelle, tracking, active FROM ".MAIN_DB_PREFIX."c_shipment_mode";
196 $tabsql[19]= "SELECT id as rowid, code, libelle, active FROM ".MAIN_DB_PREFIX."c_effectif";
197 $tabsql[20]= "SELECT rowid as rowid, code, libelle, active FROM ".MAIN_DB_PREFIX."c_input_method";
198 $tabsql[21]= "SELECT c.rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_availability AS c";
199 $tabsql[22]= "SELECT rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_input_reason";
200 $tabsql[23]= "SELECT t.rowid as rowid, t.taux, t.revenuestamp_type, c.label as country, c.code as country_code, t.fk_pays as country_id, t.note, t.active, t.accountancy_code_sell, t.accountancy_code_buy FROM ".MAIN_DB_PREFIX."c_revenuestamp as t, ".MAIN_DB_PREFIX."c_country as c WHERE t.fk_pays=c.rowid";
201 $tabsql[24]= "SELECT rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_type_resource";
202 //$tabsql[25]= "SELECT rowid as rowid, label, type_template, private, position, topic, content_lines, content, active FROM ".MAIN_DB_PREFIX."c_email_templates WHERE entity IN (".getEntity('email_template').")";
203 $tabsql[26]= "SELECT rowid as rowid, code, label, short_label, active FROM ".MAIN_DB_PREFIX."c_units";
204 $tabsql[27]= "SELECT id as rowid, code, libelle, active FROM ".MAIN_DB_PREFIX."c_stcomm";
205 $tabsql[28]= "SELECT h.rowid as rowid, h.code, h.label, h.affect, h.delay, h.newbymonth, h.fk_country as country_id, c.code as country_code, c.label as country, h.active FROM ".MAIN_DB_PREFIX."c_holiday_types as h LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON h.fk_country=c.rowid";
206 $tabsql[29]= "SELECT rowid as rowid, code, label, percent, position, active FROM ".MAIN_DB_PREFIX."c_lead_status";
207 $tabsql[30]= "SELECT rowid, code, name, paper_size, orientation, metric, leftmargin, topmargin, nx, ny, spacex, spacey, width, height, font_size, custom_x, custom_y, active FROM ".MAIN_DB_PREFIX."c_format_cards";
208 //$tabsql[31]= "SELECT s.rowid as rowid, pcg_version, s.label, s.active FROM ".MAIN_DB_PREFIX."accounting_system as s";
209 //$tabsql[32]= "SELECT a.rowid as rowid, a.code as code, a.label, a.range_account, a.sens, a.category_type, a.formula, a.position as position, a.fk_country as country_id, c.code as country_code, c.label as country, a.active FROM ".MAIN_DB_PREFIX."c_accounting_category as a, ".MAIN_DB_PREFIX."c_country as c WHERE a.fk_country=c.rowid and c.active=1";
210 $tabsql[33]= "SELECT rowid, pos, code, label, active FROM ".MAIN_DB_PREFIX."c_hrm_department";
211 $tabsql[34]= "SELECT rowid, pos, code, label, c_level, active FROM ".MAIN_DB_PREFIX."c_hrm_function";
212 $tabsql[35]= "SELECT c.rowid, c.label, c.active, c.entity FROM ".MAIN_DB_PREFIX."c_exp_tax_cat c";
213 $tabsql[36]= "SELECT r.rowid, r.fk_c_exp_tax_cat, r.range_ik, r.active, r.entity FROM ".MAIN_DB_PREFIX."c_exp_tax_range r";
214 
215 // Criteria to sort dictionaries
216 $tabsqlsort=array();
217 $tabsqlsort[1] ="country ASC, code ASC";
218 $tabsqlsort[2] ="country ASC, code ASC";
219 $tabsqlsort[3] ="country ASC, code ASC";
220 $tabsqlsort[4] ="code ASC";
221 $tabsqlsort[5] ="label ASC";
222 $tabsqlsort[6] ="a.type ASC, a.module ASC, a.position ASC, a.code ASC";
223 $tabsqlsort[7] ="country ASC, code ASC, a.libelle ASC";
224 $tabsqlsort[8] ="country DESC,".(! empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?' t.position ASC,':'')." libelle ASC";
225 $tabsqlsort[9] ="label ASC";
226 $tabsqlsort[10]="country ASC, code ASC, taux ASC, recuperableonly ASC, localtax1 ASC, localtax2 ASC";
227 $tabsqlsort[11]="t.element ASC, t.source ASC, t.position ASC, t.code ASC";
228 $tabsqlsort[12]="sortorder ASC, code ASC";
229 $tabsqlsort[13]="code ASC";
230 $tabsqlsort[14]="country ASC, e.organization ASC, code ASC";
231 $tabsqlsort[15]="rowid ASC";
232 $tabsqlsort[16]="sortorder ASC";
233 $tabsqlsort[17]="code ASC";
234 $tabsqlsort[18]="code ASC, libelle ASC";
235 $tabsqlsort[19]="id ASC";
236 $tabsqlsort[20]="code ASC, libelle ASC";
237 $tabsqlsort[21]="code ASC, label ASC";
238 $tabsqlsort[22]="code ASC, label ASC";
239 $tabsqlsort[23]="country ASC, taux ASC";
240 $tabsqlsort[24]="code ASC,label ASC";
241 //$tabsqlsort[25]="label ASC";
242 $tabsqlsort[26]="code ASC";
243 $tabsqlsort[27]="code ASC";
244 $tabsqlsort[28]="country ASC, code ASC";
245 $tabsqlsort[29]="position ASC";
246 $tabsqlsort[30]="code ASC";
247 //$tabsqlsort[31]="pcg_version ASC";
248 //$tabsqlsort[32]="position ASC";
249 $tabsqlsort[33]="code ASC";
250 $tabsqlsort[34]="code ASC";
251 $tabsqlsort[35]="c.label ASC";
252 $tabsqlsort[36]="r.fk_c_exp_tax_cat ASC, r.range_ik ASC";
253 
254 // Nom des champs en resultat de select pour affichage du dictionnaire
255 $tabfield=array();
256 $tabfield[1] = "code,libelle,country";
257 $tabfield[2] = "code,libelle,region_id,region,country"; // "code,libelle,region,country_code-country"
258 $tabfield[3] = "code,libelle,country_id,country";
259 $tabfield[4] = "code,label";
260 $tabfield[5] = "code,label";
261 $tabfield[6] = "code,libelle,type,color,position";
262 $tabfield[7] = "code,libelle,country,accountancy_code,deductible";
263 $tabfield[8] = "code,libelle,country_id,country".(! empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?',position':'');
264 $tabfield[9] = "code,label,unicode";
265 $tabfield[10]= "country_id,country,code,taux,localtax1_type,localtax1,localtax2_type,localtax2,recuperableonly,accountancy_code_sell,accountancy_code_buy,note";
266 $tabfield[11]= "element,source,code,libelle,position";
267 $tabfield[12]= "code,libelle,libelle_facture,nbjour,type_cdr,decalage,sortorder,entity";
268 $tabfield[13]= "code,libelle,type,accountancy_code,entity";
269 $tabfield[14]= "code,libelle,price,organization,country_id,country";
270 $tabfield[15]= "code,libelle,width,height,unit";
271 $tabfield[16]= "code,libelle,sortorder";
272 $tabfield[17]= "code,label,accountancy_code";
273 $tabfield[18]= "code,libelle,tracking";
274 $tabfield[19]= "code,libelle";
275 $tabfield[20]= "code,libelle";
276 $tabfield[21]= "code,label";
277 $tabfield[22]= "code,label";
278 $tabfield[23]= "country_id,country,taux,revenuestamp_type,accountancy_code_sell,accountancy_code_buy,note";
279 $tabfield[24]= "code,label";
280 //$tabfield[25]= "label,type_template,private,position,topic,content_lines,content";
281 $tabfield[26]= "code,label,short_label";
282 $tabfield[27]= "code,libelle";
283 $tabfield[28]= "code,label,affect,delay,newbymonth,country_id,country";
284 $tabfield[29]= "code,label,percent,position";
285 $tabfield[30]= "code,name,paper_size,orientation,metric,leftmargin,topmargin,nx,ny,spacex,spacey,width,height,font_size,custom_x,custom_y";
286 //$tabfield[31]= "pcg_version,label";
287 //$tabfield[32]= "code,label,range_account,sens,category_type,formula,position,country_id,country";
288 $tabfield[33]= "code,label";
289 $tabfield[34]= "code,label";
290 $tabfield[35]= "label";
291 $tabfield[36]= "range_ik,fk_c_exp_tax_cat";
292 
293 // Nom des champs d'edition pour modification d'un enregistrement
294 $tabfieldvalue=array();
295 $tabfieldvalue[1] = "code,libelle,country";
296 $tabfieldvalue[2] = "code,libelle,region"; // "code,libelle,region"
297 $tabfieldvalue[3] = "code,libelle,country";
298 $tabfieldvalue[4] = "code,label";
299 $tabfieldvalue[5] = "code,label";
300 $tabfieldvalue[6] = "code,libelle,type,color,position";
301 $tabfieldvalue[7] = "code,libelle,country,accountancy_code,deductible";
302 $tabfieldvalue[8] = "code,libelle,country".(! empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?',position':'');
303 $tabfieldvalue[9] = "code,label,unicode";
304 $tabfieldvalue[10]= "country,code,taux,localtax1_type,localtax1,localtax2_type,localtax2,recuperableonly,accountancy_code_sell,accountancy_code_buy,note";
305 $tabfieldvalue[11]= "element,source,code,libelle,position";
306 $tabfieldvalue[12]= "code,libelle,libelle_facture,nbjour,type_cdr,decalage,sortorder";
307 $tabfieldvalue[13]= "code,libelle,type,accountancy_code";
308 $tabfieldvalue[14]= "code,libelle,price,organization,country";
309 $tabfieldvalue[15]= "code,libelle,width,height,unit";
310 $tabfieldvalue[16]= "code,libelle,sortorder";
311 $tabfieldvalue[17]= "code,label,accountancy_code";
312 $tabfieldvalue[18]= "code,libelle,tracking";
313 $tabfieldvalue[19]= "code,libelle";
314 $tabfieldvalue[20]= "code,libelle";
315 $tabfieldvalue[21]= "code,label";
316 $tabfieldvalue[22]= "code,label";
317 $tabfieldvalue[23]= "country,taux,revenuestamp_type,accountancy_code_sell,accountancy_code_buy,note";
318 $tabfieldvalue[24]= "code,label";
319 //$tabfieldvalue[25]= "label,type_template,private,position,topic,content_lines,content";
320 $tabfieldvalue[26]= "code,label,short_label";
321 $tabfieldvalue[27]= "code,libelle";
322 $tabfieldvalue[28]= "code,label,affect,delay,newbymonth,country";
323 $tabfieldvalue[29]= "code,label,percent,position";
324 $tabfieldvalue[30]= "code,name,paper_size,orientation,metric,leftmargin,topmargin,nx,ny,spacex,spacey,width,height,font_size,custom_x,custom_y";
325 //$tabfieldvalue[31]= "pcg_version,label";
326 //$tabfieldvalue[32]= "code,label,range_account,sens,category_type,formula,position,country";
327 $tabfieldvalue[33]= "code,label";
328 $tabfieldvalue[34]= "code,label";
329 $tabfieldvalue[35]= "label";
330 $tabfieldvalue[36]= "range_ik,fk_c_exp_tax_cat";
331 
332 // Nom des champs dans la table pour insertion d'un enregistrement
333 $tabfieldinsert=array();
334 $tabfieldinsert[1] = "code,libelle,fk_pays";
335 $tabfieldinsert[2] = "code_departement,nom,fk_region";
336 $tabfieldinsert[3] = "code_region,nom,fk_pays";
337 $tabfieldinsert[4] = "code,label";
338 $tabfieldinsert[5] = "code,label";
339 $tabfieldinsert[6] = "code,libelle,type,color,position";
340 $tabfieldinsert[7] = "code,libelle,fk_pays,accountancy_code,deductible";
341 $tabfieldinsert[8] = "code,libelle,fk_country".(! empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?',position':'');
342 $tabfieldinsert[9] = "code_iso,label,unicode";
343 $tabfieldinsert[10]= "fk_pays,code,taux,localtax1_type,localtax1,localtax2_type,localtax2,recuperableonly,accountancy_code_sell,accountancy_code_buy,note";
344 $tabfieldinsert[11]= "element,source,code,libelle,position";
345 $tabfieldinsert[12]= "code,libelle,libelle_facture,nbjour,type_cdr,decalage,sortorder,entity";
346 $tabfieldinsert[13]= "code,libelle,type,accountancy_code,entity";
347 $tabfieldinsert[14]= "code,libelle,price,organization,fk_pays";
348 $tabfieldinsert[15]= "code,label,width,height,unit";
349 $tabfieldinsert[16]= "code,label,sortorder";
350 $tabfieldinsert[17]= "code,label,accountancy_code";
351 $tabfieldinsert[18]= "code,libelle,tracking";
352 $tabfieldinsert[19]= "code,libelle";
353 $tabfieldinsert[20]= "code,libelle";
354 $tabfieldinsert[21]= "code,label";
355 $tabfieldinsert[22]= "code,label";
356 $tabfieldinsert[23]= "fk_pays,taux,revenuestamp_type,accountancy_code_sell,accountancy_code_buy,note";
357 $tabfieldinsert[24]= "code,label";
358 //$tabfieldinsert[25]= "label,type_template,private,position,topic,content_lines,content,entity";
359 $tabfieldinsert[26]= "code,label,short_label";
360 $tabfieldinsert[27]= "code,libelle";
361 $tabfieldinsert[28]= "code,label,affect,delay,newbymonth,fk_country";
362 $tabfieldinsert[29]= "code,label,percent,position";
363 $tabfieldinsert[30]= "code,name,paper_size,orientation,metric,leftmargin,topmargin,nx,ny,spacex,spacey,width,height,font_size,custom_x,custom_y";
364 //$tabfieldinsert[31]= "pcg_version,label";
365 //$tabfieldinsert[32]= "code,label,range_account,sens,category_type,formula,position,fk_country";
366 $tabfieldinsert[33]= "code,label";
367 $tabfieldinsert[34]= "code,label";
368 $tabfieldinsert[35]= "label";
369 $tabfieldinsert[36]= "range_ik,fk_c_exp_tax_cat";
370 
371 // Nom du rowid si le champ n'est pas de type autoincrement
372 // Example: "" if id field is "rowid" and has autoincrement on
373 // "nameoffield" if id field is not "rowid" or has not autoincrement on
374 $tabrowid=array();
375 $tabrowid[1] = "";
376 $tabrowid[2] = "";
377 $tabrowid[3] = "";
378 $tabrowid[4] = "rowid";
379 $tabrowid[5] = "rowid";
380 $tabrowid[6] = "id";
381 $tabrowid[7] = "id";
382 $tabrowid[8] = "id";
383 $tabrowid[9] = "code_iso";
384 $tabrowid[10]= "";
385 $tabrowid[11]= "rowid";
386 $tabrowid[12]= "rowid";
387 $tabrowid[13]= "id";
388 $tabrowid[14]= "";
389 $tabrowid[15]= "";
390 $tabrowid[16]= "code";
391 $tabrowid[17]= "id";
392 $tabrowid[18]= "rowid";
393 $tabrowid[19]= "id";
394 $tabrowid[20]= "";
395 $tabrowid[21]= "rowid";
396 $tabrowid[22]= "rowid";
397 $tabrowid[23]= "";
398 $tabrowid[24]= "";
399 //$tabrowid[25]= "";
400 $tabrowid[26]= "";
401 $tabrowid[27]= "id";
402 $tabrowid[28]= "";
403 $tabrowid[29]= "";
404 $tabrowid[30]= "";
405 //$tabrowid[31]= "";
406 //$tabrowid[32]= "";
407 $tabrowid[33]= "rowid";
408 $tabrowid[34]= "rowid";
409 $tabrowid[35]= "";
410 $tabrowid[36]= "";
411 
412 // Condition to show dictionary in setup page
413 $tabcond=array();
414 $tabcond[1] = (! empty($conf->societe->enabled));
415 $tabcond[2] = true;
416 $tabcond[3] = true;
417 $tabcond[4] = true;
418 $tabcond[5] = (! empty($conf->societe->enabled) || ! empty($conf->adherent->enabled));
419 $tabcond[6] = ! empty($conf->agenda->enabled);
420 $tabcond[7] = ! empty($conf->tax->enabled);
421 $tabcond[8] = ! empty($conf->societe->enabled);
422 $tabcond[9] = true;
423 $tabcond[10]= true;
424 $tabcond[11]= (! empty($conf->societe->enabled));
425 $tabcond[12]= (! empty($conf->commande->enabled) || ! empty($conf->propal->enabled) || ! empty($conf->facture->enabled) || ! empty($conf->fournisseur->enabled));
426 $tabcond[13]= (! empty($conf->commande->enabled) || ! empty($conf->propal->enabled) || ! empty($conf->facture->enabled) || ! empty($conf->fournisseur->enabled));
427 $tabcond[14]= (! empty($conf->product->enabled) && ! empty($conf->ecotax->enabled));
428 $tabcond[15]= true;
429 $tabcond[16]= (! empty($conf->societe->enabled) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS));
430 $tabcond[17]= (! empty($conf->deplacement->enabled) || ! empty($conf->expensereport->enabled));
431 $tabcond[18]= ! empty($conf->expedition->enabled);
432 $tabcond[19]= ! empty($conf->societe->enabled);
433 $tabcond[20]= ! empty($conf->fournisseur->enabled);
434 $tabcond[21]= ! empty($conf->propal->enabled);
435 $tabcond[22]= (! empty($conf->commande->enabled) || ! empty($conf->propal->enabled));
436 $tabcond[23]= true;
437 $tabcond[24]= ! empty($conf->resource->enabled);
438 //$tabcond[25]= true; // && ! empty($conf->global->MAIN_EMAIL_EDIT_TEMPLATE_FROM_DIC);
439 $tabcond[26]= ! empty($conf->product->enabled);
440 $tabcond[27]= ! empty($conf->societe->enabled);
441 $tabcond[28]= ! empty($conf->holiday->enabled);
442 $tabcond[29]= ! empty($conf->projet->enabled);
443 $tabcond[30]= ! empty($conf->label->enabled);
444 //$tabcond[31]= ! empty($conf->accounting->enabled);
445 //$tabcond[32]= ! empty($conf->accounting->enabled);
446 $tabcond[33]= ! empty($conf->hrm->enabled);
447 $tabcond[34]= ! empty($conf->hrm->enabled);
448 $tabcond[35]= ! empty($conf->expensereport->enabled);
449 $tabcond[36]= ! empty($conf->expensereport->enabled);
450 
451 // List of help for fields
452 $tabhelp=array();
453 $tabhelp[1] = array('code'=>$langs->trans("EnterAnyCode"));
454 $tabhelp[2] = array('code'=>$langs->trans("EnterAnyCode"));
455 $tabhelp[3] = array('code'=>$langs->trans("EnterAnyCode"));
456 $tabhelp[4] = array('code'=>$langs->trans("EnterAnyCode"));
457 $tabhelp[5] = array('code'=>$langs->trans("EnterAnyCode"));
458 $tabhelp[6] = array('code'=>$langs->trans("EnterAnyCode"), 'color'=>$langs->trans("ColorFormat"), 'position'=>$langs->trans("PositionIntoComboList"));
459 $tabhelp[7] = array('code'=>$langs->trans("EnterAnyCode"));
460 $tabhelp[8] = array('code'=>$langs->trans("EnterAnyCode"), 'position'=>$langs->trans("PositionIntoComboList"));
461 $tabhelp[9] = array('code'=>$langs->trans("EnterAnyCode"), 'unicode'=>$langs->trans("UnicodeCurrency"));
462 $tabhelp[10] = array('code'=>$langs->trans("EnterAnyCode"), 'taux'=>$langs->trans("SellTaxRate"), 'recuperableonly'=>$langs->trans("RecuperableOnly"), 'localtax1_type'=>$langs->trans("LocalTaxDesc"), 'localtax2_type'=>$langs->trans("LocalTaxDesc"));
463 $tabhelp[11] = array('code'=>$langs->trans("EnterAnyCode"), 'position'=>$langs->trans("PositionIntoComboList"));
464 $tabhelp[12] = array('code'=>$langs->trans("EnterAnyCode"), 'type_cdr'=>$langs->trans("TypeCdr"));
465 $tabhelp[13] = array('code'=>$langs->trans("EnterAnyCode"));
466 $tabhelp[14] = array('code'=>$langs->trans("EnterAnyCode"));
467 $tabhelp[15] = array('code'=>$langs->trans("EnterAnyCode"));
468 $tabhelp[16] = array('code'=>$langs->trans("EnterAnyCode"));
469 $tabhelp[17] = array('code'=>$langs->trans("EnterAnyCode"));
470 $tabhelp[18] = array('code'=>$langs->trans("EnterAnyCode"), 'tracking'=>$langs->trans("UrlTrackingDesc"));
471 $tabhelp[19] = array('code'=>$langs->trans("EnterAnyCode"));
472 $tabhelp[20] = array('code'=>$langs->trans("EnterAnyCode"));
473 $tabhelp[21] = array('code'=>$langs->trans("EnterAnyCode"));
474 $tabhelp[22] = array('code'=>$langs->trans("EnterAnyCode"));
475 $tabhelp[23] = array('revenuestamp_type'=>'FixedOfPercent');
476 $tabhelp[24] = array('code'=>$langs->trans("EnterAnyCode"));
477 //$tabhelp[25] = array('topic'=>$langs->trans('SeeSubstitutionVars'),'content'=>$langs->trans('SeeSubstitutionVars'),'content_lines'=>$langs->trans('SeeSubstitutionVars'),'type_template'=>$langs->trans("TemplateForElement"),'private'=>$langs->trans("TemplateIsVisibleByOwnerOnly"), 'position'=>$langs->trans("PositionIntoComboList"));
478 $tabhelp[26] = array('code'=>$langs->trans("EnterAnyCode"));
479 $tabhelp[27] = array('code'=>$langs->trans("EnterAnyCode"));
480 $tabhelp[28] = array('affect'=>$langs->trans("FollowedByACounter"),'delay'=>$langs->trans("MinimumNoticePeriod"), 'newbymonth'=>$langs->trans("NbAddedAutomatically"));
481 $tabhelp[29] = array('code'=>$langs->trans("EnterAnyCode"), 'percent'=>$langs->trans("OpportunityPercent"), 'position'=>$langs->trans("PositionIntoComboList"));
482 $tabhelp[30] = array('code'=>$langs->trans("EnterAnyCode"), 'name'=>$langs->trans("LabelName"), 'paper_size'=>$langs->trans("LabelPaperSize"));
483 //$tabhelp[31] = array('pcg_version'=>$langs->trans("EnterAnyCode"));
484 //$tabhelp[32] = array('code'=>$langs->trans("EnterAnyCode"));
485 $tabhelp[33] = array('code'=>$langs->trans("EnterAnyCode"));
486 $tabhelp[34] = array('code'=>$langs->trans("EnterAnyCode"));
487 $tabhelp[35]= array();
488 $tabhelp[36]= array('range_ik'=>$langs->trans('PrevRangeToThisRange'));
489 
490 // List of check for fields (NOT USED YET)
491 $tabfieldcheck=array();
492 $tabfieldcheck[1] = array();
493 $tabfieldcheck[2] = array();
494 $tabfieldcheck[3] = array();
495 $tabfieldcheck[4] = array();
496 $tabfieldcheck[5] = array();
497 $tabfieldcheck[6] = array();
498 $tabfieldcheck[7] = array();
499 $tabfieldcheck[8] = array();
500 $tabfieldcheck[9] = array();
501 $tabfieldcheck[10] = array();
502 $tabfieldcheck[11] = array();
503 $tabfieldcheck[12] = array();
504 $tabfieldcheck[13] = array();
505 $tabfieldcheck[14] = array();
506 $tabfieldcheck[15] = array();
507 $tabfieldcheck[16] = array();
508 $tabfieldcheck[17] = array();
509 $tabfieldcheck[18] = array();
510 $tabfieldcheck[19] = array();
511 $tabfieldcheck[20] = array();
512 $tabfieldcheck[21] = array();
513 $tabfieldcheck[22] = array();
514 $tabfieldcheck[23] = array();
515 $tabfieldcheck[24] = array();
516 //$tabfieldcheck[25] = array();
517 $tabfieldcheck[26] = array();
518 $tabfieldcheck[27] = array();
519 $tabfieldcheck[28] = array();
520 $tabfieldcheck[29] = array();
521 $tabfieldcheck[30] = array();
522 //$tabfieldcheck[31] = array();
523 //$tabfieldcheck[32] = array();
524 $tabfieldcheck[33] = array();
525 $tabfieldcheck[34] = array();
526 $tabfieldcheck[35]= array();
527 $tabfieldcheck[36]= array();
528 
529 // Complete all arrays with entries found into modules
530 complete_dictionary_with_modules($taborder,$tabname,$tablib,$tabsql,$tabsqlsort,$tabfield,$tabfieldvalue,$tabfieldinsert,$tabrowid,$tabcond,$tabhelp,$tabfieldcheck);
531 
532 
533 // Defaut sortorder
534 if (empty($sortfield))
535 {
536  $tmp1 = explode(',',$tabsqlsort[$id]);
537  $tmp2 = explode(' ',$tmp1[0]);
538  $sortfield=preg_replace('/^.*\./', '', $tmp2[0]);
539 }
540 
541 // Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact")
542 $elementList = array();
543 $sourceList=array();
544 if ($id == 11)
545 {
546  $langs->load("orders");
547  $langs->load("contracts");
548  $langs->load("projects");
549  $langs->load("propal");
550  $langs->load("bills");
551  $langs->load("interventions");
552  $elementList = array(
553  '' => '',
554  'societe' => $langs->trans('ThirdParty'),
555 // 'proposal' => $langs->trans('Proposal'),
556 // 'order' => $langs->trans('Order'),
557 // 'invoice' => $langs->trans('Bill'),
558  'invoice_supplier' => $langs->trans('SupplierBill'),
559  'order_supplier' => $langs->trans('SupplierOrder'),
560 // 'intervention' => $langs->trans('InterventionCard'),
561 // 'contract' => $langs->trans('Contract'),
562  'project' => $langs->trans('Project'),
563  'project_task' => $langs->trans('Task'),
564  'agenda' => $langs->trans('Agenda'),
565  // old deprecated
566  'contrat' => $langs->trans('Contract'),
567  'propal' => $langs->trans('Proposal'),
568  'commande' => $langs->trans('Order'),
569  'facture' => $langs->trans('Bill'),
570  'resource' => $langs->trans('Resource'),
571 // 'facture_fourn' => $langs->trans('SupplierBill'),
572  'fichinter' => $langs->trans('InterventionCard')
573  );
574  if (! empty($conf->global->MAIN_SUPPORT_SHARED_CONTACT_BETWEEN_THIRDPARTIES)) $elementList["societe"] = $langs->trans('ThirdParty');
575 
576  complete_elementList_with_modules($elementList);
577 
578  asort($elementList);
579  $sourceList = array(
580  'internal' => $langs->trans('Internal'),
581  'external' => $langs->trans('External')
582  );
583 }
584 
585 // Define localtax_typeList (used for dictionary "llx_c_tva")
586 $localtax_typeList = array();
587 if ($id == 10)
588 {
589  $localtax_typeList = array(
590  "0" => $langs->trans("No"),
591  "1" => $langs->trans("Yes").' ('.$langs->trans("Type")." 1)", //$langs->trans("%ageOnAllWithoutVAT"),
592  "2" => $langs->trans("Yes").' ('.$langs->trans("Type")." 2)", //$langs->trans("%ageOnAllBeforeVAT"),
593  "3" => $langs->trans("Yes").' ('.$langs->trans("Type")." 3)", //$langs->trans("%ageOnProductsWithoutVAT"),
594  "4" => $langs->trans("Yes").' ('.$langs->trans("Type")." 4)", //$langs->trans("%ageOnProductsBeforeVAT"),
595  "5" => $langs->trans("Yes").' ('.$langs->trans("Type")." 5)", //$langs->trans("%ageOnServiceWithoutVAT"),
596  "6" => $langs->trans("Yes").' ('.$langs->trans("Type")." 6)" //$langs->trans("%ageOnServiceBeforeVAT"),
597  );
598 }
599 
600 
601 
602 /*
603  * Actions
604  */
605 
606 if (GETPOST('button_removefilter') || GETPOST('button_removefilter.x') || GETPOST('button_removefilter_x'))
607 {
608  $search_country_id = '';
609  $search_code = '';
610 }
611 
612 // Actions add or modify an entry into a dictionary
613 if (GETPOST('actionadd') || GETPOST('actionmodify'))
614 {
615  $listfield=explode(',', str_replace(' ', '',$tabfield[$id]));
616  $listfieldinsert=explode(',',$tabfieldinsert[$id]);
617  $listfieldmodify=explode(',',$tabfieldinsert[$id]);
618  $listfieldvalue=explode(',',$tabfieldvalue[$id]);
619 
620  // Check that all fields are filled
621  $ok=1;
622  foreach ($listfield as $f => $value)
623  {
624  if ($value == 'country_id' && in_array($tablib[$id],array('DictionaryVAT','DictionaryRegion','DictionaryCompanyType','DictionaryHolidayTypes','DictionaryRevenueStamp','DictionaryAccountancysystem','DictionaryAccountancyCategory'))) continue; // For some pages, country is not mandatory
625  if ($value == 'country' && in_array($tablib[$id],array('DictionaryCanton','DictionaryCompanyType','DictionaryRevenueStamp'))) continue; // For some pages, country is not mandatory
626  if ($value == 'localtax1' && empty($_POST['localtax1_type'])) continue;
627  if ($value == 'localtax2' && empty($_POST['localtax2_type'])) continue;
628  if ($value == 'color' && empty($_POST['color'])) continue;
629  if ($value == 'formula' && empty($_POST['formula'])) continue;
630  if ($value == 'sortorder') continue; // For a column name 'sortorder', we use the field name 'position'
631  if ((! isset($_POST[$value]) || $_POST[$value]=='')
632  && (! in_array($listfield[$f], array('decalage','module','accountancy_code','accountancy_code_sell','accountancy_code_buy')) // Fields that are not mandatory
633  && (! ($id == 10 && $listfield[$f] == 'code')) // Code is mandatory fir table 10
634  )
635  )
636  {
637  $ok=0;
638  $fieldnamekey=$listfield[$f];
639  // We take translate key of field
640  if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) $fieldnamekey='Label';
641  if ($fieldnamekey == 'libelle_facture') $fieldnamekey = 'LabelOnDocuments';
642  if ($fieldnamekey == 'nbjour') $fieldnamekey='NbOfDays';
643  if ($fieldnamekey == 'decalage') $fieldnamekey='Offset';
644  if ($fieldnamekey == 'module') $fieldnamekey='Module';
645  if ($fieldnamekey == 'code') $fieldnamekey = 'Code';
646  if ($fieldnamekey == 'note') $fieldnamekey = 'Note';
647  if ($fieldnamekey == 'taux') $fieldnamekey = 'Rate';
648  if ($fieldnamekey == 'type') $fieldnamekey = 'Type';
649  if ($fieldnamekey == 'position') $fieldnamekey = 'Position';
650  if ($fieldnamekey == 'unicode') $fieldnamekey = 'Unicode';
651  if ($fieldnamekey == 'deductible') $fieldnamekey = 'Deductible';
652  if ($fieldnamekey == 'sortorder') $fieldnamekey = 'SortOrder';
653  if ($fieldnamekey == 'category_type') $fieldnamekey = 'Calculated';
654  if ($fieldnamekey == 'revenuestamp_type') $fieldnamekey = 'TypeOfRevenueStamp';
655 
656  setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
657  }
658  }
659  // Other checks
660  if (GETPOST('actionadd') && $tabname[$id] == MAIN_DB_PREFIX."c_actioncomm" && isset($_POST["type"]) && in_array($_POST["type"],array('system','systemauto'))) {
661  $ok=0;
662  setEventMessages($langs->transnoentities('ErrorReservedTypeSystemSystemAuto'), null, 'errors');
663  }
664  if (isset($_POST["code"]))
665  {
666  if ($_POST["code"]=='0')
667  {
668  $ok=0;
669  setEventMessages($langs->transnoentities('ErrorCodeCantContainZero'), null, 'errors');
670  }
671  /*if (!is_numeric($_POST['code'])) // disabled, code may not be in numeric base
672  {
673  $ok = 0;
674  $msg .= $langs->transnoentities('ErrorFieldFormat', $langs->transnoentities('Code')).'<br>';
675  }*/
676  }
677  if (isset($_POST["country"]) && ($_POST["country"]=='0') && ($id != 2))
678  {
679  if (in_array($tablib[$id],array('DictionaryCompanyType','DictionaryHolidayTypes'))) // Field country is no mandatory for such dictionaries
680  {
681  $_POST["country"]='';
682  }
683  else
684  {
685  $ok=0;
686  setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->transnoentities("Country")), null, 'errors');
687  }
688  }
689  if ($id == 3 && ! is_numeric($_POST["code"]))
690  {
691  $ok=0;
692  setEventMessages($langs->transnoentities("ErrorFieldMustBeANumeric",$langs->transnoentities("Code")), null, 'errors');
693  }
694 
695  // Clean some parameters
696  if ((! empty($_POST["localtax1_type"]) || ($_POST['localtax1_type'] == '0')) && empty($_POST["localtax1"])) $_POST["localtax1"]='0'; // If empty, we force to 0
697  if ((! empty($_POST["localtax2_type"]) || ($_POST['localtax2_type'] == '0')) && empty($_POST["localtax2"])) $_POST["localtax2"]='0'; // If empty, we force to 0
698  if ($_POST["accountancy_code"] <= 0) $_POST["accountancy_code"]=''; // If empty, we force to null
699  if ($_POST["accountancy_code_sell"] <= 0) $_POST["accountancy_code_sell"]=''; // If empty, we force to null
700  if ($_POST["accountancy_code_buy"] <= 0) $_POST["accountancy_code_buy"]=''; // If empty, we force to null
701  if ($id == 10 && isset($_POST["code"])) // Spaces are not allowed into code
702  {
703  $_POST["code"]=preg_replace('/\s/','',$_POST["code"]);
704  }
705 
706  // Si verif ok et action add, on ajoute la ligne
707  if ($ok && GETPOST('actionadd'))
708  {
709  if ($tabrowid[$id])
710  {
711  // Recupere id libre pour insertion
712  $newid=0;
713  $sql = "SELECT max(".$tabrowid[$id].") newid from ".$tabname[$id];
714  $result = $db->query($sql);
715  if ($result)
716  {
717  $obj = $db->fetch_object($result);
718  $newid=($obj->newid + 1);
719 
720  } else {
721  dol_print_error($db);
722  }
723  }
724 
725  // Add new entry
726  $sql = "INSERT INTO ".$tabname[$id]." (";
727  // List of fields
728  if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
729  $sql.= $tabrowid[$id].",";
730  $sql.= $tabfieldinsert[$id];
731  $sql.=",active)";
732  $sql.= " VALUES(";
733 
734  // List of values
735  if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
736  $sql.= $newid.",";
737  $i=0;
738  foreach ($listfieldinsert as $f => $value)
739  {
740  if ($value == 'price' || preg_match('/^amount/i',$value) || $value == 'taux') {
741  $_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]],'MU');
742  }
743  else if ($value == 'entity') {
744  $_POST[$listfieldvalue[$i]] = getEntity($tabname[$id]);
745  }
746  if ($i) $sql.=",";
747  if ($listfieldvalue[$i] == 'sortorder') // For column name 'sortorder', we use the field name 'position'
748  {
749  $sql.="'".(int) $db->escape($_POST['position'])."'";
750  }
751  elseif ($_POST[$listfieldvalue[$i]] == '' && ! ($listfieldvalue[$i] == 'code' && $id == 10)) $sql.="null"; // For vat, we want/accept code = ''
752  else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
753  $i++;
754  }
755  $sql.=",1)";
756 
757  dol_syslog("actionadd", LOG_DEBUG);
758  $result = $db->query($sql);
759  if ($result) // Add is ok
760  {
761  setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
762  $_POST=array('id'=>$id); // Clean $_POST array, we keep only
763  }
764  else
765  {
766  if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
767  setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
768  }
769  else {
770  dol_print_error($db);
771  }
772  }
773  }
774 
775  // Si verif ok et action modify, on modifie la ligne
776  if ($ok && GETPOST('actionmodify'))
777  {
778  if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
779  else { $rowidcol="rowid"; }
780 
781  // Modify entry
782  $sql = "UPDATE ".$tabname[$id]." SET ";
783  // Modifie valeur des champs
784  if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldmodify))
785  {
786  $sql.= $tabrowid[$id]."=";
787  $sql.= "'".$db->escape($rowid)."', ";
788  }
789  $i = 0;
790  foreach ($listfieldmodify as $field)
791  {
792  if ($field == 'price' || preg_match('/^amount/i',$field) || $field == 'taux') {
793  $_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]],'MU');
794  }
795  else if ($field == 'entity') {
796  $_POST[$listfieldvalue[$i]] = getEntity($tabname[$id]);
797  }
798  if ($i) $sql.=",";
799  $sql.= $field."=";
800  if ($listfieldvalue[$i] == 'sortorder') // For column name 'sortorder', we use the field name 'position'
801  {
802  $sql.="'".(int) $db->escape($_POST['position'])."'";
803  }
804  elseif ($_POST[$listfieldvalue[$i]] == '' && ! ($listfieldvalue[$i] == 'code' && $id == 10)) $sql.="null"; // For vat, we want/accept code = ''
805  else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
806  $i++;
807  }
808  $sql.= " WHERE ".$rowidcol." = '".$rowid."'";
809  if (in_array('entity', $listfieldmodify)) $sql.= " AND entity = '".getEntity($tabname[$id])."'";
810 
811  dol_syslog("actionmodify", LOG_DEBUG);
812  //print $sql;
813  $resql = $db->query($sql);
814  if (! $resql)
815  {
816  setEventMessages($db->error(), null, 'errors');
817  }
818  }
819  //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
820 }
821 
822 if (GETPOST('actioncancel'))
823 {
824  //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
825 }
826 
827 if ($action == 'confirm_delete' && $confirm == 'yes') // delete
828 {
829  if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
830  else { $rowidcol="rowid"; }
831 
832  $sql = "DELETE FROM ".$tabname[$id]." WHERE ".$rowidcol."='".$rowid."'".($entity != '' ? " AND entity = " . (int) $entity : '');
833 
834  dol_syslog("delete", LOG_DEBUG);
835  $result = $db->query($sql);
836  if (! $result)
837  {
838  if ($db->errno() == 'DB_ERROR_CHILD_EXISTS')
839  {
840  setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
841  }
842  else
843  {
844  dol_print_error($db);
845  }
846  }
847 }
848 
849 // activate
850 if ($action == $acts[0])
851 {
852  if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
853  else { $rowidcol="rowid"; }
854 
855  if ($rowid) {
856  $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol."='".$rowid."'".($entity != '' ? " AND entity = " . (int) $entity : '');
857  }
858  elseif ($code) {
859  $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".dol_escape_htmltag($code)."'".($entity != '' ? " AND entity = " . (int) $entity : '');
860  }
861 
862  $result = $db->query($sql);
863  if (!$result)
864  {
865  dol_print_error($db);
866  }
867 }
868 
869 // disable
870 if ($action == $acts[1])
871 {
872  if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
873  else { $rowidcol="rowid"; }
874 
875  if ($rowid) {
876  $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol."='".$rowid."'".($entity != '' ? " AND entity = " . (int) $entity : '');
877  }
878  elseif ($code) {
879  $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".dol_escape_htmltag($code)."'".($entity != '' ? " AND entity = " . (int) $entity : '');
880  }
881 
882  $result = $db->query($sql);
883  if (!$result)
884  {
885  dol_print_error($db);
886  }
887 }
888 
889 // favorite
890 if ($action == 'activate_favorite')
891 {
892  if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
893  else { $rowidcol="rowid"; }
894 
895  if ($rowid) {
896  $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE ".$rowidcol."='".$rowid."'".($entity != '' ? " AND entity = " . (int) $entity : '');
897  }
898  elseif ($code) {
899  $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code='".dol_escape_htmltag($code)."'".($entity != '' ? " AND entity = " . (int) $entity : '');
900  }
901 
902  $result = $db->query($sql);
903  if (!$result)
904  {
905  dol_print_error($db);
906  }
907 }
908 
909 // disable favorite
910 if ($action == 'disable_favorite')
911 {
912  if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
913  else { $rowidcol="rowid"; }
914 
915  if ($rowid) {
916  $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE ".$rowidcol."='".$rowid."'".($entity != '' ? " AND entity = " . (int) $entity : '');
917  }
918  elseif ($code) {
919  $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code='".dol_escape_htmltag($code)."'".($entity != '' ? " AND entity = " . (int) $entity : '');
920  }
921 
922  $result = $db->query($sql);
923  if (!$result)
924  {
925  dol_print_error($db);
926  }
927 }
928 
929 
930 /*
931  * View
932  */
933 
934 $form = new Form($db);
935 $formadmin=new FormAdmin($db);
936 
937 llxHeader();
938 
939 $titre=$langs->trans("DictionarySetup");
940 $linkback='';
941 if ($id)
942 {
943  $titre.=' - '.$langs->trans($tablib[$id]);
944  $linkback='<a href="'.$_SERVER['PHP_SELF'].'">'.$langs->trans("BackToDictionaryList").'</a>';
945 }
946 $titlepicto='title_setup';
947 if ($id == 10 && GETPOST('from') == 'accountancy')
948 {
949  $titre=$langs->trans("MenuVatAccounts");
950  $titlepicto='title_accountancy';
951 }
952 if ($id == 7 && GETPOST('from') == 'accountancy')
953 {
954  $titre=$langs->trans("MenuTaxAccounts");
955  $titlepicto='title_accountancy';
956 }
957 
958 print load_fiche_titre($titre,$linkback,$titlepicto);
959 
960 if (empty($id))
961 {
962  print $langs->trans("DictionaryDesc");
963  print " ".$langs->trans("OnlyActiveElementsAreShown")."<br>\n";
964 }
965 print "<br>\n";
966 
967 
968 $param = '&id='.$id;
969 if ($search_country_id > 0) $param.= '&search_country_id='.$search_country_id;
970 if ($search_code != '') $param.= '&search_code='.urlencode($search_country_id);
971 if ($entity != '') $param.= '&entity=' . (int) $entity;
972 $paramwithsearch = $param;
973 if ($sortorder) $paramwithsearch.= '&sortorder='.$sortorder;
974 if ($sortfield) $paramwithsearch.= '&sortfield='.$sortfield;
975 if (GETPOST('from')) $paramwithsearch.= '&from='.GETPOST('from','alpha');
976 
977 
978 // Confirmation de la suppression de la ligne
979 if ($action == 'delete')
980 {
981  print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'rowid='.$rowid.'&code='.urlencode($code).$paramwithsearch, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete','',0,1);
982 }
983 //var_dump($elementList);
984 
985 /*
986  * Show a dictionary
987  */
988 if ($id)
989 {
990  // Complete requete recherche valeurs avec critere de tri
991  $sql=$tabsql[$id];
992 
993  if (! preg_match('/ WHERE /',$sql)) $sql.= " WHERE 1 = 1";
994  if ($search_country_id > 0) $sql.= " AND c.rowid = ".$search_country_id;
995  if ($search_code != '' && $id != 9) $sql.= natural_search("code", $search_code);
996  if ($search_code != '' && $id == 9) $sql.= natural_search("code_iso", $search_code);
997 
998  if ($sortfield)
999  {
1000  // If sort order is "country", we use country_code instead
1001  if ($sortfield == 'country') $sortfield='country_code';
1002  $sql.= " ORDER BY ".$sortfield;
1003  if ($sortorder)
1004  {
1005  $sql.=" ".strtoupper($sortorder);
1006  }
1007  $sql.=", ";
1008  // Clear the required sort criteria for the tabsqlsort to be able to force it with selected value
1009  $tabsqlsort[$id]=preg_replace('/([a-z]+\.)?'.$sortfield.' '.$sortorder.',/i','',$tabsqlsort[$id]);
1010  $tabsqlsort[$id]=preg_replace('/([a-z]+\.)?'.$sortfield.',/i','',$tabsqlsort[$id]);
1011  }
1012  else {
1013  $sql.=" ORDER BY ";
1014  }
1015  $sql.=$tabsqlsort[$id];
1016  $sql.=$db->plimit($listlimit+1,$offset);
1017  //print $sql;
1018 
1019  if (empty($tabfield[$id]))
1020  {
1021  dol_print_error($db, 'The table with id '.$id.' has no array tabfield defined');
1022  exit;
1023  }
1024  $fieldlist=explode(',',$tabfield[$id]);
1025 
1026  print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
1027  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1028  print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from','alpha')).'">';
1029 
1030  // Form to add a new line
1031  if ($tabname[$id])
1032  {
1033  $alabelisused=0;
1034  $withentity=null;
1035 
1036  $fieldlist=explode(',',$tabfield[$id]);
1037 
1038  print '<div class="div-table-responsive-no-min">';
1039  print '<table class="noborder" width="100%">';
1040 
1041  // Line for title
1042  print '<tr class="liste_titre">';
1043  foreach ($fieldlist as $field => $value)
1044  {
1045  if ($fieldlist[$field] == 'entity') {
1046  $withentity = getEntity($tabname[$id]);
1047  continue;
1048  }
1049 
1050  // Determine le nom du champ par rapport aux noms possibles
1051  // dans les dictionnaires de donnees
1052  $valuetoshow=ucfirst($fieldlist[$field]); // Par defaut
1053  $valuetoshow=$langs->trans($valuetoshow); // try to translate
1054  $class='';
1055  if ($fieldlist[$field]=='source') { $valuetoshow=$langs->trans("Contact"); }
1056  if ($fieldlist[$field]=='price') { $valuetoshow=$langs->trans("PriceUHT"); }
1057  if ($fieldlist[$field]=='taux') {
1058  if ($tabname[$id] != MAIN_DB_PREFIX."c_revenuestamp") $valuetoshow=$langs->trans("Rate");
1059  else $valuetoshow=$langs->trans("Amount");
1060  $class='center';
1061  }
1062  if ($fieldlist[$field]=='localtax1_type') { $valuetoshow=$langs->trans("UseLocalTax")." 2"; $class="center"; $sortable=0; }
1063  if ($fieldlist[$field]=='localtax1') { $valuetoshow=$langs->trans("Rate")." 2"; $class="center"; }
1064  if ($fieldlist[$field]=='localtax2_type') { $valuetoshow=$langs->trans("UseLocalTax")." 3"; $class="center"; $sortable=0; }
1065  if ($fieldlist[$field]=='localtax2') { $valuetoshow=$langs->trans("Rate")." 3"; $class="center"; }
1066  if ($fieldlist[$field]=='organization') { $valuetoshow=$langs->trans("Organization"); }
1067  if ($fieldlist[$field]=='lang') { $valuetoshow=$langs->trans("Language"); }
1068  if ($fieldlist[$field]=='type') {
1069  if ($tabname[$id] == MAIN_DB_PREFIX."c_paiement") $valuetoshow=$form->textwithtooltip($langs->trans("Type"),$langs->trans("TypePaymentDesc"),2,1,img_help(1,''));
1070  else $valuetoshow=$langs->trans("Type");
1071  }
1072  if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); $class='width100'; }
1073  if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label')
1074  {
1075  if ($id != 25) $valuetoshow=$form->textwithtooltip($langs->trans("Label"), $langs->trans("LabelUsedByDefault"),2,1,img_help(1,''));
1076  else $valuetoshow=$langs->trans("Label");
1077  }
1078  if ($fieldlist[$field]=='libelle_facture') {
1079  $valuetoshow=$form->textwithtooltip($langs->trans("LabelOnDocuments"), $langs->trans("LabelUsedByDefault"),2,1,img_help(1,''));
1080  }
1081  if ($fieldlist[$field]=='country') {
1082  if (in_array('region_id',$fieldlist)) { print '<td>&nbsp;</td>'; continue; } // For region page, we do not show the country input
1083  $valuetoshow=$langs->trans("Country");
1084  }
1085  if ($fieldlist[$field]=='recuperableonly') { $valuetoshow=$langs->trans("NPR"); $class="center"; }
1086  if ($fieldlist[$field]=='nbjour') { $valuetoshow=$langs->trans("NbOfDays"); }
1087  if ($fieldlist[$field]=='type_cdr') { $valuetoshow=$langs->trans("AtEndOfMonth"); $class="center"; }
1088  if ($fieldlist[$field]=='decalage') { $valuetoshow=$langs->trans("Offset"); }
1089  if ($fieldlist[$field]=='width' || $fieldlist[$field]=='nx') { $valuetoshow=$langs->trans("Width"); }
1090  if ($fieldlist[$field]=='height' || $fieldlist[$field]=='ny') { $valuetoshow=$langs->trans("Height"); }
1091  if ($fieldlist[$field]=='unit' || $fieldlist[$field]=='metric') { $valuetoshow=$langs->trans("MeasuringUnit"); }
1092  if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { $valuetoshow=''; }
1093  if ($fieldlist[$field]=='accountancy_code') { $valuetoshow=$langs->trans("AccountancyCode"); }
1094  if ($fieldlist[$field]=='accountancy_code_sell') { $valuetoshow=$langs->trans("AccountancyCodeSell"); }
1095  if ($fieldlist[$field]=='accountancy_code_buy') { $valuetoshow=$langs->trans("AccountancyCodeBuy"); }
1096  if ($fieldlist[$field]=='pcg_version' || $fieldlist[$field]=='fk_pcg_version') { $valuetoshow=$langs->trans("Pcg_version"); }
1097  if ($fieldlist[$field]=='account_parent') { $valuetoshow=$langs->trans("Accountparent"); }
1098  if ($fieldlist[$field]=='pcg_type') { $valuetoshow=$langs->trans("Pcg_type"); }
1099  if ($fieldlist[$field]=='pcg_subtype') { $valuetoshow=$langs->trans("Pcg_subtype"); }
1100  if ($fieldlist[$field]=='sortorder') { $valuetoshow=$langs->trans("SortOrder"); }
1101  if ($fieldlist[$field]=='short_label') { $valuetoshow=$langs->trans("ShortLabel"); }
1102  if ($fieldlist[$field]=='range_account') { $valuetoshow=$langs->trans("Range"); }
1103  if ($fieldlist[$field]=='sens') { $valuetoshow=$langs->trans("Sens"); }
1104  if ($fieldlist[$field]=='category_type') { $valuetoshow=$langs->trans("Calculated"); }
1105  if ($fieldlist[$field]=='formula') { $valuetoshow=$langs->trans("Formula"); }
1106  if ($fieldlist[$field]=='paper_size') { $valuetoshow=$langs->trans("PaperSize"); }
1107  if ($fieldlist[$field]=='orientation') { $valuetoshow=$langs->trans("Orientation"); }
1108  if ($fieldlist[$field]=='leftmargin') { $valuetoshow=$langs->trans("LeftMargin"); }
1109  if ($fieldlist[$field]=='topmargin') { $valuetoshow=$langs->trans("TopMargin"); }
1110  if ($fieldlist[$field]=='spacex') { $valuetoshow=$langs->trans("SpaceX"); }
1111  if ($fieldlist[$field]=='spacey') { $valuetoshow=$langs->trans("SpaceY"); }
1112  if ($fieldlist[$field]=='font_size') { $valuetoshow=$langs->trans("FontSize"); }
1113  if ($fieldlist[$field]=='custom_x') { $valuetoshow=$langs->trans("CustomX"); }
1114  if ($fieldlist[$field]=='custom_y') { $valuetoshow=$langs->trans("CustomY"); }
1115  if ($fieldlist[$field]=='percent') { $valuetoshow=$langs->trans("Percentage"); }
1116  if ($fieldlist[$field]=='affect') { $valuetoshow=$langs->trans("WithCounter"); }
1117  if ($fieldlist[$field]=='delay') { $valuetoshow=$langs->trans("NoticePeriod"); }
1118  if ($fieldlist[$field]=='newbymonth') { $valuetoshow=$langs->trans("NewByMonth"); }
1119  if ($fieldlist[$field]=='fk_tva') { $valuetoshow=$langs->trans("VAT"); }
1120  if ($fieldlist[$field]=='range_ik') { $valuetoshow=$langs->trans("RangeIk"); }
1121  if ($fieldlist[$field]=='fk_c_exp_tax_cat') { $valuetoshow=$langs->trans("CarCategory"); }
1122  if ($fieldlist[$field]=='revenuestamp_type') { $valuetoshow=$langs->trans('TypeOfRevenueStamp'); }
1123 
1124  if ($id == 2) // Special cas for state page
1125  {
1126  if ($fieldlist[$field]=='region_id') { $valuetoshow='&nbsp;'; $showfield=1; }
1127  if ($fieldlist[$field]=='region') { $valuetoshow=$langs->trans("Country").'/'.$langs->trans("Region"); $showfield=1; }
1128  }
1129 
1130  if ($valuetoshow != '')
1131  {
1132  print '<td'.($class?' class="'.$class.'"':'').'>';
1133  if (! empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i',$tabhelp[$id][$value])) print '<a href="'.$tabhelp[$id][$value].'" target="_blank">'.$valuetoshow.' '.img_help(1,$valuetoshow).'</a>';
1134  else if (! empty($tabhelp[$id][$value])) print $form->textwithpicto($valuetoshow,$tabhelp[$id][$value]);
1135  else print $valuetoshow;
1136  print '</td>';
1137  }
1138  if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') $alabelisused=1;
1139  }
1140 
1141  if ($id == 4) print '<td></td>';
1142  print '<td>';
1143  print '<input type="hidden" name="id" value="'.$id.'">';
1144  if (! is_null($withentity))
1145  print '<input type="hidden" name="entity" value="'.$withentity.'">';
1146  print '</td>';
1147  print '<td style="min-width: 26px;"></td>';
1148  print '<td style="min-width: 26px;"></td>';
1149  print '</tr>';
1150 
1151  // Line to enter new values
1152  print '<!-- line to add new entry --><tr class="oddeven nodrag nodrop nohover">';
1153 
1154  $obj = new stdClass();
1155  // If data was already input, we define them in obj to populate input fields.
1156  if (GETPOST('actionadd'))
1157  {
1158  foreach ($fieldlist as $key=>$val)
1159  {
1160  if (GETPOST($val) != '')
1161  $obj->$val=GETPOST($val);
1162  }
1163  }
1164 
1165  $tmpaction = 'create';
1166  $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
1167  $reshook=$hookmanager->executeHooks('createDictionaryFieldlist',$parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
1168  $error=$hookmanager->error; $errors=$hookmanager->errors;
1169 
1170  if ($id == 3) unset($fieldlist[2]); // Remove field ??? if dictionary Regions
1171 
1172  if (empty($reshook))
1173  {
1174  fieldList($fieldlist, $obj, $tabname[$id], 'add');
1175  }
1176 
1177  if ($id == 4) print '<td></td>';
1178  print '<td colspan="3" align="center">';
1179  if ($action != 'edit')
1180  {
1181  print '<input type="submit" class="button" name="actionadd" value="'.$langs->trans("Add").'">';
1182  }
1183  print '</td>';
1184  print "</tr>";
1185 
1186  $colspan=count($fieldlist)+3;
1187  if ($id == 4) $colspan++;
1188 
1189  print '</table>';
1190  print '</div>';
1191  }
1192 
1193  print '</form>';
1194 
1195  print '<br>';
1196 
1197  print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
1198  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1199  print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from','alpha')).'">';
1200 
1201  // List of available record in database
1202  dol_syslog("htdocs/admin/dict", LOG_DEBUG);
1203  $resql=$db->query($sql);
1204  if ($resql)
1205  {
1206  $num = $db->num_rows($resql);
1207  $i = 0;
1208 
1209  // There is several pages
1210  if ($num > $listlimit || $page)
1211  {
1212  print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page+1).'</span></li>');
1213  print '<div class="clearboth"></div>';
1214  }
1215 
1216  print '<div class="div-table-responsive">';
1217  print '<table class="noborder" width="100%">';
1218 
1219  // Title line with search boxes
1220  print '<tr class="liste_titre_filter">';
1221  $filterfound=0;
1222  foreach ($fieldlist as $field => $value)
1223  {
1224  if ($fieldlist[$field] == 'entity') continue;
1225 
1226  $showfield=1; // By default
1227 
1228  if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { $showfield=0; }
1229 
1230  if ($showfield)
1231  {
1232  if ($value == 'country')
1233  {
1234  print '<td class="liste_titre">';
1235  print $form->select_country($search_country_id, 'search_country_id', '', 28, 'maxwidth150 maxwidthonsmartphone');
1236  print '</td>';
1237  $filterfound++;
1238  }
1239  elseif ($value == 'code')
1240  {
1241  print '<td class="liste_titre">';
1242  print '<input type="text" class="maxwidth100" name="search_code" value="'.dol_escape_htmltag($search_code).'">';
1243  print '</td>';
1244  $filterfound++;
1245  }
1246  else
1247  {
1248  print '<td class="liste_titre">';
1249  print '</td>';
1250  }
1251  }
1252  }
1253  if ($id == 4) print '<td></td>';
1254  print '<td class="liste_titre"></td>';
1255  print '<td class="liste_titre" colspan="2" align="right">';
1256  if ($filterfound)
1257  {
1258  $searchpicto=$form->showFilterAndCheckAddButtons(0);
1259  print $searchpicto;
1260  }
1261  print '</td>';
1262  print '</tr>';
1263 
1264  // Title of lines
1265  print '<tr class="liste_titre">';
1266  foreach ($fieldlist as $field => $value)
1267  {
1268  if ($fieldlist[$field] == 'entity') continue;
1269 
1270  // Determine le nom du champ par rapport aux noms possibles
1271  // dans les dictionnaires de donnees
1272  $showfield=1; // By defaut
1273  $align="left";
1274  $sortable=1;
1275  $valuetoshow='';
1276  /*
1277  $tmparray=getLabelOfField($fieldlist[$field]);
1278  $showfield=$tmp['showfield'];
1279  $valuetoshow=$tmp['valuetoshow'];
1280  $align=$tmp['align'];
1281  $sortable=$tmp['sortable'];
1282  */
1283  $valuetoshow=ucfirst($fieldlist[$field]); // By defaut
1284  $valuetoshow=$langs->trans($valuetoshow); // try to translate
1285  if ($fieldlist[$field]=='source') { $valuetoshow=$langs->trans("Contact"); }
1286  if ($fieldlist[$field]=='price') { $valuetoshow=$langs->trans("PriceUHT"); }
1287  if ($fieldlist[$field]=='taux') {
1288  if ($tabname[$id] != MAIN_DB_PREFIX."c_revenuestamp") $valuetoshow=$langs->trans("Rate");
1289  else $valuetoshow=$langs->trans("Amount");
1290  $align='center';
1291  }
1292  if ($fieldlist[$field]=='localtax1_type') { $valuetoshow=$langs->trans("UseLocalTax")." 2"; $align="center"; $sortable=0; }
1293  if ($fieldlist[$field]=='localtax1') { $valuetoshow=$langs->trans("Rate")." 2"; $align="center"; $sortable=0; }
1294  if ($fieldlist[$field]=='localtax2_type') { $valuetoshow=$langs->trans("UseLocalTax")." 3"; $align="center"; $sortable=0; }
1295  if ($fieldlist[$field]=='localtax2') { $valuetoshow=$langs->trans("Rate")." 3"; $align="center"; $sortable=0; }
1296  if ($fieldlist[$field]=='organization') { $valuetoshow=$langs->trans("Organization"); }
1297  if ($fieldlist[$field]=='lang') { $valuetoshow=$langs->trans("Language"); }
1298  if ($fieldlist[$field]=='type') { $valuetoshow=$langs->trans("Type"); }
1299  if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); }
1300  if ($fieldlist[$field]=='position') { $align='right'; }
1301  if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label')
1302  {
1303  //if ($id != 25) $valuetoshow=$form->textwithtooltip($langs->trans("Label"), $langs->trans("LabelUsedByDefault"),2,1,img_help(1,''));
1304  //else $valuetoshow=$langs->trans("Label");
1305  $valuetoshow=$langs->trans("Label");
1306  }
1307  if ($fieldlist[$field]=='libelle_facture') {
1308  //$valuetoshow=$form->textwithtooltip($langs->trans("LabelOnDocuments"), $langs->trans("LabelUsedByDefault"),2,1,img_help(1,''));
1309  $valuetoshow=$langs->trans("LabelOnDocuments");
1310  }
1311  if ($fieldlist[$field]=='country') { $valuetoshow=$langs->trans("Country"); }
1312  if ($fieldlist[$field]=='recuperableonly') { $valuetoshow=$langs->trans("NPR"); $align="center"; }
1313  if ($fieldlist[$field]=='nbjour') { $valuetoshow=$langs->trans("NbOfDays"); }
1314  if ($fieldlist[$field]=='type_cdr') { $valuetoshow=$langs->trans("AtEndOfMonth"); $align="center"; }
1315  if ($fieldlist[$field]=='decalage') { $valuetoshow=$langs->trans("Offset"); }
1316  if ($fieldlist[$field]=='width' || $fieldlist[$field]=='nx') { $valuetoshow=$langs->trans("Width"); }
1317  if ($fieldlist[$field]=='height' || $fieldlist[$field]=='ny') { $valuetoshow=$langs->trans("Height"); }
1318  if ($fieldlist[$field]=='unit' || $fieldlist[$field]=='metric') { $valuetoshow=$langs->trans("MeasuringUnit"); }
1319  if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { $showfield=0; }
1320  if ($fieldlist[$field]=='accountancy_code'){ $valuetoshow=$langs->trans("AccountancyCode"); }
1321  if ($fieldlist[$field]=='accountancy_code_sell'){ $valuetoshow=$langs->trans("AccountancyCodeSell"); $sortable=0; }
1322  if ($fieldlist[$field]=='accountancy_code_buy'){ $valuetoshow=$langs->trans("AccountancyCodeBuy"); $sortable=0; }
1323  if ($fieldlist[$field]=='fk_pcg_version') { $valuetoshow=$langs->trans("Pcg_version"); }
1324  if ($fieldlist[$field]=='account_parent') { $valuetoshow=$langs->trans("Accountsparent"); }
1325  if ($fieldlist[$field]=='pcg_type') { $valuetoshow=$langs->trans("Pcg_type"); }
1326  if ($fieldlist[$field]=='pcg_subtype') { $valuetoshow=$langs->trans("Pcg_subtype"); }
1327  if ($fieldlist[$field]=='sortorder') { $valuetoshow=$langs->trans("SortOrder"); }
1328  if ($fieldlist[$field]=='short_label') { $valuetoshow=$langs->trans("ShortLabel"); }
1329  if ($fieldlist[$field]=='range_account') { $valuetoshow=$langs->trans("Range"); }
1330  if ($fieldlist[$field]=='sens') { $valuetoshow=$langs->trans("Sens"); }
1331  if ($fieldlist[$field]=='category_type') { $valuetoshow=$langs->trans("Calculated"); }
1332  if ($fieldlist[$field]=='formula') { $valuetoshow=$langs->trans("Formula"); }
1333  if ($fieldlist[$field]=='paper_size') { $valuetoshow=$langs->trans("PaperSize"); }
1334  if ($fieldlist[$field]=='orientation') { $valuetoshow=$langs->trans("Orientation"); }
1335  if ($fieldlist[$field]=='leftmargin') { $valuetoshow=$langs->trans("LeftMargin"); }
1336  if ($fieldlist[$field]=='topmargin') { $valuetoshow=$langs->trans("TopMargin"); }
1337  if ($fieldlist[$field]=='spacex') { $valuetoshow=$langs->trans("SpaceX"); }
1338  if ($fieldlist[$field]=='spacey') { $valuetoshow=$langs->trans("SpaceY"); }
1339  if ($fieldlist[$field]=='font_size') { $valuetoshow=$langs->trans("FontSize"); }
1340  if ($fieldlist[$field]=='custom_x') { $valuetoshow=$langs->trans("CustomX"); }
1341  if ($fieldlist[$field]=='custom_y') { $valuetoshow=$langs->trans("CustomY"); }
1342  if ($fieldlist[$field]=='percent') { $valuetoshow=$langs->trans("Percentage"); }
1343  if ($fieldlist[$field]=='affect') { $valuetoshow=$langs->trans("WithCounter"); }
1344  if ($fieldlist[$field]=='delay') { $valuetoshow=$langs->trans("NoticePeriod"); }
1345  if ($fieldlist[$field]=='newbymonth') { $valuetoshow=$langs->trans("NewByMonth"); }
1346  if ($fieldlist[$field]=='fk_tva') { $valuetoshow=$langs->trans("VAT"); }
1347  if ($fieldlist[$field]=='range_ik') { $valuetoshow=$langs->trans("RangeIk"); }
1348  if ($fieldlist[$field]=='fk_c_exp_tax_cat') { $valuetoshow=$langs->trans("CarCategory"); }
1349  if ($fieldlist[$field]=='revenuestamp_type') { $valuetoshow=$langs->trans('TypeOfRevenueStamp'); }
1350 
1351  // Affiche nom du champ
1352  if ($showfield)
1353  {
1354  print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable?$fieldlist[$field]:''), ($page?'page='.$page.'&':''), $param, "align=".$align, $sortfield, $sortorder);
1355  }
1356  }
1357  // Favorite - Only activated on country dictionary
1358  if ($id == 4) print getTitleFieldOfList($langs->trans("Favorite"), 0, $_SERVER["PHP_SELF"], "favorite", ($page?'page='.$page.'&':''), $param, 'align="center"', $sortfield, $sortorder);
1359 
1360  print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page?'page='.$page.'&':''), $param, 'align="center"', $sortfield, $sortorder);
1363  print '</tr>';
1364 
1365  if ($num)
1366  {
1367  // Lines with values
1368  while ($i < $num)
1369  {
1370  $obj = $db->fetch_object($resql);
1371  //print_r($obj);
1372  print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
1373  if ($action == 'edit' && ($rowid == (! empty($obj->rowid)?$obj->rowid:$obj->code)))
1374  {
1375  $tmpaction='edit';
1376  $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
1377  $reshook=$hookmanager->executeHooks('editDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
1378  $error=$hookmanager->error; $errors=$hookmanager->errors;
1379 
1380  // Show fields
1381  if (empty($reshook)) {
1382  $withentity = fieldList($fieldlist, $obj, $tabname[$id], 'edit');
1383  }
1384 
1385  print '<td colspan="3" align="center">';
1386  print '<div name="'.(! empty($obj->rowid)?$obj->rowid:$obj->code).'"></div>';
1387  print '<input type="hidden" name="page" value="'.$page.'">';
1388  print '<input type="hidden" name="rowid" value="'.$rowid.'">';
1389  if (! is_null($withentity))
1390  print '<input type="hidden" name="entity" value="'.$withentity.'">';
1391  print '<input type="submit" class="button" name="actionmodify" value="'.$langs->trans("Modify").'">';
1392  print '<input type="submit" class="button" name="actioncancel" value="'.$langs->trans("Cancel").'">';
1393  print '</td>';
1394  }
1395  else
1396  {
1397  $tmpaction = 'view';
1398  $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
1399  $reshook=$hookmanager->executeHooks('viewDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
1400 
1401  $error=$hookmanager->error; $errors=$hookmanager->errors;
1402 
1403  if (empty($reshook))
1404  {
1405  $withentity=null;
1406 
1407  foreach ($fieldlist as $field => $value)
1408  {
1409  //var_dump($fieldlist);
1410  $showfield=1;
1411  $align="left";
1412  $valuetoshow=$obj->{$fieldlist[$field]};
1413 
1414  if ($fieldlist[$field] == 'entity') {
1415  $withentity = $valuetoshow;
1416  continue;
1417  }
1418 
1419  if ($value == 'element')
1420  {
1421  $valuetoshow = isset($elementList[$valuetoshow])?$elementList[$valuetoshow]:$valuetoshow;
1422  }
1423  else if ($value == 'source')
1424  {
1425  $valuetoshow = isset($sourceList[$valuetoshow])?$sourceList[$valuetoshow]:$valuetoshow;
1426  }
1427  else if ($valuetoshow=='all') {
1428  $valuetoshow=$langs->trans('All');
1429  }
1430  else if ($fieldlist[$field]=='country') {
1431  if (empty($obj->country_code))
1432  {
1433  $valuetoshow='-';
1434  }
1435  else
1436  {
1437  $key=$langs->trans("Country".strtoupper($obj->country_code));
1438  $valuetoshow=($key != "Country".strtoupper($obj->country_code)?$obj->country_code." - ".$key:$obj->country);
1439  }
1440  }
1441  else if ($fieldlist[$field]=='recuperableonly' || $fieldlist[$field] == 'deductible' || $fieldlist[$field] == 'category_type') {
1442  $valuetoshow=yn($valuetoshow);
1443  $align="center";
1444  }
1445  else if ($fieldlist[$field]=='type_cdr') {
1446  if(empty($valuetoshow)) $valuetoshow = $langs->trans('None');
1447  elseif($valuetoshow == 1) $valuetoshow = $langs->trans('AtEndOfMonth');
1448  elseif($valuetoshow == 2) $valuetoshow = $langs->trans('CurrentNext');
1449  $align="center";
1450  }
1451  else if ($fieldlist[$field]=='price' || preg_match('/^amount/i',$fieldlist[$field])) {
1452  $valuetoshow=price($valuetoshow);
1453  }
1454  if ($value == 'private')
1455  {
1456  $valuetoshow = yn($elementList[$valuetoshow]);
1457  }
1458  else if ($fieldlist[$field]=='libelle_facture') {
1459  $langs->load("bills");
1460  $key=$langs->trans("PaymentCondition".strtoupper($obj->code));
1461  $valuetoshow=($obj->code && $key != "PaymentCondition".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
1462  $valuetoshow=nl2br($valuetoshow);
1463  }
1464  else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_country') {
1465  $key=$langs->trans("Country".strtoupper($obj->code));
1466  $valuetoshow=($obj->code && $key != "Country".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
1467  }
1468  else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_availability') {
1469  $langs->load("propal");
1470  $key=$langs->trans("AvailabilityType".strtoupper($obj->code));
1471  $valuetoshow=($obj->code && $key != "AvailabilityType".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
1472  }
1473  else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_actioncomm') {
1474  $key=$langs->trans("Action".strtoupper($obj->code));
1475  $valuetoshow=($obj->code && $key != "Action".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
1476  }
1477  else if (! empty($obj->code_iso) && $fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_currencies') {
1478  $key=$langs->trans("Currency".strtoupper($obj->code_iso));
1479  $valuetoshow=($obj->code_iso && $key != "Currency".strtoupper($obj->code_iso)?$key:$obj->{$fieldlist[$field]});
1480  }
1481  else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_typent') {
1482  $key=$langs->trans(strtoupper($obj->code));
1483  $valuetoshow=($key != strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
1484  }
1485  else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_prospectlevel') {
1486  $key=$langs->trans(strtoupper($obj->code));
1487  $valuetoshow=($key != strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
1488  }
1489  else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_civility') {
1490  $key=$langs->trans("Civility".strtoupper($obj->code));
1491  $valuetoshow=($obj->code && $key != "Civility".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
1492  }
1493  else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_type_contact') {
1494  $langs->load('agenda');
1495  $key=$langs->trans("TypeContact_".$obj->element."_".$obj->source."_".strtoupper($obj->code));
1496  $valuetoshow=($obj->code && $key != "TypeContact_".$obj->element."_".$obj->source."_".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
1497  }
1498  else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_payment_term') {
1499  $langs->load("bills");
1500  $key=$langs->trans("PaymentConditionShort".strtoupper($obj->code));
1501  $valuetoshow=($obj->code && $key != "PaymentConditionShort".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
1502  }
1503  else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_paiement') {
1504  $langs->load("bills");
1505  $key=$langs->trans("PaymentType".strtoupper($obj->code));
1506  $valuetoshow=($obj->code && $key != "PaymentType".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
1507  }
1508  else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_input_reason') {
1509  $key=$langs->trans("DemandReasonType".strtoupper($obj->code));
1510  $valuetoshow=($obj->code && $key != "DemandReasonType".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
1511  }
1512  else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_input_method') {
1513  $langs->load("orders");
1514  $key=$langs->trans($obj->code);
1515  $valuetoshow=($obj->code && $key != $obj->code)?$key:$obj->{$fieldlist[$field]};
1516  }
1517  else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_shipment_mode') {
1518  $langs->load("sendings");
1519  $key=$langs->trans("SendingMethod".strtoupper($obj->code));
1520  $valuetoshow=($obj->code && $key != "SendingMethod".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
1521  }
1522  else if ($fieldlist[$field] == 'libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_paper_format')
1523  {
1524  $key = $langs->trans('PaperFormat'.strtoupper($obj->code));
1525  $valuetoshow = ($obj->code && $key != 'PaperFormat'.strtoupper($obj->code) ? $key : $obj->{$fieldlist[$field]});
1526  }
1527  else if ($fieldlist[$field] == 'label' && $tabname[$id] == MAIN_DB_PREFIX.'c_type_fees')
1528  {
1529  $langs->load('trips');
1530  $key = $langs->trans(strtoupper($obj->code));
1531  $valuetoshow = ($obj->code && $key != strtoupper($obj->code) ? $key : $obj->{$fieldlist[$field]});
1532  }
1533  else if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') {
1534  $showfield=0;
1535  }
1536  else if ($fieldlist[$field]=='unicode') {
1537  $valuetoshow = $langs->getCurrencySymbol($obj->code,1);
1538  }
1539  else if ($fieldlist[$field]=='label' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_units') {
1540  $langs->load("products");
1541  $valuetoshow=$langs->trans($obj->{$fieldlist[$field]});
1542  }
1543  else if ($fieldlist[$field]=='short_label' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_units') {
1544  $langs->load("products");
1545  $valuetoshow = $langs->trans($obj->{$fieldlist[$field]});
1546  }
1547  else if (($fieldlist[$field] == 'unit') && ($tabname[$id] == MAIN_DB_PREFIX.'c_paper_format'))
1548  {
1549  $key = $langs->trans('SizeUnit'.strtolower($obj->unit));
1550  $valuetoshow = ($obj->code && $key != 'SizeUnit'.strtolower($obj->unit) ? $key : $obj->{$fieldlist[$field]});
1551  }
1552  else if ($fieldlist[$field]=='localtax1' || $fieldlist[$field]=='localtax2') {
1553  $align="center";
1554  }
1555  else if ($fieldlist[$field]=='localtax1_type') {
1556  if ($obj->localtax1 != 0)
1557  $valuetoshow=$localtax_typeList[$valuetoshow];
1558  else
1559  $valuetoshow = '';
1560  $align="center";
1561  }
1562  else if ($fieldlist[$field]=='localtax2_type') {
1563  if ($obj->localtax2 != 0)
1564  $valuetoshow=$localtax_typeList[$valuetoshow];
1565  else
1566  $valuetoshow = '';
1567  $align="center";
1568  }
1569  else if ($fieldlist[$field]=='taux') {
1570  $valuetoshow = price($valuetoshow, 0, $langs, 0, 0);
1571  $align="center";
1572  }
1573  else if (in_array($fieldlist[$field],array('recuperableonly')))
1574  {
1575  $align="center";
1576  }
1577  else if ($fieldlist[$field]=='accountancy_code' || $fieldlist[$field]=='accountancy_code_sell' || $fieldlist[$field]=='accountancy_code_buy') {
1578  $valuetoshow = length_accountg($valuetoshow);
1579  }
1580  elseif ($fieldlist[$field] == 'fk_tva')
1581  {
1582  foreach ($form->cache_vatrates as $key => $Tab)
1583  {
1584  if ($form->cache_vatrates[$key]['rowid'] == $valuetoshow)
1585  {
1586  $valuetoshow = $form->cache_vatrates[$key]['libtva'];
1587  break;
1588  }
1589  }
1590  }
1591  elseif ($fieldlist[$field] == 'fk_c_exp_tax_cat')
1592  {
1593  $valuetoshow = getDictvalue(MAIN_DB_PREFIX.'c_exp_tax_cat', 'label', $valuetoshow);
1594  $valuetoshow = $langs->trans($valuetoshow);
1595  }
1596  elseif ($tabname[$id] == MAIN_DB_PREFIX.'c_exp_tax_cat')
1597  {
1598  $valuetoshow = $langs->trans($valuetoshow);
1599  }
1600 
1601  $class='tddict';
1602  if ($fieldlist[$field] == 'note' && $id == 10) $class.=' tdoverflowmax200';
1603  if ($fieldlist[$field] == 'tracking') $class.=' tdoverflowauto';
1604  if ($fieldlist[$field] == 'code') $class.=' width100';
1605  if ($fieldlist[$field] == 'position') $class.=' right';
1606  if ($fieldlist[$field] == 'localtax1_type') $class.=' nowrap';
1607  if ($fieldlist[$field] == 'localtax2_type') $class.=' nowrap';
1608  // Show value for field
1609  if ($showfield) print '<!-- '.$fieldlist[$field].' --><td align="'.$align.'" class="'.$class.'">'.$valuetoshow.'</td>';
1610  }
1611  }
1612 
1613  // Can an entry be erased or disabled ?
1614  $iserasable=1;$canbedisabled=1;$canbemodified=1; // true by default
1615  if (isset($obj->code) && $id != 10)
1616  {
1617  if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i',$obj->code))) { $iserasable = 0; $canbedisabled = 0; }
1618  else if ($obj->code == 'RECEP') { $iserasable = 0; $canbedisabled = 0; }
1619  else if ($obj->code == 'EF0') { $iserasable = 0; $canbedisabled = 0; }
1620  }
1621 
1622  if (isset($obj->type) && in_array($obj->type, array('system', 'systemauto'))) { $iserasable=0; }
1623  if (in_array($obj->code, array('AC_OTH','AC_OTH_AUTO')) || in_array($obj->type, array('systemauto'))) { $canbedisabled=0; $canbedisabled = 0; }
1624  $canbemodified=$iserasable;
1625  if ($obj->code == 'RECEP') $canbemodified=1;
1626  if ($tabname[$id] == MAIN_DB_PREFIX."c_actioncomm") $canbemodified=1;
1627 
1628  // Url
1629  $rowidcol=$tabrowid[$id];
1630  // If rowidcol not defined
1631  if (empty($rowidcol) || in_array($id, array(6,7,8,13,17,19,27))) $rowidcol='rowid';
1632  $url = $_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.((! empty($obj->{$rowidcol}) || $obj->{$rowidcol} == '0')?$obj->{$rowidcol}:(! empty($obj->code)?urlencode($obj->code):'')).'&code='.(! empty($obj->code)?urlencode($obj->code):'');
1633  if (! empty($param)) $url .= '&'.$param;
1634  if (! is_null($withentity)) $url .= '&entity='.$withentity;
1635  $url.='&';
1636 
1637  // Favorite
1638  // Only activated on country dictionary
1639  if ($id == 4)
1640  {
1641  print '<td align="center" class="nowrap">';
1642  if ($iserasable) print '<a href="'.$url.'action='.$acts[$obj->favorite].'_favorite">'.$actl[$obj->favorite].'</a>';
1643  else print $langs->trans("AlwaysActive");
1644  print '</td>';
1645  }
1646 
1647  // Active
1648  print '<td align="center" class="nowrap">';
1649  if ($canbedisabled) print '<a href="'.$url.'action='.$acts[$obj->active].'">'.$actl[$obj->active].'</a>';
1650  else
1651  {
1652  if (in_array($obj->code, array('AC_OTH','AC_OTH_AUTO'))) print $langs->trans("AlwaysActive");
1653  else if (isset($obj->type) && in_array($obj->type, array('systemauto')) && empty($obj->active)) print $langs->trans("Deprecated");
1654  else if (isset($obj->type) && in_array($obj->type, array('system')) && ! empty($obj->active) && $obj->code != 'AC_OTH') print $langs->trans("UsedOnlyWithTypeOption");
1655  else print $langs->trans("AlwaysActive");
1656  }
1657  print "</td>";
1658 
1659  // Modify link
1660  if ($canbemodified) print '<td align="center"><a class="reposition" href="'.$url.'action=edit">'.img_edit().'</a></td>';
1661  else print '<td>&nbsp;</td>';
1662 
1663  // Delete link
1664  if ($iserasable)
1665  {
1666  print '<td align="center">';
1667  if ($user->admin) print '<a href="'.$url.'action=delete">'.img_delete().'</a>';
1668  //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
1669  print '</td>';
1670  }
1671  else print '<td>&nbsp;</td>';
1672 
1673  print "</tr>\n";
1674  }
1675  $i++;
1676  }
1677  }
1678 
1679  print '</table>';
1680  print '</div>';
1681  }
1682  else {
1683  dol_print_error($db);
1684  }
1685 
1686 
1687  print '</form>';
1688 }
1689 else
1690 {
1691  /*
1692  * Show list of dictionary to show
1693  */
1694 
1695  $lastlineisempty=false;
1696 
1697  print '<div class="div-table-responsive-no-min">';
1698  print '<table class="noborder" width="100%">';
1699  print '<tr class="liste_titre">';
1700  //print '<td>'.$langs->trans("Module").'</td>';
1701  print '<td colspan="2">'.$langs->trans("Dictionary").'</td>';
1702  print '<td>'.$langs->trans("Table").'</td>';
1703  print '</tr>';
1704 
1705  $showemptyline='';
1706  foreach ($taborder as $i)
1707  {
1708  if (isset($tabname[$i]) && empty($tabcond[$i])) continue;
1709 
1710  if ($i)
1711  {
1712  if ($showemptyline)
1713  {
1714 
1715  print '<tr class="oddeven"><td width="30%">&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
1716  $showemptyline=0;
1717  }
1718 
1719 
1720  $value=$tabname[$i];
1721  print '<tr class="oddeven"><td width="50%">';
1722  if (! empty($tabcond[$i]))
1723  {
1724  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$i.'">'.$langs->trans($tablib[$i]).'</a>';
1725  }
1726  else
1727  {
1728  print $langs->trans($tablib[$i]);
1729  }
1730  print '</td>';
1731  print '<td>';
1732  /*if (empty($tabcond[$i]))
1733  {
1734  print info_admin($langs->trans("DictionaryDisabledSinceNoModuleNeedIt"),1);
1735  }*/
1736  print '</td>';
1737  print '<td>'.$tabname[$i].'</td></tr>';
1738  $lastlineisempty=false;
1739  }
1740  else
1741  {
1742  if (! $lastlineisempty)
1743  {
1744  $showemptyline=1;
1745  $lastlineisempty=true;
1746  }
1747  }
1748  }
1749  print '</table>';
1750  print '</div>';
1751 }
1752 
1753 print '<br>';
1754 
1755 
1756 llxFooter();
1757 $db->close();
1758 
1759 
1769 function fieldList($fieldlist, $obj='', $tabname='', $context='')
1770 {
1771  global $conf,$langs,$db,$mysoc;
1772  global $form;
1773  global $region_id;
1774  global $elementList,$sourceList,$localtax_typeList;
1775  global $bc;
1776 
1777  $formadmin = new FormAdmin($db);
1778  $formcompany = new FormCompany($db);
1779  if (! empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db);
1780 
1781  $withentity='';
1782 
1783  foreach ($fieldlist as $field => $value)
1784  {
1785  if ($fieldlist[$field] == 'entity') {
1786  $withentity = $obj->{$fieldlist[$field]};
1787  continue;
1788  }
1789 
1790  if (in_array($fieldlist[$field], array('code', 'libelle', 'type')) && $tabname == MAIN_DB_PREFIX."c_actioncomm" && in_array($obj->type, array('system','systemauto')))
1791  {
1792  $hidden = (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'');
1793  print '<td>';
1794  print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$hidden.'">';
1795  print $langs->trans($hidden);
1796  print '</td>';
1797  }
1798  elseif ($fieldlist[$field] == 'country')
1799  {
1800  if (in_array('region_id',$fieldlist))
1801  {
1802  print '<td>';
1803  //print join(',',$fieldlist);
1804  print '</td>';
1805  continue;
1806  } // For state page, we do not show the country input (we link to region, not country)
1807  print '<td>';
1808  $fieldname='country';
1809  print $form->select_country((! empty($obj->country_code)?$obj->country_code:(! empty($obj->country)?$obj->country:'')), $fieldname, '', 28, 'maxwidth150 maxwidthonsmartphone');
1810  print '</td>';
1811  }
1812  elseif ($fieldlist[$field] == 'country_id')
1813  {
1814  if (! in_array('country',$fieldlist)) // If there is already a field country, we don't show country_id (avoid duplicate)
1815  {
1816  $country_id = (! empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : 0);
1817  print '<td class="tdoverflowmax100">';
1818  print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$country_id.'">';
1819  print '</td>';
1820  }
1821  }
1822  elseif ($fieldlist[$field] == 'region')
1823  {
1824  print '<td>';
1825  $formcompany->select_region($region_id,'region');
1826  print '</td>';
1827  }
1828  elseif ($fieldlist[$field] == 'region_id')
1829  {
1830  $region_id = (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:0);
1831  print '<td>';
1832  print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$region_id.'">';
1833  print '</td>';
1834  }
1835  elseif ($fieldlist[$field] == 'lang')
1836  {
1837  print '<td>';
1838  print $formadmin->select_language($conf->global->MAIN_LANG_DEFAULT,'lang');
1839  print '</td>';
1840  }
1841  // Le type de l'element (pour les type de contact)
1842  elseif ($fieldlist[$field] == 'element')
1843  {
1844  print '<td>';
1845  print $form->selectarray('element', $elementList,(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
1846  print '</td>';
1847  }
1848  // La source de l'element (pour les type de contact)
1849  elseif ($fieldlist[$field] == 'source')
1850  {
1851  print '<td>';
1852  print $form->selectarray('source', $sourceList,(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
1853  print '</td>';
1854  }
1855  elseif ($fieldlist[$field] == 'private')
1856  {
1857  print '<td>';
1858  print $form->selectyesno("private",(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
1859  print '</td>';
1860  }
1861  elseif ($fieldlist[$field] == 'type' && $tabname == MAIN_DB_PREFIX."c_actioncomm")
1862  {
1863  $type = (! empty($obj->type)?$obj->type:'user'); // Check if type is different of 'user' (external module)
1864  print '<td>';
1865  print $type.'<input type="hidden" name="type" value="'.$type.'">';
1866  print '</td>';
1867  }
1868  elseif ($fieldlist[$field] == 'recuperableonly' || $fieldlist[$field] == 'type_cdr' || $fieldlist[$field] == 'deductible' || $fieldlist[$field] == 'category_type') {
1869  if ($fieldlist[$field] == 'type_cdr') print '<td align="center">';
1870  else print '<td>';
1871  if ($fieldlist[$field] == 'type_cdr') {
1872  print $form->selectarray($fieldlist[$field], array(0=>$langs->trans('None'), 1=>$langs->trans('AtEndOfMonth'), 2=>$langs->trans('CurrentNext')), (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
1873  } else {
1874  print $form->selectyesno($fieldlist[$field],(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''),1);
1875  }
1876  print '</td>';
1877  }
1878  elseif (in_array($fieldlist[$field],array('nbjour','decalage','taux','localtax1','localtax2'))) {
1879  $align="left";
1880  if (in_array($fieldlist[$field],array('taux','localtax1','localtax2'))) $align="center"; // Fields aligned on right
1881  print '<td align="'.$align.'">';
1882  print '<input type="text" class="flat" value="'.(isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : '').'" size="3" name="'.$fieldlist[$field].'">';
1883  print '</td>';
1884  }
1885  elseif (in_array($fieldlist[$field], array('libelle_facture'))) {
1886  print '<td>';
1887  $transfound=0;
1888  // Special case for labels
1889  if ($tabname == MAIN_DB_PREFIX.'c_payment_term')
1890  {
1891  $langs->load("bills");
1892  $transkey="PaymentCondition".strtoupper($obj->code);
1893  if ($langs->trans($transkey) != $transkey)
1894  {
1895  $transfound=1;
1896  print $form->textwithpicto($langs->trans($transkey), $langs->trans("GoIntoTranslationMenuToChangeThis"));
1897  }
1898  }
1899  if (! $transfound)
1900  {
1901  print '<textarea cols="30" rows="'.ROWS_2.'" class="flat" name="'.$fieldlist[$field].'">'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'</textarea>';
1902  }
1903  print '</td>';
1904  }
1905  elseif ($fieldlist[$field] == 'price' || preg_match('/^amount/i',$fieldlist[$field])) {
1906  print '<td><input type="text" class="flat minwidth75" value="'.price((! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'')).'" name="'.$fieldlist[$field].'"></td>';
1907  }
1908  elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
1909  print '<td class="maxxxx"><input type="text" class="flat minwidth75" value="'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'"></td>';
1910  }
1911  elseif ($fieldlist[$field]=='unit') {
1912  print '<td>';
1913  $units = array(
1914  'mm' => $langs->trans('SizeUnitmm'),
1915  'cm' => $langs->trans('SizeUnitcm'),
1916  'point' => $langs->trans('SizeUnitpoint'),
1917  'inch' => $langs->trans('SizeUnitinch')
1918  );
1919  print $form->selectarray('unit', $units, (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''), 0, 0, 0);
1920  print '</td>';
1921  }
1922  // Le type de taxe locale
1923  elseif ($fieldlist[$field] == 'localtax1_type' || $fieldlist[$field] == 'localtax2_type')
1924  {
1925  print '<td align="center">';
1926  print $form->selectarray($fieldlist[$field], $localtax_typeList, (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
1927  print '</td>';
1928  }
1929  elseif ($fieldlist[$field] == 'accountancy_code' || $fieldlist[$field] == 'accountancy_code_sell' || $fieldlist[$field] == 'accountancy_code_buy')
1930  {
1931  print '<td>';
1932  if (! empty($conf->accounting->enabled))
1933  {
1934  $fieldname = $fieldlist[$field];
1935  $accountancy_account = (! empty($obj->$fieldname) ? $obj->$fieldname : 0);
1936  print $formaccounting->select_account($accountancy_account, '.'.$fieldlist[$field], 1, '', 1, 1, 'maxwidth200 maxwidthonsmartphone');
1937  }
1938  else
1939  {
1940  $fieldname = $fieldlist[$field];
1941  print '<input type="text" size="10" class="flat" value="'.(isset($obj->$fieldname)?$obj->$fieldname:'').'" name="'.$fieldlist[$field].'">';
1942  }
1943  print '</td>';
1944  }
1945  elseif ($fieldlist[$field] == 'fk_tva')
1946  {
1947  print '<td>';
1948  print $form->load_tva('fk_tva', $obj->taux, $mysoc, new Societe($db), 0, 0, '', false, -1);
1949  print '</td>';
1950  }
1951  elseif ($fieldlist[$field] == 'fk_c_exp_tax_cat')
1952  {
1953  print '<td>';
1954  print $form->selectExpenseCategories($obj->fk_c_exp_tax_cat);
1955  print '</td>';
1956  }
1957  elseif ($fieldlist[$field] == 'fk_range')
1958  {
1959  print '<td>';
1960  print $form->selectExpenseRanges($obj->fk_range);
1961  print '</td>';
1962  }
1963  else
1964  {
1965  if ($fieldlist[$field]=='sortorder') $fieldlist[$field]='position';
1966 
1967  $classtd=''; $class='';
1968  if ($fieldlist[$field]=='code') $classtd='width100';
1969  if ($fieldlist[$field]=='affect') $class='maxwidth50';
1970  if ($fieldlist[$field]=='delay') $class='maxwidth50';
1971  if ($fieldlist[$field]=='position') $class='maxwidth50';
1972  if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') $class='quatrevingtpercent';
1973  if ($fieldlist[$field]=='tracking') $class='quatrevingtpercent';
1974  if ($fieldlist[$field]=='sortorder' || $fieldlist[$field]=='sens' || $fieldlist[$field]=='category_type') $class='maxwidth50';
1975  print '<td class="'.$classtd.'">';
1976  $transfound=0;
1977  if (in_array($fieldlist[$field], array('label','libelle')))
1978  {
1979  $transkey='';
1980  // Special case for labels
1981  if ($tabname == MAIN_DB_PREFIX.'c_civility') {
1982  $transkey="Civility".strtoupper($obj->code);
1983  }
1984  if ($tabname == MAIN_DB_PREFIX.'c_payment_term') {
1985  $langs->load("bills");
1986  $transkey="PaymentCondition".strtoupper($obj->code);
1987  }
1988  if ($transkey && $langs->trans($transkey) != $transkey)
1989  {
1990  $transfound=1;
1991  print $form->textwithpicto($langs->trans($transkey), $langs->trans("GoIntoTranslationMenuToChangeThis"));
1992  }
1993  }
1994  if (! $transfound)
1995  {
1996  print '<input type="text" class="flat'.($class?' '.$class:'').'" value="'.(isset($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'">';
1997  }
1998  print '</td>';
1999  }
2000  }
2001 
2002  return $withentity;
2003 }
2004 
llxFooter()
Empty footer.
Definition: wrapper.php:58
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(!GETPOST('transkey')&&!GETPOST('transphrase')) else
View.
Definition: notice.php:43
complete_elementList_with_modules(&$elementList)
Add external modules to list of contact element.
Definition: admin.lib.php:1206
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
if(GETPOST('cancel','alpha')) if(!GETPOST('confirmmassaction','alpha')&&$massaction!= 'presend'&&$massaction!= 'confirm_presend')
Draft customers invoices.
Definition: list.php:147
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to generate html code for admin pages.
Class to build HTML component for third parties management Only common components are here...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
getDictvalue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return value from dictionary.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage third parties objects (customers, suppliers, prospects...)
print_fleche_navigation($page, $file, $options='', $nextpage=0, $betweenarrows='', $afterarrows='', $limit=-1, $totalnboflines=0, $hideselectlimit=0)
Function to show navigation arrows into lists.
complete_dictionary_with_modules(&$taborder, &$tabname, &$tablib, &$tabsql, &$tabsqlsort, &$tabfield, &$tabfieldvalue, &$tabfieldinsert, &$tabrowid, &$tabcond, &$tabhelp, &$tabfieldcheck)
Add external modules to list of dictionaries.
Definition: admin.lib.php:1032
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='')
Get title line of an array.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
getEntity($element, $shared=1, $forceentity=null)
Get list of entity id to use.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
img_delete($titlealt= 'default', $other= 'class="pictodelete"')
Show delete logo.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
print
Draft customers invoices.
Definition: index.php:91
Class to manage generation of HTML components for accounting management.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...
img_edit($titlealt= 'default', $float=0, $other= 'class="pictoedit"')
Show logo editer/modifier fiche.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...
fieldList($fieldlist, $obj='', $tabname='', $context='')
Show fields in insert/edit mode.
Definition: dict.php:1769