dolibarr 25.0.0-alpha
html.formother.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
5 * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
6 * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
7 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
8 * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
9 * Copyright (C) 2006 Marc Barilley/Ocebo <marc@ocebo.com>
10 * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerker@telenet.be>
11 * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
12 * Copyright (C) 2019 Thibault FOUCART <support@ptibogxiv.net>
13 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
14 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <https://www.gnu.org/licenses/>.
28 */
29
42{
46 private $db;
47
51 public $error;
52
53
59 public function __construct($db)
60 {
61 $this->db = $db;
62 }
63
73 public function getHTMLScannerForm($jstoexecuteonadd = 'barcodescannerjs', $mode = 'all', $warehouseselect = 0)
74 {
75 global $langs;
76
77 // $jstoexecuteonadd is the name of a js function: it is used as an id and called, so it can't contain anything else
78 $jstoexecuteonadd = sanitizeVal($jstoexecuteonadd, 'aZ09');
79
80 $out = '';
81
82 $out .= '<!-- Popup for mass barcode scanning -->'."\n";
83 $out .= '<div class="div-for-modal-topright" style="padding: 15px">';
84 $out .= '<center>'.img_picto('', 'barcode', 'class="pictofixedwidth"').'<strong>Barcode scanner tool...</strong></center><br>';
85
86 if ($mode == 'product') {
87 $out .= '<input type="hidden" name="barcodemode" value="barcodeforproduct" id="barcodeforproduct">';
88 } elseif ($mode == 'lot') {
89 $out .= '<input type="hidden" name="barcodemode" value="barcodeforlotserial" id="barcodeforlotserial">';
90 } else { // $mode = 'all'
91 $out .= '<input type="radio" name="barcodemode" value="barcodeforautodetect" id="barcodeforautodetect" checked="checked"> <label for="barcodeforautodetect">Autodetect if we scan a product barcode or a lot/serial barcode</label><br>';
92 $out .= '<input type="radio" name="barcodemode" value="barcodeforproduct" id="barcodeforproduct"> <label for="barcodeforproduct">Scan a product barcode</label><br>';
93 $out .= '<input type="radio" name="barcodemode" value="barcodeforlotserial" id="barcodeforlotserial"> <label for="barcodeforlotserial">Scan a product lot or serial number</label><br>';
94 }
95 $stringaddbarcode = $langs->trans("QtyToAddAfterBarcodeScan", "tmphtml");
96 $htmltoreplaceby = '<select name="selectaddorreplace"><option selected value="add">'.$langs->trans("Add").'</option><option value="replace">'.$langs->trans("ToReplace").'</option></select>';
97 $stringaddbarcode = str_replace("tmphtml", $htmltoreplaceby, $stringaddbarcode);
98 $out .= $stringaddbarcode.': <input type="text" name="barcodeproductqty" class="width40 right" value="1"><br>';
99 if ($warehouseselect > 0) {
100 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
101 $formproduct = new FormProduct($this->db);
102 $formproduct->loadWarehouses();
103 $out .= img_picto('', 'stock', 'class="pictofixedwidth"');
104 $out .= $formproduct->selectWarehouses('', "warehousenew", '', 0, 0, 0, '', 0, 1);
105 $out .= '<br>';
106 $out .= '<br>';
107 }
108 $out .= '<textarea type="text" name="barcodelist" class="centpercent" autofocus rows="'.ROWS_3.'" placeholder="'.dol_escape_htmltag($langs->trans("ScanOrTypeOrCopyPasteYourBarCodes")).'"></textarea>';
109
110 /*print '<br>'.$langs->trans("or").'<br>';
111
112 print '<br>';
113
114 print '<input type="text" name="barcodelotserial" class="width200"> &nbsp; &nbsp; Qty <input type="text" name="barcodelotserialqty" class="width50 right" value="1"><br>';
115 */
116 $out .= '<br>';
117 $out .= '<center>';
118 $out .= '<input type="submit" class="button marginleftonly marginrightonly" id="exec'.$jstoexecuteonadd.'" name="addscan" value="'.dolPrintHTMLForAttribute($langs->trans("Add")).'">';
119 $out .= '<input type="submit" class="button marginleftonly marginrightonly" name="cancel" value="'.dol_escape_htmltag($langs->trans("CloseWindow")).'">';
120 $out .= '</center>';
121 $out .= '<br>';
122 $out .= '<div type="text" id="scantoolmessage" class="scantoolmessage ok nopadding"></div>';
123
124 $out .= '<script nonce="'.getNonce().'">';
125 $out .= 'jQuery("#barcodeforautodetect, #barcodeforproduct, #barcodeforlotserial").click(function(){';
126 $out .= 'console.log("select choice");';
127 $out .= 'jQuery("#scantoolmessage").text("");';
128 $out .= '});'."\n";
129 $out .= '$(\'#exec'.$jstoexecuteonadd.'\').click(function(){
130 console.log(\'We call js to execute '.$jstoexecuteonadd.'\');
131 '.$jstoexecuteonadd.'();
132 return false; /* We want to stay on the scan tool */
133 })';
134 $out .= '</script>';
135
136 $out .= '</center>';
137 $out .= '</div>';
138
139 return $out;
140 }
141
142 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
153 public function select_export_model($selected = '', $htmlname = 'exportmodelid', $type = '', $useempty = 0, $fk_user = null)
154 {
155 // phpcs:enable
156 global $langs;
157
158 $sql = "SELECT rowid, label, fk_user";
159 $sql .= " FROM ".$this->db->prefix()."export_model";
160 $sql .= " WHERE type = '".$this->db->escape($type)."'";
161 if (!getDolGlobalString('EXPORTS_SHARE_MODELS')) { // EXPORTS_SHARE_MODELS means all templates are visible, whatever is owner.
162 $sql .= " AND fk_user IN (0, ".((int) $fk_user).")";
163 }
164 $sql .= " ORDER BY label";
165 $result = $this->db->query($sql);
166 if ($result) {
167 print '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
168 if ($useempty) {
169 if (is_numeric($useempty)) {
170 print '<option value="-1">&nbsp;</option>';
171 } else {
172 print '<option value="-1">'.$langs->trans($useempty).'</option>';
173 }
174 }
175
176 $tmpuser = new User($this->db);
177
178 $num = $this->db->num_rows($result);
179 $i = 0;
180 while ($i < $num) {
181 $obj = $this->db->fetch_object($result);
182
183 $label = $obj->label;
184 if ($obj->fk_user == 0) {
185 $label .= ' <span class="opacitymedium">('.$langs->trans("Everybody").')</span>';
186 } elseif ($obj->fk_user > 0) {
187 $tmpuser->fetch($obj->fk_user);
188 $label .= ' <span class="opacitymedium">('.$tmpuser->getFullName($langs).')</span>';
189 }
190
191 if ($selected == $obj->rowid) {
192 print '<option value="'.$obj->rowid.'" selected data-html="'.dolPrintHTMLForAttribute($label).'">';
193 } else {
194 print '<option value="'.$obj->rowid.'" data-html="'.dolPrintHTMLForAttribute($label).'">';
195 }
196 print $label;
197 print '</option>';
198 $i++;
199 }
200 if ($num == 0) {
201 print '<option value="-1" disabled data-html="'.dolPrintHTMLForAttribute('<span class="opacitymedium">'.$langs->transnoentitiesnoconv("NoPredefinedExportProfileYet").'</span>').'">'.$langs->transnoentitiesnoconv("NoPredefinedProfileYet").'</option>';
202 }
203 print "</select>";
204 print ajax_combobox($htmlname);
205 } else {
206 dol_print_error($this->db);
207 }
208 }
209
210
211 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
222 public function select_import_model($selected = '', $htmlname = 'importmodelid', $type = '', $useempty = 0, $fk_user = null)
223 {
224 // phpcs:enable
225 global $langs;
226
227 $sql = "SELECT rowid, label, fk_user";
228 $sql .= " FROM ".$this->db->prefix()."import_model";
229 $sql .= " WHERE type = '".$this->db->escape($type)."'";
230 if (!getDolGlobalString('EXPORTS_SHARE_MODELS')) { // EXPORTS_SHARE_MODELS means all templates are visible, whatever is owner.
231 $sql .= " AND fk_user IN (0, ".((int) $fk_user).")";
232 }
233 $sql .= " ORDER BY label";
234 $result = $this->db->query($sql);
235 if ($result) {
236 print '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
237 if (is_numeric($useempty)) {
238 print '<option value="-1">&nbsp;</option>';
239 } else {
240 print '<option value="-1">'.$langs->trans($useempty).'</option>';
241 }
242
243 $tmpuser = new User($this->db);
244
245 $num = $this->db->num_rows($result);
246 $i = 0;
247 while ($i < $num) {
248 $obj = $this->db->fetch_object($result);
249
250 $label = $obj->label;
251 if ($obj->fk_user == 0) {
252 $label .= ' <span class="opacitymedium">('.$langs->trans("Everybody").')</span>';
253 } elseif ($obj->fk_user > 0) {
254 $tmpuser->fetch($obj->fk_user);
255 $label .= ' <span class="opacitymedium">('.$tmpuser->getFullName($langs).')</span>';
256 }
257
258 if ($selected == $obj->rowid) {
259 print '<option value="'.$obj->rowid.'" selected data-html="'.dol_escape_htmltag($label).'">';
260 } else {
261 print '<option value="'.$obj->rowid.'" data-html="'.dol_escape_htmltag($label).'">';
262 }
263 print $label;
264 print '</option>';
265 $i++;
266 }
267 if ($num == 0) {
268 print '<option value="-1" disabled data-html="'.dolPrintHTMLForAttribute('<span class="opacitymedium">'.$langs->transnoentitiesnoconv("NoPredefinedProfileYet").'</span>').'">'.$langs->transnoentitiesnoconv("NoPredefinedProfileYet").'</option>';
269 }
270 print "</select>";
271 print ajax_combobox($htmlname);
272 } else {
273 dol_print_error($this->db);
274 }
275 }
276
277
278 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
286 public function select_ecotaxes($selected = '', $htmlname = 'ecotaxe_id')
287 {
288 // phpcs:enable
289 global $langs;
290
291 $sql = "SELECT e.rowid, e.code, e.label, e.price, e.organization,";
292 $sql .= " c.label as country";
293 $sql .= " FROM ".$this->db->prefix()."c_ecotaxe as e,".$this->db->prefix()."c_country as c";
294 $sql .= " WHERE e.active = 1 AND e.fk_pays = c.rowid";
295 $sql .= " ORDER BY country, e.organization ASC, e.code ASC";
296
297 dol_syslog(get_class($this).'::select_ecotaxes', LOG_DEBUG);
298 $resql = $this->db->query($sql);
299 if ($resql) {
300 print '<select class="flat" name="'.$htmlname.'">';
301 $num = $this->db->num_rows($resql);
302 $i = 0;
303 print '<option value="-1">&nbsp;</option>'."\n";
304 if ($num) {
305 while ($i < $num) {
306 $obj = $this->db->fetch_object($resql);
307 if ($selected && $selected == $obj->rowid) {
308 print '<option value="'.$obj->rowid.'" selected>';
309 } else {
310 print '<option value="'.$obj->rowid.'">';
311 //print '<option onmouseover="showtip(\''.$obj->label.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
312 }
313 $selectOptionValue = $obj->code.' - '.$obj->label.' : '.price($obj->price).' '.$langs->trans("HT").' ('.$obj->organization.')';
314 print $selectOptionValue;
315 print '</option>';
316 $i++;
317 }
318 }
319 print '</select>';
320 return 0;
321 } else {
322 dol_print_error($this->db);
323 return 1;
324 }
325 }
326
327
328 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
337 public function select_revenue_stamp($selected = '', $htmlname = 'revenuestamp', $country_code = '')
338 {
339 // phpcs:enable
340 global $langs;
341
342 $out = '';
343
344 $sql = "SELECT r.taux, r.revenuestamp_type";
345 $sql .= " FROM ".$this->db->prefix()."c_revenuestamp as r,".$this->db->prefix()."c_country as c";
346 $sql .= " WHERE r.active = 1 AND r.fk_pays = c.rowid";
347 $sql .= " AND c.code = '".$this->db->escape($country_code)."'";
348
349 dol_syslog(get_class($this).'::select_revenue_stamp', LOG_DEBUG);
350 $resql = $this->db->query($sql);
351 if ($resql) {
352 $out .= '<select class="flat" name="'.$htmlname.'">';
353 $num = $this->db->num_rows($resql);
354 $i = 0;
355 $out .= '<option value="0">&nbsp;</option>'."\n";
356 if ($num) {
357 while ($i < $num) {
358 $obj = $this->db->fetch_object($resql);
359 if (($selected && $selected == $obj->taux) || $num == 1) {
360 $out .= '<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').' selected>';
361 } else {
362 $out .= '<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').'>';
363 }
364 $out .= $obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '');
365 $out .= '</option>';
366 $i++;
367 }
368 }
369 $out .= '</select>';
370 return $out;
371 } else {
372 dol_print_error($this->db);
373 return '';
374 }
375 }
376
377
378 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
391 public function select_percent($selected = 0, $htmlname = 'percent', $disabled = 0, $increment = 5, $start = 0, $end = 100, $showempty = 0)
392 {
393 // phpcs:enable
394 $return = '<select class="flat maxwidth75 right" name="'.$htmlname.'" '.($disabled ? 'disabled' : '').'>';
395 if ($showempty) {
396 $return .= '<option value="-1"'.(($selected == -1 || $selected == '') ? ' selected' : '').'>&nbsp;</option>';
397 }
398
399 for ($i = $start; $i <= $end; $i += $increment) {
400 if ($selected != '' && (int) $selected == $i) {
401 $return .= '<option value="'.$i.'" selected>';
402 } else {
403 $return .= '<option value="'.$i.'">';
404 }
405 $return .= $i.' % ';
406 $return .= '</option>';
407 }
408
409 $return .= '</select>';
410
411 return $return;
412 }
413
414 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
427 public function select_categories($type, $selected = 0, $htmlname = 'search_categ', $nocateg = 0, $showempty = 1, $morecss = '')
428 {
429 // phpcs:enable
430 global $conf, $langs;
431 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
432
433 // For backward compatibility
434 if (is_numeric($type)) {
435 dol_syslog(__METHOD__.': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING);
436 }
437
438 // Load list of "categories"
439 $static_categs = new Categorie($this->db);
440 $tab_categs = $static_categs->get_full_arbo($type);
441
442 $moreforfilter = '';
443
444 // Print a select with each of them
445 $moreforfilter .= '<select class="flat minwidth100'.($morecss ? ' '.$morecss : '').'" id="select_categ_'.$htmlname.'" name="'.$htmlname.'">';
446 if ($showempty) {
447 $textforempty = ' ';
448 if (!empty($conf->use_javascript_ajax)) {
449 $textforempty = '&nbsp;'; // If we use ajaxcombo, we need &nbsp; here to avoid to have an empty element that is too small.
450 }
451 if (!is_numeric($showempty)) {
452 $textforempty = $showempty;
453 }
454 $moreforfilter .= '<option class="optiongrey" value="'.($showempty < 0 ? $showempty : -1).'"'.($selected == $showempty ? ' selected' : '');
455 //$moreforfilter .= ' data-html="'.dol_escape_htmltag($textforempty).'"';
456 $moreforfilter .= '>'.dol_escape_htmltag($textforempty).'</option>'."\n";
457 }
458
459 if (is_array($tab_categs)) {
460 foreach ($tab_categs as $categ) {
461 $moreforfilter .= '<option value="'.$categ['id'].'"';
462 if ($categ['id'] == $selected) {
463 $moreforfilter .= ' selected';
464 }
465 $moreforfilter .= ' data-html="'.dol_escape_htmltag(img_picto('', 'category', 'class="pictofixedwidth" style="color: #'.$categ['color'].'"').dol_trunc($categ['fulllabel'], 50, 'middle')).'"';
466 $moreforfilter .= '>'.dol_trunc($categ['fulllabel'], 50, 'middle').'</option>';
467 }
468 }
469 if ($nocateg) {
470 $langs->load("categories");
471 $moreforfilter .= '<option value="-2"'.($selected == -2 ? ' selected' : '').'>- '.$langs->trans("NotCategorized").' -</option>';
472 }
473 $moreforfilter .= '</select>';
474
475 // Enhance with select2
476 if ($conf->use_javascript_ajax) {
477 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
478 $comboenhancement = ajax_combobox('select_categ_'.$htmlname);
479 $moreforfilter .= $comboenhancement;
480 }
481
482 return $moreforfilter;
483 }
484
485
486 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
499 public function select_salesrepresentatives($selected, $htmlname, $user, $showstatus = 0, $showempty = 1, $morecss = '', $norepresentative = 0)
500 {
501 // phpcs:enable
502 global $conf, $langs, $hookmanager;
503 global $action;
504
505 $langs->load('users');
506
507 $out = '';
508
509 $reshook = $hookmanager->executeHooks('addSQLWhereFilterOnSelectSalesRep', array(), $this, $action);
510
511 // Select each sales and print them in a select input
512 $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'">';
513 if ($showempty) {
514 $textforempty = ' ';
515 if (!is_numeric($showempty)) {
516 $textforempty = $showempty;
517 }
518 if (!empty($conf->use_javascript_ajax) && $textforempty == ' ') {
519 $textforempty = '&nbsp;'; // If we use ajaxcombo, we need &nbsp; here to avoid to have an empty element that is too small.
520 }
521 $out .= '<option class="optiongrey" value="'.($showempty < 0 ? $showempty : -1).'"'.($selected == $showempty ? ' selected' : '').'>'.$textforempty.'</option>'."\n";
522 }
523
524 // Get list of users allowed to be viewed
525 $sql_usr = "SELECT u.rowid, u.lastname, u.firstname, u.statut as status, u.login, u.photo, u.gender, u.entity, u.admin";
526 $sql_usr .= " FROM ".$this->db->prefix()."user as u";
527
528 if (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
529 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
530 $sql_usr .= " WHERE u.entity IS NOT NULL"; // Show all users
531 } else {
532 $sql_usr .= " WHERE EXISTS (SELECT ug.fk_user FROM ".$this->db->prefix()."usergroup_user as ug WHERE u.rowid = ug.fk_user AND ug.entity IN (".getEntity('usergroup')."))";
533 $sql_usr .= " OR u.entity = 0"; // Show always superadmin
534 }
535 } else {
536 $sql_usr .= " WHERE u.entity IN (".getEntity('user').")";
537 }
538
539 if (!$user->hasRight('user', 'user', 'lire')) {
540 $sql_usr .= " AND u.rowid = ".((int) $user->id);
541 }
542 if (!empty($user->socid)) {
543 $sql_usr .= " AND u.fk_soc = ".((int) $user->socid);
544 }
545 if (getDolUserString('USER_HIDE_NONEMPLOYEE_IN_COMBOBOX', getDolGlobalString('USER_HIDE_NONEMPLOYEE_IN_COMBOBOX'))) {
546 $sql_usr .= " AND u.employee <> 0";
547 }
548 if (getDolUserString('USER_HIDE_EXTERNAL_IN_COMBOBOX', getDolGlobalString('USER_HIDE_EXTERNAL_IN_COMBOBOX'))) {
549 $sql_usr .= " AND u.fk_soc IS NULL";
550 }
551 if (getDolUserString('USER_HIDE_INACTIVE_IN_COMBOBOX', getDolGlobalString('USER_HIDE_INACTIVE_IN_COMBOBOX'))) { // Can be set in setup of module User.
552 $sql_usr .= " AND u.statut <> 0";
553 }
554
555 //Add hook to filter on user (for example on usergroup define in custom modules)
556 if (!empty($reshook)) {
557 $sql_usr .= $hookmanager->resArray[0]; // Trust the hook: @phan-suppress-current-line SqlInjection
558 }
559
560 // Add existing sales representatives of thirdparty of external user
561 if (!$user->hasRight('user', 'user', 'lire') && $user->socid) {
562 $sql_usr .= " UNION ";
563 $sql_usr .= "SELECT u2.rowid, u2.lastname, u2.firstname, u2.statut as status, u2.login, u2.photo, u2.gender, u2.entity, u2.admin";
564 $sql_usr .= " FROM ".$this->db->prefix()."user as u2, ".$this->db->prefix()."societe_commerciaux as sc";
565
566 if (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
567 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
568 $sql_usr .= " WHERE u2.entity IS NOT NULL"; // Show all users
569 } else {
570 $sql_usr .= " WHERE EXISTS (SELECT ug2.fk_user FROM ".$this->db->prefix()."usergroup_user as ug2 WHERE u2.rowid = ug2.fk_user AND ug2.entity IN (".getEntity('usergroup')."))";
571 }
572 } else {
573 $sql_usr .= " WHERE u2.entity IN (".getEntity('user').")";
574 }
575
576 $sql_usr .= " AND u2.rowid = sc.fk_user AND sc.fk_soc = ".((int) $user->socid);
577
578 //Add hook to filter on user (for example on usergroup define in custom modules)
579 if (!empty($reshook)) {
580 $sql_usr .= $hookmanager->resArray[1]; // Trust the hook: @phan-suppress-current-line SqlInjection
581 }
582 }
583
584 if (!getDolGlobalString('MAIN_FIRSTNAME_NAME_POSITION')) { // MAIN_FIRSTNAME_NAME_POSITION is 0 means firstname+lastname
585 $sql_usr .= " ORDER BY status DESC, firstname ASC, lastname ASC";
586 } else {
587 $sql_usr .= " ORDER BY status DESC, lastname ASC, firstname ASC";
588 }
589 //print $sql_usr;exit;
590
591 $resql_usr = $this->db->query($sql_usr);
592 if ($resql_usr) {
593 $userstatic = new User($this->db);
594
595 while ($obj_usr = $this->db->fetch_object($resql_usr)) {
596 $userstatic->id = $obj_usr->rowid;
597 $userstatic->lastname = $obj_usr->lastname;
598 $userstatic->firstname = $obj_usr->firstname;
599 $userstatic->photo = $obj_usr->photo;
600 $userstatic->status = $obj_usr->status;
601 $userstatic->entity = $obj_usr->entity;
602 $userstatic->admin = $obj_usr->admin;
603
604 $labeltoshow = dolGetFirstLastname($obj_usr->firstname, $obj_usr->lastname);
605 if (empty($obj_usr->firstname) && empty($obj_usr->lastname)) {
606 $labeltoshow = $obj_usr->login;
607 }
608
609 $out .= '<option value="'.$obj_usr->rowid.'"';
610 if ($obj_usr->rowid == $selected) {
611 $out .= ' selected';
612 }
613 $out .= ' data-html="';
614 $outhtml = $userstatic->getNomUrl(-3, '', 0, 1, 24, 1, 'login', '', 1).' ';
615 if ($showstatus >= 0 && $obj_usr->status == 0) {
616 $outhtml .= '<strike class="opacitymediumxxx">';
617 }
618 $outhtml .= $labeltoshow;
619 if ($showstatus >= 0 && $obj_usr->status == 0) {
620 $outhtml .= '</strike>';
621 }
622 $out .= dol_escape_htmltag($outhtml);
623 $out .= '">';
624
625 $out .= $labeltoshow;
626 // Complete name with more info
627 $moreinfo = 0;
628 if (getDolGlobalString('MAIN_SHOW_LOGIN')) {
629 $out .= ($moreinfo ? ' - ' : ' (').$obj_usr->login;
630 $moreinfo++;
631 }
632 if ($showstatus >= 0) {
633 if ($obj_usr->status == 1 && $showstatus == 1) {
634 $out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Enabled');
635 $moreinfo++;
636 }
637 if ($obj_usr->status == 0) {
638 $out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Disabled');
639 $moreinfo++;
640 }
641 }
642 $out .= ($moreinfo ? ')' : '');
643 $out .= '</option>';
644 }
645 $this->db->free($resql_usr);
646 } else {
647 dol_print_error($this->db);
648 }
649
650 if ($norepresentative) {
651 $langs->load("companies");
652 $out .= '<option value="-2"'.($selected == -2 ? ' selected' : '').'>- '.$langs->trans("NoSalesRepresentativeAffected").' -</option>';
653 }
654
655 $out .= '</select>';
656
657 // Enhance with select2
658 if ($conf->use_javascript_ajax) {
659 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
660
661 $comboenhancement = ajax_combobox($htmlname);
662 if ($comboenhancement) {
663 $out .= $comboenhancement;
664 }
665 }
666
667 return $out;
668 }
669
685 public function selectProjectTasks($selectedtask = 0, $projectid = 0, $htmlname = 'task_parent', $modeproject = 0, $modetask = 0, $mode = 0, $useempty = 0, $disablechildoftaskid = 0, $filteronprojstatus = '', $morecss = '')
686 {
687 global $user, $langs;
688
689 require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
690
691 //print $modeproject.'-'.$modetask;
692 $task = new Task($this->db);
693 $tasksarray = $task->getTasksArray($modetask ? $user : 0, $modeproject ? $user : 0, $projectid, 0, $mode, '', $filteronprojstatus);
694 if ($tasksarray) {
695 print '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
696 if ($useempty) {
697 print '<option value="0">&nbsp;</option>';
698 }
699 $j = 0;
700 $level = 0;
701 $this->_pLineSelect($j, 0, $tasksarray, $level, $selectedtask, $projectid, $disablechildoftaskid);
702 print '</select>';
703
704 print ajax_combobox($htmlname);
705 } else {
706 print '<div class="warning">'.$langs->trans("NoProject").'</div>';
707 }
708 }
709
722 private function _pLineSelect(&$inc, $parent, $lines, $level = 0, $selectedtask = 0, $selectedproject = 0, $disablechildoftaskid = 0)
723 {
724 global $langs, $user, $conf;
725
726 $lastprojectid = 0;
727
728 $numlines = count($lines);
729 for ($i = 0; $i < $numlines; $i++) {
730 if ($lines[$i]->fk_task_parent == $parent) {
731 //var_dump($selectedproject."--".$selectedtask."--".$lines[$i]->fk_project."_".$lines[$i]->id); // $lines[$i]->id may be empty if project has no lines
732
733 // Break on a new project
734 if ($parent == 0) { // We are on a task at first level
735 if ($lines[$i]->fk_project != $lastprojectid) { // Break found on project
736 if ($i > 0) {
737 print '<option value="0" disabled>----------</option>';
738 }
739 print '<option value="'.$lines[$i]->fk_project.'_0"';
740 if ($selectedproject == $lines[$i]->fk_project) {
741 print ' selected';
742 }
743
744 $labeltoshow = $lines[$i]->projectref;
745 //$labeltoshow .= ' '.$lines[$i]->projectlabel;
746 if (empty($lines[$i]->public)) {
747 //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')</span>';
748 $labeltoshow = img_picto($lines[$i]->projectlabel, 'project', 'class="pictofixedwidth"').$labeltoshow;
749 } else {
750 //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')</span>';
751 $labeltoshow = img_picto($lines[$i]->projectlabel, 'projectpub', 'class="pictofixedwidth"').$labeltoshow;
752 }
753
754 print ' data-html="'.dol_escape_htmltag($labeltoshow).'"';
755 print '>'; // Project -> Task
756 print $labeltoshow;
757 print "</option>\n";
758
759 $lastprojectid = $lines[$i]->fk_project;
760 $inc++;
761 }
762 }
763
764 $newdisablechildoftaskid = $disablechildoftaskid;
765
766 // Print task
767 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
768 // Check if we must disable entry
769 $disabled = 0;
770 if ($disablechildoftaskid && (($lines[$i]->id == $disablechildoftaskid || $lines[$i]->fk_task_parent == $disablechildoftaskid))) {
771 $disabled++;
772 if ($lines[$i]->fk_task_parent == $disablechildoftaskid) {
773 $newdisablechildoftaskid = $lines[$i]->id; // If task is child of a disabled parent, we will propagate id to disable next child too
774 }
775 }
776
777 print '<option value="'.$lines[$i]->fk_project.'_'.$lines[$i]->id.'"';
778 if (($lines[$i]->id == $selectedtask) || ($lines[$i]->fk_project.'_'.$lines[$i]->id == $selectedtask)) {
779 print ' selected';
780 }
781 if ($disabled) {
782 print ' disabled';
783 }
784
785 $labeltoshow = $lines[$i]->projectref;
786 //$labeltoshow .= ' '.$lines[$i]->projectlabel;
787 if (empty($lines[$i]->public)) {
788 //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')</span>';
789 $labeltoshow = img_picto($lines[$i]->projectlabel, 'project', 'class="pictofixedwidth"').$labeltoshow;
790 } else {
791 //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')</span>';
792 $labeltoshow = img_picto($lines[$i]->projectlabel, 'projectpub', 'class="pictofixedwidth"').$labeltoshow;
793 }
794 if ($lines[$i]->id) {
795 $labeltoshow .= ' > ';
796 }
797 for ($k = 0; $k < $level; $k++) {
798 $labeltoshow .= "&nbsp;&nbsp;&nbsp;";
799 }
800 $labeltoshow .= $lines[$i]->ref.' '.$lines[$i]->label;
801
802 print ' data-html="'.dol_escape_htmltag($labeltoshow).'"';
803 print '>';
804 print $labeltoshow;
805 print "</option>\n";
806 $inc++;
807 }
808
809 $level++;
810 if ($lines[$i]->id) {
811 $this->_pLineSelect($inc, $lines[$i]->id, $lines, $level, $selectedtask, $selectedproject, $newdisablechildoftaskid);
812 }
813 $level--;
814 }
815 }
816 }
817
818
827 public static function showColor($color, $textifnotdefined = '')
828 {
829 $textcolor = 'FFF';
830 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
831 if (colorIsLight($color)) {
832 $textcolor = '000';
833 }
834
835 $color = colorArrayToHex(colorStringToArray($color, array()), '');
836
837 if ($color) {
838 return '<input type="text" class="colorthumb" disabled style="padding: 1px; margin-top: 0; margin-bottom: 0; color: #'.$textcolor.'; background-color: #'.$color.'" value="'.$color.'">';
839 } else {
840 return $textifnotdefined;
841 }
842 }
843
844 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
857 public function select_color($set_color = '', $prefix = 'f_color', $form_name = '', $showcolorbox = 1, $arrayofcolors = [])
858 {
859 // phpcs:enable
860 print $this->selectColor($set_color, $prefix, $form_name, $showcolorbox, $arrayofcolors);
861 }
862
877 public static function selectColor($set_color = '', $prefix = 'f_color', $form_name = '', $showcolorbox = 1, $arrayofcolors = [], $morecss = '', $setpropertyonselect = '', $default = '')
878 {
879 // Deprecation warning
880 if ($form_name) {
881 dol_syslog(__METHOD__.": form_name parameter is deprecated", LOG_WARNING);
882 }
883
884 global $langs, $conf;
885
886 $out = '';
887
888 if (!is_array($arrayofcolors) || count($arrayofcolors) < 1) {
889 // Case of selection of any color
890 $langs->load("other");
891 if (empty($conf->dol_use_jmobile) && !empty($conf->use_javascript_ajax) && !getDolGlobalInt('MAIN_USE_HTML5_COLOR_SELECTOR')) {
892 $out .= '<link rel="stylesheet" media="screen" type="text/css" href="'.DOL_URL_ROOT.'/public/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css" />';
893 $out .= '<script nonce="'.getNonce().'" type="text/javascript" src="'.DOL_URL_ROOT.'/public/includes/jquery/plugins/jpicker/jpicker-1.1.6.js"></script>';
894 $out .= '<script nonce="'.getNonce().'" type="text/javascript">
895 jQuery(document).ready(function(){
896 var originalhex = null;
897 $(\'#colorpicker'.$prefix.'\').jPicker( {
898 window: {
899 title: \''.dol_escape_js($langs->trans("SelectAColor")).'\', /* any title for the jPicker window itself - displays "Drag Markers To Pick A Color" if left null */
900 effects:
901 {
902 type: \'show\', /* effect used to show/hide an expandable picker. Acceptable values "slide", "show", "fade" */
903 speed:
904 {
905 show: \'fast\', /* duration of "show" effect. Acceptable values are "fast", "slow", or time in ms */
906 hide: \'fast\' /* duration of "hide" effect. Acceptable values are "fast", "slow", or time in ms */
907 }
908 },
909 position:
910 {
911 x: \'screenCenter\', /* acceptable values "left", "center", "right", "screenCenter", or relative px value */
912 y: \'center\' /* acceptable values "top", "bottom", "center", or relative px value */
913 },
914 },
915 images: {
916 clientPath: \''.DOL_URL_ROOT.'/public/includes/jquery/plugins/jpicker/images/\',
917 picker: { file: \'../../../../../../theme/common/colorpicker.png\', width: 14, height: 14 }
918 },
919 localization: // alter these to change the text presented by the picker (e.g. different language)
920 {
921 text:
922 {
923 title: \''.dol_escape_js($langs->trans("SelectAColor")).'\',
924 newColor: \''.dol_escape_js($langs->trans("New")).'\',
925 currentColor: \''.dol_escape_js($langs->trans("Current")).'\',
926 ok: \''.dol_escape_js($langs->trans("Validate")).'\',
927 cancel: \''.dol_escape_js($langs->trans("Cancel")).'\'
928 }
929 }
930 },
931 function(color, context) { console.log("close color selector"); },
932 function(color, context) { var hex = color.val(\'hex\'); console.log("new color selected in jpicker "+hex+\' setpropertyonselect='.dol_escape_js($setpropertyonselect).'\');';
933 if ($setpropertyonselect) {
934 $out .= 'if (originalhex == null) {';
935 $out .= ' originalhex = getComputedStyle(document.querySelector(":root")).getPropertyValue(\'--'.dol_escape_js($setpropertyonselect).'\');';
936 $out .= ' console.log("original color is saved into originalhex = "+originalhex);';
937 $out .= '}';
938 $out .= 'if (hex != null) {';
939 $out .= ' document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', \'#\'+hex);';
940 $out .= '}';
941 }
942 $out .= '},
943 function(color, context) {
944 console.log("cancel selection of color");';
945 if ($setpropertyonselect) {
946 $out .= 'if (originalhex != null) {
947 console.log("Restore old color "+originalhex);
948 document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', originalhex);
949 }';
950 }
951 $out .= '
952 }
953 );
954 });
955 </script>';
956 $out .= '<input id="colorpicker'.$prefix.'" name="'.$prefix.'" size="6" maxlength="7" class="colorpicker flat valignmiddle'.($morecss ? ' '.$morecss : '').'" type="text" value="'.dol_escape_htmltag($set_color).'" />';
957 } else {
958 $color = ($set_color !== '' ? $set_color : ($default !== '' ? $default : 'FFFFFF'));
959 $out .= '<input id="colorpicker'.$prefix.'" name="'.$prefix.'" size="6" maxlength="7" class="colorpicker flat input-nobottom colorselector valignmiddle '.($morecss ? ' '.$morecss : '').'" type="color" data-default="'.$default.'" value="'.dol_escape_htmltag(preg_match('/^#/', $color) ? $color : '#'.$color).'" />';
960 $out .= '<script nonce="'.getNonce().'" type="text/javascript">
961 jQuery(document).ready(function(){
962 var originalhex = null;
963 jQuery("#colorpicker'.$prefix.'").on(\'change\', function() {
964 var hex = jQuery("#colorpicker'.$prefix.'").val();
965 console.log("new color selected in input color "+hex+\' setpropertyonselect='.dol_escape_js($setpropertyonselect).'\');';
966 if ($setpropertyonselect) {
967 $out .= 'if (originalhex == null) {';
968 $out .= ' originalhex = getComputedStyle(document.querySelector(":root")).getPropertyValue(\'--'.dol_escape_js($setpropertyonselect).'\');';
969 $out .= ' console.log("original color is saved into originalhex = "+originalhex);';
970 $out .= '}';
971 $out .= 'if (hex != null) {';
972 $out .= ' document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', hex);';
973 $out .= '}';
974 }
975 $out .= '
976 });
977 });
978 </script>';
979 }
980 } else {
981 // In most cases, this is not used. We used instead function with no specific list of colors
982 if (empty($conf->dol_use_jmobile) && !empty($conf->use_javascript_ajax)) {
983 $out .= '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/public/includes/jquery/plugins/colorpicker/jquery.colorpicker.css" type="text/css" media="screen" />';
984 $out .= '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/public/includes/jquery/plugins/colorpicker/jquery.colorpicker.js" type="text/javascript"></script>';
985 $out .= '<script nonce="'.getNonce().'" type="text/javascript">
986 jQuery(document).ready(function(){
987 jQuery(\'#colorpicker'.$prefix.'\').colorpicker({
988 size: 14,
989 label: \'\',
990 hide: true
991 });
992 });
993 </script>';
994 }
995 $out .= '<select id="colorpicker'.$prefix.'" class="colorpicker flat'.($morecss ? ' '.$morecss : '').'" name="'.$prefix.'">';
996 //print '<option value="-1">&nbsp;</option>';
997 foreach ($arrayofcolors as $val) {
998 $out .= '<option value="'.$val.'"';
999 if ($set_color == $val) {
1000 $out .= ' selected';
1001 }
1002 $out .= '>'.$val.'</option>';
1003 }
1004 $out .= '</select>';
1005 }
1006
1007 return $out;
1008 }
1009
1010 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1021 public function CreateColorIcon($color, $module, $name, $x = 12, $y = 12)
1022 {
1023 // phpcs:enable
1024 global $conf;
1025
1026 $file = $conf->$module->dir_temp.'/'.$name.'.png';
1027
1028 // We create temp directory
1029 if (!file_exists($conf->$module->dir_temp)) {
1030 dol_mkdir($conf->$module->dir_temp);
1031 }
1032
1033 // On cree l'image en vraies couleurs
1034 $image = imagecreatetruecolor($x, $y);
1035
1036 $color = substr($color, 1, 6);
1037
1038 $red = hexdec(substr($color, 0, 2)); // Red channel conversion
1039 $green = hexdec(substr($color, 2, 2)); // Green channel conversion
1040 $blue = hexdec(substr($color, 4, 2)); // Blue channel conversion
1041
1042 $couleur = imagecolorallocate($image, $red, $green, $blue);
1043 //print $red.$green.$blue;
1044 imagefill($image, 0, 0, $couleur); // Fill the image
1045 // Create the colr and store it in a variable to maintain it
1046 imagepng($image, $file); // Returns an image in PNG format
1047 imagedestroy($image);
1048 }
1049
1050 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1059 public function select_dayofweek($selected = '', $htmlname = 'weekid', $useempty = 0)
1060 {
1061 // phpcs:enable
1062 global $langs;
1063
1064 $week = array(
1065 0 => $langs->trans("Day0"),
1066 1 => $langs->trans("Day1"),
1067 2 => $langs->trans("Day2"),
1068 3 => $langs->trans("Day3"),
1069 4 => $langs->trans("Day4"),
1070 5 => $langs->trans("Day5"),
1071 6 => $langs->trans("Day6")
1072 );
1073
1074 $select_week = '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
1075 if ($useempty) {
1076 $select_week .= '<option value="-1">&nbsp;</option>';
1077 }
1078 foreach ($week as $key => $val) {
1079 if ($selected == $key) {
1080 $select_week .= '<option value="'.$key.'" selected>';
1081 } else {
1082 $select_week .= '<option value="'.$key.'">';
1083 }
1084 $select_week .= $val;
1085 $select_week .= '</option>';
1086 }
1087 $select_week .= '</select>';
1088
1089 $select_week .= ajax_combobox($htmlname);
1090
1091 return $select_week;
1092 }
1093
1104 public function selectDay($selected = '', $htmlname = 'dayid', $useempty = 0, $morecss = 'minwidth50 maxwidth75imp valignmiddle', $addjscombo = false)
1105 {
1106 $select_day = '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
1107 if ($useempty) {
1108 $select_day .= '<option value="0">&nbsp;</option>';
1109 }
1110 for ($i = 1; $i <= 31; $i++) {
1111 if ((int) $selected == $i) {
1112 $select_day .= '<option value="'.$i.'" selected>';
1113 } else {
1114 $select_day .= '<option value="'.$i.'">';
1115 }
1116 $select_day .= sprintf("%02d", $i);
1117 $select_day .= '</option>';
1118 }
1119 $select_day .= '</select>';
1120
1121 // Add code for jquery to use multiselect
1122 if ($addjscombo) {
1123 // Enhance with select2
1124 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1125 $select_day .= ajax_combobox($htmlname);
1126 }
1127
1128 return $select_day;
1129 }
1130
1131 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1143 public function select_month($selected = '', $htmlname = 'monthid', $useempty = 0, $longlabel = 0, $morecss = 'minwidth50 maxwidth75imp valignmiddle', $addjscombo = false)
1144 {
1145 // phpcs:enable
1146 global $langs;
1147
1148 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
1149
1150 if ($longlabel) {
1151 $montharray = monthArray($langs, 0); // Get array of month with long labels
1152 } else {
1153 $montharray = monthArray($langs, 1); // Get array of month with short labels
1154 }
1155
1156 $select_month = '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
1157 if ($useempty) {
1158 if (is_numeric($useempty)) {
1159 $select_month .= '<option value="0">&nbsp;</option>';
1160 } else {
1161 $select_month .= '<option value="-1">'.$useempty.'</option>';
1162 }
1163 }
1164 foreach ($montharray as $key => $val) {
1165 if ((int) $selected == $key) {
1166 $select_month .= '<option value="'.$key.'" selected>';
1167 } else {
1168 $select_month .= '<option value="'.$key.'">';
1169 }
1170 $select_month .= $val;
1171 $select_month .= '</option>';
1172 }
1173 $select_month .= '</select>';
1174
1175 // Add code for jquery to use multiselect
1176 if ($addjscombo) {
1177 // Enhance with select2
1178 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1179 $select_month .= ajax_combobox($htmlname);
1180 }
1181
1182 return $select_month;
1183 }
1184
1185 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1202 public function select_year($selected = '', $htmlname = 'yearid', $useempty = 0, $min_year = 10, $max_year = 5, $offset = 0, $invert = 0, $option = '', $morecss = 'valignmiddle maxwidth75imp', $addjscombo = false)
1203 {
1204 // phpcs:enable
1205 print $this->selectyear($selected, $htmlname, $useempty, $min_year, $max_year, $offset, $invert, $option, $morecss, $addjscombo);
1206 }
1207
1223 public function selectyear($selected = '', $htmlname = 'yearid', $useempty = 0, $min_year = 10, $max_year = 5, $offset = 0, $invert = 0, $option = '', $morecss = 'valignmiddle width75', $addjscombo = false)
1224 {
1225 $out = '';
1226
1227 $currentyear = idate("Y") + $offset;
1228 $max_year = $currentyear + $max_year;
1229 $min_year = $currentyear - $min_year;
1230 if (empty($selected) && empty($useempty)) {
1231 $selected = $currentyear;
1232 }
1233
1234 $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'"'.$option.' >';
1235 if ($useempty) {
1236 $selected_html = '';
1237 if ((string) $selected == '') {
1238 $selected_html = ' selected';
1239 }
1240 $out .= '<option value=""'.$selected_html.'>&nbsp;</option>';
1241 }
1242 if (!$invert) {
1243 for ($y = $max_year; $y >= $min_year; $y--) {
1244 $selected_html = '';
1245 if ((int) $selected > 0 && $y == (int) $selected) {
1246 $selected_html = ' selected';
1247 }
1248 $out .= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
1249 }
1250 } else {
1251 for ($y = $min_year; $y <= $max_year; $y++) {
1252 $selected_html = '';
1253 if ((int) $selected > 0 && $y == (int) $selected) {
1254 $selected_html = ' selected';
1255 }
1256 $out .= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
1257 }
1258 }
1259 $out .= "</select>\n";
1260
1261 // Add code for jquery to use multiselect
1262 if ($addjscombo) {
1263 // Enhance with select2
1264 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1265 $out .= ajax_combobox($htmlname);
1266 }
1267
1268 return $out;
1269 }
1270
1271
1280 public static function getBoxesArea($user, $areacode)
1281 {
1282 global $conf, $langs, $db;
1283
1284 include_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
1285 // From include
1286 '
1287 @phan-var-force ModeleBoxes[] $boxactivated
1288 @phan-var-force int[] $boxidactivatedforuser
1289 ';
1290
1291 $confuserzone = 'MAIN_BOXES_'.$areacode;
1292
1293
1294
1295 // $boxactivated will be array of boxes enabled into global setup
1296 // $boxidactivatedforuser will be array of boxes chose by user
1297
1298 $selectboxlist = '';
1299 $boxactivated = InfoBox::listBoxes($db, 'activated', (int) $areacode, (empty($user->conf->$confuserzone) ? null : $user), array(), 0); // Search boxes of common+user (or common only if user has no specific setup)
1300
1301 $boxidactivatedforuser = array();
1302 foreach ($boxactivated as $box) {
1303 if (empty($user->conf->$confuserzone) || $box->fk_user == $user->id) {
1304 $boxidactivatedforuser[$box->id] = $box->id; // We keep only boxes to show for user
1305 }
1306
1307 if (!empty($box->lang)) {
1308 $langs->loadLangs(array($box->lang));
1309 $box->boxlabel = $langs->transnoentitiesnoconv($box->boxlabel);
1310 }
1311 }
1312
1313
1314 // Define selectboxlist
1315 $arrayboxtoactivatelabel = array();
1316 if (getDolUserString($confuserzone)) {
1317 $boxorder = '';
1318 $langs->load("boxes"); // Load label of boxes
1319 foreach ($boxactivated as $box) {
1320 if (!empty($boxidactivatedforuser[$box->id])) {
1321 continue; // Already visible for user
1322 }
1323
1324 $label = $langs->transnoentitiesnoconv($box->boxlabel);
1325 //if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph").')';
1326 if (preg_match('/graph/', $box->class) && $conf->browser->layout != 'phone') {
1327 $label .= ' <span class="fas fa-chart-bar"></span>';
1328 }
1329 $arrayboxtoactivatelabel[$box->id] = array('label' => $label, 'data-html' => img_picto('', $box->boximg, 'class="pictofixedwidth valignmiddle"').'<span class="valignmiddle">'.$langs->trans($label).'</span>'); // We keep only boxes not shown for user, to show into combo list
1330 }
1331 foreach ($boxidactivatedforuser as $boxid) {
1332 if (empty($boxorder)) {
1333 $boxorder .= 'A:';
1334 }
1335 $boxorder .= $boxid.',';
1336 }
1337
1338 //var_dump($boxidactivatedforuser);
1339
1340 // Class Form must have been already loaded
1341 $widthforwidget = 'width200';
1342 $selectboxlist .= '<!-- Form with select box list -->'."\n";
1343 $selectboxlist .= '<form id="addbox" class="parentonrightofpage" name="addbox" method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
1344 $selectboxlist .= '<input type="hidden" name="token" value="'.newToken().'">';
1345 $selectboxlist .= '<input type="hidden" name="addbox" value="addbox">';
1346 $selectboxlist .= '<input type="hidden" name="userid" value="'.$user->id.'">';
1347 $selectboxlist .= '<input type="hidden" name="areacode" value="'.$areacode.'">';
1348 $selectboxlist .= '<input type="hidden" name="boxorder" value="'.$boxorder.'">';
1349 $selectboxlist .= Form::selectarray('boxcombo', $arrayboxtoactivatelabel, -1, $langs->trans("ChooseBoxToAdd").'...', 0, 0, '', 0, 0, 0, 'ASC', 'noborderfocus selectwidget max'.$widthforwidget.' hideonprint onrightofpage', 0, 'hidden selected', 0, 0);
1350 if (!empty($conf->use_javascript_ajax)) {
1351 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1352 $selectboxlist .= ajax_combobox("boxcombo", array(), 0, 0, 'resolve', '-1', 'onrightofpage '.$widthforwidget);
1353 }
1354 if (empty($conf->use_javascript_ajax)) {
1355 $selectboxlist .= ' <input type="submit" class="button" value="'.$langs->trans("AddBox").'">';
1356 }
1357 $selectboxlist .= '</form>';
1358 }
1359
1360 // Javascript code for dynamic actions
1361 if (!empty($conf->use_javascript_ajax)) {
1362 $selectboxlist .= '<script nonce="'.getNonce().'" type="text/javascript">
1363
1364 // To update list of activated boxes
1365 function updateBoxOrder(closing) {
1366 var left_list = cleanSerialize(jQuery("#boxhalfleft").sortable("serialize"));
1367 var right_list = cleanSerialize(jQuery("#boxhalfright").sortable("serialize"));
1368 var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
1369 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
1370 {
1371 jQuery.ajax({
1372 url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=1&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
1373 async: false
1374 });
1375 // We force reload to be sure to get all boxes into list
1376 window.location.search=\'mainmenu='.GETPOST("mainmenu", "aZ09").'&leftmenu='.GETPOST('leftmenu', "aZ09").'&action=delbox&token='.newToken().'\';
1377 }
1378 else
1379 {
1380 jQuery.ajax({
1381 url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=\'+closing+\'&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
1382 async: true
1383 });
1384 }
1385 }
1386
1387 jQuery(document).ready(function() {
1388 jQuery("#boxcombo").change(function() {
1389 var boxid=jQuery("#boxcombo").val();
1390 if (boxid > 0) {
1391 console.log("A box widget has been selected for addition, we call ajax page to add it.")
1392 var left_list = cleanSerialize(jQuery("#boxhalfleft").sortable("serialize"));
1393 var right_list = cleanSerialize(jQuery("#boxhalfright").sortable("serialize"));
1394 var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
1395 jQuery.ajax({
1396 url: \''.DOL_URL_ROOT.'/core/ajax/box.php?boxorder=\'+boxorder+\'&boxid=\'+boxid+\'&zone='.$areacode.'&userid='.$user->id.'\'
1397 }).done(function() {
1398 window.location.search=\'mainmenu='.GETPOST("mainmenu", "aZ09").'&leftmenu='.GETPOST('leftmenu', "aZ09").'\';
1399 });
1400 }
1401 });';
1402 if (!count($arrayboxtoactivatelabel)) {
1403 $selectboxlist .= 'jQuery("#boxcombo").hide();';
1404 }
1405 $selectboxlist .= '
1406
1407 jQuery("#boxhalfleft, #boxhalfright").sortable({
1408 handle: \'.boxhandle\',
1409 revert: \'invalid\',
1410 items: \'.boxdraggable\',
1411 containment: \'document\',
1412 connectWith: \'#boxhalfleft, #boxhalfright\',
1413 stop: function(event, ui) {
1414 console.log("We moved box so we call updateBoxOrder with ajax actions");
1415 updateBoxOrder(1); /* 1 to avoid message after a move */
1416 }
1417 });
1418
1419 jQuery(".boxclose").click(function() {
1420 var self = this; // because JQuery can modify this
1421 var boxid = self.id.substring(8);
1422 if (boxid > 0) {
1423 var label = jQuery(\'#boxlabelentry\'+boxid).val();
1424 console.log("We close box "+boxid);
1425 jQuery(\'#boxto_\'+boxid).remove();
1426 jQuery(\'#boxcombo\').append(new Option(label, boxid));
1427 updateBoxOrder(1); /* 1 to avoid message after a remove */
1428 }
1429 });
1430
1431 });'."\n";
1432
1433 $selectboxlist .= '</script>'."\n";
1434 }
1435
1436 // Define boxlista and boxlistb
1437 $boxlista = '';
1438 $boxlistb = '';
1439 $nbboxactivated = count($boxidactivatedforuser);
1440
1441 if ($nbboxactivated) {
1442 // Load translation files required by the page
1443 $langs->loadLangs(array("boxes", "projects"));
1444
1445 $emptybox = new ModeleBoxes($db);
1446
1447 $boxlista .= "\n<!-- Box left container -->\n";
1448
1449 // Define $box_max_lines
1450 $box_max_lines = getDolUserInt('MAIN_SIZE_SHORTLIST_LIMIT', getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5));
1451
1452 $ii = 0;
1453 foreach ($boxactivated as $key => $box) {
1454 if ((!empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) {
1455 continue;
1456 }
1457 if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) {
1458 $box->box_order = 'A'.sprintf("%02d", ($ii + 1)); // When box_order was not yet set to Axx or Bxx and is still 0
1459 }
1460 if (preg_match('/^A/i', $box->box_order)) { // column A
1461 $ii++;
1462 //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1463 //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1464 // Show box
1465 $box->loadBox($box_max_lines);
1466 $boxlista .= $box->showBox(null, null, 1);
1467 }
1468 }
1469
1470 if ($conf->browser->layout != 'phone') {
1471 $emptybox->box_id = 'A';
1472 $emptybox->info_box_head = array();
1473 $emptybox->info_box_contents = array();
1474 $boxlista .= $emptybox->showBox(array(), array(), 1);
1475 }
1476 $boxlista .= "<!-- End box left container -->\n";
1477
1478 $boxlistb .= "\n<!-- Box right container -->\n";
1479
1480 $ii = 0;
1481 foreach ($boxactivated as $key => $box) {
1482 if ((!empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) {
1483 continue;
1484 }
1485 if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) {
1486 $box->box_order = 'B'.sprintf("%02d", ($ii + 1)); // When box_order was not yet set to Axx or Bxx and is still 0
1487 }
1488 if (preg_match('/^B/i', $box->box_order)) { // colonne B
1489 $ii++;
1490 //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1491 //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1492 // Show box
1493 $box->loadBox($box_max_lines);
1494 $boxlistb .= $box->showBox(null, null, 1);
1495 }
1496 }
1497
1498 if ($conf->browser->layout != 'phone') {
1499 $emptybox->box_id = 'B';
1500 $emptybox->info_box_head = array();
1501 $emptybox->info_box_contents = array();
1502 $boxlistb .= $emptybox->showBox(array(), array(), 1);
1503 }
1504
1505 $boxlistb .= "<!-- End box right container -->\n";
1506 }
1507
1508 return array('selectboxlist' => count($boxactivated) ? $selectboxlist : '', 'boxactivated' => $boxactivated, 'boxlista' => $boxlista, 'boxlistb' => $boxlistb);
1509 }
1510
1511
1512 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1525 public function select_dictionary($htmlname, $dictionarytable, $keyfield = 'code', $labelfield = 'label', $selected = '', $useempty = 0, $moreattrib = '')
1526 {
1527 // phpcs:enable
1528 global $langs;
1529
1530 $langs->load("admin");
1531
1532 $sql = "SELECT rowid, ".$this->db->sanitize($keyfield).", ".$this->db->sanitize($labelfield);
1533 $sql .= " FROM ".$this->db->prefix().$dictionarytable;
1534 $sql .= $this->db->order($labelfield);
1535
1536 dol_syslog(get_class($this)."::select_dictionary", LOG_DEBUG);
1537 $result = $this->db->query($sql);
1538 if ($result) {
1539 $num = $this->db->num_rows($result);
1540 $i = 0;
1541 if ($num) {
1542 print '<select id="select'.$htmlname.'" class="flat selectdictionary" name="'.$htmlname.'"'.($moreattrib ? ' '.$moreattrib : '').'>';
1543 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
1544 print '<option value="-1">&nbsp;</option>';
1545 }
1546
1547 while ($i < $num) {
1548 $obj = $this->db->fetch_object($result);
1549 if ($selected == $obj->rowid || $selected == $obj->{$keyfield}) {
1550 print '<option value="'.$obj->{$keyfield}.'" selected>';
1551 } else {
1552 print '<option value="'.$obj->{$keyfield}.'">';
1553 }
1554 $label = ($langs->trans($dictionarytable.$obj->{$keyfield}) != $dictionarytable.$obj->{$labelfield} ? $langs->trans($dictionarytable.$obj->{$keyfield}) : $obj->{$labelfield});
1555 print $label;
1556 print '</option>';
1557 $i++;
1558 }
1559 print "</select>";
1560 } else {
1561 print $langs->trans("DictionaryEmpty");
1562 }
1563 } else {
1564 dol_print_error($this->db);
1565 }
1566 }
1567
1578 public function selectAutoManual($htmlname, $value = '', $option = 0, $disabled = false, $useempty = 0)
1579 {
1580 global $langs;
1581
1582 $automatic = "automatic";
1583 $manual = "manual";
1584 if ($option) {
1585 $automatic = "1";
1586 $manual = "0";
1587 }
1588
1589 $disabled = ($disabled ? ' disabled' : '');
1590
1591 $resultautomanual = '<select class="flat width100" id="'.$htmlname.'" name="'.$htmlname.'"'.$disabled.'>'."\n";
1592 if ($useempty) {
1593 $resultautomanual .= '<option value="-1"'.(($value < 0) ? ' selected' : '').'>&nbsp;</option>'."\n";
1594 }
1595 if (("$value" == 'automatic') || ($value == 1)) {
1596 $resultautomanual .= '<option value="'.$automatic.'" selected>'.$langs->trans("Automatic").'</option>'."\n";
1597 $resultautomanual .= '<option value="'.$manual.'">'.$langs->trans("Manual").'</option>'."\n";
1598 } else {
1599 $selected = (($useempty && $value != '0' && $value != 'manual') ? '' : ' selected');
1600 $resultautomanual .= '<option value="'.$automatic.'">'.$langs->trans("Automatic").'</option>'."\n";
1601 $resultautomanual .= '<option value="'.$manual.'"'.$selected.'>'.$langs->trans("Manual").'</option>'."\n";
1602 }
1603 $resultautomanual .= '</select>'."\n";
1604 return $resultautomanual;
1605 }
1606
1607
1618 public function selectGroupByField($object, $search_groupby, &$arrayofgroupby, $morecss = 'minwidth200 maxwidth250', $showempty = '1')
1619 {
1620 global $form;
1621
1622 $arrayofgroupbylabel = array();
1623 foreach ($arrayofgroupby as $key => $val) {
1624 $arrayofgroupbylabel[$key] = $val['label'];
1625 }
1626 $result = $form->selectarray('search_groupby', $arrayofgroupbylabel, $search_groupby, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
1627
1628 return $result;
1629 }
1630
1641 public function selectXAxisField($object, $search_xaxis, &$arrayofxaxis, $showempty = '1', $morecss = 'minwidth250 maxwidth500')
1642 {
1643 global $form;
1644
1645 $arrayofxaxislabel = array();
1646 foreach ($arrayofxaxis as $key => $val) {
1647 $arrayofxaxislabel[$key] = $val['label'];
1648 }
1649 $result = $form->selectarray('search_xaxis', $arrayofxaxislabel, $search_xaxis, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
1650
1651 return $result;
1652 }
1653}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition propal.php:281
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='', $placeholder='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:488
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
static selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='minwidth75', $addjscombo=1, $moreparamonempty='', $disablebademail=0, $nohtmlescape=0)
Return a HTML select string, built from an array of key+value.
Class to help generate other html components Only common components are here.
selectDay($selected='', $htmlname='dayid', $useempty=0, $morecss='minwidth50 maxwidth75imp valignmiddle', $addjscombo=false)
Return HTML combo list of day.
__construct($db)
Constructor.
static getBoxesArea($user, $areacode)
Get array with HTML tabs with widgets/boxes of a particular area including personalized choices of us...
select_revenue_stamp($selected='', $htmlname='revenuestamp', $country_code='')
Return list of revenue stamp for country.
select_ecotaxes($selected='', $htmlname='ecotaxe_id')
Return list of ecotaxes with label.
select_year($selected='', $htmlname='yearid', $useempty=0, $min_year=10, $max_year=5, $offset=0, $invert=0, $option='', $morecss='valignmiddle maxwidth75imp', $addjscombo=false)
Return HTML combo list of years.
selectAutoManual($htmlname, $value='', $option=0, $disabled=false, $useempty=0)
Return an html string with a select combo box to choose yes or no.
select_dayofweek($selected='', $htmlname='weekid', $useempty=0)
Return HTML combo list of week.
getHTMLScannerForm($jstoexecuteonadd='barcodescannerjs', $mode='all', $warehouseselect=0)
Return the HTML code for scanner tool.
select_dictionary($htmlname, $dictionarytable, $keyfield='code', $labelfield='label', $selected='', $useempty=0, $moreattrib='')
Return a HTML select list of a dictionary.
selectGroupByField($object, $search_groupby, &$arrayofgroupby, $morecss='minwidth200 maxwidth250', $showempty='1')
Return HTML select list to select a group by field.
selectXAxisField($object, $search_xaxis, &$arrayofxaxis, $showempty='1', $morecss='minwidth250 maxwidth500')
Return HTML select list to select a group by field.
select_month($selected='', $htmlname='monthid', $useempty=0, $longlabel=0, $morecss='minwidth50 maxwidth75imp valignmiddle', $addjscombo=false)
Return HTML combo list of month.
selectyear($selected='', $htmlname='yearid', $useempty=0, $min_year=10, $max_year=5, $offset=0, $invert=0, $option='', $morecss='valignmiddle width75', $addjscombo=false)
Return HTML combo list of years.
Class with static methods for building HTML components related to products Only components common to ...
static listBoxes($dbs, $mode, $zone, $user=null, $excludelist=array(), $includehidden=1)
Return array of boxes qualified for area and user.
Class ModeleBoxes.
monthArray($outputlangs, $short=0)
Return array of translated months or selected month.
getDolUserInt($key, $default=0, $tmpuser=null)
Return Dolibarr user constant int value.
getDolUserString($key, $default='', $tmpuser=null)
Return Dolibarr user constant string value.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
$conf db user
Active Directory does not allow anonymous connections.
Definition repair.php:166
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:165
a disabled