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