dolibarr 23.0.3
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-2025 Frédéric France <frederic.france@free.fr>
14 * Copyright (C) 2024-2025 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 $out = '';
78
79 $out .= '<!-- Popup for mass barcode scanning -->'."\n";
80 $out .= '<div class="div-for-modal-topright" style="padding: 15px">';
81 $out .= '<center>'.img_picto('', 'barcode', 'class="pictofixedwidth"').'<strong>Barcode scanner tool...</strong></center><br>';
82
83 if ($mode == 'product') {
84 $out .= '<input type="hidden" name="barcodemode" value="barcodeforproduct" id="barcodeforproduct">';
85 } elseif ($mode == 'lot') {
86 $out .= '<input type="hidden" name="barcodemode" value="barcodeforlotserial" id="barcodeforlotserial">';
87 } else { // $mode = 'all'
88 $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>';
89 $out .= '<input type="radio" name="barcodemode" value="barcodeforproduct" id="barcodeforproduct"> <label for="barcodeforproduct">Scan a product barcode</label><br>';
90 $out .= '<input type="radio" name="barcodemode" value="barcodeforlotserial" id="barcodeforlotserial"> <label for="barcodeforlotserial">Scan a product lot or serial number</label><br>';
91 }
92 $stringaddbarcode = $langs->trans("QtyToAddAfterBarcodeScan", "tmphtml");
93 $htmltoreplaceby = '<select name="selectaddorreplace"><option selected value="add">'.$langs->trans("Add").'</option><option value="replace">'.$langs->trans("ToReplace").'</option></select>';
94 $stringaddbarcode = str_replace("tmphtml", $htmltoreplaceby, $stringaddbarcode);
95 $out .= $stringaddbarcode.': <input type="text" name="barcodeproductqty" class="width40 right" value="1"><br>';
96 if ($warehouseselect > 0) {
97 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
98 $formproduct = new FormProduct($this->db);
99 $formproduct->loadWarehouses();
100 $out .= img_picto('', 'stock', 'class="pictofixedwidth"');
101 $out .= $formproduct->selectWarehouses('', "warehousenew", '', 0, 0, 0, '', 0, 1);
102 $out .= '<br>';
103 $out .= '<br>';
104 }
105 $out .= '<textarea type="text" name="barcodelist" class="centpercent" autofocus rows="'.ROWS_3.'" placeholder="'.dol_escape_htmltag($langs->trans("ScanOrTypeOrCopyPasteYourBarCodes")).'"></textarea>';
106
107 /*print '<br>'.$langs->trans("or").'<br>';
108
109 print '<br>';
110
111 print '<input type="text" name="barcodelotserial" class="width200"> &nbsp; &nbsp; Qty <input type="text" name="barcodelotserialqty" class="width50 right" value="1"><br>';
112 */
113 $out .= '<br>';
114 $out .= '<center>';
115 $out .= '<input type="submit" class="button marginleftonly marginrightonly" id ="exec'.dol_escape_js($jstoexecuteonadd).'" name="addscan" value="'.dol_escape_htmltag($langs->trans("Add")).'">';
116 $out .= '<input type="submit" class="button marginleftonly marginrightonly" name="cancel" value="'.dol_escape_htmltag($langs->trans("CloseWindow")).'">';
117 $out .= '</center>';
118 $out .= '<br>';
119 $out .= '<div type="text" id="scantoolmessage" class="scantoolmessage ok nopadding"></div>';
120
121 $out .= '<script nonce="'.getNonce().'">';
122 $out .= 'jQuery("#barcodeforautodetect, #barcodeforproduct, #barcodeforlotserial").click(function(){';
123 $out .= 'console.log("select choice");';
124 $out .= 'jQuery("#scantoolmessage").text("");';
125 $out .= '});'."\n";
126 $out .= '$("#exec'.dol_escape_js($jstoexecuteonadd).'").click(function(){
127 console.log("We call js to execute \''.dol_escape_js($jstoexecuteonadd).'\'");
128 '.dol_escape_js($jstoexecuteonadd).'();
129 return false; /* We want to stay on the scan tool */
130 })';
131 $out .= '</script>';
132
133 $out .= '</center>';
134 $out .= '</div>';
135
136 return $out;
137 }
138
139 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
150 public function select_export_model($selected = '', $htmlname = 'exportmodelid', $type = '', $useempty = 0, $fk_user = null)
151 {
152 // phpcs:enable
153 global $conf, $langs, $user;
154
155 $sql = "SELECT rowid, label, fk_user";
156 $sql .= " FROM ".$this->db->prefix()."export_model";
157 $sql .= " WHERE type = '".$this->db->escape($type)."'";
158 if (!getDolGlobalString('EXPORTS_SHARE_MODELS')) { // EXPORTS_SHARE_MODELS means all templates are visible, whatever is owner.
159 $sql .= " AND fk_user IN (0, ".((int) $fk_user).")";
160 }
161 $sql .= " ORDER BY label";
162 $result = $this->db->query($sql);
163 if ($result) {
164 print '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
165 if ($useempty) {
166 print '<option value="-1">&nbsp;</option>';
167 }
168
169 $tmpuser = new User($this->db);
170
171 $num = $this->db->num_rows($result);
172 $i = 0;
173 while ($i < $num) {
174 $obj = $this->db->fetch_object($result);
175
176 $label = $obj->label;
177 if ($obj->fk_user == 0) {
178 $label .= ' <span class="opacitymedium">('.$langs->trans("Everybody").')</span>';
179 } elseif ($obj->fk_user > 0) {
180 $tmpuser->fetch($obj->fk_user);
181 $label .= ' <span class="opacitymedium">('.$tmpuser->getFullName($langs).')</span>';
182 }
183
184 if ($selected == $obj->rowid) {
185 print '<option value="'.$obj->rowid.'" selected data-html="'.dol_escape_htmltag($label).'">';
186 } else {
187 print '<option value="'.$obj->rowid.'" data-html="'.dol_escape_htmltag($label).'">';
188 }
189 print $label;
190 print '</option>';
191 $i++;
192 }
193 print "</select>";
194 print ajax_combobox($htmlname);
195 } else {
196 dol_print_error($this->db);
197 }
198 }
199
200
201 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
212 public function select_import_model($selected = '', $htmlname = 'importmodelid', $type = '', $useempty = 0, $fk_user = null)
213 {
214 // phpcs:enable
215 global $conf, $langs, $user;
216
217 $sql = "SELECT rowid, label, fk_user";
218 $sql .= " FROM ".$this->db->prefix()."import_model";
219 $sql .= " WHERE type = '".$this->db->escape($type)."'";
220 if (!getDolGlobalString('EXPORTS_SHARE_MODELS')) { // EXPORTS_SHARE_MODELS means all templates are visible, whatever is owner.
221 $sql .= " AND fk_user IN (0, ".((int) $fk_user).")";
222 }
223 $sql .= " ORDER BY label";
224 $result = $this->db->query($sql);
225 if ($result) {
226 print '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
227 if ($useempty) {
228 print '<option value="-1">&nbsp;</option>';
229 }
230
231 $tmpuser = new User($this->db);
232
233 $num = $this->db->num_rows($result);
234 $i = 0;
235 while ($i < $num) {
236 $obj = $this->db->fetch_object($result);
237
238 $label = $obj->label;
239 if ($obj->fk_user == 0) {
240 $label .= ' <span class="opacitymedium">('.$langs->trans("Everybody").')</span>';
241 } elseif ($obj->fk_user > 0) {
242 $tmpuser->fetch($obj->fk_user);
243 $label .= ' <span class="opacitymedium">('.$tmpuser->getFullName($langs).')</span>';
244 }
245
246 if ($selected == $obj->rowid) {
247 print '<option value="'.$obj->rowid.'" selected data-html="'.dol_escape_htmltag($label).'">';
248 } else {
249 print '<option value="'.$obj->rowid.'" data-html="'.dol_escape_htmltag($label).'">';
250 }
251 print $label;
252 print '</option>';
253 $i++;
254 }
255 print "</select>";
256 print ajax_combobox($htmlname);
257 } else {
258 dol_print_error($this->db);
259 }
260 }
261
262
263 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
271 public function select_ecotaxes($selected = '', $htmlname = 'ecotaxe_id')
272 {
273 // phpcs:enable
274 global $langs;
275
276 $sql = "SELECT e.rowid, e.code, e.label, e.price, e.organization,";
277 $sql .= " c.label as country";
278 $sql .= " FROM ".$this->db->prefix()."c_ecotaxe as e,".$this->db->prefix()."c_country as c";
279 $sql .= " WHERE e.active = 1 AND e.fk_pays = c.rowid";
280 $sql .= " ORDER BY country, e.organization ASC, e.code ASC";
281
282 dol_syslog(get_class($this).'::select_ecotaxes', LOG_DEBUG);
283 $resql = $this->db->query($sql);
284 if ($resql) {
285 print '<select class="flat" name="'.$htmlname.'">';
286 $num = $this->db->num_rows($resql);
287 $i = 0;
288 print '<option value="-1">&nbsp;</option>'."\n";
289 if ($num) {
290 while ($i < $num) {
291 $obj = $this->db->fetch_object($resql);
292 if ($selected && $selected == $obj->rowid) {
293 print '<option value="'.$obj->rowid.'" selected>';
294 } else {
295 print '<option value="'.$obj->rowid.'">';
296 //print '<option onmouseover="showtip(\''.$obj->label.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
297 }
298 $selectOptionValue = $obj->code.' - '.$obj->label.' : '.price($obj->price).' '.$langs->trans("HT").' ('.$obj->organization.')';
299 print $selectOptionValue;
300 print '</option>';
301 $i++;
302 }
303 }
304 print '</select>';
305 return 0;
306 } else {
307 dol_print_error($this->db);
308 return 1;
309 }
310 }
311
312
313 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
322 public function select_revenue_stamp($selected = '', $htmlname = 'revenuestamp', $country_code = '')
323 {
324 // phpcs:enable
325 global $langs;
326
327 $out = '';
328
329 $sql = "SELECT r.taux, r.revenuestamp_type";
330 $sql .= " FROM ".$this->db->prefix()."c_revenuestamp as r,".$this->db->prefix()."c_country as c";
331 $sql .= " WHERE r.active = 1 AND r.fk_pays = c.rowid";
332 $sql .= " AND c.code = '".$this->db->escape($country_code)."'";
333
334 dol_syslog(get_class($this).'::select_revenue_stamp', LOG_DEBUG);
335 $resql = $this->db->query($sql);
336 if ($resql) {
337 $out .= '<select class="flat" name="'.$htmlname.'">';
338 $num = $this->db->num_rows($resql);
339 $i = 0;
340 $out .= '<option value="0">&nbsp;</option>'."\n";
341 if ($num) {
342 while ($i < $num) {
343 $obj = $this->db->fetch_object($resql);
344 if (($selected && $selected == $obj->taux) || $num == 1) {
345 $out .= '<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').' selected>';
346 } else {
347 $out .= '<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').'>';
348 }
349 $out .= $obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '');
350 $out .= '</option>';
351 $i++;
352 }
353 }
354 $out .= '</select>';
355 return $out;
356 } else {
357 dol_print_error($this->db);
358 return '';
359 }
360 }
361
362
363 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
376 public function select_percent($selected = 0, $htmlname = 'percent', $disabled = 0, $increment = 5, $start = 0, $end = 100, $showempty = 0)
377 {
378 // phpcs:enable
379 $return = '<select class="flat maxwidth75 right" name="'.$htmlname.'" '.($disabled ? 'disabled' : '').'>';
380 if ($showempty) {
381 $return .= '<option value="-1"'.(($selected == -1 || $selected == '') ? ' selected' : '').'>&nbsp;</option>';
382 }
383
384 for ($i = $start; $i <= $end; $i += $increment) {
385 if ($selected != '' && (int) $selected == $i) {
386 $return .= '<option value="'.$i.'" selected>';
387 } else {
388 $return .= '<option value="'.$i.'">';
389 }
390 $return .= $i.' % ';
391 $return .= '</option>';
392 }
393
394 $return .= '</select>';
395
396 return $return;
397 }
398
399 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
412 public function select_categories($type, $selected = 0, $htmlname = 'search_categ', $nocateg = 0, $showempty = 1, $morecss = '')
413 {
414 // phpcs:enable
415 global $conf, $langs;
416 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
417
418 // For backward compatibility
419 if (is_numeric($type)) {
420 dol_syslog(__METHOD__.': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING);
421 }
422
423 // Load list of "categories"
424 $static_categs = new Categorie($this->db);
425 $tab_categs = $static_categs->get_full_arbo($type);
426
427 $moreforfilter = '';
428
429 // Print a select with each of them
430 $moreforfilter .= '<select class="flat minwidth100'.($morecss ? ' '.$morecss : '').'" id="select_categ_'.$htmlname.'" name="'.$htmlname.'">';
431 if ($showempty) {
432 $textforempty = ' ';
433 if (!empty($conf->use_javascript_ajax)) {
434 $textforempty = '&nbsp;'; // If we use ajaxcombo, we need &nbsp; here to avoid to have an empty element that is too small.
435 }
436 if (!is_numeric($showempty)) {
437 $textforempty = $showempty;
438 }
439 $moreforfilter .= '<option class="optiongrey" value="'.($showempty < 0 ? $showempty : -1).'"'.($selected == $showempty ? ' selected' : '');
440 //$moreforfilter .= ' data-html="'.dol_escape_htmltag($textforempty).'"';
441 $moreforfilter .= '>'.dol_escape_htmltag($textforempty).'</option>'."\n";
442 }
443
444 if (is_array($tab_categs)) {
445 foreach ($tab_categs as $categ) {
446 $moreforfilter .= '<option value="'.$categ['id'].'"';
447 if ($categ['id'] == $selected) {
448 $moreforfilter .= ' selected';
449 }
450 $moreforfilter .= ' data-html="'.dol_escape_htmltag(img_picto('', 'category', 'class="pictofixedwidth" style="color: #'.$categ['color'].'"').dol_trunc($categ['fulllabel'], 50, 'middle')).'"';
451 $moreforfilter .= '>'.dol_trunc($categ['fulllabel'], 50, 'middle').'</option>';
452 }
453 }
454 if ($nocateg) {
455 $langs->load("categories");
456 $moreforfilter .= '<option value="-2"'.($selected == -2 ? ' selected' : '').'>- '.$langs->trans("NotCategorized").' -</option>';
457 }
458 $moreforfilter .= '</select>';
459
460 // Enhance with select2
461 if ($conf->use_javascript_ajax) {
462 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
463 $comboenhancement = ajax_combobox('select_categ_'.$htmlname);
464 $moreforfilter .= $comboenhancement;
465 }
466
467 return $moreforfilter;
468 }
469
470
471 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
484 public function select_salesrepresentatives($selected, $htmlname, $user, $showstatus = 0, $showempty = 1, $morecss = '', $norepresentative = 0)
485 {
486 // phpcs:enable
487 global $conf, $langs, $hookmanager;
488 global $action;
489
490 $langs->load('users');
491
492 $out = '';
493
494 $reshook = $hookmanager->executeHooks('addSQLWhereFilterOnSelectSalesRep', array(), $this, $action);
495
496 // Select each sales and print them in a select input
497 $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'">';
498 if ($showempty) {
499 $textforempty = ' ';
500 if (!is_numeric($showempty)) {
501 $textforempty = $showempty;
502 }
503 if (!empty($conf->use_javascript_ajax) && $textforempty == ' ') {
504 $textforempty = '&nbsp;'; // If we use ajaxcombo, we need &nbsp; here to avoid to have an empty element that is too small.
505 }
506 $out .= '<option class="optiongrey" value="'.($showempty < 0 ? $showempty : -1).'"'.($selected == $showempty ? ' selected' : '').'>'.$textforempty.'</option>'."\n";
507 }
508
509 // Get list of users allowed to be viewed
510 $sql_usr = "SELECT u.rowid, u.lastname, u.firstname, u.statut as status, u.login, u.photo, u.gender, u.entity, u.admin";
511 $sql_usr .= " FROM ".$this->db->prefix()."user as u";
512
513 if (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
514 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
515 $sql_usr .= " WHERE u.entity IS NOT NULL"; // Show all users
516 } else {
517 $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')."))";
518 $sql_usr .= " OR u.entity = 0"; // Show always superadmin
519 }
520 } else {
521 $sql_usr .= " WHERE u.entity IN (".getEntity('user').")";
522 }
523
524 if (!$user->hasRight('user', 'user', 'lire')) {
525 $sql_usr .= " AND u.rowid = ".((int) $user->id);
526 }
527 if (!empty($user->socid)) {
528 $sql_usr .= " AND u.fk_soc = ".((int) $user->socid);
529 }
530 if (getDolUserString('USER_HIDE_NONEMPLOYEE_IN_COMBOBOX', getDolGlobalString('USER_HIDE_NONEMPLOYEE_IN_COMBOBOX'))) {
531 $sql_usr .= " AND u.employee <> 0";
532 }
533 if (getDolUserString('USER_HIDE_EXTERNAL_IN_COMBOBOX', getDolGlobalString('USER_HIDE_EXTERNAL_IN_COMBOBOX'))) {
534 $sql_usr .= " AND u.fk_soc IS NULL";
535 }
536 if (getDolUserString('USER_HIDE_INACTIVE_IN_COMBOBOX', getDolGlobalString('USER_HIDE_INACTIVE_IN_COMBOBOX'))) { // Can be set in setup of module User.
537 $sql_usr .= " AND u.statut <> 0";
538 }
539
540 //Add hook to filter on user (for example on usergroup define in custom modules)
541 if (!empty($reshook)) {
542 $sql_usr .= $hookmanager->resArray[0];
543 }
544
545 // Add existing sales representatives of thirdparty of external user
546 if (!$user->hasRight('user', 'user', 'lire') && $user->socid) {
547 $sql_usr .= " UNION ";
548 $sql_usr .= "SELECT u2.rowid, u2.lastname, u2.firstname, u2.statut as status, u2.login, u2.photo, u2.gender, u2.entity, u2.admin";
549 $sql_usr .= " FROM ".$this->db->prefix()."user as u2, ".$this->db->prefix()."societe_commerciaux as sc";
550
551 if (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
552 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
553 $sql_usr .= " WHERE u2.entity IS NOT NULL"; // Show all users
554 } else {
555 $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')."))";
556 }
557 } else {
558 $sql_usr .= " WHERE u2.entity IN (".getEntity('user').")";
559 }
560
561 $sql_usr .= " AND u2.rowid = sc.fk_user AND sc.fk_soc = ".((int) $user->socid);
562
563 //Add hook to filter on user (for example on usergroup define in custom modules)
564 if (!empty($reshook)) {
565 $sql_usr .= $hookmanager->resArray[1];
566 }
567 }
568
569 if (!getDolGlobalString('MAIN_FIRSTNAME_NAME_POSITION')) { // MAIN_FIRSTNAME_NAME_POSITION is 0 means firstname+lastname
570 $sql_usr .= " ORDER BY status DESC, firstname ASC, lastname ASC";
571 } else {
572 $sql_usr .= " ORDER BY status DESC, lastname ASC, firstname ASC";
573 }
574 //print $sql_usr;exit;
575
576 $resql_usr = $this->db->query($sql_usr);
577 if ($resql_usr) {
578 $userstatic = new User($this->db);
579
580 while ($obj_usr = $this->db->fetch_object($resql_usr)) {
581 $userstatic->id = $obj_usr->rowid;
582 $userstatic->lastname = $obj_usr->lastname;
583 $userstatic->firstname = $obj_usr->firstname;
584 $userstatic->photo = $obj_usr->photo;
585 $userstatic->status = $obj_usr->status;
586 $userstatic->entity = $obj_usr->entity;
587 $userstatic->admin = $obj_usr->admin;
588
589 $labeltoshow = dolGetFirstLastname($obj_usr->firstname, $obj_usr->lastname);
590 if (empty($obj_usr->firstname) && empty($obj_usr->lastname)) {
591 $labeltoshow = $obj_usr->login;
592 }
593
594 $out .= '<option value="'.$obj_usr->rowid.'"';
595 if ($obj_usr->rowid == $selected) {
596 $out .= ' selected';
597 }
598 $out .= ' data-html="';
599 $outhtml = $userstatic->getNomUrl(-3, '', 0, 1, 24, 1, 'login', '', 1).' ';
600 if ($showstatus >= 0 && $obj_usr->status == 0) {
601 $outhtml .= '<strike class="opacitymediumxxx">';
602 }
603 $outhtml .= $labeltoshow;
604 if ($showstatus >= 0 && $obj_usr->status == 0) {
605 $outhtml .= '</strike>';
606 }
607 $out .= dol_escape_htmltag($outhtml);
608 $out .= '">';
609
610 $out .= $labeltoshow;
611 // Complete name with more info
612 $moreinfo = 0;
613 if (getDolGlobalString('MAIN_SHOW_LOGIN')) {
614 $out .= ($moreinfo ? ' - ' : ' (').$obj_usr->login;
615 $moreinfo++;
616 }
617 if ($showstatus >= 0) {
618 if ($obj_usr->status == 1 && $showstatus == 1) {
619 $out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Enabled');
620 $moreinfo++;
621 }
622 if ($obj_usr->status == 0) {
623 $out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Disabled');
624 $moreinfo++;
625 }
626 }
627 $out .= ($moreinfo ? ')' : '');
628 $out .= '</option>';
629 }
630 $this->db->free($resql_usr);
631 } else {
632 dol_print_error($this->db);
633 }
634
635 if ($norepresentative) {
636 $langs->load("companies");
637 $out .= '<option value="-2"'.($selected == -2 ? ' selected' : '').'>- '.$langs->trans("NoSalesRepresentativeAffected").' -</option>';
638 }
639
640 $out .= '</select>';
641
642 // Enhance with select2
643 if ($conf->use_javascript_ajax) {
644 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
645
646 $comboenhancement = ajax_combobox($htmlname);
647 if ($comboenhancement) {
648 $out .= $comboenhancement;
649 }
650 }
651
652 return $out;
653 }
654
670 public function selectProjectTasks($selectedtask = 0, $projectid = 0, $htmlname = 'task_parent', $modeproject = 0, $modetask = 0, $mode = 0, $useempty = 0, $disablechildoftaskid = 0, $filteronprojstatus = '', $morecss = '')
671 {
672 global $user, $langs;
673
674 require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
675
676 //print $modeproject.'-'.$modetask;
677 $task = new Task($this->db);
678 $tasksarray = $task->getTasksArray($modetask ? $user : 0, $modeproject ? $user : 0, $projectid, 0, $mode, '', $filteronprojstatus);
679 if ($tasksarray) {
680 print '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
681 if ($useempty) {
682 print '<option value="0">&nbsp;</option>';
683 }
684 $j = 0;
685 $level = 0;
686 $this->_pLineSelect($j, 0, $tasksarray, $level, $selectedtask, $projectid, $disablechildoftaskid);
687 print '</select>';
688
689 print ajax_combobox($htmlname);
690 } else {
691 print '<div class="warning">'.$langs->trans("NoProject").'</div>';
692 }
693 }
694
707 private function _pLineSelect(&$inc, $parent, $lines, $level = 0, $selectedtask = 0, $selectedproject = 0, $disablechildoftaskid = 0)
708 {
709 global $langs, $user, $conf;
710
711 $lastprojectid = 0;
712
713 $numlines = count($lines);
714 for ($i = 0; $i < $numlines; $i++) {
715 if ($lines[$i]->fk_task_parent == $parent) {
716 //var_dump($selectedproject."--".$selectedtask."--".$lines[$i]->fk_project."_".$lines[$i]->id); // $lines[$i]->id may be empty if project has no lines
717
718 // Break on a new project
719 if ($parent == 0) { // We are on a task at first level
720 if ($lines[$i]->fk_project != $lastprojectid) { // Break found on project
721 if ($i > 0) {
722 print '<option value="0" disabled>----------</option>';
723 }
724 print '<option value="'.$lines[$i]->fk_project.'_0"';
725 if ($selectedproject == $lines[$i]->fk_project) {
726 print ' selected';
727 }
728
729 $labeltoshow = $lines[$i]->projectref;
730 //$labeltoshow .= ' '.$lines[$i]->projectlabel;
731 if (empty($lines[$i]->public)) {
732 //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')</span>';
733 $labeltoshow = img_picto($lines[$i]->projectlabel, 'project', 'class="pictofixedwidth"').$labeltoshow;
734 } else {
735 //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')</span>';
736 $labeltoshow = img_picto($lines[$i]->projectlabel, 'projectpub', 'class="pictofixedwidth"').$labeltoshow;
737 }
738
739 print ' data-html="'.dol_escape_htmltag($labeltoshow).'"';
740 print '>'; // Project -> Task
741 print $labeltoshow;
742 print "</option>\n";
743
744 $lastprojectid = $lines[$i]->fk_project;
745 $inc++;
746 }
747 }
748
749 $newdisablechildoftaskid = $disablechildoftaskid;
750
751 // Print task
752 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
753 // Check if we must disable entry
754 $disabled = 0;
755 if ($disablechildoftaskid && (($lines[$i]->id == $disablechildoftaskid || $lines[$i]->fk_task_parent == $disablechildoftaskid))) {
756 $disabled++;
757 if ($lines[$i]->fk_task_parent == $disablechildoftaskid) {
758 $newdisablechildoftaskid = $lines[$i]->id; // If task is child of a disabled parent, we will propagate id to disable next child too
759 }
760 }
761
762 print '<option value="'.$lines[$i]->fk_project.'_'.$lines[$i]->id.'"';
763 if (($lines[$i]->id == $selectedtask) || ($lines[$i]->fk_project.'_'.$lines[$i]->id == $selectedtask)) {
764 print ' selected';
765 }
766 if ($disabled) {
767 print ' disabled';
768 }
769
770 $labeltoshow = $lines[$i]->projectref;
771 //$labeltoshow .= ' '.$lines[$i]->projectlabel;
772 if (empty($lines[$i]->public)) {
773 //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')</span>';
774 $labeltoshow = img_picto($lines[$i]->projectlabel, 'project', 'class="pictofixedwidth"').$labeltoshow;
775 } else {
776 //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')</span>';
777 $labeltoshow = img_picto($lines[$i]->projectlabel, 'projectpub', 'class="pictofixedwidth"').$labeltoshow;
778 }
779 if ($lines[$i]->id) {
780 $labeltoshow .= ' > ';
781 }
782 for ($k = 0; $k < $level; $k++) {
783 $labeltoshow .= "&nbsp;&nbsp;&nbsp;";
784 }
785 $labeltoshow .= $lines[$i]->ref.' '.$lines[$i]->label;
786
787 print ' data-html="'.dol_escape_htmltag($labeltoshow).'"';
788 print '>';
789 print $labeltoshow;
790 print "</option>\n";
791 $inc++;
792 }
793
794 $level++;
795 if ($lines[$i]->id) {
796 $this->_pLineSelect($inc, $lines[$i]->id, $lines, $level, $selectedtask, $selectedproject, $newdisablechildoftaskid);
797 }
798 $level--;
799 }
800 }
801 }
802
803
812 public static function showColor($color, $textifnotdefined = '')
813 {
814 $textcolor = 'FFF';
815 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
816 if (colorIsLight($color)) {
817 $textcolor = '000';
818 }
819
820 $color = colorArrayToHex(colorStringToArray($color, array()), '');
821
822 if ($color) {
823 return '<input type="text" class="colorthumb" disabled style="padding: 1px; margin-top: 0; margin-bottom: 0; color: #'.$textcolor.'; background-color: #'.$color.'" value="'.$color.'">';
824 } else {
825 return $textifnotdefined;
826 }
827 }
828
829 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
842 public function select_color($set_color = '', $prefix = 'f_color', $form_name = '', $showcolorbox = 1, $arrayofcolors = [])
843 {
844 // phpcs:enable
845 print $this->selectColor($set_color, $prefix, $form_name, $showcolorbox, $arrayofcolors);
846 }
847
862 public static function selectColor($set_color = '', $prefix = 'f_color', $form_name = '', $showcolorbox = 1, $arrayofcolors = [], $morecss = '', $setpropertyonselect = '', $default = '')
863 {
864 // Deprecation warning
865 if ($form_name) {
866 dol_syslog(__METHOD__.": form_name parameter is deprecated", LOG_WARNING);
867 }
868
869 global $langs, $conf;
870
871 $out = '';
872
873 if (!is_array($arrayofcolors) || count($arrayofcolors) < 1) {
874 // Case of selection of any color
875 $langs->load("other");
876 if (empty($conf->dol_use_jmobile) && !empty($conf->use_javascript_ajax) && !getDolGlobalInt('MAIN_USE_HTML5_COLOR_SELECTOR')) {
877 $out .= '<link rel="stylesheet" media="screen" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css" />';
878 $out .= '<script nonce="'.getNonce().'" type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/jpicker-1.1.6.js"></script>';
879 $out .= '<script nonce="'.getNonce().'" type="text/javascript">
880 jQuery(document).ready(function(){
881 var originalhex = null;
882 $(\'#colorpicker'.$prefix.'\').jPicker( {
883 window: {
884 title: \''.dol_escape_js($langs->trans("SelectAColor")).'\', /* any title for the jPicker window itself - displays "Drag Markers To Pick A Color" if left null */
885 effects:
886 {
887 type: \'show\', /* effect used to show/hide an expandable picker. Acceptable values "slide", "show", "fade" */
888 speed:
889 {
890 show: \'fast\', /* duration of "show" effect. Acceptable values are "fast", "slow", or time in ms */
891 hide: \'fast\' /* duration of "hide" effect. Acceptable values are "fast", "slow", or time in ms */
892 }
893 },
894 position:
895 {
896 x: \'screenCenter\', /* acceptable values "left", "center", "right", "screenCenter", or relative px value */
897 y: \'center\' /* acceptable values "top", "bottom", "center", or relative px value */
898 },
899 },
900 images: {
901 clientPath: \''.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/images/\',
902 picker: { file: \'../../../../../theme/common/colorpicker.png\', width: 14, height: 14 }
903 },
904 localization: // alter these to change the text presented by the picker (e.g. different language)
905 {
906 text:
907 {
908 title: \''.dol_escape_js($langs->trans("SelectAColor")).'\',
909 newColor: \''.dol_escape_js($langs->trans("New")).'\',
910 currentColor: \''.dol_escape_js($langs->trans("Current")).'\',
911 ok: \''.dol_escape_js($langs->trans("Validate")).'\',
912 cancel: \''.dol_escape_js($langs->trans("Cancel")).'\'
913 }
914 }
915 },
916 function(color, context) { console.log("close color selector"); },
917 function(color, context) { var hex = color.val(\'hex\'); console.log("new color selected in jpicker "+hex+" setpropertyonselect='.dol_escape_js($setpropertyonselect).'");';
918 if ($setpropertyonselect) {
919 $out .= 'if (originalhex == null) {';
920 $out .= ' originalhex = getComputedStyle(document.querySelector(":root")).getPropertyValue(\'--'.dol_escape_js($setpropertyonselect).'\');';
921 $out .= ' console.log("original color is saved into originalhex = "+originalhex);';
922 $out .= '}';
923 $out .= 'if (hex != null) {';
924 $out .= ' document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', \'#\'+hex);';
925 $out .= '}';
926 }
927 $out .= '},
928 function(color, context) {
929 console.log("cancel selection of color");';
930 if ($setpropertyonselect) {
931 $out .= 'if (originalhex != null) {
932 console.log("Restore old color "+originalhex);
933 document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', originalhex);
934 }';
935 }
936 $out .= '
937 }
938 );
939 });
940 </script>';
941 $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).'" />';
942 } else {
943 $color = ($set_color !== '' ? $set_color : ($default !== '' ? $default : 'FFFFFF'));
944 $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).'" />';
945 $out .= '<script nonce="'.getNonce().'" type="text/javascript">
946 jQuery(document).ready(function(){
947 var originalhex = null;
948 jQuery("#colorpicker'.$prefix.'").on(\'change\', function() {
949 var hex = jQuery("#colorpicker'.$prefix.'").val();
950 console.log("new color selected in input color "+hex+" setpropertyonselect='.dol_escape_js($setpropertyonselect).'");';
951 if ($setpropertyonselect) {
952 $out .= 'if (originalhex == null) {';
953 $out .= ' originalhex = getComputedStyle(document.querySelector(":root")).getPropertyValue(\'--'.dol_escape_js($setpropertyonselect).'\');';
954 $out .= ' console.log("original color is saved into originalhex = "+originalhex);';
955 $out .= '}';
956 $out .= 'if (hex != null) {';
957 $out .= ' document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', hex);';
958 $out .= '}';
959 }
960 $out .= '
961 });
962 });
963 </script>';
964 }
965 } else {
966 // In most cases, this is not used. We used instead function with no specific list of colors
967 if (empty($conf->dol_use_jmobile) && !empty($conf->use_javascript_ajax)) {
968 $out .= '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.css" type="text/css" media="screen" />';
969 $out .= '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.js" type="text/javascript"></script>';
970 $out .= '<script nonce="'.getNonce().'" type="text/javascript">
971 jQuery(document).ready(function(){
972 jQuery(\'#colorpicker'.$prefix.'\').colorpicker({
973 size: 14,
974 label: \'\',
975 hide: true
976 });
977 });
978 </script>';
979 }
980 $out .= '<select id="colorpicker'.$prefix.'" class="colorpicker flat'.($morecss ? ' '.$morecss : '').'" name="'.$prefix.'">';
981 //print '<option value="-1">&nbsp;</option>';
982 foreach ($arrayofcolors as $val) {
983 $out .= '<option value="'.$val.'"';
984 if ($set_color == $val) {
985 $out .= ' selected';
986 }
987 $out .= '>'.$val.'</option>';
988 }
989 $out .= '</select>';
990 }
991
992 return $out;
993 }
994
995 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1006 public function CreateColorIcon($color, $module, $name, $x = 12, $y = 12)
1007 {
1008 // phpcs:enable
1009 global $conf;
1010
1011 $file = $conf->$module->dir_temp.'/'.$name.'.png';
1012
1013 // We create temp directory
1014 if (!file_exists($conf->$module->dir_temp)) {
1015 dol_mkdir($conf->$module->dir_temp);
1016 }
1017
1018 // On cree l'image en vraies couleurs
1019 $image = imagecreatetruecolor($x, $y);
1020
1021 $color = substr($color, 1, 6);
1022
1023 $red = hexdec(substr($color, 0, 2)); // Red channel conversion
1024 $green = hexdec(substr($color, 2, 2)); // Green channel conversion
1025 $blue = hexdec(substr($color, 4, 2)); // Blue channel conversion
1026
1027 $couleur = imagecolorallocate($image, $red, $green, $blue);
1028 //print $red.$green.$blue;
1029 imagefill($image, 0, 0, $couleur); // Fill the image
1030 // Create the colr and store it in a variable to maintain it
1031 imagepng($image, $file); // Returns an image in PNG format
1032 imagedestroy($image);
1033 }
1034
1035 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1044 public function select_dayofweek($selected = '', $htmlname = 'weekid', $useempty = 0)
1045 {
1046 // phpcs:enable
1047 global $langs;
1048
1049 $week = array(
1050 0 => $langs->trans("Day0"),
1051 1 => $langs->trans("Day1"),
1052 2 => $langs->trans("Day2"),
1053 3 => $langs->trans("Day3"),
1054 4 => $langs->trans("Day4"),
1055 5 => $langs->trans("Day5"),
1056 6 => $langs->trans("Day6")
1057 );
1058
1059 $select_week = '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
1060 if ($useempty) {
1061 $select_week .= '<option value="-1">&nbsp;</option>';
1062 }
1063 foreach ($week as $key => $val) {
1064 if ($selected == $key) {
1065 $select_week .= '<option value="'.$key.'" selected>';
1066 } else {
1067 $select_week .= '<option value="'.$key.'">';
1068 }
1069 $select_week .= $val;
1070 $select_week .= '</option>';
1071 }
1072 $select_week .= '</select>';
1073
1074 $select_week .= ajax_combobox($htmlname);
1075
1076 return $select_week;
1077 }
1078
1079 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1091 public function select_month($selected = '', $htmlname = 'monthid', $useempty = 0, $longlabel = 0, $morecss = 'minwidth50 maxwidth75imp valignmiddle', $addjscombo = false)
1092 {
1093 // phpcs:enable
1094 global $langs;
1095
1096 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
1097
1098 if ($longlabel) {
1099 $montharray = monthArray($langs, 0); // Get array of month with long labels
1100 } else {
1101 $montharray = monthArray($langs, 1); // Get array of month with short labels
1102 }
1103
1104 $select_month = '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
1105 if ($useempty) {
1106 if (is_numeric($useempty)) {
1107 $select_month .= '<option value="0">&nbsp;</option>';
1108 } else {
1109 $select_month .= '<option value="-1">'.$useempty.'</option>';
1110 }
1111 }
1112 foreach ($montharray as $key => $val) {
1113 if ((int) $selected == $key) {
1114 $select_month .= '<option value="'.$key.'" selected>';
1115 } else {
1116 $select_month .= '<option value="'.$key.'">';
1117 }
1118 $select_month .= $val;
1119 $select_month .= '</option>';
1120 }
1121 $select_month .= '</select>';
1122
1123 // Add code for jquery to use multiselect
1124 if ($addjscombo) {
1125 // Enhance with select2
1126 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1127 $select_month .= ajax_combobox($htmlname);
1128 }
1129
1130 return $select_month;
1131 }
1132
1133 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1150 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)
1151 {
1152 // phpcs:enable
1153 print $this->selectyear($selected, $htmlname, $useempty, $min_year, $max_year, $offset, $invert, $option, $morecss, $addjscombo);
1154 }
1155
1171 public function selectyear($selected = '', $htmlname = 'yearid', $useempty = 0, $min_year = 10, $max_year = 5, $offset = 0, $invert = 0, $option = '', $morecss = 'valignmiddle width75', $addjscombo = false)
1172 {
1173 $out = '';
1174
1175 $currentyear = idate("Y") + $offset;
1176 $max_year = $currentyear + $max_year;
1177 $min_year = $currentyear - $min_year;
1178 if (empty($selected) && empty($useempty)) {
1179 $selected = $currentyear;
1180 }
1181
1182 $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'"'.$option.' >';
1183 if ($useempty) {
1184 $selected_html = '';
1185 if ((string) $selected == '') {
1186 $selected_html = ' selected';
1187 }
1188 $out .= '<option value=""'.$selected_html.'>&nbsp;</option>';
1189 }
1190 if (!$invert) {
1191 for ($y = $max_year; $y >= $min_year; $y--) {
1192 $selected_html = '';
1193 if ((int) $selected > 0 && $y == (int) $selected) {
1194 $selected_html = ' selected';
1195 }
1196 $out .= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
1197 }
1198 } else {
1199 for ($y = $min_year; $y <= $max_year; $y++) {
1200 $selected_html = '';
1201 if ((int) $selected > 0 && $y == (int) $selected) {
1202 $selected_html = ' selected';
1203 }
1204 $out .= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
1205 }
1206 }
1207 $out .= "</select>\n";
1208
1209 // Add code for jquery to use multiselect
1210 if ($addjscombo) {
1211 // Enhance with select2
1212 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1213 $out .= ajax_combobox($htmlname);
1214 }
1215
1216 return $out;
1217 }
1218
1219
1228 public static function getBoxesArea($user, $areacode)
1229 {
1230 global $conf, $langs, $db;
1231
1232 include_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
1233 // From include
1234 '
1235 @phan-var-force ModeleBoxes[] $boxactivated
1236 @phan-var-force int[] $boxidactivatedforuser
1237 ';
1238
1239 $confuserzone = 'MAIN_BOXES_'.$areacode;
1240
1241
1242
1243 // $boxactivated will be array of boxes enabled into global setup
1244 // $boxidactivatedforuser will be array of boxes chose by user
1245
1246 $selectboxlist = '';
1247 $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)
1248
1249 $boxidactivatedforuser = array();
1250 foreach ($boxactivated as $box) {
1251 if (empty($user->conf->$confuserzone) || $box->fk_user == $user->id) {
1252 $boxidactivatedforuser[$box->id] = $box->id; // We keep only boxes to show for user
1253 }
1254
1255 if (!empty($box->lang)) {
1256 $langs->loadLangs(array($box->lang));
1257 $box->boxlabel = $langs->transnoentitiesnoconv($box->boxlabel);
1258 }
1259 }
1260
1261
1262 // Define selectboxlist
1263 $arrayboxtoactivatelabel = array();
1264 if (getDolUserString($confuserzone)) {
1265 $boxorder = '';
1266 $langs->load("boxes"); // Load label of boxes
1267 foreach ($boxactivated as $box) {
1268 if (!empty($boxidactivatedforuser[$box->id])) {
1269 continue; // Already visible for user
1270 }
1271
1272 $label = $langs->transnoentitiesnoconv($box->boxlabel);
1273 //if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph").')';
1274 if (preg_match('/graph/', $box->class) && $conf->browser->layout != 'phone') {
1275 $label .= ' <span class="fas fa-chart-bar"></span>';
1276 }
1277 $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
1278 }
1279 foreach ($boxidactivatedforuser as $boxid) {
1280 if (empty($boxorder)) {
1281 $boxorder .= 'A:';
1282 }
1283 $boxorder .= $boxid.',';
1284 }
1285
1286 //var_dump($boxidactivatedforuser);
1287
1288 // Class Form must have been already loaded
1289 $selectboxlist .= '<!-- Form with select box list -->'."\n";
1290 $selectboxlist .= '<form id="addbox" name="addbox" method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
1291 $selectboxlist .= '<input type="hidden" name="token" value="'.newToken().'">';
1292 $selectboxlist .= '<input type="hidden" name="addbox" value="addbox">';
1293 $selectboxlist .= '<input type="hidden" name="userid" value="'.$user->id.'">';
1294 $selectboxlist .= '<input type="hidden" name="areacode" value="'.$areacode.'">';
1295 $selectboxlist .= '<input type="hidden" name="boxorder" value="'.$boxorder.'">';
1296 $selectboxlist .= Form::selectarray('boxcombo', $arrayboxtoactivatelabel, -1, $langs->trans("ChooseBoxToAdd").'...', 0, 0, '', 0, 0, 0, 'ASC', 'noborderfocus selectwidget maxwidth300 hideonprint', 0, 'hidden selected', 0, 0);
1297 if (empty($conf->use_javascript_ajax)) {
1298 $selectboxlist .= ' <input type="submit" class="button" value="'.$langs->trans("AddBox").'">';
1299 }
1300 $selectboxlist .= '</form>';
1301 if (!empty($conf->use_javascript_ajax)) {
1302 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1303 $selectboxlist .= ajax_combobox("boxcombo");
1304 }
1305 }
1306
1307 // Javascript code for dynamic actions
1308 if (!empty($conf->use_javascript_ajax)) {
1309 $selectboxlist .= '<script nonce="'.getNonce().'" type="text/javascript">
1310
1311 // To update list of activated boxes
1312 function updateBoxOrder(closing) {
1313 var left_list = cleanSerialize(jQuery("#boxhalfleft").sortable("serialize"));
1314 var right_list = cleanSerialize(jQuery("#boxhalfright").sortable("serialize"));
1315 var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
1316 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
1317 {
1318 jQuery.ajax({
1319 url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=1&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
1320 async: false
1321 });
1322 // We force reload to be sure to get all boxes into list
1323 window.location.search=\'mainmenu='.GETPOST("mainmenu", "aZ09").'&leftmenu='.GETPOST('leftmenu', "aZ09").'&action=delbox&token='.newToken().'\';
1324 }
1325 else
1326 {
1327 jQuery.ajax({
1328 url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=\'+closing+\'&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
1329 async: true
1330 });
1331 }
1332 }
1333
1334 jQuery(document).ready(function() {
1335 jQuery("#boxcombo").change(function() {
1336 var boxid=jQuery("#boxcombo").val();
1337 if (boxid > 0) {
1338 console.log("A box widget has been selected for addition, we call ajax page to add it.")
1339 var left_list = cleanSerialize(jQuery("#boxhalfleft").sortable("serialize"));
1340 var right_list = cleanSerialize(jQuery("#boxhalfright").sortable("serialize"));
1341 var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
1342 jQuery.ajax({
1343 url: \''.DOL_URL_ROOT.'/core/ajax/box.php?boxorder=\'+boxorder+\'&boxid=\'+boxid+\'&zone='.$areacode.'&userid='.$user->id.'\'
1344 }).done(function() {
1345 window.location.search=\'mainmenu='.GETPOST("mainmenu", "aZ09").'&leftmenu='.GETPOST('leftmenu', "aZ09").'\';
1346 });
1347 }
1348 });';
1349 if (!count($arrayboxtoactivatelabel)) {
1350 $selectboxlist .= 'jQuery("#boxcombo").hide();';
1351 }
1352 $selectboxlist .= '
1353
1354 jQuery("#boxhalfleft, #boxhalfright").sortable({
1355 handle: \'.boxhandle\',
1356 revert: \'invalid\',
1357 items: \'.boxdraggable\',
1358 containment: \'document\',
1359 connectWith: \'#boxhalfleft, #boxhalfright\',
1360 stop: function(event, ui) {
1361 console.log("We moved box so we call updateBoxOrder with ajax actions");
1362 updateBoxOrder(1); /* 1 to avoid message after a move */
1363 }
1364 });
1365
1366 jQuery(".boxclose").click(function() {
1367 var self = this; // because JQuery can modify this
1368 var boxid = self.id.substring(8);
1369 if (boxid > 0) {
1370 var label = jQuery(\'#boxlabelentry\'+boxid).val();
1371 console.log("We close box "+boxid);
1372 jQuery(\'#boxto_\'+boxid).remove();
1373 jQuery(\'#boxcombo\').append(new Option(label, boxid));
1374 updateBoxOrder(1); /* 1 to avoid message after a remove */
1375 }
1376 });
1377
1378 });'."\n";
1379
1380 $selectboxlist .= '</script>'."\n";
1381 }
1382
1383 // Define boxlista and boxlistb
1384 $boxlista = '';
1385 $boxlistb = '';
1386 $nbboxactivated = count($boxidactivatedforuser);
1387
1388 if ($nbboxactivated) {
1389 // Load translation files required by the page
1390 $langs->loadLangs(array("boxes", "projects"));
1391
1392 $emptybox = new ModeleBoxes($db);
1393
1394 $boxlista .= "\n<!-- Box left container -->\n";
1395
1396 // Define $box_max_lines
1397 $box_max_lines = getDolUserInt('MAIN_SIZE_SHORTLIST_LIMIT', getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5));
1398
1399 $ii = 0;
1400 foreach ($boxactivated as $key => $box) {
1401 if ((!empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) {
1402 continue;
1403 }
1404 if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) {
1405 $box->box_order = 'A'.sprintf("%02d", ($ii + 1)); // When box_order was not yet set to Axx or Bxx and is still 0
1406 }
1407 if (preg_match('/^A/i', $box->box_order)) { // column A
1408 $ii++;
1409 //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1410 //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1411 // Show box
1412 $box->loadBox($box_max_lines);
1413 $boxlista .= $box->showBox(null, null, 1);
1414 }
1415 }
1416
1417 if ($conf->browser->layout != 'phone') {
1418 $emptybox->box_id = 'A';
1419 $emptybox->info_box_head = array();
1420 $emptybox->info_box_contents = array();
1421 $boxlista .= $emptybox->showBox(array(), array(), 1);
1422 }
1423 $boxlista .= "<!-- End box left container -->\n";
1424
1425 $boxlistb .= "\n<!-- Box right container -->\n";
1426
1427 $ii = 0;
1428 foreach ($boxactivated as $key => $box) {
1429 if ((!empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) {
1430 continue;
1431 }
1432 if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) {
1433 $box->box_order = 'B'.sprintf("%02d", ($ii + 1)); // When box_order was not yet set to Axx or Bxx and is still 0
1434 }
1435 if (preg_match('/^B/i', $box->box_order)) { // colonne B
1436 $ii++;
1437 //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1438 //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1439 // Show box
1440 $box->loadBox($box_max_lines);
1441 $boxlistb .= $box->showBox(null, null, 1);
1442 }
1443 }
1444
1445 if ($conf->browser->layout != 'phone') {
1446 $emptybox->box_id = 'B';
1447 $emptybox->info_box_head = array();
1448 $emptybox->info_box_contents = array();
1449 $boxlistb .= $emptybox->showBox(array(), array(), 1);
1450 }
1451
1452 $boxlistb .= "<!-- End box right container -->\n";
1453 }
1454
1455 return array('selectboxlist' => count($boxactivated) ? $selectboxlist : '', 'boxactivated' => $boxactivated, 'boxlista' => $boxlista, 'boxlistb' => $boxlistb);
1456 }
1457
1458
1459 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1472 public function select_dictionary($htmlname, $dictionarytable, $keyfield = 'code', $labelfield = 'label', $selected = '', $useempty = 0, $moreattrib = '')
1473 {
1474 // phpcs:enable
1475 global $langs, $conf;
1476
1477 $langs->load("admin");
1478
1479 $sql = "SELECT rowid, ".$keyfield.", ".$labelfield;
1480 $sql .= " FROM ".$this->db->prefix().$dictionarytable;
1481 $sql .= " ORDER BY ".$labelfield;
1482
1483 dol_syslog(get_class($this)."::select_dictionary", LOG_DEBUG);
1484 $result = $this->db->query($sql);
1485 if ($result) {
1486 $num = $this->db->num_rows($result);
1487 $i = 0;
1488 if ($num) {
1489 print '<select id="select'.$htmlname.'" class="flat selectdictionary" name="'.$htmlname.'"'.($moreattrib ? ' '.$moreattrib : '').'>';
1490 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
1491 print '<option value="-1">&nbsp;</option>';
1492 }
1493
1494 while ($i < $num) {
1495 $obj = $this->db->fetch_object($result);
1496 if ($selected == $obj->rowid || $selected == $obj->{$keyfield}) {
1497 print '<option value="'.$obj->{$keyfield}.'" selected>';
1498 } else {
1499 print '<option value="'.$obj->{$keyfield}.'">';
1500 }
1501 $label = ($langs->trans($dictionarytable.$obj->{$keyfield}) != $dictionarytable.$obj->{$labelfield} ? $langs->trans($dictionarytable.$obj->{$keyfield}) : $obj->{$labelfield});
1502 print $label;
1503 print '</option>';
1504 $i++;
1505 }
1506 print "</select>";
1507 } else {
1508 print $langs->trans("DictionaryEmpty");
1509 }
1510 } else {
1511 dol_print_error($this->db);
1512 }
1513 }
1514
1525 public function selectAutoManual($htmlname, $value = '', $option = 0, $disabled = false, $useempty = 0)
1526 {
1527 global $langs;
1528
1529 $automatic = "automatic";
1530 $manual = "manual";
1531 if ($option) {
1532 $automatic = "1";
1533 $manual = "0";
1534 }
1535
1536 $disabled = ($disabled ? ' disabled' : '');
1537
1538 $resultautomanual = '<select class="flat width100" id="'.$htmlname.'" name="'.$htmlname.'"'.$disabled.'>'."\n";
1539 if ($useempty) {
1540 $resultautomanual .= '<option value="-1"'.(($value < 0) ? ' selected' : '').'>&nbsp;</option>'."\n";
1541 }
1542 if (("$value" == 'automatic') || ($value == 1)) {
1543 $resultautomanual .= '<option value="'.$automatic.'" selected>'.$langs->trans("Automatic").'</option>'."\n";
1544 $resultautomanual .= '<option value="'.$manual.'">'.$langs->trans("Manual").'</option>'."\n";
1545 } else {
1546 $selected = (($useempty && $value != '0' && $value != 'manual') ? '' : ' selected');
1547 $resultautomanual .= '<option value="'.$automatic.'">'.$langs->trans("Automatic").'</option>'."\n";
1548 $resultautomanual .= '<option value="'.$manual.'"'.$selected.'>'.$langs->trans("Manual").'</option>'."\n";
1549 }
1550 $resultautomanual .= '</select>'."\n";
1551 return $resultautomanual;
1552 }
1553
1554
1565 public function selectGroupByField($object, $search_groupby, &$arrayofgroupby, $morecss = 'minwidth200 maxwidth250', $showempty = '1')
1566 {
1567 global $langs, $extrafields, $form;
1568
1569 $arrayofgroupbylabel = array();
1570 foreach ($arrayofgroupby as $key => $val) {
1571 $arrayofgroupbylabel[$key] = $val['label'];
1572 }
1573 $result = $form->selectarray('search_groupby', $arrayofgroupbylabel, $search_groupby, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
1574
1575 return $result;
1576 }
1577
1588 public function selectXAxisField($object, $search_xaxis, &$arrayofxaxis, $showempty = '1', $morecss = 'minwidth250 maxwidth500')
1589 {
1590 global $form;
1591
1592 $arrayofxaxislabel = array();
1593 foreach ($arrayofxaxis as $key => $val) {
1594 $arrayofxaxislabel[$key] = $val['label'];
1595 }
1596 $result = $form->selectarray('search_xaxis', $arrayofxaxislabel, $search_xaxis, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
1597
1598 return $result;
1599 }
1600}
Class permettant la generation de composants html autre Only common components are here.
__construct($db)
Constructor.
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.
Class with static methods for building HTML components related to products Only components common to ...
Class toolbox to validate values.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:171
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
multi select button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
$conf db user
Active Directory does not allow anonymous connections.
Definition repair.php:129
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:125