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