74 public $errors = array();
85 public $cache_types_paiements = array();
87 public $cache_conditions_paiements = array();
89 public $cache_transport_mode = array();
91 public $cache_availability = array();
93 public $cache_demand_reason = array();
95 public $cache_types_fees = array();
97 public $cache_vatrates = array();
99 public $cache_invoice_subtype = array();
101 public $cache_rule_for_lines_dates = array();
106 private $phoneInputSharedJsLoaded =
false;
131 'y' => $langs->trans(
'Years'),
132 'm' => $langs->trans(
'Month'),
133 'w' => $langs->trans(
'Weeks'),
134 'd' => $langs->trans(
'Days'),
135 'h' => $langs->trans(
'Hours'),
136 'i' => $langs->trans(
'Minutes'),
137 's' => $langs->trans(
'Seconds'),
141 "y" => $langs->trans(
"Year"),
142 "m" => $langs->trans(
"Month"),
143 "w" => $langs->trans(
"Week"),
144 "d" => $langs->trans(
"Day"),
145 "h" => $langs->trans(
"Hour"),
146 "i" => $langs->trans(
"Minute"),
147 's' => $langs->trans(
'Second'),
151 return array_reverse($arrayoftypes);
153 return $arrayoftypes;
173 public function editfieldkey($text, $htmlname, $preselected,
$object, $perm, $typeofdata =
'string', $moreparam =
'', $fieldrequired = 0, $notabletag = 0, $paramid =
'id', $help =
'')
180 if (
getDolGlobalString(
'MAIN_USE_EDIT_IN_PLACE') && !preg_match(
'/^select;/', $typeofdata)) {
182 $tmp = explode(
':', $typeofdata);
183 $ret .=
'<div class="editkey_' . $tmp[0] . (!empty($tmp[1]) ?
' ' . $tmp[1] :
'') .
'" id="' . $htmlname .
'">';
184 if ($fieldrequired) {
185 $ret .=
'<span class="fieldrequired">';
190 $ret .= $langs->trans($text);
192 if ($fieldrequired) {
195 $ret .=
'</div>' .
"\n";
197 if ($fieldrequired) {
198 $ret .=
'<span class="fieldrequired">';
203 $ret .= $langs->trans($text);
205 if ($fieldrequired) {
210 if (empty($notabletag) && $perm) {
211 $ret .=
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
213 if ($fieldrequired) {
214 $ret .=
'<span class="fieldrequired">';
219 $ret .= $langs->trans($text);
221 if ($fieldrequired) {
224 if (!empty($notabletag)) {
227 if (empty($notabletag) && $perm) {
230 if (empty($notabletag) && $perm) {
231 $ret .=
'<td class="right">';
233 if ($htmlname &&
GETPOST(
'action',
'aZ09') !=
'edit' . $htmlname && $perm && is_object(
$object)) {
234 $ret .=
'<a class="editfielda reposition" href="' .
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'action' =>
'edit' . $htmlname, $paramid =>
$object->id],
true) . $moreparam .
'">';
235 $ret .= img_edit($langs->trans(
'Edit'), ($notabletag ? 0 : 1));
238 if (!empty($notabletag) && $notabletag == 1) {
245 if (!empty($notabletag) && $notabletag == 3) {
248 if (empty($notabletag) && $perm) {
251 if (empty($notabletag) && $perm) {
252 $ret .=
'</tr></table>';
282 public function editfieldval($text, $htmlname, $value,
$object, $perm, $typeofdata =
'string', $editvalue =
'', $extObject =
null, $custommsg =
null, $moreparam =
'', $notabletag = 1, $formatfunc =
'', $paramid =
'id', $gm =
'auto', $moreoptions = array(), $editaction =
'')
284 global
$conf, $langs;
289 if (empty($typeofdata)) {
290 return 'ErrorBadParameter typeofdata is empty';
293 if ($typeofdata ==
'datetime') {
294 $typeofdata =
'dayhour';
296 if ($typeofdata ==
'date') {
300 if (preg_match(
'/^(\w+)\((\d+)\)$/', $typeofdata, $reg)) {
301 if ($reg[1] ==
'varchar') {
302 $typeofdata =
'string';
303 } elseif ($reg[1] ==
'int') {
304 $typeofdata =
'numeric';
306 return 'ErrorBadParameter ' . $typeofdata;
311 if (
getDolGlobalString(
'MAIN_USE_EDIT_IN_PLACE') && !preg_match(
'/^select;|day|datepicker|dayhour|datehourpicker/', $typeofdata)) {
312 $ret .= $this->
editInPlace(
$object, $value, $htmlname, ($perm ? 1 : 0), $typeofdata, $editvalue, $extObject, $custommsg);
314 if ($editaction ==
'') {
315 $editaction =
GETPOST(
'action',
'aZ09');
317 $editmode = ($editaction ==
'edit' . $htmlname);
319 $ret .=
"<!-- formeditfieldval -->\n";
320 $ret .=
'<form method="post" action="' . $_SERVER[
"PHP_SELF"] . ($moreparam ?
'?' . $moreparam :
'') .
'">';
321 $ret .=
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
322 $ret .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
323 $ret .=
'<input type="hidden" name="' . $paramid .
'" value="' .
$object->id .
'">';
324 if (empty($notabletag)) {
325 $ret .=
'<table class="nobordernopadding centpercent">';
327 if (empty($notabletag)) {
330 if (preg_match(
'/^(string|safehtmlstring|email|phone|url)/', $typeofdata)) {
331 $tmp = explode(
':', $typeofdata);
332 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($editvalue ? $editvalue : $value) .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus spellcheck="false">';
333 } elseif (preg_match(
'/^(integer)/', $typeofdata)) {
334 $tmp = explode(
':', $typeofdata);
335 $valuetoshow =
price2num($editvalue ? $editvalue : $value, 0);
336 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $valuetoshow .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
337 } elseif (preg_match(
'/^(numeric|amount)/', $typeofdata)) {
338 $tmp = explode(
':', $typeofdata);
339 $valuetoshow =
price2num($editvalue ? $editvalue : $value);
340 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($valuetoshow !=
'' ?
price($valuetoshow) :
'') .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
341 } elseif (preg_match(
'/^(checkbox)/', $typeofdata)) {
342 $tmp = explode(
':', $typeofdata);
343 $ret .=
'<input type="checkbox" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($value ? $value :
'on') .
'"' . ($value ?
' checked' :
'') . (empty($tmp[1]) ?
'' : $tmp[1]) .
'/>';
344 } elseif (preg_match(
'/^text/', $typeofdata) || preg_match(
'/^note/', $typeofdata)) {
345 $tmp = explode(
':', $typeofdata);
346 $cols = (empty($tmp[2]) ?
'' : $tmp[2]);
348 if (preg_match(
'/%/', $cols)) {
349 $morealt =
' style="width: ' . $cols .
'"';
352 $valuetoshow = ($editvalue ? $editvalue : $value);
353 $ret .=
'<textarea id="' . $htmlname .
'" name="' . $htmlname .
'" wrap="soft" rows="' . (empty($tmp[1]) ?
'20' : $tmp[1]) .
'"' . ($cols ?
' cols="' . $cols .
'"' :
'class="quatrevingtpercent"') . $morealt .
'" autofocus>';
356 $valuetoshow = str_replace(
'&',
'&', $valuetoshow);
358 $ret .=
'</textarea><div class="clearboth"></div>';
359 } elseif ($typeofdata ==
'day' || $typeofdata ==
'datepicker') {
360 $addnowlink = empty($moreoptions[
'addnowlink']) ? 0 : $moreoptions[
'addnowlink'];
361 $adddateof = empty($moreoptions[
'adddateof']) ?
'' : $moreoptions[
'adddateof'];
362 $labeladddateof = empty($moreoptions[
'labeladddateof']) ?
'' : $moreoptions[
'labeladddateof'];
363 $ret .= $this->
selectDate($value, $htmlname, 0, 0, 1,
'form' . $htmlname, 1, $addnowlink, 0,
'',
'', $adddateof,
'', 1, $labeladddateof,
'', $gm);
364 } elseif ($typeofdata ==
'dayhour' || $typeofdata ==
'datehourpicker') {
365 $addnowlink = empty($moreoptions[
'addnowlink']) ? 0 : $moreoptions[
'addnowlink'];
366 $adddateof = empty($moreoptions[
'adddateof']) ?
'' : $moreoptions[
'adddateof'];
367 $labeladddateof = empty($moreoptions[
'labeladddateof']) ?
'' : $moreoptions[
'labeladddateof'];
368 $ret .= $this->
selectDate($value, $htmlname, 1, 1, 1,
'form' . $htmlname, 1, $addnowlink, 0,
'',
'', $adddateof,
'', 1, $labeladddateof,
'', $gm);
369 } elseif (preg_match(
'/^select;/', $typeofdata)) {
370 $arraydata = explode(
',', preg_replace(
'/^select;/',
'', $typeofdata));
371 $arraylist = array();
372 foreach ($arraydata as $val) {
373 $tmp = explode(
':', $val);
374 $tmpkey = str_replace(
'|',
':', $tmp[0]);
375 $arraylist[$tmpkey] = $tmp[1];
377 $ret .= $this->
selectarray($htmlname, $arraylist, $value);
378 } elseif (preg_match(
'/^link/', $typeofdata)) {
380 } elseif (preg_match(
'/^ckeditor/', $typeofdata)) {
381 $tmp = explode(
':', $typeofdata);
382 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
383 $doleditor =
new DolEditor($htmlname, ($editvalue ? $editvalue : $value), (empty($tmp[2]) ?
'' : $tmp[2]), (empty($tmp[3]) ? 100 : (int) $tmp[3]), (empty($tmp[1]) ?
'dolibarr_notes' : $tmp[1]),
'In', (empty($tmp[5]) ? false : (bool) $tmp[5]), (isset($tmp[8]) ? ($tmp[8] ? true :
false) :
true),
true, (empty($tmp[6]) ? 20 : (int) $tmp[6]), (empty($tmp[7]) ?
'100' : $tmp[7]));
384 $ret .= $doleditor->Create(1);
385 } elseif ($typeofdata ==
'asis') {
386 $ret .= ($editvalue ? $editvalue : $value);
388 if (empty($notabletag)) {
393 if (empty($notabletag)) {
397 $ret .=
'<input type="submit" class="smallpaddingimp nomargingtop nomarginbottom button' . (empty($notabletag) ?
'' :
' ') .
'" name="modify" value="' . $langs->trans(
"Save") .
'">';
398 if (preg_match(
'/ckeditor|textarea/', $typeofdata) && empty($notabletag)) {
399 $ret .=
'<br>' .
"\n";
401 $ret .=
'<input type="submit" class="smallpaddingimp nomargingtop nomarginbottom button button-cancel' . (empty($notabletag) ?
'' :
' ') .
'" name="cancel" value="' . $langs->trans(
"Cancel") .
'">';
402 if (empty($notabletag)) {
406 if (empty($notabletag)) {
407 $ret .=
'</tr></table>' .
"\n";
409 $ret .=
'</form>' .
"\n";
411 if (preg_match(
'/^email/', $typeofdata)) {
413 } elseif (preg_match(
'/^phone/', $typeofdata)) {
415 } elseif (preg_match(
'/^url/', $typeofdata)) {
417 } elseif (preg_match(
'/^(amount|numeric)/', $typeofdata)) {
418 $ret .= ($value !=
'' ?
price($value, 0, $langs, 0, -1, -1,
$conf->currency) :
'');
419 } elseif (preg_match(
'/^checkbox/', $typeofdata)) {
420 $tmp = explode(
':', $typeofdata);
421 $ret .=
'<input type="checkbox" disabled id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $value .
'"' . ($value ?
' checked' :
'') . ($tmp[1] ? $tmp[1] :
'') .
'/>';
422 } elseif (preg_match(
'/^text/', $typeofdata) || preg_match(
'/^note/', $typeofdata)) {
424 } elseif (preg_match(
'/^(safehtmlstring|restricthtml)/', $typeofdata)) {
426 } elseif ($typeofdata ==
'day' || $typeofdata ==
'datepicker') {
427 $ret .=
'<span class="valuedate">' .
dol_print_date($value,
'day', $gm) .
'</span>';
428 } elseif ($typeofdata ==
'dayhour' || $typeofdata ==
'datehourpicker') {
429 $ret .=
'<span class="valuedate">' .
dol_print_date($value,
'dayhour', $gm) .
'</span>';
430 } elseif (preg_match(
'/^select;/', $typeofdata)) {
431 $arraydata = explode(
',', preg_replace(
'/^select;/',
'', $typeofdata));
432 $arraylist = array();
433 foreach ($arraydata as $val) {
434 $tmp = explode(
':', $val);
435 $arraylist[$tmp[0]] = $tmp[1];
437 $ret .= $arraylist[$value];
438 if ($htmlname ==
'fk_product_type') {
440 $ret = img_picto($langs->trans(
"Product"),
'product',
'class="paddingleftonly paddingrightonly colorgrey"') . $ret;
442 $ret = img_picto($langs->trans(
"Service"),
'service',
'class="paddingleftonly paddingrightonly colorgrey"') . $ret;
445 } elseif (preg_match(
'/^ckeditor/', $typeofdata)) {
448 $firstline = preg_replace(
'/<br>.*/',
'', $tmpcontent);
449 $firstline = preg_replace(
'/[\n\r].*/',
'', $firstline);
450 $tmpcontent = $firstline . ((strlen($firstline) != strlen($tmpcontent)) ?
'...' :
'');
456 if (empty($moreoptions[
'valuealreadyhtmlescaped'])) {
464 if ($formatfunc && method_exists(
$object, $formatfunc)) {
465 $ret =
$object->$formatfunc($ret);
485 global
$conf, $langs, $extralanguages;
490 $arrayoflangcode = array();
495 if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
496 if (!is_object($extralanguages)) {
497 include_once DOL_DOCUMENT_ROOT .
'/core/class/extralanguages.class.php';
500 $extralanguages->fetch_name_extralanguages(
'societe');
505 if (empty($extralanguages->attributes[
$object->element]) || !is_array($extralanguages->attributes[
$object->element]) || empty($extralanguages->attributes[
$object->element][$fieldname])) {
509 $result .=
'<!-- Widget for translation -->' .
"\n";
510 $result .=
'<div class="inline-block paddingleft image-' .
$object->element .
'-' . $fieldname .
'">';
511 $s = img_picto($langs->trans(
"ShowOtherLanguages"),
'language',
'', 0, 0, 0,
'',
'fa-15 editfieldlang');
515 $result .=
'<div class="inline-block hidden field-' .
$object->element .
'-' . $fieldname .
'">';
517 $resultforextrlang =
'';
518 foreach ($arrayoflangcode as $langcode) {
519 $valuetoshow =
GETPOSTISSET(
'field-' .
$object->element .
"-" . $fieldname .
"-" . $langcode) ?
GETPOST(
'field-' .
$object->element .
'-' . $fieldname .
"-" . $langcode, $check) :
'';
520 if (empty($valuetoshow)) {
521 $object->fetchValuesForExtraLanguages();
523 $valuetoshow =
$object->array_languages[$fieldname][$langcode];
527 $resultforextrlang .= $s;
530 if ($typeofdata ==
'textarea') {
531 $resultforextrlang .=
'<textarea name="field-' .
$object->element .
"-" . $fieldname .
"-" . $langcode .
'" id="' . $fieldname .
"-" . $langcode .
'" class="' . $morecss .
'" rows="' . ROWS_2 .
'" wrap="soft">';
532 $resultforextrlang .= $valuetoshow;
533 $resultforextrlang .=
'</textarea>';
535 $resultforextrlang .=
'<input type="text" class="inputfieldforlang ' . ($morecss ?
' ' . $morecss :
'') .
'" name="field-' .
$object->element .
'-' . $fieldname .
'-' . $langcode .
'" value="' . $valuetoshow .
'">';
538 $result .= $resultforextrlang;
541 $result .=
'<script nonce="' .
getNonce() .
'">$(".image-' .
$object->element .
'-' . $fieldname .
'").click(function() { console.log("Toggle lang widget"); jQuery(".field-' .
$object->element .
'-' . $fieldname .
'").toggle(); });</script>';
560 protected function editInPlace(
$object, $value, $htmlname, $condition, $inputType =
'textarea', $editvalue =
null, $extObject =
null, $custommsg =
null)
565 if (preg_match(
'/^text/', $inputType)) {
567 } elseif (preg_match(
'/^numeric/', $inputType)) {
568 $value =
price($value);
569 } elseif ($inputType ==
'day' || $inputType ==
'datepicker') {
575 $table_element =
false;
579 $ext_element =
false;
580 $button_only =
false;
587 $table_element =
$object->table_element;
591 if (is_object($extObject)) {
592 $ext_element = $extObject->element;
595 if (preg_match(
'/^(string|email|numeric)/', $inputType)) {
596 $tmp = explode(
':', $inputType);
597 $inputType = $tmp[0];
598 if (!empty($tmp[1])) {
599 $inputOption = $tmp[1];
601 if (!empty($tmp[2])) {
602 $savemethod = $tmp[2];
604 $out .=
'<input id="width_' . $htmlname .
'" value="' . $inputOption .
'" type="hidden"/>' .
"\n";
605 } elseif ((preg_match(
'/^day$/', $inputType)) || (preg_match(
'/^datepicker/', $inputType)) || (preg_match(
'/^datehourpicker/', $inputType))) {
606 $tmp = explode(
':', $inputType);
607 $inputType = $tmp[0];
608 if (!empty($tmp[1])) {
609 $inputOption = $tmp[1];
611 if (!empty($tmp[2])) {
612 $savemethod = $tmp[2];
615 $out .=
'<input id="timestamp" type="hidden"/>' .
"\n";
616 } elseif (preg_match(
'/^(select|autocomplete)/', $inputType)) {
617 $tmp = explode(
':', $inputType);
618 $inputType = $tmp[0];
619 $loadmethod = $tmp[1];
620 if (!empty($tmp[2])) {
621 $savemethod = $tmp[2];
623 if (!empty($tmp[3])) {
626 } elseif (preg_match(
'/^textarea/', $inputType)) {
627 $tmp = explode(
':', $inputType);
628 $inputType = $tmp[0];
629 $rows = (empty($tmp[1]) ?
'8' : $tmp[1]);
630 $cols = (empty($tmp[2]) ?
'80' : $tmp[2]);
631 } elseif (preg_match(
'/^ckeditor/', $inputType)) {
632 $tmp = explode(
':', $inputType);
633 $inputType = $tmp[0];
635 if (!empty($tmp[2])) {
638 if (!empty($tmp[3])) {
641 if (!empty($tmp[4])) {
642 $savemethod = $tmp[4];
646 $out .=
'<input id="ckeditor_toolbar" value="' . $toolbar .
'" type="hidden"/>' .
"\n";
648 $inputType =
'textarea';
652 $out .=
'<input id="element_' . $htmlname .
'" value="' . $element .
'" type="hidden"/>' .
"\n";
653 $out .=
'<input id="table_element_' . $htmlname .
'" value="' . $table_element .
'" type="hidden"/>' .
"\n";
654 $out .=
'<input id="fk_element_' . $htmlname .
'" value="' . $fk_element .
'" type="hidden"/>' .
"\n";
655 $out .=
'<input id="loadmethod_' . $htmlname .
'" value="' . $loadmethod .
'" type="hidden"/>' .
"\n";
656 if (!empty($savemethod)) {
657 $out .=
'<input id="savemethod_' . $htmlname .
'" value="' . $savemethod .
'" type="hidden"/>' .
"\n";
659 if (!empty($ext_element)) {
660 $out .=
'<input id="ext_element_' . $htmlname .
'" value="' . $ext_element .
'" type="hidden"/>' .
"\n";
662 if (!empty($custommsg)) {
663 if (is_array($custommsg)) {
664 if (!empty($custommsg[
'success'])) {
665 $out .=
'<input id="successmsg_' . $htmlname .
'" value="' . $custommsg[
'success'] .
'" type="hidden"/>' .
"\n";
667 if (!empty($custommsg[
'error'])) {
668 $out .=
'<input id="errormsg_' . $htmlname .
'" value="' . $custommsg[
'error'] .
'" type="hidden"/>' .
"\n";
671 $out .=
'<input id="successmsg_' . $htmlname .
'" value="' . $custommsg .
'" type="hidden"/>' .
"\n";
674 if ($inputType ==
'textarea') {
675 $out .=
'<input id="textarea_' . $htmlname .
'_rows" value="' . $rows .
'" type="hidden"/>' .
"\n";
676 $out .=
'<input id="textarea_' . $htmlname .
'_cols" value="' . $cols .
'" type="hidden"/>' .
"\n";
678 $out .=
'<span id="viewval_' . $htmlname .
'" class="viewval_' . $inputType . ($button_only ?
' inactive' :
' active') .
'">' . $value .
'</span>' .
"\n";
679 $out .=
'<span id="editval_' . $htmlname .
'" class="editval_' . $inputType . ($button_only ?
' inactive' :
' active') .
' hideobject">' . (!empty($editvalue) ? $editvalue : $value) .
'</span>' .
"\n";
705 public function textwithtooltip($text, $htmltext, $tooltipon = 1, $direction = 0, $img =
'', $extracss =
'', $notabs = 3, $incbefore =
'', $noencodehtmltext = 0, $tooltiptrigger =
'', $forcenowrap = 0)
708 $text = $incbefore . $text;
713 $direction = (int) $direction;
723 $htmltext = str_replace(array(
"\r",
"\n"),
'', $htmltext);
726 if ($direction < 0) {
727 $extracss = ($extracss ? $extracss :
'') . ($notabs != 3 ?
' inline-block' :
'');
728 $extrastyle =
'padding: 0px; padding-left: 2px;';
730 if ($direction > 0) {
731 $extracss = ($extracss ? $extracss :
'') . ($notabs != 3 ?
' inline-block' :
'');
732 $extrastyle =
'padding: 0px; padding-right: 2px;';
735 $classfortooltip =
'classfortooltip';
740 if ($tooltiptrigger ==
'') {
741 $htmltext = str_replace(
'"',
'"', $htmltext);
743 $classfortooltip =
'classfortooltiponclick';
744 $textfordialog .=
'<div style="display: none;" id="idfortooltiponclick_' . $tooltiptrigger .
'" class="classfortooltiponclicktext"';
748 $textfordialog .=
' title="'.$langs->trans(
"Note").
'"';
750 $textfordialog .=
'>' . $htmltext .
'</div>';
752 if ($tooltipon == 2 || $tooltipon == 3) {
753 $paramfortooltipimg =
' class="' . $classfortooltip . ($notabs != 3 ?
' inline-block' :
'') . ($extracss ?
' ' . $extracss :
'') .
'" style="padding: 0px;' . ($extrastyle ?
' ' . $extrastyle :
'') .
'"';
754 if ($tooltiptrigger ==
'') {
755 $paramfortooltipimg .=
' title="' . ($noencodehtmltext ? $htmltext :
dol_escape_htmltag($htmltext, 1, 0,
'span', 0, 1)) .
'"';
757 $paramfortooltipimg .=
' dolid="' . $tooltiptrigger .
'"';
760 $paramfortooltipimg = ($extracss ?
' class="' . $extracss .
'"' :
'') . ($extrastyle ?
' style="' . $extrastyle .
'"' :
'');
762 if ($tooltipon == 1 || $tooltipon == 3) {
763 $paramfortooltiptd =
' class="' . ($tooltipon == 3 ?
'cursorpointer ' :
'') . $classfortooltip . ($tag !=
'td' ?
' inline-block' :
'') . ($extracss ?
' ' . $extracss :
'') .
'" style="padding: 0px;' . ($extrastyle ?
' ' . $extrastyle :
'') .
'" ';
764 if ($tooltiptrigger ==
'') {
765 $paramfortooltiptd .=
' title="' . ($noencodehtmltext ? $htmltext :
dol_escape_htmltag($htmltext, 1, 0,
'span', 0, 1)) .
'"';
767 $paramfortooltiptd .=
' dolid="' . $tooltiptrigger .
'"';
770 $paramfortooltiptd = ($extracss ?
' class="' . $extracss .
'"' :
'') . ($extrastyle ?
' style="' . $extrastyle .
'"' :
'');
772 if (empty($notabs)) {
773 $s .=
'<table class="nobordernopadding"><tr style="height: auto;">';
774 } elseif ($notabs == 2) {
775 $s .=
'<div class="inline-block' . ($forcenowrap ?
' nowrap' :
'') .
'">';
778 if ($direction < 0) {
779 $s .=
'<' . $tag . $paramfortooltipimg;
781 $s .=
' class="valigntop" width="14"';
783 $s .=
'>' . $textfordialog . $img .
'</' . $tag .
'>';
787 if ((
string) $text !=
'') {
788 $s .=
'<' . $tag . $paramfortooltiptd .
'>' . $text .
'</' . $tag .
'>';
791 if ($direction > 0) {
792 $s .=
'<' . $tag . $paramfortooltipimg;
794 $s .=
' class="valignmiddle" width="14"';
796 $s .=
'>' . $textfordialog . $img .
'</' . $tag .
'>';
798 if (empty($notabs)) {
799 $s .=
'</tr></table>';
800 } elseif ($notabs == 2) {
821 public function textwithpicto($text, $htmltooltip, $direction = 1, $type =
'help', $extracss =
'valignmiddle', $noencodehtmltext = 0, $notabs = 3, $tooltiptrigger =
'', $forcenowrap = 0)
823 global
$conf, $langs;
828 } elseif ($type ==
'1') {
832 $tooltiptrigger = preg_replace(
'/[^a-z0-9]/i',
'', $tooltiptrigger);
834 if (preg_match(
'/onsmartphone$/', $tooltiptrigger) && empty(
$conf->dol_no_mouse_hover)) {
835 $tooltiptrigger = preg_replace(
'/^.*onsmartphone$/',
'', $tooltiptrigger);
838 if ($tooltiptrigger) {
839 $alt = $langs->transnoentitiesnoconv(
"ClickToShowHelp");
843 if (empty(
$conf->use_javascript_ajax)) {
844 if ($type ==
'info' || $type ==
'infoclickable' || $type ==
'help' || $type ==
'helpclickable') {
853 if (!empty(
$conf->dol_no_mouse_hover) && empty($tooltiptrigger)) {
854 if ($type ==
'info' || $type ==
'infoclickable' || $type ==
'help' || $type ==
'helpclickable') {
865 if ($type ==
'info') {
866 $img = img_help(($tooltiptrigger !=
'' ? 2 : 0), $alt);
867 } elseif ($type ==
'help') {
868 $img = img_help(($tooltiptrigger !=
'' ? 2 : 1), $alt);
869 } elseif ($type ==
'helpclickable') {
870 $img = img_help(($tooltiptrigger !=
'' ? 2 : 1), $alt);
871 } elseif ($type ==
'warning') {
872 $img = img_warning($alt);
873 } elseif ($type !=
'none') {
875 $img = img_picto($alt, $type);
878 $tooltipon = ((($tooltiptrigger && !$img) || strpos($type,
'clickable')) ? 3 : 2);
880 return $this->
textwithtooltip($text, $htmltooltip, $tooltipon, $direction, $img, $extracss, $notabs,
'', $noencodehtmltext, $tooltiptrigger, $forcenowrap);
893 public function selectMassAction($selected, $arrayofaction, $alwaysvisible = 0, $name =
'massaction', $cssclass =
'checkforselect')
895 global
$conf, $langs, $hookmanager;
898 $ret =
'<div class="centpercent center">';
899 $ret .=
'<select class="flat' . (empty(
$conf->use_javascript_ajax) ?
'' :
' hideobject') .
' ' . $name .
' ' . $name .
'select valignmiddle alignstart" id="' . $name .
'" name="' . $name .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
'>';
902 $parameters = array();
903 $reshook = $hookmanager->executeHooks(
'addMoreMassActions', $parameters);
906 if (is_array($arrayofaction) && count($arrayofaction) == 0 && empty($hookmanager->resPrint)) {
909 if (empty($reshook)) {
910 $ret .=
'<option value="0"' . ($disabled ?
' disabled="disabled"' :
'') .
'>-- ' . $langs->trans(
"SelectAction") .
' --</option>';
911 if (is_array($arrayofaction)) {
912 foreach ($arrayofaction as $code => $label) {
913 $ret .=
'<option value="' . $code .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' data-html="' .
dol_escape_htmltag($label) .
'">' . $label .
'</option>';
917 $ret .= $hookmanager->resPrint;
921 if (empty(
$conf->dol_optimize_smallscreen)) {
926 $ret .=
'<input type="submit" name="confirmmassactioninvisible" style="display: none" tabindex="-1">';
927 $ret .=
'<input type="submit" disabled name="confirmmassaction"' . (empty(
$conf->use_javascript_ajax) ?
'' :
' style="display: none"') .
' class="reposition button smallpaddingimp' . (empty(
$conf->use_javascript_ajax) ?
'' :
' hideobject') .
' ' . $name .
' ' . $name .
'confirmed" value="' .
dol_escape_htmltag($langs->trans(
"Confirm")) .
'">';
930 if (!empty(
$conf->use_javascript_ajax)) {
931 $ret .=
'<!-- JS CODE TO ENABLE mass action select -->
933 function initCheckForSelect(mode, name, cssclass) { /* mode is 0 during init of page or click all, 1 when we click on 1 checkboxi, "name" refers to the class of the massaction button, "cssclass" to the class of the check for select boxes */
934 atleastoneselected=0;
935 jQuery("."+cssclass).each(function( index ) {
936 /* console.log( index + ": " + $( this ).text() ); */
937 if ($(this).is(\':checked\')) atleastoneselected++;
940 console.log("initCheckForSelect mode="+mode+" name="+name+" cssclass="+cssclass+" atleastoneselected="+atleastoneselected);
942 if (atleastoneselected || ' . ((int) $alwaysvisible) .
') {
943 jQuery("."+name).show();
944 ' . ($selected ?
'if (atleastoneselected) { jQuery("."+name+"select").val("' . $selected .
'").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', false); }' :
'') .
'
945 ' . ($selected ?
'if (! atleastoneselected) { jQuery("."+name+"select").val("0").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', true); } ' :
'') .
'
947 jQuery("."+name).hide();
948 jQuery("."+name+"other").hide();
952 jQuery(document).ready(function () {
953 initCheckForSelect(0, "' . $name .
'", "' . $cssclass .
'");
954 jQuery(".' . $cssclass .
'").change(function() {
955 console.log("A change was done on .' . $cssclass .
'");
956 initCheckForSelect(1, "' . $name .
'", "' . $cssclass .
'");
958 jQuery(".' . $name .
'select").change(function() {
959 var massaction = $( this ).val();
960 var urlform = $( this ).closest("form").attr("action").replace("#show_files","");
961 if (massaction == "builddoc") {
962 urlform = urlform + "#show_files";
964 $( this ).closest("form").attr("action", urlform);
965 console.log("we select a mass action name=' . $name .
' massaction="+massaction+" - "+urlform);
966 /* Warning: if you set submit button to disabled, post using Enter will no more work if there is no other button */
967 if ($(this).val() != \'0\') {
968 jQuery(".' . $name .
'confirmed").prop(\'disabled\', false);
969 jQuery(".' . $name .
'other").hide(); /* To disable if another div was open */
970 jQuery(".' . $name .
'"+massaction).show();
972 jQuery(".' . $name .
'confirmed").prop(\'disabled\', true);
973 jQuery(".' . $name .
'other").hide(); /* To disable any div open */
1003 public function select_country($selected =
'', $htmlname =
'country_id', $htmloption =
'', $maxlength = 0, $morecss =
'minwidth300', $usecodeaskey =
'', $showempty = 1, $disablefavorites = 0, $addspecialentries = 0, $exclude_country_code = array(), $hideflags = 0, $forcecombo = 0)
1008 $langs->load(
"dict");
1010 $selected = (string) $selected;
1014 $countryArray = array();
1015 $favorite = array();
1017 $atleastonefavorite = 0;
1019 $sql =
"SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite, eec";
1020 $sql .=
" FROM " . $this->db->prefix() .
"c_country";
1021 $sql .=
" WHERE active > 0";
1024 dol_syslog(get_class($this) .
"::select_country", LOG_DEBUG);
1026 $resql = $this->db->query($sql);
1028 $out .=
'<select id="select' . $htmlname .
'" class="flat maxwidth200onsmartphone selectcountry' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" ' . $htmloption .
'>';
1029 $num = $this->db->num_rows($resql);
1033 $obj = $this->db->fetch_object($resql);
1037 'rowid' => (
int) $obj->rowid,
1038 'code_iso' => (
string) $obj->code_iso,
1039 'code_iso3' => (
string) $obj->code_iso3,
1040 'label' => (
string) ($obj->code_iso && $langs->transnoentitiesnoconv(
"Country" . $obj->code_iso) !=
"Country" . $obj->code_iso ? $langs->transnoentitiesnoconv(
"Country" . $obj->code_iso) : ($obj->label !=
'-' ? $obj->label :
'')),
1041 'favorite' => (string) $obj->favorite,
1042 'eec' => (string) $obj->eec,
1044 $favorite[$i] = $obj->favorite;
1049 if (empty($disablefavorites)) {
1050 $array1_sort_order = SORT_DESC;
1051 $array2_sort_order = SORT_ASC;
1052 array_multisort($favorite, $array1_sort_order, $label, $array2_sort_order, $countryArray);
1058 if (is_numeric($showempty)) {
1059 $out .=
'<option value=""> </option>' .
"\n";
1061 $out .=
'<option value="-1">' . $langs->trans($showempty) .
'</option>' .
"\n";
1065 if ($addspecialentries) {
1067 $out .=
'<option value="special_allnotme"' . ($selected ==
'special_allnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesExceptMe", $langs->transnoentitiesnoconv(
"Country" .
$mysoc->country_code)) .
'</option>';
1068 $out .=
'<option value="special_eec"' . ($selected ==
'special_eec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEEC") .
'</option>';
1070 $out .=
'<option value="special_eecnotme"' . ($selected ==
'special_eecnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEECExceptMe", $langs->transnoentitiesnoconv(
"Country" .
$mysoc->country_code)) .
'</option>';
1072 $out .=
'<option value="special_noteec"' . ($selected ==
'special_noteec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesNotInEEC") .
'</option>';
1073 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1076 foreach ($countryArray as $row) {
1078 if (empty($row[
'rowid'])) {
1081 if (is_array($exclude_country_code) && count($exclude_country_code) && in_array($row[
'code_iso'], $exclude_country_code)) {
1085 if (empty($disablefavorites) && $row[
'favorite'] && $row[
'code_iso']) {
1086 $atleastonefavorite++;
1088 if (empty($row[
'favorite']) && $atleastonefavorite) {
1089 $atleastonefavorite = 0;
1090 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1094 if ($row[
'label']) {
1095 $labeltoshow .=
dol_trunc($row[
'label'], $maxlength,
'middle');
1097 $labeltoshow .=
' ';
1099 if ($row[
'code_iso']) {
1100 $labeltoshow .=
' <span class="opacitymedium">(' . $row[
'code_iso'] .
')</span>';
1101 if (empty($hideflags)) {
1102 $tmpflag =
picto_from_langcode($row[
'code_iso'],
'class="saturatemedium paddingrightonly"', 1);
1103 $labeltoshow = $tmpflag .
' ' . $labeltoshow;
1107 if ($selected && $selected !=
'-1' && ($selected == $row[
'rowid'] || $selected == $row[
'code_iso'] || $selected == $row[
'code_iso3'] || $selected == $row[
'label'])) {
1108 $out .=
'<option value="' . ($usecodeaskey ? ($usecodeaskey ==
'code2' ? $row[
'code_iso'] : $row[
'code_iso3']) : $row[
'rowid']) .
'" selected data-html="' .
dol_escape_htmltag($labeltoshow) .
'" data-eec="' . ((int) $row[
'eec']) .
'">';
1110 $out .=
'<option value="' . ($usecodeaskey ? ($usecodeaskey ==
'code2' ? $row[
'code_iso'] : $row[
'code_iso3']) : $row[
'rowid']) .
'" data-html="' .
dol_escape_htmltag($labeltoshow) .
'" data-eec="' . ((int) $row[
'eec']) .
'">';
1113 $out .=
'</option>' .
"\n";
1116 $out .=
'</select>';
1118 dol_print_error($this->db);
1122 if (empty($forcecombo)) {
1123 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1124 $out .=
ajax_combobox(
'select' . $htmlname, array(), 0, 0,
'resolve');
1140 public function selectPhoneCode($selected =
'', $htmlname =
'phone_code', $morecss =
'maxwidth150', $showempty = 0, $country_id_hint = 0)
1144 $langs->load(
"dict");
1147 $codeArray = array();
1148 $favorite = array();
1150 $atleastonefavorite = 0;
1152 $sql =
"SELECT rowid, code, label, phone_code, favorite, trunk_prefix";
1153 $sql .=
" FROM ".$this->db->prefix().
"c_country";
1155 $sql .=
" WHERE active > 0 AND phone_code IS NOT NULL AND phone_code != 0";
1157 dol_syslog(get_class($this).
"::selectPhoneCode", LOG_DEBUG);
1158 $resql = $this->db->query($sql);
1160 $num = $this->db->num_rows($resql);
1163 $obj = $this->db->fetch_object($resql);
1165 $translabel = ($obj->code && $langs->transnoentitiesnoconv(
"Country".$obj->code) !=
"Country".$obj->code) ? $langs->transnoentitiesnoconv(
"Country".$obj->code) : $obj->label;
1167 $codeArray[$i][
'rowid'] = $obj->rowid;
1168 $codeArray[$i][
'code'] = $obj->code;
1169 $codeArray[$i][
'label'] = $translabel;
1170 $codeArray[$i][
'phone_code'] =
'+'.$obj->phone_code;
1171 $codeArray[$i][
'favorite'] = $obj->favorite;
1172 $codeArray[$i][
'trunk_prefix'] = $obj->trunk_prefix;
1173 $favorite[$i] = $obj->favorite;
1178 $array1_sort_order = SORT_DESC;
1179 $array2_sort_order = SORT_ASC;
1180 array_multisort($favorite, $array1_sort_order, $label, $array2_sort_order, $codeArray);
1182 $out .=
'<select id="select'.$htmlname.
'" class="flat selectphonecode'.($morecss ?
' '.$morecss :
'').
'" name="'.$htmlname.
'">';
1185 $out .=
'<option value=""> </option>'.
"\n";
1190 $firstMatchIdx = -1;
1191 if ($selected !==
'') {
1192 foreach ($codeArray as $idx => $row) {
1193 if ($row[
'phone_code'] == $selected) {
1194 if ($firstMatchIdx < 0) {
1195 $firstMatchIdx = $idx;
1197 if ($country_id_hint > 0 && $row[
'rowid'] == $country_id_hint) {
1198 $selectedIdx = $idx;
1203 if ($selectedIdx < 0 && $firstMatchIdx >= 0) {
1204 $selectedIdx = $firstMatchIdx;
1208 foreach ($codeArray as $idx => $row) {
1209 if (empty($row[
'code'])) {
1213 if ($row[
'favorite']) {
1214 $atleastonefavorite++;
1216 if (empty($row[
'favorite']) && $atleastonefavorite) {
1217 $atleastonefavorite = 0;
1218 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1221 $tmpflag =
picto_from_langcode($row[
'code'],
'class="saturatemedium paddingrightonly"', 1);
1224 $selectlabel = ($tmpflag ? $tmpflag.
' ' :
'').$row[
'code'];
1227 $labeltoshow = ($tmpflag ? $tmpflag.
' ' :
'').$row[
'label'].
' '.$row[
'phone_code'];
1229 $out .=
'<option value="'.dol_escape_htmltag($row[
'phone_code']).
'"';
1230 if ($idx === $selectedIdx) {
1231 $out .=
' selected';
1233 $out .=
' data-html="'.dol_escape_htmltag($labeltoshow).
'"';
1234 $out .=
' data-select-html="'.dol_escape_htmltag($selectlabel).
'"';
1235 $out .=
' data-country-id="'.((int) $row[
'rowid']).
'"';
1236 $out .=
' data-trunk-prefix="'.dol_escape_htmltag((
string) $row[
'trunk_prefix']).
'"';
1239 $out .=
'</option>'.
"\n";
1241 $out .=
'</select>';
1243 dol_print_error($this->db);
1247 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1248 $out .=
ajax_combobox(
'select'.$htmlname, array(), 0, 0,
'resolve');
1269 public function showPhoneInput($phoneValue, $htmlname, $country_id_hint = 0, $picto =
'object_phoning', $morecss =
'maxwidth150', $maxlength = 0, $countrySelectorId =
'selectcountry_id')
1273 include_once DOL_DOCUMENT_ROOT.
'/core/lib/phone.lib.php';
1275 $codename = $htmlname.
'_code';
1278 if (empty($country_id_hint) && !empty(
$mysoc->country_id)) {
1279 $country_id_hint =
$mysoc->country_id;
1284 $fullPhone = (string)
GETPOST($htmlname);
1286 $fullPhone = (string) $phoneValue;
1295 $selectedCode = $phonecode;
1296 $numberValue = $parsed[
'number'];
1299 if (strpos($numberValue, $selectedCode) === 0) {
1300 $numberValue = str_replace($selectedCode,
'', $numberValue);
1304 if ($numberValue !==
'' && $selectedCode !==
'') {
1306 if ($trunkPrefix !==
'' && strpos($numberValue, $trunkPrefix) !== 0) {
1307 $numberValue = $trunkPrefix.$numberValue;
1315 $out .= img_picto(
'', $picto,
'class="pictofixedwidth"');
1318 $out .= $this->
selectPhoneCode($selectedCode, $codename,
'maxwidth75 phone_code_select', 0, $country_id_hint);
1321 $out .=
'<input type="tel" inputmode="numeric" pattern="[0-9]*" id="'.dol_escape_htmltag($htmlname).
'_input" class="'.
dol_escape_htmltag($morecss).
'"';
1322 if ($maxlength > 0) {
1323 $out .=
' maxlength="'.$maxlength.
'"';
1325 $out .=
' value="'.dol_escape_htmltag($numberValue).
'">';
1350 $selectId =
'select'.dol_escape_js($codename);
1352 $out =
"\n".
'<script type="text/javascript">'.
"\n";
1353 $out .=
'jQuery(document).ready(function() {'.
"\n";
1354 $out .=
' function syncPhoneField_'.$hiddenId.
'() {'.
"\n";
1355 $out .=
' var selectEl = jQuery(\'#'.$selectId.
'\');
'."\n";
1356 $out .= ' var code = selectEl.val() ||
"";
'."\n";
1357 $out .= ' var number = (jQuery(\
'#'.$inputId.
'\').val() ||
"").replace(/[^0-9]/g,
"");
'."\n";
1358 $out .= ' if (code && number) {
'."\n";
1359 $out .= ' var selOpt = selectEl[0] && selectEl[0].selectedOptions && selectEl[0].selectedOptions[0];
'."\n";
1360 $out .= ' var trunkPrefix = selOpt ? (selOpt.getAttribute(
"data-trunk-prefix") ||
"") :
"";
'."\n";
1361 $out .= ' if (trunkPrefix !==
"" && number.indexOf(trunkPrefix) === 0) {
'."\n";
1362 $out .= ' number = number.substring(trunkPrefix.length);
'."\n";
1364 $out .= ' jQuery(
"#'.$hiddenId.'").val(code +
" " + number);
'."\n";
1365 $out .= ' }
else if (number) {
'."\n";
1366 $out .= ' jQuery(
"#'.$hiddenId.'").val(number);
'."\n";
1367 $out .= ' }
else {
'."\n";
1368 $out .= ' jQuery(
"#'.$hiddenId.'").val(
"");
'."\n";
1371 $out .= ' jQuery(\
'#'.$selectId.
'\').on(
"change",
function() { syncPhoneField_
'.$hiddenId.'(); });
'."\n";
1372 $out .= ' jQuery(\
'#'.$inputId.
'\').on(
"input change",
function() { syncPhoneField_
'.$hiddenId.'(); });
'."\n";
1374 $out .= '</script>
'."\n";
1388 private function getPhoneInputSharedJs($countrySelectorId)
1390 if ($this->phoneInputSharedJsLoaded) {
1393 $this->phoneInputSharedJsLoaded = true;
1395 $out = "\n".'<script
type=
"text/javascript">
'."\n";
1396 $out .= 'jQuery(document).ready(
function() {
'."\n";
1397 $out .= ' jQuery(\
'#'.
dol_escape_js($countrySelectorId).
'\').on(
"change",
function() {
'."\n";
1398 $out .= ' var country_id = jQuery(
this).val();
'."\n";
1399 $out .= ' if (country_id) {
'."\n";
1400 $out .= ' jQuery.getJSON(
"'.DOL_URL_ROOT.'/core/ajax/getphonecode.php", {country_id: country_id, token:
"'.currentToken().'"},
function(data) {
'."\n";
1401 $out .= ' if (data.phone_code) {
'."\n";
1402 $out .= ' jQuery(
".phone_code_select").each(
function() {
'."\n";
1403 $out .= ' jQuery(
this).val(data.phone_code).trigger(
"change");
'."\n";
1404 $out .= ' });
'."\n";
1406 $out .= ' });
'."\n";
1408 $out .= ' });
'."\n";
1410 $out .= '</script>
'."\n";
1424 private function flagLinksFromHook($linksfromhook)
1426 foreach ($linksfromhook as $key => $val) {
1427 if (is_array($val)) {
1428 $linksfromhook[$key]['fromhook
'] = 1;
1432 return $linksfromhook;
1448 private function makeAddLinkToObject($object, $key, $possiblelink, $num, $resqllist)
1450 dol_syslog(__METHOD__, LOG_DEBUG);
1451 global $langs, $form;
1453 $form = new Form($this->db);
1455 $htmltoenteralink = '
';
1459 $htmltoenteralink .= '<tr
class=
"liste_titre">
';
1460 $htmltoenteralink .= '<td
class=
"nowrap"></td>
';
1461 $htmltoenteralink .= '<td>
' . $langs->trans("Ref") . '</td>
';
1462 $htmltoenteralink .= '<td>
' . $langs->trans("RefCustomer") . '</td>
';
1463 $htmltoenteralink .= '<td
class=
"right">
' . $langs->trans("AmountHTShort") . '</td>
';
1464 $htmltoenteralink .= '<td>
' . $langs->trans("Company") . '</td>
';
1465 $htmltoenteralink .= '</tr>
';
1469 $objp = $this->db->fetch_object($resqllist);
1470 $alreadylinked = false;
1471 if (!empty($object->linkedObjectsIds[$possiblelink['linkname
'] ?? $key])) {
1472 if (in_array($objp->rowid, array_values($object->linkedObjectsIds[$possiblelink['linkname
'] ?? $key]))) {
1473 $alreadylinked = true;
1476 $htmltoenteralink .= '<tr
class=
"oddeven">
';
1477 $htmltoenteralink .= '<td>
';
1478 if ($alreadylinked) {
1479 $htmltoenteralink .= img_picto('', 'link
');
1481 $htmltoenteralink .= '<input
type=
"checkbox" name=
"idtolinkto[' . $key . '_' . $objp->rowid . ']" id=
"' . $key . '_' . $objp->rowid . '" value=
"' . $objp->rowid . '">
';
1483 $htmltoenteralink .= '</td>
';
1484 $htmltoenteralink .= '<td>
';
1485 if (!$alreadylinked) {
1486 $htmltoenteralink .= '<label
for=
"' . $key . '_' . $objp->rowid . '">
';
1488 $htmltoenteralink .= $objp->ref;
1489 if (!$alreadylinked) {
1490 $htmltoenteralink .= '</label>
';
1492 $htmltoenteralink .= '</td>
';
1493 $htmltoenteralink .= '<td>
' . (!empty($objp->ref_client) ? $objp->ref_client : (!empty($objp->ref_supplier) ? $objp->ref_supplier : '')) . '</td>
';
1494 $htmltoenteralink .= '<td
class=
"right">
';
1495 if ($possiblelink['label
'] == 'LinkToContract
') {
1496 $htmltoenteralink .= $form->textwithpicto('', $langs->trans("InformationOnLinkToContract")) . ' ';
1498 $htmltoenteralink .= '<span
class=
"amount">
' . (isset($objp->total_ht) ? price($objp->total_ht) : '') . '</span>
';
1499 $htmltoenteralink .= '</td>
';
1500 $htmltoenteralink .= '<td>
' . $objp->name . '</td>
';
1501 $htmltoenteralink .= '</tr>
';
1505 return $htmltoenteralink;
1522 private function makeAddLinkToAttendee($object, $key, $possiblelink, $num, $resqllist)
1524 dol_syslog(__METHOD__, LOG_DEBUG);
1525 global $langs, $form;
1526 require_once DOL_DOCUMENT_ROOT . '/eventorganization/
class/conferenceorboothattendee.class.php
';
1527 require_once DOL_DOCUMENT_ROOT . '/societe/
class/societe.class.php
';
1528 require_once DOL_DOCUMENT_ROOT . '/projet/
class/project.class.php
';
1529 $attendeestatic = new ConferenceOrBoothAttendee($this->db);
1530 $companystatic = new Societe($this->db);
1531 $projectstatic = new Project($this->db);
1533 $form = new Form($this->db);
1535 $htmltoenteralink = '';
1539 $htmltoenteralink .= '<tr
class=
"liste_titre">
';
1540 $htmltoenteralink .= '<td
class=
"nowrap"></td>
';
1541 $htmltoenteralink .= '<td>
' . $langs->trans("Ref") . '</td>
';
1542 $htmltoenteralink .= '<td>
' . $langs->trans("Name") . '</td>
';
1543 $htmltoenteralink .= '<td>
' . $langs->trans("Email") . '</td>
';
1544 $htmltoenteralink .= '<td>
' . $langs->trans("Company") . '</td>
';
1545 $htmltoenteralink .= '<td>
' . $langs->trans("Project") . '</td>
';
1546 $htmltoenteralink .= '<td>
' . $langs->trans("DateOfRegistration") . '</td>
';
1547 $htmltoenteralink .= '</tr>
';
1551 $objp = $this->db->fetch_object($resqllist);
1552 $alreadylinked = false;
1553 if (!empty($object->linkedObjectsIds[$possiblelink['linkname
'] ?? $key])) {
1554 if (in_array($objp->rowid, array_values($object->linkedObjectsIds[$possiblelink['linkname
'] ?? $key]))) {
1555 $alreadylinked = true;
1558 $htmltoenteralink .= '<tr
class=
"oddeven">
';
1559 $htmltoenteralink .= '<td>
';
1560 if ($alreadylinked) {
1561 $htmltoenteralink .= img_picto('', 'link
');
1563 $htmltoenteralink .= '<input
type=
"checkbox" name=
"idtolinkto[' . $key . '_' . $objp->rowid . ']" id=
"' . $key . '_' . $objp->rowid . '" value=
"' . $objp->rowid . '">
';
1565 $htmltoenteralink .= '</td>
';
1566 $fetchattendee = $attendeestatic->fetch($objp->rowid);
1567 if ($fetchattendee) {
1568 $htmltoenteralink .= '<td>
' . $attendeestatic->getNomUrl(0). '</td>
';
1570 $htmltoenteralink .= '<td><label
for=
"' . $key . '_' . $objp->rowid . '">
' . $objp->ref . '</label></td>
';
1572 $htmltoenteralink .= '<td>
' . $objp->name . '</td>
';
1573 $htmltoenteralink .= '<td>
' . $objp->email . '</td>
';
1574 $fetchcompany = $companystatic->fetch($objp->socid);
1575 if ($fetchcompany) {
1576 $htmltoenteralink .= '<td>
' . $companystatic->getNomUrl(0). '</td>
';
1578 $htmltoenteralink .= '<td>
' . $objp->name . '</td>
';
1580 $fetchcproject = $projectstatic->fetch($objp->fk_project);
1581 if ($fetchcproject) {
1582 $htmltoenteralink .= '<td>
' . $projectstatic->getNomUrl(0). '</td>
';
1584 $htmltoenteralink .= '<td>
' . $objp->fk_project . '</td>
';
1586 $htmltoenteralink .= '<td>
' . $objp->date_subscription . '</td>
';
1587 $htmltoenteralink .= '</tr>
';
1591 return $htmltoenteralink;
1594 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1609 public function select_incoterms($selected = '
', $location_incoterms = '', $page = '', $htmlname = 'incoterm_id
', $htmloption = '', $forcecombo = 1, $events = array(), $disableautocomplete = 0)
1612 global $conf, $langs;
1614 $langs->load("dict");
1618 $incotermArray = array();
1620 $sql = "SELECT rowid, code";
1621 $sql .= " FROM " . $this->db->prefix() . "c_incoterms";
1622 $sql .= " WHERE active > 0";
1623 $sql .= " ORDER BY code ASC";
1625 dol_syslog(get_class($this) . "::select_incoterm", LOG_DEBUG);
1626 $resql = $this->db->query($sql);
1628 if ($conf->use_javascript_ajax && !$forcecombo) {
1629 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
1630 $out .= ajax_combobox($htmlname, $events);
1633 if (!empty($page)) {
1634 $out .= '<form method=
"post" action=
"' . $page . '">
';
1635 $out .= '<input
type=
"hidden" name=
"action" value=
"set_incoterms">
';
1636 $out .= '<input
type=
"hidden" name=
"token" value=
"' . newToken() . '">
';
1639 $out .= '<select
id=
"' . $htmlname . '" class=
"flat selectincoterm width75" name=
"' . $htmlname . '" ' . $htmloption . '>
';
1640 $out .= '<option value=
"0"> </option>
';
1641 $num = $this->db->num_rows($resql);
1645 $obj = $this->db->fetch_object($resql);
1646 $incotermArray[$i]['rowid
'] = $obj->rowid;
1647 $incotermArray[$i]['code
'] = $obj->code;
1651 foreach ($incotermArray as $row) {
1652 if ($selected && ($selected == $row['rowid
'] || $selected == $row['code
'])) {
1653 $out .= '<option value=
"' . $row['rowid'] . '" selected>
';
1655 $out .= '<option value=
"' . $row['rowid'] . '">
';
1659 $out .= $row['code
'];
1662 $out .= '</option>
';
1665 $out .= '</select>
';
1666 $out .= ajax_combobox($htmlname);
1668 if ($conf->use_javascript_ajax && empty($disableautocomplete)) {
1669 $out .= ajax_multiautocompleter('location_incoterms
', array(), DOL_URL_ROOT . '/core/ajax/locationincoterms.php
') . "\n";
1670 //$moreattrib .= ' autocomplete=
"off"';
1672 $out .= '<input
id=
"location_incoterms" class=
"maxwidthonsmartphone heightofcombo" type=
"text" name=
"location_incoterms" value=
"' . $location_incoterms . '">
' . "\n";
1674 if (!empty($page)) {
1675 $out .= '<input
type=
"submit" class=
"button valignmiddle smallpaddingimp nomargintop nomarginbottom" value=
"' . $langs->trans("Modify
") . '"></form>
';
1678 dol_print_error($this->db);
1684 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1699 public function select_type_of_lines($selected = '
', $htmlname = 'type', $showempty = 0, $hidetext = 0, $forceall = 0, $morecss = "", $useajaxcombo = 1)
1704 // If product & services are enabled or both disabled.
1705 if ($forceall == 1 || (empty($forceall) && isModEnabled("product") && isModEnabled("service"))
1706 || (empty($forceall) && !isModEnabled('product
') && !isModEnabled('service
'))) {
1707 if (empty($hidetext)) {
1708 print $langs->trans("Type").'...
';
1711 print '<select
class=
"flat'.($morecss ? ' '.$morecss : '').'" id=
"select_' . $htmlname . '" name=
"' . $htmlname . '">
';
1713 print '<option value=
"-1" class=
"opacitymedium"'.($useajaxcombo ? '' : ' disabled=
"disabled"');
1714 if ($selected == -1) {
1718 if (is_numeric($showempty)) {
1726 print '<option value=
"0"';
1727 if (0 == $selected || ($selected == -1 && getDolGlobalString('MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT
') == 'product
')) {
1730 print '>
' . $langs->trans("Product");
1733 print '<option value=
"1"';
1734 if (1 == $selected || ($selected == -1 && getDolGlobalString('MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT
') == 'service
')) {
1737 print '>
' . $langs->trans("Service");
1742 if ($useajaxcombo) {
1743 print ajax_combobox('select_
' . $htmlname);
1745 //if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1747 if ((empty($forceall) && !isModEnabled('product
') && isModEnabled("service")) || $forceall == 3) {
1748 print $langs->trans("Service");
1749 print '<input
type=
"hidden" name=
"' . $htmlname . '" value=
"1">
';
1751 if ((empty($forceall) && isModEnabled("product") && !isModEnabled('service
')) || $forceall == 2) {
1752 print $langs->trans("Product");
1753 print '<input
type=
"hidden" name=
"' . $htmlname . '" value=
"0">
';
1755 if ($forceall < 0) { // This should happened only for contracts when both predefined product and service are disabled.
1756 print '<input
type=
"hidden" name=
"' . $htmlname . '" value=
"1">
'; // By default we set on service for contract. If CONTRACT_SUPPORT_PRODUCTS is set, forceall should be 1 not -1
1760 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1767 public function load_cache_types_fees()
1772 $num = count($this->cache_types_fees);
1774 return 0; // Cache already loaded
1777 dol_syslog(__METHOD__, LOG_DEBUG);
1779 $langs->load("trips");
1781 $sql = "SELECT c.code, c.label";
1782 $sql .= " FROM " . $this->db->prefix() . "c_type_fees as c";
1783 $sql .= " WHERE active > 0";
1785 $resql = $this->db->query($sql);
1787 $num = $this->db->num_rows($resql);
1791 $obj = $this->db->fetch_object($resql);
1793 // If a translation exists, we use is, otherwise, we take the label by default
1794 $label = ($obj->code != $langs->trans($obj->code) ? $langs->trans($obj->code) : $langs->trans($obj->label));
1795 $this->cache_types_fees[$obj->code] = $label;
1799 asort($this->cache_types_fees);
1803 dol_print_error($this->db);
1808 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1821 public function select_type_fees($selected = '
', $htmlname = 'type', $showempty = 0, $morecss = '', $nooutput = 0, $noadmin = 0)
1824 global $user, $langs;
1826 dol_syslog(__METHOD__ . " selected=" . $selected . ", htmlname=" . $htmlname, LOG_DEBUG);
1828 $this->load_cache_types_fees();
1832 $out .= '<select
id=
"select_' . $htmlname . '" class=
"flat'.($morecss ? ' '.$morecss : '').'" name=
"' . $htmlname . '">
';
1834 $out .= '<option value=
"-1"';
1835 if ($selected === -1) {
1836 $out .= ' selected
';
1839 if (!is_numeric($showempty)) {
1840 $out .= $langs->trans($showempty);
1842 $out .= '</option>
';
1845 foreach ($this->cache_types_fees as $key => $value) {
1846 $out .= '<option value=
"' . $key . '"';
1847 if ($key == (string) $selected) {
1848 $out .= ' selected
';
1852 $out .= '</option>
';
1855 $out .= '</select>
';
1856 if ($user->admin && empty($noadmin)) {
1857 $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1860 $out .= ajax_combobox('select_
'.$htmlname);
1862 if (empty($nooutput)) {
1871 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1895 public function select_company($selected = '
', $htmlname = 'socid
', $filter = '', $showempty = '', $showtype = 0, $forcecombo = 0, $events = array(), $limit = 0, $morecss = 'minwidth100
', $moreparam = '', $selected_input_value = '', $hidelabel = 1, $ajaxoptions = array(), $multiple = false, $excludeids = array(), $showcode = 0)
1898 global $conf, $langs;
1902 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('COMPANY_USE_SEARCH_TO_SELECT
') && !$forcecombo) {
1903 if (is_null($ajaxoptions)) {
1904 $ajaxoptions = array();
1907 require_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
1909 // No immediate load of all database
1911 if ($selected && empty($selected_input_value)) {
1912 require_once DOL_DOCUMENT_ROOT . '/societe/
class/societe.class.php
';
1913 $societetmp = new Societe($this->db);
1914 $societetmp->fetch($selected);
1915 $selected_input_value = $societetmp->name;
1920 $urloption = 'htmlname=
' . urlencode((string) (str_replace('.
', '_
', $htmlname))) . '&outjson=1&filter=
' . urlencode((string) ($filter)) . (empty($excludeids) ? '' : '&excludeids=
' . implode(',
', $excludeids)) . ($showtype ? '&showtype=
' . urlencode((string) ($showtype)) : '') . ($showcode ? '&showcode=
' . urlencode((string) ($showcode)) : '') . ($limit ? '&limit=
'.$limit : '');
1922 $out .= '<!-- force css to be higher than dialog popup --><style
type=
"text/css">.ui-autocomplete { z-index: 1010; }</style>
';
1923 if (empty($hidelabel)) {
1924 $out .= $langs->trans("RefOrLabel") . ' :
';
1925 } elseif ($hidelabel == 1 && !is_numeric($showempty)) {
1926 $placeholder = $langs->trans($showempty);
1927 } elseif ($hidelabel > 1) {
1928 $placeholder = $langs->trans("RefOrLabel");
1929 if ($hidelabel == 2) {
1930 $out .= img_picto($langs->trans("Search"), 'search
');
1933 $out .= '<input
type=
"text" class=
"' . $morecss . '" name=
"search_' . $htmlname . '" id=
"search_' . $htmlname . '" value=
"' . $selected_input_value . '"' . ($placeholder ? ' placeholder=
"' . dol_escape_htmltag($placeholder) . '"' : '') . ' ' . (getDolGlobalString('THIRDPARTY_SEARCH_AUTOFOCUS
') ? 'autofocus
' : '') . ' spellcheck=
"false" />
';
1934 if ($hidelabel == 3) {
1935 $out .= img_picto($langs->trans("Search"), 'search
');
1938 $out .= ajax_event($htmlname, $events);
1940 // Label of the greyed line shown when the search returns nothing
1941 if (!isset($ajaxoptions['noresultlabel
'])) {
1942 $langs->load("companies");
1943 $ajaxoptions['noresultlabel
'] = dol_escape_htmltag($langs->transnoentitiesnoconv("NoThirdPartyFound"));
1946 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/societe/ajax/company.php
', $urloption, getDolGlobalInt('COMPANY_USE_SEARCH_TO_SELECT
'), 0, $ajaxoptions);
1948 // Immediate load of all database
1949 $out .= $this->select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, '', 0, $limit, $morecss, $moreparam, $multiple, $excludeids, $showcode);
1956 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1984 public function select_contact($socid, $selected = '
', $htmlname = 'contactid
', $showempty = 0, $exclude = '', $limitto = '', $showfunction = 0, $morecss = '', $nokeyifsocid = true, $showsoc = 0, $forcecombo = 0, $events = array(), $moreparam = '', $htmlid = '', $selected_input_value = '', $filter = '', $multiple = false)
1988 global $conf, $langs;
1992 if (empty($htmlid)) {
1993 $htmlid = $htmlname;
1996 $sav = getDolGlobalString('CONTACT_USE_SEARCH_TO_SELECT
');
1997 if ($nokeyifsocid && $socid > 0) {
1998 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = 0;
2001 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('CONTACT_USE_SEARCH_TO_SELECT
') && !$forcecombo) {
2002 require_once DOL_DOCUMENT_ROOT . '/contact/
class/contact.class.php
';
2003 require_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
2005 // select2 combo pre-filled with only the currently selected contact(s) as <option selected>.
2006 // select2 keeps those and fetches the rest on demand from contact/ajax/contact.php instead of
2007 // loading the whole contact list into the page.
2008 $selectedids = array();
2009 foreach (($multiple ? (is_array($selected) ? $selected : array()) : ($selected !== '' && $selected !== 0 ? array($selected) : array())) as $tmpid) {
2010 if (is_numeric($tmpid) && (int) $tmpid > 0) {
2011 $selectedids[] = (int) $tmpid;
2015 // A non-numeric $showempty ('
', a label, ...) is used as a select2 placeholder instead of
2016 // an <option> value; select2 needs an empty first <option> in single mode to be able to show it.
2017 $placeholder = is_numeric($showempty) ? '' : (string) $showempty;
2019 $out .= '<select
class=
"flat' . ($morecss ? ' ' . $morecss : '') . '" id=
"' . $htmlid . '" name=
"' . $htmlname . ($multiple ? '[]' : '') . '"' . ($multiple ? ' multiple
' : '') . ($moreparam ? ' ' . $moreparam : '') . '>
';
2021 $out .= '<option></option>
';
2023 if (count($selectedids)) {
2024 $contacttmp = new Contact($this->db);
2025 foreach ($selectedids as $tmpid) {
2026 if ($contacttmp->fetch($tmpid) > 0) {
2027 $out .= '<option value=
"' . $tmpid . '" selected>
' . dol_escape_htmltag($contacttmp->getFullName($langs)) . '</option>
';
2032 $out .= '</select>
';
2034 $out .= ajax_event($htmlname, $events);
2036 // Same as the value of 'htmlname=
' below: the endpoint reads the typed term from a GET param
2037 // named after this transformed htmlname (see contact/ajax/contact.php).
2038 $htmlnamefortermparam = str_replace('.
', '_
', $htmlname);
2039 $urloption = 'htmlname=
' . urlencode((string) $htmlnamefortermparam) . '&outjson=1&filter=
' . urlencode((string) $filter)
2040 . (empty($exclude) ? '' : '&exclude=
' . urlencode($exclude))
2041 . ($showsoc ? '&showsoc=
' . urlencode((string) $showsoc) : '')
2042 . ($socid > 0 ? '&socid=
' . ((int) $socid) : '');
2044 // A non-numeric value ('infinite
') means "infinite list": no minimum number of chars, the list
2045 // opens as soon as the field gets the focus (select2 queries the endpoint with an empty term).
2046 $minlengthforajax = getDolGlobalInt('CONTACT_USE_SEARCH_TO_SELECT
');
2047 if ($minlengthforajax < 1) {
2048 $minlengthforajax = 0;
2050 // Page size of the ajax endpoint (CONTACT_LIMIT_SIZE): select2 keeps asking for the next page
2051 // while the endpoint returns a full page, so the whole list stays browsable by scrolling.
2052 $ajaxpagesize = getDolGlobalInt('CONTACT_LIMIT_SIZE
', 20);
2054 $htmlidjs = str_replace('.
', '\\\\.
', $htmlid);
2055 $out .= '<script nonce=
"' . getNonce() . '">jQuery(
function() {
2056 jQuery(
"#' . $htmlidjs . '").select2({
2058 language: (typeof select2arrayoflanguage ===
"undefined") ?
"en" : select2arrayoflanguage,
2059 containerCssClass:
":all:",
2060 placeholder:
' . json_encode($placeholder) . ',
2061 minimumInputLength:
' . ((int) $minlengthforajax) . ',
2063 url:
"' . DOL_URL_ROOT . '/contact/ajax/contact.php?' . $urloption . '",
2066 data:
function(params) {
2068 d[
' . json_encode($htmlnamefortermparam) . '] = params.term;
2069 d.page = params.page || 1;
2072 processResults:
function(data) {
2074 jQuery.each(data,
function(i, val) {
2075 result.push({ id: val.key, text: val.value });
2077 return { results: result, pagination: { more: data.length >=
' . ((int) $ajaxpagesize) . ' } };
2081 });
' . (getDolGlobalString('CONTACT_SEARCH_AUTOFOCUS
') ? '
2082 jQuery(
"#' . $htmlidjs . '").select2(
"open");
' : '') . '
2084 $out .= '<!-- force css to be higher than dialog popup --><style
type=
"text/css">.select2-container { z-index: 1010; }</style>
';
2086 // Immediate load of all database
2087 $disableifempty = 0;
2091 $out .= $this->selectcontacts($socid, $selected, $htmlname, $showempty, $exclude, $limitto, $showfunction, $morecss, $options_only, $showsoc, $forcecombo, $events, $moreparam, $htmlid, $multiple, $disableifempty, $filter);
2094 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = $sav;
2100 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2125 public function select_thirdparty_list($selected = '
', $htmlname = 'socid
', $filter = '', $showempty = '', $showtype = 0, $forcecombo = 0, $events = array(), $filterkey = '', $outputmode = 0, $limit = 0, $morecss = 'minwidth100
', $moreparam = '', $multiple = false, $excludeids = array(), $showcode = 0)
2128 global $user, $langs;
2129 global $hookmanager;
2131 $langs->loadLangs(array("companies", "suppliers"));
2135 $outarray = array();
2137 if ($selected === '') {
2138 $selected = array();
2139 } elseif (!is_array($selected)) {
2140 $selected = array($selected);
2143 // Clean $filter that may contains sql conditions so sql code
2145 if (testSqlAndScriptInject($filter, 3) > 0) {
2147 return 'SQLInjectionTryDetected
';
2151 if ($filter != '') { // If a filter was provided
2153 $filter = forgeSQLFromUniversalSearchCriteria($filter, $errormsg, 1);
2155 // Redo clean $filter that may contains sql conditions so sql code
2157 if (testSqlAndScriptInject($filter, 3) > 0) {
2159 return 'SQLInjectionTryDetected
';
2164 // We search companies
2165 $sql = "SELECT s.rowid, s.nom as name, s.name_alias, s.tva_intra, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
2166 if (getDolGlobalString('COMPANY_SHOW_ADDRESS_SELECTLIST
')) {
2167 $sql .= ", s.address, s.zip, s.town";
2168 $sql .= ", dictp.code as country_code";
2170 $sql .= " FROM " . $this->db->prefix() . "societe as s";
2171 if (getDolGlobalString('COMPANY_SHOW_ADDRESS_SELECTLIST
')) {
2172 $sql .= " LEFT JOIN " . $this->db->prefix() . "c_country as dictp ON dictp.rowid = s.fk_pays";
2174 if (!$user->hasRight('societe
', 'client
', 'voir
')) {
2175 $sql .= ", " . $this->db->prefix() . "societe_commerciaux as sc";
2177 $sql .= " WHERE s.entity IN (" . getEntity('societe
') . ")";
2178 if (!empty($user->socid)) {
2179 $sql .= " AND s.rowid = " . ((int) $user->socid);
2182 // $filter is safe because, it has been tested by testSqlAndScriptInject() and sanitized by forgeSQLFromUniversalSearchCriteria()
2183 $sqlwhere = $filter; // @phan-suppress-current-line SqlInjection
2184 $sql .= " AND (" . $sqlwhere . ")";
2186 if (!$user->hasRight('societe
', 'client
', 'voir
')) {
2187 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . ((int) $user->id);
2189 if (getDolGlobalString('COMPANY_HIDE_INACTIVE_IN_COMBOBOX
')) {
2190 $sql .= " AND s.status <> 0";
2192 if (!empty($excludeids)) {
2193 $sql .= " AND s.rowid NOT IN (" . $this->db->sanitize(implode(',
', $excludeids)) . ")";
2195 // Add where from hooks
2196 $parameters = array();
2197 $reshook = $hookmanager->executeHooks('selectThirdpartyListWhere
', $parameters); // Note that $action and $object may have been modified by hook
2198 $sql .= $hookmanager->resPrint;
2200 if ($filterkey && $filterkey != '') {
2202 $prefix = !getDolGlobalString('COMPANY_DONOTSEARCH_ANYWHERE
') ? '%
' : ''; // Can use index if COMPANY_DONOTSEARCH_ANYWHERE is on
2203 // For natural search
2204 $search_crit = explode(' ', $filterkey);
2206 if (count($search_crit) > 1) {
2209 foreach ($search_crit as $crit) {
2213 $sql .= "(s.nom LIKE '" . $this->db->escape($prefix . $crit) . "%
')";
2216 if (count($search_crit) > 1) {
2219 if (isModEnabled('barcode
')) {
2220 $sql .= " OR s.barcode LIKE '" . $this->db->escape($prefix . $filterkey) . "%
'";
2222 $sql .= " OR s.code_client LIKE '" . $this->db->escape($prefix . $filterkey) . "%
' OR s.code_fournisseur LIKE '" . $this->db->escape($prefix . $filterkey) . "%
'";
2223 $sql .= " OR s.name_alias LIKE '" . $this->db->escape($prefix . $filterkey) . "%
' OR s.tva_intra LIKE '" . $this->db->escape($prefix . $filterkey) . "%
'";
2226 $sql .= $this->db->order("nom", "ASC");
2227 $sql .= $this->db->plimit($limit, 0);
2229 // Build output string
2230 dol_syslog(get_class($this)."::select_thirdparty_list", LOG_DEBUG);
2231 $resql = $this->db->query($sql);
2233 // Construct $out and $outarray
2234 $out .= '<select
id=
"' . $htmlname . '" class=
"flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($moreparam ? ' ' . $moreparam : '') . ' name=
"' . $htmlname . ($multiple ? '[]' : '') . '"' . ($multiple ? ' multiple
' : '') . '>
' . "\n";
2236 $textifempty = (($showempty && !is_numeric($showempty)) ? $langs->trans($showempty) : '');
2237 if (getDolGlobalString('COMPANY_USE_SEARCH_TO_SELECT
')) {
2238 // Do not use textifempty = ' ' or '
' here, or search on key will search on ' key
'.
2239 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
2240 if ($showempty && !is_numeric($showempty)) {
2241 $textifempty = $langs->trans($showempty);
2243 $textifempty .= $langs->trans("All");
2247 $out .= '<option value=
"-1" data-html=
"' . dol_escape_htmltag('<span class="opacitymedium
">' . ($textifempty ? $textifempty : ' ') . '</span>') . '">
' . $textifempty . '</option>
' . "\n";
2250 $companytemp = new Societe($this->db);
2252 $num = $this->db->num_rows($resql);
2256 $obj = $this->db->fetch_object($resql);
2258 if ($showcode || getDolGlobalString('SOCIETE_ADD_REF_IN_LIST
')) {
2259 if (($obj->client) && (!empty($obj->code_client)) && $showcode != 'supplier
') {
2260 $label = $obj->code_client . ' -
';
2262 if (($obj->fournisseur) && (!empty($obj->code_fournisseur)) && $showcode != 'customer
') {
2263 $label .= $obj->code_fournisseur . ' -
';
2265 $label .= ' ' . $obj->name;
2267 $label = $obj->name;
2270 if (!empty($obj->name_alias)) {
2271 $label .= ' (
' . $obj->name_alias . ')
';
2274 if (getDolGlobalString('SOCIETE_SHOW_VAT_IN_LIST
') && !empty($obj->tva_intra)) {
2275 $label .= ' -
'.$obj->tva_intra;
2278 $labelhtml = $label;
2281 $companytemp->id = $obj->rowid;
2282 $companytemp->client = $obj->client;
2283 $companytemp->fournisseur = $obj->fournisseur;
2284 $tmptype = $companytemp->getTypeUrl(1, '', 0, 'span
');
2286 $labelhtml .= ' ' . $tmptype;
2289 if ($obj->client || $obj->fournisseur) {
2292 if ($obj->client == 1 || $obj->client == 3) {
2293 $label .= $langs->trans("Customer");
2295 if ($obj->client == 2 || $obj->client == 3) {
2296 $label .= ($obj->client == 3 ? ',
' : '') . $langs->trans("Prospect");
2298 if ($obj->fournisseur) {
2299 $label .= ($obj->client ? ',
' : '') . $langs->trans("Supplier");
2301 if ($obj->client || $obj->fournisseur) {
2306 if (getDolGlobalString('COMPANY_SHOW_ADDRESS_SELECTLIST
')) {
2307 $s = ($obj->address ? ' -
' . $obj->address : '') . ($obj->zip ? ' -
' . $obj->zip : '') . ($obj->town ? ' ' . $obj->town : '');
2308 if (!empty($obj->country_code)) {
2309 $s .= ',
' . $langs->trans('Country
' . $obj->country_code);
2315 if (empty($outputmode)) {
2316 if (in_array($obj->rowid, $selected)) {
2317 $out .= '<option value=
"' . $obj->rowid . '" selected data-html=
"' . dol_escape_htmltag($labelhtml, 0, 0, '', 0, 1) . '">
' . dol_escape_htmltag($label, 0, 0, '', 0, 1) . '</option>
';
2319 $out .= '<option value=
"' . $obj->rowid . '" data-html=
"' . dol_escape_htmltag($labelhtml, 0, 0, '', 0, 1) . '">
' . dol_escape_htmltag($label, 0, 0, '', 0, 1) . '</option>
';
2322 array_push($outarray, array('key
' => $obj->rowid, 'value
' => $label, 'label
' => $label, 'labelhtml
' => $labelhtml));
2326 if (($i % 10) == 0) {
2331 $out .= '</select>
' . "\n";
2333 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
2334 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt("COMPANY_USE_SEARCH_TO_SELECT"));
2337 dol_print_error($this->db);
2340 $this->result = array('nbofthirdparties
' => $num);
2376 public function selectcontacts($socid, $selected = array(), $htmlname = 'contactid
', $showempty = 0, $exclude = '', $limitto = '', $showfunction = 0, $morecss = '', $options_only = 0, $showsoc = 0, $forcecombo = 0, $events = array(), $moreparam = '', $htmlid = '', $multiple = false, $disableifempty = 0, $filter = '', $limit = 0, $limitoffset = 0)
2378 global $conf, $user, $langs, $hookmanager, $action;
2380 $langs->load('companies
');
2382 if (empty($htmlid)) {
2383 $htmlid = $htmlname;
2387 $outarray = array();
2389 if ($selected === '') {
2390 $selected = array();
2391 } elseif (!is_array($selected)) {
2392 $selected = array((int) $selected);
2395 // Clean $filter that may contains sql conditions so sql code
2397 if (testSqlAndScriptInject($filter, 3) > 0) {
2399 return 'SQLInjectionTryDetected
';
2403 if ($filter != '') { // If a filter was provided
2404 if (preg_match('/[\(\)]/
', $filter)) {
2405 // If there is one parenthesis inside the criteria, we assume it is an Universal Filter Syntax.
2407 $filter = forgeSQLFromUniversalSearchCriteria($filter, $errormsg, 1);
2409 // Redo clean $filter that may contains sql conditions so sql code
2411 if (testSqlAndScriptInject($filter, 3) > 0) {
2413 return 'SQLInjectionTryDetected
';
2417 // If not, we do nothing. We already know that there is no parenthesis
2418 // TODO Disallow this case in a future by returning an error here.
2419 dol_syslog("Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Filter Syntax.", LOG_WARNING);
2423 if (!is_object($hookmanager)) {
2424 include_once DOL_DOCUMENT_ROOT . '/core/
class/hookmanager.class.php
';
2425 $hookmanager = new HookManager($this->db);
2428 // We search third parties
2429 $sql = "SELECT sp.rowid, sp.lastname, sp.statut, sp.firstname, sp.poste, sp.email, sp.phone, sp.phone_perso, sp.phone_mobile, sp.town AS contact_town";
2430 if ($showsoc > 0 || getDolGlobalString('CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST
')) {
2431 $sql .= ", s.nom as company, s.town AS company_town";
2433 $sql .= " FROM " . $this->db->prefix() . "socpeople as sp";
2434 if ($showsoc > 0 || getDolGlobalString('CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST
')) {
2435 $sql .= " LEFT JOIN " . $this->db->prefix() . "societe as s ON s.rowid = sp.fk_soc";
2437 $sql .= " WHERE sp.entity IN (" . getEntity('contact
') . ")";
2438 $sql .= " AND ((sp.fk_user_creat = ".((int) $user->id)." AND sp.priv = 1) OR sp.priv = 0)"; // check if this is a private contact
2439 if ($socid > 0 || $socid == -1) {
2440 $sql .= " AND sp.fk_soc = " . ((int) $socid);
2442 if (getDolGlobalString('CONTACT_HIDE_INACTIVE_IN_COMBOBOX
')) {
2443 $sql .= " AND sp.statut <> 0";
2445 // filter user access
2446 if (!$user->hasRight('societe
', 'client
', 'voir
') && !$user->socid) {
2447 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = sp.fk_soc AND sc.fk_user = ".(int) $user->id .")";
2449 if ($user->socid > 0) {
2450 $sql .= " AND sp.fk_soc = ".((int) $user->socid);
2453 // $filter is safe because, if it contains '(
' or ')
', it has been sanitized by testSqlAndScriptInject() and forgeSQLFromUniversalSearchCriteria()
2454 // if not, by testSqlAndScriptInject() only.
2455 $sanitizedfilter = $filter; // @phan-suppress-current-line SqlInjection
2456 $sql .= " AND (" . $sanitizedfilter . ")";
2458 // Add where from hooks
2459 $parameters = array();
2460 $reshook = $hookmanager->executeHooks('selectContactListWhere
', $parameters); // Note that $action and $object may have been modified by hook
2461 $sql .= $hookmanager->resPrint;
2462 $sql .= " ORDER BY sp.lastname ASC";
2463 $sql .= $this->db->plimit($limit, ((int) $limitoffset > 0 ? (int) $limitoffset : 0));
2465 dol_syslog(get_class($this) . "::selectcontacts", LOG_DEBUG);
2466 $resql = $this->db->query($sql);
2468 $num = $this->db->num_rows($resql);
2470 if ($htmlname != 'none
' && !$options_only) {
2471 $out .= '<select
class=
"flat' . ($morecss ? ' ' . $morecss : '') . '" id=
"' . $htmlid . '" name=
"' . $htmlname . ($multiple ? '[]' : '') . '" ' . (($num || empty($disableifempty)) ? '' : ' disabled') . ($multiple ? 'multiple
' : '') . ' ' . (!empty($moreparam) ? $moreparam : '') . '>
';
2474 if ($showempty && !is_numeric($showempty)) {
2475 $textforempty = $showempty;
2476 $out .= '<option
class=
"optiongrey" value=
"-1"' . (in_array(-1, $selected) ? ' selected
' : '') . '>
' . dol_escape_htmltag($textforempty) . '</option>
';
2478 if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) {
2479 $out .= '<option value=
"0"' . (in_array(0, $selected) ? ' selected
' : '') . '> </option>
';
2481 if ($showempty == 2) {
2482 $out .= '<option value=
"0"' . (in_array(0, $selected) ? ' selected
' : '') . '>--
' . $langs->trans("Internal") . ' --</option>
';
2488 include_once DOL_DOCUMENT_ROOT . '/contact/
class/contact.class.php
';
2489 $contactstatic = new Contact($this->db);
2492 $obj = $this->db->fetch_object($resql);
2494 // Set email (or phones) and town extended infos
2495 $extendedInfos = '';
2496 if (getDolGlobalString('CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST
')) {
2497 $extendedInfos = array();
2498 $email = trim($obj->email);
2499 if (!empty($email)) {
2500 $extendedInfos[] = $email;
2502 $phone = trim($obj->phone);
2503 $phone_perso = trim($obj->phone_perso);
2504 $phone_mobile = trim($obj->phone_mobile);
2505 if (!empty($phone)) {
2506 $extendedInfos[] = $phone;
2508 if (!empty($phone_perso)) {
2509 $extendedInfos[] = $phone_perso;
2511 if (!empty($phone_mobile)) {
2512 $extendedInfos[] = $phone_mobile;
2515 $contact_town = trim($obj->contact_town);
2516 $company_town = trim($obj->company_town);
2517 if (!empty($contact_town)) {
2518 $extendedInfos[] = $contact_town;
2519 } elseif (!empty($company_town)) {
2520 $extendedInfos[] = $company_town;
2522 $extendedInfos = implode(' -
', $extendedInfos);
2523 if (!empty($extendedInfos)) {
2524 $extendedInfos = ' -
' . $extendedInfos;
2528 $contactstatic->id = $obj->rowid;
2529 $contactstatic->lastname = $obj->lastname;
2530 $contactstatic->firstname = $obj->firstname;
2531 if ($obj->statut == 1) {
2533 if ($htmlname != 'none
') {
2535 if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) {
2538 if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) {
2541 if (!empty($selected) && in_array($obj->rowid, $selected)) {
2542 $out .= '<option value=
"' . $obj->rowid . '"';
2546 $out .= ' selected>
';
2548 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
2549 if ($showfunction && $obj->poste) {
2550 $tmplabel .= ' (
' . $obj->poste . ')
';
2552 if (($showsoc > 0) && $obj->company) {
2553 $tmplabel .= ' - (
' . $obj->company . ')
';
2557 $out .= '</option>
';
2559 $out .= '<option value=
"' . $obj->rowid . '"';
2565 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
2566 if ($showfunction && $obj->poste) {
2567 $tmplabel .= ' (
' . $obj->poste . ')
';
2569 if (($showsoc > 0) && $obj->company) {
2570 $tmplabel .= ' - (
' . $obj->company . ')
';
2574 $out .= '</option>
';
2577 if (in_array($obj->rowid, $selected)) {
2578 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
2579 if ($showfunction && $obj->poste) {
2580 $tmplabel .= ' (
' . $obj->poste . ')
';
2582 if (($showsoc > 0) && $obj->company) {
2583 $tmplabel .= ' - (
' . $obj->company . ')
';
2590 if ($tmplabel != '') {
2591 array_push($outarray, array('key
' => $obj->rowid, 'value
' => $tmplabel, 'label
' => $tmplabel, 'labelhtml
' => $tmplabel));
2597 $labeltoshow = ($socid != -1) ? ($langs->trans($socid ? "NoContactDefinedForThirdParty" : "NoContactDefined")) : $langs->trans('SelectAThirdPartyFirst
');
2598 $out .= '<option
class=
"disabled" value=
"-1"' . (($showempty == 2 || $multiple) ? '' : ' selected
') . ' disabled=
"disabled">
';
2599 $out .= $labeltoshow;
2600 $out .= '</option>
';
2603 $parameters = array(
2605 'htmlname
' => $htmlname,
2608 'showfunction
' => $showfunction,
2609 'showsoc
' => $showsoc,
2612 $reshook = $hookmanager->executeHooks('afterSelectContactOptions
', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
2614 if ($htmlname != 'none
' && !$options_only) {
2615 $out .= '</select>
';
2618 if ($conf->use_javascript_ajax && !$forcecombo && !$options_only) {
2619 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
2620 $out .= ajax_combobox($htmlid, $events, getDolGlobalInt("CONTACT_USE_SEARCH_TO_SELECT"));
2625 if ($options_only === 2) {
2626 // Return array of options
2632 dol_print_error($this->db);
2638 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2650 public function select_remises($selected, $htmlname, $filter, $socid, $maxvalue = 0)
2653 global $langs, $conf;
2655 $showsourceinvoice = getDolGlobalString('MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST
');
2657 // Search for the discounts
2658 $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
2659 $sql .= " re.description, re.fk_facture_source, re.fk_invoice_supplier_source";
2660 if ($showsourceinvoice) {
2661 // Resolve the source invoice (customer or supplier) in the main query instead of one fetch per line
2662 $sql .= ", f.ref as src_cust_ref, f.datef as src_cust_date";
2663 $sql .= ", ff.ref as src_supp_ref, ff.datef as src_supp_date";
2665 $sql .= " FROM " . $this->db->prefix() . "societe_remise_except as re";
2666 if ($showsourceinvoice) {
2667 $sql .= " LEFT JOIN " . $this->db->prefix() . "facture as f ON f.rowid = re.fk_facture_source";
2668 $sql .= " LEFT JOIN " . $this->db->prefix() . "facture_fourn as ff ON ff.rowid = re.fk_invoice_supplier_source";
2670 $sql .= " WHERE re.fk_soc = " . (int) $socid;
2671 $sql .= " AND re.entity = " . ((int) $conf->entity);
2673 $sanitizedfilter = $filter; // @phan-suppress-current-line SqlInjection
2674 if ($showsourceinvoice) {
2675 // The joined tables also carry a fk_facture_source column: qualify unprefixed references of the caller filter
2676 $sanitizedfilter = preg_replace('/(?<![a-zA-Z0-9_.])fk_facture_source\b/
', 're.fk_facture_source
', $sanitizedfilter);
2678 $sql .= " AND " . $sanitizedfilter;
2680 if ($showsourceinvoice) {
2681 // When the source invoices are shown, their date is the natural order (oldest deposit first)
2682 $sql .= " ORDER BY COALESCE(ff.datef, f.datef, re.datec) ASC, re.rowid ASC";
2684 $sql .= " ORDER BY re.description ASC";
2687 dol_syslog(get_class($this) . "::select_remises", LOG_DEBUG);
2688 $resql = $this->db->query($sql);
2690 print '<select
id=
"select_' . $htmlname . '" class=
"flat maxwidth300 maxwidth200onsmartphone" name=
"' . $htmlname . '">
';
2691 $num = $this->db->num_rows($resql);
2693 $qualifiedlines = $num;
2697 print '<option value=
"0"> </option>
';
2699 $obj = $this->db->fetch_object($resql);
2700 $desc = dol_trunc($obj->description, 40);
2701 if (preg_match('/\(CREDIT_NOTE\)/
', $desc)) {
2702 $desc = preg_replace('/\(CREDIT_NOTE\)/
', $langs->trans("CreditNote"), $desc);
2704 if (preg_match('/\(DEPOSIT\)/
', $desc)) {
2705 $desc = preg_replace('/\(DEPOSIT\)/
', $langs->trans("Deposit"), $desc);
2707 if (preg_match('/\(EXCESS RECEIVED\)/
', $desc)) {
2708 $desc = preg_replace('/\(EXCESS RECEIVED\)/
', $langs->trans("ExcessReceived"), $desc);
2710 if (preg_match('/\(EXCESS PAID\)/
', $desc)) {
2711 $desc = preg_replace('/\(EXCESS PAID\)/
', $langs->trans("ExcessPaid"), $desc);
2715 if ($selected > 0 && $selected == $obj->rowid) {
2716 $selectstring = ' selected
';
2720 if ($maxvalue > 0 && $obj->amount_ttc > $maxvalue) {
2725 if ($showsourceinvoice) {
2726 $srcref = !empty($obj->src_supp_ref) ? $obj->src_supp_ref : (!empty($obj->src_cust_ref) ? $obj->src_cust_ref : '');
2727 $srcdate = !empty($obj->src_supp_date) ? $obj->src_supp_date : (!empty($obj->src_cust_date) ? $obj->src_cust_date : '');
2729 $desc = $desc . ' -
' . $srcref;
2731 $desc .= ' (
' . dol_print_date($this->db->jdate($srcdate), 'day
') . ')
';
2736 print '<option value=
"' . $obj->rowid . '"' . $selectstring . $disabled . '>
' . $desc . ' (
' . price($obj->amount_ht) . ' ' . $langs->trans("HT") . ' -
' . price($obj->amount_ttc) . ' ' . $langs->trans("TTC") . ')</option>
';
2741 print ajax_combobox('select_
' . $htmlname);
2743 return $qualifiedlines;
2745 dol_print_error($this->db);
2751 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2768 public function select_users($selected = '
', $htmlname = 'userid
', $show_empty = 0, $exclude = null, $disabled = 0, $include = '', $enableonly = array(), $force_entity = '0
')
2771 print $this->select_dolusers($selected, $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity);
2785 public static $user_combo_allowed_morefilters = array(
2786 'u.statut:=:1
', // active users only
2787 '(statut:=:1)
', // active users only
2788 'employee:=:1
', // employees only
2789 '(employee:=:1)
', // employees only
2790 '(admin:=:1) AND (statut:=:1)
', // active administrators only
2800 public static function isUserComboMorefilterAllowed($morefilter)
2802 return in_array(trim((string) $morefilter), self::$user_combo_allowed_morefilters, true);
2820 private function buildSelectDolusersAjaxUrlOption($htmlname, $exclude, $include, $force_entity, $showstatus, $notdisabled, $maxlength, $morefilter = '
')
2822 $urloption = 'htmlname=
'.urlencode($htmlname).'&outjson=1
';
2823 if (is_array($exclude) && count($exclude)) {
2824 $urloption .= '&exclude=
'.urlencode(implode(',
', $exclude));
2826 if (is_array($include) && count($include)) {
2827 $urloption .= '&include=
'.urlencode(implode(',
', $include));
2828 } elseif (is_string($include) && $include !== '') {
2829 $urloption .= '&include=
'.urlencode($include);
2831 if ($force_entity !== '') {
2832 $urloption .= '&force_entity=
'.urlencode((string) $force_entity);
2834 if ($showstatus !== 0) {
2835 $urloption .= '&showstatus=
'.((int) $showstatus);
2837 if (!empty($notdisabled)) {
2838 $urloption .= '¬disabled=1
';
2840 if (!empty($maxlength)) {
2841 $urloption .= '&maxlength=
'.((int) $maxlength);
2843 // $morefilter is a raw Universal Search Filter fed to forgeSQLFromUniversalSearchCriteria().
2844 // Only forward it when it is one of the known-safe expressions of self::$user_combo_allowed_morefilters
2845 // (the endpoint re-checks against the same list); any other value would let a client run arbitrary
2846 // WHERE clauses on llx_user and is dropped here - the ajax list is then simply not narrowed by it.
2847 if ((string) $morefilter !== '') {
2848 if (self::isUserComboMorefilterAllowed($morefilter)) {
2849 $urloption .= '&morefilter=
'.urlencode(trim((string) $morefilter));
2851 dol_syslog(__METHOD__.": morefilter '".$morefilter."' is not in Form::\$user_combo_allowed_morefilters; the search-to-select user list will not be narrowed by it", LOG_WARNING);
2868 private function buildSelectDolusersAjaxSelect2Script($htmlname, $urloption, $minlengthforajax, $ajaxpagesize)
2870 $htmlnamejs = str_replace('.
', '\\\\.
', $htmlname);
2871 return '<script nonce=
"'.getNonce().'">jQuery(function() {
2872 jQuery(
"#'.$htmlnamejs.'").select2({
2874 language: (typeof select2arrayoflanguage ===
"undefined") ?
"en" : select2arrayoflanguage,
2875 containerCssClass:
":all:",
2877 minimumInputLength:
'.((int) $minlengthforajax).',
2879 url:
"'.DOL_URL_ROOT.'/user/ajax/users.php?'.$urloption.'",
2882 data:
function(params) {
2884 d[
'.json_encode($htmlname).'] = params.term;
2885 d.page = params.page || 1;
2888 processResults:
function(data) {
2890 jQuery.each(data,
function(i, val) {
2891 result.push({ id: val.key, text: val.value });
2893 return { results: result, pagination: { more: data.length >=
'.((int) $ajaxpagesize).' } };
2901 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2930 public function select_dolusers($userselected = '
', $htmlname = 'userid
', $show_empty = 0, $exclude = null, $disabled = 0, $include = '', $enableonly = '', $force_entity = '', $maxlength = 0, $showstatus = 0, $morefilter = '', $showalso = 0, $enableonlytext = '', $morecss = '', $notdisabled = 0, $outputmode = 0, $multiple = false, $forcecombo = 0, $filterkey = '', $limit = 0, $limitoffset = 0)
2933 global $conf, $user, $langs, $hookmanager;
2936 // Convert $selected into an int (in case it is an object)
2937 if (is_object($userselected)) {
2938 $selected = (int) $userselected->id;
2939 } elseif (is_numeric($userselected)) {
2940 $selected = (int) $userselected;
2941 } elseif (is_array($userselected)) {
2942 $selected = $userselected;
2947 // If no preselected user defined, we take current user
2948 if ((is_numeric($selected) && ((int) $selected < -4 || empty($selected))) && !getDolGlobalString('SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE
')) {
2949 $selected = $user->id;
2952 // Convert selected int into an array
2953 if (!is_array($selected)) {
2954 if ($selected === -1 || $selected === '') {
2955 $selected = array();
2957 $selected = array($selected);
2961 // Exclude some users in $excludeUsers string
2962 $excludeUsers = null;
2963 if (is_array($exclude)) {
2964 $excludeUsers = implode(",", $exclude);
2967 // Include some users in $includeUsers string
2968 $includeUsers = null;
2969 $includeUsersArray = array();
2970 if (is_array($include)) {
2971 $includeUsersArray = $include;
2972 } elseif ($include == 'hierarchy
') {
2973 // Build list includeUsersArray to have only hierarchy
2974 $includeUsersArray = $user->getAllChildIds(0);
2975 } elseif ($include == 'hierarchyme
') {
2976 // Build list includeUsersArray to have only hierarchy and current user
2977 $includeUsersArray = $user->getAllChildIds(1);
2979 // Get list of allowed users
2980 /* We do not limit list of users. Because we should limit this only for combo list into HR features where we may be allowed to
2981 * see all other users and element in other. For example in agenda, we can have permission to read all event of otherusers.
2982 * So we disable this.
2983 if (!$user->hasRight('user', 'user', 'lire
')) {
2984 if (empty($includeUsersArray)) {
2985 $includeUsers = implode(",", $user->getAllChildIds(1));
2987 $includeUsers = implode(",", array_intersect($includeUsersArray, $user->getAllChildIds(1)));
2990 $includeUsers = implode(",", $includeUsersArray);
2992 $includeUsers = implode(",", $includeUsersArray);
2997 $outarray = array();
2998 $outarray2 = array();
3000 // If the ajax "search to select" mode is enabled for users (constant USER_USE_SEARCH_TO_SELECT), we output a
3001 // select2 combo calling user/ajax/users.php instead of loading the full list of users. This is limited to
3002 // the HTML output: array output, forced combo, pseudo-entries (showalso) and per-line enabling (enableonly)
3003 // keep the full-list behaviour. Both single and multiple select page through the same endpoint (see
3004 // buildSelectDolusersAjaxSelect2Script()); only the <select> markup (single option vs multiple/[]) differs.
3005 $canajaxsearchtoselect = !empty($conf->use_javascript_ajax) && getDolGlobalString('USER_USE_SEARCH_TO_SELECT
') && !$forcecombo && empty($outputmode)
3006 && empty($showalso) && !(is_array($enableonly) && count($enableonly)) && $filterkey === '';
3008 if ($canajaxsearchtoselect && !$multiple) {
3010 if (!empty($selected)) {
3011 $firstval = reset($selected);
3012 if (is_numeric($firstval) && (int) $firstval > 0) {
3013 $preselected = (int) $firstval;
3017 $preselectedlabel = '';
3018 if ($preselected > 0) {
3019 $usertmpselect = new User($this->db);
3020 if ($usertmpselect->fetch($preselected) > 0) {
3021 $fullNameMode = getDolGlobalString('MAIN_FIRSTNAME_NAME_POSITION
') ? 0 : 1;
3022 $preselectedlabel = $usertmpselect->getFullName($langs, $fullNameMode, -1, $maxlength);
3023 if ($preselectedlabel === '') {
3024 $preselectedlabel = $usertmpselect->login;
3027 unset($usertmpselect);
3030 $out .= '<select
class=
"flat'.($morecss ? ' '.$morecss : ' minwidth200').'" id=
"'.$htmlname.'" name=
"'.$htmlname.'"'.($disabled ? ' disabled' : '').'>
';
3031 if ($preselected > 0) {
3032 $out .= '<option value=
"'.$preselected.'" selected>
'.dol_escape_htmltag($preselectedlabel).'</option>
';
3034 $out .= '</select>
';
3036 // Propagate the filters to the ajax endpoint so it returns the same subset as the full combo would
3037 $urloption = $this->buildSelectDolusersAjaxUrlOption($htmlname, $exclude, $include, $force_entity, $showstatus, $notdisabled, $maxlength, $morefilter);
3039 // A non-numeric value ('infinite
') means "infinite list": no minimum number of chars, the list
3040 // opens as soon as the field gets the focus (select2 queries the endpoint with an empty term).
3041 $minlengthforajax = getDolGlobalInt('USER_USE_SEARCH_TO_SELECT
');
3042 if ($minlengthforajax < 1) {
3043 $minlengthforajax = 0;
3045 // Page size of the ajax endpoint (USER_LIMIT_SIZE): select2 keeps asking for the next page
3046 // while the endpoint returns a full page, so the whole list stays browsable by scrolling.
3047 $ajaxpagesize = getDolGlobalInt('USER_LIMIT_SIZE
', 20);
3049 $out .= $this->buildSelectDolusersAjaxSelect2Script($htmlname, $urloption, $minlengthforajax, $ajaxpagesize);
3050 $out .= '<!-- force css to be higher than dialog popup --><style
type=
"text/css">.select2-container { z-index: 1010; }</style>
';
3055 if ($canajaxsearchtoselect && $multiple) {
3056 // Multiple select + "search to select": render a select2 combo pre-filled with only the currently
3057 // selected users as <option selected>. select2 keeps those and fetches the rest on demand from
3058 // user/ajax/users.php instead of loading the whole llx_user table into the page.
3059 $preselectedids = array();
3060 foreach ($selected as $tmpid) {
3061 if (is_numeric($tmpid) && (int) $tmpid > 0) {
3062 $preselectedids[] = (int) $tmpid;
3066 $fullNameMode = getDolGlobalString('MAIN_FIRSTNAME_NAME_POSITION
') ? 0 : 1;
3067 $out .= '<select
class=
"flat'.($morecss ? ' '.$morecss : ' minwidth200').'" id=
"'.$htmlname.'" name=
"'.$htmlname.'[]" multiple
'.($disabled ? ' disabled' : '').'>
';
3068 if (count($preselectedids)) {
3069 $usertmpselect = new User($this->db);
3070 foreach ($preselectedids as $tmpid) {
3071 if ($usertmpselect->fetch($tmpid) > 0) {
3072 $labeltoshow = $usertmpselect->getFullName($langs, $fullNameMode, -1, $maxlength);
3073 if ($labeltoshow === '') {
3074 $labeltoshow = $usertmpselect->login;
3076 $out .= '<option value=
"'.$tmpid.'" selected>
'.dol_escape_htmltag($labeltoshow).'</option>
';
3079 unset($usertmpselect);
3081 $out .= '</select>
';
3083 $urloption = $this->buildSelectDolusersAjaxUrlOption($htmlname, $exclude, $include, $force_entity, $showstatus, $notdisabled, $maxlength, $morefilter);
3085 // A non-numeric value ('infinite
') means "infinite list": no minimum number of chars, the list
3086 // opens as soon as the field gets the focus (select2 queries the endpoint with an empty term).
3087 $minlengthforajax = getDolGlobalInt('USER_USE_SEARCH_TO_SELECT
');
3088 if ($minlengthforajax < 1) {
3089 $minlengthforajax = 0;
3091 // Page size of the ajax endpoint (USER_LIMIT_SIZE): select2 keeps asking for the next page
3092 // while the endpoint returns a full page, so the whole list stays browsable by scrolling.
3093 $ajaxpagesize = getDolGlobalInt('USER_LIMIT_SIZE
', 20);
3095 $out .= $this->buildSelectDolusersAjaxSelect2Script($htmlname, $urloption, $minlengthforajax, $ajaxpagesize);
3096 $out .= '<!-- force css to be higher than dialog popup --><style
type=
"text/css">.select2-container { z-index: 1010; }</style>
';
3101 // Do we want to show the label of entity into the combo list ?
3102 $showlabelofentity = isModEnabled('multicompany
') && !getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE
') && $conf->entity == 1 && !empty($user->admin) && empty($user->entity) && !preg_match('/^search_/
', $htmlname);
3103 $userissuperadminentityone = isModEnabled('multicompany
') && $conf->entity == 1 && $user->admin && empty($user->entity);
3105 // Forge request to select users
3106 $sql = "SELECT DISTINCT u.rowid, u.lastname as lastname, u.firstname, u.statut as status, u.login, u.admin, u.entity, u.gender, u.photo";
3107 if ($showlabelofentity) {
3108 $sql .= ", e.label";
3110 $sql .= " FROM " . $this->db->prefix() . "user as u";
3111 if ($showlabelofentity) {
3112 $sql .= " LEFT JOIN " . $this->db->prefix() . "entity as e ON e.rowid = u.entity";
3114 // Condition here should be the same than into societe->getSalesRepresentatives().
3115 if ($userissuperadminentityone && $force_entity !== 'default') {
3116 if (!empty($force_entity)) {
3117 $sql .= " WHERE u.entity IN (0, " . $this->db->sanitize($force_entity) . ")";
3119 $sql .= " WHERE u.entity IS NOT NULL";
3122 if (isModEnabled('multicompany
') && getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE
')) {
3123 $sql .= " WHERE u.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix()."usergroup_user as ug WHERE ug.entity IN (".getEntity('usergroup
')."))";
3125 $sql .= " WHERE u.entity IN (" . getEntity('user') . ")";
3129 if (!empty($user->socid)) {
3130 $sql .= " AND u.fk_soc = " . ((int) $user->socid);
3132 if (is_array($exclude) && $excludeUsers) {
3133 $sql .= " AND u.rowid NOT IN (" . $this->db->sanitize($excludeUsers) . ")";
3135 if ($includeUsers) {
3136 $sql .= " AND u.rowid IN (" . $this->db->sanitize($includeUsers) . ")";
3138 if (getDolGlobalString('USER_HIDE_INACTIVE_IN_COMBOBOX
') || $notdisabled) {
3139 $sql .= " AND (u.statut <> 0";
3140 if (!empty($selected)) {
3141 $sql .= " OR u.rowid IN (".$this->db->sanitize(implode(',
', $selected)).")"; // We must always keep the selected users to avoid to loose it/them when updating
3145 if (getDolGlobalString('USER_HIDE_NONEMPLOYEE_IN_COMBOBOX
')) {
3146 $sql .= " AND u.employee <> 0";
3148 if (getDolGlobalString('USER_HIDE_EXTERNAL_IN_COMBOBOX
')) {
3149 $sql .= " AND u.fk_soc IS NULL";
3151 if (!empty($morefilter)) {
3153 $sql .= forgeSQLFromUniversalSearchCriteria($morefilter, $errormessage);
3154 if ($errormessage) {
3155 $this->errors[] = $errormessage;
3156 dol_syslog(__METHOD__.' '.implode(',
', $this->errors), LOG_ERR);
3157 if ($outputmode == 0) {
3158 return 'Error bad param $morefilter
';
3165 //Add hook to filter on user (for example on usergroup define in custom modules)
3166 $reshook = $hookmanager->executeHooks('addSQLWhereFilterOnSelectUsers
', array(), $this, $action);
3167 if (!empty($reshook)) {
3168 $sql .= $hookmanager->resPrint;
3171 // Add criteria on the natural search string (used by the user/ajax/users.php autocomplete endpoint)
3172 if ($filterkey !== '') {
3174 $prefix = getDolGlobalString('USER_DONOTSEARCH_ANYWHERE
') ? '' : '%
'; // Can use index if USER_DONOTSEARCH_ANYWHERE is on
3175 // For natural search
3176 $search_crit = explode(' ', $filterkey);
3178 if (count($search_crit) > 1) {
3181 foreach ($search_crit as $crit) {
3185 $sql .= "(u.firstname LIKE '".$this->db->escape($prefix.$crit)."%
' OR u.lastname LIKE '".$this->db->escape($prefix.$crit)."%
' OR u.login LIKE '".$this->db->escape($prefix.$crit)."%
')";
3188 if (count($search_crit) > 1) {
3194 if (!getDolGlobalString('MAIN_FIRSTNAME_NAME_POSITION
')) { // MAIN_FIRSTNAME_NAME_POSITION is 0 means firstname+lastname
3195 $sql .= " ORDER BY u.statut DESC, u.firstname ASC, u.lastname ASC";
3197 $sql .= " ORDER BY u.statut DESC, u.lastname ASC, u.firstname ASC";
3201 $sql .= $this->db->plimit($limit, ((int) $limitoffset > 0 ? (int) $limitoffset : 0));
3204 dol_syslog(get_class($this) . "::select_dolusers", LOG_DEBUG);
3206 $resql = $this->db->query($sql);
3208 $num = $this->db->num_rows($resql);
3211 // do not use maxwidthonsmartphone by default. Set it by caller so auto size to 100% will work when not defined
3212 $out .= '<select
class=
"flat' . ($morecss ? ' ' . $morecss : ' minwidth200') . '" id=
"' . $htmlname . '" name=
"' . $htmlname . ($multiple ? '[]' : '') . '" ' . ($multiple ? 'multiple
' : '') . ' ' . ($disabled ? ' disabled' : '') . '>
';
3213 if ($show_empty && !$multiple) {
3214 $textforempty = ' ';
3215 if (!empty($conf->use_javascript_ajax)) {
3216 $textforempty = '
'; // If we use ajaxcombo, we need here to avoid to have an empty element that is too small.
3218 if (!is_numeric($show_empty)) {
3219 $textforempty = $show_empty;
3221 $out .= '<option
class=
"optiongrey" value=
"' . ($show_empty < 0 ? $show_empty : -1) . '"' . ((empty($selected) || in_array(-1, $selected)) ? ' selected
' : '') . '>
' . dol_escape_htmltag($textforempty) . '</option>
' . "\n";
3223 $outarray[($show_empty < 0 ? $show_empty : -1)] = $textforempty;
3224 $outarray2[($show_empty < 0 ? $show_empty : -1)] = array(
3225 'id' => ($show_empty < 0 ? $show_empty : -1),
3226 'label
' => $textforempty,
3227 'labelhtml
' => $textforempty,
3232 if ($showalso == 2 || $showalso == 3) {
3233 $out .= '<option value=
"-3"' . ((in_array(-3, $selected)) ? ' selected
' : '') . '>--
' . $langs->trans("MyTeam") . ' --</option>
' . "\n";
3235 $hasAtLeastOneSubordinate = (count($user->getAllChildIds(1)) > 1);
3236 if ($hasAtLeastOneSubordinate) {
3237 //$sql = "SELECT rowid FROM".MAIN_DB_PREFIX."user "
3238 $outarray[-3] = '--
' . $langs->trans("MyTeam") . ' --
';
3239 $outarray2[-3] = array(
3241 'label
' => '--
' . $langs->trans("MyTeam") . ' --
',
3242 'labelhtml
' => '--
' . $langs->trans("MyTeam") . ' --
',
3248 if ($showalso == 1 || $showalso == 3) {
3249 $out .= '<option value=
"-2"' . ((in_array(-2, $selected)) ? ' selected
' : '') . '>--
' . $langs->trans("Everybody") . ' --</option>
' . "\n";
3251 $outarray[-2] = '--
' . $langs->trans("Everybody") . ' --
';
3252 $outarray2[-2] = array(
3254 'label
' => '--
' . $langs->trans("Everybody") . ' --
',
3255 'labelhtml
' => '--
' . $langs->trans("Everybody") . ' --
',
3260 if ($showalso == 4) {
3261 $out .= '<option value=
"-4"' . ((in_array(-4, $selected)) ? ' selected
' : '') . '>--
' . $langs->trans("AllProjectContacts") . ' --</option>
' . "\n";
3263 $outarray[-4] = '--
' . $langs->trans("AllProjectContacts") . ' --
';
3264 $outarray2[-4] = array(
3266 'label
' => '--
' . $langs->trans("AllProjectContacts") . ' --
',
3267 'labelhtml
' => '--
' . $langs->trans("AllProjectContacts") . ' --
',
3273 $userstatic = new User($this->db);
3276 $obj = $this->db->fetch_object($resql);
3278 $userstatic->id = $obj->rowid;
3279 $userstatic->lastname = $obj->lastname;
3280 $userstatic->firstname = $obj->firstname;
3281 $userstatic->photo = $obj->photo;
3282 $userstatic->status = $obj->status;
3283 $userstatic->entity = $obj->entity;
3284 $userstatic->admin = $obj->admin;
3285 $userstatic->gender = $obj->gender;
3288 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
3289 $disableline = ($enableonlytext ? $enableonlytext : '1
');
3293 $labeltoshowhtml = '';
3295 // $fullNameMode is 0=Lastname+Firstname (MAIN_FIRSTNAME_NAME_POSITION=1), 1=Firstname+Lastname (MAIN_FIRSTNAME_NAME_POSITION=0)
3297 if (!getDolGlobalString('MAIN_FIRSTNAME_NAME_POSITION
')) {
3298 $fullNameMode = 1; //Firstname+lastname
3300 $labeltoshow .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
3301 $labeltoshowhtml .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
3302 if (empty($obj->firstname) && empty($obj->lastname)) {
3303 $labeltoshow .= $obj->login;
3304 $labeltoshowhtml .= $obj->login;
3307 // Complete name with a more info string like: ' (info1 - info2 - ...)
'
3310 if (getDolGlobalString('MAIN_SHOW_LOGIN
')) {
3311 $moreinfo .= ($moreinfo ? ' -
' : ' (
');
3312 $moreinfohtml .= ($moreinfohtml ? ' -
' : ' <span
class=
"opacitymedium">(
');
3313 $moreinfo .= $obj->login;
3314 $moreinfohtml .= $obj->login;
3316 if ($showstatus >= 0) {
3317 if ($obj->status == 1 && $showstatus == 1) {
3318 $moreinfo .= ($moreinfo ? ' -
' : ' (
') . $langs->trans('Enabled
');
3319 $moreinfohtml .= ($moreinfohtml ? ' -
' : ' <span
class=
"opacitymedium">(
') . $langs->trans('Enabled
');
3321 if ($obj->status == 0 && $showstatus == 1) {
3322 $moreinfo .= ($moreinfo ? ' -
' : ' (
') . $langs->trans('Disabled
');
3323 $moreinfohtml .= ($moreinfohtml ? ' -
' : ' <span
class=
"opacitymedium">(
') . $langs->trans('Disabled
');
3326 if ($showlabelofentity) {
3327 if (empty($obj->entity)) {
3328 $moreinfo .= ($moreinfo ? ' -
' : ' (
') . $langs->trans("AllEntities");
3329 $moreinfohtml .= ($moreinfohtml ? ' -
' : ' <span
class=
"opacitymedium">(
') . $langs->trans("AllEntities");
3331 if ($obj->entity != $conf->entity) {
3332 $moreinfo .= ($moreinfo ? ' -
' : ' (
') . ($obj->label ? $obj->label : $langs->trans("EntityNameNotDefined"));
3333 $moreinfohtml .= ($moreinfohtml ? ' -
' : ' <span
class=
"opacitymedium">(
').($obj->label ? $obj->label : $langs->trans("EntityNameNotDefined"));
3337 $moreinfo .= (!empty($moreinfo) ? ')
' : '');
3338 $moreinfohtml .= (!empty($moreinfohtml) ? ')</span>
' : '');
3339 if (!empty($disableline) && $disableline != '1
') {
3340 // Add text from $enableonlytext parameter
3341 $moreinfo .= ' -
' . $disableline;
3342 $moreinfohtml .= ' -
' . $disableline;
3344 $labeltoshow .= $moreinfo;
3345 $labeltoshowhtml .= $moreinfohtml;
3347 $out .= '<option value=
"' . $obj->rowid . '"';
3348 if (!empty($disableline)) {
3351 if (in_array($obj->rowid, $selected)) {
3352 $out .= ' selected
';
3354 $out .= ' data-html=
"';
3356 $outhtml = $userstatic->getNomUrl(-3, '', 0, 1, 24, 1, 'login', '', 1) . ' ';
3357 if ($showstatus >= 0 && $obj->status == 0) {
3358 $outhtml .= '<strike class="opacitymediumxxx
">';
3360 $outhtml .= $labeltoshowhtml;
3361 if ($showstatus >= 0 && $obj->status == 0) {
3362 $outhtml .= '</strike>';
3364 $labeltoshowhtml = $outhtml;
3366 $out .= dol_escape_htmltag($outhtml);
3368 $out .= $labeltoshow;
3369 $out .= '</option>
';
3371 $outarray[$userstatic->id] = $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength) . $moreinfo;
3372 $outarray2[$userstatic->id] = array(
3373 'id' => $userstatic->id,
3374 'label
' => $labeltoshow,
3375 'labelhtml
' => $labeltoshowhtml,
3383 $out .= '<select
class=
"flat" id=
"' . $htmlname . '" name=
"' . $htmlname . '" disabled>
';
3384 $out .= '<option value=
"">
' . $langs->trans("None") . '</option>
';
3386 $out .= '</select>
';
3388 if ($num && !$forcecombo) {
3389 // Enhance with select2
3390 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
3391 $out .= ajax_combobox($htmlname);
3394 dol_print_error($this->db);
3399 if ($outputmode == 2) {
3401 } elseif ($outputmode) {
3409 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
3433 public function select_dolusers_forevent($action = '
', $htmlname = 'userid
', $show_empty = 0, $exclude = null, $disabled = 0, $include = array(), $enableonly = array(), $force_entity = '0
', $maxlength = 0, $showstatus = 0, $morefilter = '', $showproperties = 0, $listofuserid = array(), $listofcontactid = array(), $listofotherid = array(), $canremoveowner = 1)
3436 global $langs, $user;
3438 $userstatic = new User($this->db);
3441 // The list of selected users is provided by the caller through $listofuserid (owner first).
3442 // Fall back to the legacy global $_SESSION['assignedtouser
'] only when no list is provided
3443 // (comm/action/card.php now scopes that session bucket per event id and no longer feeds this key).
3444 if (!empty($listofuserid)) {
3445 $assignedtouser = $listofuserid;
3446 } elseif (!empty($_SESSION['assignedtouser
'])) {
3447 $assignedtouser = json_decode($_SESSION['assignedtouser
'], true);
3448 if (!is_array($assignedtouser)) {
3449 $assignedtouser = array();
3452 $assignedtouser = array();
3454 $nbassignetouser = count($assignedtouser);
3456 //if ($nbassignetouser && $action != 'view
') $out .= '<br>
';
3457 if ($nbassignetouser) {
3458 $out .= '<ul
class=
"attendees">
';
3462 foreach ($assignedtouser as $key => $value) {
3463 if ($value['id'] == $ownerid) {
3469 $userstatic->fetch($value['id']);
3470 $out .= $userstatic->getNomUrl(-4);
3473 $ownerid = $value['id'];
3474 $out .= ' (
' . $langs->trans("Owner") . ')
';
3476 // Add picto to delete owner/assignee
3477 if ($nbassignetouser > 1 && $action != 'view
') {
3478 $canremoveassignee = 1;
3480 // We are on the owner of the event
3481 if (!$canremoveowner) {
3482 $canremoveassignee = 0;
3484 if (!$user->hasRight('agenda
', 'allactions
', 'create
')) {
3485 $canremoveassignee = 0; // Can't
remove the owner
3490 if ($canremoveassignee) {
3493 $out .=
' <input type="image" style="border: 0px;" src="' . img_picto($langs->trans(
"Remove"),
'delete',
'', 0, 1) .
'" value="' . $userstatic->id .
'" class="noborderfocus removedassigned reposition" id="removedassigned_' . $userstatic->id .
'" name="removedassigned_' . $userstatic->id .
'">';
3497 if ($showproperties) {
3498 if ($ownerid == $value[
'id'] && is_array($listofuserid) && count($listofuserid) && in_array($ownerid, array_keys($listofuserid))) {
3499 $out .=
'<div class="myavailability inline-block">';
3500 $out .=
'<span class="hideonsmartphone"> - ';
3503 $out .=
' <input title="'.$langs->trans(
"Availability").
'" id="transparency" class="paddingrightonly" ' . ($action ==
'view' ?
'disabled' :
'') .
' type="checkbox" name="transparency"' . ($listofuserid[$ownerid][
'transparency'] ?
' checked' :
'') .
'><label for="transparency">' . $langs->trans(
"Busy") .
'</label>';
3513 if ($nbassignetouser) {
3518 if ($action !=
'view') {
3520 $out .=
'<div class="divadduser'.$htmlname.
'">';
3521 $out .=
'<input type="hidden" class="removedassignedhidden" name="removedassigned" value="">';
3522 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
3523 $out .=
'jQuery(".removedassigned").click(function() { jQuery(".removedassignedhidden").val(jQuery(this).val()); });';
3524 $out .=
'jQuery(".assignedtouser").change(function() { console.log(jQuery(".assignedtouser option:selected").val());';
3525 $out .=
' if (jQuery(".assignedtouser option:selected").val() > 0) { jQuery("#' . $action .
'assignedtouser").attr("disabled", false); }';
3526 $out .=
' else { jQuery("#' . $action .
'assignedtouser").attr("disabled", true); }';
3528 $out .=
'})</script>';
3529 $out .= img_picto(
'',
'user',
'class="pictofixedwidth"');
3532 $out .= $this->select_dolusers(
'', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter, 0,
'',
'minwidth200', 0, 0,
false, 1);
3534 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
3536 $out .=
' <button type="submit" disabled class="button valignmiddle smallpaddingimp reposition butActionAdd" id="' . $action .
'assignedtouser" name="' . $action .
'assignedtouser" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
3537 $out .= $langs->trans(
"Add").
'</button>';
3565 public function select_dolresources_forevent($action =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include = array(), $enableonly = array(), $force_entity =
'0', $maxlength = 0, $showstatus = 0, $morefilter =
'', $showproperties = 0, $listofresourceid = array())
3570 require_once DOL_DOCUMENT_ROOT.
'/resource/class/html.formresource.class.php';
3571 require_once DOL_DOCUMENT_ROOT.
'/resource/class/dolresource.class.php';
3579 if (!empty($listofresourceid)) {
3580 $assignedtoresource = $listofresourceid;
3581 } elseif (!empty($_SESSION[
'assignedtoresource'])) {
3582 $assignedtoresource = json_decode($_SESSION[
'assignedtoresource'],
true);
3583 if (!is_array($assignedtoresource)) {
3584 $assignedtoresource = array();
3587 $assignedtoresource = array();
3589 $nbassignetoresource = count($assignedtoresource);
3592 if ($nbassignetoresource) {
3593 $out .=
'<ul class="attendees">';
3597 foreach ($assignedtoresource as $key => $value) {
3599 $resourcestatic->fetch($value[
'id']);
3600 $out .= $resourcestatic->getNomUrl(-1);
3601 if ($nbassignetoresource >= 1 && $action !=
'view') {
3602 $out .=
' <input type="image" style="border: 0px;" src="' . img_picto($langs->trans(
"Remove"),
'delete',
'', 0, 1) .
'" value="' . $resourcestatic->id .
'" class="removedassignedresource reposition" id="removedassignedresource_' . $resourcestatic->id .
'" name="removedassignedresource_' . $resourcestatic->id .
'">';
3605 if ($showproperties) {
3606 if (is_array($listofresourceid) && count($listofresourceid)) {
3607 $out .=
'<div class="myavailability inline-block">';
3608 $out .=
'<span class="hideonsmartphone"> - ';
3611 $out .=
' <input title="'.$langs->trans(
"Availability").
'" id="transparencyresource'.$value[
'id'].
'" class="paddingrightonly" ' . ($action ==
'view' ?
'disabled' :
'') .
' type="checkbox" name="transparency"' . (!empty($listofresourceid[$value[
'id']][
'transparency']) ?
' checked' :
'') .
'><label for="transparencyresource'.$value[
'id'].
'">' . $langs->trans(
"Busy") .
'</label>';
3621 if ($nbassignetoresource) {
3626 if ($action !=
'view') {
3627 $out .=
'<input type="hidden" class="removedassignedresourcehidden" name="removedassignedresource" value="">';
3628 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
3629 $out .=
'jQuery(".removedassignedresource").click(function() { jQuery(".removedassignedresourcehidden").val(jQuery(this).val()); });';
3630 $out .=
'jQuery(".assignedtoresource").change(function() { console.log(jQuery(".assignedtoresource option:selected").val());';
3631 $out .=
' if (jQuery(".assignedtoresource option:selected").val() > 0) { jQuery("#' . $action .
'assignedtoresource").attr("disabled", false); }';
3632 $out .=
' else { jQuery("#' . $action .
'assignedtoresource").attr("disabled", true); }';
3634 $out .=
'})</script>';
3637 if ($nbassignetoresource) {
3640 $out .= img_picto(
'',
'resource',
'class="pictofixedwidth"');
3642 $out .= $formresources->select_resource_list(0, $htmlname,
'', 1, 1, 0, $events,
'', 2, 0,
'minwidth200');
3644 $out .=
' <button type="submit" disabled class="button valignmiddle smallpaddingimp reposition butActionAdd" id="' . $action .
'assignedtoresource" name="' . $action .
'assignedtoresource" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
3645 $out .= $langs->trans(
"Add");
3646 $out .=
'</button>';
3684 public function select_produits($selected = 0, $htmlname =
'productid', $filtertype =
'', $limit = 0, $price_level = 0, $status = 1, $finished = 2, $selected_input_value =
'', $hidelabel = 0, $ajaxoptions = array(), $socid = 0, $showempty =
'1', $forcecombo = 0, $morecss =
'', $hidepriceinlabel = 0, $warehouseStatus =
'', $selected_combinations =
null, $nooutput = 0, $status_purchase = -1, $warehouseId = 0)
3687 global $langs,
$conf;
3692 $price_level = (!empty($price_level) ? $price_level : 0);
3693 if (is_null($ajaxoptions)) {
3694 $ajaxoptions = array();
3706 $placeholder = (is_numeric($showempty) ?
'' :
'placeholder="'.dolPrintHTML($showempty).
'"');
3708 if ($selected && empty($selected_input_value)) {
3709 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3710 $producttmpselect =
new Product($this->db);
3711 $producttmpselect->fetch($selected);
3712 $selected_input_value = $producttmpselect->ref;
3713 unset($producttmpselect);
3716 if ($filtertype ==
'') {
3724 $urloption = ($socid > 0 ?
'socid=' . $socid .
'&' :
'') .
'htmlname=' . $htmlname .
'&outjson=1&price_level=' . $price_level .
'&type=' . $filtertype .
'&mode=1&status=' . $status .
'&status_purchase=' . $status_purchase .
'&finished=' . $finished .
'&hidepriceinlabel=' . $hidepriceinlabel .
'&warehousestatus=' . $warehouseStatus;
3725 if ((
int) $warehouseId > 0) {
3726 $urloption .=
'&warehouseid=' . (int) $warehouseId;
3729 if (
isModEnabled(
'variants') && is_array($selected_combinations)) {
3735 <!-- script to auto show attributes select tags if a variant was selected -->
3736 <script nonce="' .
getNonce() .
'">
3737 // auto show attributes fields
3738 selected = ' . json_encode($selected_combinations) .
';
3741 jQuery(document).ready(function () {
3743 jQuery("input[name=\'prod_entry_mode\']").change(function () {
3744 if (jQuery(this).val() == \'free\') {
3745 jQuery(\'div#attributes_box\').empty();
3749 jQuery("'.$htmltag.
'#' . $htmlname .
'").change(function () {
3751 if (!jQuery(this).val()) {
3752 jQuery(\'div#attributes_box\').empty();
3756 console.log("A change has started. We get variants fields to inject html select");
3758 jQuery.getJSON("' . DOL_URL_ROOT .
'/variants/ajax/getCombinations.php", {
3759 id: jQuery(this).val()
3760 }, function (data) {
3761 jQuery(\'div#attributes_box\').empty();
3763 jQuery.each(data, function (key, val) {
3765 combvalues[val.id] = val.values;
3767 var span = jQuery(document.createElement(\'div\')).css({
3768 \'display\': \'table-row\'
3772 jQuery(document.createElement(\'div\')).text(val.label).css({
3773 \'font-weight\': \'bold\',
3774 \'display\': \'table-cell\'
3778 var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({
3779 \'margin-left\': \'15px\',
3780 \'white-space\': \'pre\'
3782 jQuery(document.createElement(\'option\')).val(\'\')
3785 jQuery.each(combvalues[val.id], function (key, val) {
3786 var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value);
3788 if (selected[val.fk_product_attribute] == val.id) {
3789 tag.attr(\'selected\', \'selected\');
3796 jQuery(\'div#attributes_box\').append(span);
3801 ' . ($selected ?
'jQuery("'.$htmltag.
'#' . $htmlname .
'").change();' :
'') .
'
3807 if (empty($hidelabel)) {
3808 $placeholder =
' placeholder="' . dolPrintHTMLForAttribute($langs->trans(
"RefOrLabel")) .
'"';
3809 } elseif ($hidelabel > 1) {
3810 $placeholder =
' placeholder="' . dolPrintHTMLForAttribute($langs->trans(
"RefOrLabel")) .
'"';
3811 if ($hidelabel == 2) {
3812 $out .= img_picto($langs->trans(
"Search"),
'search');
3816 $out .=
'<input type="text" class="minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . $placeholder .
' ' . (
getDolGlobalString(
'PRODUCT_SEARCH_AUTOFOCUS') ?
'autofocus' :
'') .
' spellcheck="false" />';
3817 if ($hidelabel == 3) {
3818 $out .= img_picto($langs->trans(
"Search"),
'search');
3821 $out .=
ajax_autocompleter((
string) $selected, $htmlname, DOL_URL_ROOT .
'/product/ajax/products.php', $urloption,
getDolGlobalInt(
'PRODUIT_USE_SEARCH_TO_SELECT'),
getDolGlobalInt(
'PRODUCT_SEARCH_AUTO_SELECT_IF_ONLY_ONE', 1), $ajaxoptions);
3823 $out .= $this->select_produits_list($selected, $htmlname, $filtertype, $limit, $price_level,
'', $status, $finished, 0, $socid, $showempty, $forcecombo, $morecss, $hidepriceinlabel, $warehouseStatus, $status_purchase, $warehouseId);
3825 if (
isModEnabled(
'variants') && is_array($selected_combinations)) {
3829 $htmltag =
'select';
3831 <!-- script to auto show attributes select tags if a variant was selected -->
3832 <script nonce="' .
getNonce() .
'">
3833 // auto show attributes fields
3834 selected = ' . json_encode($selected_combinations) .
';
3837 jQuery(document).ready(function () {
3839 jQuery("input[name=\'prod_entry_mode\']").change(function () {
3840 if (jQuery(this).val() == \'free\') {
3841 jQuery(\'div#attributes_box\').empty();
3845 jQuery("'.$htmltag.
'#' . $htmlname .
'").change(function () {
3847 if (!jQuery(this).val()) {
3848 jQuery(\'div#attributes_box\').empty();
3852 console.log("A change has started. We get variants fields to inject html select");
3854 jQuery.getJSON("' . DOL_URL_ROOT .
'/variants/ajax/getCombinations.php", {
3855 id: jQuery(this).val()
3856 }, function (data) {
3857 jQuery(\'div#attributes_box\').empty();
3859 jQuery.each(data, function (key, val) {
3861 combvalues[val.id] = val.values;
3863 var span = jQuery(document.createElement(\'div\')).css({
3864 \'display\': \'table-row\'
3868 jQuery(document.createElement(\'div\')).text(val.label).css({
3869 \'font-weight\': \'bold\',
3870 \'display\': \'table-cell\'
3874 var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({
3875 \'margin-left\': \'15px\',
3876 \'white-space\': \'pre\'
3878 jQuery(document.createElement(\'option\')).val(\'\')
3881 jQuery.each(combvalues[val.id], function (key, val) {
3882 var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value);
3884 if (selected[val.fk_product_attribute] == val.id) {
3885 tag.attr(\'selected\', \'selected\');
3892 jQuery(\'div#attributes_box\').append(span);
3897 ' . ($selected ?
'jQuery("'.$htmltag.
'#' . $htmlname .
'").change();' :
'') .
'
3904 if (empty($nooutput)) {
3928 public function select_bom($selected =
'', $htmlname =
'bom_id', $limit = 0, $status = 1, $type = 0, $showempty =
'1', $morecss =
'', $nooutput =
'', $forcecombo = 0, $TProducts = [])
3932 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3938 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3943 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
3945 $sql =
'SELECT b.rowid, b.ref, b.label as bomLabel, p.label as productLabel';
3946 $sql .=
' FROM ' . $this->db->prefix() .
'bom_bom as b';
3947 $sql .=
' INNER JOIN ' . $this->db->prefix() .
'product as p ON b.fk_product = p.rowid';
3948 $sql .=
' WHERE b.entity IN (' .
getEntity(
'bom') .
')';
3949 if (!empty($status)) {
3950 $sql .=
' AND status = ' . (int) $status;
3952 if (!empty($type)) {
3953 $sql .=
' AND bomtype = ' . (int) $type;
3955 if (!empty($TProducts)) {
3956 $sql .=
' AND fk_product IN (' . $this->db->sanitize(implode(
',', $TProducts)) .
')';
3958 if (!empty($limit)) {
3959 $sql .=
' LIMIT ' . (int) $limit;
3961 $resql = $this->db->query($sql);
3964 $out .=
'<option value="-1"';
3965 if (empty($selected)) {
3966 $out .=
' selected';
3968 $out .=
'> </option>';
3970 while ($obj = $this->db->fetch_object($resql)) {
3971 $out .=
'<option value="' . $obj->rowid .
'"';
3972 if ($obj->rowid == $selected) {
3975 $out .=
'>' . $obj->ref .
' - ' . $obj->productLabel .
' - ' . $obj->bomLabel .
'</option>';
3979 dol_print_error($this->db);
3981 $out .=
'</select>';
3982 if (empty($nooutput)) {
4017 public function select_produits_list($selected = 0, $htmlname =
'productid', $filtertype =
'', $limit = 1000, $price_level = 0, $filterkey =
'', $status = 1, $finished = 2, $outputmode = 0, $socid = 0, $showempty =
'1', $forcecombo = 0, $morecss =
'maxwidth500', $hidepriceinlabel = 0, $warehouseStatus =
'', $status_purchase = -1, $warehouseId = 0)
4021 global $hookmanager;
4024 $outarray = array();
4028 $langs->load(
'other');
4031 $warehouseStatusArray = array();
4032 if (!empty($warehouseStatus)) {
4033 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/entrepot.class.php';
4034 if (preg_match(
'/warehouseclosed/', $warehouseStatus)) {
4037 if (preg_match(
'/warehouseopen/', $warehouseStatus)) {
4040 if (preg_match(
'/warehouseinternal/', $warehouseStatus)) {
4045 $selectFields =
"p.rowid, p.ref, p.label, p.description, p.barcode, p.fk_country, p.fk_product_type, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.default_vat_code, p.duration, p.fk_price_expression";
4046 if (count($warehouseStatusArray)) {
4047 $selectFieldsGrouped =
", SUM(" . $this->db->ifsql(
"e.statut IS NULL",
"0",
"ps.reel") .
") as stock";
4049 $selectFieldsGrouped =
", " . $this->db->ifsql(
"p.stock IS NULL",
'0',
"p.stock") .
" AS stock";
4055 $parameters = array();
4056 $reshook = $hookmanager->executeHooks(
'selectProductsListSelect', $parameters);
4057 if (empty($reshook)) {
4058 $sql .= $selectFields.$selectFieldsGrouped.$hookmanager->resPrint;
4060 $sql .= $hookmanager->resPrint;
4065 $sql .=
", (SELECT " . $this->db->prefix() .
"categorie_product.fk_categorie
4066 FROM " . $this->db->prefix() .
"categorie_product
4067 WHERE " . $this->db->prefix() .
"categorie_product.fk_product = p.rowid
4069 ) AS categorie_product_id";
4074 $sql .=
', pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,';
4075 $sql .=
' pcp.price_base_type as custprice_base_type, pcp.tva_tx as custtva_tx, pcp.default_vat_code as custdefault_vat_code, pcp.ref_customer as custref, pcp.discount_percent as custdiscount_percent';
4076 $selectFields .=
", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custdefault_vat_code, custref, custdiscount_percent";
4080 $sql .=
", u.label as unit_long, u.short_label as unit_short, p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units";
4081 $selectFields .=
', unit_long, unit_short, p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units';
4086 $sql .=
", pl.label as label_translated";
4087 $sql .=
", pl.description as description_translated";
4088 $selectFields .=
", label_translated";
4089 $selectFields .=
", description_translated";
4093 $sql .=
", (SELECT pp.rowid FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
4094 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
4095 $sql .=
" AND price_level = " . ((int) $price_level);
4097 $sql .=
" ORDER BY date_price";
4098 $sql .=
" DESC LIMIT 1) as price_rowid";
4099 $sql .=
", (SELECT pp.price_by_qty FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
4100 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
4101 $sql .=
" AND price_level = " . ((int) $price_level);
4103 $sql .=
" ORDER BY date_price";
4104 $sql .=
" DESC LIMIT 1) as price_by_qty";
4105 $selectFields .=
", price_rowid, price_by_qty";
4110 $sql .=
" FROM ".$this->db->prefix().
"product as p";
4113 $sql .=
" USE INDEX (" . $this->db->sanitize(
getDolGlobalString(
'MAIN_PRODUCT_FORCE_INDEX')) .
")";
4117 $parameters = array(
4120 $reshook = $hookmanager->executeHooks(
'selectProductsListFrom', $parameters);
4121 $sql .= $hookmanager->resPrint;
4123 if (count($warehouseStatusArray)) {
4126 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_stock as ps ON ps.fk_product = p.rowid";
4127 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entrepot as e ON ps.fk_entrepot = e.rowid AND e.entity IN (" .
getEntity(
'stock') .
")";
4128 $sql .=
' AND e.statut IN (' . $this->db->sanitize($this->db->escape(implode(
',', $warehouseStatusArray))) .
')';
4134 $sql .=
" LEFT JOIN (";
4135 $sql .=
" SELECT pcp1.*";
4136 $sql .=
" FROM " . $this->db->prefix() .
"product_customer_price AS pcp1";
4137 $sql .=
" LEFT JOIN (";
4138 $sql .=
" SELECT fk_soc, fk_product, MIN(date_begin) AS date_begin";
4139 $sql .=
" FROM " . $this->db->prefix() .
"product_customer_price";
4140 $sql .=
" WHERE fk_soc = " . ((int) $socid);
4141 $sql .=
" AND date_begin <= '" . $this->db->idate($now) .
"'";
4142 $sql .=
" AND (date_end IS NULL OR '" . $this->db->idate($now) .
"' <= date_end)";
4143 $sql .=
" GROUP BY fk_soc, fk_product";
4144 $sql .=
" ) AS pcp2 ON pcp1.fk_soc = pcp2.fk_soc AND pcp1.fk_product = pcp2.fk_product AND pcp1.date_begin = pcp2.date_begin";
4145 $sql .=
" WHERE pcp2.fk_soc IS NOT NULL";
4146 $sql .=
" ) AS pcp ON pcp.fk_soc = " . ((int) $socid) .
" AND pcp.fk_product = p.rowid";
4150 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units as u ON u.rowid = p.fk_unit";
4154 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_lang as pl ON pl.fk_product = p.rowid";
4156 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
4157 $soc =
new Societe($this->db);
4158 $result = $soc->fetch($socid);
4159 if ($result > 0 && !empty($soc->default_lang)) {
4160 $sql .=
" AND pl.lang = '" . $this->db->escape($soc->default_lang) .
"'";
4162 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
4165 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
4170 $sql .=
' WHERE p.entity IN (' .
getEntity(
'product') .
')';
4173 if (strlen($filterkey) != 13) {
4174 $sql .=
" AND NOT EXISTS (SELECT pac.rowid FROM ".$this->db->prefix().
"product_attribute_combination as pac WHERE pac.fk_product_child = p.rowid)";
4177 $sql .=
" AND NOT EXISTS (SELECT pac.rowid FROM ".$this->db->prefix().
"product_attribute_combination as pac WHERE pac.fk_product_child = p.rowid)";
4180 if ($finished == 0) {
4181 $sql .=
" AND p.finished = " . ((int) $finished);
4182 } elseif ($finished == 1) {
4183 $sql .=
" AND p.finished = ".((int) $finished);
4186 $sql .=
" AND p.tosell = ".((int) $status);
4188 if ($status_purchase >= 0) {
4189 $sql .=
" AND p.tobuy = " . ((int) $status_purchase);
4192 if (strval($filtertype) !=
'') {
4193 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
4195 $sql .=
" AND p.fk_product_type = 1";
4197 $sql .=
" AND p.fk_product_type = 0";
4200 if ((
int) $warehouseId > 0) {
4201 $sql .=
" AND EXISTS (SELECT psw.fk_product FROM " . $this->db->prefix() .
"product_stock as psw WHERE psw.reel > 0 AND psw.fk_entrepot = ".(int) $warehouseId.
" AND psw.fk_product = p.rowid)";
4205 $parameters = array(
4206 'filterkey' => &$filterkey,
4209 $reshook = $hookmanager->executeHooks(
'selectProductsListWhere', $parameters);
4210 $sql .= $hookmanager->resPrint;
4212 if ($filterkey !=
'') {
4213 $sqlSupplierSearch =
'';
4218 $search_crit = explode(
' ', $filterkey);
4220 if (count($search_crit) > 1) {
4223 foreach ($search_crit as $crit) {
4227 $sql .=
"(p.ref LIKE '" . $this->db->escape($prefix . $crit) .
"%' OR p.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
4229 $sql .=
" OR pl.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
4232 $sql .=
" OR pcp.ref_customer LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
4235 $sql .=
" OR p.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
4237 $sql .=
" OR pl.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
4243 $sqlSupplierSearch .= !empty($sqlSupplierSearch) ?
' AND ' :
'';
4244 $sqlSupplierSearch .=
" pfp.ref_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
4249 if (count($search_crit) > 1) {
4253 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
4258 $sql .=
" OR EXISTS (SELECT pfp.fk_product FROM " . $this->db->prefix() .
"product_fournisseur_price as pfp WHERE p.rowid = pfp.fk_product";
4260 $sql .= $sqlSupplierSearch;
4263 $sql .=
" OR pfp.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
4270 if (count($warehouseStatusArray)) {
4271 $sql .=
" GROUP BY " . $this->db->sanitize($selectFields, 0, 0, 1);
4277 $sql .=
" ORDER BY".((int) $selected > 0 ?
" CASE WHEN p.rowid = ".((
int) $selected).
" THEN 0 ELSE 1 END," :
"").
" categorie_product_id ".(
getDolGlobalInt(
'PRODUCT_SORT_BY_CATEGORY') == 1 ?
"ASC" :
"DESC");
4278 } elseif ((
int) $selected > 0) {
4279 $sql .=
" ORDER BY CASE WHEN p.rowid = ".((int) $selected).
" THEN 0 ELSE 1 END, p.ref ASC";
4281 $sql .= $this->db->order(
"p.ref");
4285 $sql .= $this->db->plimit($limit, 0);
4303 dol_syslog(get_class($this) .
"::select_produits_list search products", LOG_DEBUG);
4307 $result = $this->db->query($sql);
4310 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
4311 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4312 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
4314 $num = $this->db->num_rows($result);
4319 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
4323 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
4329 if ($showempty && !is_numeric($showempty)) {
4330 $textifempty = $langs->trans($showempty);
4332 $textifempty .= $langs->trans(
"All");
4335 if ($showempty && !is_numeric($showempty)) {
4336 $textifempty = $langs->trans($showempty);
4340 $out .=
'<option value="-1" selected>' . ($textifempty ? $textifempty :
' ') .
'</option>';
4344 while ($num && $i < $num) {
4347 $objp = $this->db->fetch_object($result);
4349 if ((
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1) {
4350 $sql =
"SELECT rowid, quantity, price, unitprice, remise_percent, remise, price_base_type";
4351 $sql .=
" FROM " . $this->db->prefix() .
"product_price_by_qty";
4352 $sql .=
" WHERE fk_product_price = " . ((int) $objp->price_rowid);
4353 $sql .=
" ORDER BY quantity ASC";
4355 dol_syslog(get_class($this) .
"::select_produits_list search prices by qty", LOG_DEBUG);
4356 $result2 = $this->db->query($sql);
4358 $nb_prices = $this->db->num_rows($result2);
4360 while ($nb_prices && $j < $nb_prices) {
4361 $objp2 = $this->db->fetch_object($result2);
4363 $objp->price_by_qty_rowid = $objp2->rowid;
4364 $objp->price_by_qty_price_base_type = $objp2->price_base_type;
4365 $objp->price_by_qty_quantity = $objp2->quantity;
4366 $objp->price_by_qty_unitprice = $objp2->unitprice;
4367 $objp->price_by_qty_remise_percent = $objp2->remise_percent;
4369 $objp->quantity = $objp2->quantity;
4370 $objp->price = $objp2->price;
4371 $objp->unitprice = $objp2->unitprice;
4372 $objp->remise_percent = $objp2->remise_percent;
4377 $this->constructProductListOption($objp, $opt, $optJson, 0, $selected, $hidepriceinlabel, $filterkey);
4378 '@phan-var-force array{key:string,value:string,label:string,label2:string,desc:string,type:string,price_ht:string,price_ttc:string,price_ht_locale:string,price_ttc_locale:string,pricebasetype:string,tva_tx:string,default_vat_code:string,qty:string,discount:string,duration_value:string,duration_unit:string,pbq:string,labeltrans:string,desctrans:string,ref_customer:string} $optJson';
4385 array_push($outarray, $optJson);
4389 if (
isModEnabled(
'dynamicprices') && !empty($objp->fk_price_expression)) {
4390 $price_product =
new Product($this->db);
4391 $price_product->fetch($objp->rowid,
'',
'',
'1');
4393 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4395 $price_result = $priceparser->parseProduct($price_product);
4396 if ($price_result >= 0) {
4397 $objp->price = $price_result;
4398 $objp->unitprice = $price_result;
4400 $objp->price_ttc = (float)
price2num($objp->price) * (1 + ($objp->tva_tx / 100));
4401 $objp->price_ttc =
price2num($objp->price_ttc,
'MU');
4404 if (
getDolGlobalInt(
'PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES') && !empty($objp->custprice)) {
4407 $this->constructProductListOption($objp, $opt, $optJson, $price_level, $selected, $hidepriceinlabel, $filterkey);
4412 array_push($outarray, $optJson);
4418 $out .=
'</select>';
4420 $this->db->free($result);
4422 if (empty($outputmode)) {
4428 dol_print_error($this->db);
4449 protected function constructProductListOption(&$objp, &$opt, &$optJson, $price_level, $selected, $hidepriceinlabel = 0, $filterkey =
'', $novirtualstock = 0)
4451 global $langs,
$conf, $user;
4452 global $hookmanager;
4458 $outlabel_translated =
'';
4460 $outdesc_translated =
'';
4466 $outpricebasetype =
'';
4468 $outdefault_vat_code =
'';
4474 $productlabel = $objp->label;
4475 if (!empty($objp->label_translated)) {
4476 $productlabel = $objp->label_translated;
4478 $label = $productlabel;
4479 if (!empty($filterkey) && $filterkey !=
'') {
4480 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
4483 $outkey = $objp->rowid;
4484 $outref = $objp->ref;
4485 $outrefcust = empty($objp->custref) ?
'' : $objp->custref;
4486 $outlabel = $objp->label;
4487 $outdesc = $objp->description;
4489 $outlabel_translated = $objp->label_translated;
4490 $outdesc_translated = $objp->description_translated;
4492 $outbarcode = $objp->barcode;
4493 $outorigin = $objp->fk_country;
4494 $outpbq = empty($objp->price_by_qty_rowid) ?
'' : $objp->price_by_qty_rowid;
4496 $outtype = $objp->fk_product_type;
4501 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
4507 if (!empty($objp->unit_short)) {
4508 $outvalUnits .=
' - ' . $objp->unit_short;
4512 if (!empty($objp->weight) && $objp->weight_units !==
null) {
4514 $outvalUnits .=
' - ' . $unitToShow;
4516 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
4517 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
4518 $outvalUnits .=
' - ' . $unitToShow;
4520 if (!empty($objp->surface) && $objp->surface_units !==
null) {
4522 $outvalUnits .=
' - ' . $unitToShow;
4524 if (!empty($objp->volume) && $objp->volume_units !==
null) {
4526 $outvalUnits .=
' - ' . $unitToShow;
4529 if ($outdurationvalue && $outdurationunit) {
4531 'h' => $langs->trans(
'Hour'),
4532 'd' => $langs->trans(
'Day'),
4533 'w' => $langs->trans(
'Week'),
4534 'm' => $langs->trans(
'Month'),
4535 'y' => $langs->trans(
'Year')
4537 if (isset($da[$outdurationunit])) {
4538 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
4545 if ($user->hasRight(
'stock',
'lire')) {
4546 if ($objp->stock > 0) {
4548 } elseif ($objp->stock <= 0) {
4556 $labeltosearch =
'';
4557 $labeltosearch .= $objp->ref;
4558 if (!empty($objp->custref)) {
4559 $labeltosearch .=
' (' . $objp->custref .
')';
4562 $labeltosearch .=
' (' . $outbarcode .
')';
4564 $labeltosearch .=
' - ' . $productlabel;
4566 $labeltosearch .=
' (' .
getCountry($outorigin,
'1') .
')';
4570 $labeltoshowhtml =
'';
4571 $labeltoshowhtml .= $objp->ref;
4572 if (!empty($objp->custref)) {
4573 $labeltoshowhtml .=
' (' . $objp->custref .
')';
4575 if (!empty($filterkey) && $filterkey !=
'') {
4576 $labeltoshowhtml = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $labeltoshowhtml, 1);
4579 $labeltoshowhtml .=
' (' . $outbarcode .
')';
4581 $labeltoshowhtml .=
' - ' .
dol_trunc($label, $maxlengtharticle);
4583 $labeltoshowhtml .=
' (' .
getCountry($outorigin,
'1') .
')';
4587 $labeltoshowstock =
'';
4588 $labeltoshowhtmlstock =
'';
4590 if ($user->hasRight(
'stock',
'lire')) {
4591 $labeltoshowstock .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
4593 if ($objp->stock > 0) {
4594 $labeltoshowhtmlstock .=
' - <span class="product_line_stock_ok">';
4595 } elseif ($objp->stock <= 0) {
4596 $labeltoshowhtmlstock .=
' - <span class="product_line_stock_too_low">';
4598 $labeltoshowhtmlstock .= $langs->transnoentities(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
4599 $labeltoshowhtmlstock .=
'</span>';
4601 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
4602 $langs->load(
"stocks");
4604 $tmpproduct =
new Product($this->db);
4605 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
4606 $tmpproduct->load_virtual_stock();
4607 $virtualstock = $tmpproduct->stock_theorique;
4609 $labeltoshowstock .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
4611 $labeltoshowhtmlstock .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
4612 if ($virtualstock > 0) {
4613 $labeltoshowhtmlstock .=
'<span class="product_line_stock_ok">';
4614 } elseif ($virtualstock <= 0) {
4615 $labeltoshowhtmlstock .=
'<span class="product_line_stock_too_low">';
4617 $labeltoshowhtmlstock .= $virtualstock;
4618 $labeltoshowhtmlstock .=
'</span>';
4627 $labeltoshowprice =
'';
4628 $labeltoshowhtmlprice =
'';
4631 $sql =
"SELECT price, price_ttc, price_base_type, tva_tx, default_vat_code";
4632 $sql .=
" FROM " . $this->db->prefix() .
"product_price";
4633 $sql .=
" WHERE fk_product = " . ((int) $objp->rowid);
4634 $sql .=
" AND entity IN (" .
getEntity(
'productprice') .
")";
4635 $sql .=
" AND price_level = " . ((int) $price_level);
4636 $sql .=
" ORDER BY date_price DESC, rowid DESC";
4639 dol_syslog(get_class($this) .
'::constructProductListOption search price for product ' . $objp->rowid .
' AND level ' . $price_level, LOG_DEBUG);
4640 $result2 = $this->db->query($sql);
4642 $objp2 = $this->db->fetch_object($result2);
4645 if ($objp2->price_base_type ==
'HT') {
4646 $labeltoshowprice .=
' - ' .
price($objp2->price, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
4647 $labeltoshowhtmlprice .=
' - ' .
price($objp2->price, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
4649 $labeltoshowprice .=
' - ' .
price($objp2->price_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
4650 $labeltoshowhtmlprice .=
' - ' .
price($objp2->price_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
4652 $outprice_ht =
price($objp2->price);
4653 $outprice_ttc =
price($objp2->price_ttc);
4654 $outpricebasetype = $objp2->price_base_type;
4656 $outtva_tx = $objp2->tva_tx;
4657 $outdefault_vat_code = $objp2->default_vat_code;
4659 $outtva_tx = $objp->tva_tx;
4660 $outdefault_vat_code = $objp->default_vat_code;
4664 dol_print_error($this->db);
4669 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1 && (
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
4671 $outqty = $objp->quantity;
4672 $outdiscount = $objp->remise_percent;
4673 if ($objp->quantity == 1) {
4674 $labeltoshowprice .=
' - ' .
price($objp->unitprice, 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
4675 $labeltoshowhtmlprice .=
' - ' .
price($objp->unitprice, 0, $langs, 0, 0, -1,
$conf->currency) .
"/";
4676 $labeltoshowprice .= $langs->trans(
"Unit");
4677 $labeltoshowhtmlprice .= $langs->transnoentities(
"Unit");
4679 $labeltoshowprice .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
4680 $labeltoshowhtmlprice .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
4681 $labeltoshowprice .= $langs->trans(
"Units");
4682 $labeltoshowhtmlprice .= $langs->transnoentities(
"Units");
4685 $outprice_ht =
price($objp->unitprice);
4686 $outprice_ttc =
price($objp->unitprice * (1 + ($objp->tva_tx / 100)));
4687 $outpricebasetype = $objp->price_base_type;
4688 $outtva_tx = $objp->tva_tx;
4689 $outdefault_vat_code = $objp->default_vat_code;
4691 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1) {
4692 $labeltoshowprice .=
" (" .
price($objp->unitprice, 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->trans(
"Unit") .
")";
4693 $labeltoshowhtmlprice .=
" (" .
price($objp->unitprice, 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->transnoentities(
"Unit") .
")";
4695 if (empty($hidepriceinlabel) && !empty($objp->remise_percent) && $objp->remise_percent >= 1) {
4696 $labeltoshowprice .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4697 $labeltoshowhtmlprice .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4702 if (!empty($objp->idprodcustprice)) {
4705 if ($objp->custprice_base_type ==
'HT') {
4706 $labeltoshowprice .=
' - ' .
price($objp->custprice, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
4707 $labeltoshowhtmlprice .=
' - ' .
price($objp->custprice, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
4709 $labeltoshowprice .=
' - ' .
price($objp->custprice_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
4710 $labeltoshowhtmlprice .=
' - ' .
price($objp->custprice_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
4713 $outprice_ht =
price($objp->custprice);
4714 $outprice_ttc =
price($objp->custprice_ttc);
4715 $outpricebasetype = $objp->custprice_base_type;
4716 $outtva_tx = $objp->custtva_tx;
4717 $outdefault_vat_code = $objp->custdefault_vat_code;
4718 $outdiscount = $objp->custdiscount_percent;
4723 if (empty($hidepriceinlabel) && !$found) {
4724 if ($objp->price_base_type ==
'HT') {
4725 $labeltoshowprice .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
4726 $labeltoshowhtmlprice .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
4728 $labeltoshowprice .=
' - ' .
price($objp->price_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
4729 $labeltoshowhtmlprice .=
' - ' .
price($objp->price_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
4731 $outprice_ht =
price($objp->price);
4732 $outprice_ttc =
price($objp->price_ttc);
4733 $outpricebasetype = $objp->price_base_type;
4734 $outtva_tx = $objp->tva_tx;
4735 $outdefault_vat_code = $objp->default_vat_code;
4738 $optiontext = $labeltosearch.$outvalUnits.$labeltoshowprice.$labeltoshowstock;
4739 $optionhtml = $labeltoshowhtml.$outvalUnits.$labeltoshowhtmlprice.$labeltoshowhtmlstock;
4743 $opt =
'<option value="' . $objp->rowid .
'"';
4744 $opt .= ($objp->rowid == $selected) ?
' selected' :
'';
4745 if (!empty($objp->price_by_qty_rowid) && $objp->price_by_qty_rowid > 0) {
4746 $opt .=
' pbq="' . $objp->price_by_qty_rowid .
'" data-pbq="' . $objp->price_by_qty_rowid .
'" data-pbqup="' . $objp->price_by_qty_unitprice .
'" data-pbqbase="' . $objp->price_by_qty_price_base_type .
'" data-pbqqty="' . $objp->price_by_qty_quantity .
'" data-pbqpercent="' . $objp->price_by_qty_remise_percent .
'"';
4749 $opt .=
' data-labeltrans="' .
dol_escape_htmltag($outlabel_translated, 0, 0,
'', 0, 1) .
'"';
4753 if ($stocktag == 1) {
4754 $opt .=
' class="product_line_stock_ok" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml, 0, array(
'strong')).dolPrintHTMLForAttribute($outvalUnits).$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
4757 if ($stocktag == -1) {
4758 $opt .=
' class="product_line_stock_too_low" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml, 0, array(
'strong')).dolPrintHTMLForAttribute($outvalUnits).$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
4761 $opt .=
' data-html="'.$optionhtmlforattribute.
'" data-select-html="'.$optionhtmlforattribute.
'"';
4767 $outval .= $labeltoshowhtml;
4770 $outval .= $outvalUnits;
4773 $outval .= $labeltoshowhtmlprice;
4776 $outval .= $labeltoshowhtmlstock;
4779 $parameters = array(
'objp' => $objp);
4780 $reshook = $hookmanager->executeHooks(
'constructProductListOption', $parameters);
4781 if (empty($reshook)) {
4782 $opt .= $hookmanager->resPrint;
4784 $opt = $hookmanager->resPrint;
4787 $opt .=
"</option>\n";
4792 'label2' => $outlabel,
4796 'price_ttc' =>
price2num($outprice_ttc),
4799 'pricebasetype' => $outpricebasetype,
4800 'tva_tx' => $outtva_tx,
4801 'default_vat_code' => $outdefault_vat_code,
4803 'discount' => $outdiscount,
4804 'duration_value' => $outdurationvalue,
4805 'duration_unit' => $outdurationunit,
4807 'labeltrans' => $outlabel_translated,
4808 'desctrans' => $outdesc_translated,
4809 'ref_customer' => $outrefcust
4831 public function select_produits_fournisseurs($socid, $selected =
'', $htmlname =
'productid', $filtertype =
'', $notused =
'', $ajaxoptions = array(), $hidelabel = 0, $alsoproductwithnosupplierprice = 0, $morecss =
'', $placeholder =
'', $nooutput = 0)
4834 global $langs,
$conf;
4835 global $price_level, $status, $finished;
4837 if (!isset($status)) {
4841 $selected_input_value =
'';
4843 $regtmpsel = array();
4844 if ((
int) $selected > 0) {
4845 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
4846 $producttmpselect =
new Product($this->db);
4847 $producttmpselect->fetch((
int) $selected);
4848 $selected_input_value = $producttmpselect->ref;
4849 unset($producttmpselect);
4850 } elseif (preg_match(
'/^idprod_([0-9]+)$/', (
string) $selected, $regtmpsel)) {
4852 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
4853 $producttmpselect =
new Product($this->db);
4854 $producttmpselect->fetch((
int) $regtmpsel[1]);
4855 $selected_input_value = $producttmpselect->ref;
4856 unset($producttmpselect);
4860 $urloption = ($socid > 0 ?
'socid=' . $socid .
'&' :
'') .
'htmlname=' . $htmlname .
'&outjson=1&price_level=' . $price_level .
'&type=' . $filtertype .
'&mode=2&status=' . $status .
'&finished=' . $finished .
'&alsoproductwithnosupplierprice=' . $alsoproductwithnosupplierprice;
4862 $s = ($hidelabel ?
'' : $langs->trans(
"RefOrLabel") .
' : ') .
'<input type="text" class="'.$morecss.
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . ($placeholder ?
' placeholder="' . $placeholder .
'"' :
'') .
' spellcheck="false">';
4864 $s .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT .
'/product/ajax/products.php', $urloption,
getDolGlobalInt(
'PRODUIT_USE_SEARCH_TO_SELECT'), 0, $ajaxoptions);
4866 $s = $this->select_produits_fournisseurs_list($socid, $selected, $htmlname, $filtertype, $notused,
'', $status, 0, 0, $alsoproductwithnosupplierprice, $morecss,
getDolGlobalInt(
'SUPPLIER_SHOW_STOCK_IN_PRODUCTS_COMBO'), $placeholder);
4896 public function select_produits_fournisseurs_list($socid, $selected =
'', $htmlname =
'productid', $filtertype =
'', $notused =
'', $filterkey =
'', $statut = -1, $outputmode = 0, $limit = 100, $alsoproductwithnosupplierprice = 0, $morecss =
'', $showstockinlist = 0, $placeholder =
'')
4899 global $langs,
$conf, $user;
4900 global $hookmanager;
4903 $outarray = array();
4907 $langs->load(
'stocks');
4910 $langs->load(
'other');
4913 $sql =
"SELECT p.rowid, p.ref, p.label, p.price, p.duration, p.fk_product_type, p.stock, p.tva_tx as tva_tx_sale, p.default_vat_code as default_vat_code_sale,";
4914 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice, pfp.barcode";
4915 $sql .=
", pfp.multicurrency_code, pfp.multicurrency_unitprice";
4916 $sql .=
", pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.default_vat_code, pfp.fk_soc, s.nom as name";
4917 $sql .=
", pfp.supplier_reputation";
4920 $sql .=
", pfp.desc_fourn as description";
4922 $sql .=
", p.description";
4926 $sql .=
", u.label as unit_long, u.short_label as unit_short, p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units";
4931 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListSelect', $parameters);
4932 $sql .= $hookmanager->resPrint;
4934 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
4938 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListFrom', $parameters);
4939 $sql .= $hookmanager->resPrint;
4941 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN (" .
getEntity(
'product') .
") )";
4943 $sql .=
" AND pfp.fk_soc = " . ((int) $socid);
4945 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
4948 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
4950 $sql .=
" WHERE p.entity IN (" .
getEntity(
'product') .
")";
4951 if ($statut != -1) {
4952 $sql .=
" AND p.tobuy = " . ((int) $statut);
4954 if (strval($filtertype) !=
'') {
4955 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
4959 $parameters = array();
4960 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListWhere', $parameters);
4961 $sql .= $hookmanager->resPrint;
4963 if ($filterkey !=
'') {
4967 $search_crit = explode(
' ', $filterkey);
4969 if (count($search_crit) > 1) {
4972 foreach ($search_crit as $crit) {
4976 $sql .=
"(pfp.ref_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%' OR p.ref LIKE '" . $this->db->escape($prefix . $crit) .
"%' OR p.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
4978 $sql .=
" OR pfp.desc_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
4983 if (count($search_crit) > 1) {
4987 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
4988 $sql .=
" OR pfp.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
4992 $sql .=
" ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC";
4993 $sql .= $this->db->plimit($limit, 0);
4997 dol_syslog(get_class($this) .
"::select_produits_fournisseurs_list", LOG_DEBUG);
4998 $result = $this->db->query($sql);
5000 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
5001 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
5003 $num = $this->db->num_rows($result);
5006 $out .=
'<select class="flat ' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'">';
5008 $out .=
'<option value="-1" selected>' . ($placeholder ? $placeholder :
' ') .
'</option>';
5010 $out .=
'<option value="-1">' . ($placeholder ? $placeholder :
' ') .
'</option>';
5015 $objp = $this->db->fetch_object($result);
5017 if (is_null($objp->idprodfournprice)) {
5019 $objp->tva_tx = $objp->tva_tx_sale;
5020 $objp->default_vat_code = $objp->default_vat_code_sale;
5023 $outkey = $objp->idprodfournprice;
5024 if (!$outkey && $alsoproductwithnosupplierprice) {
5025 $outkey =
'idprod_' . $objp->rowid;
5028 $outref = $objp->ref;
5029 $outbarcode = $objp->barcode;
5032 $outtype = $objp->fk_product_type;
5039 if (!empty($objp->unit_short)) {
5040 $outvalUnits .=
' - ' . $objp->unit_short;
5042 if (!empty($objp->weight) && $objp->weight_units !==
null) {
5044 $outvalUnits .=
' - ' . $unitToShow;
5046 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
5047 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
5048 $outvalUnits .=
' - ' . $unitToShow;
5050 if (!empty($objp->surface) && $objp->surface_units !==
null) {
5052 $outvalUnits .=
' - ' . $unitToShow;
5054 if (!empty($objp->volume) && $objp->volume_units !==
null) {
5056 $outvalUnits .=
' - ' . $unitToShow;
5058 if ($outdurationvalue && $outdurationunit) {
5060 'h' => $langs->trans(
'Hour'),
5061 'd' => $langs->trans(
'Day'),
5062 'w' => $langs->trans(
'Week'),
5063 'm' => $langs->trans(
'Month'),
5064 'y' => $langs->trans(
'Year')
5066 if (isset($da[$outdurationunit])) {
5067 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
5072 $objRef = $objp->ref;
5073 if ($filterkey && $filterkey !=
'') {
5074 $objRef = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRef, 1);
5076 $objRefFourn = $objp->ref_fourn;
5077 if ($filterkey && $filterkey !=
'') {
5078 $objRefFourn = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRefFourn, 1);
5080 $label = $objp->label;
5081 if ($filterkey && $filterkey !=
'') {
5082 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
5085 switch ($objp->fk_product_type) {
5097 if (empty($picto)) {
5100 $optlabel = img_object(
'', $picto,
'class="paddingright classfortooltip"', 0, 0, 1);
5103 $optlabel .= $objp->ref;
5104 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
5105 $optlabel .=
' <span class="opacitymedium">(' . $objp->ref_fourn .
')</span>';
5107 if (
isModEnabled(
'barcode') && !empty($objp->barcode)) {
5108 $optlabel .=
' (' . $outbarcode .
')';
5110 $optlabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
5112 $outvallabel = $objRef;
5113 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
5114 $outvallabel .=
' (' . $objRefFourn .
')';
5116 if (
isModEnabled(
'barcode') && !empty($objp->barcode)) {
5117 $outvallabel .=
' (' . $outbarcode .
')';
5119 $outvallabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
5121 $outsearchlabel = implode(
' ', array_filter(array(
5122 (
string) $objp->ref,
5123 (
string) $objp->ref_fourn,
5124 (
string) $objp->barcode,
5125 (
string) $objp->label,
5127 ), function (
string $value):
bool {
5128 return $value !==
'';
5132 $optlabel .= $outvalUnits;
5133 $outvallabel .= $outvalUnits;
5135 if (!empty($objp->idprodfournprice)) {
5136 $outqty = $objp->quantity;
5137 $outdiscount = $objp->remise_percent;
5138 if (
isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
5140 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
5141 $prod_supplier->id = $objp->fk_product;
5142 $prod_supplier->fourn_qty = $objp->quantity;
5143 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
5144 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
5146 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
5148 $price_result = $priceparser->parseProductSupplier($prod_supplier);
5149 if ($price_result >= 0) {
5150 $objp->fprice = $price_result;
5151 if ($objp->quantity >= 1) {
5152 $objp->unitprice = $objp->fprice / $objp->quantity;
5156 if ($objp->quantity == 1) {
5157 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
5158 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1,
$conf->currency) .
"/";
5159 $optlabel .= $langs->trans(
"Unit");
5160 $outvallabel .= $langs->transnoentities(
"Unit");
5162 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
5163 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
5164 $optlabel .=
' ' . $langs->trans(
"Units");
5165 $outvallabel .=
' ' . $langs->transnoentities(
"Units");
5168 if ($objp->quantity != 1) {
5169 $optlabel .=
" (" .
price($objp->unitprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->trans(
"Unit") .
")";
5170 $outvallabel .=
" (" .
price($objp->unitprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->transnoentities(
"Unit") .
")";
5172 if ($objp->remise_percent >= 1) {
5173 $optlabel .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
5174 $outvallabel .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
5176 if ($objp->duration) {
5177 $optlabel .=
" - " . $objp->duration;
5178 $outvallabel .=
" - " . $objp->duration;
5181 $optlabel .=
" - " .
dol_trunc($objp->name, 8);
5182 $outvallabel .=
" - " .
dol_trunc($objp->name, 8);
5184 if ($objp->supplier_reputation) {
5186 $reputations = array(
'' => $langs->trans(
'Standard'),
'FAVORITE' => $langs->trans(
'Favorite'),
'NOTTHGOOD' => $langs->trans(
'NotTheGoodQualitySupplier'),
'DONOTORDER' => $langs->trans(
'DoNotOrderThisProductToThisSupplier'));
5188 $optlabel .=
" - " . $reputations[$objp->supplier_reputation];
5189 $outvallabel .=
" - " . $reputations[$objp->supplier_reputation];
5192 $optlabel .=
" - <span class='opacitymedium'>" . $langs->trans(
"NoPriceDefinedForThisSupplier") .
'</span>';
5193 $outvallabel .=
' - ' . $langs->transnoentities(
"NoPriceDefinedForThisSupplier");
5197 $novirtualstock = ($showstockinlist == 2);
5199 if ($user->hasRight(
'stock',
'lire')) {
5200 $outvallabel .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
5202 if ($objp->stock > 0) {
5203 $optlabel .=
' - <span class="product_line_stock_ok">';
5204 } elseif ($objp->stock <= 0) {
5205 $optlabel .=
' - <span class="product_line_stock_too_low">';
5207 $optlabel .= $langs->transnoentities(
"Stock") .
':' .
price(
price2num($objp->stock,
'MS'));
5208 $optlabel .=
'</span>';
5209 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
5210 $langs->load(
"stocks");
5212 $tmpproduct =
new Product($this->db);
5213 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
5214 $tmpproduct->load_virtual_stock();
5215 $virtualstock = $tmpproduct->stock_theorique;
5217 $outvallabel .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
5219 $optlabel .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
5220 if ($virtualstock > 0) {
5221 $optlabel .=
'<span class="product_line_stock_ok">';
5222 } elseif ($virtualstock <= 0) {
5223 $optlabel .=
'<span class="product_line_stock_too_low">';
5225 $optlabel .= $virtualstock;
5226 $optlabel .=
'</span>';
5233 $optstart =
'<option value="' . $outkey .
'"';
5234 if ($selected && preg_match(
'/^idprod_/', (
string) $selected) && (
string) $selected ==
'idprod_'.$objp->rowid) {
5235 $optstart .=
' selected';
5236 } elseif ($selected && (
string) $selected == (
string) $objp->idprodfournprice) {
5237 $optstart .=
' selected';
5240 if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) {
5241 $optstart .=
' disabled';
5244 if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) {
5253 $optstart .=
' data-default-vat-code="' .
dol_escape_htmltag($objp->default_vat_code) .
'"';
5256 $optstart .=
' data-multicurrency-code="' .
dol_escape_htmltag($objp->multicurrency_code) .
'"';
5260 $optstart .=
' data-description="' .
dol_escape_htmltag($objp->description, 0, 1) .
'"';
5264 $outarrayentry = array(
5267 'label' => $outvallabel,
5268 'labelhtml' => $optlabel,
5270 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
5271 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
5272 'price_ht' =>
price2num($objp->unitprice,
'MU'),
5273 'tva_tx_formated' =>
price($objp->tva_tx, 0, $langs, 1, -1, 2),
5275 'default_vat_code' => $objp->default_vat_code,
5276 'supplier_ref' => $objp->ref_fourn,
5277 'discount' => $outdiscount,
5279 'duration_value' => $outdurationvalue,
5280 'duration_unit' => $outdurationunit,
5281 'disabled' => empty($objp->idprodfournprice),
5282 'description' => $objp->description
5285 $outarrayentry[
'multicurrency_code'] = $objp->multicurrency_code;
5286 $outarrayentry[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
5288 $parameters = array(
5290 'optstart' => &$optstart,
5291 'optlabel' => &$optlabel,
5292 'outvallabel' => &$outvallabel,
5293 'outarrayentry' => &$outarrayentry,
5296 $reshook = $hookmanager->executeHooks(
'selectProduitsFournisseurListOption', $parameters, $this);
5302 $out .= $optstart .
' data-html="' .
dol_escape_htmltag($optlabel) .
'">' . $optlabel .
"</option>\n";
5303 $outarraypush = array(
5306 'label' => $outvallabel,
5307 'labelhtml' => $optlabel,
5309 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
5310 'price_qty_ht_locale' =>
price($objp->fprice),
5311 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
5312 'price_unit_ht_locale' =>
price($objp->unitprice),
5313 'price_ht' =>
price2num($objp->unitprice,
'MU'),
5314 'tva_tx_formated' =>
price($objp->tva_tx),
5316 'default_vat_code' => $objp->default_vat_code,
5317 'supplier_ref' => $objp->ref_fourn,
5318 'discount' => $outdiscount,
5320 'duration_value' => $outdurationvalue,
5321 'duration_unit' => $outdurationunit,
5322 'disabled' => empty($objp->idprodfournprice),
5323 'description' => $objp->description
5326 $outarraypush[
'multicurrency_code'] = $objp->multicurrency_code;
5327 $outarraypush[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
5329 array_push($outarray, $outarraypush);
5342 $out .=
'</select>';
5344 $this->db->free($result);
5346 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
5349 dol_print_error($this->db);
5352 if (empty($outputmode)) {
5371 global $langs,
$conf;
5373 $langs->load(
'stocks');
5375 $sql =
"SELECT p.rowid, p.ref, p.label, p.price, p.duration, pfp.fk_soc,";
5376 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.remise_percent, pfp.quantity, pfp.unitprice,";
5377 $sql .=
" pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name";
5378 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
5379 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
5380 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
5381 $sql .=
" WHERE pfp.entity IN (" .
getEntity(
'productsupplierprice') .
")";
5382 $sql .=
" AND p.tobuy = 1";
5383 $sql .=
" AND s.fournisseur = 1";
5384 $sql .=
" AND p.rowid = " . ((int) $productid);
5386 $sql .=
" ORDER BY s.nom, pfp.ref_fourn DESC";
5388 $sql .=
" ORDER BY pfp.unitprice - pfp.unitprice * pfp.remise_percent / 100 ASC";
5391 dol_syslog(get_class($this) .
"::select_product_fourn_price", LOG_DEBUG);
5392 $result = $this->db->query($sql);
5395 $num = $this->db->num_rows($result);
5397 $form =
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
5400 $form .=
'<option value="0">-- ' . $langs->trans(
"NoSupplierPriceDefinedForThisProduct") .
' --</option>';
5402 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
5403 $form .=
'<option value="0"> </option>';
5407 $objp = $this->db->fetch_object($result);
5409 $opt =
'<option value="' . $objp->idprodfournprice .
'"';
5411 if ($num == 1 || ($selected_supplier > 0 && $objp->fk_soc == $selected_supplier) || ($i == 0 &&
getDolGlobalString(
'PRODUCT_BEST_SUPPLIER_PRICE_PRESELECTED'))) {
5412 $opt .=
' selected';
5414 $opt .=
'>' . $objp->name .
' - ' . $objp->ref_fourn .
' - ';
5416 if (
isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
5418 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
5419 $prod_supplier->id = $productid;
5420 $prod_supplier->fourn_qty = $objp->quantity;
5421 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
5422 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
5424 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
5426 $price_result = $priceparser->parseProductSupplier($prod_supplier);
5427 if ($price_result >= 0) {
5428 $objp->fprice = $price_result;
5429 if ($objp->quantity >= 1) {
5430 $objp->unitprice = $objp->fprice / $objp->quantity;
5434 if ($objp->quantity == 1) {
5435 $opt .=
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
5438 $opt .= $objp->quantity .
' ';
5440 if ($objp->quantity == 1) {
5441 $opt .= $langs->trans(
"Unit");
5443 $opt .= $langs->trans(
"Units");
5445 if ($objp->quantity > 1) {
5447 $opt .=
price($objp->unitprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->trans(
"Unit");
5449 if ($objp->duration) {
5450 $opt .=
" - " . $objp->duration;
5452 $opt .=
"</option>\n";
5459 $form .=
'</select>';
5460 $this->db->free($result);
5463 dol_print_error($this->db);
5478 global $langs, $hookmanager;
5480 $num = count($this->cache_conditions_paiements);
5487 $this->cache_conditions_paiements = array();
5489 $sql =
"SELECT rowid, code, libelle as label, deposit_percent, entity";
5490 $sql .=
" FROM " . $this->db->prefix() .
'c_payment_term';
5491 $sql .=
" WHERE entity IN (" .
getEntity(
'c_payment_term') .
")";
5492 $sql .=
" AND active > 0";
5493 $sql .=
" ORDER BY sortorder";
5495 $resql = $this->db->query($sql);
5497 $num = $this->db->num_rows($resql);
5500 $obj = $this->db->fetch_object($resql);
5503 $label = ($langs->trans(
"PaymentConditionShort" . $obj->code) !=
"PaymentConditionShort" . $obj->code ? $langs->trans(
"PaymentConditionShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
5505 $this->cache_conditions_paiements[$obj->rowid][
'code'] = (string) $obj->code;
5506 $this->cache_conditions_paiements[$obj->rowid][
'label'] = (string) $label;
5507 $this->cache_conditions_paiements[$obj->rowid][
'deposit_percent'] = (string) $obj->deposit_percent;
5508 $this->cache_conditions_paiements[$obj->rowid][
'entity'] = (int) $obj->entity;
5513 $parameters = array(
'dictionary' =>
'paymentterm');
5514 $reshook = $hookmanager->executeHooks(
'loadDictionaryCache', $parameters, $this);
5515 if (empty($reshook)) {
5516 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
5517 $this->cache_conditions_paiements = array_merge($this->cache_conditions_paiements, $hookmanager->resArray);
5520 $this->cache_conditions_paiements = $hookmanager->resArray;
5527 dol_print_error($this->db);
5544 $this->cache_rule_for_lines_dates = $factureRec->fields[
'rule_for_lines_dates'][
'arrayofkeyval'];
5546 if (empty($this->cache_rule_for_lines_dates)) {
5565 $num = count($this->cache_availability);
5572 $this->cache_availability = array();
5574 $langs->load(
'propal');
5576 $sql =
"SELECT rowid, code, label, position";
5577 $sql .=
" FROM " . $this->db->prefix() .
'c_availability';
5578 $sql .=
" WHERE active > 0";
5580 $resql = $this->db->query($sql);
5582 $num = $this->db->num_rows($resql);
5585 $obj = $this->db->fetch_object($resql);
5588 $label = ($langs->trans(
"AvailabilityType" . $obj->code) !=
"AvailabilityType" . $obj->code ? $langs->trans(
"AvailabilityType" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
5589 $this->cache_availability[$obj->rowid][
'code'] = (string) $obj->code;
5590 $this->cache_availability[$obj->rowid][
'label'] = (string) $label;
5591 $this->cache_availability[$obj->rowid][
'position'] = (int) $obj->position;
5596 $this->cache_availability =
dol_sort_array($this->cache_availability,
'position',
'asc', 0, 0, 1);
5600 dol_print_error($this->db);
5616 public function selectAvailabilityDelay($selected =
'', $htmlname =
'availid', $filtertype =
'', $addempty = 0, $morecss =
'', $noouput = 0)
5618 global $langs, $user;
5620 $this->load_cache_availability();
5622 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
5624 $out =
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
5626 $out .=
'<option value="-1">'.(is_numeric($addempty) ?
' ' : $langs->trans($addempty)).
'</option>';
5628 foreach ($this->cache_availability as
$id => $arrayavailability) {
5629 if ($selected ==
$id) {
5630 $out .=
'<option value="' .
$id .
'" selected>';
5632 $out .=
'<option value="' .
$id .
'">';
5635 $out .=
'</option>';
5637 $out .=
'</select>';
5639 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5656 public function loadCacheInputReason()
5660 $num = count($this->cache_demand_reason);
5665 $sql =
"SELECT rowid, code, label";
5666 $sql .=
" FROM " . $this->db->prefix() .
'c_input_reason';
5667 $sql .=
" WHERE active > 0";
5669 $resql = $this->db->query($sql);
5671 $num = $this->db->num_rows($resql);
5674 $tmparray = array();
5676 $obj = $this->db->fetch_object($resql);
5679 $label = ($obj->label !=
'-' ? (string) $obj->label :
'');
5680 if ($langs->trans(
"DemandReasonType" . $obj->code) !=
"DemandReasonType" . $obj->code) {
5681 $label = $langs->trans(
"DemandReasonType" . $obj->code);
5683 if ($langs->trans($obj->code) != $obj->code) {
5684 $label = $langs->trans($obj->code);
5687 $tmparray[(int) $obj->rowid]
5689 'id' => (
int) $obj->rowid,
5690 'code' => (string) $obj->code,
5696 $this->cache_demand_reason =
dol_sort_array($tmparray,
'label',
'asc', 0, 0, 1);
5701 dol_print_error($this->db);
5718 public function selectInputReason($selected =
'', $htmlname =
'demandreasonid', $exclude =
'', $addempty = 0, $morecss =
'', $notooltip = 0)
5720 global $langs, $user;
5722 $this->loadCacheInputReason();
5724 print
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
5726 print
'<option value="0"' . (empty($selected) ?
' selected' :
'') .
'> </option>';
5728 foreach ($this->cache_demand_reason as
$id => $arraydemandreason) {
5729 if ($arraydemandreason[
'code'] == $exclude) {
5733 if ($selected && ($selected == $arraydemandreason[
'id'] || $selected == $arraydemandreason[
'code'])) {
5734 print
'<option value="' . $arraydemandreason[
'id'] .
'" selected>';
5736 print
'<option value="' . $arraydemandreason[
'id'] .
'">';
5738 $label = $arraydemandreason[
'label'];
5739 print $langs->trans($label);
5743 if ($user->admin && empty($notooltip)) {
5744 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5759 global $langs, $hookmanager;
5761 $num = count($this->cache_types_paiements);
5768 $this->cache_types_paiements = array();
5770 $sql =
"SELECT id, code, libelle as label, type, entity, active";
5771 $sql .=
" FROM " . $this->db->prefix() .
"c_paiement";
5772 $sql .=
" WHERE entity IN (" .
getEntity(
'c_paiement') .
")";
5774 $resql = $this->db->query($sql);
5776 $num = $this->db->num_rows($resql);
5779 $obj = $this->db->fetch_object($resql);
5782 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) !=
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
5783 $shortlabel = $label;
5785 $this->cache_types_paiements[(int) $obj->id][
'id'] = (
int) $obj->id;
5786 $this->cache_types_paiements[(int) $obj->id][
'code'] = (
string) $obj->code;
5787 $this->cache_types_paiements[(int) $obj->id][
'label'] = (
string) $label;
5788 $this->cache_types_paiements[(int) $obj->id][
'shortlabel'] = (
string) $shortlabel;
5789 $this->cache_types_paiements[(int) $obj->id][
'type'] = (
int) $obj->type;
5790 $this->cache_types_paiements[(int) $obj->id][
'entity'] = (
int) $obj->entity;
5791 $this->cache_types_paiements[(int) $obj->id][
'active'] = (
int) $obj->active;
5795 $parameters = array(
'dictionary' =>
'paymenttype');
5796 $reshook = $hookmanager->executeHooks(
'loadDictionaryCache', $parameters, $this);
5797 if (empty($reshook)) {
5798 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
5799 $this->cache_types_paiements = array_merge($this->cache_types_paiements, $hookmanager->resArray);
5802 $this->cache_types_paiements = $hookmanager->resArray;
5805 $this->cache_types_paiements =
dol_sort_array($this->cache_types_paiements,
'label',
'asc', 0, 0, 1);
5809 dol_print_error($this->db);
5835 public function select_conditions_paiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1, $noprint = 0)
5838 $out = $this->getSelectConditionsPaiements($selected, $htmlname, $filtertype, $addempty, $noinfoadmin, $morecss, $deposit_percent);
5839 if (empty($noprint)) {
5863 public function getSelectConditionsPaiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1)
5865 global $langs, $user;
5868 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
5870 $this->load_cache_conditions_paiements();
5873 if (empty($selected) && strpos($htmlname,
'search_') !== 0 &&
getDolGlobalInt(
'MAIN_DEFAULT_PAYMENT_TERM_ID')) {
5874 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TERM_ID", LOG_NOTICE);
5878 $out .=
'<select id="' . $htmlname .
'" class="flat selectpaymentterms' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
5880 $out .=
'<option value="0"> </option>';
5883 $selectedDepositPercent =
null;
5885 foreach ($this->cache_conditions_paiements as
$id => $arrayconditions) {
5886 if ($filtertype <= 0 && !empty($arrayconditions[
'deposit_percent'])) {
5890 if ($selected ==
$id) {
5891 $selectedDepositPercent = $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'];
5892 $out .=
'<option value="' .
$id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'" selected>';
5894 $out .=
'<option value="' .
$id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'">';
5896 $label = $arrayconditions[
'label'];
5898 if (!empty($arrayconditions[
'deposit_percent'])) {
5899 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'], $label);
5903 $out .=
'</option>';
5905 $out .=
'</select>';
5906 if ($user->admin && empty($noinfoadmin)) {
5907 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5911 if ($deposit_percent >= 0) {
5912 $out .=
' <span id="' . $htmlname .
'_deposit_percent_container"' . (empty($selectedDepositPercent) ?
' style="display: none"' :
'') .
'>';
5913 $out .= $langs->trans(
'DepositPercent') .
' : ';
5914 $out .=
'<input id="' . $htmlname .
'_deposit_percent" name="' . $htmlname .
'_deposit_percent" class="maxwidth50" value="' . $deposit_percent .
'" />';
5917 <script nonce="' .
getNonce() .
'">
5918 $(document).ready(function () {
5919 let $select = $("#' . $htmlname .
'");
5920 let $container = $("#' . $htmlname .
'_deposit_percent_container");
5921 let $input = $("#' . $htmlname .
'_deposit_percent");
5923 function refreshDepositPercent(isInit) {
5924 let depositPercent = $select.find("option:selected").attr("data-deposit_percent") || "";
5926 if (depositPercent.length > 0) {
5928 // On page load, keep an existing (possibly customized) value; on user change use the payment term default
5929 if (!isInit || !parseFloat($input.val())) {
5930 $input.val(depositPercent);
5937 $select.change(function () {
5938 refreshDepositPercent(false);
5942 // Initialize on load so a default payment term with a deposit is reflected without a manual change
5943 refreshDepositPercent(true);
5966 $this->load_cache_rule_for_lines_dates();
5968 $out .=
'<select id="' . $htmlname .
'" class="flat selectbillingterm" name="' . $htmlname .
'">';
5970 $out .=
'<option value="-1"> </option>';
5974 foreach ($this->cache_rule_for_lines_dates as $rule_for_lines_dates_key => $rule_for_lines_dates_name) {
5975 if ($selected == $rule_for_lines_dates_key) {
5976 $out .=
'<option value="' . $rule_for_lines_dates_key .
'" selected>';
5978 $out .=
'<option value="' . $rule_for_lines_dates_key .
'">';
5981 $out .= $langs->trans($rule_for_lines_dates_name);
5982 $out .=
'</option>';
5984 $out .=
'</select>';
6010 public function select_types_paiements($selected =
'', $htmlname =
'paiementtype', $filtertype =
'', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'', $nooutput = 0)
6013 global $langs, $user;
6017 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $filtertype .
", " . $format, LOG_DEBUG);
6019 $filterarray = array();
6020 if ($filtertype ==
'CRDT') {
6021 $filterarray = array(0, 2, 3);
6022 } elseif ($filtertype ==
'DBIT') {
6023 $filterarray = array(1, 2, 3);
6024 } elseif ($filtertype !=
'' && $filtertype !=
'-1') {
6025 $filterarray = explode(
',', $filtertype);
6028 $this->load_cache_types_paiements();
6031 if (empty($selected) && strpos($htmlname,
'search_') !== 0 &&
getDolGlobalString(
'MAIN_DEFAULT_PAYMENT_TYPE_ID')) {
6032 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TYPE_ID", LOG_NOTICE);
6036 $out .=
'<select id="select' . $htmlname .
'" class="flat selectpaymenttypes' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
6038 $out .=
'<option value=""> </option>';
6040 foreach ($this->cache_types_paiements as
$id => $arraytypes) {
6042 if ($active >= 0 && $arraytypes[
'active'] != $active) {
6047 if (count($filterarray) && !in_array($arraytypes[
'type'], $filterarray)) {
6052 if ($empty && empty($arraytypes[
'code'])) {
6057 $out .=
'<option value="' .
$id .
'" data-code="'.$arraytypes[
'code'].
'"';
6058 } elseif ($format == 1) {
6059 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
6060 } elseif ($format == 2) {
6061 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
6062 } elseif ($format == 3) {
6063 $out .=
'<option value="' .
$id .
'"';
6066 if ($format == 1 || $format == 2) {
6067 if ($selected == $arraytypes[
'code']) {
6068 $out .=
' selected';
6071 if ($selected ==
$id) {
6072 $out .=
' selected';
6078 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
6079 } elseif ($format == 1) {
6080 $value = $arraytypes[
'code'];
6081 } elseif ($format == 2) {
6082 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
6083 } elseif ($format == 3) {
6084 $value = $arraytypes[
'code'];
6086 $out .= $value ? $value :
' ';
6087 $out .=
'</option>';
6089 $out .=
'</select>';
6090 if ($user->admin && !$noadmininfo) {
6091 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
6095 if (empty($nooutput)) {
6115 $return =
'<select class="flat maxwidth100" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
6117 'HT' => $langs->trans(
"HT"),
6118 'TTC' => $langs->trans(
"TTC")
6120 foreach ($options as
$id => $value) {
6121 if ($selected ==
$id) {
6122 $return .=
'<option value="' .
$id .
'" selected>' . $value;
6124 $return .=
'<option value="' .
$id .
'">' . $value;
6126 $return .=
'</option>';
6128 $return .=
'</select>';
6148 $num = count($this->cache_transport_mode);
6155 $this->cache_transport_mode = array();
6157 $sql =
"SELECT rowid, code, label, active";
6158 $sql .=
" FROM " . $this->db->prefix() .
"c_transport_mode";
6159 $sql .=
" WHERE entity IN (" .
getEntity(
'c_transport_mode') .
")";
6161 $resql = $this->db->query($sql);
6163 $num = $this->db->num_rows($resql);
6166 $obj = $this->db->fetch_object($resql);
6169 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) !=
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
6170 $this->cache_transport_mode[(int) $obj->rowid]
6172 'rowid' => (
int) $obj->rowid,
6173 'code' => (string) $obj->code,
6174 'label' => (
string) $label,
6175 'active' => (int) $obj->active,
6180 $this->cache_transport_mode =
dol_sort_array($this->cache_transport_mode,
'label',
'asc', 0, 0, 1);
6184 dol_print_error($this->db);
6202 public function selectTransportMode($selected =
'', $htmlname =
'transportmode', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'')
6204 global $langs, $user;
6206 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $format, LOG_DEBUG);
6208 $this->load_cache_transport_mode();
6210 print
'<select id="select' . $htmlname .
'" class="flat selectmodetransport' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
6212 print
'<option value=""> </option>';
6214 foreach ($this->cache_transport_mode as
$id => $arraytypes) {
6216 if ($active >= 0 && $arraytypes[
'active'] != $active) {
6221 if ($empty && empty($arraytypes[
'code'])) {
6226 print
'<option value="' .
$id .
'"';
6227 } elseif ($format == 1) {
6228 print
'<option value="' . $arraytypes[
'code'] .
'"';
6229 } elseif ($format == 2) {
6230 print
'<option value="' . $arraytypes[
'code'] .
'"';
6231 } elseif ($format == 3) {
6232 print
'<option value="' .
$id .
'"';
6235 if (preg_match(
'/[a-z]/i', $selected) && $selected == $arraytypes[
'code']) {
6237 } elseif ($selected ==
$id) {
6243 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
6244 } elseif ($format == 1) {
6245 $value = $arraytypes[
'code'];
6246 } elseif ($format == 2) {
6247 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
6248 } elseif ($format == 3) {
6249 $value = $arraytypes[
'code'];
6251 print $value ? $value :
' ';
6258 if ($user->admin && !$noadmininfo) {
6259 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
6275 public function selectShippingMethod($selected =
'', $htmlname =
'shipping_method_id', $filtre =
'', $useempty = 0, $moreattrib =
'', $noinfoadmin = 0, $morecss =
'')
6277 global $langs, $user;
6279 $langs->loadLangs(array(
"admin",
"sendings"));
6281 $sql =
"SELECT rowid, code, libelle as label";
6282 $sql .=
" FROM " . $this->db->prefix() .
"c_shipment_mode";
6283 $sql .=
" WHERE active > 0";
6287 $sql .=
" ORDER BY libelle ASC";
6289 dol_syslog(get_class($this) .
"::selectShippingMode", LOG_DEBUG);
6291 $result = $this->db->query($sql);
6293 $num = $this->db->num_rows($result);
6296 print
'<select id="select' . $htmlname .
'" class="flat selectshippingmethod' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
6297 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
6298 print
'<option value="-1"> </option>';
6301 $obj = $this->db->fetch_object($result);
6302 if ($selected == $obj->rowid) {
6303 print
'<option value="' . $obj->rowid .
'" selected>';
6305 print
'<option value="' . $obj->rowid .
'">';
6307 print ($langs->trans(
"SendingMethod" . strtoupper($obj->code)) !=
"SendingMethod" . strtoupper($obj->code)) ? $langs->trans(
"SendingMethod" . strtoupper($obj->code)) : $obj->label;
6312 if ($user->admin && empty($noinfoadmin)) {
6313 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
6318 print $langs->trans(
"NoShippingMethodDefined");
6321 dol_print_error($this->db);
6338 $langs->load(
"sendings");
6340 if ($htmlname !=
"none") {
6341 print
'<form method="POST" action="' . $page .
'">';
6342 print
'<input type="hidden" name="action" value="setshippingmethod">';
6343 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6344 $this->selectShippingMethod($selected, $htmlname,
'', $addempty);
6345 print
'<input type="submit" class="button valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6349 $code = $langs->getLabelFromKey($this->db, $selected,
'c_shipment_mode',
'rowid',
'code');
6350 print $langs->trans(
"SendingMethod" . strtoupper($code));
6369 $langs->load(
'bills');
6373 $sql =
"SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc";
6374 $sql .=
' FROM ' . $this->db->prefix() .
'facture';
6375 $sql .=
' WHERE entity IN (' .
getEntity(
'invoice') .
')';
6376 $sql .=
' AND situation_counter >= 1';
6377 $sql .=
' AND fk_soc = ' . (int) $socid;
6378 $sql .=
' AND type <> 2';
6379 $sql .=
' ORDER by situation_cycle_ref, situation_counter desc';
6380 $resql = $this->db->query($sql);
6382 $nbSituationInvoiceForThirdparty = 0;
6384 if ($resql && $this->db->num_rows($resql) > 0) {
6387 while ($obj = $this->db->fetch_object($resql)) {
6389 if ($obj->situation_cycle_ref != $ref) {
6391 $ref = $obj->situation_cycle_ref;
6393 if ($obj->situation_final != 1) {
6395 if (substr($obj->ref, 1, 4) !=
'PROV') {
6396 $nbSituationInvoiceForThirdparty++;
6398 if ($selected == $obj->rowid) {
6399 $opt .=
'<option value="' . $obj->rowid .
'" selected>' . $obj->ref .
'</option>';
6401 $opt .=
'<option value="' . $obj->rowid .
'">' . $obj->ref .
'</option>';
6408 dol_syslog(
"Error sql=" . $sql .
", error=" . $this->error, LOG_ERR);
6411 if ($nbSituationInvoiceForThirdparty > 0) {
6412 $opt =
'<option class="minwidth100" value="" selected> </option>'.$opt;
6414 $opt =
'<option class="minwidth100" value="-1" selected>'.$langs->trans(
'NoSituations').
'</option>';
6429 public function selectUnits($selected =
'', $htmlname =
'units', $showempty = 0, $unit_type =
'')
6433 $langs->load(
'products');
6435 $return =
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'">';
6437 $sql =
"SELECT rowid, label, code FROM " . $this->db->prefix() .
"c_units";
6438 $sql .=
' WHERE active > 0';
6439 if (!empty($unit_type)) {
6440 $sql .=
" AND unit_type = '" . $this->db->escape($unit_type) .
"'";
6442 $sql .=
" ORDER BY sortorder";
6444 $resql = $this->db->query($sql);
6445 if ($resql && $this->db->num_rows($resql) > 0) {
6447 $return .=
'<option value="-1"></option>';
6450 while ($res = $this->db->fetch_object($resql)) {
6451 $unitLabel = $res->label;
6452 if (!empty($langs->tab_translate[
'unit' . $res->code])) {
6453 $unitLabel = $langs->trans(
'unit' . $res->code) != $res->label ? $langs->trans(
'unit' . $res->code) : $res->label;
6456 if ($selected == $res->rowid) {
6457 $return .=
'<option value="' . $res->rowid .
'" selected>' . $unitLabel .
'</option>';
6459 $return .=
'<option value="' . $res->rowid .
'">' . $unitLabel .
'</option>';
6462 $return .=
'</select>';
6486 public function select_comptes($selected =
'', $htmlname =
'accountid', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'', $showcurrency = 0, $morecss =
'', $nooutput = 0, $addentrynone = 0)
6493 $langs->loadLangs(array(
"admin",
"banks"));
6496 $sql =
"SELECT rowid, label, bank, clos as status, currency_code";
6497 $sql .=
" FROM " . $this->db->prefix() .
"bank_account";
6498 $sql .=
" WHERE entity IN (" .
getEntity(
'bank_account') .
")";
6500 $sql .=
" AND clos = " . (int) $status;
6505 $sql .=
" ORDER BY label";
6507 dol_syslog(get_class($this) .
"::select_comptes", LOG_DEBUG);
6508 $result = $this->db->query($sql);
6510 $num = $this->db->num_rows($result);
6513 $out .=
'<select id="select' . $htmlname .
'" class="flat selectbankaccount' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
6517 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoActiveBankAccountDefined") .
'</span>';
6519 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoBankAccountDefined") .
'</span>';
6522 if (!empty($useempty) && !is_numeric($useempty)) {
6523 $out .=
'<option value="-1">'.$langs->trans($useempty).
'</option>';
6524 } elseif ($useempty == 1 || ($useempty == 2 && $num > 1)) {
6525 $out .=
'<option value="-1"> </option>';
6530 $obj = $this->db->fetch_object($result);
6532 $labeltoshow = trim($obj->label);
6533 $labeltoshowhtml = trim($obj->label);
6534 if ($showcurrency) {
6535 $labeltoshow .=
' (' . $obj->currency_code .
')';
6536 $labeltoshowhtml .=
' <span class="opacitymedium">(' . $obj->currency_code .
')</span>';
6538 if ($status == 2 && $obj->status == 1) {
6539 $labeltoshow .=
' (' . $langs->trans(
"Closed") .
')';
6540 $labeltoshowhtml .=
' <span class="opacitymedium">(' . $langs->trans(
"Closed") .
')</span>';
6543 if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
6544 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml).
'" selected>';
6546 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml).
'">';
6548 $out .= $labeltoshow;
6549 $out .=
'</option>';
6553 if (!empty($addentrynone)) {
6554 $out .=
'<option value="-2"'.($selected == -2 ?
' selected="selected"' :
'').
' data-html="'.dolPrintHTMLForAttribute(
'<span class="opacitymedium">'.$langs->trans(
"None").
'</span>').
'">'.$langs->trans(
"None").
'</option>';
6557 $out .=
"</select>";
6560 dol_print_error($this->db);
6564 if (empty($nooutput)) {
6586 public function selectRib($selected =
'', $htmlname =
'ribcompanyid', $filtre =
'', $useempty = 0, $moreattrib =
'', $showibanbic = 0, $morecss =
'', $nooutput = 0)
6593 $langs->loadLangs(array(
"admin",
"banks"));
6596 $sql =
"SELECT rowid, label, bank, status, iban_prefix, bic, default_rib";
6597 $sql .=
" FROM " . $this->db->prefix() .
"societe_rib";
6598 $sql .=
" WHERE type = 'ban'";
6602 $sql .=
" ORDER BY label";
6603 dol_syslog(get_class($this) .
"::select_comptes", LOG_DEBUG);
6604 $result = $this->db->query($sql);
6606 $num = $this->db->num_rows($result);
6609 $out .=
'<select id="select' . $htmlname .
'" class="flat selectbankaccount' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
6612 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoBankAccountDefined") .
'</span>';
6614 if (!empty($useempty) && !is_numeric($useempty)) {
6615 $out .=
'<option value="-1">'.$langs->trans($useempty).
'</option>';
6616 } elseif ($useempty == 1 || ($useempty == 2 && $num > 1)) {
6617 $out .=
'<option value="-1"> </option>';
6622 $obj = $this->db->fetch_object($result);
6624 if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
6625 $out .=
'<option value="' . $obj->rowid .
'" data-iban-prefix="' . $iban .
' data-bic="' . $obj->bic .
'" selected>';
6627 $out .=
'<option value="' . $obj->rowid .
'" data-iban-prefix="' . $iban .
' data-bic="' . $obj->bic .
'">';
6629 $out .= trim($obj->label);
6631 $out .=
' (' . $iban .
'/' .$obj->bic.
')' . ($obj->default_rib ?
' ['.$langs->trans(
"ByDefault").
']' :
'');
6633 $out .=
'</option>';
6636 $out .=
"</select>";
6639 dol_print_error($this->db);
6643 if (empty($nooutput)) {
6663 public function selectEstablishments($selected =
'', $htmlname =
'entity', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'')
6667 $langs->load(
"admin");
6670 $sql =
"SELECT rowid, name, fk_country, status, entity";
6671 $sql .=
" FROM " . $this->db->prefix() .
"establishment";
6672 $sql .=
" WHERE 1=1";
6674 $sql .=
" AND status = " . (int) $status;
6679 $sql .=
" ORDER BY name";
6681 dol_syslog(get_class($this) .
"::select_establishment", LOG_DEBUG);
6682 $result = $this->db->query($sql);
6684 $num = $this->db->num_rows($result);
6687 print
'<select id="select' . $htmlname .
'" class="flat selectestablishment" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
6688 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
6689 print
'<option value="-1"> </option>';
6693 $obj = $this->db->fetch_object($result);
6694 if ($selected == $obj->rowid) {
6695 print
'<option value="' . $obj->rowid .
'" selected>';
6697 print
'<option value="' . $obj->rowid .
'">';
6699 print trim($obj->name);
6700 if ($status == 2 && $obj->status == 1) {
6701 print
' (' . $langs->trans(
"Closed") .
')';
6709 print
'<span class="opacitymedium">' . $langs->trans(
"NoActiveEstablishmentDefined") .
'</span>';
6711 print
'<span class="opacitymedium">' . $langs->trans(
"NoEstablishmentFound") .
'</span>';
6717 dol_print_error($this->db);
6734 if ($htmlname !=
"none") {
6735 print
'<form method="POST" action="' . $page .
'">';
6736 print
'<input type="hidden" name="action" value="setbankaccount">';
6737 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6738 print img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
6739 $nbaccountfound = $this->select_comptes($selected, $htmlname, 0,
'', $addempty);
6740 if ($nbaccountfound > 0) {
6741 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6745 $langs->load(
'banks');
6748 require_once DOL_DOCUMENT_ROOT .
'/compta/bank/class/account.class.php';
6749 $bankstatic =
new Account($this->db);
6750 $result = $bankstatic->fetch((
int) $selected);
6752 print $bankstatic->getNomUrl(1);
6771 public function formRib($page, $selected =
'', $htmlname =
'ribcompanyid', $filtre =
'', $addempty = 0, $showibanbic = 0)
6774 if ($htmlname !=
"none") {
6775 print
'<form method="POST" action="' . $page .
'">';
6776 print
'<input type="hidden" name="action" value="setbankaccountcustomer">';
6777 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6778 $nbaccountfound = $this->selectRib($selected, $htmlname, $filtre, $addempty,
'', $showibanbic);
6779 if ($nbaccountfound > 0) {
6780 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6784 $langs->load(
'banks');
6787 require_once DOL_DOCUMENT_ROOT .
'/societe/class/companybankaccount.class.php';
6789 $result = $bankstatic->fetch((
int) $selected);
6791 print $bankstatic->label;
6793 print
' (' . $bankstatic->iban .
'/' .$bankstatic->bic.
')';
6817 $cate_arbo = $this->select_all_categories($categtype,
'',
'', 64, 0, 3);
6819 $arrayselected = array();
6821 $arrayselected =
GETPOST($htmlname,
'array:int');
6824 $cats =
$c->containing(
$object->id, $categtype);
6825 $arrayselected = array();
6826 foreach ($cats as $cat) {
6827 $arrayselected[] = $cat->id;
6831 $out .= img_picto(
'',
'category',
'class="pictofixedwidth"');
6832 $out .= $this->multiselectarray($htmlname, $cate_arbo, $arrayselected, 0, 0,
'minwidth100 widthcentpercentminusxx', 0, 0);
6836 $jsonclose =
'doJsCodeAfterPopupClose'.dol_sanitizeKeyCode($htmlname).
'()';
6837 $urltoopen =
'/categories/categorie_list.php?type='.urlencode($categtype).
'&nosearch=1';
6839 $s =
dolButtonToOpenUrlInDialogPopup($htmlname, $langs->transnoentitiesnoconv(
"Categories"), img_picto(
'',
'add',
'class="editfielda"'), $urltoopen,
'',
'',
'', $jsonclose);
6842 $out .=
'<!-- Add js code to open the popup for category/edit/add -->'.
"\n";
6843 $out .=
'<script>function doJsCodeAfterPopupClose'.dol_sanitizeKeyCode($htmlname).
'() {
6844 console.log("doJsCodeAfterPopupClose'.
dol_sanitizeKeyCode($htmlname).
' has been called, we refresh the combo content + refresh select2...");
6846 // Call an ajax to reload values and update the select
6849 url: \''.DOL_URL_ROOT.
'/core/ajax/fetchCategories.php\',
6851 action: \'getCategories\',
6856 success: function (data) {
6857 var $select = $(\'#'.dol_sanitizeKeyCode($htmlname).
'\');
6858 var selectedValues = $select.val();
6859 console.log(selectedValues);
6861 $.each(data,
function (index, item) {
6862 $select.append(\
'<option value="\' + item.id + \'" data-html="\' + item.htmlforattribute + \'">\' + item.htmlforoption + \'</option>\');
6864 $select.val(selectedValues);
6866 error: function (xhr, status, error) {
6867 console.log("Error when loading ajax page : " + error);
6871 // Refresh select2 to take account of new values (enough for small change)
6874 // Alternative if change in select is complex
6906 public function select_all_categories($type, $selected =
'', $htmlname =
"parent", $maxlength = 64, $fromid = 0, $outputmode = 0, $include = 0, $morecss =
'', $useempty = 1)
6911 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
6915 if (is_numeric($type)) {
6916 $type = array_search($type, $cat->MAP_ID);
6919 $cate_arbo = $cat->get_full_arbo($type, $fromid, $include);
6921 $outarray = array();
6922 $outarrayrichhtml = array();
6925 $output =
'<select class="flat minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
6927 if (is_array($cate_arbo)) {
6928 $num = count($cate_arbo);
6931 $langs->load(
"categories");
6932 $output .=
'<option value="-1" disabled>' . $langs->trans(
"NoCategoriesDefined") .
'</option>';
6934 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
6935 $output .=
'<option value="-1"> </option>';
6937 foreach ($cate_arbo as $key => $value) {
6938 if ($cate_arbo[$key][
'id'] == $selected || ($selected ===
'auto' && count($cate_arbo) == 1)) {
6944 $labeltoshow = img_picto(
'',
'category',
'class="pictofixedwidth"'.(empty($cate_arbo[$key][
'color']) ?
'' :
' style="color: #' . $cate_arbo[$key][
'color'] .
'"'));
6945 $labeltoshow .=
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle');
6947 $outarray[$cate_arbo[$key][
'id']] = $cate_arbo[$key][
'fulllabel'];
6949 $outarrayrichhtml[$cate_arbo[$key][
'id']] = $labeltoshow;
6951 $output .=
'<option ' . $add .
'value="' . $cate_arbo[$key][
'id'] .
'"';
6960 $output .=
'</option>';
6962 $cate_arbo[$key][
'data-html'] = $labeltoshow;
6966 $output .=
'</select>';
6971 if ($outputmode == 2) {
6974 } elseif ($outputmode == 1) {
6976 } elseif ($outputmode == 3) {
6977 return $outarrayrichhtml;
6997 $html =
'<details class="dolibarr-help-block" style="margin-top:8px;">';
6998 $html .=
'<summary style="cursor:pointer; color:#0056b3; font-weight:normal; list-style:none; font-size:0.9em; display:flex; align-items:center;">';
6999 $html .=
'<span class="fa ' . $icon .
'" style="margin-right:6px;"></span>';
7000 $html .= $langs->trans(
"Help");
7001 $html .=
'</summary>';
7002 $html .=
'<div style="margin-top:6px; padding:10px; background:#f8f9fa; border:1px solid #dee2e6; border-radius:4px; font-size:0.9em; color:#555; line-height:1.5;">';
7005 $html .=
'</details>';
7030 public function form_confirm($page, $title, $question, $action, $formquestion = array(), $selectedchoice =
"", $useajax = 0, $height = 170, $width = 500)
7033 dol_syslog(__METHOD__ .
': using form_confirm is deprecated. Use formconfim instead.', LOG_WARNING);
7034 print $this->formconfirm($page, $title, $question, $action, $formquestion, $selectedchoice, $useajax, $height, $width);
7068 public function formconfirm($page, $title, $question, $action, $formquestion =
'', $selectedchoice =
'', $useajax = 0, $height = 0, $width = 600, $disableformtag = 0, $labelbuttonyes =
'Yes', $labelbuttonno =
'No', $helpContent =
'', $labelbuttonother =
'', $valuebuttonother =
'other')
7070 global $langs,
$conf;
7073 $formconfirm =
'<!-- formconfirm - before call, page=' .
dol_escape_htmltag($page) .
' -->';
7079 $newselectedchoice = empty($selectedchoice) ?
"no" : $selectedchoice;
7080 if (
$conf->browser->layout ==
'phone') {
7085 if (empty($height)) {
7087 if (is_array($formquestion)) {
7089 foreach ($formquestion as $input) {
7091 if (is_array($input) && (!isset($input[
'type']) || $input[
'type'] !=
'hidden')) {
7095 $height += ($nbofquestions * 40);
7102 if (is_array($formquestion) && !empty($formquestion)) {
7104 foreach ($formquestion as $key => $input) {
7105 if (is_array($input) && !empty($input)) {
7106 if ($input[
'type'] ==
'hidden') {
7107 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
7108 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
7116 $moreonecolumn =
'';
7117 $more .=
'<div class="tagtable paddingtopbottomonly centpercent noborderspacing">' .
"\n";
7118 foreach ($formquestion as $key => $input) {
7119 if (is_array($input) && !empty($input)) {
7120 $size = (!empty($input[
'size']) ?
' size="' . $input[
'size'] .
'"' :
'');
7121 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
7122 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
7124 if ($input[
'type'] ==
'text' || $input[
'type'] ==
'input') {
7125 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">' . ($input[
'label'] ??
'') .
'</div><div class="tagtd"><input type="text" class="flat' . $morecss .
'" id="' .
dol_escape_htmltag($input[
'name']) .
'" name="' .
dol_escape_htmltag($input[
'name']) .
'"' . $size .
' value="' . (empty($input[
'value']) ?
'' : $input[
'value']) .
'"' . $moreattr .
' spellcheck="false" /></div></div>' .
"\n";
7126 } elseif ($input[
'type'] ==
'password') {
7127 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">' . ($input[
'label'] ??
'') .
'</div><div class="tagtd"><input type="password" class="flat' . $morecss .
'" id="' .
dol_escape_htmltag($input[
'name']) .
'" name="' .
dol_escape_htmltag($input[
'name']) .
'"' . $size .
' value="' . (empty($input[
'value']) ?
'' : $input[
'value']) .
'"' . $moreattr .
' /></div></div>' .
"\n";
7128 } elseif ($input[
'type'] ==
'textarea') {
7129 $moreonecolumn .=
'<div class="margintoponly">';
7130 $moreonecolumn .= ($input[
'label'] ??
'') .
'<br>';
7132 $moreonecolumn .= $input[
'value'] ??
'';
7133 $moreonecolumn .=
'</textarea>';
7134 $moreonecolumn .=
'</div>';
7135 } elseif (in_array($input[
'type'], [
'select',
'multiselect'])) {
7136 if (empty($morecss)) {
7137 $morecss =
'minwidth100';
7140 $show_empty = isset($input[
'select_show_empty']) ? $input[
'select_show_empty'] : 1;
7141 $key_in_label = isset($input[
'select_key_in_label']) ? $input[
'select_key_in_label'] : 0;
7142 $value_as_key = isset($input[
'select_value_as_key']) ? $input[
'select_value_as_key'] : 0;
7143 $translate = isset($input[
'select_translate']) ? $input[
'select_translate'] : 0;
7144 $maxlen = isset($input[
'select_maxlen']) ? $input[
'select_maxlen'] : 0;
7145 $disabled = isset($input[
'select_disabled']) ? $input[
'select_disabled'] : 0;
7146 $sort = isset($input[
'select_sort']) ? $input[
'select_sort'] :
'';
7148 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">';
7149 if (!empty($input[
'label'])) {
7150 $more .= $input[
'label'] .
'</div><div class="tagtd left">';
7152 if ($input[
'type'] ==
'select') {
7153 $more .= $this->selectarray($input[
'name'], $input[
'values'], isset($input[
'default']) ? $input[
'default'] :
'-1', $show_empty, $key_in_label, $value_as_key, $moreattr, $translate, $maxlen, $disabled, $sort, $morecss);
7155 $more .= $this->multiselectarray($input[
'name'], $input[
'values'], is_array($input[
'default']) ? $input[
'default'] : [$input[
'default']], $key_in_label, $value_as_key, $morecss, $translate, $maxlen, $moreattr);
7157 $more .=
'</div></div>' .
"\n";
7158 } elseif ($input[
'type'] ==
'checkbox') {
7159 $more .=
'<div class="tagtr">';
7160 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'"><label for="' .
dol_escape_htmltag($input[
'name']) .
'">' . $input[
'label'] .
'</label></div><div class="tagtd">';
7161 $more .=
'<input type="checkbox" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' .
dol_escape_htmltag($input[
'name']) .
'" name="' .
dol_escape_htmltag($input[
'name']) .
'"' . $moreattr;
7162 if (isset($input[
'value']) && !is_bool($input[
'value']) && $input[
'value'] !=
'false' && $input[
'value'] !=
'0' && $input[
'value'] !=
'') {
7163 $more .=
' checked';
7165 if (isset($input[
'value']) && is_bool($input[
'value']) && $input[
'value']) {
7166 $more .=
' checked';
7168 if (isset($input[
'disabled'])) {
7169 $more .=
' disabled';
7171 $more .=
' /></div>';
7172 $more .=
'</div>' .
"\n";
7173 } elseif ($input[
'type'] ==
'radio') {
7175 foreach ($input[
'values'] as $selkey => $selval) {
7176 $more .=
'<div class="tagtr">';
7177 if (isset($input[
'label'])) {
7179 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
' tdtop' : (
' tdtop ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
7181 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' "' . $input[
'tdclass'])) .
'"> </div>';
7184 $more .=
'<div class="tagtd' . ($i == 0 ?
' tdtop' :
'') .
'"><input type="radio" class="flat' . $morecss .
'" id="' .
dol_escape_htmltag($input[
'name'] . $selkey) .
'" name="' .
dol_escape_htmltag($input[
'name']) .
'" value="' . $selkey .
'"' . $moreattr;
7185 if (!empty($input[
'disabled'])) {
7186 $more .=
' disabled';
7188 if (isset($input[
'default']) && $input[
'default'] === $selkey) {
7189 $more .=
' checked="checked"';
7192 $more .=
'<label for="' .
dol_escape_htmltag($input[
'name'] . $selkey) .
'" class="valignmiddle">' . $selval .
'</label>';
7193 $more .=
'</div></div>' .
"\n";
7196 } elseif ($input[
'type'] ==
'date' || $input[
'type'] ==
'datetime') {
7197 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
7198 $more .=
'<div class="tagtd">';
7199 $addnowlink = (empty($input[
'datenow']) ? 0 : 1);
7201 if ($input[
'type'] ==
'datetime') {
7202 $h = isset($input[
'hours']) ? $input[
'hours'] : 1;
7203 $m = isset($input[
'minutes']) ? $input[
'minutes'] : 1;
7205 $more .= $this->selectDate(isset($input[
'value']) ? $input[
'value'] : -1, $input[
'name'], $h, $m, 0,
'', 1, $addnowlink);
7206 $more .=
'</div></div>'.
"\n";
7207 $formquestion[] = array(
'name' => $input[
'name'].
'day');
7208 $formquestion[] = array(
'name' => $input[
'name'].
'month');
7209 $formquestion[] = array(
'name' => $input[
'name'].
'year');
7210 $formquestion[] = array(
'name' => $input[
'name'].
'hour');
7211 $formquestion[] = array(
'name' => $input[
'name'].
'min');
7212 } elseif ($input[
'type'] ==
'other') {
7213 $more .=
'<div class="tagtr"><div class="tagtd'.(empty($input[
'tdclass']) ?
'' : (
' '.$input[
'tdclass'])).
'">';
7214 if (!empty($input[
'label'])) {
7215 $more .= $input[
'label'] .
'</div><div class="tagtd">';
7217 if (!empty($input[
'value'])) {
7218 $more .= $input[
'value'];
7220 $more .=
'</div></div>' .
"\n";
7221 } elseif ($input[
'type'] ==
'onecolumn') {
7222 $moreonecolumn .=
'<div class="margintoponly">';
7223 $moreonecolumn .= $input[
'value'] ??
'';
7224 $moreonecolumn .=
'</div>' .
"\n";
7225 } elseif ($input[
'type'] ==
'hidden') {
7227 } elseif ($input[
'type'] ==
'separator') {
7230 $more .=
'Error type ' . $input[
'type'] .
' for the confirm box is not a supported type';
7234 $more .=
'</div>' .
"\n";
7235 $more .= $moreonecolumn;
7241 if (!empty(
$conf->dol_use_jmobile)) {
7244 if (empty(
$conf->use_javascript_ajax)) {
7250 $dialogconfirm =
'dialog-confirm';
7252 if (!is_numeric($useajax)) {
7256 $dialogconfirm .=
'-' . $button;
7258 $pageyes = $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=yes';
7259 $pageno = ($useajax == 2 ? $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=no' :
'');
7262 if (is_array($formquestion)) {
7263 foreach ($formquestion as $key => $input) {
7266 if (is_array($input) && isset($input[
'name'])) {
7267 if (strpos($input[
'name'],
',') > 0) {
7268 $inputok = array_merge($inputok, explode(
',', $input[
'name']));
7270 array_push($inputok, $input[
'name']);
7275 if (is_array($input) && isset($input[
'inputko']) && $input[
'inputko'] == 1 && isset($input[
'name'])) {
7276 array_push($inputko, $input[
'name']);
7283 $formconfirm .=
'<div id="' . $dialogconfirm .
'" title="' .
dol_escape_htmltag($title) .
'" style="display: none;">';
7284 $formconfirm .=
'<div style="display: flex; flex-direction: column; height: 100%;">';
7285 if (is_array($formquestion) && array_key_exists(
'text', $formquestion) && !empty($formquestion[
'text'])) {
7286 $formconfirm .=
'<div class="confirmtext">' . $formquestion[
'text'] .
'</div>' .
"\n";
7288 if (!empty($more)) {
7289 $formconfirm .=
'<div class="confirmquestions">' . $more .
'</div>' .
"\n";
7292 if (!empty($helpContent)) {
7293 $formconfirm .=
'<div style="text-align:left; margin-top:12px; padding-top:8px; border-top:1px solid #eee; clear:both;">';
7294 $formconfirm .= $this->getHelpBlock($helpContent);
7295 $formconfirm .=
'</div>';
7297 if (!empty($question)) {
7298 $formconfirm .=
'<div class="confirmmessage" style="padding-top: 15px;">';
7299 $formconfirm .= img_help(0,
'') .
' ' . $question;
7300 $formconfirm .=
'</div>';
7302 $formconfirm .=
'</div>';
7303 $formconfirm .=
'</div>' .
"\n";
7305 $formconfirm .=
"\n<!-- begin code of popup for formconfirm page=" . $page .
" -->\n";
7306 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
7307 $formconfirm .=
"/* Code for the jQuery('#dialogforpopup').dialog() */\n";
7308 $formconfirm .=
'jQuery(document).ready(function() {
7310 $( "#' . $dialogconfirm .
'" ).dialog({
7311 autoOpen: ' . ($autoOpen ?
"true" :
"false") .
',';
7312 if ($newselectedchoice ==
'no') {
7315 $(this).parent().find("button.ui-button:eq(2)").focus();
7320 if ($useajax == 1) {
7321 $jsforcursor =
'// The call to urljump can be slow, so we set the wait cursor' .
"\n";
7322 $jsforcursor .=
'jQuery("html,body,#id-container").addClass("cursorwait");' .
"\n";
7325 $postconfirmas =
'GET';
7326 $maxurllengthforget =
getDolGlobalInt(
'MAIN_MAX_URL_LENGTH_FOR_GET', 2000);
7331 height: \'auto\',' . (is_numeric($height) ?
'
7332 minHeight: ' . ((int) $height) .
',' :
'') .
'
7333 maxHeight: Math.round($(window).height() * 0.9),
7336 closeOnEscape:
false,
7338 text: \
'' .
dol_escape_js($langs->transnoentities($labelbuttonyes)) .
'\',
7340 var options =
"token=' . urlencode(newToken()) . '";
7341 var inputok =
' . json_encode($inputok) . ';
7342 var page = \
'' .
dol_escape_js(!empty($page) ? $page :
'') .
'\';
7343 var pageyes = \
'' .
dol_escape_js(!empty($pageyes) ? $pageyes :
'') .
'\';
7345 if (inputok.length > 0) {
7346 $.each(inputok,
function(i, inputname) {
7349 if ($(
"input[name=\'" + inputname +
"\']").attr(
"type") ==
"radio") {
7350 inputvalue = $(
"input[name=\'" + inputname +
"\']:checked").val();
7352 if ($(
"#" + inputname).attr(
"type") ==
"checkbox") { more =
":checked"; }
7353 inputvalue = $(
"#" + inputname + more).val();
7355 if (typeof inputvalue ==
"undefined") { inputvalue=
""; }
7356 console.log(
"formconfirm check inputname="+inputname+
" inputvalue="+inputvalue);
7357 options +=
"&" + inputname +
"=" + encodeURIComponent(inputvalue);
7360 var urljump = pageyes + (pageyes.indexOf(
"?") < 0 ?
"?" :
"&") + options;
7361 if (pageyes.length > 0) {
';
7362 if ($postconfirmas == 'GET
') {
7363 $formconfirm .= 'dolSubmitConfirmForm(urljump, pageyes, options,
' . $maxurllengthforget . ');
';
7365 $formconfirm .= $jsforcursor;
7366 $formconfirm .= 'var post = $.post(
7369 function(data) { $(
"body").html(data); jQuery(
"html,body,#id-container").removeClass(
"cursorwait"); }
7373 console.log(
"after post ok");
7375 $(
this).dialog(
"close");
7378 text: \
'' .
dol_escape_js($langs->transnoentities($labelbuttonno)) .
'\',
7380 var options =
"token=' . urlencode(newToken()) . '";
7381 var inputko =
' . json_encode($inputko) . ';
7382 var page = \
'' .
dol_escape_js(!empty($page) ? $page :
'') .
'\';
7383 var pageno=\
'' .
dol_escape_js(!empty($pageno) ? $pageno :
'') .
'\';
7384 if (inputko.length > 0) {
7385 $.each(inputko,
function(i, inputname) {
7387 if ($(
"#" + inputname).attr(
"type") ==
"checkbox") { more =
":checked"; }
7388 var inputvalue = $(
"#" + inputname + more).val();
7389 if (typeof inputvalue ==
"undefined") { inputvalue=
""; }
7390 options +=
"&" + inputname +
"=" + encodeURIComponent(inputvalue);
7393 var urljump=pageno + (pageno.indexOf(
"?") < 0 ?
"?" :
"&") + options;
7395 if (pageno.length > 0) {
';
7396 if ($postconfirmas == 'GET
') {
7397 $formconfirm .= 'dolSubmitConfirmForm(urljump, pageno, options,
' . $maxurllengthforget . ');
';
7399 $formconfirm .= $jsforcursor;
7400 $formconfirm .= 'var post = $.post(
7403 function(data) { $(
"body").html(data); jQuery(
"html,body,#id-container").removeClass(
"cursorwait"); }
7407 console.log(
"after post ko");
7409 $(
this).dialog(
"close");
7412 if ($labelbuttonother !== '') {
7413 $formconfirm .= ', {
7414 text: \
'' .
dol_escape_js($langs->transnoentities($labelbuttonother)) .
'\',
7415 click:
function() {
';
7416 if ($valuebuttonother !== '') {
7417 $pageother = $page . (strpos($page, '?
') === false ? '?
' : '&
') . 'action=
' . urlencode($action) . '&confirm=
' . urlencode($valuebuttonother);
7419 var options =
"token=' . urlencode(newToken()) . '";
7420 var inputok =
' . json_encode($inputok) . ';
7421 var fields = $(
this).find(
":input");
7422 $.each(inputok,
function(i, inputname) {
7423 var field = fields.filter(
function() {
return this.
id === inputname || this.
name === inputname; });
7424 if (field.is(
":radio, :checkbox")) { field = field.filter(
":checked"); }
7425 var inputvalue = field.val();
7426 if (typeof inputvalue ===
"undefined") { inputvalue =
""; }
7427 options +=
"&" + encodeURIComponent(inputname) +
"=" + encodeURIComponent(inputvalue);
7430 var urljump = pageother +
"&" + options;
7431 dolSubmitConfirmForm(urljump, pageother, options,
' . $maxurllengthforget . ');
';
7434 $(
this).dialog(
"close");
7442 var
button =
"' . $button . '";
7444 $(
"#" +
button ).click(
function(e) { e.preventDefault();
7445 $(
"#' . $dialogconfirm . '").dialog(
"open");
7451 $formconfirm .= "<!-- end ajax formconfirm -->\n";
7453 $formconfirm .= "\n<!-- begin formconfirm page=" . dol_escape_htmltag($page) . " -->\n";
7455 if (empty($disableformtag)) {
7456 $formconfirm .= '<form method=
"POST" action=
"' . $page . '" class=
"notoptoleftnoright">
' . "\n";
7459 $formconfirm .= '<input
type=
"hidden" name=
"action" value=
"' . $action . '">
' . "\n";
7460 $formconfirm .= '<input
type=
"hidden" name=
"token" value=
"' . newToken() . '">
' . "\n";
7462 $formconfirm .= '<div
class=
"valid">
' . "\n";
7465 $formconfirm .= '<div
class=
"validtitre">
';
7466 $formconfirm .= img_picto('', 'pictoconfirm
') . ' ' . $title;
7467 $formconfirm .= '</div>
' . "\n";
7470 if (is_array($formquestion) && array_key_exists('text
', $formquestion) && !empty($formquestion['text
'])) {
7471 $formconfirm .= '<div
class=
"valid">
' . $formquestion['text
'] . '</div>
' . "\n";
7476 $formconfirm .= '<div>
' . "\n";
7477 $formconfirm .= $more;
7478 $formconfirm .= '</div>
' . "\n";
7481 // NEW: Help block row (between form fields and question)
7482 if (!empty($helpContent)) {
7483 $formconfirm .= '<div style=
"padding-top:8px; border-top:1px solid #888;">
';
7484 $formconfirm .= $this->getHelpBlock($helpContent);
7485 $formconfirm .= '</div>
' . "\n";
7488 // Let's add a row that acts as a spacer.
7489 $formconfirm .=
'<div style="padding-top: 20px;"></div>' .
"\n";
7492 $formconfirm .=
'<div class="inline-block">' . $question .
'</div>';
7494 $formconfirm .=
'<div class="inline-block">';
7495 if ($labelbuttonother !==
'') {
7496 foreach (array(array(
'confirm',
'yes', $labelbuttonyes), array(
'confirm',
'no', $labelbuttonno), array($valuebuttonother ===
'' ?
'cancel' :
'confirm', $valuebuttonother ===
'' ?
'1' : $valuebuttonother, $labelbuttonother)) as $confirmbutton) {
7497 $formconfirm .=
'<button class="button valignmiddle confirmvalidatebutton small" type="submit" name="' . $confirmbutton[0] .
'" value="' .
dol_escape_htmltag($confirmbutton[1]) .
'"' . ($confirmbutton[0] ===
'cancel' ?
' formnovalidate' :
'') .
'>' .
dol_escape_htmltag($langs->transnoentities($confirmbutton[2])) .
'</button>';
7500 $formconfirm .= $this->selectyesno(
"confirm", $newselectedchoice, 0,
false, 0, 0,
'marginleftonly marginrightonly', $labelbuttonyes, $labelbuttonno);
7501 $formconfirm .=
'<input class="button valignmiddle confirmvalidatebutton small" type="submit" value="' . $langs->trans(
"Validate") .
'">';
7503 $formconfirm .=
'</div>';
7505 $formconfirm .=
'</div>';
7507 if (empty($disableformtag)) {
7508 $formconfirm .=
"</form>\n";
7510 $formconfirm .=
'<br>';
7512 if (!empty(
$conf->use_javascript_ajax)) {
7513 $formconfirm .=
'<!-- code to disable button to avoid double clic -->';
7514 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
7516 $(document).ready(function () {
7517 $(".confirmvalidatebutton").off("click.formconfirm").on("click.formconfirm", function(event) {
7518 event.preventDefault();
7519 var form = $(this).closest("form");
7520 if (form.data("formconfirm-submitting")) { return; }
7521 console.log("We click on button confirmvalidatebutton");
7523 if (!this.formNoValidate && !form[0].reportValidity()) { return; }
7524 $("<input>").attr({type: "hidden", name: this.name, value: this.value, "data-formconfirm-choice": "1"}).appendTo(form);
7526 form.data("formconfirm-submitting", true);
7527 $(this).attr("disabled", "disabled");
7528 setTimeout(function() {
7529 form.removeData("formconfirm-submitting");
7530 form.find(".confirmvalidatebutton").removeAttr("disabled");
7531 form.find("[data-formconfirm-choice]").remove();
7533 //console.log($(this).closest("form"));
7538 $formconfirm .=
'</script>' .
"\n";
7541 $formconfirm .=
"<!-- end formconfirm -->\n";
7544 return $formconfirm;
7565 public function form_project($page, $socid, $selected =
'', $htmlname =
'projectid', $discard_closed = 0, $maxlength = 20, $forcefocus = 0, $nooutput = 0, $textifnoproject =
'', $morecss =
'', $option =
'')
7570 require_once DOL_DOCUMENT_ROOT .
'/core/lib/project.lib.php';
7571 require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formprojet.class.php';
7577 $langs->load(
"project");
7578 if ($htmlname !=
"none") {
7579 $out .=
'<form method="post" action="' . $page .
'">';
7580 $out .=
'<input type="hidden" name="action" value="classin">';
7581 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7582 $out .= $formproject->select_projects($socid, $selected, $htmlname, $maxlength, 0, 1, $discard_closed, $forcefocus, 0, 0,
'', 1, 0, $morecss);
7583 $out .=
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7586 $out .=
'<span class="project_head_block">';
7587 if ($selected instanceof
Project) {
7588 $out .= $selected->getNomUrl(0, $option, 1);
7589 } elseif (is_numeric($selected)) {
7590 $projet =
new Project($this->db);
7591 $projet->fetch((
int) $selected);
7592 $out .= $projet->getNomUrl(0, $option, 1);
7594 $out .=
'<span class="opacitymedium">' . $textifnoproject .
'</span>';
7599 if (empty($nooutput)) {
7623 public function form_conditions_reglement($page, $selected =
'', $htmlname =
'cond_reglement_id', $addempty = 0, $type =
'', $filtertype = -1, $deposit_percent = -1, $nooutput = 0)
7628 $selected = (int) $selected;
7632 if ($htmlname !=
"none") {
7633 $out .=
'<form method="POST" action="' . $page .
'">';
7634 $out .=
'<input type="hidden" name="action" value="setconditions">';
7635 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7637 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
7639 $out .= $this->getSelectConditionsPaiements($selected, $htmlname, $filtertype, $addempty, 0,
'', $deposit_percent);
7640 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7644 $this->load_cache_conditions_paiements();
7646 if (isset($this->cache_conditions_paiements[$selected])) {
7647 $label = $this->cache_conditions_paiements[$selected][
'label'];
7649 if (!empty($this->cache_conditions_paiements[$selected][
'deposit_percent'])) {
7650 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $this->cache_conditions_paiements[$selected][
'deposit_percent'], $label);
7655 $langs->load(
'errors');
7656 $out .= $langs->trans(
'ErrorNotInDictionaryPaymentConditions', $selected);
7663 if (empty($nooutput)) {
7689 if ($htmlname !=
'none') {
7690 $out .=
'<form method="POST" action="' . $page .
'">';
7691 $out .=
'<input type="hidden" name="action" value="setruleforlinesdates">';
7692 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7693 $out .= $this->getSelectRuleForLinesDates($selected, $htmlname, $addempty);
7694 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7697 if (isset($selected)) {
7698 $this->load_cache_rule_for_lines_dates();
7699 if (isset($this->cache_rule_for_lines_dates[$selected])) {
7700 $label = $this->cache_rule_for_lines_dates[$selected];
7701 $out .= $langs->trans($label);
7708 if (empty($nooutput)) {
7732 if ($htmlname !=
"none") {
7733 print
'<form method="post" action="' . $page .
'">';
7734 print
'<input type="hidden" name="action" value="setavailability">';
7735 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7736 print $this->selectAvailabilityDelay($selected, $htmlname,
'', $addempty,
'', 1);
7737 print
'<input type="submit" name="modify" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7738 print
'<input type="submit" name="cancel" class="button smallpaddingimp" value="' . $langs->trans(
"Cancel") .
'">';
7742 $this->load_cache_availability();
7744 if (isset($this->cache_availability[$selected])) {
7745 print $this->cache_availability[$selected][
'label'];
7766 public function formInputReason($page, $selected =
'', $htmlname =
'demandreason', $addempty = 0, $morecss =
'')
7769 if ($htmlname !=
"none") {
7770 print
'<form method="post" action="' . $page .
'">';
7771 print
'<input type="hidden" name="action" value="setdemandreason">';
7772 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7773 $this->selectInputReason($selected, $htmlname,
'-1', $addempty, $morecss);
7774 print
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7778 $this->loadCacheInputReason();
7779 foreach ($this->cache_demand_reason as $key => $val) {
7780 if ($val[
'id'] == $selected) {
7781 print $val[
'label'];
7806 public function form_date($page, $selected, $htmlname, $displayhour = 0, $displaymin = 0, $nooutput = 0, $type =
'')
7813 if ($htmlname !=
"none") {
7814 $ret .=
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
7815 $ret .=
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
7816 $ret .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7818 $ret .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
7820 $ret .=
'<table class="nobordernopadding">';
7822 $ret .= $this->selectDate($selected, $htmlname, $displayhour, $displaymin, 1,
'form' . $htmlname, 1, 0);
7824 $ret .=
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
7825 $ret .=
'</tr></table></form>';
7834 if (empty($nooutput)) {
7853 public function form_users($page, $selected =
'', $htmlname =
'userid', $exclude = array(), $include = array())
7858 if ($htmlname !=
"none") {
7859 print
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
7860 print
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
7861 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7862 print $this->select_dolusers($selected, $htmlname, 1, $exclude, 0, $include);
7863 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7867 require_once DOL_DOCUMENT_ROOT .
'/user/class/user.class.php';
7868 $theuser =
new User($this->db);
7869 $theuser->fetch((
int) $selected);
7870 print $theuser->getNomUrl(1);
7894 public function form_modes_reglement($page, $selected =
'', $htmlname =
'mode_reglement_id', $filtertype =
'', $active = 1, $addempty = 0, $type =
'', $nooutput = 0, $short = 0)
7900 if ($htmlname !=
"none") {
7901 $out .=
'<form method="POST" action="' . $page .
'">';
7902 $out .=
'<input type="hidden" name="action" value="setmode">';
7903 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7905 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
7907 $out .= $this->select_types_paiements($selected, $htmlname, $filtertype, 0, $addempty, 0, 0, $active,
'', 1);
7908 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7911 if ((
int) $selected) {
7912 $this->load_cache_types_paiements();
7914 $out .= $this->cache_types_paiements[(int) $selected][
'shortlabel'] ??
' ';
7916 $out .= $this->cache_types_paiements[(int) $selected][
'label'] ??
' ';
7944 if ($htmlname !=
"none") {
7945 print
'<form method="POST" action="' . $page .
'">';
7946 print
'<input type="hidden" name="action" value="settransportmode">';
7947 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7948 $this->selectTransportMode($selected, $htmlname, 0, $addempty, 0, 0, $active);
7949 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7953 $this->load_cache_transport_mode();
7954 print $this->cache_transport_mode[$selected][
'label'];
7975 if ($htmlname !=
"none") {
7976 print
'<form method="POST" action="' . $page .
'">';
7977 print
'<input type="hidden" name="action" value="setmulticurrencycode">';
7978 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7979 print $this->selectMultiCurrency($selected, $htmlname, 0);
7980 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7983 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
7984 print !empty($selected) ?
currency_name($selected, 1) :
' ';
8003 global $langs,
$conf;
8005 if ($htmlname !=
"none") {
8006 print
'<form method="POST" action="' . $page .
'">';
8007 print
'<input type="hidden" name="action" value="setmulticurrencyrate">';
8008 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
8011 print
'<input type="text" class="maxwidth75 valignmiddle" name="' . $htmlname .
'" value="' . dolPrintHTMLForAttribute((
string) $ratetoshow) .
'" spellcheck="false" /> ';
8012 $arraycalculationmode = array(
8013 1 =>
'Change ' . $langs->trans(
"PriceUHT") .
' of lines',
8014 2 =>
'Change ' . $langs->trans(
"PriceUHTCurrency") .
' of lines'
8016 print
'<select name="calculation_mode" id="calculation_mode">';
8018 if (count($arraycalculationmode) > 1) {
8019 print
'<option value="-1"> </option>';
8021 foreach ($arraycalculationmode as $key => $val) {
8022 print
'<option value="' . $key .
'">' . $val .
'</option>';
8026 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
8029 if (!empty($rate)) {
8030 print
price($rate, 1, $langs, 0, 0);
8031 if ($currency && $rate != 1) {
8038 print
' <span class="opacitymedium">(' .
price($rate_direct, 1, $langs, 0, 0) .
' ' .
$conf->currency .
' = 1 ' . $currency .
')</span>';
8040 print
' <span class="opacitymedium">(' .
price($rate, 1, $langs, 0, 0) .
' ' . $currency .
' = 1 ' .
$conf->currency .
')</span>';
8068 public function form_remise_dispo($page, $selected, $htmlname, $socid, $amount, $filter =
'', $maxvalue = 0, $more =
'', $hidelist = 0, $discount_type = 0, $filterabsolutediscount = 0, $filtercreditnote = 0)
8071 global
$conf, $langs;
8073 if ($htmlname !=
"none") {
8074 print
'<form method="post" action="' . $page .
'" class="inline-block">';
8075 print
'<input type="hidden" name="action" value="setabsolutediscount">';
8076 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
8077 print
'<div class="inline-block">';
8078 if (!empty($discount_type)) {
8080 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL") {
8081 $translationKey =
'HasAbsoluteDiscountFromSupplier';
8083 $translationKey =
'HasCreditNoteFromSupplier';
8086 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
8087 $translationKey =
'HasAbsoluteDiscountFromSupplier';
8089 $translationKey =
'HasCreditNoteFromSupplier';
8094 if (!$filter || $filter ==
"fk_facture_source IS NULL") {
8095 $translationKey =
'CompanyHasAbsoluteDiscount';
8097 $translationKey =
'CompanyHasCreditNote';
8100 if (!$filter || $filter ==
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
8101 $translationKey =
'CompanyHasAbsoluteDiscount';
8103 $translationKey =
'CompanyHasCreditNote';
8107 print $langs->trans($translationKey,
price($amount, 0, $langs, 0, 0, -1,
$conf->currency));
8108 if (empty($hidelist)) {
8112 if (empty($hidelist)) {
8113 print
'<div class="inline-block" style="padding-right: 10px">';
8114 $newfilter =
'discount_type = ' . intval($discount_type);
8115 if (!empty($discount_type)) {
8116 $newfilter .=
' AND fk_invoice_supplier IS NULL AND fk_invoice_supplier_line IS NULL';
8118 $newfilter .=
' AND fk_facture IS NULL AND fk_facture_line IS NULL';
8121 $sanitizedfilter = $filter;
8122 $newfilter .=
' AND (' . $sanitizedfilter .
')';
8125 $nbqualifiedlines = $this->select_remises((
string) $selected, $htmlname, $newfilter, $socid, $maxvalue);
8126 if ($nbqualifiedlines > 0) {
8127 print
' <input type="submit" class="button smallpaddingimp" value="' .
dol_escape_htmltag($langs->trans(
"UseLine")) .
'"';
8128 if (!empty($discount_type) && $filter && $filter !=
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
8129 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
8131 if (empty($discount_type) && $filter && $filter !=
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
8132 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
8140 print
'<div class="inline-block">';
8166 public function form_contacts($page, $societe, $selected =
'', $htmlname =
'contactid')
8171 if ($htmlname !=
"none") {
8172 print
'<form method="post" action="' . $page .
'">';
8173 print
'<input type="hidden" name="action" value="set_contact">';
8174 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
8175 print
'<table class="nobordernopadding">';
8177 print $this->selectcontacts($societe->id, $selected, $htmlname);
8180 $addcontact = (
getDolGlobalString(
'SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans(
"AddContact") : $langs->trans(
"AddContactAddress"));
8181 print
'<a href="' . DOL_URL_ROOT .
'/contact/card.php?socid=' . $societe->id .
'&action=create&backtoreferer=1">' . $addcontact .
'</a>';
8184 print
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
8185 print
'</tr></table></form>';
8188 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
8189 $contact =
new Contact($this->db);
8190 $contact->fetch((
int) $selected);
8191 print $contact->getFullName($langs);
8216 public function form_thirdparty($page, $selected =
'', $htmlname =
'socid', $filter =
'', $showempty = 0, $showtype = 0, $forcecombo = 0, $events = array(), $nooutput = 0, $excludeids = array(), $textifnothirdparty =
'')
8222 if ($htmlname !=
"none") {
8225 $out .=
'<form method="post" action="' . $page .
'">';
8226 $out .=
'<input type="hidden" name="action" value="set_thirdparty">';
8227 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
8228 $out .= $this->select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, $limit,
'minwidth100',
'',
'', 1, array(),
false, $excludeids);
8229 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
8233 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
8234 $soc =
new Societe($this->db);
8235 $soc->fetch((
int) $selected);
8236 $out .= $soc->getNomUrl(0,
'');
8238 $out .=
'<span class="opacitymedium">' . $textifnothirdparty .
'</span>';
8264 print $this->selectCurrency($selected, $htmlname);
8276 public function selectCurrency($selected =
'', $htmlname =
'currency_id', $mode = 0, $useempty =
'')
8278 global $langs, $user;
8280 $langs->loadCacheCurrencies(
'');
8284 if ($selected ==
'euro' || $selected ==
'euros') {
8288 $out .=
'<select class="flat maxwidth200onsmartphone minwidth300" name="' . $htmlname .
'" id="' . $htmlname .
'">';
8290 $out .=
'<option value="-1" selected></option>';
8292 foreach ($langs->cache_currencies as $code_iso => $currency) {
8293 $labeltoshow = $currency[
'label'];
8295 $labeltoshow .=
' <span class="opacitymedium">(' . $code_iso .
')</span>';
8296 } elseif ($mode == 2) {
8297 $labeltoshow .=
' <span class="opacitymedium">(' . $code_iso.
' - '.$langs->getCurrencySymbol($code_iso) .
')</span>';
8299 $labeltoshow .=
' <span class="opacitymedium">(' . $langs->getCurrencySymbol($code_iso) .
')</span>';
8302 if ($selected && $selected == $code_iso) {
8303 $out .=
'<option value="' . $code_iso .
'" selected data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
8305 $out .=
'<option value="' . $code_iso .
'" data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
8308 $out .=
'</option>';
8310 $out .=
'</select>';
8312 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
8316 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
8334 public function selectMultiCurrency($selected =
'', $htmlname =
'multicurrency_code', $useempty = 0, $filter =
'', $excludeConfCurrency =
false, $morecss =
'maxwidth200 widthcentpercentminusx')
8336 global
$conf, $langs;
8338 $langs->loadCacheCurrencies(
'');
8340 $TCurrency = array();
8342 $sql =
"SELECT code FROM " . $this->db->prefix() .
"multicurrency";
8343 $sql .=
" WHERE entity IN ('" .
getEntity(
'multicurrency') .
"')";
8347 $resql = $this->db->query($sql);
8349 while ($obj = $this->db->fetch_object($resql)) {
8350 $TCurrency[$obj->code] = $obj->code;
8355 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
8357 $out .=
'<option value=""> </option>';
8360 if (!in_array(
$conf->currency, $TCurrency) && !$excludeConfCurrency) {
8361 $TCurrency[
$conf->currency] =
$conf->currency;
8363 if (count($TCurrency) > 0) {
8364 foreach ($langs->cache_currencies as $code_iso => $currency) {
8365 if (isset($TCurrency[$code_iso])) {
8366 if (!empty($selected) && $selected == $code_iso) {
8367 $out .=
'<option value="' . $code_iso .
'" selected="selected">';
8369 $out .=
'<option value="' . $code_iso .
'">';
8372 $out .= $currency[
'label'];
8373 $out .=
' (' . $langs->getCurrencySymbol($code_iso) .
')';
8374 $out .=
'</option>';
8379 $out .=
'</select>';
8382 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
8399 global $langs, $user, $hookmanager;
8401 $num = count($this->cache_vatrates);
8410 $sql =
"SELECT t.rowid, t.entity, t.fk_pays, t.type_vat, t.code, t.taux, t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.recuperableonly, t.einvoice_vatex";
8411 $sql .=
" FROM ".$this->db->prefix().
"c_tva as t, ".$this->db->prefix().
"c_country as c";
8412 $sql .=
" WHERE t.fk_pays = c.rowid";
8413 $sql .=
" AND t.active > 0";
8414 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
8415 $sql .=
" AND c.code IN (" . $this->db->sanitize($country_code, 1) .
")";
8416 $sql .=
" ORDER BY t.code ASC, t.taux ASC, t.recuperableonly ASC";
8418 $resql = $this->db->query($sql);
8420 $num = $this->db->num_rows($resql);
8422 for ($i = 0; $i < $num; $i++) {
8423 $obj = $this->db->fetch_object($resql);
8425 $tmparray = array();
8426 $tmparray[
'rowid'] = (int) $obj->rowid;
8427 $tmparray[
'entity'] = (int) $obj->entity;
8428 $tmparray[
'fk_pays'] = (int) $obj->fk_pays;
8429 $tmparray[
'type_vat'] = ($obj->type_vat <= 0 ? 0 : $obj->type_vat);
8430 $tmparray[
'code'] = $obj->code;
8431 $tmparray[
'txtva'] = $obj->taux;
8432 $tmparray[
'nprtva'] = $obj->recuperableonly;
8433 $tmparray[
'localtax1'] = $obj->localtax1;
8434 $tmparray[
'localtax1_type'] = $obj->localtax1_type;
8435 $tmparray[
'localtax2'] = $obj->localtax2;
8436 $tmparray[
'localtax2_type'] = $obj->localtax1_type;
8437 $tmparray[
'einvoice_vatex'] = $obj->einvoice_vatex;
8439 $tmparray[
'label'] = $obj->taux .
'%' . ($obj->code ?
' (' . $obj->code .
')' :
'');
8440 $tmparray[
'labelallrates'] = $obj->taux .
'/' . ($obj->localtax1 ? $obj->localtax1 :
'0') .
'/' . ($obj->localtax2 ? $obj->localtax2 :
'0') . ($obj->code ?
' (' . $obj->code .
')' :
'');
8441 $positiverates =
'';
8443 $positiverates .= ($positiverates ?
'/' :
'') . $obj->taux;
8445 if ($obj->localtax1) {
8446 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax1;
8448 if ($obj->localtax2) {
8449 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax2;
8451 if (empty($positiverates)) {
8452 $positiverates =
'0';
8454 $tmparray[
'labelpositiverates'] = $positiverates . ($obj->code ?
' (' . $obj->code .
')' :
'');
8456 $this->cache_vatrates[$obj->rowid] = $tmparray;
8459 $parameters = array(
'dictionary' =>
'vatrate',
'country_code' => $country_code);
8460 $reshook = $hookmanager->executeHooks(
'loadDictionaryCache', $parameters, $this);
8461 if (empty($reshook)) {
8462 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
8463 $this->cache_vatrates = array_merge($this->cache_vatrates, $hookmanager->resArray);
8466 $this->cache_vatrates = $hookmanager->resArray;
8469 return count($this->cache_vatrates);
8471 $this->error =
'<span class="error">';
8472 $this->error .= $langs->trans(
"ErrorNoVATRateDefinedForSellerCountry", $country_code);
8474 if (!empty($user) && $user->admin && preg_match(
'/\'(..)\'/', $country_code, $reg)) {
8475 $langs->load(
"errors");
8476 $new_country_code = $reg[1];
8477 $country_id =
dol_getIdFromCode($this->db, $new_country_code,
'c_country',
'code',
'rowid');
8478 $this->error .=
'<br>'.$langs->trans(
"ErrorFixThisHere", DOL_URL_ROOT.
'/admin/dict.php?id=10'.($country_id > 0 ?
'&countryidforinsert='.$country_id :
''));
8480 $this->error .=
'</span>';
8484 $this->error =
'<span class="error">' . $this->db->error() .
'</span>';
8513 public function load_tva($htmlname =
'tauxtva', $selectedrate =
'', $societe_vendeuse =
null, $societe_acheteuse =
null, $idprod = 0, $info_bits = 0, $type =
'', $options_only =
false, $mode = 0, $type_vat = 0)
8516 global $langs,
$mysoc, $hookmanager;
8518 $langs->load(
'errors');
8522 $hookmanager->initHooks(array(
'commonobject'));
8523 $info_bits == 1 ? $is_npr = 1 : $is_npr = 0;
8524 $parameters = array(
8525 'htmlname' => $htmlname,
8526 'selectedrate' => $selectedrate,
8527 'seller' => $societe_vendeuse,
8528 'buyer' => $societe_acheteuse,
8529 'idprod' => $idprod,
8530 'is_npr' => $is_npr,
8532 'options_only' => $options_only,
8534 'type_vat' => $type_vat
8536 $reshook = $hookmanager->executeHooks(
'load_tva', $parameters);
8538 return $hookmanager->resPrint;
8539 } elseif ($reshook === 0) {
8540 $return .= $hookmanager->resPrint;
8544 $defaultnpr = ($info_bits & 0x01);
8545 $defaultnpr = (preg_match(
'/\*/', $selectedrate) ? 1 : $defaultnpr);
8546 $defaulttx = str_replace(
'*',
'', $selectedrate);
8549 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
8550 $defaultcode = $reg[1];
8551 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
8556 if (is_object($societe_vendeuse) && !$societe_vendeuse->country_code) {
8557 if ($societe_vendeuse->id ==
$mysoc->id) {
8558 $return .=
'<span class="error">' . $langs->trans(
"ErrorYourCountryIsNotDefined") .
'</span>';
8560 $return .=
'<span class="error">' . $langs->trans(
"ErrorSupplierCountryIsNotDefined") .
'</span>';
8577 $sellercountrycode = is_object($societe_vendeuse) ? $societe_vendeuse->country_code :
$mysoc->country_code;
8578 $sellercountryid = is_object($societe_vendeuse) ? $societe_vendeuse->country_id :
$mysoc->country_id;
8579 if ((
int) $sellercountryid > 0 && strlen((
string) $sellercountrycode) != 2) {
8580 $tmpcountrycode =
dol_getIdFromCode($this->db, (
string) $sellercountryid,
'c_country',
'rowid',
'code');
8581 if (!empty($tmpcountrycode) && !is_numeric($tmpcountrycode)) {
8582 $sellercountrycode = $tmpcountrycode;
8585 $code_country =
"'" . $sellercountrycode .
"'";
8588 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
8592 if (is_object($societe_vendeuse) && is_object($societe_acheteuse) &&
isInEEC($societe_vendeuse) &&
isInEEC($societe_acheteuse) && !$societe_acheteuse->isACompany()) {
8594 if (is_numeric($type)) {
8596 switch ($selectVatComboMode) {
8598 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
8601 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
8605 } elseif (!$idprod) {
8606 switch ($selectVatComboMode) {
8608 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
8611 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
8615 $prodstatic =
new Product($this->db);
8616 $prodstatic->fetch($idprod);
8618 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
8625 $this->load_cache_vatrates($code_country);
8628 $arrayofvatrates = array();
8629 foreach ($this->cache_vatrates as $cachevalue) {
8630 if ($type_vat == 0 || empty($cachevalue[
'type_vat']) || $cachevalue[
'type_vat'] == $type_vat) {
8631 $arrayofvatrates[] = $cachevalue;
8635 $num = count($arrayofvatrates);
8638 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
8640 $tmpthirdparty =
new Societe($this->db);
8641 $tmpthirdparty->country_code =
$mysoc->country_code;
8643 $defaulttx =
get_default_tva(is_object($societe_vendeuse) ? $societe_vendeuse : $tmpthirdparty, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
8644 $defaultnpr =
get_default_npr(is_object($societe_vendeuse) ? $societe_vendeuse : $tmpthirdparty, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
8646 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
8647 $defaultcode = $reg[1];
8648 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
8650 if (empty($defaulttx)) {
8657 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
8660 $defaulttx = $arrayofvatrates[$num - 1][
'txtva'];
8667 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
8668 $defaultcode = $reg[1];
8669 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
8677 if (is_object($societe_vendeuse) && $societe_vendeuse->id ==
$mysoc->id && empty($societe_vendeuse->tva_assuj)) {
8687 if (!$options_only) {
8688 $return .=
'<select class="flat valignmiddle minwidth75imp maxwidth100 right" id="' . $htmlname .
'" name="' . $htmlname .
'"' . ($disabled ?
' disabled' :
'') . $title .
'>';
8691 $selectedfound =
false;
8692 foreach ($arrayofvatrates as $rate) {
8694 if ($disabled && $rate[
'txtva'] != 0) {
8699 $key = $rate[
'txtva'];
8700 $key .= $rate[
'nprtva'] ?
'*' :
'';
8701 if ($mode > 0 && $rate[
'code']) {
8702 $key .=
' (' . $rate[
'code'] .
')';
8705 $key = $rate[
'rowid'];
8708 $return .=
'<option value="' . $key .
'" data-vatid="'.$rate[
'rowid'].
'"';
8709 if (!$selectedfound) {
8711 if ($defaultcode == $rate[
'code']) {
8712 $return .=
' selected';
8713 $selectedfound =
true;
8715 } elseif ($rate[
'txtva'] == $defaulttx && $rate[
'nprtva'] == $defaultnpr) {
8716 $return .=
' selected';
8717 $selectedfound =
true;
8725 $return .= $rate[
'labelpositiverates'];
8728 $return .=
vatrate($rate[
'label']);
8732 $return .= (empty($rate[
'code']) && $rate[
'nprtva']) ?
' *' :
'';
8734 $return .=
'</option>';
8737 if (!$options_only) {
8738 $return .=
'</select>';
8742 $return .= $this->error;
8776 public function select_date($set_time =
'', $prefix =
're', $h = 0, $m = 0, $empty = 0, $form_name =
"", $d = 1, $addnowlink = 0, $nooutput = 0, $disabled = 0, $fullday = 0, $addplusone =
'', $adddateof =
'')
8779 dol_syslog(__METHOD__ .
': using select_date is deprecated. Use selectDate instead.', LOG_WARNING);
8780 $retstring = $this->selectDate($set_time, $prefix, $h, $m, $empty, $form_name, $d, $addnowlink, $disabled, $fullday, $addplusone, $adddateof);
8781 if (!empty($nooutput)) {
8804 public function selectDateToDate($set_time =
'', $set_time_end =
'', $prefix =
're', $empty = 0, $forcenewline = 0)
8808 $ret = $this->selectDate($set_time, $prefix .
'_start', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"from"),
'tzuserrel');
8809 if ($forcenewline) {
8812 $ret .= $this->selectDate($set_time_end, $prefix .
'_end', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
8844 public function selectDate($set_time =
'', $prefix =
're', $h = 0, $m = 0, $empty = 0, $form_name =
"", $d = 1, $addnowlink = 0, $disabled = 0, $fullday =
'', $addplusone =
'', $adddateof =
'', $openinghours =
'', $stepminutes = 1, $labeladddateof =
'', $placeholder =
'', $gm =
'auto', $calendarpicto =
'')
8846 global
$conf, $langs;
8848 if ($gm ===
'auto') {
8849 $gm = (empty(
$conf) ?
'tzserver' :
$conf->tzuserinputkey);
8854 if ($prefix ==
'') {
8865 if ($stepminutes <= 0 || $stepminutes > 30) {
8876 $orig_set_time = $set_time;
8878 if ($set_time ===
'' && $emptydate == 0) {
8879 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
8880 if ($gm ==
'tzuser' || $gm ==
'tzuserrel') {
8892 if (!empty($set_time) && preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/', (
string) $set_time, $reg)) {
8894 $syear = (!empty($reg[1]) ? $reg[1] :
'');
8895 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
8896 $sday = (!empty($reg[3]) ? $reg[3] :
'');
8897 $shour = (!empty($reg[4]) ? $reg[4] :
'');
8898 $smin = (!empty($reg[5]) ? $reg[5] :
'');
8899 } elseif (strval($set_time) !=
'' && $set_time != -1) {
8904 if ($orig_set_time !=
'') {
8918 if ($h == 3 || $h == 4) {
8929 $usecalendar =
'combo';
8935 $usecalendar =
'html';
8940 if ($usecalendar !=
'combo') {
8942 $reduceformat = (!empty(
$conf->dol_optimize_smallscreen) ? 1 : 0);
8943 if ($reduceformat) {
8944 $format = str_replace(
'%Y',
'%y', $langs->transnoentitiesnoconv(
"FormatDateShortInput"));
8945 $formatjslong = $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput");
8946 $formatjs = str_replace(
'yyyy',
'yy', $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput"));
8947 $formatjquery = str_replace(
'yyyy',
'yy', $langs->trans(
"FormatDateShortJQueryInput"));
8949 $format = $langs->transnoentitiesnoconv(
"FormatDateShortInput");
8950 $formatjslong = $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput");
8951 $formatjs = $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput");
8952 $formatjquery = $langs->trans(
"FormatDateShortJQueryInput");
8956 $formatted_date =
'';
8957 if (strval($set_time) !=
'' && $set_time != -1) {
8962 if ($usecalendar ==
"eldy") {
8988 } elseif ($usecalendar ==
'jquery' || $usecalendar ==
'html') {
8989 if (!$disabled && $usecalendar !=
'html') {
8991 $minYear =
getDolGlobalInt(
'MIN_YEAR_SELECT_DATE', (idate(
'Y') - 100));
8992 $maxYear =
getDolGlobalInt(
'MAX_YEAR_SELECT_DATE', (idate(
'Y') + 100));
8994 $retstring .=
'<!-- datepicker usecalendar='.$usecalendar.
' --><script nonce="' .
getNonce() .
'" type="text/javascript">';
8995 $retstring .=
"$(function(){ $('#" . $prefix .
"').datepicker({
8998 todayHighlight: true,
8999 yearRange: '" . $minYear .
":" . $maxYear .
"',";
9000 if (!empty(
$conf->dol_use_jmobile)) {
9002 beforeShow: function (input, datePicker) {
9003 input.disabled = true;
9005 onClose: function (dateText, datePicker) {
9006 this.disabled = false;
9012 $buttonImage = $calendarpicto ?: DOL_URL_ROOT .
"/theme/" .
dol_escape_js(
$conf->theme) .
"/img/object_calendarday.png";
9014 showOn: 'button', /* both has problem with autocompletion */
9015 buttonImage: '" . $buttonImage .
"',
9016 buttonImageOnly: true";
9020 $retstring .=
"</script>";
9024 $retstring .=
'<div class="nowraponall inline-block divfordateinput">';
9025 $retstring .=
'<input id="'.$prefix.
'" name="'.$prefix.
'" type="'.($usecalendar ==
'html' ?
"date" :
"text").
'" class="maxwidthdate'.(
getDolUserString(
'MAIN_OPTIMIZEFORTEXTBROWSER') ?
' textbrowser' :
'').
' center" maxlength="11" value="'.$formatted_date.
'"';
9026 $retstring .= ($disabled ?
' disabled' :
'');
9027 $retstring .= ($placeholder ?
' placeholder="' .
dol_escape_htmltag($placeholder) .
'"' :
'');
9028 $retstring .=
' onChange="dpChangeDay(\'' .
dol_escape_js($prefix) .
'\',\
'' .
dol_escape_js($usecalendar ==
'html' ?
'yyyy-mm-dd' : $formatjslong) .
'\');
"'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
9029 $retstring .= ' autocomplete="off
">';
9033 $retstringbutton = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
">' . img_object($langs->trans("Disabled
"), 'calendarday', 'class="datecallink ui-datepicker-notrigger
"') . '</button>';
9034 $retstring .= $retstringbutton;
9037 $retstring .= '</div>';
9038 $retstring .= '<input type="hidden
" id="' . $prefix . 'day
" name="' . $prefix . 'day
" value="' . $sday . '">' . "\n
";
9039 $retstring .= '<input type="hidden
" id="' . $prefix . 'month
" name="' . $prefix . 'month
" value="' . $smonth . '">' . "\n
";
9040 $retstring .= '<input type="hidden
" id="' . $prefix . 'year
" name="' . $prefix . 'year
" value="' . $syear . '">' . "\n
";
9042 $retstring .= "Bad value of MAIN_POPUP_CALENDAR
";
9045 // Show date with combo selects
9047 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50imp
" id="' . $prefix . 'day
" name="' . $prefix . 'day
">';
9049 if ($emptydate || $set_time == -1) {
9050 $retstring .= '<option value="0
" selected> </option>';
9053 for ($day = 1; $day <= 31; $day++) {
9054 $retstring .= '<option value="' . $day . '"' . ($day == $sday ? ' selected' : '') . '>' . $day . '</option>';
9057 $retstring .= "</select>
";
9059 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'month
" name="' . $prefix . 'month
">';
9060 if ($emptydate || $set_time == -1) {
9061 $retstring .= '<option value="0
" selected> </option>';
9065 for ($month = 1; $month <= 12; $month++) {
9066 $retstring .= '<option value="' . $month . '"' . ($month == $smonth ? ' selected' : '') . '>';
9067 $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b
");
9068 $retstring .= "</option>
";
9070 $retstring .= "</select>
";
9073 if ($emptydate || $set_time == -1) {
9074 $retstring .= '<input' . ($disabled ? ' disabled' : '') . ' placeholder="' . dol_escape_htmltag($langs->trans("Year")) . '" class="flat maxwidth50imp valignmiddle
" type="number
" min="0
" max="3000
" maxlength="4
" id="' . $prefix . 'year
" name="' . $prefix . 'year
" value="' . $syear . '">';
9076 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'year
" name="' . $prefix . 'year
">';
9078 $syear = (int) $syear;
9079 for ($year = $syear - 10; $year < (int) $syear + 10; $year++) {
9080 $retstring .= '<option value="' . $year . '"' . ($year == $syear ? ' selected' : '') . '>' . $year . '</option>';
9082 $retstring .= "</select>\n
";
9088 $retstring .= (($h == 2 || $h == 4) ? '<br>' : ' ');
9089 $retstring .= '<span class="nowraponall
">';
9095 if ($openinghours != '') {
9096 $openinghours = explode(',', $openinghours);
9097 $hourstart = $openinghours[0];
9098 $hourend = $openinghours[1];
9099 if ($hourend < $hourstart) {
9100 $hourend = $hourstart;
9105 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75
'; // Note maxwidth50 generates truncated number on some desktops even with same version of chrome that works on others
9106 $retstring .= ($fullday ? $fullday . 'hour
' : '') . '" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
">';
9108 $retstring .= '<option value="-1
"> </option>';
9110 for ($hour = $hourstart; $hour < $hourend; $hour++) {
9111 if (strlen($hour) < 2) {
9112 $hour = "0
" . $hour;
9114 $retstring .= '<option value="' . $hour . '"' . (($hour == $shour) ? ' selected' : '') . '>' . $hour;
9115 $retstring .= '</option>';
9117 $retstring .= '</select>';
9120 $retstring .= '<input type="hidden
" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
" value="' . $shour . '">' . "\n
";
9129 $retstring .= '<select ' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75
'; // Note maxwidth50 generates truncated number on some desktops even with same version of chrome that works on others
9130 $retstring .= ($fullday ? $fullday . 'min
' : '') . '" id="' . $prefix . 'min
" name="' . $prefix . 'min
">';
9132 $retstring .= '<option value="-1
"> </option>';
9134 for ($min = 0; $min < 60; $min += $stepminutes) {
9135 $min_str = sprintf("%02d
", $min);
9136 $retstring .= '<option value="' . $min_str . '"' . (($min_str == $smin) ? ' selected' : '') . '>' . $min_str . '</option>';
9138 $retstring .= '</select>';
9140 $retstring .= '<input type="hidden
" id="' . $prefix . 'min
" name="' . $prefix . 'min
" value="' . $smin . '">' . "\n
";
9143 $retstring .= '<input type="hidden
" name="' . $prefix . 'sec
" value="' . $ssec . '">';
9147 $retstring .= '</span>';
9151 if (!empty($conf->use_javascript_ajax) && $addnowlink && !$disabled) {
9152 // Script which will be inserted in the onClick of the "Now
" link
9153 $reset_scripts = "";
9154 if ($addnowlink == 2) { // local computer time
9155 // pad add leading 0 on numbers
9156 $reset_scripts .= "Number.prototype.pad =
function(size) {
9157 var s = String(
this);
9158 while (s.length < (size || 2)) {s =
'0' + s;}
9161 var d =
new Date();
";
9164 // Generate the date part, depending on the use or not of the javascript calendar
9165 if ($addnowlink == 1) { // server time expressed in user time setup
9166 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
9167 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
9168 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
9169 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
9170 } elseif ($addnowlink == 2) {
9171 /* Disabled because the output does not use the string format defined by FormatDateShort key to forge the value into #prefix.
9172 * This break application for foreign languages.
9173 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(d.toLocaleDateString(\''.str_replace('_', '-', $langs->defaultlang).'\'));';
9174 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(d.getDate().pad());';
9175 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(parseInt(d.getMonth().pad()) + 1);';
9176 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(d.getFullYear());';
9178 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
9179 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
9180 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
9181 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
9183 /*if ($usecalendar == "eldy
")
9185 $base=DOL_URL_ROOT.'/core/';
9186 $reset_scripts .= 'resetDP(\''.$base.'\',\''.$prefix.'\',\''.$langs->trans("FormatDateShortJavaInput
").'\',\''.$langs->defaultlang.'\');';
9190 $reset_scripts .= 'this.form.elements[\''.$prefix.'day\'].value=formatDate(new Date(), \'d\'); ';
9191 $reset_scripts .= 'this.form.elements[\''.$prefix.'month\'].value=formatDate(new Date(), \'M\'); ';
9192 $reset_scripts .= 'this.form.elements[\''.$prefix.'year\'].value=formatDate(new Date(), \'yyyy\'); ';
9194 // Update the hour part
9197 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
9199 //$reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); ';
9200 if ($addnowlink == 1) {
9201 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
9202 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
9203 } elseif ($addnowlink == 2) {
9204 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(d.getHours().pad());';
9205 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
9209 $reset_scripts .= ' } ';
9212 // Update the minute part
9215 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
9217 //$reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); ';
9218 if ($addnowlink == 1) {
9219 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
9220 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
9221 } elseif ($addnowlink == 2) {
9222 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(d.getMinutes().pad());';
9223 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
9226 $reset_scripts .= ' } ';
9229 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
9230 if ($reset_scripts && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
9231 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonNow
" type="button" name="_useless
" value="now
" onClick="' . $reset_scripts . '">';
9232 $retstring .= $langs->trans("Now
");
9233 $retstring .= '</button> ';
9237 // Add a "Plus one hour
" link
9238 if ($conf->use_javascript_ajax && $addplusone && !$disabled) {
9239 // Script which will be inserted in the onClick of the "Add plusone
" link
9240 $reset_scripts = "";
9242 // Generate the date part, depending on the use or not of the javascript calendar
9243 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'dayinputnoreduce', 'tzuserrel') . '\');';
9244 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
9245 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
9246 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
9247 // Update the hour part
9250 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
9252 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
9254 $reset_scripts .= ' } ';
9257 // Update the minute part
9260 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
9262 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
9264 $reset_scripts .= ' } ';
9267 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
9268 if ($reset_scripts && empty($conf->dol_optimize_smallscreen)) {
9269 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonPlusOne
" type="button" name="_useless2
" value="plusone
" onClick="' . $reset_scripts . '">';
9270 $retstring .= $langs->trans("DateStartPlusOne
");
9271 $retstring .= '</button> ';
9275 // Add a link to set data
9276 if ($conf->use_javascript_ajax && !empty($adddateof) && !$disabled) {
9277 if (!is_array($adddateof)) {
9278 $arrayofdateof = array(array('adddateof' => $adddateof, 'labeladddateof' => $labeladddateof));
9280 $arrayofdateof = $adddateof;
9282 foreach ($arrayofdateof as $valuedateof) {
9283 $tmpadddateof = empty($valuedateof['adddateof']) ? 0 : $valuedateof['adddateof'];
9284 $tmplabeladddateof = empty($valuedateof['labeladddateof']) ? '' : $valuedateof['labeladddateof'];
9285 $tmparray = dol_getdate($tmpadddateof);
9286 if (empty($tmplabeladddateof)) {
9287 $tmplabeladddateof = $langs->trans("DateInvoice
");
9289 $reset_scripts = 'console.log(\'Click on now link\'); ';
9290 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(\''.dol_print_date($tmpadddateof, 'dayinputnoreduce').'\');';
9291 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(\''.$tmparray['mday'].'\');';
9292 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(\''.$tmparray['mon'].'\');';
9293 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(\''.$tmparray['year'].'\');';
9294 $retstring .= ' - <button class="dpInvisibleButtons datenowlink
" id="dateofinvoice
" type="button" name="_dateofinvoice
" value="now
" onclick="'.$reset_scripts.'">'.$tmplabeladddateof.'</button>';
9310 public function selectTypeDuration($prefix, $selected = 'i', $excludetypes = array(), $morecss = 'minwidth75 maxwidth100')
9314 $TDurationTypes = $this->getDurationTypes($langs);
9316 // Removed undesired duration types
9317 foreach ($excludetypes as $value) {
9318 unset($TDurationTypes[$value]);
9321 $retstring = '<select class="flat
'.($morecss ? ' '.$morecss : '').'" id="select_
' . $prefix . 'type_duration
" name="' . $prefix . 'type_duration
">';
9322 foreach ($TDurationTypes as $key => $typeduration) {
9323 $retstring .= '<option value="' . $key . '"';
9324 if ($key == $selected) {
9325 $retstring .= " selected
";
9327 $retstring .= ">
" . $typeduration . "</option>
";
9329 $retstring .= "</select>
";
9331 $retstring .= ajax_combobox('select_' . $prefix . 'type_duration');
9336 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
9351 public function select_duration($prefix, $iSecond = '', $disabled = 0, $typehour = 'select', $minunderhours = 0, $nooutput = 0)
9356 $retstring = '<span class="nowraponall
">';
9362 if ($iSecond != '') {
9363 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
9365 $hourSelected = convertSecondToTime($iSecond, 'allhour');
9366 $minSelected = convertSecondToTime($iSecond, 'min');
9369 if ($typehour == 'select') {
9370 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'hour
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . '>';
9371 for ($hour = 0; $hour < 25; $hour++) { // For a duration, we allow 24 hours
9372 $retstring .= '<option value="' . $hour . '"';
9373 if (is_numeric($hourSelected) && $hourSelected == $hour) {
9374 $retstring .= " selected
";
9376 $retstring .= ">
" . $hour . "</option>
";
9378 $retstring .= "</select>
";
9379 } elseif ($typehour == 'text' || $typehour == 'textselect') {
9380 $retstring .= '<input placeholder="' . $langs->trans('HourShort
') . '" type="number
" min="0
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputhour right
" value="' . (($hourSelected != '') ? ((int) $hourSelected) : '') . '">';
9382 return 'BadValueForParameterTypeHour';
9385 if ($typehour != 'text') {
9386 $retstring .= ' ' . $langs->trans('HourShort');
9388 $retstring .= '<span class="">:</span>';
9392 if ($minunderhours) {
9393 $retstring .= '<br>';
9395 if ($typehour != 'text') {
9396 $retstring .= '<span class="hideonsmartphone
"> </span>';
9400 if ($typehour == 'select' || $typehour == 'textselect') {
9401 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'min
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . '>';
9402 $step = getDolGlobalInt('MAIN_DURATION_STEP');
9403 $duration_step = ($step > 0) ? $step : 5;
9404 for ($min = 0; $min <= 59; $min += $duration_step) {
9405 $retstring .= '<option value="' . $min . '"';
9406 if (is_numeric($minSelected) && $minSelected == $min) {
9407 $retstring .= ' selected';
9409 $retstring .= '>' . $min . '</option>';
9411 $retstring .= "</select>
";
9412 } elseif ($typehour == 'text') {
9413 $retstring .= '<input placeholder="' . $langs->trans('MinuteShort
') . '" type="number
" min="0
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputminute right
" value="' . (($minSelected != '') ? ((int) $minSelected) : '') . '">';
9416 if ($typehour != 'text') {
9417 $retstring .= ' ' . $langs->trans('MinuteShort');
9420 $retstring .= "</span>
";
9422 if (!empty($nooutput)) {
9450 public function selectTickets($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 0, $status = 1, $selected_input_value = '', $hidelabel = 0, $ajaxoptions = array(), $socid = 0, $showempty = '1', $forcecombo = 0, $morecss = '', $selected_combinations = null, $nooutput = 0)
9452 global $langs, $conf;
9457 if (is_null($ajaxoptions)) {
9458 $ajaxoptions = array();
9461 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
9464 if ($selected && empty($selected_input_value)) {
9465 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
9466 $tickettmpselect = new Ticket($this->db);
9467 $tickettmpselect->fetch((int) $selected);
9468 $selected_input_value = $tickettmpselect->ref;
9469 unset($tickettmpselect);
9473 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/ticket/ajax/tickets.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
9475 if (empty($hidelabel)) {
9476 $out .= $langs->trans("RefOrLabel
") . ' : ';
9477 } elseif ($hidelabel > 1) {
9478 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
9479 if ($hidelabel == 2) {
9480 $out .= img_picto($langs->trans("Search
"), 'search');
9483 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
9484 if ($hidelabel == 3) {
9485 $out .= img_picto($langs->trans("Search
"), 'search');
9488 $out .= $this->selectTicketsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
9491 if (empty($nooutput)) {
9516 public function selectTicketsList($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
9521 $outarray = array();
9523 $selectFields = " p.rowid, p.ref, p.message
";
9526 $sql .= $this->db->sanitize($selectFields, 0, 0, 1);
9527 $sql .= " FROM
" . $this->db->prefix() . "ticket as p
";
9528 $sql .= ' WHERE p.entity IN (' . getEntity('ticket') . ')';
9530 // Add criteria on ref/label
9531 if ($filterkey != '') {
9533 $prefix = getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '' : '%'; // Can use index if TICKET_DONOTSEARCH_ANYWHERE is on
9534 // For natural search
9535 $search_crit = explode(' ', $filterkey);
9537 if (count($search_crit) > 1) {
9540 foreach ($search_crit as $crit) {
9544 $sql .= "(p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%' OR p.subject LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
9548 if (count($search_crit) > 1) {
9554 $sql .= $this->db->plimit($limit, 0);
9556 // Build output string
9557 dol_syslog(get_class($this) . "::selectTicketsList search tickets
", LOG_DEBUG);
9558 $result = $this->db->query($sql);
9560 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
9561 require_once DOL_DOCUMENT_ROOT . '/core/lib/ticket.lib.php';
9563 $num = $this->db->num_rows($result);
9568 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
9569 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('TICKET_USE_SEARCH_TO_SELECT'));
9572 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
9575 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
9576 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
9577 if (getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
9578 if ($showempty && !is_numeric($showempty)) {
9579 $textifempty = $langs->trans($showempty);
9581 $textifempty .= $langs->trans("All
");
9584 if ($showempty && !is_numeric($showempty)) {
9585 $textifempty = $langs->trans($showempty);
9589 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
9593 while ($num && $i < $num) {
9596 $objp = $this->db->fetch_object($result);
9598 $this->constructTicketListOption($objp, $opt, $optJson, $selected, $filterkey);
9599 '@phan-var-force array{key:string,value:mixed,type:int} $optJson';
9601 // "key
" value of json key array is used by jQuery automatically as selected value
9602 // "label
" value of json key array is used by jQuery automatically as text for combo box
9604 array_push($outarray, $optJson);
9609 $out .= '</select>';
9611 $this->db->free($result);
9613 if (empty($outputmode)) {
9618 dol_print_error($this->db);
9635 protected function constructTicketListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
9641 $outkey = $objp->rowid;
9642 $outref = $objp->ref;
9644 $opt = '<option value="
' . $objp->rowid . '"';
9645 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
9648 $objRef = $objp->ref;
9649 if (!empty($filterkey) && $filterkey != '') {
9650 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1);
9653 $opt .= "</option>\n
";
9654 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
9676 public function selectProjects($selected = '', $htmlname = 'projectid', $filtertype = '', $limit = 0, $status = 1, $selected_input_value = '', $hidelabel = 0, $ajaxoptions = array(), $socid = 0, $showempty = '1', $forcecombo = 0, $morecss = '', $selected_combinations = null, $nooutput = 0)
9678 global $langs, $conf;
9683 if (is_null($ajaxoptions)) {
9684 $ajaxoptions = array();
9687 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
9690 if ($selected && empty($selected_input_value)) {
9691 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
9692 $projecttmpselect = new Project($this->db);
9693 $projecttmpselect->fetch((int) $selected);
9694 $selected_input_value = $projecttmpselect->ref;
9695 unset($projecttmpselect);
9699 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/projet/ajax/projects.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
9701 if (empty($hidelabel)) {
9702 $out .= $langs->trans("RefOrLabel
") . ' : ';
9703 } elseif ($hidelabel > 1) {
9704 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
9705 if ($hidelabel == 2) {
9706 $out .= img_picto($langs->trans("Search
"), 'search');
9709 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
9710 if ($hidelabel == 3) {
9711 $out .= img_picto($langs->trans("Search
"), 'search');
9714 $out .= $this->selectProjectsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
9717 if (empty($nooutput)) {
9741 public function selectProjectsList($selected = '', $htmlname = 'projectid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
9743 global $langs, $conf;
9746 $outarray = array();
9748 $selectFields = " p.rowid, p.ref
";
9751 $sql .= $this->db->sanitize($selectFields, 0, 0, 1);
9752 $sql .= " FROM
" . $this->db->prefix() . "projet as p
";
9753 $sql .= ' WHERE p.entity IN (' . getEntity('project') . ')';
9755 // Add criteria on ref/label
9756 if ($filterkey != '') {
9758 $prefix = !getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
9759 // For natural search
9760 $search_crit = explode(' ', $filterkey);
9762 if (count($search_crit) > 1) {
9765 foreach ($search_crit as $crit) {
9769 $sql .= "p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
9773 if (count($search_crit) > 1) {
9779 $sql .= $this->db->plimit($limit, 0);
9781 // Build output string
9782 dol_syslog(get_class($this) . "::selectProjectsList search projects
", LOG_DEBUG);
9783 $result = $this->db->query($sql);
9785 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
9786 require_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php';
9788 $num = $this->db->num_rows($result);
9793 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
9794 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('PROJECT_USE_SEARCH_TO_SELECT'));
9797 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
9800 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
9801 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
9802 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
9803 if ($showempty && !is_numeric($showempty)) {
9804 $textifempty = $langs->trans($showempty);
9806 $textifempty .= $langs->trans("All
");
9809 if ($showempty && !is_numeric($showempty)) {
9810 $textifempty = $langs->trans($showempty);
9814 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
9818 while ($num && $i < $num) {
9821 $objp = $this->db->fetch_object($result);
9823 $this->constructProjectListOption($objp, $opt, $optJson, $selected, $filterkey);
9825 // "key
" value of json key array is used by jQuery automatically as selected value
9826 // "label
" value of json key array is used by jQuery automatically as text for combo box
9828 array_push($outarray, $optJson);
9833 $out .= '</select>';
9835 $this->db->free($result);
9837 if (empty($outputmode)) {
9842 dol_print_error($this->db);
9861 protected function constructProjectListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
9867 $label = $objp->label;
9869 $outkey = $objp->rowid;
9870 $outref = $objp->ref;
9871 $outlabel = $objp->label;
9872 $outtype = $objp->fk_product_type;
9874 $opt = '<option value="
' . $objp->rowid . '"';
9875 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
9878 $objRef = $objp->ref;
9879 if (!empty($filterkey) && $filterkey != '') {
9880 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', (string) $objRef, 1);
9883 $opt .= "</option>\n
";
9884 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
9908 public function selectMembers($selected = '', $htmlname = 'adherentid', $filtertype = '', $limit = 0, $status = 1, $selected_input_value = '', $hidelabel = 0, $ajaxoptions = array(), $socid = 0, $showempty = '1', $forcecombo = 0, $morecss = '', $selected_combinations = null, $nooutput = 0, $excludeids = array())
9910 global $langs, $conf;
9915 if (is_null($ajaxoptions)) {
9916 $ajaxoptions = array();
9919 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
9922 if ($selected && empty($selected_input_value)) {
9923 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
9924 $adherenttmpselect = new Adherent($this->db);
9925 $adherenttmpselect->fetch((int) $selected);
9926 $selected_input_value = $adherenttmpselect->ref;
9927 unset($adherenttmpselect);
9932 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/adherents/ajax/adherents.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
9934 if (empty($hidelabel)) {
9935 $out .= $langs->trans("RefOrLabel
") . ' : ';
9936 } elseif ($hidelabel > 1) {
9937 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
9938 if ($hidelabel == 2) {
9939 $out .= img_picto($langs->trans("Search
"), 'search');
9942 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
9943 if ($hidelabel == 3) {
9944 $out .= img_picto($langs->trans("Search
"), 'search');
9949 $out .= $this->selectMembersList($selected, $htmlname, $filtertype, $limit, $filterkey, $status, 0, $showempty, $forcecombo, $morecss, $excludeids);
9952 if (empty($nooutput)) {
9977 public function selectMembersList($selected = '', $htmlname = 'adherentid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '', $excludeids = array())
9979 global $langs, $conf;
9982 $outarray = array();
9984 $selectFields = " p.rowid, p.ref, p.firstname, p.lastname, p.fk_adherent_type
";
9987 $sql .= $this->db->sanitize($selectFields, 0, 0, 1);
9988 $sql .= " FROM
" . $this->db->prefix() . "adherent as p
";
9989 $sql .= ' WHERE p.entity IN (' . getEntity('adherent') . ')';
9991 // Add criteria on ref/label
9992 if ($filterkey != '') {
9994 $prefix = !getDolGlobalString('MEMBER_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
9995 // For natural search
9996 $search_crit = explode(' ', $filterkey);
9998 if (count($search_crit) > 1) {
10001 foreach ($search_crit as $crit) {
10005 $sql .= "(p.firstname LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
10006 $sql .= " OR p.lastname LIKE
'" . $this->db->escape($prefix . $crit) . "%')
";
10009 if (count($search_crit) > 1) {
10014 if ($status != -1) {
10015 $sql .= ' AND statut = ' . ((int) $status);
10017 if (!empty($excludeids)) {
10018 $sql .= " AND p.rowid NOT IN (
" . $this->db->sanitize(implode(',', $excludeids)) . ")
";
10020 $sql .= $this->db->plimit($limit, 0);
10022 // Build output string
10023 dol_syslog(get_class($this) . "::selectMembersList search adherents
", LOG_DEBUG);
10024 $result = $this->db->query($sql);
10026 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
10027 require_once DOL_DOCUMENT_ROOT . '/core/lib/member.lib.php';
10029 $num = $this->db->num_rows($result);
10033 if (!$forcecombo) {
10034 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
10035 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('PROJECT_USE_SEARCH_TO_SELECT'));
10038 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
10041 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
10042 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
10043 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
10044 if ($showempty && !is_numeric($showempty)) {
10045 $textifempty = $langs->trans($showempty);
10047 $textifempty .= $langs->trans("All
");
10050 if ($showempty && !is_numeric($showempty)) {
10051 $textifempty = $langs->trans($showempty);
10055 $out .= '<option value="-1
" selected>' . $textifempty . '</option>';
10059 while ($num && $i < $num) {
10061 $optJson = array();
10062 $objp = $this->db->fetch_object($result);
10064 $this->constructMemberListOption($objp, $opt, $optJson, $selected, $filterkey);
10067 // "key
" value of json key array is used by jQuery automatically as selected value
10068 // "label
" value of json key array is used by jQuery automatically as text for combo box
10070 array_push($outarray, $optJson);
10075 $out .= '</select>';
10077 $this->db->free($result);
10079 if (empty($outputmode)) {
10084 dol_print_error($this->db);
10101 protected function constructMemberListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
10107 $outkey = $objp->rowid;
10108 $outlabel = dolGetFirstLastname($objp->firstname, $objp->lastname);
10109 $outtype = $objp->fk_adherent_type;
10111 $opt = '<option value="
' . $objp->rowid . '"';
10112 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
10114 if (!empty($filterkey) && $filterkey != '') {
10115 $outlabel = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $outlabel, 1);
10118 $opt .= "</option>\n
";
10120 $optJson = array('key' => $outkey, 'value' => $outlabel, 'type' => $outtype);
10144 public function selectForForms($objectdesc, $htmlname, $preSelectedValue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $disabled = 0, $selected_input_value = '', $objectfield = '')
10146 global $conf, $extrafields, $user, $hookmanager, $action;
10148 // Example of common usage for a link to a thirdparty
10150 // We got this in a modulebuilder form of "
MyObject" of module "mymodule
".
10151 // When ->fields is array( ... "fk_soc
" => array("type"=>"integer:
Societe:societe/
class/societe.class.php:1:((
status:=:1) AND (entity:IN:__SHARED_ENTITIES__))
" ...), we have
10152 // $objectdesc = 'Societe'
10153 // $objectfield = Method 1: 'myobject@mymodule:fk_soc' ('fk_soc' is code to retrieve myobject->fields['fk_soc'])
10154 // Method 2 recommended (it can be the array): array("type"=>"integer:
Societe:societe/class/societe.class.php:1:((
status:=:1) AND (entity:IN:__SHARED_ENTITIES__))
" ...)
10156 // We got this when showing an extrafields on resource that is a link to societe
10157 // When extrafields 'link_to_societe' for object Resource is 'link' to 'Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))', we have
10158 // $objectdesc = 'Societe'
10159 // $objectfield = Method 1: 'resource:options_link_to_societe'
10160 // Method 2 recommended (it can be the array): array("type"=>'Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))" ...)
10169 $objectdescorig = $objectdesc;
10171 $InfoFieldList = array();
10176 if (is_array($objectfield)) {
10177 $objectdesc = $objectfield[
'type'];
10178 $objectdesc = preg_replace(
'/^integer[^:]*:/',
'', $objectdesc);
10179 } elseif ($objectfield) {
10181 $tmparray = explode(
':', $objectfield);
10184 $objectforfieldstmp = fetchObjectByElement(0, strtolower($tmparray[0]));
10186 if (is_object($objectforfieldstmp)) {
10190 if (preg_match(
'/^options_(.*)$/', $tmparray[1], $reg)) {
10194 $extrafields->fetch_name_optionals_label($objectforfieldstmp->table_element);
10196 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element][
'type'][$key]) && $extrafields->attributes[$objectforfieldstmp->table_element][
'type'][$key] ==
'link') {
10197 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element][
'param'][$key][
'options'])) {
10198 $tmpextrafields = array_keys($extrafields->attributes[$objectforfieldstmp->table_element][
'param'][$key][
'options']);
10199 $objectdesc = $tmpextrafields[0];
10204 if (array_key_exists($tmparray[1], $objectforfieldstmp->fields)) {
10205 $objectdesc = $objectforfieldstmp->fields[$tmparray[1]][
'type'];
10206 $objectdesc = preg_replace(
'/^integer[^:]*:/',
'', $objectdesc);
10217 $InfoFieldList = explode(
":", $objectdesc, 4);
10218 $vartmp = (empty($InfoFieldList[3]) ?
'' : $InfoFieldList[3]);
10220 if (preg_match(
'/^.*:(\w*)$/', $vartmp, $reg)) {
10221 $InfoFieldList[4] = $reg[1];
10223 $InfoFieldList[3] = preg_replace(
'/:\w*$/',
'', $vartmp);
10225 $classname = $InfoFieldList[0];
10226 $classpath = empty($InfoFieldList[1]) ?
'' : $InfoFieldList[1];
10228 $filter = empty($InfoFieldList[3]) ?
'' : $InfoFieldList[3];
10229 $sortfield = empty($InfoFieldList[4]) ?
'' : $InfoFieldList[4];
10232 $objecttmp = fetchObjectByElement(0, strtolower($InfoFieldList[0]));
10235 if (empty($objecttmp) && !empty($classpath)) {
10238 if ($classname && class_exists($classname)) {
10239 $objecttmp =
new $classname($this->db);
10246 $sharedentities = (is_object($objecttmp) && property_exists($objecttmp,
'element')) ?
getEntity($objecttmp->element) : strtolower($classname);
10247 $filter = str_replace(
10248 array(
'__ENTITY__',
'__SHARED_ENTITIES__',
'__USER_ID__'),
10249 array(
$conf->entity, $sharedentities, $user->id),
10253 if (!is_object($objecttmp)) {
10254 dol_syslog(
'selectForForms: Error bad setup of field objectdescorig=' . $objectdescorig.
', objectfield='.(is_array($objectfield) ?
'array' : $objectfield).
', objectdesc='.$objectdesc, LOG_WARNING);
10255 return 'selectForForms: Error bad setup of field objectdescorig=' . $objectdescorig.
', objectfield='.(is_array($objectfield) ?
'array' : $objectfield).
', objectdesc='.$objectdesc;
10257 '@phan-var-force CommonObject $objecttmp';
10260 $prefixforautocompletemode = $objecttmp->element;
10261 if ($prefixforautocompletemode ==
'societe') {
10262 $prefixforautocompletemode =
'company';
10264 if ($prefixforautocompletemode ==
'product') {
10265 $prefixforautocompletemode =
'produit';
10268 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) .
'_USE_SEARCH_TO_SELECT';
10270 dol_syslog(get_class($this) .
"::selectForForms filter=" . $filter, LOG_DEBUG);
10278 if ($preSelectedValue && empty($selected_input_value)) {
10279 $objecttmp->fetch($preSelectedValue);
10280 $selected_input_value = ($prefixforautocompletemode ==
'company' ? $objecttmp->name : $objecttmp->ref);
10282 $oldValueForShowOnCombobox = 0;
10283 foreach ($objecttmp->fields as $fieldK => $fielV) {
10284 if (!array_key_exists(
'showoncombobox', $fielV) || !$fielV[
'showoncombobox'] || empty($objecttmp->$fieldK)) {
10288 if (!$oldValueForShowOnCombobox) {
10289 $selected_input_value =
'';
10292 $selected_input_value .= $oldValueForShowOnCombobox ?
' - ' :
'';
10293 $selected_input_value .= $objecttmp->$fieldK;
10294 $oldValueForShowOnCombobox = empty($fielV[
'showoncombobox']) ? 0 : $fielV[
'showoncombobox'];
10299 $urlforajaxcall = DOL_URL_ROOT .
'/core/ajax/selectobject.php';
10300 $urloption =
'htmlname=' . urlencode($htmlname) .
'&outjson=1&objectdesc=' . urlencode($objectdescorig) . (is_scalar($objectfield) ?
'&objectfield='.urlencode($objectfield) :
'') . ($sortfield ?
'&sortfield=' . urlencode($sortfield) :
'');
10304 $parameters = array(
10305 'urloption' => $urloption,
10306 'object' => $objecttmp,
10307 'htmlname' => $htmlname,
10308 'filter' => $filter,
10309 'searchkey' => $searchkey,
10311 $reshook = $hookmanager->executeHooks(
'selectForFormsListUrl', $parameters, $objecttmp, $action);
10312 if (!empty($reshook)) {
10313 $urloption = $hookmanager->resPrint;
10314 $hookmanager->resPrint =
'';
10319 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
10320 $out .=
'<input type="text" class="' . $morecss .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . ($placeholder ?
' placeholder="' .
dol_escape_htmltag($placeholder) .
'"' :
'') .
' />';
10323 $out .= $this->selectForFormsList($objecttmp, $htmlname, $preSelectedValue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled, $sortfield, $filter);
10351 public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty =
'', $searchkey =
'', $placeholder =
'', $morecss =
'', $moreparams =
'', $forcecombo = 0, $outputmode = 0, $disabled = 0, $sortfield =
'', $filter =
'', $sortorder =
'ASC')
10353 global $langs, $user, $hookmanager;
10357 $prefixforautocompletemode = $objecttmp->element;
10358 if ($prefixforautocompletemode ==
'societe') {
10359 $prefixforautocompletemode =
'company';
10361 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) .
'_USE_SEARCH_TO_SELECT';
10363 $fieldstoshow =
'';
10364 if (!empty($objecttmp->fields)) {
10365 $tmpfieldstoshow =
'';
10366 foreach ($objecttmp->fields as $key => $val) {
10367 if (! (
int)
dol_eval((
string) $val[
'enabled'], 1, 1,
'1')) {
10370 if (!empty($val[
'showoncombobox'])) {
10371 $tmpfieldstoshow .= ($tmpfieldstoshow ?
',' :
'') .
't.' . $key;
10374 if ($tmpfieldstoshow) {
10375 $fieldstoshow = $tmpfieldstoshow;
10377 } elseif ($objecttmp->element ===
'category') {
10378 $fieldstoshow =
't.label';
10381 $objecttmp->fields[
'ref'] = array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'enabled' => 1,
'position' => 10,
'visible' => 4,
'showoncombobox' => 1);
10384 if (empty($fieldstoshow)) {
10385 if (!empty($objecttmp->parent_element)) {
10386 $fieldstoshow =
'o.ref';
10387 if (empty($sortfield)) {
10388 $sortfield =
'o.ref';
10390 if (in_array($objecttmp->element, [
'commandedet',
'propaldet',
'facturedet',
'expeditiondet'])) {
10391 $fieldstoshow .=
',p.ref AS p_ref,p.label,t.description';
10392 $sortfield .=
', p.ref';
10394 } elseif (isset($objecttmp->fields[
'ref'])) {
10395 $fieldstoshow =
't.ref';
10397 $langs->load(
"errors");
10398 $this->error = $langs->trans(
"ErrorNoFieldWithAttributeShowoncombobox");
10399 return $langs->trans(
'ErrorNoFieldWithAttributeShowoncombobox');
10404 $outarray = array();
10405 $tmparray = array();
10409 $sanitizedfieldstoshow = $fieldstoshow;
10412 $sql =
"SELECT t.rowid, " . $sanitizedfieldstoshow .
" FROM " . $this->db->prefix() . $this->db->sanitize($objecttmp->table_element) .
" as t";
10413 if (!empty($objecttmp->isextrafieldmanaged)) {
10414 $extrafieldTable = $objecttmp->table_element;
10415 if ($extrafieldTable ==
'categorie') {
10416 $extrafieldTable =
'categories';
10418 $sql .=
" LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($extrafieldTable) .
"_extrafields as e ON t.rowid = e.fk_object";
10420 if (!empty($objecttmp->parent_element)) {
10421 '@phan-var-force CommonObjectLine $objecttmp';
10424 $sql .=
" INNER JOIN " . $this->db->prefix() . $this->db->sanitize($parent_properties[
'table_element']) .
" as o ON o.rowid = t.".$this->db->sanitize($objecttmp->fk_parent_attribute);
10426 if (!empty($objecttmp->parent_element) && in_array($objecttmp->parent_element, [
'commande',
'propal',
'facture',
'expedition'])) {
10427 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product as p ON p.rowid = t.fk_product";
10429 if (!empty($objecttmp->ismultientitymanaged)) {
10430 if ($objecttmp->ismultientitymanaged == 1) {
10433 if (!is_numeric($objecttmp->ismultientitymanaged)) {
10434 $tmparray = explode(
'@', $objecttmp->ismultientitymanaged);
10435 $sql .=
" INNER JOIN " . $this->db->prefix() . $this->db->sanitize($tmparray[1]) .
" as parenttable ON parenttable.rowid = t." . $this->db->sanitize($tmparray[0]);
10440 $parameters = array(
10441 'object' => $objecttmp,
10442 'htmlname' => $htmlname,
10443 'filter' => $filter,
10444 'searchkey' => $searchkey
10447 $reshook = $hookmanager->executeHooks(
'selectForFormsListWhere', $parameters);
10448 if (!empty($hookmanager->resPrint)) {
10449 $sql .= $hookmanager->resPrint;
10451 $sql .=
" WHERE 1=1";
10454 if (!empty($objecttmp->ismultientitymanaged)) {
10455 if ($objecttmp->ismultientitymanaged == 1) {
10456 $sql .=
" AND t.entity IN (" .
getEntity($objecttmp->element) .
")";
10458 if (!is_numeric($objecttmp->ismultientitymanaged)) {
10459 $sql .=
" AND parenttable.entity = t." . $this->db->sanitize($tmparray[0]);
10463 if ($objecttmp->ismultientitymanaged ===
'fk_soc@societe') {
10464 if (!$user->hasRight(
'societe',
'client',
'voir') && empty($user->socid)) {
10465 $sql .=
" AND EXISTS (SELECT sc.rowid FROM ".$this->db->prefix() .
"societe_commerciaux as sc";
10466 $sql .=
" WHERE sc.fk_soc = t.fk_soc AND sc.fk_user = ".((int) $user->id).
")";
10472 if (!empty($user->socid)) {
10473 if ($objecttmp->element ==
'societe') {
10474 $sql .=
" AND t.rowid = " . ((int) $user->socid);
10475 } elseif (!empty($objecttmp->fields[
'fk_soc']) || !empty($objecttmp->fields[
't.fk_soc']) || property_exists($objecttmp,
'fk_soc') || property_exists($objecttmp,
'socid')) {
10476 $sql .=
" AND t.fk_soc = " . ((int) $user->socid);
10477 } elseif (!empty($objecttmp->parent_element)) {
10478 $tmpparent = fetchObjectByElement(0, $objecttmp->parent_element,
'', 1);
10479 if (is_object($tmpparent) && (!empty($tmpparent->fields[
'fk_soc']) || !empty($tmpparent->fields[
't.fk_soc']) || property_exists($tmpparent,
'fk_soc') || property_exists($tmpparent,
'socid'))) {
10480 $sql .=
" AND o.fk_soc = " . ((int) $user->socid);
10485 $splittedfieldstoshow = explode(
',', $fieldstoshow);
10486 foreach ($splittedfieldstoshow as &$field2) {
10487 if (is_numeric($pos = strpos($field2,
' '))) {
10488 $field2 = substr($field2, 0, $pos);
10491 if ($searchkey !=
'') {
10496 $errormessage =
'';
10498 if ($errormessage) {
10499 return 'Error forging a SQL request from an universal criteria: ' . $errormessage;
10503 $sql .= $this->db->order($sortfield ? $sortfield : $fieldstoshow, $sortorder);
10508 $resql = $this->db->query($sql);
10511 $out .=
'<select id="' . $htmlname .
'" class="flat minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') . ($moreparams ?
' ' . $moreparams :
'') .
' name="' . $htmlname .
'">' .
"\n";
10514 $textifempty =
' ';
10518 if ($showempty && !is_numeric($showempty)) {
10519 $textifempty = $langs->trans($showempty);
10521 $textifempty .= $langs->trans(
"All");
10525 $out .=
'<option value="-1">' . $textifempty .
'</option>' .
"\n";
10528 $num = $this->db->num_rows($resql);
10531 while ($i < $num) {
10532 $obj = $this->db->fetch_object($resql);
10535 $tmparray = explode(
',', $fieldstoshow);
10536 $oldvalueforshowoncombobox = 0;
10537 foreach ($tmparray as $key => $val) {
10538 $val = preg_replace(
'/(t|p|o)\./',
'', $val);
10539 $label .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val][
'showoncombobox'] ?
' - ' :
' ') :
'');
10540 $labelhtml .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val][
'showoncombobox'] ?
' - ' :
' ') :
'');
10541 $label .= $obj->$val;
10542 $labelhtml .= $obj->$val;
10544 $oldvalueforshowoncombobox = empty($objecttmp->fields[$val][
'showoncombobox']) ? 0 : $objecttmp->fields[$val][
'showoncombobox'];
10546 if (empty($outputmode)) {
10547 if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) {
10548 $out .=
'<option value="' . $obj->rowid .
'" selected data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
10550 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
10553 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label));
10557 if (($i % 10) == 0) {
10563 $out .=
'</select>' .
"\n";
10565 if (!$forcecombo) {
10566 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
10570 dol_print_error($this->db);
10573 $this->result = array(
'nbofelement' => $num);
10591 public static function radio($htmlName, $radioItems, $selected =
'', $moreGlobalParams = [])
10595 'disabled' =>
false,
10598 'name' => $htmlName,
10601 'labelIsHtml' => false
10608 if (!empty($radioItems)) {
10609 foreach ($radioItems as $key => $item) {
10611 if (!is_array($item)) {
10623 'value' => !isset($item[
'attr'][
'value']) ? $key :
'',
10633 if ((is_array($selected) && in_array($item[
'attr'][
'value'], $selected,
true)) || $selected === $item[
'attr'][
'value']) {
10634 $item[
'attr'][
'checked'] =
true;
10642 $text = $item[
'labelIsHtml'] ? $item[
'label'] : htmlspecialchars($item[
'label'], ENT_QUOTES | ENT_SUBSTITUTE);
10645 $out .=
'<label ' . $labelAttributes .
'><input ' . $inputAttributes .
' /> ' . $text .
'</label> ';
10676 public static function selectarray($htmlname, $array,
$id =
'', $show_empty = 0, $key_in_label = 0, $value_as_key = 0, $moreparam =
'', $translate = 0, $maxlen = 0, $disabled = 0, $sort =
'', $morecss =
'minwidth75', $addjscombo = 1, $moreparamonempty =
'', $disablebademail = 0, $nohtmlescape = 0)
10678 global
$conf, $langs;
10685 if ($value_as_key) {
10686 $array = array_combine($array, $array);
10689 '@phan-var-force array{label:string,data-html:string,disable?:int<0,1>,css?:string} $array';
10693 if ($addjscombo < 0) {
10700 $idname = str_replace(array(
'[',
']'), array(
'',
''), $htmlname);
10701 $out .=
'<select id="' . preg_replace(
'/^\./',
'', $idname) .
'" ' . ($disabled ?
'disabled="disabled" ' :
'') .
'class="flat ' . (preg_replace(
'/^\./',
'', $htmlname)) . ($morecss ?
' ' . $morecss :
'') .
' selectformat"';
10702 $out .=
' name="' . preg_replace(
'/^\./',
'', $htmlname) .
'" ' . ($moreparam ? $moreparam :
'');
10706 $textforempty =
' ';
10707 if (!empty(
$conf->use_javascript_ajax)) {
10708 $textforempty =
' ';
10710 if (!is_numeric($show_empty)) {
10711 $textforempty = $show_empty;
10713 $out .=
'<option class="optiongrey" ' . ($moreparamonempty ? $moreparamonempty .
' ' :
'') .
'value="' . (((
int) $show_empty) < 0 ? $show_empty : -1) .
'"' . (
$id == $show_empty ?
' selected' :
'') .
'>' .
dol_escape_htmltag($textforempty) .
'</option>' .
"\n";
10715 if (is_array($array)) {
10718 foreach ($array as $key => $value) {
10719 if (!is_array($value)) {
10720 $array[$key] = $langs->trans($value);
10722 $array[$key][
'label'] = $langs->trans($value[
'label']);
10727 if ($sort ==
'ASC') {
10729 } elseif ($sort ==
'DESC') {
10733 foreach ($array as $key => $tmpvalue) {
10734 if (is_array($tmpvalue)) {
10735 $value = $tmpvalue[
'label'];
10737 $disabled = empty($tmpvalue[
'disabled']) ?
'' :
' disabled';
10738 $style = empty($tmpvalue[
'css']) ?
'' :
' class="' . $tmpvalue[
'css'] .
'"';
10740 $value = $tmpvalue;
10745 if (!empty($disablebademail)) {
10746 if (($disablebademail == 1 && !preg_match(
'/<.+@.+>/', $value))
10747 || ($disablebademail == 2 && preg_match(
'/---/', $value))) {
10748 $disabled =
' disabled';
10749 $style =
' class="warning"';
10752 if ($key_in_label) {
10753 if (empty($nohtmlescape)) {
10756 $selectOptionValue = $key .
' - ' . ($maxlen ?
dol_trunc($value, $maxlen) : $value);
10759 if (empty($nohtmlescape)) {
10762 $selectOptionValue = $maxlen ?
dol_trunc($value, $maxlen) : $value;
10764 if ($value ==
'' || $value ==
'-') {
10765 $selectOptionValue =
' ';
10768 $out .=
'<option value="' . $key .
'"';
10769 $out .= $style . $disabled;
10770 $out .= is_array($tmpvalue) && !empty($tmpvalue[
'parent']) ?
' parent="' . dolPrintHTMLForAttribute($tmpvalue[
'parent']) .
'"' :
'';
10771 if (is_array(
$id)) {
10772 if (in_array($key,
$id) && !$disabled) {
10773 $out .=
' selected';
10777 if (
$id !=
'' && ((
$id == (
string) $key) || (
$id ==
'ifone' && count($array) == 1)) && !$disabled) {
10778 $out .=
' selected';
10782 if (is_array($tmpvalue)) {
10783 foreach ($tmpvalue as $keyforvalue => $valueforvalue) {
10784 if ($keyforvalue ==
'labelhtml') {
10785 $keyforvalue =
'data-html';
10787 if (preg_match(
'/^data-/', $keyforvalue)) {
10788 $out .=
' '.dol_escape_htmltag($keyforvalue).
'="'.
dol_escape_htmltag($valueforvalue).
'"';
10791 } elseif (!empty($nohtmlescape)) {
10796 $out .= $selectOptionValue;
10797 $out .=
"</option>\n";
10800 $out .=
"</select>";
10803 if ($addjscombo && $jsbeautify) {
10805 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
10806 $out .=
ajax_combobox($idname, array(), 0, 0,
'resolve', (((
int) $show_empty) < 0 ? (
string) $show_empty :
'-1'), $morecss);
10830 public static function selectArrayAjax($htmlname, $url,
$id =
'', $moreparam =
'', $moreparamtourl =
'', $disabled = 0, $minimumInputLength = 1, $morecss =
'', $callurlonselect = 0, $placeholder =
'', $acceptdelayedhtml = 0)
10833 global $delayedhtmlcontent;
10836 if (!
getDolGlobalString(
'MAIN_USE_JQUERY_MULTISELECT') && !defined(
'REQUIRE_JQUERY_MULTISELECT')) {
10840 $out =
'<select type="text" class="' . $htmlname . ($morecss ?
' ' . $morecss :
'') .
'" ' . ($moreparam ? $moreparam .
' ' :
'') .
'name="' . $htmlname .
'"></select>';
10843 if (!empty(
$conf->use_javascript_ajax)) {
10844 $tmpplugin =
'select2';
10845 $outdelayed =
"\n" .
'<!-- JS CODE TO ENABLE ' . $tmpplugin .
' for id ' . $htmlname .
' -->
10846 <script nonce="' .
getNonce() .
'">
10847 $(document).ready(function () {
10849 ' . ($callurlonselect ?
'var saveRemoteData = [];' :
'') .
'
10851 $(".' . $htmlname .
'").select2({
10854 url: "' . $url .
'",
10855 dataType: \'json\',
10857 data: function (params) {
10859 q: params.term, // search term
10863 processResults: function (data) {
10864 // parse the results into the format expected by Select2.
10865 // since we are using custom formatting functions we do not need to alter the remote JSON data
10866 //console.log(data);
10867 saveRemoteData = data;
10868 /* format json result for select2 */
10870 $.each( data, function( key, value ) {
10871 result.push({id: key, text: value.text});
10873 //return {results:[{id:\'none\', text:\'aa\'}, {id:\'rrr\', text:\'Red\'},{id:\'bbb\', text:\'Search a into projects\'}], more:false}
10874 //console.log(result);
10875 return {results: result, more: false}
10879 language: (typeof select2arrayoflanguage === \'undefined\') ? \'en\' : select2arrayoflanguage,
10880 containerCssClass: \':all:\', /* Line to add class from the original SELECT propagated to the new <span class="select2-selection...> tag */
10882 escapeMarkup:
function (markup) {
return markup; },
10883 minimumInputLength:
' . ((int) $minimumInputLength) . ',
10884 formatResult:
function (result, container, query, escapeMarkup) {
10885 return escapeMarkup(result.text);
10889 ' . ($callurlonselect ? '
10891 $(
".' . $htmlname . '").change(
function() {
10892 var selected = $(\
'.' .
dol_escape_js($htmlname) .
'\').val();
10893 console.log(
"We select in selectArrayAjax the entry "+selected)
10895 $.each( saveRemoteData,
function( key, value ) {
10896 if (key == selected)
10898 console.log(
"selectArrayAjax - Do a redirect to "+value.url)
10899 location.assign(value.url);
10908 if ($acceptdelayedhtml) {
10909 $delayedhtmlcontent .= $outdelayed;
10911 $out .= $outdelayed;
10935 public static function selectArrayFilter($htmlname, $array, $id = '
', $moreparam = '', $disableFiltering = 0, $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0, $textfortitle = '')
10938 global $delayedhtmlcontent; // Will be used later outside of this function
10940 // TODO Use an internal dolibarr component instead of select2
10941 if (!getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT
') && !defined('REQUIRE_JQUERY_MULTISELECT
')) {
10945 $out = '<select
type=
"text"'.($textfortitle ? ' title=
"'.dol_escape_htmltag($textfortitle).'"' : '').' id=
"'.$htmlname.'" class=
"'.$htmlname.($morecss ? ' ' . $morecss : '').'"'.($moreparam ? ' '.$moreparam : '').' name=
"'.$htmlname.'"><option></option></select>
';
10947 $formattedarrayresult = array();
10949 foreach ($array as $key => $value) {
10950 $o = new stdClass();
10952 $o->text = $value['text
'];
10953 $o->url = $value['url
'];
10954 $formattedarrayresult[] = $o;
10958 if (!empty($conf->use_javascript_ajax)) {
10959 $tmpplugin = 'select2
';
10960 $outdelayed = "\n" . '<!-- JS CODE TO ENABLE
' . $tmpplugin . ' for id ' . $htmlname . ' -->
10961 <script nonce=
"' . getNonce() . '">
10962 $(document).ready(
function () {
10963 var data =
' . json_encode($formattedarrayresult) . ';
10965 ' . ($callurlonselect ? 'var saveRemoteData =
' . json_encode($array) . ';
' : '') . '
10969 language: (typeof select2arrayoflanguage === \
'undefined\') ? \'en\' : select2arrayoflanguage,
10970 containerCssClass: \':all:\', /* Line to add class from the original SELECT propagated to the new <span class="select2-selection...> tag */
10972 escapeMarkup:
function (markup) {
return markup; },
10973 minimumInputLength:
' . ((int) $minimumInputLength) . ',
10974 formatResult:
function (result, container, query, escapeMarkup) {
10975 return escapeMarkup(result.text);
10977 matcher:
function (params, data) {
10979 if(! data.id)
return null;
';
10981 if ($callurlonselect) {
10982 // We forge the url with 'sall=
'
10985 var urlBase = data.url;
10986 var separ = urlBase.indexOf(
"?") >= 0 ?
"&" :
"?";
10989 saveRemoteData[data.id].url = urlBase + separ +
"search_all=" + encodeURIComponent(params.term.replace(/\
"/g, ""));';
10992 if (!$disableFiltering) {
10995 if(data.text.match(new RegExp(params.term))) {
11010 ' . ($callurlonselect ? '
11011 /* Code to execute a GET when we select a value */
11012 $(\'.' . dol_escape_js($htmlname) . '\').change(function() {
11013 var selected = $(\'.' . dol_escape_js($htmlname) . '\').val();
11014 console.log("We select
"+selected)
11016 $(\'.' . dol_escape_js($htmlname) . '\').val(""); /* reset visible combo value */
11017 $.each( saveRemoteData, function( key, value ) {
11018 if (key == selected)
11020 console.log("selectArrayFilter - Do a redirect to
"+value.url)
11021 location.assign(value.url);
11030 if ($acceptdelayedhtml) {
11031 $delayedhtmlcontent .= $outdelayed;
11033 $out .= $outdelayed;
11056 public static function multiselectarray($htmlname, $array, $selected = array(), $key_in_label = 0, $value_as_key = 0, $morecss = '', $translate = 0, $width = 0, $moreattrib = '', $nu = '', $placeholder = '', $addjscombo = -1)
11058 global $conf, $langs;
11061 if ($addjscombo < 0) {
11062 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
11069 $useenhancedmultiselect = 0;
11070 if (!empty($conf->use_javascript_ajax) && !defined('MAIN_DO_NOT_USE_JQUERY_MULTISELECT') && (getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') || defined('REQUIRE_JQUERY_MULTISELECT'))) {
11072 $useenhancedmultiselect = 1; // Use the js multiselect in one line. Possible only if $addjscombo not 0.
11076 $out .= '<span class="multiselectarray
'.$htmlname.'">';
11078 // We need a hidden field because when using the multiselect, if we unselect all, there is no
11079 // variable submitted at all, so no way to make a difference between variable not submitted and variable
11080 // submitted to nothing.
11081 $out .= '<input type="hidden
" name="'.$htmlname.'_multiselect
" value="1
">';
11082 // Output select component
11083 $out .= '<select id="'.$htmlname.'" class="multiselect
' . ($useenhancedmultiselect ? ' multiselectononeline
' : '') . ($morecss ? ' ' . $morecss : '') . '" multiple name="' . $htmlname . '[]
"' . ($moreattrib ? ' ' . $moreattrib : '') . ($width ? ' style="width:
' . (preg_match('/%/
', (string) $width) ? $width : $width . 'px
') . '"' : '') . '>' . "\n
";
11084 if (is_array($array) && !empty($array)) {
11085 if ($value_as_key) {
11086 $array = array_combine($array, $array);
11089 if (!empty($array)) {
11090 foreach ($array as $key => $value) {
11092 $tmplabel = $value;
11093 $tmplabelhtml = '';
11097 if (is_array($value) && array_key_exists('id', $value) && array_key_exists('label', $value)) {
11098 $tmpkey = $value['id'];
11099 $tmplabel = empty($value['label']) ? '' : $value['label'];
11100 $tmplabelhtml = empty($value['labelhtml']) ? (empty($value['data-html']) ? '' : $value['data-html']) : $value['labelhtml'];
11101 $tmpcolor = empty($value['color']) ? '' : $value['color'];
11102 $tmppicto = empty($value['picto']) ? '' : $value['picto'];
11103 $tmpdisabled = empty($value['disabled']) ? '' : $value['disabled'];
11105 $newval = ($translate ? $langs->trans($tmplabel) : $tmplabel);
11106 $newval = ($key_in_label ? $tmpkey . ' - ' . $newval : $newval);
11108 $tmplabelhtml = ($translate ? $langs->trans($tmplabelhtml) : $tmplabelhtml);
11109 $tmplabelhtml = ($key_in_label ? $tmpkey . ' - ' . $tmplabelhtml : $tmplabelhtml);
11111 $out .= '<option value="' . $tmpkey . '"';
11112 if (is_array($selected) && !empty($selected) && in_array((string) $tmpkey, $selected) && ((string) $tmpkey != '')) {
11113 $out .= ' selected';
11115 $out .= is_array($value) && array_key_exists('parent', $value) && !empty($value['parent']) ? ' parent="' . dolPrintHTMLForAttribute($value['parent
']) . '"' : '';
11116 if ($tmpdisabled) {
11119 if (!empty($tmplabelhtml)) {
11120 $out .= ' data-html="' . dolPrintHTMLForAttribute($tmplabelhtml) . '"';
11122 $tmplabelhtml = ($tmppicto ? img_picto('', $tmppicto, 'class="pictofixedwidth
" style="color: #
' . $tmpcolor . '"') : '') . $newval;
11123 $out .= ' data-html="' . dolPrintHTMLForAttribute($tmplabelhtml) . '"';
11126 $out .= dol_htmlentitiesbr($newval);
11127 $out .= '</option>' . "\n
";
11131 $out .= '</select>' . "\n
";
11135 // Add code for jquery to use multiselect
11136 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') || defined('REQUIRE_JQUERY_MULTISELECT')) {
11137 $out .= "\n
" . '<!-- JS CODE TO ENABLE select for id ' . $htmlname . ', addjscombo=' . $addjscombo . ' -->';
11138 $out .= "\n
" . '<script nonce="' . getNonce() . '">' . "\n
";
11139 if ($addjscombo == 1) {
11140 $moreselect2theme = ($morecss ? dol_escape_js(' '.$morecss) : '');
11141 $moreselect2theme = preg_replace('/widthcentpercentminus[^\s]*/', '', $moreselect2theme);
11143 $widthTypeOfAutocomplete = 'resolve';
11145 $tmpplugin = getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT', (defined('REQUIRE_JQUERY_MULTISELECT') ? constant('REQUIRE_JQUERY_MULTISELECT') : 'select2'));
11147 // If property data-html set, we decode html entities and use this.
11148 // Note that HTML content must have been sanitized from js with dol_escape_htmltag(xxx, 0, 0, '', 0, 1) when building the select option.
11149 // TODO Move this into common js ?
11150 $out .= 'function formatResult(record, container) {' . "\n
";
11151 $out .= ' if ($(record.element).attr("data-html
") != undefined && typeof htmlEntityDecodeJs === "function
") {';
11152 $out .= ' return htmlEntityDecodeJs($(record.element).attr("data-html
"));';
11154 $out .= ' return record.text;';
11155 $out .= '}' . "\n
";
11157 $out .= 'function formatSelection(record) {' . "\n
";
11158 $out .= ' return record.text;';
11159 $out .= '}' . "\n
";
11161 // Load the select2 enhancer
11162 //$out .= 'console.log(\'addjscombo=1 for htmlname=' . dol_escape_js($htmlname) . '\');';
11163 $out .= '$(document).ready(function () {
11164 $(\'#' . dol_escape_js($htmlname) . '\').' . $tmpplugin . '({';
11165 // when $morecss contains 'onrightofpage', the select2 component must also be inside a parent with class="parentonrightofpage
"
11166 if (preg_match('/onrightofpage/', $morecss)) { // In this cas, htmlname must be an ID not a class.
11167 $out .= ' dropdownAutoWidth: true, ';
11168 $out .= ' dropdownParent: $(\'#'.$htmlname.'\').parent(), ';
11170 if ($placeholder) {
11174 text: \''.dol_escape_js($placeholder).'\'
11177 $out .= ' dir: \'ltr\',
11178 width: \''.dol_escape_js($widthTypeOfAutocomplete).'\', /* off or resolve */
11179 theme: \'default' . dol_escape_js($moreselect2theme) . '\', /* to add css on generated html components */
11180 containerCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag (ko with multiselect) */
11181 selectionCssClass: \
':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag */
11182 dropdownCssClass: \'dol-dropdown-dialog dol-dropdown-dialogmulti\', /* Line to add class on the new <span class="select2-selection...> tag (ok with multiselect). Need full version of select2. */
11183 // Specify format function for dropdown item
11184 formatResult: formatResult,
11185 templateResult: formatResult, /* For 4.0 */
11186 escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
11187 // Specify format function for selected item
11188 formatSelection: formatSelection,
11189 templateSelection: formatSelection, /* For 4.0 */
11190 language: (typeof select2arrayoflanguage === \'undefined\') ? \'en\' : select2arrayoflanguage
11193 /* Add also morecss to the css .select2 that is after the #htmlname, for component that are shown dynamically after load, because select2 set
11194 the size only if component is not hidden by default on load */
11197 } elseif ($addjscombo == 2 && !defined(
'DISABLE_MULTISELECT')) {
11201 $out .=
'console.log(\'addjscombo=2 for htmlname=' .
dol_escape_js($htmlname) .
'\');
';
11202 $out .= '$(document).ready(
function () {
11204 containerHTML: \
'<div class="multi-select-container">\',
11205 menuHTML: \'<div class="multi-select-menu">\',
11206 buttonHTML: \'<span class="multi-select-button ' .
dol_escape_js($morecss) .
'">\',
11207 menuItemHTML: \'<label class="multi-select-menuitem">\',
11208 activeClass: \'multi-select-container--open\',
11213 $out .= '</script>
';
11233 public static function multiSelectArrayWithCheckbox($htmlname, &$array, $varpage, $pos = '
', $draganddrop = 0)
11235 global $conf, $langs, $user;
11237 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER
')) {
11240 if (empty($array)) {
11244 $tmpvar = "MAIN_SELECTEDFIELDS_" . $varpage; // To get list of saved selected fields to show
11246 if (!empty($user->conf->$tmpvar)) { // A list of fields was already customized for user
11247 $tmparray = explode(',
', $user->conf->$tmpvar);
11248 foreach ($array as $key => $val) {
11250 //var_dump($tmparray);
11251 if (in_array($key, $tmparray)) {
11252 $array[$key]['checked
'] = 1;
11254 $array[$key]['checked
'] = 0;
11257 } else { // There is no list of fields already customized for user
11258 foreach ($array as $key => $val) {
11259 if (!empty($array[$key]['checked
']) && $array[$key]['checked
'] < 0) {
11260 $array[$key]['checked
'] = 0;
11265 $listoffieldsforselection = '';
11266 $listcheckedstring = '';
11268 foreach ($array as $key => $val) {
11270 // var_dump(array_key_exists('enabled
', $val));
11271 // var_dump(!$val['enabled
']);
11272 if (array_key_exists('enabled
', $val) && isset($val['enabled
']) && !$val['enabled
']) {
11273 unset($array[$key]); // We don't want
this field
11276 if (!empty($val[
'type']) && $val[
'type'] ==
'separate') {
11281 if (!empty($val[
'label']) && $val[
'label']) {
11282 if (!empty($val[
'langfile']) && is_object($langs)) {
11283 $langs->load($val[
'langfile']);
11287 $listoffieldsforselection .=
'<li '.(!empty($draganddrop) ?
'class="fieldsortable" id="'.$key :
'').
'"><input type="checkbox" id="checkbox' . $key .
'" value="' . $key .
'"' . ((!array_key_exists(
'checked', $val) || empty($val[
'checked']) || $val[
'checked'] ==
'-1') ?
'' :
' checked="checked"') .
' data-position="'.(empty($val[
'position']) ?
'' : $val[
'position']).
'" />';
11288 $listoffieldsforselection .=
'<label for="checkbox' . $key .
'" class="paddingleft">';
11289 $listoffieldsforselection .= dolPrintHTML(
dol_string_nohtmltag($langs->trans($val[
'label'])));
11290 $listoffieldsforselection .=
'</label>';
11291 if (!empty($draganddrop)) {
11292 $listoffieldsforselection .= img_picto($langs->trans(
"MoveField", !empty($key) ? $key :
'none'),
'grip_title',
'class="opacitymedium boxhandle hideonsmartphone cursormove marginleftonly"');
11294 $listoffieldsforselection .=
'</li>';
11295 $listcheckedstring .= (empty($val[
'checked']) ?
'' : $key .
',');
11299 $out =
'<!-- Component multiSelectArrayWithCheckbox ' . $htmlname .
' -->
11301 <dl class="dropdown">
11303 <a href="#' . $htmlname .
'" class="multiselectpicto">
11304 ' . img_picto(
'',
'list') .
'
11306 <input type="hidden" class="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $listcheckedstring .
'">
11308 <dd class="dropdowndd">
11309 <div class="multiselectcheckbox'.$htmlname.
'">
11310 <ul class="'.$htmlname.(((string) $pos ==
'1' || (
string) $pos ==
'left') ?
'left' :
'').(!empty($draganddrop) ?
' sortable' :
'').
'">
11311 <li class="liinputsearch">
11312 <input class="inputsearch_dropdownselectedfields width90p minwidth200imp" style="width:90%;" type="text" placeholder="'.$langs->trans(
'Search').
'">
11314 '.$listoffieldsforselection.
'
11321 function updateFieldOrder() {
11322 var positionfields = $(".sortable").sortable("toArray");
11324 url: \''.DOL_URL_ROOT.
'/core/ajax/changepositionfields.php?positionfields=\'+positionfields+\'&token='.
newToken().
'&action=listafterchangingpositionfields&contextpage='.$varpage.
'&userid='.$user->id.
'\',
11326 success: function () {
11328 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'";
11332 $( ".sortable" ).sortable({
11333 handle: \'.boxhandle\',
11334 revert: \'invalid\',
11335 items: \'.fieldsortable\',
11336 stop: function(event, ui) {
11337 console.log("We moved box so we call updateBoxOrder with ajax actions");
11338 updateFieldOrder(); /* 1 to avoid message after a move */
11343 <script nonce="' .
getNonce() .
'" type="text/javascript">
11344 jQuery(document).ready(function () {
11345 $(\'.multiselectcheckbox' . $htmlname .
' input[type="checkbox"]\').on("click", function () {
11346 console.log("A new field was added/removed, we edit field input[name=formfilteraction]");
11348 $("input:hidden[name=formfilteraction]").val(\'listafterchangingselectedfields\'); // Update field so we know we changed something on selected fields after POST
11350 var title = $(this).val() + ",";
11351 if ($(this).is(\':checked\')) {
11352 $(\'.' . $htmlname .
'\').val(title + $(\'.' . $htmlname .
'\').val());
11355 $(\'.' . $htmlname .
'\').val( $(\'.' . $htmlname .
'\').val().replace(title, \'\') )
11357 // Now, we submit page
11358 //$(this).parents(\'form:first\').submit();
11361 $("input.inputsearch_dropdownselectedfields").on("keyup", function() {
11362 console.log("keyup on inputsearch_dropdownselectedfields");
11363 var value = $(this).val().toLowerCase();
11364 $(\'.multiselectcheckbox'.$htmlname.
' li > label\').filter(function() {
11365 $(this).parent().toggle($(this).text().toLowerCase().indexOf(value) > -1)
11369 if (empty(
$conf->browser->layout) ||
$conf->browser->layout !=
'phone') {
11371 $(".dropdown dt a").on("click", function () {
11372 console.log("Click on dropdown, we set focus to search field");
11373 setTimeout(() => { $(\'.inputsearch_dropdownselectedfields\').focus(); }, 200);
11397 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
11400 $categories = $cat->containing(
$id, $type);
11402 if ($rendermode == 1 || $rendermode == 2) {
11403 $toprint = array();
11404 foreach ($categories as
$c) {
11405 $ways =
$c->print_all_ways(
'auto', ($nolink ?
'none' :
''), 0, 1, ($rendermode == 2 ? 0 : 1));
11406 foreach ($ways as $way) {
11407 $color =
$c->color;
11408 $sfortag =
'<li class="select2-search-choice-dolibarr noborderoncategories'.(empty($toprint) ?
' nomarginleft' :
'');
11409 $forced_color =
'categtextwhite';
11411 $forced_color =
'categtextblack';
11413 $sfortag .=
' '.$forced_color;
11415 $sfortag .= ($color ?
' style="background: #' . $color .
';"' :
' style="background: #bbb"');
11416 $titlestring = $ways[0];
11418 $sfortag .=
' title="' . dolPrintHTMLForAttribute($titlestring) .
'"';
11420 if ($rendermode == 1) {
11421 $sfortag .=
'<a href="'.DOL_URL_ROOT.
'/categories/viewcat.php?id='.((int)
$c->id).
'&type='.urlencode(
$c->type).
'" class="'.$forced_color.
'" tabindex="-1">';
11422 $sfortag .= img_picto(
'',
'category',
'class="paddingright"');
11423 if (
$conf->dol_optimize_smallscreen) {
11424 $sfortag .= dolPrintHTML(
dol_trunc(
$c->label, 8));
11426 $sfortag .= dolPrintHTML(
$c->label);
11428 $sfortag .=
'</a>';
11432 $sfortag .=
'</li>';
11434 $toprint[] = $sfortag;
11437 if (empty($toprint)) {
11440 return '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
11444 if ($rendermode == 0) {
11445 $arrayselected = array();
11446 $cate_arbo = $this->select_all_categories($type,
'',
'parent', 64, 0, 3);
11447 foreach ($categories as
$c) {
11448 $arrayselected[(string)
$c->id] = (
string)
$c->id;
11451 return $this->multiselectarray(
'categories', $cate_arbo, $arrayselected, 0, 0,
'', 0,
'100%',
'disabled',
'category');
11454 return 'ErrorBadValueForParameterRenderMode';
11468 global
$conf, $langs, $hookmanager;
11474 $object->fetchObjectLinked();
11477 $hookmanager->initHooks(array(
'commonobject'));
11478 $parameters = array(
11479 'morehtmlright' => $morehtmlright,
11480 'compatibleImportElementsList' => &$compatibleImportElementsList,
11482 $reshook = $hookmanager->executeHooks(
'showLinkedObjectBlock', $parameters,
$object, $action);
11484 $nbofdifferenttypes = count(
$object->linkedObjects);
11486 if (empty($reshook)) {
11487 print
'<!-- showLinkedObjectBlock -->';
11488 print
load_fiche_titre($langs->trans($title), $morehtmlright,
'', 0,
'',
'showlinkedobjectblock');
11491 print
'<div class="div-table-responsive-no-min">';
11492 print
'<table class="noborder allwidth" data-block="showLinkedObject" data-element="' .
$object->element .
'" data-elementid="' .
$object->id .
'" >';
11494 print
'<tr class="liste_titre">';
11495 print
'<td>' . $langs->trans(
"Type") .
'</td>';
11496 print
'<td>' . $langs->trans(
"Ref") .
'</td>';
11499 print
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
11500 print
'<td class="right">' . $langs->trans(
"Status") .
'</td>';
11504 $nboftypesoutput = 0;
11506 foreach (
$object->linkedObjects as $objecttype => $objects) {
11507 $tplpath = $element = $subelement = $objecttype;
11510 global $showImportButton;
11511 $showImportButton =
false;
11512 if (!empty($compatibleImportElementsList) && in_array($element, $compatibleImportElementsList)) {
11513 $showImportButton =
true;
11518 if ($objecttype !=
'supplier_proposal' && preg_match(
'/^([^_]+)_([^_]+)/i', $objecttype, $regs)) {
11519 $element = $regs[1];
11520 $subelement = $regs[2];
11521 $tplpath = $element .
'/' . $subelement;
11523 $tplname =
'linkedobjectblock';
11526 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $objecttype, $regs)) {
11527 $element = $regs[1];
11529 $tplpath =
$module.
'/' . $element;
11530 $tplname = $tplname.
'_'.$element;
11534 if ($objecttype ==
'facture') {
11535 $tplpath =
'compta/' . $element;
11539 } elseif ($objecttype ==
'facturerec') {
11540 $tplpath =
'compta/facture';
11541 $tplname =
'linkedobjectblockForRec';
11545 } elseif ($objecttype ==
'propal') {
11546 $tplpath =
'comm/' . $element;
11550 } elseif ($objecttype ==
'supplier_proposal') {
11554 } elseif ($objecttype ==
'shipping' || $objecttype ==
'shipment' || $objecttype ==
'expedition') {
11555 $tplpath =
'expedition';
11559 } elseif ($objecttype ==
'reception') {
11560 $tplpath =
'reception';
11564 } elseif ($objecttype ==
'delivery') {
11565 $tplpath =
'delivery';
11569 } elseif ($objecttype ==
'ficheinter') {
11570 $tplpath =
'fichinter';
11574 } elseif ($objecttype ==
'invoice_supplier') {
11575 $tplpath =
'fourn/facture';
11576 } elseif ($objecttype ==
'order_supplier') {
11577 $tplpath =
'fourn/commande';
11578 } elseif ($objecttype ==
'expensereport') {
11579 $tplpath =
'expensereport';
11580 } elseif ($objecttype ==
'subscription') {
11581 $tplpath =
'adherents';
11582 } elseif ($objecttype ==
'conferenceorbooth') {
11583 $tplpath =
'eventorganization';
11584 } elseif ($objecttype ==
'conferenceorboothattendee') {
11585 $tplpath =
'eventorganization';
11586 } elseif ($objecttype ==
'mo') {
11591 } elseif ($objecttype ==
'project_task') {
11592 $tplpath =
'projet/tasks';
11595 global $linkedObjectBlock;
11596 $linkedObjectBlock = $objects;
11599 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array(
'/' . $tplpath .
'/tpl'));
11601 foreach ($dirtpls as $reldir) {
11602 $reldir = rtrim($reldir,
'/');
11603 if ($nboftypesoutput == ($nbofdifferenttypes - 1)) {
11604 global $noMoreLinkedObjectBlockAfter;
11605 $noMoreLinkedObjectBlockAfter = 1;
11607 $file =
dol_buildpath($reldir .
'/' . $tplname .
'.tpl.php');
11608 if (file_exists($file)) {
11609 $res = @include $file;
11611 $nboftypesoutput++;
11618 if (!$nboftypesoutput) {
11619 print
'<tr><td colspan="7"><span class="opacitymedium">' . $langs->trans(
"None") .
'</span></td></tr>';
11624 if (!empty($compatibleImportElementsList)) {
11625 $res = @include
dol_buildpath(
'core/tpl/objectlinked_lineimport.tpl.php');
11631 return $nbofdifferenttypes;
11645 global
$conf, $langs, $hookmanager, $form;
11650 if (empty($form)) {
11651 $form =
new Form($this->db);
11655 $linktoelemlist =
'';
11656 $listofidcompanytoscan =
'';
11658 if (!is_object(
$object->thirdparty)) {
11659 if (
$object->element ==
'subscription' && isset(
$object->fk_adherent)) {
11665 $fk_adherent = $subby->fk_adherent;
11666 $adh->fetch($fk_adherent);
11667 $thirdparty_id = $adh->fetch_thirdparty();
11670 $thirdparty_id =
$object->thirdparty->id;
11673 $possiblelinks = array();
11675 $dontIncludeCompletedItems =
getDolGlobalString(
'DONT_INCLUDE_COMPLETED_ELEMENTS_LINKS');
11681 $maxcandidates =
getDolGlobalInt(
'MAIN_LINKTOOBJECT_MAX_CANDIDATES', 100);
11683 if (!empty($thirdparty_id) && $thirdparty_id > 0) {
11684 $listofidcompanytoscan = (int) $thirdparty_id;
11686 $listofidcompanytoscan .=
',' . (int)
$object->thirdparty->parent;
11689 include_once DOL_DOCUMENT_ROOT .
'/projet/class/project.class.php';
11690 $tmpproject =
new Project($this->db);
11691 $tmpproject->fetch((
int)
$object->fk_project);
11692 if ($tmpproject->socid > 0 && ($tmpproject->socid != $thirdparty_id)) {
11693 $listofidcompanytoscan .=
',' . (int) $tmpproject->socid;
11695 unset($tmpproject);
11698 $possiblelinks = array(
11702 'label' =>
'LinkToProposal',
11703 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"propal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'propal') .
')'.($dontIncludeCompletedItems ?
' AND t.fk_statut < 4' :
''),
11705 'shipping' => array(
11708 'label' =>
'LinkToExpedition',
11709 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"expedition as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'shipping') .
')'.($dontIncludeCompletedItems ?
' AND t.fk_statut < 2' :
''),
11714 'label' =>
'LinkToOrder',
11715 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"commande as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'commande') .
')'.($dontIncludeCompletedItems ?
' AND t.facture < 1' :
''),
11716 'linkname' =>
'commande',
11718 'subscription' => array(
11721 'label' =>
'LinkToMemberSubscription',
11722 'sql' =>
"SELECT a.fk_soc as socid, CONCAT(a.firstname, ' ', a.lastname) as name, a.entity as client, sub.rowid, sub.note as ref, '' as ref_client, sub.subscription as total_ht FROM " . $this->db->prefix() .
"adherent as a, " . $this->db->prefix() .
"subscription as sub WHERE sub.fk_adherent = a.rowid AND a.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND a.entity IN (' .
getEntity(
'subscription') .
')',
11723 'linkname' =>
'subscription',
11724 'orderby' =>
'sub.rowid DESC',
11726 'conferenceorboothattendee' => array(
11729 'label' =>
'LinkToConferenceOrBoothAttendee',
11730 'sql' =>
"SELECT s.rowid as socid, CONCAT(a.firstname, ' ', a.lastname) as name, a.rowid as rowid, a.fk_project as fk_project, a.ref as ref, a.email as email, a.date_subscription as date_subscription FROM "
11731 .$this->db->prefix().
"societe as s, "
11732 .$this->db->prefix().
"eventorganization_conferenceorboothattendee as a WHERE a.fk_soc = s.rowid AND a.fk_soc IN ("
11733 .$this->db->sanitize($listofidcompanytoscan) .
') AND s.entity IN (' .
getEntity(
'conferenceorboothattendee') .
')'
11734 . (empty(
$object->fk_project) ?
'' :
' AND a.fk_project = ' . (int)
$object->fk_project),
11735 'linkname' =>
'attendee',
11736 'orderby' =>
'a.rowid DESC',
11738 'invoice' => array(
11741 'label' =>
'LinkToInvoice',
11742 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"facture as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'invoice') .
')'.($dontIncludeCompletedItems ?
' AND t.paye < 1' :
''),
11743 'linkname' =>
'facture',
11745 'invoice_template' => array(
11748 'label' =>
'LinkToTemplateInvoice',
11749 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.titre as ref, t.total_ht FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"facture_rec as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'invoice') .
')',
11751 'contrat' => array(
11754 'label' =>
'LinkToContract',
11755 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_customer as ref_client, t.ref_supplier, SUM(td.total_ht) as total_ht
11756 FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"contrat as t, " . $this->db->prefix() .
"contratdet as td WHERE t.fk_soc = s.rowid AND td.fk_contrat = t.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'contract') .
') GROUP BY s.rowid, s.nom, s.client, t.rowid, t.ref, t.ref_customer, t.ref_supplier',
11758 'fichinter' => array(
11761 'label' =>
'LinkToIntervention',
11762 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"fichinter as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'intervention') .
')',
11764 'supplier_proposal' => array(
11767 'label' =>
'LinkToSupplierProposal',
11768 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, '' as ref_supplier, t.total_ht FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"supplier_proposal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'supplier_proposal') .
')'.($dontIncludeCompletedItems ?
' AND t.fk_statut < 4' :
''),
11770 'order_supplier' => array(
11773 'label' =>
'LinkToSupplierOrder',
11774 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"commande_fournisseur as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'commande_fournisseur') .
')'.($dontIncludeCompletedItems ?
' AND t.billed < 1' :
''),
11776 'invoice_supplier' => array(
11778 'perms' => 1,
'label' =>
'LinkToSupplierInvoice',
11779 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"facture_fourn as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'facture_fourn') .
')'.($dontIncludeCompletedItems ?
' AND t.paye < 1' :
''),
11784 'label' =>
'LinkToTicket',
11785 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.track_id, '0' as total_ht FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"ticket as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'ticket') .
')'.($dontIncludeCompletedItems ?
' AND t.fk_statut < 8' :
''),
11790 'label' =>
'LinkToMo',
11791 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.rowid, '0' as total_ht FROM " . $this->db->prefix() .
"societe as s INNER JOIN " . $this->db->prefix() .
"mrp_mo as t ON t.fk_soc = s.rowid WHERE t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'mo') .
')'.($dontIncludeCompletedItems ?
' AND t.status < 3' :
''),
11796 if (
$object->table_element ==
'commande_fournisseur') {
11797 $possiblelinks[
'mo'][
'sql'] =
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.rowid, '0' as total_ht FROM ".$this->db->prefix().
"societe as s INNER JOIN ".$this->db->prefix().
'mrp_mo as t ON t.fk_soc = s.rowid WHERE t.entity IN ('.
getEntity(
'mo').
')'.($dontIncludeCompletedItems ?
' AND t.status < 3' :
'');
11798 } elseif (
$object->table_element ==
'mrp_mo') {
11799 $possiblelinks[
'order_supplier'][
'sql'] =
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".$this->db->prefix().
"societe as s, ".$this->db->prefix().
'commande_fournisseur as t WHERE t.fk_soc = s.rowid AND t.entity IN ('.
getEntity(
'commande_fournisseur').
')'.($dontIncludeCompletedItems ?
' AND t.billed < 1' :
'');
11803 if (!empty($listofidcompanytoscan)) {
11805 $hookmanager->initHooks(array(
'commonobject'));
11806 $parameters = array(
'listofidcompanytoscan' => $listofidcompanytoscan,
'possiblelinks' => $possiblelinks);
11807 $reshook = $hookmanager->executeHooks(
'showLinkToObjectBlock', $parameters,
$object, $action);
11810 if (empty($reshook)) {
11811 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
11812 $possiblelinks = array_merge($possiblelinks, $this->flagLinksFromHook($hookmanager->resArray));
11814 } elseif ($reshook > 0) {
11815 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
11816 $possiblelinks = $this->flagLinksFromHook($hookmanager->resArray);
11820 if (!empty($possiblelinks)) {
11821 $object->fetchObjectLinked();
11825 $htmltoenteralink =
'';
11826 foreach ($possiblelinks as $key => $possiblelink) {
11828 if (empty($possiblelink[
'enabled'])) {
11835 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $key, $regs)) {
11840 if (!empty($possiblelink[
'perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || !in_array($key, $excludelinksto))) {
11841 $htmltoenteralink .=
'<div id="' . $key .
'list"' . (empty(
$conf->use_javascript_ajax) ?
'' :
' style="display:none"') .
'>';
11845 $htmltoenteralink .=
'<br>'.
"\n";
11846 $htmltoenteralink .=
'<!-- form to add a link from anywhere -->'.
"\n";
11847 $htmltoenteralink .=
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinkedbyref' . $key .
'">';
11848 $htmltoenteralink .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
11849 $htmltoenteralink .=
'<input type="hidden" name="action" value="addlinkbyref">';
11850 $htmltoenteralink .=
'<input type="hidden" name="id" value="' .
$object->id .
'">';
11851 $htmltoenteralink .=
'<input type="hidden" name="addlink" value="' . $key .(!empty(
$module) ?
'@'.$module :
'').
'">';
11852 $htmltoenteralink .=
'<table class="noborder">';
11853 $htmltoenteralink .=
'<tr class="liste_titre">';
11855 $htmltoenteralink .=
'<td class="center"><input type="text" placeholder="'.dol_escape_htmltag($langs->trans(
"Ref")).
'" name="reftolinkto" value="' .
dol_escape_htmltag(
GETPOST(
'reftolinkto',
'alpha')) .
'">';
11856 $htmltoenteralink .=
'<br>';
11857 $htmltoenteralink .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
'ToLink') .
'"> ';
11858 $htmltoenteralink .=
'<input type="submit" class="button smallpaddingimp" name="cancel" value="' . $langs->trans(
'Cancel') .
'">';
11859 $htmltoenteralink .=
'</td>';
11860 $htmltoenteralink .=
'</tr>';
11861 $htmltoenteralink .=
'</table>';
11862 $htmltoenteralink .=
'</form>';
11865 $sql = $possiblelink[
'sql'];
11872 $truncated =
false;
11873 $applylimit = ($maxcandidates > 0 && !preg_match(
'/\bLIMIT\b/i', $sql));
11874 if ($applylimit && !empty($possiblelink[
'fromhook']) && empty($possiblelink[
'orderby'])) {
11875 $applylimit =
false;
11879 $sql .=
' ORDER BY '.$this->db->sanitize(empty($possiblelink[
'orderby']) ?
't.rowid DESC' : $possiblelink[
'orderby'], 0, 0, 1);
11880 $sql .= $this->db->plimit($maxcandidates + 1, 0);
11883 $resqllist = $this->db->query($sql);
11885 $num = $this->db->num_rows($resqllist);
11887 if ($applylimit && $num > $maxcandidates) {
11889 $num = $maxcandidates;
11895 $htmltoenteralink .=
'<br>';
11899 $htmltoenteralink .=
'<div class="opacitymedium small paddingtopbottom">';
11900 $htmltoenteralink .= img_warning().
' '.$langs->trans(
"LinkToObjectListTruncated", $maxcandidates);
11901 $htmltoenteralink .=
'</div>';
11904 $htmltoenteralink .=
'<!-- form to add a link from object to same thirdparty -->'.
"\n";
11905 $htmltoenteralink .=
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinked' . $key .
'">';
11906 $htmltoenteralink .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
11907 $htmltoenteralink .=
'<input type="hidden" name="action" value="addlink">';
11908 $htmltoenteralink .=
'<input type="hidden" name="id" value="' .
$object->id .
'">';
11909 $htmltoenteralink .=
'<input type="hidden" name="addlink" value="' . $key . (!empty(
$module) ?
'@'.$module :
'').
'">';
11910 $htmltoenteralink .=
'<table class="noborder">';
11913 case 'conferenceorboothattendee':
11915 $htmltoenteralink .= $this->makeAddLinkToAttendee(
$object, $key, $possiblelink, $num, $resqllist);
11920 $htmltoenteralink .= $this->makeAddLinkToObject(
$object, $key, $possiblelink, $num, $resqllist);
11924 $htmltoenteralink .=
'</table>';
11925 $htmltoenteralink .=
'<div class="center">';
11927 $htmltoenteralink .=
'<input type="submit" class="button valignmiddle marginleftonly marginrightonly smallpaddingimp" value="' . $langs->trans(
'ToLink') .
'">';
11929 if (empty(
$conf->use_javascript_ajax)) {
11930 $htmltoenteralink .=
'<input type="submit" class="button button-cancel marginleftonly marginrightonly smallpaddingimp" name="cancel" value="' . $langs->trans(
"Cancel") .
'"></div>';
11932 $htmltoenteralink .=
'<input type="submit" onclick="jQuery(\'#' . $key .
'list\').toggle(); return false;" class="button button-cancel marginleftonly marginrightonly smallpaddingimp" name="cancel" value="' . $langs->trans(
"Cancel") .
'"></div>';
11934 $htmltoenteralink .=
'</form>';
11937 $this->db->free($resqllist);
11939 dol_print_error($this->db);
11941 $htmltoenteralink .=
'</div>';
11946 $nbtoshow = ($truncated ? $num.
'+' : (string) $num);
11948 $linktoelemlist .=
'<li><a href="#linkto' . $key .
'" class="linkto dropdowncloseonclick" rel="' . $key .
'">' . $langs->trans($possiblelink[
'label']) .
' (' . $nbtoshow .
')</a></li>';
11951 $linktoelemlist .=
'<li><span class="linktodisabled">' . $langs->trans($possiblelink[
'label']) .
' (0)</span></li>';
11956 if ($linktoelemlist) {
11958 <dl class="dropdown" id="linktoobjectname">
11960 if (!empty(
$conf->use_javascript_ajax)) {
11961 $linktoelem .=
'<dt><a href="#linktoobjectname"><span class="fas fa-link paddingrightonly"></span>' . $langs->trans(
"LinkTo") .
'...</a></dt>';
11963 $linktoelem .=
'<dd>
11964 <div class="multiselectlinkto">
11965 <ul class="ulselectedfields">' . $linktoelemlist .
'
11974 if (!empty(
$conf->use_javascript_ajax)) {
11975 print
'<!-- Add js to show linkto box -->
11976 <script nonce="' .
getNonce() .
'">
11977 jQuery(document).ready(function() {
11978 jQuery(".linkto").click(function() {
11979 console.log("We choose to show/hide links for rel="+jQuery(this).attr(\'rel\')+" so #"+jQuery(this).attr(\'rel\')+"list");
11980 jQuery("#"+jQuery(this).attr(\'rel\')+"list").toggle();
11988 return array(
'linktoelem' => $linktoelem,
'htmltoenteralink' => $htmltoenteralink);
11990 print $htmltoenteralink;
11993 return $linktoelem;
12010 public function selectyesno($htmlname, $value =
'', $option = 0, $disabled =
false, $useempty = 0, $addjscombo = 0, $morecss =
'yesno width75', $labelyes =
'Yes', $labelno =
'No')
12021 $disabled = ($disabled ?
' disabled' :
'');
12023 $resultyesno =
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'"' . $disabled .
'>' .
"\n";
12025 $resultyesno .=
'<option value="-1"' . (($value < 0) ?
' selected' :
'') .
'> </option>' .
"\n";
12027 if ((
"$value" ==
'yes') || ($value == 1)) {
12028 $resultyesno .=
'<option value="' . $yes .
'" selected>' . $langs->trans($labelyes) .
'</option>' .
"\n";
12029 $resultyesno .=
'<option value="' . $no .
'">' . $langs->trans($labelno) .
'</option>' .
"\n";
12031 $selected = (($useempty && $value !=
'0' && $value !=
'no') ?
'' :
' selected');
12032 $resultyesno .=
'<option value="' . $yes .
'">' . $langs->trans($labelyes) .
'</option>' .
"\n";
12033 $resultyesno .=
'<option value="' . $no .
'"' . $selected .
'>' . $langs->trans($labelno) .
'</option>' .
"\n";
12035 $resultyesno .=
'</select>' .
"\n";
12038 $resultyesno .=
ajax_combobox($htmlname, array(), 0, 0,
'resolve', ($useempty < 0 ? (
string) $useempty :
'-1'), $morecss);
12041 return $resultyesno;
12058 $sql =
"SELECT rowid, label";
12059 $sql .=
" FROM " . $this->db->prefix() .
"export_model";
12060 $sql .=
" WHERE type = '" . $this->db->escape($type) .
"'";
12061 $sql .=
" ORDER BY rowid";
12062 $result = $this->db->query($sql);
12064 print
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
12066 print
'<option value="-1"> </option>';
12069 $num = $this->db->num_rows($result);
12071 while ($i < $num) {
12072 $obj = $this->db->fetch_object($result);
12073 if ($selected == $obj->rowid) {
12074 print
'<option value="' . $obj->rowid .
'" selected>';
12076 print
'<option value="' . $obj->rowid .
'">';
12084 dol_print_error($this->db);
12106 public function showrefnav(
$object, $paramid, $morehtml =
'', $shownav = 1, $fieldid =
'rowid', $fieldref =
'ref', $morehtmlref =
'', $moreparam =
'', $nodbprefix = 0, $morehtmlleft =
'', $morehtmlstatus =
'', $morehtmlright =
'')
12108 global
$conf, $langs, $hookmanager, $extralanguages;
12111 if (empty($fieldid)) {
12112 $fieldid =
'rowid';
12114 if (empty($fieldref)) {
12119 $addgendertxt =
'';
12120 if (property_exists(
$object,
'gender') && !empty(
$object->gender)) {
12121 $addgendertxt =
' ';
12124 $addgendertxt .=
'<i class="fas fa-mars valignmiddle"></i>';
12127 $addgendertxt .=
'<i class="fas fa-venus valignmiddle"></i>';
12130 $addgendertxt .=
'<i class="fas fa-transgender valignmiddle"></i>';
12136 if (is_object($hookmanager)) {
12137 $parameters = array(
'showrefnav' =>
true);
12138 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters,
$object);
12139 if (!empty($hookmanager->resPrint)) {
12140 if (empty(
$object->next_prev_filter) && preg_match(
'/^\s*AND/i', $hookmanager->resPrint)) {
12141 $object->next_prev_filter = (string) preg_replace(
'/^\s*AND\s*/i',
'', $hookmanager->resPrint);
12142 } elseif (!empty(
$object->next_prev_filter) && !preg_match(
'/^\s*AND/i', $hookmanager->resPrint)) {
12143 $object->next_prev_filter .=
' AND '.$hookmanager->resPrint;
12145 $object->next_prev_filter .= $hookmanager->resPrint;
12150 $previous_ref = $next_ref =
'';
12153 $object->load_previous_next_ref((isset(
$object->next_prev_filter) ?
$object->next_prev_filter :
''), $fieldid, $nodbprefix);
12155 $navurl = $_SERVER[
"PHP_SELF"];
12158 if ($paramid ==
'api_token_card') {
12159 if (preg_match(
'/\/user\/api_token/', $navurl)) {
12160 $navurl = preg_replace(
'/card/',
'list', $navurl);
12166 if ($paramid ==
'project_ref') {
12167 if (preg_match(
'/\/tasks\/(task|contact|note|document)\.php/', $navurl)) {
12168 $navurl = preg_replace(
'/\/tasks\/(task|contact|time|note|document)\.php/',
'/tasks.php', $navurl);
12173 $previous_ref =
$object->ref_previous ?
'<a accesskey="p" alt="'.dol_escape_htmltag($langs->trans(
"Previous")).
'" title="' .
$conf->browser->stringforfirstkey .
' p" class="classfortooltip reposition" href="' . $navurl .
'?' . $paramid .
'=' . urlencode(
$object->ref_previous) . $moreparam .
'"><i class="fa fa-chevron-left"></i></a>' :
'<span class="inactive"><i class="fa fa-chevron-left opacitymedium"></i></span>';
12174 $next_ref =
$object->ref_next ?
'<a accesskey="n" alt="'.dol_escape_htmltag($langs->trans(
"Next")).
'" title="' .
$conf->browser->stringforfirstkey .
' n" class="classfortooltip reposition" href="' . $navurl .
'?' . $paramid .
'=' . urlencode(
$object->ref_next) . $moreparam .
'"><i class="fa fa-chevron-right"></i></a>' :
'<span class="inactive"><i class="fa fa-chevron-right opacitymedium"></i></span>';
12178 $ret .=
'<!-- Start banner content --><div style="vertical-align: middle">';
12181 if ($morehtmlright) {
12182 $ret .=
'<div class="inline-block floatleft">' . $morehtmlright .
'</div>';
12185 if ($previous_ref || $next_ref || $morehtml) {
12186 $ret .=
'<div class="pagination paginationref"><ul class="right">';
12188 if ($morehtml &&
getDolGlobalInt(
'MAIN_OPTIMIZEFORTEXTBROWSER') < 2) {
12189 $ret .=
'<!-- morehtml --><li class="noborder litext' . (($shownav && $previous_ref && $next_ref) ?
' clearbothonsmartphone' :
'') .
'">' . $morehtml .
'</li>';
12191 if ($shownav && ($previous_ref || $next_ref)) {
12192 $ret .=
'<li class="pagination">' . $previous_ref .
'</li>';
12193 $ret .=
'<li class="pagination">' . $next_ref .
'</li>';
12195 if ($previous_ref || $next_ref || $morehtml) {
12196 $ret .=
'</ul></div>';
12200 $parameters = array(
'morehtmlstatus' => $morehtmlstatus);
12201 $reshook = $hookmanager->executeHooks(
'moreHtmlStatus', $parameters,
$object);
12202 if (empty($reshook)) {
12203 $morehtmlstatus .= $hookmanager->resPrint;
12205 $morehtmlstatus = $hookmanager->resPrint;
12207 if ($morehtmlstatus) {
12208 $ret .=
'<!-- status --><div class="statusref">' . $morehtmlstatus .
'</div>';
12211 $parameters = array();
12212 $reshook = $hookmanager->executeHooks(
'moreHtmlRef', $parameters,
$object);
12213 if (empty($reshook)) {
12214 $morehtmlref .= $hookmanager->resPrint;
12215 } elseif ($reshook > 0) {
12216 $morehtmlref = $hookmanager->resPrint;
12220 if ($morehtmlleft) {
12221 if (
$conf->browser->layout ==
'phone') {
12222 $ret .=
'<!-- morehtmlleft --><div class="floatleft">' . $morehtmlleft .
'</div>';
12224 $ret .=
'<!-- morehtmlleft --><div class="inline-block floatleft">' . $morehtmlleft .
'</div>';
12229 $ret .=
'<!-- Ref or ID --><div class="inline-block floatleft valignmiddle maxwidth750 marginbottomonly refid' . (($shownav && ($previous_ref || $next_ref)) ?
' refidpadding' :
'') .
'">';
12232 if (
$object->element ==
'societe') {
12233 $ret .=
'<span class="valignmiddle">'.dolPrintHTML((
string)
$object->name).
'</span>';
12236 $arrayoflangcode = array();
12241 if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
12242 if (!is_object($extralanguages)) {
12243 include_once DOL_DOCUMENT_ROOT .
'/core/class/extralanguages.class.php';
12246 $extralanguages->fetch_name_extralanguages(
'societe');
12250 if (!empty($extralanguages->attributes[
'societe']) && !empty($extralanguages->attributes[
'societe'][
'name'])) {
12251 $object->fetchValuesForExtraLanguages();
12255 foreach ($arrayoflangcode as $extralangcode) {
12257 if (
$object->array_languages[
'name'][$extralangcode]) {
12258 $htmltext .=
$object->array_languages[
'name'][$extralangcode];
12260 $htmltext .=
'<span class="opacitymedium">' . $langs->trans(
"SwitchInEditModeToAddTranslation") .
'</span>';
12263 $ret .=
'<!-- Show translations of name -->' .
"\n";
12264 $ret .= $this->textwithpicto(
'', $htmltext, -1,
'language',
'opacitymedium paddingleft');
12267 } elseif (
$object->element ==
'member') {
12268 '@phan-var-force Adherent $object';
12269 $ret .=
$object->ref .
'<br>';
12270 $fullname =
$object->getFullName($langs);
12272 $ret .=
'<span class="valignmiddle">'.dolPrintHTML((
string)
$object->societe) . ((!empty($fullname) &&
$object->societe != $fullname) ?
' (' .
dol_htmlentities($fullname) . $addgendertxt .
')' :
'').
'</span>';
12274 $ret .=
'<span class="valignmiddle">'.dolPrintHTML($fullname) . $addgendertxt . ((!empty(
$object->societe) &&
$object->societe != $fullname) ?
' (' .
dol_htmlentities((
string)
$object->societe) .
')' :
'').
'</span>';
12276 } elseif (in_array(
$object->element, array(
'contact',
'user'))) {
12277 $ret .=
'<span class="valignmiddle">'.dolPrintHTML(
$object->getFullName($langs)).
'</span>'.$addgendertxt;
12278 } elseif (
$object->element ==
'usergroup') {
12280 } elseif (in_array(
$object->element, array(
'action',
'agenda'))) {
12281 '@phan-var-force ActionComm $object';
12283 } elseif (in_array(
$object->element, array(
'adherent_type'))) {
12285 } elseif (
$object->element ==
'ecm_directories') {
12287 } elseif (
$object->element ==
'accountingbookkeeping' && !empty(
$object->context[
'mode']) &&
$object->context[
'mode'] ==
'_tmp') {
12288 $ret .=
'<span class="valignmiddle">'.$langs->trans(
"Draft").
'</span>';
12290 '@phan-var-force Ticket $object';
12291 $ret .=
'<span class="valignmiddle">'.dolPrintHTML(!empty(
$object->$fieldref) ?
$object->$fieldref :
"").
'</span>';
12292 $ret .=
' <span class="nobold small" title="'.dolPrintHTMLForAttribute($langs->trans(
"TicketTrackId")).
'">('.
$object->track_id.
')</span>';
12293 } elseif ($fieldref !=
'none') {
12295 $ret .=
'<span class="valignmiddle">'.dolPrintHTML(!empty(
$object->$fieldref) ?
$object->$fieldref :
"").
'</span>';
12297 if ($morehtmlref) {
12299 if (substr($morehtmlref, 0, 4) !=
'<div') {
12303 $ret .=
'<!-- morehtmlref -->'.$morehtmlref;
12308 $ret .=
'</div><!-- End banner content -->';
12325 if (empty(
$object->barcode)) {
12330 if (empty(
$object->barcode_type_code) || empty(
$object->barcode_type_coder)) {
12332 $result =
$object->fetchBarCode();
12335 return '<!-- ErrorFetchBarcode -->';
12340 $url = DOL_URL_ROOT .
'/viewimage.php?modulepart=barcode&generator=' . urlencode(
$object->barcode_type_coder) .
'&code=' . urlencode(
$object->barcode) .
'&encoding=' . urlencode(
$object->barcode_type_code);
12341 $out =
'<!-- url barcode = ' . $url .
' -->';
12342 $out .=
'<img src="' . $url .
'"' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
'>';
12365 public static function showphoto($modulepart,
$object, $width = 100, $height = 0, $caneditfield = 0, $cssclass =
'photowithmargin', $imagesize =
'', $addlinktofullsize = 1, $cache = 0, $forcecapture =
'', $noexternsourceoverwrite = 0, $usesharelinkifavailable = 0)
12367 global
$conf, $db, $langs;
12374 $originalfile =
'';
12378 if ($modulepart ==
'societe') {
12379 $dir =
$conf->societe->multidir_output[$entity];
12382 if ((
string) $imagesize ==
'mini') {
12384 } elseif ((
string) $imagesize ==
'small') {
12393 } elseif ($modulepart ==
'contact') {
12394 $dir =
$conf->societe->multidir_output[$entity] .
'/contact';
12396 if (!empty($photo)) {
12398 if ((
string) $imagesize ==
'mini') {
12400 } elseif ((
string) $imagesize ==
'small') {
12405 $originalfile =
get_exdir(0, 0, 0, 0,
$object,
'contact') .
'photos/' . $photo;
12410 } elseif ($modulepart ==
'userphoto') {
12411 $dir =
$conf->user->dir_output;
12413 if (!empty($photo)) {
12415 if ((
string) $imagesize ==
'mini') {
12417 } elseif ((
string) $imagesize ==
'small') {
12422 $originalfile =
get_exdir(0, 0, 0, 0,
$object,
'user') .
'photos/' . $photo;
12426 $altfile =
$object->id .
".jpg";
12430 } elseif ($modulepart ==
'memberphoto') {
12431 $dir =
$conf->member->dir_output;
12433 if (!empty($photo)) {
12435 if ((
string) $imagesize ==
'mini') {
12437 } elseif ((
string) $imagesize ==
'small') {
12442 $originalfile =
get_exdir(0, 0, 0, 0,
$object,
'member') .
'photos/' . $photo;
12446 $altfile =
$object->id .
".jpg";
12453 if ($modulepart !=
"unknown" && method_exists(
$object,
'getDataToShowPhoto')) {
12454 $tmpdata =
$object->getDataToShowPhoto($modulepart, $imagesize);
12456 $dir = $tmpdata[
'dir'];
12457 $file = $tmpdata[
'file'];
12458 $originalfile = $tmpdata[
'originalfile'];
12459 $altfile = $tmpdata[
'altfile'];
12460 $email = $tmpdata[
'email'];
12461 $capture = $tmpdata[
'capture'];
12465 if ($forcecapture) {
12466 $capture = $forcecapture;
12472 if ($file && file_exists($dir .
"/" . $file)) {
12473 if ($addlinktofullsize) {
12475 if ($urladvanced) {
12476 $ret .=
'<a href="' . $urladvanced .
'">';
12478 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
12483 if ($usesharelinkifavailable) {
12485 $relativefileforecm = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT.
'/',
'/').
'/',
'', $dir.
'/'.$originalfile);
12487 require_once DOL_DOCUMENT_ROOT .
'/ecm/class/ecmfiles.class.php';
12489 $ecmfiles->fetch(0,
'', $relativefileforecm);
12491 $sharekey = (string) $ecmfiles->share;
12494 if (!empty($sharekey)) {
12495 $ret .=
'<img alt="" class="photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
' photologo' . (preg_replace(
'/[^a-z]/i',
'_', $file)) .
'" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="' . DOL_URL_ROOT .
'/viewimage.php?hashp=' . urlencode($sharekey) .
'&cache=' . urlencode((
string) $cache) .
'">';
12497 $ret .=
'<img alt="" class="photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
' photologo' . (preg_replace(
'/[^a-z]/i',
'_', $file)) .
'" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . urlencode($modulepart) .
'&entity=' . ((int) $entity) .
'&file=' . urlencode($file) .
'&cache=' . urlencode((
string) $cache) .
'">';
12499 if ($addlinktofullsize) {
12502 } elseif ($altfile && file_exists($dir .
"/" . $altfile)) {
12503 if ($addlinktofullsize) {
12505 if ($urladvanced) {
12506 $ret .=
'<a href="' . $urladvanced .
'">';
12508 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
12511 $ret .=
'<img class="photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="Photo alt" id="photologo' . (preg_replace(
'/[^a-z]/i',
'_', $file)) .
'" class="' . $cssclass .
'" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . urlencode($modulepart) .
'&entity=' . ((int) $entity) .
'&file=' . urlencode($altfile) .
'&cache=' . urlencode((
string) $cache) .
'">';
12512 if ($addlinktofullsize) {
12516 $nophoto =
'/public/theme/common/nophoto.png';
12517 $defaultimg =
'identicon';
12518 if (in_array($modulepart, array(
'societe',
'userphoto',
'contact',
'memberphoto'))) {
12519 if ($modulepart ==
'societe' || ($modulepart ==
'memberphoto' && !empty(
$object->morphy) && strpos(
$object->morphy,
'mor') !==
false)) {
12520 $nophoto =
'company';
12522 $nophoto =
'/public/theme/common/user_anonymous.png';
12524 $nophoto =
'/public/theme/common/user_man.png';
12527 $nophoto =
'/public/theme/common/user_woman.png';
12532 if (
isModEnabled(
'gravatar') && $email && empty($noexternsourceoverwrite)) {
12534 $ret .=
'<!-- Put link to gravatar -->';
12535 $ret .=
'<img class="gravatar photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" title="'.dolPrintHTMLForAttribute(
'Gravatar avatar - '.$email).
'" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="https://www.gravatar.com/avatar/' .
dol_hash(strtolower(trim($email)),
'sha256', 1) .
'?s=' . $width .
'&d=' . $defaultimg .
'">';
12537 if ($nophoto ==
'company') {
12538 $ret .=
'<div class="divforspanimg valignmiddle inline-block center photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
'>' . img_picto(
'',
'company') .
'</div>';
12541 $ret .=
'<img class="photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="' . DOL_URL_ROOT . $nophoto .
'">';
12546 if ($caneditfield) {
12550 $ret .=
'<table class="nobordernopadding centpercent">';
12552 $ret .=
'<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> <label for="photodelete">' . $langs->trans(
"Delete") .
'</label><br><br></td></tr>';
12554 $ret .=
'<tr><td class="tdoverflow">';
12556 $maxmin = $maxfilesizearray[
'maxmin'];
12558 $ret .=
'<input type="hidden" name="MAX_FILE_SIZE" value="' . ($maxmin * 1024) .
'">';
12560 $ret .=
'<input type="file" class="flat maxwidth200onsmartphone" name="photo" id="photoinput" accept="image/*"' . ($capture ?
' capture="' . dolPrintHTMLForAttribute($capture) .
'"' :
'') .
'>';
12561 $ret .=
'</td></tr>';
12562 $ret .=
'</table>';
12587 public function select_dolgroups($selected = 0, $htmlname =
'groupid', $show_empty = 0, $exclude =
'', $disabled = 0, $include =
'', $enableonly = array(), $force_entity =
'0', $multiple =
false, $morecss =
'minwidth200')
12590 global
$conf, $user, $langs;
12593 $excludeGroups =
null;
12594 if (is_array($exclude)) {
12595 $excludeGroups = implode(
",", $exclude);
12598 $includeGroups =
null;
12599 if (is_array($include)) {
12600 $includeGroups = implode(
",", $include);
12603 if (!is_array($selected)) {
12604 $selected = array($selected);
12610 $sql =
"SELECT ug.rowid, ug.nom as name";
12611 if (
isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && !$user->entity) {
12612 $sql .=
", e.label";
12614 $sql .=
" FROM " . $this->db->prefix() .
"usergroup as ug ";
12615 if (
isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && !$user->entity) {
12616 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid=ug.entity";
12617 if ($force_entity) {
12618 $sql .=
" WHERE ug.entity IN (0, " . ((int) $force_entity) .
")";
12620 $sql .=
" WHERE ug.entity IS NOT NULL";
12623 $sql .=
" WHERE ug.entity IN (0, " . ((int)
$conf->entity) .
")";
12625 if (is_array($exclude) && $excludeGroups) {
12626 $sql .=
" AND ug.rowid NOT IN (" . $this->db->sanitize($excludeGroups) .
")";
12628 if (is_array($include) && $includeGroups) {
12629 $sql .=
" AND ug.rowid IN (" . $this->db->sanitize($includeGroups) .
")";
12631 $sql .=
" ORDER BY ug.nom ASC";
12633 dol_syslog(get_class($this) .
"::select_dolgroups", LOG_DEBUG);
12634 $resql = $this->db->query($sql);
12637 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
12639 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
12641 $num = $this->db->num_rows($resql);
12644 if ($show_empty && !$multiple) {
12645 $textforempty =
' ';
12646 if (!is_numeric($show_empty)) {
12649 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'>' . $textforempty .
'</option>' .
"\n";
12652 while ($i < $num) {
12653 $obj = $this->db->fetch_object($resql);
12655 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
12659 $label = $obj->name;
12660 $labelhtml = $obj->name;
12662 $label .=
" (" . $obj->label .
")";
12663 $labelhtml .=
' <span class="opacitymedium">(' . $obj->label .
')</span>';
12666 $out .=
'<option value="' . $obj->rowid .
'"';
12667 if ($disableline) {
12668 $out .=
' disabled';
12670 if ((isset($selected[0]) && is_object($selected[0]) && $selected[0]->
id == $obj->rowid)
12671 || ((!isset($selected[0]) || !is_object($selected[0])) && !empty($selected) && in_array($obj->rowid, $selected))) {
12672 $out .=
' selected';
12674 $out .=
' data-html="'.dol_escape_htmltag($labelhtml).
'"';
12677 $out .=
'</option>';
12682 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'></option>' .
"\n";
12684 $out .=
'<option value="" disabled>' . $langs->trans(
"NoUserGroupDefined") .
'</option>';
12686 $out .=
'</select>';
12690 dol_print_error($this->db);
12705 $out =
'<div class="nowraponall">';
12706 $out .=
'<button type="submit" class="liste_titre button_search reposition" name="button_search_x" value="x"><span class="fas fa-search"></span></button>';
12707 $out .=
'<button type="submit" class="liste_titre button_removefilter reposition" name="button_removefilter_x" value="x"><span class="fas fa-times"></span></button>';
12721 public function showCheckAddButtons($cssclass =
'checkforaction', $calljsfunction = 0, $massactionname =
"massaction")
12727 if (!empty(
$conf->use_javascript_ajax)) {
12728 $out .=
'<div class="inline-block checkallactions"><input type="checkbox" id="' . $cssclass .
's" name="' . $cssclass .
's" class="checkallactions"></div>';
12730 $out .=
'<script nonce="' .
getNonce() .
'">
12731 $(document).ready(function() {
12732 $("#' . $cssclass .
's").click(function() {
12733 if($(this).is(\':checked\')){
12734 console.log("We check all ' . $cssclass .
' and trigger the change method");
12735 $(".' . $cssclass .
'").prop(\'checked\', true).trigger(\'change\');
12739 console.log("We uncheck all");
12740 $(".' . $cssclass .
'").prop(\'checked\', false).trigger(\'change\');
12742 if ($calljsfunction) {
12743 $out .=
'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0, "' . $massactionname .
'", "' . $cssclass .
'"); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }';
12746 $(".' . $cssclass .
'").change(function() {
12747 console.log("We check and change the tr class highlight after a change on .'.$cssclass.
'");
12748 var $row = $(this).closest("tr");
12750 var anyChecked = $row.find(\'input[type="checkbox"].' . $cssclass .
':checked\').length > 0;
12751 console.log("anychecked="+anyChecked);
12753 $row.removeClass("highlight");
12755 $row.addClass("highlight");
12776 $out = $this->showFilterButtons();
12777 if ($addcheckuncheckall) {
12778 $out .= $this->showCheckAddButtons($cssclass, $calljsfunction, $massactionname);
12796 public function selectExpenseCategories($selected =
'', $htmlname =
'fk_c_exp_tax_cat', $useempty = 0, $excludeid = array(), $target =
'', $default_selected = 0, $params = array(), $info_admin = 1)
12798 global $langs, $user;
12801 $sql =
"SELECT rowid, label FROM " . $this->db->prefix() .
"c_exp_tax_cat WHERE active = 1";
12802 $sql .=
" AND entity IN (0," .
getEntity(
'c_exp_tax_cat') .
")";
12803 if (!empty($excludeid)) {
12804 $sql .=
" AND rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeid)) .
")";
12806 $sql .=
" ORDER BY label";
12808 $resql = $this->db->query($sql);
12810 $out =
'<select id="select_' . $htmlname .
'" name="' . $htmlname .
'" class="' . $htmlname .
' flat minwidth75imp maxwidth200">';
12812 $out .=
'<option value="0"> </option>';
12815 while ($obj = $this->db->fetch_object($resql)) {
12816 $out .=
'<option ' . ($selected == $obj->rowid ?
'selected="selected"' :
'') .
' value="' . $obj->rowid .
'">' . $langs->trans($obj->label) .
'</option>';
12818 $out .=
'</select>';
12821 if (!empty($htmlname) && $user->admin && $info_admin) {
12822 $out .=
' ' .
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
12825 if (!empty($target)) {
12826 $sql =
"SELECT c.id FROM " . $this->db->prefix() .
"c_type_fees as c WHERE c.code = 'EX_KME' AND c.active = 1";
12827 $resql = $this->db->query($sql);
12829 if ($this->db->num_rows($resql) > 0) {
12830 $obj = $this->db->fetch_object($resql);
12831 $out .=
'<script nonce="' .
getNonce() .
'">
12833 $("select[name=' . $target .
']").on("change", function() {
12834 var current_val = $(this).val();
12835 if (current_val == ' . $obj->id .
') {';
12836 if (!empty($default_selected) || !empty($selected)) {
12837 $out .=
'$("select[name=' . $htmlname .
']").val("' . ($default_selected > 0 ? $default_selected : $selected) .
'");';
12841 $("select[name=' . $htmlname .
']").change();
12845 $("select[name=' . $htmlname .
']").change(function() {
12847 if ($("select[name=' . $target .
']").val() == ' . $obj->id .
') {
12848 // get price of kilometer to fill the unit price
12852 data: { fk_c_exp_tax_cat: $(this).val(), token: \'' .
currentToken() .
'\' },
12853 url:
"' . (DOL_URL_ROOT . '/expensereport/ajax/ajaxik.php?' . implode('&', $params)) . '",
12854 }).done(
function( data, textStatus, jqXHR ) {
12856 if (typeof data.up !=
"undefined") {
12857 $(
"input[name=value_unit]").val(data.up);
12858 $(
"select[name=' . $htmlname . ']").attr(
"title", data.title);
12860 $(
"input[name=value_unit]").val(
"");
12861 $(
"select[name=' . $htmlname . ']").attr(
"title",
"");
12872 dol_print_error($this->db);
12886 public function selectExpenseRanges($selected = '
', $htmlname = 'fk_range
', $useempty = 0)
12891 $sql = "SELECT rowid, range_ik FROM " . $this->db->prefix() . "c_exp_tax_range";
12892 $sql .= " WHERE entity IN (0," . getEntity('c_exp_tax_range
') . ") AND active = 1";
12894 $resql = $this->db->query($sql);
12896 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
12898 $out .= '<option value=
"0"></option>
';
12901 while ($obj = $this->db->fetch_object($resql)) {
12902 $out .= '<option
' . ($selected == $obj->rowid ? 'selected=
"selected"' : '') . ' value=
"' . $obj->rowid . '">
' . price($obj->range_ik, 0, $langs, 1, 0) . '</option>
';
12904 $out .= '</select>
';
12906 dol_print_error($this->db);
12922 public function selectExpenseFees($selected = '
', $htmlname = 'fk_c_type_fees
', $useempty = 0, $allchoice = 1, $useid = 0)
12927 $sql = "SELECT id, code, label";
12928 $sql .= " FROM ".$this->db->prefix()."c_type_fees";
12929 $sql .= " WHERE active = 1";
12931 $resql = $this->db->query($sql);
12933 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
12935 $out .= '<option value=
"0"></option>
';
12938 $out .= '<option value=
"-1">
' . $langs->trans('AllExpenseReport
') . '</option>
';
12946 while ($obj = $this->db->fetch_object($resql)) {
12947 $key = $langs->trans($obj->code);
12948 $out .= '<option
' . ($selected == $obj->{$field} ? 'selected=
"selected"' : '') . ' value=
"' . $obj->{$field} . '">
' . ($key != $obj->code ? $key : $obj->label) . '</option>
';
12950 $out .= '</select>
';
12952 $out .= ajax_combobox('select_
'.$htmlname);
12954 dol_print_error($this->db);
12978 public function selectInvoiceForTimeProject($socid = -1, $selected = '
', $htmlname = 'invoiceid
', $maxlength = 24, $option_only = 0, $show_empty = '1
', $discard_closed = 0, $forcefocus = 0, $disabled = 0, $morecss = 'maxwidth500
', $projectsListId = '', $showproject = 'all
', $usertofilter = null)
12980 global $user, $conf, $langs;
12982 require_once DOL_DOCUMENT_ROOT . '/projet/
class/project.class.php
';
12984 if (is_null($usertofilter)) {
12985 $usertofilter = $user;
12990 $hideunselectables = false;
12991 if (getDolGlobalString('INVOICE_HIDE_UNSELECTABLES
')) {
12992 $hideunselectables = true;
12995 if (empty($projectsListId)) {
12996 if (!$usertofilter->hasRight('projet
', 'all
', 'lire
')) {
12997 $projectstatic = new Project($this->db);
12998 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1);
13002 // Search all projects
13003 $sql = "SELECT f.rowid, f.ref as fref, 'nolabel
' as flabel, p.rowid as pid, f.ref, p.title, p.fk_soc, p.fk_statut, p.public, s.nom as name";
13004 $sql .= " FROM " . $this->db->prefix() . "facture as f";
13005 $sql .= " INNER JOIN " . $this->db->prefix() . "projet as p ON p.entity IN (" . getEntity('project
') . ") AND f.fk_projet = p.rowid";
13006 $sql .= " LEFT JOIN " . $this->db->prefix() . "societe as s ON s.rowid = p.fk_soc";
13007 $sql .= " WHERE f.fk_statut = 0"; // Draft invoices only
13008 //if ($projectsListId) $sql.= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")";
13009 //if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
13010 //if ($socid > 0) $sql.= " AND (p.fk_soc=".((int) $socid)." OR p.fk_soc IS NULL)";
13011 $sql .= " ORDER BY p.ref, f.ref ASC";
13013 $resql = $this->db->query($sql);
13015 // Use select2 selector
13016 if (!empty($conf->use_javascript_ajax)) {
13017 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
13018 $comboenhancement = ajax_combobox($htmlname, array(), 0, $forcefocus);
13019 $out .= $comboenhancement;
13020 $morecss = 'minwidth200imp maxwidth500
';
13023 if (empty($option_only)) {
13024 $out .= '<select
class=
"valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled=
"disabled"' : '') . ' id=
"' . $htmlname . '" name=
"' . $htmlname . '">
';
13026 if (!empty($show_empty)) {
13027 $out .= '<option value=
"0" class=
"optiongrey">
';
13028 if (!is_numeric($show_empty)) {
13029 $out .= $show_empty;
13033 $out .= '</option>
';
13035 $num = $this->db->num_rows($resql);
13038 while ($i < $num) {
13039 $obj = $this->db->fetch_object($resql);
13040 // If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
13041 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$usertofilter->hasRight('societe
', 'lire
')) {
13044 if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) {
13051 if ($showproject == 'all
') {
13052 $labeltoshow .= dol_trunc($obj->ref, 18); // Invoice ref
13054 $labeltoshow .= ' -
' . $obj->name; // Soc name
13058 if ($obj->fk_statut == Project::STATUS_DRAFT) {
13060 $labeltoshow .= ' -
' . $langs->trans("Draft");
13061 } elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
13062 if ($discard_closed == 2) {
13065 $labeltoshow .= ' -
' . $langs->trans("Closed");
13066 } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
13068 $labeltoshow .= ' -
' . $langs->trans("LinkedToAnotherCompany");
13072 if (!empty($selected) && $selected == $obj->rowid) {
13073 $out .= '<option value=
"' . $obj->rowid . '" selected
';
13074 //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected
if disabled
13075 $out .=
'>' . $labeltoshow .
'</option>';
13077 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
13080 $resultat =
'<option value="' . $obj->rowid .
'"';
13082 $resultat .=
' disabled';
13087 $resultat .= $labeltoshow;
13088 $resultat .=
'</option>';
13096 if (empty($option_only)) {
13097 $out .=
'</select>';
13100 $this->db->free($resql);
13104 dol_print_error($this->db);
13123 public function selectInvoiceRec($selected =
'', $htmlname =
'facrecid', $maxlength = 24, $option_only = 0, $show_empty =
'1', $forcefocus = 0, $disabled = 0, $morecss =
'maxwidth500')
13125 global
$conf, $langs;
13131 $sql =
'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc';
13132 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'facture_rec as f';
13133 $sql .=
" WHERE f.entity IN (" .
getEntity(
'invoice') .
")";
13134 $sql .=
" ORDER BY f.titre ASC";
13136 $resql = $this->db->query($sql);
13139 if (!empty(
$conf->use_javascript_ajax)) {
13140 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
13141 $comboenhancement =
ajax_combobox($htmlname, array(), 0, $forcefocus);
13142 $out .= $comboenhancement;
13143 $morecss =
'minwidth200imp maxwidth500';
13146 if (empty($option_only)) {
13147 $out .=
'<select class="valignmiddle flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' id="' . $htmlname .
'" name="' . $htmlname .
'">';
13149 if (!empty($show_empty)) {
13150 $out .=
'<option value="0" class="optiongrey">';
13151 if (!is_numeric($show_empty)) {
13152 $out .= $show_empty;
13156 $out .=
'</option>';
13158 $num = $this->db->num_rows($resql);
13160 while ($obj = $this->db->fetch_object($resql)) {
13161 $labeltoshow =
dol_trunc($obj->title, 18);
13164 if (!empty($obj->suspended)) {
13166 $labeltoshow .=
' - ' . $langs->trans(
"Closed");
13170 if (!empty($selected) && $selected == $obj->rowid) {
13171 $out .=
'<option value="' . $obj->rowid .
'" selected';
13173 $out .=
'>' . $labeltoshow .
'</option>';
13175 if ($disabled && ($selected != $obj->rowid)) {
13178 $resultat =
'<option value="' . $obj->rowid .
'"';
13180 $resultat .=
' disabled';
13183 $resultat .= $labeltoshow;
13184 $resultat .=
'</option>';
13190 if (empty($option_only)) {
13191 $out .=
'</select>';
13196 $this->db->free($resql);
13199 $this->errors[] = $this->db->lasterror;
13215 public function searchComponent($arrayofcriterias, $search_component_params, $arrayofinputfieldsalreadyoutput = array(), $search_component_params_hidden =
'', $arrayoffiltercriterias = array())
13218 global $langs, $form;
13220 if ($search_component_params_hidden !=
'' && !preg_match(
'/^\(.*\)$/', $search_component_params_hidden)) {
13221 $search_component_params_hidden =
'(' . $search_component_params_hidden .
')';
13224 $ret =
'<!-- filterComponent -->';
13226 $ret .=
'<div class="divadvancedsearchfieldcomp centpercent inline-block">';
13227 $ret .=
'<a href="#" class="dropdownsearch-toggle unsetcolor" tabindex="-1">';
13228 $ret .=
'<span class="fas fa-filter linkobject boxfilter paddingright pictofixedwidth" title="' .
dol_escape_htmltag($langs->trans(
"Filters")) .
'" id="idsubimgproductdistribution"></span>';
13231 $ret .=
'<div class="divadvancedsearchfieldcompinput centpercentminusx inline-block minwidth500">';
13234 $ret .=
'<div id="divsearch_component_params" name="divsearch_component_params" class="noborderbottom search_component_params inline-block">';
13236 if ($search_component_params_hidden) {
13244 foreach ($arrayofandtags as $tmpkey => $tmpval) {
13245 $errormessage =
'';
13247 if ($errormessage) {
13248 $this->error =
'ERROR in parsing search string: '.$errormessage;
13251 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
13254 $ret .=
'<span class="marginleftonlyshort valignmiddle tagsearch" data-ufilterid="'.($tmpkey + 1).
'" data-ufilter="'.
dol_escape_htmltag($tmpval).
'">';
13255 $ret .=
'<span class="tagsearchdelete select2-selection__choice__remove" data-ufilterid="'.($tmpkey + 1).
'">x</span> ';
13267 $show_search_component_params_hidden = 1;
13268 if ($show_search_component_params_hidden) {
13269 $ret .=
'<input type="hidden" name="show_search_component_params_hidden" value="1">';
13271 $ret .=
"<!-- We store the full Universal Search String into this field. For example: (t.ref:like:'SO-%') AND ((t.ref:like:'CO-%') OR (t.ref:like:'AA%')) -->";
13272 $ret .=
'<input type="hidden" id="search_component_params_hidden" name="search_component_params_hidden" value="' .
dol_escape_htmltag($search_component_params_hidden) .
'">';
13277 foreach ($arrayofcriterias as $criteria) {
13278 foreach ($criteria as $criteriafamilykey => $criteriafamilyval) {
13279 if (in_array(
'search_' . $criteriafamilykey, $arrayofinputfieldsalreadyoutput)) {
13282 if (in_array($criteriafamilykey, array(
'rowid',
'ref_ext',
'entity',
'extraparams'))) {
13285 if (in_array($criteriafamilyval[
'type'], array(
'date',
'datetime',
'timestamp'))) {
13286 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_start">';
13287 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startyear">';
13288 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startmonth">';
13289 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startday">';
13290 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_end">';
13291 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endyear">';
13292 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endmonth">';
13293 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endday">';
13295 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'">';
13302 $ret .=
"<!-- Field to enter a generic filter string: t.ref:like:'SO-%', t.date_creation:>:'20160101', t.date_creation:<:'2016-01-01 12:30:00', t.nature:is:NULL, t.field2:isnot:NULL -->\n";
13303 $ret .=
'<input type="text" placeholder="' . $langs->trans(
"Filters") .
'" id="search_component_params_input" name="search_component_params_input" class="noborderall search_component_input" value="">';
13309 jQuery("#divsearch_component_params").on("click", ".tagsearchdelete", function(e) { /* Delegated, so it works also for tags added by JS */
13310 var filterid = $(this).parents().attr("data-ufilterid");
13311 console.log("We click to delete the criteria nb "+filterid);
13313 // Regenerate the search_component_params_hidden with all data-ufilter except the one to delete, and post the page
13314 var newparamstring = \'\';
13315 $(\'.tagsearch[data-ufilterid]\').each(function(index, element) {
13316 tmpfilterid = $(this).attr("data-ufilterid");
13317 if (tmpfilterid != filterid) {
13318 // We keep this criteria
13319 if (newparamstring == \'\') {
13320 newparamstring = $(this).attr("data-ufilter");
13322 newparamstring = newparamstring + \' AND \' + $(this).attr("data-ufilter");
13326 console.log("newparamstring = "+newparamstring);
13328 jQuery("#search_component_params_hidden").val(newparamstring);
13330 // We repost the form
13331 $(this).closest(\'form\').submit();
13334 jQuery("#search_component_params_input").keydown(function(e) {
13335 console.log("We press a key on the filter field that is "+jQuery("#search_component_params_input").val());
13336 console.log(e.which);
13337 if (jQuery("#search_component_params_input").val() == "" && e.which == 8) {
13338 /* We click on back when the input field is already empty */
13339 event.preventDefault();
13340 jQuery("#divsearch_component_params .tagsearch").last().remove();
13341 /* Regenerate content of search_component_params_hidden from remaining .tagsearch */
13343 jQuery("#divsearch_component_params .tagsearch").each(function( index ) {
13347 s = s + $(this).attr("data-ufilter");
13349 console.log("New value for search_component_params_hidden = "+s);
13350 jQuery("#search_component_params_hidden").val(s);
13358 $arrayoffiltercriterias_json = json_encode($arrayoffiltercriterias);
13363 $arrayoffilterelements = array();
13365 foreach ($arrayoffiltercriterias as $key => $val) {
13368 if (isset($val[
'bi']) && (
int) $val[
'bi'] == 0) {
13372 $tmpelementkey = preg_replace(
'/\.[^.]*$/',
'', $key);
13374 $tmpelementkey = preg_replace(
'/^te(__|$)/',
't$1', $tmpelementkey);
13376 $tmpelementlabel = $tmpelementkey;
13377 $tmpelementpicto =
'';
13378 $tmpfieldlabel = $key;
13379 if (!empty($val[
'labelnohtml'])) {
13380 $tmpfieldlabel = $val[
'labelnohtml'];
13382 $tmpmatch = array();
13383 if (preg_match(
'/^(.+?): /', $val[
'labelnohtml'], $tmpmatch)) {
13384 $tmpelementlabel = $tmpmatch[1];
13385 $tmpfieldlabel = trim(substr($val[
'labelnohtml'], strlen($tmpelementlabel) + 1));
13387 if (!empty($val[
'label'])) {
13389 $tmpelementpicto = trim(str_replace($val[
'labelnohtml'],
'', $val[
'label']));
13393 if (!isset($arrayoffilterelements[$tmpelementkey])) {
13394 $arrayoffilterelements[$tmpelementkey] = array(
'picto' => $tmpelementpicto,
'label' => $tmpelementlabel,
'fields' => array());
13396 $arrayoffilterelements[$tmpelementkey][
'fields'][$key] = array(
'label' => $tmpfieldlabel,
'type' => $val[
'type']);
13399 var arrayoffiltercriterias = ' . $arrayoffiltercriterias_json .
';
13404 $ret .=
'<div class="search-component-assistance">';
13407 $ret .=
'<p class="assistance-title">' . img_picto(
'',
'filter') .
' ' . $langs->trans(
'FilterAssistance') .
' </p>';
13409 $ret .=
'<p class="assistance-errors error" style="display:none">' . $langs->trans(
'AllFieldsRequired') .
' </p>';
13414 $ret .=
'<div class="operand valigntop">';
13415 $ret .=
'<div class="fieldcombo">';
13417 $ret .=
'<input type="hidden" id="search_filter_field" name="search_filter_field" value="">';
13419 $ret .=
'<button type="button" class="fieldcombo-toggle"><span class="fieldcombo-label opacitymedium">' .
dol_escape_htmltag($langs->trans(
'Fields')) .
'</span><span class="fas fa-caret-down fieldcombo-caret"></span></button>';
13423 $ret .=
'<div class="fieldcombo-panel" style="display:none">';
13424 $ret .=
'<div class="liinputsearch"><input type="text" class="fieldcombo-search noborderfocus" placeholder="' .
dol_escape_htmltag($langs->trans(
'Search')) .
'"></div>';
13425 $ret .=
'<div class="fieldcombo-list">';
13436 $renderElementCombo =
function ($tmpelementkey) use ($arrayoffilterelements, &$renderElementCombo) {
13437 $tmpelementval = $arrayoffilterelements[$tmpelementkey];
13438 $arrayofchildelementkeys = array();
13439 foreach ($arrayoffilterelements as $tmpchildelementkey => $tmpchildelementval) {
13440 if (strpos($tmpchildelementkey, $tmpelementkey.
'__') === 0 && strpos(substr($tmpchildelementkey, strlen($tmpelementkey) + 2),
'__') ===
false) {
13441 $arrayofchildelementkeys[] = $tmpchildelementkey;
13445 $out .=
'<div class="fieldcombo-element" data-element="' . dolPrintHTMLForAttribute($tmpelementkey) .
'">';
13446 $out .=
'<div class="fieldcombo-elementheader" tabindex="0"><span class="fieldcombo-elementlabel">' . $tmpelementval[
'picto'] .
' ' .
dol_escape_htmltag($tmpelementval[
'label']) .
'</span><span class="fas fa-caret-right fieldcombo-elementcaret"></span></div>';
13448 $out .=
'<div class="fieldcombo-fields" style="display:none">';
13449 foreach ($tmpelementval[
'fields'] as $tmpfieldkey => $tmpfieldval) {
13450 $out .=
'<div class="fieldcombo-field" tabindex="0" data-field="' . dolPrintHTMLForAttribute($tmpfieldkey) .
'" data-type="' . dolPrintHTMLForAttribute($tmpfieldval[
'type']) .
'">' .
dol_escape_htmltag($tmpfieldval[
'label']) .
'</div>';
13453 if (!empty($arrayofchildelementkeys)) {
13456 $out .=
'<div class="fieldcombo-children" style="display:none">';
13457 foreach ($arrayofchildelementkeys as $tmpchildelementkey) {
13458 $out .= $renderElementCombo($tmpchildelementkey);
13468 foreach ($arrayoffilterelements as $tmpelementkey => $tmpelementval) {
13470 $tmpparentkey =
'';
13471 if (strpos($tmpelementkey,
'__') !==
false) {
13472 $tmparrayofkey = explode(
'__', $tmpelementkey);
13473 array_pop($tmparrayofkey);
13474 $tmpparentkey = implode(
'__', $tmparrayofkey);
13478 if ($tmpparentkey ==
'' || !isset($arrayoffilterelements[$tmpparentkey])) {
13479 $ret .= $renderElementCombo($tmpelementkey);
13487 $ret .=
'<span class="separator"></span>';
13490 $ret .=
'<div class="operator valigntop">';
13491 $ret .=
'<select class="operator-selector width150" id="operator-selector"">';
13492 $ret .=
'</select>';
13493 $ret .=
'<script>$(document).ready(function() {';
13494 $ret .=
' $(".operator-selector").select2({';
13495 $ret .=
' dropdownCssClass: \'operator-selector-dropdown\',';
13496 $ret .=
' placeholder: \'' .
dol_escape_js($langs->transnoentitiesnoconv(
'Operator')) .
'\'';
13499 $ret .=
' $(".operator-selector").next(".select2-container").find(".select2-selection").on("keydown", function(e) {';
13500 $ret .=
' if ((e.key === "ArrowDown" || e.key === "ArrowRight") && !$(this).closest(".select2-container").hasClass("select2-container--open")) {';
13501 $ret .=
' e.preventDefault();';
13502 $ret .=
' $(".operator-selector").select2("open");';
13505 $ret .=
'});</script>';
13508 $ret .=
'<span class="separator"></span>';
13510 $ret .=
'<div class="value valigntop">';
13512 $ret .=
'<input type="text" class="flat width100 value-input" placeholder="' . dolPrintHTML($langs->trans(
'Value')) .
'">';
13516 $ret .=
'<span class="date-one" style="display:none">';
13517 $ret .= $form->selectDate(($dateOne ? $dateOne : -1),
'dateone', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'');
13521 $ret .=
'<select class="value-selector width150" id="value-selector" style="display:none">';
13522 $ret .=
'</select>';
13524 $(document).ready(function() {
13525 $("#value-selector").select2({
13526 placeholder: \'' .
dol_escape_js($langs->trans(
'Value')) .
'\'
13528 $(
"#value-selector").hide();
13529 $(
"#value-selector").next(
".select2-container").hide();
13535 $ret .= '<div
class=
"btn-div">
';
13536 $ret .= '<
button class=
"butAction add-filter-btn" type=
"button">
' . $langs->trans("addToFilter") . '</
button>
';
13540 //$ret .= '</tbody></
table>
';
13542 // End of the assistance div
13545 // Script jQuery to show/hide the floating assistance
13547 $(document).ready(
function() {
13548 $(
"#search_component_params_input").closest(
".divadvancedsearchfieldcompinput").on(
"click",
function(e) {
13550 if ($(e.target).closest(
".tagsearch").length) {
13553 const inputPosition = $(
"#search_component_params_input").offset();
13554 const inputHeight = $(
"#search_component_params_input").outerHeight();
13555 $(
".search-component-assistance").css({
13556 top: inputPosition.top + inputHeight + 5 +
"px",
13557 left: $(
"#divsearch_component_params").position().left
13558 }).slideToggle(200);
13560 $(document).on(
"click",
function(e) {
13561 if (!$(e.target).closest(
".search-component-assistance, #ui-datepicker-div").length && !$(e.target).closest(
".divadvancedsearchfieldcompinput").find(
"#search_component_params_input").length) {
13562 $(
".search-component-assistance").hide();
13566 $(
"#search_component_params_input").on(
"keydown",
function(e) {
13567 if (e.key !==
"ArrowDown" && !(e.key ===
"ArrowRight" &&
this.selectionStart ===
this.value.length)) {
13570 if ($(
".search-component-assistance").is(
":visible")) {
13573 e.preventDefault();
13574 $(
this).trigger(
"click");
13575 $(
".fieldcombo-toggle").trigger(
"focus");
13579 document.addEventListener(
"keydown",
function(e) {
13580 if (e.key !==
"Escape" || !$(
".search-component-assistance").is(
":visible")) {
13583 if ($(
".fieldcombo-panel").is(
":visible") || $(
".select2-container--open").length || $(
"#ui-datepicker-div").is(
":visible")) {
13586 $(
".search-component-assistance").hide();
13587 $(
"#search_component_params_input").trigger(
"focus");
13593 $(document).ready(
function() {
13595 function resetValueInputs() {
13596 $(
".value-input, .dateone, .datemonth, .dateyear").val(
"").hide();
13597 $(
"#datemonth, #dateyear").val(
null).trigger(
"change.select2");
13598 $(
"#dateone").datepicker(
"setDate",
null);
13599 $(
".date-one, .date-month, .date-year").hide();
13600 $(
"#value-selector").val(
"").hide();
13601 $(
"#value-selector").next(
".select2-container").hide();
13602 $(
"#value-selector").val(
null).trigger(
"change.select2");
13606 function resetOperatorAndValueInputs() {
13607 $(
".operator-selector").empty();
13608 resetValueInputs();
13613 $(
".fieldcombo-toggle").on(
"click",
function(e) {
13614 e.stopPropagation();
13615 $(
this).closest(
".fieldcombo").find(
".fieldcombo-panel").toggle();
13618 $(
this).closest(
".fieldcombo").find(
".fieldcombo-search").val(
"").trigger(
"keyup");
13620 if ($(
this).closest(
".fieldcombo").find(
".fieldcombo-panel").is(
":visible")) {
13621 $(
this).closest(
".fieldcombo").find(
".fieldcombo-search").trigger(
"focus");
13626 $(
".fieldcombo-toggle").on(
"keydown",
function(e) {
13627 if ((e.key ===
"ArrowDown" || e.key ===
"ArrowRight") && !$(
this).closest(
".fieldcombo").find(
".fieldcombo-panel").is(
":visible")) {
13628 e.preventDefault();
13629 $(
this).trigger(
"click");
13635 $(
".fieldcombo-panel").on(
"keydown",
function(e) {
13636 const isnext = (e.key ===
"ArrowDown");
13637 const isprev = (e.key ===
"ArrowUp");
13638 const search = $(
this).find(
".fieldcombo-search");
13639 if ((!isnext && !isprev) || (e.target === search[0] && e.key !==
"ArrowDown")) {
13642 e.preventDefault();
13643 const rows = $(
this).find(
".fieldcombo-elementheader:visible, .fieldcombo-field:visible");
13644 const index = (e.target === search[0] ? -1 : rows.index(e.target)) + (isnext ? 1 : -1);
13646 search.trigger(
"focus");
13647 }
else if (index < rows.length) {
13648 rows.eq(index).trigger(
"focus");
13654 $(
".fieldcombo-elementheader").on(
"click",
function(e) {
13655 e.stopPropagation();
13656 const elementdiv = $(
this).closest(
".fieldcombo-element");
13657 const wasopen = elementdiv.hasClass(
"open");
13658 $(
".fieldcombo-element").removeClass(
"open");
13659 $(
".fieldcombo-fields, .fieldcombo-children").hide();
13660 $(
".fieldcombo-field").show();
13661 elementdiv.parents(
".fieldcombo-element").addClass(
"open").show().children(
".fieldcombo-fields, .fieldcombo-children").show();
13663 elementdiv.addClass(
"open").show().children(
".fieldcombo-fields, .fieldcombo-children").show();
13668 $(
".fieldcombo-field").on(
"click",
function(e) {
13669 e.stopPropagation();
13670 const fieldlabel = $(
this).text();
13671 const elementlabelhtml = $(
this).closest(
".fieldcombo-element").find(
".fieldcombo-elementlabel").html();
13672 $(
".fieldcombo-field").removeClass(
"selected");
13673 $(
this).addClass(
"selected");
13674 $(
".fieldcombo-label").html(elementlabelhtml).removeClass(
"opacitymedium").append(document.createTextNode(
": " + fieldlabel));
13675 $(
"#search_filter_field").attr(
"data-type", $(
this).attr(
"data-type")).val($(
this).attr(
"data-field"));
13676 $(
".fieldcombo-panel").hide();
13677 $(
this).closest(
".fieldcombo").find(
".fieldcombo-toggle").trigger(
"focus");
13678 $(
"#search_filter_field").trigger(
"change");
13682 $(
".fieldcombo-search").on(
"keyup change",
function() {
13683 const term = $(
this).val().toLowerCase();
13687 $(
".fieldcombo-element").removeClass(
"open").show();
13688 $(
".fieldcombo-fields, .fieldcombo-children").hide();
13689 $(
".fieldcombo-field").show();
13690 $(
".fieldcombo-list > .fieldcombo-element").addClass(
"open").children(
".fieldcombo-fields, .fieldcombo-children").show();
13695 $(
".fieldcombo-element").each(
function() {
13696 const elementmatch = $(
this).children(
".fieldcombo-elementheader").find(
".fieldcombo-elementlabel").text().toLowerCase().indexOf(term) > -1;
13697 let hasfieldmatch =
false;
13698 $(
this).children(
".fieldcombo-fields").children(
".fieldcombo-field").each(
function() {
13699 const fieldmatch = elementmatch || $(
this).text().toLowerCase().indexOf(term) > -1;
13700 $(
this).toggle(fieldmatch);
13702 hasfieldmatch =
true;
13705 $(
this).toggleClass(
"open", elementmatch || hasfieldmatch);
13706 $(
this).children(
".fieldcombo-fields").toggle(elementmatch || hasfieldmatch);
13708 $(
".fieldcombo-element").each(
function() {
13709 if ($(
this).hasClass(
"open")) {
13712 $(
this).parents(
".fieldcombo-element").addClass(
"open").show().children(
".fieldcombo-children").show();
13720 $(document).on(
"keydown",
function(e) {
13721 if (e.which === 27) {
13722 if ($(
".fieldcombo-panel").is(
":visible") && $(e.target).closest(
".fieldcombo").length) {
13723 $(e.target).closest(
".fieldcombo").find(
".fieldcombo-toggle").trigger(
"focus");
13725 $(
".fieldcombo-panel").hide();
13728 $(
".fieldcombo-elementheader, .fieldcombo-field").on(
"keydown",
function(e) {
13729 if (e.which === 13) {
13730 e.preventDefault();
13731 $(this).trigger(
"click");
13736 $(document).on(
"click",
function(e) {
13737 if (!$(e.target).closest(
".fieldcombo").length) {
13738 $(
".fieldcombo-panel").hide();
13742 $(
".fieldcombo").on(
"focusout",
function(e) {
13743 if (e.relatedTarget && !$.contains(
this, e.relatedTarget)) {
13744 $(this).find(
".fieldcombo-panel").hide();
13748 $(
"#search_filter_field").on(
"change",
function() {
13749 console.log(
"We change search_filter_field");
13752 let fieldType = $(
this).attr(
"data-type");
13753 const selectedFieldValue = $(
this).val();
13756 if (arrayoffiltercriterias[selectedFieldValue] === undefined) {
13757 resetOperatorAndValueInputs();
13762 if (arrayoffiltercriterias[selectedFieldValue][
"arrayofkeyval"] !== undefined) {
13763 fieldType =
"select";
13767 if (arrayoffiltercriterias[selectedFieldValue][
"maybenull"] !== undefined) {
13770 const operators = getOperatorsForFieldType(fieldType, maybenull);
13771 const operatorSelector = $(
".operator-selector");
13774 operatorSelector.empty();
13777 Object.entries(operators).forEach(
function([
operator, label]) {
13778 if (
operator.indexOf(
"separator") === 0) {
13780 operatorSelector.append(
"<option value=\'" +
operator +
"\' disabled>" + label +
"</option>");
13782 operatorSelector.append(
"<option value=\'" +
operator +
"\'>" + label +
"</option>");
13786 operatorSelector.trigger(
"change.select2");
13789 resetValueInputs();
13791 if (fieldType ===
"date" || fieldType ===
"datetime" || fieldType ===
"timestamp") {
13792 $(
".date-one").show();
13793 }
else if (arrayoffiltercriterias[selectedFieldValue][
"arrayofkeyval"] !== undefined) {
13794 var arrayofkeyval = arrayoffiltercriterias[selectedFieldValue][
"arrayofkeyval"];
13795 var valueSelector = $(
"#value-selector");
13796 valueSelector.empty();
13797 Object.entries(arrayofkeyval).forEach(
function([key, val]) {
13798 valueSelector.append(
"<option value=\'" + key +
"\'>" + val +
"</option>");
13800 valueSelector.trigger(
"change.select2");
13802 $(
"#value-selector").show();
13803 $(
"#value-selector").next(
".select2-container").show();
13805 $(
".value-input").show();
13809 $(
"#operator-selector").on(
"change",
function() {
13810 console.log(
"We change operator-selector");
13812 const selectedOperator = $(
this).find(
":selected").val();
13813 if (selectedOperator ===
"IsDefined" || selectedOperator ===
"IsNotDefined") {
13815 $(
".value-input, .dateone, .datemonth, .dateyear").val(
"").prop(
"disabled",
true);
13816 $(
"#datemonth, #dateyear").val(
null).trigger(
"change.select2");
13817 $(
"#dateone").datepicker(
"setDate",
null).datepicker(
"option",
"disabled",
true);
13818 $(
".date-one, .date-month, .date-year").prop(
"disabled",
true);
13819 $(
"#value-selector").val(
"").prop(
"disabled",
true);
13820 $(
"#value-selector").val(
null).trigger(
"change.select2");
13823 $(
".value-input, .dateone, .datemonth, .dateyear").prop(
"disabled",
false);
13824 $(
".date-one, .date-month, .date-year").prop(
"disabled",
false);
13825 $(
"#dateone").datepicker(
"option",
"disabled",
false);
13826 $(
"#value-selector").prop(
"disabled",
false);
13831 const selectedFieldForOperator = $(
"#search_filter_field").val();
13832 if (arrayoffiltercriterias[selectedFieldForOperator] !== undefined && arrayoffiltercriterias[selectedFieldForOperator][
"arrayofkeyval"] !== undefined) {
13833 if (selectedOperator ===
"IsInList" || selectedOperator ===
"IsNotInList") {
13834 $(
"#value-selector").hide();
13835 $(
"#value-selector").next(
".select2-container").hide();
13836 $(
".value-input").val(
"").show();
13838 $(
".value-input").val(
"").hide();
13839 $(
"#value-selector").show();
13840 $(
"#value-selector").next(
".select2-container").show();
13845 $(
".add-filter-btn").on(
"click",
function(event) {
13846 console.log(
"We click on add-filter-btn");
13848 event.preventDefault();
13850 const field = $(
"#search_filter_field").val();
13851 const operator = $(
".operator-selector").val();
13852 let value = $(
".value-input").val();
13853 const fieldType = $(
"#search_filter_field").attr(
"data-type");
13855 if ([
"date",
"datetime",
"timestamp"].includes(fieldType)) {
13856 const year = $(
"#dateoneyear").val().toString().padStart(4,
"0");;
13857 const month = $(
"#dateonemonth").val().toString().padStart(2,
"0");
13858 const day = $(
"#dateoneday").val().toString().padStart(2,
"0");
13859 value = `${year}-${month}-${day}`;
13860 console.log(
"value="+value);
13865 if (
operator !==
"IsInList" &&
operator !==
"IsNotInList" && arrayoffiltercriterias[field] !== undefined && arrayoffiltercriterias[field][
"arrayofkeyval"] !== undefined) {
13866 value = $(
"#value-selector").val();
13870 if (
operator ===
"IsDefined" ||
operator ===
"IsNotDefined") {
13874 const filterString = generateFilterString(field,
operator, value, fieldType);
13877 if (filterString !==
"" && field !==
"" && field !==
"-1" && field !==
null &&
operator !==
"" &&
operator !==
null && value !==
"" && value !==
null) {
13879 let ufilter = filterString;
13880 const regufs = filterString.match(/^([a-zA-Z0-9_.]+) (like|notlike|=|!=|<|>|<=|>=) (.*)$/);
13882 ufilter =
"(" + regufs[1] +
":" + regufs[2] +
":" + regufs[3] +
")";
13883 }
else if (!/^\(.*\)$/.test(filterString)) {
13884 ufilter =
"(" + filterString +
")";
13886 console.log(
"Add the criteria "+ufilter+
" to search_component_params_hidden");
13888 const hiddenfield = $(
"#search_component_params_hidden");
13889 hiddenfield.val(hiddenfield.val() !==
"" ? hiddenfield.val() +
" AND " + ufilter : ufilter);
13891 let newufilterid = 1;
13892 $(
"#divsearch_component_params .tagsearch[data-ufilterid]").each(
function() {
13893 newufilterid = Math.max(newufilterid, parseInt($(
this).attr(
"data-ufilterid")) + 1);
13895 const newtag = $(
"<span class=\"marginleftonlyshort valignmiddle tagsearch\"></span>").attr(
"data-ufilterid", newufilterid).attr(
"data-ufilter", ufilter);
13896 newtag.append($(
"<span class=\"tagsearchdelete select2-selection__choice__remove\">x</span>").attr(
"data-ufilterid", newufilterid),
" ", document.createTextNode(ufilter.replace(/^\((.*)\)$/,
"$1").replace(/^([a-zA-Z0-9_.]+):([a-zA-Z!<>=]+):/,
"$1 $2 ")));
13897 const lasttag = $(
"#divsearch_component_params .tagsearch").last();
13898 if (lasttag.length) {
13899 newtag.insertAfter(lasttag);
13901 $(
"#divsearch_component_params").prepend(newtag);
13905 $(
".assistance-errors").hide();
13906 $(
".value-input").val(
"").trigger(
"focus");
13908 $(
".assistance-errors").show();
13913 $(
".search-component-assistance").on(
"keydown",
function(e) {
13914 if (e.which !== 13) {
13917 const target = $(e.target);
13919 if (target.closest(
".fieldcombo-elementheader, .fieldcombo-field, .add-filter-btn").length) {
13922 e.preventDefault();
13924 if (target.hasClass(
"fieldcombo-search")) {
13928 target.filter(
"input").trigger(
"change");
13929 $(
".add-filter-btn").trigger(
"click");
13948 public function selectModelMail($prefix, $modelType = '
', $default = 0, $addjscombo = 0, $selected = 0, $morecss = '')
13950 global $langs, $user;
13954 $TModels = array();
13956 include_once DOL_DOCUMENT_ROOT . '/core/
class/html.formmail.class.php
';
13957 $formmail = new FormMail($this->db);
13958 $result = $formmail->fetchAllEMailTemplate($modelType, $user, $langs);
13961 $TModels[0] = $langs->trans('DefaultMailModel
');
13964 foreach ($formmail->lines_model as $model) {
13965 $TModels[(int) $model->id] = $model->label;
13969 $retstring .= '<select
class=
"flat'.($morecss ? ' '.$morecss : '').'" id=
"select_' . $prefix . 'model_mail" name=
"' . $prefix . 'model_mail">
';
13971 foreach ($TModels as $id_model => $label_model) {
13972 $retstring .= '<option value=
"' . $id_model . '"';
13973 if (!empty($selected) && ((int) $selected) == $id_model) {
13974 $retstring .= "selected";
13976 $retstring .= ">" . $label_model . "</option>";
13979 $retstring .= "</select>";
13982 $retstring .= ajax_combobox('select_
' . $prefix . 'model_mail
');
13999 public function buttonsSaveCancel($save_label = 'Save
', $cancel_label = 'Cancel
', $morebuttons = array(), $withoutdiv = false, $morecss = '', $dol_openinpopup = '')
14003 $buttons = array();
14007 'label_key
' => $save_label,
14010 if ($save_label == 'Create
' || $save_label == 'Add
') {
14011 $save['name'] = 'add
';
14012 } elseif ($save_label == 'Modify
') {
14013 $save['name'] = 'edit
';
14017 'name' => 'cancel
',
14018 'label_key
' => 'Cancel
',
14021 // If MAIN_BUTTON_POSITION_FIRST_OR_LEFT not set, default is to have main action first, then complementary, then cancel at end
14022 if (!getDolGlobalInt('MAIN_BUTTON_POSITION_FIRST_OR_LEFT
')) {
14023 !empty($save_label) ? $buttons[] = $save : '';
14024 if (!empty($morebuttons)) {
14025 $buttons[] = $morebuttons;
14027 !empty($cancel_label) ? $buttons[] = $cancel : '';
14029 if (!empty($morebuttons)) {
14030 $buttons[] = $morebuttons;
14032 !empty($cancel_label) ? $buttons[] = $cancel : '';
14033 !empty($save_label) ? $buttons[] = $save : '';
14036 $retstring = $withoutdiv ? '' : '<div
class=
"center">
';
14038 foreach ($buttons as $button) {
14039 $addclass = empty($button['addclass
']) ? '' : $button['addclass
'];
14040 // Add class to disable submit buttons (except cancel) once form is submitted to prevent duplicate form submissions on slow connections (see lib_foot.js.php)
14041 if ($button['name'] !== 'cancel
') {
14042 $addclass .= ($addclass ? ' ' : '').'disableonsubmit
';
14044 $retstring .= '<input
type=
"submit" class=
"button marginleftonly marginrightonly button-' . $button['name'] . ($morecss ? ' ' . $morecss : '') . ' ' . $addclass . '" name=
"' . $button['name'] . '" value=
"' . dol_escape_htmltag($langs->transnoentities($button['label_key'])) . '">
';
14046 $retstring .= $withoutdiv ? '' : '</div>
';
14048 if ($dol_openinpopup) {
14049 $retstring .= '<!-- buttons are shown into a $dol_openinpopup=
' . dol_escape_htmltag($dol_openinpopup) . ' context, so we enable the close of dialog on cancel -->
' . "\n";
14050 $retstring .= '<script nonce=
"' . getNonce() . '">
';
14051 $retstring .= 'jQuery(
".button-cancel").click(
function(e) {
14052 e.preventDefault(); console.log(\
'We click on cancel in iframe popup ' .
dol_escape_js($dol_openinpopup) .
'\');
14053 window.parent.jQuery(\
'#idfordialog' .
dol_escape_js($dol_openinpopup) .
'\').dialog(\
'close\');
14055 $retstring .=
'</script>';
14074 $num = count($this->cache_invoice_subtype);
14081 $sql =
"SELECT rowid, code, label as label";
14082 $sql .=
" FROM " . MAIN_DB_PREFIX .
'c_invoice_subtype';
14083 $sql .=
" WHERE active = 1";
14085 $resql = $this->db->query($sql);
14087 $num = $this->db->num_rows($resql);
14089 while ($i < $num) {
14090 $obj = $this->db->fetch_object($resql);
14093 $label = ($langs->trans(
"InvoiceSubtype" . $obj->rowid) !=
"InvoiceSubtype" . $obj->rowid) ? $langs->trans(
"InvoiceSubtype" . $obj->rowid) : (($obj->label !=
'-') ? $obj->label :
'');
14094 $this->cache_invoice_subtype[(int) $obj->rowid][
'rowid'] = (
int) $obj->rowid;
14095 $this->cache_invoice_subtype[(int) $obj->rowid][
'code'] = (
string) $obj->code;
14096 $this->cache_invoice_subtype[(int) $obj->rowid][
'label'] = (
string) $label;
14100 $this->cache_invoice_subtype =
dol_sort_array($this->cache_invoice_subtype,
'code',
'asc', 0, 0, 1);
14104 dol_print_error($this->db);
14122 global $langs, $user;
14125 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
14127 $this->load_cache_invoice_subtype();
14129 $out .=
'<select id="' . $htmlname .
'" class="flat selectsubtype' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
14131 $out .=
'<option value="0"> </option>';
14134 foreach ($this->cache_invoice_subtype as $rowid => $subtype) {
14135 $label = $subtype[
'label'];
14136 $out .=
'<option value="' . $subtype[
'rowid'] .
'"';
14137 if ($selected == $subtype[
'rowid']) {
14138 $out .=
' selected="selected"';
14142 $out .=
'</option>';
14145 $out .=
'</select>';
14146 if ($user->admin && empty($noinfoadmin)) {
14147 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
14168 'type' =>
'search',
14169 'name' => $htmlName,
14171 'class' =>
"search-tool-input",
14172 'placeholder' => $langs->trans(
'Search'),
14173 'autocomplete' =>
'off'
14181 if ($dataTarget !==
false) {
14182 $attr[
'data-search-tool-target'] = $dataTarget;
14186 if (!empty($params[
'attr']) && is_array($params[
'attr'])) {
14187 foreach ($params[
'attr'] as $key => $value) {
14188 if ($key ==
'class') {
14189 $attr[
'class'] .=
' '.$value;
14190 } elseif ($key ==
'classOverride') {
14191 $attr[
'class'] = $value;
14193 $attr[$key] = $value;
14199 if (!empty($attr[
'title']) && !empty($attr[
'class']) && strpos($attr[
'class'],
'classfortooltip') ===
false) {
14200 $attr[
'class'] .=
' classfortooltip';
14203 $TCompiledAttr = [];
14204 foreach ($attr as $key => $value) {
14205 if (in_array($key, [
'data-target'])
14206 || (!empty($params[
'use_unsecured_unescapedattr']) && is_array($params[
'use_unsecured_unescapedattr']) && in_array($key, $params[
'use_unsecured_unescapedattr']))) {
14209 $value = dolPrintHTMLForAttribute($value);
14212 $TCompiledAttr[] = $key .
'="' . $value .
'"';
14215 $compiledAttributes = implode(
' ', $TCompiledAttr);
14218 return '<div class="search-tool-container"><input '.$compiledAttributes.
'></div>';
14234 public function inputType($type, $name, $value =
'',
$id =
'', $morecss =
'', $moreparam =
'', $label =
'', $addInputLabel =
'')
14237 if ($label !=
'') {
14238 $out .=
'<label for="' . dolPrintHTMLForAttribute(
$id) .
'">';
14240 $out .=
'<input type="' . dolPrintHTMLForAttribute($type) .
'"';
14241 $out .=
' class="flat valignmiddle maxwidthonsmartphone ' . dolPrintHTMLForAttribute($morecss) .
'"';
14243 $out .=
' id="' . dolPrintHTMLForAttribute(
$id) .
'"';
14245 $out .=
' name="' . dolPrintHTMLForAttribute($name) .
'"';
14246 $out .=
' value="' . dolPrintHTMLForAttribute($value) .
'" ';
14247 $out .= ($moreparam ?
' ' . $moreparam :
'');
14248 $out .=
' />' . $addInputLabel;
14249 if ($label !=
'') {
14250 $out .= $label .
'</label>';
14268 public function inputSelectAjax($htmlName, $array,
$id, $ajaxUrl, $ajaxData = [], $morecss =
'minwidth75', $moreparam =
'')
14272 $(document).ready(function () {
14273 $('#" . $htmlName .
"').select2({
14275 url: '" . $ajaxUrl .
"',
14277 delay: 250, // wait 250 milliseconds before triggering the request
14278 data: function (params) {
14280 search: params.term,
14281 page: params.page || 1";
14282 if (!empty($ajaxData) && is_array($ajaxData)) {
14283 foreach ($ajaxData as $key => $value) {
14284 $out .=
", " . $key .
": '" . $value .
"'";
14296 $out .= $this->selectarray($htmlName, $array,
$id, 0, 0, 0, $moreparam, 0, 0, 0,
'', $morecss);
14310 public function inputHtml($htmlName, $value, $morecss =
'', $moreparam =
'')
14312 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
14313 $doleditor =
new DolEditor($htmlName, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
isModEnabled(
'fckeditor') &&
getDolGlobalInt(
'FCKEDITOR_ENABLE_SOCIETE'), ROWS_5,
'90%');
14315 return (
string) $doleditor->Create(1,
'',
true,
'',
'', $moreparam, $morecss);
14328 public function inputText($htmlName, $value, $morecss =
'', $moreparam =
'', $options = array())
14333 if (!empty($options)) {
14335 $out .= $this->selectarray($htmlName .
"_multiinput", $options,
'', 1, 0, 0, $moreparam, 0, 0, 0,
'',
"flat maxwidthonphone" . $morecss);
14336 $out .=
'<input id="' . $htmlName .
'_multiinputadd" type="button" class="button" value="' . $langs->trans(
"Add") .
'">';
14337 $out .=
"<script>";
14339 function handlemultiinputdisabling(htmlname){
14340 console.log("We handle the disabling of used options for "+htmlname+"_multiinput");
14341 multiinput = $("#"+htmlname+"_multiinput");
14342 multiinput.find("option").each(function(){
14343 tmpval = $("#"+htmlname).val();
14344 tmpvalarray = tmpval.split("\n");
14345 valtotest = $(this).val();
14346 if(tmpvalarray.includes(valtotest)){
14347 $(this).prop("disabled",true);
14349 if($(this).prop("disabled") == true){
14350 console.log(valtotest)
14351 $(this).prop("disabled", false);
14357 $(document).ready(function () {
14358 $("#' . $htmlName .
'_multiinputadd").on("click",function() {
14359 tmpval = $("#' . $htmlName .
'").val();
14360 tmpvalarray = tmpval.split(",");
14361 valtotest = $("#' . $htmlName .
'_multiinput").val();
14362 if(valtotest != -1 && !tmpvalarray.includes(valtotest)){
14363 console.log("We add the selected value to the text area ' . $htmlName .
'");
14365 tmpval = valtotest;
14367 tmpval = tmpval + "\n" + valtotest;
14369 $("#' . $htmlName .
'").val(tmpval);
14370 handlemultiinputdisabling("' . $htmlName .
'");
14371 $("#' . $htmlName .
'_multiinput").val(-1);
14373 console.log("We add nothing the text area ' . $htmlName .
'");
14376 $("#' . $htmlName .
'").on("change",function(){
14377 handlemultiinputdisabling("' . $htmlName .
'");
14379 handlemultiinputdisabling("' . $htmlName .
'");
14381 $out .=
"</script>";
14382 $value = str_replace(
',',
"\n", $value);
14385 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
14386 $doleditor =
new DolEditor($htmlName, (
string) $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
14387 $out .= (string) $doleditor->Create(1,
'',
true,
'',
'', $moreparam, $morecss);
14402 public function inputRadio($htmlName, $options, $selectedValue, $morecss =
'', $moreparam =
'')
14405 foreach ($options as $optionKey => $optionLabel) {
14406 $selected = ((string) $selectedValue) === ((string) $optionKey) ?
' checked="checked"' :
'';
14407 $optionId = $htmlName .
'_' . $optionKey;
14408 $out .=
'<input class="flat' . $morecss .
'" type="radio" name="' . $htmlName .
'" id="' . $optionId .
'" value="' . dolPrintHTMLForAttribute((
string) $optionKey) .
'"' . $selected . $moreparam .
'/><label for="' . $optionId .
'">' . $optionLabel .
'</label><br>';
14424 public function inputStars($htmlName, $size, $value, $morecss =
'', $moreparam =
'')
14426 $out =
'<input type="hidden" class="flat ' . $morecss .
'" name="' . $htmlName .
'" id="' . $htmlName .
'" value="' . dolPrintHTMLForAttribute((
string) $value) .
'"' . $moreparam .
'>';
14427 $out .=
'<div class="star-selection" id="' . $htmlName .
'_selection">';
14428 for ($i = 1; $i <= $size; $i++) {
14429 $out .=
'<span class="star" data-value="' . $i .
'">' . img_picto(
'',
'fontawesome_star_fas') .
'</span>';
14433 jQuery(function($) { /* commonobject.class.php 1 */
14434 let container = $("#' . $htmlName .
'_selection");
14435 let selectedStars = parseInt($("#' . $htmlName .
'").val()) || 0;
14436 container.find(".star").each(function() {
14437 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
14439 container.find(".star").on("mouseover", function() {
14440 let selectedStar = $(this).data("value");
14441 container.find(".star").each(function() {
14442 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
14445 container.on("mouseout", function() {
14446 container.find(".star").each(function() {
14447 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
14450 container.find(".star").off("click").on("click", function() {
14451 selectedStars = $(this).data("value");
14452 if (selectedStars === 1 && $("#' . $htmlName .
'").val() == 1) {
14455 $("#' . $htmlName .
'").val(selectedStars);
14456 container.find(".star").each(function() {
14457 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
14475 public function inputIcon($htmlName, $value, $morecss =
'', $moreparam =
'')
14484 $out =
'<input type="text" class="form-control icp icp-auto iconpicker-element iconpicker-input flat ' . $morecss .
' maxwidthonsmartphone"';
14485 $out .=
' name="' . $htmlName .
'" id="' . $htmlName .
'" value="' . dolPrintHTMLForAttribute((
string) $value) .
'" ' . ((string) $moreparam) .
'>';
14487 $out .=
'<script>';
14488 $options =
"{ title: '<b>" . $langs->trans(
"IconFieldSelector") .
"</b>', placement: 'right', showFooter: false, templates: {";
14489 $options .=
"iconpicker: '<div class=\"iconpicker\"><div style=\"background-color:#EFEFEF;\" class=\"iconpicker-items\"></div></div>',";
14490 $options .=
"iconpickerItem: '<a role=\"button\" href=\"#\" class=\"iconpicker-item\" style=\"background-color:#DDDDDD;\"><i></i></a>',";
14493 $options .=
"footer: '<div class=\"popover-footer\" style=\"background-color:#EFEFEF;\"></div>',";
14494 $options .=
"search: '<input type=\"search\" class\"form-control iconpicker-search\" placeholder=\"" . $langs->trans(
"TypeToFilter") .
"\" />',";
14495 $options .=
"popover: '<div class=\"iconpicker-popover popover\">";
14496 $options .=
" <div class=\"arrow\" ></div>";
14497 $options .=
" <div class=\"popover-title\" style=\"text-align:center;background-color:#EFEFEF;\"></div>";
14498 $options .=
" <div class=\"popover-content \" ></div>";
14499 $options .=
"</div>'}}";
14500 $out .=
"$('#" . $htmlName .
"').iconpicker(" . $options .
");";
14501 $out .=
'</script>';
14517 require_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeophp.class.php';
14518 require_once DOL_DOCUMENT_ROOT .
'/core/class/geomapeditor.class.php';
14524 if (!empty($value)) {
14525 $tmparray = $dolgeophp->parseGeoString($value);
14526 $geojson = $tmparray[
'geojson'];
14527 $centroidjson = $tmparray[
'centroidjson'];
14530 return $geomapeditor->getHtml($htmlName, $geojson, $centroidjson, $type);
14542 $toPrint = array();
14543 $values = is_array($values) ? $values : array();
14545 foreach ($values as $value) {
14546 $toPrint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $value .
'</li>';
14548 if (!empty($toPrint)) {
14549 $out =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(
' ', $toPrint) .
'</ul></div>';
14564 $out =
'<div class="star-selection" data-value="' . dolPrintHTMLForAttribute((
string) $value) .
'">';
14565 for ($i = 1; $i <= $size; $i++) {
14566 $out .=
'<span class="star' . ($i <= $value ?
' active' :
'') .
'" data-value="' . $i .
'">' . img_picto(
'',
'fontawesome_star_fas') .
'</span>';
14581 $out =
'<span class="' . dolPrintHTMLForAttribute((
string) $value) .
'"></span>';
14597 if (!empty($value)) {
14598 require_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeophp.class.php';
14600 if ($type ==
'point') {
14601 $out = $dolgeophp->getXYString($value);
14603 $out = $dolgeophp->getPointString($value);
14624 public function getNomUrl(&
$object, $withpicto = 0, $option =
'', $maxlength = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'', $add_label = 0, $sep =
' - ')
14626 if (is_object(
$object) && method_exists(
$object,
'getNomUrl')) {
14627 $out =
$object->getNomUrl($withpicto, $option, $maxlength, $save_lastsearch_value, $notooltip, $morecss, $add_label, $sep);
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLength=2, $autoselect=0, $ajaxoptions=array(), $moreparams='')
Generic function that return javascript to add to transform a common input text or select field into ...
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='', $placeholder='')
Convert a html select field into an ajax combobox.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage bank accounts.
Class to manage members of a foundation.
Class to manage categories.
Class to manage bank accounts description of third parties.
Class to manage a WYSIWYG editor.
Class to manage Geo processing Usage: $dolgeophp=new DolGeoPHP($db);.
Class to manage ECM files.
const STATUS_OPEN_INTERNAL
Warehouse open and only operations for stock transfers/corrections allowed (not for customer shipping...
const STATUS_OPEN_ALL
Warehouse open and any operations are allowed (customer shipping, supplier dispatch,...
const STATUS_CLOSED
Warehouse closed, inactive.
Class to manage invoice templates.
Class to manage a Leaflet map width geometrics objects.
Class to parse product price expressions.
Class to manage predefined suppliers products.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage subscriptions of foundation members.
Class to manage translations.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
if(! $sortfield) if(! $sortorder) $module
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
currency_name($code_iso, $withcode=0, $outputlangs=null)
Return label of currency or code+label.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
getServerTimeZoneInt($refgmtdate='now')
Return server timezone int.
removeGlobalParenthesis($string)
Remove first and last parenthesis but only if first is the opening and last the closing of the same g...
dol_now($mode='gmt')
Return date for now.
dol_print_email($email, $contactid=0, $socid=0, $addlink=0, $max=0, $showinvalid=2, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
dolForgeExplodeAnd($sqlfilters)
Explode an universal search string with AND parts.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
currentToken()
Return the value of token currently saved into session with name 'token'.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_print_url($url, $target='_blank', $max=32, $withpicto=0, $morecss='')
Show Url link.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolUserString($key, $default='', $tmpuser=null)
Return Dolibarr user constant string value.
GETPOSTISARRAY($paramname, $method=0)
Return true if the parameter $paramname is submit from a POST OR GET as an array.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getElementProperties($elementType)
Get an array with properties of an element.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_string_neverthesehtmltags($stringtoclean, $disallowed_tags=array('textarea'), $cleanalsosomestyles=0)
Clean a string from some undesirable HTML tags.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
colorIsLight($stringcolor)
Return true if the color is light.
dolIsAllowedForPreview($file)
Return if a file is qualified for preview.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
getNonce()
Return a random string to be used as a nonce value for js.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox=0, $check='restricthtml')
Sanitize a HTML to remove js, dangerous content and external links.
dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array(), $allowlink=0, $allowscript=0, $allowstyle=0, $allowphp=0)
Clean a string to keep only desirable HTML tags.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_sanitizeKeyCode($str)
Clean a string to use it as a key or code.
isModEnabled($module)
Is Dolibarr module enabled.
array_merge_recursive_distinct(array $array1, array $array2)
Recursively merges two arrays while preserving keys and replacing existing values.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_nboflines_bis($text, $maxlinesize=0, $charset='UTF-8')
Return nb of lines of a formatted text with and (WARNING: string must not have mixed and br sep...
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
commonHtmlAttributeBuilder($attr, array $unescapedAttr=[])
Builds an array of safe and properly escaped HTML attributes from a key-value pair list.
dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled='', $morecss='classlink button bordertransp', $jsonopen='', $jsonclose='', $accesskey='')
Return HTML code to output a button to open a dialog popup box.
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
getAdvancedPreviewUrl($modulepart, $relativepath, $alldata=0, $param='')
Return URL we can use for advanced preview links.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
Build the customer statement lines (invoices and payments) with running balance.
Class to generate the form for creating a new ticket.
dol_get_trunk_prefix($db, $phone_code)
Get the national trunk prefix for a phone code.
dol_parse_phone($phone)
Parse a stored phone number into country code and number parts.
dol_get_phone_code_from_country($db, $country_id)
Get the phone calling code for a country.
measuringUnitString($unitid, $measuring_style='', $unitscale=null, $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
$conf db user
Active Directory does not allow anonymous connections.
$conf db name
Only used if Module[ID]Name translation string is not found.
getMaxFileSizeArray()
Return the max allowed for file upload.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.
dolDecrypt($chain, $key='', $patterntotest='')
Decode a string with a symmetric encryption.
multi select button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
treeview li table
No Email.
testSqlAndScriptInject($val, $type)
Security: WAF layer for SQL Injection and XSS Injection (scripts) protection (Filters on GET,...