73 public function getHTMLScannerForm($jstoexecuteonadd =
'barcodescannerjs', $mode =
'all', $warehouseselect = 0)
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>';
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">';
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>';
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';
99 $formproduct->loadWarehouses();
100 $out .=
img_picto(
'',
'stock',
'class="pictofixedwidth"');
101 $out .= $formproduct->selectWarehouses(
'',
"warehousenew",
'', 0, 0, 0,
'', 0, 1);
105 $out .=
'<textarea type="text" name="barcodelist" class="centpercent" autofocus rows="'.ROWS_3.
'" placeholder="'.
dol_escape_htmltag($langs->trans(
"ScanOrTypeOrCopyPasteYourBarCodes")).
'"></textarea>';
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")).
'">';
119 $out .=
'<div type="text" id="scantoolmessage" class="scantoolmessage ok nopadding"></div>';
121 $out .=
'<script nonce="'.getNonce().
'">';
122 $out .=
'jQuery("#barcodeforautodetect, #barcodeforproduct, #barcodeforlotserial").click(function(){';
123 $out .=
'console.log("select choice");';
124 $out .=
'jQuery("#scantoolmessage").text("");';
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 */
150 public function select_export_model($selected = '', $htmlname = 'exportmodelid', $type = '', $useempty = 0, $fk_user = null)
153 global $conf, $langs, $user;
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).")
";
161 $sql .= " ORDER BY label
";
162 $result = $this->db->query($sql);
164 print '<select class="flat minwidth200
" name="'.$htmlname.'" id="'.$htmlname.'">';
166 print '<option value="-1
"> </option>';
169 $tmpuser = new User($this->db);
171 $num = $this->db->num_rows($result);
174 $obj = $this->db->fetch_object($result);
176 $label = $obj->label;
177 if ($obj->fk_user == 0) {
178 $label .= ' <span class="opacitymedium
">('.$langs->trans("Everybody
").')</span>';
179 } elseif ($obj->fk_user > 0) {
180 $tmpuser->fetch($obj->fk_user);
181 $label .= ' <span class="opacitymedium
">('.$tmpuser->getFullName($langs).')</span>';
184 if ($selected == $obj->rowid) {
185 print '<option value="'.$obj->rowid.'" selected data-html="'.dol_escape_htmltag($label).'">';
187 print '<option value="'.$obj->rowid.'" data-html="'.dol_escape_htmltag($label).'">';
194 print ajax_combobox($htmlname);
196 dol_print_error($this->db);
212 public function select_import_model($selected = '', $htmlname = 'importmodelid', $type = '', $useempty = 0, $fk_user = null)
215 global $conf, $langs, $user;
217 $sql = "SELECT rowid, label, fk_user
";
218 $sql .= " FROM
".$this->db->prefix()."import_model
";
219 $sql .= " WHERE
type =
'".$this->db->escape($type)."'";
220 if (!getDolGlobalString('EXPORTS_SHARE_MODELS')) { // EXPORTS_SHARE_MODELS means all templates are visible, whatever is owner.
221 $sql .= " AND fk_user IN (0,
".((int) $fk_user).")
";
223 $sql .= " ORDER BY label
";
224 $result = $this->db->query($sql);
226 print '<select class="flat minwidth200
" name="'.$htmlname.'" id="'.$htmlname.'">';
228 print '<option value="-1
"> </option>';
231 $tmpuser = new User($this->db);
233 $num = $this->db->num_rows($result);
236 $obj = $this->db->fetch_object($result);
238 $label = $obj->label;
239 if ($obj->fk_user == 0) {
240 $label .= ' <span class="opacitymedium
">('.$langs->trans("Everybody
").')</span>';
241 } elseif ($obj->fk_user > 0) {
242 $tmpuser->fetch($obj->fk_user);
243 $label .= ' <span class="opacitymedium
">('.$tmpuser->getFullName($langs).')</span>';
246 if ($selected == $obj->rowid) {
247 print '<option value="'.$obj->rowid.'" selected data-html="'.dol_escape_htmltag($label).'">';
249 print '<option value="'.$obj->rowid.'" data-html="'.dol_escape_htmltag($label).'">';
256 print ajax_combobox($htmlname);
258 dol_print_error($this->db);
271 public function select_ecotaxes($selected = '', $htmlname = 'ecotaxe_id')
276 $sql = "SELECT e.rowid, e.code, e.label, e.price, e.organization,
";
277 $sql .= " c.label as country
";
278 $sql .= " FROM
".$this->db->prefix()."c_ecotaxe as e,
".$this->db->prefix()."c_country as c
";
279 $sql .= " WHERE e.active = 1 AND e.fk_pays = c.rowid
";
280 $sql .= " ORDER BY country, e.organization ASC, e.code ASC
";
282 dol_syslog(get_class($this).'::select_ecotaxes', LOG_DEBUG);
283 $resql = $this->db->query($sql);
285 print '<select class="flat
" name="'.$htmlname.'">';
286 $num = $this->db->num_rows($resql);
288 print '<option value="-1
"> </option>'."\n
";
291 $obj = $this->db->fetch_object($resql);
292 if ($selected && $selected == $obj->rowid) {
293 print '<option value="'.$obj->rowid.'" selected>';
295 print '<option value="'.$obj->rowid.'">';
296 //print '<option onmouseover="showtip(\
''.$obj->label.
'\')
" onMouseout="hidetip()
" value="'.$obj->rowid.'">';
298 $selectOptionValue = $obj->code.' - '.$obj->label.' : '.price($obj->price).' '.$langs->trans("HT
").' ('.$obj->organization.')';
299 print $selectOptionValue;
307 dol_print_error($this->db);
322 public function select_revenue_stamp($selected = '', $htmlname = 'revenuestamp', $country_code = '')
329 $sql = "SELECT r.taux, r.revenuestamp_type
";
330 $sql .= " FROM
".$this->db->prefix()."c_revenuestamp as r,
".$this->db->prefix()."c_country as c
";
331 $sql .= " WHERE r.active = 1 AND r.fk_pays = c.rowid
";
332 $sql .= " AND c.code =
'".$this->db->escape($country_code)."'";
334 dol_syslog(get_class($this).'::select_revenue_stamp', LOG_DEBUG);
335 $resql = $this->db->query($sql);
337 $out .= '<select class="flat
" name="'.$htmlname.'">';
338 $num = $this->db->num_rows($resql);
340 $out .= '<option value="0
"> </option>'."\n
";
343 $obj = $this->db->fetch_object($resql);
344 if (($selected && $selected == $obj->taux) || $num == 1) {
345 $out .= '<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent
' ? '%
' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent
"' : '').' selected>';
347 $out .= '<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent
' ? '%
' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent
"' : '').'>';
349 $out .= $obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '');
357 dol_print_error($this->db);
376 public function select_percent($selected = 0, $htmlname = 'percent', $disabled = 0, $increment = 5, $start = 0, $end = 100, $showempty = 0)
379 $return = '<select class="flat maxwidth75 right
" name="'.$htmlname.'" '.($disabled ? 'disabled' : '').'>';
381 $return .= '<option value="-1
"'.(($selected == -1 || $selected == '') ? ' selected' : '').'> </option>';
384 for ($i = $start; $i <= $end; $i += $increment) {
385 if ($selected != '' && (int) $selected == $i) {
386 $return .= '<option value="'.$i.'" selected>';
388 $return .= '<option value="'.$i.'">';
391 $return .= '</option>';
394 $return .= '</select>';
412 public function select_categories($type, $selected = 0, $htmlname = 'search_categ', $nocateg = 0, $showempty = 1, $morecss = '')
415 global $conf, $langs;
416 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
418 // For backward compatibility
419 if (is_numeric($type)) {
420 dol_syslog(__METHOD__.': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING);
423 // Load list of "categories
"
424 $static_categs = new Categorie($this->db);
425 $tab_categs = $static_categs->get_full_arbo($type);
429 // Print a select with each of them
430 $moreforfilter .= '<select class="flat minwidth100
'.($morecss ? ' '.$morecss : '').'" id="select_categ_
'.$htmlname.'" name="'.$htmlname.'">';
433 if (!empty($conf->use_javascript_ajax)) {
434 $textforempty = ' '; // If we use ajaxcombo, we need here to avoid to have an empty element that is too small.
436 if (!is_numeric($showempty)) {
437 $textforempty = $showempty;
439 $moreforfilter .= '<option class="optiongrey
" value="'.($showempty < 0 ? $showempty : -1).'"'.($selected == $showempty ? ' selected' : '');
440 //$moreforfilter .= ' data-html="'.dol_escape_htmltag($textforempty).'"';
441 $moreforfilter .= '>'.dol_escape_htmltag($textforempty).'</option>'."\n
";
444 if (is_array($tab_categs)) {
445 foreach ($tab_categs as $categ) {
446 $moreforfilter .= '<option value="'.$categ['id'].'"';
447 if ($categ['id'] == $selected) {
448 $moreforfilter .= ' selected';
450 $moreforfilter .= ' data-html="'.dol_escape_htmltag(img_picto('', 'category
', 'class=
"pictofixedwidth" style=
"color: #'.$categ['color'].'"').dol_trunc($categ['fulllabel
'], 50, 'middle
')).'"';
451 $moreforfilter .= '>'.dol_trunc($categ['fulllabel'], 50, 'middle').'</option>';
455 $langs->load("categories
");
456 $moreforfilter .= '<option value="-2
"'.($selected == -2 ? ' selected' : '').'>- '.$langs->trans("NotCategorized
").' -</option>';
458 $moreforfilter .= '</select>';
460 // Enhance with select2
461 if ($conf->use_javascript_ajax) {
462 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
463 $comboenhancement = ajax_combobox('select_categ_'.$htmlname);
464 $moreforfilter .= $comboenhancement;
467 return $moreforfilter;
484 public function select_salesrepresentatives($selected, $htmlname, $user, $showstatus = 0, $showempty = 1, $morecss = '', $norepresentative = 0)
487 global $conf, $langs, $hookmanager;
490 $langs->load('users');
494 $reshook = $hookmanager->executeHooks('addSQLWhereFilterOnSelectSalesRep', array(), $this, $action);
496 // Select each sales and print them in a select input
497 $out .= '<select class="flat
'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'">';
500 if (!is_numeric($showempty)) {
501 $textforempty = $showempty;
503 if (!empty($conf->use_javascript_ajax) && $textforempty == ' ') {
504 $textforempty = ' '; // If we use ajaxcombo, we need here to avoid to have an empty element that is too small.
506 $out .= '<option class="optiongrey
" value="'.($showempty < 0 ? $showempty : -1).'"'.($selected == $showempty ? ' selected' : '').'>'.$textforempty.'</option>'."\n
";
509 // Get list of users allowed to be viewed
510 $sql_usr = "SELECT u.rowid, u.lastname, u.firstname, u.statut as
status, u.login, u.photo, u.gender, u.entity, u.admin
";
511 $sql_usr .= " FROM
".$this->db->prefix()."user as u
";
513 if (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
514 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
515 $sql_usr .= " WHERE u.entity IS NOT NULL
"; // Show all users
517 $sql_usr .= " WHERE EXISTS (SELECT ug.fk_user FROM
".$this->db->prefix()."usergroup_user as ug WHERE u.rowid = ug.fk_user AND ug.entity IN (
".getEntity('usergroup')."))
";
518 $sql_usr .= " OR u.entity = 0
"; // Show always superadmin
521 $sql_usr .= " WHERE u.entity IN (
".getEntity('user').")
";
524 if (!$user->hasRight('user', 'user', 'lire')) {
525 $sql_usr .= " AND u.rowid =
".((int) $user->id);
527 if (!empty($user->socid)) {
528 $sql_usr .= " AND u.fk_soc =
".((int) $user->socid);
530 if (getDolUserString('USER_HIDE_NONEMPLOYEE_IN_COMBOBOX', getDolGlobalString('USER_HIDE_NONEMPLOYEE_IN_COMBOBOX'))) {
531 $sql_usr .= " AND u.employee <> 0
";
533 if (getDolUserString('USER_HIDE_EXTERNAL_IN_COMBOBOX', getDolGlobalString('USER_HIDE_EXTERNAL_IN_COMBOBOX'))) {
534 $sql_usr .= " AND u.fk_soc IS NULL
";
536 if (getDolUserString('USER_HIDE_INACTIVE_IN_COMBOBOX', getDolGlobalString('USER_HIDE_INACTIVE_IN_COMBOBOX'))) { // Can be set in setup of module User.
537 $sql_usr .= " AND u.statut <> 0
";
540 //Add hook to filter on user (for example on usergroup define in custom modules)
541 if (!empty($reshook)) {
542 $sql_usr .= $hookmanager->resArray[0];
545 // Add existing sales representatives of thirdparty of external user
546 if (!$user->hasRight('user', 'user', 'lire') && $user->socid) {
547 $sql_usr .= " UNION
";
548 $sql_usr .= "SELECT u2.rowid, u2.lastname, u2.firstname, u2.statut as
status, u2.login, u2.photo, u2.gender, u2.entity, u2.admin
";
549 $sql_usr .= " FROM
".$this->db->prefix()."user as u2,
".$this->db->prefix()."societe_commerciaux as sc
";
551 if (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
552 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
553 $sql_usr .= " WHERE u2.entity IS NOT NULL
"; // Show all users
555 $sql_usr .= " WHERE EXISTS (SELECT ug2.fk_user FROM
".$this->db->prefix()."usergroup_user as ug2 WHERE u2.rowid = ug2.fk_user AND ug2.entity IN (
".getEntity('usergroup')."))
";
558 $sql_usr .= " WHERE u2.entity IN (
".getEntity('user').")
";
561 $sql_usr .= " AND u2.rowid = sc.fk_user AND sc.fk_soc =
".((int) $user->socid);
563 //Add hook to filter on user (for example on usergroup define in custom modules)
564 if (!empty($reshook)) {
565 $sql_usr .= $hookmanager->resArray[1];
569 if (!getDolGlobalString('MAIN_FIRSTNAME_NAME_POSITION')) { // MAIN_FIRSTNAME_NAME_POSITION is 0 means firstname+lastname
570 $sql_usr .= " ORDER BY
status DESC, firstname ASC, lastname ASC
";
572 $sql_usr .= " ORDER BY
status DESC, lastname ASC, firstname ASC
";
574 //print $sql_usr;exit;
576 $resql_usr = $this->db->query($sql_usr);
578 $userstatic = new User($this->db);
580 while ($obj_usr = $this->db->fetch_object($resql_usr)) {
581 $userstatic->id = $obj_usr->rowid;
582 $userstatic->lastname = $obj_usr->lastname;
583 $userstatic->firstname = $obj_usr->firstname;
584 $userstatic->photo = $obj_usr->photo;
585 $userstatic->status = $obj_usr->status;
586 $userstatic->entity = $obj_usr->entity;
587 $userstatic->admin = $obj_usr->admin;
589 $labeltoshow = dolGetFirstLastname($obj_usr->firstname, $obj_usr->lastname);
590 if (empty($obj_usr->firstname) && empty($obj_usr->lastname)) {
591 $labeltoshow = $obj_usr->login;
594 $out .= '<option value="'.$obj_usr->rowid.'"';
595 if ($obj_usr->rowid == $selected) {
598 $out .= ' data-html="';
599 $outhtml = $userstatic->getNomUrl(-3, '', 0, 1, 24, 1, 'login
', '', 1).' ';
600 if ($showstatus >= 0 && $obj_usr->status == 0) {
601 $outhtml .= '<strike
class=
"opacitymediumxxx">
';
603 $outhtml .= $labeltoshow;
604 if ($showstatus >= 0 && $obj_usr->status == 0) {
605 $outhtml .= '</strike>
';
607 $out .= dol_escape_htmltag($outhtml);
610 $out .= $labeltoshow;
611 // Complete name with more info
613 if (getDolGlobalString('MAIN_SHOW_LOGIN')) {
614 $out .= ($moreinfo ? ' - ' : ' (').$obj_usr->login;
617 if ($showstatus >= 0) {
618 if ($obj_usr->status == 1 && $showstatus == 1) {
619 $out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Enabled');
622 if ($obj_usr->status == 0) {
623 $out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Disabled');
627 $out .= ($moreinfo ? ')' : '');
630 $this->db->free($resql_usr);
632 dol_print_error($this->db);
635 if ($norepresentative) {
636 $langs->load("companies
");
637 $out .= '<option value="-2
"'.($selected == -2 ? ' selected' : '').'>- '.$langs->trans("NoSalesRepresentativeAffected
").' -</option>';
642 // Enhance with select2
643 if ($conf->use_javascript_ajax) {
644 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
646 $comboenhancement = ajax_combobox($htmlname);
647 if ($comboenhancement) {
648 $out .= $comboenhancement;
670 public function selectProjectTasks($selectedtask = 0, $projectid = 0, $htmlname = 'task_parent', $modeproject = 0, $modetask = 0, $mode = 0, $useempty = 0, $disablechildoftaskid = 0, $filteronprojstatus = '', $morecss = '')
672 global $user, $langs;
674 require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
676 //print $modeproject.'-'.$modetask;
677 $task = new Task($this->db);
678 $tasksarray = $task->getTasksArray($modetask ? $user : 0, $modeproject ? $user : 0, $projectid, 0, $mode, '', $filteronprojstatus);
680 print '<select class="flat
'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
682 print '<option value="0
"> </option>';
686 $this->_pLineSelect($j, 0, $tasksarray, $level, $selectedtask, $projectid, $disablechildoftaskid);
689 print ajax_combobox($htmlname);
691 print '<div class="warning
">'.$langs->trans("NoProject
").'</div>';
707 private function _pLineSelect(&$inc, $parent, $lines, $level = 0, $selectedtask = 0, $selectedproject = 0, $disablechildoftaskid = 0)
709 global $langs, $user, $conf;
713 $numlines = count($lines);
714 for ($i = 0; $i < $numlines; $i++) {
715 if ($lines[$i]->fk_task_parent == $parent) {
716 //var_dump($selectedproject."--
".$selectedtask."--
".$lines[$i]->fk_project."_
".$lines[$i]->id); // $lines[$i]->id may be empty if project has no lines
718 // Break on a new project
719 if ($parent == 0) { // We are on a task at first level
720 if ($lines[$i]->fk_project != $lastprojectid) { // Break found on project
722 print '<option value="0
" disabled>----------</option>';
724 print '<option value="'.$lines[$i]->fk_project.'_0
"';
725 if ($selectedproject == $lines[$i]->fk_project) {
729 $labeltoshow = $lines[$i]->projectref;
730 //$labeltoshow .= ' '.$lines[$i]->projectlabel;
731 if (empty($lines[$i]->public)) {
732 //$labeltoshow .= ' <span class="opacitymedium
">('.$langs->trans("Visibility
").': '.$langs->trans("PrivateProject
").')</span>';
733 $labeltoshow = img_picto($lines[$i]->projectlabel, 'project', 'class="pictofixedwidth
"').$labeltoshow;
735 //$labeltoshow .= ' <span class="opacitymedium
">('.$langs->trans("Visibility
").': '.$langs->trans("SharedProject
").')</span>';
736 $labeltoshow = img_picto($lines[$i]->projectlabel, 'projectpub', 'class="pictofixedwidth
"').$labeltoshow;
739 print ' data-html="'.dol_escape_htmltag($labeltoshow).'"';
740 print '>'; // Project -> Task
744 $lastprojectid = $lines[$i]->fk_project;
749 $newdisablechildoftaskid = $disablechildoftaskid;
752 if (isset($lines[$i]->id)) { // We use isset because $lines[$i]->id may be null if project has no task and are on root project (tasks may be caught by a left join). We enter here only if '0' or >0
753 // Check if we must disable entry
755 if ($disablechildoftaskid && (($lines[$i]->id == $disablechildoftaskid || $lines[$i]->fk_task_parent == $disablechildoftaskid))) {
757 if ($lines[$i]->fk_task_parent == $disablechildoftaskid) {
758 $newdisablechildoftaskid = $lines[$i]->id; // If task is child of a disabled parent, we will propagate id to disable next child too
762 print '<option value="'.$lines[$i]->fk_project.'_
'.$lines[$i]->id.'"';
763 if (($lines[$i]->id == $selectedtask) || ($lines[$i]->fk_project.'_'.$lines[$i]->id == $selectedtask)) {
770 $labeltoshow = $lines[$i]->projectref;
771 //$labeltoshow .= ' '.$lines[$i]->projectlabel;
772 if (empty($lines[$i]->public)) {
773 //$labeltoshow .= ' <span class="opacitymedium
">('.$langs->trans("Visibility
").': '.$langs->trans("PrivateProject
").')</span>';
774 $labeltoshow = img_picto($lines[$i]->projectlabel, 'project', 'class="pictofixedwidth
"').$labeltoshow;
776 //$labeltoshow .= ' <span class="opacitymedium
">('.$langs->trans("Visibility
").': '.$langs->trans("SharedProject
").')</span>';
777 $labeltoshow = img_picto($lines[$i]->projectlabel, 'projectpub', 'class="pictofixedwidth
"').$labeltoshow;
779 if ($lines[$i]->id) {
780 $labeltoshow .= ' > ';
782 for ($k = 0; $k < $level; $k++) {
783 $labeltoshow .= "
";
785 $labeltoshow .= $lines[$i]->ref.' '.$lines[$i]->label;
787 print ' data-html="'.dol_escape_htmltag($labeltoshow).'"';
795 if ($lines[$i]->id) {
796 $this->_pLineSelect($inc, $lines[$i]->id, $lines, $level, $selectedtask, $selectedproject, $newdisablechildoftaskid);
812 public static function showColor($color, $textifnotdefined = '')
815 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
816 if (colorIsLight($color)) {
820 $color = colorArrayToHex(colorStringToArray($color, array()), '');
823 return '<input type="text
" class="colorthumb
" disabled style="padding: 1px; margin-top: 0; margin-bottom: 0; color: #
'.$textcolor.'; background-color: #
'.$color.'" value="'.$color.'">';
825 return $textifnotdefined;
842 public function select_color($set_color = '', $prefix = 'f_color', $form_name = '', $showcolorbox = 1, $arrayofcolors = [])
845 print $this->selectColor($set_color, $prefix, $form_name, $showcolorbox, $arrayofcolors);
862 public static function selectColor($set_color = '', $prefix = 'f_color', $form_name = '', $showcolorbox = 1, $arrayofcolors = [], $morecss = '', $setpropertyonselect = '', $default = '')
864 // Deprecation warning
866 dol_syslog(__METHOD__.": form_name parameter is deprecated
", LOG_WARNING);
869 global $langs, $conf;
873 if (!is_array($arrayofcolors) || count($arrayofcolors) < 1) {
874 // Case of selection of any color
875 $langs->load("other
");
876 if (empty($conf->dol_use_jmobile) && !empty($conf->use_javascript_ajax) && !getDolGlobalInt('MAIN_USE_HTML5_COLOR_SELECTOR')) {
877 $out .= '<link rel="stylesheet
" media="screen
" type="text/css
" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css
" />';
878 $out .= '<script nonce="'.getNonce().'" type="text/javascript
" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/jpicker-1.1.6.js
"></script>';
879 $out .= '<script nonce="'.getNonce().'" type="text/javascript
">
880 jQuery(document).ready(function(){
881 var originalhex = null;
882 $(\'#colorpicker'.$prefix.'\').jPicker( {
884 title: \''.dol_escape_js($langs->trans("SelectAColor
")).'\', /* any title for the jPicker window itself - displays "Drag Markers To Pick A Color
" if left null */
887 type: \'show\', /* effect used to show/hide an expandable picker. Acceptable values "slide
", "show
", "fade
" */
890 show: \'fast\', /* duration of "show
" effect. Acceptable values are "fast
", "slow
", or time in ms */
891 hide: \'fast\' /* duration of "hide
" effect. Acceptable values are "fast
", "slow
", or time in ms */
896 x: \'screenCenter\', /* acceptable values "left
", "center
", "right
", "screenCenter
", or relative px value */
897 y: \'center\' /* acceptable values "top
", "bottom
", "center
", or relative px value */
901 clientPath: \''.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/images/\',
902 picker: { file: \'../../../../../theme/common/colorpicker.png\', width: 14, height: 14 }
904 localization: // alter these to change the text presented by the picker (e.g. different language)
908 title: \''.dol_escape_js($langs->trans("SelectAColor
")).'\',
909 newColor: \''.dol_escape_js($langs->trans("New
")).'\',
910 currentColor: \''.dol_escape_js($langs->trans("Current
")).'\',
911 ok: \''.dol_escape_js($langs->trans("Validate")).'\',
912 cancel: \''.dol_escape_js($langs->trans("Cancel
")).'\'
916 function(color, context) { console.log("close color selector
"); },
917 function(color, context) { var hex = color.val(\'hex\'); console.log("new color selected in jpicker
"+hex+" setpropertyonselect=
'.dol_escape_js($setpropertyonselect).'");';
918 if ($setpropertyonselect) {
919 $out .= 'if (originalhex == null) {';
920 $out .= ' originalhex = getComputedStyle(document.querySelector(":root
")).getPropertyValue(\'--'.dol_escape_js($setpropertyonselect).'\');';
921 $out .= ' console.log("original color is saved into originalhex =
"+originalhex);';
923 $out .= 'if (hex != null) {';
924 $out .= ' document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', \'#\'+hex);';
928 function(color, context) {
929 console.log("cancel selection of color
");';
930 if ($setpropertyonselect) {
931 $out .= 'if (originalhex != null) {
932 console.log("Restore old color
"+originalhex);
933 document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', originalhex);
941 $out .= '<input id="colorpicker
'.$prefix.'" name="'.$prefix.'" size="6
" maxlength="7
" class="flat valignmiddle
'.($morecss ? ' '.$morecss : '').'" type="text
" value="'.dol_escape_htmltag($set_color).'" />';
943 $color = ($set_color !== '' ? $set_color : ($default !== '' ? $default : 'FFFFFF'));
944 $out .= '<input id="colorpicker
'.$prefix.'" name="'.$prefix.'" size="6
" maxlength="7
" class="flat input-nobottom colorselector valignmiddle
'.($morecss ? ' '.$morecss : '').'" type="color
" data-default="'.$default.'" value="'.dol_escape_htmltag(preg_match('/^#/
', $color) ? $color : '#
'.$color).'" />';
945 $out .= '<script nonce="'.getNonce().'" type="text/javascript
">
946 jQuery(document).ready(function(){
947 var originalhex = null;
948 jQuery("#colorpicker
'.$prefix.'").on(\'change\', function() {
949 var hex = jQuery("#colorpicker
'.$prefix.'").val();
950 console.log("new color selected in input color
"+hex+" setpropertyonselect=
'.dol_escape_js($setpropertyonselect).'");';
951 if ($setpropertyonselect) {
952 $out .= 'if (originalhex == null) {';
953 $out .= ' originalhex = getComputedStyle(document.querySelector(":root
")).getPropertyValue(\'--'.dol_escape_js($setpropertyonselect).'\');';
954 $out .= ' console.log("original color is saved into originalhex =
"+originalhex);';
956 $out .= 'if (hex != null) {';
957 $out .= ' document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', hex);';
966 // In most cases, this is not used. We used instead function with no specific list of colors
967 if (empty($conf->dol_use_jmobile) && !empty($conf->use_javascript_ajax)) {
968 $out .= '<link rel="stylesheet
" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.css
" type="text/css
" media="screen
" />';
969 $out .= '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.js
" type="text/javascript
"></script>';
970 $out .= '<script nonce="'.getNonce().'" type="text/javascript
">
971 jQuery(document).ready(function(){
972 jQuery(\'#colorpicker'.$prefix.'\').colorpicker({
980 $out .= '<select id="colorpicker
'.$prefix.'" class="flat
'.($morecss ? ' '.$morecss : '').'" name="'.$prefix.'">';
981 //print '<option value="-1
"> </option>';
982 foreach ($arrayofcolors as $val) {
983 $out .= '<option value="'.$val.'"';
984 if ($set_color == $val) {
987 $out .= '>'.$val.'</option>';
1006 public function CreateColorIcon($color, $module, $name, $x = 12, $y = 12)
1011 $file = $conf->$module->dir_temp.'/'.$name.'.png';
1013 // We create temp directory
1014 if (!file_exists($conf->$module->dir_temp)) {
1015 dol_mkdir($conf->$module->dir_temp);
1018 // On cree l'image en vraies couleurs
1019 $image = imagecreatetruecolor($x, $y);
1021 $color = substr($color, 1, 6);
1023 $red = hexdec(substr($color, 0, 2)); // Red channel conversion
1024 $green = hexdec(substr($color, 2, 2)); // Green channel conversion
1025 $blue = hexdec(substr($color, 4, 2)); // Blue channel conversion
1027 $couleur = imagecolorallocate($image, $red, $green, $blue);
1028 //print $red.$green.$blue;
1029 imagefill($image, 0, 0, $couleur); // Fill the image
1030 // Create the colr and store it in a variable to maintain it
1031 imagepng($image, $file); // Returns an image in PNG format
1032 imagedestroy($image);
1091 public function select_month($selected = '', $htmlname = 'monthid', $useempty = 0, $longlabel = 0, $morecss = 'minwidth50 maxwidth75imp valignmiddle', $addjscombo = false)
1096 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
1099 $montharray = monthArray($langs, 0); // Get array
1101 $montharray = monthArray($langs, 1);
1104 $select_month = '<select class="flat
'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
1106 $select_month .= '<option value="0
"> </option>';
1108 foreach ($montharray as $key => $val) {
1109 if ($selected == $key) {
1110 $select_month .= '<option value="'.$key.'" selected>';
1112 $select_month .= '<option value="'.$key.'">';
1114 $select_month .= $val;
1115 $select_month .= '</option>';
1117 $select_month .= '</select>';
1119 // Add code for jquery to use multiselect
1121 // Enhance with select2
1122 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1123 $select_month .= ajax_combobox($htmlname);
1126 return $select_month;
1146 public function select_year($selected = '', $htmlname = 'yearid', $useempty = 0, $min_year = 10, $max_year = 5, $offset = 0, $invert = 0, $option = '', $morecss = 'valignmiddle maxwidth75imp', $addjscombo = false)
1149 print $this->selectyear($selected, $htmlname, $useempty, $min_year, $max_year, $offset, $invert, $option, $morecss, $addjscombo);
1167 public function selectyear($selected = '', $htmlname = 'yearid', $useempty = 0, $min_year = 10, $max_year = 5, $offset = 0, $invert = 0, $option = '', $morecss = 'valignmiddle width75', $addjscombo = false)
1171 $currentyear = idate("Y
") + $offset;
1172 $max_year = $currentyear + $max_year;
1173 $min_year = $currentyear - $min_year;
1174 if (empty($selected) && empty($useempty)) {
1175 $selected = $currentyear;
1178 $out .= '<select class="flat
'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'"'.$option.' >';
1180 $selected_html = '';
1181 if ($selected == '') {
1182 $selected_html = ' selected';
1184 $out .= '<option value=""'.$selected_html.'> </option>';
1187 for ($y = $max_year; $y >= $min_year; $y--) {
1188 $selected_html = '';
1189 if ($selected > 0 && $y == $selected) {
1190 $selected_html = ' selected';
1192 $out .= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
1195 for ($y = $min_year; $y <= $max_year; $y++) {
1196 $selected_html = '';
1197 if ($selected > 0 && $y == $selected) {
1198 $selected_html = ' selected';
1200 $out .= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
1203 $out .= "</select>\n
";
1205 // Add code for jquery to use multiselect
1207 // Enhance with select2
1208 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1209 $out .= ajax_combobox($htmlname);
1224 public static function getBoxesArea($user, $areacode)
1226 global $conf, $langs, $db;
1228 include_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
1231 @phan-var-force ModeleBoxes[] $boxactivated
1232 @phan-var-force int[] $boxidactivatedforuser
1235 $confuserzone = 'MAIN_BOXES_'.$areacode;
1239 // $boxactivated will be array of boxes enabled into global setup
1240 // $boxidactivatedforuser will be array of boxes chose by user
1242 $selectboxlist = '';
1243 $boxactivated = InfoBox::listBoxes($db, 'activated', $areacode, (empty($user->conf->$confuserzone) ? null : $user), array(), 0); // Search boxes of common+user (or common only if user has no specific setup)
1245 $boxidactivatedforuser = array();
1246 foreach ($boxactivated as $box) {
1247 if (empty($user->conf->$confuserzone) || $box->fk_user == $user->id) {
1248 $boxidactivatedforuser[$box->id] = $box->id; // We keep only boxes to show for user
1251 if (!empty($box->lang)) {
1252 $langs->loadLangs(array($box->lang));
1253 $box->boxlabel = $langs->transnoentitiesnoconv($box->boxlabel);
1258 // Define selectboxlist
1259 $arrayboxtoactivatelabel = array();
1260 if (!empty($user->conf->$confuserzone)) {
1262 $langs->load("boxes
"); // Load label of boxes
1263 foreach ($boxactivated as $box) {
1264 if (!empty($boxidactivatedforuser[$box->id])) {
1265 continue; // Already visible for user
1268 $label = $langs->transnoentitiesnoconv($box->boxlabel);
1269 //if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph
").')';
1270 if (preg_match('/graph/', $box->class) && $conf->browser->layout != 'phone') {
1271 $label .= ' <span class="fas fa-chart-bar
"></span>';
1273 $arrayboxtoactivatelabel[$box->id] = array('label' => $label, 'data-html' => img_picto('', $box->boximg, 'class="pictofixedwidth valignmiddle
"').'<span class="valignmiddle
">'.$langs->trans($label).'</span>'); // We keep only boxes not shown for user, to show into combo list
1275 foreach ($boxidactivatedforuser as $boxid) {
1276 if (empty($boxorder)) {
1279 $boxorder .= $boxid.',';
1282 //var_dump($boxidactivatedforuser);
1284 // Class Form must have been already loaded
1285 $selectboxlist .= '<!-- Form with select box list -->'."\n
";
1286 $selectboxlist .= '<form id="addbox
" name="addbox
" method="POST
" action="'.$_SERVER["PHP_SELF"].'">';
1287 $selectboxlist .= '<input type="hidden
" name="token
" value="'.newToken().'">';
1288 $selectboxlist .= '<input type="hidden
" name="addbox
" value="addbox
">';
1289 $selectboxlist .= '<input type="hidden
" name="userid
" value="'.$user->id.'">';
1290 $selectboxlist .= '<input type="hidden
" name="areacode
" value="'.$areacode.'">';
1291 $selectboxlist .= '<input type="hidden
" name="boxorder
" value="'.$boxorder.'">';
1292 $selectboxlist .= Form::selectarray('boxcombo', $arrayboxtoactivatelabel, -1, $langs->trans("ChooseBoxToAdd
").'...', 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth300 hideonprint', 0, 'hidden selected', 0, 0);
1293 if (empty($conf->use_javascript_ajax)) {
1294 $selectboxlist .= ' <input type="submit
" class="button" value="'.$langs->trans("AddBox").'">';
1296 $selectboxlist .= '</form>';
1297 if (!empty($conf->use_javascript_ajax)) {
1298 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1299 $selectboxlist .= ajax_combobox("boxcombo
");
1303 // Javascript code for dynamic actions
1304 if (!empty($conf->use_javascript_ajax)) {
1305 $selectboxlist .= '<script nonce="'.getNonce().'" type="text/javascript
">
1307 // To update list of activated boxes
1308 function updateBoxOrder(closing) {
1309 var left_list = cleanSerialize(jQuery("#boxhalfleft
").sortable("serialize
"));
1310 var right_list = cleanSerialize(jQuery("#boxhalfright
").sortable("serialize
"));
1311 var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
1312 if (boxorder==\'A:A-B:B\' && closing == 1) // There is no more boxes on screen, and we are after a delete of a box so we must hide title
1315 url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=1&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
1318 // We force reload to be sure to get all boxes into list
1319 window.location.search=\'mainmenu='.GETPOST("mainmenu
", "aZ09
").'&leftmenu='.GETPOST('leftmenu', "aZ09
").'&action=delbox&token='.newToken().'\';
1324 url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=\'+closing+\'&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
1330 jQuery(document).ready(function() {
1331 jQuery("#boxcombo
").change(function() {
1332 var boxid=jQuery("#boxcombo
").val();
1334 console.log("A box widget has been selected
for addition, we call ajax page to add it.
")
1335 var left_list = cleanSerialize(jQuery("#boxhalfleft
").sortable("serialize
"));
1336 var right_list = cleanSerialize(jQuery("#boxhalfright
").sortable("serialize
"));
1337 var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
1339 url: \''.DOL_URL_ROOT.'/core/ajax/box.php?boxorder=\'+boxorder+\'&boxid=\'+boxid+\'&zone='.$areacode.'&userid='.$user->id.'\'
1340 }).done(function() {
1341 window.location.search=\'mainmenu='.GETPOST("mainmenu
", "aZ09
").'&leftmenu='.GETPOST('leftmenu', "aZ09
").'\';
1345 if (!count($arrayboxtoactivatelabel)) {
1346 $selectboxlist .= 'jQuery("#boxcombo
").hide();';
1350 jQuery("#boxhalfleft, #boxhalfright
").sortable({
1351 handle: \'.boxhandle\',
1352 revert: \'invalid\',
1353 items: \'.boxdraggable\',
1354 containment: \'document\',
1355 connectWith: \'#boxhalfleft, #boxhalfright\',
1356 stop: function(event, ui) {
1357 console.log("We moved box so we call updateBoxOrder with ajax actions
");
1358 updateBoxOrder(1); /* 1 to avoid message after a move */
1362 jQuery(".boxclose
").click(function() {
1363 var self = this; // because JQuery can modify this
1364 var boxid = self.id.substring(8);
1366 var label = jQuery(\'#boxlabelentry\'+boxid).val();
1367 console.log("We close box
"+boxid);
1368 jQuery(\'#boxto_\'+boxid).remove();
1369 jQuery(\'#boxcombo\').append(new Option(label, boxid));
1370 updateBoxOrder(1); /* 1 to avoid message after a remove */
1376 $selectboxlist .= '</script>'."\n
";
1379 // Define boxlista and boxlistb
1382 $nbboxactivated = count($boxidactivatedforuser);
1384 if ($nbboxactivated) {
1385 // Load translation files required by the page
1386 $langs->loadLangs(array("boxes
", "projects
"));
1388 $emptybox = new ModeleBoxes($db);
1390 $boxlista .= "\n<!-- Box left container -->\n
";
1392 // Define $box_max_lines
1393 $box_max_lines = getDolUserInt('MAIN_SIZE_SHORTLIST_LIMIT', getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5));
1396 foreach ($boxactivated as $key => $box) {
1397 if ((!empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) {
1400 if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) {
1401 $box->box_order = 'A'.sprintf("%02d
", ($ii + 1)); // When box_order was not yet set to Axx or Bxx and is still 0
1403 if (preg_match('/^A/i', $box->box_order)) { // column A
1405 //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1406 //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1408 $box->loadBox($box_max_lines);
1409 $boxlista .= $box->showBox(null, null, 1);
1413 if ($conf->browser->layout != 'phone') {
1414 $emptybox->box_id = 'A';
1415 $emptybox->info_box_head = array();
1416 $emptybox->info_box_contents = array();
1417 $boxlista .= $emptybox->showBox(array(), array(), 1);
1419 $boxlista .= "<!-- End box left container -->\n
";
1421 $boxlistb .= "\n<!-- Box right container -->\n
";
1424 foreach ($boxactivated as $key => $box) {
1425 if ((!empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) {
1428 if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) {
1429 $box->box_order = 'B'.sprintf("%02d
", ($ii + 1)); // When box_order was not yet set to Axx or Bxx and is still 0
1431 if (preg_match('/^B/i', $box->box_order)) { // colonne B
1433 //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1434 //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1436 $box->loadBox($box_max_lines);
1437 $boxlistb .= $box->showBox(null, null, 1);
1441 if ($conf->browser->layout != 'phone') {
1442 $emptybox->box_id = 'B';
1443 $emptybox->info_box_head = array();
1444 $emptybox->info_box_contents = array();
1445 $boxlistb .= $emptybox->showBox(array(), array(), 1);
1448 $boxlistb .= "<!-- End box right container -->\n
";
1451 return array('selectboxlist' => count($boxactivated) ? $selectboxlist : '', 'boxactivated' => $boxactivated, 'boxlista' => $boxlista, 'boxlistb' => $boxlistb);
1561 public function selectGroupByField($object, $search_groupby, &$arrayofgroupby, $morecss = 'minwidth200 maxwidth250', $showempty = '1')
1563 global $langs, $extrafields, $form;
1565 $arrayofgroupbylabel = array();
1566 foreach ($arrayofgroupby as $key => $val) {
1567 $arrayofgroupbylabel[$key] = $val['label'];
1569 $result = $form->selectarray('search_groupby', $arrayofgroupbylabel, $search_groupby, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
1584 public function selectXAxisField($object, $search_xaxis, &$arrayofxaxis, $showempty = '1', $morecss = 'minwidth250 maxwidth500')
1588 $arrayofxaxislabel = array();
1589 foreach ($arrayofxaxis as $key => $val) {
1590 $arrayofxaxislabel[$key] = $val['label'];
1592 $result = $form->selectarray('search_xaxis', $arrayofxaxislabel, $search_xaxis, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);