73 $out .=
'<!-- Popup for mass barcode scanning -->'.
"\n";
74 $out .=
'<div class="div-for-modal-topright" style="padding: 15px">';
75 $out .=
'<center>'.img_picto(
'',
'barcode',
'class="pictofixedwidth"').
'<strong>Barcode scanner tool...</strong></center><br>';
77 if ($mode ==
'product') {
78 $out .=
'<input type="hidden" name="barcodemode" value="barcodeforproduct" id="barcodeforproduct">';
79 } elseif ($mode ==
'lot') {
80 $out .=
'<input type="hidden" name="barcodemode" value="barcodeforlotserial" id="barcodeforlotserial">';
82 $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>';
83 $out .=
'<input type="radio" name="barcodemode" value="barcodeforproduct" id="barcodeforproduct"> <label for="barcodeforproduct">Scan a product barcode</label><br>';
84 $out .=
'<input type="radio" name="barcodemode" value="barcodeforlotserial" id="barcodeforlotserial"> <label for="barcodeforlotserial">Scan a product lot or serial number</label><br>';
86 $stringaddbarcode = $langs->trans(
"QtyToAddAfterBarcodeScan",
"tmphtml");
87 $htmltoreplaceby =
'<select name="selectaddorreplace"><option selected value="add">'.$langs->trans(
"Add").
'</option><option value="replace">'.$langs->trans(
"ToReplace").
'</option></select>';
88 $stringaddbarcode = str_replace(
"tmphtml", $htmltoreplaceby, $stringaddbarcode);
89 $out .= $stringaddbarcode.
' <input type="text" name="barcodeproductqty" class="width50 right" value="1"><br>';
91 $out .=
'<textarea type="text" name="barcodelist" class="centpercent" autofocus rows="'.ROWS_3.
'" placeholder="'.
dol_escape_htmltag($langs->trans(
"ScanOrTypeOrCopyPasteYourBarCodes")).
'"></textarea>';
101 $out .=
'<input type="submit" class="button marginleftonly marginrightonly" id ="exec'.dol_escape_js($jstoexecuteonadd).
'" name="addscan" value="'.
dol_escape_htmltag($langs->trans(
"Add")).
'">';
102 $out .=
'<input type="submit" class="button marginleftonly marginrightonly" name="cancel" value="'.dol_escape_htmltag($langs->trans(
"CloseWindow")).
'">';
105 $out .=
'<div type="text" id="scantoolmessage" class="scantoolmessage ok nopadding"></div>';
107 $out .=
'<script nonce="'.getNonce().
'">';
108 $out .=
'jQuery("#barcodeforautodetect, #barcodeforproduct, #barcodeforlotserial").click(function(){';
109 $out .=
'console.log("select choice");';
110 $out .=
'jQuery("#scantoolmessage").text("");';
112 $out .=
'$("#exec'.dol_escape_js($jstoexecuteonadd).
'").click(function(){
113 console.log("We call js to execute \''.
dol_escape_js($jstoexecuteonadd).
'\'");
114 '.dol_escape_js($jstoexecuteonadd).'();
115 return false; /* We want to stay on the scan tool */
136 public function select_export_model($selected = '', $htmlname = 'exportmodelid', $type = '', $useempty = 0, $fk_user = null)
139 global $conf, $langs, $user;
141 $sql = "SELECT
rowid, label, fk_user
";
142 $sql .= " FROM
".$this->db->prefix()."export_model
";
143 $sql .= " WHERE
type =
'".$this->db->escape($type)."'";
144 if (empty($conf->global->EXPORTS_SHARE_MODELS)) { // EXPORTS_SHARE_MODELS means all templates are visible, whatever is owner.
145 $sql .= " AND fk_user IN (0,
".((int) $fk_user).")
";
147 $sql .= " ORDER BY label
";
148 $result = $this->db->query($sql);
150 print '<select class="flat minwidth200
" name="'.$htmlname.'" id="'.$htmlname.'">';
152 print '<option value="-1
"> </option>';
155 $tmpuser = new User($this->db);
157 $num = $this->db->num_rows($result);
160 $obj = $this->db->fetch_object($result);
162 $label = $obj->label;
163 if ($obj->fk_user == 0) {
164 $label .= ' <span class="opacitymedium
">('.$langs->trans("Everybody
").')</span>';
165 } elseif ($obj->fk_user > 0) {
166 $tmpuser->fetch($obj->fk_user);
167 $label .= ' <span class="opacitymedium
">('.$tmpuser->getFullName($langs).')</span>';
170 if ($selected == $obj->rowid) {
171 print '<option value="'.$obj->rowid.'" selected data-html="'.dol_escape_htmltag($label).'">';
173 print '<option value="'.$obj->rowid.'" data-html="'.dol_escape_htmltag($label).'">';
180 print ajax_combobox($htmlname);
182 dol_print_error($this->db);
198 public function select_import_model($selected = '', $htmlname = 'importmodelid', $type = '', $useempty = 0, $fk_user = null)
201 global $conf, $langs, $user;
203 $sql = "SELECT
rowid, label, fk_user
";
204 $sql .= " FROM
".$this->db->prefix()."import_model
";
205 $sql .= " WHERE
type =
'".$this->db->escape($type)."'";
206 if (empty($conf->global->EXPORTS_SHARE_MODELS)) { // EXPORTS_SHARE_MODELS means all templates are visible, whatever is owner.
207 $sql .= " AND fk_user IN (0,
".((int) $fk_user).")
";
209 $sql .= " ORDER BY label
";
210 $result = $this->db->query($sql);
212 print '<select class="flat minwidth200
" name="'.$htmlname.'" id="'.$htmlname.'">';
214 print '<option value="-1
"> </option>';
217 $tmpuser = new User($this->db);
219 $num = $this->db->num_rows($result);
222 $obj = $this->db->fetch_object($result);
224 $label = $obj->label;
225 if ($obj->fk_user == 0) {
226 $label .= ' <span class="opacitymedium
">('.$langs->trans("Everybody
").')</span>';
227 } elseif ($obj->fk_user > 0) {
228 $tmpuser->fetch($obj->fk_user);
229 $label .= ' <span class="opacitymedium
">('.$tmpuser->getFullName($langs).')</span>';
232 if ($selected == $obj->rowid) {
233 print '<option value="'.$obj->rowid.'" selected data-html="'.dol_escape_htmltag($label).'">';
235 print '<option value="'.$obj->rowid.'" data-html="'.dol_escape_htmltag($label).'">';
242 print ajax_combobox($htmlname);
244 dol_print_error($this->db);
257 public function select_ecotaxes($selected = '', $htmlname = 'ecotaxe_id')
262 $sql = "SELECT e.rowid, e.code, e.label, e.price, e.organization,
";
263 $sql .= " c.label as country
";
264 $sql .= " FROM
".$this->db->prefix()."c_ecotaxe as e,
".$this->db->prefix()."c_country as c
";
265 $sql .= " WHERE e.active = 1 AND e.fk_pays = c.rowid
";
266 $sql .= " ORDER BY country, e.organization ASC, e.code ASC
";
268 dol_syslog(get_class($this).'::select_ecotaxes', LOG_DEBUG);
269 $resql = $this->db->query($sql);
271 print '<select class="flat
" name="'.$htmlname.'">';
272 $num = $this->db->num_rows($resql);
274 print '<option value="-1
"> </option>'."\n
";
277 $obj = $this->db->fetch_object($resql);
278 if ($selected && $selected == $obj->rowid) {
279 print '<option value="'.$obj->rowid.'" selected>';
281 print '<option value="'.$obj->rowid.'">';
282 //print '<option onmouseover="showtip(\
''.$obj->label.
'\')
" onMouseout="hidetip()
" value="'.$obj->rowid.'">';
284 $selectOptionValue = $obj->code.' - '.$obj->label.' : '.price($obj->price).' '.$langs->trans("HT
").' ('.$obj->organization.')';
285 print $selectOptionValue;
293 dol_print_error($this->db);
308 public function select_revenue_stamp($selected = '', $htmlname = 'revenuestamp', $country_code = '')
315 $sql = "SELECT r.taux, r.revenuestamp_type
";
316 $sql .= " FROM
".$this->db->prefix()."c_revenuestamp as r,
".$this->db->prefix()."c_country as c
";
317 $sql .= " WHERE r.active = 1 AND r.fk_pays = c.rowid
";
318 $sql .= " AND c.code =
'".$this->db->escape($country_code)."'";
320 dol_syslog(get_class($this).'::select_revenue_stamp', LOG_DEBUG);
321 $resql = $this->db->query($sql);
323 $out .= '<select class="flat
" name="'.$htmlname.'">';
324 $num = $this->db->num_rows($resql);
326 $out .= '<option value="0
"> </option>'."\n
";
329 $obj = $this->db->fetch_object($resql);
330 if (($selected && $selected == $obj->taux) || $num == 1) {
331 $out .= '<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent
' ? '%
' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent
"' : '').' selected>';
333 $out .= '<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent
' ? '%
' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent
"' : '').'>';
334 //print '<option onmouseover="showtip(\
''.$obj->libelle.
'\')
" onMouseout="hidetip()
" value="'.$obj->rowid.'">';
336 $out .= $obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '');
344 dol_print_error($this->db);
363 public function select_percent($selected = 0, $htmlname = 'percent', $disabled = 0, $increment = 5, $start = 0, $end = 100, $showempty = 0)
366 $return = '<select class="flat maxwidth75
" name="'.$htmlname.'" '.($disabled ? 'disabled' : '').'>';
368 $return .= '<option value="-1
"'.(($selected == -1 || $selected == '') ? ' selected' : '').'> </option>';
371 for ($i = $start; $i <= $end; $i += $increment) {
372 if ($selected != '' && (int) $selected == $i) {
373 $return .= '<option value="'.$i.'" selected>';
375 $return .= '<option value="'.$i.'">';
378 $return .= '</option>';
381 $return .= '</select>';
399 public function select_categories($type, $selected = 0, $htmlname = 'search_categ', $nocateg = 0, $showempty = 1, $morecss = '')
402 global $conf, $langs;
403 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
405 // For backward compatibility
406 if (is_numeric($type)) {
407 dol_syslog(__METHOD__.': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING);
410 // Load list of "categories
"
411 $static_categs = new Categorie($this->db);
412 $tab_categs = $static_categs->get_full_arbo($type);
416 // Print a select with each of them
417 $moreforfilter .= '<select class="flat minwidth100
'.($morecss ? ' '.$morecss : '').'" id="select_categ_
'.$htmlname.'" name="'.$htmlname.'">';
420 if (!empty($conf->use_javascript_ajax)) {
421 $textforempty = ' '; // If we use ajaxcombo, we need here to avoid to have an empty element that is too small.
423 if (!is_numeric($showempty)) {
424 $textforempty = $showempty;
426 $moreforfilter .= '<option class="optiongrey
" value="'.($showempty < 0 ? $showempty : -1).'"'.($selected == $showempty ? ' selected' : '');
427 //$moreforfilter .= ' data-html="'.dol_escape_htmltag($textforempty).'"';
428 $moreforfilter .= '>'.dol_escape_htmltag($textforempty).'</option>'."\n
";
431 if (is_array($tab_categs)) {
432 foreach ($tab_categs as $categ) {
433 $moreforfilter .= '<option value="'.$categ['id'].'"';
434 if ($categ['id'] == $selected) {
435 $moreforfilter .= ' selected';
437 $moreforfilter .= ' data-html="'.dol_escape_htmltag(img_picto('', 'category
', 'class=
"pictofixedwidth" style=
"color: #'.$categ['color'].'"').dol_trunc($categ['fulllabel
'], 50, 'middle
')).'"';
438 $moreforfilter .= '>'.dol_trunc($categ['fulllabel'], 50, 'middle').'</option>';
442 $langs->load("categories
");
443 $moreforfilter .= '<option value="-2
"'.($selected == -2 ? ' selected' : '').'>- '.$langs->trans("NotCategorized
").' -</option>';
445 $moreforfilter .= '</select>';
447 // Enhance with select2
448 if ($conf->use_javascript_ajax) {
449 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
450 $comboenhancement = ajax_combobox('select_categ_'.$htmlname);
451 $moreforfilter .= $comboenhancement;
454 return $moreforfilter;
471 public function select_salesrepresentatives($selected, $htmlname, $user, $showstatus = 0, $showempty = 1, $morecss = '', $norepresentative = 0)
474 global $conf, $langs, $hookmanager;
476 $langs->load('users');
480 $reshook = $hookmanager->executeHooks('addSQLWhereFilterOnSelectSalesRep', array(), $this, $action);
482 // Select each sales and print them in a select input
483 $out .= '<select class="flat
'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'">';
486 if (!is_numeric($showempty)) {
487 $textforempty = $showempty;
489 if (!empty($conf->use_javascript_ajax) && $textforempty == ' ') {
490 $textforempty = ' '; // If we use ajaxcombo, we need here to avoid to have an empty element that is too small.
492 $out .= '<option class="optiongrey
" value="'.($showempty < 0 ? $showempty : -1).'"'.($selected == $showempty ? ' selected' : '').'>'.$textforempty.'</option>'."\n
";
495 // Get list of users allowed to be viewed
496 $sql_usr = "SELECT u.rowid, u.lastname, u.firstname, u.statut as status, u.login, u.photo, u.gender, u.entity, u.admin
";
497 $sql_usr .= " FROM
".$this->db->prefix()."user as u
";
499 if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
500 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
501 $sql_usr .= " WHERE u.entity IS NOT NULL
"; // Show all users
503 $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')."))
";
504 $sql_usr .= " OR u.entity = 0
"; // Show always superadmin
507 $sql_usr .= " WHERE u.entity IN (
".getEntity('user').")
";
510 if (empty($user->rights->user->user->lire)) {
511 $sql_usr .= " AND u.rowid =
".((int) $user->id);
513 if (!empty($user->socid)) {
514 $sql_usr .= " AND u.fk_soc =
".((int) $user->socid);
517 //Add hook to filter on user (for exemple on usergroup define in custom modules)
518 if (!empty($reshook)) {
519 $sql_usr .= $hookmanager->resArray[0];
522 // Add existing sales representatives of thirdparty of external user
523 if (empty($user->rights->user->user->lire) && $user->socid) {
524 $sql_usr .= " UNION
";
525 $sql_usr .= "SELECT u2.rowid, u2.lastname, u2.firstname, u2.statut as status, u2.login, u2.photo, u2.gender, u2.entity, u2.admin
";
526 $sql_usr .= " FROM
".$this->db->prefix()."user as u2,
".$this->db->prefix()."societe_commerciaux as sc
";
528 if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
529 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
530 $sql_usr .= " WHERE u2.entity IS NOT NULL
"; // Show all users
532 $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')."))
";
535 $sql_usr .= " WHERE u2.entity IN (
".getEntity('user').")
";
538 $sql_usr .= " AND u2.rowid = sc.fk_user AND sc.fk_soc =
".((int) $user->socid);
540 //Add hook to filter on user (for exemple on usergroup define in custom modules)
541 if (!empty($reshook)) {
542 $sql_usr .= $hookmanager->resArray[1];
546 if (empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)) { // MAIN_FIRSTNAME_NAME_POSITION is 0 means firstname+lastname
547 $sql_usr .= " ORDER BY status DESC, firstname ASC, lastname ASC
";
549 $sql_usr .= " ORDER BY status DESC, lastname ASC, firstname ASC
";
551 //print $sql_usr;exit;
553 $resql_usr = $this->db->query($sql_usr);
555 $userstatic = new User($this->db);
557 while ($obj_usr = $this->db->fetch_object($resql_usr)) {
558 $userstatic->id = $obj_usr->rowid;
559 $userstatic->lastname = $obj_usr->lastname;
560 $userstatic->firstname = $obj_usr->firstname;
561 $userstatic->photo = $obj_usr->photo;
562 $userstatic->statut = $obj_usr->status;
563 $userstatic->entity = $obj_usr->entity;
564 $userstatic->admin = $obj_usr->admin;
566 $labeltoshow = dolGetFirstLastname($obj_usr->firstname, $obj_usr->lastname);
567 if (empty($obj_usr->firstname) && empty($obj_usr->lastname)) {
568 $labeltoshow = $obj_usr->login;
571 $out .= '<option value="'.$obj_usr->rowid.'"';
572 if ($obj_usr->rowid == $selected) {
575 $out .= ' data-html="';
576 $outhtml = $userstatic->getNomUrl(-3, '', 0, 1, 24, 1, 'login
', '', 1).' ';
577 if ($showstatus >= 0 && $obj_usr->status == 0) {
578 $outhtml .= '<strike
class=
"opacitymediumxxx">
';
580 $outhtml .= $labeltoshow;
581 if ($showstatus >= 0 && $obj_usr->status == 0) {
582 $outhtml .= '</strike>
';
584 $out .= dol_escape_htmltag($outhtml);
587 $out .= $labeltoshow;
588 // Complete name with more info
590 if (!empty($conf->global->MAIN_SHOW_LOGIN)) {
591 $out .= ($moreinfo ? ' - ' : ' (').$obj_usr->login;
594 if ($showstatus >= 0) {
595 if ($obj_usr->status == 1 && $showstatus == 1) {
596 $out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Enabled');
599 if ($obj_usr->status == 0) {
600 $out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Disabled');
604 $out .= ($moreinfo ? ')' : '');
607 $this->db->free($resql_usr);
609 dol_print_error($this->db);
612 if ($norepresentative) {
613 $langs->load("companies
");
614 $out .= '<option value="-2
"'.($selected == -2 ? ' selected' : '').'>- '.$langs->trans("NoSalesRepresentativeAffected
").' -</option>';
619 // Enhance with select2
620 if ($conf->use_javascript_ajax) {
621 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
623 $comboenhancement = ajax_combobox($htmlname);
624 if ($comboenhancement) {
625 $out .= $comboenhancement;
647 public function selectProjectTasks($selectedtask = '', $projectid = 0, $htmlname = 'task_parent', $modeproject = 0, $modetask = 0, $mode = 0, $useempty = 0, $disablechildoftaskid = 0, $filteronprojstatus = '', $morecss = '')
649 global $user, $langs;
651 require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
653 //print $modeproject.'-'.$modetask;
654 $task = new Task($this->db);
655 $tasksarray = $task->getTasksArray($modetask ? $user : 0, $modeproject ? $user : 0, $projectid, 0, $mode, '', $filteronprojstatus);
657 print '<select class="flat
'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
659 print '<option value="0
"> </option>';
663 $this->_pLineSelect($j, 0, $tasksarray, $level, $selectedtask, $projectid, $disablechildoftaskid);
666 print ajax_combobox($htmlname);
668 print '<div class="warning
">'.$langs->trans("NoProject
").'</div>';
684 private function _pLineSelect(&$inc, $parent, $lines, $level = 0, $selectedtask = 0, $selectedproject = 0, $disablechildoftaskid = 0)
686 global $langs, $user, $conf;
690 $numlines = count($lines);
691 for ($i = 0; $i < $numlines; $i++) {
692 if ($lines[$i]->fk_task_parent == $parent) {
693 //var_dump($selectedproject."--
".$selectedtask."--
".$lines[$i]->fk_project."_
".$lines[$i]->id); // $lines[$i]->id may be empty if project has no lines
695 // Break on a new project
696 if ($parent == 0) { // We are on a task at first level
697 if ($lines[$i]->fk_project != $lastprojectid) { // Break found on project
699 print '<option value="0
" disabled>----------</option>';
701 print '<option value="'.$lines[$i]->fk_project.'_0
"';
702 if ($selectedproject == $lines[$i]->fk_project) {
706 $labeltoshow = $lines[$i]->projectref;
707 //$labeltoshow .= ' '.$lines[$i]->projectlabel;
708 if (empty($lines[$i]->public)) {
709 //$labeltoshow .= ' <span class="opacitymedium
">('.$langs->trans("Visibility
").': '.$langs->trans("PrivateProject
").')</span>';
710 $labeltoshow = img_picto($lines[$i]->projectlabel, 'project', 'class="pictofixedwidth
"').$labeltoshow;
712 //$labeltoshow .= ' <span class="opacitymedium
">('.$langs->trans("Visibility
").': '.$langs->trans("SharedProject
").')</span>';
713 $labeltoshow = img_picto($lines[$i]->projectlabel, 'projectpub', 'class="pictofixedwidth
"').$labeltoshow;
716 print ' data-html="'.dol_escape_htmltag($labeltoshow).'"';
717 print '>'; // Project -> Task
721 $lastprojectid = $lines[$i]->fk_project;
726 $newdisablechildoftaskid = $disablechildoftaskid;
729 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
730 // Check if we must disable entry
732 if ($disablechildoftaskid && (($lines[$i]->id == $disablechildoftaskid || $lines[$i]->fk_task_parent == $disablechildoftaskid))) {
734 if ($lines[$i]->fk_task_parent == $disablechildoftaskid) {
735 $newdisablechildoftaskid = $lines[$i]->id; // If task is child of a disabled parent, we will propagate id to disable next child too
739 print '<option value="'.$lines[$i]->fk_project.'_
'.$lines[$i]->id.'"';
740 if (($lines[$i]->id == $selectedtask) || ($lines[$i]->fk_project.'_'.$lines[$i]->id == $selectedtask)) {
747 $labeltoshow = $lines[$i]->projectref;
748 //$labeltoshow .= ' '.$lines[$i]->projectlabel;
749 if (empty($lines[$i]->public)) {
750 //$labeltoshow .= ' <span class="opacitymedium
">('.$langs->trans("Visibility
").': '.$langs->trans("PrivateProject
").')</span>';
751 $labeltoshow = img_picto($lines[$i]->projectlabel, 'project', 'class="pictofixedwidth
"').$labeltoshow;
753 //$labeltoshow .= ' <span class="opacitymedium
">('.$langs->trans("Visibility
").': '.$langs->trans("SharedProject
").')</span>';
754 $labeltoshow = img_picto($lines[$i]->projectlabel, 'projectpub', 'class="pictofixedwidth
"').$labeltoshow;
756 if ($lines[$i]->id) {
757 $labeltoshow .= ' > ';
759 for ($k = 0; $k < $level; $k++) {
760 $labeltoshow .= "
";
762 $labeltoshow .= $lines[$i]->ref.' '.$lines[$i]->label;
764 print ' data-html="'.dol_escape_htmltag($labeltoshow).'"';
772 if ($lines[$i]->id) {
773 $this->_pLineSelect($inc, $lines[$i]->id, $lines, $level, $selectedtask, $selectedproject, $newdisablechildoftaskid);
789 public static function showColor($color, $textifnotdefined = '')
792 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
793 if (colorIsLight($color)) {
797 $color = colorArrayToHex(colorStringToArray($color, array()), '');
800 return '<input type="text
" class="colorthumb
" disabled style="padding: 1px; margin-top: 0; margin-bottom: 0; color: #
'.$textcolor.'; background-color: #
'.$color.'" value="'.$color.'">';
802 return $textifnotdefined;
819 public function select_color($set_color = '', $prefix = 'f_color', $form_name = '', $showcolorbox = 1, $arrayofcolors = '')
822 print $this->selectColor($set_color, $prefix, $form_name, $showcolorbox, $arrayofcolors);
838 public static function selectColor($set_color = '', $prefix = 'f_color', $form_name = '', $showcolorbox = 1, $arrayofcolors = '', $morecss = '', $setpropertyonselect = '')
840 // Deprecation warning
842 dol_syslog(__METHOD__.": form_name parameter is deprecated
", LOG_WARNING);
845 global $langs, $conf;
849 if (!is_array($arrayofcolors) || count($arrayofcolors) < 1) {
850 $langs->load("other
");
851 if (empty($conf->dol_use_jmobile) && !empty($conf->use_javascript_ajax)) {
852 $out .= '<link rel="stylesheet
" media="screen
" type="text/css
" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css
" />';
853 $out .= '<script nonce="'.getNonce().'" type="text/javascript
" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/jpicker-1.1.6.js
"></script>';
854 $out .= '<script nonce="'.getNonce().'" type="text/javascript
">
855 jQuery(document).ready(function(){
856 var originalhex = null;
857 $(\'#colorpicker'.$prefix.'\').jPicker( {
859 title: \''.dol_escape_js($langs->trans("SelectAColor
")).'\', /* any title for the jPicker window itself - displays "Drag Markers To Pick A Color
" if left null */
862 type: \'show\', /* effect used to show/hide an expandable picker. Acceptable values "slide
", "show
", "fade
" */
865 show: \'fast\', /* duration of "show
" effect. Acceptable values are "fast
", "slow
", or time in ms */
866 hide: \'fast\' /* duration of "hide
" effect. Acceptable values are "fast
", "slow
", or time in ms */
871 x: \'screenCenter\', /* acceptable values "left
", "center
", "right
", "screenCenter
", or relative px value */
872 y: \'center\' /* acceptable values "top
", "bottom
", "center
", or relative px value */
876 clientPath: \''.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/images/\',
877 picker: { file: \'../../../../../theme/common/colorpicker.png\', width: 14, height: 14 }
879 localization: // alter these to change the text presented by the picker (e.g. different language)
883 title: \''.dol_escape_js($langs->trans("SelectAColor
")).'\',
884 newColor: \''.dol_escape_js($langs->trans("New
")).'\',
885 currentColor: \''.dol_escape_js($langs->trans("Current
")).'\',
886 ok: \''.dol_escape_js($langs->trans("Validate")).'\',
887 cancel: \''.dol_escape_js($langs->trans("Cancel
")).'\'
891 function(color, context) { console.log("close color selector
"); },
892 function(color, context) { var hex = color.val(\'hex\'); console.log("new color selected in jpicker
"+hex+" setpropertyonselect=
'.dol_escape_js($setpropertyonselect).'");';
893 if ($setpropertyonselect) {
894 $out .= 'if (originalhex == null) {';
895 $out .= ' originalhex = getComputedStyle(document.querySelector(":root
")).getPropertyValue(\'--'.dol_escape_js($setpropertyonselect).'\');';
896 $out .= ' console.log("original color is saved into originalhex =
"+originalhex);';
898 $out .= 'if (hex != null) {';
899 $out .= ' document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', \'#\'+hex);';
903 function(color, context) {
904 console.log("cancel selection of color
");';
905 if ($setpropertyonselect) {
906 $out .= 'if (originalhex != null) {
907 console.log("Restore old color
"+originalhex);
908 document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', originalhex);
917 $out .= '<input id="colorpicker
'.$prefix.'" name="'.$prefix.'" size="6
" maxlength="7
" class="flat
'.($morecss ? ' '.$morecss : '').'" type="text
" value="'.dol_escape_htmltag($set_color).'" />';
918 } else { // In most cases, this is not used. We used instead function with no specific list of colors
919 if (empty($conf->dol_use_jmobile) && !empty($conf->use_javascript_ajax)) {
920 $out .= '<link rel="stylesheet
" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.css
" type="text/css
" media="screen
" />';
921 $out .= '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.js
" type="text/javascript
"></script>';
922 $out .= '<script nonce="'.getNonce().'" type="text/javascript
">
923 jQuery(document).ready(function(){
924 jQuery(\'#colorpicker'.$prefix.'\').colorpicker({
932 $out .= '<select id="colorpicker
'.$prefix.'" class="flat
'.($morecss ? ' '.$morecss : '').'" name="'.$prefix.'">';
933 //print '<option value="-1
"> </option>';
934 foreach ($arrayofcolors as $val) {
935 $out .= '<option value="'.$val.'"';
936 if ($set_color == $val) {
939 $out .= '>'.$val.'</option>';
958 public function CreateColorIcon($color, $module, $name, $x = '12', $y = '12')
963 $file = $conf->$module->dir_temp.'/'.$name.'.png';
965 // On cree le repertoire contenant les icones
966 if (!file_exists($conf->$module->dir_temp)) {
967 dol_mkdir($conf->$module->dir_temp);
970 // On cree l'image en vraies couleurs
971 $image = imagecreatetruecolor($x, $y);
973 $color = substr($color, 1, 6);
975 $rouge = hexdec(substr($color, 0, 2)); //conversion du canal rouge
976 $vert = hexdec(substr($color, 2, 2)); //conversion du canal vert
977 $bleu = hexdec(substr($color, 4, 2)); //conversion du canal bleu
979 $couleur = imagecolorallocate($image, $rouge, $vert, $bleu);
980 //print $rouge.$vert.$bleu;
981 imagefill($image, 0, 0, $couleur); //on remplit l'image
982 // On cree la couleur et on l'attribue a une variable pour ne pas la perdre
983 ImagePng($image, $file); //renvoie une image sous format png
984 ImageDestroy($image);
1043 public function select_month($selected = '', $htmlname = 'monthid', $useempty = 0, $longlabel = 0, $morecss = 'minwidth50 maxwidth75imp valignmiddle', $addjscombo = false)
1048 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
1051 $montharray = monthArray($langs, 0); // Get array
1053 $montharray = monthArray($langs, 1);
1056 $select_month = '<select class="flat
'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
1058 $select_month .= '<option value="0
"> </option>';
1060 foreach ($montharray as $key => $val) {
1061 if ($selected == $key) {
1062 $select_month .= '<option value="'.$key.'" selected>';
1064 $select_month .= '<option value="'.$key.'">';
1066 $select_month .= $val;
1067 $select_month .= '</option>';
1069 $select_month .= '</select>';
1071 // Add code for jquery to use multiselect
1073 // Enhance with select2
1074 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1075 $select_month .= ajax_combobox($htmlname);
1078 return $select_month;
1098 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)
1101 print $this->selectyear($selected, $htmlname, $useempty, $min_year, $max_year, $offset, $invert, $option, $morecss, $addjscombo);
1119 public function selectyear($selected = '', $htmlname = 'yearid', $useempty = 0, $min_year = 10, $max_year = 5, $offset = 0, $invert = 0, $option = '', $morecss = 'valignmiddle width75', $addjscombo = false)
1123 $currentyear = date("Y
") + $offset;
1124 $max_year = $currentyear + $max_year;
1125 $min_year = $currentyear - $min_year;
1126 if (empty($selected) && empty($useempty)) {
1127 $selected = $currentyear;
1130 $out .= '<select class="flat
'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'"'.$option.' >';
1132 $selected_html = '';
1133 if ($selected == '') {
1134 $selected_html = ' selected';
1136 $out .= '<option value=""'.$selected_html.'> </option>';
1139 for ($y = $max_year; $y >= $min_year; $y--) {
1140 $selected_html = '';
1141 if ($selected > 0 && $y == $selected) {
1142 $selected_html = ' selected';
1144 $out .= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
1147 for ($y = $min_year; $y <= $max_year; $y++) {
1148 $selected_html = '';
1149 if ($selected > 0 && $y == $selected) {
1150 $selected_html = ' selected';
1152 $out .= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
1155 $out .= "</select>\n
";
1157 // Add code for jquery to use multiselect
1159 // Enhance with select2
1160 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1161 $out .= ajax_combobox($htmlname);
1176 public static function getBoxesArea($user, $areacode)
1178 global $conf, $langs, $db;
1180 include_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
1182 $confuserzone = 'MAIN_BOXES_'.$areacode;
1184 // $boxactivated will be array of boxes enabled into global setup
1185 // $boxidactivatedforuser will be array of boxes choosed by user
1187 $selectboxlist = '';
1188 $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)
1190 $boxidactivatedforuser = array();
1191 foreach ($boxactivated as $box) {
1192 if (empty($user->conf->$confuserzone) || $box->fk_user == $user->id) {
1193 $boxidactivatedforuser[$box->id] = $box->id; // We keep only boxes to show for user
1197 // Define selectboxlist
1198 $arrayboxtoactivatelabel = array();
1199 if (!empty($user->conf->$confuserzone)) {
1201 $langs->load("boxes
"); // Load label of boxes
1202 foreach ($boxactivated as $box) {
1203 if (!empty($boxidactivatedforuser[$box->id])) {
1204 continue; // Already visible for user
1206 $label = $langs->transnoentitiesnoconv($box->boxlabel);
1207 //if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph
").')';
1208 if (preg_match('/graph/', $box->class) && $conf->browser->layout != 'phone') {
1209 $label = $label.' <span class="fa fa-bar-chart
"></span>';
1211 $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
1213 foreach ($boxidactivatedforuser as $boxid) {
1214 if (empty($boxorder)) {
1217 $boxorder .= $boxid.',';
1220 //var_dump($boxidactivatedforuser);
1222 // Class Form must have been already loaded
1223 $selectboxlist .= '<!-- Form with select box list -->'."\n
";
1224 $selectboxlist .= '<form id="addbox
" name="addbox
" method="POST
" action="'.$_SERVER["PHP_SELF"].'">';
1225 $selectboxlist .= '<input type="hidden
" name="token
" value="'.newToken().'">';
1226 $selectboxlist .= '<input type="hidden
" name="addbox
" value="addbox
">';
1227 $selectboxlist .= '<input type="hidden
" name="userid
" value="'.$user->id.'">';
1228 $selectboxlist .= '<input type="hidden
" name="areacode
" value="'.$areacode.'">';
1229 $selectboxlist .= '<input type="hidden
" name="boxorder
" value="'.$boxorder.'">';
1230 $selectboxlist .= Form::selectarray('boxcombo', $arrayboxtoactivatelabel, -1, $langs->trans("ChooseBoxToAdd
").'...', 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth150onsmartphone hideonprint', 0, 'hidden selected', 0, 0);
1231 if (empty($conf->use_javascript_ajax)) {
1232 $selectboxlist .= ' <input type="submit
" class="button" value="'.$langs->trans("AddBox").'">';
1234 $selectboxlist .= '</form>';
1235 if (!empty($conf->use_javascript_ajax)) {
1236 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1237 $selectboxlist .= ajax_combobox("boxcombo
");
1241 // Javascript code for dynamic actions
1242 if (!empty($conf->use_javascript_ajax)) {
1243 $selectboxlist .= '<script nonce="'.getNonce().'" type="text/javascript
">
1245 // To update list of activated boxes
1246 function updateBoxOrder(closing) {
1247 var left_list = cleanSerialize(jQuery("#boxhalfleft
").sortable("serialize
"));
1248 var right_list = cleanSerialize(jQuery("#boxhalfright
").sortable("serialize
"));
1249 var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
1250 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
1253 url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=1&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
1256 // We force reload to be sure to get all boxes into list
1257 window.location.search=\'mainmenu='.GETPOST("mainmenu
", "aZ09
").'&leftmenu='.GETPOST('leftmenu', "aZ09
").'&action=delbox&token='.newToken().'\';
1262 url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=\'+closing+\'&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
1268 jQuery(document).ready(function() {
1269 jQuery("#boxcombo
").change(function() {
1270 var boxid=jQuery("#boxcombo
").val();
1272 console.log("A box widget has been selected
for addition, we call ajax page to add it.
")
1273 var left_list = cleanSerialize(jQuery("#boxhalfleft
").sortable("serialize
"));
1274 var right_list = cleanSerialize(jQuery("#boxhalfright
").sortable("serialize
"));
1275 var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
1277 url: \''.DOL_URL_ROOT.'/core/ajax/box.php?boxorder=\'+boxorder+\'&boxid=\'+boxid+\'&zone='.$areacode.'&userid='.$user->id.'\'
1278 }).done(function() {
1279 window.location.search=\'mainmenu='.GETPOST("mainmenu
", "aZ09
").'&leftmenu='.GETPOST('leftmenu', "aZ09
").'\';
1283 if (!count($arrayboxtoactivatelabel)) {
1284 $selectboxlist .= 'jQuery("#boxcombo
").hide();';
1288 jQuery("#boxhalfleft, #boxhalfright
").sortable({
1289 handle: \'.boxhandle\',
1290 revert: \'invalid\',
1291 items: \'.boxdraggable\',
1292 containment: \'document\',
1293 connectWith: \'#boxhalfleft, #boxhalfright\',
1294 stop: function(event, ui) {
1295 console.log("We moved box so we call updateBoxOrder with ajax actions
");
1296 updateBoxOrder(1); /* 1 to avoid message after a move */
1300 jQuery(".boxclose
").click(function() {
1301 var self = this; // because JQuery can modify this
1302 var boxid = self.id.substring(8);
1304 var label = jQuery(\'#boxlabelentry\'+boxid).val();
1305 console.log("We close box
"+boxid);
1306 jQuery(\'#boxto_\'+boxid).remove();
1307 jQuery(\'#boxcombo\').append(new Option(label, boxid));
1308 updateBoxOrder(1); /* 1 to avoid message after a remove */
1314 $selectboxlist .= '</script>'."\n
";
1317 // Define boxlista and boxlistb
1320 $nbboxactivated = count($boxidactivatedforuser);
1322 if ($nbboxactivated) {
1323 // Load translation files required by the page
1324 $langs->loadLangs(array("boxes
", "projects
"));
1326 $emptybox = new ModeleBoxes($db);
1328 $boxlista .= "\n<!-- Box left container -->\n
";
1330 // Define $box_max_lines
1332 if (!empty($conf->global->MAIN_BOXES_MAXLINES)) {
1333 $box_max_lines = $conf->global->MAIN_BOXES_MAXLINES;
1337 foreach ($boxactivated as $key => $box) {
1338 if ((!empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) {
1341 if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) {
1342 $box->box_order = 'A'.sprintf("%02d
", ($ii + 1)); // When box_order was not yet set to Axx or Bxx and is still 0
1344 if (preg_match('/^A/i', $box->box_order)) { // column A
1346 //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1347 //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1349 $box->loadBox($box_max_lines);
1350 $boxlista .= $box->showBox(null, null, 1);
1354 if ($conf->browser->layout != 'phone') {
1355 $emptybox->box_id = 'A';
1356 $emptybox->info_box_head = array();
1357 $emptybox->info_box_contents = array();
1358 $boxlista .= $emptybox->showBox(array(), array(), 1);
1360 $boxlista .= "<!-- End box left container -->\n
";
1362 $boxlistb .= "\n<!-- Box right container -->\n
";
1365 foreach ($boxactivated as $key => $box) {
1366 if ((!empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) {
1369 if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) {
1370 $box->box_order = 'B'.sprintf("%02d
", ($ii + 1)); // When box_order was not yet set to Axx or Bxx and is still 0
1372 if (preg_match('/^B/i', $box->box_order)) { // colonne B
1374 //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1375 //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1377 $box->loadBox($box_max_lines);
1378 $boxlistb .= $box->showBox(null, null, 1);
1382 if ($conf->browser->layout != 'phone') {
1383 $emptybox->box_id = 'B';
1384 $emptybox->info_box_head = array();
1385 $emptybox->info_box_contents = array();
1386 $boxlistb .= $emptybox->showBox(array(), array(), 1);
1389 $boxlistb .= "<!-- End box right container -->\n
";
1392 return array('selectboxlist'=>count($boxactivated) ? $selectboxlist : '', 'boxactivated'=>$boxactivated, 'boxlista'=>$boxlista, 'boxlistb'=>$boxlistb);
1502 public function selectGroupByField($object, $search_groupby, &$arrayofgroupby, $morecss = 'minwidth200 maxwidth250', $showempty = '1')
1504 global $langs, $extrafields, $form;
1506 $arrayofgroupbylabel = array();
1507 foreach ($arrayofgroupby as $key => $val) {
1508 $arrayofgroupbylabel[$key] = $val['label'];
1510 $result = $form->selectarray('search_groupby', $arrayofgroupbylabel, $search_groupby, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
1525 public function selectXAxisField($object, $search_xaxis, &$arrayofxaxis, $showempty = '1', $morecss = 'minwidth250 maxwidth500')
1529 $arrayofxaxislabel = array();
1530 foreach ($arrayofxaxis as $key => $val) {
1531 $arrayofxaxislabel[$key] = $val['label'];
1533 $result = $form->selectarray('search_xaxis', $arrayofxaxislabel, $search_xaxis, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);