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