Passed
Push — master ( 7e4a07...284492 )
by Alxarafe
19:58
created

dolibarr/htdocs/admin/dict.php (1 issue)

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