dolibarr 25.0.0-alpha
dict.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
5 * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2010-2022 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2011-2021 Philippe Grand <philippe.grand@atoo-net.com>
8 * Copyright (C) 2011 Remy Younes <ryounes@gmail.com>
9 * Copyright (C) 2012-2015 Marcos García <marcosgdf@gmail.com>
10 * Copyright (C) 2012 Christophe Battarel <christophe.battarel@ltairis.fr>
11 * Copyright (C) 2011-2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
12 * Copyright (C) 2015 Ferran Marcet <fmarcet@2byte.es>
13 * Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
14 * Copyright (C) 2019-2026 Frédéric France <frederic.france@free.fr>
15 * Copyright (C) 2020-2026 Open-Dsi <support@open-dsi.fr>
16 * Copyright (C) 2024-2025 Charlene Benke <charlene@patas-monkey.com>
17 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 3 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <https://www.gnu.org/licenses/>.
31 */
32
39// Load Dolibarr environment
40require '../main.inc.php';
41require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
45require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
46require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
47require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
48require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
49require_once DOL_DOCUMENT_ROOT.'/core/lib/socialnetwork.lib.php';
50
51// constants for IDs of core dictionaries
52const DICT_FORME_JURIDIQUE = 1;
53const DICT_DEPARTEMENTS = 2;
54const DICT_REGIONS = 3;
55const DICT_COUNTRY = 4;
56const DICT_CIVILITY = 5;
57const DICT_ACTIONCOMM = 6;
58const DICT_CHARGESOCIALES = 7;
59const DICT_TYPENT = 8;
60const DICT_CURRENCIES = 9;
61const DICT_TVA = 10;
62const DICT_TYPE_CONTACT = 11;
63const DICT_PAYMENT_TERM = 12;
64const DICT_PAIEMENT = 13;
65const DICT_ECOTAXE = 14;
66const DICT_PAPER_FORMAT = 15;
67const DICT_PROSPECTLEVEL = 16;
68const DICT_TYPE_FEES = 17;
69const DICT_SHIPMENT_MODE = 18;
70const DICT_EFFECTIF = 19;
71const DICT_INPUT_METHOD = 20;
72const DICT_AVAILABILITY = 21;
73const DICT_INPUT_REASON = 22;
74const DICT_REVENUESTAMP = 23;
75const DICT_TYPE_RESOURCE = 24;
76const DICT_TYPE_CONTAINER = 25;
77//const DICT_UNITS = 26;
78const DICT_STCOMM = 27;
79const DICT_HOLIDAY_TYPES = 28;
80const DICT_LEAD_STATUS = 29;
81const DICT_FORMAT_CARDS = 30;
82const DICT_INVOICE_SUBTYPE = 31;
83const DICT_HRM_PUBLIC_HOLIDAY = 32;
84const DICT_HRM_DEPARTMENT = 33;
85const DICT_HRM_FUNCTION = 34;
86const DICT_EXP_TAX_CAT = 35;
87const DICT_EXP_TAX_RANGE = 36;
88const DICT_UNITS = 37;
89const DICT_SOCIALNETWORKS = 38;
90const DICT_PROSPECTCONTACTLEVEL = 39;
91const DICT_STCOMMCONTACT = 40;
92const DICT_TRANSPORT_MODE = 41;
93const DICT_PRODUCT_NATURE = 42;
94const DICT_PRODUCTBATCH_QCSTATUS = 43;
95const DICT_ASSET_DISPOSAL_TYPE = 44;
96
106// Load translation files required by the page
107$langs->loadLangs(array("errors", "admin", "main", "companies", "compta", "resource", "holiday", "accountancy", "hrm", "orders", "contracts", "projects", "propal", "bills", "interventions", "ticket"));
108
109$action = GETPOST('action', 'alpha') ? GETPOST('action', 'alpha') : 'view';
110$confirm = GETPOST('confirm', 'alpha');
111
112$id = GETPOSTINT('id');
113$rowid = GETPOST('rowid', 'alpha');
114$entity = GETPOST('entity', 'alpha'); // Do not use GETPOSTINT here. Should be '', 0 or >0.
115$code = GETPOST('code', 'alpha');
116$from = GETPOST('from', 'alpha');
117
118$acts = array();
119$actl = array();
120$acts[0] = "activate";
121$acts[1] = "disable";
122$actl[0] = img_picto($langs->trans("Disabled"), 'switch_off', 'class="size15x"');
123$actl[1] = img_picto($langs->trans("Activated"), 'switch_on', 'class="size15x"');
124
125// Load variable for pagination
126$listlimit = GETPOST('listlimit') > 0 ? GETPOST('listlimit') : $conf->liste_limit; // To avoid too long dictionaries
127$sortfield = GETPOST('sortfield', 'aZ09comma');
128$sortorder = GETPOST('sortorder', 'aZ09comma');
129$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
130if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
131 // If $page is not defined, or '' or -1 or if we click on clear filters
132 $page = 0;
133}
134$offset = $listlimit * $page;
135$pageprev = $page - 1;
136$pagenext = $page + 1;
137
138$search_country_id = GETPOST('search_country_id', 'int');
139$search_code = GETPOST('search_code', 'alpha');
140$search_active = GETPOST('search_active', 'alpha');
141
142// Special case to set a default value for country according to dictionary
143if (!GETPOSTISSET('search_country_id') && $search_country_id == '' && ($id == DICT_DEPARTEMENTS || $id == DICT_REGIONS || $id == DICT_TVA)) { // 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.
144 $search_country_id = $mysoc->country_id;
145}
146
147// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
148$hookmanager->initHooks(array('admin', 'dictionaryadmin'));
149
150$allowed = $user->admin;
151if ($id == DICT_CHARGESOCIALES && $user->hasRight('accounting', 'chartofaccount')) {
152 $allowed = 1; // Tax page allowed to manager of chart account
153}
154if ($id == DICT_TVA && $user->hasRight('accounting', 'chartofaccount')) {
155 $allowed = 1; // Vat page allowed to manager of chart account
156}
157if ($id == DICT_TYPE_FEES && $user->hasRight('accounting', 'chartofaccount')) {
158 $allowed = 1; // Dictionary with type of expense report and accounting account allowed to manager of chart account
159}
160if (!$allowed) {
162}
163
164$permissiontoadd = $allowed;
165
166
167// This page is a generic page to edit dictionaries
168// Put here declaration of dictionaries properties
169
170// Sort order to show dictionary (0 is space). All other dictionaries (added by modules) will be at end of this.
171$taborder = array(
172 DICT_CURRENCIES, DICT_PAPER_FORMAT, DICT_FORMAT_CARDS, 0,
173 DICT_COUNTRY, DICT_REGIONS, DICT_DEPARTEMENTS, 0,
174 DICT_FORME_JURIDIQUE, DICT_TYPENT, DICT_EFFECTIF, DICT_PROSPECTLEVEL, DICT_PROSPECTCONTACTLEVEL, DICT_STCOMM, DICT_STCOMMCONTACT, DICT_SOCIALNETWORKS, 0,
175 DICT_CIVILITY, DICT_TYPE_CONTACT, 0,
176 DICT_ACTIONCOMM, DICT_TYPE_RESOURCE, 0,
177 DICT_LEAD_STATUS, 0,
178 DICT_HRM_DEPARTMENT, DICT_HRM_FUNCTION, DICT_HRM_PUBLIC_HOLIDAY, DICT_HOLIDAY_TYPES, DICT_TYPE_FEES, DICT_EXP_TAX_CAT, DICT_EXP_TAX_RANGE, 0,
179 DICT_TVA, DICT_INVOICE_SUBTYPE, DICT_REVENUESTAMP, DICT_PAYMENT_TERM, DICT_PAIEMENT, DICT_CHARGESOCIALES, 0,
180 DICT_ECOTAXE, 0,
181 DICT_INPUT_REASON, DICT_INPUT_METHOD, DICT_SHIPMENT_MODE, DICT_AVAILABILITY, DICT_TRANSPORT_MODE, 0,
182 DICT_UNITS, DICT_PRODUCT_NATURE, 0,
183 DICT_PRODUCTBATCH_QCSTATUS, 0,
184 DICT_TYPE_CONTAINER, 0,
185 DICT_ASSET_DISPOSAL_TYPE, 0
186);
187
188// Name of SQL tables of dictionaries
189$tabname = array();
190$tabname[DICT_FORME_JURIDIQUE] = "c_forme_juridique";
191$tabname[DICT_DEPARTEMENTS] = "c_departements";
192$tabname[DICT_REGIONS] = "c_regions";
193$tabname[DICT_COUNTRY] = "c_country";
194$tabname[DICT_CIVILITY] = "c_civility";
195$tabname[DICT_ACTIONCOMM] = "c_actioncomm";
196$tabname[DICT_CHARGESOCIALES] = "c_chargesociales";
197$tabname[DICT_TYPENT] = "c_typent";
198$tabname[DICT_CURRENCIES] = "c_currencies";
199$tabname[DICT_TVA] = "c_tva";
200$tabname[DICT_TYPE_CONTACT] = "c_type_contact";
201$tabname[DICT_PAYMENT_TERM] = "c_payment_term";
202$tabname[DICT_PAIEMENT] = "c_paiement";
203$tabname[DICT_ECOTAXE] = "c_ecotaxe";
204$tabname[DICT_PAPER_FORMAT] = "c_paper_format";
205$tabname[DICT_PROSPECTLEVEL] = "c_prospectlevel";
206$tabname[DICT_TYPE_FEES] = "c_type_fees";
207$tabname[DICT_SHIPMENT_MODE] = "c_shipment_mode";
208$tabname[DICT_EFFECTIF] = "c_effectif";
209$tabname[DICT_INPUT_METHOD] = "c_input_method";
210$tabname[DICT_AVAILABILITY] = "c_availability";
211$tabname[DICT_INPUT_REASON] = "c_input_reason";
212$tabname[DICT_REVENUESTAMP] = "c_revenuestamp";
213$tabname[DICT_TYPE_RESOURCE] = "c_type_resource";
214$tabname[DICT_TYPE_CONTAINER] = "c_type_container";
215//$tabname[DICT_UNITS]= "c_units";
216$tabname[DICT_STCOMM] = "c_stcomm";
217$tabname[DICT_HOLIDAY_TYPES] = "c_holiday_types";
218$tabname[DICT_LEAD_STATUS] = "c_lead_status";
219$tabname[DICT_FORMAT_CARDS] = "c_format_cards";
220$tabname[DICT_INVOICE_SUBTYPE] = "c_invoice_subtype";
221$tabname[DICT_HRM_PUBLIC_HOLIDAY] = "c_hrm_public_holiday";
222$tabname[DICT_HRM_DEPARTMENT] = "c_hrm_department";
223$tabname[DICT_HRM_FUNCTION] = "c_hrm_function";
224$tabname[DICT_EXP_TAX_CAT] = "c_exp_tax_cat";
225$tabname[DICT_EXP_TAX_RANGE] = "c_exp_tax_range";
226$tabname[DICT_UNITS] = "c_units";
227$tabname[DICT_SOCIALNETWORKS] = "c_socialnetworks";
228$tabname[DICT_PROSPECTCONTACTLEVEL] = "c_prospectcontactlevel";
229$tabname[DICT_STCOMMCONTACT] = "c_stcommcontact";
230$tabname[DICT_TRANSPORT_MODE] = "c_transport_mode";
231$tabname[DICT_PRODUCT_NATURE] = "c_product_nature";
232$tabname[DICT_PRODUCTBATCH_QCSTATUS] = "c_productbatch_qcstatus";
233$tabname[DICT_ASSET_DISPOSAL_TYPE] = "c_asset_disposal_type";
234
235// Dictionary labels
236$tablib = array();
237$tablib[DICT_FORME_JURIDIQUE] = "DictionaryCompanyJuridicalType";
238$tablib[DICT_DEPARTEMENTS] = "DictionaryCanton";
239$tablib[DICT_REGIONS] = "DictionaryRegion";
240$tablib[DICT_COUNTRY] = "DictionaryCountry";
241$tablib[DICT_CIVILITY] = "DictionaryCivility";
242$tablib[DICT_ACTIONCOMM] = "DictionaryActions";
243$tablib[DICT_CHARGESOCIALES] = "DictionarySocialContributions";
244$tablib[DICT_TYPENT] = "DictionaryCompanyType";
245$tablib[DICT_CURRENCIES] = "DictionaryCurrency";
246$tablib[DICT_TVA] = "DictionaryVAT";
247$tablib[DICT_TYPE_CONTACT] = "DictionaryTypeContact";
248$tablib[DICT_PAYMENT_TERM] = "DictionaryPaymentConditions";
249$tablib[DICT_PAIEMENT] = "DictionaryPaymentModes";
250$tablib[DICT_ECOTAXE] = "DictionaryEcotaxe";
251$tablib[DICT_PAPER_FORMAT] = "DictionaryPaperFormat";
252$tablib[DICT_PROSPECTLEVEL] = "DictionaryProspectLevel";
253$tablib[DICT_TYPE_FEES] = "DictionaryFees";
254$tablib[DICT_SHIPMENT_MODE] = "DictionarySendingMethods";
255$tablib[DICT_EFFECTIF] = "DictionaryStaff";
256$tablib[DICT_INPUT_METHOD] = "DictionaryOrderMethods";
257$tablib[DICT_AVAILABILITY] = "DictionaryAvailability";
258$tablib[DICT_INPUT_REASON] = "DictionarySource";
259$tablib[DICT_REVENUESTAMP] = "DictionaryRevenueStamp";
260$tablib[DICT_TYPE_RESOURCE] = "DictionaryResourceType";
261$tablib[DICT_TYPE_CONTAINER] = "DictionaryTypeOfContainer";
262//$tablib[DICT_UNITS]= "DictionaryUnits";
263$tablib[DICT_STCOMM] = "DictionaryProspectStatus";
264$tablib[DICT_HOLIDAY_TYPES] = "DictionaryHolidayTypes";
265$tablib[DICT_LEAD_STATUS] = "DictionaryOpportunityStatus";
266$tablib[DICT_FORMAT_CARDS] = "DictionaryFormatCards";
267$tablib[DICT_INVOICE_SUBTYPE] = "DictionaryInvoiceSubtype";
268$tablib[DICT_HRM_PUBLIC_HOLIDAY] = "DictionaryPublicHolidays";
269$tablib[DICT_HRM_DEPARTMENT] = "DictionaryDepartment";
270$tablib[DICT_HRM_FUNCTION] = "DictionaryFunction";
271$tablib[DICT_EXP_TAX_CAT] = "DictionaryExpenseTaxCat";
272$tablib[DICT_EXP_TAX_RANGE] = "DictionaryExpenseTaxRange";
273$tablib[DICT_UNITS] = "DictionaryMeasuringUnits";
274$tablib[DICT_SOCIALNETWORKS] = "DictionarySocialNetworks";
275$tablib[DICT_PROSPECTCONTACTLEVEL] = "DictionaryProspectContactLevel";
276$tablib[DICT_STCOMMCONTACT] = "DictionaryProspectContactStatus";
277$tablib[DICT_TRANSPORT_MODE] = "DictionaryTransportMode";
278$tablib[DICT_PRODUCT_NATURE] = "DictionaryProductNature";
279$tablib[DICT_PRODUCTBATCH_QCSTATUS] = "DictionaryBatchStatus";
280$tablib[DICT_ASSET_DISPOSAL_TYPE] = "DictionaryAssetDisposalType";
281
282// Requests to extract data
283$tabsql = array();
284$tabsql[DICT_FORME_JURIDIQUE] = "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";
285$tabsql[DICT_DEPARTEMENTS] = "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";
286$tabsql[DICT_REGIONS] = "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";
287$tabsql[DICT_COUNTRY] = "SELECT c.rowid as rowid, c.code, c.label, c.phone_code, c.trunk_prefix, c.active, c.favorite, c.eec, c.sepa FROM ".MAIN_DB_PREFIX."c_country AS c";
288$tabsql[DICT_CIVILITY] = "SELECT c.rowid as rowid, c.code as code, c.label, c.active FROM ".MAIN_DB_PREFIX."c_civility AS c";
289$tabsql[DICT_ACTIONCOMM] = "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";
290$tabsql[DICT_CHARGESOCIALES] = "SELECT a.id as rowid, a.code as code, a.libelle AS libelle, a.accountancy_code as accountancy_code, 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";
291$tabsql[DICT_TYPENT] = "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.module, 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";
292$tabsql[DICT_CURRENCIES] = "SELECT c.code_iso as code, c.label, c.unicode, c.active FROM ".MAIN_DB_PREFIX."c_currencies AS c";
293$tabsql[DICT_TVA] = "SELECT t.rowid, t.entity, t.code, t.type_vat, t.taux, t.localtax1_type, t.localtax1, t.localtax2_type, t.localtax2, t.einvoice_vatex, c.label as country, c.code as country_code, t.fk_pays as country_id, t.fk_department_buyer as department_buyer_id, db.nom as department_buyer, t.recuperableonly, t.note, t.active, t.accountancy_code_sell, t.accountancy_code_buy, t.use_default FROM "
294 .MAIN_DB_PREFIX."c_tva as t INNER JOIN "
295 .MAIN_DB_PREFIX."c_country as c ON t.fk_pays = c.rowid LEFT JOIN "
296 .MAIN_DB_PREFIX."c_departements as db ON t.fk_department_buyer = db.rowid WHERE t.entity IN ("
297 .getEntity($tabname[DICT_TVA]).")";
298$tabsql[DICT_TYPE_CONTACT] = "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";
299$tabsql[DICT_PAYMENT_TERM] = "SELECT c.rowid as rowid, c.code, c.libelle, c.libelle_facture, c.deposit_percent, 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 IN (".getEntity($tabname[DICT_PAYMENT_TERM]).")";
300$tabsql[DICT_PAIEMENT] = "SELECT c.id as rowid, c.code, c.libelle, c.type, c.accountancy_code, c.active, c.entity FROM ".MAIN_DB_PREFIX."c_paiement AS c WHERE c.entity IN (".getEntity($tabname[DICT_PAIEMENT]).")";
301$tabsql[DICT_ECOTAXE] = "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";
302$tabsql[DICT_PAPER_FORMAT] = "SELECT t.rowid as rowid, t.code, t.label as libelle, t.width, t.height, t.unit, t.active FROM ".MAIN_DB_PREFIX."c_paper_format as t";
303$tabsql[DICT_PROSPECTLEVEL] = "SELECT t.code, t.label as libelle, t.sortorder, t.active FROM ".MAIN_DB_PREFIX."c_prospectlevel as t";
304$tabsql[DICT_TYPE_FEES] = "SELECT t.id as rowid, t.code, t.label, t.accountancy_code, t.active FROM ".MAIN_DB_PREFIX."c_type_fees as t";
305$tabsql[DICT_SHIPMENT_MODE] = "SELECT t.rowid as rowid, t.code, t.libelle, t.tracking, t.active FROM ".MAIN_DB_PREFIX."c_shipment_mode as t";
306$tabsql[DICT_EFFECTIF] = "SELECT t.id as rowid, t.code, t.libelle, t.active FROM ".MAIN_DB_PREFIX."c_effectif as t";
307$tabsql[DICT_INPUT_METHOD] = "SELECT t.rowid as rowid, t.code, t.libelle, t.active FROM ".MAIN_DB_PREFIX."c_input_method as t";
308$tabsql[DICT_AVAILABILITY] = "SELECT c.rowid as rowid, c.code, c.label, c.type_duration, c.qty, c.active, c.position FROM ".MAIN_DB_PREFIX."c_availability AS c";
309$tabsql[DICT_INPUT_REASON] = "SELECT t.rowid as rowid, t.code, t.label, t.active FROM ".MAIN_DB_PREFIX."c_input_reason as t";
310$tabsql[DICT_REVENUESTAMP] = "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";
311$tabsql[DICT_TYPE_RESOURCE] = "SELECT t.rowid as rowid, t.code, t.label, t.active FROM ".MAIN_DB_PREFIX."c_type_resource as t";
312$tabsql[DICT_TYPE_CONTAINER] = "SELECT t.rowid as rowid, t.entity, t.code, t.label, t.active, t.module FROM ".MAIN_DB_PREFIX."c_type_container as t WHERE t.entity IN (".getEntity($tabname[DICT_TYPE_CONTAINER]).")";
313//$tabsql[DICT_UNITS]= "SELECT t.rowid as rowid, t.code, t.label, t.short_label, t.active FROM ".MAIN_DB_PREFIX."c_units as t";
314$tabsql[DICT_STCOMM] = "SELECT t.id as rowid, t.code, t.libelle, t.picto, t.active FROM ".MAIN_DB_PREFIX."c_stcomm as t";
315$tabsql[DICT_HOLIDAY_TYPES] = "SELECT h.rowid as rowid, h.entity, 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.block_if_negative, h.sortorder, 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 WHERE h.entity IN (".getEntity($tabname[DICT_HOLIDAY_TYPES]).")";
316$tabsql[DICT_LEAD_STATUS] = "SELECT t.rowid as rowid, t.code, t.label, percent, t.position, t.active FROM ".MAIN_DB_PREFIX."c_lead_status as t";
317$tabsql[DICT_FORMAT_CARDS] = "SELECT t.rowid, t.code, t.name, t.paper_size, t.orientation, t.metric, t.leftmargin, t.topmargin, t.nx, t.ny, t.spacex, t.spacey, t.width, t.height, t.font_size, t.custom_x, t.custom_y, t.active FROM ".MAIN_DB_PREFIX."c_format_cards as t";
318$tabsql[DICT_INVOICE_SUBTYPE] = "SELECT t.rowid, t.code, t.label, c.label as country, c.code as country_code, t.fk_country as country_id, t.active FROM ".MAIN_DB_PREFIX."c_invoice_subtype as t, ".MAIN_DB_PREFIX."c_country as c WHERE t.fk_country = c.rowid";
319$tabsql[DICT_HRM_PUBLIC_HOLIDAY] = "SELECT a.id as rowid, a.entity, a.code, a.fk_country as country_id, c.code as country_code, c.label as country, a.dayrule, a.day, a.month, a.year, a.active FROM ".MAIN_DB_PREFIX."c_hrm_public_holiday as a LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON a.fk_country=c.rowid AND c.active=1 WHERE a.entity IN (".getEntity($tabname[DICT_HRM_PUBLIC_HOLIDAY]).")";
320$tabsql[DICT_HRM_DEPARTMENT] = "SELECT t.rowid, t.pos, t.code, t.label, t.active FROM ".MAIN_DB_PREFIX."c_hrm_department as t";
321$tabsql[DICT_HRM_FUNCTION] = "SELECT t.rowid, t.pos, t.code, t.label, t.c_level, t.active FROM ".MAIN_DB_PREFIX."c_hrm_function as t";
322$tabsql[DICT_EXP_TAX_CAT] = "SELECT c.rowid, c.label, c.active, c.entity FROM ".MAIN_DB_PREFIX."c_exp_tax_cat as c";
323$tabsql[DICT_EXP_TAX_RANGE] = "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";
324$tabsql[DICT_UNITS] = "SELECT r.rowid, r.code, r.sortorder, r.label, r.short_label, r.unit_type, r.scale, r.active FROM ".MAIN_DB_PREFIX."c_units r";
325$tabsql[DICT_SOCIALNETWORKS] = "SELECT s.rowid, s.entity, s.code, s.label, s.url, s.icon, s.active FROM ".MAIN_DB_PREFIX."c_socialnetworks as s WHERE s.entity IN (".getEntity($tabname[DICT_SOCIALNETWORKS]).")";
326$tabsql[DICT_PROSPECTCONTACTLEVEL] = "SELECT t.code, t.label as libelle, t.sortorder, t.active FROM ".MAIN_DB_PREFIX."c_prospectcontactlevel as t";
327$tabsql[DICT_STCOMMCONTACT] = "SELECT t.id as rowid, t.code, t.libelle, t.picto, t.active FROM ".MAIN_DB_PREFIX."c_stcommcontact as t";
328$tabsql[DICT_TRANSPORT_MODE] = "SELECT t.rowid as rowid, t.code, t.label, t.active FROM ".MAIN_DB_PREFIX."c_transport_mode as t";
329$tabsql[DICT_PRODUCT_NATURE] = "SELECT t.rowid as rowid, t.code, t.label, t.active FROM ".MAIN_DB_PREFIX."c_product_nature as t";
330$tabsql[DICT_PRODUCTBATCH_QCSTATUS] = "SELECT t.rowid, t.code, t.label, t.active FROM ".MAIN_DB_PREFIX."c_productbatch_qcstatus as t";
331$tabsql[DICT_ASSET_DISPOSAL_TYPE] = "SELECT t.rowid, t.code, t.label, t.active FROM ".MAIN_DB_PREFIX."c_asset_disposal_type as t";
332
333// Criteria to sort dictionaries
334$tabsqlsort = array();
335$tabsqlsort[DICT_FORME_JURIDIQUE] = "country ASC, code ASC";
336$tabsqlsort[DICT_DEPARTEMENTS] = "country ASC, code ASC";
337$tabsqlsort[DICT_REGIONS] = "country ASC, code ASC";
338$tabsqlsort[DICT_COUNTRY] = "code ASC";
339$tabsqlsort[DICT_CIVILITY] = "label ASC";
340$tabsqlsort[DICT_ACTIONCOMM] = "a.type ASC, a.module ASC, a.position ASC, a.code ASC";
341$tabsqlsort[DICT_CHARGESOCIALES] = "c.label ASC, a.code ASC, a.libelle ASC";
342$tabsqlsort[DICT_TYPENT] = "country DESC,".(getDolGlobalString('SOCIETE_SORT_ON_TYPEENT') ? ' t.position ASC,' : '')." libelle ASC";
343$tabsqlsort[DICT_CURRENCIES] = "label ASC";
344$tabsqlsort[DICT_TVA] = "country ASC, department_buyer ASC, code ASC, taux ASC, recuperableonly ASC, localtax1 ASC, localtax2 ASC";
345$tabsqlsort[DICT_TYPE_CONTACT] = "t.element ASC, t.source ASC, t.position ASC, t.code ASC";
346$tabsqlsort[DICT_PAYMENT_TERM] = "sortorder ASC, code ASC";
347$tabsqlsort[DICT_PAIEMENT] = "code ASC";
348$tabsqlsort[DICT_ECOTAXE] = "country ASC, e.organization ASC, code ASC";
349$tabsqlsort[DICT_PAPER_FORMAT] = "rowid ASC";
350$tabsqlsort[DICT_PROSPECTLEVEL] = "sortorder ASC";
351$tabsqlsort[DICT_TYPE_FEES] = "code ASC";
352$tabsqlsort[DICT_SHIPMENT_MODE] = "code ASC, libelle ASC";
353$tabsqlsort[DICT_EFFECTIF] = "id ASC";
354$tabsqlsort[DICT_INPUT_METHOD] = "code ASC, libelle ASC";
355$tabsqlsort[DICT_AVAILABILITY] = "position ASC, type_duration ASC, qty ASC";
356$tabsqlsort[DICT_INPUT_REASON] = "code ASC, label ASC";
357$tabsqlsort[DICT_REVENUESTAMP] = "country ASC, taux ASC";
358$tabsqlsort[DICT_TYPE_RESOURCE] = "code ASC, label ASC";
359$tabsqlsort[DICT_TYPE_CONTAINER] = "t.module ASC, t.code ASC, t.label ASC";
360//$tabsqlsort[DICT_UNITS]="code ASC";
361$tabsqlsort[DICT_STCOMM] = "code ASC";
362$tabsqlsort[DICT_HOLIDAY_TYPES] = "sortorder ASC, country ASC, code ASC";
363$tabsqlsort[DICT_LEAD_STATUS] = "position ASC";
364$tabsqlsort[DICT_FORMAT_CARDS] = "code ASC";
365$tabsqlsort[DICT_INVOICE_SUBTYPE] = "country ASC, code ASC";
366$tabsqlsort[DICT_HRM_PUBLIC_HOLIDAY] = "country, year ASC, month ASC, day ASC";
367$tabsqlsort[DICT_HRM_DEPARTMENT] = "code ASC";
368$tabsqlsort[DICT_HRM_FUNCTION] = "code ASC";
369$tabsqlsort[DICT_EXP_TAX_CAT] = "c.label ASC";
370$tabsqlsort[DICT_EXP_TAX_RANGE] = "r.fk_c_exp_tax_cat ASC, r.range_ik ASC";
371$tabsqlsort[DICT_UNITS] = "sortorder ASC";
372$tabsqlsort[DICT_SOCIALNETWORKS] = "rowid, code ASC";
373$tabsqlsort[DICT_PROSPECTCONTACTLEVEL] = "sortorder ASC";
374$tabsqlsort[DICT_STCOMMCONTACT] = "code ASC";
375$tabsqlsort[DICT_TRANSPORT_MODE] = "code ASC";
376$tabsqlsort[DICT_PRODUCT_NATURE] = "code ASC";
377$tabsqlsort[DICT_PRODUCTBATCH_QCSTATUS] = "code ASC";
378$tabsqlsort[DICT_ASSET_DISPOSAL_TYPE] = "code ASC";
379
380// Field names in select result for dictionary display
381$tabfield = array();
382$tabfield[DICT_FORME_JURIDIQUE] = "code,libelle,country";
383$tabfield[DICT_DEPARTEMENTS] = "code,libelle,region_id,region,country"; // "code,libelle,region,country_code-country"
384$tabfield[DICT_REGIONS] = "code,libelle,country_id,country";
385$tabfield[DICT_COUNTRY] = "code,label,phone_code,trunk_prefix";
386$tabfield[DICT_CIVILITY] = "code,label";
387$tabfield[DICT_ACTIONCOMM] = "code,libelle,type,color,position";
388$tabfield[DICT_CHARGESOCIALES] = "code,libelle,country,accountancy_code";
389$tabfield[DICT_TYPENT] = "code,libelle,module,country_id,country".(getDolGlobalString('SOCIETE_SORT_ON_TYPEENT') ? ',position' : '');
390$tabfield[DICT_CURRENCIES] = "code,label,unicode";
391$tabfield[DICT_TVA] = "country_id,country,department_buyer_id,department_buyer,code,type_vat,taux,localtax1_type,localtax1,localtax2_type,localtax2,recuperableonly,einvoice_vatex,accountancy_code_sell,accountancy_code_buy,use_default,note";
392$tabfield[DICT_TYPE_CONTACT] = "element,source,code,libelle,position";
393$tabfield[DICT_PAYMENT_TERM] = "code,libelle,libelle_facture,deposit_percent,nbjour,type_cdr,decalage,sortorder";
394$tabfield[DICT_PAIEMENT] = "code,libelle,type,accountancy_code";
395$tabfield[DICT_ECOTAXE] = "code,label,price,organization,country";
396$tabfield[DICT_PAPER_FORMAT] = "code,libelle,width,height,unit";
397$tabfield[DICT_PROSPECTLEVEL] = "code,libelle,sortorder";
398$tabfield[DICT_TYPE_FEES] = "code,label,accountancy_code";
399$tabfield[DICT_SHIPMENT_MODE] = "code,libelle,tracking";
400$tabfield[DICT_EFFECTIF] = "code,libelle";
401$tabfield[DICT_INPUT_METHOD] = "code,libelle";
402$tabfield[DICT_AVAILABILITY] = "code,label,qty,type_duration,position";
403$tabfield[DICT_INPUT_REASON] = "code,label";
404$tabfield[DICT_REVENUESTAMP] = "country_id,country,taux,revenuestamp_type,accountancy_code_sell,accountancy_code_buy,note";
405$tabfield[DICT_TYPE_RESOURCE] = "code,label";
406$tabfield[DICT_TYPE_CONTAINER] = "code,label";
407//$tabfield[DICT_UNITS]= "code,label,short_label";
408$tabfield[DICT_STCOMM] = "code,libelle,picto";
409$tabfield[DICT_HOLIDAY_TYPES] = "code,label,affect,delay,newbymonth,country_id,country,block_if_negative,sortorder";
410$tabfield[DICT_LEAD_STATUS] = "code,label,percent,position";
411$tabfield[DICT_FORMAT_CARDS] = "code,name,paper_size,orientation,metric,leftmargin,topmargin,nx,ny,spacex,spacey,width,height,font_size,custom_x,custom_y";
412$tabfield[DICT_INVOICE_SUBTYPE] = "country_id,country,code,label";
413$tabfield[DICT_HRM_PUBLIC_HOLIDAY] = "code,dayrule,year,month,day,country_id,country";
414$tabfield[DICT_HRM_DEPARTMENT] = "code,label";
415$tabfield[DICT_HRM_FUNCTION] = "code,label";
416$tabfield[DICT_EXP_TAX_CAT] = "label";
417$tabfield[DICT_EXP_TAX_RANGE] = "range_ik,fk_c_exp_tax_cat";
418$tabfield[DICT_UNITS] = "code,label,short_label,unit_type,scale,sortorder";
419$tabfield[DICT_SOCIALNETWORKS] = "code,label,url,icon";
420$tabfield[DICT_PROSPECTCONTACTLEVEL] = "code,libelle,sortorder";
421$tabfield[DICT_STCOMMCONTACT] = "code,libelle,picto";
422$tabfield[DICT_TRANSPORT_MODE] = "code,label";
423$tabfield[DICT_PRODUCT_NATURE] = "code,label";
424$tabfield[DICT_PRODUCTBATCH_QCSTATUS] = "code,label";
425$tabfield[DICT_ASSET_DISPOSAL_TYPE] = "code,label";
426
427// Edit field names for editing a record
428$tabfieldvalue = array();
429$tabfieldvalue[DICT_FORME_JURIDIQUE] = "code,libelle,country";
430$tabfieldvalue[DICT_DEPARTEMENTS] = "code,libelle,region"; // "code,libelle,region"
431$tabfieldvalue[DICT_REGIONS] = "code,libelle,country";
432$tabfieldvalue[DICT_COUNTRY] = "code,label,phone_code,trunk_prefix";
433$tabfieldvalue[DICT_CIVILITY] = "code,label";
434$tabfieldvalue[DICT_ACTIONCOMM] = "code,libelle,type,color,position";
435$tabfieldvalue[DICT_CHARGESOCIALES] = "code,libelle,country,accountancy_code";
436$tabfieldvalue[DICT_TYPENT] = "code,libelle,country".(getDolGlobalString('SOCIETE_SORT_ON_TYPEENT') ? ',position' : '');
437$tabfieldvalue[DICT_CURRENCIES] = "code,label,unicode";
438$tabfieldvalue[DICT_TVA] = "country,department_buyer_id,code,type_vat,taux,localtax1_type,localtax1,localtax2_type,localtax2,recuperableonly,einvoice_vatex,accountancy_code_sell,accountancy_code_buy,use_default,note";
439$tabfieldvalue[DICT_TYPE_CONTACT] = "element,source,code,libelle,position";
440$tabfieldvalue[DICT_PAYMENT_TERM] = "code,libelle,libelle_facture,deposit_percent,nbjour,type_cdr,decalage,sortorder";
441$tabfieldvalue[DICT_PAIEMENT] = "code,libelle,type,accountancy_code";
442$tabfieldvalue[DICT_ECOTAXE] = "code,label,price,organization,country";
443$tabfieldvalue[DICT_PAPER_FORMAT] = "code,libelle,width,height,unit";
444$tabfieldvalue[DICT_PROSPECTLEVEL] = "code,libelle,sortorder";
445$tabfieldvalue[DICT_TYPE_FEES] = "code,label,accountancy_code";
446$tabfieldvalue[DICT_SHIPMENT_MODE] = "code,libelle,tracking";
447$tabfieldvalue[DICT_EFFECTIF] = "code,libelle";
448$tabfieldvalue[DICT_INPUT_METHOD] = "code,libelle";
449$tabfieldvalue[DICT_AVAILABILITY] = "code,label,qty,type_duration,position";
450$tabfieldvalue[DICT_INPUT_REASON] = "code,label";
451$tabfieldvalue[DICT_REVENUESTAMP] = "country,taux,revenuestamp_type,accountancy_code_sell,accountancy_code_buy,note";
452$tabfieldvalue[DICT_TYPE_RESOURCE] = "code,label";
453$tabfieldvalue[DICT_TYPE_CONTAINER] = "code,label";
454//$tabfieldvalue[DICT_UNITS]= "code,label,short_label";
455$tabfieldvalue[DICT_STCOMM] = "code,libelle,picto";
456$tabfieldvalue[DICT_HOLIDAY_TYPES] = "code,label,affect,delay,newbymonth,country,block_if_negative,sortorder";
457$tabfieldvalue[DICT_LEAD_STATUS] = "code,label,percent,position";
458$tabfieldvalue[DICT_FORMAT_CARDS] = "code,name,paper_size,orientation,metric,leftmargin,topmargin,nx,ny,spacex,spacey,width,height,font_size,custom_x,custom_y";
459$tabfieldvalue[DICT_INVOICE_SUBTYPE] = "country,code,label";
460$tabfieldvalue[DICT_HRM_PUBLIC_HOLIDAY] = "code,dayrule,day,month,year,country";
461$tabfieldvalue[DICT_HRM_DEPARTMENT] = "code,label";
462$tabfieldvalue[DICT_HRM_FUNCTION] = "code,label";
463$tabfieldvalue[DICT_EXP_TAX_CAT] = "label";
464$tabfieldvalue[DICT_EXP_TAX_RANGE] = "range_ik,fk_c_exp_tax_cat";
465$tabfieldvalue[DICT_UNITS] = "code,label,short_label,unit_type,scale,sortorder";
466$tabfieldvalue[DICT_SOCIALNETWORKS] = "code,label,url,icon";
467$tabfieldvalue[DICT_PROSPECTCONTACTLEVEL] = "code,libelle,sortorder";
468$tabfieldvalue[DICT_STCOMMCONTACT] = "code,libelle,picto";
469$tabfieldvalue[DICT_TRANSPORT_MODE] = "code,label";
470$tabfieldvalue[DICT_PRODUCT_NATURE] = "code,label";
471$tabfieldvalue[DICT_PRODUCTBATCH_QCSTATUS] = "code,label";
472$tabfieldvalue[DICT_ASSET_DISPOSAL_TYPE] = "code,label";
473
474// Field names in the table for inserting a record (add field "entity" only here when dictionary is ready to personalized by entity)
475$tabfieldinsert = array();
476$tabfieldinsert[DICT_FORME_JURIDIQUE] = "code,libelle,fk_pays";
477$tabfieldinsert[DICT_DEPARTEMENTS] = "code_departement,nom,fk_region";
478$tabfieldinsert[DICT_REGIONS] = "code_region,nom,fk_pays";
479$tabfieldinsert[DICT_COUNTRY] = "code,label,phone_code,trunk_prefix";
480$tabfieldinsert[DICT_CIVILITY] = "code,label";
481$tabfieldinsert[DICT_ACTIONCOMM] = "code,libelle,type,color,position";
482$tabfieldinsert[DICT_CHARGESOCIALES] = "code,libelle,fk_pays,accountancy_code";
483$tabfieldinsert[DICT_TYPENT] = "code,libelle,fk_country".(getDolGlobalString('SOCIETE_SORT_ON_TYPEENT') ? ',position' : '');
484$tabfieldinsert[DICT_CURRENCIES] = "code_iso,label,unicode";
485$tabfieldinsert[DICT_TVA] = "fk_pays,fk_department_buyer,code,type_vat,taux,localtax1_type,localtax1,localtax2_type,localtax2,recuperableonly,einvoice_vatex,accountancy_code_sell,accountancy_code_buy,use_default,note,entity";
486$tabfieldinsert[DICT_TYPE_CONTACT] = "element,source,code,libelle,position";
487$tabfieldinsert[DICT_PAYMENT_TERM] = "code,libelle,libelle_facture,deposit_percent,nbjour,type_cdr,decalage,sortorder,entity";
488$tabfieldinsert[DICT_PAIEMENT] = "code,libelle,type,accountancy_code,entity";
489$tabfieldinsert[DICT_ECOTAXE] = "code,label,price,organization,fk_pays";
490$tabfieldinsert[DICT_PAPER_FORMAT] = "code,label,width,height,unit";
491$tabfieldinsert[DICT_PROSPECTLEVEL] = "code,label,sortorder";
492$tabfieldinsert[DICT_TYPE_FEES] = "code,label,accountancy_code";
493$tabfieldinsert[DICT_SHIPMENT_MODE] = "code,libelle,tracking";
494$tabfieldinsert[DICT_EFFECTIF] = "code,libelle";
495$tabfieldinsert[DICT_INPUT_METHOD] = "code,libelle";
496$tabfieldinsert[DICT_AVAILABILITY] = "code,label,qty,type_duration,position";
497$tabfieldinsert[DICT_INPUT_REASON] = "code,label";
498$tabfieldinsert[DICT_REVENUESTAMP] = "fk_pays,taux,revenuestamp_type,accountancy_code_sell,accountancy_code_buy,note";
499$tabfieldinsert[DICT_TYPE_RESOURCE] = "code,label";
500$tabfieldinsert[DICT_TYPE_CONTAINER] = "code,label,entity";
501//$tabfieldinsert[DICT_UNITS]= "code,label,short_label";
502$tabfieldinsert[DICT_STCOMM] = "code,libelle,picto";
503$tabfieldinsert[DICT_HOLIDAY_TYPES] = "code,label,affect,delay,newbymonth,fk_country,block_if_negative,sortorder,entity";
504$tabfieldinsert[DICT_LEAD_STATUS] = "code,label,percent,position";
505$tabfieldinsert[DICT_FORMAT_CARDS] = "code,name,paper_size,orientation,metric,leftmargin,topmargin,nx,ny,spacex,spacey,width,height,font_size,custom_x,custom_y";
506$tabfieldinsert[DICT_INVOICE_SUBTYPE] = "fk_country,code,label";
507$tabfieldinsert[DICT_HRM_PUBLIC_HOLIDAY] = "code,dayrule,day,month,year,fk_country,entity";
508$tabfieldinsert[DICT_HRM_DEPARTMENT] = "code,label";
509$tabfieldinsert[DICT_HRM_FUNCTION] = "code,label";
510$tabfieldinsert[DICT_EXP_TAX_CAT] = "label";
511$tabfieldinsert[DICT_EXP_TAX_RANGE] = "range_ik,fk_c_exp_tax_cat";
512$tabfieldinsert[DICT_UNITS] = "code,label,short_label,unit_type,scale,sortorder";
513$tabfieldinsert[DICT_SOCIALNETWORKS] = "code,label,url,icon,entity";
514$tabfieldinsert[DICT_PROSPECTCONTACTLEVEL] = "code,label,sortorder";
515$tabfieldinsert[DICT_STCOMMCONTACT] = "code,libelle,picto";
516$tabfieldinsert[DICT_TRANSPORT_MODE] = "code,label";
517$tabfieldinsert[DICT_PRODUCT_NATURE] = "code,label";
518$tabfieldinsert[DICT_PRODUCTBATCH_QCSTATUS] = "code,label";
519$tabfieldinsert[DICT_ASSET_DISPOSAL_TYPE] = "code,label";
520
521// Rowid name of field depending if field is autoincrement on or off..
522// Use "" if id field is "rowid" and has autoincrement on
523// Use "nameoffield" if id field is not "rowid" or has not autoincrement on
524$tabrowid = array();
525$tabrowid[DICT_FORME_JURIDIQUE] = "";
526$tabrowid[DICT_DEPARTEMENTS] = "";
527$tabrowid[DICT_REGIONS] = "";
528$tabrowid[DICT_COUNTRY] = "rowid";
529$tabrowid[DICT_CIVILITY] = "rowid";
530$tabrowid[DICT_ACTIONCOMM] = "id";
531$tabrowid[DICT_CHARGESOCIALES] = "id";
532$tabrowid[DICT_TYPENT] = "id";
533$tabrowid[DICT_CURRENCIES] = "code_iso";
534$tabrowid[DICT_TVA] = "";
535$tabrowid[DICT_TYPE_CONTACT] = "rowid";
536$tabrowid[DICT_PAYMENT_TERM] = "";
537$tabrowid[DICT_PAIEMENT] = "id";
538$tabrowid[DICT_ECOTAXE] = "";
539$tabrowid[DICT_PAPER_FORMAT] = "";
540$tabrowid[DICT_PROSPECTLEVEL] = "code";
541$tabrowid[DICT_TYPE_FEES] = "id";
542$tabrowid[DICT_SHIPMENT_MODE] = "rowid";
543$tabrowid[DICT_EFFECTIF] = "id";
544$tabrowid[DICT_INPUT_METHOD] = "";
545$tabrowid[DICT_AVAILABILITY] = "rowid";
546$tabrowid[DICT_INPUT_REASON] = "rowid";
547$tabrowid[DICT_REVENUESTAMP] = "";
548$tabrowid[DICT_TYPE_RESOURCE] = "";
549$tabrowid[DICT_TYPE_CONTAINER] = "";
550//$tabrowid[DICT_UNITS]= "";
551$tabrowid[DICT_STCOMM] = "id";
552$tabrowid[DICT_HOLIDAY_TYPES] = "";
553$tabrowid[DICT_LEAD_STATUS] = "";
554$tabrowid[DICT_FORMAT_CARDS] = "";
555$tabrowid[DICT_INVOICE_SUBTYPE] = "";
556$tabrowid[DICT_HRM_PUBLIC_HOLIDAY] = "id";
557$tabrowid[DICT_HRM_DEPARTMENT] = "rowid";
558$tabrowid[DICT_HRM_FUNCTION] = "rowid";
559$tabrowid[DICT_EXP_TAX_CAT] = "";
560$tabrowid[DICT_EXP_TAX_RANGE] = "";
561$tabrowid[DICT_UNITS] = "";
562$tabrowid[DICT_SOCIALNETWORKS] = "";
563$tabrowid[DICT_PROSPECTCONTACTLEVEL] = "code";
564$tabrowid[DICT_STCOMMCONTACT] = "id";
565$tabrowid[DICT_TRANSPORT_MODE] = "";
566$tabrowid[DICT_PRODUCT_NATURE] = "rowid";
567$tabrowid[DICT_PRODUCTBATCH_QCSTATUS] = "rowid";
568$tabrowid[DICT_ASSET_DISPOSAL_TYPE] = "rowid";
569
570// Condition to show dictionary in setup page
571$tabcond = array();
572$tabcond[DICT_FORME_JURIDIQUE] = (isModEnabled("societe"));
573$tabcond[DICT_DEPARTEMENTS] = true;
574$tabcond[DICT_REGIONS] = true;
575$tabcond[DICT_COUNTRY] = true;
576$tabcond[DICT_CIVILITY] = (isModEnabled("societe") || isModEnabled('member'));
577$tabcond[DICT_ACTIONCOMM] = isModEnabled('agenda');
578$tabcond[DICT_CHARGESOCIALES] = isModEnabled('tax');
579$tabcond[DICT_TYPENT] = isModEnabled("societe");
580$tabcond[DICT_CURRENCIES] = true;
581$tabcond[DICT_TVA] = true;
582$tabcond[DICT_TYPE_CONTACT] = (isModEnabled("societe"));
583$tabcond[DICT_PAYMENT_TERM] = (isModEnabled('order') || isModEnabled("propal") || isModEnabled('invoice') || isModEnabled("supplier_invoice") || isModEnabled("supplier_order"));
584$tabcond[DICT_PAIEMENT] = (isModEnabled('order') || isModEnabled("propal") || isModEnabled('invoice') || isModEnabled("supplier_invoice") || isModEnabled("supplier_order"));
585$tabcond[DICT_ECOTAXE] = (isModEnabled("product") && (isModEnabled('ecotax') || getDolGlobalString('MAIN_SHOW_ECOTAX_DICTIONNARY')));
586$tabcond[DICT_PAPER_FORMAT] = true;
587$tabcond[DICT_PROSPECTLEVEL] = (isModEnabled("societe") && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS'));
588$tabcond[DICT_TYPE_FEES] = (isModEnabled('deplacement') || isModEnabled('expensereport'));
589$tabcond[DICT_SHIPMENT_MODE] = isModEnabled("shipping") || isModEnabled("reception");
590$tabcond[DICT_EFFECTIF] = isModEnabled("societe");
591$tabcond[DICT_INPUT_METHOD] = isModEnabled("supplier_order");
592$tabcond[DICT_AVAILABILITY] = isModEnabled("propal");
593$tabcond[DICT_INPUT_REASON] = (isModEnabled('order') || isModEnabled("propal"));
594$tabcond[DICT_REVENUESTAMP] = true;
595$tabcond[DICT_TYPE_RESOURCE] = isModEnabled('resource');
596$tabcond[DICT_TYPE_CONTAINER] = isModEnabled('website');
597//$tabcond[DICT_UNITS]= isModEnabled("product");
598$tabcond[DICT_STCOMM] = isModEnabled("societe");
599$tabcond[DICT_HOLIDAY_TYPES] = isModEnabled('holiday');
600$tabcond[DICT_LEAD_STATUS] = isModEnabled('project');
601$tabcond[DICT_FORMAT_CARDS] = (isModEnabled('label') || isModEnabled('barcode') || isModEnabled('member')); // stickers format dictionary
602$tabcond[DICT_INVOICE_SUBTYPE] = ((isModEnabled('invoice') || isModEnabled('supplier_invoice')) && $mysoc->country_code == 'GR');
603$tabcond[DICT_HRM_PUBLIC_HOLIDAY] = (isModEnabled('holiday') || isModEnabled('hrm'));
604$tabcond[DICT_HRM_DEPARTMENT] = isModEnabled('hrm');
605$tabcond[DICT_HRM_FUNCTION] = isModEnabled('hrm');
606$tabcond[DICT_EXP_TAX_CAT] = isModEnabled('expensereport') && getDolGlobalString('MAIN_USE_EXPENSE_IK');
607$tabcond[DICT_EXP_TAX_RANGE] = isModEnabled('expensereport') && getDolGlobalString('MAIN_USE_EXPENSE_IK');
608$tabcond[DICT_UNITS] = isModEnabled("product");
609$tabcond[DICT_SOCIALNETWORKS] = isModEnabled('socialnetworks');
610$tabcond[DICT_PROSPECTCONTACTLEVEL] = (isModEnabled("societe") && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') && getDolGlobalString('THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES'));
611$tabcond[DICT_STCOMMCONTACT] = (isModEnabled("societe") && getDolGlobalString('THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES'));
612$tabcond[DICT_TRANSPORT_MODE] = isModEnabled('intracommreport');
613$tabcond[DICT_PRODUCT_NATURE] = isModEnabled("product");
614$tabcond[DICT_PRODUCTBATCH_QCSTATUS] = isModEnabled("product") && isModEnabled('productbatch') && getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2;
615$tabcond[DICT_ASSET_DISPOSAL_TYPE] = isModEnabled('asset');
616
617// List of help for fields (no more used, help is defined into tabcomplete)
618$tabhelp = array();
619
620
621$tooltipvatex = $langs->trans("VATExemptionCodeDesc").'<br>'.$langs->trans("VATExemptionCodeDesc2").'<br>'.$langs->trans("VATExemptionCodeDesc3");
622if (($mysoc->country_code == 'FR')) {
623 $tooltipvatex .= '<br><br>'.$langs->trans("Example").':<br>';
624 $tooltipvatex .= 'VATEX-FR-FRANCHISE, VATEX-FR-CGI261-4, VATEX-FR-J, VATEX-FR-I, VATEX-FR-D, ...';
625}
626
627// Table to store complete information (will replace all other tables). Key is table name.
628$tabcomplete = array(
629 'c_forme_juridique' => array(
630 'picto' => 'company',
631 'help' => array('code' => $langs->trans("EnterAnyCode"))
632 ),
633 'c_departements' => array(
634 'picto' => 'state',
635 'help' => array('code' => $langs->trans("EnterAnyCode"))
636 ),
637 'c_regions' => array(
638 'picto' => 'region',
639 'help' => array('code' => $langs->trans("EnterAnyCode"))
640 ),
641 'c_country' => array('picto' => 'country', 'help' => array('code' => $langs->trans("EnterAnyCode"), 'phone_code' => 'e.g. 33', 'trunk_prefix' => 'e.g. 0')),
642 'c_civility' => array('picto' => 'contact', 'help' => array('code' => $langs->trans("EnterAnyCode"))),
643 'c_actioncomm' => array('picto' => 'action', 'help' => array('code' => $langs->trans("EnterAnyCode"), 'color' => $langs->trans("ColorFormat"), 'position' => $langs->trans("PositionIntoComboList"))),
644 'c_chargesociales' => array('picto' => 'bill', 'help' => array('code' => $langs->trans("EnterAnyCode"))),
645 'c_typent' => array('picto' => 'company', 'help' => array('code' => $langs->trans("EnterAnyCode"), 'position' => $langs->trans("PositionIntoComboList"))),
646 'c_currencies' => array('picto' => 'multicurrency', 'help' => array('code' => $langs->trans("EnterAnyCode"), 'unicode' => $langs->trans("UnicodeCurrency"))),
647 'c_tva' => array('picto' => 'bill', 'css' => array('einvoice_vatex' => 'tdoverflowmax100'), 'help' => array('code' => $langs->trans("EnterAnyCode"), 'taux' => $langs->trans("SellTaxRate"), 'recuperableonly' => $langs->trans("RecuperableOnly"), 'localtax1_type' => $langs->trans("LocalTaxDesc"), 'localtax2_type' => $langs->trans("LocalTaxDesc"), 'einvoice_vatex' => $tooltipvatex)),
648 'c_type_contact' => array('picto' => 'contact', 'help' => array('code' => $langs->trans("EnterAnyCode"), 'position' => $langs->trans("PositionIntoComboList"))),
649 'c_payment_term' => array('picto' => 'bill', 'help' => array('code' => $langs->trans("EnterAnyCode"), 'type_cdr' => $langs->trans("TypeCdr", $langs->transnoentitiesnoconv("NbOfDays"), $langs->transnoentitiesnoconv("Offset"), $langs->transnoentitiesnoconv("NbOfDays"), $langs->transnoentitiesnoconv("Offset")))),
650 'c_paiement' => array('picto' => 'bill', 'help' => array('code' => $langs->trans("EnterAnyCode"))),
651 'c_ecotaxe' => array('picto' => 'bill', 'help' => array('code' => $langs->trans("EnterAnyCode"))),
652 'c_paper_format' => array('picto' => 'generic', 'help' => array('code' => $langs->trans("EnterAnyCode"))),
653 'c_prospectlevel' => array('picto' => 'company', 'help' => array('code' => $langs->trans("EnterAnyCode"))),
654 'c_type_fees' => array('picto' => 'trip', 'help' => array('code' => $langs->trans("EnterAnyCode"))),
655 'c_shipment_mode' => array('picto' => 'shipment', 'help' => array('code' => $langs->trans("EnterAnyCode"), 'tracking' => $langs->trans("UrlTrackingDesc"))),
656 'c_effectif' => array('picto' => 'company', 'help' => array('code' => $langs->trans("EnterAnyCode"))),
657 'c_input_method' => array('picto' => 'order', 'help' => array('code' => $langs->trans("EnterAnyCode"))),
658 'c_input_reason' => array('picto' => 'order', 'help' => array('code' => $langs->trans("EnterAnyCode"), 'position' => $langs->trans("PositionIntoComboList"))),
659 'c_availability' => array('picto' => 'shipment', 'help' => array('code' => $langs->trans("EnterAnyCode"))),
660 'c_revenuestamp' => array('picto' => 'bill', 'help' => array('revenuestamp_type' => $langs->trans('FixedOrPercent'))),
661 'c_type_resource' => array('picto' => 'resource', 'help' => array('code' => $langs->trans("EnterAnyCode"))),
662 'c_type_container' => array('picto' => 'website', 'help' => array('code' => $langs->trans("EnterAnyCode"))),
663 'c_stcomm' => array('picto' => 'company', 'help' => array('code' => $langs->trans("EnterAnyCode"), 'picto' => $langs->trans("PictoHelp"))),
664 'c_holiday_types' => array('picto' => 'holiday', 'help' => array('affect' => $langs->trans("FollowedByACounter"), 'delay' => $langs->trans("MinimumNoticePeriod"), 'newbymonth' => $langs->trans("NbAddedAutomatically"))),
665 'c_lead_status' => array('picto' => 'project', 'help' => array('code' => $langs->trans("EnterAnyCode"), 'percent' => $langs->trans("OpportunityPercent"), 'position' => $langs->trans("PositionIntoComboList"))),
666 'c_format_cards' => array('picto' => 'generic', 'help' => array('code' => $langs->trans("EnterAnyCode"), 'name' => $langs->trans("LabelName"), 'paper_size' => $langs->trans("LabelPaperSize"))),
667 'c_hrm_public_holiday' => array('picto' => 'holiday', 'help' => array('code' => $langs->trans("EnterAnyCode"), 'dayrule' => "Keep empty for a date defined with month and day (most common case).<br>Use a keyword like 'easter', 'eastermonday', ... for a date predefined by complex rules.", 'country' => $langs->trans("CountryIfSpecificToOneCountry"), 'year' => $langs->trans("ZeroMeansEveryYear"))),
668 'c_hrm_department' => array('picto' => 'hrm', 'help' => array('code' => $langs->trans("EnterAnyCode"))),
669 'c_hrm_function' => array('picto' => 'hrm', 'help' => array('code' => $langs->trans("EnterAnyCode"))),
670 'c_exp_tax_cat' => array('picto' => 'expensereport', 'help' => array()),
671 'c_exp_tax_range' => array('picto' => 'expensereport', 'help' => array('range_ik' => $langs->trans('PrevRangeToThisRange'))),
672 'c_units' => array('picto' => 'product', 'help' => array('code' => $langs->trans("EnterAnyCode"), 'unit_type' => $langs->trans('Measuringtype_durationDesc'), 'scale' => $langs->trans('MeasuringScaleDesc'))),
673 'c_socialnetworks' => array('picto' => 'share-alt', 'help' => array('code' => $langs->trans("EnterAnyCode"), 'url' => $langs->trans('UrlSocialNetworksDesc'), 'icon' => $langs->trans('FafaIconSocialNetworksDesc'))),
674 'c_prospectcontactlevel' => array('picto' => 'company', 'help' => array('code' => $langs->trans("EnterAnyCode"))),
675 'c_stcommcontact' => array('picto' => 'company', 'help' => array('code' => $langs->trans("EnterAnyCode"), 'picto' => $langs->trans("PictoHelp"))),
676 'c_transport_mode' => array('picto' => 'incoterm', 'help' => array('code' => $langs->trans("EnterAnyCode"))),
677 'c_product_nature' => array('picto' => 'product', 'help' => array('code' => $langs->trans("EnterAnyCode"))),
678 'c_productbatch_qcstatus' => array('picto' => 'lot', 'help' => array('code' => $langs->trans("EnterAnyCode"))),
679 'c_asset_disposal_type' => array('picto' => 'asset', 'help' => array('code' => $langs->trans("EnterAnyCode"))),
680 'c_invoice_subtype' => array('picto' => 'bill', 'help' => array('code' => $langs->trans("EnterAnyCode"))),
681);
682
683
684// Complete all arrays with entries found into modules
685complete_dictionary_with_modules($taborder, $tabname, $tablib, $tabsql, $tabsqlsort, $tabfield, $tabfieldvalue, $tabfieldinsert, $tabrowid, $tabcond, $tabhelp, $tabcomplete);
686
687// Complete the table $tabcomplete
688$i = 0;
689foreach ($tabcomplete as $key => $value) {
690 $i++;
691 // When a dictionary is commented
692 if (!isset($tabcond[$i])) {
693 continue;
694 }
695 $tabcomplete[$key]['id'] = $i;
696
697 // TODO Comment this lines when data is stored into the tabcomplete array
698 $tabcomplete[$key]['cond'] = $tabcond[$i];
699 $tabcomplete[$key]['rowid'] = $tabrowid[$i];
700 $tabcomplete[$key]['fieldinsert'] = $tabfieldinsert[$i];
701 $tabcomplete[$key]['fieldvalue'] = $tabfieldvalue[$i];
702 $tabcomplete[$key]['lib'] = $tablib[$i];
703 $tabcomplete[$key]['sql'] = $tabsql[$i];
704 $tabcomplete[$key]['sqlsort'] = $tabsqlsort[$i];
705 $tabcomplete[$key]['field'] = $tabfield[$i];
706 //$tabcomplete[$key]['picto'] = $tabpicto[$i]; // array picto already loaded into tabcomplete
707 //$tabcomplete[$key]['help'] = $tabhelp[$i]; // array help already loaded into tabcomplete
708}
709
710$keytable = '';
711if ($id > 0) {
712 $arrayofkeys = array_keys($tabcomplete);
713 if (array_key_exists($id - 1, $arrayofkeys)) {
714 $keytable = $arrayofkeys[$id - 1];
715 }
716}
717
718// Default sortorder
719if (empty($sortfield)) {
720 $tmp1 = explode(',', empty($tabcomplete[$keytable]['sqlsort']) ? '' : $tabcomplete[$keytable]['sqlsort']);
721 $tmp2 = explode(' ', $tmp1[0]);
722 $sortfield = preg_replace('/^.*\./', '', $tmp2[0]);
723 $sortorder = (!empty($tmp2[1]) ? $tmp2[1] : ''); // @phan-suppress-current-line SqlInjection
724 //var_dump($sortfield); //var_dump($sortorder);
725}
726
727global $elementList, $sourceList, $localtax_typeList, $type_vatList; // Used in dictFieldList() below
728
729// Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact")
730$elementList = array();
731$sourceList = array();
732if ($id == DICT_TYPE_CONTACT) {
733 $elementList = array(
734 '' => '',
735 'agenda' => img_picto('', 'action', 'class="pictofixedwidth"').$langs->trans('Agenda'),
736 'dolresource' => img_picto('', 'resource', 'class="pictofixedwidth"').$langs->trans('Resource'),
737 'societe' => img_picto('', 'company', 'class="pictofixedwidth"').$langs->trans('ThirdParty'),
738 'product' => img_picto('', 'product', 'class="pictofixedwidth"').$langs->trans('Product'),
739 // 'proposal' => $langs->trans('Proposal'),
740 // 'order' => $langs->trans('Order'),
741 // 'invoice' => $langs->trans('Bill'),
742 // 'intervention' => $langs->trans('InterventionCard'),
743 // 'contract' => $langs->trans('Contract'),
744 'project' => img_picto('', 'project', 'class="pictofixedwidth"').$langs->trans('Project'),
745 'project_task' => img_picto('', 'projecttask', 'class="pictofixedwidth"').$langs->trans('Task'),
746 'propal' => img_picto('', 'propal', 'class="pictofixedwidth"').$langs->trans('Proposal'),
747 'commande' => img_picto('', 'order', 'class="pictofixedwidth"').$langs->trans('Order'),
748 'shipping' => img_picto('', 'dolly', 'class="pictofixedwidth"') . $langs->trans('Shipment'),
749 'facture' => img_picto('', 'bill', 'class="pictofixedwidth"').$langs->trans('Bill'),
750 'fichinter' => img_picto('', 'intervention', 'class="pictofixedwidth"').$langs->trans('InterventionCard'),
751 'contrat' => img_picto('', 'contract', 'class="pictofixedwidth"').$langs->trans('Contract'),
752 'ticket' => img_picto('', 'ticket', 'class="pictofixedwidth"').$langs->trans('Ticket'),
753 'supplier_proposal' => img_picto('', 'supplier_proposal', 'class="pictofixedwidth"').$langs->trans('SupplierProposal'),
754 'order_supplier' => img_picto('', 'supplier_order', 'class="pictofixedwidth"').$langs->trans('SupplierOrder'),
755 'invoice_supplier' => img_picto('', 'supplier_invoice', 'class="pictofixedwidth"').$langs->trans('SupplierBill'),
756 'conferenceorbooth' => img_picto('', 'eventorganization', 'class="pictofixedwidth"').$langs->trans('ConferenceOrBooth'),
757 );
758
759 complete_elementList_with_modules($elementList);
760
761 //asort($elementList);
762 $sourceList = array(
763 'internal' => $langs->trans('Internal'),
764 'external' => $langs->trans('External')
765 );
766}
767
768// Define type_vatList (used for dictionary "llx_c_tva")
769$type_vatList = array(
770 "0" => $langs->trans("Sell").'+'.$langs->trans("Buy"),
771 "1" => $langs->trans("Sell"),
772 "2" => $langs->trans("Buy")
773);
774
775// Define localtax_typeList (used for dictionary "llx_c_tva")
776$localtax_typeList = array(
777 "0" => $langs->trans("No"),
778 "1" => $langs->trans("Yes").' ('.$langs->trans("Type")." 1)", //$langs->trans("%ageOnAllWithoutVAT"),
779 "2" => $langs->trans("Yes").' ('.$langs->trans("Type")." 2)", //$langs->trans("%ageOnAllBeforeVAT"),
780 "3" => $langs->trans("Yes").' ('.$langs->trans("Type")." 3)", //$langs->trans("%ageOnProductsWithoutVAT"),
781 "4" => $langs->trans("Yes").' ('.$langs->trans("Type")." 4)", //$langs->trans("%ageOnProductsBeforeVAT"),
782 "5" => $langs->trans("Yes").' ('.$langs->trans("Type")." 5)", //$langs->trans("%ageOnServiceWithoutVAT"),
783 "6" => $langs->trans("Yes").' ('.$langs->trans("Type")." 6)" //$langs->trans("%ageOnServiceBeforeVAT"),
784);
785
786
787
788/*
789 * Actions
790 */
791
792$object = new stdClass();
793$parameters = array(
794 'id' => $id,
795 'rowid' => $rowid,
796 'code' => $code,
797 'confirm' => $confirm,
798 'entity' => $entity,
799 'taborder' => $taborder,
800 'tabname' => $tabname,
801 'tablib' => $tablib,
802 'tabsql' => $tabsql,
803 'tabsqlsort' => $tabsqlsort,
804 'tabfield' => $tabfield,
805 'tabfieldvalue' => $tabfieldvalue,
806 'tabfieldinsert' => $tabfieldinsert,
807 'tabrowid' => $tabrowid,
808 'tabcond' => $tabcond,
809 'tabhelp' => $tabhelp,
810 'tabcomplete' => $tabcomplete
811);
812$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
813if ($reshook < 0) {
814 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
815}
816
817if (GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter_x', 'alpha')) {
818 $search_country_id = '';
819 $search_code = '';
820 $search_active = '';
821}
822
823if (empty($reshook)) {
824 // Actions add or modify an entry into a dictionary
825 if (GETPOST('actionadd') || GETPOST('actionmodify')) {
826 $listfield = explode(',', str_replace(' ', '', $tabfield[$id]));
827 $listfieldinsert = explode(',', $tabfieldinsert[$id]);
828 $listfieldmodify = explode(',', $tabfieldinsert[$id]);
829 $listfieldvalue = explode(',', $tabfieldvalue[$id]);
830
831 // Check that all mandatory fields are filled
832 $ok = 1;
833 foreach ($listfield as $f => $value) {
834 // Discard check of mandatory fields for country for some tables
835 if ($value == 'country_id' && in_array($tablib[$id], array('DictionaryPublicHolidays', 'DictionaryVAT', 'DictionaryInvoiceSubtype', 'DictionaryRegion', 'DictionaryCompanyType', 'DictionaryHolidayTypes', 'DictionaryRevenueStamp', 'DictionaryAccountancysystem', 'DictionaryAccountancyCategory'))) {
836 continue; // For some pages, country is not mandatory
837 }
838 if ($value == 'country' && in_array($tablib[$id], array('DictionaryPublicHolidays', 'DictionaryCanton', 'DictionaryCompanyType', 'DictionaryHolidayTypes', 'DictionaryRevenueStamp'))) {
839 continue; // For some pages, country is not mandatory
840 }
841 // Discard check of mandatory fields for department buyer id for some tables (only for add action)
842 if (GETPOST('actionadd') && $value == 'department_buyer_id' && $tablib[$id] == 'DictionaryVAT') {
843 continue; // For some pages, department buyer id is not mandatory
844 }
845 // Discard check of mandatory fields for department buyer for some tables
846 if ($value == 'department_buyer' && $tablib[$id] == 'DictionaryVAT') {
847 continue; // For some pages, department buyer is not mandatory
848 }
849 // Discard check of mandatory fields for other fields
850 $notmandatoryarray = array('localtax1', 'localtax2', 'color', 'formula', 'dayrule', 'einvoice_vatex');
851 foreach ($notmandatoryarray as $notmandatory) {
852 if (!GETPOST($notmandatory)) {
853 continue 2;
854 }
855 }
856 if ($value == 'sortorder') {
857 continue; // For a column name 'sortorder', we use the field name 'position'
858 }
859 if ((!GETPOSTISSET($value) || GETPOST($value) == '')
860 && (
861 !in_array($value, array('decalage', 'module', 'accountancy_code', 'accountancy_code_sell', 'accountancy_code_buy', 'tracking', 'picto', 'deposit_percent')) // Fields that are not mandatory
862 && ($id != DICT_TVA || ($value != 'code' && $value != 'note')) // Field code and note is not mandatory for dictionary table 10
863 )
864 ) {
865 $ok = 0;
866 $fieldnamekey = $value;
867 // We take translate key of field
868 if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) {
869 $fieldnamekey = 'Label';
870 }
871 if ($fieldnamekey == 'libelle_facture') {
872 $fieldnamekey = 'LabelOnDocuments';
873 }
874 if ($fieldnamekey == 'deposit_percent') {
875 $fieldnamekey = 'DepositPercent';
876 }
877 if ($fieldnamekey == 'nbjour') {
878 $fieldnamekey = 'NbOfDays';
879 }
880 if ($fieldnamekey == 'decalage') {
881 $fieldnamekey = 'Offset';
882 }
883 if ($fieldnamekey == 'module') {
884 $fieldnamekey = 'Module';
885 }
886 if ($fieldnamekey == 'code') {
887 $fieldnamekey = 'Code';
888 }
889 if ($fieldnamekey == 'note') {
890 $fieldnamekey = 'Note';
891 }
892 if ($fieldnamekey == 'taux') {
893 $fieldnamekey = 'Rate';
894 }
895 if ($fieldnamekey == 'type') {
896 $fieldnamekey = 'Type';
897 }
898 if ($fieldnamekey == 'position') {
899 $fieldnamekey = 'Position';
900 }
901 if ($fieldnamekey == 'unicode') {
902 $fieldnamekey = 'Unicode';
903 }
904 if ($fieldnamekey == 'deductible') {
905 $fieldnamekey = 'Deductible';
906 }
907 if ($fieldnamekey == 'sortorder') {
908 $fieldnamekey = 'SortOrder';
909 }
910 if ($fieldnamekey == 'category_type') {
911 $fieldnamekey = 'Calculated';
912 }
913 if ($fieldnamekey == 'revenuestamp_type') {
914 $fieldnamekey = 'TypeOfRevenueStamp';
915 }
916 if ($fieldnamekey == 'use_default') {
917 $fieldnamekey = 'UseByDefault';
918 }
919
920 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
921 }
922 }
923 // Other special checks
924 if (GETPOST('actionadd') && $tabname[$id] == "c_actioncomm" && GETPOSTISSET("type") && in_array(GETPOST("type"), array('system', 'systemauto'))) {
925 $ok = 0;
926 setEventMessages($langs->transnoentities('ErrorReservedTypeSystemSystemAuto'), null, 'errors');
927 }
928 if (GETPOSTISSET("code")) {
929 if (GETPOST("code") == '0') {
930 $ok = 0;
931 setEventMessages($langs->transnoentities('ErrorCodeCantContainZero'), null, 'errors');
932 }
933 }
934 if (GETPOSTISSET("country") && (GETPOST("country") == '0') && ($id != DICT_DEPARTEMENTS)) {
935 if (in_array($tablib[$id], array('DictionaryCompanyType', 'DictionaryHolidayTypes'))) { // Field country is no mandatory for such dictionaries
936 $_POST["country"] = '';
937 } else {
938 $ok = 0;
939 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities("Country")), null, 'errors');
940 }
941 }
942 if (($id == DICT_REGIONS || $id == DICT_PRODUCT_NATURE) && !is_numeric(GETPOST("code")) && GETPOST('actionadd')) {
943 $ok = 0;
944 setEventMessages($langs->transnoentities("ErrorFieldMustBeANumeric", $langs->transnoentities("Code")), null, 'errors');
945 }
946 if ($id == DICT_COUNTRY && strlen(GETPOST("code")) != 2) { // 2 char on code for country code
947 $ok = 0;
948 setEventMessages($langs->transnoentities("ErrorCountryCodeMustBe2Char", $langs->transnoentities("Code")), null, 'errors');
949 }
950 if ($id == DICT_PAIEMENT && strlen(GETPOST("code")) >= 6) { // 6 char max on code for payment mode codes
951 $ok = 0;
952 setEventMessages($langs->transnoentities("ErrorFieldMustHaveLessThanXChar", $langs->transnoentities("Code"), '6'), null, 'errors');
953 }
954
955 // Clean some parameters
956 if ((GETPOST("localtax1_type") || (GETPOST('localtax1_type') == '0')) && !GETPOST("localtax1")) {
957 $_POST["localtax1"] = '0'; // If empty, we force to 0
958 }
959 if ((GETPOST("localtax2_type") || (GETPOST('localtax2_type') == '0')) && !GETPOST("localtax2")) {
960 $_POST["localtax2"] = '0'; // If empty, we force to 0
961 }
962 if (GETPOST('department_buyer_id') <= 0) {
963 $_POST['department_buyer_id'] = ''; // If empty, we force to null
964 }
965 if (GETPOST("accountancy_code") <= 0) {
966 $_POST["accountancy_code"] = ''; // If empty, we force to null
967 }
968 if (GETPOST("accountancy_code_sell") <= 0) {
969 $_POST["accountancy_code_sell"] = ''; // If empty, we force to null
970 }
971 if (GETPOST("accountancy_code_buy") <= 0) {
972 $_POST["accountancy_code_buy"] = ''; // If empty, we force to null
973 }
974 if ($id == DICT_TVA && GETPOSTISSET("code")) { // Spaces are not allowed into code for tax dictionary
975 $_POST["code"] = preg_replace('/[^a-zA-Z0-9_\-\+]/', '', GETPOST("code"));
976 }
977
978 $tablename = $tabname[$id];
979 $tablename = preg_replace('/^'.preg_quote(MAIN_DB_PREFIX, '/').'/', '', $tablename);
980
981 // If check ok and action add, add the line
982 if ($ok && GETPOST('actionadd')) {
983 $newid = 0;
984 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
985 // Get free id for insert
986 $sql = "SELECT MAX(".$tabrowid[$id].") as newid FROM ".MAIN_DB_PREFIX.$db->sanitize($tablename);
987 $result = $db->query($sql);
988 if ($result) {
989 $obj = $db->fetch_object($result);
990 $newid = ((int) $obj->newid) + 1;
991 } else {
993 }
994 }
995
996 // Add new entry
997 $sql = "INSERT INTO ".MAIN_DB_PREFIX.$db->sanitize($tablename)." (";
998 // List of fields
999 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
1000 $sql .= $tabrowid[$id].",";
1001 }
1002 $sql .= $tabfieldinsert[$id];
1003 $sql .= ",active)";
1004 $sql .= " VALUES(";
1005
1006 // List of values
1007 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
1008 $sql .= ((int) $newid).",";
1009 }
1010 $i = 0;
1011 foreach ($listfieldinsert as $f => $value) {
1012 $keycode = (isset($listfieldvalue[$i]) ? $listfieldvalue[$i] : '');
1013 if (empty($keycode)) {
1014 $keycode = $value;
1015 }
1016
1017 if ($value == 'price' || preg_match('/^amount/i', $value)) {
1018 $_POST[$keycode] = price2num(GETPOST($keycode), 'MU');
1019 } elseif ($value == 'taux' || $value == 'localtax1') {
1020 $_POST[$keycode] = price2num(GETPOST($keycode), 8); // Note that localtax2 can be a list of rates separated by coma like X:Y:Z
1021 } elseif ($value == 'entity') {
1022 $_POST[$keycode] = (int) getEntity($tablename, 0);
1023 }
1024
1025 if ($i) {
1026 $sql .= ",";
1027 }
1028
1029 if ($keycode == 'sortorder') { // For column name 'sortorder', we use the field name 'position'
1030 $sql .= GETPOSTINT('position');
1031 } elseif (GETPOST($keycode) == '' && !($keycode == 'code' && $id == DICT_TVA)) {
1032 $sql .= "null"; // For vat, we want/accept code = ''
1033 } elseif ($keycode == 'content') {
1034 $sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
1035 } elseif (in_array($keycode, array('joinfile', 'private', 'pos', 'position', 'scale', 'use_default'))) {
1036 $sql .= GETPOSTINT($keycode);
1037 } else {
1038 $sql .= "'".$db->escape(GETPOST($keycode, 'alphanohtml'))."'";
1039 }
1040
1041 $i++;
1042 }
1043 $sql .= ",1)";
1044
1045 dol_syslog("actionadd", LOG_DEBUG);
1046 $resql = $db->query($sql);
1047 if ($resql) { // Add is ok
1048 setEventMessages($langs->transnoentities("RecordCreatedSuccessfully"), null, 'mesgs');
1049
1050 // PostgreSQL: when we forced the rowid we must bump the matching <table>_<rowid_col>_seq
1051 // so the next auto-increment insert does not collide with our chosen value (#36510).
1052 if ($db->type == 'pgsql' && $tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
1053 $db->query("SELECT setval(pg_get_serial_sequence('".$db->escape(MAIN_DB_PREFIX.$db->sanitize($tablename))."', '".$db->escape($tabrowid[$id])."'), GREATEST((SELECT MAX(".$db->sanitize($tabrowid[$id]).") FROM ".MAIN_DB_PREFIX.$db->sanitize($tablename)."), 1))");
1054 }
1055
1056 // Clean $_POST array, we keep only id of dictionary
1057 if ($id == DICT_TVA && GETPOSTINT('country') > 0) {
1058 $search_country_id = GETPOSTINT('country');
1059 }
1060 $_POST = array('id' => $id);
1061 } else {
1062 if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
1063 setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
1064 } else {
1066 }
1067 }
1068 }
1069
1070 // If verif ok and action modify, modify the line
1071 if ($ok && GETPOST('actionmodify')) {
1072 if ($tabrowid[$id]) {
1073 $rowidcol = $tabrowid[$id];
1074 } else {
1075 $rowidcol = "rowid";
1076 }
1077
1078 // Modify entry
1079 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($tablename)." SET ";
1080 // Update fields value
1081 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
1082 $sql .= $tabrowid[$id]."=";
1083 $sql .= "'".$db->escape($rowid)."', ";
1084 }
1085 $i = 0;
1086 foreach ($listfieldmodify as $field) {
1087 $keycode = empty($listfieldvalue[$i]) ? '' : $listfieldvalue[$i];
1088 if (empty($keycode)) {
1089 $keycode = $field;
1090 }
1091
1092 if ($field == 'price' || preg_match('/^amount/i', $field)) {
1093 $_POST[$keycode] = price2num(GETPOST($keycode), 'MU');
1094 } elseif ($field == 'taux' || $field == 'localtax1') {
1095 $_POST[$keycode] = price2num(GETPOST($keycode), 8); // Note that localtax2 can be a list of rates separated by coma like X:Y:Z
1096 } elseif ($field == 'entity') {
1097 $_POST[$keycode] = (int) getEntity($tablename, 0);
1098 }
1099
1100 if ($i) {
1101 $sql .= ",";
1102 }
1103 $sql .= $field."=";
1104 if ($keycode == 'sortorder') { // For column name 'sortorder', we use the field name 'position'
1105 $sql .= GETPOSTINT('position');
1106 } elseif (GETPOST($keycode) == '' && !($keycode == 'code' && $id == DICT_TVA)) {
1107 $sql .= "null"; // For vat, we want/accept code = ''
1108 } elseif ($keycode == 'content') {
1109 $sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
1110 } elseif (in_array($keycode, array('joinfile', 'private', 'pos', 'position', 'scale', 'use_default'))) {
1111 $sql .= GETPOSTINT($keycode);
1112 } else {
1113 $sql .= "'".$db->escape(GETPOST($keycode, 'alphanohtml'))."'";
1114 }
1115
1116 $i++;
1117 }
1118 if (in_array($rowidcol, array('code', 'code_iso'))) {
1119 $sql .= " WHERE ".$db->sanitize($rowidcol)." = '".$db->escape($rowid)."'";
1120 } else {
1121 $sql .= " WHERE ".$db->sanitize($rowidcol)." = ".((int) $rowid);
1122 }
1123 if (in_array('entity', $listfieldmodify)) {
1124 $sql .= " AND entity = ".((int) getEntity($tablename, 0));
1125 }
1126
1127 dol_syslog("actionmodify", LOG_DEBUG);
1128 //print $sql;
1129 $resql = $db->query($sql);
1130 if (!$resql) {
1131 setEventMessages($db->error(), null, 'errors');
1132 }
1133 }
1134
1135 if (!$ok && GETPOST('actionadd')) {
1136 $action = 'create';
1137 }
1138 if (!$ok && GETPOST('actionmodify')) {
1139 $action = 'edit';
1140 }
1141 }
1142
1143 if ($action == 'confirm_delete' && $confirm == 'yes') { // delete
1144 if ($tabrowid[$id]) {
1145 $rowidcol = $tabrowid[$id];
1146 } else {
1147 $rowidcol = "rowid";
1148 }
1149
1150 $tablename = $tabname[$id];
1151 $tablename = preg_replace('/^'.preg_quote(MAIN_DB_PREFIX, '/').'/', '', $tablename);
1152
1153 $sql = "DELETE FROM ".MAIN_DB_PREFIX.$db->sanitize($tablename)." WHERE ".$db->sanitize($rowidcol)." = '".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
1154
1155 dol_syslog("delete", LOG_DEBUG);
1156 $result = $db->query($sql);
1157 if (!$result) {
1158 if ($db->errno() == 'DB_ERROR_CHILD_EXISTS') {
1159 setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
1160 } else {
1162 }
1163 }
1164 }
1165
1166 // activate
1167 if ($action == $acts[0]) {
1168 if ($tabrowid[$id]) {
1169 $rowidcol = $tabrowid[$id];
1170 } else {
1171 $rowidcol = "rowid";
1172 }
1173
1174 $tablename = $tabname[$id];
1175 $tablename = preg_replace('/^'.preg_quote(MAIN_DB_PREFIX, '/').'/', '', $tablename);
1176
1177 if ($rowid) {
1178 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($tablename)." SET active = 1 WHERE ".$db->sanitize($rowidcol)." = ".((int) $rowid).($entity != '' ? " AND entity = ".(int) $entity : '');
1179 } elseif ($code) {
1180 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($tablename)." SET active = 1 WHERE code = '".$db->escape(dol_escape_htmltag($code))."'".($entity != '' ? " AND entity = ".(int) $entity : '');
1181 } else {
1182 $sql = null;
1183 }
1184
1185 if ($sql !== null) {
1186 $result = $db->query($sql);
1187 if (!$result) {
1189 }
1190 } else {
1191 dol_print_error(null, "No DB entry or no code");
1192 }
1193 }
1194
1195 // disable
1196 if ($action == $acts[1]) {
1197 if ($tabrowid[$id]) {
1198 $rowidcol = $tabrowid[$id];
1199 } else {
1200 $rowidcol = "rowid";
1201 }
1202
1203 $tablename = $tabname[$id];
1204 $tablename = preg_replace('/^'.preg_quote(MAIN_DB_PREFIX, '/').'/', '', $tablename);
1205
1206 if ($rowid) {
1207 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($tablename)." SET active = 0 WHERE ".$db->sanitize($rowidcol)." = '".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
1208 } elseif ($code) {
1209 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($tablename)." SET active = 0 WHERE code = '".$db->escape(dol_escape_htmltag($code))."'".($entity != '' ? " AND entity = ".(int) $entity : '');
1210 } else {
1211 $sql = null;
1212 }
1213
1214 if ($sql !== null) {
1215 $result = $db->query($sql);
1216 if (!$result) {
1218 }
1219 } else {
1220 dol_print_error(null, "No DB entry or no code");
1221 }
1222 }
1223
1224 // favorite
1225 if ($action == 'activate_favorite') {
1226 if ($tabrowid[$id]) {
1227 $rowidcol = $tabrowid[$id];
1228 } else {
1229 $rowidcol = "rowid";
1230 }
1231
1232 $tablename = $tabname[$id];
1233 $tablename = preg_replace('/^'.preg_quote(MAIN_DB_PREFIX, '/').'/', '', $tablename);
1234
1235 if ($rowid) {
1236 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($tablename)." SET favorite = 1 WHERE ".$db->sanitize($rowidcol)." = '".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
1237 } elseif ($code) {
1238 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($tablename)." SET favorite = 1 WHERE code = '".$db->escape(dol_escape_htmltag($code))."'".($entity != '' ? " AND entity = ".(int) $entity : '');
1239 } else {
1240 $sql = null;
1241 }
1242
1243 if ($sql !== null) {
1244 $result = $db->query($sql);
1245 if (!$result) {
1247 }
1248 } else {
1249 dol_print_error(null, "No DB entry or no code");
1250 }
1251 }
1252
1253 // disable favorite
1254 if ($action == 'disable_favorite') {
1255 if ($tabrowid[$id]) {
1256 $rowidcol = $tabrowid[$id];
1257 } else {
1258 $rowidcol = "rowid";
1259 }
1260
1261 $tablename = $tabname[$id];
1262 $tablename = preg_replace('/^'.preg_quote(MAIN_DB_PREFIX, '/').'/', '', $tablename);
1263
1264 if ($rowid) {
1265 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($tablename)." SET favorite = 0 WHERE ".$db->sanitize($rowidcol)." = '".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
1266 } elseif ($code) {
1267 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($tablename)." SET favorite = 0 WHERE code = '".$db->escape(dol_escape_htmltag($code))."'".($entity != '' ? " AND entity = ".(int) $entity : '');
1268 } else {
1269 $sql = null;
1270 }
1271
1272 if ($sql !== null) {
1273 $result = $db->query($sql);
1274 if (!$result) {
1276 }
1277 } else {
1278 dol_print_error(null, "No DB entry or no code");
1279 }
1280 }
1281
1282 // Is in EEC - Activate
1283 if ($action == 'activate_eec') {
1284 if ($tabrowid[$id]) {
1285 $rowidcol = $tabrowid[$id];
1286 } else {
1287 $rowidcol = "rowid";
1288 }
1289
1290 $tablename = $tabname[$id];
1291 $tablename = preg_replace('/^'.preg_quote(MAIN_DB_PREFIX, '/').'/', '', $tablename);
1292
1293 if ($rowid) {
1294 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($tablename)." SET eec = 1 WHERE ".$db->sanitize($rowidcol)." = '".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
1295 } elseif ($code) {
1296 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($tablename)." SET eec = 1 WHERE code = '".$db->escape(dol_escape_htmltag($code))."'".($entity != '' ? " AND entity = ".(int) $entity : '');
1297 } else {
1298 $sql = null;
1299 }
1300
1301 if ($sql !== null) {
1302 $result = $db->query($sql);
1303 if (!$result) {
1305 }
1306 } else {
1307 dol_print_error(null, "No DB entry or no code");
1308 }
1309 }
1310
1311 // Is in EEC - Disable
1312 if ($action == 'disable_eec') {
1313 if ($tabrowid[$id]) {
1314 $rowidcol = $tabrowid[$id];
1315 } else {
1316 $rowidcol = "rowid";
1317 }
1318
1319 $tablename = $tabname[$id];
1320 $tablename = preg_replace('/^'.preg_quote(MAIN_DB_PREFIX, '/').'/', '', $tablename);
1321
1322 if ($rowid) {
1323 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($tablename)." SET eec = 0 WHERE ".$db->sanitize($rowidcol)." = '".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
1324 } elseif ($code) {
1325 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($tablename)." SET eec = 0 WHERE code = '".$db->escape(dol_escape_htmltag($code))."'".($entity != '' ? " AND entity = ".(int) $entity : '');
1326 } else {
1327 $sql = null;
1328 }
1329
1330 if ($sql !== null) {
1331 $result = $db->query($sql);
1332 if (!$result) {
1334 }
1335 } else {
1336 dol_print_error(null, "No DB entry or no code");
1337 }
1338 }
1339
1340 // Is in Sepa - Activate
1341 if ($action == 'activate_sepa') {
1342 if ($tabrowid[$id]) {
1343 $rowidcol = $tabrowid[$id];
1344 } else {
1345 $rowidcol = "rowid";
1346 }
1347
1348 $tablename = $tabname[$id];
1349 $tablename = preg_replace('/^'.preg_quote(MAIN_DB_PREFIX, '/').'/', '', $tablename);
1350
1351 if ($rowid) {
1352 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($tablename)." SET sepa = 1 WHERE ".$db->sanitize($rowidcol)." = '".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
1353 } elseif ($code) {
1354 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($tablename)." SET sepa = 1 WHERE code = '".$db->escape(dol_escape_htmltag($code))."'".($entity != '' ? " AND entity = ".(int) $entity : '');
1355 } else {
1356 $sql = null;
1357 }
1358
1359 if ($sql !== null) {
1360 $result = $db->query($sql);
1361 if (!$result) {
1363 }
1364 } else {
1365 dol_print_error(null, "No DB entry or no code");
1366 }
1367 }
1368
1369 // Is in Sepa - Disable
1370 if ($action == 'disable_sepa') {
1371 if ($tabrowid[$id]) {
1372 $rowidcol = $tabrowid[$id];
1373 } else {
1374 $rowidcol = "rowid";
1375 }
1376
1377 $tablename = $tabname[$id];
1378 $tablename = preg_replace('/^'.preg_quote(MAIN_DB_PREFIX, '/').'/', '', $tablename);
1379
1380 if ($rowid) {
1381 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($tablename)." SET sepa = 0 WHERE ".$db->sanitize($rowidcol)." = '".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
1382 } elseif ($code) {
1383 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($tablename)." SET sepa = 0 WHERE code = '".$db->escape(dol_escape_htmltag($code))."'".($entity != '' ? " AND entity = ".(int) $entity : '');
1384 } else {
1385 $sql = null;
1386 }
1387
1388 if ($sql !== null) {
1389 $result = $db->query($sql);
1390 if (!$result) {
1392 }
1393 } else {
1394 dol_print_error(null, "No DB entry or no code");
1395 }
1396 }
1397}
1398
1399
1400/*
1401 * View
1402 */
1403global $form, $formother; // Used in dictFieldList() below
1404
1405$form = new Form($db);
1406$formother = new FormOther($db);
1407
1408$title = $langs->trans("DictionarySetup");
1409
1410llxHeader('', $title, '', '', 0, 0, '', '', '', 'mod-admin page-dict');
1411
1412if (GETPOSTINT('id') == DICT_SOCIALNETWORKS && $from == 'socialnetworksetup') {
1413 $head = socialnetwork_prepare_head();
1414 print dol_get_fiche_head($head, 'dict', $langs->trans('MenuDict'), -1, 'user');
1415}
1416
1417
1418$linkback = '';
1419if ($id && empty($from)) {
1420 $title .= ' - '.$langs->trans($tablib[$id]);
1421 $linkback = '<a href="'.$_SERVER['PHP_SELF'].'">'.img_picto($langs->trans("BackToDictionaryList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToDictionaryList").'</span></a>';
1422}
1423$titlepicto = 'title_setup';
1424if ($id == DICT_TVA && GETPOST('from') == 'accountancy') {
1425 $title = $langs->trans("MenuVatAccounts");
1426 $titlepicto = 'accountancy';
1427}
1428if ($id == DICT_CHARGESOCIALES && GETPOST('from') == 'accountancy') {
1429 $title = $langs->trans("MenuTaxAccounts");
1430 $titlepicto = 'accountancy';
1431}
1432
1433$param = '&id='.urlencode((string) ($id));
1434if ($search_country_id || GETPOSTISSET('page') || GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter_x', 'alpha')) {
1435 $param .= '&search_country_id='.urlencode((string) ($search_country_id ? $search_country_id : -1));
1436}
1437if ($search_code != '') {
1438 $param .= '&search_code='.urlencode($search_code);
1439}
1440if ($search_active != '') {
1441 $param .= '&search_active='.urlencode($search_active);
1442}
1443if ($entity != '') {
1444 $param .= '&entity='.(int) $entity;
1445}
1446if ($from) {
1447 $param .= '&from='.urlencode($from);
1448}
1449$paramwithsearch = $param;
1450if ($sortorder) {
1451 $paramwithsearch .= '&sortorder='.urlencode($sortorder);
1452}
1453if ($sortfield) {
1454 $paramwithsearch .= '&sortfield='.urlencode($sortfield);
1455}
1456if ($from) {
1457 $paramwithsearch .= '&from='.urlencode($from);
1458}
1459
1460
1461// Confirmation of the deletion of the line
1462if ($action == 'delete') {
1463 print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page ? 'page='.$page.'&' : '').'rowid='.urlencode($rowid).'&code='.urlencode($code).$paramwithsearch, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete', '', 0, 1);
1464}
1465
1466// Show a dictionary
1467if ($id > 0) {
1468 // Complete search values request with sort criteria
1469 $sqlfields = $tabsql[$id];
1470
1471 $tablecode = 't.code';
1472 $tableprefix = '';
1473 $tableprefixarray = array(
1474 DICT_FORME_JURIDIQUE => 'f.code',
1475 DICT_DEPARTEMENTS => 'd.code_departement',
1476 DICT_REGIONS => 'r.code_region',
1477 DICT_COUNTRY => 'c.code',
1478 DICT_CIVILITY => 'c.code',
1479 DICT_ACTIONCOMM => 'a.code',
1480 DICT_CHARGESOCIALES => 'a.code',
1481 DICT_TYPENT => 't.code',
1482 DICT_CURRENCIES => 'c.code_iso',
1483 DICT_ECOTAXE => 'e.code',
1484 DICT_HOLIDAY_TYPES => 'h.code',
1485 DICT_HRM_PUBLIC_HOLIDAY => 'a.code',
1486 DICT_UNITS => 'r.code',
1487 DICT_SOCIALNETWORKS => 's.code',
1488 45 => 'f.code',
1489 46 => 'f.code',
1490 47 => 'f.code',
1491 48 => 'f.code',
1492 );
1493 if (!empty($tableprefixarray[$id])) {
1494 $tablecode = $tableprefixarray[$id];
1495 $tableprefix = preg_replace('/\..*$/', '.', $tablecode);
1496 }
1497 $reg = array();
1498 if (empty($tableprefix) && preg_match('/SELECT ([a-z]\.)rowid/i', $sqlfields, $reg)) {
1499 $tableprefix = $reg[1];
1500 }
1501
1502 $sql = $sqlfields;
1503 if (!preg_match('/ WHERE /', $sql)) {
1504 $sql .= " WHERE 1 = 1";
1505 }
1506 if ($search_country_id > 0) {
1507 if ($id == DICT_HRM_PUBLIC_HOLIDAY || $id == DICT_HOLIDAY_TYPES) {
1508 $sql .= " AND (c.rowid IS NULL OR c.rowid = 0 OR c.rowid = ".((int) $search_country_id).")";
1509 } else {
1510 $sql .= " AND c.rowid = ".((int) $search_country_id);
1511 }
1512 }
1513 if ($search_code != '') {
1514 $sql .= natural_search($tablecode, $search_code);
1515 }
1516 if ($search_active == 'yes') {
1517 $sql .= " AND ".$db->sanitize($tableprefix)."active = 1";
1518 } elseif ($search_active == 'no') {
1519 $sql .= " AND ".$db->sanitize($tableprefix)."active = 0";
1520 }
1521
1522 // Count total nb of records
1523 $nbtotalofrecords = '';
1524 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
1525 /* The fast and low memory method to get and count full list converts the sql into a sql count */
1526 $sqlforcount = preg_replace('/^.*\sFROM\s/', 'SELECT COUNT(*) as nbtotalofrecords FROM ', $sql);
1527 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
1528 $resql = $db->query($sqlforcount);
1529 if ($resql) {
1530 $objforcount = $db->fetch_object($resql);
1531 $nbtotalofrecords = $objforcount->nbtotalofrecords;
1532 } else {
1534 }
1535
1536 if (($page * $listlimit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
1537 $page = 0;
1538 $offset = 0;
1539 }
1540 $db->free($resql);
1541 }
1542
1543 if ($sortfield) {
1544 // If sort order is "country", we use country_code instead
1545 if ($sortfield == 'country') {
1546 $sortfield = 'country_code';
1547 }
1548 $sql .= $db->order($sortfield, $sortorder);
1549 $sql .= ", ";
1550 // Clear the required sort criteria for the tabsqlsort to be able to force it with selected value
1551 $tabsqlsort[$id] = preg_replace('/([a-z]+\.)?'.$sortfield.' '.$sortorder.',/i', '', $tabsqlsort[$id]);
1552 $tabsqlsort[$id] = preg_replace('/([a-z]+\.)?'.$sortfield.',/i', '', $tabsqlsort[$id]);
1553 } else {
1554 $sql .= " ORDER BY ";
1555 }
1556 $sql .= $tabsqlsort[$id];
1557
1558 $sql .= $db->plimit($listlimit + 1, $offset);
1559
1560 //print $sql;
1561
1562 if (empty($tabfield[$id])) {
1563 dol_print_error($db, 'The table with id '.$id.' has no array tabfield defined');
1564 exit;
1565 }
1566 $fieldlist = explode(',', $tabfield[$id]);
1567
1568 print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST" spellcheck="false">';
1569 print '<input type="hidden" name="token" value="'.newToken().'">';
1570 print '<input type="hidden" name="from" value="'.dol_escape_htmltag($from).'">';
1571
1572 // Special warning for VAT dictionary
1573 if ($id == DICT_TVA && !getDolGlobalString('FACTURE_TVAOPTION')) {
1574 print info_admin($langs->trans("VATIsUsedIsOff", $langs->transnoentities("Setup"), $langs->transnoentities("CompanyFoundation")));
1575 print "<br>\n";
1576 }
1577
1578 // List of available record in database
1579 dol_syslog("htdocs/admin/dict", LOG_DEBUG);
1580
1581 $resql = $db->query($sql);
1582 if ($resql) {
1583 $num = $db->num_rows($resql);
1584 $i = 0;
1585
1586 $massactionbutton = $linkback;
1587
1588 $newcardbutton = '';
1589 /*$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));
1590 $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition'));
1591 $newcardbutton .= dolGetButtonTitleSeparator();
1592 */
1593 $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/admin/dict.php?action=create'.$param.'&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
1594
1595 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'tools', 0, $newcardbutton, '', $listlimit, 'listlimit', 0, 1);
1596
1597
1598 if ($action == 'create') {
1599 // Form to add a new line
1600 if ($tabname[$id]) {
1601 $withentity = null;
1602
1603 $fieldlist = explode(',', $tabfield[$id]);
1604
1605 print '<div class="div-table-responsive-no-min">';
1606 print '<table class="noborder centpercent">';
1607
1608 // Line for title
1609 print '<!-- line title to add new entry -->';
1610 $tdsoffields = '<tr class="liste_titre">';
1611 foreach ($fieldlist as $field => $value) {
1612 if ($value == 'entity') {
1613 $withentity = (int) getEntity($tabname[$id], 0);
1614 continue;
1615 }
1616
1617 // Define field friendly name from its technical name
1618 $valuetoshow = ucfirst($value); // Par default
1619 $valuetoshow = $langs->trans($valuetoshow); // try to translate
1620 $class = '';
1621
1622 if ($value == 'pos') {
1623 $valuetoshow = $langs->trans("Position");
1624 $class = 'right';
1625 }
1626 if ($value == 'source') {
1627 $valuetoshow = $langs->trans("Contact");
1628 }
1629 if ($value == 'price') {
1630 $valuetoshow = $langs->trans("PriceUHT");
1631 }
1632 if ($value == 'taux') {
1633 if ($tabname[$id] != "c_revenuestamp") {
1634 $valuetoshow = $langs->trans("Rate");
1635 } else {
1636 $valuetoshow = $langs->trans("Amount");
1637 }
1638 $class = 'center';
1639 }
1640 if ($value == 'localtax1_type') {
1641 $valuetoshow = $langs->trans("UseLocalTax")." 2";
1642 $class = "center";
1643 $sortable = 0;
1644 }
1645 if ($value == 'localtax1') {
1646 $valuetoshow = $langs->trans("RateOfTaxN", '2');
1647 $class = "center minwidth75";
1648 }
1649 if ($value == 'localtax2_type') {
1650 $valuetoshow = $langs->trans("UseLocalTax")." 3";
1651 $class = "center";
1652 $sortable = 0;
1653 }
1654 if ($value == 'localtax2') {
1655 $valuetoshow = $langs->trans("RateOfTaxN", '3');
1656 $class = "center minwidth75";
1657 }
1658 if ($value == 'type_vat') {
1659 $valuetoshow = $langs->trans("VATType");
1660 }
1661 if ($value == 'organization') {
1662 $valuetoshow = $langs->trans("Organization");
1663 }
1664 if ($value == 'lang') {
1665 $valuetoshow = $langs->trans("Language");
1666 }
1667 if ($value == 'type') {
1668 if ($tabname[$id] == "c_paiement") {
1669 $valuetoshow = $form->textwithtooltip($langs->trans("Type"), $langs->trans("TypePaymentDesc"), 2, 1, img_help(1, ''));
1670 } else {
1671 $valuetoshow = $langs->trans("Type");
1672 }
1673 }
1674 if ($value == 'code') {
1675 $valuetoshow = $langs->trans("Code");
1676 $class = 'maxwidth100';
1677 }
1678 if ($value == 'libelle' || $value == 'label') {
1679 $valuetoshow = $form->textwithtooltip($langs->trans("Label"), $langs->trans("LabelUsedByDefault"), 2, 1, img_help(1, ''));
1680 }
1681 if ($value == 'libelle_facture') {
1682 $valuetoshow = $form->textwithtooltip($langs->trans("LabelOnDocuments"), $langs->trans("LabelUsedByDefault"), 2, 1, img_help(1, ''));
1683 }
1684 if ($value == 'deposit_percent') {
1685 $valuetoshow = $langs->trans('DepositPercent');
1686 $class = 'right';
1687 }
1688 if ($value == 'country') {
1689 if (in_array('region_id', $fieldlist)) {
1690 //print '<td>&nbsp;</td>';
1691 continue;
1692 } // For region page, we do not show the country input
1693 $valuetoshow = $langs->trans("Country");
1694 }
1695 if ($value == 'department_buyer') {
1696 $valuetoshow = '';
1697 }
1698 if ($value == 'recuperableonly') {
1699 $valuetoshow = $langs->trans("NPR");
1700 $class = "center";
1701 }
1702 if ($value == 'einvoice_vatex') {
1703 $valuetoshow = $langs->trans("VATExemptionCode");
1704 $class = "center";
1705 }
1706 if ($value == 'nbjour') {
1707 $valuetoshow = $langs->trans("NbOfDays");
1708 $class = 'right';
1709 }
1710 if ($value == 'type_cdr') {
1711 $valuetoshow = $langs->trans("AtEndOfMonth");
1712 $class = "center";
1713 }
1714 if ($value == 'decalage') {
1715 $valuetoshow = $langs->trans("Offset");
1716 $class = 'right';
1717 }
1718 if ($value == 'width' || $value == 'nx') {
1719 $valuetoshow = $langs->trans("Width");
1720 }
1721 if ($value == 'height' || $value == 'ny') {
1722 $valuetoshow = $langs->trans("Height");
1723 }
1724 if ($value == 'unit' || $value == 'metric') {
1725 $valuetoshow = $langs->trans("MeasuringUnit");
1726 }
1727 if ($value == 'region_id' || $value == 'country_id' || $value == 'department_buyer_id') {
1728 $valuetoshow = '';
1729 }
1730 if ($value == 'accountancy_code') {
1731 $valuetoshow = $langs->trans("AccountancyCode");
1732 }
1733 if ($value == 'accountancy_code_sell') {
1734 $valuetoshow = $langs->trans("AccountancyCodeSell");
1735 }
1736 if ($value == 'accountancy_code_buy') {
1737 $valuetoshow = $langs->trans("AccountancyCodeBuy");
1738 }
1739 if ($value == 'pcg_version' || $value == 'fk_pcg_version') {
1740 $valuetoshow = $langs->trans("Pcg_version");
1741 }
1742 if ($value == 'account_parent') {
1743 $valuetoshow = $langs->trans("Accountparent");
1744 }
1745 if ($value == 'pcg_type') {
1746 $valuetoshow = $langs->trans("Pcg_type");
1747 }
1748 if ($value == 'pcg_subtype') {
1749 $valuetoshow = $langs->trans("Pcg_subtype");
1750 }
1751 if ($value == 'sortorder') {
1752 $valuetoshow = $langs->trans("SortOrder");
1753 $class = 'center';
1754 }
1755 if ($value == 'short_label') {
1756 $valuetoshow = $langs->trans("ShortLabel");
1757 }
1758 if ($value == 'fk_parent') {
1759 $valuetoshow = $langs->trans("ParentID");
1760 $class = 'center';
1761 }
1762 if ($value == 'range_account') {
1763 $valuetoshow = $langs->trans("Range");
1764 }
1765 if ($value == 'sens') {
1766 $valuetoshow = $langs->trans("Sens");
1767 }
1768 if ($value == 'category_type') {
1769 $valuetoshow = $langs->trans("Calculated");
1770 }
1771 if ($value == 'formula') {
1772 $valuetoshow = $langs->trans("Formula");
1773 }
1774 if ($value == 'paper_size') {
1775 $valuetoshow = $langs->trans("PaperSize");
1776 }
1777 if ($value == 'orientation') {
1778 $valuetoshow = $langs->trans("Orientation");
1779 }
1780 if ($value == 'leftmargin') {
1781 $valuetoshow = $langs->trans("LeftMargin");
1782 }
1783 if ($value == 'topmargin') {
1784 $valuetoshow = $langs->trans("TopMargin");
1785 }
1786 if ($value == 'spacex') {
1787 $valuetoshow = $langs->trans("SpaceX");
1788 }
1789 if ($value == 'spacey') {
1790 $valuetoshow = $langs->trans("SpaceY");
1791 }
1792 if ($value == 'font_size') {
1793 $valuetoshow = $langs->trans("FontSize");
1794 }
1795 if ($value == 'custom_x') {
1796 $valuetoshow = $langs->trans("CustomX");
1797 }
1798 if ($value == 'custom_y') {
1799 $valuetoshow = $langs->trans("CustomY");
1800 }
1801 if ($value == 'percent') {
1802 $valuetoshow = $langs->trans("Percentage");
1803 }
1804 if ($value == 'affect') {
1805 $valuetoshow = $langs->trans("WithCounter");
1806 }
1807 if ($value == 'delay') {
1808 $valuetoshow = $langs->trans("NoticePeriod");
1809 }
1810 if ($value == 'newbymonth') {
1811 $valuetoshow = $langs->trans("NewByMonth");
1812 }
1813 if ($value == 'fk_tva') {
1814 $valuetoshow = $langs->trans("VAT");
1815 }
1816 if ($value == 'range_ik') {
1817 $valuetoshow = $langs->trans("RangeIk");
1818 }
1819 if ($value == 'fk_c_exp_tax_cat') {
1820 $valuetoshow = $langs->trans("CarCategory");
1821 }
1822 if ($value == 'revenuestamp_type') {
1823 $valuetoshow = $langs->trans('TypeOfRevenueStamp');
1824 }
1825 if ($value == 'use_default') {
1826 $valuetoshow = $langs->trans('Default');
1827 $class = 'center';
1828 }
1829 if ($value == 'unit_type') {
1830 $valuetoshow = $langs->trans('TypeOfUnit');
1831 }
1832 if ($value == 'public' && $tablib[$id] == 'TicketDictCategory') {
1833 $valuetoshow = $langs->trans('TicketGroupIsPublic');
1834 $class = 'center';
1835 }
1836 if ($value == 'block_if_negative') {
1837 $valuetoshow = $langs->trans('BlockHolidayIfNegative');
1838 }
1839 if ($value == 'type_duration') {
1840 $valuetoshow = $langs->trans('Unit');
1841 }
1842
1843 if ($id == DICT_DEPARTEMENTS) { // Special case for state page
1844 if ($value == 'region_id') {
1845 $valuetoshow = '&nbsp;';
1846 $showfield = 1;
1847 }
1848 if ($value == 'region') {
1849 $valuetoshow = $langs->trans("Country").'/'.$langs->trans("Region");
1850 $showfield = 1;
1851 }
1852 }
1853
1854 if ($valuetoshow != '') {
1855 $tooltiphelp = (isset($tabcomplete[$tabname[$id]]['help'][$value]) ? $tabcomplete[$tabname[$id]]['help'][$value] : '');
1856
1857 $tdsoffields .= '<th'.($class ? ' class="'.$class.'"' : '').'>';
1858 if ($tooltiphelp && preg_match('/^http(s*):/i', $tooltiphelp)) {
1859 $tdsoffields .= '<a href="'.$tooltiphelp.'" target="_blank">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
1860 } elseif ($tooltiphelp) {
1861 $tdsoffields .= $form->textwithpicto($valuetoshow, $tooltiphelp);
1862 } else {
1863 $tdsoffields .= $valuetoshow;
1864 }
1865 $tdsoffields .= '</th>';
1866 }
1867 }
1868
1869 if ($id == DICT_COUNTRY) {
1870 $tdsoffields .= '<th></th>';
1871 $tdsoffields .= '<th></th>';
1872 }
1873 $tdsoffields .= '<th>';
1874 $tdsoffields .= '<input type="hidden" name="id" value="'.$id.'">';
1875 if (!is_null($withentity)) {
1876 $tdsoffields .= '<input type="hidden" name="entity" value="'.$withentity.'">';
1877 }
1878 $tdsoffields .= '</th>';
1879 $tdsoffields .= '<th style="min-width: 26px;"></th>';
1880 $tdsoffields .= '<th style="min-width: 26px;"></th>';
1881 $tdsoffields .= '</tr>';
1882
1883 print $tdsoffields;
1884
1885
1886 // Line to enter new values
1887 print '<!-- line input to add new entry -->';
1888 print '<tr class="oddeven nodrag nodrop nohover">';
1889
1890 $obj = new stdClass();
1891 // If data was already input, we define them in obj to populate input fields.
1892 if (GETPOST('actionadd')) {
1893 foreach ($fieldlist as $key => $val) {
1894 if (GETPOST($val) != '') {
1895 $obj->$val = GETPOST($val);
1896 }
1897 }
1898 }
1899
1900 $tmpaction = 'create';
1901 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
1902 $reshook = $hookmanager->executeHooks('createDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
1903 $error = $hookmanager->error;
1904 $errors = $hookmanager->errors;
1905
1906 if ($id == DICT_REGIONS) {
1907 unset($fieldlist[2]); // Remove field ??? if dictionary Regions
1908 }
1909
1910 if (empty($reshook)) {
1911 dictFieldList($fieldlist, $obj, $tabname[$id], 'add');
1912 }
1913
1914 if ($id == DICT_COUNTRY) {
1915 print '<td></td>';
1916 print '<td></td>';
1917 print '<td></td>';
1918 }
1919 print '<td colspan="3" class="center">';
1920 if ($action != 'edit') {
1921 print '<input type="submit" class="button button-add small" name="actionadd" value="'.$langs->trans("Add").'">';
1922 } else {
1923 print '<input type="submit" class="button button-add small disabled" name="actionadd" value="'.$langs->trans("Add").'">';
1924 }
1925 print '</td>';
1926
1927 print "</tr>";
1928
1929 print '</table>';
1930 print '</div>';
1931 }
1932
1933 print '</form>';
1934
1935 print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST" spellcheck="false">';
1936 print '<input type="hidden" name="token" value="'.newToken().'">';
1937 print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
1938 }
1939
1940
1941 $filterfound = 0;
1942 foreach ($fieldlist as $field => $value) {
1943 if ($value == 'entity') {
1944 continue;
1945 }
1946
1947 $showfield = 1; // By default
1948 if ($value == 'region_id' || $value == 'country_id' || $value == 'department_buyer_id') {
1949 $showfield = 0;
1950 }
1951
1952 if ($showfield) {
1953 if ($value == 'country') {
1954 $filterfound++;
1955 } elseif ($value == 'code') {
1956 $filterfound++;
1957 }
1958 }
1959 }
1960
1961 print '<div class="div-table-responsive">';
1962 print '<table class="noborder centpercent noborder">';
1963
1964 $colspan = 0;
1965
1966 // Title line with search input fields
1967 print '<!-- line title to search record -->'."\n";
1968 print '<tr class="liste_titre_filter">';
1969
1970 // Action button
1971 if ($conf->main_checkbox_left_column) {
1972 print '<td class="liste_titre center">';
1973 if ($filterfound) {
1974 $searchpicto = $form->showFilterAndCheckAddButtons(0);
1975 print $searchpicto;
1976 }
1977 print '</td>';
1978 $colspan++;
1979 }
1980
1981 foreach ($fieldlist as $field => $value) {
1982 if ($value == 'entity') {
1983 continue;
1984 }
1985
1986 $showfield = 1; // By default
1987 if ($value == 'region_id' || $value == 'country_id' || $value == 'department_buyer_id') {
1988 $showfield = 0;
1989 }
1990
1991 if ($showfield) {
1992 if ($value == 'country') {
1993 print '<td class="liste_titre">';
1994 print $form->select_country($search_country_id, 'search_country_id', '', 28, 'minwidth100 maxwidth150 maxwidthonsmartphone', '', '&nbsp;');
1995 print '</td>';
1996 $colspan++;
1997 } elseif ($value == 'code') {
1998 print '<td class="liste_titre">';
1999 print '<input type="text" class="maxwidth100" name="search_code" value="'.dol_escape_htmltag($search_code).'">';
2000 print '</td>';
2001 $colspan++;
2002 } elseif ($value == 'type_vat') {
2003 print '<td class="liste_titre">';
2004 print $form->selectarray('search_'.$value, $type_vatList, (empty($obj->{$value}) ? '' : $obj->{$value}), 1);
2005 print '</td>';
2006 $colspan++;
2007 } else {
2008 print '<td class="liste_titre">';
2009 print '</td>';
2010 $colspan++;
2011 }
2012 }
2013 }
2014 if ($id == DICT_COUNTRY) {
2015 print '<td></td>';
2016 $colspan++;
2017 print '<td></td>';
2018 $colspan++;
2019 print '<td></td>';
2020 $colspan++;
2021 }
2022
2023 // Active
2024 print '<td class="liste_titre center parentonrightofpage">';
2025 print $form->selectyesno('search_active', $search_active, 0, false, 1, 1, 'maxwidth100 onrightofpage', 'Activated', 'Disabled');
2026 print '</td>';
2027 $colspan++;
2028
2029 // Action button
2030 if (!$conf->main_checkbox_left_column) {
2031 print '<td class="liste_titre center">';
2032 if ($filterfound) {
2033 $searchpicto = $form->showFilterAndCheckAddButtons(0);
2034 print $searchpicto;
2035 }
2036 print '</td>';
2037 $colspan++;
2038 }
2039
2040 print '</tr>';
2041
2042
2043 // Title of lines
2044 print '<!-- line title of record -->'."\n";
2045 print '<tr class="liste_titre">';
2046
2047 // Action button
2048 if ($conf->main_checkbox_left_column) {
2049 print getTitleFieldOfList('');
2050 }
2051
2052 foreach ($fieldlist as $field => $value) {
2053 if ($value == 'entity') {
2054 continue;
2055 }
2056
2057 if (in_array($value, array('label', 'libelle', 'libelle_facture')) && empty($tabcomplete[$tabname[$id]]['help'][$value])) {
2058 if (!isset($tabcomplete[$tabname[$id]]['help']) || !is_array($tabcomplete[$tabname[$id]]['help'])) { // protection when $tabcomplete[$tabname[$id]]['help'] is a an empty string, we must force it into an array
2059 $tabcomplete[$tabname[$id]]['help'] = array();
2060 }
2061 $tabcomplete[$tabname[$id]]['help'][$value] = $langs->trans('LabelUsedByDefault');
2062 }
2063
2064 // Determines the name of the field in relation to the possible names
2065 // in data dictionaries
2066 $showfield = 1; // By default
2067 $cssprefix = '';
2068 $sortable = 1;
2069 $valuetoshow = ucfirst($value); // By default
2070 $valuetoshow = $langs->trans($valuetoshow); // try to translate
2071
2072 // Special cases
2073 if ($value == 'source') {
2074 $valuetoshow = $langs->trans("Contact");
2075 }
2076 if ($value == 'price') {
2077 $valuetoshow = $langs->trans("PriceUHT");
2078 }
2079 if ($value == 'taux') {
2080 if ($tabname[$id] != "c_revenuestamp") {
2081 $valuetoshow = $langs->trans("Rate");
2082 } else {
2083 $valuetoshow = $langs->trans("Amount");
2084 }
2085 $cssprefix = 'center ';
2086 }
2087
2088 if ($value == 'type_vat') {
2089 $valuetoshow = $langs->trans("VATType");
2090 $cssprefix = "center minwidth75 ";
2091 $sortable = 0;
2092 }
2093 if ($value == 'localtax1_type') {
2094 $valuetoshow = $langs->trans("UseLocalTax")." 2";
2095 $cssprefix = "center minwidth75 ";
2096 $sortable = 0;
2097 }
2098 if ($value == 'localtax1') {
2099 $valuetoshow = $langs->trans("RateOfTaxN", '2');
2100 $cssprefix = "center minwidth75 ";
2101 $sortable = 0;
2102 }
2103 if ($value == 'localtax2_type') {
2104 $valuetoshow = $langs->trans("UseLocalTax")." 3";
2105 $cssprefix = "center minwidth75 ";
2106 $sortable = 0;
2107 }
2108 if ($value == 'localtax2') {
2109 $valuetoshow = $langs->trans("RateOfTaxN", '3');
2110 $cssprefix = "center minwidth75 ";
2111 $sortable = 0;
2112 }
2113 if ($value == 'organization') {
2114 $valuetoshow = $langs->trans("Organization");
2115 }
2116 if ($value == 'lang') {
2117 $valuetoshow = $langs->trans("Language");
2118 }
2119 if ($value == 'type') {
2120 $valuetoshow = $langs->trans("Type");
2121 }
2122 if ($value == 'code') {
2123 $valuetoshow = $langs->trans("Code");
2124 }
2125 if (in_array($value, array('pos', 'position'))) {
2126 $valuetoshow = $langs->trans("Position");
2127 $cssprefix = 'right ';
2128 }
2129 if ($value == 'libelle' || $value == 'label') {
2130 $valuetoshow = $langs->trans("Label");
2131 }
2132 if ($value == 'libelle_facture') {
2133 $valuetoshow = $langs->trans("LabelOnDocuments");
2134 }
2135 if ($value == 'deposit_percent') {
2136 $valuetoshow = $langs->trans('DepositPercent');
2137 $cssprefix = 'right ';
2138 }
2139 if ($value == 'country') {
2140 $valuetoshow = $langs->trans("Country");
2141 }
2142 if ($value == 'phone_code') {
2143 $valuetoshow = $langs->trans("PhoneCode");
2144 }
2145 if ($value == 'trunk_prefix') {
2146 $valuetoshow = $langs->trans("TrunkPrefix");
2147 }
2148 if ($value == 'department_buyer') {
2149 $valuetoshow = $langs->trans('DepartmentBuyer');
2150 }
2151 if ($value == 'recuperableonly') {
2152 $valuetoshow = $langs->trans("NPR");
2153 $cssprefix = "center ";
2154 }
2155 if ($value == 'einvoice_vatex') {
2156 $valuetoshow = $langs->trans("VATExemptionCode");
2157 $cssprefix = "center";
2158 }
2159 if ($value == 'nbjour') {
2160 $valuetoshow = $langs->trans("NbOfDays");
2161 $cssprefix = 'right ';
2162 }
2163 if ($value == 'type_cdr') {
2164 $valuetoshow = $langs->trans("AtEndOfMonth");
2165 $cssprefix = "center ";
2166 }
2167 if ($value == 'decalage') {
2168 $valuetoshow = $langs->trans("Offset");
2169 $cssprefix = 'right ';
2170 }
2171 if ($value == 'width' || $value == 'nx') {
2172 $valuetoshow = $langs->trans("Width");
2173 }
2174 if ($value == 'height' || $value == 'ny') {
2175 $valuetoshow = $langs->trans("Height");
2176 }
2177 if ($value == 'unit' || $value == 'metric') {
2178 $valuetoshow = $langs->trans("MeasuringUnit");
2179 }
2180 if ($value == 'accountancy_code') {
2181 $valuetoshow = $langs->trans("AccountancyCode");
2182 }
2183 if ($value == 'accountancy_code_sell') {
2184 $valuetoshow = $langs->trans("AccountancyCodeSell");
2185 $sortable = 0;
2186 }
2187 if ($value == 'accountancy_code_buy') {
2188 $valuetoshow = $langs->trans("AccountancyCodeBuy");
2189 $sortable = 0;
2190 }
2191 if ($value == 'fk_pcg_version') {
2192 $valuetoshow = $langs->trans("Pcg_version");
2193 }
2194 if ($value == 'account_parent') {
2195 $valuetoshow = $langs->trans("Accountsparent");
2196 }
2197 if ($value == 'pcg_type') {
2198 $valuetoshow = $langs->trans("Pcg_type");
2199 }
2200 if ($value == 'pcg_subtype') {
2201 $valuetoshow = $langs->trans("Pcg_subtype");
2202 }
2203 if ($value == 'sortorder') {
2204 $valuetoshow = $langs->trans("SortOrder");
2205 $cssprefix = 'center ';
2206 }
2207 if ($value == 'short_label') {
2208 $valuetoshow = $langs->trans("ShortLabel");
2209 }
2210 if ($value == 'fk_parent') {
2211 $valuetoshow = $langs->trans("ParentID");
2212 $cssprefix = 'center ';
2213 }
2214 if ($value == 'range_account') {
2215 $valuetoshow = $langs->trans("Range");
2216 }
2217 if ($value == 'sens') {
2218 $valuetoshow = $langs->trans("Sens");
2219 }
2220 if ($value == 'category_type') {
2221 $valuetoshow = $langs->trans("Calculated");
2222 }
2223 if ($value == 'formula') {
2224 $valuetoshow = $langs->trans("Formula");
2225 }
2226 if ($value == 'paper_size') {
2227 $valuetoshow = $langs->trans("PaperSize");
2228 }
2229 if ($value == 'orientation') {
2230 $valuetoshow = $langs->trans("Orientation");
2231 }
2232 if ($value == 'leftmargin') {
2233 $valuetoshow = $langs->trans("LeftMargin");
2234 }
2235 if ($value == 'topmargin') {
2236 $valuetoshow = $langs->trans("TopMargin");
2237 }
2238 if ($value == 'spacex') {
2239 $valuetoshow = $langs->trans("SpaceX");
2240 }
2241 if ($value == 'spacey') {
2242 $valuetoshow = $langs->trans("SpaceY");
2243 }
2244 if ($value == 'font_size') {
2245 $valuetoshow = $langs->trans("FontSize");
2246 }
2247 if ($value == 'custom_x') {
2248 $valuetoshow = $langs->trans("CustomX");
2249 }
2250 if ($value == 'custom_y') {
2251 $valuetoshow = $langs->trans("CustomY");
2252 }
2253 if ($value == 'percent') {
2254 $valuetoshow = $langs->trans("Percentage");
2255 }
2256 if ($value == 'affect') {
2257 $valuetoshow = $langs->trans("WithCounter");
2258 }
2259 if ($value == 'delay') {
2260 $valuetoshow = $langs->trans("NoticePeriod");
2261 }
2262 if ($value == 'newbymonth') {
2263 $valuetoshow = $langs->trans("NewByMonth");
2264 }
2265 if ($value == 'fk_tva') {
2266 $valuetoshow = $langs->trans("VAT");
2267 }
2268 if ($value == 'range_ik') {
2269 $valuetoshow = $langs->trans("RangeIk");
2270 }
2271 if ($value == 'fk_c_exp_tax_cat') {
2272 $valuetoshow = $langs->trans("CarCategory");
2273 }
2274 if ($value == 'revenuestamp_type') {
2275 $valuetoshow = $langs->trans('TypeOfRevenueStamp');
2276 }
2277 if ($value == 'use_default') {
2278 $valuetoshow = $langs->trans('Default');
2279 $cssprefix = 'center ';
2280 }
2281 if ($value == 'unit_type') {
2282 $valuetoshow = $langs->trans('TypeOfUnit');
2283 }
2284 if ($value == 'public' && $tablib[$id] == 'TicketDictCategory') {
2285 $valuetoshow = $langs->trans('TicketGroupIsPublic');
2286 $cssprefix = 'center ';
2287 }
2288 if ($value == 'block_if_negative') {
2289 $valuetoshow = $langs->trans('BlockHolidayIfNegative');
2290 }
2291 if ($value == 'type_duration') {
2292 $valuetoshow = $langs->trans('Unit');
2293 }
2294
2295 if ($value == 'region_id' || $value == 'country_id' || $value == 'department_buyer_id') {
2296 $showfield = 0;
2297 }
2298
2299 // Show field title
2300 if ($showfield) {
2301 $tooltiphelp = (isset($tabcomplete[$tabname[$id]]['help'][$value]) ? $tabcomplete[$tabname[$id]]['help'][$value] : '');
2302
2303 if ($tooltiphelp && preg_match('/^http(s*):/i', $tooltiphelp)) {
2304 $newvaluetoshow = '<a href="'.$tooltiphelp.'" target="_blank">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
2305 } elseif ($tooltiphelp) {
2306 $newvaluetoshow = $form->textwithpicto($valuetoshow, $tooltiphelp);
2307 } else {
2308 $newvaluetoshow = $valuetoshow;
2309 }
2310
2311 print getTitleFieldOfList($newvaluetoshow, 0, $_SERVER["PHP_SELF"], ($sortable ? $value : ''), ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, $cssprefix);
2312 }
2313 }
2314 // Favorite, EEC & Sepa - Only activated on country dictionary
2315 if ($id == DICT_COUNTRY) {
2316 print getTitleFieldOfList($langs->trans("InEEC"), 0, $_SERVER["PHP_SELF"], "eec", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, 'center ', 0, $langs->trans("CountryIsInEEC"));
2317 print getTitleFieldOfList($langs->trans("InSepa"), 0, $_SERVER["PHP_SELF"], "sepa", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, 'center ', 0, $langs->trans("CountryIsInSepa"));
2318 print getTitleFieldOfList($langs->trans("Favorite"), 0, $_SERVER["PHP_SELF"], "favorite", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, 'center ');
2319 }
2320
2321 // Status
2322 print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, 'center ');
2323
2324 // Action button
2325 if (!$conf->main_checkbox_left_column) {
2326 print getTitleFieldOfList('');
2327 }
2328 print '</tr>';
2329
2330
2331 // Lines with values
2332 if ($num) {
2333 print '<!-- lines of dict -->'."\n";
2334 while ($i < $num) {
2335 $obj = $db->fetch_object($resql);
2336
2337 // Entity owning this row, when the dictionary is entity aware (the SELECT of
2338 // $tabsql must then include the entity column). It is used to target the right row
2339 // on write, and to tell rows of another entity apart just below.
2340 $withentity = (isset($obj->entity) ? (int) $obj->entity : null);
2341
2342 // We discard empty lines
2343 if ($id == DICT_COUNTRY) {
2344 if ($obj->code == '') {
2345 $i++;
2346 continue;
2347 }
2348 }
2349
2350 // Can an entry be erased, disabled or modified ? (true by default)
2351 $iserasable = 1;
2352 $canbedisabled = 1;
2353 $canbemodified = 1;
2354 if (isset($obj->code) && !in_array($id, array(DICT_TVA, DICT_PRODUCT_NATURE))) {
2355 if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i', $obj->code))) {
2356 $iserasable = 0;
2357 $canbedisabled = 0;
2358 } elseif ($obj->code == 'RECEP') {
2359 $iserasable = 0;
2360 $canbedisabled = 0;
2361 } elseif ($obj->code == 'EF0') {
2362 $iserasable = 0;
2363 $canbedisabled = 0;
2364 }
2365 }
2366 if ($id == DICT_TYPE_CONTAINER && $obj->module == 'system') {
2367 $iserasable = 0;
2368 $canbedisabled = 0;
2369 if (in_array($obj->code, array('banner'))) {
2370 $canbedisabled = 1;
2371 }
2372 }
2373 if (isset($obj->type) && in_array($obj->type, array('system', 'systemauto'))) {
2374 $iserasable = 0;
2375 }
2376 if (in_array(empty($obj->code) ? '' : $obj->code, array('AC_OTH', 'AC_OTH_AUTO')) || in_array(empty($obj->type) ? '' : $obj->type, array('systemauto'))) {
2377 $canbedisabled = 0;
2378 $canbedisabled = 0;
2379 }
2380 $canbemodified = $iserasable;
2381
2382 if (!empty($obj->code) && $obj->code == 'RECEP') {
2383 $canbemodified = 1;
2384 }
2385 if ($tabname[$id] == "c_actioncomm") {
2386 $canbemodified = 1;
2387 }
2388
2389 if ($tabname[$id] == "c_product_nature" && in_array($obj->code, array(0, 1))) {
2390 $canbedisabled = 0;
2391 $canbemodified = 0;
2392 $iserasable = 0;
2393 }
2394
2395 // A row owned by another entity is read-only here. This happens when a dictionary
2396 // is shared with the current entity (for instance the dictionary of the master
2397 // entity that this entity only extends, with module multicompany): the row is
2398 // legitimately listed, but editing it would change it for the other entity too.
2399 // Without multicompany, getEntity() returns the current entity and every listed row
2400 // belongs to it, so this never triggers.
2401 if (!is_null($withentity) && $withentity != (int) getEntity($tabname[$id], 0)) {
2402 $iserasable = 0;
2403 $canbedisabled = 0;
2404 $canbemodified = 0;
2405 }
2406 // Build Url. The table is id=, the id of line is rowid=
2407 $rowidcol = empty($tabrowid[$id]) ? 'rowid' : $tabrowid[$id];
2408 // If rowidcol not defined
2409 if (empty($rowidcol) || in_array($id, array(DICT_ACTIONCOMM, DICT_CHARGESOCIALES, DICT_TYPENT, DICT_PAIEMENT, DICT_TYPE_FEES, DICT_EFFECTIF, DICT_STCOMM, DICT_HRM_PUBLIC_HOLIDAY))) {
2410 $rowidcol = 'rowid';
2411 }
2412 $url = $_SERVER["PHP_SELF"].'?'.($page ? 'page='.$page.'&' : '').'sortfield='.urlencode($sortfield).'&sortorder='.urlencode($sortorder);
2413 $url .= '&rowid='.(isset($obj->$rowidcol) ? ((int) $obj->$rowidcol) : (!empty($obj->code) ? urlencode($obj->code) : ''));
2414 $url .= '&code='.(!empty($obj->code) ? urlencode($obj->code) : '');
2415 if (!empty($param)) {
2416 $url .= '&'.$param;
2417 }
2418 // If dictionary is different for each entity
2419 if (!is_null($withentity)) {
2420 $url .= '&entity='.((int) $withentity);
2421 }
2422 $url .= '&';
2423
2424
2425 //print_r($obj);
2426 print '<tr class="oddeven" id="rowid-'.(empty($obj->rowid) ? '' : $obj->rowid).'">';
2427
2428 // Action button
2429 if ($conf->main_checkbox_left_column) {
2430 print '<td class="center maxwidthsearch nowraponall">';
2431 // Modify link
2432 if ($canbemodified) {
2433 print '<a class="reposition editfielda marginleftonly paddingleft marginrightonly paddingright" href="'.$url.'action=edit&token='.newToken().'">'.img_edit().'</a>';
2434 }
2435 // Delete link
2436 if ($iserasable) {
2437 if ($user->admin) {
2438 print '<a class="reposition marginleftonly paddingleft marginrightonly paddingright" href="'.$url.'action=delete&token='.newToken().'">'.img_delete().'</a>';
2439 }
2440 }
2441 print '</td>';
2442 }
2443
2444 // Use isset() rather than !empty() so a dictionary row with rowid = 0
2445 // (for example ST_NEVER in llx_c_stcomm) is treated as a real rowid and
2446 // not fallen back to the code, which would make it un-editable (#38781).
2447 if ($action == 'edit' && ($rowid == (isset($obj->rowid) ? $obj->rowid : $obj->code))) {
2448 $tmpaction = 'edit';
2449 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
2450 $reshook = $hookmanager->executeHooks('editDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
2451 $error = $hookmanager->error;
2452 $errors = $hookmanager->errors;
2453
2454 // Show fields
2455 if (empty($reshook)) {
2456 $withentity = dictFieldList($fieldlist, $obj, $tabname[$id], 'edit');
2457 }
2458
2459 print '<td colspan="3" class="center">';
2460 print '<div name="'.(isset($obj->rowid) ? $obj->rowid : $obj->code).'"></div>';
2461 print '<input type="hidden" name="page" value="'.((int) $page).'">';
2462 print '<input type="hidden" name="rowid" value="'.dol_escape_htmltag($rowid).'">';
2463 if (!is_null($withentity)) {
2464 print '<input type="hidden" name="entity" value="'.$withentity.'">';
2465 }
2466 print '<input type="submit" class="button button-edit smallpaddingimp" name="actionmodify" value="'.$langs->trans("Modify").'">';
2467 print '<input type="submit" class="button button-cancel smallpaddingimp" name="actioncancel" value="'.$langs->trans("Cancel").'">';
2468 print '</td>';
2469 } else {
2470 $tmpaction = 'view';
2471 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
2472 $reshook = $hookmanager->executeHooks('viewDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
2473
2474 $error = $hookmanager->error;
2475 $errors = $hookmanager->errors;
2476
2477 $langs->loadLangs(array("bills", "agenda", "propal"));
2478
2479 if (empty($reshook)) {
2480 $withentity = null;
2481 $TDurationTypes = $form->getDurationTypes($langs);
2482
2483 foreach ($fieldlist as $field => $value) {
2484 $class = (isset($tabcomplete[$tabname[$id]]['css'][$value]) ? $tabcomplete[$tabname[$id]]['css'][$value] : '');
2485 $showfield = 1;
2486 $valuetoshow = (isset($obj->$value) && $obj->$value !== null && $obj->$value !== '') ? $obj->$value : '';
2487 $titletoshow = '';
2488
2489 if ($value == 'entity') {
2490 $withentity = $valuetoshow;
2491 continue;
2492 }
2493
2494 // Management of several special cases and exceptions
2495 if ($value == 'code' && $id == DICT_PRODUCT_NATURE) {
2496 $valuetoshow = (int) $valuetoshow;
2497 } elseif ($value == 'element') {
2498 $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow;
2499 } elseif ($value == 'source') {
2500 $valuetoshow = isset($sourceList[$valuetoshow]) ? $sourceList[$valuetoshow] : $valuetoshow;
2501 } elseif ($valuetoshow == 'all') {
2502 $valuetoshow = $langs->trans('All');
2503 } elseif ($value == 'country') {
2504 if (empty($obj->country_code)) {
2505 $valuetoshow = '-';
2506 } else {
2507 $key = $langs->trans("Country".strtoupper($obj->country_code));
2508 $valuetoshow = ($key != "Country".strtoupper($obj->country_code) ? $obj->country_code." - ".$key : $obj->country);
2509 }
2510 } elseif ($value == 'recuperableonly' || $value == 'deductible' || $value == 'category_type') {
2511 $valuetoshow = yn($valuetoshow ? 1 : 0);
2512 $class = "center";
2513 } elseif ($value == 'type_cdr') {
2514 if (empty($valuetoshow)) {
2515 $valuetoshow = $langs->trans('None');
2516 } elseif ($valuetoshow == 1) {
2517 $valuetoshow = $langs->trans('AtEndOfMonth');
2518 } elseif ($valuetoshow == 2) {
2519 $valuetoshow = $langs->trans('CurrentNext');
2520 }
2521 $class = "center tdoverflowmax125";
2522 } elseif ($value == 'price' || preg_match('/^amount/i', $value)) {
2523 $valuetoshow = price($valuetoshow);
2524 }
2525 if (in_array($value, array('private', 'joinfile', 'use_default'))) {
2526 if (!empty($valuetoshow)) {
2527 $valuetoshow = img_picto('', 'tick');
2528 } else {
2529 $valuetoshow = '';
2530 }
2531 } elseif ($value == 'libelle_facture') {
2532 $key = $langs->trans("PaymentCondition".strtoupper($obj->code));
2533 $valuetoshow = ($obj->code && $key != "PaymentCondition".strtoupper($obj->code) ? $key : $obj->$value);
2534 $valuetoshow = nl2br($valuetoshow);
2535 $titletoshow = $valuetoshow;
2536 $class = 'small tdoverflowmax200';
2537 } elseif ($value == 'label' && $tabname[$id] == 'c_country') {
2538 $key = $langs->trans("Country".strtoupper($obj->code));
2539 $valuetoshow = ($obj->code && $key != "Country".strtoupper($obj->code) ? $key : $obj->$value);
2540 } elseif ($value == 'label' && $tabname[$id] == 'c_availability') {
2541 $key = $langs->trans("AvailabilityType".strtoupper($obj->code));
2542 $valuetoshow = ($obj->code && $key != "AvailabilityType".strtoupper($obj->code) ? $key : $obj->$value);
2543 } elseif ($value == 'libelle' && $tabname[$id] == 'c_actioncomm') {
2544 $key = $langs->trans("Action".strtoupper($obj->code));
2545 $valuetoshow = ($obj->code && $key != "Action".strtoupper($obj->code) ? $key : $obj->$value);
2546 } elseif (!empty($obj->code_iso) && $value == 'label' && $tabname[$id] == 'c_currencies') {
2547 $key = $langs->trans("Currency".strtoupper($obj->code_iso));
2548 $valuetoshow = (/* $obj->code_iso && */ $key != "Currency".strtoupper($obj->code_iso) ? $key : $obj->$value);
2549 } elseif ($value == 'libelle' && $tabname[$id] == 'c_typent') {
2550 $key = $langs->trans(strtoupper($obj->code));
2551 $valuetoshow = ($key != strtoupper($obj->code) ? $key : $obj->$value);
2552 } elseif ($value == 'libelle' && $tabname[$id] == 'c_prospectlevel') {
2553 $key = $langs->trans(strtoupper($obj->code));
2554 $valuetoshow = ($key != strtoupper($obj->code) ? $key : $obj->$value);
2555 } elseif ($value == 'label' && $tabname[$id] == 'c_civility') {
2556 $key = $langs->trans("Civility".strtoupper($obj->code));
2557 $valuetoshow = ($obj->code && $key != "Civility".strtoupper($obj->code) ? $key : $obj->$value);
2558 } elseif ($value == 'libelle' && $tabname[$id] == 'c_type_contact') {
2559 $key = $langs->trans("TypeContact_".$obj->element."_".$obj->source."_".strtoupper($obj->code));
2560 $valuetoshow = ($obj->code && $key != "TypeContact_".$obj->element."_".$obj->source."_".strtoupper($obj->code) ? $key : $obj->$value);
2561 } elseif ($value == 'libelle' && $tabname[$id] == 'c_payment_term') {
2562 $key = $langs->trans("PaymentConditionShort".strtoupper($obj->code));
2563 $valuetoshow = ($obj->code && $key != "PaymentConditionShort".strtoupper($obj->code) ? $key : $obj->$value);
2564 $titletoshow = $key;
2565 $class = "tdoverflowmax150";
2566 } elseif ($value == 'libelle' && $tabname[$id] == 'c_paiement') {
2567 $key = $langs->trans("PaymentType".strtoupper($obj->code));
2568 $valuetoshow = $obj->$value;
2569 if ($obj->code && array_key_exists("PaymentType".strtoupper($obj->code), $langs->tab_translate)) {
2570 $htmltext = $form->textwithpicto($langs->trans("TranslationFound").': '.$key, $langs->trans("TheTranslationIsSearchedFromKey", "PaymentType".strtoupper($obj->code)));
2571 } else {
2572 $htmltext = $form->textwithpicto($langs->trans("TranslationFound").': '.$langs->trans("No"), $langs->trans("TheTranslationIsSearchedFromKey", "PaymentType".strtoupper($obj->code)));
2573 }
2574 //$valuetoshow = $form->textwithpicto($valuetoshow, $htmltext);
2575 $valuetoshow .= '<br><span class="opacitymedium small">'.$htmltext.'</span>';
2576 } elseif ($value == 'type' && $tabname[$id] == 'c_paiement') {
2577 $payment_type_list = array(0 => $langs->trans('PaymentTypeCustomer'), 1 => $langs->trans('PaymentTypeSupplier'), 2 => $langs->trans('PaymentTypeBoth'));
2578 $valuetoshow = $payment_type_list[$valuetoshow];
2579 } elseif ($value == 'label' && $tabname[$id] == 'c_input_reason') {
2580 $key = $langs->trans("DemandReasonType".strtoupper($obj->code));
2581 $valuetoshow = ($obj->code && $key != "DemandReasonType".strtoupper($obj->code) ? $key : $obj->$value);
2582 } elseif ($value == 'libelle' && $tabname[$id] == 'c_input_method') {
2583 $langs->load("orders");
2584 $key = $langs->trans($obj->code);
2585 $valuetoshow = ($obj->code && $key != $obj->code) ? $key : $obj->$value;
2586 } elseif ($value == 'libelle' && $tabname[$id] == 'c_shipment_mode') {
2587 $langs->load("sendings");
2588 $key = $langs->trans("SendingMethod".strtoupper($obj->code));
2589 $valuetoshow = ($obj->code && $key != "SendingMethod".strtoupper($obj->code) ? $key : $obj->$value);
2590 } elseif ($value == 'libelle' && $tabname[$id] == 'c_paper_format') {
2591 $key = $langs->trans('PaperFormat'.strtoupper($obj->code));
2592 $valuetoshow = ($obj->code && $key != 'PaperFormat'.strtoupper($obj->code) ? $key : $obj->$value);
2593 } elseif ($value == 'label' && $tabname[$id] == 'c_type_fees') {
2594 $langs->load('trips');
2595 $key = $langs->trans(strtoupper($obj->code));
2596 $valuetoshow = ($obj->code && $key != strtoupper($obj->code) ? $key : $obj->$value);
2597 } elseif ($value == 'region_id' || $value == 'country_id' || $value == 'department_buyer_id') {
2598 $showfield = 0;
2599 } elseif ($value == 'unicode') {
2600 $valuetoshow = $langs->getCurrencySymbol($obj->code, 1);
2601 } elseif ($value == 'label' && $tabname[GETPOSTINT("id")] == 'c_units') {
2602 $langs->load("products");
2603 $valuetoshow = $langs->trans($obj->$value);
2604 } elseif ($value == 'short_label' && $tabname[GETPOSTINT("id")] == 'c_units') {
2605 $langs->load("products");
2606 $valuetoshow = $langs->trans($obj->$value);
2607 } elseif (($value == 'unit') && ($tabname[$id] == 'c_paper_format')) {
2608 $key = $langs->trans('SizeUnit'.strtolower($obj->unit));
2609 $valuetoshow = ($obj->code && $key != 'SizeUnit'.strtolower($obj->unit) ? $key : $obj->$value);
2610 } elseif ($value == 'localtax1' || $value == 'localtax2') {
2611 $class = "center";
2612 } elseif ($value == 'type_vat') {
2613 $valuetoshow = $type_vatList[(int) $valuetoshow];
2614 $class = "center";
2615 } elseif ($value == 'localtax1_type') {
2616 if ($obj->localtax1 != 0) {
2617 $valuetoshow = $localtax_typeList[$valuetoshow];
2618 } else {
2619 $valuetoshow = '';
2620 }
2621 $class = "center";
2622 } elseif ($value == 'localtax2_type') {
2623 if ($obj->localtax2 != 0) {
2624 $valuetoshow = $localtax_typeList[$valuetoshow];
2625 } else {
2626 $valuetoshow = '';
2627 }
2628 $class = "center";
2629 } elseif ($value == 'taux') {
2630 $valuetoshow = price($valuetoshow, 0, $langs, 0, 0);
2631 $class = "center";
2632 } elseif (in_array($value, array('recuperableonly'))) {
2633 $class = "center";
2634 } elseif ($value == 'accountancy_code' || $value == 'accountancy_code_sell' || $value == 'accountancy_code_buy') {
2635 if (isModEnabled('accounting')) {
2636 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
2637 $tmpaccountingaccount = new AccountingAccount($db);
2638 $tmpaccountingaccount->fetch(0, $valuetoshow, 1);
2639 $titletoshow = $langs->transnoentitiesnoconv("Pcgtype").': '.$tmpaccountingaccount->pcg_type;
2640 }
2641 $valuetoshow = length_accountg($valuetoshow);
2642 } elseif ($value == 'fk_tva') {
2643 if (empty($form->cache_vatrates)) {
2644 $form->load_tva('cache_fk_tva', '', $mysoc, new Societe($db), 0, 0, '', false, -1);
2645 }
2646 foreach ($form->cache_vatrates as $key => $Tab) {
2647 if ($form->cache_vatrates[$key]['rowid'] == $valuetoshow) {
2648 $valuetoshow = $form->cache_vatrates[$key]['label'];
2649 break;
2650 }
2651 }
2652 } elseif ($value == 'fk_c_exp_tax_cat') {
2653 $tmpid = $valuetoshow;
2654 $valuetoshow = getDictionaryValue('c_exp_tax_cat', 'label', $tmpid);
2655 $valuetoshow = $langs->trans($valuetoshow ? $valuetoshow : $tmpid);
2656 } elseif ($tabname[$id] == 'c_exp_tax_cat') {
2657 $valuetoshow = $langs->trans($valuetoshow);
2658 } elseif ($value == 'libelle' && ($tabname[$id] == 'c_stcomm' || $tabname[$id] == 'c_stcommcontact')) {
2659 $key = 'StatusProspect'.$obj->rowid;
2660 $trans = $langs->trans($key);
2661 $valuetoshow = ($trans != $key ? $trans : $obj->{$value});
2662 } elseif ($value == 'label' && $tabname[$id] == 'c_units') {
2663 $langs->load('other');
2664 $key = $langs->trans($obj->label);
2665 $valuetoshow = ($obj->label && $key != strtoupper($obj->label) ? $key : $obj->{$value});
2666 } elseif ($value == 'label' && $tabname[$id] == 'c_product_nature') {
2667 $langs->load("products");
2668 $valuetoshow = $langs->trans($obj->{$value});
2669 } elseif ($fieldlist[$field] == 'label' && $tabname[$id] == 'c_productbatch_qcstatus') {
2670 $langs->load("productbatch");
2671 $valuetoshow = $langs->trans($obj->{$value});
2672 } elseif ($value == 'block_if_negative') {
2673 $valuetoshow = yn($obj->{$value});
2674 } elseif ($value == 'icon') {
2675 $valuetoshow = $obj->{$value}." ".img_picto("", preg_replace('/^fa-/', '', $obj->{$value}));
2676 } elseif ($value == 'type_duration') {
2677 if (!empty($obj->{$value}) && array_key_exists($obj->{$value}, $TDurationTypes)) {
2678 $valuetoshow = $TDurationTypes[$obj->{$value}];
2679 }
2680 } elseif (in_array($value, array('leftmargin', 'topmargin', 'spacex', 'spacey', 'width', 'height', 'custom_x', 'custom_y'))) {
2681 $valuetoshow = price2num($valuetoshow);
2682 } elseif ($value == 'type' && $id == DICT_ACTIONCOMM && !empty($obj->module)) {
2683 $titletoshow = $langs->trans("Module").' '.$obj->module;
2684 } elseif ($value == 'color') {
2685 $valuetoshow = $formother->showColor($obj->{$value}, '');
2686 }
2687
2688
2689 // Now we define the CSS
2690 $class .= ($class ? ' ' : '').'tddict';
2691 if ($value == 'name') {
2692 $class .= ' tdoverflowmax200';
2693 }
2694 if ($value == 'note' && $id == DICT_TVA) {
2695 $class .= ' tdoverflowmax200';
2696 }
2697 if (in_array($value, array($value == 'tracking'))) {
2698 $class .= ' tdoverflowauto';
2699 }
2700 if (in_array($value, array('nbjour', 'decalage', 'pos', 'position', 'deposit_percent'))) {
2701 $class .= ' right';
2702 }
2703 if (in_array($value, array('icon', 'type_vat', 'localtax1_type', 'localtax2_type'))) {
2704 $class .= ' nowraponall';
2705 }
2706 if (in_array($value, array('use_default', 'fk_parent', 'sortorder', 'public'))) {
2707 $class .= ' center';
2708 }
2709 if (in_array($value, array('localtax1_type', 'localtax2_type', 'note', 'note_public', 'note_private'))) {
2710 $class .= ' small';
2711 }
2712
2713 // Add val as tooltip if there is a tdoverflow on the cell
2714 if (empty($titletoshow) && preg_match('/tdoverflow/', $class)) {
2715 $titletoshow = $valuetoshow;
2716 }
2717
2718 // Show value for field
2719 if ($showfield) {
2720 print '<!-- field value '. $value .' --><td class="'.$class.'"'.($titletoshow ? ' title="'.dolPrintHTMLForAttribute($titletoshow).'"' : '').'>'.$valuetoshow.'</td>';
2721 }
2722 }
2723
2724 // Favorite, EEC & Sepa
2725 // Only for country dictionary
2726 if ($id == DICT_COUNTRY) {
2727 print '<td class="nowraponall center">';
2728 // Is in EEC
2729 if ($iserasable) {
2730 print '<a class="reposition" href="'.$url.'action='.$acts[$obj->eec].'_eec&token='.newToken().'">'.$actl[$obj->eec].'</a>';
2731 } else {
2732 print '<span class="opacitymedium">'.$langs->trans("AlwaysActive").'</span>';
2733 }
2734 print '</td>';
2735 print '<td class="nowraponall center">';
2736 // Is in Sepa
2737 if ($iserasable) {
2738 print '<a class="reposition" href="'.$url.'action='.$acts[$obj->sepa].'_sepa&token='.newToken().'">'.$actl[$obj->sepa].'</a>';
2739 } else {
2740 print '<span class="opacitymedium">'.$langs->trans("AlwaysActive").'</span>';
2741 }
2742 print '</td>';
2743 print '<td class="nowraponall center">';
2744 // Favorite
2745 if ($iserasable) {
2746 print '<a class="reposition" href="'.$url.'action='.$acts[$obj->favorite].'_favorite&token='.newToken().'">'.$actl[$obj->favorite].'</a>';
2747 } else {
2748 print '<span class="opacitymedium">'.$langs->trans("AlwaysActive").'</span>';
2749 }
2750 print '</td>';
2751 }
2752 }
2753
2754 // Active
2755 print '<td class="nowraponall center">';
2756 if ($canbedisabled) {
2757 print '<a class="reposition" href="'.$url.'action='.$acts[$obj->active].'&token='.newToken().'">'.$actl[$obj->active].'</a>';
2758 } else {
2759 if (in_array($obj->code, array('AC_OTH', 'AC_OTH_AUTO'))) {
2760 print $langs->trans("AlwaysActive");
2761 } elseif (isset($obj->type) && in_array($obj->type, array('systemauto')) && empty($obj->active)) {
2762 print $langs->trans("Deprecated");
2763 } elseif (isset($obj->type) && in_array($obj->type, array('system')) && !empty($obj->active) && $obj->code != 'AC_OTH') {
2764 print $langs->trans("UsedOnlyWithTypeOption");
2765 } else {
2766 print '<span class="opacitymedium">'.$langs->trans("AlwaysActive").'</span>';
2767 }
2768 }
2769 print "</td>";
2770
2771 // Action button
2772 if (!$conf->main_checkbox_left_column) {
2773 print '<td class="center maxwidthsearch nowraponall">';
2774 // Modify link
2775 if ($canbemodified) {
2776 print '<a class="reposition marginleftonly paddingleft marginrightonly paddingright editfielda" href="'.$url.'action=edit&token='.newToken().'">'.img_edit().'</a>';
2777 }
2778 // Delete link
2779 if ($iserasable) {
2780 if ($user->admin) {
2781 print '<a class="reposition marginleftonly paddingleft marginrightonly paddingright" href="'.$url.'action=delete&token='.newToken().'">'.img_delete().'</a>';
2782 }
2783 }
2784 print '</td>';
2785 }
2786
2787 print "</tr>\n";
2788 }
2789 $i++;
2790 }
2791 } else {
2792 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
2793 }
2794
2795 print '</table>';
2796 print '</div>';
2797 } else {
2799 }
2800
2801 print '</form>';
2802} else {
2803 /*
2804 * Show list of dictionary to show
2805 */
2806 print load_fiche_titre($title, $linkback, $titlepicto);
2807
2808 print '<span class="opacitymedium">'.$langs->trans("DictionaryDesc");
2809 print " ".$langs->trans("OnlyActiveElementsAreShown")."<br>\n";
2810 print '</span><br>';
2811 print "<br>\n";
2812
2813 $lastlineisempty = false;
2814
2815 print '<div class="div-table-responsive-no-min">';
2816 print '<table class="noborder centpercent">';
2817 print '<tr class="liste_titre">';
2818 print '<td>'.$langs->trans("Dictionary").'</td>';
2819 print '<td></td>';
2820 print '<td class="hideonsmartphone"></td>';
2821 print '</tr>';
2822
2823 $showemptyline = '';
2824 foreach ($taborder as $i) {
2825 if (isset($tabname[$i]) && empty($tabcond[$i])) {
2826 continue;
2827 }
2828
2829 if ($i) {
2830 if ($showemptyline) {
2831 print '<tr class="oddeven"><td></td><td></td><td class="hideonsmartphone"></td></tr>';
2832 $showemptyline = 0;
2833 }
2834
2835
2836 $value = $tabname[$i];
2837 print '<tr class="oddeven"><td class="minwidth200">';
2838 if (!empty($tabcond[$i])) {
2839 $tabnamenoprefix = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabname[$i]);
2840 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$i;
2841 if ($i == DICT_CHARGESOCIALES) {
2842 print '&search_country_id='.$mysoc->country_id;
2843 }
2844 print '">';
2845 if (!empty($tabcomplete[$tabnamenoprefix]['picto'])) {
2846 print img_picto('', $tabcomplete[$tabnamenoprefix]['picto'], 'class="pictofixedwidth paddingrightonly"');
2847 }
2848 print $langs->trans($tablib[$i]);
2849 print '</a>';
2850 } else {
2851 print $langs->trans($tablib[$i]);
2852 }
2853 print '</td>';
2854 print '<td>';
2855 print '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?id='.$i.'">';
2856 print img_picto('Edit', 'edit', '');
2857 print '</a>';
2858 print '</td>';
2859 print '<td class="right hideonsmartphone">';
2860 print $form->textwithpicto('', $langs->trans("Table").': '.MAIN_DB_PREFIX.$tabname[$i]);
2861 print '</td>';
2862 print '</tr>';
2863 $lastlineisempty = false;
2864 } else {
2865 if (!$lastlineisempty) {
2866 $showemptyline = 1;
2867 $lastlineisempty = true;
2868 }
2869 }
2870 }
2871 print '</table>';
2872 print '</div>';
2873}
2874
2875print '<br>';
2876if (GETPOST('id') && GETPOST('id') == DICT_SOCIALNETWORKS) {
2877 print dol_get_fiche_end();
2878}
2879// End of page
2880llxFooter();
2881$db->close();
2882
2883
2893function dictFieldList($fieldlist, $obj = null, $tabname = '', $context = '')
2894{
2895 global $langs, $db, $mysoc;
2896 global $form, $formother;
2897 global $region_id;
2898 global $elementList, $sourceList, $localtax_typeList, $type_vatList;
2899
2900 $formadmin = new FormAdmin($db);
2901 $formcompany = new FormCompany($db);
2902 $formaccounting = new FormAccounting($db);
2903
2904 $withentity = '';
2905
2906 foreach ($fieldlist as $field => $value) {
2907 if ($value == 'entity' && isset($obj->$value)) {
2908 $withentity = $obj->$value;
2909 continue;
2910 }
2911
2912 if (in_array($value, array('code', 'libelle', 'type')) && $tabname == "c_actioncomm" && isset($obj->$value) && in_array($obj->type, array('system', 'systemauto'))) {
2913 // Special case for c_actioncomm (field that should not be modified)
2914 $hidden = (!empty($obj->{$value}) ? $obj->{$value} : '');
2915 print '<td>';
2916 print '<input type="hidden" name="'. $value .'" value="'.$hidden.'">';
2917 print $langs->trans($hidden);
2918 print '</td>';
2919 } elseif ($value == 'country') {
2920 if (in_array('region_id', $fieldlist)) {
2921 print '<td>';
2922 print '</td>';
2923 continue;
2924 } // For state page, we do not show the country input (we link to region, not country)
2925 print '<td>';
2926
2927 $selected = (!empty($obj->country_code) ? $obj->country_code : (!empty($obj->country) ? $obj->country : ''));
2928 if (!GETPOSTISSET('code')) {
2929 $selected = GETPOST('countryidforinsert');
2930 }
2931 print $form->select_country($selected, $value, '', 28, 'minwidth100 maxwidth150 maxwidthonsmartphone');
2932 print '</td>';
2933 } elseif ($value == 'country_id') {
2934 if (!in_array('country', $fieldlist)) { // If there is already a field country, we don't show country_id (avoid duplicate)
2935 $country_id = (!empty($obj->{$value}) ? $obj->{$value} : 0);
2936 print '<td class="tdoverflowmax100">';
2937 print '<input type="hidden" name="'. $value .'" value="'.$country_id.'">';
2938 print '</td>';
2939 }
2940 } elseif ($value == 'region') {
2941 print '<td>';
2942 $formcompany->select_region($region_id, 'region');
2943 print '</td>';
2944 } elseif ($value == 'region_id') {
2945 $region_id = (!empty($obj->{$value}) ? $obj->{$value} : 0);
2946 print '<td>';
2947 print '<input type="hidden" name="'. $value .'" value="'.$region_id.'">';
2948 print '</td>';
2949 } elseif ($value == 'department_buyer') {
2950 if ($context == 'edit') {
2951 print '<td class="nowraponall">';
2952 // show department buyer list
2953 $country_code = (!empty($obj->country_code) ? $obj->country_code : '');
2954 $department_buyer_id = (!empty($obj->department_buyer_id) ? (int) $obj->department_buyer_id : 0);
2955 if ($country_code != '') {
2956 print $formcompany->select_state($department_buyer_id, $country_code, 'department_buyer_id', 'minwidth100 maxwidth150 maxwidthonsmartphone');
2957 }
2958 print '</td>';
2959 }
2960 } elseif ($value == 'department_buyer_id') {
2961 if (!in_array('department_buyer', $fieldlist)) { // If there is already a field department buyer, we don't show department buyer id (avoid duplicate)
2962 $department_buyer_id = (!empty($obj->{$value}) ? $obj->{$value} : 0);
2963 print '<td class="tdoverflowmax100">';
2964 print '<input type="hidden" name="'.$value.'" value="'.$department_buyer_id.'">';
2965 print '</td>';
2966 }
2967 } elseif ($value == 'lang') {
2968 print '<td>';
2969 print $formadmin->select_language(getDolGlobalString('MAIN_LANG_DEFAULT'), 'lang');
2970 print '</td>';
2971 } elseif (in_array($value, array('element', 'source'))) { // Example: the type and source of the element (for contact types)
2972 $tmparray = array();
2973 if ($value == 'element') {
2974 $tmparray = $elementList;
2975 } else {
2976 $tmparray = $sourceList;
2977 }
2978 print '<td>';
2979 print $form->selectarray($value, $tmparray, (!empty($obj->{$value}) ? $obj->{$value} : ''), 0, 0, 0, '', 0, 0, 0, '', 'maxwidth250');
2980 print '</td>';
2981 } elseif (in_array($value, array('public', 'use_default'))) {
2982 // Fields 0/1 with a combo select Yes/No
2983 print '<td class="center">';
2984 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
2985 print $form->selectyesno($value, (!empty($obj->{$value}) ? $obj->{$value} : ''), 1);
2986 print '</td>';
2987 } elseif ($value == 'private') {
2988 // Fields 'no'/'yes' with a combo select Yes/No
2989 print '<td>';
2990 print $form->selectyesno("private", (!empty($obj->{$value}) ? $obj->{$value} : ''));
2991 print '</td>';
2992 } elseif ($value == 'type' && $tabname == "c_actioncomm") {
2993 $type = (!empty($obj->type) ? $obj->type : 'user'); // Check if type is different of 'user' (external module)
2994 print '<td>';
2995 print $type.'<input type="hidden" name="type" value="'.$type.'">';
2996 print '</td>';
2997 } elseif ($value == 'type' && $tabname == 'c_paiement') {
2998 print '<td>';
2999 $select_list = array(0 => $langs->trans('PaymentTypeCustomer'), 1 => $langs->trans('PaymentTypeSupplier'), 2 => $langs->trans('PaymentTypeBoth'));
3000 // Use isset(), not !empty(), because 0 (Customer) is a valid value that empty() would treat as unset
3001 print $form->selectarray($value, $select_list, (isset($obj->{$value}) && $obj->{$value} !== '' ? $obj->{$value} : '2'));
3002 print '</td>';
3003 } elseif ($value == 'recuperableonly' || $value == 'type_cdr' || $value == 'deductible' || $value == 'category_type') {
3004 if ($value == 'type_cdr') {
3005 print '<td class="center">';
3006 } else {
3007 print '<td>';
3008 }
3009 if ($value == 'type_cdr') {
3010 print $form->selectarray($value, array(0 => $langs->trans('None'), 1 => $langs->trans('AtEndOfMonth'), 2 => $langs->trans('CurrentNext')), (!empty($obj->{$value}) ? $obj->{$value} : ''));
3011 } else {
3012 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
3013 print $form->selectyesno($value, (!empty($obj->{$value}) ? $obj->{$value} : ''), 1);
3014 }
3015 print '</td>';
3016 } elseif (in_array($value, array('nbjour', 'decalage', 'taux', 'localtax1', 'localtax2'))) {
3017 $class = "right";
3018 if (in_array($value, array('taux', 'localtax1', 'localtax2'))) {
3019 $class = "center"; // Fields aligned on right
3020 }
3021 print '<td class="'.$class.'">';
3022 print '<input type="text" class="flat" value="'.(isset($obj->{$value}) ? $obj->{$value} : '').'" size="3" name="'. $value .'">';
3023 print '</td>';
3024 } elseif (in_array($value, array('libelle_facture', 'content'))) {
3025 print '<td>';
3026 $transfound = 0;
3027 $transkey = '';
3028 // Special case for labels
3029 if ($tabname == 'c_payment_term') {
3030 $langs->load("bills");
3031 if (isset($obj->code) && !empty($obj->code)) {
3032 $transkey = "PaymentCondition" . strtoupper($obj->code);
3033 if ($langs->trans($transkey) != $transkey) {
3034 $transfound = 1;
3035 print $form->textwithpicto($langs->trans($transkey), $langs->trans("GoIntoTranslationMenuToChangeThis"));
3036 }
3037 }
3038 }
3039 if (!$transfound) {
3040 print '<textarea cols="30" rows="'.ROWS_2.'" class="flat" name="'. $value .'">'.(empty($obj->{$value}) ? '' : $obj->{$value}).'</textarea>';
3041 } else {
3042 print '<input type="hidden" name="'. $value .'" value="'.$transkey.'">';
3043 }
3044 print '</td>';
3045 } elseif ($value == 'price' || preg_match('/^amount/i', (string) $value)) {
3046 print '<td><input type="text" class="flat minwidth75" value="'.price((!empty($obj->{$value}) ? $obj->{$value} : '')).'" name="'. $value .'"></td>';
3047 } elseif ($value == 'code' && isset($obj->{$value})) {
3048 print '<td>';
3049 if ($tabname == 'c_paiement' && in_array($obj->{$value}, array('LIQ', 'CB', 'CHQ', 'VIR'))) {
3050 // Case of code that should not be modified
3051 print '<input type="hidden" class="flat minwidth75 maxwidth100" value="'.(empty($obj->{$value}) ? '' : $obj->{$value}).'" name="'. $value .'">';
3052 print $obj->{$value};
3053 } else {
3054 print '<input type="text" class="flat minwidth75 maxwidth100" value="'.(empty($obj->{$value}) ? '' : $obj->{$value}).'" name="'. $value .'">';
3055 }
3056 print '</td>';
3057 } elseif ($value == 'unit') {
3058 print '<td>';
3059 $units = array(
3060 'mm' => $langs->trans('SizeUnitmm'),
3061 'cm' => $langs->trans('SizeUnitcm'),
3062 'point' => $langs->trans('SizeUnitpoint'),
3063 'inch' => $langs->trans('SizeUnitinch')
3064 );
3065 print $form->selectarray('unit', $units, (empty($obj->{$value}) ? '' : $obj->{$value}), 0, 0, 0);
3066 print '</td>';
3067 } elseif ($value == 'type_vat') {
3068 // VAT type 0: all, 1: sell, 2: purchase
3069 print '<td class="center">';
3070 print $form->selectarray($value, $type_vatList, (empty($obj->{$value}) ? '0' : $obj->{$value}));
3071 print '</td>';
3072 } elseif ($value == 'localtax1_type' || $value == 'localtax2_type') {
3073 // Le type de taxe locale
3074 print '<td class="center">';
3075 print $form->selectarray($value, $localtax_typeList, (empty($obj->{$value}) ? '' : $obj->{$value}));
3076 print '</td>';
3077 } elseif ($value == 'accountancy_code' || $value == 'accountancy_code_sell' || $value == 'accountancy_code_buy') {
3078 print '<td>';
3079 if (isModEnabled('accounting')) {
3080 $fieldname = $value;
3081 $accountancy_account = (empty($obj->$fieldname) ? 0 : $obj->$fieldname);
3082 print $formaccounting->select_account($accountancy_account, '.'. $value, 1, array(), 1, 1, 'maxwidth125 maxwidthonsmartphone');
3083 } else {
3084 $fieldname = $value;
3085 print '<input type="text" class="flat minwidth100" value="'.(isset($obj->$fieldname) ? $obj->$fieldname : '').'" name="'. $value .'">';
3086 }
3087 print '</td>';
3088 } elseif ($value == 'fk_tva') {
3089 print '<td>';
3090 print $form->load_tva('fk_tva', $obj->taux, $mysoc, new Societe($db), 0, 0, '', false, -1);
3091 print '</td>';
3092 } elseif ($value == 'fk_c_exp_tax_cat') {
3093 print '<td>';
3094 print $form->selectExpenseCategories($obj->fk_c_exp_tax_cat);
3095 print '</td>';
3096 } elseif ($value == 'fk_range') {
3097 print '<td>';
3098 print $form->selectExpenseRanges($obj->fk_range);
3099 print '</td>';
3100 } elseif ($value == 'block_if_negative') {
3101 print '<td>';
3102 print $form->selectyesno("block_if_negative", (empty($obj->block_if_negative) ? '' : $obj->block_if_negative), 1);
3103 print '</td>';
3104 } elseif ($value == 'type_duration') {
3105 print '<td>';
3106 print $form->selectTypeDuration('', (empty($obj->type_duration) ? '' : $obj->type_duration), ['s', 'i', 'h']);
3107 print '</td>';
3108 } elseif ($value == 'color') {
3109 print '<td>';
3110 print $formother->selectColor((empty($obj->{$value}) ? '' : $obj->{$value}), 'color');
3111 print '</td>';
3112 } else {
3113 $fieldValue = isset($obj->{$value}) ? $obj->{$value} : '';
3114 $classtd = '';
3115 $class = '';
3116
3117 if ($value == 'sortorder') {
3118 $fieldlist[$field] = 'position';
3119 }
3120
3121 if ($fieldlist[$field] == 'code') {
3122 $class = 'maxwidth100';
3123 }
3124 if (in_array($fieldlist[$field], array('deposit_percent'))) {
3125 $classtd = 'right';
3126 $class = 'maxwidth50 right';
3127 }
3128 if (in_array($fieldlist[$field], array('pos', 'position'))) {
3129 $classtd = 'right';
3130 $class = 'maxwidth50 right';
3131 }
3132 if (in_array($fieldlist[$field], array('dayrule', 'day', 'month', 'year', 'use_default', 'affect', 'delay', 'public', 'sortorder', 'sens', 'category_type', 'fk_parent'))) {
3133 $class = 'maxwidth50 center';
3134 }
3135 if (in_array($fieldlist[$field], array('use_default', 'public', 'fk_parent'))) {
3136 $classtd = 'center';
3137 }
3138 if (in_array($fieldlist[$field], array('libelle', 'label', 'tracking'))) {
3139 $class = 'quatrevingtpercent';
3140 }
3141 // Fields that must be suggested as '0' instead of ''
3142 if ($fieldlist[$field] == 'fk_parent') {
3143 if (empty($fieldValue)) {
3144 $fieldValue = '0';
3145 }
3146 }
3147
3148 // Labels Length
3149 $maxlength = '';
3150 if (in_array($fieldlist[$field], array('libelle', 'label'))) {
3151 switch ($tabname) {
3152 case 'c_ecotaxe':
3153 case 'c_email_senderprofile':
3154 case 'c_forme_juridique':
3155 case 'c_holiday_types':
3156 case 'c_payment_term':
3157 case 'c_transport_mode':
3158 $maxlength = ' maxlength="255"';
3159 break;
3160 case 'c_email_templates':
3161 $maxlength = ' maxlength="180"';
3162 break;
3163 case 'c_socialnetworks':
3164 $maxlength = ' maxlength="150"';
3165 break;
3166 default:
3167 $maxlength = ' maxlength="128"';
3168 }
3169 }
3170
3171 print '<td class="'.$classtd.'">';
3172 $transfound = 0;
3173 $transkey = '';
3174 if (in_array($fieldlist[$field], array('label', 'libelle'))) { // For label
3175 // Special case for labels
3176 if ($tabname == 'c_civility' && !empty($obj->code)) {
3177 $transkey = "Civility".strtoupper($obj->code);
3178 }
3179 if ($tabname == 'c_payment_term' && !empty($obj->code)) {
3180 $langs->load("bills");
3181 $transkey = "PaymentConditionShort".strtoupper($obj->code);
3182 }
3183 if ($transkey && $langs->trans($transkey) != $transkey) {
3184 $transfound = 1;
3185 print $form->textwithpicto($langs->trans($transkey), $langs->trans("GoIntoTranslationMenuToChangeThis"));
3186 }
3187 }
3188 if (!$transfound) {
3189 print '<input type="text" class="flat'.($class ? ' '.$class : '').'"'.($maxlength ? ' '.$maxlength : '').' value="'.dol_escape_htmltag($fieldValue).'" name="'.$fieldlist[$field].'">';
3190 } else {
3191 print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$transkey.'">';
3192 }
3193 print '</td>';
3194 }
3195 }
3196
3197 return $withentity;
3198}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage accounting accounts.
Class to manage generation of HTML components for accounting management.
Class to generate html code for admin pages.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Class to help generate other html components Only common components are here.
Class to manage third parties objects (customers, suppliers, prospects...)
global $mysoc
dictFieldList($fieldlist, $obj=null, $tabname='', $context='')
Show fields in insert/edit mode.
Definition dict.php:2893
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:519
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:717
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
Definition html.lib.php:172
$context
@method int call_trigger(string $triggerName, ?User $user)
Definition logout.php:42
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:130
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.