dolibarr 21.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 Frédéric France <frederic.france@free.fr>
14 * Copyright (C) 2024 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="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="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="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
1100 } else {
1101 $montharray = monthArray($langs, 1);
1102 }
1103
1104 $select_month = '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
1105 if ($useempty) {
1106 $select_month .= '<option value="0">&nbsp;</option>';
1107 }
1108 foreach ($montharray as $key => $val) {
1109 if ($selected == $key) {
1110 $select_month .= '<option value="'.$key.'" selected>';
1111 } else {
1112 $select_month .= '<option value="'.$key.'">';
1113 }
1114 $select_month .= $val;
1115 $select_month .= '</option>';
1116 }
1117 $select_month .= '</select>';
1118
1119 // Add code for jquery to use multiselect
1120 if ($addjscombo) {
1121 // Enhance with select2
1122 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1123 $select_month .= ajax_combobox($htmlname);
1124 }
1125
1126 return $select_month;
1127 }
1128
1129 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1146 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)
1147 {
1148 // phpcs:enable
1149 print $this->selectyear($selected, $htmlname, $useempty, $min_year, $max_year, $offset, $invert, $option, $morecss, $addjscombo);
1150 }
1151
1167 public function selectyear($selected = '', $htmlname = 'yearid', $useempty = 0, $min_year = 10, $max_year = 5, $offset = 0, $invert = 0, $option = '', $morecss = 'valignmiddle width75', $addjscombo = false)
1168 {
1169 $out = '';
1170
1171 $currentyear = idate("Y") + $offset;
1172 $max_year = $currentyear + $max_year;
1173 $min_year = $currentyear - $min_year;
1174 if (empty($selected) && empty($useempty)) {
1175 $selected = $currentyear;
1176 }
1177
1178 $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'"'.$option.' >';
1179 if ($useempty) {
1180 $selected_html = '';
1181 if ($selected == '') {
1182 $selected_html = ' selected';
1183 }
1184 $out .= '<option value=""'.$selected_html.'>&nbsp;</option>';
1185 }
1186 if (!$invert) {
1187 for ($y = $max_year; $y >= $min_year; $y--) {
1188 $selected_html = '';
1189 if ($selected > 0 && $y == $selected) {
1190 $selected_html = ' selected';
1191 }
1192 $out .= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
1193 }
1194 } else {
1195 for ($y = $min_year; $y <= $max_year; $y++) {
1196 $selected_html = '';
1197 if ($selected > 0 && $y == $selected) {
1198 $selected_html = ' selected';
1199 }
1200 $out .= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
1201 }
1202 }
1203 $out .= "</select>\n";
1204
1205 // Add code for jquery to use multiselect
1206 if ($addjscombo) {
1207 // Enhance with select2
1208 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1209 $out .= ajax_combobox($htmlname);
1210 }
1211
1212 return $out;
1213 }
1214
1215
1224 public static function getBoxesArea($user, $areacode)
1225 {
1226 global $conf, $langs, $db;
1227
1228 include_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
1229 // From include
1230 '
1231 @phan-var-force ModeleBoxes[] $boxactivated
1232 @phan-var-force int[] $boxidactivatedforuser
1233 ';
1234
1235 $confuserzone = 'MAIN_BOXES_'.$areacode;
1236
1237
1238
1239 // $boxactivated will be array of boxes enabled into global setup
1240 // $boxidactivatedforuser will be array of boxes chose by user
1241
1242 $selectboxlist = '';
1243 $boxactivated = InfoBox::listBoxes($db, 'activated', $areacode, (empty($user->conf->$confuserzone) ? null : $user), array(), 0); // Search boxes of common+user (or common only if user has no specific setup)
1244
1245 $boxidactivatedforuser = array();
1246 foreach ($boxactivated as $box) {
1247 if (empty($user->conf->$confuserzone) || $box->fk_user == $user->id) {
1248 $boxidactivatedforuser[$box->id] = $box->id; // We keep only boxes to show for user
1249 }
1250
1251 if (!empty($box->lang)) {
1252 $langs->loadLangs(array($box->lang));
1253 $box->boxlabel = $langs->transnoentitiesnoconv($box->boxlabel);
1254 }
1255 }
1256
1257
1258 // Define selectboxlist
1259 $arrayboxtoactivatelabel = array();
1260 if (!empty($user->conf->$confuserzone)) {
1261 $boxorder = '';
1262 $langs->load("boxes"); // Load label of boxes
1263 foreach ($boxactivated as $box) {
1264 if (!empty($boxidactivatedforuser[$box->id])) {
1265 continue; // Already visible for user
1266 }
1267
1268 $label = $langs->transnoentitiesnoconv($box->boxlabel);
1269 //if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph").')';
1270 if (preg_match('/graph/', $box->class) && $conf->browser->layout != 'phone') {
1271 $label .= ' <span class="fas fa-chart-bar"></span>';
1272 }
1273 $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
1274 }
1275 foreach ($boxidactivatedforuser as $boxid) {
1276 if (empty($boxorder)) {
1277 $boxorder .= 'A:';
1278 }
1279 $boxorder .= $boxid.',';
1280 }
1281
1282 //var_dump($boxidactivatedforuser);
1283
1284 // Class Form must have been already loaded
1285 $selectboxlist .= '<!-- Form with select box list -->'."\n";
1286 $selectboxlist .= '<form id="addbox" name="addbox" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
1287 $selectboxlist .= '<input type="hidden" name="token" value="'.newToken().'">';
1288 $selectboxlist .= '<input type="hidden" name="addbox" value="addbox">';
1289 $selectboxlist .= '<input type="hidden" name="userid" value="'.$user->id.'">';
1290 $selectboxlist .= '<input type="hidden" name="areacode" value="'.$areacode.'">';
1291 $selectboxlist .= '<input type="hidden" name="boxorder" value="'.$boxorder.'">';
1292 $selectboxlist .= Form::selectarray('boxcombo', $arrayboxtoactivatelabel, -1, $langs->trans("ChooseBoxToAdd").'...', 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth300 hideonprint', 0, 'hidden selected', 0, 0);
1293 if (empty($conf->use_javascript_ajax)) {
1294 $selectboxlist .= ' <input type="submit" class="button" value="'.$langs->trans("AddBox").'">';
1295 }
1296 $selectboxlist .= '</form>';
1297 if (!empty($conf->use_javascript_ajax)) {
1298 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1299 $selectboxlist .= ajax_combobox("boxcombo");
1300 }
1301 }
1302
1303 // Javascript code for dynamic actions
1304 if (!empty($conf->use_javascript_ajax)) {
1305 $selectboxlist .= '<script nonce="'.getNonce().'" type="text/javascript">
1306
1307 // To update list of activated boxes
1308 function updateBoxOrder(closing) {
1309 var left_list = cleanSerialize(jQuery("#boxhalfleft").sortable("serialize"));
1310 var right_list = cleanSerialize(jQuery("#boxhalfright").sortable("serialize"));
1311 var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
1312 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
1313 {
1314 jQuery.ajax({
1315 url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=1&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
1316 async: false
1317 });
1318 // We force reload to be sure to get all boxes into list
1319 window.location.search=\'mainmenu='.GETPOST("mainmenu", "aZ09").'&leftmenu='.GETPOST('leftmenu', "aZ09").'&action=delbox&token='.newToken().'\';
1320 }
1321 else
1322 {
1323 jQuery.ajax({
1324 url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=\'+closing+\'&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
1325 async: true
1326 });
1327 }
1328 }
1329
1330 jQuery(document).ready(function() {
1331 jQuery("#boxcombo").change(function() {
1332 var boxid=jQuery("#boxcombo").val();
1333 if (boxid > 0) {
1334 console.log("A box widget has been selected for addition, we call ajax page to add it.")
1335 var left_list = cleanSerialize(jQuery("#boxhalfleft").sortable("serialize"));
1336 var right_list = cleanSerialize(jQuery("#boxhalfright").sortable("serialize"));
1337 var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
1338 jQuery.ajax({
1339 url: \''.DOL_URL_ROOT.'/core/ajax/box.php?boxorder=\'+boxorder+\'&boxid=\'+boxid+\'&zone='.$areacode.'&userid='.$user->id.'\'
1340 }).done(function() {
1341 window.location.search=\'mainmenu='.GETPOST("mainmenu", "aZ09").'&leftmenu='.GETPOST('leftmenu', "aZ09").'\';
1342 });
1343 }
1344 });';
1345 if (!count($arrayboxtoactivatelabel)) {
1346 $selectboxlist .= 'jQuery("#boxcombo").hide();';
1347 }
1348 $selectboxlist .= '
1349
1350 jQuery("#boxhalfleft, #boxhalfright").sortable({
1351 handle: \'.boxhandle\',
1352 revert: \'invalid\',
1353 items: \'.boxdraggable\',
1354 containment: \'document\',
1355 connectWith: \'#boxhalfleft, #boxhalfright\',
1356 stop: function(event, ui) {
1357 console.log("We moved box so we call updateBoxOrder with ajax actions");
1358 updateBoxOrder(1); /* 1 to avoid message after a move */
1359 }
1360 });
1361
1362 jQuery(".boxclose").click(function() {
1363 var self = this; // because JQuery can modify this
1364 var boxid = self.id.substring(8);
1365 if (boxid > 0) {
1366 var label = jQuery(\'#boxlabelentry\'+boxid).val();
1367 console.log("We close box "+boxid);
1368 jQuery(\'#boxto_\'+boxid).remove();
1369 jQuery(\'#boxcombo\').append(new Option(label, boxid));
1370 updateBoxOrder(1); /* 1 to avoid message after a remove */
1371 }
1372 });
1373
1374 });'."\n";
1375
1376 $selectboxlist .= '</script>'."\n";
1377 }
1378
1379 // Define boxlista and boxlistb
1380 $boxlista = '';
1381 $boxlistb = '';
1382 $nbboxactivated = count($boxidactivatedforuser);
1383
1384 if ($nbboxactivated) {
1385 // Load translation files required by the page
1386 $langs->loadLangs(array("boxes", "projects"));
1387
1388 $emptybox = new ModeleBoxes($db);
1389
1390 $boxlista .= "\n<!-- Box left container -->\n";
1391
1392 // Define $box_max_lines
1393 $box_max_lines = getDolUserInt('MAIN_SIZE_SHORTLIST_LIMIT', getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5));
1394
1395 $ii = 0;
1396 foreach ($boxactivated as $key => $box) {
1397 if ((!empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) {
1398 continue;
1399 }
1400 if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) {
1401 $box->box_order = 'A'.sprintf("%02d", ($ii + 1)); // When box_order was not yet set to Axx or Bxx and is still 0
1402 }
1403 if (preg_match('/^A/i', $box->box_order)) { // column A
1404 $ii++;
1405 //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1406 //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1407 // Show box
1408 $box->loadBox($box_max_lines);
1409 $boxlista .= $box->showBox(null, null, 1);
1410 }
1411 }
1412
1413 if ($conf->browser->layout != 'phone') {
1414 $emptybox->box_id = 'A';
1415 $emptybox->info_box_head = array();
1416 $emptybox->info_box_contents = array();
1417 $boxlista .= $emptybox->showBox(array(), array(), 1);
1418 }
1419 $boxlista .= "<!-- End box left container -->\n";
1420
1421 $boxlistb .= "\n<!-- Box right container -->\n";
1422
1423 $ii = 0;
1424 foreach ($boxactivated as $key => $box) {
1425 if ((!empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) {
1426 continue;
1427 }
1428 if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) {
1429 $box->box_order = 'B'.sprintf("%02d", ($ii + 1)); // When box_order was not yet set to Axx or Bxx and is still 0
1430 }
1431 if (preg_match('/^B/i', $box->box_order)) { // colonne B
1432 $ii++;
1433 //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1434 //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1435 // Show box
1436 $box->loadBox($box_max_lines);
1437 $boxlistb .= $box->showBox(null, null, 1);
1438 }
1439 }
1440
1441 if ($conf->browser->layout != 'phone') {
1442 $emptybox->box_id = 'B';
1443 $emptybox->info_box_head = array();
1444 $emptybox->info_box_contents = array();
1445 $boxlistb .= $emptybox->showBox(array(), array(), 1);
1446 }
1447
1448 $boxlistb .= "<!-- End box right container -->\n";
1449 }
1450
1451 return array('selectboxlist' => count($boxactivated) ? $selectboxlist : '', 'boxactivated' => $boxactivated, 'boxlista' => $boxlista, 'boxlistb' => $boxlistb);
1452 }
1453
1454
1455 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1468 public function select_dictionary($htmlname, $dictionarytable, $keyfield = 'code', $labelfield = 'label', $selected = '', $useempty = 0, $moreattrib = '')
1469 {
1470 // phpcs:enable
1471 global $langs, $conf;
1472
1473 $langs->load("admin");
1474
1475 $sql = "SELECT rowid, ".$keyfield.", ".$labelfield;
1476 $sql .= " FROM ".$this->db->prefix().$dictionarytable;
1477 $sql .= " ORDER BY ".$labelfield;
1478
1479 dol_syslog(get_class($this)."::select_dictionary", LOG_DEBUG);
1480 $result = $this->db->query($sql);
1481 if ($result) {
1482 $num = $this->db->num_rows($result);
1483 $i = 0;
1484 if ($num) {
1485 print '<select id="select'.$htmlname.'" class="flat selectdictionary" name="'.$htmlname.'"'.($moreattrib ? ' '.$moreattrib : '').'>';
1486 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
1487 print '<option value="-1">&nbsp;</option>';
1488 }
1489
1490 while ($i < $num) {
1491 $obj = $this->db->fetch_object($result);
1492 if ($selected == $obj->rowid || $selected == $obj->{$keyfield}) {
1493 print '<option value="'.$obj->{$keyfield}.'" selected>';
1494 } else {
1495 print '<option value="'.$obj->{$keyfield}.'">';
1496 }
1497 $label = ($langs->trans($dictionarytable.$obj->{$keyfield}) != $dictionarytable.$obj->{$labelfield} ? $langs->trans($dictionarytable.$obj->{$keyfield}) : $obj->{$labelfield});
1498 print $label;
1499 print '</option>';
1500 $i++;
1501 }
1502 print "</select>";
1503 } else {
1504 print $langs->trans("DictionaryEmpty");
1505 }
1506 } else {
1507 dol_print_error($this->db);
1508 }
1509 }
1510
1521 public function selectAutoManual($htmlname, $value = '', $option = 0, $disabled = false, $useempty = 0)
1522 {
1523 global $langs;
1524
1525 $automatic = "automatic";
1526 $manual = "manual";
1527 if ($option) {
1528 $automatic = "1";
1529 $manual = "0";
1530 }
1531
1532 $disabled = ($disabled ? ' disabled' : '');
1533
1534 $resultautomanual = '<select class="flat width100" id="'.$htmlname.'" name="'.$htmlname.'"'.$disabled.'>'."\n";
1535 if ($useempty) {
1536 $resultautomanual .= '<option value="-1"'.(($value < 0) ? ' selected' : '').'>&nbsp;</option>'."\n";
1537 }
1538 if (("$value" == 'automatic') || ($value == 1)) {
1539 $resultautomanual .= '<option value="'.$automatic.'" selected>'.$langs->trans("Automatic").'</option>'."\n";
1540 $resultautomanual .= '<option value="'.$manual.'">'.$langs->trans("Manual").'</option>'."\n";
1541 } else {
1542 $selected = (($useempty && $value != '0' && $value != 'manual') ? '' : ' selected');
1543 $resultautomanual .= '<option value="'.$automatic.'">'.$langs->trans("Automatic").'</option>'."\n";
1544 $resultautomanual .= '<option value="'.$manual.'"'.$selected.'>'.$langs->trans("Manual").'</option>'."\n";
1545 }
1546 $resultautomanual .= '</select>'."\n";
1547 return $resultautomanual;
1548 }
1549
1550
1561 public function selectGroupByField($object, $search_groupby, &$arrayofgroupby, $morecss = 'minwidth200 maxwidth250', $showempty = '1')
1562 {
1563 global $langs, $extrafields, $form;
1564
1565 $arrayofgroupbylabel = array();
1566 foreach ($arrayofgroupby as $key => $val) {
1567 $arrayofgroupbylabel[$key] = $val['label'];
1568 }
1569 $result = $form->selectarray('search_groupby', $arrayofgroupbylabel, $search_groupby, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
1570
1571 return $result;
1572 }
1573
1584 public function selectXAxisField($object, $search_xaxis, &$arrayofxaxis, $showempty = '1', $morecss = 'minwidth250 maxwidth500')
1585 {
1586 global $form;
1587
1588 $arrayofxaxislabel = array();
1589 foreach ($arrayofxaxis as $key => $val) {
1590 $arrayofxaxislabel[$key] = $val['label'];
1591 }
1592 $result = $form->selectarray('search_xaxis', $arrayofxaxislabel, $search_xaxis, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
1593
1594 return $result;
1595 }
1596}
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:162
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
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...
ui state ui widget content ui state ui widget header ui state a ui 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:141
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:137