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