dolibarr 19.0.3
html.formother.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
5 * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
6 * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
7 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
8 * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
9 * Copyright (C) 2006 Marc Barilley/Ocebo <marc@ocebo.com>
10 * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerker@telenet.be>
11 * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
12 * Copyright (C) 2019 Thibault FOUCART <support@ptibogxiv.net>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27
40{
41 private $db;
42
46 public $error;
47
48
54 public function __construct($db)
55 {
56 $this->db = $db;
57 }
58
68 public function getHTMLScannerForm($jstoexecuteonadd = 'barcodescannerjs', $mode = 'all', $warehouseselect = 0)
69 {
70 global $langs;
71
72 $out = '';
73
74 $out .= '<!-- Popup for mass barcode scanning -->'."\n";
75 $out .= '<div class="div-for-modal-topright" style="padding: 15px">';
76 $out .= '<center>'.img_picto('', 'barcode', 'class="pictofixedwidth"').'<strong>Barcode scanner tool...</strong></center><br>';
77
78 if ($mode == 'product') {
79 $out .= '<input type="hidden" name="barcodemode" value="barcodeforproduct" id="barcodeforproduct">';
80 } elseif ($mode == 'lot') {
81 $out .= '<input type="hidden" name="barcodemode" value="barcodeforlotserial" id="barcodeforlotserial">';
82 } else { // $mode = 'all'
83 $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>';
84 $out .= '<input type="radio" name="barcodemode" value="barcodeforproduct" id="barcodeforproduct"> <label for="barcodeforproduct">Scan a product barcode</label><br>';
85 $out .= '<input type="radio" name="barcodemode" value="barcodeforlotserial" id="barcodeforlotserial"> <label for="barcodeforlotserial">Scan a product lot or serial number</label><br>';
86 }
87 $stringaddbarcode = $langs->trans("QtyToAddAfterBarcodeScan", "tmphtml");
88 $htmltoreplaceby = '<select name="selectaddorreplace"><option selected value="add">'.$langs->trans("Add").'</option><option value="replace">'.$langs->trans("ToReplace").'</option></select>';
89 $stringaddbarcode = str_replace("tmphtml", $htmltoreplaceby, $stringaddbarcode);
90 $out .= $stringaddbarcode.': <input type="text" name="barcodeproductqty" class="width40 right" value="1"><br>';
91 if ($warehouseselect > 0) {
92 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
93 $formproduct = new FormProduct($this->db);
94 $formproduct->loadWarehouses();
95 $out .= img_picto('', 'stock', 'class="pictofixedwidth"');
96 $out .= $formproduct->selectWarehouses('', "warehousenew", '', 0, 0, 0, '', 0, 1);
97 $out .= '<br>';
98 $out .= '<br>';
99 }
100 $out .= '<textarea type="text" name="barcodelist" class="centpercent" autofocus rows="'.ROWS_3.'" placeholder="'.dol_escape_htmltag($langs->trans("ScanOrTypeOrCopyPasteYourBarCodes")).'"></textarea>';
101
102 /*print '<br>'.$langs->trans("or").'<br>';
103
104 print '<br>';
105
106 print '<input type="text" name="barcodelotserial" class="width200"> &nbsp; &nbsp; Qty <input type="text" name="barcodelotserialqty" class="width50 right" value="1"><br>';
107 */
108 $out .= '<br>';
109 $out .= '<center>';
110 $out .= '<input type="submit" class="button marginleftonly marginrightonly" id ="exec'.dol_escape_js($jstoexecuteonadd).'" name="addscan" value="'.dol_escape_htmltag($langs->trans("Add")).'">';
111 $out .= '<input type="submit" class="button marginleftonly marginrightonly" name="cancel" value="'.dol_escape_htmltag($langs->trans("CloseWindow")).'">';
112 $out .= '</center>';
113 $out .= '<br>';
114 $out .= '<div type="text" id="scantoolmessage" class="scantoolmessage ok nopadding"></div>';
115
116 $out .= '<script nonce="'.getNonce().'">';
117 $out .= 'jQuery("#barcodeforautodetect, #barcodeforproduct, #barcodeforlotserial").click(function(){';
118 $out .= 'console.log("select choice");';
119 $out .= 'jQuery("#scantoolmessage").text("");';
120 $out .= '});'."\n";
121 $out .= '$("#exec'.dol_escape_js($jstoexecuteonadd).'").click(function(){
122 console.log("We call js to execute \''.dol_escape_js($jstoexecuteonadd).'\'");
123 '.dol_escape_js($jstoexecuteonadd).'();
124 return false; /* We want to stay on the scan tool */
125 })';
126 $out .= '</script>';
127
128 $out .= '</center>';
129 $out .= '</div>';
130
131 return $out;
132 }
133
134 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
145 public function select_export_model($selected = '', $htmlname = 'exportmodelid', $type = '', $useempty = 0, $fk_user = null)
146 {
147 // phpcs:enable
148 global $conf, $langs, $user;
149
150 $sql = "SELECT rowid, label, fk_user";
151 $sql .= " FROM ".$this->db->prefix()."export_model";
152 $sql .= " WHERE type = '".$this->db->escape($type)."'";
153 if (!getDolGlobalString('EXPORTS_SHARE_MODELS')) { // EXPORTS_SHARE_MODELS means all templates are visible, whatever is owner.
154 $sql .= " AND fk_user IN (0, ".((int) $fk_user).")";
155 }
156 $sql .= " ORDER BY label";
157 $result = $this->db->query($sql);
158 if ($result) {
159 print '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
160 if ($useempty) {
161 print '<option value="-1">&nbsp;</option>';
162 }
163
164 $tmpuser = new User($this->db);
165
166 $num = $this->db->num_rows($result);
167 $i = 0;
168 while ($i < $num) {
169 $obj = $this->db->fetch_object($result);
170
171 $label = $obj->label;
172 if ($obj->fk_user == 0) {
173 $label .= ' <span class="opacitymedium">('.$langs->trans("Everybody").')</span>';
174 } elseif ($obj->fk_user > 0) {
175 $tmpuser->fetch($obj->fk_user);
176 $label .= ' <span class="opacitymedium">('.$tmpuser->getFullName($langs).')</span>';
177 }
178
179 if ($selected == $obj->rowid) {
180 print '<option value="'.$obj->rowid.'" selected data-html="'.dol_escape_htmltag($label).'">';
181 } else {
182 print '<option value="'.$obj->rowid.'" data-html="'.dol_escape_htmltag($label).'">';
183 }
184 print $label;
185 print '</option>';
186 $i++;
187 }
188 print "</select>";
189 print ajax_combobox($htmlname);
190 } else {
191 dol_print_error($this->db);
192 }
193 }
194
195
196 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
207 public function select_import_model($selected = '', $htmlname = 'importmodelid', $type = '', $useempty = 0, $fk_user = null)
208 {
209 // phpcs:enable
210 global $conf, $langs, $user;
211
212 $sql = "SELECT rowid, label, fk_user";
213 $sql .= " FROM ".$this->db->prefix()."import_model";
214 $sql .= " WHERE type = '".$this->db->escape($type)."'";
215 if (!getDolGlobalString('EXPORTS_SHARE_MODELS')) { // EXPORTS_SHARE_MODELS means all templates are visible, whatever is owner.
216 $sql .= " AND fk_user IN (0, ".((int) $fk_user).")";
217 }
218 $sql .= " ORDER BY label";
219 $result = $this->db->query($sql);
220 if ($result) {
221 print '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
222 if ($useempty) {
223 print '<option value="-1">&nbsp;</option>';
224 }
225
226 $tmpuser = new User($this->db);
227
228 $num = $this->db->num_rows($result);
229 $i = 0;
230 while ($i < $num) {
231 $obj = $this->db->fetch_object($result);
232
233 $label = $obj->label;
234 if ($obj->fk_user == 0) {
235 $label .= ' <span class="opacitymedium">('.$langs->trans("Everybody").')</span>';
236 } elseif ($obj->fk_user > 0) {
237 $tmpuser->fetch($obj->fk_user);
238 $label .= ' <span class="opacitymedium">('.$tmpuser->getFullName($langs).')</span>';
239 }
240
241 if ($selected == $obj->rowid) {
242 print '<option value="'.$obj->rowid.'" selected data-html="'.dol_escape_htmltag($label).'">';
243 } else {
244 print '<option value="'.$obj->rowid.'" data-html="'.dol_escape_htmltag($label).'">';
245 }
246 print $label;
247 print '</option>';
248 $i++;
249 }
250 print "</select>";
251 print ajax_combobox($htmlname);
252 } else {
253 dol_print_error($this->db);
254 }
255 }
256
257
258 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
266 public function select_ecotaxes($selected = '', $htmlname = 'ecotaxe_id')
267 {
268 // phpcs:enable
269 global $langs;
270
271 $sql = "SELECT e.rowid, e.code, e.label, e.price, e.organization,";
272 $sql .= " c.label as country";
273 $sql .= " FROM ".$this->db->prefix()."c_ecotaxe as e,".$this->db->prefix()."c_country as c";
274 $sql .= " WHERE e.active = 1 AND e.fk_pays = c.rowid";
275 $sql .= " ORDER BY country, e.organization ASC, e.code ASC";
276
277 dol_syslog(get_class($this).'::select_ecotaxes', LOG_DEBUG);
278 $resql = $this->db->query($sql);
279 if ($resql) {
280 print '<select class="flat" name="'.$htmlname.'">';
281 $num = $this->db->num_rows($resql);
282 $i = 0;
283 print '<option value="-1">&nbsp;</option>'."\n";
284 if ($num) {
285 while ($i < $num) {
286 $obj = $this->db->fetch_object($resql);
287 if ($selected && $selected == $obj->rowid) {
288 print '<option value="'.$obj->rowid.'" selected>';
289 } else {
290 print '<option value="'.$obj->rowid.'">';
291 //print '<option onmouseover="showtip(\''.$obj->label.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
292 }
293 $selectOptionValue = $obj->code.' - '.$obj->label.' : '.price($obj->price).' '.$langs->trans("HT").' ('.$obj->organization.')';
294 print $selectOptionValue;
295 print '</option>';
296 $i++;
297 }
298 }
299 print '</select>';
300 return 0;
301 } else {
302 dol_print_error($this->db);
303 return 1;
304 }
305 }
306
307
308 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
317 public function select_revenue_stamp($selected = '', $htmlname = 'revenuestamp', $country_code = '')
318 {
319 // phpcs:enable
320 global $langs;
321
322 $out = '';
323
324 $sql = "SELECT r.taux, r.revenuestamp_type";
325 $sql .= " FROM ".$this->db->prefix()."c_revenuestamp as r,".$this->db->prefix()."c_country as c";
326 $sql .= " WHERE r.active = 1 AND r.fk_pays = c.rowid";
327 $sql .= " AND c.code = '".$this->db->escape($country_code)."'";
328
329 dol_syslog(get_class($this).'::select_revenue_stamp', LOG_DEBUG);
330 $resql = $this->db->query($sql);
331 if ($resql) {
332 $out .= '<select class="flat" name="'.$htmlname.'">';
333 $num = $this->db->num_rows($resql);
334 $i = 0;
335 $out .= '<option value="0">&nbsp;</option>'."\n";
336 if ($num) {
337 while ($i < $num) {
338 $obj = $this->db->fetch_object($resql);
339 if (($selected && $selected == $obj->taux) || $num == 1) {
340 $out .= '<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').' selected>';
341 } else {
342 $out .= '<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').'>';
343 }
344 $out .= $obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '');
345 $out .= '</option>';
346 $i++;
347 }
348 }
349 $out .= '</select>';
350 return $out;
351 } else {
352 dol_print_error($this->db);
353 return '';
354 }
355 }
356
357
358 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
371 public function select_percent($selected = 0, $htmlname = 'percent', $disabled = 0, $increment = 5, $start = 0, $end = 100, $showempty = 0)
372 {
373 // phpcs:enable
374 $return = '<select class="flat maxwidth75 right" name="'.$htmlname.'" '.($disabled ? 'disabled' : '').'>';
375 if ($showempty) {
376 $return .= '<option value="-1"'.(($selected == -1 || $selected == '') ? ' selected' : '').'>&nbsp;</option>';
377 }
378
379 for ($i = $start; $i <= $end; $i += $increment) {
380 if ($selected != '' && (int) $selected == $i) {
381 $return .= '<option value="'.$i.'" selected>';
382 } else {
383 $return .= '<option value="'.$i.'">';
384 }
385 $return .= $i.' % ';
386 $return .= '</option>';
387 }
388
389 $return .= '</select>';
390
391 return $return;
392 }
393
394 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
407 public function select_categories($type, $selected = 0, $htmlname = 'search_categ', $nocateg = 0, $showempty = 1, $morecss = '')
408 {
409 // phpcs:enable
410 global $conf, $langs;
411 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
412
413 // For backward compatibility
414 if (is_numeric($type)) {
415 dol_syslog(__METHOD__.': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING);
416 }
417
418 // Load list of "categories"
419 $static_categs = new Categorie($this->db);
420 $tab_categs = $static_categs->get_full_arbo($type);
421
422 $moreforfilter = '';
423
424 // Print a select with each of them
425 $moreforfilter .= '<select class="flat minwidth100'.($morecss ? ' '.$morecss : '').'" id="select_categ_'.$htmlname.'" name="'.$htmlname.'">';
426 if ($showempty) {
427 $textforempty = ' ';
428 if (!empty($conf->use_javascript_ajax)) {
429 $textforempty = '&nbsp;'; // If we use ajaxcombo, we need &nbsp; here to avoid to have an empty element that is too small.
430 }
431 if (!is_numeric($showempty)) {
432 $textforempty = $showempty;
433 }
434 $moreforfilter .= '<option class="optiongrey" value="'.($showempty < 0 ? $showempty : -1).'"'.($selected == $showempty ? ' selected' : '');
435 //$moreforfilter .= ' data-html="'.dol_escape_htmltag($textforempty).'"';
436 $moreforfilter .= '>'.dol_escape_htmltag($textforempty).'</option>'."\n";
437 }
438
439 if (is_array($tab_categs)) {
440 foreach ($tab_categs as $categ) {
441 $moreforfilter .= '<option value="'.$categ['id'].'"';
442 if ($categ['id'] == $selected) {
443 $moreforfilter .= ' selected';
444 }
445 $moreforfilter .= ' data-html="'.dol_escape_htmltag(img_picto('', 'category', 'class="pictofixedwidth" style="color: #'.$categ['color'].'"').dol_trunc($categ['fulllabel'], 50, 'middle')).'"';
446 $moreforfilter .= '>'.dol_trunc($categ['fulllabel'], 50, 'middle').'</option>';
447 }
448 }
449 if ($nocateg) {
450 $langs->load("categories");
451 $moreforfilter .= '<option value="-2"'.($selected == -2 ? ' selected' : '').'>- '.$langs->trans("NotCategorized").' -</option>';
452 }
453 $moreforfilter .= '</select>';
454
455 // Enhance with select2
456 if ($conf->use_javascript_ajax) {
457 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
458 $comboenhancement = ajax_combobox('select_categ_'.$htmlname);
459 $moreforfilter .= $comboenhancement;
460 }
461
462 return $moreforfilter;
463 }
464
465
466 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
479 public function select_salesrepresentatives($selected, $htmlname, $user, $showstatus = 0, $showempty = 1, $morecss = '', $norepresentative = 0)
480 {
481 // phpcs:enable
482 global $conf, $langs, $hookmanager;
483 global $action;
484
485 $langs->load('users');
486
487 $out = '';
488
489 $reshook = $hookmanager->executeHooks('addSQLWhereFilterOnSelectSalesRep', array(), $this, $action);
490
491 // Select each sales and print them in a select input
492 $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'">';
493 if ($showempty) {
494 $textforempty = ' ';
495 if (!is_numeric($showempty)) {
496 $textforempty = $showempty;
497 }
498 if (!empty($conf->use_javascript_ajax) && $textforempty == ' ') {
499 $textforempty = '&nbsp;'; // If we use ajaxcombo, we need &nbsp; here to avoid to have an empty element that is too small.
500 }
501 $out .= '<option class="optiongrey" value="'.($showempty < 0 ? $showempty : -1).'"'.($selected == $showempty ? ' selected' : '').'>'.$textforempty.'</option>'."\n";
502 }
503
504 // Get list of users allowed to be viewed
505 $sql_usr = "SELECT u.rowid, u.lastname, u.firstname, u.statut as status, u.login, u.photo, u.gender, u.entity, u.admin";
506 $sql_usr .= " FROM ".$this->db->prefix()."user as u";
507
508 if (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
509 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
510 $sql_usr .= " WHERE u.entity IS NOT NULL"; // Show all users
511 } else {
512 $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')."))";
513 $sql_usr .= " OR u.entity = 0"; // Show always superadmin
514 }
515 } else {
516 $sql_usr .= " WHERE u.entity IN (".getEntity('user').")";
517 }
518
519 if (!$user->hasRight('user', 'user', 'lire')) {
520 $sql_usr .= " AND u.rowid = ".((int) $user->id);
521 }
522 if (!empty($user->socid)) {
523 $sql_usr .= " AND u.fk_soc = ".((int) $user->socid);
524 }
525
526 //Add hook to filter on user (for exemple on usergroup define in custom modules)
527 if (!empty($reshook)) {
528 $sql_usr .= $hookmanager->resArray[0];
529 }
530
531 // Add existing sales representatives of thirdparty of external user
532 if (!$user->hasRight('user', 'user', 'lire') && $user->socid) {
533 $sql_usr .= " UNION ";
534 $sql_usr .= "SELECT u2.rowid, u2.lastname, u2.firstname, u2.statut as status, u2.login, u2.photo, u2.gender, u2.entity, u2.admin";
535 $sql_usr .= " FROM ".$this->db->prefix()."user as u2, ".$this->db->prefix()."societe_commerciaux as sc";
536
537 if (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
538 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
539 $sql_usr .= " WHERE u2.entity IS NOT NULL"; // Show all users
540 } else {
541 $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')."))";
542 }
543 } else {
544 $sql_usr .= " WHERE u2.entity IN (".getEntity('user').")";
545 }
546
547 $sql_usr .= " AND u2.rowid = sc.fk_user AND sc.fk_soc = ".((int) $user->socid);
548
549 //Add hook to filter on user (for exemple on usergroup define in custom modules)
550 if (!empty($reshook)) {
551 $sql_usr .= $hookmanager->resArray[1];
552 }
553 }
554
555 if (!getDolGlobalString('MAIN_FIRSTNAME_NAME_POSITION')) { // MAIN_FIRSTNAME_NAME_POSITION is 0 means firstname+lastname
556 $sql_usr .= " ORDER BY status DESC, firstname ASC, lastname ASC";
557 } else {
558 $sql_usr .= " ORDER BY status DESC, lastname ASC, firstname ASC";
559 }
560 //print $sql_usr;exit;
561
562 $resql_usr = $this->db->query($sql_usr);
563 if ($resql_usr) {
564 $userstatic = new User($this->db);
565
566 while ($obj_usr = $this->db->fetch_object($resql_usr)) {
567 $userstatic->id = $obj_usr->rowid;
568 $userstatic->lastname = $obj_usr->lastname;
569 $userstatic->firstname = $obj_usr->firstname;
570 $userstatic->photo = $obj_usr->photo;
571 $userstatic->statut = $obj_usr->status;
572 $userstatic->entity = $obj_usr->entity;
573 $userstatic->admin = $obj_usr->admin;
574
575 $labeltoshow = dolGetFirstLastname($obj_usr->firstname, $obj_usr->lastname);
576 if (empty($obj_usr->firstname) && empty($obj_usr->lastname)) {
577 $labeltoshow = $obj_usr->login;
578 }
579
580 $out .= '<option value="'.$obj_usr->rowid.'"';
581 if ($obj_usr->rowid == $selected) {
582 $out .= ' selected';
583 }
584 $out .= ' data-html="';
585 $outhtml = $userstatic->getNomUrl(-3, '', 0, 1, 24, 1, 'login', '', 1).' ';
586 if ($showstatus >= 0 && $obj_usr->status == 0) {
587 $outhtml .= '<strike class="opacitymediumxxx">';
588 }
589 $outhtml .= $labeltoshow;
590 if ($showstatus >= 0 && $obj_usr->status == 0) {
591 $outhtml .= '</strike>';
592 }
593 $out .= dol_escape_htmltag($outhtml);
594 $out .= '">';
595
596 $out .= $labeltoshow;
597 // Complete name with more info
598 $moreinfo = 0;
599 if (getDolGlobalString('MAIN_SHOW_LOGIN')) {
600 $out .= ($moreinfo ? ' - ' : ' (').$obj_usr->login;
601 $moreinfo++;
602 }
603 if ($showstatus >= 0) {
604 if ($obj_usr->status == 1 && $showstatus == 1) {
605 $out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Enabled');
606 $moreinfo++;
607 }
608 if ($obj_usr->status == 0) {
609 $out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Disabled');
610 $moreinfo++;
611 }
612 }
613 $out .= ($moreinfo ? ')' : '');
614 $out .= '</option>';
615 }
616 $this->db->free($resql_usr);
617 } else {
618 dol_print_error($this->db);
619 }
620
621 if ($norepresentative) {
622 $langs->load("companies");
623 $out .= '<option value="-2"'.($selected == -2 ? ' selected' : '').'>- '.$langs->trans("NoSalesRepresentativeAffected").' -</option>';
624 }
625
626 $out .= '</select>';
627
628 // Enhance with select2
629 if ($conf->use_javascript_ajax) {
630 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
631
632 $comboenhancement = ajax_combobox($htmlname);
633 if ($comboenhancement) {
634 $out .= $comboenhancement;
635 }
636 }
637
638 return $out;
639 }
640
656 public function selectProjectTasks($selectedtask = '', $projectid = 0, $htmlname = 'task_parent', $modeproject = 0, $modetask = 0, $mode = 0, $useempty = 0, $disablechildoftaskid = 0, $filteronprojstatus = '', $morecss = '')
657 {
658 global $user, $langs;
659
660 require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
661
662 //print $modeproject.'-'.$modetask;
663 $task = new Task($this->db);
664 $tasksarray = $task->getTasksArray($modetask ? $user : 0, $modeproject ? $user : 0, $projectid, 0, $mode, '', $filteronprojstatus);
665 if ($tasksarray) {
666 print '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
667 if ($useempty) {
668 print '<option value="0">&nbsp;</option>';
669 }
670 $j = 0;
671 $level = 0;
672 $this->_pLineSelect($j, 0, $tasksarray, $level, $selectedtask, $projectid, $disablechildoftaskid);
673 print '</select>';
674
675 print ajax_combobox($htmlname);
676 } else {
677 print '<div class="warning">'.$langs->trans("NoProject").'</div>';
678 }
679 }
680
693 private function _pLineSelect(&$inc, $parent, $lines, $level = 0, $selectedtask = 0, $selectedproject = 0, $disablechildoftaskid = 0)
694 {
695 global $langs, $user, $conf;
696
697 $lastprojectid = 0;
698
699 $numlines = count($lines);
700 for ($i = 0; $i < $numlines; $i++) {
701 if ($lines[$i]->fk_task_parent == $parent) {
702 //var_dump($selectedproject."--".$selectedtask."--".$lines[$i]->fk_project."_".$lines[$i]->id); // $lines[$i]->id may be empty if project has no lines
703
704 // Break on a new project
705 if ($parent == 0) { // We are on a task at first level
706 if ($lines[$i]->fk_project != $lastprojectid) { // Break found on project
707 if ($i > 0) {
708 print '<option value="0" disabled>----------</option>';
709 }
710 print '<option value="'.$lines[$i]->fk_project.'_0"';
711 if ($selectedproject == $lines[$i]->fk_project) {
712 print ' selected';
713 }
714
715 $labeltoshow = $lines[$i]->projectref;
716 //$labeltoshow .= ' '.$lines[$i]->projectlabel;
717 if (empty($lines[$i]->public)) {
718 //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')</span>';
719 $labeltoshow = img_picto($lines[$i]->projectlabel, 'project', 'class="pictofixedwidth"').$labeltoshow;
720 } else {
721 //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')</span>';
722 $labeltoshow = img_picto($lines[$i]->projectlabel, 'projectpub', 'class="pictofixedwidth"').$labeltoshow;
723 }
724
725 print ' data-html="'.dol_escape_htmltag($labeltoshow).'"';
726 print '>'; // Project -> Task
727 print $labeltoshow;
728 print "</option>\n";
729
730 $lastprojectid = $lines[$i]->fk_project;
731 $inc++;
732 }
733 }
734
735 $newdisablechildoftaskid = $disablechildoftaskid;
736
737 // Print task
738 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
739 // Check if we must disable entry
740 $disabled = 0;
741 if ($disablechildoftaskid && (($lines[$i]->id == $disablechildoftaskid || $lines[$i]->fk_task_parent == $disablechildoftaskid))) {
742 $disabled++;
743 if ($lines[$i]->fk_task_parent == $disablechildoftaskid) {
744 $newdisablechildoftaskid = $lines[$i]->id; // If task is child of a disabled parent, we will propagate id to disable next child too
745 }
746 }
747
748 print '<option value="'.$lines[$i]->fk_project.'_'.$lines[$i]->id.'"';
749 if (($lines[$i]->id == $selectedtask) || ($lines[$i]->fk_project.'_'.$lines[$i]->id == $selectedtask)) {
750 print ' selected';
751 }
752 if ($disabled) {
753 print ' disabled';
754 }
755
756 $labeltoshow = $lines[$i]->projectref;
757 //$labeltoshow .= ' '.$lines[$i]->projectlabel;
758 if (empty($lines[$i]->public)) {
759 //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')</span>';
760 $labeltoshow = img_picto($lines[$i]->projectlabel, 'project', 'class="pictofixedwidth"').$labeltoshow;
761 } else {
762 //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')</span>';
763 $labeltoshow = img_picto($lines[$i]->projectlabel, 'projectpub', 'class="pictofixedwidth"').$labeltoshow;
764 }
765 if ($lines[$i]->id) {
766 $labeltoshow .= ' > ';
767 }
768 for ($k = 0; $k < $level; $k++) {
769 $labeltoshow .= "&nbsp;&nbsp;&nbsp;";
770 }
771 $labeltoshow .= $lines[$i]->ref.' '.$lines[$i]->label;
772
773 print ' data-html="'.dol_escape_htmltag($labeltoshow).'"';
774 print '>';
775 print $labeltoshow;
776 print "</option>\n";
777 $inc++;
778 }
779
780 $level++;
781 if ($lines[$i]->id) {
782 $this->_pLineSelect($inc, $lines[$i]->id, $lines, $level, $selectedtask, $selectedproject, $newdisablechildoftaskid);
783 }
784 $level--;
785 }
786 }
787 }
788
789
798 public static function showColor($color, $textifnotdefined = '')
799 {
800 $textcolor = 'FFF';
801 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
802 if (colorIsLight($color)) {
803 $textcolor = '000';
804 }
805
806 $color = colorArrayToHex(colorStringToArray($color, array()), '');
807
808 if ($color) {
809 return '<input type="text" class="colorthumb" disabled style="padding: 1px; margin-top: 0; margin-bottom: 0; color: #'.$textcolor.'; background-color: #'.$color.'" value="'.$color.'">';
810 } else {
811 return $textifnotdefined;
812 }
813 }
814
815 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
828 public function select_color($set_color = '', $prefix = 'f_color', $form_name = '', $showcolorbox = 1, $arrayofcolors = '')
829 {
830 // phpcs:enable
831 print $this->selectColor($set_color, $prefix, $form_name, $showcolorbox, $arrayofcolors);
832 }
833
848 public static function selectColor($set_color = '', $prefix = 'f_color', $form_name = '', $showcolorbox = 1, $arrayofcolors = '', $morecss = '', $setpropertyonselect = '', $default = '')
849 {
850 // Deprecation warning
851 if ($form_name) {
852 dol_syslog(__METHOD__.": form_name parameter is deprecated", LOG_WARNING);
853 }
854
855 global $langs, $conf;
856
857 $out = '';
858
859 if (!is_array($arrayofcolors) || count($arrayofcolors) < 1) {
860 // Case of selection of any color
861 $langs->load("other");
862 if (empty($conf->dol_use_jmobile) && !empty($conf->use_javascript_ajax) && !getDolGlobalInt('MAIN_USE_HTML5_COLOR_SELECTOR')) {
863 $out .= '<link rel="stylesheet" media="screen" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css" />';
864 $out .= '<script nonce="'.getNonce().'" type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/jpicker-1.1.6.js"></script>';
865 $out .= '<script nonce="'.getNonce().'" type="text/javascript">
866 jQuery(document).ready(function(){
867 var originalhex = null;
868 $(\'#colorpicker'.$prefix.'\').jPicker( {
869 window: {
870 title: \''.dol_escape_js($langs->trans("SelectAColor")).'\', /* any title for the jPicker window itself - displays "Drag Markers To Pick A Color" if left null */
871 effects:
872 {
873 type: \'show\', /* effect used to show/hide an expandable picker. Acceptable values "slide", "show", "fade" */
874 speed:
875 {
876 show: \'fast\', /* duration of "show" effect. Acceptable values are "fast", "slow", or time in ms */
877 hide: \'fast\' /* duration of "hide" effect. Acceptable values are "fast", "slow", or time in ms */
878 }
879 },
880 position:
881 {
882 x: \'screenCenter\', /* acceptable values "left", "center", "right", "screenCenter", or relative px value */
883 y: \'center\' /* acceptable values "top", "bottom", "center", or relative px value */
884 },
885 },
886 images: {
887 clientPath: \''.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/images/\',
888 picker: { file: \'../../../../../theme/common/colorpicker.png\', width: 14, height: 14 }
889 },
890 localization: // alter these to change the text presented by the picker (e.g. different language)
891 {
892 text:
893 {
894 title: \''.dol_escape_js($langs->trans("SelectAColor")).'\',
895 newColor: \''.dol_escape_js($langs->trans("New")).'\',
896 currentColor: \''.dol_escape_js($langs->trans("Current")).'\',
897 ok: \''.dol_escape_js($langs->trans("Validate")).'\',
898 cancel: \''.dol_escape_js($langs->trans("Cancel")).'\'
899 }
900 }
901 },
902 function(color, context) { console.log("close color selector"); },
903 function(color, context) { var hex = color.val(\'hex\'); console.log("new color selected in jpicker "+hex+" setpropertyonselect='.dol_escape_js($setpropertyonselect).'");';
904 if ($setpropertyonselect) {
905 $out .= 'if (originalhex == null) {';
906 $out .= ' originalhex = getComputedStyle(document.querySelector(":root")).getPropertyValue(\'--'.dol_escape_js($setpropertyonselect).'\');';
907 $out .= ' console.log("original color is saved into originalhex = "+originalhex);';
908 $out .= '}';
909 $out .= 'if (hex != null) {';
910 $out .= ' document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', \'#\'+hex);';
911 $out .= '}';
912 }
913 $out .= '},
914 function(color, context) {
915 console.log("cancel selection of color");';
916 if ($setpropertyonselect) {
917 $out .= 'if (originalhex != null) {
918 console.log("Restore old color "+originalhex);
919 document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', originalhex);
920 }';
921 }
922 $out .= '
923 }
924 );
925 });
926 </script>';
927 $out .= '<input id="colorpicker'.$prefix.'" name="'.$prefix.'" size="6" maxlength="7" class="flat valignmiddle'.($morecss ? ' '.$morecss : '').'" type="text" value="'.dol_escape_htmltag($set_color).'" />';
928 } else {
929 $color = ($set_color !== '' ? $set_color : ($default !== '' ? $default : 'FFFFFF'));
930 $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).'" />';
931 $out .= '<script nonce="'.getNonce().'" type="text/javascript">
932 jQuery(document).ready(function(){
933 var originalhex = null;
934 jQuery("#colorpicker'.$prefix.'").on(\'change\', function() {
935 var hex = jQuery("#colorpicker'.$prefix.'").val();
936 console.log("new color selected in input color "+hex+" setpropertyonselect='.dol_escape_js($setpropertyonselect).'");';
937 if ($setpropertyonselect) {
938 $out .= 'if (originalhex == null) {';
939 $out .= ' originalhex = getComputedStyle(document.querySelector(":root")).getPropertyValue(\'--'.dol_escape_js($setpropertyonselect).'\');';
940 $out .= ' console.log("original color is saved into originalhex = "+originalhex);';
941 $out .= '}';
942 $out .= 'if (hex != null) {';
943 $out .= ' document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', hex);';
944 $out .= '}';
945 }
946 $out .= '
947 });
948 });
949 </script>';
950 }
951 } else {
952 // In most cases, this is not used. We used instead function with no specific list of colors
953 if (empty($conf->dol_use_jmobile) && !empty($conf->use_javascript_ajax)) {
954 $out .= '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.css" type="text/css" media="screen" />';
955 $out .= '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.js" type="text/javascript"></script>';
956 $out .= '<script nonce="'.getNonce().'" type="text/javascript">
957 jQuery(document).ready(function(){
958 jQuery(\'#colorpicker'.$prefix.'\').colorpicker({
959 size: 14,
960 label: \'\',
961 hide: true
962 });
963 });
964 </script>';
965 }
966 $out .= '<select id="colorpicker'.$prefix.'" class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$prefix.'">';
967 //print '<option value="-1">&nbsp;</option>';
968 foreach ($arrayofcolors as $val) {
969 $out .= '<option value="'.$val.'"';
970 if ($set_color == $val) {
971 $out .= ' selected';
972 }
973 $out .= '>'.$val.'</option>';
974 }
975 $out .= '</select>';
976 }
977
978 return $out;
979 }
980
981 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
992 public function CreateColorIcon($color, $module, $name, $x = '12', $y = '12')
993 {
994 // phpcs:enable
995 global $conf;
996
997 $file = $conf->$module->dir_temp.'/'.$name.'.png';
998
999 // We create temp directory
1000 if (!file_exists($conf->$module->dir_temp)) {
1001 dol_mkdir($conf->$module->dir_temp);
1002 }
1003
1004 // On cree l'image en vraies couleurs
1005 $image = imagecreatetruecolor($x, $y);
1006
1007 $color = substr($color, 1, 6);
1008
1009 $rouge = hexdec(substr($color, 0, 2)); //conversion du canal rouge
1010 $vert = hexdec(substr($color, 2, 2)); //conversion du canal vert
1011 $bleu = hexdec(substr($color, 4, 2)); //conversion du canal bleu
1012
1013 $couleur = imagecolorallocate($image, $rouge, $vert, $bleu);
1014 //print $rouge.$vert.$bleu;
1015 imagefill($image, 0, 0, $couleur); //on remplit l'image
1016 // On cree la couleur et on l'attribue a une variable pour ne pas la perdre
1017 ImagePng($image, $file); //renvoie une image sous format png
1018 ImageDestroy($image);
1019 }
1020
1021 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1030 public function select_dayofweek($selected = '', $htmlname = 'weekid', $useempty = 0)
1031 {
1032 // phpcs:enable
1033 global $langs;
1034
1035 $week = array(
1036 0=>$langs->trans("Day0"),
1037 1=>$langs->trans("Day1"),
1038 2=>$langs->trans("Day2"),
1039 3=>$langs->trans("Day3"),
1040 4=>$langs->trans("Day4"),
1041 5=>$langs->trans("Day5"),
1042 6=>$langs->trans("Day6")
1043 );
1044
1045 $select_week = '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
1046 if ($useempty) {
1047 $select_week .= '<option value="-1">&nbsp;</option>';
1048 }
1049 foreach ($week as $key => $val) {
1050 if ($selected == $key) {
1051 $select_week .= '<option value="'.$key.'" selected>';
1052 } else {
1053 $select_week .= '<option value="'.$key.'">';
1054 }
1055 $select_week .= $val;
1056 $select_week .= '</option>';
1057 }
1058 $select_week .= '</select>';
1059
1060 $select_week .= ajax_combobox($htmlname);
1061
1062 return $select_week;
1063 }
1064
1065 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1077 public function select_month($selected = '', $htmlname = 'monthid', $useempty = 0, $longlabel = 0, $morecss = 'minwidth50 maxwidth75imp valignmiddle', $addjscombo = false)
1078 {
1079 // phpcs:enable
1080 global $langs;
1081
1082 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
1083
1084 if ($longlabel) {
1085 $montharray = monthArray($langs, 0); // Get array
1086 } else {
1087 $montharray = monthArray($langs, 1);
1088 }
1089
1090 $select_month = '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
1091 if ($useempty) {
1092 $select_month .= '<option value="0">&nbsp;</option>';
1093 }
1094 foreach ($montharray as $key => $val) {
1095 if ($selected == $key) {
1096 $select_month .= '<option value="'.$key.'" selected>';
1097 } else {
1098 $select_month .= '<option value="'.$key.'">';
1099 }
1100 $select_month .= $val;
1101 $select_month .= '</option>';
1102 }
1103 $select_month .= '</select>';
1104
1105 // Add code for jquery to use multiselect
1106 if ($addjscombo) {
1107 // Enhance with select2
1108 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1109 $select_month .= ajax_combobox($htmlname);
1110 }
1111
1112 return $select_month;
1113 }
1114
1115 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1132 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)
1133 {
1134 // phpcs:enable
1135 print $this->selectyear($selected, $htmlname, $useempty, $min_year, $max_year, $offset, $invert, $option, $morecss, $addjscombo);
1136 }
1137
1153 public function selectyear($selected = '', $htmlname = 'yearid', $useempty = 0, $min_year = 10, $max_year = 5, $offset = 0, $invert = 0, $option = '', $morecss = 'valignmiddle width75', $addjscombo = false)
1154 {
1155 $out = '';
1156
1157 $currentyear = date("Y") + $offset;
1158 $max_year = $currentyear + $max_year;
1159 $min_year = $currentyear - $min_year;
1160 if (empty($selected) && empty($useempty)) {
1161 $selected = $currentyear;
1162 }
1163
1164 $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'"'.$option.' >';
1165 if ($useempty) {
1166 $selected_html = '';
1167 if ($selected == '') {
1168 $selected_html = ' selected';
1169 }
1170 $out .= '<option value=""'.$selected_html.'>&nbsp;</option>';
1171 }
1172 if (!$invert) {
1173 for ($y = $max_year; $y >= $min_year; $y--) {
1174 $selected_html = '';
1175 if ($selected > 0 && $y == $selected) {
1176 $selected_html = ' selected';
1177 }
1178 $out .= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
1179 }
1180 } else {
1181 for ($y = $min_year; $y <= $max_year; $y++) {
1182 $selected_html = '';
1183 if ($selected > 0 && $y == $selected) {
1184 $selected_html = ' selected';
1185 }
1186 $out .= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
1187 }
1188 }
1189 $out .= "</select>\n";
1190
1191 // Add code for jquery to use multiselect
1192 if ($addjscombo) {
1193 // Enhance with select2
1194 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1195 $out .= ajax_combobox($htmlname);
1196 }
1197
1198 return $out;
1199 }
1200
1201
1210 public static function getBoxesArea($user, $areacode)
1211 {
1212 global $conf, $langs, $db;
1213
1214 include_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
1215
1216 $confuserzone = 'MAIN_BOXES_'.$areacode;
1217
1218 // $boxactivated will be array of boxes enabled into global setup
1219 // $boxidactivatedforuser will be array of boxes choosed by user
1220
1221 $selectboxlist = '';
1222 $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)
1223
1224 $boxidactivatedforuser = array();
1225 foreach ($boxactivated as $box) {
1226 if (empty($user->conf->$confuserzone) || $box->fk_user == $user->id) {
1227 $boxidactivatedforuser[$box->id] = $box->id; // We keep only boxes to show for user
1228 }
1229 }
1230
1231 // Define selectboxlist
1232 $arrayboxtoactivatelabel = array();
1233 if (!empty($user->conf->$confuserzone)) {
1234 $boxorder = '';
1235 $langs->load("boxes"); // Load label of boxes
1236 foreach ($boxactivated as $box) {
1237 if (!empty($boxidactivatedforuser[$box->id])) {
1238 continue; // Already visible for user
1239 }
1240 $label = $langs->transnoentitiesnoconv($box->boxlabel);
1241 //if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph").')';
1242 if (preg_match('/graph/', $box->class) && $conf->browser->layout != 'phone') {
1243 $label = $label.' <span class="fas fa-chart-bar"></span>';
1244 }
1245 $arrayboxtoactivatelabel[$box->id] = array('label'=>$label, 'data-html'=>img_picto('', $box->boximg, 'class="pictofixedwidth"').$langs->trans($label)); // We keep only boxes not shown for user, to show into combo list
1246 }
1247 foreach ($boxidactivatedforuser as $boxid) {
1248 if (empty($boxorder)) {
1249 $boxorder .= 'A:';
1250 }
1251 $boxorder .= $boxid.',';
1252 }
1253
1254 //var_dump($boxidactivatedforuser);
1255
1256 // Class Form must have been already loaded
1257 $selectboxlist .= '<!-- Form with select box list -->'."\n";
1258 $selectboxlist .= '<form id="addbox" name="addbox" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
1259 $selectboxlist .= '<input type="hidden" name="token" value="'.newToken().'">';
1260 $selectboxlist .= '<input type="hidden" name="addbox" value="addbox">';
1261 $selectboxlist .= '<input type="hidden" name="userid" value="'.$user->id.'">';
1262 $selectboxlist .= '<input type="hidden" name="areacode" value="'.$areacode.'">';
1263 $selectboxlist .= '<input type="hidden" name="boxorder" value="'.$boxorder.'">';
1264 $selectboxlist .= Form::selectarray('boxcombo', $arrayboxtoactivatelabel, -1, $langs->trans("ChooseBoxToAdd").'...', 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth150onsmartphone hideonprint', 0, 'hidden selected', 0, 0);
1265 if (empty($conf->use_javascript_ajax)) {
1266 $selectboxlist .= ' <input type="submit" class="button" value="'.$langs->trans("AddBox").'">';
1267 }
1268 $selectboxlist .= '</form>';
1269 if (!empty($conf->use_javascript_ajax)) {
1270 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1271 $selectboxlist .= ajax_combobox("boxcombo");
1272 }
1273 }
1274
1275 // Javascript code for dynamic actions
1276 if (!empty($conf->use_javascript_ajax)) {
1277 $selectboxlist .= '<script nonce="'.getNonce().'" type="text/javascript">
1278
1279 // To update list of activated boxes
1280 function updateBoxOrder(closing) {
1281 var left_list = cleanSerialize(jQuery("#boxhalfleft").sortable("serialize"));
1282 var right_list = cleanSerialize(jQuery("#boxhalfright").sortable("serialize"));
1283 var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
1284 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
1285 {
1286 jQuery.ajax({
1287 url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=1&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
1288 async: false
1289 });
1290 // We force reload to be sure to get all boxes into list
1291 window.location.search=\'mainmenu='.GETPOST("mainmenu", "aZ09").'&leftmenu='.GETPOST('leftmenu', "aZ09").'&action=delbox&token='.newToken().'\';
1292 }
1293 else
1294 {
1295 jQuery.ajax({
1296 url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=\'+closing+\'&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
1297 async: true
1298 });
1299 }
1300 }
1301
1302 jQuery(document).ready(function() {
1303 jQuery("#boxcombo").change(function() {
1304 var boxid=jQuery("#boxcombo").val();
1305 if (boxid > 0) {
1306 console.log("A box widget has been selected for addition, we call ajax page to add it.")
1307 var left_list = cleanSerialize(jQuery("#boxhalfleft").sortable("serialize"));
1308 var right_list = cleanSerialize(jQuery("#boxhalfright").sortable("serialize"));
1309 var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
1310 jQuery.ajax({
1311 url: \''.DOL_URL_ROOT.'/core/ajax/box.php?boxorder=\'+boxorder+\'&boxid=\'+boxid+\'&zone='.$areacode.'&userid='.$user->id.'\'
1312 }).done(function() {
1313 window.location.search=\'mainmenu='.GETPOST("mainmenu", "aZ09").'&leftmenu='.GETPOST('leftmenu', "aZ09").'\';
1314 });
1315 }
1316 });';
1317 if (!count($arrayboxtoactivatelabel)) {
1318 $selectboxlist .= 'jQuery("#boxcombo").hide();';
1319 }
1320 $selectboxlist .= '
1321
1322 jQuery("#boxhalfleft, #boxhalfright").sortable({
1323 handle: \'.boxhandle\',
1324 revert: \'invalid\',
1325 items: \'.boxdraggable\',
1326 containment: \'document\',
1327 connectWith: \'#boxhalfleft, #boxhalfright\',
1328 stop: function(event, ui) {
1329 console.log("We moved box so we call updateBoxOrder with ajax actions");
1330 updateBoxOrder(1); /* 1 to avoid message after a move */
1331 }
1332 });
1333
1334 jQuery(".boxclose").click(function() {
1335 var self = this; // because JQuery can modify this
1336 var boxid = self.id.substring(8);
1337 if (boxid > 0) {
1338 var label = jQuery(\'#boxlabelentry\'+boxid).val();
1339 console.log("We close box "+boxid);
1340 jQuery(\'#boxto_\'+boxid).remove();
1341 jQuery(\'#boxcombo\').append(new Option(label, boxid));
1342 updateBoxOrder(1); /* 1 to avoid message after a remove */
1343 }
1344 });
1345
1346 });'."\n";
1347
1348 $selectboxlist .= '</script>'."\n";
1349 }
1350
1351 // Define boxlista and boxlistb
1352 $boxlista = '';
1353 $boxlistb = '';
1354 $nbboxactivated = count($boxidactivatedforuser);
1355
1356 if ($nbboxactivated) {
1357 // Load translation files required by the page
1358 $langs->loadLangs(array("boxes", "projects"));
1359
1360 $emptybox = new ModeleBoxes($db);
1361
1362 $boxlista .= "\n<!-- Box left container -->\n";
1363
1364 // Define $box_max_lines
1365 $box_max_lines = 5;
1366 if (getDolGlobalString('MAIN_BOXES_MAXLINES')) {
1367 $box_max_lines = $conf->global->MAIN_BOXES_MAXLINES;
1368 }
1369
1370 $ii = 0;
1371 foreach ($boxactivated as $key => $box) {
1372 if ((!empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) {
1373 continue;
1374 }
1375 if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) {
1376 $box->box_order = 'A'.sprintf("%02d", ($ii + 1)); // When box_order was not yet set to Axx or Bxx and is still 0
1377 }
1378 if (preg_match('/^A/i', $box->box_order)) { // column A
1379 $ii++;
1380 //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1381 //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1382 // Show box
1383 $box->loadBox($box_max_lines);
1384 $boxlista .= $box->showBox(null, null, 1);
1385 }
1386 }
1387
1388 if ($conf->browser->layout != 'phone') {
1389 $emptybox->box_id = 'A';
1390 $emptybox->info_box_head = array();
1391 $emptybox->info_box_contents = array();
1392 $boxlista .= $emptybox->showBox(array(), array(), 1);
1393 }
1394 $boxlista .= "<!-- End box left container -->\n";
1395
1396 $boxlistb .= "\n<!-- Box right container -->\n";
1397
1398 $ii = 0;
1399 foreach ($boxactivated as $key => $box) {
1400 if ((!empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) {
1401 continue;
1402 }
1403 if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) {
1404 $box->box_order = 'B'.sprintf("%02d", ($ii + 1)); // When box_order was not yet set to Axx or Bxx and is still 0
1405 }
1406 if (preg_match('/^B/i', $box->box_order)) { // colonne B
1407 $ii++;
1408 //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1409 //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1410 // Show box
1411 $box->loadBox($box_max_lines);
1412 $boxlistb .= $box->showBox(null, null, 1);
1413 }
1414 }
1415
1416 if ($conf->browser->layout != 'phone') {
1417 $emptybox->box_id = 'B';
1418 $emptybox->info_box_head = array();
1419 $emptybox->info_box_contents = array();
1420 $boxlistb .= $emptybox->showBox(array(), array(), 1);
1421 }
1422
1423 $boxlistb .= "<!-- End box right container -->\n";
1424 }
1425
1426 return array('selectboxlist'=>count($boxactivated) ? $selectboxlist : '', 'boxactivated'=>$boxactivated, 'boxlista'=>$boxlista, 'boxlistb'=>$boxlistb);
1427 }
1428
1429
1430 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1443 public function select_dictionary($htmlname, $dictionarytable, $keyfield = 'code', $labelfield = 'label', $selected = '', $useempty = 0, $moreattrib = '')
1444 {
1445 // phpcs:enable
1446 global $langs, $conf;
1447
1448 $langs->load("admin");
1449
1450 $sql = "SELECT rowid, ".$keyfield.", ".$labelfield;
1451 $sql .= " FROM ".$this->db->prefix().$dictionarytable;
1452 $sql .= " ORDER BY ".$labelfield;
1453
1454 dol_syslog(get_class($this)."::select_dictionary", LOG_DEBUG);
1455 $result = $this->db->query($sql);
1456 if ($result) {
1457 $num = $this->db->num_rows($result);
1458 $i = 0;
1459 if ($num) {
1460 print '<select id="select'.$htmlname.'" class="flat selectdictionary" name="'.$htmlname.'"'.($moreattrib ? ' '.$moreattrib : '').'>';
1461 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
1462 print '<option value="-1">&nbsp;</option>';
1463 }
1464
1465 while ($i < $num) {
1466 $obj = $this->db->fetch_object($result);
1467 if ($selected == $obj->rowid || $selected == $obj->{$keyfield}) {
1468 print '<option value="'.$obj->{$keyfield}.'" selected>';
1469 } else {
1470 print '<option value="'.$obj->{$keyfield}.'">';
1471 }
1472 $label = ($langs->trans($dictionarytable.$obj->{$keyfield}) != $dictionarytable.$obj->{$labelfield} ? $langs->trans($dictionarytable.$obj->{$keyfield}) : $obj->{$labelfield});
1473 print $label;
1474 print '</option>';
1475 $i++;
1476 }
1477 print "</select>";
1478 } else {
1479 print $langs->trans("DictionaryEmpty");
1480 }
1481 } else {
1482 dol_print_error($this->db);
1483 }
1484 }
1485
1496 public function selectAutoManual($htmlname, $value = '', $option = 0, $disabled = false, $useempty = 0)
1497 {
1498 global $langs;
1499
1500 $automatic = "automatic";
1501 $manual = "manual";
1502 if ($option) {
1503 $automatic = "1";
1504 $manual = "0";
1505 }
1506
1507 $disabled = ($disabled ? ' disabled' : '');
1508
1509 $resultautomanual = '<select class="flat width100" id="'.$htmlname.'" name="'.$htmlname.'"'.$disabled.'>'."\n";
1510 if ($useempty) {
1511 $resultautomanual .= '<option value="-1"'.(($value < 0) ? ' selected' : '').'>&nbsp;</option>'."\n";
1512 }
1513 if (("$value" == 'automatic') || ($value == 1)) {
1514 $resultautomanual .= '<option value="'.$automatic.'" selected>'.$langs->trans("Automatic").'</option>'."\n";
1515 $resultautomanual .= '<option value="'.$manual.'">'.$langs->trans("Manual").'</option>'."\n";
1516 } else {
1517 $selected = (($useempty && $value != '0' && $value != 'manual') ? '' : ' selected');
1518 $resultautomanual .= '<option value="'.$automatic.'">'.$langs->trans("Automatic").'</option>'."\n";
1519 $resultautomanual .= '<option value="'.$manual.'"'.$selected.'>'.$langs->trans("Manual").'</option>'."\n";
1520 }
1521 $resultautomanual .= '</select>'."\n";
1522 return $resultautomanual;
1523 }
1524
1525
1536 public function selectGroupByField($object, $search_groupby, &$arrayofgroupby, $morecss = 'minwidth200 maxwidth250', $showempty = '1')
1537 {
1538 global $langs, $extrafields, $form;
1539
1540 $arrayofgroupbylabel = array();
1541 foreach ($arrayofgroupby as $key => $val) {
1542 $arrayofgroupbylabel[$key] = $val['label'];
1543 }
1544 $result = $form->selectarray('search_groupby', $arrayofgroupbylabel, $search_groupby, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
1545
1546 return $result;
1547 }
1548
1559 public function selectXAxisField($object, $search_xaxis, &$arrayofxaxis, $showempty = '1', $morecss = 'minwidth250 maxwidth500')
1560 {
1561 global $form;
1562
1563 $arrayofxaxislabel = array();
1564 foreach ($arrayofxaxis as $key => $val) {
1565 $arrayofxaxislabel[$key] = $val['label'];
1566 }
1567 $result = $form->selectarray('search_xaxis', $arrayofxaxislabel, $search_xaxis, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
1568
1569 return $result;
1570 }
1571}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Definition security.php:604
Classe 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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $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...
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e rowid
Definition invoice.php:1926
ui dialog ui datepicker calendar ui widget content ui state ui datepicker calendar ui widget header ui state ui datepicker calendar ui button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
$conf db user
Definition repair.php:125
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:121