1
|
|
|
<?php
|
2
|
|
|
/* Copyright (c) 2002-2007 Rodolphe Quiedeville <[email protected]>
|
3
|
|
|
* Copyright (C) 2004-2012 Laurent Destailleur <[email protected]>
|
4
|
|
|
* Copyright (C) 2004 Benoit Mortier <[email protected]>
|
5
|
|
|
* Copyright (C) 2004 Sebastien Di Cintio <[email protected]>
|
6
|
|
|
* Copyright (C) 2004 Eric Seigne <[email protected]>
|
7
|
|
|
* Copyright (C) 2005-2012 Regis Houssin <[email protected]>
|
8
|
|
|
* Copyright (C) 2006 Andre Cianfarani <[email protected]>
|
9
|
|
|
* Copyright (C) 2006 Marc Barilley/Ocebo <[email protected]>
|
10
|
|
|
* Copyright (C) 2007 Franky Van Liedekerke <[email protected]>
|
11
|
|
|
* Copyright (C) 2007 Patrick Raguin <[email protected]>
|
12
|
|
|
*
|
13
|
|
|
* This program is free software; you can redistribute it and/or modify
|
14
|
|
|
* it under the terms of the GNU General Public License as published by
|
15
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
16
|
|
|
* (at your option) any later version.
|
17
|
|
|
*
|
18
|
|
|
* This program is distributed in the hope that it will be useful,
|
19
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21
|
|
|
* GNU General Public License for more details.
|
22
|
|
|
*
|
23
|
|
|
* You should have received a copy of the GNU General Public License
|
24
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25
|
|
|
*/
|
26
|
|
|
namespace Alixar\Base;
|
27
|
|
|
|
28
|
|
|
/**
|
29
|
|
|
* \file htdocs/core/class/html.formother.class.php
|
30
|
|
|
* \ingroup core
|
31
|
|
|
* \brief Fichier de la classe des fonctions predefinie de composants html autre
|
32
|
|
|
*/
|
33
|
|
|
|
34
|
|
|
|
35
|
|
|
/**
|
36
|
|
|
* Classe permettant la generation de composants html autre
|
37
|
|
|
* Only common components are here.
|
38
|
|
|
*/
|
39
|
|
|
class FormOther
|
40
|
|
|
{
|
41
|
|
|
// private $db;
|
42
|
|
|
|
43
|
|
|
/**
|
44
|
|
|
* @var string Error code (or message)
|
45
|
|
|
*/
|
46
|
|
|
public $error;
|
47
|
|
|
|
48
|
|
|
|
49
|
|
|
/**
|
50
|
|
|
* Constructor
|
51
|
|
|
*
|
52
|
|
|
* @param DoliDB $db Database handler
|
|
|
|
|
53
|
|
|
*/
|
54
|
|
|
function __construct()
|
55
|
|
|
{
|
56
|
|
|
// $this->db = $db;
|
57
|
|
|
}
|
58
|
|
|
|
59
|
|
|
|
60
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
|
61
|
|
|
/**
|
62
|
|
|
* Return HTML select list of export models
|
63
|
|
|
*
|
64
|
|
|
* @param string $selected Id modele pre-selectionne
|
65
|
|
|
* @param string $htmlname Nom de la zone select
|
66
|
|
|
* @param string $type Type des modeles recherches
|
67
|
|
|
* @param int $useempty Affiche valeur vide dans liste
|
68
|
|
|
* @param int $fk_user Utilisateur créant le modèle
|
69
|
|
|
* @return void
|
70
|
|
|
*/
|
71
|
|
|
function select_export_model($selected='', $htmlname='exportmodelid', $type='', $useempty=0, $fk_user=null)
|
72
|
|
|
{
|
73
|
|
|
// phpcs:enable
|
74
|
|
|
$sql = "SELECT rowid, label";
|
75
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."export_model";
|
76
|
|
|
$sql.= " WHERE type = '".$type."'";
|
77
|
|
|
if (!empty($fk_user)) $sql.=" AND fk_user=".$fk_user;
|
78
|
|
|
$sql.= " ORDER BY rowid";
|
79
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
80
|
|
|
if ($result)
|
81
|
|
|
{
|
82
|
|
|
print '<select class="flat minwidth200" name="'.$htmlname.'">';
|
83
|
|
|
if ($useempty)
|
84
|
|
|
{
|
85
|
|
|
print '<option value="-1"> </option>';
|
86
|
|
|
}
|
87
|
|
|
|
88
|
|
|
$num = $this->db->num_rows($result);
|
89
|
|
|
$i = 0;
|
90
|
|
|
while ($i < $num)
|
91
|
|
|
{
|
92
|
|
|
$obj = $this->db->fetch_object($result);
|
93
|
|
|
if ($selected == $obj->rowid)
|
94
|
|
|
{
|
95
|
|
|
print '<option value="'.$obj->rowid.'" selected>';
|
96
|
|
|
}
|
97
|
|
|
else
|
98
|
|
|
{
|
99
|
|
|
print '<option value="'.$obj->rowid.'">';
|
100
|
|
|
}
|
101
|
|
|
print $obj->label;
|
102
|
|
|
print '</option>';
|
103
|
|
|
$i++;
|
104
|
|
|
}
|
105
|
|
|
print "</select>";
|
106
|
|
|
}
|
107
|
|
|
else {
|
108
|
|
|
dol_print_error($this->db);
|
109
|
|
|
}
|
110
|
|
|
}
|
111
|
|
|
|
112
|
|
|
|
113
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
|
114
|
|
|
/**
|
115
|
|
|
* Return list of export models
|
116
|
|
|
*
|
117
|
|
|
* @param string $selected Id modele pre-selectionne
|
118
|
|
|
* @param string $htmlname Nom de la zone select
|
119
|
|
|
* @param string $type Type des modeles recherches
|
120
|
|
|
* @param int $useempty Affiche valeur vide dans liste
|
121
|
|
|
* @return void
|
122
|
|
|
*/
|
123
|
|
|
function select_import_model($selected='', $htmlname='importmodelid', $type='', $useempty=0)
|
124
|
|
|
{
|
125
|
|
|
// phpcs:enable
|
126
|
|
|
$sql = "SELECT rowid, label";
|
127
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."import_model";
|
128
|
|
|
$sql.= " WHERE type = '".$type."'";
|
129
|
|
|
$sql.= " ORDER BY rowid";
|
130
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
131
|
|
|
if ($result)
|
132
|
|
|
{
|
133
|
|
|
print '<select class="flat minwidth200" name="'.$htmlname.'">';
|
134
|
|
|
if ($useempty)
|
135
|
|
|
{
|
136
|
|
|
print '<option value="-1"> </option>';
|
137
|
|
|
}
|
138
|
|
|
|
139
|
|
|
$num = $this->db->num_rows($result);
|
140
|
|
|
$i = 0;
|
141
|
|
|
while ($i < $num)
|
142
|
|
|
{
|
143
|
|
|
$obj = $this->db->fetch_object($result);
|
144
|
|
|
if ($selected == $obj->rowid)
|
145
|
|
|
{
|
146
|
|
|
print '<option value="'.$obj->rowid.'" selected>';
|
147
|
|
|
}
|
148
|
|
|
else
|
149
|
|
|
{
|
150
|
|
|
print '<option value="'.$obj->rowid.'">';
|
151
|
|
|
}
|
152
|
|
|
print $obj->label;
|
153
|
|
|
print '</option>';
|
154
|
|
|
$i++;
|
155
|
|
|
}
|
156
|
|
|
print "</select>";
|
157
|
|
|
}
|
158
|
|
|
else {
|
159
|
|
|
dol_print_error($this->db);
|
160
|
|
|
}
|
161
|
|
|
}
|
162
|
|
|
|
163
|
|
|
|
164
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
|
165
|
|
|
/**
|
166
|
|
|
* Return list of ecotaxes with label
|
167
|
|
|
*
|
168
|
|
|
* @param string $selected Preselected ecotaxes
|
169
|
|
|
* @param string $htmlname Name of combo list
|
170
|
|
|
* @return integer
|
171
|
|
|
*/
|
172
|
|
|
function select_ecotaxes($selected='', $htmlname='ecotaxe_id')
|
173
|
|
|
{
|
174
|
|
|
// phpcs:enable
|
175
|
|
|
global $langs;
|
176
|
|
|
|
177
|
|
|
$sql = "SELECT e.rowid, e.code, e.label, e.price, e.organization,";
|
178
|
|
|
$sql.= " c.label as country";
|
179
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."c_ecotaxe as e,".MAIN_DB_PREFIX."c_country as c";
|
180
|
|
|
$sql.= " WHERE e.active = 1 AND e.fk_pays = c.rowid";
|
181
|
|
|
$sql.= " ORDER BY country, e.organization ASC, e.code ASC";
|
182
|
|
|
|
183
|
|
|
dol_syslog(get_class($this).'::select_ecotaxes', LOG_DEBUG);
|
184
|
|
|
$resql=$this->db->query($sql);
|
|
|
|
|
185
|
|
|
if ($resql)
|
186
|
|
|
{
|
187
|
|
|
print '<select class="flat" name="'.$htmlname.'">';
|
188
|
|
|
$num = $this->db->num_rows($resql);
|
189
|
|
|
$i = 0;
|
190
|
|
|
print '<option value="-1"> </option>'."\n";
|
191
|
|
|
if ($num)
|
192
|
|
|
{
|
193
|
|
|
while ($i < $num)
|
194
|
|
|
{
|
195
|
|
|
$obj = $this->db->fetch_object($resql);
|
196
|
|
|
if ($selected && $selected == $obj->rowid)
|
197
|
|
|
{
|
198
|
|
|
print '<option value="'.$obj->rowid.'" selected>';
|
199
|
|
|
}
|
200
|
|
|
else
|
201
|
|
|
{
|
202
|
|
|
print '<option value="'.$obj->rowid.'">';
|
203
|
|
|
//print '<option onmouseover="showtip(\''.$obj->label.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
|
204
|
|
|
}
|
205
|
|
|
$selectOptionValue = $obj->code.' - '.$obj->label.' : '.price($obj->price).' '.$langs->trans("HT").' ('.$obj->organization.')';
|
206
|
|
|
print $selectOptionValue;
|
207
|
|
|
print '</option>';
|
208
|
|
|
$i++;
|
209
|
|
|
}
|
210
|
|
|
}
|
211
|
|
|
print '</select>';
|
212
|
|
|
return 0;
|
213
|
|
|
}
|
214
|
|
|
else
|
215
|
|
|
{
|
216
|
|
|
dol_print_error($this->db);
|
217
|
|
|
return 1;
|
218
|
|
|
}
|
219
|
|
|
}
|
220
|
|
|
|
221
|
|
|
|
222
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
|
223
|
|
|
/**
|
224
|
|
|
* Return list of revenue stamp for country
|
225
|
|
|
*
|
226
|
|
|
* @param string $selected Value of preselected revenue stamp
|
227
|
|
|
* @param string $htmlname Name of combo list
|
228
|
|
|
* @param string $country_code Country Code
|
229
|
|
|
* @return string HTML select list
|
230
|
|
|
*/
|
231
|
|
|
function select_revenue_stamp($selected='', $htmlname='revenuestamp', $country_code='')
|
232
|
|
|
{
|
233
|
|
|
// phpcs:enable
|
234
|
|
|
global $langs;
|
235
|
|
|
|
236
|
|
|
$out='';
|
237
|
|
|
|
238
|
|
|
$sql = "SELECT r.taux, r.revenuestamp_type";
|
239
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."c_revenuestamp as r,".MAIN_DB_PREFIX."c_country as c";
|
240
|
|
|
$sql.= " WHERE r.active = 1 AND r.fk_pays = c.rowid";
|
241
|
|
|
$sql.= " AND c.code = '".$country_code."'";
|
242
|
|
|
|
243
|
|
|
dol_syslog(get_class($this).'::select_revenue_stamp', LOG_DEBUG);
|
244
|
|
|
$resql=$this->db->query($sql);
|
|
|
|
|
245
|
|
|
if ($resql)
|
246
|
|
|
{
|
247
|
|
|
$out.='<select class="flat" name="'.$htmlname.'">';
|
248
|
|
|
$num = $this->db->num_rows($resql);
|
249
|
|
|
$i = 0;
|
250
|
|
|
$out.='<option value="0"> </option>'."\n";
|
251
|
|
|
if ($num)
|
252
|
|
|
{
|
253
|
|
|
while ($i < $num)
|
254
|
|
|
{
|
255
|
|
|
$obj = $this->db->fetch_object($resql);
|
256
|
|
|
if (($selected && $selected == $obj->taux) || $num == 1)
|
257
|
|
|
{
|
258
|
|
|
$out.='<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').' selected>';
|
259
|
|
|
}
|
260
|
|
|
else
|
261
|
|
|
{
|
262
|
|
|
$out.='<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').'>';
|
263
|
|
|
//print '<option onmouseover="showtip(\''.$obj->libelle.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
|
264
|
|
|
}
|
265
|
|
|
$out.=$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '');
|
266
|
|
|
$out.='</option>';
|
267
|
|
|
$i++;
|
268
|
|
|
}
|
269
|
|
|
}
|
270
|
|
|
$out.='</select>';
|
271
|
|
|
return $out;
|
272
|
|
|
}
|
273
|
|
|
else
|
274
|
|
|
{
|
275
|
|
|
dol_print_error($this->db);
|
276
|
|
|
return '';
|
277
|
|
|
}
|
278
|
|
|
}
|
279
|
|
|
|
280
|
|
|
|
281
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
|
282
|
|
|
/**
|
283
|
|
|
* Return a HTML select list to select a percent
|
284
|
|
|
*
|
285
|
|
|
* @param integer $selected pourcentage pre-selectionne
|
286
|
|
|
* @param string $htmlname nom de la liste deroulante
|
287
|
|
|
* @param int $disabled Disabled or not
|
288
|
|
|
* @param int $increment increment value
|
289
|
|
|
* @param int $start start value
|
290
|
|
|
* @param int $end end value
|
291
|
|
|
* @param int $showempty Add also an empty line
|
292
|
|
|
* @return string HTML select string
|
293
|
|
|
*/
|
294
|
|
|
function select_percent($selected=0,$htmlname='percent',$disabled=0,$increment=5,$start=0,$end=100,$showempty=0)
|
295
|
|
|
{
|
296
|
|
|
// phpcs:enable
|
297
|
|
|
$return = '<select class="flat" name="'.$htmlname.'" '.($disabled?'disabled':'').'>';
|
298
|
|
|
if ($showempty) $return.='<option value="-1"'.(($selected == -1 || $selected == '')?' selected':'').'> </option>';
|
299
|
|
|
|
300
|
|
|
for ($i = $start ; $i <= $end ; $i += $increment)
|
301
|
|
|
{
|
302
|
|
|
if ($selected != '' && (int) $selected == $i)
|
303
|
|
|
{
|
304
|
|
|
$return.= '<option value="'.$i.'" selected>';
|
305
|
|
|
}
|
306
|
|
|
else
|
307
|
|
|
{
|
308
|
|
|
$return.= '<option value="'.$i.'">';
|
309
|
|
|
}
|
310
|
|
|
$return.= $i.' % ';
|
311
|
|
|
$return.= '</option>';
|
312
|
|
|
}
|
313
|
|
|
|
314
|
|
|
$return.= '</select>';
|
315
|
|
|
|
316
|
|
|
return $return;
|
317
|
|
|
}
|
318
|
|
|
|
319
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
|
320
|
|
|
/**
|
321
|
|
|
* Return select list for categories (to use in form search selectors)
|
322
|
|
|
*
|
323
|
|
|
* @param int $type Type of category ('customer', 'supplier', 'contact', 'product', 'member'). Old mode (0, 1, 2, ...) is deprecated.
|
324
|
|
|
* @param integer $selected Preselected value
|
325
|
|
|
* @param string $htmlname Name of combo list
|
326
|
|
|
* @param int $nocateg Show also an entry "Not categorized"
|
327
|
|
|
* @param int $showempty Add also an empty line
|
328
|
|
|
* @param string $morecss More CSS
|
329
|
|
|
* @return string Html combo list code
|
330
|
|
|
* @see select_all_categories
|
331
|
|
|
*/
|
332
|
|
|
function select_categories($type, $selected=0, $htmlname='search_categ', $nocateg=0, $showempty=1, $morecss='')
|
333
|
|
|
{
|
334
|
|
|
// phpcs:enable
|
335
|
|
|
global $conf, $langs;
|
336
|
|
|
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
|
337
|
|
|
|
338
|
|
|
// For backward compatibility
|
339
|
|
|
if (is_numeric($type))
|
340
|
|
|
{
|
341
|
|
|
dol_syslog(__METHOD__ . ': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING);
|
342
|
|
|
}
|
343
|
|
|
|
344
|
|
|
// Load list of "categories"
|
345
|
|
|
$static_categs = new Categorie($this->db);
|
|
|
|
|
346
|
|
|
$tab_categs = $static_categs->get_full_arbo($type);
|
347
|
|
|
|
348
|
|
|
$moreforfilter = '';
|
349
|
|
|
// Enhance with select2
|
350
|
|
|
if ($conf->use_javascript_ajax)
|
351
|
|
|
{
|
352
|
|
|
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
|
353
|
|
|
$comboenhancement = ajax_combobox('select_categ_'.$htmlname);
|
354
|
|
|
$moreforfilter.=$comboenhancement;
|
355
|
|
|
}
|
356
|
|
|
|
357
|
|
|
// Print a select with each of them
|
358
|
|
|
$moreforfilter.='<select class="flat minwidth100'.($morecss?' '.$morecss:'').'" id="select_categ_'.$htmlname.'" name="'.$htmlname.'">';
|
359
|
|
|
if ($showempty) $moreforfilter.='<option value="0"> </option>'; // Should use -1 to say nothing
|
360
|
|
|
|
361
|
|
|
if (is_array($tab_categs))
|
362
|
|
|
{
|
363
|
|
|
foreach ($tab_categs as $categ)
|
364
|
|
|
{
|
365
|
|
|
$moreforfilter.='<option value="'.$categ['id'].'"';
|
366
|
|
|
if ($categ['id'] == $selected) $moreforfilter.=' selected';
|
367
|
|
|
$moreforfilter.='>'.dol_trunc($categ['fulllabel'],50,'middle').'</option>';
|
368
|
|
|
}
|
369
|
|
|
}
|
370
|
|
|
if ($nocateg)
|
371
|
|
|
{
|
372
|
|
|
$langs->load("categories");
|
373
|
|
|
$moreforfilter.='<option value="-2"'.($selected == -2 ? ' selected':'').'>- '.$langs->trans("NotCategorized").' -</option>';
|
374
|
|
|
}
|
375
|
|
|
$moreforfilter.='</select>';
|
376
|
|
|
|
377
|
|
|
return $moreforfilter;
|
378
|
|
|
}
|
379
|
|
|
|
380
|
|
|
|
381
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
|
382
|
|
|
/**
|
383
|
|
|
* Return select list for categories (to use in form search selectors)
|
384
|
|
|
*
|
385
|
|
|
* @param string $selected Preselected value
|
386
|
|
|
* @param string $htmlname Name of combo list (example: 'search_sale')
|
387
|
|
|
* @param User $user Object user
|
388
|
|
|
* @param int $showstatus 0=show user status only if status is disabled, 1=always show user status into label, -1=never show user status
|
389
|
|
|
* @param int $showempty 1=show also an empty value
|
390
|
|
|
* @param string $morecss More CSS
|
391
|
|
|
* @return string Html combo list code
|
392
|
|
|
*/
|
393
|
|
|
function select_salesrepresentatives($selected,$htmlname,$user,$showstatus=0,$showempty=1,$morecss='')
|
394
|
|
|
{
|
395
|
|
|
// phpcs:enable
|
396
|
|
|
global $conf,$langs;
|
397
|
|
|
$langs->load('users');
|
398
|
|
|
|
399
|
|
|
$out = '';
|
400
|
|
|
// Enhance with select2
|
401
|
|
|
if ($conf->use_javascript_ajax)
|
402
|
|
|
{
|
403
|
|
|
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
|
404
|
|
|
|
405
|
|
|
$comboenhancement = ajax_combobox($htmlname);
|
406
|
|
|
if ($comboenhancement)
|
407
|
|
|
{
|
408
|
|
|
$out.=$comboenhancement;
|
409
|
|
|
}
|
410
|
|
|
}
|
411
|
|
|
// Select each sales and print them in a select input
|
412
|
|
|
$out.='<select class="flat'.($morecss?' '.$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'">';
|
413
|
|
|
if ($showempty) $out.='<option value="0"> </option>';
|
414
|
|
|
|
415
|
|
|
// Get list of users allowed to be viewed
|
416
|
|
|
$sql_usr = "SELECT u.rowid, u.lastname, u.firstname, u.statut, u.login";
|
417
|
|
|
$sql_usr.= " FROM ".MAIN_DB_PREFIX."user as u";
|
418
|
|
|
$sql_usr.= " WHERE u.entity IN (0,".$conf->entity.")";
|
419
|
|
|
if (empty($user->rights->user->user->lire)) $sql_usr.=" AND u.rowid = ".$user->id;
|
420
|
|
|
if (! empty($user->societe_id)) $sql_usr.=" AND u.fk_soc = ".$user->societe_id;
|
421
|
|
|
// Add existing sales representatives of thirdparty of external user
|
422
|
|
|
if (empty($user->rights->user->user->lire) && $user->societe_id)
|
423
|
|
|
{
|
424
|
|
|
$sql_usr.=" UNION ";
|
425
|
|
|
$sql_usr.= "SELECT u2.rowid, u2.lastname, u2.firstname, u2.statut, u2.login";
|
426
|
|
|
$sql_usr.= " FROM ".MAIN_DB_PREFIX."user as u2, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
427
|
|
|
$sql_usr.= " WHERE u2.entity IN (0,".$conf->entity.")";
|
428
|
|
|
$sql_usr.= " AND u2.rowid = sc.fk_user AND sc.fk_soc=".$user->societe_id;
|
429
|
|
|
}
|
430
|
|
|
$sql_usr.= " ORDER BY statut DESC, lastname ASC"; // Do not use 'ORDER BY u.statut' here, not compatible with the UNION.
|
431
|
|
|
//print $sql_usr;exit;
|
432
|
|
|
|
433
|
|
|
$resql_usr = $this->db->query($sql_usr);
|
|
|
|
|
434
|
|
|
if ($resql_usr)
|
435
|
|
|
{
|
436
|
|
|
while ($obj_usr = $this->db->fetch_object($resql_usr))
|
437
|
|
|
{
|
438
|
|
|
|
439
|
|
|
$out.='<option value="'.$obj_usr->rowid.'"';
|
440
|
|
|
|
441
|
|
|
if ($obj_usr->rowid == $selected) $out.=' selected';
|
442
|
|
|
|
443
|
|
|
$out.='>';
|
444
|
|
|
$out.=dolGetFirstLastname($obj_usr->firstname,$obj_usr->lastname);
|
445
|
|
|
// Complete name with more info
|
446
|
|
|
$moreinfo=0;
|
447
|
|
|
if (! empty($conf->global->MAIN_SHOW_LOGIN))
|
448
|
|
|
{
|
449
|
|
|
$out.=($moreinfo?' - ':' (').$obj_usr->login;
|
450
|
|
|
$moreinfo++;
|
451
|
|
|
}
|
452
|
|
|
if ($showstatus >= 0)
|
453
|
|
|
{
|
454
|
|
|
if ($obj_usr->statut == 1 && $showstatus == 1)
|
455
|
|
|
{
|
456
|
|
|
$out.=($moreinfo?' - ':' (').$langs->trans('Enabled');
|
457
|
|
|
$moreinfo++;
|
458
|
|
|
}
|
459
|
|
|
if ($obj_usr->statut == 0)
|
460
|
|
|
{
|
461
|
|
|
$out.=($moreinfo?' - ':' (').$langs->trans('Disabled');
|
462
|
|
|
$moreinfo++;
|
463
|
|
|
}
|
464
|
|
|
}
|
465
|
|
|
$out.=($moreinfo?')':'');
|
466
|
|
|
$out.='</option>';
|
467
|
|
|
}
|
468
|
|
|
$this->db->free($resql_usr);
|
469
|
|
|
}
|
470
|
|
|
else
|
471
|
|
|
{
|
472
|
|
|
dol_print_error($this->db);
|
473
|
|
|
}
|
474
|
|
|
$out.='</select>';
|
475
|
|
|
|
476
|
|
|
return $out;
|
477
|
|
|
}
|
478
|
|
|
|
479
|
|
|
/**
|
480
|
|
|
* Return list of project and tasks
|
481
|
|
|
*
|
482
|
|
|
* @param int $selectedtask Pre-selected task
|
483
|
|
|
* @param int $projectid Project id
|
484
|
|
|
* @param string $htmlname Name of html select
|
485
|
|
|
* @param int $modeproject 1 to restrict on projects owned by user
|
486
|
|
|
* @param int $modetask 1 to restrict on tasks associated to user
|
487
|
|
|
* @param int $mode 0=Return list of tasks and their projects, 1=Return projects and tasks if exists
|
488
|
|
|
* @param int $useempty 0=Allow empty values
|
489
|
|
|
* @param int $disablechildoftaskid 1=Disable task that are child of the provided task id
|
490
|
|
|
* @param string $filteronprojstatus Filter on project status ('-1'=no filter, '0,1'=Draft+Validated status)
|
491
|
|
|
* @param string $morecss More css
|
492
|
|
|
* @return void
|
493
|
|
|
*/
|
494
|
|
|
function selectProjectTasks($selectedtask='', $projectid=0, $htmlname='task_parent', $modeproject=0, $modetask=0, $mode=0, $useempty=0, $disablechildoftaskid=0, $filteronprojstatus='', $morecss='')
|
495
|
|
|
{
|
496
|
|
|
global $user, $langs;
|
497
|
|
|
|
498
|
|
|
require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
|
499
|
|
|
|
500
|
|
|
//print $modeproject.'-'.$modetask;
|
501
|
|
|
$task=new Task($this->db);
|
|
|
|
|
502
|
|
|
$tasksarray=$task->getTasksArray($modetask?$user:0, $modeproject?$user:0, $projectid, 0, $mode, '', $filteronprojstatus);
|
503
|
|
|
if ($tasksarray)
|
504
|
|
|
{
|
505
|
|
|
print '<select class="flat'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
|
506
|
|
|
if ($useempty) print '<option value="0"> </option>';
|
507
|
|
|
$j=0;
|
508
|
|
|
$level=0;
|
509
|
|
|
$this->_pLineSelect($j, 0, $tasksarray, $level, $selectedtask, $projectid, $disablechildoftaskid);
|
510
|
|
|
print '</select>';
|
511
|
|
|
|
512
|
|
|
print ajax_combobox($htmlname);
|
513
|
|
|
}
|
514
|
|
|
else
|
515
|
|
|
{
|
516
|
|
|
print '<div class="warning">'.$langs->trans("NoProject").'</div>';
|
517
|
|
|
}
|
518
|
|
|
}
|
519
|
|
|
|
520
|
|
|
/**
|
521
|
|
|
* Write lines of a project (all lines of a project if parent = 0)
|
522
|
|
|
*
|
523
|
|
|
* @param int $inc Cursor counter
|
524
|
|
|
* @param int $parent Id of parent task we want to see
|
525
|
|
|
* @param array $lines Array of task lines
|
526
|
|
|
* @param int $level Level
|
527
|
|
|
* @param int $selectedtask Id selected task
|
528
|
|
|
* @param int $selectedproject Id selected project
|
529
|
|
|
* @param int $disablechildoftaskid 1=Disable task that are child of the provided task id
|
530
|
|
|
* @return void
|
531
|
|
|
*/
|
532
|
|
|
private function _pLineSelect(&$inc, $parent, $lines, $level=0, $selectedtask=0, $selectedproject=0, $disablechildoftaskid=0)
|
533
|
|
|
{
|
534
|
|
|
global $langs, $user, $conf;
|
535
|
|
|
|
536
|
|
|
$lastprojectid=0;
|
537
|
|
|
|
538
|
|
|
$numlines=count($lines);
|
539
|
|
|
for ($i = 0 ; $i < $numlines ; $i++)
|
540
|
|
|
{
|
541
|
|
|
if ($lines[$i]->fk_parent == $parent)
|
542
|
|
|
{
|
543
|
|
|
$var = !$var;
|
544
|
|
|
|
545
|
|
|
//var_dump($selectedproject."--".$selectedtask."--".$lines[$i]->fk_project."_".$lines[$i]->id); // $lines[$i]->id may be empty if project has no lines
|
546
|
|
|
|
547
|
|
|
// Break on a new project
|
548
|
|
|
if ($parent == 0) // We are on a task at first level
|
549
|
|
|
{
|
550
|
|
|
if ($lines[$i]->fk_project != $lastprojectid) // Break found on project
|
551
|
|
|
{
|
552
|
|
|
if ($i > 0) print '<option value="0" disabled>----------</option>';
|
553
|
|
|
print '<option value="'.$lines[$i]->fk_project.'_0"';
|
554
|
|
|
if ($selectedproject == $lines[$i]->fk_project) print ' selected';
|
555
|
|
|
print '>'; // Project -> Task
|
556
|
|
|
print $langs->trans("Project").' '.$lines[$i]->projectref;
|
557
|
|
|
if (empty($lines[$i]->public))
|
558
|
|
|
{
|
559
|
|
|
print ' ('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')';
|
560
|
|
|
}
|
561
|
|
|
else
|
562
|
|
|
{
|
563
|
|
|
print ' ('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')';
|
564
|
|
|
}
|
565
|
|
|
//print '-'.$parent.'-'.$lines[$i]->fk_project.'-'.$lastprojectid;
|
566
|
|
|
print "</option>\n";
|
567
|
|
|
|
568
|
|
|
$lastprojectid=$lines[$i]->fk_project;
|
569
|
|
|
$inc++;
|
570
|
|
|
}
|
571
|
|
|
}
|
572
|
|
|
|
573
|
|
|
$newdisablechildoftaskid=$disablechildoftaskid;
|
574
|
|
|
|
575
|
|
|
// Print task
|
576
|
|
|
if (isset($lines[$i]->id)) // We use isset because $lines[$i]->id may be null if project has no task and are on root project (tasks may be caught by a left join). We enter here only if '0' or >0
|
577
|
|
|
{
|
578
|
|
|
// Check if we must disable entry
|
579
|
|
|
$disabled=0;
|
580
|
|
|
if ($disablechildoftaskid && (($lines[$i]->id == $disablechildoftaskid || $lines[$i]->fk_parent == $disablechildoftaskid)))
|
581
|
|
|
{
|
582
|
|
|
$disabled++;
|
583
|
|
|
if ($lines[$i]->fk_parent == $disablechildoftaskid) $newdisablechildoftaskid=$lines[$i]->id; // If task is child of a disabled parent, we will propagate id to disable next child too
|
584
|
|
|
}
|
585
|
|
|
|
586
|
|
|
print '<option value="'.$lines[$i]->fk_project.'_'.$lines[$i]->id.'"';
|
587
|
|
|
if (($lines[$i]->id == $selectedtask) || ($lines[$i]->fk_project.'_'.$lines[$i]->id == $selectedtask)) print ' selected';
|
588
|
|
|
if ($disabled) print ' disabled';
|
589
|
|
|
print '>';
|
590
|
|
|
print $langs->trans("Project").' '.$lines[$i]->projectref;
|
591
|
|
|
print ' '.$lines[$i]->projectlabel;
|
592
|
|
|
if (empty($lines[$i]->public))
|
593
|
|
|
{
|
594
|
|
|
print ' ('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')';
|
595
|
|
|
}
|
596
|
|
|
else
|
597
|
|
|
{
|
598
|
|
|
print ' ('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')';
|
599
|
|
|
}
|
600
|
|
|
if ($lines[$i]->id) print ' > ';
|
601
|
|
|
for ($k = 0 ; $k < $level ; $k++)
|
602
|
|
|
{
|
603
|
|
|
print " ";
|
604
|
|
|
}
|
605
|
|
|
print $lines[$i]->ref.' '.$lines[$i]->label."</option>\n";
|
606
|
|
|
$inc++;
|
607
|
|
|
}
|
608
|
|
|
|
609
|
|
|
$level++;
|
610
|
|
|
if ($lines[$i]->id) $this->_pLineSelect($inc, $lines[$i]->id, $lines, $level, $selectedtask, $selectedproject, $newdisablechildoftaskid);
|
611
|
|
|
$level--;
|
612
|
|
|
}
|
613
|
|
|
}
|
614
|
|
|
}
|
615
|
|
|
|
616
|
|
|
|
617
|
|
|
/**
|
618
|
|
|
* Output a HTML thumb of color or a text if not defined.
|
619
|
|
|
*
|
620
|
|
|
* @param string $color String with hex (FFFFFF) or comma RGB ('255,255,255')
|
621
|
|
|
* @param string $textifnotdefined Text to show if color not defined
|
622
|
|
|
* @return string HTML code for color thumb
|
623
|
|
|
* @see selectColor
|
624
|
|
|
*/
|
625
|
|
|
static function showColor($color, $textifnotdefined='')
|
626
|
|
|
{
|
627
|
|
|
$textcolor='FFF';
|
628
|
|
|
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
|
629
|
|
|
if(colorIsLight($color)) $textcolor='000';
|
630
|
|
|
|
631
|
|
|
$color = colorArrayToHex(colorStringToArray($color,array()),'');
|
632
|
|
|
|
633
|
|
|
if ($color) print '<input type="text" class="colorthumb" disabled style="padding: 1px; margin-top: 0; margin-bottom: 0; color: #'.$textcolor.'; background-color: #'.$color.'" value="'.$color.'">';
|
634
|
|
|
else print $textifnotdefined;
|
635
|
|
|
}
|
636
|
|
|
|
637
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
|
638
|
|
|
/**
|
639
|
|
|
* Output a HTML code to select a color
|
640
|
|
|
*
|
641
|
|
|
* @param string $set_color Pre-selected color
|
642
|
|
|
* @param string $prefix Name of HTML field
|
643
|
|
|
* @param string $form_name Deprecated. Not used.
|
644
|
|
|
* @param int $showcolorbox 1=Show color code and color box, 0=Show only color code
|
645
|
|
|
* @param array $arrayofcolors Array of colors. Example: array('29527A','5229A3','A32929','7A367A','B1365F','0D7813')
|
646
|
|
|
* @return void
|
647
|
|
|
* @deprecated Use instead selectColor
|
648
|
|
|
* @see selectColor()
|
649
|
|
|
*/
|
650
|
|
|
function select_color($set_color='', $prefix='f_color', $form_name='', $showcolorbox=1, $arrayofcolors='')
|
651
|
|
|
{
|
652
|
|
|
// phpcs:enable
|
653
|
|
|
print $this->selectColor($set_color, $prefix, $form_name, $showcolorbox, $arrayofcolors);
|
654
|
|
|
}
|
655
|
|
|
|
656
|
|
|
/**
|
657
|
|
|
* Output a HTML code to select a color. Field will return an hexa color like '334455'.
|
658
|
|
|
*
|
659
|
|
|
* @param string $set_color Pre-selected color
|
660
|
|
|
* @param string $prefix Name of HTML field
|
661
|
|
|
* @param string $form_name Deprecated. Not used.
|
662
|
|
|
* @param int $showcolorbox 1=Show color code and color box, 0=Show only color code
|
663
|
|
|
* @param array $arrayofcolors Array of colors. Example: array('29527A','5229A3','A32929','7A367A','B1365F','0D7813')
|
664
|
|
|
* @param string $morecss Add css style into input field
|
665
|
|
|
* @return string
|
666
|
|
|
* @see showColor
|
667
|
|
|
*/
|
668
|
|
|
static function selectColor($set_color='', $prefix='f_color', $form_name='', $showcolorbox=1, $arrayofcolors='', $morecss='')
|
669
|
|
|
{
|
670
|
|
|
// Deprecation warning
|
671
|
|
|
if ($form_name) {
|
672
|
|
|
dol_syslog(__METHOD__ . ": form_name parameter is deprecated", LOG_WARNING);
|
673
|
|
|
}
|
674
|
|
|
|
675
|
|
|
global $langs,$conf;
|
676
|
|
|
|
677
|
|
|
$out='';
|
678
|
|
|
|
679
|
|
|
if (! is_array($arrayofcolors) || count($arrayofcolors) < 1)
|
680
|
|
|
{
|
681
|
|
|
$langs->load("other");
|
682
|
|
|
if (empty($conf->dol_use_jmobile))
|
683
|
|
|
{
|
684
|
|
|
$out.= '<link rel="stylesheet" media="screen" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css" />';
|
685
|
|
|
$out.= '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/jpicker-1.1.6.js"></script>';
|
686
|
|
|
$out.= '<script type="text/javascript">
|
687
|
|
|
jQuery(document).ready(function(){
|
688
|
|
|
$(\'#colorpicker'.$prefix.'\').jPicker( {
|
689
|
|
|
window: {
|
690
|
|
|
title: \''.dol_escape_js($langs->trans("SelectAColor")).'\', /* any title for the jPicker window itself - displays "Drag Markers To Pick A Color" if left null */
|
691
|
|
|
effects:
|
692
|
|
|
{
|
693
|
|
|
type: \'show\', /* effect used to show/hide an expandable picker. Acceptable values "slide", "show", "fade" */
|
694
|
|
|
speed:
|
695
|
|
|
{
|
696
|
|
|
show: \'fast\', /* duration of "show" effect. Acceptable values are "fast", "slow", or time in ms */
|
697
|
|
|
hide: \'fast\' /* duration of "hide" effect. Acceptable values are "fast", "slow", or time in ms */
|
698
|
|
|
}
|
699
|
|
|
},
|
700
|
|
|
position:
|
701
|
|
|
{
|
702
|
|
|
x: \'screenCenter\', /* acceptable values "left", "center", "right", "screenCenter", or relative px value */
|
703
|
|
|
y: \'center\' /* acceptable values "top", "bottom", "center", or relative px value */
|
704
|
|
|
},
|
705
|
|
|
},
|
706
|
|
|
images: {
|
707
|
|
|
clientPath: \''.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/images/\',
|
708
|
|
|
picker: { file: \'../../../../../theme/common/colorpicker.png\', width: 14, height: 14 }
|
709
|
|
|
},
|
710
|
|
|
localization: // alter these to change the text presented by the picker (e.g. different language)
|
711
|
|
|
{
|
712
|
|
|
text:
|
713
|
|
|
{
|
714
|
|
|
title: \''.dol_escape_js($langs->trans("SelectAColor")).'\',
|
715
|
|
|
newColor: \''.dol_escape_js($langs->trans("New")).'\',
|
716
|
|
|
currentColor: \''.dol_escape_js($langs->trans("Current")).'\',
|
717
|
|
|
ok: \''.dol_escape_js($langs->trans("Save")).'\',
|
718
|
|
|
cancel: \''.dol_escape_js($langs->trans("Cancel")).'\'
|
719
|
|
|
}
|
720
|
|
|
}
|
721
|
|
|
} ); });
|
722
|
|
|
</script>';
|
723
|
|
|
}
|
724
|
|
|
$out.= '<input id="colorpicker'.$prefix.'" name="'.$prefix.'" size="6" maxlength="7" class="flat'.($morecss?' '.$morecss:'').'" type="text" value="'.$set_color.'" />';
|
725
|
|
|
}
|
726
|
|
|
else // In most cases, this is not used. We used instead function with no specific list of colors
|
727
|
|
|
{
|
728
|
|
|
if (empty($conf->dol_use_jmobile))
|
729
|
|
|
{
|
730
|
|
|
$out.= '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.css" type="text/css" media="screen" />';
|
731
|
|
|
$out.= '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.js" type="text/javascript"></script>';
|
732
|
|
|
$out.= '<script type="text/javascript">
|
733
|
|
|
jQuery(document).ready(function(){
|
734
|
|
|
jQuery(\'#colorpicker'.$prefix.'\').colorpicker({
|
735
|
|
|
size: 14,
|
736
|
|
|
label: \'\',
|
737
|
|
|
hide: true
|
738
|
|
|
});
|
739
|
|
|
});
|
740
|
|
|
</script>';
|
741
|
|
|
}
|
742
|
|
|
$out.= '<select id="colorpicker'.$prefix.'" class="flat'.($morecss?' '.$morecss:'').'" name="'.$prefix.'">';
|
743
|
|
|
//print '<option value="-1"> </option>';
|
744
|
|
|
foreach ($arrayofcolors as $val)
|
745
|
|
|
{
|
746
|
|
|
$out.= '<option value="'.$val.'"';
|
747
|
|
|
if ($set_color == $val) $out.= ' selected';
|
748
|
|
|
$out.= '>'.$val.'</option>';
|
749
|
|
|
}
|
750
|
|
|
$out.= '</select>';
|
751
|
|
|
}
|
752
|
|
|
|
753
|
|
|
return $out;
|
754
|
|
|
}
|
755
|
|
|
|
756
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
|
757
|
|
|
/**
|
758
|
|
|
* Creation d'un icone de couleur
|
759
|
|
|
*
|
760
|
|
|
* @param string $color Couleur de l'image
|
761
|
|
|
* @param string $module Nom du module
|
762
|
|
|
* @param string $name Nom de l'image
|
763
|
|
|
* @param int $x Largeur de l'image en pixels
|
764
|
|
|
* @param int $y Hauteur de l'image en pixels
|
765
|
|
|
* @return void
|
766
|
|
|
*/
|
767
|
|
|
function CreateColorIcon($color,$module,$name,$x='12',$y='12')
|
768
|
|
|
{
|
769
|
|
|
// phpcs:enable
|
770
|
|
|
global $conf;
|
771
|
|
|
|
772
|
|
|
$file = $conf->$module->dir_temp.'/'.$name.'.png';
|
773
|
|
|
|
774
|
|
|
// On cree le repertoire contenant les icones
|
775
|
|
|
if (! file_exists($conf->$module->dir_temp))
|
776
|
|
|
{
|
777
|
|
|
dol_mkdir($conf->$module->dir_temp);
|
778
|
|
|
}
|
779
|
|
|
|
780
|
|
|
// On cree l'image en vraies couleurs
|
781
|
|
|
$image = imagecreatetruecolor($x,$y);
|
782
|
|
|
|
783
|
|
|
$color = substr($color,1,6);
|
784
|
|
|
|
785
|
|
|
$rouge = hexdec(substr($color,0,2)); //conversion du canal rouge
|
786
|
|
|
$vert = hexdec(substr($color,2,2)); //conversion du canal vert
|
787
|
|
|
$bleu = hexdec(substr($color,4,2)); //conversion du canal bleu
|
788
|
|
|
|
789
|
|
|
$couleur = imagecolorallocate($image,$rouge,$vert,$bleu);
|
790
|
|
|
//print $rouge.$vert.$bleu;
|
791
|
|
|
imagefill($image,0,0,$couleur); //on remplit l'image
|
792
|
|
|
// On cree la couleur et on l'attribue a une variable pour ne pas la perdre
|
793
|
|
|
ImagePng($image,$file); //renvoie une image sous format png
|
794
|
|
|
ImageDestroy($image);
|
795
|
|
|
}
|
796
|
|
|
|
797
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
|
798
|
|
|
/**
|
799
|
|
|
* Return HTML combo list of week
|
800
|
|
|
*
|
801
|
|
|
* @param string $selected Preselected value
|
802
|
|
|
* @param string $htmlname Nom de la zone select
|
803
|
|
|
* @param int $useempty Affiche valeur vide dans liste
|
804
|
|
|
* @return string
|
805
|
|
|
*/
|
806
|
|
|
function select_dayofweek($selected='',$htmlname='weekid',$useempty=0)
|
807
|
|
|
{
|
808
|
|
|
// phpcs:enable
|
809
|
|
|
global $langs;
|
810
|
|
|
|
811
|
|
|
$week = array(
|
812
|
|
|
0=>$langs->trans("Day0"),
|
813
|
|
|
1=>$langs->trans("Day1"),
|
814
|
|
|
2=>$langs->trans("Day2"),
|
815
|
|
|
3=>$langs->trans("Day3"),
|
816
|
|
|
4=>$langs->trans("Day4"),
|
817
|
|
|
5=>$langs->trans("Day5"),
|
818
|
|
|
6=>$langs->trans("Day6")
|
819
|
|
|
);
|
820
|
|
|
|
821
|
|
|
$select_week = '<select class="flat" name="'.$htmlname.'">';
|
822
|
|
|
if ($useempty)
|
823
|
|
|
{
|
824
|
|
|
$select_week .= '<option value="-1"> </option>';
|
825
|
|
|
}
|
826
|
|
|
foreach ($week as $key => $val)
|
827
|
|
|
{
|
828
|
|
|
if ($selected == $key)
|
829
|
|
|
{
|
830
|
|
|
$select_week .= '<option value="'.$key.'" selected>';
|
831
|
|
|
}
|
832
|
|
|
else
|
833
|
|
|
{
|
834
|
|
|
$select_week .= '<option value="'.$key.'">';
|
835
|
|
|
}
|
836
|
|
|
$select_week .= $val;
|
837
|
|
|
$select_week .= '</option>';
|
838
|
|
|
}
|
839
|
|
|
$select_week .= '</select>';
|
840
|
|
|
return $select_week;
|
841
|
|
|
}
|
842
|
|
|
|
843
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
|
844
|
|
|
/**
|
845
|
|
|
* Return HTML combo list of month
|
846
|
|
|
*
|
847
|
|
|
* @param string $selected Preselected value
|
848
|
|
|
* @param string $htmlname Name of HTML select object
|
849
|
|
|
* @param int $useempty Show empty in list
|
850
|
|
|
* @param int $longlabel Show long label
|
851
|
|
|
* @param string $morecss More Css
|
852
|
|
|
* @return string
|
853
|
|
|
*/
|
854
|
|
|
function select_month($selected='', $htmlname='monthid', $useempty=0, $longlabel=0, $morecss='')
|
855
|
|
|
{
|
856
|
|
|
// phpcs:enable
|
857
|
|
|
global $langs;
|
858
|
|
|
|
859
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
860
|
|
|
|
861
|
|
|
if ($longlabel) $montharray = monthArray($langs, 0); // Get array
|
862
|
|
|
else $montharray = monthArray($langs, 1);
|
863
|
|
|
|
864
|
|
|
$select_month = '<select class="flat'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
|
865
|
|
|
if ($useempty)
|
866
|
|
|
{
|
867
|
|
|
$select_month .= '<option value="0"> </option>';
|
868
|
|
|
}
|
869
|
|
|
foreach ($montharray as $key => $val)
|
870
|
|
|
{
|
871
|
|
|
if ($selected == $key)
|
872
|
|
|
{
|
873
|
|
|
$select_month .= '<option value="'.$key.'" selected>';
|
874
|
|
|
}
|
875
|
|
|
else
|
876
|
|
|
{
|
877
|
|
|
$select_month .= '<option value="'.$key.'">';
|
878
|
|
|
}
|
879
|
|
|
$select_month .= $val;
|
880
|
|
|
$select_month .= '</option>';
|
881
|
|
|
}
|
882
|
|
|
$select_month .= '</select>';
|
883
|
|
|
return $select_month;
|
884
|
|
|
}
|
885
|
|
|
|
886
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
|
887
|
|
|
/**
|
888
|
|
|
* Return HTML combo list of years
|
889
|
|
|
*
|
890
|
|
|
* @param string $selected Preselected value (''=current year, -1=none, year otherwise)
|
891
|
|
|
* @param string $htmlname Name of HTML select object
|
892
|
|
|
* @param int $useempty Affiche valeur vide dans liste
|
893
|
|
|
* @param int $min_year Offset of minimum year into list (by default current year -10)
|
894
|
|
|
* @param int $max_year Offset of maximum year into list (by default current year + 5)
|
895
|
|
|
* @param int $offset Offset
|
896
|
|
|
* @param int $invert Invert
|
897
|
|
|
* @param string $option Option
|
898
|
|
|
* @param string $morecss More CSS
|
899
|
|
|
* @return string
|
900
|
|
|
*/
|
901
|
|
|
function select_year($selected='',$htmlname='yearid',$useempty=0, $min_year=10, $max_year=5, $offset=0, $invert=0, $option='', $morecss='valignmiddle widthauto')
|
902
|
|
|
{
|
903
|
|
|
// phpcs:enable
|
904
|
|
|
print $this->selectyear($selected,$htmlname,$useempty,$min_year,$max_year,$offset,$invert,$option,$morecss);
|
905
|
|
|
}
|
906
|
|
|
|
907
|
|
|
/**
|
908
|
|
|
* Return HTML combo list of years
|
909
|
|
|
*
|
910
|
|
|
* @param string $selected Preselected value (''=current year, -1=none, year otherwise)
|
911
|
|
|
* @param string $htmlname Name of HTML select object
|
912
|
|
|
* @param int $useempty Affiche valeur vide dans liste
|
913
|
|
|
* @param int $min_year Offset of minimum year into list (by default current year -10)
|
914
|
|
|
* @param int $max_year Offset of maximum year into list (by default current year + 5)
|
915
|
|
|
* @param int $offset Offset
|
916
|
|
|
* @param int $invert Invert
|
917
|
|
|
* @param string $option Option
|
918
|
|
|
* @param string $morecss More css
|
919
|
|
|
* @return string
|
920
|
|
|
*/
|
921
|
|
|
function selectyear($selected='',$htmlname='yearid',$useempty=0, $min_year=10, $max_year=5, $offset=0, $invert=0, $option='', $morecss='valignmiddle widthauto')
|
922
|
|
|
{
|
923
|
|
|
$out='';
|
924
|
|
|
|
925
|
|
|
$currentyear = date("Y")+$offset;
|
926
|
|
|
$max_year = $currentyear+$max_year;
|
927
|
|
|
$min_year = $currentyear-$min_year;
|
928
|
|
|
if(empty($selected) && empty($useempty)) $selected = $currentyear;
|
929
|
|
|
|
930
|
|
|
$out.= '<select class="flat'.($morecss?' '.$morecss:'').'" id="' . $htmlname . '" name="' . $htmlname . '"'.$option.' >';
|
931
|
|
|
if($useempty)
|
932
|
|
|
{
|
933
|
|
|
$selected_html='';
|
934
|
|
|
if ($selected == '') $selected_html = ' selected';
|
935
|
|
|
$out.= '<option value=""' . $selected_html . '> </option>';
|
936
|
|
|
}
|
937
|
|
|
if (! $invert)
|
938
|
|
|
{
|
939
|
|
|
for ($y = $max_year; $y >= $min_year; $y--)
|
940
|
|
|
{
|
941
|
|
|
$selected_html='';
|
942
|
|
|
if ($selected > 0 && $y == $selected) $selected_html = ' selected';
|
943
|
|
|
$out.= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
|
944
|
|
|
}
|
945
|
|
|
}
|
946
|
|
|
else
|
947
|
|
|
{
|
948
|
|
|
for ($y = $min_year; $y <= $max_year; $y++)
|
949
|
|
|
{
|
950
|
|
|
$selected_html='';
|
951
|
|
|
if ($selected > 0 && $y == $selected) $selected_html = ' selected';
|
952
|
|
|
$out.= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
|
953
|
|
|
}
|
954
|
|
|
}
|
955
|
|
|
$out.= "</select>\n";
|
956
|
|
|
|
957
|
|
|
return $out;
|
958
|
|
|
}
|
959
|
|
|
|
960
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
|
961
|
|
|
/**
|
962
|
|
|
* Show form to select address
|
963
|
|
|
*
|
964
|
|
|
* @param int $page Page
|
965
|
|
|
* @param string $selected Id condition pre-selectionne
|
966
|
|
|
* @param int $socid Id of third party
|
967
|
|
|
* @param string $htmlname Nom du formulaire select
|
968
|
|
|
* @param string $origin Origine de l'appel pour pouvoir creer un retour
|
969
|
|
|
* @param int $originid Id de l'origine
|
970
|
|
|
* @return void
|
971
|
|
|
*/
|
972
|
|
|
function form_address($page, $selected, $socid, $htmlname='address_id', $origin='', $originid='')
|
973
|
|
|
{
|
974
|
|
|
// phpcs:enable
|
975
|
|
|
global $langs,$conf;
|
976
|
|
|
global $form;
|
977
|
|
|
|
978
|
|
|
if ($htmlname != "none")
|
979
|
|
|
{
|
980
|
|
|
print '<form method="post" action="'.$page.'">';
|
981
|
|
|
print '<input type="hidden" name="action" value="setaddress">';
|
982
|
|
|
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
983
|
|
|
$form->select_address($selected, $socid, $htmlname, 1);
|
984
|
|
|
print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
|
985
|
|
|
$langs->load("companies");
|
986
|
|
|
print ' <a href='.DOL_URL_ROOT.'/comm/address.php?socid='.$socid.'&action=create&origin='.$origin.'&originid='.$originid.'>'.$langs->trans("AddAddress").'</a>';
|
987
|
|
|
print '</form>';
|
988
|
|
|
}
|
989
|
|
|
else
|
990
|
|
|
{
|
991
|
|
|
if ($selected)
|
992
|
|
|
{
|
993
|
|
|
require_once DOL_DOCUMENT_ROOT .'/societe/class/address.class.php';
|
994
|
|
|
$address=new Address($this->db);
|
|
|
|
|
995
|
|
|
$result=$address->fetch_address($selected);
|
996
|
|
|
print '<a href='.DOL_URL_ROOT.'/comm/address.php?socid='.$address->socid.'&id='.$address->id.'&action=edit&origin='.$origin.'&originid='.$originid.'>'.$address->label.'</a>';
|
997
|
|
|
}
|
998
|
|
|
else
|
999
|
|
|
{
|
1000
|
|
|
print " ";
|
1001
|
|
|
}
|
1002
|
|
|
}
|
1003
|
|
|
}
|
1004
|
|
|
|
1005
|
|
|
|
1006
|
|
|
|
1007
|
|
|
/**
|
1008
|
|
|
* Get array with HTML tabs with boxes of a particular area including personalized choices of user.
|
1009
|
|
|
* Class 'Form' must be known.
|
1010
|
|
|
*
|
1011
|
|
|
* @param User $user Object User
|
1012
|
|
|
* @param String $areacode Code of area for pages ('0'=value for Home page)
|
1013
|
|
|
* @return array array('selectboxlist'=>, 'boxactivated'=>, 'boxlista'=>, 'boxlistb'=>)
|
1014
|
|
|
*/
|
1015
|
|
|
static function getBoxesArea($user,$areacode)
|
1016
|
|
|
{
|
1017
|
|
|
global $conf,$langs,$db;
|
1018
|
|
|
|
1019
|
|
|
include_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
|
1020
|
|
|
|
1021
|
|
|
$confuserzone='MAIN_BOXES_'.$areacode;
|
1022
|
|
|
|
1023
|
|
|
// $boxactivated will be array of boxes enabled into global setup
|
1024
|
|
|
// $boxidactivatedforuser will be array of boxes choosed by user
|
1025
|
|
|
|
1026
|
|
|
$selectboxlist='';
|
1027
|
|
|
$boxactivated=InfoBox::listBoxes($db, 'activated', $areacode, (empty($user->conf->$confuserzone)?null:$user), array(), 0); // Search boxes of common+user (or common only if user has no specific setup)
|
|
|
|
|
1028
|
|
|
|
1029
|
|
|
$boxidactivatedforuser=array();
|
1030
|
|
|
foreach($boxactivated as $box)
|
1031
|
|
|
{
|
1032
|
|
|
if (empty($user->conf->$confuserzone) || $box->fk_user == $user->id) $boxidactivatedforuser[$box->id]=$box->id; // We keep only boxes to show for user
|
1033
|
|
|
}
|
1034
|
|
|
|
1035
|
|
|
// Define selectboxlist
|
1036
|
|
|
$arrayboxtoactivatelabel=array();
|
1037
|
|
|
if (! empty($user->conf->$confuserzone))
|
1038
|
|
|
{
|
1039
|
|
|
$boxorder='';
|
1040
|
|
|
$langs->load("boxes"); // Load label of boxes
|
1041
|
|
|
foreach($boxactivated as $box)
|
1042
|
|
|
{
|
1043
|
|
|
if (! empty($boxidactivatedforuser[$box->id])) continue; // Already visible for user
|
1044
|
|
|
$label=$langs->transnoentitiesnoconv($box->boxlabel);
|
1045
|
|
|
//if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph").')';
|
1046
|
|
|
if (preg_match('/graph/',$box->class) && $conf->browser->layout != 'phone')
|
1047
|
|
|
{
|
1048
|
|
|
$label=$label.' <span class="fa fa-bar-chart"></span>';
|
1049
|
|
|
}
|
1050
|
|
|
$arrayboxtoactivatelabel[$box->id]=$label; // We keep only boxes not shown for user, to show into combo list
|
1051
|
|
|
}
|
1052
|
|
|
foreach($boxidactivatedforuser as $boxid)
|
1053
|
|
|
{
|
1054
|
|
|
if (empty($boxorder)) $boxorder.='A:';
|
1055
|
|
|
$boxorder.=$boxid.',';
|
1056
|
|
|
}
|
1057
|
|
|
|
1058
|
|
|
//var_dump($boxidactivatedforuser);
|
1059
|
|
|
|
1060
|
|
|
// Class Form must have been already loaded
|
1061
|
|
|
$selectboxlist.='<!-- Form with select box list -->'."\n";
|
1062
|
|
|
$selectboxlist.='<form id="addbox" name="addbox" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
1063
|
|
|
$selectboxlist.='<input type="hidden" name="addbox" value="addbox">';
|
1064
|
|
|
$selectboxlist.='<input type="hidden" name="userid" value="'.$user->id.'">';
|
1065
|
|
|
$selectboxlist.='<input type="hidden" name="areacode" value="'.$areacode.'">';
|
1066
|
|
|
$selectboxlist.='<input type="hidden" name="boxorder" value="'.$boxorder.'">';
|
1067
|
|
|
$selectboxlist.=Form::selectarray('boxcombo', $arrayboxtoactivatelabel, -1, $langs->trans("ChooseBoxToAdd").'...', 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth150onsmartphone', 0, 'hidden selected', 0, 1);
|
1068
|
|
|
if (empty($conf->use_javascript_ajax)) $selectboxlist.=' <input type="submit" class="button" value="'.$langs->trans("AddBox").'">';
|
1069
|
|
|
$selectboxlist.='</form>';
|
1070
|
|
|
if (! empty($conf->use_javascript_ajax))
|
1071
|
|
|
{
|
1072
|
|
|
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
|
1073
|
|
|
$selectboxlist.=ajax_combobox("boxcombo");
|
1074
|
|
|
}
|
1075
|
|
|
}
|
1076
|
|
|
|
1077
|
|
|
// Javascript code for dynamic actions
|
1078
|
|
|
if (! empty($conf->use_javascript_ajax))
|
1079
|
|
|
{
|
1080
|
|
|
$selectboxlist.='<script type="text/javascript" language="javascript">
|
1081
|
|
|
|
1082
|
|
|
// To update list of activated boxes
|
1083
|
|
|
function updateBoxOrder(closing) {
|
1084
|
|
|
var left_list = cleanSerialize(jQuery("#boxhalfleft").sortable("serialize"));
|
1085
|
|
|
var right_list = cleanSerialize(jQuery("#boxhalfright").sortable("serialize"));
|
1086
|
|
|
var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
|
1087
|
|
|
if (boxorder==\'A:A-B:B\' && closing == 1) // There is no more boxes on screen, and we are after a delete of a box so we must hide title
|
1088
|
|
|
{
|
1089
|
|
|
jQuery.ajax({
|
1090
|
|
|
url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=0&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
|
1091
|
|
|
async: false
|
1092
|
|
|
});
|
1093
|
|
|
// We force reload to be sure to get all boxes into list
|
1094
|
|
|
window.location.search=\'mainmenu='.GETPOST("mainmenu","aZ09").'&leftmenu='.GETPOST('leftmenu',"aZ09").'&action=delbox\';
|
1095
|
|
|
}
|
1096
|
|
|
else
|
1097
|
|
|
{
|
1098
|
|
|
jQuery.ajax({
|
1099
|
|
|
url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=\'+closing+\'&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
|
1100
|
|
|
async: true
|
1101
|
|
|
});
|
1102
|
|
|
}
|
1103
|
|
|
}
|
1104
|
|
|
|
1105
|
|
|
jQuery(document).ready(function() {
|
1106
|
|
|
jQuery("#boxcombo").change(function() {
|
1107
|
|
|
var boxid=jQuery("#boxcombo").val();
|
1108
|
|
|
if (boxid > 0) {
|
1109
|
|
|
var left_list = cleanSerialize(jQuery("#boxhalfleft").sortable("serialize"));
|
1110
|
|
|
var right_list = cleanSerialize(jQuery("#boxhalfright").sortable("serialize"));
|
1111
|
|
|
var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
|
1112
|
|
|
jQuery.ajax({
|
1113
|
|
|
url: \''.DOL_URL_ROOT.'/core/ajax/box.php?boxorder=\'+boxorder+\'&boxid=\'+boxid+\'&zone='.$areacode.'&userid='.$user->id.'\',
|
1114
|
|
|
async: false
|
1115
|
|
|
});
|
1116
|
|
|
window.location.search=\'mainmenu='.GETPOST("mainmenu","aZ09").'&leftmenu='.GETPOST('leftmenu',"aZ09").'&action=addbox&boxid=\'+boxid;
|
1117
|
|
|
}
|
1118
|
|
|
});';
|
1119
|
|
|
if (! count($arrayboxtoactivatelabel)) $selectboxlist.='jQuery("#boxcombo").hide();';
|
1120
|
|
|
$selectboxlist.='
|
1121
|
|
|
|
1122
|
|
|
jQuery("#boxhalfleft, #boxhalfright").sortable({
|
1123
|
|
|
handle: \'.boxhandle\',
|
1124
|
|
|
revert: \'invalid\',
|
1125
|
|
|
items: \'.boxdraggable\',
|
1126
|
|
|
containment: \'document\',
|
1127
|
|
|
connectWith: \'#boxhalfleft, #boxhalfright\',
|
1128
|
|
|
stop: function(event, ui) {
|
1129
|
|
|
updateBoxOrder(1); /* 1 to avoid message after a move */
|
1130
|
|
|
}
|
1131
|
|
|
});
|
1132
|
|
|
|
1133
|
|
|
jQuery(".boxclose").click(function() {
|
1134
|
|
|
var self = this; // because JQuery can modify this
|
1135
|
|
|
var boxid=self.id.substring(8);
|
1136
|
|
|
var label=jQuery(\'#boxlabelentry\'+boxid).val();
|
1137
|
|
|
console.log("We close box "+boxid);
|
1138
|
|
|
jQuery(\'#boxto_\'+boxid).remove();
|
1139
|
|
|
if (boxid > 0) jQuery(\'#boxcombo\').append(new Option(label, boxid));
|
1140
|
|
|
updateBoxOrder(1); /* 1 to avoid message after a remove */
|
1141
|
|
|
});
|
1142
|
|
|
|
1143
|
|
|
});'."\n";
|
1144
|
|
|
|
1145
|
|
|
$selectboxlist.='</script>'."\n";
|
1146
|
|
|
}
|
1147
|
|
|
|
1148
|
|
|
// Define boxlista and boxlistb
|
1149
|
|
|
$nbboxactivated=count($boxidactivatedforuser);
|
1150
|
|
|
|
1151
|
|
|
if ($nbboxactivated)
|
1152
|
|
|
{
|
1153
|
|
|
// Load translation files required by the page
|
1154
|
|
|
$langs->loadLangs(array("boxes","projects"));
|
1155
|
|
|
|
1156
|
|
|
$emptybox=new ModeleBoxes($db);
|
|
|
|
|
1157
|
|
|
|
1158
|
|
|
$boxlista.="\n<!-- Box left container -->\n";
|
|
|
|
|
1159
|
|
|
|
1160
|
|
|
// Define $box_max_lines
|
1161
|
|
|
$box_max_lines=5;
|
1162
|
|
|
if (! empty($conf->global->MAIN_BOXES_MAXLINES)) $box_max_lines=$conf->global->MAIN_BOXES_MAXLINES;
|
1163
|
|
|
|
1164
|
|
|
$ii=0;
|
1165
|
|
|
foreach ($boxactivated as $key => $box)
|
1166
|
|
|
{
|
1167
|
|
|
if ((! empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) continue;
|
1168
|
|
|
if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) $box->box_order='A'.sprintf("%02d",($ii+1)); // When box_order was not yet set to Axx or Bxx and is still 0
|
1169
|
|
|
if (preg_match('/^A/i',$box->box_order)) // column A
|
1170
|
|
|
{
|
1171
|
|
|
$ii++;
|
1172
|
|
|
//print 'box_id '.$boxactivated[$ii]->box_id.' ';
|
1173
|
|
|
//print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
|
1174
|
|
|
// Show box
|
1175
|
|
|
$box->loadBox($box_max_lines);
|
1176
|
|
|
$boxlista.= $box->outputBox();
|
1177
|
|
|
}
|
1178
|
|
|
}
|
1179
|
|
|
|
1180
|
|
|
if ($conf->browser->layout != 'phone')
|
1181
|
|
|
{
|
1182
|
|
|
$emptybox->box_id='A';
|
1183
|
|
|
$emptybox->info_box_head=array();
|
1184
|
|
|
$emptybox->info_box_contents=array();
|
1185
|
|
|
$boxlista.= $emptybox->outputBox(array(),array());
|
1186
|
|
|
}
|
1187
|
|
|
$boxlista.= "<!-- End box left container -->\n";
|
1188
|
|
|
|
1189
|
|
|
$boxlistb.= "\n<!-- Box right container -->\n";
|
|
|
|
|
1190
|
|
|
|
1191
|
|
|
$ii=0;
|
1192
|
|
|
foreach ($boxactivated as $key => $box)
|
1193
|
|
|
{
|
1194
|
|
|
if ((! empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) continue;
|
1195
|
|
|
if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) $box->box_order='B'.sprintf("%02d",($ii+1)); // When box_order was not yet set to Axx or Bxx and is still 0
|
1196
|
|
|
if (preg_match('/^B/i',$box->box_order)) // colonne B
|
1197
|
|
|
{
|
1198
|
|
|
$ii++;
|
1199
|
|
|
//print 'box_id '.$boxactivated[$ii]->box_id.' ';
|
1200
|
|
|
//print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
|
1201
|
|
|
// Show box
|
1202
|
|
|
$box->loadBox($box_max_lines);
|
1203
|
|
|
$boxlistb.= $box->outputBox();
|
1204
|
|
|
}
|
1205
|
|
|
}
|
1206
|
|
|
|
1207
|
|
|
if ($conf->browser->layout != 'phone')
|
1208
|
|
|
{
|
1209
|
|
|
$emptybox->box_id='B';
|
1210
|
|
|
$emptybox->info_box_head=array();
|
1211
|
|
|
$emptybox->info_box_contents=array();
|
1212
|
|
|
$boxlistb.= $emptybox->outputBox(array(),array());
|
1213
|
|
|
}
|
1214
|
|
|
|
1215
|
|
|
$boxlistb.= "<!-- End box right container -->\n";
|
1216
|
|
|
}
|
1217
|
|
|
|
1218
|
|
|
return array('selectboxlist'=>count($boxactivated)?$selectboxlist:'', 'boxactivated'=>$boxactivated, 'boxlista'=>$boxlista, 'boxlistb'=>$boxlistb);
|
1219
|
|
|
}
|
1220
|
|
|
|
1221
|
|
|
|
1222
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
|
1223
|
|
|
/**
|
1224
|
|
|
* Return a HTML select list of a dictionary
|
1225
|
|
|
*
|
1226
|
|
|
* @param string $htmlname Name of select zone
|
1227
|
|
|
* @param string $dictionarytable Dictionary table
|
1228
|
|
|
* @param string $keyfield Field for key
|
1229
|
|
|
* @param string $labelfield Label field
|
1230
|
|
|
* @param string $selected Selected value
|
1231
|
|
|
* @param int $useempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries.
|
1232
|
|
|
* @param string $moreattrib More attributes on HTML select tag
|
1233
|
|
|
* @return void
|
1234
|
|
|
*/
|
1235
|
|
|
function select_dictionary($htmlname,$dictionarytable,$keyfield='code',$labelfield='label',$selected='',$useempty=0,$moreattrib='')
|
1236
|
|
|
{
|
1237
|
|
|
// phpcs:enable
|
1238
|
|
|
global $langs, $conf;
|
1239
|
|
|
|
1240
|
|
|
$langs->load("admin");
|
1241
|
|
|
|
1242
|
|
|
$sql = "SELECT rowid, ".$keyfield.", ".$labelfield;
|
1243
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX.$dictionarytable;
|
1244
|
|
|
$sql.= " ORDER BY ".$labelfield;
|
1245
|
|
|
|
1246
|
|
|
dol_syslog(get_class($this)."::select_dictionary", LOG_DEBUG);
|
1247
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
1248
|
|
|
if ($result)
|
1249
|
|
|
{
|
1250
|
|
|
$num = $this->db->num_rows($result);
|
1251
|
|
|
$i = 0;
|
1252
|
|
|
if ($num)
|
1253
|
|
|
{
|
1254
|
|
|
print '<select id="select'.$htmlname.'" class="flat selectdictionary" name="'.$htmlname.'"'.($moreattrib?' '.$moreattrib:'').'>';
|
1255
|
|
|
if ($useempty == 1 || ($useempty == 2 && $num > 1))
|
1256
|
|
|
{
|
1257
|
|
|
print '<option value="-1"> </option>';
|
1258
|
|
|
}
|
1259
|
|
|
|
1260
|
|
|
while ($i < $num)
|
1261
|
|
|
{
|
1262
|
|
|
$obj = $this->db->fetch_object($result);
|
1263
|
|
|
if ($selected == $obj->rowid || $selected == $obj->$keyfield)
|
1264
|
|
|
{
|
1265
|
|
|
print '<option value="'.$obj->$keyfield.'" selected>';
|
1266
|
|
|
}
|
1267
|
|
|
else
|
1268
|
|
|
{
|
1269
|
|
|
print '<option value="'.$obj->$keyfield.'">';
|
1270
|
|
|
}
|
1271
|
|
|
print $obj->$labelfield;
|
1272
|
|
|
print '</option>';
|
1273
|
|
|
$i++;
|
1274
|
|
|
}
|
1275
|
|
|
print "</select>";
|
1276
|
|
|
}
|
1277
|
|
|
else
|
1278
|
|
|
{
|
1279
|
|
|
print $langs->trans("DictionaryEmpty");
|
1280
|
|
|
}
|
1281
|
|
|
}
|
1282
|
|
|
else {
|
1283
|
|
|
dol_print_error($this->db);
|
1284
|
|
|
}
|
1285
|
|
|
}
|
1286
|
|
|
}
|
1287
|
|
|
|