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') {
873 } elseif ($type !=
'none') {
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>';
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>';
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;
1286 $fullPhone = (
string) $phoneValue;
1295 $selectedCode = $phonecode;
1296 $numberValue = $parsed[
'number'];
1299 if ($numberValue !==
'' && $selectedCode !==
'') {
1301 if ($trunkPrefix !==
'' && strpos($numberValue, $trunkPrefix) !== 0) {
1302 $numberValue = $trunkPrefix.$numberValue;
1310 $out .=
img_picto(
'', $picto,
'class="pictofixedwidth"');
1313 $out .= $this->
selectPhoneCode($selectedCode, $codename,
'maxwidth75 phone_code_select', 0, $country_id_hint);
1316 $out .=
'<input type="tel" inputmode="numeric" pattern="[0-9]*" id="'.dol_escape_htmltag($htmlname).
'_input" class="'.
dol_escape_htmltag($morecss).
'"';
1317 if ($maxlength > 0) {
1318 $out .=
' maxlength="'.$maxlength.
'"';
1320 $out .=
' value="'.dol_escape_htmltag($numberValue).
'">';
1345 $selectId =
'select'.dol_escape_js($codename);
1347 $out =
"\n".
'<script type="text/javascript">'.
"\n";
1348 $out .=
'jQuery(document).ready(function() {'.
"\n";
1349 $out .=
' function syncPhoneField_'.$hiddenId.
'() {'.
"\n";
1350 $out .=
' var selectEl = jQuery("#'.$selectId.
'");'.
"\n";
1351 $out .=
' var code = selectEl.val() || "";'.
"\n";
1352 $out .=
' var number = (jQuery("#'.$inputId.
'").val() || "").replace(/[^0-9]/g, "");'.
"\n";
1353 $out .=
' if (code && number) {'.
"\n";
1354 $out .=
' var selOpt = selectEl[0] && selectEl[0].selectedOptions && selectEl[0].selectedOptions[0];'.
"\n";
1355 $out .=
' var trunkPrefix = selOpt ? (selOpt.getAttribute("data-trunk-prefix") || "") : "";'.
"\n";
1356 $out .=
' if (trunkPrefix !== "" && number.indexOf(trunkPrefix) === 0) {'.
"\n";
1357 $out .=
' number = number.substring(trunkPrefix.length);'.
"\n";
1359 $out .=
' jQuery("#'.$hiddenId.
'").val(code + " " + number);'.
"\n";
1360 $out .=
' } else if (number) {'.
"\n";
1361 $out .=
' jQuery("#'.$hiddenId.
'").val(number);'.
"\n";
1362 $out .=
' } else {'.
"\n";
1363 $out .=
' jQuery("#'.$hiddenId.
'").val("");'.
"\n";
1366 $out .=
' jQuery("#'.$selectId.
'").on("change", function() { syncPhoneField_'.$hiddenId.
'(); });'.
"\n";
1367 $out .=
' jQuery("#'.$inputId.
'").on("input change", function() { syncPhoneField_'.$hiddenId.
'(); });'.
"\n";
1369 $out .=
'</script>'.
"\n";
1385 if ($this->phoneInputSharedJsLoaded) {
1388 $this->phoneInputSharedJsLoaded =
true;
1390 $out =
"\n".
'<script type="text/javascript">'.
"\n";
1391 $out .=
'jQuery(document).ready(function() {'.
"\n";
1392 $out .=
' jQuery("#'.dol_escape_js($countrySelectorId).
'").on("change", function() {'.
"\n";
1393 $out .=
' var country_id = jQuery(this).val();'.
"\n";
1394 $out .=
' if (country_id) {'.
"\n";
1395 $out .=
' jQuery.getJSON("'.DOL_URL_ROOT.
'/core/ajax/getphonecode.php", {country_id: country_id, token: "'.
currentToken().
'"}, function(data) {'.
"\n";
1396 $out .=
' if (data.phone_code) {'.
"\n";
1397 $out .=
' jQuery(".phone_code_select").each(function() {'.
"\n";
1398 $out .=
' jQuery(this).val(data.phone_code).trigger("change");'.
"\n";
1399 $out .=
' });'.
"\n";
1401 $out .=
' });'.
"\n";
1403 $out .=
' });'.
"\n";
1405 $out .=
'</script>'.
"\n";
1426 global $langs, $form;
1428 $form =
new Form($this->db);
1430 $htmltoenteralink =
'';
1434 $htmltoenteralink .=
'<tr class="liste_titre">';
1435 $htmltoenteralink .=
'<td class="nowrap"></td>';
1436 $htmltoenteralink .=
'<td>' . $langs->trans(
"Ref") .
'</td>';
1437 $htmltoenteralink .=
'<td>' . $langs->trans(
"RefCustomer") .
'</td>';
1438 $htmltoenteralink .=
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
1439 $htmltoenteralink .=
'<td>' . $langs->trans(
"Company") .
'</td>';
1440 $htmltoenteralink .=
'</tr>';
1444 $objp = $this->db->fetch_object($resqllist);
1445 $alreadylinked =
false;
1446 if (!empty(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key])) {
1447 if (in_array($objp->rowid, array_values(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key]))) {
1448 $alreadylinked =
true;
1451 $htmltoenteralink .=
'<tr class="oddeven">';
1452 $htmltoenteralink .=
'<td>';
1453 if ($alreadylinked) {
1454 $htmltoenteralink .=
img_picto(
'',
'link');
1456 $htmltoenteralink .=
'<input type="checkbox" name="idtolinkto[' . $key .
'_' . $objp->rowid .
']" id="' . $key .
'_' . $objp->rowid .
'" value="' . $objp->rowid .
'">';
1458 $htmltoenteralink .=
'</td>';
1459 $htmltoenteralink .=
'<td>';
1460 if (!$alreadylinked) {
1461 $htmltoenteralink .=
'<label for="' . $key .
'_' . $objp->rowid .
'">';
1463 $htmltoenteralink .= $objp->ref;
1464 if (!$alreadylinked) {
1465 $htmltoenteralink .=
'</label>';
1467 $htmltoenteralink .=
'</td>';
1468 $htmltoenteralink .=
'<td>' . (!empty($objp->ref_client) ? $objp->ref_client : (!empty($objp->ref_supplier) ? $objp->ref_supplier :
'')) .
'</td>';
1469 $htmltoenteralink .=
'<td class="right">';
1470 if ($possiblelink[
'label'] ==
'LinkToContract') {
1471 $htmltoenteralink .= $form->textwithpicto(
'', $langs->trans(
"InformationOnLinkToContract")) .
' ';
1473 $htmltoenteralink .=
'<span class="amount">' . (isset($objp->total_ht) ?
price($objp->total_ht) :
'') .
'</span>';
1474 $htmltoenteralink .=
'</td>';
1475 $htmltoenteralink .=
'<td>' . $objp->name .
'</td>';
1476 $htmltoenteralink .=
'</tr>';
1480 return $htmltoenteralink;
1500 global $langs, $form;
1501 require_once DOL_DOCUMENT_ROOT .
'/eventorganization/class/conferenceorboothattendee.class.php';
1502 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
1503 require_once DOL_DOCUMENT_ROOT .
'/projet/class/project.class.php';
1505 $companystatic =
new Societe($this->db);
1506 $projectstatic =
new Project($this->db);
1508 $form =
new Form($this->db);
1510 $htmltoenteralink =
'';
1514 $htmltoenteralink .=
'<tr class="liste_titre">';
1515 $htmltoenteralink .=
'<td class="nowrap"></td>';
1516 $htmltoenteralink .=
'<td>' . $langs->trans(
"Ref") .
'</td>';
1517 $htmltoenteralink .=
'<td>' . $langs->trans(
"Name") .
'</td>';
1518 $htmltoenteralink .=
'<td>' . $langs->trans(
"Email") .
'</td>';
1519 $htmltoenteralink .=
'<td>' . $langs->trans(
"Company") .
'</td>';
1520 $htmltoenteralink .=
'<td>' . $langs->trans(
"Project") .
'</td>';
1521 $htmltoenteralink .=
'<td>' . $langs->trans(
"DateOfRegistration") .
'</td>';
1522 $htmltoenteralink .=
'</tr>';
1526 $objp = $this->db->fetch_object($resqllist);
1527 $alreadylinked =
false;
1528 if (!empty(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key])) {
1529 if (in_array($objp->rowid, array_values(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key]))) {
1530 $alreadylinked =
true;
1533 $htmltoenteralink .=
'<tr class="oddeven">';
1534 $htmltoenteralink .=
'<td>';
1535 if ($alreadylinked) {
1536 $htmltoenteralink .=
img_picto(
'',
'link');
1538 $htmltoenteralink .=
'<input type="checkbox" name="idtolinkto[' . $key .
'_' . $objp->rowid .
']" id="' . $key .
'_' . $objp->rowid .
'" value="' . $objp->rowid .
'">';
1540 $htmltoenteralink .=
'</td>';
1541 $fetchattendee = $attendeestatic->fetch($objp->rowid);
1542 if ($fetchattendee) {
1543 $htmltoenteralink .=
'<td>' . $attendeestatic->getNomUrl(0).
'</td>';
1545 $htmltoenteralink .=
'<td><label for="' . $key .
'_' . $objp->rowid .
'">' . $objp->ref .
'</label></td>';
1547 $htmltoenteralink .=
'<td>' . $objp->name .
'</td>';
1548 $htmltoenteralink .=
'<td>' . $objp->email .
'</td>';
1549 $fetchcompany = $companystatic->fetch($objp->socid);
1550 if ($fetchcompany) {
1551 $htmltoenteralink .=
'<td>' . $companystatic->getNomUrl(0).
'</td>';
1553 $htmltoenteralink .=
'<td>' . $objp->name .
'</td>';
1555 $fetchcproject = $projectstatic->fetch($objp->fk_project);
1556 if ($fetchcproject) {
1557 $htmltoenteralink .=
'<td>' . $projectstatic->getNomUrl(0).
'</td>';
1559 $htmltoenteralink .=
'<td>' . $objp->fk_project .
'</td>';
1561 $htmltoenteralink .=
'<td>' . $objp->date_subscription .
'</td>';
1562 $htmltoenteralink .=
'</tr>';
1566 return $htmltoenteralink;
1584 public function select_incoterms($selected =
'', $location_incoterms =
'', $page =
'', $htmlname =
'incoterm_id', $htmloption =
'', $forcecombo = 1, $events = array(), $disableautocomplete = 0)
1587 global
$conf, $langs;
1589 $langs->load(
"dict");
1593 $incotermArray = array();
1595 $sql =
"SELECT rowid, code";
1596 $sql .=
" FROM " . $this->db->prefix() .
"c_incoterms";
1597 $sql .=
" WHERE active > 0";
1598 $sql .=
" ORDER BY code ASC";
1600 dol_syslog(get_class($this) .
"::select_incoterm", LOG_DEBUG);
1601 $resql = $this->db->query($sql);
1603 if (
$conf->use_javascript_ajax && !$forcecombo) {
1604 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1608 if (!empty($page)) {
1609 $out .=
'<form method="post" action="' . $page .
'">';
1610 $out .=
'<input type="hidden" name="action" value="set_incoterms">';
1611 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
1614 $out .=
'<select id="' . $htmlname .
'" class="flat selectincoterm width75" name="' . $htmlname .
'" ' . $htmloption .
'>';
1615 $out .=
'<option value="0"> </option>';
1616 $num = $this->db->num_rows($resql);
1620 $obj = $this->db->fetch_object($resql);
1621 $incotermArray[$i][
'rowid'] = $obj->rowid;
1622 $incotermArray[$i][
'code'] = $obj->code;
1626 foreach ($incotermArray as $row) {
1627 if ($selected && ($selected == $row[
'rowid'] || $selected == $row[
'code'])) {
1628 $out .=
'<option value="' . $row[
'rowid'] .
'" selected>';
1630 $out .=
'<option value="' . $row[
'rowid'] .
'">';
1634 $out .= $row[
'code'];
1637 $out .=
'</option>';
1640 $out .=
'</select>';
1643 if (
$conf->use_javascript_ajax && empty($disableautocomplete)) {
1644 $out .=
ajax_multiautocompleter(
'location_incoterms', array(), DOL_URL_ROOT .
'/core/ajax/locationincoterms.php') .
"\n";
1647 $out .=
'<input id="location_incoterms" class="maxwidthonsmartphone heightofcombo" type="text" name="location_incoterms" value="' . $location_incoterms .
'">' .
"\n";
1649 if (!empty($page)) {
1650 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp nomargintop nomarginbottom" value="' . $langs->trans(
"Modify") .
'"></form>';
1674 public function select_type_of_lines($selected =
'', $htmlname =
'type', $showempty = 0, $hidetext = 0, $forceall = 0, $morecss =
"", $useajaxcombo = 1)
1682 if (empty($hidetext)) {
1683 print $langs->trans(
"Type").
'...';
1686 print
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
1688 print
'<option value="-1" class="opacitymedium"'.($useajaxcombo ?
'' :
' disabled="disabled"');
1689 if ($selected == -1) {
1693 if (is_numeric($showempty)) {
1701 print
'<option value="0"';
1702 if (0 == $selected || ($selected == -1 &&
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') ==
'product')) {
1705 print
'>' . $langs->trans(
"Product");
1708 print
'<option value="1"';
1709 if (1 == $selected || ($selected == -1 &&
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') ==
'service')) {
1712 print
'>' . $langs->trans(
"Service");
1717 if ($useajaxcombo) {
1723 print $langs->trans(
"Service");
1724 print
'<input type="hidden" name="' . $htmlname .
'" value="1">';
1727 print $langs->trans(
"Product");
1728 print
'<input type="hidden" name="' . $htmlname .
'" value="0">';
1730 if ($forceall < 0) {
1731 print
'<input type="hidden" name="' . $htmlname .
'" value="1">';
1747 $num = count($this->cache_types_fees);
1754 $langs->load(
"trips");
1756 $sql =
"SELECT c.code, c.label";
1757 $sql .=
" FROM " . $this->db->prefix() .
"c_type_fees as c";
1758 $sql .=
" WHERE active > 0";
1760 $resql = $this->db->query($sql);
1762 $num = $this->db->num_rows($resql);
1766 $obj = $this->db->fetch_object($resql);
1769 $label = ($obj->code != $langs->trans($obj->code) ? $langs->trans($obj->code) : $langs->trans($obj->label));
1770 $this->cache_types_fees[$obj->code] = $label;
1774 asort($this->cache_types_fees);
1796 global $user, $langs;
1798 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
1802 print
'<select id="select_' . $htmlname .
'" class="flat" name="' . $htmlname .
'">';
1804 print
'<option value="-1"';
1805 if ($selected == -1) {
1808 print
'> </option>';
1811 foreach ($this->cache_types_fees as $key => $value) {
1812 print
'<option value="' . $key .
'"';
1813 if ($key == $selected) {
1823 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1852 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)
1855 global
$conf, $langs;
1859 if (!empty(
$conf->use_javascript_ajax) &&
getDolGlobalString(
'COMPANY_USE_SEARCH_TO_SELECT') && !$forcecombo) {
1860 if (is_null($ajaxoptions)) {
1861 $ajaxoptions = array();
1864 require_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1868 if ($selected && empty($selected_input_value)) {
1869 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
1870 $societetmp =
new Societe($this->db);
1871 $societetmp->fetch($selected);
1872 $selected_input_value = $societetmp->name;
1877 $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 :
'');
1879 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
1880 if (empty($hidelabel)) {
1881 $out .= $langs->trans(
"RefOrLabel") .
' : ';
1882 } elseif ($hidelabel == 1 && !is_numeric($showempty)) {
1883 $placeholder = $langs->trans($showempty);
1884 } elseif ($hidelabel > 1) {
1885 $placeholder = $langs->trans(
"RefOrLabel");
1886 if ($hidelabel == 2) {
1887 $out .=
img_picto($langs->trans(
"Search"),
'search');
1890 $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" />';
1891 if ($hidelabel == 3) {
1892 $out .=
img_picto($langs->trans(
"Search"),
'search');
1897 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.
'/societe/ajax/company.php', $urloption,
getDolGlobalInt(
'COMPANY_USE_SEARCH_TO_SELECT'), 0, $ajaxoptions);
1900 $out .= $this->
select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events,
'', 0, $limit, $morecss, $moreparam, $multiple, $excludeids, $showcode);
1934 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 =
'')
1938 global
$conf, $langs;
1943 if ($nokeyifsocid && $socid > 0) {
1944 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = 0;
1947 if (!empty(
$conf->use_javascript_ajax) &&
getDolGlobalString(
'CONTACT_USE_SEARCH_TO_SELECT') && !$forcecombo) {
1948 $ajaxoptions = array();
1950 require_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1954 if ($selected && empty($selected_input_value)) {
1955 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
1956 $contacttmp =
new Contact($this->db);
1957 $contacttmp->fetch($selected);
1958 $selected_input_value = $contacttmp->getFullName($langs);
1961 if (!is_numeric($showempty)) {
1962 $placeholder = $showempty;
1966 $urloption =
'htmlname=' . urlencode((
string) (str_replace(
'.',
'_', $htmlname))) .
'&outjson=1&filter=' . urlencode((
string) ($filter)) . (empty($exclude) ?
'' :
'&exclude=' . urlencode($exclude)) . ($showsoc ?
'&showsoc=' . urlencode((
string) ($showsoc)) :
'');
1968 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
1970 $out .=
'<input type="text" class="' . $morecss .
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . ($placeholder ?
' placeholder="' .
dol_escape_htmltag($placeholder) .
'"' :
'') .
' ' . (
getDolGlobalString(
'CONTACT_SEARCH_AUTOFOCUS') ?
'autofocus' :
'') .
' spellcheck="false" />';
1974 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.
'/contact/ajax/contact.php', $urloption,
getDolGlobalInt(
'CONTACT_USE_SEARCH_TO_SELECT'), 0, $ajaxoptions);
1978 $disableifempty = 0;
1982 $out .= $this->
selectcontacts($socid, $selected, $htmlname, $showempty, $exclude, $limitto, $showfunction, $morecss, $options_only, $showsoc, $forcecombo, $events, $moreparam, $htmlid, $multiple, $disableifempty);
1985 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = $sav;
2016 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)
2019 global $user, $langs;
2020 global $hookmanager;
2022 $langs->loadLangs(array(
"companies",
"suppliers"));
2026 $outarray = array();
2028 if ($selected ===
'') {
2029 $selected = array();
2030 } elseif (!is_array($selected)) {
2031 $selected = array($selected);
2035 if (function_exists(
'testSqlAndScriptInject')) {
2038 return 'SQLInjectionTryDetected';
2042 if ($filter !=
'') {
2047 if (function_exists(
'testSqlAndScriptInject')) {
2050 return 'SQLInjectionTryDetected';
2056 $sql =
"SELECT s.rowid, s.nom as name, s.name_alias, s.tva_intra, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
2058 $sql .=
", s.address, s.zip, s.town";
2059 $sql .=
", dictp.code as country_code";
2061 $sql .=
" FROM " . $this->db->prefix() .
"societe as s";
2063 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_country as dictp ON dictp.rowid = s.fk_pays";
2065 if (!$user->hasRight(
'societe',
'client',
'voir')) {
2066 $sql .=
", " . $this->db->prefix() .
"societe_commerciaux as sc";
2068 $sql .=
" WHERE s.entity IN (" .
getEntity(
'societe') .
")";
2069 if (!empty($user->socid)) {
2070 $sql .=
" AND s.rowid = " . ((int) $user->socid);
2074 $sqlwhere = $filter;
2075 $sql .=
" AND (" . $sqlwhere .
")";
2077 if (!$user->hasRight(
'societe',
'client',
'voir')) {
2078 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = " . ((int) $user->id);
2081 $sql .=
" AND s.status <> 0";
2083 if (!empty($excludeids)) {
2084 $sql .=
" AND s.rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeids)) .
")";
2087 $parameters = array();
2088 $reshook = $hookmanager->executeHooks(
'selectThirdpartyListWhere', $parameters);
2089 $sql .= $hookmanager->resPrint;
2091 if ($filterkey && $filterkey !=
'') {
2095 $search_crit = explode(
' ', $filterkey);
2097 if (count($search_crit) > 1) {
2100 foreach ($search_crit as $crit) {
2104 $sql .=
"(s.nom LIKE '" . $this->db->escape($prefix . $crit) .
"%')";
2107 if (count($search_crit) > 1) {
2111 $sql .=
" OR s.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
2113 $sql .=
" OR s.code_client LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.code_fournisseur LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
2114 $sql .=
" OR s.name_alias LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.tva_intra LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
2117 $sql .= $this->db->order(
"nom",
"ASC");
2118 $sql .= $this->db->plimit($limit, 0);
2121 dol_syslog(get_class($this).
"::select_thirdparty_list", LOG_DEBUG);
2122 $resql = $this->db->query($sql);
2125 $out .=
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
' name="' . $htmlname . ($multiple ?
'[]' :
'') .
'"' . ($multiple ?
' multiple' :
'') .
'>' .
"\n";
2127 $textifempty = (($showempty && !is_numeric($showempty)) ? $langs->trans($showempty) :
'');
2131 if ($showempty && !is_numeric($showempty)) {
2132 $textifempty = $langs->trans($showempty);
2134 $textifempty .= $langs->trans(
"All");
2138 $out .=
'<option value="-1" data-html="' .
dol_escape_htmltag(
'<span class="opacitymedium">' . ($textifempty ? $textifempty :
' ') .
'</span>') .
'">' . $textifempty .
'</option>' .
"\n";
2141 $companytemp =
new Societe($this->db);
2143 $num = $this->db->num_rows($resql);
2147 $obj = $this->db->fetch_object($resql);
2150 if (($obj->client) && (!empty($obj->code_client))) {
2151 $label = $obj->code_client .
' - ';
2153 if (($obj->fournisseur) && (!empty($obj->code_fournisseur))) {
2154 $label .= $obj->code_fournisseur .
' - ';
2156 $label .=
' ' . $obj->name;
2158 $label = $obj->name;
2161 if (!empty($obj->name_alias)) {
2162 $label .=
' (' . $obj->name_alias .
')';
2166 $label .=
' - '.$obj->tva_intra;
2169 $labelhtml = $label;
2172 $companytemp->id = $obj->rowid;
2173 $companytemp->client = $obj->client;
2174 $companytemp->fournisseur = $obj->fournisseur;
2175 $tmptype = $companytemp->getTypeUrl(1,
'', 0,
'span');
2177 $labelhtml .=
' ' . $tmptype;
2180 if ($obj->client || $obj->fournisseur) {
2183 if ($obj->client == 1 || $obj->client == 3) {
2184 $label .= $langs->trans(
"Customer");
2186 if ($obj->client == 2 || $obj->client == 3) {
2187 $label .= ($obj->client == 3 ?
', ' :
'') . $langs->trans(
"Prospect");
2189 if ($obj->fournisseur) {
2190 $label .= ($obj->client ?
', ' :
'') . $langs->trans(
"Supplier");
2192 if ($obj->client || $obj->fournisseur) {
2198 $s = ($obj->address ?
' - ' . $obj->address :
'') . ($obj->zip ?
' - ' . $obj->zip :
'') . ($obj->town ?
' ' . $obj->town :
'');
2199 if (!empty($obj->country_code)) {
2200 $s .=
', ' . $langs->trans(
'Country' . $obj->country_code);
2206 if (empty($outputmode)) {
2207 if (in_array($obj->rowid, $selected)) {
2208 $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>';
2210 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
2213 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label,
'labelhtml' => $labelhtml));
2217 if (($i % 10) == 0) {
2222 $out .=
'</select>' .
"\n";
2224 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2231 $this->result = array(
'nbofthirdparties' => $num);
2265 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 =
'')
2267 global
$conf, $user, $langs, $hookmanager, $action;
2269 $langs->load(
'companies');
2271 if (empty($htmlid)) {
2272 $htmlid = $htmlname;
2276 $outarray = array();
2278 if ($selected ===
'') {
2279 $selected = array();
2280 } elseif (!is_array($selected)) {
2281 $selected = array((
int) $selected);
2285 if (function_exists(
'testSqlAndScriptInject')) {
2288 return 'SQLInjectionTryDetected';
2292 if ($filter !=
'') {
2293 if (preg_match(
'/[\(\)]/', $filter)) {
2299 if (function_exists(
'testSqlAndScriptInject')) {
2302 return 'SQLInjectionTryDetected';
2308 dol_syslog(
"Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Filter Syntax.", LOG_WARNING);
2312 if (!is_object($hookmanager)) {
2313 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
2318 $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";
2319 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
2320 $sql .=
", s.nom as company, s.town AS company_town";
2322 $sql .=
" FROM " . $this->db->prefix() .
"socpeople as sp";
2323 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
2324 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON s.rowid = sp.fk_soc";
2326 $sql .=
" WHERE sp.entity IN (" .
getEntity(
'contact') .
")";
2327 $sql .=
" AND ((sp.fk_user_creat = ".((int) $user->id).
" AND sp.priv = 1) OR sp.priv = 0)";
2328 if ($socid > 0 || $socid == -1) {
2329 $sql .=
" AND sp.fk_soc = " . ((int) $socid);
2332 $sql .=
" AND sp.statut <> 0";
2335 if (!$user->hasRight(
'societe',
'client',
'voir') && !$user->socid) {
2336 $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 .
")";
2338 if ($user->socid > 0) {
2339 $sql .=
" AND sp.fk_soc = ".((int) $user->socid);
2344 $sanitizedfilter = $filter;
2345 $sql .=
" AND (" . $sanitizedfilter .
")";
2348 $parameters = array();
2349 $reshook = $hookmanager->executeHooks(
'selectContactListWhere', $parameters);
2350 $sql .= $hookmanager->resPrint;
2351 $sql .=
" ORDER BY sp.lastname ASC";
2353 dol_syslog(get_class($this) .
"::selectcontacts", LOG_DEBUG);
2354 $resql = $this->db->query($sql);
2356 $num = $this->db->num_rows($resql);
2358 if ($htmlname !=
'none' && !$options_only) {
2359 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlid .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . (($num || empty($disableifempty)) ?
'' :
' disabled') . ($multiple ?
'multiple' :
'') .
' ' . (!empty($moreparam) ? $moreparam :
'') .
'>';
2362 if ($showempty && !is_numeric($showempty)) {
2363 $textforempty = $showempty;
2364 $out .=
'<option class="optiongrey" value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'>' . $textforempty .
'</option>';
2366 if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) {
2367 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'> </option>';
2369 if ($showempty == 2) {
2370 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Internal") .
' --</option>';
2376 include_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
2377 $contactstatic =
new Contact($this->db);
2380 $obj = $this->db->fetch_object($resql);
2383 $extendedInfos =
'';
2385 $extendedInfos = array();
2386 $email = trim($obj->email);
2387 if (!empty($email)) {
2388 $extendedInfos[] = $email;
2390 $phone = trim($obj->phone);
2391 $phone_perso = trim($obj->phone_perso);
2392 $phone_mobile = trim($obj->phone_mobile);
2393 if (!empty($phone)) {
2394 $extendedInfos[] = $phone;
2396 if (!empty($phone_perso)) {
2397 $extendedInfos[] = $phone_perso;
2399 if (!empty($phone_mobile)) {
2400 $extendedInfos[] = $phone_mobile;
2403 $contact_town = trim($obj->contact_town);
2404 $company_town = trim($obj->company_town);
2405 if (!empty($contact_town)) {
2406 $extendedInfos[] = $contact_town;
2407 } elseif (!empty($company_town)) {
2408 $extendedInfos[] = $company_town;
2410 $extendedInfos = implode(
' - ', $extendedInfos);
2411 if (!empty($extendedInfos)) {
2412 $extendedInfos =
' - ' . $extendedInfos;
2416 $contactstatic->id = $obj->rowid;
2417 $contactstatic->lastname = $obj->lastname;
2418 $contactstatic->firstname = $obj->firstname;
2419 if ($obj->statut == 1) {
2421 if ($htmlname !=
'none') {
2423 if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) {
2426 if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) {
2429 if (!empty($selected) && in_array($obj->rowid, $selected)) {
2430 $out .=
'<option value="' . $obj->rowid .
'"';
2432 $out .=
' disabled';
2434 $out .=
' selected>';
2436 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
2437 if ($showfunction && $obj->poste) {
2438 $tmplabel .=
' (' . $obj->poste .
')';
2440 if (($showsoc > 0) && $obj->company) {
2441 $tmplabel .=
' - (' . $obj->company .
')';
2445 $out .=
'</option>';
2447 $out .=
'<option value="' . $obj->rowid .
'"';
2449 $out .=
' disabled';
2453 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
2454 if ($showfunction && $obj->poste) {
2455 $tmplabel .=
' (' . $obj->poste .
')';
2457 if (($showsoc > 0) && $obj->company) {
2458 $tmplabel .=
' - (' . $obj->company .
')';
2462 $out .=
'</option>';
2465 if (in_array($obj->rowid, $selected)) {
2466 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
2467 if ($showfunction && $obj->poste) {
2468 $tmplabel .=
' (' . $obj->poste .
')';
2470 if (($showsoc > 0) && $obj->company) {
2471 $tmplabel .=
' - (' . $obj->company .
')';
2478 if ($tmplabel !=
'') {
2479 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $tmplabel,
'label' => $tmplabel,
'labelhtml' => $tmplabel));
2485 $labeltoshow = ($socid != -1) ? ($langs->trans($socid ?
"NoContactDefinedForThirdParty" :
"NoContactDefined")) : $langs->trans(
'SelectAThirdPartyFirst');
2486 $out .=
'<option class="disabled" value="-1"' . (($showempty == 2 || $multiple) ?
'' :
' selected') .
' disabled="disabled">';
2487 $out .= $labeltoshow;
2488 $out .=
'</option>';
2491 $parameters = array(
2493 'htmlname' => $htmlname,
2496 'showfunction' => $showfunction,
2497 'showsoc' => $showsoc,
2500 $reshook = $hookmanager->executeHooks(
'afterSelectContactOptions', $parameters, $this, $action);
2502 if ($htmlname !=
'none' && !$options_only) {
2503 $out .=
'</select>';
2506 if (
$conf->use_javascript_ajax && !$forcecombo && !$options_only) {
2507 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2513 if ($options_only === 2) {
2541 global $langs,
$conf;
2544 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
2545 $sql .=
" re.description, re.fk_facture_source";
2546 $sql .=
" FROM " . $this->db->prefix() .
"societe_remise_except as re";
2547 $sql .=
" WHERE re.fk_soc = " . (int) $socid;
2548 $sql .=
" AND re.entity = " . ((int)
$conf->entity);
2550 $sanitizedfilter = $filter;
2551 $sql .=
" AND " . $sanitizedfilter;
2553 $sql .=
" ORDER BY re.description ASC";
2555 dol_syslog(get_class($this) .
"::select_remises", LOG_DEBUG);
2556 $resql = $this->db->query($sql);
2558 print
'<select id="select_' . $htmlname .
'" class="flat maxwidth200onsmartphone" name="' . $htmlname .
'">';
2559 $num = $this->db->num_rows($resql);
2561 $qualifiedlines = $num;
2565 print
'<option value="0"> </option>';
2567 $obj = $this->db->fetch_object($resql);
2568 $desc =
dol_trunc($obj->description, 40);
2569 if (preg_match(
'/\(CREDIT_NOTE\)/', $desc)) {
2570 $desc = preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $desc);
2572 if (preg_match(
'/\(DEPOSIT\)/', $desc)) {
2573 $desc = preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"Deposit"), $desc);
2575 if (preg_match(
'/\(EXCESS RECEIVED\)/', $desc)) {
2576 $desc = preg_replace(
'/\(EXCESS RECEIVED\)/', $langs->trans(
"ExcessReceived"), $desc);
2578 if (preg_match(
'/\(EXCESS PAID\)/', $desc)) {
2579 $desc = preg_replace(
'/\(EXCESS PAID\)/', $langs->trans(
"ExcessPaid"), $desc);
2583 if ($selected > 0 && $selected == $obj->rowid) {
2584 $selectstring =
' selected';
2588 if ($maxvalue > 0 && $obj->amount_ttc > $maxvalue) {
2590 $disabled =
' disabled';
2593 if (
getDolGlobalString(
'MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST') && !empty($obj->fk_facture_source)) {
2594 $tmpfac =
new Facture($this->db);
2595 if ($tmpfac->fetch($obj->fk_facture_source) > 0) {
2596 $desc = $desc .
' - ' . $tmpfac->ref;
2600 print
'<option value="' . $obj->rowid .
'"' . $selectstring . $disabled .
'>' . $desc .
' (' .
price($obj->amount_ht) .
' ' . $langs->trans(
"HT") .
' - ' .
price($obj->amount_ttc) .
' ' . $langs->trans(
"TTC") .
')</option>';
2607 return $qualifiedlines;
2632 public function select_users($selected =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include =
'', $enableonly = array(), $force_entity =
'0')
2635 print $this->
select_dolusers($selected, $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity);
2664 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)
2667 global
$conf, $user, $langs, $hookmanager;
2671 if (is_object($userselected)) {
2672 $selected = (int) $userselected->id;
2673 } elseif (is_numeric($userselected)) {
2674 $selected = (int) $userselected;
2675 } elseif (is_array($userselected)) {
2676 $selected = $userselected;
2682 if ((is_numeric($selected) && ((
int) $selected < -4 || empty($selected))) && !
getDolGlobalString(
'SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE')) {
2683 $selected = $user->id;
2687 if (!is_array($selected)) {
2688 if ($selected === -1 || $selected ===
'') {
2689 $selected = array();
2691 $selected = array($selected);
2696 $excludeUsers =
null;
2697 if (is_array($exclude)) {
2698 $excludeUsers = implode(
",", $exclude);
2702 $includeUsers =
null;
2703 $includeUsersArray = array();
2704 if (is_array($include)) {
2705 $includeUsersArray = $include;
2706 } elseif ($include ==
'hierarchy') {
2708 $includeUsersArray = $user->getAllChildIds(0);
2709 } elseif ($include ==
'hierarchyme') {
2711 $includeUsersArray = $user->getAllChildIds(1);
2726 $includeUsers = implode(
",", $includeUsersArray);
2731 $outarray = array();
2732 $outarray2 = array();
2735 $showlabelofentity =
isModEnabled(
'multicompany') && !
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE') &&
$conf->entity == 1 && !empty($user->admin) && empty($user->entity) && !preg_match(
'/^search_/', $htmlname);
2736 $userissuperadminentityone =
isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && empty($user->entity);
2739 $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";
2740 if ($showlabelofentity) {
2741 $sql .=
", e.label";
2743 $sql .=
" FROM " . $this->db->prefix() .
"user as u";
2744 if ($showlabelofentity) {
2745 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid = u.entity";
2748 if ($userissuperadminentityone && $force_entity !==
'default') {
2749 if (!empty($force_entity)) {
2750 $sql .=
" WHERE u.entity IN (0, " . $this->db->sanitize($force_entity) .
")";
2752 $sql .=
" WHERE u.entity IS NOT NULL";
2756 $sql .=
" WHERE u.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
2758 $sql .=
" WHERE u.entity IN (" .
getEntity(
'user') .
")";
2762 if (!empty($user->socid)) {
2763 $sql .=
" AND u.fk_soc = " . ((int) $user->socid);
2765 if (is_array($exclude) && $excludeUsers) {
2766 $sql .=
" AND u.rowid NOT IN (" . $this->db->sanitize($excludeUsers) .
")";
2768 if ($includeUsers) {
2769 $sql .=
" AND u.rowid IN (" . $this->db->sanitize($includeUsers) .
")";
2772 $sql .=
" AND (u.statut <> 0";
2773 if (!empty($selected)) {
2774 $sql .=
" OR u.rowid IN (".$this->db->sanitize(implode(
',', $selected)).
")";
2779 $sql .=
" AND u.employee <> 0";
2782 $sql .=
" AND u.fk_soc IS NULL";
2784 if (!empty($morefilter)) {
2787 if ($errormessage) {
2788 $this->errors[] = $errormessage;
2789 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2790 if ($outputmode == 0) {
2791 return 'Error bad param $morefilter';
2799 $reshook = $hookmanager->executeHooks(
'addSQLWhereFilterOnSelectUsers', array(), $this, $action);
2800 if (!empty($reshook)) {
2801 $sql .= $hookmanager->resPrint;
2805 $sql .=
" ORDER BY u.statut DESC, u.firstname ASC, u.lastname ASC";
2807 $sql .=
" ORDER BY u.statut DESC, u.lastname ASC, u.firstname ASC";
2810 dol_syslog(get_class($this) .
"::select_dolusers", LOG_DEBUG);
2812 $resql = $this->db->query($sql);
2814 $num = $this->db->num_rows($resql);
2818 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
' minwidth200') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
2819 if ($show_empty && !$multiple) {
2820 $textforempty =
' ';
2821 if (!empty(
$conf->use_javascript_ajax)) {
2822 $textforempty =
' ';
2824 if (!is_numeric($show_empty)) {
2825 $textforempty = $show_empty;
2827 $out .=
'<option class="optiongrey" value="' . ($show_empty < 0 ? $show_empty : -1) .
'"' . ((empty($selected) || in_array(-1, $selected)) ?
' selected' :
'') .
'>' . $textforempty .
'</option>' .
"\n";
2829 $outarray[($show_empty < 0 ? $show_empty : -1)] = $textforempty;
2830 $outarray2[($show_empty < 0 ? $show_empty : -1)] = array(
2831 'id' => ($show_empty < 0 ? $show_empty : -1),
2832 'label' => $textforempty,
2833 'labelhtml' => $textforempty,
2838 if ($showalso == 2 || $showalso == 3) {
2839 $out .=
'<option value="-3"' . ((in_array(-3, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"MyTeam") .
' --</option>' .
"\n";
2841 $hasAtLeastOneSubordinate = (count($user->getAllChildIds(1)) > 1);
2842 if ($hasAtLeastOneSubordinate) {
2844 $outarray[-3] =
'-- ' . $langs->trans(
"MyTeam") .
' --';
2845 $outarray2[-3] = array(
2847 'label' =>
'-- ' . $langs->trans(
"MyTeam") .
' --',
2848 'labelhtml' =>
'-- ' . $langs->trans(
"MyTeam") .
' --',
2854 if ($showalso == 1 || $showalso == 3) {
2855 $out .=
'<option value="-2"' . ((in_array(-2, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Everybody") .
' --</option>' .
"\n";
2857 $outarray[-2] =
'-- ' . $langs->trans(
"Everybody") .
' --';
2858 $outarray2[-2] = array(
2860 'label' =>
'-- ' . $langs->trans(
"Everybody") .
' --',
2861 'labelhtml' =>
'-- ' . $langs->trans(
"Everybody") .
' --',
2866 if ($showalso == 4) {
2867 $out .=
'<option value="-4"' . ((in_array(-4, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"AllProjectContacts") .
' --</option>' .
"\n";
2869 $outarray[-4] =
'-- ' . $langs->trans(
"AllProjectContacts") .
' --';
2870 $outarray2[-4] = array(
2872 'label' =>
'-- ' . $langs->trans(
"AllProjectContacts") .
' --',
2873 'labelhtml' =>
'-- ' . $langs->trans(
"AllProjectContacts") .
' --',
2879 $userstatic =
new User($this->db);
2882 $obj = $this->db->fetch_object($resql);
2884 $userstatic->id = $obj->rowid;
2885 $userstatic->lastname = $obj->lastname;
2886 $userstatic->firstname = $obj->firstname;
2887 $userstatic->photo = $obj->photo;
2888 $userstatic->status = $obj->status;
2889 $userstatic->entity = $obj->entity;
2890 $userstatic->admin = $obj->admin;
2891 $userstatic->gender = $obj->gender;
2894 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
2895 $disableline = ($enableonlytext ? $enableonlytext :
'1');
2899 $labeltoshowhtml =
'';
2906 $labeltoshow .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2907 $labeltoshowhtml .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2908 if (empty($obj->firstname) && empty($obj->lastname)) {
2909 $labeltoshow .= $obj->login;
2910 $labeltoshowhtml .= $obj->login;
2917 $moreinfo .= ($moreinfo ?
' - ' :
' (');
2918 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(');
2919 $moreinfo .= $obj->login;
2920 $moreinfohtml .= $obj->login;
2922 if ($showstatus >= 0) {
2923 if ($obj->status == 1 && $showstatus == 1) {
2924 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Enabled');
2925 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Enabled');
2927 if ($obj->status == 0 && $showstatus == 1) {
2928 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Disabled');
2929 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Disabled');
2932 if ($showlabelofentity) {
2933 if (empty($obj->entity)) {
2934 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
"AllEntities");
2935 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
"AllEntities");
2937 if ($obj->entity !=
$conf->entity) {
2938 $moreinfo .= ($moreinfo ?
' - ' :
' (') . ($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2939 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(').($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2943 $moreinfo .= (!empty($moreinfo) ?
')' :
'');
2944 $moreinfohtml .= (!empty($moreinfohtml) ?
')</span>' :
'');
2945 if (!empty($disableline) && $disableline !=
'1') {
2947 $moreinfo .=
' - ' . $disableline;
2948 $moreinfohtml .=
' - ' . $disableline;
2950 $labeltoshow .= $moreinfo;
2951 $labeltoshowhtml .= $moreinfohtml;
2953 $out .=
'<option value="' . $obj->rowid .
'"';
2954 if (!empty($disableline)) {
2955 $out .=
' disabled';
2957 if (in_array($obj->rowid, $selected)) {
2958 $out .=
' selected';
2960 $out .=
' data-html="';
2962 $outhtml = $userstatic->getNomUrl(-3,
'', 0, 1, 24, 1,
'login',
'', 1) .
' ';
2963 if ($showstatus >= 0 && $obj->status == 0) {
2964 $outhtml .=
'<strike class="opacitymediumxxx">';
2966 $outhtml .= $labeltoshowhtml;
2967 if ($showstatus >= 0 && $obj->status == 0) {
2968 $outhtml .=
'</strike>';
2970 $labeltoshowhtml = $outhtml;
2974 $out .= $labeltoshow;
2975 $out .=
'</option>';
2977 $outarray[$userstatic->id] = $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength) . $moreinfo;
2978 $outarray2[$userstatic->id] = array(
2979 'id' => $userstatic->id,
2980 'label' => $labeltoshow,
2981 'labelhtml' => $labeltoshowhtml,
2989 $out .=
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'" disabled>';
2990 $out .=
'<option value="">' . $langs->trans(
"None") .
'</option>';
2992 $out .=
'</select>';
2994 if ($num && !$forcecombo) {
2996 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3005 if ($outputmode == 2) {
3007 } elseif ($outputmode) {
3039 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)
3042 global $langs, $user;
3044 $userstatic =
new User($this->db);
3050 if (!empty($listofuserid)) {
3051 $assignedtouser = $listofuserid;
3052 } elseif (!empty($_SESSION[
'assignedtouser'])) {
3053 $assignedtouser = json_decode($_SESSION[
'assignedtouser'],
true);
3054 if (!is_array($assignedtouser)) {
3055 $assignedtouser = array();
3058 $assignedtouser = array();
3060 $nbassignetouser = count($assignedtouser);
3063 if ($nbassignetouser) {
3064 $out .=
'<ul class="attendees">';
3068 foreach ($assignedtouser as $key => $value) {
3069 if ($value[
'id'] == $ownerid) {
3075 $userstatic->fetch($value[
'id']);
3076 $out .= $userstatic->getNomUrl(-4);
3079 $ownerid = $value[
'id'];
3080 $out .=
' (' . $langs->trans(
"Owner") .
')';
3083 if ($nbassignetouser > 1 && $action !=
'view') {
3084 $canremoveassignee = 1;
3087 if (!$canremoveowner) {
3088 $canremoveassignee = 0;
3090 if (!$user->hasRight(
'agenda',
'allactions',
'create')) {
3091 $canremoveassignee = 0;
3096 if ($canremoveassignee) {
3099 $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 .
'">';
3103 if ($showproperties) {
3104 if ($ownerid == $value[
'id'] && is_array($listofuserid) && count($listofuserid) && in_array($ownerid, array_keys($listofuserid))) {
3105 $out .=
'<div class="myavailability inline-block">';
3106 $out .=
'<span class="hideonsmartphone"> - ';
3109 $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>';
3119 if ($nbassignetouser) {
3124 if ($action !=
'view') {
3126 $out .=
'<div class="divadduser'.$htmlname.
'">';
3127 $out .=
'<input type="hidden" class="removedassignedhidden" name="removedassigned" value="">';
3128 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
3129 $out .=
'jQuery(".removedassigned").click(function() { jQuery(".removedassignedhidden").val(jQuery(this).val()); });';
3130 $out .=
'jQuery(".assignedtouser").change(function() { console.log(jQuery(".assignedtouser option:selected").val());';
3131 $out .=
' if (jQuery(".assignedtouser option:selected").val() > 0) { jQuery("#' . $action .
'assignedtouser").attr("disabled", false); }';
3132 $out .=
' else { jQuery("#' . $action .
'assignedtouser").attr("disabled", true); }';
3134 $out .=
'})</script>';
3135 $out .=
img_picto(
'',
'user',
'class="pictofixedwidth"');
3136 $out .= $this->
select_dolusers(
'', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter, 0,
'',
'minwidth200');
3137 $out .=
' <button type="submit" disabled class="button valignmiddle smallpaddingimp reposition butActionAdd" id="' . $action .
'assignedtouser" name="' . $action .
'assignedtouser" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
3138 $out .= $langs->trans(
"Add").
'</button>';
3166 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())
3171 require_once DOL_DOCUMENT_ROOT.
'/resource/class/html.formresource.class.php';
3172 require_once DOL_DOCUMENT_ROOT.
'/resource/class/dolresource.class.php';
3177 if (!empty($_SESSION[
'assignedtoresource'])) {
3178 $assignedtoresource = json_decode($_SESSION[
'assignedtoresource'],
true);
3179 if (!is_array($assignedtoresource)) {
3180 $assignedtoresource = array();
3183 $assignedtoresource = array();
3185 $nbassignetoresource = count($assignedtoresource);
3188 if ($nbassignetoresource) {
3189 $out .=
'<ul class="attendees">';
3193 foreach ($assignedtoresource as $key => $value) {
3195 $resourcestatic->fetch($value[
'id']);
3196 $out .= $resourcestatic->getNomUrl(-1);
3197 if ($nbassignetoresource >= 1 && $action !=
'view') {
3198 $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 .
'">';
3201 if ($showproperties) {
3202 if (is_array($listofresourceid) && count($listofresourceid)) {
3203 $out .=
'<div class="myavailability inline-block">';
3204 $out .=
'<span class="hideonsmartphone"> - ';
3207 $out .=
' <input title="'.$langs->trans(
"Availability").
'" id="transparencyresource'.$value[
'id'].
'" class="paddingrightonly" ' . ($action ==
'view' ?
'disabled' :
'') .
' type="checkbox" name="transparency"' . ($listofresourceid[$value[
'id']][
'transparency'] ?
' checked' :
'') .
'><label for="transparencyresource'.$value[
'id'].
'">' . $langs->trans(
"Busy") .
'</label>';
3217 if ($nbassignetoresource) {
3222 if ($action !=
'view') {
3223 $out .=
'<input type="hidden" class="removedassignedresourcehidden" name="removedassignedresource" value="">';
3224 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
3225 $out .=
'jQuery(".removedassignedresource").click(function() { jQuery(".removedassignedresourcehidden").val(jQuery(this).val()); });';
3226 $out .=
'jQuery(".assignedtoresource").change(function() { console.log(jQuery(".assignedtoresource option:selected").val());';
3227 $out .=
' if (jQuery(".assignedtoresource option:selected").val() > 0) { jQuery("#' . $action .
'assignedtoresource").attr("disabled", false); }';
3228 $out .=
' else { jQuery("#' . $action .
'assignedtoresource").attr("disabled", true); }';
3230 $out .=
'})</script>';
3233 if ($nbassignetoresource) {
3236 $out .=
img_picto(
'',
'resource',
'class="pictofixedwidth"');
3238 $out .= $formresources->select_resource_list(0, $htmlname,
'', 1, 1, 0, $events,
'', 2, 0,
'minwidth200');
3240 $out .=
' <button type="submit" disabled class="button valignmiddle smallpaddingimp reposition butActionAdd" id="' . $action .
'assignedtoresource" name="' . $action .
'assignedtoresource" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
3241 $out .= $langs->trans(
"Add");
3242 $out .=
'</button>';
3280 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)
3283 global $langs,
$conf;
3288 $price_level = (!empty($price_level) ? $price_level : 0);
3289 if (is_null($ajaxoptions)) {
3290 $ajaxoptions = array();
3302 $placeholder = (is_numeric($showempty) ?
'' :
'placeholder="'.dolPrintHTML($showempty).
'"');
3304 if ($selected && empty($selected_input_value)) {
3305 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3306 $producttmpselect =
new Product($this->db);
3307 $producttmpselect->fetch($selected);
3308 $selected_input_value = $producttmpselect->ref;
3309 unset($producttmpselect);
3312 if ($filtertype ==
'') {
3320 $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;
3321 if ((
int) $warehouseId > 0) {
3322 $urloption .=
'&warehouseid=' . (int) $warehouseId;
3325 if (
isModEnabled(
'variants') && is_array($selected_combinations)) {
3331 <!-- script to auto show attributes select tags if a variant was selected -->
3332 <script nonce="' .
getNonce() .
'">
3333 // auto show attributes fields
3334 selected = ' . json_encode($selected_combinations) .
';
3337 jQuery(document).ready(function () {
3339 jQuery("input[name=\'prod_entry_mode\']").change(function () {
3340 if (jQuery(this).val() == \'free\') {
3341 jQuery(\'div#attributes_box\').empty();
3345 jQuery("'.$htmltag.
'#' . $htmlname .
'").change(function () {
3347 if (!jQuery(this).val()) {
3348 jQuery(\'div#attributes_box\').empty();
3352 console.log("A change has started. We get variants fields to inject html select");
3354 jQuery.getJSON("' . DOL_URL_ROOT .
'/variants/ajax/getCombinations.php", {
3355 id: jQuery(this).val()
3356 }, function (data) {
3357 jQuery(\'div#attributes_box\').empty();
3359 jQuery.each(data, function (key, val) {
3361 combvalues[val.id] = val.values;
3363 var span = jQuery(document.createElement(\'div\')).css({
3364 \'display\': \'table-row\'
3368 jQuery(document.createElement(\'div\')).text(val.label).css({
3369 \'font-weight\': \'bold\',
3370 \'display\': \'table-cell\'
3374 var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({
3375 \'margin-left\': \'15px\',
3376 \'white-space\': \'pre\'
3378 jQuery(document.createElement(\'option\')).val(\'\')
3381 jQuery.each(combvalues[val.id], function (key, val) {
3382 var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value);
3384 if (selected[val.fk_product_attribute] == val.id) {
3385 tag.attr(\'selected\', \'selected\');
3392 jQuery(\'div#attributes_box\').append(span);
3397 ' . ($selected ?
'jQuery("'.$htmltag.
'#' . $htmlname .
'").change();' :
'') .
'
3403 if (empty($hidelabel)) {
3405 } elseif ($hidelabel > 1) {
3407 if ($hidelabel == 2) {
3408 $out .=
img_picto($langs->trans(
"Search"),
'search');
3412 $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" />';
3413 if ($hidelabel == 3) {
3414 $out .=
img_picto($langs->trans(
"Search"),
'search');
3417 $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);
3419 $out .= $this->
select_produits_list($selected, $htmlname, $filtertype, $limit, $price_level,
'', $status, $finished, 0, $socid, $showempty, $forcecombo, $morecss, $hidepriceinlabel, $warehouseStatus, $status_purchase, $warehouseId);
3421 if (
isModEnabled(
'variants') && is_array($selected_combinations)) {
3425 $htmltag =
'select';
3427 <!-- script to auto show attributes select tags if a variant was selected -->
3428 <script nonce="' .
getNonce() .
'">
3429 // auto show attributes fields
3430 selected = ' . json_encode($selected_combinations) .
';
3433 jQuery(document).ready(function () {
3435 jQuery("input[name=\'prod_entry_mode\']").change(function () {
3436 if (jQuery(this).val() == \'free\') {
3437 jQuery(\'div#attributes_box\').empty();
3441 jQuery("'.$htmltag.
'#' . $htmlname .
'").change(function () {
3443 if (!jQuery(this).val()) {
3444 jQuery(\'div#attributes_box\').empty();
3448 console.log("A change has started. We get variants fields to inject html select");
3450 jQuery.getJSON("' . DOL_URL_ROOT .
'/variants/ajax/getCombinations.php", {
3451 id: jQuery(this).val()
3452 }, function (data) {
3453 jQuery(\'div#attributes_box\').empty();
3455 jQuery.each(data, function (key, val) {
3457 combvalues[val.id] = val.values;
3459 var span = jQuery(document.createElement(\'div\')).css({
3460 \'display\': \'table-row\'
3464 jQuery(document.createElement(\'div\')).text(val.label).css({
3465 \'font-weight\': \'bold\',
3466 \'display\': \'table-cell\'
3470 var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({
3471 \'margin-left\': \'15px\',
3472 \'white-space\': \'pre\'
3474 jQuery(document.createElement(\'option\')).val(\'\')
3477 jQuery.each(combvalues[val.id], function (key, val) {
3478 var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value);
3480 if (selected[val.fk_product_attribute] == val.id) {
3481 tag.attr(\'selected\', \'selected\');
3488 jQuery(\'div#attributes_box\').append(span);
3493 ' . ($selected ?
'jQuery("'.$htmltag.
'#' . $htmlname .
'").change();' :
'') .
'
3500 if (empty($nooutput)) {
3524 public function select_bom($selected =
'', $htmlname =
'bom_id', $limit = 0, $status = 1, $type = 0, $showempty =
'1', $morecss =
'', $nooutput =
'', $forcecombo = 0, $TProducts = [])
3528 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3534 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3539 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
3541 $sql =
'SELECT b.rowid, b.ref, b.label as bomLabel, p.label as productLabel';
3542 $sql .=
' FROM ' . $this->db->prefix() .
'bom_bom as b';
3543 $sql .=
' INNER JOIN ' . $this->db->prefix() .
'product as p ON b.fk_product = p.rowid';
3544 $sql .=
' WHERE b.entity IN (' .
getEntity(
'bom') .
')';
3545 if (!empty($status)) {
3546 $sql .=
' AND status = ' . (int) $status;
3548 if (!empty($type)) {
3549 $sql .=
' AND bomtype = ' . (int) $type;
3551 if (!empty($TProducts)) {
3552 $sql .=
' AND fk_product IN (' . $this->db->sanitize(implode(
',', $TProducts)) .
')';
3554 if (!empty($limit)) {
3555 $sql .=
' LIMIT ' . (int) $limit;
3557 $resql = $this->db->query($sql);
3560 $out .=
'<option value="-1"';
3561 if (empty($selected)) {
3562 $out .=
' selected';
3564 $out .=
'> </option>';
3566 while ($obj = $this->db->fetch_object($resql)) {
3567 $out .=
'<option value="' . $obj->rowid .
'"';
3568 if ($obj->rowid == $selected) {
3571 $out .=
'>' . $obj->ref .
' - ' . $obj->productLabel .
' - ' . $obj->bomLabel .
'</option>';
3577 $out .=
'</select>';
3578 if (empty($nooutput)) {
3613 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)
3617 global $hookmanager;
3620 $outarray = array();
3624 $langs->load(
'other');
3627 $warehouseStatusArray = array();
3628 if (!empty($warehouseStatus)) {
3629 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/entrepot.class.php';
3630 if (preg_match(
'/warehouseclosed/', $warehouseStatus)) {
3633 if (preg_match(
'/warehouseopen/', $warehouseStatus)) {
3636 if (preg_match(
'/warehouseinternal/', $warehouseStatus)) {
3641 $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";
3642 if (count($warehouseStatusArray)) {
3643 $selectFieldsGrouped =
", SUM(" . $this->db->ifsql(
"e.statut IS NULL",
"0",
"ps.reel") .
") as stock";
3645 $selectFieldsGrouped =
", " . $this->db->ifsql(
"p.stock IS NULL",
'0',
"p.stock") .
" AS stock";
3651 $parameters = array();
3652 $reshook = $hookmanager->executeHooks(
'selectProductsListSelect', $parameters);
3653 if (empty($reshook)) {
3654 $sql .= $selectFields.$selectFieldsGrouped.$hookmanager->resPrint;
3656 $sql .= $hookmanager->resPrint;
3661 $sql .=
", (SELECT " . $this->db->prefix() .
"categorie_product.fk_categorie
3662 FROM " . $this->db->prefix() .
"categorie_product
3663 WHERE " . $this->db->prefix() .
"categorie_product.fk_product = p.rowid
3665 ) AS categorie_product_id";
3670 $sql .=
', pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,';
3671 $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';
3672 $selectFields .=
", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custdefault_vat_code, custref, custdiscount_percent";
3676 $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";
3677 $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';
3682 $sql .=
", pl.label as label_translated";
3683 $sql .=
", pl.description as description_translated";
3684 $selectFields .=
", label_translated";
3685 $selectFields .=
", description_translated";
3689 $sql .=
", (SELECT pp.rowid FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
3690 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
3691 $sql .=
" AND price_level = " . ((int) $price_level);
3693 $sql .=
" ORDER BY date_price";
3694 $sql .=
" DESC LIMIT 1) as price_rowid";
3695 $sql .=
", (SELECT pp.price_by_qty FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
3696 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
3697 $sql .=
" AND price_level = " . ((int) $price_level);
3699 $sql .=
" ORDER BY date_price";
3700 $sql .=
" DESC LIMIT 1) as price_by_qty";
3701 $selectFields .=
", price_rowid, price_by_qty";
3706 $sql .=
" FROM ".$this->db->prefix().
"product as p";
3709 $sql .=
" USE INDEX (" . $this->db->sanitize(
getDolGlobalString(
'MAIN_PRODUCT_FORCE_INDEX')) .
")";
3713 $parameters = array(
3716 $reshook = $hookmanager->executeHooks(
'selectProductsListFrom', $parameters);
3717 $sql .= $hookmanager->resPrint;
3719 if (count($warehouseStatusArray)) {
3722 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_stock as ps ON ps.fk_product = p.rowid";
3723 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entrepot as e ON ps.fk_entrepot = e.rowid AND e.entity IN (" .
getEntity(
'stock') .
")";
3724 $sql .=
' AND e.statut IN (' . $this->db->sanitize($this->db->escape(implode(
',', $warehouseStatusArray))) .
')';
3730 $sql .=
" LEFT JOIN (";
3731 $sql .=
" SELECT pcp1.*";
3732 $sql .=
" FROM " . $this->db->prefix() .
"product_customer_price AS pcp1";
3733 $sql .=
" LEFT JOIN (";
3734 $sql .=
" SELECT fk_soc, fk_product, MIN(date_begin) AS date_begin";
3735 $sql .=
" FROM " . $this->db->prefix() .
"product_customer_price";
3736 $sql .=
" WHERE fk_soc = " . ((int) $socid);
3737 $sql .=
" AND date_begin <= '" . $this->db->idate($now) .
"'";
3738 $sql .=
" AND (date_end IS NULL OR '" . $this->db->idate($now) .
"' <= date_end)";
3739 $sql .=
" GROUP BY fk_soc, fk_product";
3740 $sql .=
" ) AS pcp2 ON pcp1.fk_soc = pcp2.fk_soc AND pcp1.fk_product = pcp2.fk_product AND pcp1.date_begin = pcp2.date_begin";
3741 $sql .=
" WHERE pcp2.fk_soc IS NOT NULL";
3742 $sql .=
" ) AS pcp ON pcp.fk_soc = " . ((int) $socid) .
" AND pcp.fk_product = p.rowid";
3746 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units as u ON u.rowid = p.fk_unit";
3750 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_lang as pl ON pl.fk_product = p.rowid";
3752 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
3753 $soc =
new Societe($this->db);
3754 $result = $soc->fetch($socid);
3755 if ($result > 0 && !empty($soc->default_lang)) {
3756 $sql .=
" AND pl.lang = '" . $this->db->escape($soc->default_lang) .
"'";
3758 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3761 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3766 $sql .=
' WHERE p.entity IN (' .
getEntity(
'product') .
')';
3769 if (strlen($filterkey) != 13) {
3770 $sql .=
" AND NOT EXISTS (SELECT pac.rowid FROM ".$this->db->prefix().
"product_attribute_combination as pac WHERE pac.fk_product_child = p.rowid)";
3773 $sql .=
" AND NOT EXISTS (SELECT pac.rowid FROM ".$this->db->prefix().
"product_attribute_combination as pac WHERE pac.fk_product_child = p.rowid)";
3776 if ($finished == 0) {
3777 $sql .=
" AND p.finished = " . ((int) $finished);
3778 } elseif ($finished == 1) {
3779 $sql .=
" AND p.finished = ".((int) $finished);
3782 $sql .=
" AND p.tosell = ".((int) $status);
3784 if ($status_purchase >= 0) {
3785 $sql .=
" AND p.tobuy = " . ((int) $status_purchase);
3788 if (strval($filtertype) !=
'') {
3789 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
3791 $sql .=
" AND p.fk_product_type = 1";
3793 $sql .=
" AND p.fk_product_type = 0";
3796 if ((
int) $warehouseId > 0) {
3797 $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)";
3801 $parameters = array(
3802 'filterkey' => &$filterkey,
3805 $reshook = $hookmanager->executeHooks(
'selectProductsListWhere', $parameters);
3806 $sql .= $hookmanager->resPrint;
3808 if ($filterkey !=
'') {
3809 $sqlSupplierSearch =
'';
3814 $search_crit = explode(
' ', $filterkey);
3816 if (count($search_crit) > 1) {
3819 foreach ($search_crit as $crit) {
3823 $sql .=
"(p.ref LIKE '" . $this->db->escape($prefix . $crit) .
"%' OR p.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3825 $sql .=
" OR pl.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3828 $sql .=
" OR pcp.ref_customer LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3831 $sql .=
" OR p.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3833 $sql .=
" OR pl.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3839 $sqlSupplierSearch .= !empty($sqlSupplierSearch) ?
' AND ' :
'';
3840 $sqlSupplierSearch .=
" pfp.ref_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3845 if (count($search_crit) > 1) {
3849 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3854 $sql .=
" OR EXISTS (SELECT pfp.fk_product FROM " . $this->db->prefix() .
"product_fournisseur_price as pfp WHERE p.rowid = pfp.fk_product";
3856 $sql .= $sqlSupplierSearch;
3862 if (count($warehouseStatusArray)) {
3863 $sql .=
" GROUP BY " . $this->db->sanitize($selectFields, 0, 0, 1);
3868 $sql .=
" ORDER BY categorie_product_id ".(getDolGlobalInt(
'PRODUCT_SORT_BY_CATEGORY') == 1 ?
"ASC" :
"DESC");
3870 $sql .= $this->db->order(
"p.ref");
3874 $sql .= $this->db->plimit($limit, 0);
3892 dol_syslog(get_class($this) .
"::select_produits_list search products", LOG_DEBUG);
3896 $result = $this->db->query($sql);
3899 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3900 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3901 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
3903 $num = $this->db->num_rows($result);
3908 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3912 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
3918 if ($showempty && !is_numeric($showempty)) {
3919 $textifempty = $langs->trans($showempty);
3921 $textifempty .= $langs->trans(
"All");
3924 if ($showempty && !is_numeric($showempty)) {
3925 $textifempty = $langs->trans($showempty);
3929 $out .=
'<option value="-1" selected>' . ($textifempty ? $textifempty :
' ') .
'</option>';
3933 while ($num && $i < $num) {
3936 $objp = $this->db->fetch_object($result);
3938 if ((
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1) {
3939 $sql =
"SELECT rowid, quantity, price, unitprice, remise_percent, remise, price_base_type";
3940 $sql .=
" FROM " . $this->db->prefix() .
"product_price_by_qty";
3941 $sql .=
" WHERE fk_product_price = " . ((int) $objp->price_rowid);
3942 $sql .=
" ORDER BY quantity ASC";
3944 dol_syslog(get_class($this) .
"::select_produits_list search prices by qty", LOG_DEBUG);
3945 $result2 = $this->db->query($sql);
3947 $nb_prices = $this->db->num_rows($result2);
3949 while ($nb_prices && $j < $nb_prices) {
3950 $objp2 = $this->db->fetch_object($result2);
3952 $objp->price_by_qty_rowid = $objp2->rowid;
3953 $objp->price_by_qty_price_base_type = $objp2->price_base_type;
3954 $objp->price_by_qty_quantity = $objp2->quantity;
3955 $objp->price_by_qty_unitprice = $objp2->unitprice;
3956 $objp->price_by_qty_remise_percent = $objp2->remise_percent;
3958 $objp->quantity = $objp2->quantity;
3959 $objp->price = $objp2->price;
3960 $objp->unitprice = $objp2->unitprice;
3961 $objp->remise_percent = $objp2->remise_percent;
3967 '@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';
3974 array_push($outarray, $optJson);
3978 if (
isModEnabled(
'dynamicprices') && !empty($objp->fk_price_expression)) {
3979 $price_product =
new Product($this->db);
3980 $price_product->fetch($objp->rowid,
'',
'',
'1');
3982 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3984 $price_result = $priceparser->parseProduct($price_product);
3985 if ($price_result >= 0) {
3986 $objp->price = $price_result;
3987 $objp->unitprice = $price_result;
3989 $objp->price_ttc = (float)
price2num($objp->price) * (1 + ($objp->tva_tx / 100));
3990 $objp->price_ttc =
price2num($objp->price_ttc,
'MU');
3993 if (
getDolGlobalInt(
'PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES') && !empty($objp->custprice)) {
4001 array_push($outarray, $optJson);
4007 $out .=
'</select>';
4009 $this->db->free($result);
4011 if (empty($outputmode)) {
4038 protected function constructProductListOption(&$objp, &$opt, &$optJson, $price_level, $selected, $hidepriceinlabel = 0, $filterkey =
'', $novirtualstock = 0)
4040 global $langs,
$conf, $user;
4041 global $hookmanager;
4047 $outlabel_translated =
'';
4049 $outdesc_translated =
'';
4055 $outpricebasetype =
'';
4057 $outdefault_vat_code =
'';
4063 $productlabel = $objp->label;
4064 if (!empty($objp->label_translated)) {
4065 $productlabel = $objp->label_translated;
4067 $label = $productlabel;
4068 if (!empty($filterkey) && $filterkey !=
'') {
4069 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
4072 $outkey = $objp->rowid;
4073 $outref = $objp->ref;
4074 $outrefcust = empty($objp->custref) ?
'' : $objp->custref;
4075 $outlabel = $objp->label;
4076 $outdesc = $objp->description;
4078 $outlabel_translated = $objp->label_translated;
4079 $outdesc_translated = $objp->description_translated;
4081 $outbarcode = $objp->barcode;
4082 $outorigin = $objp->fk_country;
4083 $outpbq = empty($objp->price_by_qty_rowid) ?
'' : $objp->price_by_qty_rowid;
4085 $outtype = $objp->fk_product_type;
4090 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
4096 if (!empty($objp->unit_short)) {
4097 $outvalUnits .=
' - ' . $objp->unit_short;
4101 if (!empty($objp->weight) && $objp->weight_units !==
null) {
4103 $outvalUnits .=
' - ' . $unitToShow;
4105 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
4106 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
4107 $outvalUnits .=
' - ' . $unitToShow;
4109 if (!empty($objp->surface) && $objp->surface_units !==
null) {
4111 $outvalUnits .=
' - ' . $unitToShow;
4113 if (!empty($objp->volume) && $objp->volume_units !==
null) {
4115 $outvalUnits .=
' - ' . $unitToShow;
4118 if ($outdurationvalue && $outdurationunit) {
4120 'h' => $langs->trans(
'Hour'),
4121 'd' => $langs->trans(
'Day'),
4122 'w' => $langs->trans(
'Week'),
4123 'm' => $langs->trans(
'Month'),
4124 'y' => $langs->trans(
'Year')
4126 if (isset($da[$outdurationunit])) {
4127 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
4134 if ($user->hasRight(
'stock',
'lire')) {
4135 if ($objp->stock > 0) {
4137 } elseif ($objp->stock <= 0) {
4145 $labeltosearch =
'';
4146 $labeltosearch .= $objp->ref;
4147 if (!empty($objp->custref)) {
4148 $labeltosearch .=
' (' . $objp->custref .
')';
4151 $labeltosearch .=
' (' . $outbarcode .
')';
4153 $labeltosearch .=
' - ' . $productlabel;
4155 $labeltosearch .=
' (' .
getCountry($outorigin,
'1') .
')';
4159 $labeltoshowhtml =
'';
4160 $labeltoshowhtml .= $objp->ref;
4161 if (!empty($objp->custref)) {
4162 $labeltoshowhtml .=
' (' . $objp->custref .
')';
4164 if (!empty($filterkey) && $filterkey !=
'') {
4165 $labeltoshowhtml = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $labeltoshowhtml, 1);
4168 $labeltoshowhtml .=
' (' . $outbarcode .
')';
4170 $labeltoshowhtml .=
' - ' .
dol_trunc($label, $maxlengtharticle);
4172 $labeltoshowhtml .=
' (' .
getCountry($outorigin,
'1') .
')';
4176 $labeltoshowstock =
'';
4177 $labeltoshowhtmlstock =
'';
4179 if ($user->hasRight(
'stock',
'lire')) {
4180 $labeltoshowstock .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
4182 if ($objp->stock > 0) {
4183 $labeltoshowhtmlstock .=
' - <span class="product_line_stock_ok">';
4184 } elseif ($objp->stock <= 0) {
4185 $labeltoshowhtmlstock .=
' - <span class="product_line_stock_too_low">';
4187 $labeltoshowhtmlstock .= $langs->transnoentities(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
4188 $labeltoshowhtmlstock .=
'</span>';
4190 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
4191 $langs->load(
"stocks");
4193 $tmpproduct =
new Product($this->db);
4194 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
4195 $tmpproduct->load_virtual_stock();
4196 $virtualstock = $tmpproduct->stock_theorique;
4198 $labeltoshowstock .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
4200 $labeltoshowhtmlstock .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
4201 if ($virtualstock > 0) {
4202 $labeltoshowhtmlstock .=
'<span class="product_line_stock_ok">';
4203 } elseif ($virtualstock <= 0) {
4204 $labeltoshowhtmlstock .=
'<span class="product_line_stock_too_low">';
4206 $labeltoshowhtmlstock .= $virtualstock;
4207 $labeltoshowhtmlstock .=
'</span>';
4216 $labeltoshowprice =
'';
4217 $labeltoshowhtmlprice =
'';
4220 $sql =
"SELECT price, price_ttc, price_base_type, tva_tx, default_vat_code";
4221 $sql .=
" FROM " . $this->db->prefix() .
"product_price";
4222 $sql .=
" WHERE fk_product = " . ((int) $objp->rowid);
4223 $sql .=
" AND entity IN (" .
getEntity(
'productprice') .
")";
4224 $sql .=
" AND price_level = " . ((int) $price_level);
4225 $sql .=
" ORDER BY date_price DESC, rowid DESC";
4228 dol_syslog(get_class($this) .
'::constructProductListOption search price for product ' . $objp->rowid .
' AND level ' . $price_level, LOG_DEBUG);
4229 $result2 = $this->db->query($sql);
4231 $objp2 = $this->db->fetch_object($result2);
4234 if ($objp2->price_base_type ==
'HT') {
4235 $labeltoshowprice .=
' - ' .
price($objp2->price, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
4236 $labeltoshowhtmlprice .=
' - ' .
price($objp2->price, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
4238 $labeltoshowprice .=
' - ' .
price($objp2->price_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
4239 $labeltoshowhtmlprice .=
' - ' .
price($objp2->price_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
4241 $outprice_ht =
price($objp2->price);
4242 $outprice_ttc =
price($objp2->price_ttc);
4243 $outpricebasetype = $objp2->price_base_type;
4245 $outtva_tx = $objp2->tva_tx;
4246 $outdefault_vat_code = $objp2->default_vat_code;
4248 $outtva_tx = $objp->tva_tx;
4249 $outdefault_vat_code = $objp->default_vat_code;
4258 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1 && (
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
4260 $outqty = $objp->quantity;
4261 $outdiscount = $objp->remise_percent;
4262 if ($objp->quantity == 1) {
4263 $labeltoshowprice .=
' - ' .
price($objp->unitprice, 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
4264 $labeltoshowhtmlprice .=
' - ' .
price($objp->unitprice, 0, $langs, 0, 0, -1,
$conf->currency) .
"/";
4265 $labeltoshowprice .= $langs->trans(
"Unit");
4266 $labeltoshowhtmlprice .= $langs->transnoentities(
"Unit");
4268 $labeltoshowprice .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
4269 $labeltoshowhtmlprice .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
4270 $labeltoshowprice .= $langs->trans(
"Units");
4271 $labeltoshowhtmlprice .= $langs->transnoentities(
"Units");
4274 $outprice_ht =
price($objp->unitprice);
4275 $outprice_ttc =
price($objp->unitprice * (1 + ($objp->tva_tx / 100)));
4276 $outpricebasetype = $objp->price_base_type;
4277 $outtva_tx = $objp->tva_tx;
4278 $outdefault_vat_code = $objp->default_vat_code;
4280 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1) {
4281 $labeltoshowprice .=
" (" .
price($objp->unitprice, 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->trans(
"Unit") .
")";
4282 $labeltoshowhtmlprice .=
" (" .
price($objp->unitprice, 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->transnoentities(
"Unit") .
")";
4284 if (empty($hidepriceinlabel) && !empty($objp->remise_percent) && $objp->remise_percent >= 1) {
4285 $labeltoshowprice .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4286 $labeltoshowhtmlprice .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4291 if (!empty($objp->idprodcustprice)) {
4294 if ($objp->custprice_base_type ==
'HT') {
4295 $labeltoshowprice .=
' - ' .
price($objp->custprice, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
4296 $labeltoshowhtmlprice .=
' - ' .
price($objp->custprice, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
4298 $labeltoshowprice .=
' - ' .
price($objp->custprice_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
4299 $labeltoshowhtmlprice .=
' - ' .
price($objp->custprice_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
4302 $outprice_ht =
price($objp->custprice);
4303 $outprice_ttc =
price($objp->custprice_ttc);
4304 $outpricebasetype = $objp->custprice_base_type;
4305 $outtva_tx = $objp->custtva_tx;
4306 $outdefault_vat_code = $objp->custdefault_vat_code;
4307 $outdiscount = $objp->custdiscount_percent;
4312 if (empty($hidepriceinlabel) && !$found) {
4313 if ($objp->price_base_type ==
'HT') {
4314 $labeltoshowprice .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
4315 $labeltoshowhtmlprice .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
4317 $labeltoshowprice .=
' - ' .
price($objp->price_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
4318 $labeltoshowhtmlprice .=
' - ' .
price($objp->price_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
4320 $outprice_ht =
price($objp->price);
4321 $outprice_ttc =
price($objp->price_ttc);
4322 $outpricebasetype = $objp->price_base_type;
4323 $outtva_tx = $objp->tva_tx;
4324 $outdefault_vat_code = $objp->default_vat_code;
4327 $optiontext = $labeltosearch.$outvalUnits.$labeltoshowprice.$labeltoshowstock;
4328 $optionhtml = $labeltoshowhtml.$outvalUnits.$labeltoshowhtmlprice.$labeltoshowhtmlstock;
4332 $opt =
'<option value="' . $objp->rowid .
'"';
4333 $opt .= ($objp->rowid == $selected) ?
' selected' :
'';
4334 if (!empty($objp->price_by_qty_rowid) && $objp->price_by_qty_rowid > 0) {
4335 $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 .
'"';
4338 $opt .=
' data-labeltrans="' .
dol_escape_htmltag($outlabel_translated, 0, 0,
'', 0, 1) .
'"';
4342 if ($stocktag == 1) {
4343 $opt .=
' class="product_line_stock_ok" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml, 0, array(
'strong')).dolPrintHTMLForAttribute($outvalUnits).$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
4346 if ($stocktag == -1) {
4347 $opt .=
' class="product_line_stock_too_low" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml, 0, array(
'strong')).dolPrintHTMLForAttribute($outvalUnits).$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
4350 $opt .=
' data-html="'.$optionhtmlforattribute.
'" data-select-html="'.$optionhtmlforattribute.
'"';
4356 $outval .= $labeltoshowhtml;
4359 $outval .= $outvalUnits;
4362 $outval .= $labeltoshowhtmlprice;
4365 $outval .= $labeltoshowhtmlstock;
4368 $parameters = array(
'objp' => $objp);
4369 $reshook = $hookmanager->executeHooks(
'constructProductListOption', $parameters);
4370 if (empty($reshook)) {
4371 $opt .= $hookmanager->resPrint;
4373 $opt = $hookmanager->resPrint;
4376 $opt .=
"</option>\n";
4381 'label2' => $outlabel,
4385 'price_ttc' =>
price2num($outprice_ttc),
4388 'pricebasetype' => $outpricebasetype,
4389 'tva_tx' => $outtva_tx,
4390 'default_vat_code' => $outdefault_vat_code,
4392 'discount' => $outdiscount,
4393 'duration_value' => $outdurationvalue,
4394 'duration_unit' => $outdurationunit,
4396 'labeltrans' => $outlabel_translated,
4397 'desctrans' => $outdesc_translated,
4398 'ref_customer' => $outrefcust
4420 public function select_produits_fournisseurs($socid, $selected =
'', $htmlname =
'productid', $filtertype =
'', $notused =
'', $ajaxoptions = array(), $hidelabel = 0, $alsoproductwithnosupplierprice = 0, $morecss =
'', $placeholder =
'', $nooutput = 0)
4423 global $langs,
$conf;
4424 global $price_level, $status, $finished;
4426 if (!isset($status)) {
4430 $selected_input_value =
'';
4432 if ((
int) $selected > 0) {
4433 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
4434 $producttmpselect =
new Product($this->db);
4435 $producttmpselect->fetch((
int) $selected);
4436 $selected_input_value = $producttmpselect->ref;
4437 unset($producttmpselect);
4438 } elseif (preg_match(
'/^idprod_([0-9]+)$/', (
string) $selected, $regtmpsel)) {
4440 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
4441 $producttmpselect =
new Product($this->db);
4442 $producttmpselect->fetch((
int) $regtmpsel[1]);
4443 $selected_input_value = $producttmpselect->ref;
4444 unset($producttmpselect);
4448 $urloption = ($socid > 0 ?
'socid=' . $socid .
'&' :
'') .
'htmlname=' . $htmlname .
'&outjson=1&price_level=' . $price_level .
'&type=' . $filtertype .
'&mode=2&status=' . $status .
'&finished=' . $finished .
'&alsoproductwithnosupplierprice=' . $alsoproductwithnosupplierprice;
4450 $s = ($hidelabel ?
'' : $langs->trans(
"RefOrLabel") .
' : ') .
'<input type="text" class="'.$morecss.
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . ($placeholder ?
' placeholder="' . $placeholder .
'"' :
'') .
'>';
4452 $s .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT .
'/product/ajax/products.php', $urloption,
getDolGlobalInt(
'PRODUIT_USE_SEARCH_TO_SELECT'), 0, $ajaxoptions);
4454 $s = $this->
select_produits_fournisseurs_list($socid, $selected, $htmlname, $filtertype, $notused,
'', $status, 0, 0, $alsoproductwithnosupplierprice, $morecss,
getDolGlobalInt(
'SUPPLIER_SHOW_STOCK_IN_PRODUCTS_COMBO'), $placeholder);
4484 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 =
'')
4487 global $langs,
$conf, $user;
4488 global $hookmanager;
4491 $outarray = array();
4495 $langs->load(
'stocks');
4498 $langs->load(
'other');
4501 $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,";
4502 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice, pfp.barcode";
4503 $sql .=
", pfp.multicurrency_code, pfp.multicurrency_unitprice";
4504 $sql .=
", pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.default_vat_code, pfp.fk_soc, s.nom as name";
4505 $sql .=
", pfp.supplier_reputation";
4508 $sql .=
", pfp.desc_fourn as description";
4510 $sql .=
", p.description";
4514 $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";
4519 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListSelect', $parameters);
4520 $sql .= $hookmanager->resPrint;
4522 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
4526 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListFrom', $parameters);
4527 $sql .= $hookmanager->resPrint;
4529 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN (" .
getEntity(
'product') .
") )";
4531 $sql .=
" AND pfp.fk_soc = " . ((int) $socid);
4533 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
4536 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
4538 $sql .=
" WHERE p.entity IN (" .
getEntity(
'product') .
")";
4539 if ($statut != -1) {
4540 $sql .=
" AND p.tobuy = " . ((int) $statut);
4542 if (strval($filtertype) !=
'') {
4543 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
4547 $parameters = array();
4548 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListWhere', $parameters);
4549 $sql .= $hookmanager->resPrint;
4551 if ($filterkey !=
'') {
4555 $search_crit = explode(
' ', $filterkey);
4557 if (count($search_crit) > 1) {
4560 foreach ($search_crit as $crit) {
4564 $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) .
"%'";
4566 $sql .=
" OR pfp.desc_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
4571 if (count($search_crit) > 1) {
4575 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
4576 $sql .=
" OR pfp.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
4580 $sql .=
" ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC";
4581 $sql .= $this->db->plimit($limit, 0);
4585 dol_syslog(get_class($this) .
"::select_produits_fournisseurs_list", LOG_DEBUG);
4586 $result = $this->db->query($sql);
4588 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4589 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
4591 $num = $this->db->num_rows($result);
4594 $out .=
'<select class="flat ' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'">';
4596 $out .=
'<option value="-1" selected>' . ($placeholder ? $placeholder :
' ') .
'</option>';
4598 $out .=
'<option value="-1">' . ($placeholder ? $placeholder :
' ') .
'</option>';
4603 $objp = $this->db->fetch_object($result);
4605 if (is_null($objp->idprodfournprice)) {
4607 $objp->tva_tx = $objp->tva_tx_sale;
4608 $objp->default_vat_code = $objp->default_vat_code_sale;
4611 $outkey = $objp->idprodfournprice;
4612 if (!$outkey && $alsoproductwithnosupplierprice) {
4613 $outkey =
'idprod_' . $objp->rowid;
4616 $outref = $objp->ref;
4617 $outbarcode = $objp->barcode;
4620 $outtype = $objp->fk_product_type;
4627 if (!empty($objp->unit_short)) {
4628 $outvalUnits .=
' - ' . $objp->unit_short;
4630 if (!empty($objp->weight) && $objp->weight_units !==
null) {
4632 $outvalUnits .=
' - ' . $unitToShow;
4634 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
4635 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
4636 $outvalUnits .=
' - ' . $unitToShow;
4638 if (!empty($objp->surface) && $objp->surface_units !==
null) {
4640 $outvalUnits .=
' - ' . $unitToShow;
4642 if (!empty($objp->volume) && $objp->volume_units !==
null) {
4644 $outvalUnits .=
' - ' . $unitToShow;
4646 if ($outdurationvalue && $outdurationunit) {
4648 'h' => $langs->trans(
'Hour'),
4649 'd' => $langs->trans(
'Day'),
4650 'w' => $langs->trans(
'Week'),
4651 'm' => $langs->trans(
'Month'),
4652 'y' => $langs->trans(
'Year')
4654 if (isset($da[$outdurationunit])) {
4655 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
4660 $objRef = $objp->ref;
4661 if ($filterkey && $filterkey !=
'') {
4662 $objRef = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRef, 1);
4664 $objRefFourn = $objp->ref_fourn;
4665 if ($filterkey && $filterkey !=
'') {
4666 $objRefFourn = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRefFourn, 1);
4668 $label = $objp->label;
4669 if ($filterkey && $filterkey !=
'') {
4670 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
4673 switch ($objp->fk_product_type) {
4685 if (empty($picto)) {
4688 $optlabel =
img_object(
'', $picto,
'class="paddingright classfortooltip"', 0, 0, 1);
4691 $optlabel .= $objp->ref;
4692 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
4693 $optlabel .=
' <span class="opacitymedium">(' . $objp->ref_fourn .
')</span>';
4695 if (
isModEnabled(
'barcode') && !empty($objp->barcode)) {
4696 $optlabel .=
' (' . $outbarcode .
')';
4698 $optlabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
4700 $outvallabel = $objRef;
4701 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
4702 $outvallabel .=
' (' . $objRefFourn .
')';
4704 if (
isModEnabled(
'barcode') && !empty($objp->barcode)) {
4705 $outvallabel .=
' (' . $outbarcode .
')';
4707 $outvallabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
4709 $outsearchlabel = implode(
' ', array_filter(array(
4710 (
string) $objp->ref,
4711 (
string) $objp->ref_fourn,
4712 (
string) $objp->barcode,
4713 (
string) $objp->label,
4715 ), function (
string $value):
bool {
4716 return $value !==
'';
4720 $optlabel .= $outvalUnits;
4721 $outvallabel .= $outvalUnits;
4723 if (!empty($objp->idprodfournprice)) {
4724 $outqty = $objp->quantity;
4725 $outdiscount = $objp->remise_percent;
4726 if (
isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
4728 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
4729 $prod_supplier->id = $objp->fk_product;
4730 $prod_supplier->fourn_qty = $objp->quantity;
4731 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
4732 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
4734 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4736 $price_result = $priceparser->parseProductSupplier($prod_supplier);
4737 if ($price_result >= 0) {
4738 $objp->fprice = $price_result;
4739 if ($objp->quantity >= 1) {
4740 $objp->unitprice = $objp->fprice / $objp->quantity;
4744 if ($objp->quantity == 1) {
4745 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
4746 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1,
$conf->currency) .
"/";
4747 $optlabel .= $langs->trans(
"Unit");
4748 $outvallabel .= $langs->transnoentities(
"Unit");
4750 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
4751 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
4752 $optlabel .=
' ' . $langs->trans(
"Units");
4753 $outvallabel .=
' ' . $langs->transnoentities(
"Units");
4756 if ($objp->quantity != 1) {
4757 $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") .
")";
4758 $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") .
")";
4760 if ($objp->remise_percent >= 1) {
4761 $optlabel .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4762 $outvallabel .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4764 if ($objp->duration) {
4765 $optlabel .=
" - " . $objp->duration;
4766 $outvallabel .=
" - " . $objp->duration;
4769 $optlabel .=
" - " .
dol_trunc($objp->name, 8);
4770 $outvallabel .=
" - " .
dol_trunc($objp->name, 8);
4772 if ($objp->supplier_reputation) {
4774 $reputations = array(
'' => $langs->trans(
'Standard'),
'FAVORITE' => $langs->trans(
'Favorite'),
'NOTTHGOOD' => $langs->trans(
'NotTheGoodQualitySupplier'),
'DONOTORDER' => $langs->trans(
'DoNotOrderThisProductToThisSupplier'));
4776 $optlabel .=
" - " . $reputations[$objp->supplier_reputation];
4777 $outvallabel .=
" - " . $reputations[$objp->supplier_reputation];
4780 $optlabel .=
" - <span class='opacitymedium'>" . $langs->trans(
"NoPriceDefinedForThisSupplier") .
'</span>';
4781 $outvallabel .=
' - ' . $langs->transnoentities(
"NoPriceDefinedForThisSupplier");
4785 $novirtualstock = ($showstockinlist == 2);
4787 if ($user->hasRight(
'stock',
'lire')) {
4788 $outvallabel .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
4790 if ($objp->stock > 0) {
4791 $optlabel .=
' - <span class="product_line_stock_ok">';
4792 } elseif ($objp->stock <= 0) {
4793 $optlabel .=
' - <span class="product_line_stock_too_low">';
4795 $optlabel .= $langs->transnoentities(
"Stock") .
':' .
price(
price2num($objp->stock,
'MS'));
4796 $optlabel .=
'</span>';
4797 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
4798 $langs->load(
"stocks");
4800 $tmpproduct =
new Product($this->db);
4801 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
4802 $tmpproduct->load_virtual_stock();
4803 $virtualstock = $tmpproduct->stock_theorique;
4805 $outvallabel .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
4807 $optlabel .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
4808 if ($virtualstock > 0) {
4809 $optlabel .=
'<span class="product_line_stock_ok">';
4810 } elseif ($virtualstock <= 0) {
4811 $optlabel .=
'<span class="product_line_stock_too_low">';
4813 $optlabel .= $virtualstock;
4814 $optlabel .=
'</span>';
4821 $optstart =
'<option value="' . $outkey .
'"';
4822 if ($selected && preg_match(
'/^idprod_/', (
string) $selected) && (
string) $selected ==
'idprod_'.$objp->rowid) {
4823 $optstart .=
' selected';
4824 } elseif ($selected && (
string) $selected == (
string) $objp->idprodfournprice) {
4825 $optstart .=
' selected';
4828 if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) {
4829 $optstart .=
' disabled';
4832 if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) {
4841 $optstart .=
' data-default-vat-code="' .
dol_escape_htmltag($objp->default_vat_code) .
'"';
4844 $optstart .=
' data-multicurrency-code="' .
dol_escape_htmltag($objp->multicurrency_code) .
'"';
4848 $optstart .=
' data-description="' .
dol_escape_htmltag($objp->description, 0, 1) .
'"';
4852 $outarrayentry = array(
4855 'label' => $outvallabel,
4856 'labelhtml' => $optlabel,
4858 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4859 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4860 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4861 'tva_tx_formated' =>
price($objp->tva_tx, 0, $langs, 1, -1, 2),
4863 'default_vat_code' => $objp->default_vat_code,
4864 'supplier_ref' => $objp->ref_fourn,
4865 'discount' => $outdiscount,
4867 'duration_value' => $outdurationvalue,
4868 'duration_unit' => $outdurationunit,
4869 'disabled' => empty($objp->idprodfournprice),
4870 'description' => $objp->description
4873 $outarrayentry[
'multicurrency_code'] = $objp->multicurrency_code;
4874 $outarrayentry[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4876 $parameters = array(
4878 'optstart' => &$optstart,
4879 'optlabel' => &$optlabel,
4880 'outvallabel' => &$outvallabel,
4881 'outarrayentry' => &$outarrayentry,
4884 $reshook = $hookmanager->executeHooks(
'selectProduitsFournisseurListOption', $parameters, $this);
4890 $out .= $optstart .
' data-html="' .
dol_escape_htmltag($optlabel) .
'">' . $optlabel .
"</option>\n";
4891 $outarraypush = array(
4894 'label' => $outvallabel,
4895 'labelhtml' => $optlabel,
4897 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4898 'price_qty_ht_locale' =>
price($objp->fprice),
4899 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4900 'price_unit_ht_locale' =>
price($objp->unitprice),
4901 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4902 'tva_tx_formated' =>
price($objp->tva_tx),
4904 'default_vat_code' => $objp->default_vat_code,
4905 'supplier_ref' => $objp->ref_fourn,
4906 'discount' => $outdiscount,
4908 'duration_value' => $outdurationvalue,
4909 'duration_unit' => $outdurationunit,
4910 'disabled' => empty($objp->idprodfournprice),
4911 'description' => $objp->description
4914 $outarraypush[
'multicurrency_code'] = $objp->multicurrency_code;
4915 $outarraypush[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4917 array_push($outarray, $outarraypush);
4930 $out .=
'</select>';
4932 $this->db->free($result);
4934 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
4940 if (empty($outputmode)) {
4959 global $langs,
$conf;
4961 $langs->load(
'stocks');
4963 $sql =
"SELECT p.rowid, p.ref, p.label, p.price, p.duration, pfp.fk_soc,";
4964 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.remise_percent, pfp.quantity, pfp.unitprice,";
4965 $sql .=
" pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name";
4966 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
4967 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
4968 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
4969 $sql .=
" WHERE pfp.entity IN (" .
getEntity(
'productsupplierprice') .
")";
4970 $sql .=
" AND p.tobuy = 1";
4971 $sql .=
" AND s.fournisseur = 1";
4972 $sql .=
" AND p.rowid = " . ((int) $productid);
4974 $sql .=
" ORDER BY s.nom, pfp.ref_fourn DESC";
4976 $sql .=
" ORDER BY pfp.unitprice - pfp.unitprice * pfp.remise_percent / 100 ASC";
4979 dol_syslog(get_class($this) .
"::select_product_fourn_price", LOG_DEBUG);
4980 $result = $this->db->query($sql);
4983 $num = $this->db->num_rows($result);
4985 $form =
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
4988 $form .=
'<option value="0">-- ' . $langs->trans(
"NoSupplierPriceDefinedForThisProduct") .
' --</option>';
4990 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4991 $form .=
'<option value="0"> </option>';
4995 $objp = $this->db->fetch_object($result);
4997 $opt =
'<option value="' . $objp->idprodfournprice .
'"';
4999 if ($num == 1 || ($selected_supplier > 0 && $objp->fk_soc == $selected_supplier) || ($i == 0 &&
getDolGlobalString(
'PRODUCT_BEST_SUPPLIER_PRICE_PRESELECTED'))) {
5000 $opt .=
' selected';
5002 $opt .=
'>' . $objp->name .
' - ' . $objp->ref_fourn .
' - ';
5004 if (
isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
5006 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
5007 $prod_supplier->id = $productid;
5008 $prod_supplier->fourn_qty = $objp->quantity;
5009 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
5010 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
5012 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
5014 $price_result = $priceparser->parseProductSupplier($prod_supplier);
5015 if ($price_result >= 0) {
5016 $objp->fprice = $price_result;
5017 if ($objp->quantity >= 1) {
5018 $objp->unitprice = $objp->fprice / $objp->quantity;
5022 if ($objp->quantity == 1) {
5023 $opt .=
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
5026 $opt .= $objp->quantity .
' ';
5028 if ($objp->quantity == 1) {
5029 $opt .= $langs->trans(
"Unit");
5031 $opt .= $langs->trans(
"Units");
5033 if ($objp->quantity > 1) {
5035 $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");
5037 if ($objp->duration) {
5038 $opt .=
" - " . $objp->duration;
5040 $opt .=
"</option>\n";
5047 $form .=
'</select>';
5048 $this->db->free($result);
5066 global $langs, $hookmanager;
5068 $num = count($this->cache_conditions_paiements);
5075 $this->cache_conditions_paiements = array();
5077 $sql =
"SELECT rowid, code, libelle as label, deposit_percent, entity";
5078 $sql .=
" FROM " . $this->db->prefix() .
'c_payment_term';
5079 $sql .=
" WHERE entity IN (" .
getEntity(
'c_payment_term') .
")";
5080 $sql .=
" AND active > 0";
5081 $sql .=
" ORDER BY sortorder";
5083 $resql = $this->db->query($sql);
5085 $num = $this->db->num_rows($resql);
5088 $obj = $this->db->fetch_object($resql);
5091 $label = ($langs->trans(
"PaymentConditionShort" . $obj->code) !=
"PaymentConditionShort" . $obj->code ? $langs->trans(
"PaymentConditionShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
5093 $this->cache_conditions_paiements[$obj->rowid][
'code'] = (
string) $obj->code;
5094 $this->cache_conditions_paiements[$obj->rowid][
'label'] = (
string) $label;
5095 $this->cache_conditions_paiements[$obj->rowid][
'deposit_percent'] = (
string) $obj->deposit_percent;
5096 $this->cache_conditions_paiements[$obj->rowid][
'entity'] = (int) $obj->entity;
5101 $parameters = array(
'context' =>
'paymentterm');
5102 $reshook = $hookmanager->executeHooks(
'loadDictionaryCache', $parameters, $this);
5103 if (empty($reshook)) {
5104 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
5105 $this->cache_conditions_paiements = array_merge($this->cache_conditions_paiements, $hookmanager->resArray);
5108 $this->cache_conditions_paiements = $hookmanager->resArray;
5132 $this->cache_rule_for_lines_dates = $factureRec->fields[
'rule_for_lines_dates'][
'arrayofkeyval'];
5134 if (empty($this->cache_rule_for_lines_dates)) {
5153 $num = count($this->cache_availability);
5160 $this->cache_availability = array();
5162 $langs->load(
'propal');
5164 $sql =
"SELECT rowid, code, label, position";
5165 $sql .=
" FROM " . $this->db->prefix() .
'c_availability';
5166 $sql .=
" WHERE active > 0";
5168 $resql = $this->db->query($sql);
5170 $num = $this->db->num_rows($resql);
5173 $obj = $this->db->fetch_object($resql);
5176 $label = ($langs->trans(
"AvailabilityType" . $obj->code) !=
"AvailabilityType" . $obj->code ? $langs->trans(
"AvailabilityType" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
5177 $this->cache_availability[$obj->rowid][
'code'] = (
string) $obj->code;
5178 $this->cache_availability[$obj->rowid][
'label'] = (
string) $label;
5179 $this->cache_availability[$obj->rowid][
'position'] = (int) $obj->position;
5184 $this->cache_availability =
dol_sort_array($this->cache_availability,
'position',
'asc', 0, 0, 1);
5204 public function selectAvailabilityDelay($selected =
'', $htmlname =
'availid', $filtertype =
'', $addempty = 0, $morecss =
'', $noouput = 0)
5206 global $langs, $user;
5210 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
5212 $out =
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
5214 $out .=
'<option value="-1">'.(is_numeric($addempty) ?
' ' : $langs->trans($addempty)).
'</option>';
5216 foreach ($this->cache_availability as
$id => $arrayavailability) {
5217 if ($selected ==
$id) {
5218 $out .=
'<option value="' .
$id .
'" selected>';
5220 $out .=
'<option value="' .
$id .
'">';
5223 $out .=
'</option>';
5225 $out .=
'</select>';
5227 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5244 public function loadCacheInputReason()
5248 $num = count($this->cache_demand_reason);
5253 $sql =
"SELECT rowid, code, label";
5254 $sql .=
" FROM " . $this->db->prefix() .
'c_input_reason';
5255 $sql .=
" WHERE active > 0";
5257 $resql = $this->db->query($sql);
5259 $num = $this->db->num_rows($resql);
5262 $tmparray = array();
5264 $obj = $this->db->fetch_object($resql);
5267 $label = ($obj->label !=
'-' ? (
string) $obj->label :
'');
5268 if ($langs->trans(
"DemandReasonType" . $obj->code) !=
"DemandReasonType" . $obj->code) {
5269 $label = $langs->trans(
"DemandReasonType" . $obj->code);
5271 if ($langs->trans($obj->code) != $obj->code) {
5272 $label = $langs->trans($obj->code);
5275 $tmparray[(int) $obj->rowid]
5277 'id' => (
int) $obj->rowid,
5278 'code' => (
string) $obj->code,
5284 $this->cache_demand_reason =
dol_sort_array($tmparray,
'label',
'asc', 0, 0, 1);
5306 public function selectInputReason($selected =
'', $htmlname =
'demandreasonid', $exclude =
'', $addempty = 0, $morecss =
'', $notooltip = 0)
5308 global $langs, $user;
5310 $this->loadCacheInputReason();
5312 print
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
5314 print
'<option value="0"' . (empty($selected) ?
' selected' :
'') .
'> </option>';
5316 foreach ($this->cache_demand_reason as
$id => $arraydemandreason) {
5317 if ($arraydemandreason[
'code'] == $exclude) {
5321 if ($selected && ($selected == $arraydemandreason[
'id'] || $selected == $arraydemandreason[
'code'])) {
5322 print
'<option value="' . $arraydemandreason[
'id'] .
'" selected>';
5324 print
'<option value="' . $arraydemandreason[
'id'] .
'">';
5326 $label = $arraydemandreason[
'label'];
5327 print $langs->trans($label);
5331 if ($user->admin && empty($notooltip)) {
5332 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5347 global $langs, $hookmanager;
5349 $num = count($this->cache_types_paiements);
5356 $this->cache_types_paiements = array();
5358 $sql =
"SELECT id, code, libelle as label, type, entity, active";
5359 $sql .=
" FROM " . $this->db->prefix() .
"c_paiement";
5360 $sql .=
" WHERE entity IN (" .
getEntity(
'c_paiement') .
")";
5362 $resql = $this->db->query($sql);
5364 $num = $this->db->num_rows($resql);
5367 $obj = $this->db->fetch_object($resql);
5370 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) !=
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
5371 $this->cache_types_paiements[(int) $obj->id][
'id'] = (
int) $obj->id;
5372 $this->cache_types_paiements[(int) $obj->id][
'code'] = (
string) $obj->code;
5373 $this->cache_types_paiements[(int) $obj->id][
'label'] = (
string) $label;
5374 $this->cache_types_paiements[(int) $obj->id][
'type'] = (
int) $obj->type;
5375 $this->cache_types_paiements[(int) $obj->id][
'entity'] = (
int) $obj->entity;
5376 $this->cache_types_paiements[(int) $obj->id][
'active'] = (
int) $obj->active;
5380 $parameters = array(
'context' =>
'paymenttype');
5381 $reshook = $hookmanager->executeHooks(
'loadDictionaryCache', $parameters, $this);
5382 if (empty($reshook)) {
5383 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
5384 $this->cache_types_paiements = array_merge($this->cache_types_paiements, $hookmanager->resArray);
5387 $this->cache_types_paiements = $hookmanager->resArray;
5390 $this->cache_types_paiements =
dol_sort_array($this->cache_types_paiements,
'label',
'asc', 0, 0, 1);
5420 public function select_conditions_paiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1, $noprint = 0)
5424 if (empty($noprint)) {
5448 public function getSelectConditionsPaiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1)
5450 global $langs, $user;
5453 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
5458 if (empty($selected) && strpos($htmlname,
'search_') !== 0 &&
getDolGlobalInt(
'MAIN_DEFAULT_PAYMENT_TERM_ID')) {
5459 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TERM_ID", LOG_NOTICE);
5463 $out .=
'<select id="' . $htmlname .
'" class="flat selectpaymentterms' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
5465 $out .=
'<option value="0"> </option>';
5468 $selectedDepositPercent =
null;
5470 foreach ($this->cache_conditions_paiements as
$id => $arrayconditions) {
5471 if ($filtertype <= 0 && !empty($arrayconditions[
'deposit_percent'])) {
5475 if ($selected ==
$id) {
5476 $selectedDepositPercent = $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'];
5477 $out .=
'<option value="' .
$id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'" selected>';
5479 $out .=
'<option value="' .
$id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'">';
5481 $label = $arrayconditions[
'label'];
5483 if (!empty($arrayconditions[
'deposit_percent'])) {
5484 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'], $label);
5488 $out .=
'</option>';
5490 $out .=
'</select>';
5491 if ($user->admin && empty($noinfoadmin)) {
5492 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5496 if ($deposit_percent >= 0) {
5497 $out .=
' <span id="' . $htmlname .
'_deposit_percent_container"' . (empty($selectedDepositPercent) ?
' style="display: none"' :
'') .
'>';
5498 $out .= $langs->trans(
'DepositPercent') .
' : ';
5499 $out .=
'<input id="' . $htmlname .
'_deposit_percent" name="' . $htmlname .
'_deposit_percent" class="maxwidth50" value="' . $deposit_percent .
'" />';
5502 <script nonce="' .
getNonce() .
'">
5503 $(document).ready(function () {
5504 $("#' . $htmlname .
'").change(function () {
5505 let $selected = $(this).find("option:selected");
5506 let depositPercent = $selected.attr("data-deposit_percent");
5508 if (depositPercent.length > 0) {
5509 $("#' . $htmlname .
'_deposit_percent_container").show().find("#' . $htmlname .
'_deposit_percent").val(depositPercent);
5511 $("#' . $htmlname .
'_deposit_percent_container").hide();
5540 $out .=
'<select id="' . $htmlname .
'" class="flat selectbillingterm" name="' . $htmlname .
'">';
5542 $out .=
'<option value="-1"> </option>';
5546 foreach ($this->cache_rule_for_lines_dates as $rule_for_lines_dates_key => $rule_for_lines_dates_name) {
5547 if ($selected == $rule_for_lines_dates_key) {
5548 $out .=
'<option value="' . $rule_for_lines_dates_key .
'" selected>';
5550 $out .=
'<option value="' . $rule_for_lines_dates_key .
'">';
5553 $out .= $langs->trans($rule_for_lines_dates_name);
5554 $out .=
'</option>';
5556 $out .=
'</select>';
5582 public function select_types_paiements($selected =
'', $htmlname =
'paiementtype', $filtertype =
'', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'', $nooutput = 0)
5585 global $langs, $user;
5589 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $filtertype .
", " . $format, LOG_DEBUG);
5591 $filterarray = array();
5592 if ($filtertype ==
'CRDT') {
5593 $filterarray = array(0, 2, 3);
5594 } elseif ($filtertype ==
'DBIT') {
5595 $filterarray = array(1, 2, 3);
5596 } elseif ($filtertype !=
'' && $filtertype !=
'-1') {
5597 $filterarray = explode(
',', $filtertype);
5603 if (empty($selected) && strpos($htmlname,
'search_') !== 0 &&
getDolGlobalString(
'MAIN_DEFAULT_PAYMENT_TYPE_ID')) {
5604 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TYPE_ID", LOG_NOTICE);
5608 $out .=
'<select id="select' . $htmlname .
'" class="flat selectpaymenttypes' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
5610 $out .=
'<option value=""> </option>';
5612 foreach ($this->cache_types_paiements as
$id => $arraytypes) {
5614 if ($active >= 0 && $arraytypes[
'active'] != $active) {
5619 if (count($filterarray) && !in_array($arraytypes[
'type'], $filterarray)) {
5624 if ($empty && empty($arraytypes[
'code'])) {
5629 $out .=
'<option value="' .
$id .
'" data-code="'.$arraytypes[
'code'].
'"';
5630 } elseif ($format == 1) {
5631 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
5632 } elseif ($format == 2) {
5633 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
5634 } elseif ($format == 3) {
5635 $out .=
'<option value="' .
$id .
'"';
5638 if ($format == 1 || $format == 2) {
5639 if ($selected == $arraytypes[
'code']) {
5640 $out .=
' selected';
5643 if ($selected ==
$id) {
5644 $out .=
' selected';
5650 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
5651 } elseif ($format == 1) {
5652 $value = $arraytypes[
'code'];
5653 } elseif ($format == 2) {
5654 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
5655 } elseif ($format == 3) {
5656 $value = $arraytypes[
'code'];
5658 $out .= $value ? $value :
' ';
5659 $out .=
'</option>';
5661 $out .=
'</select>';
5662 if ($user->admin && !$noadmininfo) {
5663 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5667 if (empty($nooutput)) {
5687 $return =
'<select class="flat maxwidth100" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
5689 'HT' => $langs->trans(
"HT"),
5690 'TTC' => $langs->trans(
"TTC")
5692 foreach ($options as
$id => $value) {
5693 if ($selected ==
$id) {
5694 $return .=
'<option value="' .
$id .
'" selected>' . $value;
5696 $return .=
'<option value="' .
$id .
'">' . $value;
5698 $return .=
'</option>';
5700 $return .=
'</select>';
5720 $num = count($this->cache_transport_mode);
5727 $this->cache_transport_mode = array();
5729 $sql =
"SELECT rowid, code, label, active";
5730 $sql .=
" FROM " . $this->db->prefix() .
"c_transport_mode";
5731 $sql .=
" WHERE entity IN (" .
getEntity(
'c_transport_mode') .
")";
5733 $resql = $this->db->query($sql);
5735 $num = $this->db->num_rows($resql);
5738 $obj = $this->db->fetch_object($resql);
5741 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) !=
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
5742 $this->cache_transport_mode[(int) $obj->rowid]
5744 'rowid' => (
int) $obj->rowid,
5745 'code' => (
string) $obj->code,
5746 'label' => (
string) $label,
5747 'active' => (int) $obj->active,
5752 $this->cache_transport_mode =
dol_sort_array($this->cache_transport_mode,
'label',
'asc', 0, 0, 1);
5774 public function selectTransportMode($selected =
'', $htmlname =
'transportmode', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'')
5776 global $langs, $user;
5778 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $format, LOG_DEBUG);
5782 print
'<select id="select' . $htmlname .
'" class="flat selectmodetransport' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
5784 print
'<option value=""> </option>';
5786 foreach ($this->cache_transport_mode as
$id => $arraytypes) {
5788 if ($active >= 0 && $arraytypes[
'active'] != $active) {
5793 if ($empty && empty($arraytypes[
'code'])) {
5798 print
'<option value="' .
$id .
'"';
5799 } elseif ($format == 1) {
5800 print
'<option value="' . $arraytypes[
'code'] .
'"';
5801 } elseif ($format == 2) {
5802 print
'<option value="' . $arraytypes[
'code'] .
'"';
5803 } elseif ($format == 3) {
5804 print
'<option value="' .
$id .
'"';
5807 if (preg_match(
'/[a-z]/i', $selected) && $selected == $arraytypes[
'code']) {
5809 } elseif ($selected ==
$id) {
5815 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
5816 } elseif ($format == 1) {
5817 $value = $arraytypes[
'code'];
5818 } elseif ($format == 2) {
5819 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
5820 } elseif ($format == 3) {
5821 $value = $arraytypes[
'code'];
5823 print $value ? $value :
' ';
5830 if ($user->admin && !$noadmininfo) {
5831 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5847 public function selectShippingMethod($selected =
'', $htmlname =
'shipping_method_id', $filtre =
'', $useempty = 0, $moreattrib =
'', $noinfoadmin = 0, $morecss =
'')
5849 global $langs, $user;
5851 $langs->loadLangs(array(
"admin",
"sendings"));
5853 $sql =
"SELECT rowid, code, libelle as label";
5854 $sql .=
" FROM " . $this->db->prefix() .
"c_shipment_mode";
5855 $sql .=
" WHERE active > 0";
5859 $sql .=
" ORDER BY libelle ASC";
5861 dol_syslog(get_class($this) .
"::selectShippingMode", LOG_DEBUG);
5863 $result = $this->db->query($sql);
5865 $num = $this->db->num_rows($result);
5868 print
'<select id="select' . $htmlname .
'" class="flat selectshippingmethod' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5869 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5870 print
'<option value="-1"> </option>';
5873 $obj = $this->db->fetch_object($result);
5874 if ($selected == $obj->rowid) {
5875 print
'<option value="' . $obj->rowid .
'" selected>';
5877 print
'<option value="' . $obj->rowid .
'">';
5879 print ($langs->trans(
"SendingMethod" . strtoupper($obj->code)) !=
"SendingMethod" . strtoupper($obj->code)) ? $langs->trans(
"SendingMethod" . strtoupper($obj->code)) : $obj->label;
5884 if ($user->admin && empty($noinfoadmin)) {
5885 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5890 print $langs->trans(
"NoShippingMethodDefined");
5910 $langs->load(
"sendings");
5912 if ($htmlname !=
"none") {
5913 print
'<form method="POST" action="' . $page .
'">';
5914 print
'<input type="hidden" name="action" value="setshippingmethod">';
5915 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5917 print
'<input type="submit" class="button valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5921 $code = $langs->getLabelFromKey($this->db, $selected,
'c_shipment_mode',
'rowid',
'code');
5922 print $langs->trans(
"SendingMethod" . strtoupper($code));
5941 $langs->load(
'bills');
5945 $sql =
"SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc";
5946 $sql .=
' FROM ' . $this->db->prefix() .
'facture';
5947 $sql .=
' WHERE entity IN (' .
getEntity(
'invoice') .
')';
5948 $sql .=
' AND situation_counter >= 1';
5949 $sql .=
' AND fk_soc = ' . (int) $socid;
5950 $sql .=
' AND type <> 2';
5951 $sql .=
' ORDER by situation_cycle_ref, situation_counter desc';
5952 $resql = $this->db->query($sql);
5954 $nbSituationInvoiceForThirdparty = 0;
5956 if ($resql && $this->db->num_rows($resql) > 0) {
5959 while ($obj = $this->db->fetch_object($resql)) {
5961 if ($obj->situation_cycle_ref != $ref) {
5963 $ref = $obj->situation_cycle_ref;
5965 if ($obj->situation_final != 1) {
5967 if (substr($obj->ref, 1, 4) !=
'PROV') {
5968 $nbSituationInvoiceForThirdparty++;
5970 if ($selected == $obj->rowid) {
5971 $opt .=
'<option value="' . $obj->rowid .
'" selected>' . $obj->ref .
'</option>';
5973 $opt .=
'<option value="' . $obj->rowid .
'">' . $obj->ref .
'</option>';
5980 dol_syslog(
"Error sql=" . $sql .
", error=" . $this->error, LOG_ERR);
5983 if ($nbSituationInvoiceForThirdparty > 0) {
5984 $opt =
'<option class="minwidth100" value="" selected> </option>'.$opt;
5986 $opt =
'<option class="minwidth100" value="-1" selected>'.$langs->trans(
'NoSituations').
'</option>';
6001 public function selectUnits($selected =
'', $htmlname =
'units', $showempty = 0, $unit_type =
'')
6005 $langs->load(
'products');
6007 $return =
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'">';
6009 $sql =
"SELECT rowid, label, code FROM " . $this->db->prefix() .
"c_units";
6010 $sql .=
' WHERE active > 0';
6011 if (!empty($unit_type)) {
6012 $sql .=
" AND unit_type = '" . $this->db->escape($unit_type) .
"'";
6014 $sql .=
" ORDER BY sortorder";
6016 $resql = $this->db->query($sql);
6017 if ($resql && $this->db->num_rows($resql) > 0) {
6019 $return .=
'<option value="-1"></option>';
6022 while ($res = $this->db->fetch_object($resql)) {
6023 $unitLabel = $res->label;
6024 if (!empty($langs->tab_translate[
'unit' . $res->code])) {
6025 $unitLabel = $langs->trans(
'unit' . $res->code) != $res->label ? $langs->trans(
'unit' . $res->code) : $res->label;
6028 if ($selected == $res->rowid) {
6029 $return .=
'<option value="' . $res->rowid .
'" selected>' . $unitLabel .
'</option>';
6031 $return .=
'<option value="' . $res->rowid .
'">' . $unitLabel .
'</option>';
6034 $return .=
'</select>';
6058 public function select_comptes($selected =
'', $htmlname =
'accountid', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'', $showcurrency = 0, $morecss =
'', $nooutput = 0, $addentrynone = 0)
6065 $langs->loadLangs(array(
"admin",
"banks"));
6068 $sql =
"SELECT rowid, label, bank, clos as status, currency_code";
6069 $sql .=
" FROM " . $this->db->prefix() .
"bank_account";
6070 $sql .=
" WHERE entity IN (" .
getEntity(
'bank_account') .
")";
6072 $sql .=
" AND clos = " . (int) $status;
6077 $sql .=
" ORDER BY label";
6079 dol_syslog(get_class($this) .
"::select_comptes", LOG_DEBUG);
6080 $result = $this->db->query($sql);
6082 $num = $this->db->num_rows($result);
6085 $out .=
'<select id="select' . $htmlname .
'" class="flat selectbankaccount' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
6089 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoActiveBankAccountDefined") .
'</span>';
6091 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoBankAccountDefined") .
'</span>';
6094 if (!empty($useempty) && !is_numeric($useempty)) {
6095 $out .=
'<option value="-1">'.$langs->trans($useempty).
'</option>';
6096 } elseif ($useempty == 1 || ($useempty == 2 && $num > 1)) {
6097 $out .=
'<option value="-1"> </option>';
6102 $obj = $this->db->fetch_object($result);
6104 $labeltoshow = trim($obj->label);
6105 $labeltoshowhtml = trim($obj->label);
6106 if ($showcurrency) {
6107 $labeltoshow .=
' (' . $obj->currency_code .
')';
6108 $labeltoshowhtml .=
' <span class="opacitymedium">(' . $obj->currency_code .
')</span>';
6110 if ($status == 2 && $obj->status == 1) {
6111 $labeltoshow .=
' (' . $langs->trans(
"Closed") .
')';
6112 $labeltoshowhtml .=
' <span class="opacitymedium">(' . $langs->trans(
"Closed") .
')</span>';
6115 if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
6116 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml).
'" selected>';
6118 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml).
'">';
6120 $out .= $labeltoshow;
6121 $out .=
'</option>';
6125 if (!empty($addentrynone)) {
6126 $out .=
'<option value="-2"'.($selected == -2 ?
' selected="selected"' :
'').
' data-html="'.
dolPrintHTMLForAttribute(
'<span class="opacitymedium">'.$langs->trans(
"None").
'</span>').
'">'.$langs->trans(
"None").
'</option>';
6129 $out .=
"</select>";
6136 if (empty($nooutput)) {
6158 public function selectRib($selected =
'', $htmlname =
'ribcompanyid', $filtre =
'', $useempty = 0, $moreattrib =
'', $showibanbic = 0, $morecss =
'', $nooutput = 0)
6165 $langs->loadLangs(array(
"admin",
"banks"));
6168 $sql =
"SELECT rowid, label, bank, status, iban_prefix, bic, default_rib";
6169 $sql .=
" FROM " . $this->db->prefix() .
"societe_rib";
6170 $sql .=
" WHERE type = 'ban'";
6174 $sql .=
" ORDER BY label";
6175 dol_syslog(get_class($this) .
"::select_comptes", LOG_DEBUG);
6176 $result = $this->db->query($sql);
6178 $num = $this->db->num_rows($result);
6181 $out .=
'<select id="select' . $htmlname .
'" class="flat selectbankaccount' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
6184 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoBankAccountDefined") .
'</span>';
6186 if (!empty($useempty) && !is_numeric($useempty)) {
6187 $out .=
'<option value="-1">'.$langs->trans($useempty).
'</option>';
6188 } elseif ($useempty == 1 || ($useempty == 2 && $num > 1)) {
6189 $out .=
'<option value="-1"> </option>';
6194 $obj = $this->db->fetch_object($result);
6196 if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
6197 $out .=
'<option value="' . $obj->rowid .
'" data-iban-prefix="' . $iban .
' data-bic="' . $obj->bic .
'" selected>';
6199 $out .=
'<option value="' . $obj->rowid .
'" data-iban-prefix="' . $iban .
' data-bic="' . $obj->bic .
'">';
6201 $out .= trim($obj->label);
6203 $out .=
' (' . $iban .
'/' .$obj->bic.
')' . ($obj->default_rib ?
' ['.$langs->trans(
"ByDefault").
']' :
'');
6205 $out .=
'</option>';
6208 $out .=
"</select>";
6215 if (empty($nooutput)) {
6235 public function selectEstablishments($selected =
'', $htmlname =
'entity', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'')
6239 $langs->load(
"admin");
6242 $sql =
"SELECT rowid, name, fk_country, status, entity";
6243 $sql .=
" FROM " . $this->db->prefix() .
"establishment";
6244 $sql .=
" WHERE 1=1";
6246 $sql .=
" AND status = " . (int) $status;
6251 $sql .=
" ORDER BY name";
6253 dol_syslog(get_class($this) .
"::select_establishment", LOG_DEBUG);
6254 $result = $this->db->query($sql);
6256 $num = $this->db->num_rows($result);
6259 print
'<select id="select' . $htmlname .
'" class="flat selectestablishment" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
6260 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
6261 print
'<option value="-1"> </option>';
6265 $obj = $this->db->fetch_object($result);
6266 if ($selected == $obj->rowid) {
6267 print
'<option value="' . $obj->rowid .
'" selected>';
6269 print
'<option value="' . $obj->rowid .
'">';
6271 print trim($obj->name);
6272 if ($status == 2 && $obj->status == 1) {
6273 print
' (' . $langs->trans(
"Closed") .
')';
6281 print
'<span class="opacitymedium">' . $langs->trans(
"NoActiveEstablishmentDefined") .
'</span>';
6283 print
'<span class="opacitymedium">' . $langs->trans(
"NoEstablishmentFound") .
'</span>';
6306 if ($htmlname !=
"none") {
6307 print
'<form method="POST" action="' . $page .
'">';
6308 print
'<input type="hidden" name="action" value="setbankaccount">';
6309 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6310 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
6311 $nbaccountfound = $this->
select_comptes($selected, $htmlname, 0,
'', $addempty);
6312 if ($nbaccountfound > 0) {
6313 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6317 $langs->load(
'banks');
6320 require_once DOL_DOCUMENT_ROOT .
'/compta/bank/class/account.class.php';
6321 $bankstatic =
new Account($this->db);
6322 $result = $bankstatic->fetch((
int) $selected);
6324 print $bankstatic->getNomUrl(1);
6343 public function formRib($page, $selected =
'', $htmlname =
'ribcompanyid', $filtre =
'', $addempty = 0, $showibanbic = 0)
6346 if ($htmlname !=
"none") {
6347 print
'<form method="POST" action="' . $page .
'">';
6348 print
'<input type="hidden" name="action" value="setbankaccountcustomer">';
6349 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6350 $nbaccountfound = $this->
selectRib($selected, $htmlname, $filtre, $addempty,
'', $showibanbic);
6351 if ($nbaccountfound > 0) {
6352 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6356 $langs->load(
'banks');
6359 require_once DOL_DOCUMENT_ROOT .
'/societe/class/companybankaccount.class.php';
6361 $result = $bankstatic->fetch((
int) $selected);
6363 print $bankstatic->label;
6365 print
' (' . $bankstatic->iban .
'/' .$bankstatic->bic.
')';
6391 $arrayselected = array();
6393 $arrayselected =
GETPOST($htmlname,
'array:int');
6396 $cats =
$c->containing(
$object->id, $categtype);
6397 $arrayselected = array();
6398 foreach ($cats as $cat) {
6399 $arrayselected[] = $cat->id;
6403 $out .=
img_picto(
'',
'category',
'class="pictofixedwidth"');
6404 $out .= $this->
multiselectarray($htmlname, $cate_arbo, $arrayselected, 0, 0,
'minwidth100 widthcentpercentminusxx', 0, 0);
6408 $jsonclose =
'doJsCodeAfterPopupClose'.dol_sanitizeKeyCode($htmlname).
'()';
6409 $urltoopen =
'/categories/categorie_list.php?type='.urlencode($categtype).
'&nosearch=1';
6414 $out .=
'<!-- Add js code to open the popup for category/edit/add -->'.
"\n";
6415 $out .=
'<script>function doJsCodeAfterPopupClose'.dol_sanitizeKeyCode($htmlname).
'() {
6416 console.log("doJsCodeAfterPopupClose'.
dol_sanitizeKeyCode($htmlname).
' has been called, we refresh the combo content + refresh select2...");
6418 // Call an ajax to reload values and update the select
6421 url: \''.DOL_URL_ROOT.
'/core/ajax/fetchCategories.php\',
6423 action: \'getCategories\',
6428 success: function (data) {
6429 var $select = $(\'#'.dol_sanitizeKeyCode($htmlname).
'\');
6430 var selectedValues = $select.val();
6431 console.log(selectedValues);
6433 $.each(data,
function (index, item) {
6434 $select.append(\
'<option value="\' + item.id + \'" data-html="\' + item.htmlforattribute + \'">\' + item.htmlforoption + \'</option>\');
6436 $select.val(selectedValues);
6438 error: function (xhr, status, error) {
6439 console.log("Error when loading ajax page : " + error);
6443 // Refresh select2 to take account of new values (enough for small change)
6446 // Alternative if change in select is complex
6478 public function select_all_categories($type, $selected =
'', $htmlname =
"parent", $maxlength = 64, $fromid = 0, $outputmode = 0, $include = 0, $morecss =
'', $useempty = 1)
6483 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
6487 if (is_numeric($type)) {
6488 $type = array_search($type, $cat->MAP_ID);
6491 $cate_arbo = $cat->get_full_arbo($type, $fromid, $include);
6493 $outarray = array();
6494 $outarrayrichhtml = array();
6497 $output =
'<select class="flat minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
6499 if (is_array($cate_arbo)) {
6500 $num = count($cate_arbo);
6503 $langs->load(
"categories");
6504 $output .=
'<option value="-1" disabled>' . $langs->trans(
"NoCategoriesDefined") .
'</option>';
6506 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
6507 $output .=
'<option value="-1"> </option>';
6509 foreach ($cate_arbo as $key => $value) {
6510 if ($cate_arbo[$key][
'id'] == $selected || ($selected ===
'auto' && count($cate_arbo) == 1)) {
6516 $labeltoshow =
img_picto(
'',
'category',
'class="pictofixedwidth"'.(empty($cate_arbo[$key][
'color']) ?
'' :
' style="color: #' . $cate_arbo[$key][
'color'] .
'"'));
6517 $labeltoshow .=
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle');
6519 $outarray[$cate_arbo[$key][
'id']] = $cate_arbo[$key][
'fulllabel'];
6521 $outarrayrichhtml[$cate_arbo[$key][
'id']] = $labeltoshow;
6523 $output .=
'<option ' . $add .
'value="' . $cate_arbo[$key][
'id'] .
'"';
6532 $output .=
'</option>';
6534 $cate_arbo[$key][
'data-html'] = $labeltoshow;
6538 $output .=
'</select>';
6543 if ($outputmode == 2) {
6546 } elseif ($outputmode == 1) {
6548 } elseif ($outputmode == 3) {
6549 return $outarrayrichhtml;
6569 $html =
'<details class="dolibarr-help-block" style="margin-top:8px;">';
6570 $html .=
'<summary style="cursor:pointer; color:#0056b3; font-weight:normal; list-style:none; font-size:0.9em; display:flex; align-items:center;">';
6571 $html .=
'<span class="fa ' . $icon .
'" style="margin-right:6px;"></span>';
6572 $html .= $langs->trans(
"Help");
6573 $html .=
'</summary>';
6574 $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;">';
6577 $html .=
'</details>';
6602 public function form_confirm($page, $title, $question, $action, $formquestion = array(), $selectedchoice =
"", $useajax = 0, $height = 170, $width = 500)
6605 dol_syslog(__METHOD__ .
': using form_confirm is deprecated. Use formconfim instead.', LOG_WARNING);
6606 print $this->
formconfirm($page, $title, $question, $action, $formquestion, $selectedchoice, $useajax, $height, $width);
6638 public function formconfirm($page, $title, $question, $action, $formquestion =
'', $selectedchoice =
'', $useajax = 0, $height = 0, $width = 600, $disableformtag = 0, $labelbuttonyes =
'Yes', $labelbuttonno =
'No', $helpContent =
'')
6640 global $langs,
$conf;
6643 $formconfirm =
'<!-- formconfirm - before call, page=' .
dol_escape_htmltag($page) .
' -->';
6649 $newselectedchoice = empty($selectedchoice) ?
"no" : $selectedchoice;
6650 if (
$conf->browser->layout ==
'phone') {
6655 if (empty($height)) {
6657 if (is_array($formquestion)) {
6658 $height += (count($formquestion) * 40);
6665 if (is_array($formquestion) && !empty($formquestion)) {
6667 foreach ($formquestion as $key => $input) {
6668 if (is_array($input) && !empty($input)) {
6669 if ($input[
'type'] ==
'hidden') {
6670 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
6671 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
6679 $moreonecolumn =
'';
6680 $more .=
'<div class="tagtable paddingtopbottomonly centpercent noborderspacing">' .
"\n";
6681 foreach ($formquestion as $key => $input) {
6682 if (is_array($input) && !empty($input)) {
6683 $size = (!empty($input[
'size']) ?
' size="' . $input[
'size'] .
'"' :
'');
6684 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
6685 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
6687 if ($input[
'type'] ==
'text' || $input[
'type'] ==
'input') {
6688 $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";
6689 } elseif ($input[
'type'] ==
'password') {
6690 $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";
6691 } elseif ($input[
'type'] ==
'textarea') {
6692 $moreonecolumn .=
'<div class="margintoponly">';
6693 $moreonecolumn .= $input[
'label'] .
'<br>';
6695 $moreonecolumn .= $input[
'value'];
6696 $moreonecolumn .=
'</textarea>';
6697 $moreonecolumn .=
'</div>';
6698 } elseif (in_array($input[
'type'], [
'select',
'multiselect'])) {
6699 if (empty($morecss)) {
6700 $morecss =
'minwidth100';
6703 $show_empty = isset($input[
'select_show_empty']) ? $input[
'select_show_empty'] : 1;
6704 $key_in_label = isset($input[
'select_key_in_label']) ? $input[
'select_key_in_label'] : 0;
6705 $value_as_key = isset($input[
'select_value_as_key']) ? $input[
'select_value_as_key'] : 0;
6706 $translate = isset($input[
'select_translate']) ? $input[
'select_translate'] : 0;
6707 $maxlen = isset($input[
'select_maxlen']) ? $input[
'select_maxlen'] : 0;
6708 $disabled = isset($input[
'select_disabled']) ? $input[
'select_disabled'] : 0;
6709 $sort = isset($input[
'select_sort']) ? $input[
'select_sort'] :
'';
6711 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">';
6712 if (!empty($input[
'label'])) {
6713 $more .= $input[
'label'] .
'</div><div class="tagtd left">';
6715 if ($input[
'type'] ==
'select') {
6716 $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);
6718 $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);
6720 $more .=
'</div></div>' .
"\n";
6721 } elseif ($input[
'type'] ==
'checkbox') {
6722 $more .=
'<div class="tagtr">';
6723 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'"><label for="' .
dol_escape_htmltag($input[
'name']) .
'">' . $input[
'label'] .
'</label></div><div class="tagtd">';
6724 $more .=
'<input type="checkbox" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' .
dol_escape_htmltag($input[
'name']) .
'" name="' .
dol_escape_htmltag($input[
'name']) .
'"' . $moreattr;
6725 if (isset($input[
'value']) && !is_bool($input[
'value']) && $input[
'value'] !=
'false' && $input[
'value'] !=
'0' && $input[
'value'] !=
'') {
6726 $more .=
' checked';
6728 if (isset($input[
'value']) && is_bool($input[
'value']) && $input[
'value']) {
6729 $more .=
' checked';
6731 if (isset($input[
'disabled'])) {
6732 $more .=
' disabled';
6734 $more .=
' /></div>';
6735 $more .=
'</div>' .
"\n";
6736 } elseif ($input[
'type'] ==
'radio') {
6738 foreach ($input[
'values'] as $selkey => $selval) {
6739 $more .=
'<div class="tagtr">';
6740 if (isset($input[
'label'])) {
6742 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
' tdtop' : (
' tdtop ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
6744 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' "' . $input[
'tdclass'])) .
'"> </div>';
6747 $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;
6748 if (!empty($input[
'disabled'])) {
6749 $more .=
' disabled';
6751 if (isset($input[
'default']) && $input[
'default'] === $selkey) {
6752 $more .=
' checked="checked"';
6755 $more .=
'<label for="' .
dol_escape_htmltag($input[
'name'] . $selkey) .
'" class="valignmiddle">' . $selval .
'</label>';
6756 $more .=
'</div></div>' .
"\n";
6759 } elseif ($input[
'type'] ==
'date' || $input[
'type'] ==
'datetime') {
6760 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
6761 $more .=
'<div class="tagtd">';
6762 $addnowlink = (empty($input[
'datenow']) ? 0 : 1);
6764 if ($input[
'type'] ==
'datetime') {
6765 $h = isset($input[
'hours']) ? $input[
'hours'] : 1;
6766 $m = isset($input[
'minutes']) ? $input[
'minutes'] : 1;
6768 $more .= $this->
selectDate(isset($input[
'value']) ? $input[
'value'] : -1, $input[
'name'], $h, $m, 0,
'', 1, $addnowlink);
6769 $more .=
'</div></div>'.
"\n";
6770 $formquestion[] = array(
'name' => $input[
'name'].
'day');
6771 $formquestion[] = array(
'name' => $input[
'name'].
'month');
6772 $formquestion[] = array(
'name' => $input[
'name'].
'year');
6773 $formquestion[] = array(
'name' => $input[
'name'].
'hour');
6774 $formquestion[] = array(
'name' => $input[
'name'].
'min');
6775 } elseif ($input[
'type'] ==
'other') {
6776 $more .=
'<div class="tagtr"><div class="tagtd'.(empty($input[
'tdclass']) ?
'' : (
' '.$input[
'tdclass'])).
'">';
6777 if (!empty($input[
'label'])) {
6778 $more .= $input[
'label'] .
'</div><div class="tagtd">';
6780 if (!empty($input[
'value'])) {
6781 $more .= $input[
'value'];
6783 $more .=
'</div></div>' .
"\n";
6784 } elseif ($input[
'type'] ==
'onecolumn') {
6785 $moreonecolumn .=
'<div class="margintoponly">';
6786 $moreonecolumn .= $input[
'value'];
6787 $moreonecolumn .=
'</div>' .
"\n";
6788 } elseif ($input[
'type'] ==
'hidden') {
6790 } elseif ($input[
'type'] ==
'separator') {
6793 $more .=
'Error type ' . $input[
'type'] .
' for the confirm box is not a supported type';
6797 $more .=
'</div>' .
"\n";
6798 $more .= $moreonecolumn;
6804 if (!empty(
$conf->dol_use_jmobile)) {
6807 if (empty(
$conf->use_javascript_ajax)) {
6813 $dialogconfirm =
'dialog-confirm';
6815 if (!is_numeric($useajax)) {
6819 $dialogconfirm .=
'-' . $button;
6821 $pageyes = $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=yes';
6822 $pageno = ($useajax == 2 ? $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=no' :
'');
6825 if (is_array($formquestion)) {
6826 foreach ($formquestion as $key => $input) {
6829 if (is_array($input) && isset($input[
'name'])) {
6830 if (strpos($input[
'name'],
',') > 0) {
6831 $inputok = array_merge($inputok, explode(
',', $input[
'name']));
6833 array_push($inputok, $input[
'name']);
6838 if (is_array($input) && isset($input[
'inputko']) && $input[
'inputko'] == 1 && isset($input[
'name'])) {
6839 array_push($inputko, $input[
'name']);
6846 $formconfirm .=
'<div id="' . $dialogconfirm .
'" title="' .
dol_escape_htmltag($title) .
'" style="display: none;">';
6847 $formconfirm .=
'<div style="display: flex; flex-direction: column; height: 100%;">';
6848 if (is_array($formquestion) && array_key_exists(
'text', $formquestion) && !empty($formquestion[
'text'])) {
6849 $formconfirm .=
'<div class="confirmtext">' . $formquestion[
'text'] .
'</div>' .
"\n";
6851 if (!empty($more)) {
6852 $formconfirm .=
'<div class="confirmquestions">' . $more .
'</div>' .
"\n";
6855 if (!empty($helpContent)) {
6856 $formconfirm .=
'<div style="text-align:left; margin-top:12px; padding-top:8px; border-top:1px solid #eee; clear:both;">';
6858 $formconfirm .=
'</div>';
6860 if (!empty($question)) {
6861 $formconfirm .=
'<div class="confirmmessage" style="padding-top: 15px;">';
6862 $formconfirm .=
img_help(0,
'') .
' ' . $question;
6863 $formconfirm .=
'</div>';
6865 $formconfirm .=
'</div>';
6866 $formconfirm .=
'</div>' .
"\n";
6868 $formconfirm .=
"\n<!-- begin code of popup for formconfirm page=" . $page .
" -->\n";
6869 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
6870 $formconfirm .=
"/* Code for the jQuery('#dialogforpopup').dialog() */\n";
6871 $formconfirm .=
'jQuery(document).ready(function() {
6873 $( "#' . $dialogconfirm .
'" ).dialog({
6874 autoOpen: ' . ($autoOpen ?
"true" :
"false") .
',';
6875 if ($newselectedchoice ==
'no') {
6878 $(this).parent().find("button.ui-button:eq(2)").focus();
6883 if ($useajax == 1) {
6884 $jsforcursor =
'// The call to urljump can be slow, so we set the wait cursor' .
"\n";
6885 $jsforcursor .=
'jQuery("html,body,#id-container").addClass("cursorwait");' .
"\n";
6888 $postconfirmas =
'GET';
6895 closeOnEscape:
false,
6897 "' . dol_escape_js($langs->transnoentities($labelbuttonyes)) . '":
function() {
6898 var options =
"token=' . urlencode(newToken()) . '";
6899 var inputok =
' . json_encode($inputok) . ';
6900 var page = \
'' .
dol_escape_js(!empty($page) ? $page :
'') .
'\';
6901 var pageyes = \
'' .
dol_escape_js(!empty($pageyes) ? $pageyes :
'') .
'\';
6903 if (inputok.length > 0) {
6904 $.each(inputok,
function(i, inputname) {
6907 if ($(
"input[name=\'" + inputname +
"\']").attr(
"type") ==
"radio") {
6908 inputvalue = $(
"input[name=\'" + inputname +
"\']:checked").val();
6910 if ($(
"#" + inputname).attr(
"type") ==
"checkbox") { more =
":checked"; }
6911 inputvalue = $(
"#" + inputname + more).val();
6913 if (typeof inputvalue ==
"undefined") { inputvalue=
""; }
6914 console.log(
"formconfirm check inputname="+inputname+
" inputvalue="+inputvalue);
6915 options +=
"&" + inputname +
"=" + encodeURIComponent(inputvalue);
6918 var urljump = pageyes + (pageyes.indexOf(
"?") < 0 ?
"?" :
"&") + options;
6919 if (pageyes.length > 0) {
';
6920 if ($postconfirmas == 'GET
') {
6921 $formconfirm .= 'location.href = urljump;
';
6923 $formconfirm .= $jsforcursor;
6924 $formconfirm .= 'var post = $.post(
6927 function(data) { $(
"body").html(data); jQuery(
"html,body,#id-container").removeClass(
"cursorwait"); }
6931 console.log(
"after post ok");
6933 $(
this).dialog(
"close");
6935 "' . dol_escape_js($langs->transnoentities($labelbuttonno)) . '":
function() {
6936 var options =
"token=' . urlencode(newToken()) . '";
6937 var inputko =
' . json_encode($inputko) . ';
6938 var page =
"' . dol_escape_js(!empty($page) ? $page : '') . '";
6939 var pageno=
"' . dol_escape_js(!empty($pageno) ? $pageno : '') . '";
6940 if (inputko.length > 0) {
6941 $.each(inputko,
function(i, inputname) {
6943 if ($(
"#" + inputname).attr(
"type") ==
"checkbox") { more =
":checked"; }
6944 var inputvalue = $(
"#" + inputname + more).val();
6945 if (typeof inputvalue ==
"undefined") { inputvalue=
""; }
6946 options +=
"&" + inputname +
"=" + encodeURIComponent(inputvalue);
6949 var urljump=pageno + (pageno.indexOf(
"?") < 0 ?
"?" :
"&") + options;
6951 if (pageno.length > 0) {
';
6952 if ($postconfirmas == 'GET
') {
6953 $formconfirm .= 'location.href = urljump;
';
6955 $formconfirm .= $jsforcursor;
6956 $formconfirm .= 'var post = $.post(
6959 function(data) { $(
"body").html(data); jQuery(
"html,body,#id-container").removeClass(
"cursorwait"); }
6963 console.log(
"after post ko");
6965 $(
this).dialog(
"close");
6971 var
button =
"' . $button . '";
6973 $(
"#" +
button ).click(
function() {
6974 $(
"#' . $dialogconfirm . '").dialog(
"open");
6980 $formconfirm .= "<!-- end ajax formconfirm -->\n";
6982 $formconfirm .= "\n<!-- begin formconfirm page=" . dol_escape_htmltag($page) . " -->\n";
6984 if (empty($disableformtag)) {
6985 $formconfirm .= '<form method=
"POST" action=
"' . $page . '" class=
"notoptoleftnoright">
' . "\n";
6988 $formconfirm .= '<input
type=
"hidden" name=
"action" value=
"' . $action . '">
' . "\n";
6989 $formconfirm .= '<input
type=
"hidden" name=
"token" value=
"' . newToken() . '">
' . "\n";
6991 $formconfirm .= '<div
class=
"valid">
' . "\n";
6994 $formconfirm .= '<div
class=
"validtitre">
';
6995 $formconfirm .= img_picto('', 'pictoconfirm
') . ' ' . $title;
6996 $formconfirm .= '</div>
' . "\n";
6999 if (is_array($formquestion) && array_key_exists('text
', $formquestion) && !empty($formquestion['text
'])) {
7000 $formconfirm .= '<div
class=
"valid">
' . $formquestion['text
'] . '</div>
' . "\n";
7005 $formconfirm .= '<div>
' . "\n";
7006 $formconfirm .= $more;
7007 $formconfirm .= '</div>
' . "\n";
7010 // NEW: Help block row (between form fields and question)
7011 if (!empty($helpContent)) {
7012 $formconfirm .= '<div style=
"padding-top:8px; border-top:1px solid #888;">
';
7013 $formconfirm .= $this->getHelpBlock($helpContent);
7014 $formconfirm .= '</div>
' . "\n";
7017 // Let's add a row that acts as a spacer.
7018 $formconfirm .=
'<div style="padding-top: 20px;"></div>' .
"\n";
7021 $formconfirm .=
'<div class="inline-block">' . $question .
'</div>';
7023 $formconfirm .=
'<div class="inline-block">';
7024 $formconfirm .= $this->selectyesno(
"confirm", $newselectedchoice, 0,
false, 0, 0,
'marginleftonly marginrightonly', $labelbuttonyes, $labelbuttonno);
7025 $formconfirm .=
'<input class="button valignmiddle confirmvalidatebutton small" type="submit" value="' . $langs->trans(
"Validate") .
'">';
7026 $formconfirm .=
'</div>';
7028 $formconfirm .=
'</div>';
7030 if (empty($disableformtag)) {
7031 $formconfirm .=
"</form>\n";
7033 $formconfirm .=
'<br>';
7035 if (!empty(
$conf->use_javascript_ajax)) {
7036 $formconfirm .=
'<!-- code to disable button to avoid double clic -->';
7037 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
7039 $(document).ready(function () {
7040 $(".confirmvalidatebutton").on("click", function() {
7041 console.log("We click on button confirmvalidatebutton");
7042 $(this).attr("disabled", "disabled");
7043 setTimeout(\'$(".confirmvalidatebutton").removeAttr("disabled")\', 3000);
7044 //console.log($(this).closest("form"));
7045 $(this).closest("form").submit();
7049 $formconfirm .=
'</script>' .
"\n";
7052 $formconfirm .=
"<!-- end formconfirm -->\n";
7055 return $formconfirm;
7076 public function form_project($page, $socid, $selected =
'', $htmlname =
'projectid', $discard_closed = 0, $maxlength = 20, $forcefocus = 0, $nooutput = 0, $textifnoproject =
'', $morecss =
'', $option =
'')
7081 require_once DOL_DOCUMENT_ROOT .
'/core/lib/project.lib.php';
7082 require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formprojet.class.php';
7088 $langs->load(
"project");
7089 if ($htmlname !=
"none") {
7090 $out .=
'<form method="post" action="' . $page .
'">';
7091 $out .=
'<input type="hidden" name="action" value="classin">';
7092 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7093 $out .= $formproject->select_projects($socid, $selected, $htmlname, $maxlength, 0, 1, $discard_closed, $forcefocus, 0, 0,
'', 1, 0, $morecss);
7094 $out .=
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7097 $out .=
'<span class="project_head_block">';
7098 if ($selected instanceof
Project) {
7099 $out .= $selected->getNomUrl(0, $option, 1);
7100 } elseif (is_numeric($selected)) {
7101 $projet =
new Project($this->db);
7102 $projet->fetch((
int) $selected);
7103 $out .= $projet->getNomUrl(0, $option, 1);
7105 $out .=
'<span class="opacitymedium">' . $textifnoproject .
'</span>';
7110 if (empty($nooutput)) {
7134 public function form_conditions_reglement($page, $selected =
'', $htmlname =
'cond_reglement_id', $addempty = 0, $type =
'', $filtertype = -1, $deposit_percent = -1, $nooutput = 0)
7139 $selected = (int) $selected;
7143 if ($htmlname !=
"none") {
7144 $out .=
'<form method="POST" action="' . $page .
'">';
7145 $out .=
'<input type="hidden" name="action" value="setconditions">';
7146 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7148 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
7150 $out .= $this->getSelectConditionsPaiements($selected, $htmlname, $filtertype, $addempty, 0,
'', $deposit_percent);
7151 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7155 $this->load_cache_conditions_paiements();
7157 if (isset($this->cache_conditions_paiements[$selected])) {
7158 $label = $this->cache_conditions_paiements[$selected][
'label'];
7160 if (!empty($this->cache_conditions_paiements[$selected][
'deposit_percent'])) {
7161 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $this->cache_conditions_paiements[$selected][
'deposit_percent'], $label);
7166 $langs->load(
'errors');
7167 $out .= $langs->trans(
'ErrorNotInDictionaryPaymentConditions', $selected);
7174 if (empty($nooutput)) {
7200 if ($htmlname !=
'none') {
7201 $out .=
'<form method="POST" action="' . $page .
'">';
7202 $out .=
'<input type="hidden" name="action" value="setruleforlinesdates">';
7203 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7204 $out .= $this->getSelectRuleForLinesDates($selected, $htmlname, $addempty);
7205 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7208 if (isset($selected)) {
7209 $this->load_cache_rule_for_lines_dates();
7210 if (isset($this->cache_rule_for_lines_dates[$selected])) {
7211 $label = $this->cache_rule_for_lines_dates[$selected];
7212 $out .= $langs->trans($label);
7219 if (empty($nooutput)) {
7243 if ($htmlname !=
"none") {
7244 print
'<form method="post" action="' . $page .
'">';
7245 print
'<input type="hidden" name="action" value="setavailability">';
7246 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7247 print $this->selectAvailabilityDelay($selected, $htmlname,
'', $addempty,
'', 1);
7248 print
'<input type="submit" name="modify" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7249 print
'<input type="submit" name="cancel" class="button smallpaddingimp" value="' . $langs->trans(
"Cancel") .
'">';
7253 $this->load_cache_availability();
7255 if (isset($this->cache_availability[$selected])) {
7256 print $this->cache_availability[$selected][
'label'];
7277 public function formInputReason($page, $selected =
'', $htmlname =
'demandreason', $addempty = 0, $morecss =
'')
7280 if ($htmlname !=
"none") {
7281 print
'<form method="post" action="' . $page .
'">';
7282 print
'<input type="hidden" name="action" value="setdemandreason">';
7283 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7284 $this->selectInputReason($selected, $htmlname,
'-1', $addempty, $morecss);
7285 print
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7289 $this->loadCacheInputReason();
7290 foreach ($this->cache_demand_reason as $key => $val) {
7291 if ($val[
'id'] == $selected) {
7292 print $val[
'label'];
7317 public function form_date($page, $selected, $htmlname, $displayhour = 0, $displaymin = 0, $nooutput = 0, $type =
'')
7324 if ($htmlname !=
"none") {
7325 $ret .=
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
7326 $ret .=
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
7327 $ret .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7329 $ret .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
7331 $ret .=
'<table class="nobordernopadding">';
7333 $ret .= $this->selectDate($selected, $htmlname, $displayhour, $displaymin, 1,
'form' . $htmlname, 1, 0);
7335 $ret .=
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
7336 $ret .=
'</tr></table></form>';
7345 if (empty($nooutput)) {
7364 public function form_users($page, $selected =
'', $htmlname =
'userid', $exclude = array(), $include = array())
7369 if ($htmlname !=
"none") {
7370 print
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
7371 print
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
7372 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7373 print $this->select_dolusers($selected, $htmlname, 1, $exclude, 0, $include);
7374 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7378 require_once DOL_DOCUMENT_ROOT .
'/user/class/user.class.php';
7379 $theuser =
new User($this->db);
7380 $theuser->fetch((
int) $selected);
7381 print $theuser->getNomUrl(1);
7404 public function form_modes_reglement($page, $selected =
'', $htmlname =
'mode_reglement_id', $filtertype =
'', $active = 1, $addempty = 0, $type =
'', $nooutput = 0)
7410 if ($htmlname !=
"none") {
7411 $out .=
'<form method="POST" action="' . $page .
'">';
7412 $out .=
'<input type="hidden" name="action" value="setmode">';
7413 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7415 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
7417 $out .= $this->select_types_paiements($selected, $htmlname, $filtertype, 0, $addempty, 0, 0, $active,
'', 1);
7418 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7422 $this->load_cache_types_paiements();
7424 $out .= isset($this->cache_types_paiements[(
int) $selected][
'label']) ? $this->cache_types_paiements[(int) $selected][
'label'] :
'';
7451 if ($htmlname !=
"none") {
7452 print
'<form method="POST" action="' . $page .
'">';
7453 print
'<input type="hidden" name="action" value="settransportmode">';
7454 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7455 $this->selectTransportMode($selected, $htmlname, 0, $addempty, 0, 0, $active);
7456 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7460 $this->load_cache_transport_mode();
7461 print $this->cache_transport_mode[$selected][
'label'];
7482 if ($htmlname !=
"none") {
7483 print
'<form method="POST" action="' . $page .
'">';
7484 print
'<input type="hidden" name="action" value="setmulticurrencycode">';
7485 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7486 print $this->selectMultiCurrency($selected, $htmlname, 0);
7487 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7490 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
7491 print !empty($selected) ?
currency_name($selected, 1) :
' ';
7510 global $langs,
$conf;
7512 if ($htmlname !=
"none") {
7513 print
'<form method="POST" action="' . $page .
'">';
7514 print
'<input type="hidden" name="action" value="setmulticurrencyrate">';
7515 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7516 print
'<input type="text" class="maxwidth75" name="' . $htmlname .
'" value="' . (!empty($rate) ?
price(
price2num($rate,
'CU')) : 1) .
'" spellcheck="false" /> ';
7517 print
'<select name="calculation_mode" id="calculation_mode">';
7518 print
'<option value="1">Change ' . $langs->trans(
"PriceUHT") .
' of lines</option>';
7519 print
'<option value="2">Change ' . $langs->trans(
"PriceUHTCurrency") .
' of lines</option>';
7522 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7525 if (!empty($rate)) {
7526 print
price($rate, 1, $langs, 0, 0);
7527 if ($currency && $rate != 1) {
7534 print
' <span class="opacitymedium">(' .
price($rate_direct, 1, $langs, 0, 0) .
' ' .
$conf->currency .
' = 1 ' . $currency .
')</span>';
7536 print
' <span class="opacitymedium">(' .
price($rate, 1, $langs, 0, 0) .
' ' . $currency .
' = 1 ' .
$conf->currency .
')</span>';
7564 public function form_remise_dispo($page, $selected, $htmlname, $socid, $amount, $filter =
'', $maxvalue = 0, $more =
'', $hidelist = 0, $discount_type = 0, $filterabsolutediscount = 0, $filtercreditnote = 0)
7567 global
$conf, $langs;
7569 if ($htmlname !=
"none") {
7570 print
'<form method="post" action="' . $page .
'" class="inline-block">';
7571 print
'<input type="hidden" name="action" value="setabsolutediscount">';
7572 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7573 print
'<div class="inline-block">';
7574 if (!empty($discount_type)) {
7576 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL") {
7577 $translationKey =
'HasAbsoluteDiscountFromSupplier';
7579 $translationKey =
'HasCreditNoteFromSupplier';
7582 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
7583 $translationKey =
'HasAbsoluteDiscountFromSupplier';
7585 $translationKey =
'HasCreditNoteFromSupplier';
7590 if (!$filter || $filter ==
"fk_facture_source IS NULL") {
7591 $translationKey =
'CompanyHasAbsoluteDiscount';
7593 $translationKey =
'CompanyHasCreditNote';
7596 if (!$filter || $filter ==
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
7597 $translationKey =
'CompanyHasAbsoluteDiscount';
7599 $translationKey =
'CompanyHasCreditNote';
7603 print $langs->trans($translationKey,
price($amount, 0, $langs, 0, 0, -1,
$conf->currency));
7604 if (empty($hidelist)) {
7608 if (empty($hidelist)) {
7609 print
'<div class="inline-block" style="padding-right: 10px">';
7610 $newfilter =
'discount_type = ' . intval($discount_type);
7611 if (!empty($discount_type)) {
7612 $newfilter .=
' AND fk_invoice_supplier IS NULL AND fk_invoice_supplier_line IS NULL';
7614 $newfilter .=
' AND fk_facture IS NULL AND fk_facture_line IS NULL';
7617 $sanitizedfilter = $filter;
7618 $newfilter .=
' AND (' . $sanitizedfilter .
')';
7621 $nbqualifiedlines = $this->select_remises((
string) $selected, $htmlname, $newfilter, $socid, $maxvalue);
7622 if ($nbqualifiedlines > 0) {
7623 print
' <input type="submit" class="button smallpaddingimp" value="' .
dol_escape_htmltag($langs->trans(
"UseLine")) .
'"';
7624 if (!empty($discount_type) && $filter && $filter !=
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
7625 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
7627 if (empty($discount_type) && $filter && $filter !=
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
7628 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
7636 print
'<div class="inline-block">';
7662 public function form_contacts($page, $societe, $selected =
'', $htmlname =
'contactid')
7667 if ($htmlname !=
"none") {
7668 print
'<form method="post" action="' . $page .
'">';
7669 print
'<input type="hidden" name="action" value="set_contact">';
7670 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7671 print
'<table class="nobordernopadding">';
7673 print $this->selectcontacts($societe->id, $selected, $htmlname);
7676 $addcontact = (
getDolGlobalString(
'SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans(
"AddContact") : $langs->trans(
"AddContactAddress"));
7677 print
'<a href="' . DOL_URL_ROOT .
'/contact/card.php?socid=' . $societe->id .
'&action=create&backtoreferer=1">' . $addcontact .
'</a>';
7680 print
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
7681 print
'</tr></table></form>';
7684 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
7685 $contact =
new Contact($this->db);
7686 $contact->fetch((
int) $selected);
7687 print $contact->getFullName($langs);
7712 public function form_thirdparty($page, $selected =
'', $htmlname =
'socid', $filter =
'', $showempty = 0, $showtype = 0, $forcecombo = 0, $events = array(), $nooutput = 0, $excludeids = array(), $textifnothirdparty =
'')
7718 if ($htmlname !=
"none") {
7721 $out .=
'<form method="post" action="' . $page .
'">';
7722 $out .=
'<input type="hidden" name="action" value="set_thirdparty">';
7723 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7724 $out .= $this->select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, $limit,
'minwidth100',
'',
'', 1, array(),
false, $excludeids);
7725 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7729 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
7730 $soc =
new Societe($this->db);
7731 $soc->fetch((
int) $selected);
7732 $out .= $soc->getNomUrl(0,
'');
7734 $out .=
'<span class="opacitymedium">' . $textifnothirdparty .
'</span>';
7760 print $this->selectCurrency($selected, $htmlname);
7772 public function selectCurrency($selected =
'', $htmlname =
'currency_id', $mode = 0, $useempty =
'')
7774 global $langs, $user;
7776 $langs->loadCacheCurrencies(
'');
7780 if ($selected ==
'euro' || $selected ==
'euros') {
7784 $out .=
'<select class="flat maxwidth200onsmartphone minwidth300" name="' . $htmlname .
'" id="' . $htmlname .
'">';
7786 $out .=
'<option value="-1" selected></option>';
7788 foreach ($langs->cache_currencies as $code_iso => $currency) {
7789 $labeltoshow = $currency[
'label'];
7791 $labeltoshow .=
' <span class="opacitymedium">(' . $code_iso .
')</span>';
7792 } elseif ($mode == 2) {
7793 $labeltoshow .=
' <span class="opacitymedium">(' . $code_iso.
' - '.$langs->getCurrencySymbol($code_iso) .
')</span>';
7795 $labeltoshow .=
' <span class="opacitymedium">(' . $langs->getCurrencySymbol($code_iso) .
')</span>';
7798 if ($selected && $selected == $code_iso) {
7799 $out .=
'<option value="' . $code_iso .
'" selected data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
7801 $out .=
'<option value="' . $code_iso .
'" data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
7804 $out .=
'</option>';
7806 $out .=
'</select>';
7808 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
7812 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
7830 public function selectMultiCurrency($selected =
'', $htmlname =
'multicurrency_code', $useempty = 0, $filter =
'', $excludeConfCurrency =
false, $morecss =
'maxwidth200 widthcentpercentminusx')
7832 global
$conf, $langs;
7834 $langs->loadCacheCurrencies(
'');
7836 $TCurrency = array();
7838 $sql =
"SELECT code FROM " . $this->db->prefix() .
"multicurrency";
7839 $sql .=
" WHERE entity IN ('" .
getEntity(
'multicurrency') .
"')";
7843 $resql = $this->db->query($sql);
7845 while ($obj = $this->db->fetch_object($resql)) {
7846 $TCurrency[$obj->code] = $obj->code;
7851 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
7853 $out .=
'<option value=""> </option>';
7856 if (!in_array(
$conf->currency, $TCurrency) && !$excludeConfCurrency) {
7857 $TCurrency[
$conf->currency] =
$conf->currency;
7859 if (count($TCurrency) > 0) {
7860 foreach ($langs->cache_currencies as $code_iso => $currency) {
7861 if (isset($TCurrency[$code_iso])) {
7862 if (!empty($selected) && $selected == $code_iso) {
7863 $out .=
'<option value="' . $code_iso .
'" selected="selected">';
7865 $out .=
'<option value="' . $code_iso .
'">';
7868 $out .= $currency[
'label'];
7869 $out .=
' (' . $langs->getCurrencySymbol($code_iso) .
')';
7870 $out .=
'</option>';
7875 $out .=
'</select>';
7878 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
7895 global $langs, $user;
7897 $num = count($this->cache_vatrates);
7904 $sql =
"SELECT t.rowid, t.type_vat, t.code, t.taux, t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.recuperableonly, t.einvoice_vatex";
7905 $sql .=
" FROM ".$this->db->prefix().
"c_tva as t, ".$this->db->prefix().
"c_country as c";
7906 $sql .=
" WHERE t.fk_pays = c.rowid";
7907 $sql .=
" AND t.active > 0";
7908 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
7909 $sql .=
" AND c.code IN (" . $this->db->sanitize($country_code, 1) .
")";
7910 $sql .=
" ORDER BY t.code ASC, t.taux ASC, t.recuperableonly ASC";
7912 $resql = $this->db->query($sql);
7914 $num = $this->db->num_rows($resql);
7916 for ($i = 0; $i < $num; $i++) {
7917 $obj = $this->db->fetch_object($resql);
7919 $tmparray = array();
7920 $tmparray[
'rowid'] = (int) $obj->rowid;
7921 $tmparray[
'type_vat'] = ($obj->type_vat <= 0 ? 0 : $obj->type_vat);
7922 $tmparray[
'code'] = $obj->code;
7923 $tmparray[
'txtva'] = $obj->taux;
7924 $tmparray[
'nprtva'] = $obj->recuperableonly;
7925 $tmparray[
'localtax1'] = $obj->localtax1;
7926 $tmparray[
'localtax1_type'] = $obj->localtax1_type;
7927 $tmparray[
'localtax2'] = $obj->localtax2;
7928 $tmparray[
'localtax2_type'] = $obj->localtax1_type;
7929 $tmparray[
'einvoice_vatex'] = $obj->einvoice_vatex;
7931 $tmparray[
'label'] = $obj->taux .
'%' . ($obj->code ?
' (' . $obj->code .
')' :
'');
7932 $tmparray[
'labelallrates'] = $obj->taux .
'/' . ($obj->localtax1 ? $obj->localtax1 :
'0') .
'/' . ($obj->localtax2 ? $obj->localtax2 :
'0') . ($obj->code ?
' (' . $obj->code .
')' :
'');
7933 $positiverates =
'';
7935 $positiverates .= ($positiverates ?
'/' :
'') . $obj->taux;
7937 if ($obj->localtax1) {
7938 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax1;
7940 if ($obj->localtax2) {
7941 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax2;
7943 if (empty($positiverates)) {
7944 $positiverates =
'0';
7946 $tmparray[
'labelpositiverates'] = $positiverates . ($obj->code ?
' (' . $obj->code .
')' :
'');
7948 $this->cache_vatrates[$obj->rowid] = $tmparray;
7953 $this->error =
'<span class="error">';
7954 $this->error .= $langs->trans(
"ErrorNoVATRateDefinedForSellerCountry", $country_code);
7956 if (!empty($user) && $user->admin && preg_match(
'/\'(..)\'/', $country_code, $reg)) {
7957 $langs->load(
"errors");
7958 $new_country_code = $reg[1];
7959 $country_id =
dol_getIdFromCode($this->db, $new_country_code,
'c_country',
'code',
'rowid');
7960 $this->error .=
'<br>'.$langs->trans(
"ErrorFixThisHere", DOL_URL_ROOT.
'/admin/dict.php?id=10'.($country_id > 0 ?
'&countryidforinsert='.$country_id :
''));
7962 $this->error .=
'</span>';
7966 $this->error =
'<span class="error">' . $this->db->error() .
'</span>';
7995 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)
7998 global $langs,
$mysoc, $hookmanager;
8000 $langs->load(
'errors');
8004 $hookmanager->initHooks(array(
'commonobject'));
8005 $info_bits == 1 ? $is_npr = 1 : $is_npr = 0;
8006 $parameters = array(
8007 'htmlname' => $htmlname,
8008 'selectedrate' => $selectedrate,
8009 'seller' => $societe_vendeuse,
8010 'buyer' => $societe_acheteuse,
8011 'idprod' => $idprod,
8012 'is_npr' => $is_npr,
8014 'options_only' => $options_only,
8016 'type_vat' => $type_vat
8018 $reshook = $hookmanager->executeHooks(
'load_tva', $parameters);
8020 return $hookmanager->resPrint;
8021 } elseif ($reshook === 0) {
8022 $return .= $hookmanager->resPrint;
8026 $defaultnpr = ($info_bits & 0x01);
8027 $defaultnpr = (preg_match(
'/\*/', $selectedrate) ? 1 : $defaultnpr);
8028 $defaulttx = str_replace(
'*',
'', $selectedrate);
8031 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
8032 $defaultcode = $reg[1];
8033 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
8038 if (is_object($societe_vendeuse) && !$societe_vendeuse->country_code) {
8039 if ($societe_vendeuse->id ==
$mysoc->id) {
8040 $return .=
'<span class="error">' . $langs->trans(
"ErrorYourCountryIsNotDefined") .
'</span>';
8042 $return .=
'<span class="error">' . $langs->trans(
"ErrorSupplierCountryIsNotDefined") .
'</span>';
8059 $sellercountrycode = is_object($societe_vendeuse) ? $societe_vendeuse->country_code :
$mysoc->country_code;
8060 $sellercountryid = is_object($societe_vendeuse) ? $societe_vendeuse->country_id :
$mysoc->country_id;
8061 if ((
int) $sellercountryid > 0 && strlen((
string) $sellercountrycode) != 2) {
8062 $tmpcountrycode =
dol_getIdFromCode($this->db, (
string) $sellercountryid,
'c_country',
'rowid',
'code');
8063 if (!empty($tmpcountrycode) && !is_numeric($tmpcountrycode)) {
8064 $sellercountrycode = $tmpcountrycode;
8067 $code_country =
"'" . $sellercountrycode .
"'";
8070 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
8074 if (is_object($societe_vendeuse) && is_object($societe_acheteuse) &&
isInEEC($societe_vendeuse) &&
isInEEC($societe_acheteuse) && !$societe_acheteuse->isACompany()) {
8076 if (is_numeric($type)) {
8078 switch ($selectVatComboMode) {
8080 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
8083 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
8087 } elseif (!$idprod) {
8088 switch ($selectVatComboMode) {
8090 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
8093 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
8097 $prodstatic =
new Product($this->db);
8098 $prodstatic->fetch($idprod);
8100 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
8107 $this->load_cache_vatrates($code_country);
8110 $arrayofvatrates = array();
8111 foreach ($this->cache_vatrates as $cachevalue) {
8112 if (empty($cachevalue[
'type_vat']) || $cachevalue[
'type_vat'] == $type_vat) {
8113 $arrayofvatrates[] = $cachevalue;
8117 $num = count($arrayofvatrates);
8120 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
8122 $tmpthirdparty =
new Societe($this->db);
8123 $tmpthirdparty->country_code =
$mysoc->country_code;
8125 $defaulttx =
get_default_tva(is_object($societe_vendeuse) ? $societe_vendeuse : $tmpthirdparty, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
8126 $defaultnpr =
get_default_npr(is_object($societe_vendeuse) ? $societe_vendeuse : $tmpthirdparty, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
8128 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
8129 $defaultcode = $reg[1];
8130 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
8132 if (empty($defaulttx)) {
8139 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
8142 $defaulttx = $arrayofvatrates[$num - 1][
'txtva'];
8149 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
8150 $defaultcode = $reg[1];
8151 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
8159 if (is_object($societe_vendeuse) && $societe_vendeuse->id ==
$mysoc->id && empty($societe_vendeuse->tva_assuj)) {
8169 if (!$options_only) {
8170 $return .=
'<select class="flat valignmiddle minwidth75imp maxwidth100 right" id="' . $htmlname .
'" name="' . $htmlname .
'"' . ($disabled ?
' disabled' :
'') . $title .
'>';
8173 $selectedfound =
false;
8174 foreach ($arrayofvatrates as $rate) {
8176 if ($disabled && $rate[
'txtva'] != 0) {
8181 $key = $rate[
'txtva'];
8182 $key .= $rate[
'nprtva'] ?
'*' :
'';
8183 if ($mode > 0 && $rate[
'code']) {
8184 $key .=
' (' . $rate[
'code'] .
')';
8187 $key = $rate[
'rowid'];
8190 $return .=
'<option value="' . $key .
'" data-vatid="'.$rate[
'rowid'].
'"';
8191 if (!$selectedfound) {
8193 if ($defaultcode == $rate[
'code']) {
8194 $return .=
' selected';
8195 $selectedfound =
true;
8197 } elseif ($rate[
'txtva'] == $defaulttx && $rate[
'nprtva'] == $defaultnpr) {
8198 $return .=
' selected';
8199 $selectedfound =
true;
8207 $return .= $rate[
'labelpositiverates'];
8210 $return .=
vatrate($rate[
'label']);
8214 $return .= (empty($rate[
'code']) && $rate[
'nprtva']) ?
' *' :
'';
8216 $return .=
'</option>';
8219 if (!$options_only) {
8220 $return .=
'</select>';
8224 $return .= $this->error;
8258 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 =
'')
8261 dol_syslog(__METHOD__ .
': using select_date is deprecated. Use selectDate instead.', LOG_WARNING);
8262 $retstring = $this->selectDate($set_time, $prefix, $h, $m, $empty, $form_name, $d, $addnowlink, $disabled, $fullday, $addplusone, $adddateof);
8263 if (!empty($nooutput)) {
8286 public function selectDateToDate($set_time =
'', $set_time_end =
'', $prefix =
're', $empty = 0, $forcenewline = 0)
8290 $ret = $this->selectDate($set_time, $prefix .
'_start', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"from"),
'tzuserrel');
8291 if ($forcenewline) {
8294 $ret .= $this->selectDate($set_time_end, $prefix .
'_end', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
8326 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 =
'')
8328 global
$conf, $langs;
8330 if ($gm ===
'auto') {
8331 $gm = (empty(
$conf) ?
'tzserver' :
$conf->tzuserinputkey);
8336 if ($prefix ==
'') {
8347 if ($stepminutes <= 0 || $stepminutes > 30) {
8358 $orig_set_time = $set_time;
8360 if ($set_time ===
'' && $emptydate == 0) {
8361 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
8362 if ($gm ==
'tzuser' || $gm ==
'tzuserrel') {
8374 if (!empty($set_time) && preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/', (
string) $set_time, $reg)) {
8376 $syear = (!empty($reg[1]) ? $reg[1] :
'');
8377 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
8378 $sday = (!empty($reg[3]) ? $reg[3] :
'');
8379 $shour = (!empty($reg[4]) ? $reg[4] :
'');
8380 $smin = (!empty($reg[5]) ? $reg[5] :
'');
8381 } elseif (strval($set_time) !=
'' && $set_time != -1) {
8386 if ($orig_set_time !=
'') {
8400 if ($h == 3 || $h == 4) {
8411 $usecalendar =
'combo';
8417 $usecalendar =
'html';
8422 if ($usecalendar !=
'combo') {
8424 $reduceformat = (!empty(
$conf->dol_optimize_smallscreen) ? 1 : 0);
8425 if ($reduceformat) {
8426 $format = str_replace(
'%Y',
'%y', $langs->transnoentitiesnoconv(
"FormatDateShortInput"));
8427 $formatjslong = $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput");
8428 $formatjs = str_replace(
'yyyy',
'yy', $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput"));
8429 $formatjquery = str_replace(
'yyyy',
'yy', $langs->trans(
"FormatDateShortJQueryInput"));
8431 $format = $langs->transnoentitiesnoconv(
"FormatDateShortInput");
8432 $formatjslong = $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput");
8433 $formatjs = $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput");
8434 $formatjquery = $langs->trans(
"FormatDateShortJQueryInput");
8438 $formatted_date =
'';
8439 if (strval($set_time) !=
'' && $set_time != -1) {
8444 if ($usecalendar ==
"eldy") {
8470 } elseif ($usecalendar ==
'jquery' || $usecalendar ==
'html') {
8471 if (!$disabled && $usecalendar !=
'html') {
8473 $minYear =
getDolGlobalInt(
'MIN_YEAR_SELECT_DATE', (idate(
'Y') - 100));
8474 $maxYear =
getDolGlobalInt(
'MAX_YEAR_SELECT_DATE', (idate(
'Y') + 100));
8476 $retstring .=
'<!-- datepicker usecalendar='.$usecalendar.
' --><script nonce="' .
getNonce() .
'" type="text/javascript">';
8477 $retstring .=
"$(function(){ $('#" . $prefix .
"').datepicker({
8480 todayHighlight: true,
8481 yearRange: '" . $minYear .
":" . $maxYear .
"',";
8482 if (!empty(
$conf->dol_use_jmobile)) {
8484 beforeShow: function (input, datePicker) {
8485 input.disabled = true;
8487 onClose: function (dateText, datePicker) {
8488 this.disabled = false;
8494 $buttonImage = $calendarpicto ?: DOL_URL_ROOT .
"/theme/" .
dol_escape_js(
$conf->theme) .
"/img/object_calendarday.png";
8496 showOn: 'button', /* both has problem with autocompletion */
8497 buttonImage: '" . $buttonImage .
"',
8498 buttonImageOnly: true";
8502 $retstring .=
"</script>";
8506 $retstring .=
'<div class="nowraponall inline-block divfordateinput">';
8507 $retstring .=
'<input id="'.$prefix.
'" name="'.$prefix.
'" type="'.($usecalendar ==
'html' ?
"date" :
"text").
'" class="maxwidthdate'.(
getDolUserString(
'MAIN_OPTIMIZEFORTEXTBROWSER') ?
' textbrowser' :
'').
' center" maxlength="11" value="'.$formatted_date.
'"';
8508 $retstring .= ($disabled ?
' disabled' :
'');
8509 $retstring .= ($placeholder ?
' placeholder="' .
dol_escape_htmltag($placeholder) .
'"' :
'');
8510 $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
8511 $retstring .= ' autocomplete="off
">';
8515 $retstringbutton = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
">' . img_object($langs->trans("Disabled
"), 'calendarday', 'class="datecallink ui-datepicker-notrigger
"') . '</button>';
8516 $retstring .= $retstringbutton;
8519 $retstring .= '</div>';
8520 $retstring .= '<input type="hidden
" id="' . $prefix . 'day
" name="' . $prefix . 'day
" value="' . $sday . '">' . "\n
";
8521 $retstring .= '<input type="hidden
" id="' . $prefix . 'month
" name="' . $prefix . 'month
" value="' . $smonth . '">' . "\n
";
8522 $retstring .= '<input type="hidden
" id="' . $prefix . 'year
" name="' . $prefix . 'year
" value="' . $syear . '">' . "\n
";
8524 $retstring .= "Bad value of MAIN_POPUP_CALENDAR
";
8527 // Show date with combo selects
8529 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50imp
" id="' . $prefix . 'day
" name="' . $prefix . 'day
">';
8531 if ($emptydate || $set_time == -1) {
8532 $retstring .= '<option value="0
" selected> </option>';
8535 for ($day = 1; $day <= 31; $day++) {
8536 $retstring .= '<option value="' . $day . '"' . ($day == $sday ? ' selected' : '') . '>' . $day . '</option>';
8539 $retstring .= "</select>
";
8541 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'month
" name="' . $prefix . 'month
">';
8542 if ($emptydate || $set_time == -1) {
8543 $retstring .= '<option value="0
" selected> </option>';
8547 for ($month = 1; $month <= 12; $month++) {
8548 $retstring .= '<option value="' . $month . '"' . ($month == $smonth ? ' selected' : '') . '>';
8549 $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b
");
8550 $retstring .= "</option>
";
8552 $retstring .= "</select>
";
8555 if ($emptydate || $set_time == -1) {
8556 $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 . '">';
8558 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'year
" name="' . $prefix . 'year
">';
8560 $syear = (int) $syear;
8561 for ($year = $syear - 10; $year < (int) $syear + 10; $year++) {
8562 $retstring .= '<option value="' . $year . '"' . ($year == $syear ? ' selected' : '') . '>' . $year . '</option>';
8564 $retstring .= "</select>\n
";
8570 $retstring .= (($h == 2 || $h == 4) ? '<br>' : ' ');
8571 $retstring .= '<span class="nowraponall
">';
8577 if ($openinghours != '') {
8578 $openinghours = explode(',', $openinghours);
8579 $hourstart = $openinghours[0];
8580 $hourend = $openinghours[1];
8581 if ($hourend < $hourstart) {
8582 $hourend = $hourstart;
8587 $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
8588 $retstring .= ($fullday ? $fullday . 'hour
' : '') . '" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
">';
8590 $retstring .= '<option value="-1
"> </option>';
8592 for ($hour = $hourstart; $hour < $hourend; $hour++) {
8593 if (strlen($hour) < 2) {
8594 $hour = "0
" . $hour;
8596 $retstring .= '<option value="' . $hour . '"' . (($hour == $shour) ? ' selected' : '') . '>' . $hour;
8597 $retstring .= '</option>';
8599 $retstring .= '</select>';
8602 $retstring .= '<input type="hidden
" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
" value="' . $shour . '">' . "\n
";
8611 $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
8612 $retstring .= ($fullday ? $fullday . 'min
' : '') . '" id="' . $prefix . 'min
" name="' . $prefix . 'min
">';
8614 $retstring .= '<option value="-1
"> </option>';
8616 for ($min = 0; $min < 60; $min += $stepminutes) {
8617 $min_str = sprintf("%02d
", $min);
8618 $retstring .= '<option value="' . $min_str . '"' . (($min_str == $smin) ? ' selected' : '') . '>' . $min_str . '</option>';
8620 $retstring .= '</select>';
8622 $retstring .= '<input type="hidden
" id="' . $prefix . 'min
" name="' . $prefix . 'min
" value="' . $smin . '">' . "\n
";
8625 $retstring .= '<input type="hidden
" name="' . $prefix . 'sec
" value="' . $ssec . '">';
8629 $retstring .= '</span>';
8633 if (!empty($conf->use_javascript_ajax) && $addnowlink && !$disabled) {
8634 // Script which will be inserted in the onClick of the "Now
" link
8635 $reset_scripts = "";
8636 if ($addnowlink == 2) { // local computer time
8637 // pad add leading 0 on numbers
8638 $reset_scripts .= "Number.prototype.pad =
function(size) {
8639 var s = String(
this);
8640 while (s.length < (size || 2)) {s =
'0' + s;}
8643 var d =
new Date();
";
8646 // Generate the date part, depending on the use or not of the javascript calendar
8647 if ($addnowlink == 1) { // server time expressed in user time setup
8648 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
8649 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
8650 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
8651 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
8652 } elseif ($addnowlink == 2) {
8653 /* Disabled because the output does not use the string format defined by FormatDateShort key to forge the value into #prefix.
8654 * This break application for foreign languages.
8655 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(d.toLocaleDateString(\''.str_replace('_', '-', $langs->defaultlang).'\'));';
8656 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(d.getDate().pad());';
8657 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(parseInt(d.getMonth().pad()) + 1);';
8658 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(d.getFullYear());';
8660 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
8661 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
8662 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
8663 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
8665 /*if ($usecalendar == "eldy
")
8667 $base=DOL_URL_ROOT.'/core/';
8668 $reset_scripts .= 'resetDP(\''.$base.'\',\''.$prefix.'\',\''.$langs->trans("FormatDateShortJavaInput
").'\',\''.$langs->defaultlang.'\');';
8672 $reset_scripts .= 'this.form.elements[\''.$prefix.'day\'].value=formatDate(new Date(), \'d\'); ';
8673 $reset_scripts .= 'this.form.elements[\''.$prefix.'month\'].value=formatDate(new Date(), \'M\'); ';
8674 $reset_scripts .= 'this.form.elements[\''.$prefix.'year\'].value=formatDate(new Date(), \'yyyy\'); ';
8676 // Update the hour part
8679 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8681 //$reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); ';
8682 if ($addnowlink == 1) {
8683 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
8684 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
8685 } elseif ($addnowlink == 2) {
8686 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(d.getHours().pad());';
8687 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
8691 $reset_scripts .= ' } ';
8694 // Update the minute part
8697 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8699 //$reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); ';
8700 if ($addnowlink == 1) {
8701 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
8702 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
8703 } elseif ($addnowlink == 2) {
8704 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(d.getMinutes().pad());';
8705 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
8708 $reset_scripts .= ' } ';
8711 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
8712 if ($reset_scripts && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
8713 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonNow
" type="button" name="_useless
" value="now
" onClick="' . $reset_scripts . '">';
8714 $retstring .= $langs->trans("Now
");
8715 $retstring .= '</button> ';
8719 // Add a "Plus one hour
" link
8720 if ($conf->use_javascript_ajax && $addplusone && !$disabled) {
8721 // Script which will be inserted in the onClick of the "Add plusone
" link
8722 $reset_scripts = "";
8724 // Generate the date part, depending on the use or not of the javascript calendar
8725 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'dayinputnoreduce', 'tzuserrel') . '\');';
8726 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
8727 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
8728 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
8729 // Update the hour part
8732 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8734 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
8736 $reset_scripts .= ' } ';
8739 // Update the minute part
8742 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8744 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
8746 $reset_scripts .= ' } ';
8749 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
8750 if ($reset_scripts && empty($conf->dol_optimize_smallscreen)) {
8751 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonPlusOne
" type="button" name="_useless2
" value="plusone
" onClick="' . $reset_scripts . '">';
8752 $retstring .= $langs->trans("DateStartPlusOne
");
8753 $retstring .= '</button> ';
8757 // Add a link to set data
8758 if ($conf->use_javascript_ajax && !empty($adddateof) && !$disabled) {
8759 if (!is_array($adddateof)) {
8760 $arrayofdateof = array(array('adddateof' => $adddateof, 'labeladddateof' => $labeladddateof));
8762 $arrayofdateof = $adddateof;
8764 foreach ($arrayofdateof as $valuedateof) {
8765 $tmpadddateof = empty($valuedateof['adddateof']) ? 0 : $valuedateof['adddateof'];
8766 $tmplabeladddateof = empty($valuedateof['labeladddateof']) ? '' : $valuedateof['labeladddateof'];
8767 $tmparray = dol_getdate($tmpadddateof);
8768 if (empty($tmplabeladddateof)) {
8769 $tmplabeladddateof = $langs->trans("DateInvoice
");
8771 $reset_scripts = 'console.log(\'Click on now link\'); ';
8772 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(\''.dol_print_date($tmpadddateof, 'dayinputnoreduce').'\');';
8773 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(\''.$tmparray['mday'].'\');';
8774 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(\''.$tmparray['mon'].'\');';
8775 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(\''.$tmparray['year'].'\');';
8776 $retstring .= ' - <button class="dpInvisibleButtons datenowlink
" id="dateofinvoice
" type="button" name="_dateofinvoice
" value="now
" onclick="'.$reset_scripts.'">'.$tmplabeladddateof.'</button>';
8792 public function selectTypeDuration($prefix, $selected = 'i', $excludetypes = array(), $morecss = 'minwidth75 maxwidth100')
8796 $TDurationTypes = $this->getDurationTypes($langs);
8798 // Removed undesired duration types
8799 foreach ($excludetypes as $value) {
8800 unset($TDurationTypes[$value]);
8803 $retstring = '<select class="flat
'.($morecss ? ' '.$morecss : '').'" id="select_
' . $prefix . 'type_duration
" name="' . $prefix . 'type_duration
">';
8804 foreach ($TDurationTypes as $key => $typeduration) {
8805 $retstring .= '<option value="' . $key . '"';
8806 if ($key == $selected) {
8807 $retstring .= " selected
";
8809 $retstring .= ">
" . $typeduration . "</option>
";
8811 $retstring .= "</select>
";
8813 $retstring .= ajax_combobox('select_' . $prefix . 'type_duration');
8818 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
8833 public function select_duration($prefix, $iSecond = '', $disabled = 0, $typehour = 'select', $minunderhours = 0, $nooutput = 0)
8838 $retstring = '<span class="nowraponall
">';
8844 if ($iSecond != '') {
8845 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
8847 $hourSelected = convertSecondToTime($iSecond, 'allhour');
8848 $minSelected = convertSecondToTime($iSecond, 'min');
8851 if ($typehour == 'select') {
8852 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'hour
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . '>';
8853 for ($hour = 0; $hour < 25; $hour++) { // For a duration, we allow 24 hours
8854 $retstring .= '<option value="' . $hour . '"';
8855 if (is_numeric($hourSelected) && $hourSelected == $hour) {
8856 $retstring .= " selected
";
8858 $retstring .= ">
" . $hour . "</option>
";
8860 $retstring .= "</select>
";
8861 } elseif ($typehour == 'text' || $typehour == 'textselect') {
8862 $retstring .= '<input placeholder="' . $langs->trans('HourShort
') . '" type="number
" min="0
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputhour right
" value="' . (($hourSelected != '') ? ((int) $hourSelected) : '') . '">';
8864 return 'BadValueForParameterTypeHour';
8867 if ($typehour != 'text') {
8868 $retstring .= ' ' . $langs->trans('HourShort');
8870 $retstring .= '<span class="">:</span>';
8874 if ($minunderhours) {
8875 $retstring .= '<br>';
8877 if ($typehour != 'text') {
8878 $retstring .= '<span class="hideonsmartphone
"> </span>';
8882 if ($typehour == 'select' || $typehour == 'textselect') {
8883 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'min
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . '>';
8884 $step = getDolGlobalInt('MAIN_DURATION_STEP');
8885 $duration_step = ($step > 0) ? $step : 5;
8886 for ($min = 0; $min <= 59; $min += $duration_step) {
8887 $retstring .= '<option value="' . $min . '"';
8888 if (is_numeric($minSelected) && $minSelected == $min) {
8889 $retstring .= ' selected';
8891 $retstring .= '>' . $min . '</option>';
8893 $retstring .= "</select>
";
8894 } elseif ($typehour == 'text') {
8895 $retstring .= '<input placeholder="' . $langs->trans('MinuteShort
') . '" type="number
" min="0
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputminute right
" value="' . (($minSelected != '') ? ((int) $minSelected) : '') . '">';
8898 if ($typehour != 'text') {
8899 $retstring .= ' ' . $langs->trans('MinuteShort');
8902 $retstring .= "</span>
";
8904 if (!empty($nooutput)) {
8932 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)
8934 global $langs, $conf;
8939 if (is_null($ajaxoptions)) {
8940 $ajaxoptions = array();
8943 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
8946 if ($selected && empty($selected_input_value)) {
8947 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
8948 $tickettmpselect = new Ticket($this->db);
8949 $tickettmpselect->fetch((int) $selected);
8950 $selected_input_value = $tickettmpselect->ref;
8951 unset($tickettmpselect);
8955 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/ticket/ajax/tickets.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
8957 if (empty($hidelabel)) {
8958 $out .= $langs->trans("RefOrLabel
") . ' : ';
8959 } elseif ($hidelabel > 1) {
8960 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
8961 if ($hidelabel == 2) {
8962 $out .= img_picto($langs->trans("Search
"), 'search');
8965 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
8966 if ($hidelabel == 3) {
8967 $out .= img_picto($langs->trans("Search
"), 'search');
8970 $out .= $this->selectTicketsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
8973 if (empty($nooutput)) {
8998 public function selectTicketsList($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
9003 $outarray = array();
9005 $selectFields = " p.rowid, p.ref, p.message
";
9008 $sql .= $this->db->sanitize($selectFields, 0, 0, 1);
9009 $sql .= " FROM
" . $this->db->prefix() . "ticket as p
";
9010 $sql .= ' WHERE p.entity IN (' . getEntity('ticket') . ')';
9012 // Add criteria on ref/label
9013 if ($filterkey != '') {
9015 $prefix = getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '' : '%'; // Can use index if TICKET_DONOTSEARCH_ANYWHERE is on
9016 // For natural search
9017 $search_crit = explode(' ', $filterkey);
9019 if (count($search_crit) > 1) {
9022 foreach ($search_crit as $crit) {
9026 $sql .= "(p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%' OR p.subject LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
9030 if (count($search_crit) > 1) {
9036 $sql .= $this->db->plimit($limit, 0);
9038 // Build output string
9039 dol_syslog(get_class($this) . "::selectTicketsList search tickets
", LOG_DEBUG);
9040 $result = $this->db->query($sql);
9042 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
9043 require_once DOL_DOCUMENT_ROOT . '/core/lib/ticket.lib.php';
9045 $num = $this->db->num_rows($result);
9050 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
9051 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('TICKET_USE_SEARCH_TO_SELECT'));
9054 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
9057 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
9058 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
9059 if (getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
9060 if ($showempty && !is_numeric($showempty)) {
9061 $textifempty = $langs->trans($showempty);
9063 $textifempty .= $langs->trans("All
");
9066 if ($showempty && !is_numeric($showempty)) {
9067 $textifempty = $langs->trans($showempty);
9071 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
9075 while ($num && $i < $num) {
9078 $objp = $this->db->fetch_object($result);
9080 $this->constructTicketListOption($objp, $opt, $optJson, $selected, $filterkey);
9081 '@phan-var-force array{key:string,value:mixed,type:int} $optJson';
9083 // "key
" value of json key array is used by jQuery automatically as selected value
9084 // "label
" value of json key array is used by jQuery automatically as text for combo box
9086 array_push($outarray, $optJson);
9091 $out .= '</select>';
9093 $this->db->free($result);
9095 if (empty($outputmode)) {
9100 dol_print_error($this->db);
9117 protected function constructTicketListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
9123 $outkey = $objp->rowid;
9124 $outref = $objp->ref;
9126 $opt = '<option value="
' . $objp->rowid . '"';
9127 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
9130 $objRef = $objp->ref;
9131 if (!empty($filterkey) && $filterkey != '') {
9132 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1);
9135 $opt .= "</option>\n
";
9136 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
9158 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)
9160 global $langs, $conf;
9165 if (is_null($ajaxoptions)) {
9166 $ajaxoptions = array();
9169 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
9172 if ($selected && empty($selected_input_value)) {
9173 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
9174 $projecttmpselect = new Project($this->db);
9175 $projecttmpselect->fetch((int) $selected);
9176 $selected_input_value = $projecttmpselect->ref;
9177 unset($projecttmpselect);
9181 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/projet/ajax/projects.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
9183 if (empty($hidelabel)) {
9184 $out .= $langs->trans("RefOrLabel
") . ' : ';
9185 } elseif ($hidelabel > 1) {
9186 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
9187 if ($hidelabel == 2) {
9188 $out .= img_picto($langs->trans("Search
"), 'search');
9191 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
9192 if ($hidelabel == 3) {
9193 $out .= img_picto($langs->trans("Search
"), 'search');
9196 $out .= $this->selectProjectsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
9199 if (empty($nooutput)) {
9223 public function selectProjectsList($selected = '', $htmlname = 'projectid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
9225 global $langs, $conf;
9228 $outarray = array();
9230 $selectFields = " p.rowid, p.ref
";
9233 $sql .= $this->db->sanitize($selectFields, 0, 0, 1);
9234 $sql .= " FROM
" . $this->db->prefix() . "projet as p
";
9235 $sql .= ' WHERE p.entity IN (' . getEntity('project') . ')';
9237 // Add criteria on ref/label
9238 if ($filterkey != '') {
9240 $prefix = !getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
9241 // For natural search
9242 $search_crit = explode(' ', $filterkey);
9244 if (count($search_crit) > 1) {
9247 foreach ($search_crit as $crit) {
9251 $sql .= "p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
9255 if (count($search_crit) > 1) {
9261 $sql .= $this->db->plimit($limit, 0);
9263 // Build output string
9264 dol_syslog(get_class($this) . "::selectProjectsList search projects
", LOG_DEBUG);
9265 $result = $this->db->query($sql);
9267 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
9268 require_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php';
9270 $num = $this->db->num_rows($result);
9275 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
9276 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('PROJECT_USE_SEARCH_TO_SELECT'));
9279 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
9282 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
9283 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
9284 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
9285 if ($showempty && !is_numeric($showempty)) {
9286 $textifempty = $langs->trans($showempty);
9288 $textifempty .= $langs->trans("All
");
9291 if ($showempty && !is_numeric($showempty)) {
9292 $textifempty = $langs->trans($showempty);
9296 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
9300 while ($num && $i < $num) {
9303 $objp = $this->db->fetch_object($result);
9305 $this->constructProjectListOption($objp, $opt, $optJson, $selected, $filterkey);
9307 // "key
" value of json key array is used by jQuery automatically as selected value
9308 // "label
" value of json key array is used by jQuery automatically as text for combo box
9310 array_push($outarray, $optJson);
9315 $out .= '</select>';
9317 $this->db->free($result);
9319 if (empty($outputmode)) {
9324 dol_print_error($this->db);
9343 protected function constructProjectListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
9349 $label = $objp->label;
9351 $outkey = $objp->rowid;
9352 $outref = $objp->ref;
9353 $outlabel = $objp->label;
9354 $outtype = $objp->fk_product_type;
9356 $opt = '<option value="
' . $objp->rowid . '"';
9357 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
9360 $objRef = $objp->ref;
9361 if (!empty($filterkey) && $filterkey != '') {
9362 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', (string) $objRef, 1);
9365 $opt .= "</option>\n
";
9366 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
9390 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())
9392 global $langs, $conf;
9397 if (is_null($ajaxoptions)) {
9398 $ajaxoptions = array();
9401 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
9404 if ($selected && empty($selected_input_value)) {
9405 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
9406 $adherenttmpselect = new Adherent($this->db);
9407 $adherenttmpselect->fetch((int) $selected);
9408 $selected_input_value = $adherenttmpselect->ref;
9409 unset($adherenttmpselect);
9414 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/adherents/ajax/adherents.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
9416 if (empty($hidelabel)) {
9417 $out .= $langs->trans("RefOrLabel
") . ' : ';
9418 } elseif ($hidelabel > 1) {
9419 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
9420 if ($hidelabel == 2) {
9421 $out .= img_picto($langs->trans("Search
"), 'search');
9424 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
9425 if ($hidelabel == 3) {
9426 $out .= img_picto($langs->trans("Search
"), 'search');
9431 $out .= $this->selectMembersList($selected, $htmlname, $filtertype, $limit, $filterkey, $status, 0, $showempty, $forcecombo, $morecss, $excludeids);
9434 if (empty($nooutput)) {
9459 public function selectMembersList($selected = '', $htmlname = 'adherentid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '', $excludeids = array())
9461 global $langs, $conf;
9464 $outarray = array();
9466 $selectFields = " p.rowid, p.ref, p.firstname, p.lastname, p.fk_adherent_type
";
9469 $sql .= $this->db->sanitize($selectFields, 0, 0, 1);
9470 $sql .= " FROM
" . $this->db->prefix() . "adherent as p
";
9471 $sql .= ' WHERE p.entity IN (' . getEntity('adherent') . ')';
9473 // Add criteria on ref/label
9474 if ($filterkey != '') {
9476 $prefix = !getDolGlobalString('MEMBER_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
9477 // For natural search
9478 $search_crit = explode(' ', $filterkey);
9480 if (count($search_crit) > 1) {
9483 foreach ($search_crit as $crit) {
9487 $sql .= "(p.firstname LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
9488 $sql .= " OR p.lastname LIKE
'" . $this->db->escape($prefix . $crit) . "%')
";
9491 if (count($search_crit) > 1) {
9496 if ($status != -1) {
9497 $sql .= ' AND statut = ' . ((int) $status);
9499 if (!empty($excludeids)) {
9500 $sql .= " AND p.rowid NOT IN (
" . $this->db->sanitize(implode(',', $excludeids)) . ")
";
9502 $sql .= $this->db->plimit($limit, 0);
9504 // Build output string
9505 dol_syslog(get_class($this) . "::selectMembersList search adherents
", LOG_DEBUG);
9506 $result = $this->db->query($sql);
9508 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
9509 require_once DOL_DOCUMENT_ROOT . '/core/lib/member.lib.php';
9511 $num = $this->db->num_rows($result);
9516 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
9517 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('PROJECT_USE_SEARCH_TO_SELECT'));
9520 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
9523 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
9524 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
9525 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
9526 if ($showempty && !is_numeric($showempty)) {
9527 $textifempty = $langs->trans($showempty);
9529 $textifempty .= $langs->trans("All
");
9532 if ($showempty && !is_numeric($showempty)) {
9533 $textifempty = $langs->trans($showempty);
9537 $out .= '<option value="-1
" selected>' . $textifempty . '</option>';
9541 while ($num && $i < $num) {
9544 $objp = $this->db->fetch_object($result);
9546 $this->constructMemberListOption($objp, $opt, $optJson, $selected, $filterkey);
9549 // "key
" value of json key array is used by jQuery automatically as selected value
9550 // "label
" value of json key array is used by jQuery automatically as text for combo box
9552 array_push($outarray, $optJson);
9557 $out .= '</select>';
9559 $this->db->free($result);
9561 if (empty($outputmode)) {
9566 dol_print_error($this->db);
9583 protected function constructMemberListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
9589 $outkey = $objp->rowid;
9590 $outlabel = dolGetFirstLastname($objp->firstname, $objp->lastname);
9591 $outtype = $objp->fk_adherent_type;
9593 $opt = '<option value="
' . $objp->rowid . '"';
9594 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
9596 if (!empty($filterkey) && $filterkey != '') {
9597 $outlabel = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $outlabel, 1);
9600 $opt .= "</option>\n
";
9602 $optJson = array('key' => $outkey, 'value' => $outlabel, 'type' => $outtype);
9626 public function selectForForms($objectdesc, $htmlname, $preSelectedValue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $disabled = 0, $selected_input_value = '', $objectfield = '')
9628 global $conf, $extrafields, $user, $hookmanager, $action;
9630 // Example of common usage for a link to a thirdparty
9632 // We got this in a modulebuilder form of "
MyObject" of module "mymodule
".
9633 // 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
9634 // $objectdesc = 'Societe'
9635 // $objectfield = Method 1: 'myobject@mymodule:fk_soc' ('fk_soc' is code to retrieve myobject->fields['fk_soc'])
9636 // 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__))
" ...)
9638 // We got this when showing an extrafields on resource that is a link to societe
9639 // 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
9640 // $objectdesc = 'Societe'
9641 // $objectfield = Method 1: 'resource:options_link_to_societe'
9642 // Method 2 recommended (it can be the array): array("type"=>'Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))" ...)
9651 $objectdescorig = $objectdesc;
9653 $InfoFieldList = array();
9658 if (is_array($objectfield)) {
9659 $objectdesc = $objectfield[
'type'];
9660 $objectdesc = preg_replace(
'/^integer[^:]*:/',
'', $objectdesc);
9661 } elseif ($objectfield) {
9663 $tmparray = explode(
':', $objectfield);
9666 $objectforfieldstmp = fetchObjectByElement(0, strtolower($tmparray[0]));
9668 if (is_object($objectforfieldstmp)) {
9672 if (preg_match(
'/^options_(.*)$/', $tmparray[1], $reg)) {
9676 $extrafields->fetch_name_optionals_label($objectforfieldstmp->table_element);
9678 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element][
'type'][$key]) && $extrafields->attributes[$objectforfieldstmp->table_element][
'type'][$key] ==
'link') {
9679 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element][
'param'][$key][
'options'])) {
9680 $tmpextrafields = array_keys($extrafields->attributes[$objectforfieldstmp->table_element][
'param'][$key][
'options']);
9681 $objectdesc = $tmpextrafields[0];
9686 if (array_key_exists($tmparray[1], $objectforfieldstmp->fields)) {
9687 $objectdesc = $objectforfieldstmp->fields[$tmparray[1]][
'type'];
9688 $objectdesc = preg_replace(
'/^integer[^:]*:/',
'', $objectdesc);
9699 $InfoFieldList = explode(
":", $objectdesc, 4);
9700 $vartmp = (empty($InfoFieldList[3]) ?
'' : $InfoFieldList[3]);
9702 if (preg_match(
'/^.*:(\w*)$/', $vartmp, $reg)) {
9703 $InfoFieldList[4] = $reg[1];
9705 $InfoFieldList[3] = preg_replace(
'/:\w*$/',
'', $vartmp);
9707 $classname = $InfoFieldList[0];
9708 $classpath = empty($InfoFieldList[1]) ?
'' : $InfoFieldList[1];
9710 $filter = empty($InfoFieldList[3]) ?
'' : $InfoFieldList[3];
9711 $sortfield = empty($InfoFieldList[4]) ?
'' : $InfoFieldList[4];
9714 $objecttmp = fetchObjectByElement(0, strtolower($InfoFieldList[0]));
9717 if (empty($objecttmp) && !empty($classpath)) {
9720 if ($classname && class_exists($classname)) {
9721 $objecttmp =
new $classname($this->db);
9728 $sharedentities = (is_object($objecttmp) && property_exists($objecttmp,
'element')) ?
getEntity($objecttmp->element) : strtolower($classname);
9729 $filter = str_replace(
9730 array(
'__ENTITY__',
'__SHARED_ENTITIES__',
'__USER_ID__'),
9731 array(
$conf->entity, $sharedentities, $user->id),
9735 if (!is_object($objecttmp)) {
9736 dol_syslog(
'selectForForms: Error bad setup of field objectdescorig=' . $objectdescorig.
', objectfield='.(is_array($objectfield) ?
'array' : $objectfield).
', objectdesc='.$objectdesc, LOG_WARNING);
9737 return 'selectForForms: Error bad setup of field objectdescorig=' . $objectdescorig.
', objectfield='.(is_array($objectfield) ?
'array' : $objectfield).
', objectdesc='.$objectdesc;
9739 '@phan-var-force CommonObject $objecttmp';
9742 $prefixforautocompletemode = $objecttmp->element;
9743 if ($prefixforautocompletemode ==
'societe') {
9744 $prefixforautocompletemode =
'company';
9746 if ($prefixforautocompletemode ==
'product') {
9747 $prefixforautocompletemode =
'produit';
9750 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) .
'_USE_SEARCH_TO_SELECT';
9752 dol_syslog(get_class($this) .
"::selectForForms filter=" . $filter, LOG_DEBUG);
9760 if ($preSelectedValue && empty($selected_input_value)) {
9761 $objecttmp->fetch($preSelectedValue);
9762 $selected_input_value = ($prefixforautocompletemode ==
'company' ? $objecttmp->name : $objecttmp->ref);
9764 $oldValueForShowOnCombobox = 0;
9765 foreach ($objecttmp->fields as $fieldK => $fielV) {
9766 if (!array_key_exists(
'showoncombobox', $fielV) || !$fielV[
'showoncombobox'] || empty($objecttmp->$fieldK)) {
9770 if (!$oldValueForShowOnCombobox) {
9771 $selected_input_value =
'';
9774 $selected_input_value .= $oldValueForShowOnCombobox ?
' - ' :
'';
9775 $selected_input_value .= $objecttmp->$fieldK;
9776 $oldValueForShowOnCombobox = empty($fielV[
'showoncombobox']) ? 0 : $fielV[
'showoncombobox'];
9781 $urlforajaxcall = DOL_URL_ROOT .
'/core/ajax/selectobject.php';
9782 $urloption =
'htmlname=' . urlencode($htmlname) .
'&outjson=1&objectdesc=' . urlencode($objectdescorig) . (is_scalar($objectfield) ?
'&objectfield='.urlencode($objectfield) :
'') . ($sortfield ?
'&sortfield=' . urlencode($sortfield) :
'');
9786 $parameters = array(
9787 'urloption' => $urloption,
9788 'object' => $objecttmp,
9789 'htmlname' => $htmlname,
9790 'filter' => $filter,
9791 'searchkey' => $searchkey,
9793 $reshook = $hookmanager->executeHooks(
'selectForFormsListUrl', $parameters, $objecttmp, $action);
9794 if (!empty($reshook)) {
9795 $urloption = $hookmanager->resPrint;
9796 $hookmanager->resPrint =
'';
9801 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
9802 $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) .
'"' :
'') .
' />';
9805 $out .= $this->selectForFormsList($objecttmp, $htmlname, $preSelectedValue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled, $sortfield, $filter);
9833 public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty =
'', $searchkey =
'', $placeholder =
'', $morecss =
'', $moreparams =
'', $forcecombo = 0, $outputmode = 0, $disabled = 0, $sortfield =
'', $filter =
'', $sortorder =
'ASC')
9835 global $langs, $user, $hookmanager;
9839 $prefixforautocompletemode = $objecttmp->element;
9840 if ($prefixforautocompletemode ==
'societe') {
9841 $prefixforautocompletemode =
'company';
9843 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) .
'_USE_SEARCH_TO_SELECT';
9846 if (!empty($objecttmp->fields)) {
9847 $tmpfieldstoshow =
'';
9848 foreach ($objecttmp->fields as $key => $val) {
9849 if (! (
int)
dol_eval((
string) $val[
'enabled'], 1, 1,
'1')) {
9852 if (!empty($val[
'showoncombobox'])) {
9853 $tmpfieldstoshow .= ($tmpfieldstoshow ?
',' :
'') .
't.' . $key;
9856 if ($tmpfieldstoshow) {
9857 $fieldstoshow = $tmpfieldstoshow;
9859 } elseif ($objecttmp->element ===
'category') {
9860 $fieldstoshow =
't.label';
9863 $objecttmp->fields[
'ref'] = array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'enabled' => 1,
'position' => 10,
'visible' => 4,
'showoncombobox' => 1);
9866 if (empty($fieldstoshow)) {
9867 if (!empty($objecttmp->parent_element)) {
9868 $fieldstoshow =
'o.ref';
9869 if (empty($sortfield)) {
9870 $sortfield =
'o.ref';
9872 if (in_array($objecttmp->element, [
'commandedet',
'propaldet',
'facturedet',
'expeditiondet'])) {
9873 $fieldstoshow .=
',p.ref AS p_ref,p.label,t.description';
9874 $sortfield .=
', p.ref';
9876 } elseif (isset($objecttmp->fields[
'ref'])) {
9877 $fieldstoshow =
't.ref';
9879 $langs->load(
"errors");
9880 $this->error = $langs->trans(
"ErrorNoFieldWithAttributeShowoncombobox");
9881 return $langs->trans(
'ErrorNoFieldWithAttributeShowoncombobox');
9886 $outarray = array();
9887 $tmparray = array();
9891 $sanitizedfieldstoshow = $fieldstoshow;
9894 $sql =
"SELECT t.rowid, " . $sanitizedfieldstoshow .
" FROM " . $this->db->prefix() . $this->db->sanitize($objecttmp->table_element) .
" as t";
9895 if (!empty($objecttmp->isextrafieldmanaged)) {
9896 $extrafieldTable = $objecttmp->table_element;
9897 if ($extrafieldTable ==
'categorie') {
9898 $extrafieldTable =
'categories';
9900 $sql .=
" LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($extrafieldTable) .
"_extrafields as e ON t.rowid = e.fk_object";
9902 if (!empty($objecttmp->parent_element)) {
9903 '@phan-var-force CommonObjectLine $objecttmp';
9906 $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);
9908 if (!empty($objecttmp->parent_element) && in_array($objecttmp->parent_element, [
'commande',
'propal',
'facture',
'expedition'])) {
9909 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product as p ON p.rowid = t.fk_product";
9911 if (!empty($objecttmp->ismultientitymanaged)) {
9912 if ($objecttmp->ismultientitymanaged == 1) {
9915 if (!is_numeric($objecttmp->ismultientitymanaged)) {
9916 $tmparray = explode(
'@', $objecttmp->ismultientitymanaged);
9917 $sql .=
" INNER JOIN " . $this->db->prefix() . $this->db->sanitize($tmparray[1]) .
" as parenttable ON parenttable.rowid = t." . $this->db->sanitize($tmparray[0]);
9922 $parameters = array(
9923 'object' => $objecttmp,
9924 'htmlname' => $htmlname,
9925 'filter' => $filter,
9926 'searchkey' => $searchkey
9929 $reshook = $hookmanager->executeHooks(
'selectForFormsListWhere', $parameters);
9930 if (!empty($hookmanager->resPrint)) {
9931 $sql .= $hookmanager->resPrint;
9933 $sql .=
" WHERE 1=1";
9936 if (!empty($objecttmp->ismultientitymanaged)) {
9937 if ($objecttmp->ismultientitymanaged == 1) {
9938 $sql .=
" AND t.entity IN (" .
getEntity($objecttmp->element) .
")";
9940 if (!is_numeric($objecttmp->ismultientitymanaged)) {
9941 $sql .=
" AND parenttable.entity = t." . $this->db->sanitize($tmparray[0]);
9945 if ($objecttmp->ismultientitymanaged ===
'fk_soc@societe') {
9946 if (!$user->hasRight(
'societe',
'client',
'voir') && empty($user->socid)) {
9947 $sql .=
" AND EXISTS (SELECT sc.rowid FROM ".$this->db->prefix() .
"societe_commerciaux as sc";
9948 $sql .=
" WHERE sc.fk_soc = t.fk_soc AND sc.fk_user = ".((int) $user->id).
")";
9954 if (!empty($user->socid)) {
9955 if ($objecttmp->element ==
'societe') {
9956 $sql .=
" AND t.rowid = " . ((int) $user->socid);
9957 } elseif (!empty($objecttmp->fields[
'fk_soc']) || !empty($objecttmp->fields[
't.fk_soc']) || property_exists($objecttmp,
'fk_soc') || property_exists($objecttmp,
'socid')) {
9958 $sql .=
" AND t.fk_soc = " . ((int) $user->socid);
9959 } elseif (!empty($objecttmp->parent_element)) {
9960 $tmpparent = fetchObjectByElement(0, $objecttmp->parent_element,
'', 1);
9961 if (is_object($tmpparent) && (!empty($tmpparent->fields[
'fk_soc']) || !empty($tmpparent->fields[
't.fk_soc']) || property_exists($tmpparent,
'fk_soc') || property_exists($tmpparent,
'socid'))) {
9962 $sql .=
" AND o.fk_soc = " . ((int) $user->socid);
9967 $splittedfieldstoshow = explode(
',', $fieldstoshow);
9968 foreach ($splittedfieldstoshow as &$field2) {
9969 if (is_numeric($pos = strpos($field2,
' '))) {
9970 $field2 = substr($field2, 0, $pos);
9973 if ($searchkey !=
'') {
9980 if ($errormessage) {
9981 return 'Error forging a SQL request from an universal criteria: ' . $errormessage;
9985 $sql .= $this->db->order($sortfield ? $sortfield : $fieldstoshow, $sortorder);
9990 $resql = $this->db->query($sql);
9993 $out .=
'<select id="' . $htmlname .
'" class="flat minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') . ($moreparams ?
' ' . $moreparams :
'') .
' name="' . $htmlname .
'">' .
"\n";
9996 $textifempty =
' ';
10000 if ($showempty && !is_numeric($showempty)) {
10001 $textifempty = $langs->trans($showempty);
10003 $textifempty .= $langs->trans(
"All");
10007 $out .=
'<option value="-1">' . $textifempty .
'</option>' .
"\n";
10010 $num = $this->db->num_rows($resql);
10013 while ($i < $num) {
10014 $obj = $this->db->fetch_object($resql);
10017 $tmparray = explode(
',', $fieldstoshow);
10018 $oldvalueforshowoncombobox = 0;
10019 foreach ($tmparray as $key => $val) {
10020 $val = preg_replace(
'/(t|p|o)\./',
'', $val);
10021 $label .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val][
'showoncombobox'] ?
' - ' :
' ') :
'');
10022 $labelhtml .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val][
'showoncombobox'] ?
' - ' :
' ') :
'');
10023 $label .= $obj->$val;
10024 $labelhtml .= $obj->$val;
10026 $oldvalueforshowoncombobox = empty($objecttmp->fields[$val][
'showoncombobox']) ? 0 : $objecttmp->fields[$val][
'showoncombobox'];
10028 if (empty($outputmode)) {
10029 if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) {
10030 $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>';
10032 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
10035 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label));
10039 if (($i % 10) == 0) {
10045 $out .=
'</select>' .
"\n";
10047 if (!$forcecombo) {
10048 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
10055 $this->result = array(
'nbofelement' => $num);
10073 public static function radio($htmlName, $radioItems, $selected =
'', $moreGlobalParams = [])
10077 'disabled' =>
false,
10080 'name' => $htmlName,
10083 'labelIsHtml' => false
10090 if (!empty($radioItems)) {
10091 foreach ($radioItems as $key => $item) {
10093 if (!is_array($item)) {
10105 'value' => !isset($item[
'attr'][
'value']) ? $key :
'',
10115 if ((is_array($selected) && in_array($item[
'attr'][
'value'], $selected,
true)) || $selected === $item[
'attr'][
'value']) {
10116 $item[
'attr'][
'checked'] =
true;
10124 $text = $item[
'labelIsHtml'] ? $item[
'label'] : htmlspecialchars($item[
'label'], ENT_QUOTES | ENT_SUBSTITUTE);
10127 $out .=
'<label ' . $labelAttributes .
'><input ' . $inputAttributes .
' /> ' . $text .
'</label> ';
10158 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)
10160 global
$conf, $langs;
10167 if ($value_as_key) {
10168 $array = array_combine($array, $array);
10171 '@phan-var-force array{label:string,data-html:string,disable?:int<0,1>,css?:string} $array';
10175 if ($addjscombo < 0) {
10182 $idname = str_replace(array(
'[',
']'), array(
'',
''), $htmlname);
10183 $out .=
'<select id="' . preg_replace(
'/^\./',
'', $idname) .
'" ' . ($disabled ?
'disabled="disabled" ' :
'') .
'class="flat ' . (preg_replace(
'/^\./',
'', $htmlname)) . ($morecss ?
' ' . $morecss :
'') .
' selectformat"';
10184 $out .=
' name="' . preg_replace(
'/^\./',
'', $htmlname) .
'" ' . ($moreparam ? $moreparam :
'');
10188 $textforempty =
' ';
10189 if (!empty(
$conf->use_javascript_ajax)) {
10190 $textforempty =
' ';
10192 if (!is_numeric($show_empty)) {
10193 $textforempty = $show_empty;
10195 $out .=
'<option class="optiongrey" ' . ($moreparamonempty ? $moreparamonempty .
' ' :
'') .
'value="' . (((
int) $show_empty) < 0 ? $show_empty : -1) .
'"' . (
$id == $show_empty ?
' selected' :
'') .
'>' . $textforempty .
'</option>' .
"\n";
10197 if (is_array($array)) {
10200 foreach ($array as $key => $value) {
10201 if (!is_array($value)) {
10202 $array[$key] = $langs->trans($value);
10204 $array[$key][
'label'] = $langs->trans($value[
'label']);
10209 if ($sort ==
'ASC') {
10211 } elseif ($sort ==
'DESC') {
10215 foreach ($array as $key => $tmpvalue) {
10216 if (is_array($tmpvalue)) {
10217 $value = $tmpvalue[
'label'];
10219 $disabled = empty($tmpvalue[
'disabled']) ?
'' :
' disabled';
10220 $style = empty($tmpvalue[
'css']) ?
'' :
' class="' . $tmpvalue[
'css'] .
'"';
10222 $value = $tmpvalue;
10227 if (!empty($disablebademail)) {
10228 if (($disablebademail == 1 && !preg_match(
'/<.+@.+>/', $value))
10229 || ($disablebademail == 2 && preg_match(
'/---/', $value))) {
10230 $disabled =
' disabled';
10231 $style =
' class="warning"';
10234 if ($key_in_label) {
10235 if (empty($nohtmlescape)) {
10238 $selectOptionValue = $key .
' - ' . ($maxlen ?
dol_trunc($value, $maxlen) : $value);
10241 if (empty($nohtmlescape)) {
10244 $selectOptionValue = $maxlen ?
dol_trunc($value, $maxlen) : $value;
10246 if ($value ==
'' || $value ==
'-') {
10247 $selectOptionValue =
' ';
10250 $out .=
'<option value="' . $key .
'"';
10251 $out .= $style . $disabled;
10252 $out .= is_array($tmpvalue) && !empty($tmpvalue[
'parent']) ?
' parent="' .
dolPrintHTMLForAttribute($tmpvalue[
'parent']) .
'"' :
'';
10253 if (is_array(
$id)) {
10254 if (in_array($key,
$id) && !$disabled) {
10255 $out .=
' selected';
10259 if (
$id !=
'' && ((
$id == (
string) $key) || (
$id ==
'ifone' && count($array) == 1)) && !$disabled) {
10260 $out .=
' selected';
10264 if (is_array($tmpvalue)) {
10265 foreach ($tmpvalue as $keyforvalue => $valueforvalue) {
10266 if ($keyforvalue ==
'labelhtml') {
10267 $keyforvalue =
'data-html';
10269 if (preg_match(
'/^data-/', $keyforvalue)) {
10270 $out .=
' '.dol_escape_htmltag($keyforvalue).
'="'.
dol_escape_htmltag($valueforvalue).
'"';
10273 } elseif (!empty($nohtmlescape)) {
10278 $out .= $selectOptionValue;
10279 $out .=
"</option>\n";
10282 $out .=
"</select>";
10285 if ($addjscombo && $jsbeautify) {
10287 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
10288 $out .=
ajax_combobox($idname, array(), 0, 0,
'resolve', (((
int) $show_empty) < 0 ? (
string) $show_empty :
'-1'), $morecss);
10312 public static function selectArrayAjax($htmlname, $url,
$id =
'', $moreparam =
'', $moreparamtourl =
'', $disabled = 0, $minimumInputLength = 1, $morecss =
'', $callurlonselect = 0, $placeholder =
'', $acceptdelayedhtml = 0)
10315 global $delayedhtmlcontent;
10318 if (!
getDolGlobalString(
'MAIN_USE_JQUERY_MULTISELECT') && !defined(
'REQUIRE_JQUERY_MULTISELECT')) {
10322 $out =
'<select type="text" class="' . $htmlname . ($morecss ?
' ' . $morecss :
'') .
'" ' . ($moreparam ? $moreparam .
' ' :
'') .
'name="' . $htmlname .
'"></select>';
10325 if (!empty(
$conf->use_javascript_ajax)) {
10326 $tmpplugin =
'select2';
10327 $outdelayed =
"\n" .
'<!-- JS CODE TO ENABLE ' . $tmpplugin .
' for id ' . $htmlname .
' -->
10328 <script nonce="' .
getNonce() .
'">
10329 $(document).ready(function () {
10331 ' . ($callurlonselect ?
'var saveRemoteData = [];' :
'') .
'
10333 $(".' . $htmlname .
'").select2({
10336 url: "' . $url .
'",
10337 dataType: \'json\',
10339 data: function (params) {
10341 q: params.term, // search term
10345 processResults: function (data) {
10346 // parse the results into the format expected by Select2.
10347 // since we are using custom formatting functions we do not need to alter the remote JSON data
10348 //console.log(data);
10349 saveRemoteData = data;
10350 /* format json result for select2 */
10352 $.each( data, function( key, value ) {
10353 result.push({id: key, text: value.text});
10355 //return {results:[{id:\'none\', text:\'aa\'}, {id:\'rrr\', text:\'Red\'},{id:\'bbb\', text:\'Search a into projects\'}], more:false}
10356 //console.log(result);
10357 return {results: result, more: false}
10361 language: (typeof select2arrayoflanguage === \'undefined\') ? \'en\' : select2arrayoflanguage,
10362 containerCssClass: \':all:\', /* Line to add class from the original SELECT propagated to the new <span class="select2-selection...> tag */
10364 escapeMarkup:
function (markup) {
return markup; },
10365 minimumInputLength:
' . ((int) $minimumInputLength) . ',
10366 formatResult:
function (result, container, query, escapeMarkup) {
10367 return escapeMarkup(result.text);
10371 ' . ($callurlonselect ? '
10373 $(
".' . $htmlname . '").change(
function() {
10374 var selected = $(\
'.' .
dol_escape_js($htmlname) .
'\').val();
10375 console.log(
"We select in selectArrayAjax the entry "+selected)
10377 $.each( saveRemoteData,
function( key, value ) {
10378 if (key == selected)
10380 console.log(
"selectArrayAjax - Do a redirect to "+value.url)
10381 location.assign(value.url);
10390 if ($acceptdelayedhtml) {
10391 $delayedhtmlcontent .= $outdelayed;
10393 $out .= $outdelayed;
10417 public static function selectArrayFilter($htmlname, $array, $id = '
', $moreparam = '', $disableFiltering = 0, $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0, $textfortitle = '')
10420 global $delayedhtmlcontent; // Will be used later outside of this function
10422 // TODO Use an internal dolibarr component instead of select2
10423 if (!getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT
') && !defined('REQUIRE_JQUERY_MULTISELECT
')) {
10427 $out = '<select
type=
"text"'.($textfortitle ? ' title=
"'.dol_escape_htmltag($textfortitle).'"' : '').' id=
"'.$htmlname.'" class=
"'.$htmlname.($morecss ? ' ' . $morecss : '').'"'.($moreparam ? ' '.$moreparam : '').' name=
"'.$htmlname.'"><option></option></select>
';
10429 $formattedarrayresult = array();
10431 foreach ($array as $key => $value) {
10432 $o = new stdClass();
10434 $o->text = $value['text
'];
10435 $o->url = $value['url
'];
10436 $formattedarrayresult[] = $o;
10440 if (!empty($conf->use_javascript_ajax)) {
10441 $tmpplugin = 'select2
';
10442 $outdelayed = "\n" . '<!-- JS CODE TO ENABLE
' . $tmpplugin . ' for id ' . $htmlname . ' -->
10443 <script nonce=
"' . getNonce() . '">
10444 $(document).ready(
function () {
10445 var data =
' . json_encode($formattedarrayresult) . ';
10447 ' . ($callurlonselect ? 'var saveRemoteData =
' . json_encode($array) . ';
' : '') . '
10451 language: (typeof select2arrayoflanguage === \
'undefined\') ? \'en\' : select2arrayoflanguage,
10452 containerCssClass: \':all:\', /* Line to add class from the original SELECT propagated to the new <span class="select2-selection...> tag */
10454 escapeMarkup:
function (markup) {
return markup; },
10455 minimumInputLength:
' . ((int) $minimumInputLength) . ',
10456 formatResult:
function (result, container, query, escapeMarkup) {
10457 return escapeMarkup(result.text);
10459 matcher:
function (params, data) {
10461 if(! data.id)
return null;
';
10463 if ($callurlonselect) {
10464 // We forge the url with 'sall=
'
10467 var urlBase = data.url;
10468 var separ = urlBase.indexOf(
"?") >= 0 ?
"&" :
"?";
10471 saveRemoteData[data.id].url = urlBase + separ +
"search_all=" + encodeURIComponent(params.term.replace(/\
"/g, ""));';
10474 if (!$disableFiltering) {
10477 if(data.text.match(new RegExp(params.term))) {
10492 ' . ($callurlonselect ? '
10493 /* Code to execute a GET when we select a value */
10494 $(\'.' . dol_escape_js($htmlname) . '\').change(function() {
10495 var selected = $(\'.' . dol_escape_js($htmlname) . '\').val();
10496 console.log("We select
"+selected)
10498 $(\'.' . dol_escape_js($htmlname) . '\').val(""); /* reset visible combo value */
10499 $.each( saveRemoteData, function( key, value ) {
10500 if (key == selected)
10502 console.log("selectArrayFilter - Do a redirect to
"+value.url)
10503 location.assign(value.url);
10512 if ($acceptdelayedhtml) {
10513 $delayedhtmlcontent .= $outdelayed;
10515 $out .= $outdelayed;
10538 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)
10540 global $conf, $langs;
10543 if ($addjscombo < 0) {
10544 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
10551 $useenhancedmultiselect = 0;
10552 if (!empty($conf->use_javascript_ajax) && !defined('MAIN_DO_NOT_USE_JQUERY_MULTISELECT') && (getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') || defined('REQUIRE_JQUERY_MULTISELECT'))) {
10554 $useenhancedmultiselect = 1; // Use the js multiselect in one line. Possible only if $addjscombo not 0.
10558 $out .= '<span class="multiselectarray
'.$htmlname.'">';
10560 // We need a hidden field because when using the multiselect, if we unselect all, there is no
10561 // variable submitted at all, so no way to make a difference between variable not submitted and variable
10562 // submitted to nothing.
10563 $out .= '<input type="hidden
" name="'.$htmlname.'_multiselect
" value="1
">';
10564 // Output select component
10565 $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
";
10566 if (is_array($array) && !empty($array)) {
10567 if ($value_as_key) {
10568 $array = array_combine($array, $array);
10571 if (!empty($array)) {
10572 foreach ($array as $key => $value) {
10574 $tmplabel = $value;
10575 $tmplabelhtml = '';
10579 if (is_array($value) && array_key_exists('id', $value) && array_key_exists('label', $value)) {
10580 $tmpkey = $value['id'];
10581 $tmplabel = empty($value['label']) ? '' : $value['label'];
10582 $tmplabelhtml = empty($value['labelhtml']) ? (empty($value['data-html']) ? '' : $value['data-html']) : $value['labelhtml'];
10583 $tmpcolor = empty($value['color']) ? '' : $value['color'];
10584 $tmppicto = empty($value['picto']) ? '' : $value['picto'];
10585 $tmpdisabled = empty($value['disabled']) ? '' : $value['disabled'];
10587 $newval = ($translate ? $langs->trans($tmplabel) : $tmplabel);
10588 $newval = ($key_in_label ? $tmpkey . ' - ' . $newval : $newval);
10590 $tmplabelhtml = ($translate ? $langs->trans($tmplabelhtml) : $tmplabelhtml);
10591 $tmplabelhtml = ($key_in_label ? $tmpkey . ' - ' . $tmplabelhtml : $tmplabelhtml);
10593 $out .= '<option value="' . $tmpkey . '"';
10594 if (is_array($selected) && !empty($selected) && in_array((string) $tmpkey, $selected) && ((string) $tmpkey != '')) {
10595 $out .= ' selected';
10597 $out .= is_array($value) && array_key_exists('parent', $value) && !empty($value['parent']) ? ' parent="' . dolPrintHTMLForAttribute($value['parent
']) . '"' : '';
10598 if ($tmpdisabled) {
10601 if (!empty($tmplabelhtml)) {
10602 $out .= ' data-html="' . dolPrintHTMLForAttribute($tmplabelhtml) . '"';
10604 $tmplabelhtml = ($tmppicto ? img_picto('', $tmppicto, 'class="pictofixedwidth
" style="color: #
' . $tmpcolor . '"') : '') . $newval;
10605 $out .= ' data-html="' . dolPrintHTMLForAttribute($tmplabelhtml) . '"';
10608 $out .= dol_htmlentitiesbr($newval);
10609 $out .= '</option>' . "\n
";
10613 $out .= '</select>' . "\n
";
10617 // Add code for jquery to use multiselect
10618 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') || defined('REQUIRE_JQUERY_MULTISELECT')) {
10619 $out .= "\n
" . '<!-- JS CODE TO ENABLE select for id ' . $htmlname . ', addjscombo=' . $addjscombo . ' -->';
10620 $out .= "\n
" . '<script nonce="' . getNonce() . '">' . "\n
";
10621 if ($addjscombo == 1) {
10622 $tmpplugin = getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT', (defined('REQUIRE_JQUERY_MULTISELECT') ? constant('REQUIRE_JQUERY_MULTISELECT') : 'select2'));
10624 // If property data-html set, we decode html entities and use this.
10625 // Note that HTML content must have been sanitized from js with dol_escape_htmltag(xxx, 0, 0, '', 0, 1) when building the select option.
10626 // TODO Move this into common js ?
10627 $out .= 'function formatResult(record, container) {' . "\n
";
10628 $out .= ' if ($(record.element).attr("data-html
") != undefined && typeof htmlEntityDecodeJs === "function
") {';
10629 $out .= ' return htmlEntityDecodeJs($(record.element).attr("data-html
"));';
10631 $out .= ' return record.text;';
10632 $out .= '}' . "\n
";
10634 $out .= 'function formatSelection(record) {' . "\n
";
10635 $out .= ' return record.text;';
10636 $out .= '}' . "\n
";
10638 // Load the select2 enhancer
10639 //$out .= 'console.log(\'addjscombo=1 for htmlname=' . dol_escape_js($htmlname) . '\');';
10640 $out .= '$(document).ready(function () {
10641 $(\'#' . dol_escape_js($htmlname) . '\').' . $tmpplugin . '({';
10642 if ($placeholder) {
10646 text: \''.dol_escape_js($placeholder).'\'
10649 $out .= ' dir: \'ltr\',
10650 containerCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag (ko with multiselect) */
10651 dropdownCssClass: \
'' .
dol_escape_js($morecss) .
'\', /* Line to add class on the new <span class="select2-selection...> tag (ok with multiselect). Need full version of select2. */
10652 // Specify format function for dropdown item
10653 formatResult: formatResult,
10654 templateResult: formatResult, /* For 4.0 */
10655 escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
10656 // Specify format function for selected item
10657 formatSelection: formatSelection,
10658 templateSelection: formatSelection, /* For 4.0 */
10659 language: (typeof select2arrayoflanguage === \'undefined\') ? \'en\' : select2arrayoflanguage
10662 /* Add also morecss to the css .select2 that is after the #htmlname, for component that are shown dynamically after load, because select2 set
10663 the size only if component is not hidden by default on load */
10666 } elseif ($addjscombo == 2 && !defined(
'DISABLE_MULTISELECT')) {
10670 $out .=
'console.log(\'addjscombo=2 for htmlname=' .
dol_escape_js($htmlname) .
'\');
';
10671 $out .= '$(document).ready(
function () {
10673 containerHTML: \
'<div class="multi-select-container">\',
10674 menuHTML: \'<div class="multi-select-menu">\',
10675 buttonHTML: \'<span class="multi-select-button ' .
dol_escape_js($morecss) .
'">\',
10676 menuItemHTML: \'<label class="multi-select-menuitem">\',
10677 activeClass: \'multi-select-container--open\',
10682 $out .= '</script>
';
10702 public static function multiSelectArrayWithCheckbox($htmlname, &$array, $varpage, $pos = '
', $draganddrop = 0)
10704 global $conf, $langs, $user;
10706 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER
')) {
10709 if (empty($array)) {
10713 $tmpvar = "MAIN_SELECTEDFIELDS_" . $varpage; // To get list of saved selected fields to show
10715 if (!empty($user->conf->$tmpvar)) { // A list of fields was already customized for user
10716 $tmparray = explode(',
', $user->conf->$tmpvar);
10717 foreach ($array as $key => $val) {
10719 //var_dump($tmparray);
10720 if (in_array($key, $tmparray)) {
10721 $array[$key]['checked
'] = 1;
10723 $array[$key]['checked
'] = 0;
10726 } else { // There is no list of fields already customized for user
10727 foreach ($array as $key => $val) {
10728 if (!empty($array[$key]['checked
']) && $array[$key]['checked
'] < 0) {
10729 $array[$key]['checked
'] = 0;
10734 $listoffieldsforselection = '';
10735 $listcheckedstring = '';
10737 foreach ($array as $key => $val) {
10739 // var_dump(array_key_exists('enabled
', $val));
10740 // var_dump(!$val['enabled
']);
10741 if (array_key_exists('enabled
', $val) && isset($val['enabled
']) && !$val['enabled
']) {
10742 unset($array[$key]); // We don't want
this field
10745 if (!empty($val[
'type']) && $val[
'type'] ==
'separate') {
10750 if (!empty($val[
'label']) && $val[
'label']) {
10751 if (!empty($val[
'langfile']) && is_object($langs)) {
10752 $langs->load($val[
'langfile']);
10756 $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']).
'" />';
10757 $listoffieldsforselection .=
'<label for="checkbox' . $key .
'" class="paddingleft">';
10759 $listoffieldsforselection .=
'</label>';
10760 if (!empty($draganddrop)) {
10761 $listoffieldsforselection .=
img_picto($langs->trans(
"MoveField", !empty($key) ? $key :
'none'),
'grip_title',
'class="opacitymedium boxhandle hideonsmartphone cursormove marginleftonly"');
10763 $listoffieldsforselection .=
'</li>';
10764 $listcheckedstring .= (empty($val[
'checked']) ?
'' : $key .
',');
10768 $out =
'<!-- Component multiSelectArrayWithCheckbox ' . $htmlname .
' -->
10770 <dl class="dropdown">
10772 <a href="#' . $htmlname .
'" class="multiselectpicto">
10775 <input type="hidden" class="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $listcheckedstring .
'">
10777 <dd class="dropdowndd">
10778 <div class="multiselectcheckbox'.$htmlname.
'">
10779 <ul class="'.$htmlname.(((string) $pos ==
'1' || (
string) $pos ==
'left') ?
'left' :
'').(!empty($draganddrop) ?
' sortable' :
'').
'">
10780 <li class="liinputsearch">
10781 <input class="inputsearch_dropdownselectedfields width90p minwidth200imp" style="width:90%;" type="text" placeholder="'.$langs->trans(
'Search').
'">
10783 '.$listoffieldsforselection.
'
10790 function updateFieldOrder() {
10791 var positionfields = $(".sortable").sortable("toArray");
10793 url: \''.DOL_URL_ROOT.
'/core/ajax/changepositionfields.php?positionfields=\'+positionfields+\'&token='.
newToken().
'&action=listafterchangingpositionfields&contextpage='.$varpage.
'&userid='.$user->id.
'\',
10795 success: function () {
10797 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'";
10801 $( ".sortable" ).sortable({
10802 handle: \'.boxhandle\',
10803 revert: \'invalid\',
10804 items: \'.fieldsortable\',
10805 stop: function(event, ui) {
10806 console.log("We moved box so we call updateBoxOrder with ajax actions");
10807 updateFieldOrder(); /* 1 to avoid message after a move */
10812 <script nonce="' .
getNonce() .
'" type="text/javascript">
10813 jQuery(document).ready(function () {
10814 $(\'.multiselectcheckbox' . $htmlname .
' input[type="checkbox"]\').on("click", function () {
10815 console.log("A new field was added/removed, we edit field input[name=formfilteraction]");
10817 $("input:hidden[name=formfilteraction]").val(\'listafterchangingselectedfields\'); // Update field so we know we changed something on selected fields after POST
10819 var title = $(this).val() + ",";
10820 if ($(this).is(\':checked\')) {
10821 $(\'.' . $htmlname .
'\').val(title + $(\'.' . $htmlname .
'\').val());
10824 $(\'.' . $htmlname .
'\').val( $(\'.' . $htmlname .
'\').val().replace(title, \'\') )
10826 // Now, we submit page
10827 //$(this).parents(\'form:first\').submit();
10830 $("input.inputsearch_dropdownselectedfields").on("keyup", function() {
10831 console.log("keyup on inputsearch_dropdownselectedfields");
10832 var value = $(this).val().toLowerCase();
10833 $(\'.multiselectcheckbox'.$htmlname.
' li > label\').filter(function() {
10834 $(this).parent().toggle($(this).text().toLowerCase().indexOf(value) > -1)
10838 if (empty(
$conf->browser->layout) ||
$conf->browser->layout !=
'phone') {
10840 $(".dropdown dt a").on("click", function () {
10841 console.log("Click on dropdown, we set focus to search field");
10842 setTimeout(() => { $(\'.inputsearch_dropdownselectedfields\').focus(); }, 200);
10866 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
10869 $categories = $cat->containing(
$id, $type);
10871 if ($rendermode == 1 || $rendermode == 2) {
10872 $toprint = array();
10873 foreach ($categories as
$c) {
10874 $ways =
$c->print_all_ways(
'auto', ($nolink ?
'none' :
''), 0, 1, ($rendermode == 2 ? 0 : 1));
10875 foreach ($ways as $way) {
10876 $color =
$c->color;
10877 $sfortag =
'<li class="select2-search-choice-dolibarr noborderoncategories'.(empty($toprint) ?
' nomarginleft' :
'');
10878 $forced_color =
'categtextwhite';
10880 $forced_color =
'categtextblack';
10882 $sfortag .=
' '.$forced_color;
10884 $sfortag .= ($color ?
' style="background: #' . $color .
';"' :
' style="background: #bbb"');
10885 $titlestring = $ways[0];
10889 if ($rendermode == 1) {
10890 $sfortag .=
'<a href="'.DOL_URL_ROOT.
'/categories/viewcat.php?id='.((int)
$c->id).
'&type='.urlencode(
$c->type).
'" class="'.$forced_color.
'">';
10891 $sfortag .=
img_picto(
'',
'category',
'class="paddingright"');
10892 if (
$conf->dol_optimize_smallscreen) {
10897 $sfortag .=
'</a>';
10901 $sfortag .=
'</li>';
10903 $toprint[] = $sfortag;
10906 if (empty($toprint)) {
10909 return '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
10913 if ($rendermode == 0) {
10914 $arrayselected = array();
10915 $cate_arbo = $this->select_all_categories($type,
'',
'parent', 64, 0, 3);
10916 foreach ($categories as
$c) {
10917 $arrayselected[(
string)
$c->id] = (
string)
$c->id;
10920 return $this->multiselectarray(
'categories', $cate_arbo, $arrayselected, 0, 0,
'', 0,
'100%',
'disabled',
'category');
10923 return 'ErrorBadValueForParameterRenderMode';
10937 global
$conf, $langs, $hookmanager;
10943 $object->fetchObjectLinked();
10946 $hookmanager->initHooks(array(
'commonobject'));
10947 $parameters = array(
10948 'morehtmlright' => $morehtmlright,
10949 'compatibleImportElementsList' => &$compatibleImportElementsList,
10951 $reshook = $hookmanager->executeHooks(
'showLinkedObjectBlock', $parameters,
$object, $action);
10953 $nbofdifferenttypes = count(
$object->linkedObjects);
10955 if (empty($reshook)) {
10956 print
'<!-- showLinkedObjectBlock -->';
10957 print
load_fiche_titre($langs->trans($title), $morehtmlright,
'', 0,
'',
'showlinkedobjectblock');
10960 print
'<div class="div-table-responsive-no-min">';
10961 print
'<table class="noborder allwidth" data-block="showLinkedObject" data-element="' .
$object->element .
'" data-elementid="' .
$object->id .
'" >';
10963 print
'<tr class="liste_titre">';
10964 print
'<td>' . $langs->trans(
"Type") .
'</td>';
10965 print
'<td>' . $langs->trans(
"Ref") .
'</td>';
10968 print
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
10969 print
'<td class="right">' . $langs->trans(
"Status") .
'</td>';
10973 $nboftypesoutput = 0;
10975 foreach (
$object->linkedObjects as $objecttype => $objects) {
10976 $tplpath = $element = $subelement = $objecttype;
10979 global $showImportButton;
10980 $showImportButton =
false;
10981 if (!empty($compatibleImportElementsList) && in_array($element, $compatibleImportElementsList)) {
10982 $showImportButton =
true;
10987 if ($objecttype !=
'supplier_proposal' && preg_match(
'/^([^_]+)_([^_]+)/i', $objecttype, $regs)) {
10988 $element = $regs[1];
10989 $subelement = $regs[2];
10990 $tplpath = $element .
'/' . $subelement;
10992 $tplname =
'linkedobjectblock';
10995 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $objecttype, $regs)) {
10996 $element = $regs[1];
10997 $module = $regs[2];
10998 $tplpath = $module.
'/' . $element;
10999 $tplname = $tplname.
'_'.$element;
11003 if ($objecttype ==
'facture') {
11004 $tplpath =
'compta/' . $element;
11008 } elseif ($objecttype ==
'facturerec') {
11009 $tplpath =
'compta/facture';
11010 $tplname =
'linkedobjectblockForRec';
11014 } elseif ($objecttype ==
'propal') {
11015 $tplpath =
'comm/' . $element;
11019 } elseif ($objecttype ==
'supplier_proposal') {
11023 } elseif ($objecttype ==
'shipping' || $objecttype ==
'shipment' || $objecttype ==
'expedition') {
11024 $tplpath =
'expedition';
11028 } elseif ($objecttype ==
'reception') {
11029 $tplpath =
'reception';
11033 } elseif ($objecttype ==
'delivery') {
11034 $tplpath =
'delivery';
11038 } elseif ($objecttype ==
'ficheinter') {
11039 $tplpath =
'fichinter';
11043 } elseif ($objecttype ==
'invoice_supplier') {
11044 $tplpath =
'fourn/facture';
11045 } elseif ($objecttype ==
'order_supplier') {
11046 $tplpath =
'fourn/commande';
11047 } elseif ($objecttype ==
'expensereport') {
11048 $tplpath =
'expensereport';
11049 } elseif ($objecttype ==
'subscription') {
11050 $tplpath =
'adherents';
11051 } elseif ($objecttype ==
'conferenceorbooth') {
11052 $tplpath =
'eventorganization';
11053 } elseif ($objecttype ==
'conferenceorboothattendee') {
11054 $tplpath =
'eventorganization';
11055 } elseif ($objecttype ==
'mo') {
11060 } elseif ($objecttype ==
'project_task') {
11061 $tplpath =
'projet/tasks';
11064 global $linkedObjectBlock;
11065 $linkedObjectBlock = $objects;
11068 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array(
'/' . $tplpath .
'/tpl'));
11070 foreach ($dirtpls as $reldir) {
11071 $reldir = rtrim($reldir,
'/');
11072 if ($nboftypesoutput == ($nbofdifferenttypes - 1)) {
11073 global $noMoreLinkedObjectBlockAfter;
11074 $noMoreLinkedObjectBlockAfter = 1;
11076 $file =
dol_buildpath($reldir .
'/' . $tplname .
'.tpl.php');
11077 if (file_exists($file)) {
11078 $res = @include $file;
11080 $nboftypesoutput++;
11087 if (!$nboftypesoutput) {
11088 print
'<tr><td colspan="7"><span class="opacitymedium">' . $langs->trans(
"None") .
'</span></td></tr>';
11093 if (!empty($compatibleImportElementsList)) {
11094 $res = @include
dol_buildpath(
'core/tpl/objectlinked_lineimport.tpl.php');
11100 return $nbofdifferenttypes;
11114 global
$conf, $langs, $hookmanager, $form;
11119 if (empty($form)) {
11120 $form =
new Form($this->db);
11124 $linktoelemlist =
'';
11125 $listofidcompanytoscan =
'';
11127 if (!is_object(
$object->thirdparty)) {
11128 if (
$object->element ==
'subscription' && isset(
$object->fk_adherent)) {
11134 $fk_adherent = $subby->fk_adherent;
11135 $adh->fetch($fk_adherent);
11136 $thirdparty_id = $adh->fetch_thirdparty();
11139 $thirdparty_id =
$object->thirdparty->id;
11142 $possiblelinks = array();
11144 $dontIncludeCompletedItems =
getDolGlobalString(
'DONT_INCLUDE_COMPLETED_ELEMENTS_LINKS');
11146 if (!empty($thirdparty_id) && $thirdparty_id > 0) {
11147 $listofidcompanytoscan = (int) $thirdparty_id;
11149 $listofidcompanytoscan .=
',' . (int)
$object->thirdparty->parent;
11152 include_once DOL_DOCUMENT_ROOT .
'/projet/class/project.class.php';
11153 $tmpproject =
new Project($this->db);
11154 $tmpproject->fetch((
int)
$object->fk_project);
11155 if ($tmpproject->socid > 0 && ($tmpproject->socid != $thirdparty_id)) {
11156 $listofidcompanytoscan .=
',' . (int) $tmpproject->socid;
11158 unset($tmpproject);
11161 $possiblelinks = array(
11165 'label' =>
'LinkToProposal',
11166 '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' :
''),
11168 'shipping' => array(
11171 'label' =>
'LinkToExpedition',
11172 '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' :
''),
11177 'label' =>
'LinkToOrder',
11178 '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' :
''),
11179 'linkname' =>
'commande',
11181 'subscription' => array(
11184 'label' =>
'LinkToMemberSubscription',
11185 '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') .
')',
11186 'linkname' =>
'subscription',
11188 'conferenceorboothattendee' => array(
11191 'label' =>
'LinkToConferenceOrBoothAttendee',
11192 '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 " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"eventorganization_conferenceorboothattendee as a WHERE a.fk_soc = s.rowid AND a.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND s.entity IN (' .
getEntity(
'conferenceorboothattendee') .
')' . (empty(
$object->fk_project) ?
'' :
' AND a.fk_project = ' . (int)
$object->fk_project),
11193 'linkname' =>
'attendee'
11195 'invoice' => array(
11198 'label' =>
'LinkToInvoice',
11199 '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' :
''),
11200 'linkname' =>
'facture',
11202 'invoice_template' => array(
11205 'label' =>
'LinkToTemplateInvoice',
11206 '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') .
')',
11208 'contrat' => array(
11211 'label' =>
'LinkToContract',
11212 '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
11213 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',
11215 'fichinter' => array(
11218 'label' =>
'LinkToIntervention',
11219 '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') .
')',
11221 'supplier_proposal' => array(
11224 'label' =>
'LinkToSupplierProposal',
11225 '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' :
''),
11227 'order_supplier' => array(
11230 'label' =>
'LinkToSupplierOrder',
11231 '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' :
''),
11233 'invoice_supplier' => array(
11235 'perms' => 1,
'label' =>
'LinkToSupplierInvoice',
11236 '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' :
''),
11241 'label' =>
'LinkToTicket',
11242 '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' :
''),
11247 'label' =>
'LinkToMo',
11248 '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' :
''),
11253 if (
$object->table_element ==
'commande_fournisseur') {
11254 $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' :
'');
11255 } elseif (
$object->table_element ==
'mrp_mo') {
11256 $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' :
'');
11260 if (!empty($listofidcompanytoscan)) {
11262 $hookmanager->initHooks(array(
'commonobject'));
11263 $parameters = array(
'listofidcompanytoscan' => $listofidcompanytoscan,
'possiblelinks' => $possiblelinks);
11264 $reshook = $hookmanager->executeHooks(
'showLinkToObjectBlock', $parameters,
$object, $action);
11267 if (empty($reshook)) {
11268 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
11269 $possiblelinks = array_merge($possiblelinks, $hookmanager->resArray);
11271 } elseif ($reshook > 0) {
11272 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
11273 $possiblelinks = $hookmanager->resArray;
11277 if (!empty($possiblelinks)) {
11278 $object->fetchObjectLinked();
11282 $htmltoenteralink =
'';
11283 foreach ($possiblelinks as $key => $possiblelink) {
11285 if (empty($possiblelink[
'enabled'])) {
11292 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $key, $regs)) {
11294 $module = $regs[2];
11297 if (!empty($possiblelink[
'perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || !in_array($key, $excludelinksto))) {
11298 $htmltoenteralink .=
'<div id="' . $key .
'list"' . (empty(
$conf->use_javascript_ajax) ?
'' :
' style="display:none"') .
'>';
11302 $htmltoenteralink .=
'<br>'.
"\n";
11303 $htmltoenteralink .=
'<!-- form to add a link from anywhere -->'.
"\n";
11304 $htmltoenteralink .=
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinkedbyref' . $key .
'">';
11305 $htmltoenteralink .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
11306 $htmltoenteralink .=
'<input type="hidden" name="action" value="addlinkbyref">';
11307 $htmltoenteralink .=
'<input type="hidden" name="id" value="' .
$object->id .
'">';
11308 $htmltoenteralink .=
'<input type="hidden" name="addlink" value="' . $key .(!empty($module) ?
'@'.$module :
'').
'">';
11309 $htmltoenteralink .=
'<table class="noborder">';
11310 $htmltoenteralink .=
'<tr class="liste_titre">';
11312 $htmltoenteralink .=
'<td class="center"><input type="text" placeholder="'.dol_escape_htmltag($langs->trans(
"Ref")).
'" name="reftolinkto" value="' .
dol_escape_htmltag(
GETPOST(
'reftolinkto',
'alpha')) .
'">';
11313 $htmltoenteralink .=
'<br>';
11314 $htmltoenteralink .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
'ToLink') .
'"> ';
11315 $htmltoenteralink .=
'<input type="submit" class="button smallpaddingimp" name="cancel" value="' . $langs->trans(
'Cancel') .
'">';
11316 $htmltoenteralink .=
'</td>';
11317 $htmltoenteralink .=
'</tr>';
11318 $htmltoenteralink .=
'</table>';
11319 $htmltoenteralink .=
'</form>';
11322 $sql = $possiblelink[
'sql'];
11324 $resqllist = $this->db->query($sql);
11326 $num = $this->db->num_rows($resqllist);
11331 $htmltoenteralink .=
'<br>';
11333 $htmltoenteralink .=
'<!-- form to add a link from object to same thirdparty -->'.
"\n";
11334 $htmltoenteralink .=
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinked' . $key .
'">';
11335 $htmltoenteralink .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
11336 $htmltoenteralink .=
'<input type="hidden" name="action" value="addlink">';
11337 $htmltoenteralink .=
'<input type="hidden" name="id" value="' .
$object->id .
'">';
11338 $htmltoenteralink .=
'<input type="hidden" name="addlink" value="' . $key . (!empty($module) ?
'@'.$module :
'').
'">';
11339 $htmltoenteralink .=
'<table class="noborder">';
11342 case 'conferenceorboothattendee':
11344 $htmltoenteralink .= $this->makeAddLinkToAttendee(
$object, $key, $possiblelink, $num, $resqllist);
11349 $htmltoenteralink .= $this->makeAddLinkToObject(
$object, $key, $possiblelink, $num, $resqllist);
11353 $htmltoenteralink .=
'</table>';
11354 $htmltoenteralink .=
'<div class="center">';
11356 $htmltoenteralink .=
'<input type="submit" class="button valignmiddle marginleftonly marginrightonly smallpaddingimp" value="' . $langs->trans(
'ToLink') .
'">';
11358 if (empty(
$conf->use_javascript_ajax)) {
11359 $htmltoenteralink .=
'<input type="submit" class="button button-cancel marginleftonly marginrightonly smallpaddingimp" name="cancel" value="' . $langs->trans(
"Cancel") .
'"></div>';
11361 $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>';
11363 $htmltoenteralink .=
'</form>';
11366 $this->db->free($resqllist);
11370 $htmltoenteralink .=
'</div>';
11375 $linktoelemlist .=
'<li><a href="#linkto' . $key .
'" class="linkto dropdowncloseonclick" rel="' . $key .
'">' . $langs->trans($possiblelink[
'label']) .
' (' . $num .
')</a></li>';
11378 $linktoelemlist .=
'<li><span class="linktodisabled">' . $langs->trans($possiblelink[
'label']) .
' (0)</span></li>';
11383 if ($linktoelemlist) {
11385 <dl class="dropdown" id="linktoobjectname">
11387 if (!empty(
$conf->use_javascript_ajax)) {
11388 $linktoelem .=
'<dt><a href="#linktoobjectname"><span class="fas fa-link paddingrightonly"></span>' . $langs->trans(
"LinkTo") .
'...</a></dt>';
11390 $linktoelem .=
'<dd>
11391 <div class="multiselectlinkto">
11392 <ul class="ulselectedfields">' . $linktoelemlist .
'
11401 if (!empty(
$conf->use_javascript_ajax)) {
11402 print
'<!-- Add js to show linkto box -->
11403 <script nonce="' .
getNonce() .
'">
11404 jQuery(document).ready(function() {
11405 jQuery(".linkto").click(function() {
11406 console.log("We choose to show/hide links for rel="+jQuery(this).attr(\'rel\')+" so #"+jQuery(this).attr(\'rel\')+"list");
11407 jQuery("#"+jQuery(this).attr(\'rel\')+"list").toggle();
11415 return array(
'linktoelem' => $linktoelem,
'htmltoenteralink' => $htmltoenteralink);
11417 print $htmltoenteralink;
11420 return $linktoelem;
11437 public function selectyesno($htmlname, $value =
'', $option = 0, $disabled =
false, $useempty = 0, $addjscombo = 0, $morecss =
'yesno width75', $labelyes =
'Yes', $labelno =
'No')
11448 $disabled = ($disabled ?
' disabled' :
'');
11450 $resultyesno =
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'"' . $disabled .
'>' .
"\n";
11452 $resultyesno .=
'<option value="-1"' . (($value < 0) ?
' selected' :
'') .
'> </option>' .
"\n";
11454 if ((
"$value" ==
'yes') || ($value == 1)) {
11455 $resultyesno .=
'<option value="' . $yes .
'" selected>' . $langs->trans($labelyes) .
'</option>' .
"\n";
11456 $resultyesno .=
'<option value="' . $no .
'">' . $langs->trans($labelno) .
'</option>' .
"\n";
11458 $selected = (($useempty && $value !=
'0' && $value !=
'no') ?
'' :
' selected');
11459 $resultyesno .=
'<option value="' . $yes .
'">' . $langs->trans($labelyes) .
'</option>' .
"\n";
11460 $resultyesno .=
'<option value="' . $no .
'"' . $selected .
'>' . $langs->trans($labelno) .
'</option>' .
"\n";
11462 $resultyesno .=
'</select>' .
"\n";
11465 $resultyesno .=
ajax_combobox($htmlname, array(), 0, 0,
'resolve', ($useempty < 0 ? (
string) $useempty :
'-1'), $morecss);
11468 return $resultyesno;
11485 $sql =
"SELECT rowid, label";
11486 $sql .=
" FROM " . $this->db->prefix() .
"export_model";
11487 $sql .=
" WHERE type = '" . $this->db->escape($type) .
"'";
11488 $sql .=
" ORDER BY rowid";
11489 $result = $this->db->query($sql);
11491 print
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
11493 print
'<option value="-1"> </option>';
11496 $num = $this->db->num_rows($result);
11498 while ($i < $num) {
11499 $obj = $this->db->fetch_object($result);
11500 if ($selected == $obj->rowid) {
11501 print
'<option value="' . $obj->rowid .
'" selected>';
11503 print
'<option value="' . $obj->rowid .
'">';
11533 public function showrefnav(
$object, $paramid, $morehtml =
'', $shownav = 1, $fieldid =
'rowid', $fieldref =
'ref', $morehtmlref =
'', $moreparam =
'', $nodbprefix = 0, $morehtmlleft =
'', $morehtmlstatus =
'', $morehtmlright =
'')
11535 global
$conf, $langs, $hookmanager, $extralanguages;
11538 if (empty($fieldid)) {
11539 $fieldid =
'rowid';
11541 if (empty($fieldref)) {
11546 $addgendertxt =
'';
11547 if (property_exists(
$object,
'gender') && !empty(
$object->gender)) {
11548 $addgendertxt =
' ';
11551 $addgendertxt .=
'<i class="fas fa-mars valignmiddle"></i>';
11554 $addgendertxt .=
'<i class="fas fa-venus valignmiddle"></i>';
11557 $addgendertxt .=
'<i class="fas fa-transgender valignmiddle"></i>';
11563 if (is_object($hookmanager)) {
11564 $parameters = array(
'showrefnav' =>
true);
11565 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters,
$object);
11566 if (!empty($hookmanager->resPrint)) {
11567 if (empty(
$object->next_prev_filter) && preg_match(
'/^\s*AND/i', $hookmanager->resPrint)) {
11568 $object->next_prev_filter = (
string) preg_replace(
'/^\s*AND\s*/i',
'', $hookmanager->resPrint);
11569 } elseif (!empty(
$object->next_prev_filter) && !preg_match(
'/^\s*AND/i', $hookmanager->resPrint)) {
11570 $object->next_prev_filter .=
' AND '.$hookmanager->resPrint;
11572 $object->next_prev_filter .= $hookmanager->resPrint;
11577 $previous_ref = $next_ref =
'';
11580 $object->load_previous_next_ref((isset(
$object->next_prev_filter) ?
$object->next_prev_filter :
''), $fieldid, $nodbprefix);
11582 $navurl = $_SERVER[
"PHP_SELF"];
11585 if ($paramid ==
'api_token_card') {
11586 if (preg_match(
'/\/user\/api_token/', $navurl)) {
11587 $navurl = preg_replace(
'/card/',
'list', $navurl);
11593 if ($paramid ==
'project_ref') {
11594 if (preg_match(
'/\/tasks\/(task|contact|note|document)\.php/', $navurl)) {
11595 $navurl = preg_replace(
'/\/tasks\/(task|contact|time|note|document)\.php/',
'/tasks.php', $navurl);
11600 $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>';
11601 $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>';
11605 $ret .=
'<!-- Start banner content --><div style="vertical-align: middle">';
11608 if ($morehtmlright) {
11609 $ret .=
'<div class="inline-block floatleft">' . $morehtmlright .
'</div>';
11612 if ($previous_ref || $next_ref || $morehtml) {
11613 $ret .=
'<div class="pagination paginationref"><ul class="right">';
11615 if ($morehtml &&
getDolGlobalInt(
'MAIN_OPTIMIZEFORTEXTBROWSER') < 2) {
11616 $ret .=
'<!-- morehtml --><li class="noborder litext' . (($shownav && $previous_ref && $next_ref) ?
' clearbothonsmartphone' :
'') .
'">' . $morehtml .
'</li>';
11618 if ($shownav && ($previous_ref || $next_ref)) {
11619 $ret .=
'<li class="pagination">' . $previous_ref .
'</li>';
11620 $ret .=
'<li class="pagination">' . $next_ref .
'</li>';
11622 if ($previous_ref || $next_ref || $morehtml) {
11623 $ret .=
'</ul></div>';
11627 $parameters = array(
'morehtmlstatus' => $morehtmlstatus);
11628 $reshook = $hookmanager->executeHooks(
'moreHtmlStatus', $parameters,
$object);
11629 if (empty($reshook)) {
11630 $morehtmlstatus .= $hookmanager->resPrint;
11632 $morehtmlstatus = $hookmanager->resPrint;
11634 if ($morehtmlstatus) {
11635 $ret .=
'<!-- status --><div class="statusref">' . $morehtmlstatus .
'</div>';
11638 $parameters = array();
11639 $reshook = $hookmanager->executeHooks(
'moreHtmlRef', $parameters,
$object);
11640 if (empty($reshook)) {
11641 $morehtmlref .= $hookmanager->resPrint;
11642 } elseif ($reshook > 0) {
11643 $morehtmlref = $hookmanager->resPrint;
11647 if ($morehtmlleft) {
11648 if (
$conf->browser->layout ==
'phone') {
11649 $ret .=
'<!-- morehtmlleft --><div class="floatleft">' . $morehtmlleft .
'</div>';
11651 $ret .=
'<!-- morehtmlleft --><div class="inline-block floatleft">' . $morehtmlleft .
'</div>';
11656 $ret .=
'<!-- Ref or ID --><div class="inline-block floatleft valignmiddle maxwidth750 marginbottomonly refid' . (($shownav && ($previous_ref || $next_ref)) ?
' refidpadding' :
'') .
'">';
11659 if (
$object->element ==
'societe') {
11660 $ret .=
'<span class="valignmiddle">'.dolPrintHTML((
string)
$object->name).
'</span>';
11663 $arrayoflangcode = array();
11668 if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
11669 if (!is_object($extralanguages)) {
11670 include_once DOL_DOCUMENT_ROOT .
'/core/class/extralanguages.class.php';
11673 $extralanguages->fetch_name_extralanguages(
'societe');
11677 if (!empty($extralanguages->attributes[
'societe']) && !empty($extralanguages->attributes[
'societe'][
'name'])) {
11678 $object->fetchValuesForExtraLanguages();
11682 foreach ($arrayoflangcode as $extralangcode) {
11684 if (
$object->array_languages[
'name'][$extralangcode]) {
11685 $htmltext .=
$object->array_languages[
'name'][$extralangcode];
11687 $htmltext .=
'<span class="opacitymedium">' . $langs->trans(
"SwitchInEditModeToAddTranslation") .
'</span>';
11690 $ret .=
'<!-- Show translations of name -->' .
"\n";
11691 $ret .= $this->textwithpicto(
'', $htmltext, -1,
'language',
'opacitymedium paddingleft');
11694 } elseif (
$object->element ==
'member') {
11695 '@phan-var-force Adherent $object';
11696 $ret .=
$object->ref .
'<br>';
11697 $fullname =
$object->getFullName($langs);
11699 $ret .=
'<span class="valignmiddle">'.dolPrintHTML((
string)
$object->societe) . ((!empty($fullname) &&
$object->societe != $fullname) ?
' (' .
dol_htmlentities($fullname) . $addgendertxt .
')' :
'').
'</span>';
11701 $ret .=
'<span class="valignmiddle">'.dolPrintHTML($fullname) . $addgendertxt . ((!empty(
$object->societe) &&
$object->societe != $fullname) ?
' (' .
dol_htmlentities((
string)
$object->societe) .
')' :
'').
'</span>';
11703 } elseif (in_array(
$object->element, array(
'contact',
'user'))) {
11704 $ret .=
'<span class="valignmiddle">'.dolPrintHTML(
$object->getFullName($langs)).
'</span>'.$addgendertxt;
11705 } elseif (
$object->element ==
'usergroup') {
11707 } elseif (in_array(
$object->element, array(
'action',
'agenda'))) {
11708 '@phan-var-force ActionComm $object';
11710 } elseif (in_array(
$object->element, array(
'adherent_type'))) {
11712 } elseif (
$object->element ==
'ecm_directories') {
11714 } elseif (
$object->element ==
'accountingbookkeeping' && !empty(
$object->context[
'mode']) &&
$object->context[
'mode'] ==
'_tmp') {
11715 $ret .=
'<span class="valignmiddle">'.$langs->trans(
"Draft").
'</span>';
11717 '@phan-var-force Ticket $object';
11718 $ret .=
'<span class="valignmiddle">'.dolPrintHTML(!empty(
$object->$fieldref) ?
$object->$fieldref :
"").
'</span>';
11719 $ret .=
' <span class="nobold small" title="'.dolPrintHTMLForAttribute($langs->trans(
"TicketTrackId")).
'">('.
$object->track_id.
')</span>';
11720 } elseif ($fieldref !=
'none') {
11722 $ret .=
'<span class="valignmiddle">'.dolPrintHTML(!empty(
$object->$fieldref) ?
$object->$fieldref :
"").
'</span>';
11724 if ($morehtmlref) {
11726 if (substr($morehtmlref, 0, 4) !=
'<div') {
11730 $ret .=
'<!-- morehtmlref -->'.$morehtmlref;
11735 $ret .=
'</div><!-- End banner content -->';
11752 if (empty(
$object->barcode)) {
11757 if (empty(
$object->barcode_type_code) || empty(
$object->barcode_type_coder)) {
11759 $result =
$object->fetchBarCode();
11762 return '<!-- ErrorFetchBarcode -->';
11767 $url = DOL_URL_ROOT .
'/viewimage.php?modulepart=barcode&generator=' . urlencode(
$object->barcode_type_coder) .
'&code=' . urlencode(
$object->barcode) .
'&encoding=' . urlencode(
$object->barcode_type_code);
11768 $out =
'<!-- url barcode = ' . $url .
' -->';
11769 $out .=
'<img src="' . $url .
'"' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
'>';
11792 public static function showphoto($modulepart,
$object, $width = 100, $height = 0, $caneditfield = 0, $cssclass =
'photowithmargin', $imagesize =
'', $addlinktofullsize = 1, $cache = 0, $forcecapture =
'', $noexternsourceoverwrite = 0, $usesharelinkifavailable = 0)
11801 $originalfile =
'';
11805 if ($modulepart ==
'societe') {
11806 $dir =
$conf->societe->multidir_output[$entity];
11809 if ((
string) $imagesize ==
'mini') {
11811 } elseif ((
string) $imagesize ==
'small') {
11820 } elseif ($modulepart ==
'contact') {
11821 $dir =
$conf->societe->multidir_output[$entity] .
'/contact';
11823 if (!empty($photo)) {
11825 if ((
string) $imagesize ==
'mini') {
11827 } elseif ((
string) $imagesize ==
'small') {
11832 $originalfile =
get_exdir(0, 0, 0, 0,
$object,
'contact') .
'photos/' . $photo;
11837 } elseif ($modulepart ==
'userphoto') {
11838 $dir =
$conf->user->dir_output;
11840 if (!empty($photo)) {
11842 if ((
string) $imagesize ==
'mini') {
11844 } elseif ((
string) $imagesize ==
'small') {
11849 $originalfile =
get_exdir(0, 0, 0, 0,
$object,
'user') .
'photos/' . $photo;
11853 $altfile =
$object->id .
".jpg";
11857 } elseif ($modulepart ==
'memberphoto') {
11858 $dir =
$conf->member->dir_output;
11860 if (!empty($photo)) {
11862 if ((
string) $imagesize ==
'mini') {
11864 } elseif ((
string) $imagesize ==
'small') {
11869 $originalfile =
get_exdir(0, 0, 0, 0,
$object,
'member') .
'photos/' . $photo;
11873 $altfile =
$object->id .
".jpg";
11880 if ($modulepart !=
"unknown" && method_exists(
$object,
'getDataToShowPhoto')) {
11881 $tmpdata =
$object->getDataToShowPhoto($modulepart, $imagesize);
11883 $dir = $tmpdata[
'dir'];
11884 $file = $tmpdata[
'file'];
11885 $originalfile = $tmpdata[
'originalfile'];
11886 $altfile = $tmpdata[
'altfile'];
11887 $email = $tmpdata[
'email'];
11888 $capture = $tmpdata[
'capture'];
11892 if ($forcecapture) {
11893 $capture = $forcecapture;
11899 if ($file && file_exists($dir .
"/" . $file)) {
11900 if ($addlinktofullsize) {
11902 if ($urladvanced) {
11903 $ret .=
'<a href="' . $urladvanced .
'">';
11905 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
11910 if ($usesharelinkifavailable) {
11912 $relativefileforecm = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT.
'/',
'/').
'/',
'', $dir.
'/'.$originalfile);
11914 require_once DOL_DOCUMENT_ROOT .
'/ecm/class/ecmfiles.class.php';
11916 $ecmfiles->fetch(0,
'', $relativefileforecm);
11918 $sharekey = (
string) $ecmfiles->share;
11921 if (!empty($sharekey)) {
11922 $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) .
'">';
11924 $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) .
'">';
11926 if ($addlinktofullsize) {
11929 } elseif ($altfile && file_exists($dir .
"/" . $altfile)) {
11930 if ($addlinktofullsize) {
11932 if ($urladvanced) {
11933 $ret .=
'<a href="' . $urladvanced .
'">';
11935 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
11938 $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) .
'">';
11939 if ($addlinktofullsize) {
11943 $nophoto =
'/public/theme/common/nophoto.png';
11944 $defaultimg =
'identicon';
11945 if (in_array($modulepart, array(
'societe',
'userphoto',
'contact',
'memberphoto'))) {
11946 if ($modulepart ==
'societe' || ($modulepart ==
'memberphoto' && !empty(
$object->morphy) && strpos(
$object->morphy,
'mor') !==
false)) {
11947 $nophoto =
'company';
11949 $nophoto =
'/public/theme/common/user_anonymous.png';
11951 $nophoto =
'/public/theme/common/user_man.png';
11954 $nophoto =
'/public/theme/common/user_woman.png';
11959 if (
isModEnabled(
'gravatar') && $email && empty($noexternsourceoverwrite)) {
11961 $ret .=
'<!-- Put link to gravatar -->';
11962 $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 .
'">';
11964 if ($nophoto ==
'company') {
11965 $ret .=
'<div class="divforspanimg valignmiddle inline-block center photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
'>' .
img_picto(
'',
'company') .
'</div>';
11968 $ret .=
'<img class="photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="' . DOL_URL_ROOT . $nophoto .
'">';
11973 if ($caneditfield) {
11977 $ret .=
'<table class="nobordernopadding centpercent">';
11979 $ret .=
'<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> <label for="photodelete">' . $langs->trans(
"Delete") .
'</label><br><br></td></tr>';
11981 $ret .=
'<tr><td class="tdoverflow">';
11983 $maxmin = $maxfilesizearray[
'maxmin'];
11985 $ret .=
'<input type="hidden" name="MAX_FILE_SIZE" value="' . ($maxmin * 1024) .
'">';
11987 $ret .=
'<input type="file" class="flat maxwidth200onsmartphone" name="photo" id="photoinput" accept="image/*"' . ($capture ?
' capture="' .
dolPrintHTMLForAttribute($capture) .
'"' :
'') .
'>';
11988 $ret .=
'</td></tr>';
11989 $ret .=
'</table>';
12014 public function select_dolgroups($selected = 0, $htmlname =
'groupid', $show_empty = 0, $exclude =
'', $disabled = 0, $include =
'', $enableonly = array(), $force_entity =
'0', $multiple =
false, $morecss =
'minwidth200')
12017 global
$conf, $user, $langs;
12020 $excludeGroups =
null;
12021 if (is_array($exclude)) {
12022 $excludeGroups = implode(
",", $exclude);
12025 $includeGroups =
null;
12026 if (is_array($include)) {
12027 $includeGroups = implode(
",", $include);
12030 if (!is_array($selected)) {
12031 $selected = array($selected);
12037 $sql =
"SELECT ug.rowid, ug.nom as name";
12038 if (
isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && !$user->entity) {
12039 $sql .=
", e.label";
12041 $sql .=
" FROM " . $this->db->prefix() .
"usergroup as ug ";
12042 if (
isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && !$user->entity) {
12043 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid=ug.entity";
12044 if ($force_entity) {
12045 $sql .=
" WHERE ug.entity IN (0, " . ((int) $force_entity) .
")";
12047 $sql .=
" WHERE ug.entity IS NOT NULL";
12050 $sql .=
" WHERE ug.entity IN (0, " . ((int)
$conf->entity) .
")";
12052 if (is_array($exclude) && $excludeGroups) {
12053 $sql .=
" AND ug.rowid NOT IN (" . $this->db->sanitize($excludeGroups) .
")";
12055 if (is_array($include) && $includeGroups) {
12056 $sql .=
" AND ug.rowid IN (" . $this->db->sanitize($includeGroups) .
")";
12058 $sql .=
" ORDER BY ug.nom ASC";
12060 dol_syslog(get_class($this) .
"::select_dolgroups", LOG_DEBUG);
12061 $resql = $this->db->query($sql);
12064 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
12066 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
12068 $num = $this->db->num_rows($resql);
12071 if ($show_empty && !$multiple) {
12072 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'> </option>' .
"\n";
12075 while ($i < $num) {
12076 $obj = $this->db->fetch_object($resql);
12078 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
12082 $label = $obj->name;
12083 $labelhtml = $obj->name;
12085 $label .=
" (" . $obj->label .
")";
12086 $labelhtml .=
' <span class="opacitymedium">(' . $obj->label .
')</span>';
12089 $out .=
'<option value="' . $obj->rowid .
'"';
12090 if ($disableline) {
12091 $out .=
' disabled';
12093 if ((isset($selected[0]) && is_object($selected[0]) && $selected[0]->
id == $obj->rowid)
12094 || ((!isset($selected[0]) || !is_object($selected[0])) && !empty($selected) && in_array($obj->rowid, $selected))) {
12095 $out .=
' selected';
12097 $out .=
' data-html="'.dol_escape_htmltag($labelhtml).
'"';
12100 $out .=
'</option>';
12105 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'></option>' .
"\n";
12107 $out .=
'<option value="" disabled>' . $langs->trans(
"NoUserGroupDefined") .
'</option>';
12109 $out .=
'</select>';
12128 $out =
'<div class="nowraponall">';
12129 $out .=
'<button type="submit" class="liste_titre button_search reposition" name="button_search_x" value="x"><span class="fas fa-search"></span></button>';
12130 $out .=
'<button type="submit" class="liste_titre button_removefilter reposition" name="button_removefilter_x" value="x"><span class="fas fa-times"></span></button>';
12144 public function showCheckAddButtons($cssclass =
'checkforaction', $calljsfunction = 0, $massactionname =
"massaction")
12150 if (!empty(
$conf->use_javascript_ajax)) {
12151 $out .=
'<div class="inline-block checkallactions"><input type="checkbox" id="' . $cssclass .
's" name="' . $cssclass .
's" class="checkallactions"></div>';
12153 $out .=
'<script nonce="' .
getNonce() .
'">
12154 $(document).ready(function() {
12155 $("#' . $cssclass .
's").click(function() {
12156 if($(this).is(\':checked\')){
12157 console.log("We check all ' . $cssclass .
' and trigger the change method");
12158 $(".' . $cssclass .
'").prop(\'checked\', true).trigger(\'change\');
12162 console.log("We uncheck all");
12163 $(".' . $cssclass .
'").prop(\'checked\', false).trigger(\'change\');
12165 if ($calljsfunction) {
12166 $out .=
'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0, "' . $massactionname .
'", "' . $cssclass .
'"); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }';
12170 $(".' . $cssclass .
'").change(function() {
12171 console.log("We check and change the tr class highlight after a change on .'.$cssclass.
'");
12172 var $row = $(this).closest("tr");
12174 var anyChecked = $row.find(\'input[type="checkbox"].checkforselect:checked\').length > 0;
12175 console.log("anychecked="+anyChecked);
12177 $row.removeClass("highlight");
12179 $row.addClass("highlight");
12201 $out = $this->showFilterButtons();
12202 if ($addcheckuncheckall) {
12203 $out .= $this->showCheckAddButtons($cssclass, $calljsfunction, $massactionname);
12221 public function selectExpenseCategories($selected =
'', $htmlname =
'fk_c_exp_tax_cat', $useempty = 0, $excludeid = array(), $target =
'', $default_selected = 0, $params = array(), $info_admin = 1)
12223 global $langs, $user;
12226 $sql =
"SELECT rowid, label FROM " . $this->db->prefix() .
"c_exp_tax_cat WHERE active = 1";
12227 $sql .=
" AND entity IN (0," .
getEntity(
'exp_tax_cat') .
")";
12228 if (!empty($excludeid)) {
12229 $sql .=
" AND rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeid)) .
")";
12231 $sql .=
" ORDER BY label";
12233 $resql = $this->db->query($sql);
12235 $out =
'<select id="select_' . $htmlname .
'" name="' . $htmlname .
'" class="' . $htmlname .
' flat minwidth75imp maxwidth200">';
12237 $out .=
'<option value="0"> </option>';
12240 while ($obj = $this->db->fetch_object($resql)) {
12241 $out .=
'<option ' . ($selected == $obj->rowid ?
'selected="selected"' :
'') .
' value="' . $obj->rowid .
'">' . $langs->trans($obj->label) .
'</option>';
12243 $out .=
'</select>';
12246 if (!empty($htmlname) && $user->admin && $info_admin) {
12247 $out .=
' ' .
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
12250 if (!empty($target)) {
12251 $sql =
"SELECT c.id FROM " . $this->db->prefix() .
"c_type_fees as c WHERE c.code = 'EX_KME' AND c.active = 1";
12252 $resql = $this->db->query($sql);
12254 if ($this->db->num_rows($resql) > 0) {
12255 $obj = $this->db->fetch_object($resql);
12256 $out .=
'<script nonce="' .
getNonce() .
'">
12258 $("select[name=' . $target .
']").on("change", function() {
12259 var current_val = $(this).val();
12260 if (current_val == ' . $obj->id .
') {';
12261 if (!empty($default_selected) || !empty($selected)) {
12262 $out .=
'$("select[name=' . $htmlname .
']").val("' . ($default_selected > 0 ? $default_selected : $selected) .
'");';
12266 $("select[name=' . $htmlname .
']").change();
12270 $("select[name=' . $htmlname .
']").change(function() {
12272 if ($("select[name=' . $target .
']").val() == ' . $obj->id .
') {
12273 // get price of kilometer to fill the unit price
12277 data: { fk_c_exp_tax_cat: $(this).val(), token: \'' .
currentToken() .
'\' },
12278 url:
"' . (DOL_URL_ROOT . '/expensereport/ajax/ajaxik.php?' . implode('&', $params)) . '",
12279 }).done(
function( data, textStatus, jqXHR ) {
12281 if (typeof data.up !=
"undefined") {
12282 $(
"input[name=value_unit]").val(data.up);
12283 $(
"select[name=' . $htmlname . ']").attr(
"title", data.title);
12285 $(
"input[name=value_unit]").val(
"");
12286 $(
"select[name=' . $htmlname . ']").attr(
"title",
"");
12297 dol_print_error($this->db);
12311 public function selectExpenseRanges($selected = '
', $htmlname = 'fk_range
', $useempty = 0)
12313 global $conf, $langs;
12316 $sql = "SELECT rowid, range_ik FROM " . $this->db->prefix() . "c_exp_tax_range";
12317 $sql .= " WHERE entity = " . ((int) $conf->entity) . " AND active = 1";
12319 $resql = $this->db->query($sql);
12321 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
12323 $out .= '<option value=
"0"></option>
';
12326 while ($obj = $this->db->fetch_object($resql)) {
12327 $out .= '<option
' . ($selected == $obj->rowid ? 'selected=
"selected"' : '') . ' value=
"' . $obj->rowid . '">
' . price($obj->range_ik, 0, $langs, 1, 0) . '</option>
';
12329 $out .= '</select>
';
12331 dol_print_error($this->db);
12347 public function selectExpenseFees($selected = '
', $htmlname = 'fk_c_type_fees
', $useempty = 0, $allchoice = 1, $useid = 0)
12352 $sql = "SELECT id, code, label";
12353 $sql .= " FROM ".$this->db->prefix()."c_type_fees";
12354 $sql .= " WHERE active = 1";
12356 $resql = $this->db->query($sql);
12358 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
12360 $out .= '<option value=
"0"></option>
';
12363 $out .= '<option value=
"-1">
' . $langs->trans('AllExpenseReport
') . '</option>
';
12371 while ($obj = $this->db->fetch_object($resql)) {
12372 $key = $langs->trans($obj->code);
12373 $out .= '<option
' . ($selected == $obj->{$field} ? 'selected=
"selected"' : '') . ' value=
"' . $obj->{$field} . '">
' . ($key != $obj->code ? $key : $obj->label) . '</option>
';
12375 $out .= '</select>
';
12377 $out .= ajax_combobox('select_
'.$htmlname);
12379 dol_print_error($this->db);
12403 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)
12405 global $user, $conf, $langs;
12407 require_once DOL_DOCUMENT_ROOT . '/projet/
class/project.class.php
';
12409 if (is_null($usertofilter)) {
12410 $usertofilter = $user;
12415 $hideunselectables = false;
12416 if (getDolGlobalString('INVOICE_HIDE_UNSELECTABLES
')) {
12417 $hideunselectables = true;
12420 if (empty($projectsListId)) {
12421 if (!$usertofilter->hasRight('projet
', 'all
', 'lire
')) {
12422 $projectstatic = new Project($this->db);
12423 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1);
12427 // Search all projects
12428 $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";
12429 $sql .= " FROM " . $this->db->prefix() . "facture as f";
12430 $sql .= " INNER JOIN " . $this->db->prefix() . "projet as p ON p.entity IN (" . getEntity('project
') . ") AND f.fk_projet = p.rowid";
12431 $sql .= " LEFT JOIN " . $this->db->prefix() . "societe as s ON s.rowid = p.fk_soc";
12432 $sql .= " WHERE f.fk_statut = 0"; // Draft invoices only
12433 //if ($projectsListId) $sql.= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")";
12434 //if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
12435 //if ($socid > 0) $sql.= " AND (p.fk_soc=".((int) $socid)." OR p.fk_soc IS NULL)";
12436 $sql .= " ORDER BY p.ref, f.ref ASC";
12438 $resql = $this->db->query($sql);
12440 // Use select2 selector
12441 if (!empty($conf->use_javascript_ajax)) {
12442 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
12443 $comboenhancement = ajax_combobox($htmlname, array(), 0, $forcefocus);
12444 $out .= $comboenhancement;
12445 $morecss = 'minwidth200imp maxwidth500
';
12448 if (empty($option_only)) {
12449 $out .= '<select
class=
"valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled=
"disabled"' : '') . ' id=
"' . $htmlname . '" name=
"' . $htmlname . '">
';
12451 if (!empty($show_empty)) {
12452 $out .= '<option value=
"0" class=
"optiongrey">
';
12453 if (!is_numeric($show_empty)) {
12454 $out .= $show_empty;
12458 $out .= '</option>
';
12460 $num = $this->db->num_rows($resql);
12463 while ($i < $num) {
12464 $obj = $this->db->fetch_object($resql);
12465 // 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.
12466 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$usertofilter->hasRight('societe
', 'lire
')) {
12469 if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) {
12476 if ($showproject == 'all
') {
12477 $labeltoshow .= dol_trunc($obj->ref, 18); // Invoice ref
12479 $labeltoshow .= ' -
' . $obj->name; // Soc name
12483 if ($obj->fk_statut == Project::STATUS_DRAFT) {
12485 $labeltoshow .= ' -
' . $langs->trans("Draft");
12486 } elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
12487 if ($discard_closed == 2) {
12490 $labeltoshow .= ' -
' . $langs->trans("Closed");
12491 } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
12493 $labeltoshow .= ' -
' . $langs->trans("LinkedToAnotherCompany");
12497 if (!empty($selected) && $selected == $obj->rowid) {
12498 $out .= '<option value=
"' . $obj->rowid . '" selected
';
12499 //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected
if disabled
12500 $out .=
'>' . $labeltoshow .
'</option>';
12502 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
12505 $resultat =
'<option value="' . $obj->rowid .
'"';
12507 $resultat .=
' disabled';
12512 $resultat .= $labeltoshow;
12513 $resultat .=
'</option>';
12521 if (empty($option_only)) {
12522 $out .=
'</select>';
12525 $this->db->free($resql);
12548 public function selectInvoiceRec($selected =
'', $htmlname =
'facrecid', $maxlength = 24, $option_only = 0, $show_empty =
'1', $forcefocus = 0, $disabled = 0, $morecss =
'maxwidth500')
12550 global
$conf, $langs;
12556 $sql =
'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc';
12557 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'facture_rec as f';
12558 $sql .=
" WHERE f.entity IN (" .
getEntity(
'invoice') .
")";
12559 $sql .=
" ORDER BY f.titre ASC";
12561 $resql = $this->db->query($sql);
12564 if (!empty(
$conf->use_javascript_ajax)) {
12565 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
12566 $comboenhancement =
ajax_combobox($htmlname, array(), 0, $forcefocus);
12567 $out .= $comboenhancement;
12568 $morecss =
'minwidth200imp maxwidth500';
12571 if (empty($option_only)) {
12572 $out .=
'<select class="valignmiddle flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' id="' . $htmlname .
'" name="' . $htmlname .
'">';
12574 if (!empty($show_empty)) {
12575 $out .=
'<option value="0" class="optiongrey">';
12576 if (!is_numeric($show_empty)) {
12577 $out .= $show_empty;
12581 $out .=
'</option>';
12583 $num = $this->db->num_rows($resql);
12585 while ($obj = $this->db->fetch_object($resql)) {
12586 $labeltoshow =
dol_trunc($obj->title, 18);
12589 if (!empty($obj->suspended)) {
12591 $labeltoshow .=
' - ' . $langs->trans(
"Closed");
12595 if (!empty($selected) && $selected == $obj->rowid) {
12596 $out .=
'<option value="' . $obj->rowid .
'" selected';
12598 $out .=
'>' . $labeltoshow .
'</option>';
12600 if ($disabled && ($selected != $obj->rowid)) {
12603 $resultat =
'<option value="' . $obj->rowid .
'"';
12605 $resultat .=
' disabled';
12608 $resultat .= $labeltoshow;
12609 $resultat .=
'</option>';
12615 if (empty($option_only)) {
12616 $out .=
'</select>';
12621 $this->db->free($resql);
12624 $this->errors[] = $this->db->lasterror;
12640 public function searchComponent($arrayofcriterias, $search_component_params, $arrayofinputfieldsalreadyoutput = array(), $search_component_params_hidden =
'', $arrayoffiltercriterias = array())
12643 global $langs, $form;
12648 if ($search_component_params_hidden !=
'' && !preg_match(
'/^\(.*\)$/', $search_component_params_hidden)) {
12649 $search_component_params_hidden =
'(' . $search_component_params_hidden .
')';
12652 $ret =
'<!-- searchComponent -->';
12654 $ret .=
'<div class="divadvancedsearchfieldcomp centpercent inline-block">';
12655 $ret .=
'<a href="#" class="dropdownsearch-toggle unsetcolor">';
12656 $ret .=
'<span class="fas fa-filter linkobject boxfilter paddingright pictofixedwidth" title="' .
dol_escape_htmltag($langs->trans(
"Filters")) .
'" id="idsubimgproductdistribution"></span>';
12659 $ret .=
'<div class="divadvancedsearchfieldcompinput inline-block minwidth500 maxwidth300onsmartphone">';
12662 $ret .=
'<div id="divsearch_component_params" name="divsearch_component_params" class="noborderbottom search_component_params inline-block valignmiddle">';
12664 if ($search_component_params_hidden) {
12672 foreach ($arrayofandtags as $tmpkey => $tmpval) {
12673 $errormessage =
'';
12675 if ($errormessage) {
12676 $this->error =
'ERROR in parsing search string: '.$errormessage;
12679 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
12682 $ret .=
'<span class="marginleftonlyshort valignmiddle tagsearch" data-ufilterid="'.($tmpkey + 1).
'" data-ufilter="'.
dol_escape_htmltag($tmpval).
'">';
12683 $ret .=
'<span class="tagsearchdelete select2-selection__choice__remove" data-ufilterid="'.($tmpkey + 1).
'">x</span> ';
12695 $show_search_component_params_hidden = 1;
12696 if ($show_search_component_params_hidden) {
12697 $ret .=
'<input type="hidden" name="show_search_component_params_hidden" value="1">';
12699 $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%')) -->";
12700 $ret .=
'<input type="hidden" id="search_component_params_hidden" name="search_component_params_hidden" value="' .
dol_escape_htmltag($search_component_params_hidden) .
'">';
12705 foreach ($arrayofcriterias as $criteria) {
12706 foreach ($criteria as $criteriafamilykey => $criteriafamilyval) {
12707 if (in_array(
'search_' . $criteriafamilykey, $arrayofinputfieldsalreadyoutput)) {
12710 if (in_array($criteriafamilykey, array(
'rowid',
'ref_ext',
'entity',
'extraparams'))) {
12713 if (in_array($criteriafamilyval[
'type'], array(
'date',
'datetime',
'timestamp'))) {
12714 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_start">';
12715 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startyear">';
12716 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startmonth">';
12717 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startday">';
12718 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_end">';
12719 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endyear">';
12720 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endmonth">';
12721 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endday">';
12723 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'">';
12730 $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";
12731 $ret .=
'<input type="text" placeholder="' . $langs->trans(
"Filters") .
'" id="search_component_params_input" name="search_component_params_input" class="noborderall search_component_input" value="">';
12737 jQuery(".tagsearchdelete").click(function(e) {
12738 var filterid = $(this).parents().attr("data-ufilterid");
12739 console.log("We click to delete the criteria nb "+filterid);
12741 // Regenerate the search_component_params_hidden with all data-ufilter except the one to delete, and post the page
12742 var newparamstring = \'\';
12743 $(\'.tagsearch\').each(function(index, element) {
12744 tmpfilterid = $(this).attr("data-ufilterid");
12745 if (tmpfilterid != filterid) {
12746 // We keep this criteria
12747 if (newparamstring == \'\') {
12748 newparamstring = $(this).attr("data-ufilter");
12750 newparamstring = newparamstring + \' AND \' + $(this).attr("data-ufilter");
12754 console.log("newparamstring = "+newparamstring);
12756 jQuery("#search_component_params_hidden").val(newparamstring);
12758 // We repost the form
12759 $(this).closest(\'form\').submit();
12762 jQuery("#search_component_params_input").keydown(function(e) {
12763 console.log("We press a key on the filter field that is "+jQuery("#search_component_params_input").val());
12764 console.log(e.which);
12765 if (jQuery("#search_component_params_input").val() == "" && e.which == 8) {
12766 /* We click on back when the input field is already empty */
12767 event.preventDefault();
12768 jQuery("#divsearch_component_params .tagsearch").last().remove();
12769 /* Regenerate content of search_component_params_hidden from remaining .tagsearch */
12771 jQuery("#divsearch_component_params .tagsearch").each(function( index ) {
12775 s = s + $(this).attr("data-ufilter");
12777 console.log("New value for search_component_params_hidden = "+s);
12778 jQuery("#search_component_params_hidden").val(s);
12786 $arrayoffiltercriterias_json = json_encode($arrayoffiltercriterias);
12788 var arrayoffiltercriterias = ' . $arrayoffiltercriterias_json .
';
12792 $arrayoffilterfieldslabel = array();
12793 foreach ($arrayoffiltercriterias as $key => $val) {
12794 $arrayoffilterfieldslabel[$key][
'label'] = $val[
'label'];
12795 $arrayoffilterfieldslabel[$key][
'data-type'] = $val[
'type'];
12799 $ret .=
'<div class="search-component-assistance">';
12802 $ret .=
'<p class="assistance-title">' .
img_picto(
'',
'filter') .
' ' . $langs->trans(
'FilterAssistance') .
' </p>';
12804 $ret .=
'<p class="assistance-errors error" style="display:none">' . $langs->trans(
'AllFieldsRequired') .
' </p>';
12806 $ret .=
'<div class="operand">';
12807 $ret .= $form->selectarray(
'search_filter_field', $arrayoffilterfieldslabel,
'', $langs->trans(
"Fields"), 0, 0,
'', 0, 0, 0,
'',
'width200 combolargeelem', 1);
12810 $ret .=
'<span class="separator"></span>';
12813 $ret .=
'<div class="operator">';
12814 $ret .=
'<select class="operator-selector width150" id="operator-selector"">';
12815 $ret .=
'</select>';
12816 $ret .=
'<script>$(document).ready(function() {';
12817 $ret .=
' $(".operator-selector").select2({';
12818 $ret .=
' placeholder: \'' .
dol_escape_js($langs->transnoentitiesnoconv(
'Operator')) .
'\'';
12820 $ret .=
'});</script>';
12823 $ret .=
'<span class="separator"></span>';
12825 $ret .=
'<div class="value">';
12827 $ret .=
'<input type="text" class="flat width100 value-input" placeholder="' .
dolPrintHTML($langs->trans(
'Value')) .
'">';
12831 $ret .=
'<span class="date-one" style="display:none">';
12832 $ret .= $form->selectDate(($dateOne ? $dateOne : -1),
'dateone', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'');
12836 $ret .=
'<select class="value-selector width150" id="value-selector" style="display:none">';
12837 $ret .=
'</select>';
12839 $(document).ready(function() {
12840 $("#value-selector").select2({
12841 placeholder: "' .
dol_escape_js($langs->trans(
'Value')) .
'"
12843 $("#value-selector").hide();
12844 $("#value-selector").next(".select2-container").hide();
12850 $ret .=
'<div class="btn-div">';
12851 $ret .=
'<button class="button buttongen button-save add-filter-btn" type="button">' . $langs->trans(
"addToFilter") .
'</button>';
12862 $(document).ready(function() {
12863 $("#search_component_params_input").on("click", function() {
12864 const inputPosition = $(this).offset();
12865 const inputHeight = $(this).outerHeight();
12866 $(".search-component-assistance").css({
12867 top: inputPosition.top + inputHeight + 5 + "px",
12868 left: $("#divsearch_component_params").position().left
12869 }).slideToggle(200);
12871 $(document).on("click", function(e) {
12872 if (!$(e.target).closest("#search_component_params_input, .search-component-assistance, #ui-datepicker-div").length) {
12873 $(".search-component-assistance").hide();
12880 $(document).ready(function() {
12881 $(".search_filter_field").on("change", function() {
12882 console.log("We change search_filter_field");
12885 const selectedField = $(this).find(":selected");
12886 let fieldType = selectedField.data("type");
12887 const selectedFieldValue = selectedField.val();
12889 // If the selected field has an array of values then ask toshow the value selector instead of the value input
12890 if (arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"] !== undefined) {
12891 fieldType = "select";
12894 // If the selected field may be null then ask to append the "IsDefined" and "IsNotDefined" operators
12895 if (arrayoffiltercriterias[selectedFieldValue]["maybenull"] !== undefined) {
12898 const operators = getOperatorsForFieldType(fieldType, maybenull);
12899 const operatorSelector = $(".operator-selector");
12901 // Clear existing options
12902 operatorSelector.empty();
12904 // Populate operators
12905 Object.entries(operators).forEach(function([operator, label]) {
12906 operatorSelector.append("<option value=\'" + operator + "\'>" + label + "</option>");
12909 operatorSelector.trigger("change.select2");
12911 // Clear and hide all input elements initially
12912 $(".value-input, .dateone, .datemonth, .dateyear").val("").hide();
12913 $("#datemonth, #dateyear").val(null).trigger("change.select2");
12914 $("#dateone").datepicker("setDate", null);
12915 $(".date-one, .date-month, .date-year").hide();
12916 $("#value-selector").val("").hide();
12917 $("#value-selector").next(".select2-container").hide();
12918 $("#value-selector").val(null).trigger("change.select2");
12920 if (fieldType === "date" || fieldType === "datetime" || fieldType === "timestamp") {
12921 $(".date-one").show();
12922 } else if (arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"] !== undefined) {
12923 var arrayofkeyval = arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"];
12924 var valueSelector = $("#value-selector");
12925 valueSelector.empty();
12926 Object.entries(arrayofkeyval).forEach(function([key, val]) {
12927 valueSelector.append("<option value=\'" + key + "\'>" + val + "</option>");
12929 valueSelector.trigger("change.select2");
12931 $("#value-selector").show();
12932 $("#value-selector").next(".select2-container").show();
12934 $(".value-input").show();
12938 $("#operator-selector").on("change", function() {
12939 console.log("We change operator-selector");
12941 const selectedOperator = $(this).find(":selected").val();
12942 if (selectedOperator === "IsDefined" || selectedOperator === "IsNotDefined") {
12943 // Disable all value input elements
12944 $(".value-input, .dateone, .datemonth, .dateyear").val("").prop("disabled", true);
12945 $("#datemonth, #dateyear").val(null).trigger("change.select2");
12946 $("#dateone").datepicker("setDate", null).datepicker("option", "disabled", true);
12947 $(".date-one, .date-month, .date-year").prop("disabled", true);
12948 $("#value-selector").val("").prop("disabled", true);
12949 $("#value-selector").val(null).trigger("change.select2");
12951 // Enable all value input elements
12952 $(".value-input, .dateone, .datemonth, .dateyear").prop("disabled", false);
12953 $(".date-one, .date-month, .date-year").prop("disabled", false);
12954 $("#dateone").datepicker("option", "disabled", false);
12955 $("#value-selector").prop("disabled", false);
12959 $(".add-filter-btn").on("click", function(event) {
12960 console.log("We click on add-filter-btn");
12962 event.preventDefault();
12964 const field = $(".search_filter_field").val();
12965 const operator = $(".operator-selector").val();
12966 let value = $(".value-input").val();
12967 const fieldType = $(".search_filter_field").find(":selected").data("type");
12969 if (["date", "datetime", "timestamp"].includes(fieldType)) {
12970 const year = $("#dateoneyear").val().toString().padStart(4, "0");;
12971 const month = $("#dateonemonth").val().toString().padStart(2, "0");
12972 const day = $("#dateoneday").val().toString().padStart(2, "0");
12973 value = `${year}-${month}-${day}`;
12974 console.log("value="+value);
12977 // If the selected field has an array of values then take the selected value
12978 if (arrayoffiltercriterias[field]["arrayofkeyval"] !== undefined) {
12979 value = $("#value-selector").val();
12982 // If the operator is "IsDefined" or "IsNotDefined" then set the value to 1 (it will not be used)
12983 if (operator === "IsDefined" || operator === "IsNotDefined") {
12987 const filterString = generateFilterString(field, operator, value, fieldType);
12990 if (filterString !== "" && field !== "" && operator !== "" && value !== "") {
12991 $("#search_component_params_input").val($("#search_component_params_input").val() + " " + filterString);
12992 $("#search_component_params_input").closest("form").submit();
12994 $(".assistance-errors").show();
13014 public function selectModelMail($prefix, $modelType =
'', $default = 0, $addjscombo = 0, $selected = 0, $morecss =
'')
13016 global $langs, $user;
13020 $TModels = array();
13022 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
13023 $formmail =
new FormMail($this->db);
13024 $result = $formmail->fetchAllEMailTemplate($modelType, $user, $langs);
13027 $TModels[0] = $langs->trans(
'DefaultMailModel');
13030 foreach ($formmail->lines_model as $model) {
13031 $TModels[(int) $model->id] = $model->label;
13035 $retstring .=
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" id="select_' . $prefix .
'model_mail" name="' . $prefix .
'model_mail">';
13037 foreach ($TModels as $id_model => $label_model) {
13038 $retstring .=
'<option value="' . $id_model .
'"';
13039 if (!empty($selected) && ((int) $selected) == $id_model) {
13040 $retstring .=
"selected";
13042 $retstring .=
">" . $label_model .
"</option>";
13045 $retstring .=
"</select>";
13048 $retstring .=
ajax_combobox(
'select_' . $prefix .
'model_mail');
13065 public function buttonsSaveCancel($save_label =
'Save', $cancel_label =
'Cancel', $morebuttons = array(), $withoutdiv =
false, $morecss =
'', $dol_openinpopup =
'')
13069 $buttons = array();
13073 'label_key' => $save_label,
13076 if ($save_label ==
'Create' || $save_label ==
'Add') {
13077 $save[
'name'] =
'add';
13078 } elseif ($save_label ==
'Modify') {
13079 $save[
'name'] =
'edit';
13083 'name' =>
'cancel',
13084 'label_key' =>
'Cancel',
13089 !empty($save_label) ? $buttons[] = $save :
'';
13090 if (!empty($morebuttons)) {
13091 $buttons[] = $morebuttons;
13093 !empty($cancel_label) ? $buttons[] = $cancel :
'';
13095 if (!empty($morebuttons)) {
13096 $buttons[] = $morebuttons;
13098 !empty($cancel_label) ? $buttons[] = $cancel :
'';
13099 !empty($save_label) ? $buttons[] = $save :
'';
13102 $retstring = $withoutdiv ?
'' :
'<div class="center">';
13104 foreach ($buttons as $button) {
13105 $addclass = empty($button[
'addclass']) ?
'' : $button[
'addclass'];
13106 $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'])) .
'">';
13108 $retstring .= $withoutdiv ?
'' :
'</div>';
13110 if ($dol_openinpopup) {
13111 $retstring .=
'<!-- buttons are shown into a $dol_openinpopup=' .
dol_escape_htmltag($dol_openinpopup) .
' context, so we enable the close of dialog on cancel -->' .
"\n";
13112 $retstring .=
'<script nonce="' .
getNonce() .
'">';
13113 $retstring .=
'jQuery(".button-cancel").click(function(e) {
13114 e.preventDefault(); console.log(\'We click on cancel in iframe popup ' .
dol_escape_js($dol_openinpopup) .
'\');
13115 window.parent.jQuery(\
'#idfordialog' .
dol_escape_js($dol_openinpopup) .
'\').dialog(\
'close\');
13117 $retstring .=
'</script>';
13136 $num = count($this->cache_invoice_subtype);
13143 $sql =
"SELECT rowid, code, label as label";
13144 $sql .=
" FROM " . MAIN_DB_PREFIX .
'c_invoice_subtype';
13145 $sql .=
" WHERE active = 1";
13147 $resql = $this->db->query($sql);
13149 $num = $this->db->num_rows($resql);
13151 while ($i < $num) {
13152 $obj = $this->db->fetch_object($resql);
13155 $label = ($langs->trans(
"InvoiceSubtype" . $obj->rowid) !=
"InvoiceSubtype" . $obj->rowid) ? $langs->trans(
"InvoiceSubtype" . $obj->rowid) : (($obj->label !=
'-') ? $obj->label :
'');
13156 $this->cache_invoice_subtype[$obj->rowid][
'rowid'] = $obj->rowid;
13157 $this->cache_invoice_subtype[$obj->rowid][
'code'] = $obj->code;
13158 $this->cache_invoice_subtype[$obj->rowid][
'label'] = $label;
13162 $this->cache_invoice_subtype =
dol_sort_array($this->cache_invoice_subtype,
'code',
'asc', 0, 0, 1);
13184 global $langs, $user;
13187 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
13189 $this->load_cache_invoice_subtype();
13191 $out .=
'<select id="' . $htmlname .
'" class="flat selectsubtype' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
13193 $out .=
'<option value="0"> </option>';
13196 foreach ($this->cache_invoice_subtype as $rowid => $subtype) {
13197 $label = $subtype[
'label'];
13198 $out .=
'<option value="' . $subtype[
'rowid'] .
'"';
13199 if ($selected == $subtype[
'rowid']) {
13200 $out .=
' selected="selected"';
13204 $out .=
'</option>';
13207 $out .=
'</select>';
13208 if ($user->admin && empty($noinfoadmin)) {
13209 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
13230 'type' =>
'search',
13231 'name' => $htmlName,
13233 'class' =>
"search-tool-input",
13234 'placeholder' => $langs->trans(
'Search'),
13235 'autocomplete' =>
'off'
13243 if ($dataTarget !==
false) {
13244 $attr[
'data-search-tool-target'] = $dataTarget;
13248 if (!empty($params[
'attr']) && is_array($params[
'attr'])) {
13249 foreach ($params[
'attr'] as $key => $value) {
13250 if ($key ==
'class') {
13251 $attr[
'class'] .=
' '.$value;
13252 } elseif ($key ==
'classOverride') {
13253 $attr[
'class'] = $value;
13255 $attr[$key] = $value;
13261 if (!empty($attr[
'title']) && !empty($attr[
'class']) && strpos($attr[
'class'],
'classfortooltip') ===
false) {
13262 $attr[
'class'] .=
' classfortooltip';
13265 $TCompiledAttr = [];
13266 foreach ($attr as $key => $value) {
13267 if (in_array($key, [
'data-target'])
13268 || (!empty($params[
'use_unsecured_unescapedattr']) && is_array($params[
'use_unsecured_unescapedattr']) && in_array($key, $params[
'use_unsecured_unescapedattr']))) {
13274 $TCompiledAttr[] = $key .
'="' . $value .
'"';
13277 $compiledAttributes = implode(
' ', $TCompiledAttr);
13280 return '<div class="search-tool-container"><input '.$compiledAttributes.
'></div>';
13296 public function inputType($type, $name, $value =
'',
$id =
'', $morecss =
'', $moreparam =
'', $label =
'', $addInputLabel =
'')
13299 if ($label !=
'') {
13309 $out .= ($moreparam ?
' ' . $moreparam :
'');
13310 $out .=
' />' . $addInputLabel;
13311 if ($label !=
'') {
13312 $out .= $label .
'</label>';
13330 public function inputSelectAjax($htmlName, $array,
$id, $ajaxUrl, $ajaxData = [], $morecss =
'minwidth75', $moreparam =
'')
13334 $(document).ready(function () {
13335 $('#" . $htmlName .
"').select2({
13337 url: '" . $ajaxUrl .
"',
13339 delay: 250, // wait 250 milliseconds before triggering the request
13340 data: function (params) {
13342 search: params.term,
13343 page: params.page || 1";
13344 if (!empty($ajaxData) && is_array($ajaxData)) {
13345 foreach ($ajaxData as $key => $value) {
13346 $out .=
", " . $key .
": '" . $value .
"'";
13358 $out .= $this->selectarray($htmlName, $array,
$id, 0, 0, 0, $moreparam, 0, 0, 0,
'', $morecss);
13372 public function inputHtml($htmlName, $value, $morecss =
'', $moreparam =
'')
13374 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
13375 $doleditor =
new DolEditor($htmlName, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
isModEnabled(
'fckeditor') &&
getDolGlobalInt(
'FCKEDITOR_ENABLE_SOCIETE'), ROWS_5,
'90%');
13377 return (
string) $doleditor->Create(1,
'',
true,
'',
'', $moreparam, $morecss);
13390 public function inputText($htmlName, $value, $morecss =
'', $moreparam =
'', $options = array())
13395 if (!empty($options)) {
13397 $out .= $this->selectarray($htmlName .
"_multiinput", $options,
'', 1, 0, 0, $moreparam, 0, 0, 0,
'',
"flat maxwidthonphone" . $morecss);
13398 $out .=
'<input id="' . $htmlName .
'_multiinputadd" type="button" class="button" value="' . $langs->trans(
"Add") .
'">';
13399 $out .=
"<script>";
13401 function handlemultiinputdisabling(htmlname){
13402 console.log("We handle the disabling of used options for "+htmlname+"_multiinput");
13403 multiinput = $("#"+htmlname+"_multiinput");
13404 multiinput.find("option").each(function(){
13405 tmpval = $("#"+htmlname).val();
13406 tmpvalarray = tmpval.split("\n");
13407 valtotest = $(this).val();
13408 if(tmpvalarray.includes(valtotest)){
13409 $(this).prop("disabled",true);
13411 if($(this).prop("disabled") == true){
13412 console.log(valtotest)
13413 $(this).prop("disabled", false);
13419 $(document).ready(function () {
13420 $("#' . $htmlName .
'_multiinputadd").on("click",function() {
13421 tmpval = $("#' . $htmlName .
'").val();
13422 tmpvalarray = tmpval.split(",");
13423 valtotest = $("#' . $htmlName .
'_multiinput").val();
13424 if(valtotest != -1 && !tmpvalarray.includes(valtotest)){
13425 console.log("We add the selected value to the text area ' . $htmlName .
'");
13427 tmpval = valtotest;
13429 tmpval = tmpval + "\n" + valtotest;
13431 $("#' . $htmlName .
'").val(tmpval);
13432 handlemultiinputdisabling("' . $htmlName .
'");
13433 $("#' . $htmlName .
'_multiinput").val(-1);
13435 console.log("We add nothing the text area ' . $htmlName .
'");
13438 $("#' . $htmlName .
'").on("change",function(){
13439 handlemultiinputdisabling("' . $htmlName .
'");
13441 handlemultiinputdisabling("' . $htmlName .
'");
13443 $out .=
"</script>";
13444 $value = str_replace(
',',
"\n", $value);
13447 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
13448 $doleditor =
new DolEditor($htmlName, (
string) $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
13449 $out .= (
string) $doleditor->Create(1,
'',
true,
'',
'', $moreparam, $morecss);
13464 public function inputRadio($htmlName, $options, $selectedValue, $morecss =
'', $moreparam =
'')
13467 foreach ($options as $optionKey => $optionLabel) {
13468 $selected = ((
string) $selectedValue) === ((
string) $optionKey) ?
' checked="checked"' :
'';
13469 $optionId = $htmlName .
'_' . $optionKey;
13470 $out .=
'<input class="flat' . $morecss .
'" type="radio" name="' . $htmlName .
'" id="' . $optionId .
'" value="' .
dolPrintHTMLForAttribute((
string) $optionKey) .
'"' . $selected . $moreparam .
'/><label for="' . $optionId .
'">' . $optionLabel .
'</label><br>';
13486 public function inputStars($htmlName, $size, $value, $morecss =
'', $moreparam =
'')
13488 $out =
'<input type="hidden" class="flat ' . $morecss .
'" name="' . $htmlName .
'" id="' . $htmlName .
'" value="' .
dolPrintHTMLForAttribute((
string) $value) .
'"' . $moreparam .
'>';
13489 $out .=
'<div class="star-selection" id="' . $htmlName .
'_selection">';
13490 for ($i = 1; $i <= $size; $i++) {
13491 $out .=
'<span class="star" data-value="' . $i .
'">' .
img_picto(
'',
'fontawesome_star_fas') .
'</span>';
13495 jQuery(function($) { /* commonobject.class.php 1 */
13496 let container = $("#' . $htmlName .
'_selection");
13497 let selectedStars = parseInt($("#' . $htmlName .
'").val()) || 0;
13498 container.find(".star").each(function() {
13499 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
13501 container.find(".star").on("mouseover", function() {
13502 let selectedStar = $(this).data("value");
13503 container.find(".star").each(function() {
13504 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
13507 container.on("mouseout", function() {
13508 container.find(".star").each(function() {
13509 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
13512 container.find(".star").off("click").on("click", function() {
13513 selectedStars = $(this).data("value");
13514 if (selectedStars === 1 && $("#' . $htmlName .
'").val() == 1) {
13517 $("#' . $htmlName .
'").val(selectedStars);
13518 container.find(".star").each(function() {
13519 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
13537 public function inputIcon($htmlName, $value, $morecss =
'', $moreparam =
'')
13546 $out =
'<input type="text" class="form-control icp icp-auto iconpicker-element iconpicker-input flat ' . $morecss .
' maxwidthonsmartphone"';
13547 $out .=
' name="' . $htmlName .
'" id="' . $htmlName .
'" value="' .
dolPrintHTMLForAttribute((
string) $value) .
'" ' . ((
string) $moreparam) .
'>';
13549 $out .=
'<script>';
13550 $options =
"{ title: '<b>" . $langs->trans(
"IconFieldSelector") .
"</b>', placement: 'right', showFooter: false, templates: {";
13551 $options .=
"iconpicker: '<div class=\"iconpicker\"><div style=\"background-color:#EFEFEF;\" class=\"iconpicker-items\"></div></div>',";
13552 $options .=
"iconpickerItem: '<a role=\"button\" href=\"#\" class=\"iconpicker-item\" style=\"background-color:#DDDDDD;\"><i></i></a>',";
13555 $options .=
"footer: '<div class=\"popover-footer\" style=\"background-color:#EFEFEF;\"></div>',";
13556 $options .=
"search: '<input type=\"search\" class\"form-control iconpicker-search\" placeholder=\"" . $langs->trans(
"TypeToFilter") .
"\" />',";
13557 $options .=
"popover: '<div class=\"iconpicker-popover popover\">";
13558 $options .=
" <div class=\"arrow\" ></div>";
13559 $options .=
" <div class=\"popover-title\" style=\"text-align:center;background-color:#EFEFEF;\"></div>";
13560 $options .=
" <div class=\"popover-content \" ></div>";
13561 $options .=
"</div>'}}";
13562 $out .=
"$('#" . $htmlName .
"').iconpicker(" . $options .
");";
13563 $out .=
'</script>';
13579 require_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeophp.class.php';
13580 require_once DOL_DOCUMENT_ROOT .
'/core/class/geomapeditor.class.php';
13586 if (!empty($value)) {
13587 $tmparray = $dolgeophp->parseGeoString($value);
13588 $geojson = $tmparray[
'geojson'];
13589 $centroidjson = $tmparray[
'centroidjson'];
13592 return $geomapeditor->getHtml($htmlName, $geojson, $centroidjson, $type);
13604 $toPrint = array();
13605 $values = is_array($values) ? $values : array();
13607 foreach ($values as $value) {
13608 $toPrint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $value .
'</li>';
13610 if (!empty($toPrint)) {
13611 $out =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(
' ', $toPrint) .
'</ul></div>';
13627 for ($i = 1; $i <= $size; $i++) {
13628 $out .=
'<span class="star' . ($i <= $value ?
' active' :
'') .
'" data-value="' . $i .
'">' .
img_picto(
'',
'fontawesome_star_fas') .
'</span>';
13659 if (!empty($value)) {
13660 require_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeophp.class.php';
13662 if ($type ==
'point') {
13663 $out = $dolgeophp->getXYString($value);
13665 $out = $dolgeophp->getPointString($value);
13686 public function getNomUrl(&
$object, $withpicto = 0, $option =
'', $maxlength = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'', $add_label = 0, $sep =
' - ')
13688 if (is_object(
$object) && method_exists(
$object,
'getNomUrl')) {
13689 $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
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='')
Convert a html select field into an ajax combobox.
ajax_multiautocompleter($htmlname, $fields, $url, $option='', $minLength=2, $autoselect=0)
Generic function that return javascript to add to a page to transform a common input text field into ...
ajax_event($htmlname, $events)
Add event management script.
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 for ConferenceOrBoothAttendee.
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 invoices.
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...
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.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
commonHtmlAttributeBuilder($attr, array $unescapedAttr=[])
Builds an array of safe and properly escaped HTML attributes from a key-value pair list.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dolPrintHTML($s, $allowiframe=0, $moreallowedtags=array())
Return a string (that can be on several lines) ready to be output on a HTML page.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
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.
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
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.
dolPrintHTMLForAttribute($s, $escapeonlyhtmltags=0, $allowothertags=array())
Return a string ready to be output into an HTML attribute (alt, title, data-html, ....
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.
getAdvancedPreviewUrl($modulepart, $relativepath, $alldata=0, $param='')
Return URL we can use for advanced preview links.
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_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
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...
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.
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...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
multi select button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
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.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
$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.
testSqlAndScriptInject($val, $type)
Security: WAF layer for SQL Injection and XSS Injection (scripts) protection (Filters on GET,...