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";
1154 $sql .=
" WHERE active > 0 AND phone_code IS NOT NULL AND phone_code != ''";
1156 dol_syslog(get_class($this).
"::selectPhoneCode", LOG_DEBUG);
1157 $resql = $this->db->query($sql);
1159 $num = $this->db->num_rows($resql);
1162 $obj = $this->db->fetch_object($resql);
1164 $translabel = ($obj->code && $langs->transnoentitiesnoconv(
"Country".$obj->code) !=
"Country".$obj->code) ? $langs->transnoentitiesnoconv(
"Country".$obj->code) : $obj->label;
1166 $codeArray[$i][
'rowid'] = $obj->rowid;
1167 $codeArray[$i][
'code'] = $obj->code;
1168 $codeArray[$i][
'label'] = $translabel;
1169 $codeArray[$i][
'phone_code'] =
'+'.$obj->phone_code;
1170 $codeArray[$i][
'favorite'] = $obj->favorite;
1171 $codeArray[$i][
'trunk_prefix'] = $obj->trunk_prefix;
1172 $favorite[$i] = $obj->favorite;
1177 $array1_sort_order = SORT_DESC;
1178 $array2_sort_order = SORT_ASC;
1179 array_multisort($favorite, $array1_sort_order, $label, $array2_sort_order, $codeArray);
1181 $out .=
'<select id="select'.$htmlname.
'" class="flat selectphonecode'.($morecss ?
' '.$morecss :
'').
'" name="'.$htmlname.
'">';
1184 $out .=
'<option value=""> </option>'.
"\n";
1189 $firstMatchIdx = -1;
1190 if ($selected !==
'') {
1191 foreach ($codeArray as $idx => $row) {
1192 if ($row[
'phone_code'] == $selected) {
1193 if ($firstMatchIdx < 0) {
1194 $firstMatchIdx = $idx;
1196 if ($country_id_hint > 0 && $row[
'rowid'] == $country_id_hint) {
1197 $selectedIdx = $idx;
1202 if ($selectedIdx < 0 && $firstMatchIdx >= 0) {
1203 $selectedIdx = $firstMatchIdx;
1207 foreach ($codeArray as $idx => $row) {
1208 if (empty($row[
'code'])) {
1212 if ($row[
'favorite']) {
1213 $atleastonefavorite++;
1215 if (empty($row[
'favorite']) && $atleastonefavorite) {
1216 $atleastonefavorite = 0;
1217 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1220 $tmpflag =
picto_from_langcode($row[
'code'],
'class="saturatemedium paddingrightonly"', 1);
1223 $selectlabel = ($tmpflag ? $tmpflag.
' ' :
'').$row[
'code'];
1226 $labeltoshow = ($tmpflag ? $tmpflag.
' ' :
'').$row[
'label'].
' '.$row[
'phone_code'];
1228 $out .=
'<option value="'.dol_escape_htmltag($row[
'phone_code']).
'"';
1229 if ($idx === $selectedIdx) {
1230 $out .=
' selected';
1232 $out .=
' data-html="'.dol_escape_htmltag($labeltoshow).
'"';
1233 $out .=
' data-select-html="'.dol_escape_htmltag($selectlabel).
'"';
1234 $out .=
' data-country-id="'.((int) $row[
'rowid']).
'"';
1235 $out .=
' data-trunk-prefix="'.dol_escape_htmltag((
string) $row[
'trunk_prefix']).
'"';
1238 $out .=
'</option>'.
"\n";
1240 $out .=
'</select>';
1246 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1247 $out .=
ajax_combobox(
'select'.$htmlname, array(), 0, 0,
'resolve');
1268 public function showPhoneInput($phoneValue, $htmlname, $country_id_hint = 0, $picto =
'object_phoning', $morecss =
'maxwidth150', $maxlength = 0, $countrySelectorId =
'selectcountry_id')
1272 include_once DOL_DOCUMENT_ROOT.
'/core/lib/phone.lib.php';
1274 $codename = $htmlname.
'_code';
1277 if (empty($country_id_hint) && !empty(
$mysoc->country_id)) {
1278 $country_id_hint =
$mysoc->country_id;
1282 if (GETPOSTISSET($htmlname)) {
1285 $fullPhone = (
string) $phoneValue;
1294 $selectedCode = $phonecode;
1295 $numberValue = $parsed[
'number'];
1298 if ($numberValue !==
'' && $selectedCode !==
'') {
1300 if ($trunkPrefix !==
'' && strpos($numberValue, $trunkPrefix) !== 0) {
1301 $numberValue = $trunkPrefix.$numberValue;
1309 $out .=
img_picto(
'', $picto,
'class="pictofixedwidth"');
1312 $out .= $this->
selectPhoneCode($selectedCode, $codename,
'maxwidth75 phone_code_select', 0, $country_id_hint);
1315 $out .=
'<input type="tel" inputmode="numeric" pattern="[0-9]*" id="'.dol_escape_htmltag($htmlname).
'_input" class="'.
dol_escape_htmltag($morecss).
'"';
1316 if ($maxlength > 0) {
1317 $out .=
' maxlength="'.$maxlength.
'"';
1319 $out .=
' value="'.dol_escape_htmltag($numberValue).
'">';
1344 $selectId =
'select'.dol_escape_js($codename);
1346 $out =
"\n".
'<script type="text/javascript">'.
"\n";
1347 $out .=
'jQuery(document).ready(function() {'.
"\n";
1348 $out .=
' function syncPhoneField_'.$hiddenId.
'() {'.
"\n";
1349 $out .=
' var selectEl = jQuery("#'.$selectId.
'");'.
"\n";
1350 $out .=
' var code = selectEl.val() || "";'.
"\n";
1351 $out .=
' var number = (jQuery("#'.$inputId.
'").val() || "").replace(/[^0-9]/g, "");'.
"\n";
1352 $out .=
' if (code && number) {'.
"\n";
1353 $out .=
' var selOpt = selectEl[0] && selectEl[0].selectedOptions && selectEl[0].selectedOptions[0];'.
"\n";
1354 $out .=
' var trunkPrefix = selOpt ? (selOpt.getAttribute("data-trunk-prefix") || "") : "";'.
"\n";
1355 $out .=
' if (trunkPrefix !== "" && number.indexOf(trunkPrefix) === 0) {'.
"\n";
1356 $out .=
' number = number.substring(trunkPrefix.length);'.
"\n";
1358 $out .=
' jQuery("#'.$hiddenId.
'").val(code + " " + number);'.
"\n";
1359 $out .=
' } else if (number) {'.
"\n";
1360 $out .=
' jQuery("#'.$hiddenId.
'").val(number);'.
"\n";
1361 $out .=
' } else {'.
"\n";
1362 $out .=
' jQuery("#'.$hiddenId.
'").val("");'.
"\n";
1365 $out .=
' jQuery("#'.$selectId.
'").on("change", function() { syncPhoneField_'.$hiddenId.
'(); });'.
"\n";
1366 $out .=
' jQuery("#'.$inputId.
'").on("input change", function() { syncPhoneField_'.$hiddenId.
'(); });'.
"\n";
1368 $out .=
'</script>'.
"\n";
1384 if ($this->phoneInputSharedJsLoaded) {
1387 $this->phoneInputSharedJsLoaded =
true;
1389 $out =
"\n".
'<script type="text/javascript">'.
"\n";
1390 $out .=
'jQuery(document).ready(function() {'.
"\n";
1391 $out .=
' jQuery("#'.dol_escape_js($countrySelectorId).
'").on("change", function() {'.
"\n";
1392 $out .=
' var country_id = jQuery(this).val();'.
"\n";
1393 $out .=
' if (country_id) {'.
"\n";
1394 $out .=
' jQuery.getJSON("'.DOL_URL_ROOT.
'/core/ajax/getphonecode.php", {country_id: country_id, token: "'.
currentToken().
'"}, function(data) {'.
"\n";
1395 $out .=
' if (data.phone_code) {'.
"\n";
1396 $out .=
' jQuery(".phone_code_select").each(function() {'.
"\n";
1397 $out .=
' jQuery(this).val(data.phone_code).trigger("change");'.
"\n";
1398 $out .=
' });'.
"\n";
1400 $out .=
' });'.
"\n";
1402 $out .=
' });'.
"\n";
1404 $out .=
'</script>'.
"\n";
1425 global $langs, $form;
1427 $form =
new Form($this->db);
1429 $htmltoenteralink =
'';
1433 $htmltoenteralink .=
'<tr class="liste_titre">';
1434 $htmltoenteralink .=
'<td class="nowrap"></td>';
1435 $htmltoenteralink .=
'<td>' . $langs->trans(
"Ref") .
'</td>';
1436 $htmltoenteralink .=
'<td>' . $langs->trans(
"RefCustomer") .
'</td>';
1437 $htmltoenteralink .=
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
1438 $htmltoenteralink .=
'<td>' . $langs->trans(
"Company") .
'</td>';
1439 $htmltoenteralink .=
'</tr>';
1443 $objp = $this->db->fetch_object($resqllist);
1444 $alreadylinked =
false;
1445 if (!empty(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key])) {
1446 if (in_array($objp->rowid, array_values(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key]))) {
1447 $alreadylinked =
true;
1450 $htmltoenteralink .=
'<tr class="oddeven">';
1451 $htmltoenteralink .=
'<td>';
1452 if ($alreadylinked) {
1453 $htmltoenteralink .=
img_picto(
'',
'link');
1455 $htmltoenteralink .=
'<input type="checkbox" name="idtolinkto[' . $key .
'_' . $objp->rowid .
']" id="' . $key .
'_' . $objp->rowid .
'" value="' . $objp->rowid .
'">';
1457 $htmltoenteralink .=
'</td>';
1458 $htmltoenteralink .=
'<td>';
1459 if (!$alreadylinked) {
1460 $htmltoenteralink .=
'<label for="' . $key .
'_' . $objp->rowid .
'">';
1462 $htmltoenteralink .= $objp->ref;
1463 if (!$alreadylinked) {
1464 $htmltoenteralink .=
'</label>';
1466 $htmltoenteralink .=
'</td>';
1467 $htmltoenteralink .=
'<td>' . (!empty($objp->ref_client) ? $objp->ref_client : (!empty($objp->ref_supplier) ? $objp->ref_supplier :
'')) .
'</td>';
1468 $htmltoenteralink .=
'<td class="right">';
1469 if ($possiblelink[
'label'] ==
'LinkToContract') {
1470 $htmltoenteralink .= $form->textwithpicto(
'', $langs->trans(
"InformationOnLinkToContract")) .
' ';
1472 $htmltoenteralink .=
'<span class="amount">' . (isset($objp->total_ht) ?
price($objp->total_ht) :
'') .
'</span>';
1473 $htmltoenteralink .=
'</td>';
1474 $htmltoenteralink .=
'<td>' . $objp->name .
'</td>';
1475 $htmltoenteralink .=
'</tr>';
1479 return $htmltoenteralink;
1499 global $langs, $form;
1500 require_once DOL_DOCUMENT_ROOT .
'/eventorganization/class/conferenceorboothattendee.class.php';
1501 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
1502 require_once DOL_DOCUMENT_ROOT .
'/projet/class/project.class.php';
1504 $companystatic =
new Societe($this->db);
1505 $projectstatic =
new Project($this->db);
1507 $form =
new Form($this->db);
1509 $htmltoenteralink =
'';
1513 $htmltoenteralink .=
'<tr class="liste_titre">';
1514 $htmltoenteralink .=
'<td class="nowrap"></td>';
1515 $htmltoenteralink .=
'<td>' . $langs->trans(
"Ref") .
'</td>';
1516 $htmltoenteralink .=
'<td>' . $langs->trans(
"Name") .
'</td>';
1517 $htmltoenteralink .=
'<td>' . $langs->trans(
"Email") .
'</td>';
1518 $htmltoenteralink .=
'<td>' . $langs->trans(
"Company") .
'</td>';
1519 $htmltoenteralink .=
'<td>' . $langs->trans(
"Project") .
'</td>';
1520 $htmltoenteralink .=
'<td>' . $langs->trans(
"DateOfRegistration") .
'</td>';
1521 $htmltoenteralink .=
'</tr>';
1525 $objp = $this->db->fetch_object($resqllist);
1526 $alreadylinked =
false;
1527 if (!empty(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key])) {
1528 if (in_array($objp->rowid, array_values(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key]))) {
1529 $alreadylinked =
true;
1532 $htmltoenteralink .=
'<tr class="oddeven">';
1533 $htmltoenteralink .=
'<td>';
1534 if ($alreadylinked) {
1535 $htmltoenteralink .=
img_picto(
'',
'link');
1537 $htmltoenteralink .=
'<input type="checkbox" name="idtolinkto[' . $key .
'_' . $objp->rowid .
']" id="' . $key .
'_' . $objp->rowid .
'" value="' . $objp->rowid .
'">';
1539 $htmltoenteralink .=
'</td>';
1540 $fetchattendee = $attendeestatic->fetch($objp->rowid);
1541 if ($fetchattendee) {
1542 $htmltoenteralink .=
'<td>' . $attendeestatic->getNomUrl(0).
'</td>';
1544 $htmltoenteralink .=
'<td><label for="' . $key .
'_' . $objp->rowid .
'">' . $objp->ref .
'</label></td>';
1546 $htmltoenteralink .=
'<td>' . $objp->name .
'</td>';
1547 $htmltoenteralink .=
'<td>' . $objp->email .
'</td>';
1548 $fetchcompany = $companystatic->fetch($objp->socid);
1549 if ($fetchcompany) {
1550 $htmltoenteralink .=
'<td>' . $companystatic->getNomUrl(0).
'</td>';
1552 $htmltoenteralink .=
'<td>' . $objp->name .
'</td>';
1554 $fetchcproject = $projectstatic->fetch($objp->fk_project);
1555 if ($fetchcproject) {
1556 $htmltoenteralink .=
'<td>' . $projectstatic->getNomUrl(0).
'</td>';
1558 $htmltoenteralink .=
'<td>' . $objp->fk_project .
'</td>';
1560 $htmltoenteralink .=
'<td>' . $objp->date_subscription .
'</td>';
1561 $htmltoenteralink .=
'</tr>';
1565 return $htmltoenteralink;
1583 public function select_incoterms($selected =
'', $location_incoterms =
'', $page =
'', $htmlname =
'incoterm_id', $htmloption =
'', $forcecombo = 1, $events = array(), $disableautocomplete = 0)
1586 global
$conf, $langs;
1588 $langs->load(
"dict");
1592 $incotermArray = array();
1594 $sql =
"SELECT rowid, code";
1595 $sql .=
" FROM " . $this->db->prefix() .
"c_incoterms";
1596 $sql .=
" WHERE active > 0";
1597 $sql .=
" ORDER BY code ASC";
1599 dol_syslog(get_class($this) .
"::select_incoterm", LOG_DEBUG);
1600 $resql = $this->db->query($sql);
1602 if (
$conf->use_javascript_ajax && !$forcecombo) {
1603 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1607 if (!empty($page)) {
1608 $out .=
'<form method="post" action="' . $page .
'">';
1609 $out .=
'<input type="hidden" name="action" value="set_incoterms">';
1610 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
1613 $out .=
'<select id="' . $htmlname .
'" class="flat selectincoterm width75" name="' . $htmlname .
'" ' . $htmloption .
'>';
1614 $out .=
'<option value="0"> </option>';
1615 $num = $this->db->num_rows($resql);
1619 $obj = $this->db->fetch_object($resql);
1620 $incotermArray[$i][
'rowid'] = $obj->rowid;
1621 $incotermArray[$i][
'code'] = $obj->code;
1625 foreach ($incotermArray as $row) {
1626 if ($selected && ($selected == $row[
'rowid'] || $selected == $row[
'code'])) {
1627 $out .=
'<option value="' . $row[
'rowid'] .
'" selected>';
1629 $out .=
'<option value="' . $row[
'rowid'] .
'">';
1633 $out .= $row[
'code'];
1636 $out .=
'</option>';
1639 $out .=
'</select>';
1642 if (
$conf->use_javascript_ajax && empty($disableautocomplete)) {
1643 $out .=
ajax_multiautocompleter(
'location_incoterms', array(), DOL_URL_ROOT .
'/core/ajax/locationincoterms.php') .
"\n";
1646 $out .=
'<input id="location_incoterms" class="maxwidthonsmartphone heightofcombo" type="text" name="location_incoterms" value="' . $location_incoterms .
'">' .
"\n";
1648 if (!empty($page)) {
1649 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp nomargintop nomarginbottom" value="' . $langs->trans(
"Modify") .
'"></form>';
1673 public function select_type_of_lines($selected =
'', $htmlname =
'type', $showempty = 0, $hidetext = 0, $forceall = 0, $morecss =
"", $useajaxcombo = 1)
1681 if (empty($hidetext)) {
1682 print $langs->trans(
"Type").
'...';
1685 print
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
1687 print
'<option value="-1" class="opacitymedium"'.($useajaxcombo ?
'' :
' disabled="disabled"');
1688 if ($selected == -1) {
1692 if (is_numeric($showempty)) {
1700 print
'<option value="0"';
1701 if (0 == $selected || ($selected == -1 &&
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') ==
'product')) {
1704 print
'>' . $langs->trans(
"Product");
1707 print
'<option value="1"';
1708 if (1 == $selected || ($selected == -1 &&
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') ==
'service')) {
1711 print
'>' . $langs->trans(
"Service");
1716 if ($useajaxcombo) {
1722 print $langs->trans(
"Service");
1723 print
'<input type="hidden" name="' . $htmlname .
'" value="1">';
1726 print $langs->trans(
"Product");
1727 print
'<input type="hidden" name="' . $htmlname .
'" value="0">';
1729 if ($forceall < 0) {
1730 print
'<input type="hidden" name="' . $htmlname .
'" value="1">';
1746 $num = count($this->cache_types_fees);
1753 $langs->load(
"trips");
1755 $sql =
"SELECT c.code, c.label";
1756 $sql .=
" FROM " . $this->db->prefix() .
"c_type_fees as c";
1757 $sql .=
" WHERE active > 0";
1759 $resql = $this->db->query($sql);
1761 $num = $this->db->num_rows($resql);
1765 $obj = $this->db->fetch_object($resql);
1768 $label = ($obj->code != $langs->trans($obj->code) ? $langs->trans($obj->code) : $langs->trans($obj->label));
1769 $this->cache_types_fees[$obj->code] = $label;
1773 asort($this->cache_types_fees);
1795 global $user, $langs;
1797 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
1801 print
'<select id="select_' . $htmlname .
'" class="flat" name="' . $htmlname .
'">';
1803 print
'<option value="-1"';
1804 if ($selected == -1) {
1807 print
'> </option>';
1810 foreach ($this->cache_types_fees as $key => $value) {
1811 print
'<option value="' . $key .
'"';
1812 if ($key == $selected) {
1822 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1851 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)
1854 global
$conf, $langs;
1858 if (!empty(
$conf->use_javascript_ajax) &&
getDolGlobalString(
'COMPANY_USE_SEARCH_TO_SELECT') && !$forcecombo) {
1859 if (is_null($ajaxoptions)) {
1860 $ajaxoptions = array();
1863 require_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1867 if ($selected && empty($selected_input_value)) {
1868 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
1869 $societetmp =
new Societe($this->db);
1870 $societetmp->fetch($selected);
1871 $selected_input_value = $societetmp->name;
1876 $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 :
'');
1878 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
1879 if (empty($hidelabel)) {
1880 $out .= $langs->trans(
"RefOrLabel") .
' : ';
1881 } elseif ($hidelabel == 1 && !is_numeric($showempty)) {
1882 $placeholder = $langs->trans($showempty);
1883 } elseif ($hidelabel > 1) {
1884 $placeholder = $langs->trans(
"RefOrLabel");
1885 if ($hidelabel == 2) {
1886 $out .=
img_picto($langs->trans(
"Search"),
'search');
1889 $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" />';
1890 if ($hidelabel == 3) {
1891 $out .=
img_picto($langs->trans(
"Search"),
'search');
1896 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.
'/societe/ajax/company.php', $urloption,
getDolGlobalInt(
'COMPANY_USE_SEARCH_TO_SELECT'), 0, $ajaxoptions);
1899 $out .= $this->
select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events,
'', 0, $limit, $morecss, $moreparam, $multiple, $excludeids, $showcode);
1933 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 =
'')
1937 global
$conf, $langs;
1942 if ($nokeyifsocid && $socid > 0) {
1943 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = 0;
1946 if (!empty(
$conf->use_javascript_ajax) &&
getDolGlobalString(
'CONTACT_USE_SEARCH_TO_SELECT') && !$forcecombo) {
1947 $ajaxoptions = array();
1949 require_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1953 if ($selected && empty($selected_input_value)) {
1954 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
1955 $contacttmp =
new Contact($this->db);
1956 $contacttmp->fetch($selected);
1957 $selected_input_value = $contacttmp->getFullName($langs);
1960 if (!is_numeric($showempty)) {
1961 $placeholder = $showempty;
1965 $urloption =
'htmlname=' . urlencode((
string) (str_replace(
'.',
'_', $htmlname))) .
'&outjson=1&filter=' . urlencode((
string) ($filter)) . (empty($exclude) ?
'' :
'&exclude=' . urlencode($exclude)) . ($showsoc ?
'&showsoc=' . urlencode((
string) ($showsoc)) :
'');
1967 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
1969 $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" />';
1973 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.
'/contact/ajax/contact.php', $urloption,
getDolGlobalInt(
'CONTACT_USE_SEARCH_TO_SELECT'), 0, $ajaxoptions);
1977 $disableifempty = 0;
1981 $out .= $this->
selectcontacts($socid, $selected, $htmlname, $showempty, $exclude, $limitto, $showfunction, $morecss, $options_only, $showsoc, $forcecombo, $events, $moreparam, $htmlid, $multiple, $disableifempty, $filter);
1984 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = $sav;
2015 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)
2018 global $user, $langs;
2019 global $hookmanager;
2021 $langs->loadLangs(array(
"companies",
"suppliers"));
2025 $outarray = array();
2027 if ($selected ===
'') {
2028 $selected = array();
2029 } elseif (!is_array($selected)) {
2030 $selected = array($selected);
2034 if (function_exists(
'testSqlAndScriptInject')) {
2037 return 'SQLInjectionTryDetected';
2041 if ($filter !=
'') {
2046 if (function_exists(
'testSqlAndScriptInject')) {
2049 return 'SQLInjectionTryDetected';
2055 $sql =
"SELECT s.rowid, s.nom as name, s.name_alias, s.tva_intra, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
2057 $sql .=
", s.address, s.zip, s.town";
2058 $sql .=
", dictp.code as country_code";
2060 $sql .=
" FROM " . $this->db->prefix() .
"societe as s";
2062 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_country as dictp ON dictp.rowid = s.fk_pays";
2064 if (!$user->hasRight(
'societe',
'client',
'voir')) {
2065 $sql .=
", " . $this->db->prefix() .
"societe_commerciaux as sc";
2067 $sql .=
" WHERE s.entity IN (" .
getEntity(
'societe') .
")";
2068 if (!empty($user->socid)) {
2069 $sql .=
" AND s.rowid = " . ((int) $user->socid);
2073 $sqlwhere = $filter;
2074 $sql .=
" AND (" . $sqlwhere .
")";
2076 if (!$user->hasRight(
'societe',
'client',
'voir')) {
2077 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = " . ((int) $user->id);
2080 $sql .=
" AND s.status <> 0";
2082 if (!empty($excludeids)) {
2083 $sql .=
" AND s.rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeids)) .
")";
2086 $parameters = array();
2087 $reshook = $hookmanager->executeHooks(
'selectThirdpartyListWhere', $parameters);
2088 $sql .= $hookmanager->resPrint;
2090 if ($filterkey && $filterkey !=
'') {
2094 $search_crit = explode(
' ', $filterkey);
2096 if (count($search_crit) > 1) {
2099 foreach ($search_crit as $crit) {
2103 $sql .=
"(s.nom LIKE '" . $this->db->escape($prefix . $crit) .
"%')";
2106 if (count($search_crit) > 1) {
2110 $sql .=
" OR s.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
2112 $sql .=
" OR s.code_client LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.code_fournisseur LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
2113 $sql .=
" OR s.name_alias LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.tva_intra LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
2116 $sql .= $this->db->order(
"nom",
"ASC");
2117 $sql .= $this->db->plimit($limit, 0);
2120 dol_syslog(get_class($this).
"::select_thirdparty_list", LOG_DEBUG);
2121 $resql = $this->db->query($sql);
2124 $out .=
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
' name="' . $htmlname . ($multiple ?
'[]' :
'') .
'"' . ($multiple ?
' multiple' :
'') .
'>' .
"\n";
2126 $textifempty = (($showempty && !is_numeric($showempty)) ? $langs->trans($showempty) :
'');
2130 if ($showempty && !is_numeric($showempty)) {
2131 $textifempty = $langs->trans($showempty);
2133 $textifempty .= $langs->trans(
"All");
2137 $out .=
'<option value="-1" data-html="' .
dol_escape_htmltag(
'<span class="opacitymedium">' . ($textifempty ? $textifempty :
' ') .
'</span>') .
'">' . $textifempty .
'</option>' .
"\n";
2140 $companytemp =
new Societe($this->db);
2142 $num = $this->db->num_rows($resql);
2146 $obj = $this->db->fetch_object($resql);
2149 if (($obj->client) && (!empty($obj->code_client))) {
2150 $label = $obj->code_client .
' - ';
2152 if (($obj->fournisseur) && (!empty($obj->code_fournisseur))) {
2153 $label .= $obj->code_fournisseur .
' - ';
2155 $label .=
' ' . $obj->name;
2157 $label = $obj->name;
2160 if (!empty($obj->name_alias)) {
2161 $label .=
' (' . $obj->name_alias .
')';
2165 $label .=
' - '.$obj->tva_intra;
2168 $labelhtml = $label;
2171 $companytemp->id = $obj->rowid;
2172 $companytemp->client = $obj->client;
2173 $companytemp->fournisseur = $obj->fournisseur;
2174 $tmptype = $companytemp->getTypeUrl(1,
'', 0,
'span');
2176 $labelhtml .=
' ' . $tmptype;
2179 if ($obj->client || $obj->fournisseur) {
2182 if ($obj->client == 1 || $obj->client == 3) {
2183 $label .= $langs->trans(
"Customer");
2185 if ($obj->client == 2 || $obj->client == 3) {
2186 $label .= ($obj->client == 3 ?
', ' :
'') . $langs->trans(
"Prospect");
2188 if ($obj->fournisseur) {
2189 $label .= ($obj->client ?
', ' :
'') . $langs->trans(
"Supplier");
2191 if ($obj->client || $obj->fournisseur) {
2197 $s = ($obj->address ?
' - ' . $obj->address :
'') . ($obj->zip ?
' - ' . $obj->zip :
'') . ($obj->town ?
' ' . $obj->town :
'');
2198 if (!empty($obj->country_code)) {
2199 $s .=
', ' . $langs->trans(
'Country' . $obj->country_code);
2205 if (empty($outputmode)) {
2206 if (in_array($obj->rowid, $selected)) {
2207 $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>';
2209 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
2212 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label,
'labelhtml' => $labelhtml));
2216 if (($i % 10) == 0) {
2221 $out .=
'</select>' .
"\n";
2223 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2230 $this->result = array(
'nbofthirdparties' => $num);
2264 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 =
'')
2266 global
$conf, $user, $langs, $hookmanager, $action;
2268 $langs->load(
'companies');
2270 if (empty($htmlid)) {
2271 $htmlid = $htmlname;
2275 $outarray = array();
2277 if ($selected ===
'') {
2278 $selected = array();
2279 } elseif (!is_array($selected)) {
2280 $selected = array((
int) $selected);
2284 if (function_exists(
'testSqlAndScriptInject')) {
2287 return 'SQLInjectionTryDetected';
2291 if ($filter !=
'') {
2292 if (preg_match(
'/[\(\)]/', $filter)) {
2298 if (function_exists(
'testSqlAndScriptInject')) {
2301 return 'SQLInjectionTryDetected';
2307 dol_syslog(
"Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Filter Syntax.", LOG_WARNING);
2311 if (!is_object($hookmanager)) {
2312 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
2317 $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";
2318 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
2319 $sql .=
", s.nom as company, s.town AS company_town";
2321 $sql .=
" FROM " . $this->db->prefix() .
"socpeople as sp";
2322 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
2323 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON s.rowid = sp.fk_soc";
2325 $sql .=
" WHERE sp.entity IN (" .
getEntity(
'contact') .
")";
2326 $sql .=
" AND ((sp.fk_user_creat = ".((int) $user->id).
" AND sp.priv = 1) OR sp.priv = 0)";
2327 if ($socid > 0 || $socid == -1) {
2328 $sql .=
" AND sp.fk_soc = " . ((int) $socid);
2331 $sql .=
" AND sp.statut <> 0";
2334 if (!$user->hasRight(
'societe',
'client',
'voir') && !$user->socid) {
2335 $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 .
")";
2337 if ($user->socid > 0) {
2338 $sql .=
" AND sp.fk_soc = ".((int) $user->socid);
2343 $sanitizedfilter = $filter;
2344 $sql .=
" AND (" . $sanitizedfilter .
")";
2347 $parameters = array();
2348 $reshook = $hookmanager->executeHooks(
'selectContactListWhere', $parameters);
2349 $sql .= $hookmanager->resPrint;
2350 $sql .=
" ORDER BY sp.lastname ASC";
2352 dol_syslog(get_class($this) .
"::selectcontacts", LOG_DEBUG);
2353 $resql = $this->db->query($sql);
2355 $num = $this->db->num_rows($resql);
2357 if ($htmlname !=
'none' && !$options_only) {
2358 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlid .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . (($num || empty($disableifempty)) ?
'' :
' disabled') . ($multiple ?
'multiple' :
'') .
' ' . (!empty($moreparam) ? $moreparam :
'') .
'>';
2361 if ($showempty && !is_numeric($showempty)) {
2362 $textforempty = $showempty;
2363 $out .=
'<option class="optiongrey" value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'>' .
dol_escape_htmltag($textforempty) .
'</option>';
2365 if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) {
2366 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'> </option>';
2368 if ($showempty == 2) {
2369 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Internal") .
' --</option>';
2375 include_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
2376 $contactstatic =
new Contact($this->db);
2379 $obj = $this->db->fetch_object($resql);
2382 $extendedInfos =
'';
2384 $extendedInfos = array();
2385 $email = trim($obj->email);
2386 if (!empty($email)) {
2387 $extendedInfos[] = $email;
2389 $phone = trim($obj->phone);
2390 $phone_perso = trim($obj->phone_perso);
2391 $phone_mobile = trim($obj->phone_mobile);
2392 if (!empty($phone)) {
2393 $extendedInfos[] = $phone;
2395 if (!empty($phone_perso)) {
2396 $extendedInfos[] = $phone_perso;
2398 if (!empty($phone_mobile)) {
2399 $extendedInfos[] = $phone_mobile;
2402 $contact_town = trim($obj->contact_town);
2403 $company_town = trim($obj->company_town);
2404 if (!empty($contact_town)) {
2405 $extendedInfos[] = $contact_town;
2406 } elseif (!empty($company_town)) {
2407 $extendedInfos[] = $company_town;
2409 $extendedInfos = implode(
' - ', $extendedInfos);
2410 if (!empty($extendedInfos)) {
2411 $extendedInfos =
' - ' . $extendedInfos;
2415 $contactstatic->id = $obj->rowid;
2416 $contactstatic->lastname = $obj->lastname;
2417 $contactstatic->firstname = $obj->firstname;
2418 if ($obj->statut == 1) {
2420 if ($htmlname !=
'none') {
2422 if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) {
2425 if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) {
2428 if (!empty($selected) && in_array($obj->rowid, $selected)) {
2429 $out .=
'<option value="' . $obj->rowid .
'"';
2431 $out .=
' disabled';
2433 $out .=
' selected>';
2435 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
2436 if ($showfunction && $obj->poste) {
2437 $tmplabel .=
' (' . $obj->poste .
')';
2439 if (($showsoc > 0) && $obj->company) {
2440 $tmplabel .=
' - (' . $obj->company .
')';
2444 $out .=
'</option>';
2446 $out .=
'<option value="' . $obj->rowid .
'"';
2448 $out .=
' disabled';
2452 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
2453 if ($showfunction && $obj->poste) {
2454 $tmplabel .=
' (' . $obj->poste .
')';
2456 if (($showsoc > 0) && $obj->company) {
2457 $tmplabel .=
' - (' . $obj->company .
')';
2461 $out .=
'</option>';
2464 if (in_array($obj->rowid, $selected)) {
2465 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
2466 if ($showfunction && $obj->poste) {
2467 $tmplabel .=
' (' . $obj->poste .
')';
2469 if (($showsoc > 0) && $obj->company) {
2470 $tmplabel .=
' - (' . $obj->company .
')';
2477 if ($tmplabel !=
'') {
2478 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $tmplabel,
'label' => $tmplabel,
'labelhtml' => $tmplabel));
2484 $labeltoshow = ($socid != -1) ? ($langs->trans($socid ?
"NoContactDefinedForThirdParty" :
"NoContactDefined")) : $langs->trans(
'SelectAThirdPartyFirst');
2485 $out .=
'<option class="disabled" value="-1"' . (($showempty == 2 || $multiple) ?
'' :
' selected') .
' disabled="disabled">';
2486 $out .= $labeltoshow;
2487 $out .=
'</option>';
2490 $parameters = array(
2492 'htmlname' => $htmlname,
2495 'showfunction' => $showfunction,
2496 'showsoc' => $showsoc,
2499 $reshook = $hookmanager->executeHooks(
'afterSelectContactOptions', $parameters, $this, $action);
2501 if ($htmlname !=
'none' && !$options_only) {
2502 $out .=
'</select>';
2505 if (
$conf->use_javascript_ajax && !$forcecombo && !$options_only) {
2506 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2512 if ($options_only === 2) {
2540 global $langs,
$conf;
2543 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
2544 $sql .=
" re.description, re.fk_facture_source";
2545 $sql .=
" FROM " . $this->db->prefix() .
"societe_remise_except as re";
2546 $sql .=
" WHERE re.fk_soc = " . (int) $socid;
2547 $sql .=
" AND re.entity = " . ((int)
$conf->entity);
2549 $sanitizedfilter = $filter;
2550 $sql .=
" AND " . $sanitizedfilter;
2552 $sql .=
" ORDER BY re.description ASC";
2554 dol_syslog(get_class($this) .
"::select_remises", LOG_DEBUG);
2555 $resql = $this->db->query($sql);
2557 print
'<select id="select_' . $htmlname .
'" class="flat maxwidth200onsmartphone" name="' . $htmlname .
'">';
2558 $num = $this->db->num_rows($resql);
2560 $qualifiedlines = $num;
2564 print
'<option value="0"> </option>';
2566 $obj = $this->db->fetch_object($resql);
2567 $desc =
dol_trunc($obj->description, 40);
2568 if (preg_match(
'/\(CREDIT_NOTE\)/', $desc)) {
2569 $desc = preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $desc);
2571 if (preg_match(
'/\(DEPOSIT\)/', $desc)) {
2572 $desc = preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"Deposit"), $desc);
2574 if (preg_match(
'/\(EXCESS RECEIVED\)/', $desc)) {
2575 $desc = preg_replace(
'/\(EXCESS RECEIVED\)/', $langs->trans(
"ExcessReceived"), $desc);
2577 if (preg_match(
'/\(EXCESS PAID\)/', $desc)) {
2578 $desc = preg_replace(
'/\(EXCESS PAID\)/', $langs->trans(
"ExcessPaid"), $desc);
2582 if ($selected > 0 && $selected == $obj->rowid) {
2583 $selectstring =
' selected';
2587 if ($maxvalue > 0 && $obj->amount_ttc > $maxvalue) {
2589 $disabled =
' disabled';
2592 if (
getDolGlobalString(
'MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST') && !empty($obj->fk_facture_source)) {
2593 $tmpfac =
new Facture($this->db);
2594 if ($tmpfac->fetch($obj->fk_facture_source) > 0) {
2595 $desc = $desc .
' - ' . $tmpfac->ref;
2599 print
'<option value="' . $obj->rowid .
'"' . $selectstring . $disabled .
'>' . $desc .
' (' .
price($obj->amount_ht) .
' ' . $langs->trans(
"HT") .
' - ' .
price($obj->amount_ttc) .
' ' . $langs->trans(
"TTC") .
')</option>';
2606 return $qualifiedlines;
2631 public function select_users($selected =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include =
'', $enableonly = array(), $force_entity =
'0')
2634 print $this->
select_dolusers($selected, $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity);
2663 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)
2666 global
$conf, $user, $langs, $hookmanager;
2670 if (is_object($userselected)) {
2671 $selected = (int) $userselected->id;
2672 } elseif (is_numeric($userselected)) {
2673 $selected = (int) $userselected;
2674 } elseif (is_array($userselected)) {
2675 $selected = $userselected;
2681 if ((is_numeric($selected) && ((
int) $selected < -4 || empty($selected))) && !
getDolGlobalString(
'SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE')) {
2682 $selected = $user->id;
2686 if (!is_array($selected)) {
2687 if ($selected === -1 || $selected ===
'') {
2688 $selected = array();
2690 $selected = array($selected);
2695 $excludeUsers =
null;
2696 if (is_array($exclude)) {
2697 $excludeUsers = implode(
",", $exclude);
2701 $includeUsers =
null;
2702 $includeUsersArray = array();
2703 if (is_array($include)) {
2704 $includeUsersArray = $include;
2705 } elseif ($include ==
'hierarchy') {
2707 $includeUsersArray = $user->getAllChildIds(0);
2708 } elseif ($include ==
'hierarchyme') {
2710 $includeUsersArray = $user->getAllChildIds(1);
2725 $includeUsers = implode(
",", $includeUsersArray);
2730 $outarray = array();
2731 $outarray2 = array();
2734 $showlabelofentity =
isModEnabled(
'multicompany') && !
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE') &&
$conf->entity == 1 && !empty($user->admin) && empty($user->entity) && !preg_match(
'/^search_/', $htmlname);
2735 $userissuperadminentityone =
isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && empty($user->entity);
2738 $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";
2739 if ($showlabelofentity) {
2740 $sql .=
", e.label";
2742 $sql .=
" FROM " . $this->db->prefix() .
"user as u";
2743 if ($showlabelofentity) {
2744 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid = u.entity";
2747 if ($userissuperadminentityone && $force_entity !==
'default') {
2748 if (!empty($force_entity)) {
2749 $sql .=
" WHERE u.entity IN (0, " . $this->db->sanitize($force_entity) .
")";
2751 $sql .=
" WHERE u.entity IS NOT NULL";
2755 $sql .=
" WHERE u.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
2757 $sql .=
" WHERE u.entity IN (" .
getEntity(
'user') .
")";
2761 if (!empty($user->socid)) {
2762 $sql .=
" AND u.fk_soc = " . ((int) $user->socid);
2764 if (is_array($exclude) && $excludeUsers) {
2765 $sql .=
" AND u.rowid NOT IN (" . $this->db->sanitize($excludeUsers) .
")";
2767 if ($includeUsers) {
2768 $sql .=
" AND u.rowid IN (" . $this->db->sanitize($includeUsers) .
")";
2771 $sql .=
" AND (u.statut <> 0";
2772 if (!empty($selected)) {
2773 $sql .=
" OR u.rowid IN (".$this->db->sanitize(implode(
',', $selected)).
")";
2778 $sql .=
" AND u.employee <> 0";
2781 $sql .=
" AND u.fk_soc IS NULL";
2783 if (!empty($morefilter)) {
2786 if ($errormessage) {
2787 $this->errors[] = $errormessage;
2788 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2789 if ($outputmode == 0) {
2790 return 'Error bad param $morefilter';
2798 $reshook = $hookmanager->executeHooks(
'addSQLWhereFilterOnSelectUsers', array(), $this, $action);
2799 if (!empty($reshook)) {
2800 $sql .= $hookmanager->resPrint;
2804 $sql .=
" ORDER BY u.statut DESC, u.firstname ASC, u.lastname ASC";
2806 $sql .=
" ORDER BY u.statut DESC, u.lastname ASC, u.firstname ASC";
2809 dol_syslog(get_class($this) .
"::select_dolusers", LOG_DEBUG);
2811 $resql = $this->db->query($sql);
2813 $num = $this->db->num_rows($resql);
2817 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
' minwidth200') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
2818 if ($show_empty && !$multiple) {
2819 $textforempty =
' ';
2820 if (!empty(
$conf->use_javascript_ajax)) {
2821 $textforempty =
' ';
2823 if (!is_numeric($show_empty)) {
2824 $textforempty = $show_empty;
2826 $out .=
'<option class="optiongrey" value="' . ($show_empty < 0 ? $show_empty : -1) .
'"' . ((empty($selected) || in_array(-1, $selected)) ?
' selected' :
'') .
'>' .
dol_escape_htmltag($textforempty) .
'</option>' .
"\n";
2828 $outarray[($show_empty < 0 ? $show_empty : -1)] = $textforempty;
2829 $outarray2[($show_empty < 0 ? $show_empty : -1)] = array(
2830 'id' => ($show_empty < 0 ? $show_empty : -1),
2831 'label' => $textforempty,
2832 'labelhtml' => $textforempty,
2837 if ($showalso == 2 || $showalso == 3) {
2838 $out .=
'<option value="-3"' . ((in_array(-3, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"MyTeam") .
' --</option>' .
"\n";
2840 $hasAtLeastOneSubordinate = (count($user->getAllChildIds(1)) > 1);
2841 if ($hasAtLeastOneSubordinate) {
2843 $outarray[-3] =
'-- ' . $langs->trans(
"MyTeam") .
' --';
2844 $outarray2[-3] = array(
2846 'label' =>
'-- ' . $langs->trans(
"MyTeam") .
' --',
2847 'labelhtml' =>
'-- ' . $langs->trans(
"MyTeam") .
' --',
2853 if ($showalso == 1 || $showalso == 3) {
2854 $out .=
'<option value="-2"' . ((in_array(-2, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Everybody") .
' --</option>' .
"\n";
2856 $outarray[-2] =
'-- ' . $langs->trans(
"Everybody") .
' --';
2857 $outarray2[-2] = array(
2859 'label' =>
'-- ' . $langs->trans(
"Everybody") .
' --',
2860 'labelhtml' =>
'-- ' . $langs->trans(
"Everybody") .
' --',
2865 if ($showalso == 4) {
2866 $out .=
'<option value="-4"' . ((in_array(-4, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"AllProjectContacts") .
' --</option>' .
"\n";
2868 $outarray[-4] =
'-- ' . $langs->trans(
"AllProjectContacts") .
' --';
2869 $outarray2[-4] = array(
2871 'label' =>
'-- ' . $langs->trans(
"AllProjectContacts") .
' --',
2872 'labelhtml' =>
'-- ' . $langs->trans(
"AllProjectContacts") .
' --',
2878 $userstatic =
new User($this->db);
2881 $obj = $this->db->fetch_object($resql);
2883 $userstatic->id = $obj->rowid;
2884 $userstatic->lastname = $obj->lastname;
2885 $userstatic->firstname = $obj->firstname;
2886 $userstatic->photo = $obj->photo;
2887 $userstatic->status = $obj->status;
2888 $userstatic->entity = $obj->entity;
2889 $userstatic->admin = $obj->admin;
2890 $userstatic->gender = $obj->gender;
2893 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
2894 $disableline = ($enableonlytext ? $enableonlytext :
'1');
2898 $labeltoshowhtml =
'';
2905 $labeltoshow .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2906 $labeltoshowhtml .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2907 if (empty($obj->firstname) && empty($obj->lastname)) {
2908 $labeltoshow .= $obj->login;
2909 $labeltoshowhtml .= $obj->login;
2916 $moreinfo .= ($moreinfo ?
' - ' :
' (');
2917 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(');
2918 $moreinfo .= $obj->login;
2919 $moreinfohtml .= $obj->login;
2921 if ($showstatus >= 0) {
2922 if ($obj->status == 1 && $showstatus == 1) {
2923 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Enabled');
2924 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Enabled');
2926 if ($obj->status == 0 && $showstatus == 1) {
2927 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Disabled');
2928 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Disabled');
2931 if ($showlabelofentity) {
2932 if (empty($obj->entity)) {
2933 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
"AllEntities");
2934 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
"AllEntities");
2936 if ($obj->entity !=
$conf->entity) {
2937 $moreinfo .= ($moreinfo ?
' - ' :
' (') . ($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2938 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(').($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2942 $moreinfo .= (!empty($moreinfo) ?
')' :
'');
2943 $moreinfohtml .= (!empty($moreinfohtml) ?
')</span>' :
'');
2944 if (!empty($disableline) && $disableline !=
'1') {
2946 $moreinfo .=
' - ' . $disableline;
2947 $moreinfohtml .=
' - ' . $disableline;
2949 $labeltoshow .= $moreinfo;
2950 $labeltoshowhtml .= $moreinfohtml;
2952 $out .=
'<option value="' . $obj->rowid .
'"';
2953 if (!empty($disableline)) {
2954 $out .=
' disabled';
2956 if (in_array($obj->rowid, $selected)) {
2957 $out .=
' selected';
2959 $out .=
' data-html="';
2961 $outhtml = $userstatic->getNomUrl(-3,
'', 0, 1, 24, 1,
'login',
'', 1) .
' ';
2962 if ($showstatus >= 0 && $obj->status == 0) {
2963 $outhtml .=
'<strike class="opacitymediumxxx">';
2965 $outhtml .= $labeltoshowhtml;
2966 if ($showstatus >= 0 && $obj->status == 0) {
2967 $outhtml .=
'</strike>';
2969 $labeltoshowhtml = $outhtml;
2973 $out .= $labeltoshow;
2974 $out .=
'</option>';
2976 $outarray[$userstatic->id] = $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength) . $moreinfo;
2977 $outarray2[$userstatic->id] = array(
2978 'id' => $userstatic->id,
2979 'label' => $labeltoshow,
2980 'labelhtml' => $labeltoshowhtml,
2988 $out .=
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'" disabled>';
2989 $out .=
'<option value="">' . $langs->trans(
"None") .
'</option>';
2991 $out .=
'</select>';
2993 if ($num && !$forcecombo) {
2995 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3004 if ($outputmode == 2) {
3006 } elseif ($outputmode) {
3038 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)
3041 global $langs, $user;
3043 $userstatic =
new User($this->db);
3046 if (!empty($_SESSION[
'assignedtouser'])) {
3047 $assignedtouser = json_decode($_SESSION[
'assignedtouser'],
true);
3048 if (!is_array($assignedtouser)) {
3049 $assignedtouser = array();
3052 $assignedtouser = array();
3054 $nbassignetouser = count($assignedtouser);
3057 if ($nbassignetouser) {
3058 $out .=
'<ul class="attendees">';
3062 foreach ($assignedtouser as $key => $value) {
3063 if ($value[
'id'] == $ownerid) {
3069 $userstatic->fetch($value[
'id']);
3070 $out .= $userstatic->getNomUrl(-4);
3073 $ownerid = $value[
'id'];
3074 $out .=
' (' . $langs->trans(
"Owner") .
')';
3077 if ($nbassignetouser > 1 && $action !=
'view') {
3078 $canremoveassignee = 1;
3081 if (!$canremoveowner) {
3082 $canremoveassignee = 0;
3084 if (!$user->hasRight(
'agenda',
'allactions',
'create')) {
3085 $canremoveassignee = 0;
3090 if ($canremoveassignee) {
3093 $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 .
'">';
3097 if ($showproperties) {
3098 if ($ownerid == $value[
'id'] && is_array($listofuserid) && count($listofuserid) && in_array($ownerid, array_keys($listofuserid))) {
3099 $out .=
'<div class="myavailability inline-block">';
3100 $out .=
'<span class="hideonsmartphone"> - ';
3103 $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>';
3113 if ($nbassignetouser) {
3118 if ($action !=
'view') {
3120 $out .=
'<div class="divadduser'.$htmlname.
'">';
3121 $out .=
'<input type="hidden" class="removedassignedhidden" name="removedassigned" value="">';
3122 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
3123 $out .=
'jQuery(".removedassigned").click(function() { jQuery(".removedassignedhidden").val(jQuery(this).val()); });';
3124 $out .=
'jQuery(".assignedtouser").change(function() { console.log(jQuery(".assignedtouser option:selected").val());';
3125 $out .=
' if (jQuery(".assignedtouser option:selected").val() > 0) { jQuery("#' . $action .
'assignedtouser").attr("disabled", false); }';
3126 $out .=
' else { jQuery("#' . $action .
'assignedtouser").attr("disabled", true); }';
3128 $out .=
'})</script>';
3129 $out .=
img_picto(
'',
'user',
'class="pictofixedwidth"');
3130 $out .= $this->
select_dolusers(
'', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter, 0,
'',
'minwidth200');
3131 $out .=
' <button type="submit" disabled class="button valignmiddle smallpaddingimp reposition butActionAdd" id="' . $action .
'assignedtouser" name="' . $action .
'assignedtouser" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
3132 $out .= $langs->trans(
"Add").
'</button>';
3160 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())
3165 require_once DOL_DOCUMENT_ROOT.
'/resource/class/html.formresource.class.php';
3166 require_once DOL_DOCUMENT_ROOT.
'/resource/class/dolresource.class.php';
3171 if (!empty($_SESSION[
'assignedtoresource'])) {
3172 $assignedtoresource = json_decode($_SESSION[
'assignedtoresource'],
true);
3173 if (!is_array($assignedtoresource)) {
3174 $assignedtoresource = array();
3177 $assignedtoresource = array();
3179 $nbassignetoresource = count($assignedtoresource);
3182 if ($nbassignetoresource) {
3183 $out .=
'<ul class="attendees">';
3187 foreach ($assignedtoresource as $key => $value) {
3189 $resourcestatic->fetch($value[
'id']);
3190 $out .= $resourcestatic->getNomUrl(-1);
3191 if ($nbassignetoresource >= 1 && $action !=
'view') {
3192 $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 .
'">';
3195 if ($showproperties) {
3196 if (is_array($listofresourceid) && count($listofresourceid)) {
3197 $out .=
'<div class="myavailability inline-block">';
3198 $out .=
'<span class="hideonsmartphone"> - ';
3201 $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>';
3211 if ($nbassignetoresource) {
3216 if ($action !=
'view') {
3217 $out .=
'<input type="hidden" class="removedassignedresourcehidden" name="removedassignedresource" value="">';
3218 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
3219 $out .=
'jQuery(".removedassignedresource").click(function() { jQuery(".removedassignedresourcehidden").val(jQuery(this).val()); });';
3220 $out .=
'jQuery(".assignedtoresource").change(function() { console.log(jQuery(".assignedtoresource option:selected").val());';
3221 $out .=
' if (jQuery(".assignedtoresource option:selected").val() > 0) { jQuery("#' . $action .
'assignedtoresource").attr("disabled", false); }';
3222 $out .=
' else { jQuery("#' . $action .
'assignedtoresource").attr("disabled", true); }';
3224 $out .=
'})</script>';
3227 if ($nbassignetoresource) {
3230 $out .=
img_picto(
'',
'resource',
'class="pictofixedwidth"');
3232 $out .= $formresources->select_resource_list(0, $htmlname,
'', 1, 1, 0, $events,
'', 2, 0,
'minwidth200');
3234 $out .=
' <button type="submit" disabled class="button valignmiddle smallpaddingimp reposition butActionAdd" id="' . $action .
'assignedtoresource" name="' . $action .
'assignedtoresource" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
3235 $out .= $langs->trans(
"Add");
3236 $out .=
'</button>';
3274 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)
3277 global $langs,
$conf;
3282 $price_level = (!empty($price_level) ? $price_level : 0);
3283 if (is_null($ajaxoptions)) {
3284 $ajaxoptions = array();
3296 $placeholder = (is_numeric($showempty) ?
'' :
'placeholder="'.dolPrintHTML($showempty).
'"');
3298 if ($selected && empty($selected_input_value)) {
3299 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3300 $producttmpselect =
new Product($this->db);
3301 $producttmpselect->fetch($selected);
3302 $selected_input_value = $producttmpselect->ref;
3303 unset($producttmpselect);
3306 if ($filtertype ==
'') {
3314 $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;
3315 if ((
int) $warehouseId > 0) {
3316 $urloption .=
'&warehouseid=' . (int) $warehouseId;
3319 if (
isModEnabled(
'variants') && is_array($selected_combinations)) {
3325 <!-- script to auto show attributes select tags if a variant was selected -->
3326 <script nonce="' .
getNonce() .
'">
3327 // auto show attributes fields
3328 selected = ' . json_encode($selected_combinations) .
';
3331 jQuery(document).ready(function () {
3333 jQuery("input[name=\'prod_entry_mode\']").change(function () {
3334 if (jQuery(this).val() == \'free\') {
3335 jQuery(\'div#attributes_box\').empty();
3339 jQuery("'.$htmltag.
'#' . $htmlname .
'").change(function () {
3341 if (!jQuery(this).val()) {
3342 jQuery(\'div#attributes_box\').empty();
3346 console.log("A change has started. We get variants fields to inject html select");
3348 jQuery.getJSON("' . DOL_URL_ROOT .
'/variants/ajax/getCombinations.php", {
3349 id: jQuery(this).val()
3350 }, function (data) {
3351 jQuery(\'div#attributes_box\').empty();
3353 jQuery.each(data, function (key, val) {
3355 combvalues[val.id] = val.values;
3357 var span = jQuery(document.createElement(\'div\')).css({
3358 \'display\': \'table-row\'
3362 jQuery(document.createElement(\'div\')).text(val.label).css({
3363 \'font-weight\': \'bold\',
3364 \'display\': \'table-cell\'
3368 var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({
3369 \'margin-left\': \'15px\',
3370 \'white-space\': \'pre\'
3372 jQuery(document.createElement(\'option\')).val(\'\')
3375 jQuery.each(combvalues[val.id], function (key, val) {
3376 var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value);
3378 if (selected[val.fk_product_attribute] == val.id) {
3379 tag.attr(\'selected\', \'selected\');
3386 jQuery(\'div#attributes_box\').append(span);
3391 ' . ($selected ?
'jQuery("'.$htmltag.
'#' . $htmlname .
'").change();' :
'') .
'
3397 if (empty($hidelabel)) {
3399 } elseif ($hidelabel > 1) {
3401 if ($hidelabel == 2) {
3402 $out .=
img_picto($langs->trans(
"Search"),
'search');
3406 $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" />';
3407 if ($hidelabel == 3) {
3408 $out .=
img_picto($langs->trans(
"Search"),
'search');
3411 $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);
3413 $out .= $this->
select_produits_list($selected, $htmlname, $filtertype, $limit, $price_level,
'', $status, $finished, 0, $socid, $showempty, $forcecombo, $morecss, $hidepriceinlabel, $warehouseStatus, $status_purchase, $warehouseId);
3415 if (
isModEnabled(
'variants') && is_array($selected_combinations)) {
3419 $htmltag =
'select';
3421 <!-- script to auto show attributes select tags if a variant was selected -->
3422 <script nonce="' .
getNonce() .
'">
3423 // auto show attributes fields
3424 selected = ' . json_encode($selected_combinations) .
';
3427 jQuery(document).ready(function () {
3429 jQuery("input[name=\'prod_entry_mode\']").change(function () {
3430 if (jQuery(this).val() == \'free\') {
3431 jQuery(\'div#attributes_box\').empty();
3435 jQuery("'.$htmltag.
'#' . $htmlname .
'").change(function () {
3437 if (!jQuery(this).val()) {
3438 jQuery(\'div#attributes_box\').empty();
3442 console.log("A change has started. We get variants fields to inject html select");
3444 jQuery.getJSON("' . DOL_URL_ROOT .
'/variants/ajax/getCombinations.php", {
3445 id: jQuery(this).val()
3446 }, function (data) {
3447 jQuery(\'div#attributes_box\').empty();
3449 jQuery.each(data, function (key, val) {
3451 combvalues[val.id] = val.values;
3453 var span = jQuery(document.createElement(\'div\')).css({
3454 \'display\': \'table-row\'
3458 jQuery(document.createElement(\'div\')).text(val.label).css({
3459 \'font-weight\': \'bold\',
3460 \'display\': \'table-cell\'
3464 var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({
3465 \'margin-left\': \'15px\',
3466 \'white-space\': \'pre\'
3468 jQuery(document.createElement(\'option\')).val(\'\')
3471 jQuery.each(combvalues[val.id], function (key, val) {
3472 var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value);
3474 if (selected[val.fk_product_attribute] == val.id) {
3475 tag.attr(\'selected\', \'selected\');
3482 jQuery(\'div#attributes_box\').append(span);
3487 ' . ($selected ?
'jQuery("'.$htmltag.
'#' . $htmlname .
'").change();' :
'') .
'
3494 if (empty($nooutput)) {
3518 public function select_bom($selected =
'', $htmlname =
'bom_id', $limit = 0, $status = 1, $type = 0, $showempty =
'1', $morecss =
'', $nooutput =
'', $forcecombo = 0, $TProducts = [])
3522 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3528 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3533 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
3535 $sql =
'SELECT b.rowid, b.ref, b.label as bomLabel, p.label as productLabel';
3536 $sql .=
' FROM ' . $this->db->prefix() .
'bom_bom as b';
3537 $sql .=
' INNER JOIN ' . $this->db->prefix() .
'product as p ON b.fk_product = p.rowid';
3538 $sql .=
' WHERE b.entity IN (' .
getEntity(
'bom') .
')';
3539 if (!empty($status)) {
3540 $sql .=
' AND status = ' . (int) $status;
3542 if (!empty($type)) {
3543 $sql .=
' AND bomtype = ' . (int) $type;
3545 if (!empty($TProducts)) {
3546 $sql .=
' AND fk_product IN (' . $this->db->sanitize(implode(
',', $TProducts)) .
')';
3548 if (!empty($limit)) {
3549 $sql .=
' LIMIT ' . (int) $limit;
3551 $resql = $this->db->query($sql);
3554 $out .=
'<option value="-1"';
3555 if (empty($selected)) {
3556 $out .=
' selected';
3558 $out .=
'> </option>';
3560 while ($obj = $this->db->fetch_object($resql)) {
3561 $out .=
'<option value="' . $obj->rowid .
'"';
3562 if ($obj->rowid == $selected) {
3565 $out .=
'>' . $obj->ref .
' - ' . $obj->productLabel .
' - ' . $obj->bomLabel .
'</option>';
3571 $out .=
'</select>';
3572 if (empty($nooutput)) {
3607 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)
3611 global $hookmanager;
3614 $outarray = array();
3618 $langs->load(
'other');
3621 $warehouseStatusArray = array();
3622 if (!empty($warehouseStatus)) {
3623 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/entrepot.class.php';
3624 if (preg_match(
'/warehouseclosed/', $warehouseStatus)) {
3627 if (preg_match(
'/warehouseopen/', $warehouseStatus)) {
3630 if (preg_match(
'/warehouseinternal/', $warehouseStatus)) {
3635 $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";
3636 if (count($warehouseStatusArray)) {
3637 $selectFieldsGrouped =
", SUM(" . $this->db->ifsql(
"e.statut IS NULL",
"0",
"ps.reel") .
") as stock";
3639 $selectFieldsGrouped =
", " . $this->db->ifsql(
"p.stock IS NULL",
'0',
"p.stock") .
" AS stock";
3645 $parameters = array();
3646 $reshook = $hookmanager->executeHooks(
'selectProductsListSelect', $parameters);
3647 if (empty($reshook)) {
3648 $sql .= $selectFields.$selectFieldsGrouped.$hookmanager->resPrint;
3650 $sql .= $hookmanager->resPrint;
3655 $sql .=
", (SELECT " . $this->db->prefix() .
"categorie_product.fk_categorie
3656 FROM " . $this->db->prefix() .
"categorie_product
3657 WHERE " . $this->db->prefix() .
"categorie_product.fk_product = p.rowid
3659 ) AS categorie_product_id";
3664 $sql .=
', pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,';
3665 $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';
3666 $selectFields .=
", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custdefault_vat_code, custref, custdiscount_percent";
3670 $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";
3671 $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';
3676 $sql .=
", pl.label as label_translated";
3677 $sql .=
", pl.description as description_translated";
3678 $selectFields .=
", label_translated";
3679 $selectFields .=
", description_translated";
3683 $sql .=
", (SELECT pp.rowid FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
3684 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
3685 $sql .=
" AND price_level = " . ((int) $price_level);
3687 $sql .=
" ORDER BY date_price";
3688 $sql .=
" DESC LIMIT 1) as price_rowid";
3689 $sql .=
", (SELECT pp.price_by_qty 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_by_qty";
3695 $selectFields .=
", price_rowid, price_by_qty";
3700 $sql .=
" FROM ".$this->db->prefix().
"product as p";
3703 $sql .=
" USE INDEX (" . $this->db->sanitize(
getDolGlobalString(
'MAIN_PRODUCT_FORCE_INDEX')) .
")";
3707 $parameters = array(
3710 $reshook = $hookmanager->executeHooks(
'selectProductsListFrom', $parameters);
3711 $sql .= $hookmanager->resPrint;
3713 if (count($warehouseStatusArray)) {
3716 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_stock as ps ON ps.fk_product = p.rowid";
3717 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entrepot as e ON ps.fk_entrepot = e.rowid AND e.entity IN (" .
getEntity(
'stock') .
")";
3718 $sql .=
' AND e.statut IN (' . $this->db->sanitize($this->db->escape(implode(
',', $warehouseStatusArray))) .
')';
3724 $sql .=
" LEFT JOIN (";
3725 $sql .=
" SELECT pcp1.*";
3726 $sql .=
" FROM " . $this->db->prefix() .
"product_customer_price AS pcp1";
3727 $sql .=
" LEFT JOIN (";
3728 $sql .=
" SELECT fk_soc, fk_product, MIN(date_begin) AS date_begin";
3729 $sql .=
" FROM " . $this->db->prefix() .
"product_customer_price";
3730 $sql .=
" WHERE fk_soc = " . ((int) $socid);
3731 $sql .=
" AND date_begin <= '" . $this->db->idate($now) .
"'";
3732 $sql .=
" AND (date_end IS NULL OR '" . $this->db->idate($now) .
"' <= date_end)";
3733 $sql .=
" GROUP BY fk_soc, fk_product";
3734 $sql .=
" ) AS pcp2 ON pcp1.fk_soc = pcp2.fk_soc AND pcp1.fk_product = pcp2.fk_product AND pcp1.date_begin = pcp2.date_begin";
3735 $sql .=
" WHERE pcp2.fk_soc IS NOT NULL";
3736 $sql .=
" ) AS pcp ON pcp.fk_soc = " . ((int) $socid) .
" AND pcp.fk_product = p.rowid";
3740 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units as u ON u.rowid = p.fk_unit";
3744 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_lang as pl ON pl.fk_product = p.rowid";
3746 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
3747 $soc =
new Societe($this->db);
3748 $result = $soc->fetch($socid);
3749 if ($result > 0 && !empty($soc->default_lang)) {
3750 $sql .=
" AND pl.lang = '" . $this->db->escape($soc->default_lang) .
"'";
3752 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3755 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3760 $sql .=
' WHERE p.entity IN (' .
getEntity(
'product') .
')';
3763 if (strlen($filterkey) != 13) {
3764 $sql .=
" AND NOT EXISTS (SELECT pac.rowid FROM ".$this->db->prefix().
"product_attribute_combination as pac WHERE pac.fk_product_child = p.rowid)";
3767 $sql .=
" AND NOT EXISTS (SELECT pac.rowid FROM ".$this->db->prefix().
"product_attribute_combination as pac WHERE pac.fk_product_child = p.rowid)";
3770 if ($finished == 0) {
3771 $sql .=
" AND p.finished = " . ((int) $finished);
3772 } elseif ($finished == 1) {
3773 $sql .=
" AND p.finished = ".((int) $finished);
3776 $sql .=
" AND p.tosell = ".((int) $status);
3778 if ($status_purchase >= 0) {
3779 $sql .=
" AND p.tobuy = " . ((int) $status_purchase);
3782 if (strval($filtertype) !=
'') {
3783 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
3785 $sql .=
" AND p.fk_product_type = 1";
3787 $sql .=
" AND p.fk_product_type = 0";
3790 if ((
int) $warehouseId > 0) {
3791 $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)";
3795 $parameters = array(
3796 'filterkey' => &$filterkey,
3799 $reshook = $hookmanager->executeHooks(
'selectProductsListWhere', $parameters);
3800 $sql .= $hookmanager->resPrint;
3802 if ($filterkey !=
'') {
3803 $sqlSupplierSearch =
'';
3808 $search_crit = explode(
' ', $filterkey);
3810 if (count($search_crit) > 1) {
3813 foreach ($search_crit as $crit) {
3817 $sql .=
"(p.ref LIKE '" . $this->db->escape($prefix . $crit) .
"%' OR p.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3819 $sql .=
" OR pl.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3822 $sql .=
" OR pcp.ref_customer LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3825 $sql .=
" OR p.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3827 $sql .=
" OR pl.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3833 $sqlSupplierSearch .= !empty($sqlSupplierSearch) ?
' AND ' :
'';
3834 $sqlSupplierSearch .=
" pfp.ref_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3839 if (count($search_crit) > 1) {
3843 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3848 $sql .=
" OR EXISTS (SELECT pfp.fk_product FROM " . $this->db->prefix() .
"product_fournisseur_price as pfp WHERE p.rowid = pfp.fk_product";
3850 $sql .= $sqlSupplierSearch;
3856 if (count($warehouseStatusArray)) {
3857 $sql .=
" GROUP BY " . $this->db->sanitize($selectFields, 0, 0, 1);
3862 $sql .=
" ORDER BY categorie_product_id ".(getDolGlobalInt(
'PRODUCT_SORT_BY_CATEGORY') == 1 ?
"ASC" :
"DESC");
3864 $sql .= $this->db->order(
"p.ref");
3868 $sql .= $this->db->plimit($limit, 0);
3886 dol_syslog(get_class($this) .
"::select_produits_list search products", LOG_DEBUG);
3890 $result = $this->db->query($sql);
3893 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3894 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3895 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
3897 $num = $this->db->num_rows($result);
3902 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3906 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
3912 if ($showempty && !is_numeric($showempty)) {
3913 $textifempty = $langs->trans($showempty);
3915 $textifempty .= $langs->trans(
"All");
3918 if ($showempty && !is_numeric($showempty)) {
3919 $textifempty = $langs->trans($showempty);
3923 $out .=
'<option value="-1" selected>' . ($textifempty ? $textifempty :
' ') .
'</option>';
3927 while ($num && $i < $num) {
3930 $objp = $this->db->fetch_object($result);
3932 if ((
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1) {
3933 $sql =
"SELECT rowid, quantity, price, unitprice, remise_percent, remise, price_base_type";
3934 $sql .=
" FROM " . $this->db->prefix() .
"product_price_by_qty";
3935 $sql .=
" WHERE fk_product_price = " . ((int) $objp->price_rowid);
3936 $sql .=
" ORDER BY quantity ASC";
3938 dol_syslog(get_class($this) .
"::select_produits_list search prices by qty", LOG_DEBUG);
3939 $result2 = $this->db->query($sql);
3941 $nb_prices = $this->db->num_rows($result2);
3943 while ($nb_prices && $j < $nb_prices) {
3944 $objp2 = $this->db->fetch_object($result2);
3946 $objp->price_by_qty_rowid = $objp2->rowid;
3947 $objp->price_by_qty_price_base_type = $objp2->price_base_type;
3948 $objp->price_by_qty_quantity = $objp2->quantity;
3949 $objp->price_by_qty_unitprice = $objp2->unitprice;
3950 $objp->price_by_qty_remise_percent = $objp2->remise_percent;
3952 $objp->quantity = $objp2->quantity;
3953 $objp->price = $objp2->price;
3954 $objp->unitprice = $objp2->unitprice;
3955 $objp->remise_percent = $objp2->remise_percent;
3961 '@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';
3968 array_push($outarray, $optJson);
3972 if (
isModEnabled(
'dynamicprices') && !empty($objp->fk_price_expression)) {
3973 $price_product =
new Product($this->db);
3974 $price_product->fetch($objp->rowid,
'',
'',
'1');
3976 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3978 $price_result = $priceparser->parseProduct($price_product);
3979 if ($price_result >= 0) {
3980 $objp->price = $price_result;
3981 $objp->unitprice = $price_result;
3983 $objp->price_ttc = (float)
price2num($objp->price) * (1 + ($objp->tva_tx / 100));
3984 $objp->price_ttc =
price2num($objp->price_ttc,
'MU');
3987 if (
getDolGlobalInt(
'PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES') && !empty($objp->custprice)) {
3995 array_push($outarray, $optJson);
4001 $out .=
'</select>';
4003 $this->db->free($result);
4005 if (empty($outputmode)) {
4032 protected function constructProductListOption(&$objp, &$opt, &$optJson, $price_level, $selected, $hidepriceinlabel = 0, $filterkey =
'', $novirtualstock = 0)
4034 global $langs,
$conf, $user;
4035 global $hookmanager;
4041 $outlabel_translated =
'';
4043 $outdesc_translated =
'';
4049 $outpricebasetype =
'';
4051 $outdefault_vat_code =
'';
4057 $productlabel = $objp->label;
4058 if (!empty($objp->label_translated)) {
4059 $productlabel = $objp->label_translated;
4061 $label = $productlabel;
4062 if (!empty($filterkey) && $filterkey !=
'') {
4063 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
4066 $outkey = $objp->rowid;
4067 $outref = $objp->ref;
4068 $outrefcust = empty($objp->custref) ?
'' : $objp->custref;
4069 $outlabel = $objp->label;
4070 $outdesc = $objp->description;
4072 $outlabel_translated = $objp->label_translated;
4073 $outdesc_translated = $objp->description_translated;
4075 $outbarcode = $objp->barcode;
4076 $outorigin = $objp->fk_country;
4077 $outpbq = empty($objp->price_by_qty_rowid) ?
'' : $objp->price_by_qty_rowid;
4079 $outtype = $objp->fk_product_type;
4084 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
4090 if (!empty($objp->unit_short)) {
4091 $outvalUnits .=
' - ' . $objp->unit_short;
4095 if (!empty($objp->weight) && $objp->weight_units !==
null) {
4097 $outvalUnits .=
' - ' . $unitToShow;
4099 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
4100 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
4101 $outvalUnits .=
' - ' . $unitToShow;
4103 if (!empty($objp->surface) && $objp->surface_units !==
null) {
4105 $outvalUnits .=
' - ' . $unitToShow;
4107 if (!empty($objp->volume) && $objp->volume_units !==
null) {
4109 $outvalUnits .=
' - ' . $unitToShow;
4112 if ($outdurationvalue && $outdurationunit) {
4114 'h' => $langs->trans(
'Hour'),
4115 'd' => $langs->trans(
'Day'),
4116 'w' => $langs->trans(
'Week'),
4117 'm' => $langs->trans(
'Month'),
4118 'y' => $langs->trans(
'Year')
4120 if (isset($da[$outdurationunit])) {
4121 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
4128 if ($user->hasRight(
'stock',
'lire')) {
4129 if ($objp->stock > 0) {
4131 } elseif ($objp->stock <= 0) {
4139 $labeltosearch =
'';
4140 $labeltosearch .= $objp->ref;
4141 if (!empty($objp->custref)) {
4142 $labeltosearch .=
' (' . $objp->custref .
')';
4145 $labeltosearch .=
' (' . $outbarcode .
')';
4147 $labeltosearch .=
' - ' . $productlabel;
4149 $labeltosearch .=
' (' .
getCountry($outorigin,
'1') .
')';
4153 $labeltoshowhtml =
'';
4154 $labeltoshowhtml .= $objp->ref;
4155 if (!empty($objp->custref)) {
4156 $labeltoshowhtml .=
' (' . $objp->custref .
')';
4158 if (!empty($filterkey) && $filterkey !=
'') {
4159 $labeltoshowhtml = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $labeltoshowhtml, 1);
4162 $labeltoshowhtml .=
' (' . $outbarcode .
')';
4164 $labeltoshowhtml .=
' - ' .
dol_trunc($label, $maxlengtharticle);
4166 $labeltoshowhtml .=
' (' .
getCountry($outorigin,
'1') .
')';
4170 $labeltoshowstock =
'';
4171 $labeltoshowhtmlstock =
'';
4173 if ($user->hasRight(
'stock',
'lire')) {
4174 $labeltoshowstock .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
4176 if ($objp->stock > 0) {
4177 $labeltoshowhtmlstock .=
' - <span class="product_line_stock_ok">';
4178 } elseif ($objp->stock <= 0) {
4179 $labeltoshowhtmlstock .=
' - <span class="product_line_stock_too_low">';
4181 $labeltoshowhtmlstock .= $langs->transnoentities(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
4182 $labeltoshowhtmlstock .=
'</span>';
4184 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
4185 $langs->load(
"stocks");
4187 $tmpproduct =
new Product($this->db);
4188 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
4189 $tmpproduct->load_virtual_stock();
4190 $virtualstock = $tmpproduct->stock_theorique;
4192 $labeltoshowstock .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
4194 $labeltoshowhtmlstock .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
4195 if ($virtualstock > 0) {
4196 $labeltoshowhtmlstock .=
'<span class="product_line_stock_ok">';
4197 } elseif ($virtualstock <= 0) {
4198 $labeltoshowhtmlstock .=
'<span class="product_line_stock_too_low">';
4200 $labeltoshowhtmlstock .= $virtualstock;
4201 $labeltoshowhtmlstock .=
'</span>';
4210 $labeltoshowprice =
'';
4211 $labeltoshowhtmlprice =
'';
4214 $sql =
"SELECT price, price_ttc, price_base_type, tva_tx, default_vat_code";
4215 $sql .=
" FROM " . $this->db->prefix() .
"product_price";
4216 $sql .=
" WHERE fk_product = " . ((int) $objp->rowid);
4217 $sql .=
" AND entity IN (" .
getEntity(
'productprice') .
")";
4218 $sql .=
" AND price_level = " . ((int) $price_level);
4219 $sql .=
" ORDER BY date_price DESC, rowid DESC";
4222 dol_syslog(get_class($this) .
'::constructProductListOption search price for product ' . $objp->rowid .
' AND level ' . $price_level, LOG_DEBUG);
4223 $result2 = $this->db->query($sql);
4225 $objp2 = $this->db->fetch_object($result2);
4228 if ($objp2->price_base_type ==
'HT') {
4229 $labeltoshowprice .=
' - ' .
price($objp2->price, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
4230 $labeltoshowhtmlprice .=
' - ' .
price($objp2->price, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
4232 $labeltoshowprice .=
' - ' .
price($objp2->price_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
4233 $labeltoshowhtmlprice .=
' - ' .
price($objp2->price_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
4235 $outprice_ht =
price($objp2->price);
4236 $outprice_ttc =
price($objp2->price_ttc);
4237 $outpricebasetype = $objp2->price_base_type;
4239 $outtva_tx = $objp2->tva_tx;
4240 $outdefault_vat_code = $objp2->default_vat_code;
4242 $outtva_tx = $objp->tva_tx;
4243 $outdefault_vat_code = $objp->default_vat_code;
4252 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1 && (
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
4254 $outqty = $objp->quantity;
4255 $outdiscount = $objp->remise_percent;
4256 if ($objp->quantity == 1) {
4257 $labeltoshowprice .=
' - ' .
price($objp->unitprice, 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
4258 $labeltoshowhtmlprice .=
' - ' .
price($objp->unitprice, 0, $langs, 0, 0, -1,
$conf->currency) .
"/";
4259 $labeltoshowprice .= $langs->trans(
"Unit");
4260 $labeltoshowhtmlprice .= $langs->transnoentities(
"Unit");
4262 $labeltoshowprice .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
4263 $labeltoshowhtmlprice .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
4264 $labeltoshowprice .= $langs->trans(
"Units");
4265 $labeltoshowhtmlprice .= $langs->transnoentities(
"Units");
4268 $outprice_ht =
price($objp->unitprice);
4269 $outprice_ttc =
price($objp->unitprice * (1 + ($objp->tva_tx / 100)));
4270 $outpricebasetype = $objp->price_base_type;
4271 $outtva_tx = $objp->tva_tx;
4272 $outdefault_vat_code = $objp->default_vat_code;
4274 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1) {
4275 $labeltoshowprice .=
" (" .
price($objp->unitprice, 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->trans(
"Unit") .
")";
4276 $labeltoshowhtmlprice .=
" (" .
price($objp->unitprice, 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->transnoentities(
"Unit") .
")";
4278 if (empty($hidepriceinlabel) && !empty($objp->remise_percent) && $objp->remise_percent >= 1) {
4279 $labeltoshowprice .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4280 $labeltoshowhtmlprice .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4285 if (!empty($objp->idprodcustprice)) {
4288 if ($objp->custprice_base_type ==
'HT') {
4289 $labeltoshowprice .=
' - ' .
price($objp->custprice, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
4290 $labeltoshowhtmlprice .=
' - ' .
price($objp->custprice, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
4292 $labeltoshowprice .=
' - ' .
price($objp->custprice_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
4293 $labeltoshowhtmlprice .=
' - ' .
price($objp->custprice_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
4296 $outprice_ht =
price($objp->custprice);
4297 $outprice_ttc =
price($objp->custprice_ttc);
4298 $outpricebasetype = $objp->custprice_base_type;
4299 $outtva_tx = $objp->custtva_tx;
4300 $outdefault_vat_code = $objp->custdefault_vat_code;
4301 $outdiscount = $objp->custdiscount_percent;
4306 if (empty($hidepriceinlabel) && !$found) {
4307 if ($objp->price_base_type ==
'HT') {
4308 $labeltoshowprice .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
4309 $labeltoshowhtmlprice .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
4311 $labeltoshowprice .=
' - ' .
price($objp->price_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
4312 $labeltoshowhtmlprice .=
' - ' .
price($objp->price_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
4314 $outprice_ht =
price($objp->price);
4315 $outprice_ttc =
price($objp->price_ttc);
4316 $outpricebasetype = $objp->price_base_type;
4317 $outtva_tx = $objp->tva_tx;
4318 $outdefault_vat_code = $objp->default_vat_code;
4321 $optiontext = $labeltosearch.$outvalUnits.$labeltoshowprice.$labeltoshowstock;
4322 $optionhtml = $labeltoshowhtml.$outvalUnits.$labeltoshowhtmlprice.$labeltoshowhtmlstock;
4326 $opt =
'<option value="' . $objp->rowid .
'"';
4327 $opt .= ($objp->rowid == $selected) ?
' selected' :
'';
4328 if (!empty($objp->price_by_qty_rowid) && $objp->price_by_qty_rowid > 0) {
4329 $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 .
'"';
4332 $opt .=
' data-labeltrans="' .
dol_escape_htmltag($outlabel_translated, 0, 0,
'', 0, 1) .
'"';
4336 if ($stocktag == 1) {
4337 $opt .=
' class="product_line_stock_ok" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml, 0, array(
'strong')).dolPrintHTMLForAttribute($outvalUnits).$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
4340 if ($stocktag == -1) {
4341 $opt .=
' class="product_line_stock_too_low" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml, 0, array(
'strong')).dolPrintHTMLForAttribute($outvalUnits).$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
4344 $opt .=
' data-html="'.$optionhtmlforattribute.
'" data-select-html="'.$optionhtmlforattribute.
'"';
4350 $outval .= $labeltoshowhtml;
4353 $outval .= $outvalUnits;
4356 $outval .= $labeltoshowhtmlprice;
4359 $outval .= $labeltoshowhtmlstock;
4362 $parameters = array(
'objp' => $objp);
4363 $reshook = $hookmanager->executeHooks(
'constructProductListOption', $parameters);
4364 if (empty($reshook)) {
4365 $opt .= $hookmanager->resPrint;
4367 $opt = $hookmanager->resPrint;
4370 $opt .=
"</option>\n";
4375 'label2' => $outlabel,
4379 'price_ttc' =>
price2num($outprice_ttc),
4382 'pricebasetype' => $outpricebasetype,
4383 'tva_tx' => $outtva_tx,
4384 'default_vat_code' => $outdefault_vat_code,
4386 'discount' => $outdiscount,
4387 'duration_value' => $outdurationvalue,
4388 'duration_unit' => $outdurationunit,
4390 'labeltrans' => $outlabel_translated,
4391 'desctrans' => $outdesc_translated,
4392 'ref_customer' => $outrefcust
4414 public function select_produits_fournisseurs($socid, $selected =
'', $htmlname =
'productid', $filtertype =
'', $notused =
'', $ajaxoptions = array(), $hidelabel = 0, $alsoproductwithnosupplierprice = 0, $morecss =
'', $placeholder =
'', $nooutput = 0)
4417 global $langs,
$conf;
4418 global $price_level, $status, $finished;
4420 if (!isset($status)) {
4424 $selected_input_value =
'';
4426 $regtmpsel = array();
4427 if ((
int) $selected > 0) {
4428 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
4429 $producttmpselect =
new Product($this->db);
4430 $producttmpselect->fetch((
int) $selected);
4431 $selected_input_value = $producttmpselect->ref;
4432 unset($producttmpselect);
4433 } elseif (preg_match(
'/^idprod_([0-9]+)$/', (
string) $selected, $regtmpsel)) {
4435 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
4436 $producttmpselect =
new Product($this->db);
4437 $producttmpselect->fetch((
int) $regtmpsel[1]);
4438 $selected_input_value = $producttmpselect->ref;
4439 unset($producttmpselect);
4443 $urloption = ($socid > 0 ?
'socid=' . $socid .
'&' :
'') .
'htmlname=' . $htmlname .
'&outjson=1&price_level=' . $price_level .
'&type=' . $filtertype .
'&mode=2&status=' . $status .
'&finished=' . $finished .
'&alsoproductwithnosupplierprice=' . $alsoproductwithnosupplierprice;
4445 $s = ($hidelabel ?
'' : $langs->trans(
"RefOrLabel") .
' : ') .
'<input type="text" class="'.$morecss.
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . ($placeholder ?
' placeholder="' . $placeholder .
'"' :
'') .
' spellcheck="false">';
4447 $s .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT .
'/product/ajax/products.php', $urloption,
getDolGlobalInt(
'PRODUIT_USE_SEARCH_TO_SELECT'), 0, $ajaxoptions);
4449 $s = $this->
select_produits_fournisseurs_list($socid, $selected, $htmlname, $filtertype, $notused,
'', $status, 0, 0, $alsoproductwithnosupplierprice, $morecss,
getDolGlobalInt(
'SUPPLIER_SHOW_STOCK_IN_PRODUCTS_COMBO'), $placeholder);
4479 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 =
'')
4482 global $langs,
$conf, $user;
4483 global $hookmanager;
4486 $outarray = array();
4490 $langs->load(
'stocks');
4493 $langs->load(
'other');
4496 $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,";
4497 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice, pfp.barcode";
4498 $sql .=
", pfp.multicurrency_code, pfp.multicurrency_unitprice";
4499 $sql .=
", pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.default_vat_code, pfp.fk_soc, s.nom as name";
4500 $sql .=
", pfp.supplier_reputation";
4503 $sql .=
", pfp.desc_fourn as description";
4505 $sql .=
", p.description";
4509 $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";
4514 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListSelect', $parameters);
4515 $sql .= $hookmanager->resPrint;
4517 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
4521 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListFrom', $parameters);
4522 $sql .= $hookmanager->resPrint;
4524 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN (" .
getEntity(
'product') .
") )";
4526 $sql .=
" AND pfp.fk_soc = " . ((int) $socid);
4528 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
4531 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
4533 $sql .=
" WHERE p.entity IN (" .
getEntity(
'product') .
")";
4534 if ($statut != -1) {
4535 $sql .=
" AND p.tobuy = " . ((int) $statut);
4537 if (strval($filtertype) !=
'') {
4538 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
4542 $parameters = array();
4543 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListWhere', $parameters);
4544 $sql .= $hookmanager->resPrint;
4546 if ($filterkey !=
'') {
4550 $search_crit = explode(
' ', $filterkey);
4552 if (count($search_crit) > 1) {
4555 foreach ($search_crit as $crit) {
4559 $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) .
"%'";
4561 $sql .=
" OR pfp.desc_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
4566 if (count($search_crit) > 1) {
4570 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
4571 $sql .=
" OR pfp.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
4575 $sql .=
" ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC";
4576 $sql .= $this->db->plimit($limit, 0);
4580 dol_syslog(get_class($this) .
"::select_produits_fournisseurs_list", LOG_DEBUG);
4581 $result = $this->db->query($sql);
4583 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4584 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
4586 $num = $this->db->num_rows($result);
4589 $out .=
'<select class="flat ' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'">';
4591 $out .=
'<option value="-1" selected>' . ($placeholder ? $placeholder :
' ') .
'</option>';
4593 $out .=
'<option value="-1">' . ($placeholder ? $placeholder :
' ') .
'</option>';
4598 $objp = $this->db->fetch_object($result);
4600 if (is_null($objp->idprodfournprice)) {
4602 $objp->tva_tx = $objp->tva_tx_sale;
4603 $objp->default_vat_code = $objp->default_vat_code_sale;
4606 $outkey = $objp->idprodfournprice;
4607 if (!$outkey && $alsoproductwithnosupplierprice) {
4608 $outkey =
'idprod_' . $objp->rowid;
4611 $outref = $objp->ref;
4612 $outbarcode = $objp->barcode;
4615 $outtype = $objp->fk_product_type;
4622 if (!empty($objp->unit_short)) {
4623 $outvalUnits .=
' - ' . $objp->unit_short;
4625 if (!empty($objp->weight) && $objp->weight_units !==
null) {
4627 $outvalUnits .=
' - ' . $unitToShow;
4629 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
4630 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
4631 $outvalUnits .=
' - ' . $unitToShow;
4633 if (!empty($objp->surface) && $objp->surface_units !==
null) {
4635 $outvalUnits .=
' - ' . $unitToShow;
4637 if (!empty($objp->volume) && $objp->volume_units !==
null) {
4639 $outvalUnits .=
' - ' . $unitToShow;
4641 if ($outdurationvalue && $outdurationunit) {
4643 'h' => $langs->trans(
'Hour'),
4644 'd' => $langs->trans(
'Day'),
4645 'w' => $langs->trans(
'Week'),
4646 'm' => $langs->trans(
'Month'),
4647 'y' => $langs->trans(
'Year')
4649 if (isset($da[$outdurationunit])) {
4650 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
4655 $objRef = $objp->ref;
4656 if ($filterkey && $filterkey !=
'') {
4657 $objRef = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRef, 1);
4659 $objRefFourn = $objp->ref_fourn;
4660 if ($filterkey && $filterkey !=
'') {
4661 $objRefFourn = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRefFourn, 1);
4663 $label = $objp->label;
4664 if ($filterkey && $filterkey !=
'') {
4665 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
4668 switch ($objp->fk_product_type) {
4680 if (empty($picto)) {
4683 $optlabel =
img_object(
'', $picto,
'class="paddingright classfortooltip"', 0, 0, 1);
4686 $optlabel .= $objp->ref;
4687 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
4688 $optlabel .=
' <span class="opacitymedium">(' . $objp->ref_fourn .
')</span>';
4690 if (
isModEnabled(
'barcode') && !empty($objp->barcode)) {
4691 $optlabel .=
' (' . $outbarcode .
')';
4693 $optlabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
4695 $outvallabel = $objRef;
4696 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
4697 $outvallabel .=
' (' . $objRefFourn .
')';
4699 if (
isModEnabled(
'barcode') && !empty($objp->barcode)) {
4700 $outvallabel .=
' (' . $outbarcode .
')';
4702 $outvallabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
4704 $outsearchlabel = implode(
' ', array_filter(array(
4705 (
string) $objp->ref,
4706 (
string) $objp->ref_fourn,
4707 (
string) $objp->barcode,
4708 (
string) $objp->label,
4710 ), function (
string $value):
bool {
4711 return $value !==
'';
4715 $optlabel .= $outvalUnits;
4716 $outvallabel .= $outvalUnits;
4718 if (!empty($objp->idprodfournprice)) {
4719 $outqty = $objp->quantity;
4720 $outdiscount = $objp->remise_percent;
4721 if (
isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
4723 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
4724 $prod_supplier->id = $objp->fk_product;
4725 $prod_supplier->fourn_qty = $objp->quantity;
4726 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
4727 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
4729 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4731 $price_result = $priceparser->parseProductSupplier($prod_supplier);
4732 if ($price_result >= 0) {
4733 $objp->fprice = $price_result;
4734 if ($objp->quantity >= 1) {
4735 $objp->unitprice = $objp->fprice / $objp->quantity;
4739 if ($objp->quantity == 1) {
4740 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
4741 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1,
$conf->currency) .
"/";
4742 $optlabel .= $langs->trans(
"Unit");
4743 $outvallabel .= $langs->transnoentities(
"Unit");
4745 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
4746 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
4747 $optlabel .=
' ' . $langs->trans(
"Units");
4748 $outvallabel .=
' ' . $langs->transnoentities(
"Units");
4751 if ($objp->quantity != 1) {
4752 $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") .
")";
4753 $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") .
")";
4755 if ($objp->remise_percent >= 1) {
4756 $optlabel .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4757 $outvallabel .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4759 if ($objp->duration) {
4760 $optlabel .=
" - " . $objp->duration;
4761 $outvallabel .=
" - " . $objp->duration;
4764 $optlabel .=
" - " .
dol_trunc($objp->name, 8);
4765 $outvallabel .=
" - " .
dol_trunc($objp->name, 8);
4767 if ($objp->supplier_reputation) {
4769 $reputations = array(
'' => $langs->trans(
'Standard'),
'FAVORITE' => $langs->trans(
'Favorite'),
'NOTTHGOOD' => $langs->trans(
'NotTheGoodQualitySupplier'),
'DONOTORDER' => $langs->trans(
'DoNotOrderThisProductToThisSupplier'));
4771 $optlabel .=
" - " . $reputations[$objp->supplier_reputation];
4772 $outvallabel .=
" - " . $reputations[$objp->supplier_reputation];
4775 $optlabel .=
" - <span class='opacitymedium'>" . $langs->trans(
"NoPriceDefinedForThisSupplier") .
'</span>';
4776 $outvallabel .=
' - ' . $langs->transnoentities(
"NoPriceDefinedForThisSupplier");
4780 $novirtualstock = ($showstockinlist == 2);
4782 if ($user->hasRight(
'stock',
'lire')) {
4783 $outvallabel .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
4785 if ($objp->stock > 0) {
4786 $optlabel .=
' - <span class="product_line_stock_ok">';
4787 } elseif ($objp->stock <= 0) {
4788 $optlabel .=
' - <span class="product_line_stock_too_low">';
4790 $optlabel .= $langs->transnoentities(
"Stock") .
':' .
price(
price2num($objp->stock,
'MS'));
4791 $optlabel .=
'</span>';
4792 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
4793 $langs->load(
"stocks");
4795 $tmpproduct =
new Product($this->db);
4796 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
4797 $tmpproduct->load_virtual_stock();
4798 $virtualstock = $tmpproduct->stock_theorique;
4800 $outvallabel .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
4802 $optlabel .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
4803 if ($virtualstock > 0) {
4804 $optlabel .=
'<span class="product_line_stock_ok">';
4805 } elseif ($virtualstock <= 0) {
4806 $optlabel .=
'<span class="product_line_stock_too_low">';
4808 $optlabel .= $virtualstock;
4809 $optlabel .=
'</span>';
4816 $optstart =
'<option value="' . $outkey .
'"';
4817 if ($selected && preg_match(
'/^idprod_/', (
string) $selected) && (
string) $selected ==
'idprod_'.$objp->rowid) {
4818 $optstart .=
' selected';
4819 } elseif ($selected && (
string) $selected == (
string) $objp->idprodfournprice) {
4820 $optstart .=
' selected';
4823 if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) {
4824 $optstart .=
' disabled';
4827 if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) {
4836 $optstart .=
' data-default-vat-code="' .
dol_escape_htmltag($objp->default_vat_code) .
'"';
4839 $optstart .=
' data-multicurrency-code="' .
dol_escape_htmltag($objp->multicurrency_code) .
'"';
4843 $optstart .=
' data-description="' .
dol_escape_htmltag($objp->description, 0, 1) .
'"';
4847 $outarrayentry = array(
4850 'label' => $outvallabel,
4851 'labelhtml' => $optlabel,
4853 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4854 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4855 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4856 'tva_tx_formated' =>
price($objp->tva_tx, 0, $langs, 1, -1, 2),
4858 'default_vat_code' => $objp->default_vat_code,
4859 'supplier_ref' => $objp->ref_fourn,
4860 'discount' => $outdiscount,
4862 'duration_value' => $outdurationvalue,
4863 'duration_unit' => $outdurationunit,
4864 'disabled' => empty($objp->idprodfournprice),
4865 'description' => $objp->description
4868 $outarrayentry[
'multicurrency_code'] = $objp->multicurrency_code;
4869 $outarrayentry[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4871 $parameters = array(
4873 'optstart' => &$optstart,
4874 'optlabel' => &$optlabel,
4875 'outvallabel' => &$outvallabel,
4876 'outarrayentry' => &$outarrayentry,
4879 $reshook = $hookmanager->executeHooks(
'selectProduitsFournisseurListOption', $parameters, $this);
4885 $out .= $optstart .
' data-html="' .
dol_escape_htmltag($optlabel) .
'">' . $optlabel .
"</option>\n";
4886 $outarraypush = array(
4889 'label' => $outvallabel,
4890 'labelhtml' => $optlabel,
4892 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4893 'price_qty_ht_locale' =>
price($objp->fprice),
4894 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4895 'price_unit_ht_locale' =>
price($objp->unitprice),
4896 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4897 'tva_tx_formated' =>
price($objp->tva_tx),
4899 'default_vat_code' => $objp->default_vat_code,
4900 'supplier_ref' => $objp->ref_fourn,
4901 'discount' => $outdiscount,
4903 'duration_value' => $outdurationvalue,
4904 'duration_unit' => $outdurationunit,
4905 'disabled' => empty($objp->idprodfournprice),
4906 'description' => $objp->description
4909 $outarraypush[
'multicurrency_code'] = $objp->multicurrency_code;
4910 $outarraypush[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4912 array_push($outarray, $outarraypush);
4925 $out .=
'</select>';
4927 $this->db->free($result);
4929 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
4935 if (empty($outputmode)) {
4954 global $langs,
$conf;
4956 $langs->load(
'stocks');
4958 $sql =
"SELECT p.rowid, p.ref, p.label, p.price, p.duration, pfp.fk_soc,";
4959 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.remise_percent, pfp.quantity, pfp.unitprice,";
4960 $sql .=
" pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name";
4961 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
4962 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
4963 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
4964 $sql .=
" WHERE pfp.entity IN (" .
getEntity(
'productsupplierprice') .
")";
4965 $sql .=
" AND p.tobuy = 1";
4966 $sql .=
" AND s.fournisseur = 1";
4967 $sql .=
" AND p.rowid = " . ((int) $productid);
4969 $sql .=
" ORDER BY s.nom, pfp.ref_fourn DESC";
4971 $sql .=
" ORDER BY pfp.unitprice - pfp.unitprice * pfp.remise_percent / 100 ASC";
4974 dol_syslog(get_class($this) .
"::select_product_fourn_price", LOG_DEBUG);
4975 $result = $this->db->query($sql);
4978 $num = $this->db->num_rows($result);
4980 $form =
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
4983 $form .=
'<option value="0">-- ' . $langs->trans(
"NoSupplierPriceDefinedForThisProduct") .
' --</option>';
4985 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4986 $form .=
'<option value="0"> </option>';
4990 $objp = $this->db->fetch_object($result);
4992 $opt =
'<option value="' . $objp->idprodfournprice .
'"';
4994 if ($num == 1 || ($selected_supplier > 0 && $objp->fk_soc == $selected_supplier) || ($i == 0 &&
getDolGlobalString(
'PRODUCT_BEST_SUPPLIER_PRICE_PRESELECTED'))) {
4995 $opt .=
' selected';
4997 $opt .=
'>' . $objp->name .
' - ' . $objp->ref_fourn .
' - ';
4999 if (
isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
5001 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
5002 $prod_supplier->id = $productid;
5003 $prod_supplier->fourn_qty = $objp->quantity;
5004 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
5005 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
5007 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
5009 $price_result = $priceparser->parseProductSupplier($prod_supplier);
5010 if ($price_result >= 0) {
5011 $objp->fprice = $price_result;
5012 if ($objp->quantity >= 1) {
5013 $objp->unitprice = $objp->fprice / $objp->quantity;
5017 if ($objp->quantity == 1) {
5018 $opt .=
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
5021 $opt .= $objp->quantity .
' ';
5023 if ($objp->quantity == 1) {
5024 $opt .= $langs->trans(
"Unit");
5026 $opt .= $langs->trans(
"Units");
5028 if ($objp->quantity > 1) {
5030 $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");
5032 if ($objp->duration) {
5033 $opt .=
" - " . $objp->duration;
5035 $opt .=
"</option>\n";
5042 $form .=
'</select>';
5043 $this->db->free($result);
5061 global $langs, $hookmanager;
5063 $num = count($this->cache_conditions_paiements);
5070 $this->cache_conditions_paiements = array();
5072 $sql =
"SELECT rowid, code, libelle as label, deposit_percent, entity";
5073 $sql .=
" FROM " . $this->db->prefix() .
'c_payment_term';
5074 $sql .=
" WHERE entity IN (" .
getEntity(
'c_payment_term') .
")";
5075 $sql .=
" AND active > 0";
5076 $sql .=
" ORDER BY sortorder";
5078 $resql = $this->db->query($sql);
5080 $num = $this->db->num_rows($resql);
5083 $obj = $this->db->fetch_object($resql);
5086 $label = ($langs->trans(
"PaymentConditionShort" . $obj->code) !=
"PaymentConditionShort" . $obj->code ? $langs->trans(
"PaymentConditionShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
5088 $this->cache_conditions_paiements[$obj->rowid][
'code'] = (
string) $obj->code;
5089 $this->cache_conditions_paiements[$obj->rowid][
'label'] = (
string) $label;
5090 $this->cache_conditions_paiements[$obj->rowid][
'deposit_percent'] = (
string) $obj->deposit_percent;
5091 $this->cache_conditions_paiements[$obj->rowid][
'entity'] = (int) $obj->entity;
5096 $parameters = array(
'dictionary' =>
'paymentterm');
5097 $reshook = $hookmanager->executeHooks(
'loadDictionaryCache', $parameters, $this);
5098 if (empty($reshook)) {
5099 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
5100 $this->cache_conditions_paiements = array_merge($this->cache_conditions_paiements, $hookmanager->resArray);
5103 $this->cache_conditions_paiements = $hookmanager->resArray;
5127 $this->cache_rule_for_lines_dates = $factureRec->fields[
'rule_for_lines_dates'][
'arrayofkeyval'];
5129 if (empty($this->cache_rule_for_lines_dates)) {
5148 $num = count($this->cache_availability);
5155 $this->cache_availability = array();
5157 $langs->load(
'propal');
5159 $sql =
"SELECT rowid, code, label, position";
5160 $sql .=
" FROM " . $this->db->prefix() .
'c_availability';
5161 $sql .=
" WHERE active > 0";
5163 $resql = $this->db->query($sql);
5165 $num = $this->db->num_rows($resql);
5168 $obj = $this->db->fetch_object($resql);
5171 $label = ($langs->trans(
"AvailabilityType" . $obj->code) !=
"AvailabilityType" . $obj->code ? $langs->trans(
"AvailabilityType" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
5172 $this->cache_availability[$obj->rowid][
'code'] = (
string) $obj->code;
5173 $this->cache_availability[$obj->rowid][
'label'] = (
string) $label;
5174 $this->cache_availability[$obj->rowid][
'position'] = (int) $obj->position;
5179 $this->cache_availability =
dol_sort_array($this->cache_availability,
'position',
'asc', 0, 0, 1);
5199 public function selectAvailabilityDelay($selected =
'', $htmlname =
'availid', $filtertype =
'', $addempty = 0, $morecss =
'', $noouput = 0)
5201 global $langs, $user;
5205 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
5207 $out =
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
5209 $out .=
'<option value="-1">'.(is_numeric($addempty) ?
' ' : $langs->trans($addempty)).
'</option>';
5211 foreach ($this->cache_availability as
$id => $arrayavailability) {
5212 if ($selected ==
$id) {
5213 $out .=
'<option value="' .
$id .
'" selected>';
5215 $out .=
'<option value="' .
$id .
'">';
5218 $out .=
'</option>';
5220 $out .=
'</select>';
5222 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5239 public function loadCacheInputReason()
5243 $num = count($this->cache_demand_reason);
5248 $sql =
"SELECT rowid, code, label";
5249 $sql .=
" FROM " . $this->db->prefix() .
'c_input_reason';
5250 $sql .=
" WHERE active > 0";
5252 $resql = $this->db->query($sql);
5254 $num = $this->db->num_rows($resql);
5257 $tmparray = array();
5259 $obj = $this->db->fetch_object($resql);
5262 $label = ($obj->label !=
'-' ? (
string) $obj->label :
'');
5263 if ($langs->trans(
"DemandReasonType" . $obj->code) !=
"DemandReasonType" . $obj->code) {
5264 $label = $langs->trans(
"DemandReasonType" . $obj->code);
5266 if ($langs->trans($obj->code) != $obj->code) {
5267 $label = $langs->trans($obj->code);
5270 $tmparray[(int) $obj->rowid]
5272 'id' => (
int) $obj->rowid,
5273 'code' => (
string) $obj->code,
5279 $this->cache_demand_reason =
dol_sort_array($tmparray,
'label',
'asc', 0, 0, 1);
5301 public function selectInputReason($selected =
'', $htmlname =
'demandreasonid', $exclude =
'', $addempty = 0, $morecss =
'', $notooltip = 0)
5303 global $langs, $user;
5305 $this->loadCacheInputReason();
5307 print
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
5309 print
'<option value="0"' . (empty($selected) ?
' selected' :
'') .
'> </option>';
5311 foreach ($this->cache_demand_reason as
$id => $arraydemandreason) {
5312 if ($arraydemandreason[
'code'] == $exclude) {
5316 if ($selected && ($selected == $arraydemandreason[
'id'] || $selected == $arraydemandreason[
'code'])) {
5317 print
'<option value="' . $arraydemandreason[
'id'] .
'" selected>';
5319 print
'<option value="' . $arraydemandreason[
'id'] .
'">';
5321 $label = $arraydemandreason[
'label'];
5322 print $langs->trans($label);
5326 if ($user->admin && empty($notooltip)) {
5327 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5342 global $langs, $hookmanager;
5344 $num = count($this->cache_types_paiements);
5351 $this->cache_types_paiements = array();
5353 $sql =
"SELECT id, code, libelle as label, type, entity, active";
5354 $sql .=
" FROM " . $this->db->prefix() .
"c_paiement";
5355 $sql .=
" WHERE entity IN (" .
getEntity(
'c_paiement') .
")";
5357 $resql = $this->db->query($sql);
5359 $num = $this->db->num_rows($resql);
5362 $obj = $this->db->fetch_object($resql);
5365 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) !=
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
5366 $this->cache_types_paiements[(int) $obj->id][
'id'] = (
int) $obj->id;
5367 $this->cache_types_paiements[(int) $obj->id][
'code'] = (
string) $obj->code;
5368 $this->cache_types_paiements[(int) $obj->id][
'label'] = (
string) $label;
5369 $this->cache_types_paiements[(int) $obj->id][
'type'] = (
int) $obj->type;
5370 $this->cache_types_paiements[(int) $obj->id][
'entity'] = (
int) $obj->entity;
5371 $this->cache_types_paiements[(int) $obj->id][
'active'] = (
int) $obj->active;
5375 $parameters = array(
'dictionary' =>
'paymenttype');
5376 $reshook = $hookmanager->executeHooks(
'loadDictionaryCache', $parameters, $this);
5377 if (empty($reshook)) {
5378 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
5379 $this->cache_types_paiements = array_merge($this->cache_types_paiements, $hookmanager->resArray);
5382 $this->cache_types_paiements = $hookmanager->resArray;
5385 $this->cache_types_paiements =
dol_sort_array($this->cache_types_paiements,
'label',
'asc', 0, 0, 1);
5415 public function select_conditions_paiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1, $noprint = 0)
5419 if (empty($noprint)) {
5443 public function getSelectConditionsPaiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1)
5445 global $langs, $user;
5448 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
5453 if (empty($selected) && strpos($htmlname,
'search_') !== 0 &&
getDolGlobalInt(
'MAIN_DEFAULT_PAYMENT_TERM_ID')) {
5454 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TERM_ID", LOG_NOTICE);
5458 $out .=
'<select id="' . $htmlname .
'" class="flat selectpaymentterms' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
5460 $out .=
'<option value="0"> </option>';
5463 $selectedDepositPercent =
null;
5465 foreach ($this->cache_conditions_paiements as
$id => $arrayconditions) {
5466 if ($filtertype <= 0 && !empty($arrayconditions[
'deposit_percent'])) {
5470 if ($selected ==
$id) {
5471 $selectedDepositPercent = $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'];
5472 $out .=
'<option value="' .
$id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'" selected>';
5474 $out .=
'<option value="' .
$id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'">';
5476 $label = $arrayconditions[
'label'];
5478 if (!empty($arrayconditions[
'deposit_percent'])) {
5479 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'], $label);
5483 $out .=
'</option>';
5485 $out .=
'</select>';
5486 if ($user->admin && empty($noinfoadmin)) {
5487 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5491 if ($deposit_percent >= 0) {
5492 $out .=
' <span id="' . $htmlname .
'_deposit_percent_container"' . (empty($selectedDepositPercent) ?
' style="display: none"' :
'') .
'>';
5493 $out .= $langs->trans(
'DepositPercent') .
' : ';
5494 $out .=
'<input id="' . $htmlname .
'_deposit_percent" name="' . $htmlname .
'_deposit_percent" class="maxwidth50" value="' . $deposit_percent .
'" />';
5497 <script nonce="' .
getNonce() .
'">
5498 $(document).ready(function () {
5499 $("#' . $htmlname .
'").change(function () {
5500 let $selected = $(this).find("option:selected");
5501 let depositPercent = $selected.attr("data-deposit_percent");
5503 if (depositPercent.length > 0) {
5504 $("#' . $htmlname .
'_deposit_percent_container").show().find("#' . $htmlname .
'_deposit_percent").val(depositPercent);
5506 $("#' . $htmlname .
'_deposit_percent_container").hide();
5535 $out .=
'<select id="' . $htmlname .
'" class="flat selectbillingterm" name="' . $htmlname .
'">';
5537 $out .=
'<option value="-1"> </option>';
5541 foreach ($this->cache_rule_for_lines_dates as $rule_for_lines_dates_key => $rule_for_lines_dates_name) {
5542 if ($selected == $rule_for_lines_dates_key) {
5543 $out .=
'<option value="' . $rule_for_lines_dates_key .
'" selected>';
5545 $out .=
'<option value="' . $rule_for_lines_dates_key .
'">';
5548 $out .= $langs->trans($rule_for_lines_dates_name);
5549 $out .=
'</option>';
5551 $out .=
'</select>';
5577 public function select_types_paiements($selected =
'', $htmlname =
'paiementtype', $filtertype =
'', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'', $nooutput = 0)
5580 global $langs, $user;
5584 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $filtertype .
", " . $format, LOG_DEBUG);
5586 $filterarray = array();
5587 if ($filtertype ==
'CRDT') {
5588 $filterarray = array(0, 2, 3);
5589 } elseif ($filtertype ==
'DBIT') {
5590 $filterarray = array(1, 2, 3);
5591 } elseif ($filtertype !=
'' && $filtertype !=
'-1') {
5592 $filterarray = explode(
',', $filtertype);
5598 if (empty($selected) && strpos($htmlname,
'search_') !== 0 &&
getDolGlobalString(
'MAIN_DEFAULT_PAYMENT_TYPE_ID')) {
5599 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TYPE_ID", LOG_NOTICE);
5603 $out .=
'<select id="select' . $htmlname .
'" class="flat selectpaymenttypes' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
5605 $out .=
'<option value=""> </option>';
5607 foreach ($this->cache_types_paiements as
$id => $arraytypes) {
5609 if ($active >= 0 && $arraytypes[
'active'] != $active) {
5614 if (count($filterarray) && !in_array($arraytypes[
'type'], $filterarray)) {
5619 if ($empty && empty($arraytypes[
'code'])) {
5624 $out .=
'<option value="' .
$id .
'" data-code="'.$arraytypes[
'code'].
'"';
5625 } elseif ($format == 1) {
5626 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
5627 } elseif ($format == 2) {
5628 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
5629 } elseif ($format == 3) {
5630 $out .=
'<option value="' .
$id .
'"';
5633 if ($format == 1 || $format == 2) {
5634 if ($selected == $arraytypes[
'code']) {
5635 $out .=
' selected';
5638 if ($selected ==
$id) {
5639 $out .=
' selected';
5645 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
5646 } elseif ($format == 1) {
5647 $value = $arraytypes[
'code'];
5648 } elseif ($format == 2) {
5649 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
5650 } elseif ($format == 3) {
5651 $value = $arraytypes[
'code'];
5653 $out .= $value ? $value :
' ';
5654 $out .=
'</option>';
5656 $out .=
'</select>';
5657 if ($user->admin && !$noadmininfo) {
5658 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5662 if (empty($nooutput)) {
5682 $return =
'<select class="flat maxwidth100" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
5684 'HT' => $langs->trans(
"HT"),
5685 'TTC' => $langs->trans(
"TTC")
5687 foreach ($options as
$id => $value) {
5688 if ($selected ==
$id) {
5689 $return .=
'<option value="' .
$id .
'" selected>' . $value;
5691 $return .=
'<option value="' .
$id .
'">' . $value;
5693 $return .=
'</option>';
5695 $return .=
'</select>';
5715 $num = count($this->cache_transport_mode);
5722 $this->cache_transport_mode = array();
5724 $sql =
"SELECT rowid, code, label, active";
5725 $sql .=
" FROM " . $this->db->prefix() .
"c_transport_mode";
5726 $sql .=
" WHERE entity IN (" .
getEntity(
'c_transport_mode') .
")";
5728 $resql = $this->db->query($sql);
5730 $num = $this->db->num_rows($resql);
5733 $obj = $this->db->fetch_object($resql);
5736 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) !=
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
5737 $this->cache_transport_mode[(int) $obj->rowid]
5739 'rowid' => (
int) $obj->rowid,
5740 'code' => (
string) $obj->code,
5741 'label' => (
string) $label,
5742 'active' => (int) $obj->active,
5747 $this->cache_transport_mode =
dol_sort_array($this->cache_transport_mode,
'label',
'asc', 0, 0, 1);
5769 public function selectTransportMode($selected =
'', $htmlname =
'transportmode', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'')
5771 global $langs, $user;
5773 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $format, LOG_DEBUG);
5777 print
'<select id="select' . $htmlname .
'" class="flat selectmodetransport' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
5779 print
'<option value=""> </option>';
5781 foreach ($this->cache_transport_mode as
$id => $arraytypes) {
5783 if ($active >= 0 && $arraytypes[
'active'] != $active) {
5788 if ($empty && empty($arraytypes[
'code'])) {
5793 print
'<option value="' .
$id .
'"';
5794 } elseif ($format == 1) {
5795 print
'<option value="' . $arraytypes[
'code'] .
'"';
5796 } elseif ($format == 2) {
5797 print
'<option value="' . $arraytypes[
'code'] .
'"';
5798 } elseif ($format == 3) {
5799 print
'<option value="' .
$id .
'"';
5802 if (preg_match(
'/[a-z]/i', $selected) && $selected == $arraytypes[
'code']) {
5804 } elseif ($selected ==
$id) {
5810 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
5811 } elseif ($format == 1) {
5812 $value = $arraytypes[
'code'];
5813 } elseif ($format == 2) {
5814 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
5815 } elseif ($format == 3) {
5816 $value = $arraytypes[
'code'];
5818 print $value ? $value :
' ';
5825 if ($user->admin && !$noadmininfo) {
5826 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5842 public function selectShippingMethod($selected =
'', $htmlname =
'shipping_method_id', $filtre =
'', $useempty = 0, $moreattrib =
'', $noinfoadmin = 0, $morecss =
'')
5844 global $langs, $user;
5846 $langs->loadLangs(array(
"admin",
"sendings"));
5848 $sql =
"SELECT rowid, code, libelle as label";
5849 $sql .=
" FROM " . $this->db->prefix() .
"c_shipment_mode";
5850 $sql .=
" WHERE active > 0";
5854 $sql .=
" ORDER BY libelle ASC";
5856 dol_syslog(get_class($this) .
"::selectShippingMode", LOG_DEBUG);
5858 $result = $this->db->query($sql);
5860 $num = $this->db->num_rows($result);
5863 print
'<select id="select' . $htmlname .
'" class="flat selectshippingmethod' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5864 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5865 print
'<option value="-1"> </option>';
5868 $obj = $this->db->fetch_object($result);
5869 if ($selected == $obj->rowid) {
5870 print
'<option value="' . $obj->rowid .
'" selected>';
5872 print
'<option value="' . $obj->rowid .
'">';
5874 print ($langs->trans(
"SendingMethod" . strtoupper($obj->code)) !=
"SendingMethod" . strtoupper($obj->code)) ? $langs->trans(
"SendingMethod" . strtoupper($obj->code)) : $obj->label;
5879 if ($user->admin && empty($noinfoadmin)) {
5880 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5885 print $langs->trans(
"NoShippingMethodDefined");
5905 $langs->load(
"sendings");
5907 if ($htmlname !=
"none") {
5908 print
'<form method="POST" action="' . $page .
'">';
5909 print
'<input type="hidden" name="action" value="setshippingmethod">';
5910 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5912 print
'<input type="submit" class="button valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5916 $code = $langs->getLabelFromKey($this->db, $selected,
'c_shipment_mode',
'rowid',
'code');
5917 print $langs->trans(
"SendingMethod" . strtoupper($code));
5936 $langs->load(
'bills');
5940 $sql =
"SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc";
5941 $sql .=
' FROM ' . $this->db->prefix() .
'facture';
5942 $sql .=
' WHERE entity IN (' .
getEntity(
'invoice') .
')';
5943 $sql .=
' AND situation_counter >= 1';
5944 $sql .=
' AND fk_soc = ' . (int) $socid;
5945 $sql .=
' AND type <> 2';
5946 $sql .=
' ORDER by situation_cycle_ref, situation_counter desc';
5947 $resql = $this->db->query($sql);
5949 $nbSituationInvoiceForThirdparty = 0;
5951 if ($resql && $this->db->num_rows($resql) > 0) {
5954 while ($obj = $this->db->fetch_object($resql)) {
5956 if ($obj->situation_cycle_ref != $ref) {
5958 $ref = $obj->situation_cycle_ref;
5960 if ($obj->situation_final != 1) {
5962 if (substr($obj->ref, 1, 4) !=
'PROV') {
5963 $nbSituationInvoiceForThirdparty++;
5965 if ($selected == $obj->rowid) {
5966 $opt .=
'<option value="' . $obj->rowid .
'" selected>' . $obj->ref .
'</option>';
5968 $opt .=
'<option value="' . $obj->rowid .
'">' . $obj->ref .
'</option>';
5975 dol_syslog(
"Error sql=" . $sql .
", error=" . $this->error, LOG_ERR);
5978 if ($nbSituationInvoiceForThirdparty > 0) {
5979 $opt =
'<option class="minwidth100" value="" selected> </option>'.$opt;
5981 $opt =
'<option class="minwidth100" value="-1" selected>'.$langs->trans(
'NoSituations').
'</option>';
5996 public function selectUnits($selected =
'', $htmlname =
'units', $showempty = 0, $unit_type =
'')
6000 $langs->load(
'products');
6002 $return =
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'">';
6004 $sql =
"SELECT rowid, label, code FROM " . $this->db->prefix() .
"c_units";
6005 $sql .=
' WHERE active > 0';
6006 if (!empty($unit_type)) {
6007 $sql .=
" AND unit_type = '" . $this->db->escape($unit_type) .
"'";
6009 $sql .=
" ORDER BY sortorder";
6011 $resql = $this->db->query($sql);
6012 if ($resql && $this->db->num_rows($resql) > 0) {
6014 $return .=
'<option value="-1"></option>';
6017 while ($res = $this->db->fetch_object($resql)) {
6018 $unitLabel = $res->label;
6019 if (!empty($langs->tab_translate[
'unit' . $res->code])) {
6020 $unitLabel = $langs->trans(
'unit' . $res->code) != $res->label ? $langs->trans(
'unit' . $res->code) : $res->label;
6023 if ($selected == $res->rowid) {
6024 $return .=
'<option value="' . $res->rowid .
'" selected>' . $unitLabel .
'</option>';
6026 $return .=
'<option value="' . $res->rowid .
'">' . $unitLabel .
'</option>';
6029 $return .=
'</select>';
6053 public function select_comptes($selected =
'', $htmlname =
'accountid', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'', $showcurrency = 0, $morecss =
'', $nooutput = 0, $addentrynone = 0)
6060 $langs->loadLangs(array(
"admin",
"banks"));
6063 $sql =
"SELECT rowid, label, bank, clos as status, currency_code";
6064 $sql .=
" FROM " . $this->db->prefix() .
"bank_account";
6065 $sql .=
" WHERE entity IN (" .
getEntity(
'bank_account') .
")";
6067 $sql .=
" AND clos = " . (int) $status;
6072 $sql .=
" ORDER BY label";
6074 dol_syslog(get_class($this) .
"::select_comptes", LOG_DEBUG);
6075 $result = $this->db->query($sql);
6077 $num = $this->db->num_rows($result);
6080 $out .=
'<select id="select' . $htmlname .
'" class="flat selectbankaccount' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
6084 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoActiveBankAccountDefined") .
'</span>';
6086 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoBankAccountDefined") .
'</span>';
6089 if (!empty($useempty) && !is_numeric($useempty)) {
6090 $out .=
'<option value="-1">'.$langs->trans($useempty).
'</option>';
6091 } elseif ($useempty == 1 || ($useempty == 2 && $num > 1)) {
6092 $out .=
'<option value="-1"> </option>';
6097 $obj = $this->db->fetch_object($result);
6099 $labeltoshow = trim($obj->label);
6100 $labeltoshowhtml = trim($obj->label);
6101 if ($showcurrency) {
6102 $labeltoshow .=
' (' . $obj->currency_code .
')';
6103 $labeltoshowhtml .=
' <span class="opacitymedium">(' . $obj->currency_code .
')</span>';
6105 if ($status == 2 && $obj->status == 1) {
6106 $labeltoshow .=
' (' . $langs->trans(
"Closed") .
')';
6107 $labeltoshowhtml .=
' <span class="opacitymedium">(' . $langs->trans(
"Closed") .
')</span>';
6110 if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
6111 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml).
'" selected>';
6113 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml).
'">';
6115 $out .= $labeltoshow;
6116 $out .=
'</option>';
6120 if (!empty($addentrynone)) {
6121 $out .=
'<option value="-2"'.($selected == -2 ?
' selected="selected"' :
'').
' data-html="'.
dolPrintHTMLForAttribute(
'<span class="opacitymedium">'.$langs->trans(
"None").
'</span>').
'">'.$langs->trans(
"None").
'</option>';
6124 $out .=
"</select>";
6131 if (empty($nooutput)) {
6153 public function selectRib($selected =
'', $htmlname =
'ribcompanyid', $filtre =
'', $useempty = 0, $moreattrib =
'', $showibanbic = 0, $morecss =
'', $nooutput = 0)
6160 $langs->loadLangs(array(
"admin",
"banks"));
6163 $sql =
"SELECT rowid, label, bank, status, iban_prefix, bic, default_rib";
6164 $sql .=
" FROM " . $this->db->prefix() .
"societe_rib";
6165 $sql .=
" WHERE type = 'ban'";
6169 $sql .=
" ORDER BY label";
6170 dol_syslog(get_class($this) .
"::select_comptes", LOG_DEBUG);
6171 $result = $this->db->query($sql);
6173 $num = $this->db->num_rows($result);
6176 $out .=
'<select id="select' . $htmlname .
'" class="flat selectbankaccount' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
6179 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoBankAccountDefined") .
'</span>';
6181 if (!empty($useempty) && !is_numeric($useempty)) {
6182 $out .=
'<option value="-1">'.$langs->trans($useempty).
'</option>';
6183 } elseif ($useempty == 1 || ($useempty == 2 && $num > 1)) {
6184 $out .=
'<option value="-1"> </option>';
6189 $obj = $this->db->fetch_object($result);
6191 if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
6192 $out .=
'<option value="' . $obj->rowid .
'" data-iban-prefix="' . $iban .
' data-bic="' . $obj->bic .
'" selected>';
6194 $out .=
'<option value="' . $obj->rowid .
'" data-iban-prefix="' . $iban .
' data-bic="' . $obj->bic .
'">';
6196 $out .= trim($obj->label);
6198 $out .=
' (' . $iban .
'/' .$obj->bic.
')' . ($obj->default_rib ?
' ['.$langs->trans(
"ByDefault").
']' :
'');
6200 $out .=
'</option>';
6203 $out .=
"</select>";
6210 if (empty($nooutput)) {
6230 public function selectEstablishments($selected =
'', $htmlname =
'entity', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'')
6234 $langs->load(
"admin");
6237 $sql =
"SELECT rowid, name, fk_country, status, entity";
6238 $sql .=
" FROM " . $this->db->prefix() .
"establishment";
6239 $sql .=
" WHERE 1=1";
6241 $sql .=
" AND status = " . (int) $status;
6246 $sql .=
" ORDER BY name";
6248 dol_syslog(get_class($this) .
"::select_establishment", LOG_DEBUG);
6249 $result = $this->db->query($sql);
6251 $num = $this->db->num_rows($result);
6254 print
'<select id="select' . $htmlname .
'" class="flat selectestablishment" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
6255 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
6256 print
'<option value="-1"> </option>';
6260 $obj = $this->db->fetch_object($result);
6261 if ($selected == $obj->rowid) {
6262 print
'<option value="' . $obj->rowid .
'" selected>';
6264 print
'<option value="' . $obj->rowid .
'">';
6266 print trim($obj->name);
6267 if ($status == 2 && $obj->status == 1) {
6268 print
' (' . $langs->trans(
"Closed") .
')';
6276 print
'<span class="opacitymedium">' . $langs->trans(
"NoActiveEstablishmentDefined") .
'</span>';
6278 print
'<span class="opacitymedium">' . $langs->trans(
"NoEstablishmentFound") .
'</span>';
6301 if ($htmlname !=
"none") {
6302 print
'<form method="POST" action="' . $page .
'">';
6303 print
'<input type="hidden" name="action" value="setbankaccount">';
6304 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6305 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
6306 $nbaccountfound = $this->
select_comptes($selected, $htmlname, 0,
'', $addempty);
6307 if ($nbaccountfound > 0) {
6308 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6312 $langs->load(
'banks');
6315 require_once DOL_DOCUMENT_ROOT .
'/compta/bank/class/account.class.php';
6316 $bankstatic =
new Account($this->db);
6317 $result = $bankstatic->fetch((
int) $selected);
6319 print $bankstatic->getNomUrl(1);
6338 public function formRib($page, $selected =
'', $htmlname =
'ribcompanyid', $filtre =
'', $addempty = 0, $showibanbic = 0)
6341 if ($htmlname !=
"none") {
6342 print
'<form method="POST" action="' . $page .
'">';
6343 print
'<input type="hidden" name="action" value="setbankaccountcustomer">';
6344 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6345 $nbaccountfound = $this->
selectRib($selected, $htmlname, $filtre, $addempty,
'', $showibanbic);
6346 if ($nbaccountfound > 0) {
6347 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6351 $langs->load(
'banks');
6354 require_once DOL_DOCUMENT_ROOT .
'/societe/class/companybankaccount.class.php';
6356 $result = $bankstatic->fetch((
int) $selected);
6358 print $bankstatic->label;
6360 print
' (' . $bankstatic->iban .
'/' .$bankstatic->bic.
')';
6386 $arrayselected = array();
6388 $arrayselected =
GETPOST($htmlname,
'array:int');
6391 $cats =
$c->containing(
$object->id, $categtype);
6392 $arrayselected = array();
6393 foreach ($cats as $cat) {
6394 $arrayselected[] = $cat->id;
6398 $out .=
img_picto(
'',
'category',
'class="pictofixedwidth"');
6399 $out .= $this->
multiselectarray($htmlname, $cate_arbo, $arrayselected, 0, 0,
'minwidth100 widthcentpercentminusxx', 0, 0);
6403 $jsonclose =
'doJsCodeAfterPopupClose'.dol_sanitizeKeyCode($htmlname).
'()';
6404 $urltoopen =
'/categories/categorie_list.php?type='.urlencode($categtype).
'&nosearch=1';
6409 $out .=
'<!-- Add js code to open the popup for category/edit/add -->'.
"\n";
6410 $out .=
'<script>function doJsCodeAfterPopupClose'.dol_sanitizeKeyCode($htmlname).
'() {
6411 console.log("doJsCodeAfterPopupClose'.
dol_sanitizeKeyCode($htmlname).
' has been called, we refresh the combo content + refresh select2...");
6413 // Call an ajax to reload values and update the select
6416 url: \''.DOL_URL_ROOT.
'/core/ajax/fetchCategories.php\',
6418 action: \'getCategories\',
6423 success: function (data) {
6424 var $select = $(\'#'.dol_sanitizeKeyCode($htmlname).
'\');
6425 var selectedValues = $select.val();
6426 console.log(selectedValues);
6428 $.each(data,
function (index, item) {
6429 $select.append(\
'<option value="\' + item.id + \'" data-html="\' + item.htmlforattribute + \'">\' + item.htmlforoption + \'</option>\');
6431 $select.val(selectedValues);
6433 error: function (xhr, status, error) {
6434 console.log("Error when loading ajax page : " + error);
6438 // Refresh select2 to take account of new values (enough for small change)
6441 // Alternative if change in select is complex
6473 public function select_all_categories($type, $selected =
'', $htmlname =
"parent", $maxlength = 64, $fromid = 0, $outputmode = 0, $include = 0, $morecss =
'', $useempty = 1)
6478 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
6482 if (is_numeric($type)) {
6483 $type = array_search($type, $cat->MAP_ID);
6486 $cate_arbo = $cat->get_full_arbo($type, $fromid, $include);
6488 $outarray = array();
6489 $outarrayrichhtml = array();
6492 $output =
'<select class="flat minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
6494 if (is_array($cate_arbo)) {
6495 $num = count($cate_arbo);
6498 $langs->load(
"categories");
6499 $output .=
'<option value="-1" disabled>' . $langs->trans(
"NoCategoriesDefined") .
'</option>';
6501 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
6502 $output .=
'<option value="-1"> </option>';
6504 foreach ($cate_arbo as $key => $value) {
6505 if ($cate_arbo[$key][
'id'] == $selected || ($selected ===
'auto' && count($cate_arbo) == 1)) {
6511 $labeltoshow =
img_picto(
'',
'category',
'class="pictofixedwidth"'.(empty($cate_arbo[$key][
'color']) ?
'' :
' style="color: #' . $cate_arbo[$key][
'color'] .
'"'));
6512 $labeltoshow .=
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle');
6514 $outarray[$cate_arbo[$key][
'id']] = $cate_arbo[$key][
'fulllabel'];
6516 $outarrayrichhtml[$cate_arbo[$key][
'id']] = $labeltoshow;
6518 $output .=
'<option ' . $add .
'value="' . $cate_arbo[$key][
'id'] .
'"';
6527 $output .=
'</option>';
6529 $cate_arbo[$key][
'data-html'] = $labeltoshow;
6533 $output .=
'</select>';
6538 if ($outputmode == 2) {
6541 } elseif ($outputmode == 1) {
6543 } elseif ($outputmode == 3) {
6544 return $outarrayrichhtml;
6564 $html =
'<details class="dolibarr-help-block" style="margin-top:8px;">';
6565 $html .=
'<summary style="cursor:pointer; color:#0056b3; font-weight:normal; list-style:none; font-size:0.9em; display:flex; align-items:center;">';
6566 $html .=
'<span class="fa ' . $icon .
'" style="margin-right:6px;"></span>';
6567 $html .= $langs->trans(
"Help");
6568 $html .=
'</summary>';
6569 $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;">';
6572 $html .=
'</details>';
6597 public function form_confirm($page, $title, $question, $action, $formquestion = array(), $selectedchoice =
"", $useajax = 0, $height = 170, $width = 500)
6600 dol_syslog(__METHOD__ .
': using form_confirm is deprecated. Use formconfim instead.', LOG_WARNING);
6601 print $this->
formconfirm($page, $title, $question, $action, $formquestion, $selectedchoice, $useajax, $height, $width);
6633 public function formconfirm($page, $title, $question, $action, $formquestion =
'', $selectedchoice =
'', $useajax = 0, $height = 0, $width = 600, $disableformtag = 0, $labelbuttonyes =
'Yes', $labelbuttonno =
'No', $helpContent =
'')
6635 global $langs,
$conf;
6638 $formconfirm =
'<!-- formconfirm - before call, page=' .
dol_escape_htmltag($page) .
' -->';
6644 $newselectedchoice = empty($selectedchoice) ?
"no" : $selectedchoice;
6645 if (
$conf->browser->layout ==
'phone') {
6650 if (empty($height)) {
6652 if (is_array($formquestion)) {
6653 $height += (count($formquestion) * 40);
6660 if (is_array($formquestion) && !empty($formquestion)) {
6662 foreach ($formquestion as $key => $input) {
6663 if (is_array($input) && !empty($input)) {
6664 if ($input[
'type'] ==
'hidden') {
6665 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
6666 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
6674 $moreonecolumn =
'';
6675 $more .=
'<div class="tagtable paddingtopbottomonly centpercent noborderspacing">' .
"\n";
6676 foreach ($formquestion as $key => $input) {
6677 if (is_array($input) && !empty($input)) {
6678 $size = (!empty($input[
'size']) ?
' size="' . $input[
'size'] .
'"' :
'');
6679 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
6680 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
6682 if ($input[
'type'] ==
'text' || $input[
'type'] ==
'input') {
6683 $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";
6684 } elseif ($input[
'type'] ==
'password') {
6685 $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";
6686 } elseif ($input[
'type'] ==
'textarea') {
6687 $moreonecolumn .=
'<div class="margintoponly">';
6688 $moreonecolumn .= ($input[
'label'] ??
'') .
'<br>';
6690 $moreonecolumn .= $input[
'value'] ??
'';
6691 $moreonecolumn .=
'</textarea>';
6692 $moreonecolumn .=
'</div>';
6693 } elseif (in_array($input[
'type'], [
'select',
'multiselect'])) {
6694 if (empty($morecss)) {
6695 $morecss =
'minwidth100';
6698 $show_empty = isset($input[
'select_show_empty']) ? $input[
'select_show_empty'] : 1;
6699 $key_in_label = isset($input[
'select_key_in_label']) ? $input[
'select_key_in_label'] : 0;
6700 $value_as_key = isset($input[
'select_value_as_key']) ? $input[
'select_value_as_key'] : 0;
6701 $translate = isset($input[
'select_translate']) ? $input[
'select_translate'] : 0;
6702 $maxlen = isset($input[
'select_maxlen']) ? $input[
'select_maxlen'] : 0;
6703 $disabled = isset($input[
'select_disabled']) ? $input[
'select_disabled'] : 0;
6704 $sort = isset($input[
'select_sort']) ? $input[
'select_sort'] :
'';
6706 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">';
6707 if (!empty($input[
'label'])) {
6708 $more .= $input[
'label'] .
'</div><div class="tagtd left">';
6710 if ($input[
'type'] ==
'select') {
6711 $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);
6713 $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);
6715 $more .=
'</div></div>' .
"\n";
6716 } elseif ($input[
'type'] ==
'checkbox') {
6717 $more .=
'<div class="tagtr">';
6718 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'"><label for="' .
dol_escape_htmltag($input[
'name']) .
'">' . $input[
'label'] .
'</label></div><div class="tagtd">';
6719 $more .=
'<input type="checkbox" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' .
dol_escape_htmltag($input[
'name']) .
'" name="' .
dol_escape_htmltag($input[
'name']) .
'"' . $moreattr;
6720 if (isset($input[
'value']) && !is_bool($input[
'value']) && $input[
'value'] !=
'false' && $input[
'value'] !=
'0' && $input[
'value'] !=
'') {
6721 $more .=
' checked';
6723 if (isset($input[
'value']) && is_bool($input[
'value']) && $input[
'value']) {
6724 $more .=
' checked';
6726 if (isset($input[
'disabled'])) {
6727 $more .=
' disabled';
6729 $more .=
' /></div>';
6730 $more .=
'</div>' .
"\n";
6731 } elseif ($input[
'type'] ==
'radio') {
6733 foreach ($input[
'values'] as $selkey => $selval) {
6734 $more .=
'<div class="tagtr">';
6735 if (isset($input[
'label'])) {
6737 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
' tdtop' : (
' tdtop ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
6739 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' "' . $input[
'tdclass'])) .
'"> </div>';
6742 $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;
6743 if (!empty($input[
'disabled'])) {
6744 $more .=
' disabled';
6746 if (isset($input[
'default']) && $input[
'default'] === $selkey) {
6747 $more .=
' checked="checked"';
6750 $more .=
'<label for="' .
dol_escape_htmltag($input[
'name'] . $selkey) .
'" class="valignmiddle">' . $selval .
'</label>';
6751 $more .=
'</div></div>' .
"\n";
6754 } elseif ($input[
'type'] ==
'date' || $input[
'type'] ==
'datetime') {
6755 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
6756 $more .=
'<div class="tagtd">';
6757 $addnowlink = (empty($input[
'datenow']) ? 0 : 1);
6759 if ($input[
'type'] ==
'datetime') {
6760 $h = isset($input[
'hours']) ? $input[
'hours'] : 1;
6761 $m = isset($input[
'minutes']) ? $input[
'minutes'] : 1;
6763 $more .= $this->
selectDate(isset($input[
'value']) ? $input[
'value'] : -1, $input[
'name'], $h, $m, 0,
'', 1, $addnowlink);
6764 $more .=
'</div></div>'.
"\n";
6765 $formquestion[] = array(
'name' => $input[
'name'].
'day');
6766 $formquestion[] = array(
'name' => $input[
'name'].
'month');
6767 $formquestion[] = array(
'name' => $input[
'name'].
'year');
6768 $formquestion[] = array(
'name' => $input[
'name'].
'hour');
6769 $formquestion[] = array(
'name' => $input[
'name'].
'min');
6770 } elseif ($input[
'type'] ==
'other') {
6771 $more .=
'<div class="tagtr"><div class="tagtd'.(empty($input[
'tdclass']) ?
'' : (
' '.$input[
'tdclass'])).
'">';
6772 if (!empty($input[
'label'])) {
6773 $more .= $input[
'label'] .
'</div><div class="tagtd">';
6775 if (!empty($input[
'value'])) {
6776 $more .= $input[
'value'];
6778 $more .=
'</div></div>' .
"\n";
6779 } elseif ($input[
'type'] ==
'onecolumn') {
6780 $moreonecolumn .=
'<div class="margintoponly">';
6781 $moreonecolumn .= $input[
'value'] ??
'';
6782 $moreonecolumn .=
'</div>' .
"\n";
6783 } elseif ($input[
'type'] ==
'hidden') {
6785 } elseif ($input[
'type'] ==
'separator') {
6788 $more .=
'Error type ' . $input[
'type'] .
' for the confirm box is not a supported type';
6792 $more .=
'</div>' .
"\n";
6793 $more .= $moreonecolumn;
6799 if (!empty(
$conf->dol_use_jmobile)) {
6802 if (empty(
$conf->use_javascript_ajax)) {
6808 $dialogconfirm =
'dialog-confirm';
6810 if (!is_numeric($useajax)) {
6814 $dialogconfirm .=
'-' . $button;
6816 $pageyes = $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=yes';
6817 $pageno = ($useajax == 2 ? $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=no' :
'');
6820 if (is_array($formquestion)) {
6821 foreach ($formquestion as $key => $input) {
6824 if (is_array($input) && isset($input[
'name'])) {
6825 if (strpos($input[
'name'],
',') > 0) {
6826 $inputok = array_merge($inputok, explode(
',', $input[
'name']));
6828 array_push($inputok, $input[
'name']);
6833 if (is_array($input) && isset($input[
'inputko']) && $input[
'inputko'] == 1 && isset($input[
'name'])) {
6834 array_push($inputko, $input[
'name']);
6841 $formconfirm .=
'<div id="' . $dialogconfirm .
'" title="' .
dol_escape_htmltag($title) .
'" style="display: none;">';
6842 $formconfirm .=
'<div style="display: flex; flex-direction: column; height: 100%;">';
6843 if (is_array($formquestion) && array_key_exists(
'text', $formquestion) && !empty($formquestion[
'text'])) {
6844 $formconfirm .=
'<div class="confirmtext">' . $formquestion[
'text'] .
'</div>' .
"\n";
6846 if (!empty($more)) {
6847 $formconfirm .=
'<div class="confirmquestions">' . $more .
'</div>' .
"\n";
6850 if (!empty($helpContent)) {
6851 $formconfirm .=
'<div style="text-align:left; margin-top:12px; padding-top:8px; border-top:1px solid #eee; clear:both;">';
6853 $formconfirm .=
'</div>';
6855 if (!empty($question)) {
6856 $formconfirm .=
'<div class="confirmmessage" style="padding-top: 15px;">';
6857 $formconfirm .=
img_help(0,
'') .
' ' . $question;
6858 $formconfirm .=
'</div>';
6860 $formconfirm .=
'</div>';
6861 $formconfirm .=
'</div>' .
"\n";
6863 $formconfirm .=
"\n<!-- begin code of popup for formconfirm page=" . $page .
" -->\n";
6864 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
6865 $formconfirm .=
"/* Code for the jQuery('#dialogforpopup').dialog() */\n";
6866 $formconfirm .=
'jQuery(document).ready(function() {
6868 $( "#' . $dialogconfirm .
'" ).dialog({
6869 autoOpen: ' . ($autoOpen ?
"true" :
"false") .
',';
6870 if ($newselectedchoice ==
'no') {
6873 $(this).parent().find("button.ui-button:eq(2)").focus();
6878 if ($useajax == 1) {
6879 $jsforcursor =
'// The call to urljump can be slow, so we set the wait cursor' .
"\n";
6880 $jsforcursor .=
'jQuery("html,body,#id-container").addClass("cursorwait");' .
"\n";
6883 $postconfirmas =
'GET';
6884 $maxurllengthforget =
getDolGlobalInt(
'MAIN_MAX_URL_LENGTH_FOR_GET', 2000);
6891 closeOnEscape:
false,
6893 "' . dol_escape_js($langs->transnoentities($labelbuttonyes)) . '":
function() {
6894 var options =
"token=' . urlencode(newToken()) . '";
6895 var inputok =
' . json_encode($inputok) . ';
6896 var page = \
'' .
dol_escape_js(!empty($page) ? $page :
'') .
'\';
6897 var pageyes = \
'' .
dol_escape_js(!empty($pageyes) ? $pageyes :
'') .
'\';
6899 if (inputok.length > 0) {
6900 $.each(inputok,
function(i, inputname) {
6903 if ($(
"input[name=\'" + inputname +
"\']").attr(
"type") ==
"radio") {
6904 inputvalue = $(
"input[name=\'" + inputname +
"\']:checked").val();
6906 if ($(
"#" + inputname).attr(
"type") ==
"checkbox") { more =
":checked"; }
6907 inputvalue = $(
"#" + inputname + more).val();
6909 if (typeof inputvalue ==
"undefined") { inputvalue=
""; }
6910 console.log(
"formconfirm check inputname="+inputname+
" inputvalue="+inputvalue);
6911 options +=
"&" + inputname +
"=" + encodeURIComponent(inputvalue);
6914 var urljump = pageyes + (pageyes.indexOf(
"?") < 0 ?
"?" :
"&") + options;
6915 if (pageyes.length > 0) {
';
6916 if ($postconfirmas == 'GET
') {
6917 $formconfirm .= 'dolSubmitConfirmForm(urljump, pageyes, options,
' . $maxurllengthforget . ');
';
6919 $formconfirm .= $jsforcursor;
6920 $formconfirm .= 'var post = $.post(
6923 function(data) { $(
"body").html(data); jQuery(
"html,body,#id-container").removeClass(
"cursorwait"); }
6927 console.log(
"after post ok");
6929 $(
this).dialog(
"close");
6931 "' . dol_escape_js($langs->transnoentities($labelbuttonno)) . '":
function() {
6932 var options =
"token=' . urlencode(newToken()) . '";
6933 var inputko =
' . json_encode($inputko) . ';
6934 var page =
"' . dol_escape_js(!empty($page) ? $page : '') . '";
6935 var pageno=
"' . dol_escape_js(!empty($pageno) ? $pageno : '') . '";
6936 if (inputko.length > 0) {
6937 $.each(inputko,
function(i, inputname) {
6939 if ($(
"#" + inputname).attr(
"type") ==
"checkbox") { more =
":checked"; }
6940 var inputvalue = $(
"#" + inputname + more).val();
6941 if (typeof inputvalue ==
"undefined") { inputvalue=
""; }
6942 options +=
"&" + inputname +
"=" + encodeURIComponent(inputvalue);
6945 var urljump=pageno + (pageno.indexOf(
"?") < 0 ?
"?" :
"&") + options;
6947 if (pageno.length > 0) {
';
6948 if ($postconfirmas == 'GET
') {
6949 $formconfirm .= 'dolSubmitConfirmForm(urljump, pageno, options,
' . $maxurllengthforget . ');
';
6951 $formconfirm .= $jsforcursor;
6952 $formconfirm .= 'var post = $.post(
6955 function(data) { $(
"body").html(data); jQuery(
"html,body,#id-container").removeClass(
"cursorwait"); }
6959 console.log(
"after post ko");
6961 $(
this).dialog(
"close");
6967 var
button =
"' . $button . '";
6969 $(
"#" +
button ).click(
function() {
6970 $(
"#' . $dialogconfirm . '").dialog(
"open");
6976 $formconfirm .= "<!-- end ajax formconfirm -->\n";
6978 $formconfirm .= "\n<!-- begin formconfirm page=" . dol_escape_htmltag($page) . " -->\n";
6980 if (empty($disableformtag)) {
6981 $formconfirm .= '<form method=
"POST" action=
"' . $page . '" class=
"notoptoleftnoright">
' . "\n";
6984 $formconfirm .= '<input
type=
"hidden" name=
"action" value=
"' . $action . '">
' . "\n";
6985 $formconfirm .= '<input
type=
"hidden" name=
"token" value=
"' . newToken() . '">
' . "\n";
6987 $formconfirm .= '<div
class=
"valid">
' . "\n";
6990 $formconfirm .= '<div
class=
"validtitre">
';
6991 $formconfirm .= img_picto('', 'pictoconfirm
') . ' ' . $title;
6992 $formconfirm .= '</div>
' . "\n";
6995 if (is_array($formquestion) && array_key_exists('text
', $formquestion) && !empty($formquestion['text
'])) {
6996 $formconfirm .= '<div
class=
"valid">
' . $formquestion['text
'] . '</div>
' . "\n";
7001 $formconfirm .= '<div>
' . "\n";
7002 $formconfirm .= $more;
7003 $formconfirm .= '</div>
' . "\n";
7006 // NEW: Help block row (between form fields and question)
7007 if (!empty($helpContent)) {
7008 $formconfirm .= '<div style=
"padding-top:8px; border-top:1px solid #888;">
';
7009 $formconfirm .= $this->getHelpBlock($helpContent);
7010 $formconfirm .= '</div>
' . "\n";
7013 // Let's add a row that acts as a spacer.
7014 $formconfirm .=
'<div style="padding-top: 20px;"></div>' .
"\n";
7017 $formconfirm .=
'<div class="inline-block">' . $question .
'</div>';
7019 $formconfirm .=
'<div class="inline-block">';
7020 $formconfirm .= $this->selectyesno(
"confirm", $newselectedchoice, 0,
false, 0, 0,
'marginleftonly marginrightonly', $labelbuttonyes, $labelbuttonno);
7021 $formconfirm .=
'<input class="button valignmiddle confirmvalidatebutton small" type="submit" value="' . $langs->trans(
"Validate") .
'">';
7022 $formconfirm .=
'</div>';
7024 $formconfirm .=
'</div>';
7026 if (empty($disableformtag)) {
7027 $formconfirm .=
"</form>\n";
7029 $formconfirm .=
'<br>';
7031 if (!empty(
$conf->use_javascript_ajax)) {
7032 $formconfirm .=
'<!-- code to disable button to avoid double clic -->';
7033 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
7035 $(document).ready(function () {
7036 $(".confirmvalidatebutton").on("click", function() {
7037 console.log("We click on button confirmvalidatebutton");
7038 $(this).attr("disabled", "disabled");
7039 setTimeout(\'$(".confirmvalidatebutton").removeAttr("disabled")\', 3000);
7040 //console.log($(this).closest("form"));
7041 $(this).closest("form").submit();
7045 $formconfirm .=
'</script>' .
"\n";
7048 $formconfirm .=
"<!-- end formconfirm -->\n";
7051 return $formconfirm;
7072 public function form_project($page, $socid, $selected =
'', $htmlname =
'projectid', $discard_closed = 0, $maxlength = 20, $forcefocus = 0, $nooutput = 0, $textifnoproject =
'', $morecss =
'', $option =
'')
7077 require_once DOL_DOCUMENT_ROOT .
'/core/lib/project.lib.php';
7078 require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formprojet.class.php';
7084 $langs->load(
"project");
7085 if ($htmlname !=
"none") {
7086 $out .=
'<form method="post" action="' . $page .
'">';
7087 $out .=
'<input type="hidden" name="action" value="classin">';
7088 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7089 $out .= $formproject->select_projects($socid, $selected, $htmlname, $maxlength, 0, 1, $discard_closed, $forcefocus, 0, 0,
'', 1, 0, $morecss);
7090 $out .=
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7093 $out .=
'<span class="project_head_block">';
7094 if ($selected instanceof
Project) {
7095 $out .= $selected->getNomUrl(0, $option, 1);
7096 } elseif (is_numeric($selected)) {
7097 $projet =
new Project($this->db);
7098 $projet->fetch((
int) $selected);
7099 $out .= $projet->getNomUrl(0, $option, 1);
7101 $out .=
'<span class="opacitymedium">' . $textifnoproject .
'</span>';
7106 if (empty($nooutput)) {
7130 public function form_conditions_reglement($page, $selected =
'', $htmlname =
'cond_reglement_id', $addempty = 0, $type =
'', $filtertype = -1, $deposit_percent = -1, $nooutput = 0)
7135 $selected = (int) $selected;
7139 if ($htmlname !=
"none") {
7140 $out .=
'<form method="POST" action="' . $page .
'">';
7141 $out .=
'<input type="hidden" name="action" value="setconditions">';
7142 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7144 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
7146 $out .= $this->getSelectConditionsPaiements($selected, $htmlname, $filtertype, $addempty, 0,
'', $deposit_percent);
7147 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7151 $this->load_cache_conditions_paiements();
7153 if (isset($this->cache_conditions_paiements[$selected])) {
7154 $label = $this->cache_conditions_paiements[$selected][
'label'];
7156 if (!empty($this->cache_conditions_paiements[$selected][
'deposit_percent'])) {
7157 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $this->cache_conditions_paiements[$selected][
'deposit_percent'], $label);
7162 $langs->load(
'errors');
7163 $out .= $langs->trans(
'ErrorNotInDictionaryPaymentConditions');
7170 if (empty($nooutput)) {
7196 if ($htmlname !=
'none') {
7197 $out .=
'<form method="POST" action="' . $page .
'">';
7198 $out .=
'<input type="hidden" name="action" value="setruleforlinesdates">';
7199 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7200 $out .= $this->getSelectRuleForLinesDates($selected, $htmlname, $addempty);
7201 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7204 if (isset($selected)) {
7205 $this->load_cache_rule_for_lines_dates();
7206 if (isset($this->cache_rule_for_lines_dates[$selected])) {
7207 $label = $this->cache_rule_for_lines_dates[$selected];
7208 $out .= $langs->trans($label);
7215 if (empty($nooutput)) {
7239 if ($htmlname !=
"none") {
7240 print
'<form method="post" action="' . $page .
'">';
7241 print
'<input type="hidden" name="action" value="setavailability">';
7242 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7243 print $this->selectAvailabilityDelay($selected, $htmlname,
'', $addempty,
'', 1);
7244 print
'<input type="submit" name="modify" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7245 print
'<input type="submit" name="cancel" class="button smallpaddingimp" value="' . $langs->trans(
"Cancel") .
'">';
7249 $this->load_cache_availability();
7251 if (isset($this->cache_availability[$selected])) {
7252 print $this->cache_availability[$selected][
'label'];
7273 public function formInputReason($page, $selected =
'', $htmlname =
'demandreason', $addempty = 0, $morecss =
'')
7276 if ($htmlname !=
"none") {
7277 print
'<form method="post" action="' . $page .
'">';
7278 print
'<input type="hidden" name="action" value="setdemandreason">';
7279 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7280 $this->selectInputReason($selected, $htmlname,
'-1', $addempty, $morecss);
7281 print
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7285 $this->loadCacheInputReason();
7286 foreach ($this->cache_demand_reason as $key => $val) {
7287 if ($val[
'id'] == $selected) {
7288 print $val[
'label'];
7313 public function form_date($page, $selected, $htmlname, $displayhour = 0, $displaymin = 0, $nooutput = 0, $type =
'')
7320 if ($htmlname !=
"none") {
7321 $ret .=
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
7322 $ret .=
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
7323 $ret .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7325 $ret .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
7327 $ret .=
'<table class="nobordernopadding">';
7329 $ret .= $this->selectDate($selected, $htmlname, $displayhour, $displaymin, 1,
'form' . $htmlname, 1, 0);
7331 $ret .=
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
7332 $ret .=
'</tr></table></form>';
7341 if (empty($nooutput)) {
7360 public function form_users($page, $selected =
'', $htmlname =
'userid', $exclude = array(), $include = array())
7365 if ($htmlname !=
"none") {
7366 print
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
7367 print
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
7368 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7369 print $this->select_dolusers($selected, $htmlname, 1, $exclude, 0, $include);
7370 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7374 require_once DOL_DOCUMENT_ROOT .
'/user/class/user.class.php';
7375 $theuser =
new User($this->db);
7376 $theuser->fetch((
int) $selected);
7377 print $theuser->getNomUrl(1);
7400 public function form_modes_reglement($page, $selected =
'', $htmlname =
'mode_reglement_id', $filtertype =
'', $active = 1, $addempty = 0, $type =
'', $nooutput = 0)
7406 if ($htmlname !=
"none") {
7407 $out .=
'<form method="POST" action="' . $page .
'">';
7408 $out .=
'<input type="hidden" name="action" value="setmode">';
7409 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7411 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
7413 $out .= $this->select_types_paiements($selected, $htmlname, $filtertype, 0, $addempty, 0, 0, $active,
'', 1);
7414 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7417 if ((
int) $selected) {
7418 $this->load_cache_types_paiements();
7419 $out .= $this->cache_types_paiements[(int) $selected][
'label'] ??
' ';
7446 if ($htmlname !=
"none") {
7447 print
'<form method="POST" action="' . $page .
'">';
7448 print
'<input type="hidden" name="action" value="settransportmode">';
7449 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7450 $this->selectTransportMode($selected, $htmlname, 0, $addempty, 0, 0, $active);
7451 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7455 $this->load_cache_transport_mode();
7456 print $this->cache_transport_mode[$selected][
'label'];
7477 if ($htmlname !=
"none") {
7478 print
'<form method="POST" action="' . $page .
'">';
7479 print
'<input type="hidden" name="action" value="setmulticurrencycode">';
7480 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7481 print $this->selectMultiCurrency($selected, $htmlname, 0);
7482 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7485 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
7486 print !empty($selected) ?
currency_name($selected, 1) :
' ';
7505 global $langs,
$conf;
7507 if ($htmlname !=
"none") {
7508 print
'<form method="POST" action="' . $page .
'">';
7509 print
'<input type="hidden" name="action" value="setmulticurrencyrate">';
7510 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7511 print
'<input type="text" class="maxwidth75" name="' . $htmlname .
'" value="' . (!empty($rate) ?
price(
price2num($rate,
'CU')) : 1) .
'" spellcheck="false" /> ';
7512 print
'<select name="calculation_mode" id="calculation_mode">';
7513 print
'<option value="1">Change ' . $langs->trans(
"PriceUHT") .
' of lines</option>';
7514 print
'<option value="2">Change ' . $langs->trans(
"PriceUHTCurrency") .
' of lines</option>';
7517 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7520 if (!empty($rate)) {
7521 print
price($rate, 1, $langs, 0, 0);
7522 if ($currency && $rate != 1) {
7529 print
' <span class="opacitymedium">(' .
price($rate_direct, 1, $langs, 0, 0) .
' ' .
$conf->currency .
' = 1 ' . $currency .
')</span>';
7531 print
' <span class="opacitymedium">(' .
price($rate, 1, $langs, 0, 0) .
' ' . $currency .
' = 1 ' .
$conf->currency .
')</span>';
7559 public function form_remise_dispo($page, $selected, $htmlname, $socid, $amount, $filter =
'', $maxvalue = 0, $more =
'', $hidelist = 0, $discount_type = 0, $filterabsolutediscount = 0, $filtercreditnote = 0)
7562 global
$conf, $langs;
7564 if ($htmlname !=
"none") {
7565 print
'<form method="post" action="' . $page .
'" class="inline-block">';
7566 print
'<input type="hidden" name="action" value="setabsolutediscount">';
7567 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7568 print
'<div class="inline-block">';
7569 if (!empty($discount_type)) {
7571 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL") {
7572 $translationKey =
'HasAbsoluteDiscountFromSupplier';
7574 $translationKey =
'HasCreditNoteFromSupplier';
7577 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
7578 $translationKey =
'HasAbsoluteDiscountFromSupplier';
7580 $translationKey =
'HasCreditNoteFromSupplier';
7585 if (!$filter || $filter ==
"fk_facture_source IS NULL") {
7586 $translationKey =
'CompanyHasAbsoluteDiscount';
7588 $translationKey =
'CompanyHasCreditNote';
7591 if (!$filter || $filter ==
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
7592 $translationKey =
'CompanyHasAbsoluteDiscount';
7594 $translationKey =
'CompanyHasCreditNote';
7598 print $langs->trans($translationKey,
price($amount, 0, $langs, 0, 0, -1,
$conf->currency));
7599 if (empty($hidelist)) {
7603 if (empty($hidelist)) {
7604 print
'<div class="inline-block" style="padding-right: 10px">';
7605 $newfilter =
'discount_type = ' . intval($discount_type);
7606 if (!empty($discount_type)) {
7607 $newfilter .=
' AND fk_invoice_supplier IS NULL AND fk_invoice_supplier_line IS NULL';
7609 $newfilter .=
' AND fk_facture IS NULL AND fk_facture_line IS NULL';
7612 $sanitizedfilter = $filter;
7613 $newfilter .=
' AND (' . $sanitizedfilter .
')';
7616 $nbqualifiedlines = $this->select_remises((
string) $selected, $htmlname, $newfilter, $socid, $maxvalue);
7617 if ($nbqualifiedlines > 0) {
7618 print
' <input type="submit" class="button smallpaddingimp" value="' .
dol_escape_htmltag($langs->trans(
"UseLine")) .
'"';
7619 if (!empty($discount_type) && $filter && $filter !=
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
7620 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
7622 if (empty($discount_type) && $filter && $filter !=
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
7623 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
7631 print
'<div class="inline-block">';
7657 public function form_contacts($page, $societe, $selected =
'', $htmlname =
'contactid')
7662 if ($htmlname !=
"none") {
7663 print
'<form method="post" action="' . $page .
'">';
7664 print
'<input type="hidden" name="action" value="set_contact">';
7665 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7666 print
'<table class="nobordernopadding">';
7668 print $this->selectcontacts($societe->id, $selected, $htmlname);
7671 $addcontact = (
getDolGlobalString(
'SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans(
"AddContact") : $langs->trans(
"AddContactAddress"));
7672 print
'<a href="' . DOL_URL_ROOT .
'/contact/card.php?socid=' . $societe->id .
'&action=create&backtoreferer=1">' . $addcontact .
'</a>';
7675 print
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
7676 print
'</tr></table></form>';
7679 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
7680 $contact =
new Contact($this->db);
7681 $contact->fetch((
int) $selected);
7682 print $contact->getFullName($langs);
7707 public function form_thirdparty($page, $selected =
'', $htmlname =
'socid', $filter =
'', $showempty = 0, $showtype = 0, $forcecombo = 0, $events = array(), $nooutput = 0, $excludeids = array(), $textifnothirdparty =
'')
7713 if ($htmlname !=
"none") {
7716 $out .=
'<form method="post" action="' . $page .
'">';
7717 $out .=
'<input type="hidden" name="action" value="set_thirdparty">';
7718 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7719 $out .= $this->select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, $limit,
'minwidth100',
'',
'', 1, array(),
false, $excludeids);
7720 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7724 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
7725 $soc =
new Societe($this->db);
7726 $soc->fetch((
int) $selected);
7727 $out .= $soc->getNomUrl(0,
'');
7729 $out .=
'<span class="opacitymedium">' . $textifnothirdparty .
'</span>';
7755 print $this->selectCurrency($selected, $htmlname);
7767 public function selectCurrency($selected =
'', $htmlname =
'currency_id', $mode = 0, $useempty =
'')
7769 global $langs, $user;
7771 $langs->loadCacheCurrencies(
'');
7775 if ($selected ==
'euro' || $selected ==
'euros') {
7779 $out .=
'<select class="flat maxwidth200onsmartphone minwidth300" name="' . $htmlname .
'" id="' . $htmlname .
'">';
7781 $out .=
'<option value="-1" selected></option>';
7783 foreach ($langs->cache_currencies as $code_iso => $currency) {
7784 $labeltoshow = $currency[
'label'];
7786 $labeltoshow .=
' <span class="opacitymedium">(' . $code_iso .
')</span>';
7787 } elseif ($mode == 2) {
7788 $labeltoshow .=
' <span class="opacitymedium">(' . $code_iso.
' - '.$langs->getCurrencySymbol($code_iso) .
')</span>';
7790 $labeltoshow .=
' <span class="opacitymedium">(' . $langs->getCurrencySymbol($code_iso) .
')</span>';
7793 if ($selected && $selected == $code_iso) {
7794 $out .=
'<option value="' . $code_iso .
'" selected data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
7796 $out .=
'<option value="' . $code_iso .
'" data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
7799 $out .=
'</option>';
7801 $out .=
'</select>';
7803 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
7807 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
7825 public function selectMultiCurrency($selected =
'', $htmlname =
'multicurrency_code', $useempty = 0, $filter =
'', $excludeConfCurrency =
false, $morecss =
'maxwidth200 widthcentpercentminusx')
7827 global
$conf, $langs;
7829 $langs->loadCacheCurrencies(
'');
7831 $TCurrency = array();
7833 $sql =
"SELECT code FROM " . $this->db->prefix() .
"multicurrency";
7834 $sql .=
" WHERE entity IN ('" .
getEntity(
'multicurrency') .
"')";
7838 $resql = $this->db->query($sql);
7840 while ($obj = $this->db->fetch_object($resql)) {
7841 $TCurrency[$obj->code] = $obj->code;
7846 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
7848 $out .=
'<option value=""> </option>';
7851 if (!in_array(
$conf->currency, $TCurrency) && !$excludeConfCurrency) {
7852 $TCurrency[
$conf->currency] =
$conf->currency;
7854 if (count($TCurrency) > 0) {
7855 foreach ($langs->cache_currencies as $code_iso => $currency) {
7856 if (isset($TCurrency[$code_iso])) {
7857 if (!empty($selected) && $selected == $code_iso) {
7858 $out .=
'<option value="' . $code_iso .
'" selected="selected">';
7860 $out .=
'<option value="' . $code_iso .
'">';
7863 $out .= $currency[
'label'];
7864 $out .=
' (' . $langs->getCurrencySymbol($code_iso) .
')';
7865 $out .=
'</option>';
7870 $out .=
'</select>';
7873 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
7890 global $langs, $user, $hookmanager;
7892 $num = count($this->cache_vatrates);
7901 $sql =
"SELECT t.rowid, t.entity, t.fk_pays, t.type_vat, t.code, t.taux, t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.recuperableonly, t.einvoice_vatex";
7902 $sql .=
" FROM ".$this->db->prefix().
"c_tva as t, ".$this->db->prefix().
"c_country as c";
7903 $sql .=
" WHERE t.fk_pays = c.rowid";
7904 $sql .=
" AND t.active > 0";
7905 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
7906 $sql .=
" AND c.code IN (" . $this->db->sanitize($country_code, 1) .
")";
7907 $sql .=
" ORDER BY t.code ASC, t.taux ASC, t.recuperableonly ASC";
7909 $resql = $this->db->query($sql);
7911 $num = $this->db->num_rows($resql);
7913 for ($i = 0; $i < $num; $i++) {
7914 $obj = $this->db->fetch_object($resql);
7916 $tmparray = array();
7917 $tmparray[
'rowid'] = (int) $obj->rowid;
7918 $tmparray[
'entity'] = (int) $obj->entity;
7919 $tmparray[
'fk_pays'] = (int) $obj->fk_pays;
7920 $tmparray[
'type_vat'] = ($obj->type_vat <= 0 ? 0 : $obj->type_vat);
7921 $tmparray[
'code'] = $obj->code;
7922 $tmparray[
'txtva'] = $obj->taux;
7923 $tmparray[
'nprtva'] = $obj->recuperableonly;
7924 $tmparray[
'localtax1'] = $obj->localtax1;
7925 $tmparray[
'localtax1_type'] = $obj->localtax1_type;
7926 $tmparray[
'localtax2'] = $obj->localtax2;
7927 $tmparray[
'localtax2_type'] = $obj->localtax1_type;
7928 $tmparray[
'einvoice_vatex'] = $obj->einvoice_vatex;
7930 $tmparray[
'label'] = $obj->taux .
'%' . ($obj->code ?
' (' . $obj->code .
')' :
'');
7931 $tmparray[
'labelallrates'] = $obj->taux .
'/' . ($obj->localtax1 ? $obj->localtax1 :
'0') .
'/' . ($obj->localtax2 ? $obj->localtax2 :
'0') . ($obj->code ?
' (' . $obj->code .
')' :
'');
7932 $positiverates =
'';
7934 $positiverates .= ($positiverates ?
'/' :
'') . $obj->taux;
7936 if ($obj->localtax1) {
7937 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax1;
7939 if ($obj->localtax2) {
7940 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax2;
7942 if (empty($positiverates)) {
7943 $positiverates =
'0';
7945 $tmparray[
'labelpositiverates'] = $positiverates . ($obj->code ?
' (' . $obj->code .
')' :
'');
7947 $this->cache_vatrates[$obj->rowid] = $tmparray;
7950 $parameters = array(
'dictionary' =>
'vatrate',
'country_code' => $country_code);
7951 $reshook = $hookmanager->executeHooks(
'loadDictionaryCache', $parameters, $this);
7952 if (empty($reshook)) {
7953 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
7954 $this->cache_vatrates = array_merge($this->cache_vatrates, $hookmanager->resArray);
7957 $this->cache_vatrates = $hookmanager->resArray;
7960 return count($this->cache_vatrates);
7962 $this->error =
'<span class="error">';
7963 $this->error .= $langs->trans(
"ErrorNoVATRateDefinedForSellerCountry", $country_code);
7965 if (!empty($user) && $user->admin && preg_match(
'/\'(..)\'/', $country_code, $reg)) {
7966 $langs->load(
"errors");
7967 $new_country_code = $reg[1];
7968 $country_id =
dol_getIdFromCode($this->db, $new_country_code,
'c_country',
'code',
'rowid');
7969 $this->error .=
'<br>'.$langs->trans(
"ErrorFixThisHere", DOL_URL_ROOT.
'/admin/dict.php?id=10'.($country_id > 0 ?
'&countryidforinsert='.$country_id :
''));
7971 $this->error .=
'</span>';
7975 $this->error =
'<span class="error">' . $this->db->error() .
'</span>';
8004 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)
8007 global $langs,
$mysoc, $hookmanager;
8009 $langs->load(
'errors');
8013 $hookmanager->initHooks(array(
'commonobject'));
8014 $info_bits == 1 ? $is_npr = 1 : $is_npr = 0;
8015 $parameters = array(
8016 'htmlname' => $htmlname,
8017 'selectedrate' => $selectedrate,
8018 'seller' => $societe_vendeuse,
8019 'buyer' => $societe_acheteuse,
8020 'idprod' => $idprod,
8021 'is_npr' => $is_npr,
8023 'options_only' => $options_only,
8025 'type_vat' => $type_vat
8027 $reshook = $hookmanager->executeHooks(
'load_tva', $parameters);
8029 return $hookmanager->resPrint;
8030 } elseif ($reshook === 0) {
8031 $return .= $hookmanager->resPrint;
8035 $defaultnpr = ($info_bits & 0x01);
8036 $defaultnpr = (preg_match(
'/\*/', $selectedrate) ? 1 : $defaultnpr);
8037 $defaulttx = str_replace(
'*',
'', $selectedrate);
8040 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
8041 $defaultcode = $reg[1];
8042 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
8047 if (is_object($societe_vendeuse) && !$societe_vendeuse->country_code) {
8048 if ($societe_vendeuse->id ==
$mysoc->id) {
8049 $return .=
'<span class="error">' . $langs->trans(
"ErrorYourCountryIsNotDefined") .
'</span>';
8051 $return .=
'<span class="error">' . $langs->trans(
"ErrorSupplierCountryIsNotDefined") .
'</span>';
8068 $sellercountrycode = is_object($societe_vendeuse) ? $societe_vendeuse->country_code :
$mysoc->country_code;
8069 $sellercountryid = is_object($societe_vendeuse) ? $societe_vendeuse->country_id :
$mysoc->country_id;
8070 if ((
int) $sellercountryid > 0 && strlen((
string) $sellercountrycode) != 2) {
8071 $tmpcountrycode =
dol_getIdFromCode($this->db, (
string) $sellercountryid,
'c_country',
'rowid',
'code');
8072 if (!empty($tmpcountrycode) && !is_numeric($tmpcountrycode)) {
8073 $sellercountrycode = $tmpcountrycode;
8076 $code_country =
"'" . $sellercountrycode .
"'";
8079 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
8083 if (is_object($societe_vendeuse) && is_object($societe_acheteuse) &&
isInEEC($societe_vendeuse) &&
isInEEC($societe_acheteuse) && !$societe_acheteuse->isACompany()) {
8085 if (is_numeric($type)) {
8087 switch ($selectVatComboMode) {
8089 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
8092 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
8096 } elseif (!$idprod) {
8097 switch ($selectVatComboMode) {
8099 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
8102 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
8106 $prodstatic =
new Product($this->db);
8107 $prodstatic->fetch($idprod);
8109 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
8116 $this->load_cache_vatrates($code_country);
8119 $arrayofvatrates = array();
8120 foreach ($this->cache_vatrates as $cachevalue) {
8121 if (empty($cachevalue[
'type_vat']) || $cachevalue[
'type_vat'] == $type_vat) {
8122 $arrayofvatrates[] = $cachevalue;
8126 $num = count($arrayofvatrates);
8129 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
8131 $tmpthirdparty =
new Societe($this->db);
8132 $tmpthirdparty->country_code =
$mysoc->country_code;
8134 $defaulttx =
get_default_tva(is_object($societe_vendeuse) ? $societe_vendeuse : $tmpthirdparty, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
8135 $defaultnpr =
get_default_npr(is_object($societe_vendeuse) ? $societe_vendeuse : $tmpthirdparty, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
8137 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
8138 $defaultcode = $reg[1];
8139 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
8141 if (empty($defaulttx)) {
8148 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
8151 $defaulttx = $arrayofvatrates[$num - 1][
'txtva'];
8158 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
8159 $defaultcode = $reg[1];
8160 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
8168 if (is_object($societe_vendeuse) && $societe_vendeuse->id ==
$mysoc->id && empty($societe_vendeuse->tva_assuj)) {
8178 if (!$options_only) {
8179 $return .=
'<select class="flat valignmiddle minwidth75imp maxwidth100 right" id="' . $htmlname .
'" name="' . $htmlname .
'"' . ($disabled ?
' disabled' :
'') . $title .
'>';
8182 $selectedfound =
false;
8183 foreach ($arrayofvatrates as $rate) {
8185 if ($disabled && $rate[
'txtva'] != 0) {
8190 $key = $rate[
'txtva'];
8191 $key .= $rate[
'nprtva'] ?
'*' :
'';
8192 if ($mode > 0 && $rate[
'code']) {
8193 $key .=
' (' . $rate[
'code'] .
')';
8196 $key = $rate[
'rowid'];
8199 $return .=
'<option value="' . $key .
'" data-vatid="'.$rate[
'rowid'].
'"';
8200 if (!$selectedfound) {
8202 if ($defaultcode == $rate[
'code']) {
8203 $return .=
' selected';
8204 $selectedfound =
true;
8206 } elseif ($rate[
'txtva'] == $defaulttx && $rate[
'nprtva'] == $defaultnpr) {
8207 $return .=
' selected';
8208 $selectedfound =
true;
8216 $return .= $rate[
'labelpositiverates'];
8219 $return .=
vatrate($rate[
'label']);
8223 $return .= (empty($rate[
'code']) && $rate[
'nprtva']) ?
' *' :
'';
8225 $return .=
'</option>';
8228 if (!$options_only) {
8229 $return .=
'</select>';
8233 $return .= $this->error;
8267 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 =
'')
8270 dol_syslog(__METHOD__ .
': using select_date is deprecated. Use selectDate instead.', LOG_WARNING);
8271 $retstring = $this->selectDate($set_time, $prefix, $h, $m, $empty, $form_name, $d, $addnowlink, $disabled, $fullday, $addplusone, $adddateof);
8272 if (!empty($nooutput)) {
8295 public function selectDateToDate($set_time =
'', $set_time_end =
'', $prefix =
're', $empty = 0, $forcenewline = 0)
8299 $ret = $this->selectDate($set_time, $prefix .
'_start', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"from"),
'tzuserrel');
8300 if ($forcenewline) {
8303 $ret .= $this->selectDate($set_time_end, $prefix .
'_end', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
8335 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 =
'')
8337 global
$conf, $langs;
8339 if ($gm ===
'auto') {
8340 $gm = (empty(
$conf) ?
'tzserver' :
$conf->tzuserinputkey);
8345 if ($prefix ==
'') {
8356 if ($stepminutes <= 0 || $stepminutes > 30) {
8367 $orig_set_time = $set_time;
8369 if ($set_time ===
'' && $emptydate == 0) {
8370 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
8371 if ($gm ==
'tzuser' || $gm ==
'tzuserrel') {
8383 if (!empty($set_time) && preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/', (
string) $set_time, $reg)) {
8385 $syear = (!empty($reg[1]) ? $reg[1] :
'');
8386 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
8387 $sday = (!empty($reg[3]) ? $reg[3] :
'');
8388 $shour = (!empty($reg[4]) ? $reg[4] :
'');
8389 $smin = (!empty($reg[5]) ? $reg[5] :
'');
8390 } elseif (strval($set_time) !=
'' && $set_time != -1) {
8395 if ($orig_set_time !=
'') {
8409 if ($h == 3 || $h == 4) {
8420 $usecalendar =
'combo';
8426 $usecalendar =
'html';
8431 if ($usecalendar !=
'combo') {
8433 $reduceformat = (!empty(
$conf->dol_optimize_smallscreen) ? 1 : 0);
8434 if ($reduceformat) {
8435 $format = str_replace(
'%Y',
'%y', $langs->transnoentitiesnoconv(
"FormatDateShortInput"));
8436 $formatjslong = $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput");
8437 $formatjs = str_replace(
'yyyy',
'yy', $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput"));
8438 $formatjquery = str_replace(
'yyyy',
'yy', $langs->trans(
"FormatDateShortJQueryInput"));
8440 $format = $langs->transnoentitiesnoconv(
"FormatDateShortInput");
8441 $formatjslong = $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput");
8442 $formatjs = $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput");
8443 $formatjquery = $langs->trans(
"FormatDateShortJQueryInput");
8447 $formatted_date =
'';
8448 if (strval($set_time) !=
'' && $set_time != -1) {
8453 if ($usecalendar ==
"eldy") {
8479 } elseif ($usecalendar ==
'jquery' || $usecalendar ==
'html') {
8480 if (!$disabled && $usecalendar !=
'html') {
8482 $minYear =
getDolGlobalInt(
'MIN_YEAR_SELECT_DATE', (idate(
'Y') - 100));
8483 $maxYear =
getDolGlobalInt(
'MAX_YEAR_SELECT_DATE', (idate(
'Y') + 100));
8485 $retstring .=
'<!-- datepicker usecalendar='.$usecalendar.
' --><script nonce="' .
getNonce() .
'" type="text/javascript">';
8486 $retstring .=
"$(function(){ $('#" . $prefix .
"').datepicker({
8489 todayHighlight: true,
8490 yearRange: '" . $minYear .
":" . $maxYear .
"',";
8491 if (!empty(
$conf->dol_use_jmobile)) {
8493 beforeShow: function (input, datePicker) {
8494 input.disabled = true;
8496 onClose: function (dateText, datePicker) {
8497 this.disabled = false;
8503 $buttonImage = $calendarpicto ?: DOL_URL_ROOT .
"/theme/" .
dol_escape_js(
$conf->theme) .
"/img/object_calendarday.png";
8505 showOn: 'button', /* both has problem with autocompletion */
8506 buttonImage: '" . $buttonImage .
"',
8507 buttonImageOnly: true";
8511 $retstring .=
"</script>";
8515 $retstring .=
'<div class="nowraponall inline-block divfordateinput">';
8516 $retstring .=
'<input id="'.$prefix.
'" name="'.$prefix.
'" type="'.($usecalendar ==
'html' ?
"date" :
"text").
'" class="maxwidthdate'.(
getDolUserString(
'MAIN_OPTIMIZEFORTEXTBROWSER') ?
' textbrowser' :
'').
' center" maxlength="11" value="'.$formatted_date.
'"';
8517 $retstring .= ($disabled ?
' disabled' :
'');
8518 $retstring .= ($placeholder ?
' placeholder="' .
dol_escape_htmltag($placeholder) .
'"' :
'');
8519 $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
8520 $retstring .= ' autocomplete="off
">';
8524 $retstringbutton = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
">' . img_object($langs->trans("Disabled
"), 'calendarday', 'class="datecallink ui-datepicker-notrigger
"') . '</button>';
8525 $retstring .= $retstringbutton;
8528 $retstring .= '</div>';
8529 $retstring .= '<input type="hidden
" id="' . $prefix . 'day
" name="' . $prefix . 'day
" value="' . $sday . '">' . "\n
";
8530 $retstring .= '<input type="hidden
" id="' . $prefix . 'month
" name="' . $prefix . 'month
" value="' . $smonth . '">' . "\n
";
8531 $retstring .= '<input type="hidden
" id="' . $prefix . 'year
" name="' . $prefix . 'year
" value="' . $syear . '">' . "\n
";
8533 $retstring .= "Bad value of MAIN_POPUP_CALENDAR
";
8536 // Show date with combo selects
8538 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50imp
" id="' . $prefix . 'day
" name="' . $prefix . 'day
">';
8540 if ($emptydate || $set_time == -1) {
8541 $retstring .= '<option value="0
" selected> </option>';
8544 for ($day = 1; $day <= 31; $day++) {
8545 $retstring .= '<option value="' . $day . '"' . ($day == $sday ? ' selected' : '') . '>' . $day . '</option>';
8548 $retstring .= "</select>
";
8550 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'month
" name="' . $prefix . 'month
">';
8551 if ($emptydate || $set_time == -1) {
8552 $retstring .= '<option value="0
" selected> </option>';
8556 for ($month = 1; $month <= 12; $month++) {
8557 $retstring .= '<option value="' . $month . '"' . ($month == $smonth ? ' selected' : '') . '>';
8558 $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b
");
8559 $retstring .= "</option>
";
8561 $retstring .= "</select>
";
8564 if ($emptydate || $set_time == -1) {
8565 $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 . '">';
8567 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'year
" name="' . $prefix . 'year
">';
8569 $syear = (int) $syear;
8570 for ($year = $syear - 10; $year < (int) $syear + 10; $year++) {
8571 $retstring .= '<option value="' . $year . '"' . ($year == $syear ? ' selected' : '') . '>' . $year . '</option>';
8573 $retstring .= "</select>\n
";
8579 $retstring .= (($h == 2 || $h == 4) ? '<br>' : ' ');
8580 $retstring .= '<span class="nowraponall
">';
8586 if ($openinghours != '') {
8587 $openinghours = explode(',', $openinghours);
8588 $hourstart = $openinghours[0];
8589 $hourend = $openinghours[1];
8590 if ($hourend < $hourstart) {
8591 $hourend = $hourstart;
8596 $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
8597 $retstring .= ($fullday ? $fullday . 'hour
' : '') . '" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
">';
8599 $retstring .= '<option value="-1
"> </option>';
8601 for ($hour = $hourstart; $hour < $hourend; $hour++) {
8602 if (strlen($hour) < 2) {
8603 $hour = "0
" . $hour;
8605 $retstring .= '<option value="' . $hour . '"' . (($hour == $shour) ? ' selected' : '') . '>' . $hour;
8606 $retstring .= '</option>';
8608 $retstring .= '</select>';
8611 $retstring .= '<input type="hidden
" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
" value="' . $shour . '">' . "\n
";
8620 $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
8621 $retstring .= ($fullday ? $fullday . 'min
' : '') . '" id="' . $prefix . 'min
" name="' . $prefix . 'min
">';
8623 $retstring .= '<option value="-1
"> </option>';
8625 for ($min = 0; $min < 60; $min += $stepminutes) {
8626 $min_str = sprintf("%02d
", $min);
8627 $retstring .= '<option value="' . $min_str . '"' . (($min_str == $smin) ? ' selected' : '') . '>' . $min_str . '</option>';
8629 $retstring .= '</select>';
8631 $retstring .= '<input type="hidden
" id="' . $prefix . 'min
" name="' . $prefix . 'min
" value="' . $smin . '">' . "\n
";
8634 $retstring .= '<input type="hidden
" name="' . $prefix . 'sec
" value="' . $ssec . '">';
8638 $retstring .= '</span>';
8642 if (!empty($conf->use_javascript_ajax) && $addnowlink && !$disabled) {
8643 // Script which will be inserted in the onClick of the "Now
" link
8644 $reset_scripts = "";
8645 if ($addnowlink == 2) { // local computer time
8646 // pad add leading 0 on numbers
8647 $reset_scripts .= "Number.prototype.pad =
function(size) {
8648 var s = String(
this);
8649 while (s.length < (size || 2)) {s =
'0' + s;}
8652 var d =
new Date();
";
8655 // Generate the date part, depending on the use or not of the javascript calendar
8656 if ($addnowlink == 1) { // server time expressed in user time setup
8657 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
8658 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
8659 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
8660 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
8661 } elseif ($addnowlink == 2) {
8662 /* Disabled because the output does not use the string format defined by FormatDateShort key to forge the value into #prefix.
8663 * This break application for foreign languages.
8664 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(d.toLocaleDateString(\''.str_replace('_', '-', $langs->defaultlang).'\'));';
8665 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(d.getDate().pad());';
8666 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(parseInt(d.getMonth().pad()) + 1);';
8667 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(d.getFullYear());';
8669 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
8670 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
8671 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
8672 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
8674 /*if ($usecalendar == "eldy
")
8676 $base=DOL_URL_ROOT.'/core/';
8677 $reset_scripts .= 'resetDP(\''.$base.'\',\''.$prefix.'\',\''.$langs->trans("FormatDateShortJavaInput
").'\',\''.$langs->defaultlang.'\');';
8681 $reset_scripts .= 'this.form.elements[\''.$prefix.'day\'].value=formatDate(new Date(), \'d\'); ';
8682 $reset_scripts .= 'this.form.elements[\''.$prefix.'month\'].value=formatDate(new Date(), \'M\'); ';
8683 $reset_scripts .= 'this.form.elements[\''.$prefix.'year\'].value=formatDate(new Date(), \'yyyy\'); ';
8685 // Update the hour part
8688 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8690 //$reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); ';
8691 if ($addnowlink == 1) {
8692 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
8693 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
8694 } elseif ($addnowlink == 2) {
8695 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(d.getHours().pad());';
8696 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
8700 $reset_scripts .= ' } ';
8703 // Update the minute part
8706 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8708 //$reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); ';
8709 if ($addnowlink == 1) {
8710 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
8711 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
8712 } elseif ($addnowlink == 2) {
8713 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(d.getMinutes().pad());';
8714 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
8717 $reset_scripts .= ' } ';
8720 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
8721 if ($reset_scripts && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
8722 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonNow
" type="button" name="_useless
" value="now
" onClick="' . $reset_scripts . '">';
8723 $retstring .= $langs->trans("Now
");
8724 $retstring .= '</button> ';
8728 // Add a "Plus one hour
" link
8729 if ($conf->use_javascript_ajax && $addplusone && !$disabled) {
8730 // Script which will be inserted in the onClick of the "Add plusone
" link
8731 $reset_scripts = "";
8733 // Generate the date part, depending on the use or not of the javascript calendar
8734 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'dayinputnoreduce', 'tzuserrel') . '\');';
8735 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
8736 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
8737 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
8738 // Update the hour part
8741 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8743 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
8745 $reset_scripts .= ' } ';
8748 // Update the minute part
8751 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8753 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
8755 $reset_scripts .= ' } ';
8758 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
8759 if ($reset_scripts && empty($conf->dol_optimize_smallscreen)) {
8760 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonPlusOne
" type="button" name="_useless2
" value="plusone
" onClick="' . $reset_scripts . '">';
8761 $retstring .= $langs->trans("DateStartPlusOne
");
8762 $retstring .= '</button> ';
8766 // Add a link to set data
8767 if ($conf->use_javascript_ajax && !empty($adddateof) && !$disabled) {
8768 if (!is_array($adddateof)) {
8769 $arrayofdateof = array(array('adddateof' => $adddateof, 'labeladddateof' => $labeladddateof));
8771 $arrayofdateof = $adddateof;
8773 foreach ($arrayofdateof as $valuedateof) {
8774 $tmpadddateof = empty($valuedateof['adddateof']) ? 0 : $valuedateof['adddateof'];
8775 $tmplabeladddateof = empty($valuedateof['labeladddateof']) ? '' : $valuedateof['labeladddateof'];
8776 $tmparray = dol_getdate($tmpadddateof);
8777 if (empty($tmplabeladddateof)) {
8778 $tmplabeladddateof = $langs->trans("DateInvoice
");
8780 $reset_scripts = 'console.log(\'Click on now link\'); ';
8781 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(\''.dol_print_date($tmpadddateof, 'dayinputnoreduce').'\');';
8782 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(\''.$tmparray['mday'].'\');';
8783 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(\''.$tmparray['mon'].'\');';
8784 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(\''.$tmparray['year'].'\');';
8785 $retstring .= ' - <button class="dpInvisibleButtons datenowlink
" id="dateofinvoice
" type="button" name="_dateofinvoice
" value="now
" onclick="'.$reset_scripts.'">'.$tmplabeladddateof.'</button>';
8801 public function selectTypeDuration($prefix, $selected = 'i', $excludetypes = array(), $morecss = 'minwidth75 maxwidth100')
8805 $TDurationTypes = $this->getDurationTypes($langs);
8807 // Removed undesired duration types
8808 foreach ($excludetypes as $value) {
8809 unset($TDurationTypes[$value]);
8812 $retstring = '<select class="flat
'.($morecss ? ' '.$morecss : '').'" id="select_
' . $prefix . 'type_duration
" name="' . $prefix . 'type_duration
">';
8813 foreach ($TDurationTypes as $key => $typeduration) {
8814 $retstring .= '<option value="' . $key . '"';
8815 if ($key == $selected) {
8816 $retstring .= " selected
";
8818 $retstring .= ">
" . $typeduration . "</option>
";
8820 $retstring .= "</select>
";
8822 $retstring .= ajax_combobox('select_' . $prefix . 'type_duration');
8827 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
8842 public function select_duration($prefix, $iSecond = '', $disabled = 0, $typehour = 'select', $minunderhours = 0, $nooutput = 0)
8847 $retstring = '<span class="nowraponall
">';
8853 if ($iSecond != '') {
8854 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
8856 $hourSelected = convertSecondToTime($iSecond, 'allhour');
8857 $minSelected = convertSecondToTime($iSecond, 'min');
8860 if ($typehour == 'select') {
8861 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'hour
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . '>';
8862 for ($hour = 0; $hour < 25; $hour++) { // For a duration, we allow 24 hours
8863 $retstring .= '<option value="' . $hour . '"';
8864 if (is_numeric($hourSelected) && $hourSelected == $hour) {
8865 $retstring .= " selected
";
8867 $retstring .= ">
" . $hour . "</option>
";
8869 $retstring .= "</select>
";
8870 } elseif ($typehour == 'text' || $typehour == 'textselect') {
8871 $retstring .= '<input placeholder="' . $langs->trans('HourShort
') . '" type="number
" min="0
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputhour right
" value="' . (($hourSelected != '') ? ((int) $hourSelected) : '') . '">';
8873 return 'BadValueForParameterTypeHour';
8876 if ($typehour != 'text') {
8877 $retstring .= ' ' . $langs->trans('HourShort');
8879 $retstring .= '<span class="">:</span>';
8883 if ($minunderhours) {
8884 $retstring .= '<br>';
8886 if ($typehour != 'text') {
8887 $retstring .= '<span class="hideonsmartphone
"> </span>';
8891 if ($typehour == 'select' || $typehour == 'textselect') {
8892 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'min
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . '>';
8893 $step = getDolGlobalInt('MAIN_DURATION_STEP');
8894 $duration_step = ($step > 0) ? $step : 5;
8895 for ($min = 0; $min <= 59; $min += $duration_step) {
8896 $retstring .= '<option value="' . $min . '"';
8897 if (is_numeric($minSelected) && $minSelected == $min) {
8898 $retstring .= ' selected';
8900 $retstring .= '>' . $min . '</option>';
8902 $retstring .= "</select>
";
8903 } elseif ($typehour == 'text') {
8904 $retstring .= '<input placeholder="' . $langs->trans('MinuteShort
') . '" type="number
" min="0
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputminute right
" value="' . (($minSelected != '') ? ((int) $minSelected) : '') . '">';
8907 if ($typehour != 'text') {
8908 $retstring .= ' ' . $langs->trans('MinuteShort');
8911 $retstring .= "</span>
";
8913 if (!empty($nooutput)) {
8941 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)
8943 global $langs, $conf;
8948 if (is_null($ajaxoptions)) {
8949 $ajaxoptions = array();
8952 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
8955 if ($selected && empty($selected_input_value)) {
8956 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
8957 $tickettmpselect = new Ticket($this->db);
8958 $tickettmpselect->fetch((int) $selected);
8959 $selected_input_value = $tickettmpselect->ref;
8960 unset($tickettmpselect);
8964 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/ticket/ajax/tickets.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
8966 if (empty($hidelabel)) {
8967 $out .= $langs->trans("RefOrLabel
") . ' : ';
8968 } elseif ($hidelabel > 1) {
8969 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
8970 if ($hidelabel == 2) {
8971 $out .= img_picto($langs->trans("Search
"), 'search');
8974 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
8975 if ($hidelabel == 3) {
8976 $out .= img_picto($langs->trans("Search
"), 'search');
8979 $out .= $this->selectTicketsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
8982 if (empty($nooutput)) {
9007 public function selectTicketsList($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
9012 $outarray = array();
9014 $selectFields = " p.rowid, p.ref, p.message
";
9017 $sql .= $this->db->sanitize($selectFields, 0, 0, 1);
9018 $sql .= " FROM
" . $this->db->prefix() . "ticket as p
";
9019 $sql .= ' WHERE p.entity IN (' . getEntity('ticket') . ')';
9021 // Add criteria on ref/label
9022 if ($filterkey != '') {
9024 $prefix = getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '' : '%'; // Can use index if TICKET_DONOTSEARCH_ANYWHERE is on
9025 // For natural search
9026 $search_crit = explode(' ', $filterkey);
9028 if (count($search_crit) > 1) {
9031 foreach ($search_crit as $crit) {
9035 $sql .= "(p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%' OR p.subject LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
9039 if (count($search_crit) > 1) {
9045 $sql .= $this->db->plimit($limit, 0);
9047 // Build output string
9048 dol_syslog(get_class($this) . "::selectTicketsList search tickets
", LOG_DEBUG);
9049 $result = $this->db->query($sql);
9051 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
9052 require_once DOL_DOCUMENT_ROOT . '/core/lib/ticket.lib.php';
9054 $num = $this->db->num_rows($result);
9059 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
9060 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('TICKET_USE_SEARCH_TO_SELECT'));
9063 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
9066 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
9067 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
9068 if (getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
9069 if ($showempty && !is_numeric($showempty)) {
9070 $textifempty = $langs->trans($showempty);
9072 $textifempty .= $langs->trans("All
");
9075 if ($showempty && !is_numeric($showempty)) {
9076 $textifempty = $langs->trans($showempty);
9080 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
9084 while ($num && $i < $num) {
9087 $objp = $this->db->fetch_object($result);
9089 $this->constructTicketListOption($objp, $opt, $optJson, $selected, $filterkey);
9090 '@phan-var-force array{key:string,value:mixed,type:int} $optJson';
9092 // "key
" value of json key array is used by jQuery automatically as selected value
9093 // "label
" value of json key array is used by jQuery automatically as text for combo box
9095 array_push($outarray, $optJson);
9100 $out .= '</select>';
9102 $this->db->free($result);
9104 if (empty($outputmode)) {
9109 dol_print_error($this->db);
9126 protected function constructTicketListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
9132 $outkey = $objp->rowid;
9133 $outref = $objp->ref;
9135 $opt = '<option value="
' . $objp->rowid . '"';
9136 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
9139 $objRef = $objp->ref;
9140 if (!empty($filterkey) && $filterkey != '') {
9141 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1);
9144 $opt .= "</option>\n
";
9145 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
9167 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)
9169 global $langs, $conf;
9174 if (is_null($ajaxoptions)) {
9175 $ajaxoptions = array();
9178 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
9181 if ($selected && empty($selected_input_value)) {
9182 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
9183 $projecttmpselect = new Project($this->db);
9184 $projecttmpselect->fetch((int) $selected);
9185 $selected_input_value = $projecttmpselect->ref;
9186 unset($projecttmpselect);
9190 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/projet/ajax/projects.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
9192 if (empty($hidelabel)) {
9193 $out .= $langs->trans("RefOrLabel
") . ' : ';
9194 } elseif ($hidelabel > 1) {
9195 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
9196 if ($hidelabel == 2) {
9197 $out .= img_picto($langs->trans("Search
"), 'search');
9200 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
9201 if ($hidelabel == 3) {
9202 $out .= img_picto($langs->trans("Search
"), 'search');
9205 $out .= $this->selectProjectsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
9208 if (empty($nooutput)) {
9232 public function selectProjectsList($selected = '', $htmlname = 'projectid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
9234 global $langs, $conf;
9237 $outarray = array();
9239 $selectFields = " p.rowid, p.ref
";
9242 $sql .= $this->db->sanitize($selectFields, 0, 0, 1);
9243 $sql .= " FROM
" . $this->db->prefix() . "projet as p
";
9244 $sql .= ' WHERE p.entity IN (' . getEntity('project') . ')';
9246 // Add criteria on ref/label
9247 if ($filterkey != '') {
9249 $prefix = !getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
9250 // For natural search
9251 $search_crit = explode(' ', $filterkey);
9253 if (count($search_crit) > 1) {
9256 foreach ($search_crit as $crit) {
9260 $sql .= "p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
9264 if (count($search_crit) > 1) {
9270 $sql .= $this->db->plimit($limit, 0);
9272 // Build output string
9273 dol_syslog(get_class($this) . "::selectProjectsList search projects
", LOG_DEBUG);
9274 $result = $this->db->query($sql);
9276 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
9277 require_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php';
9279 $num = $this->db->num_rows($result);
9284 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
9285 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('PROJECT_USE_SEARCH_TO_SELECT'));
9288 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
9291 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
9292 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
9293 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
9294 if ($showempty && !is_numeric($showempty)) {
9295 $textifempty = $langs->trans($showempty);
9297 $textifempty .= $langs->trans("All
");
9300 if ($showempty && !is_numeric($showempty)) {
9301 $textifempty = $langs->trans($showempty);
9305 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
9309 while ($num && $i < $num) {
9312 $objp = $this->db->fetch_object($result);
9314 $this->constructProjectListOption($objp, $opt, $optJson, $selected, $filterkey);
9316 // "key
" value of json key array is used by jQuery automatically as selected value
9317 // "label
" value of json key array is used by jQuery automatically as text for combo box
9319 array_push($outarray, $optJson);
9324 $out .= '</select>';
9326 $this->db->free($result);
9328 if (empty($outputmode)) {
9333 dol_print_error($this->db);
9352 protected function constructProjectListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
9358 $label = $objp->label;
9360 $outkey = $objp->rowid;
9361 $outref = $objp->ref;
9362 $outlabel = $objp->label;
9363 $outtype = $objp->fk_product_type;
9365 $opt = '<option value="
' . $objp->rowid . '"';
9366 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
9369 $objRef = $objp->ref;
9370 if (!empty($filterkey) && $filterkey != '') {
9371 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', (string) $objRef, 1);
9374 $opt .= "</option>\n
";
9375 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
9399 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())
9401 global $langs, $conf;
9406 if (is_null($ajaxoptions)) {
9407 $ajaxoptions = array();
9410 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
9413 if ($selected && empty($selected_input_value)) {
9414 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
9415 $adherenttmpselect = new Adherent($this->db);
9416 $adherenttmpselect->fetch((int) $selected);
9417 $selected_input_value = $adherenttmpselect->ref;
9418 unset($adherenttmpselect);
9423 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/adherents/ajax/adherents.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
9425 if (empty($hidelabel)) {
9426 $out .= $langs->trans("RefOrLabel
") . ' : ';
9427 } elseif ($hidelabel > 1) {
9428 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
9429 if ($hidelabel == 2) {
9430 $out .= img_picto($langs->trans("Search
"), 'search');
9433 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
9434 if ($hidelabel == 3) {
9435 $out .= img_picto($langs->trans("Search
"), 'search');
9440 $out .= $this->selectMembersList($selected, $htmlname, $filtertype, $limit, $filterkey, $status, 0, $showempty, $forcecombo, $morecss, $excludeids);
9443 if (empty($nooutput)) {
9468 public function selectMembersList($selected = '', $htmlname = 'adherentid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '', $excludeids = array())
9470 global $langs, $conf;
9473 $outarray = array();
9475 $selectFields = " p.rowid, p.ref, p.firstname, p.lastname, p.fk_adherent_type
";
9478 $sql .= $this->db->sanitize($selectFields, 0, 0, 1);
9479 $sql .= " FROM
" . $this->db->prefix() . "adherent as p
";
9480 $sql .= ' WHERE p.entity IN (' . getEntity('adherent') . ')';
9482 // Add criteria on ref/label
9483 if ($filterkey != '') {
9485 $prefix = !getDolGlobalString('MEMBER_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
9486 // For natural search
9487 $search_crit = explode(' ', $filterkey);
9489 if (count($search_crit) > 1) {
9492 foreach ($search_crit as $crit) {
9496 $sql .= "(p.firstname LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
9497 $sql .= " OR p.lastname LIKE
'" . $this->db->escape($prefix . $crit) . "%')
";
9500 if (count($search_crit) > 1) {
9505 if ($status != -1) {
9506 $sql .= ' AND statut = ' . ((int) $status);
9508 if (!empty($excludeids)) {
9509 $sql .= " AND p.rowid NOT IN (
" . $this->db->sanitize(implode(',', $excludeids)) . ")
";
9511 $sql .= $this->db->plimit($limit, 0);
9513 // Build output string
9514 dol_syslog(get_class($this) . "::selectMembersList search adherents
", LOG_DEBUG);
9515 $result = $this->db->query($sql);
9517 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
9518 require_once DOL_DOCUMENT_ROOT . '/core/lib/member.lib.php';
9520 $num = $this->db->num_rows($result);
9525 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
9526 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('PROJECT_USE_SEARCH_TO_SELECT'));
9529 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
9532 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
9533 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
9534 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
9535 if ($showempty && !is_numeric($showempty)) {
9536 $textifempty = $langs->trans($showempty);
9538 $textifempty .= $langs->trans("All
");
9541 if ($showempty && !is_numeric($showempty)) {
9542 $textifempty = $langs->trans($showempty);
9546 $out .= '<option value="-1
" selected>' . $textifempty . '</option>';
9550 while ($num && $i < $num) {
9553 $objp = $this->db->fetch_object($result);
9555 $this->constructMemberListOption($objp, $opt, $optJson, $selected, $filterkey);
9558 // "key
" value of json key array is used by jQuery automatically as selected value
9559 // "label
" value of json key array is used by jQuery automatically as text for combo box
9561 array_push($outarray, $optJson);
9566 $out .= '</select>';
9568 $this->db->free($result);
9570 if (empty($outputmode)) {
9575 dol_print_error($this->db);
9592 protected function constructMemberListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
9598 $outkey = $objp->rowid;
9599 $outlabel = dolGetFirstLastname($objp->firstname, $objp->lastname);
9600 $outtype = $objp->fk_adherent_type;
9602 $opt = '<option value="
' . $objp->rowid . '"';
9603 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
9605 if (!empty($filterkey) && $filterkey != '') {
9606 $outlabel = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $outlabel, 1);
9609 $opt .= "</option>\n
";
9611 $optJson = array('key' => $outkey, 'value' => $outlabel, 'type' => $outtype);
9635 public function selectForForms($objectdesc, $htmlname, $preSelectedValue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $disabled = 0, $selected_input_value = '', $objectfield = '')
9637 global $conf, $extrafields, $user, $hookmanager, $action;
9639 // Example of common usage for a link to a thirdparty
9641 // We got this in a modulebuilder form of "
MyObject" of module "mymodule
".
9642 // 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
9643 // $objectdesc = 'Societe'
9644 // $objectfield = Method 1: 'myobject@mymodule:fk_soc' ('fk_soc' is code to retrieve myobject->fields['fk_soc'])
9645 // 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__))
" ...)
9647 // We got this when showing an extrafields on resource that is a link to societe
9648 // 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
9649 // $objectdesc = 'Societe'
9650 // $objectfield = Method 1: 'resource:options_link_to_societe'
9651 // Method 2 recommended (it can be the array): array("type"=>'Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))" ...)
9660 $objectdescorig = $objectdesc;
9662 $InfoFieldList = array();
9667 if (is_array($objectfield)) {
9668 $objectdesc = $objectfield[
'type'];
9669 $objectdesc = preg_replace(
'/^integer[^:]*:/',
'', $objectdesc);
9670 } elseif ($objectfield) {
9672 $tmparray = explode(
':', $objectfield);
9675 $objectforfieldstmp = fetchObjectByElement(0, strtolower($tmparray[0]));
9677 if (is_object($objectforfieldstmp)) {
9681 if (preg_match(
'/^options_(.*)$/', $tmparray[1], $reg)) {
9685 $extrafields->fetch_name_optionals_label($objectforfieldstmp->table_element);
9687 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element][
'type'][$key]) && $extrafields->attributes[$objectforfieldstmp->table_element][
'type'][$key] ==
'link') {
9688 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element][
'param'][$key][
'options'])) {
9689 $tmpextrafields = array_keys($extrafields->attributes[$objectforfieldstmp->table_element][
'param'][$key][
'options']);
9690 $objectdesc = $tmpextrafields[0];
9695 if (array_key_exists($tmparray[1], $objectforfieldstmp->fields)) {
9696 $objectdesc = $objectforfieldstmp->fields[$tmparray[1]][
'type'];
9697 $objectdesc = preg_replace(
'/^integer[^:]*:/',
'', $objectdesc);
9708 $InfoFieldList = explode(
":", $objectdesc, 4);
9709 $vartmp = (empty($InfoFieldList[3]) ?
'' : $InfoFieldList[3]);
9711 if (preg_match(
'/^.*:(\w*)$/', $vartmp, $reg)) {
9712 $InfoFieldList[4] = $reg[1];
9714 $InfoFieldList[3] = preg_replace(
'/:\w*$/',
'', $vartmp);
9716 $classname = $InfoFieldList[0];
9717 $classpath = empty($InfoFieldList[1]) ?
'' : $InfoFieldList[1];
9719 $filter = empty($InfoFieldList[3]) ?
'' : $InfoFieldList[3];
9720 $sortfield = empty($InfoFieldList[4]) ?
'' : $InfoFieldList[4];
9723 $objecttmp = fetchObjectByElement(0, strtolower($InfoFieldList[0]));
9726 if (empty($objecttmp) && !empty($classpath)) {
9729 if ($classname && class_exists($classname)) {
9730 $objecttmp =
new $classname($this->db);
9737 $sharedentities = (is_object($objecttmp) && property_exists($objecttmp,
'element')) ?
getEntity($objecttmp->element) : strtolower($classname);
9738 $filter = str_replace(
9739 array(
'__ENTITY__',
'__SHARED_ENTITIES__',
'__USER_ID__'),
9740 array(
$conf->entity, $sharedentities, $user->id),
9744 if (!is_object($objecttmp)) {
9745 dol_syslog(
'selectForForms: Error bad setup of field objectdescorig=' . $objectdescorig.
', objectfield='.(is_array($objectfield) ?
'array' : $objectfield).
', objectdesc='.$objectdesc, LOG_WARNING);
9746 return 'selectForForms: Error bad setup of field objectdescorig=' . $objectdescorig.
', objectfield='.(is_array($objectfield) ?
'array' : $objectfield).
', objectdesc='.$objectdesc;
9748 '@phan-var-force CommonObject $objecttmp';
9751 $prefixforautocompletemode = $objecttmp->element;
9752 if ($prefixforautocompletemode ==
'societe') {
9753 $prefixforautocompletemode =
'company';
9755 if ($prefixforautocompletemode ==
'product') {
9756 $prefixforautocompletemode =
'produit';
9759 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) .
'_USE_SEARCH_TO_SELECT';
9761 dol_syslog(get_class($this) .
"::selectForForms filter=" . $filter, LOG_DEBUG);
9769 if ($preSelectedValue && empty($selected_input_value)) {
9770 $objecttmp->fetch($preSelectedValue);
9771 $selected_input_value = ($prefixforautocompletemode ==
'company' ? $objecttmp->name : $objecttmp->ref);
9773 $oldValueForShowOnCombobox = 0;
9774 foreach ($objecttmp->fields as $fieldK => $fielV) {
9775 if (!array_key_exists(
'showoncombobox', $fielV) || !$fielV[
'showoncombobox'] || empty($objecttmp->$fieldK)) {
9779 if (!$oldValueForShowOnCombobox) {
9780 $selected_input_value =
'';
9783 $selected_input_value .= $oldValueForShowOnCombobox ?
' - ' :
'';
9784 $selected_input_value .= $objecttmp->$fieldK;
9785 $oldValueForShowOnCombobox = empty($fielV[
'showoncombobox']) ? 0 : $fielV[
'showoncombobox'];
9790 $urlforajaxcall = DOL_URL_ROOT .
'/core/ajax/selectobject.php';
9791 $urloption =
'htmlname=' . urlencode($htmlname) .
'&outjson=1&objectdesc=' . urlencode($objectdescorig) . (is_scalar($objectfield) ?
'&objectfield='.urlencode($objectfield) :
'') . ($sortfield ?
'&sortfield=' . urlencode($sortfield) :
'');
9795 $parameters = array(
9796 'urloption' => $urloption,
9797 'object' => $objecttmp,
9798 'htmlname' => $htmlname,
9799 'filter' => $filter,
9800 'searchkey' => $searchkey,
9802 $reshook = $hookmanager->executeHooks(
'selectForFormsListUrl', $parameters, $objecttmp, $action);
9803 if (!empty($reshook)) {
9804 $urloption = $hookmanager->resPrint;
9805 $hookmanager->resPrint =
'';
9810 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
9811 $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) .
'"' :
'') .
' />';
9814 $out .= $this->selectForFormsList($objecttmp, $htmlname, $preSelectedValue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled, $sortfield, $filter);
9842 public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty =
'', $searchkey =
'', $placeholder =
'', $morecss =
'', $moreparams =
'', $forcecombo = 0, $outputmode = 0, $disabled = 0, $sortfield =
'', $filter =
'', $sortorder =
'ASC')
9844 global $langs, $user, $hookmanager;
9848 $prefixforautocompletemode = $objecttmp->element;
9849 if ($prefixforautocompletemode ==
'societe') {
9850 $prefixforautocompletemode =
'company';
9852 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) .
'_USE_SEARCH_TO_SELECT';
9855 if (!empty($objecttmp->fields)) {
9856 $tmpfieldstoshow =
'';
9857 foreach ($objecttmp->fields as $key => $val) {
9858 if (! (
int)
dol_eval((
string) $val[
'enabled'], 1, 1,
'1')) {
9861 if (!empty($val[
'showoncombobox'])) {
9862 $tmpfieldstoshow .= ($tmpfieldstoshow ?
',' :
'') .
't.' . $key;
9865 if ($tmpfieldstoshow) {
9866 $fieldstoshow = $tmpfieldstoshow;
9868 } elseif ($objecttmp->element ===
'category') {
9869 $fieldstoshow =
't.label';
9872 $objecttmp->fields[
'ref'] = array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'enabled' => 1,
'position' => 10,
'visible' => 4,
'showoncombobox' => 1);
9875 if (empty($fieldstoshow)) {
9876 if (!empty($objecttmp->parent_element)) {
9877 $fieldstoshow =
'o.ref';
9878 if (empty($sortfield)) {
9879 $sortfield =
'o.ref';
9881 if (in_array($objecttmp->element, [
'commandedet',
'propaldet',
'facturedet',
'expeditiondet'])) {
9882 $fieldstoshow .=
',p.ref AS p_ref,p.label,t.description';
9883 $sortfield .=
', p.ref';
9885 } elseif (isset($objecttmp->fields[
'ref'])) {
9886 $fieldstoshow =
't.ref';
9888 $langs->load(
"errors");
9889 $this->error = $langs->trans(
"ErrorNoFieldWithAttributeShowoncombobox");
9890 return $langs->trans(
'ErrorNoFieldWithAttributeShowoncombobox');
9895 $outarray = array();
9896 $tmparray = array();
9900 $sanitizedfieldstoshow = $fieldstoshow;
9903 $sql =
"SELECT t.rowid, " . $sanitizedfieldstoshow .
" FROM " . $this->db->prefix() . $this->db->sanitize($objecttmp->table_element) .
" as t";
9904 if (!empty($objecttmp->isextrafieldmanaged)) {
9905 $extrafieldTable = $objecttmp->table_element;
9906 if ($extrafieldTable ==
'categorie') {
9907 $extrafieldTable =
'categories';
9909 $sql .=
" LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($extrafieldTable) .
"_extrafields as e ON t.rowid = e.fk_object";
9911 if (!empty($objecttmp->parent_element)) {
9912 '@phan-var-force CommonObjectLine $objecttmp';
9915 $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);
9917 if (!empty($objecttmp->parent_element) && in_array($objecttmp->parent_element, [
'commande',
'propal',
'facture',
'expedition'])) {
9918 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product as p ON p.rowid = t.fk_product";
9920 if (!empty($objecttmp->ismultientitymanaged)) {
9921 if ($objecttmp->ismultientitymanaged == 1) {
9924 if (!is_numeric($objecttmp->ismultientitymanaged)) {
9925 $tmparray = explode(
'@', $objecttmp->ismultientitymanaged);
9926 $sql .=
" INNER JOIN " . $this->db->prefix() . $this->db->sanitize($tmparray[1]) .
" as parenttable ON parenttable.rowid = t." . $this->db->sanitize($tmparray[0]);
9931 $parameters = array(
9932 'object' => $objecttmp,
9933 'htmlname' => $htmlname,
9934 'filter' => $filter,
9935 'searchkey' => $searchkey
9938 $reshook = $hookmanager->executeHooks(
'selectForFormsListWhere', $parameters);
9939 if (!empty($hookmanager->resPrint)) {
9940 $sql .= $hookmanager->resPrint;
9942 $sql .=
" WHERE 1=1";
9945 if (!empty($objecttmp->ismultientitymanaged)) {
9946 if ($objecttmp->ismultientitymanaged == 1) {
9947 $sql .=
" AND t.entity IN (" .
getEntity($objecttmp->element) .
")";
9949 if (!is_numeric($objecttmp->ismultientitymanaged)) {
9950 $sql .=
" AND parenttable.entity = t." . $this->db->sanitize($tmparray[0]);
9954 if ($objecttmp->ismultientitymanaged ===
'fk_soc@societe') {
9955 if (!$user->hasRight(
'societe',
'client',
'voir') && empty($user->socid)) {
9956 $sql .=
" AND EXISTS (SELECT sc.rowid FROM ".$this->db->prefix() .
"societe_commerciaux as sc";
9957 $sql .=
" WHERE sc.fk_soc = t.fk_soc AND sc.fk_user = ".((int) $user->id).
")";
9963 if (!empty($user->socid)) {
9964 if ($objecttmp->element ==
'societe') {
9965 $sql .=
" AND t.rowid = " . ((int) $user->socid);
9966 } elseif (!empty($objecttmp->fields[
'fk_soc']) || !empty($objecttmp->fields[
't.fk_soc']) || property_exists($objecttmp,
'fk_soc') || property_exists($objecttmp,
'socid')) {
9967 $sql .=
" AND t.fk_soc = " . ((int) $user->socid);
9968 } elseif (!empty($objecttmp->parent_element)) {
9969 $tmpparent = fetchObjectByElement(0, $objecttmp->parent_element,
'', 1);
9970 if (is_object($tmpparent) && (!empty($tmpparent->fields[
'fk_soc']) || !empty($tmpparent->fields[
't.fk_soc']) || property_exists($tmpparent,
'fk_soc') || property_exists($tmpparent,
'socid'))) {
9971 $sql .=
" AND o.fk_soc = " . ((int) $user->socid);
9976 $splittedfieldstoshow = explode(
',', $fieldstoshow);
9977 foreach ($splittedfieldstoshow as &$field2) {
9978 if (is_numeric($pos = strpos($field2,
' '))) {
9979 $field2 = substr($field2, 0, $pos);
9982 if ($searchkey !=
'') {
9989 if ($errormessage) {
9990 return 'Error forging a SQL request from an universal criteria: ' . $errormessage;
9994 $sql .= $this->db->order($sortfield ? $sortfield : $fieldstoshow, $sortorder);
9999 $resql = $this->db->query($sql);
10002 $out .=
'<select id="' . $htmlname .
'" class="flat minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') . ($moreparams ?
' ' . $moreparams :
'') .
' name="' . $htmlname .
'">' .
"\n";
10005 $textifempty =
' ';
10009 if ($showempty && !is_numeric($showempty)) {
10010 $textifempty = $langs->trans($showempty);
10012 $textifempty .= $langs->trans(
"All");
10016 $out .=
'<option value="-1">' . $textifempty .
'</option>' .
"\n";
10019 $num = $this->db->num_rows($resql);
10022 while ($i < $num) {
10023 $obj = $this->db->fetch_object($resql);
10026 $tmparray = explode(
',', $fieldstoshow);
10027 $oldvalueforshowoncombobox = 0;
10028 foreach ($tmparray as $key => $val) {
10029 $val = preg_replace(
'/(t|p|o)\./',
'', $val);
10030 $label .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val][
'showoncombobox'] ?
' - ' :
' ') :
'');
10031 $labelhtml .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val][
'showoncombobox'] ?
' - ' :
' ') :
'');
10032 $label .= $obj->$val;
10033 $labelhtml .= $obj->$val;
10035 $oldvalueforshowoncombobox = empty($objecttmp->fields[$val][
'showoncombobox']) ? 0 : $objecttmp->fields[$val][
'showoncombobox'];
10037 if (empty($outputmode)) {
10038 if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) {
10039 $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>';
10041 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
10044 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label));
10048 if (($i % 10) == 0) {
10054 $out .=
'</select>' .
"\n";
10056 if (!$forcecombo) {
10057 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
10064 $this->result = array(
'nbofelement' => $num);
10082 public static function radio($htmlName, $radioItems, $selected =
'', $moreGlobalParams = [])
10086 'disabled' =>
false,
10089 'name' => $htmlName,
10092 'labelIsHtml' => false
10099 if (!empty($radioItems)) {
10100 foreach ($radioItems as $key => $item) {
10102 if (!is_array($item)) {
10114 'value' => !isset($item[
'attr'][
'value']) ? $key :
'',
10124 if ((is_array($selected) && in_array($item[
'attr'][
'value'], $selected,
true)) || $selected === $item[
'attr'][
'value']) {
10125 $item[
'attr'][
'checked'] =
true;
10133 $text = $item[
'labelIsHtml'] ? $item[
'label'] : htmlspecialchars($item[
'label'], ENT_QUOTES | ENT_SUBSTITUTE);
10136 $out .=
'<label ' . $labelAttributes .
'><input ' . $inputAttributes .
' /> ' . $text .
'</label> ';
10167 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)
10169 global
$conf, $langs;
10176 if ($value_as_key) {
10177 $array = array_combine($array, $array);
10180 '@phan-var-force array{label:string,data-html:string,disable?:int<0,1>,css?:string} $array';
10184 if ($addjscombo < 0) {
10191 $idname = str_replace(array(
'[',
']'), array(
'',
''), $htmlname);
10192 $out .=
'<select id="' . preg_replace(
'/^\./',
'', $idname) .
'" ' . ($disabled ?
'disabled="disabled" ' :
'') .
'class="flat ' . (preg_replace(
'/^\./',
'', $htmlname)) . ($morecss ?
' ' . $morecss :
'') .
' selectformat"';
10193 $out .=
' name="' . preg_replace(
'/^\./',
'', $htmlname) .
'" ' . ($moreparam ? $moreparam :
'');
10197 $textforempty =
' ';
10198 if (!empty(
$conf->use_javascript_ajax)) {
10199 $textforempty =
' ';
10201 if (!is_numeric($show_empty)) {
10202 $textforempty = $show_empty;
10204 $out .=
'<option class="optiongrey" ' . ($moreparamonempty ? $moreparamonempty .
' ' :
'') .
'value="' . (((
int) $show_empty) < 0 ? $show_empty : -1) .
'"' . (
$id == $show_empty ?
' selected' :
'') .
'>' .
dol_escape_htmltag($textforempty) .
'</option>' .
"\n";
10206 if (is_array($array)) {
10209 foreach ($array as $key => $value) {
10210 if (!is_array($value)) {
10211 $array[$key] = $langs->trans($value);
10213 $array[$key][
'label'] = $langs->trans($value[
'label']);
10218 if ($sort ==
'ASC') {
10220 } elseif ($sort ==
'DESC') {
10224 foreach ($array as $key => $tmpvalue) {
10225 if (is_array($tmpvalue)) {
10226 $value = $tmpvalue[
'label'];
10228 $disabled = empty($tmpvalue[
'disabled']) ?
'' :
' disabled';
10229 $style = empty($tmpvalue[
'css']) ?
'' :
' class="' . $tmpvalue[
'css'] .
'"';
10231 $value = $tmpvalue;
10236 if (!empty($disablebademail)) {
10237 if (($disablebademail == 1 && !preg_match(
'/<.+@.+>/', $value))
10238 || ($disablebademail == 2 && preg_match(
'/---/', $value))) {
10239 $disabled =
' disabled';
10240 $style =
' class="warning"';
10243 if ($key_in_label) {
10244 if (empty($nohtmlescape)) {
10247 $selectOptionValue = $key .
' - ' . ($maxlen ?
dol_trunc($value, $maxlen) : $value);
10250 if (empty($nohtmlescape)) {
10253 $selectOptionValue = $maxlen ?
dol_trunc($value, $maxlen) : $value;
10255 if ($value ==
'' || $value ==
'-') {
10256 $selectOptionValue =
' ';
10259 $out .=
'<option value="' . $key .
'"';
10260 $out .= $style . $disabled;
10261 $out .= is_array($tmpvalue) && !empty($tmpvalue[
'parent']) ?
' parent="' .
dolPrintHTMLForAttribute($tmpvalue[
'parent']) .
'"' :
'';
10262 if (is_array(
$id)) {
10263 if (in_array($key,
$id) && !$disabled) {
10264 $out .=
' selected';
10268 if (
$id !=
'' && ((
$id == (
string) $key) || (
$id ==
'ifone' && count($array) == 1)) && !$disabled) {
10269 $out .=
' selected';
10273 if (is_array($tmpvalue)) {
10274 foreach ($tmpvalue as $keyforvalue => $valueforvalue) {
10275 if ($keyforvalue ==
'labelhtml') {
10276 $keyforvalue =
'data-html';
10278 if (preg_match(
'/^data-/', $keyforvalue)) {
10279 $out .=
' '.dol_escape_htmltag($keyforvalue).
'="'.
dol_escape_htmltag($valueforvalue).
'"';
10282 } elseif (!empty($nohtmlescape)) {
10287 $out .= $selectOptionValue;
10288 $out .=
"</option>\n";
10291 $out .=
"</select>";
10294 if ($addjscombo && $jsbeautify) {
10296 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
10297 $out .=
ajax_combobox($idname, array(), 0, 0,
'resolve', (((
int) $show_empty) < 0 ? (
string) $show_empty :
'-1'), $morecss);
10321 public static function selectArrayAjax($htmlname, $url,
$id =
'', $moreparam =
'', $moreparamtourl =
'', $disabled = 0, $minimumInputLength = 1, $morecss =
'', $callurlonselect = 0, $placeholder =
'', $acceptdelayedhtml = 0)
10324 global $delayedhtmlcontent;
10327 if (!
getDolGlobalString(
'MAIN_USE_JQUERY_MULTISELECT') && !defined(
'REQUIRE_JQUERY_MULTISELECT')) {
10331 $out =
'<select type="text" class="' . $htmlname . ($morecss ?
' ' . $morecss :
'') .
'" ' . ($moreparam ? $moreparam .
' ' :
'') .
'name="' . $htmlname .
'"></select>';
10334 if (!empty(
$conf->use_javascript_ajax)) {
10335 $tmpplugin =
'select2';
10336 $outdelayed =
"\n" .
'<!-- JS CODE TO ENABLE ' . $tmpplugin .
' for id ' . $htmlname .
' -->
10337 <script nonce="' .
getNonce() .
'">
10338 $(document).ready(function () {
10340 ' . ($callurlonselect ?
'var saveRemoteData = [];' :
'') .
'
10342 $(".' . $htmlname .
'").select2({
10345 url: "' . $url .
'",
10346 dataType: \'json\',
10348 data: function (params) {
10350 q: params.term, // search term
10354 processResults: function (data) {
10355 // parse the results into the format expected by Select2.
10356 // since we are using custom formatting functions we do not need to alter the remote JSON data
10357 //console.log(data);
10358 saveRemoteData = data;
10359 /* format json result for select2 */
10361 $.each( data, function( key, value ) {
10362 result.push({id: key, text: value.text});
10364 //return {results:[{id:\'none\', text:\'aa\'}, {id:\'rrr\', text:\'Red\'},{id:\'bbb\', text:\'Search a into projects\'}], more:false}
10365 //console.log(result);
10366 return {results: result, more: false}
10370 language: (typeof select2arrayoflanguage === \'undefined\') ? \'en\' : select2arrayoflanguage,
10371 containerCssClass: \':all:\', /* Line to add class from the original SELECT propagated to the new <span class="select2-selection...> tag */
10373 escapeMarkup:
function (markup) {
return markup; },
10374 minimumInputLength:
' . ((int) $minimumInputLength) . ',
10375 formatResult:
function (result, container, query, escapeMarkup) {
10376 return escapeMarkup(result.text);
10380 ' . ($callurlonselect ? '
10382 $(
".' . $htmlname . '").change(
function() {
10383 var selected = $(\
'.' .
dol_escape_js($htmlname) .
'\').val();
10384 console.log(
"We select in selectArrayAjax the entry "+selected)
10386 $.each( saveRemoteData,
function( key, value ) {
10387 if (key == selected)
10389 console.log(
"selectArrayAjax - Do a redirect to "+value.url)
10390 location.assign(value.url);
10399 if ($acceptdelayedhtml) {
10400 $delayedhtmlcontent .= $outdelayed;
10402 $out .= $outdelayed;
10426 public static function selectArrayFilter($htmlname, $array, $id = '
', $moreparam = '', $disableFiltering = 0, $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0, $textfortitle = '')
10429 global $delayedhtmlcontent; // Will be used later outside of this function
10431 // TODO Use an internal dolibarr component instead of select2
10432 if (!getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT
') && !defined('REQUIRE_JQUERY_MULTISELECT
')) {
10436 $out = '<select
type=
"text"'.($textfortitle ? ' title=
"'.dol_escape_htmltag($textfortitle).'"' : '').' id=
"'.$htmlname.'" class=
"'.$htmlname.($morecss ? ' ' . $morecss : '').'"'.($moreparam ? ' '.$moreparam : '').' name=
"'.$htmlname.'"><option></option></select>
';
10438 $formattedarrayresult = array();
10440 foreach ($array as $key => $value) {
10441 $o = new stdClass();
10443 $o->text = $value['text
'];
10444 $o->url = $value['url
'];
10445 $formattedarrayresult[] = $o;
10449 if (!empty($conf->use_javascript_ajax)) {
10450 $tmpplugin = 'select2
';
10451 $outdelayed = "\n" . '<!-- JS CODE TO ENABLE
' . $tmpplugin . ' for id ' . $htmlname . ' -->
10452 <script nonce=
"' . getNonce() . '">
10453 $(document).ready(
function () {
10454 var data =
' . json_encode($formattedarrayresult) . ';
10456 ' . ($callurlonselect ? 'var saveRemoteData =
' . json_encode($array) . ';
' : '') . '
10460 language: (typeof select2arrayoflanguage === \
'undefined\') ? \'en\' : select2arrayoflanguage,
10461 containerCssClass: \':all:\', /* Line to add class from the original SELECT propagated to the new <span class="select2-selection...> tag */
10463 escapeMarkup:
function (markup) {
return markup; },
10464 minimumInputLength:
' . ((int) $minimumInputLength) . ',
10465 formatResult:
function (result, container, query, escapeMarkup) {
10466 return escapeMarkup(result.text);
10468 matcher:
function (params, data) {
10470 if(! data.id)
return null;
';
10472 if ($callurlonselect) {
10473 // We forge the url with 'sall=
'
10476 var urlBase = data.url;
10477 var separ = urlBase.indexOf(
"?") >= 0 ?
"&" :
"?";
10480 saveRemoteData[data.id].url = urlBase + separ +
"search_all=" + encodeURIComponent(params.term.replace(/\
"/g, ""));';
10483 if (!$disableFiltering) {
10486 if(data.text.match(new RegExp(params.term))) {
10501 ' . ($callurlonselect ? '
10502 /* Code to execute a GET when we select a value */
10503 $(\'.' . dol_escape_js($htmlname) . '\').change(function() {
10504 var selected = $(\'.' . dol_escape_js($htmlname) . '\').val();
10505 console.log("We select
"+selected)
10507 $(\'.' . dol_escape_js($htmlname) . '\').val(""); /* reset visible combo value */
10508 $.each( saveRemoteData, function( key, value ) {
10509 if (key == selected)
10511 console.log("selectArrayFilter - Do a redirect to
"+value.url)
10512 location.assign(value.url);
10521 if ($acceptdelayedhtml) {
10522 $delayedhtmlcontent .= $outdelayed;
10524 $out .= $outdelayed;
10547 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)
10549 global $conf, $langs;
10552 if ($addjscombo < 0) {
10553 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
10560 $useenhancedmultiselect = 0;
10561 if (!empty($conf->use_javascript_ajax) && !defined('MAIN_DO_NOT_USE_JQUERY_MULTISELECT') && (getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') || defined('REQUIRE_JQUERY_MULTISELECT'))) {
10563 $useenhancedmultiselect = 1; // Use the js multiselect in one line. Possible only if $addjscombo not 0.
10567 $out .= '<span class="multiselectarray
'.$htmlname.'">';
10569 // We need a hidden field because when using the multiselect, if we unselect all, there is no
10570 // variable submitted at all, so no way to make a difference between variable not submitted and variable
10571 // submitted to nothing.
10572 $out .= '<input type="hidden
" name="'.$htmlname.'_multiselect
" value="1
">';
10573 // Output select component
10574 $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
";
10575 if (is_array($array) && !empty($array)) {
10576 if ($value_as_key) {
10577 $array = array_combine($array, $array);
10580 if (!empty($array)) {
10581 foreach ($array as $key => $value) {
10583 $tmplabel = $value;
10584 $tmplabelhtml = '';
10588 if (is_array($value) && array_key_exists('id', $value) && array_key_exists('label', $value)) {
10589 $tmpkey = $value['id'];
10590 $tmplabel = empty($value['label']) ? '' : $value['label'];
10591 $tmplabelhtml = empty($value['labelhtml']) ? (empty($value['data-html']) ? '' : $value['data-html']) : $value['labelhtml'];
10592 $tmpcolor = empty($value['color']) ? '' : $value['color'];
10593 $tmppicto = empty($value['picto']) ? '' : $value['picto'];
10594 $tmpdisabled = empty($value['disabled']) ? '' : $value['disabled'];
10596 $newval = ($translate ? $langs->trans($tmplabel) : $tmplabel);
10597 $newval = ($key_in_label ? $tmpkey . ' - ' . $newval : $newval);
10599 $tmplabelhtml = ($translate ? $langs->trans($tmplabelhtml) : $tmplabelhtml);
10600 $tmplabelhtml = ($key_in_label ? $tmpkey . ' - ' . $tmplabelhtml : $tmplabelhtml);
10602 $out .= '<option value="' . $tmpkey . '"';
10603 if (is_array($selected) && !empty($selected) && in_array((string) $tmpkey, $selected) && ((string) $tmpkey != '')) {
10604 $out .= ' selected';
10606 $out .= is_array($value) && array_key_exists('parent', $value) && !empty($value['parent']) ? ' parent="' . dolPrintHTMLForAttribute($value['parent
']) . '"' : '';
10607 if ($tmpdisabled) {
10610 if (!empty($tmplabelhtml)) {
10611 $out .= ' data-html="' . dolPrintHTMLForAttribute($tmplabelhtml) . '"';
10613 $tmplabelhtml = ($tmppicto ? img_picto('', $tmppicto, 'class="pictofixedwidth
" style="color: #
' . $tmpcolor . '"') : '') . $newval;
10614 $out .= ' data-html="' . dolPrintHTMLForAttribute($tmplabelhtml) . '"';
10617 $out .= dol_htmlentitiesbr($newval);
10618 $out .= '</option>' . "\n
";
10622 $out .= '</select>' . "\n
";
10626 // Add code for jquery to use multiselect
10627 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') || defined('REQUIRE_JQUERY_MULTISELECT')) {
10628 $out .= "\n
" . '<!-- JS CODE TO ENABLE select for id ' . $htmlname . ', addjscombo=' . $addjscombo . ' -->';
10629 $out .= "\n
" . '<script nonce="' . getNonce() . '">' . "\n
";
10630 if ($addjscombo == 1) {
10631 $tmpplugin = getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT', (defined('REQUIRE_JQUERY_MULTISELECT') ? constant('REQUIRE_JQUERY_MULTISELECT') : 'select2'));
10633 // If property data-html set, we decode html entities and use this.
10634 // Note that HTML content must have been sanitized from js with dol_escape_htmltag(xxx, 0, 0, '', 0, 1) when building the select option.
10635 // TODO Move this into common js ?
10636 $out .= 'function formatResult(record, container) {' . "\n
";
10637 $out .= ' if ($(record.element).attr("data-html
") != undefined && typeof htmlEntityDecodeJs === "function
") {';
10638 $out .= ' return htmlEntityDecodeJs($(record.element).attr("data-html
"));';
10640 $out .= ' return record.text;';
10641 $out .= '}' . "\n
";
10643 $out .= 'function formatSelection(record) {' . "\n
";
10644 $out .= ' return record.text;';
10645 $out .= '}' . "\n
";
10647 // Load the select2 enhancer
10648 //$out .= 'console.log(\'addjscombo=1 for htmlname=' . dol_escape_js($htmlname) . '\');';
10649 $out .= '$(document).ready(function () {
10650 $(\'#' . dol_escape_js($htmlname) . '\').' . $tmpplugin . '({';
10651 if ($placeholder) {
10655 text: \''.dol_escape_js($placeholder).'\'
10658 $out .= ' dir: \'ltr\',
10659 containerCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag (ko with multiselect) */
10660 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. */
10661 // Specify format function for dropdown item
10662 formatResult: formatResult,
10663 templateResult: formatResult, /* For 4.0 */
10664 escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
10665 // Specify format function for selected item
10666 formatSelection: formatSelection,
10667 templateSelection: formatSelection, /* For 4.0 */
10668 language: (typeof select2arrayoflanguage === \'undefined\') ? \'en\' : select2arrayoflanguage
10671 /* Add also morecss to the css .select2 that is after the #htmlname, for component that are shown dynamically after load, because select2 set
10672 the size only if component is not hidden by default on load */
10675 } elseif ($addjscombo == 2 && !defined(
'DISABLE_MULTISELECT')) {
10679 $out .=
'console.log(\'addjscombo=2 for htmlname=' .
dol_escape_js($htmlname) .
'\');
';
10680 $out .= '$(document).ready(
function () {
10682 containerHTML: \
'<div class="multi-select-container">\',
10683 menuHTML: \'<div class="multi-select-menu">\',
10684 buttonHTML: \'<span class="multi-select-button ' .
dol_escape_js($morecss) .
'">\',
10685 menuItemHTML: \'<label class="multi-select-menuitem">\',
10686 activeClass: \'multi-select-container--open\',
10691 $out .= '</script>
';
10711 public static function multiSelectArrayWithCheckbox($htmlname, &$array, $varpage, $pos = '
', $draganddrop = 0)
10713 global $conf, $langs, $user;
10715 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER
')) {
10718 if (empty($array)) {
10722 $tmpvar = "MAIN_SELECTEDFIELDS_" . $varpage; // To get list of saved selected fields to show
10724 if (!empty($user->conf->$tmpvar)) { // A list of fields was already customized for user
10725 $tmparray = explode(',
', $user->conf->$tmpvar);
10726 foreach ($array as $key => $val) {
10728 //var_dump($tmparray);
10729 if (in_array($key, $tmparray)) {
10730 $array[$key]['checked
'] = 1;
10732 $array[$key]['checked
'] = 0;
10735 } else { // There is no list of fields already customized for user
10736 foreach ($array as $key => $val) {
10737 if (!empty($array[$key]['checked
']) && $array[$key]['checked
'] < 0) {
10738 $array[$key]['checked
'] = 0;
10743 $listoffieldsforselection = '';
10744 $listcheckedstring = '';
10746 foreach ($array as $key => $val) {
10748 // var_dump(array_key_exists('enabled
', $val));
10749 // var_dump(!$val['enabled
']);
10750 if (array_key_exists('enabled
', $val) && isset($val['enabled
']) && !$val['enabled
']) {
10751 unset($array[$key]); // We don't want
this field
10754 if (!empty($val[
'type']) && $val[
'type'] ==
'separate') {
10759 if (!empty($val[
'label']) && $val[
'label']) {
10760 if (!empty($val[
'langfile']) && is_object($langs)) {
10761 $langs->load($val[
'langfile']);
10765 $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']).
'" />';
10766 $listoffieldsforselection .=
'<label for="checkbox' . $key .
'" class="paddingleft">';
10768 $listoffieldsforselection .=
'</label>';
10769 if (!empty($draganddrop)) {
10770 $listoffieldsforselection .=
img_picto($langs->trans(
"MoveField", !empty($key) ? $key :
'none'),
'grip_title',
'class="opacitymedium boxhandle hideonsmartphone cursormove marginleftonly"');
10772 $listoffieldsforselection .=
'</li>';
10773 $listcheckedstring .= (empty($val[
'checked']) ?
'' : $key .
',');
10777 $out =
'<!-- Component multiSelectArrayWithCheckbox ' . $htmlname .
' -->
10779 <dl class="dropdown">
10781 <a href="#' . $htmlname .
'" class="multiselectpicto">
10784 <input type="hidden" class="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $listcheckedstring .
'">
10786 <dd class="dropdowndd">
10787 <div class="multiselectcheckbox'.$htmlname.
'">
10788 <ul class="'.$htmlname.(((string) $pos ==
'1' || (
string) $pos ==
'left') ?
'left' :
'').(!empty($draganddrop) ?
' sortable' :
'').
'">
10789 <li class="liinputsearch">
10790 <input class="inputsearch_dropdownselectedfields width90p minwidth200imp" style="width:90%;" type="text" placeholder="'.$langs->trans(
'Search').
'">
10792 '.$listoffieldsforselection.
'
10799 function updateFieldOrder() {
10800 var positionfields = $(".sortable").sortable("toArray");
10802 url: \''.DOL_URL_ROOT.
'/core/ajax/changepositionfields.php?positionfields=\'+positionfields+\'&token='.
newToken().
'&action=listafterchangingpositionfields&contextpage='.$varpage.
'&userid='.$user->id.
'\',
10804 success: function () {
10806 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'";
10810 $( ".sortable" ).sortable({
10811 handle: \'.boxhandle\',
10812 revert: \'invalid\',
10813 items: \'.fieldsortable\',
10814 stop: function(event, ui) {
10815 console.log("We moved box so we call updateBoxOrder with ajax actions");
10816 updateFieldOrder(); /* 1 to avoid message after a move */
10821 <script nonce="' .
getNonce() .
'" type="text/javascript">
10822 jQuery(document).ready(function () {
10823 $(\'.multiselectcheckbox' . $htmlname .
' input[type="checkbox"]\').on("click", function () {
10824 console.log("A new field was added/removed, we edit field input[name=formfilteraction]");
10826 $("input:hidden[name=formfilteraction]").val(\'listafterchangingselectedfields\'); // Update field so we know we changed something on selected fields after POST
10828 var title = $(this).val() + ",";
10829 if ($(this).is(\':checked\')) {
10830 $(\'.' . $htmlname .
'\').val(title + $(\'.' . $htmlname .
'\').val());
10833 $(\'.' . $htmlname .
'\').val( $(\'.' . $htmlname .
'\').val().replace(title, \'\') )
10835 // Now, we submit page
10836 //$(this).parents(\'form:first\').submit();
10839 $("input.inputsearch_dropdownselectedfields").on("keyup", function() {
10840 console.log("keyup on inputsearch_dropdownselectedfields");
10841 var value = $(this).val().toLowerCase();
10842 $(\'.multiselectcheckbox'.$htmlname.
' li > label\').filter(function() {
10843 $(this).parent().toggle($(this).text().toLowerCase().indexOf(value) > -1)
10847 if (empty(
$conf->browser->layout) ||
$conf->browser->layout !=
'phone') {
10849 $(".dropdown dt a").on("click", function () {
10850 console.log("Click on dropdown, we set focus to search field");
10851 setTimeout(() => { $(\'.inputsearch_dropdownselectedfields\').focus(); }, 200);
10875 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
10878 $categories = $cat->containing(
$id, $type);
10880 if ($rendermode == 1 || $rendermode == 2) {
10881 $toprint = array();
10882 foreach ($categories as
$c) {
10883 $ways =
$c->print_all_ways(
'auto', ($nolink ?
'none' :
''), 0, 1, ($rendermode == 2 ? 0 : 1));
10884 foreach ($ways as $way) {
10885 $color =
$c->color;
10886 $sfortag =
'<li class="select2-search-choice-dolibarr noborderoncategories'.(empty($toprint) ?
' nomarginleft' :
'');
10887 $forced_color =
'categtextwhite';
10889 $forced_color =
'categtextblack';
10891 $sfortag .=
' '.$forced_color;
10893 $sfortag .= ($color ?
' style="background: #' . $color .
';"' :
' style="background: #bbb"');
10894 $titlestring = $ways[0];
10898 if ($rendermode == 1) {
10899 $sfortag .=
'<a href="'.DOL_URL_ROOT.
'/categories/viewcat.php?id='.((int)
$c->id).
'&type='.urlencode(
$c->type).
'" class="'.$forced_color.
'">';
10900 $sfortag .=
img_picto(
'',
'category',
'class="paddingright"');
10901 if (
$conf->dol_optimize_smallscreen) {
10906 $sfortag .=
'</a>';
10910 $sfortag .=
'</li>';
10912 $toprint[] = $sfortag;
10915 if (empty($toprint)) {
10918 return '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
10922 if ($rendermode == 0) {
10923 $arrayselected = array();
10924 $cate_arbo = $this->select_all_categories($type,
'',
'parent', 64, 0, 3);
10925 foreach ($categories as
$c) {
10926 $arrayselected[(
string)
$c->id] = (
string)
$c->id;
10929 return $this->multiselectarray(
'categories', $cate_arbo, $arrayselected, 0, 0,
'', 0,
'100%',
'disabled',
'category');
10932 return 'ErrorBadValueForParameterRenderMode';
10946 global
$conf, $langs, $hookmanager;
10952 $object->fetchObjectLinked();
10955 $hookmanager->initHooks(array(
'commonobject'));
10956 $parameters = array(
10957 'morehtmlright' => $morehtmlright,
10958 'compatibleImportElementsList' => &$compatibleImportElementsList,
10960 $reshook = $hookmanager->executeHooks(
'showLinkedObjectBlock', $parameters,
$object, $action);
10962 $nbofdifferenttypes = count(
$object->linkedObjects);
10964 if (empty($reshook)) {
10965 print
'<!-- showLinkedObjectBlock -->';
10966 print
load_fiche_titre($langs->trans($title), $morehtmlright,
'', 0,
'',
'showlinkedobjectblock');
10969 print
'<div class="div-table-responsive-no-min">';
10970 print
'<table class="noborder allwidth" data-block="showLinkedObject" data-element="' .
$object->element .
'" data-elementid="' .
$object->id .
'" >';
10972 print
'<tr class="liste_titre">';
10973 print
'<td>' . $langs->trans(
"Type") .
'</td>';
10974 print
'<td>' . $langs->trans(
"Ref") .
'</td>';
10977 print
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
10978 print
'<td class="right">' . $langs->trans(
"Status") .
'</td>';
10982 $nboftypesoutput = 0;
10984 foreach (
$object->linkedObjects as $objecttype => $objects) {
10985 $tplpath = $element = $subelement = $objecttype;
10988 global $showImportButton;
10989 $showImportButton =
false;
10990 if (!empty($compatibleImportElementsList) && in_array($element, $compatibleImportElementsList)) {
10991 $showImportButton =
true;
10996 if ($objecttype !=
'supplier_proposal' && preg_match(
'/^([^_]+)_([^_]+)/i', $objecttype, $regs)) {
10997 $element = $regs[1];
10998 $subelement = $regs[2];
10999 $tplpath = $element .
'/' . $subelement;
11001 $tplname =
'linkedobjectblock';
11004 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $objecttype, $regs)) {
11005 $element = $regs[1];
11006 $module = $regs[2];
11007 $tplpath = $module.
'/' . $element;
11008 $tplname = $tplname.
'_'.$element;
11012 if ($objecttype ==
'facture') {
11013 $tplpath =
'compta/' . $element;
11017 } elseif ($objecttype ==
'facturerec') {
11018 $tplpath =
'compta/facture';
11019 $tplname =
'linkedobjectblockForRec';
11023 } elseif ($objecttype ==
'propal') {
11024 $tplpath =
'comm/' . $element;
11028 } elseif ($objecttype ==
'supplier_proposal') {
11032 } elseif ($objecttype ==
'shipping' || $objecttype ==
'shipment' || $objecttype ==
'expedition') {
11033 $tplpath =
'expedition';
11037 } elseif ($objecttype ==
'reception') {
11038 $tplpath =
'reception';
11042 } elseif ($objecttype ==
'delivery') {
11043 $tplpath =
'delivery';
11047 } elseif ($objecttype ==
'ficheinter') {
11048 $tplpath =
'fichinter';
11052 } elseif ($objecttype ==
'invoice_supplier') {
11053 $tplpath =
'fourn/facture';
11054 } elseif ($objecttype ==
'order_supplier') {
11055 $tplpath =
'fourn/commande';
11056 } elseif ($objecttype ==
'expensereport') {
11057 $tplpath =
'expensereport';
11058 } elseif ($objecttype ==
'subscription') {
11059 $tplpath =
'adherents';
11060 } elseif ($objecttype ==
'conferenceorbooth') {
11061 $tplpath =
'eventorganization';
11062 } elseif ($objecttype ==
'conferenceorboothattendee') {
11063 $tplpath =
'eventorganization';
11064 } elseif ($objecttype ==
'mo') {
11069 } elseif ($objecttype ==
'project_task') {
11070 $tplpath =
'projet/tasks';
11073 global $linkedObjectBlock;
11074 $linkedObjectBlock = $objects;
11077 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array(
'/' . $tplpath .
'/tpl'));
11079 foreach ($dirtpls as $reldir) {
11080 $reldir = rtrim($reldir,
'/');
11081 if ($nboftypesoutput == ($nbofdifferenttypes - 1)) {
11082 global $noMoreLinkedObjectBlockAfter;
11083 $noMoreLinkedObjectBlockAfter = 1;
11085 $file =
dol_buildpath($reldir .
'/' . $tplname .
'.tpl.php');
11086 if (file_exists($file)) {
11087 $res = @include $file;
11089 $nboftypesoutput++;
11096 if (!$nboftypesoutput) {
11097 print
'<tr><td colspan="7"><span class="opacitymedium">' . $langs->trans(
"None") .
'</span></td></tr>';
11102 if (!empty($compatibleImportElementsList)) {
11103 $res = @include
dol_buildpath(
'core/tpl/objectlinked_lineimport.tpl.php');
11109 return $nbofdifferenttypes;
11123 global
$conf, $langs, $hookmanager, $form;
11128 if (empty($form)) {
11129 $form =
new Form($this->db);
11133 $linktoelemlist =
'';
11134 $listofidcompanytoscan =
'';
11136 if (!is_object(
$object->thirdparty)) {
11137 if (
$object->element ==
'subscription' && isset(
$object->fk_adherent)) {
11143 $fk_adherent = $subby->fk_adherent;
11144 $adh->fetch($fk_adherent);
11145 $thirdparty_id = $adh->fetch_thirdparty();
11148 $thirdparty_id =
$object->thirdparty->id;
11151 $possiblelinks = array();
11153 $dontIncludeCompletedItems =
getDolGlobalString(
'DONT_INCLUDE_COMPLETED_ELEMENTS_LINKS');
11155 if (!empty($thirdparty_id) && $thirdparty_id > 0) {
11156 $listofidcompanytoscan = (int) $thirdparty_id;
11158 $listofidcompanytoscan .=
',' . (int)
$object->thirdparty->parent;
11161 include_once DOL_DOCUMENT_ROOT .
'/projet/class/project.class.php';
11162 $tmpproject =
new Project($this->db);
11163 $tmpproject->fetch((
int)
$object->fk_project);
11164 if ($tmpproject->socid > 0 && ($tmpproject->socid != $thirdparty_id)) {
11165 $listofidcompanytoscan .=
',' . (int) $tmpproject->socid;
11167 unset($tmpproject);
11170 $possiblelinks = array(
11174 'label' =>
'LinkToProposal',
11175 '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' :
''),
11177 'shipping' => array(
11180 'label' =>
'LinkToExpedition',
11181 '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' :
''),
11186 'label' =>
'LinkToOrder',
11187 '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' :
''),
11188 'linkname' =>
'commande',
11190 'subscription' => array(
11193 'label' =>
'LinkToMemberSubscription',
11194 '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') .
')',
11195 'linkname' =>
'subscription',
11197 'conferenceorboothattendee' => array(
11200 'label' =>
'LinkToConferenceOrBoothAttendee',
11201 '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 "
11202 .$this->db->prefix().
"societe as s, "
11203 .$this->db->prefix().
"eventorganization_conferenceorboothattendee as a WHERE a.fk_soc = s.rowid AND a.fk_soc IN ("
11204 .$this->db->sanitize($listofidcompanytoscan) .
') AND s.entity IN (' .
getEntity(
'conferenceorboothattendee') .
')'
11205 . (empty(
$object->fk_project) ?
'' :
' AND a.fk_project = ' . (int)
$object->fk_project),
11206 'linkname' =>
'attendee'
11208 'invoice' => array(
11211 'label' =>
'LinkToInvoice',
11212 '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' :
''),
11213 'linkname' =>
'facture',
11215 'invoice_template' => array(
11218 'label' =>
'LinkToTemplateInvoice',
11219 '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') .
')',
11221 'contrat' => array(
11224 'label' =>
'LinkToContract',
11225 '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
11226 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',
11228 'fichinter' => array(
11231 'label' =>
'LinkToIntervention',
11232 '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') .
')',
11234 'supplier_proposal' => array(
11237 'label' =>
'LinkToSupplierProposal',
11238 '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' :
''),
11240 'order_supplier' => array(
11243 'label' =>
'LinkToSupplierOrder',
11244 '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' :
''),
11246 'invoice_supplier' => array(
11248 'perms' => 1,
'label' =>
'LinkToSupplierInvoice',
11249 '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' :
''),
11254 'label' =>
'LinkToTicket',
11255 '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' :
''),
11260 'label' =>
'LinkToMo',
11261 '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' :
''),
11266 if (
$object->table_element ==
'commande_fournisseur') {
11267 $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' :
'');
11268 } elseif (
$object->table_element ==
'mrp_mo') {
11269 $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' :
'');
11273 if (!empty($listofidcompanytoscan)) {
11275 $hookmanager->initHooks(array(
'commonobject'));
11276 $parameters = array(
'listofidcompanytoscan' => $listofidcompanytoscan,
'possiblelinks' => $possiblelinks);
11277 $reshook = $hookmanager->executeHooks(
'showLinkToObjectBlock', $parameters,
$object, $action);
11280 if (empty($reshook)) {
11281 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
11282 $possiblelinks = array_merge($possiblelinks, $hookmanager->resArray);
11284 } elseif ($reshook > 0) {
11285 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
11286 $possiblelinks = $hookmanager->resArray;
11290 if (!empty($possiblelinks)) {
11291 $object->fetchObjectLinked();
11295 $htmltoenteralink =
'';
11296 foreach ($possiblelinks as $key => $possiblelink) {
11298 if (empty($possiblelink[
'enabled'])) {
11305 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $key, $regs)) {
11307 $module = $regs[2];
11310 if (!empty($possiblelink[
'perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || !in_array($key, $excludelinksto))) {
11311 $htmltoenteralink .=
'<div id="' . $key .
'list"' . (empty(
$conf->use_javascript_ajax) ?
'' :
' style="display:none"') .
'>';
11315 $htmltoenteralink .=
'<br>'.
"\n";
11316 $htmltoenteralink .=
'<!-- form to add a link from anywhere -->'.
"\n";
11317 $htmltoenteralink .=
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinkedbyref' . $key .
'">';
11318 $htmltoenteralink .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
11319 $htmltoenteralink .=
'<input type="hidden" name="action" value="addlinkbyref">';
11320 $htmltoenteralink .=
'<input type="hidden" name="id" value="' .
$object->id .
'">';
11321 $htmltoenteralink .=
'<input type="hidden" name="addlink" value="' . $key .(!empty($module) ?
'@'.$module :
'').
'">';
11322 $htmltoenteralink .=
'<table class="noborder">';
11323 $htmltoenteralink .=
'<tr class="liste_titre">';
11325 $htmltoenteralink .=
'<td class="center"><input type="text" placeholder="'.dol_escape_htmltag($langs->trans(
"Ref")).
'" name="reftolinkto" value="' .
dol_escape_htmltag(
GETPOST(
'reftolinkto',
'alpha')) .
'">';
11326 $htmltoenteralink .=
'<br>';
11327 $htmltoenteralink .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
'ToLink') .
'"> ';
11328 $htmltoenteralink .=
'<input type="submit" class="button smallpaddingimp" name="cancel" value="' . $langs->trans(
'Cancel') .
'">';
11329 $htmltoenteralink .=
'</td>';
11330 $htmltoenteralink .=
'</tr>';
11331 $htmltoenteralink .=
'</table>';
11332 $htmltoenteralink .=
'</form>';
11335 $sql = $possiblelink[
'sql'];
11337 $resqllist = $this->db->query($sql);
11339 $num = $this->db->num_rows($resqllist);
11344 $htmltoenteralink .=
'<br>';
11346 $htmltoenteralink .=
'<!-- form to add a link from object to same thirdparty -->'.
"\n";
11347 $htmltoenteralink .=
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinked' . $key .
'">';
11348 $htmltoenteralink .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
11349 $htmltoenteralink .=
'<input type="hidden" name="action" value="addlink">';
11350 $htmltoenteralink .=
'<input type="hidden" name="id" value="' .
$object->id .
'">';
11351 $htmltoenteralink .=
'<input type="hidden" name="addlink" value="' . $key . (!empty($module) ?
'@'.$module :
'').
'">';
11352 $htmltoenteralink .=
'<table class="noborder">';
11355 case 'conferenceorboothattendee':
11357 $htmltoenteralink .= $this->makeAddLinkToAttendee(
$object, $key, $possiblelink, $num, $resqllist);
11362 $htmltoenteralink .= $this->makeAddLinkToObject(
$object, $key, $possiblelink, $num, $resqllist);
11366 $htmltoenteralink .=
'</table>';
11367 $htmltoenteralink .=
'<div class="center">';
11369 $htmltoenteralink .=
'<input type="submit" class="button valignmiddle marginleftonly marginrightonly smallpaddingimp" value="' . $langs->trans(
'ToLink') .
'">';
11371 if (empty(
$conf->use_javascript_ajax)) {
11372 $htmltoenteralink .=
'<input type="submit" class="button button-cancel marginleftonly marginrightonly smallpaddingimp" name="cancel" value="' . $langs->trans(
"Cancel") .
'"></div>';
11374 $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>';
11376 $htmltoenteralink .=
'</form>';
11379 $this->db->free($resqllist);
11383 $htmltoenteralink .=
'</div>';
11388 $linktoelemlist .=
'<li><a href="#linkto' . $key .
'" class="linkto dropdowncloseonclick" rel="' . $key .
'">' . $langs->trans($possiblelink[
'label']) .
' (' . $num .
')</a></li>';
11391 $linktoelemlist .=
'<li><span class="linktodisabled">' . $langs->trans($possiblelink[
'label']) .
' (0)</span></li>';
11396 if ($linktoelemlist) {
11398 <dl class="dropdown" id="linktoobjectname">
11400 if (!empty(
$conf->use_javascript_ajax)) {
11401 $linktoelem .=
'<dt><a href="#linktoobjectname"><span class="fas fa-link paddingrightonly"></span>' . $langs->trans(
"LinkTo") .
'...</a></dt>';
11403 $linktoelem .=
'<dd>
11404 <div class="multiselectlinkto">
11405 <ul class="ulselectedfields">' . $linktoelemlist .
'
11414 if (!empty(
$conf->use_javascript_ajax)) {
11415 print
'<!-- Add js to show linkto box -->
11416 <script nonce="' .
getNonce() .
'">
11417 jQuery(document).ready(function() {
11418 jQuery(".linkto").click(function() {
11419 console.log("We choose to show/hide links for rel="+jQuery(this).attr(\'rel\')+" so #"+jQuery(this).attr(\'rel\')+"list");
11420 jQuery("#"+jQuery(this).attr(\'rel\')+"list").toggle();
11428 return array(
'linktoelem' => $linktoelem,
'htmltoenteralink' => $htmltoenteralink);
11430 print $htmltoenteralink;
11433 return $linktoelem;
11450 public function selectyesno($htmlname, $value =
'', $option = 0, $disabled =
false, $useempty = 0, $addjscombo = 0, $morecss =
'yesno width75', $labelyes =
'Yes', $labelno =
'No')
11461 $disabled = ($disabled ?
' disabled' :
'');
11463 $resultyesno =
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'"' . $disabled .
'>' .
"\n";
11465 $resultyesno .=
'<option value="-1"' . (($value < 0) ?
' selected' :
'') .
'> </option>' .
"\n";
11467 if ((
"$value" ==
'yes') || ($value == 1)) {
11468 $resultyesno .=
'<option value="' . $yes .
'" selected>' . $langs->trans($labelyes) .
'</option>' .
"\n";
11469 $resultyesno .=
'<option value="' . $no .
'">' . $langs->trans($labelno) .
'</option>' .
"\n";
11471 $selected = (($useempty && $value !=
'0' && $value !=
'no') ?
'' :
' selected');
11472 $resultyesno .=
'<option value="' . $yes .
'">' . $langs->trans($labelyes) .
'</option>' .
"\n";
11473 $resultyesno .=
'<option value="' . $no .
'"' . $selected .
'>' . $langs->trans($labelno) .
'</option>' .
"\n";
11475 $resultyesno .=
'</select>' .
"\n";
11478 $resultyesno .=
ajax_combobox($htmlname, array(), 0, 0,
'resolve', ($useempty < 0 ? (
string) $useempty :
'-1'), $morecss);
11481 return $resultyesno;
11498 $sql =
"SELECT rowid, label";
11499 $sql .=
" FROM " . $this->db->prefix() .
"export_model";
11500 $sql .=
" WHERE type = '" . $this->db->escape($type) .
"'";
11501 $sql .=
" ORDER BY rowid";
11502 $result = $this->db->query($sql);
11504 print
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
11506 print
'<option value="-1"> </option>';
11509 $num = $this->db->num_rows($result);
11511 while ($i < $num) {
11512 $obj = $this->db->fetch_object($result);
11513 if ($selected == $obj->rowid) {
11514 print
'<option value="' . $obj->rowid .
'" selected>';
11516 print
'<option value="' . $obj->rowid .
'">';
11546 public function showrefnav(
$object, $paramid, $morehtml =
'', $shownav = 1, $fieldid =
'rowid', $fieldref =
'ref', $morehtmlref =
'', $moreparam =
'', $nodbprefix = 0, $morehtmlleft =
'', $morehtmlstatus =
'', $morehtmlright =
'')
11548 global
$conf, $langs, $hookmanager, $extralanguages;
11551 if (empty($fieldid)) {
11552 $fieldid =
'rowid';
11554 if (empty($fieldref)) {
11559 $addgendertxt =
'';
11560 if (property_exists(
$object,
'gender') && !empty(
$object->gender)) {
11561 $addgendertxt =
' ';
11564 $addgendertxt .=
'<i class="fas fa-mars valignmiddle"></i>';
11567 $addgendertxt .=
'<i class="fas fa-venus valignmiddle"></i>';
11570 $addgendertxt .=
'<i class="fas fa-transgender valignmiddle"></i>';
11576 if (is_object($hookmanager)) {
11577 $parameters = array(
'showrefnav' =>
true);
11578 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters,
$object);
11579 if (!empty($hookmanager->resPrint)) {
11580 if (empty(
$object->next_prev_filter) && preg_match(
'/^\s*AND/i', $hookmanager->resPrint)) {
11581 $object->next_prev_filter = (
string) preg_replace(
'/^\s*AND\s*/i',
'', $hookmanager->resPrint);
11582 } elseif (!empty(
$object->next_prev_filter) && !preg_match(
'/^\s*AND/i', $hookmanager->resPrint)) {
11583 $object->next_prev_filter .=
' AND '.$hookmanager->resPrint;
11585 $object->next_prev_filter .= $hookmanager->resPrint;
11590 $previous_ref = $next_ref =
'';
11593 $object->load_previous_next_ref((isset(
$object->next_prev_filter) ?
$object->next_prev_filter :
''), $fieldid, $nodbprefix);
11595 $navurl = $_SERVER[
"PHP_SELF"];
11598 if ($paramid ==
'api_token_card') {
11599 if (preg_match(
'/\/user\/api_token/', $navurl)) {
11600 $navurl = preg_replace(
'/card/',
'list', $navurl);
11606 if ($paramid ==
'project_ref') {
11607 if (preg_match(
'/\/tasks\/(task|contact|note|document)\.php/', $navurl)) {
11608 $navurl = preg_replace(
'/\/tasks\/(task|contact|time|note|document)\.php/',
'/tasks.php', $navurl);
11613 $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>';
11614 $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>';
11618 $ret .=
'<!-- Start banner content --><div style="vertical-align: middle">';
11621 if ($morehtmlright) {
11622 $ret .=
'<div class="inline-block floatleft">' . $morehtmlright .
'</div>';
11625 if ($previous_ref || $next_ref || $morehtml) {
11626 $ret .=
'<div class="pagination paginationref"><ul class="right">';
11628 if ($morehtml &&
getDolGlobalInt(
'MAIN_OPTIMIZEFORTEXTBROWSER') < 2) {
11629 $ret .=
'<!-- morehtml --><li class="noborder litext' . (($shownav && $previous_ref && $next_ref) ?
' clearbothonsmartphone' :
'') .
'">' . $morehtml .
'</li>';
11631 if ($shownav && ($previous_ref || $next_ref)) {
11632 $ret .=
'<li class="pagination">' . $previous_ref .
'</li>';
11633 $ret .=
'<li class="pagination">' . $next_ref .
'</li>';
11635 if ($previous_ref || $next_ref || $morehtml) {
11636 $ret .=
'</ul></div>';
11640 $parameters = array(
'morehtmlstatus' => $morehtmlstatus);
11641 $reshook = $hookmanager->executeHooks(
'moreHtmlStatus', $parameters,
$object);
11642 if (empty($reshook)) {
11643 $morehtmlstatus .= $hookmanager->resPrint;
11645 $morehtmlstatus = $hookmanager->resPrint;
11647 if ($morehtmlstatus) {
11648 $ret .=
'<!-- status --><div class="statusref">' . $morehtmlstatus .
'</div>';
11651 $parameters = array();
11652 $reshook = $hookmanager->executeHooks(
'moreHtmlRef', $parameters,
$object);
11653 if (empty($reshook)) {
11654 $morehtmlref .= $hookmanager->resPrint;
11655 } elseif ($reshook > 0) {
11656 $morehtmlref = $hookmanager->resPrint;
11660 if ($morehtmlleft) {
11661 if (
$conf->browser->layout ==
'phone') {
11662 $ret .=
'<!-- morehtmlleft --><div class="floatleft">' . $morehtmlleft .
'</div>';
11664 $ret .=
'<!-- morehtmlleft --><div class="inline-block floatleft">' . $morehtmlleft .
'</div>';
11669 $ret .=
'<!-- Ref or ID --><div class="inline-block floatleft valignmiddle maxwidth750 marginbottomonly refid' . (($shownav && ($previous_ref || $next_ref)) ?
' refidpadding' :
'') .
'">';
11672 if (
$object->element ==
'societe') {
11673 $ret .=
'<span class="valignmiddle">'.dolPrintHTML((
string)
$object->name).
'</span>';
11676 $arrayoflangcode = array();
11681 if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
11682 if (!is_object($extralanguages)) {
11683 include_once DOL_DOCUMENT_ROOT .
'/core/class/extralanguages.class.php';
11686 $extralanguages->fetch_name_extralanguages(
'societe');
11690 if (!empty($extralanguages->attributes[
'societe']) && !empty($extralanguages->attributes[
'societe'][
'name'])) {
11691 $object->fetchValuesForExtraLanguages();
11695 foreach ($arrayoflangcode as $extralangcode) {
11697 if (
$object->array_languages[
'name'][$extralangcode]) {
11698 $htmltext .=
$object->array_languages[
'name'][$extralangcode];
11700 $htmltext .=
'<span class="opacitymedium">' . $langs->trans(
"SwitchInEditModeToAddTranslation") .
'</span>';
11703 $ret .=
'<!-- Show translations of name -->' .
"\n";
11704 $ret .= $this->textwithpicto(
'', $htmltext, -1,
'language',
'opacitymedium paddingleft');
11707 } elseif (
$object->element ==
'member') {
11708 '@phan-var-force Adherent $object';
11709 $ret .=
$object->ref .
'<br>';
11710 $fullname =
$object->getFullName($langs);
11712 $ret .=
'<span class="valignmiddle">'.dolPrintHTML((
string)
$object->societe) . ((!empty($fullname) &&
$object->societe != $fullname) ?
' (' .
dol_htmlentities($fullname) . $addgendertxt .
')' :
'').
'</span>';
11714 $ret .=
'<span class="valignmiddle">'.dolPrintHTML($fullname) . $addgendertxt . ((!empty(
$object->societe) &&
$object->societe != $fullname) ?
' (' .
dol_htmlentities((
string)
$object->societe) .
')' :
'').
'</span>';
11716 } elseif (in_array(
$object->element, array(
'contact',
'user'))) {
11717 $ret .=
'<span class="valignmiddle">'.dolPrintHTML(
$object->getFullName($langs)).
'</span>'.$addgendertxt;
11718 } elseif (
$object->element ==
'usergroup') {
11720 } elseif (in_array(
$object->element, array(
'action',
'agenda'))) {
11721 '@phan-var-force ActionComm $object';
11723 } elseif (in_array(
$object->element, array(
'adherent_type'))) {
11725 } elseif (
$object->element ==
'ecm_directories') {
11727 } elseif (
$object->element ==
'accountingbookkeeping' && !empty(
$object->context[
'mode']) &&
$object->context[
'mode'] ==
'_tmp') {
11728 $ret .=
'<span class="valignmiddle">'.$langs->trans(
"Draft").
'</span>';
11730 '@phan-var-force Ticket $object';
11731 $ret .=
'<span class="valignmiddle">'.dolPrintHTML(!empty(
$object->$fieldref) ?
$object->$fieldref :
"").
'</span>';
11732 $ret .=
' <span class="nobold small" title="'.dolPrintHTMLForAttribute($langs->trans(
"TicketTrackId")).
'">('.
$object->track_id.
')</span>';
11733 } elseif ($fieldref !=
'none') {
11735 $ret .=
'<span class="valignmiddle">'.dolPrintHTML(!empty(
$object->$fieldref) ?
$object->$fieldref :
"").
'</span>';
11737 if ($morehtmlref) {
11739 if (substr($morehtmlref, 0, 4) !=
'<div') {
11743 $ret .=
'<!-- morehtmlref -->'.$morehtmlref;
11748 $ret .=
'</div><!-- End banner content -->';
11765 if (empty(
$object->barcode)) {
11770 if (empty(
$object->barcode_type_code) || empty(
$object->barcode_type_coder)) {
11772 $result =
$object->fetchBarCode();
11775 return '<!-- ErrorFetchBarcode -->';
11780 $url = DOL_URL_ROOT .
'/viewimage.php?modulepart=barcode&generator=' . urlencode(
$object->barcode_type_coder) .
'&code=' . urlencode(
$object->barcode) .
'&encoding=' . urlencode(
$object->barcode_type_code);
11781 $out =
'<!-- url barcode = ' . $url .
' -->';
11782 $out .=
'<img src="' . $url .
'"' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
'>';
11805 public static function showphoto($modulepart,
$object, $width = 100, $height = 0, $caneditfield = 0, $cssclass =
'photowithmargin', $imagesize =
'', $addlinktofullsize = 1, $cache = 0, $forcecapture =
'', $noexternsourceoverwrite = 0, $usesharelinkifavailable = 0)
11814 $originalfile =
'';
11818 if ($modulepart ==
'societe') {
11819 $dir =
$conf->societe->multidir_output[$entity];
11822 if ((
string) $imagesize ==
'mini') {
11824 } elseif ((
string) $imagesize ==
'small') {
11833 } elseif ($modulepart ==
'contact') {
11834 $dir =
$conf->societe->multidir_output[$entity] .
'/contact';
11836 if (!empty($photo)) {
11838 if ((
string) $imagesize ==
'mini') {
11840 } elseif ((
string) $imagesize ==
'small') {
11845 $originalfile =
get_exdir(0, 0, 0, 0,
$object,
'contact') .
'photos/' . $photo;
11850 } elseif ($modulepart ==
'userphoto') {
11851 $dir =
$conf->user->dir_output;
11853 if (!empty($photo)) {
11855 if ((
string) $imagesize ==
'mini') {
11857 } elseif ((
string) $imagesize ==
'small') {
11862 $originalfile =
get_exdir(0, 0, 0, 0,
$object,
'user') .
'photos/' . $photo;
11866 $altfile =
$object->id .
".jpg";
11870 } elseif ($modulepart ==
'memberphoto') {
11871 $dir =
$conf->member->dir_output;
11873 if (!empty($photo)) {
11875 if ((
string) $imagesize ==
'mini') {
11877 } elseif ((
string) $imagesize ==
'small') {
11882 $originalfile =
get_exdir(0, 0, 0, 0,
$object,
'member') .
'photos/' . $photo;
11886 $altfile =
$object->id .
".jpg";
11893 if ($modulepart !=
"unknown" && method_exists(
$object,
'getDataToShowPhoto')) {
11894 $tmpdata =
$object->getDataToShowPhoto($modulepart, $imagesize);
11896 $dir = $tmpdata[
'dir'];
11897 $file = $tmpdata[
'file'];
11898 $originalfile = $tmpdata[
'originalfile'];
11899 $altfile = $tmpdata[
'altfile'];
11900 $email = $tmpdata[
'email'];
11901 $capture = $tmpdata[
'capture'];
11905 if ($forcecapture) {
11906 $capture = $forcecapture;
11912 if ($file && file_exists($dir .
"/" . $file)) {
11913 if ($addlinktofullsize) {
11915 if ($urladvanced) {
11916 $ret .=
'<a href="' . $urladvanced .
'">';
11918 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
11923 if ($usesharelinkifavailable) {
11925 $relativefileforecm = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT.
'/',
'/').
'/',
'', $dir.
'/'.$originalfile);
11927 require_once DOL_DOCUMENT_ROOT .
'/ecm/class/ecmfiles.class.php';
11929 $ecmfiles->fetch(0,
'', $relativefileforecm);
11931 $sharekey = (
string) $ecmfiles->share;
11934 if (!empty($sharekey)) {
11935 $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) .
'">';
11937 $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) .
'">';
11939 if ($addlinktofullsize) {
11942 } elseif ($altfile && file_exists($dir .
"/" . $altfile)) {
11943 if ($addlinktofullsize) {
11945 if ($urladvanced) {
11946 $ret .=
'<a href="' . $urladvanced .
'">';
11948 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
11951 $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) .
'">';
11952 if ($addlinktofullsize) {
11956 $nophoto =
'/public/theme/common/nophoto.png';
11957 $defaultimg =
'identicon';
11958 if (in_array($modulepart, array(
'societe',
'userphoto',
'contact',
'memberphoto'))) {
11959 if ($modulepart ==
'societe' || ($modulepart ==
'memberphoto' && !empty(
$object->morphy) && strpos(
$object->morphy,
'mor') !==
false)) {
11960 $nophoto =
'company';
11962 $nophoto =
'/public/theme/common/user_anonymous.png';
11964 $nophoto =
'/public/theme/common/user_man.png';
11967 $nophoto =
'/public/theme/common/user_woman.png';
11972 if (
isModEnabled(
'gravatar') && $email && empty($noexternsourceoverwrite)) {
11974 $ret .=
'<!-- Put link to gravatar -->';
11975 $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 .
'">';
11977 if ($nophoto ==
'company') {
11978 $ret .=
'<div class="divforspanimg valignmiddle inline-block center photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
'>' .
img_picto(
'',
'company') .
'</div>';
11981 $ret .=
'<img class="photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="' . DOL_URL_ROOT . $nophoto .
'">';
11986 if ($caneditfield) {
11990 $ret .=
'<table class="nobordernopadding centpercent">';
11992 $ret .=
'<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> <label for="photodelete">' . $langs->trans(
"Delete") .
'</label><br><br></td></tr>';
11994 $ret .=
'<tr><td class="tdoverflow">';
11996 $maxmin = $maxfilesizearray[
'maxmin'];
11998 $ret .=
'<input type="hidden" name="MAX_FILE_SIZE" value="' . ($maxmin * 1024) .
'">';
12000 $ret .=
'<input type="file" class="flat maxwidth200onsmartphone" name="photo" id="photoinput" accept="image/*"' . ($capture ?
' capture="' .
dolPrintHTMLForAttribute($capture) .
'"' :
'') .
'>';
12001 $ret .=
'</td></tr>';
12002 $ret .=
'</table>';
12027 public function select_dolgroups($selected = 0, $htmlname =
'groupid', $show_empty = 0, $exclude =
'', $disabled = 0, $include =
'', $enableonly = array(), $force_entity =
'0', $multiple =
false, $morecss =
'minwidth200')
12030 global
$conf, $user, $langs;
12033 $excludeGroups =
null;
12034 if (is_array($exclude)) {
12035 $excludeGroups = implode(
",", $exclude);
12038 $includeGroups =
null;
12039 if (is_array($include)) {
12040 $includeGroups = implode(
",", $include);
12043 if (!is_array($selected)) {
12044 $selected = array($selected);
12050 $sql =
"SELECT ug.rowid, ug.nom as name";
12051 if (
isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && !$user->entity) {
12052 $sql .=
", e.label";
12054 $sql .=
" FROM " . $this->db->prefix() .
"usergroup as ug ";
12055 if (
isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && !$user->entity) {
12056 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid=ug.entity";
12057 if ($force_entity) {
12058 $sql .=
" WHERE ug.entity IN (0, " . ((int) $force_entity) .
")";
12060 $sql .=
" WHERE ug.entity IS NOT NULL";
12063 $sql .=
" WHERE ug.entity IN (0, " . ((int)
$conf->entity) .
")";
12065 if (is_array($exclude) && $excludeGroups) {
12066 $sql .=
" AND ug.rowid NOT IN (" . $this->db->sanitize($excludeGroups) .
")";
12068 if (is_array($include) && $includeGroups) {
12069 $sql .=
" AND ug.rowid IN (" . $this->db->sanitize($includeGroups) .
")";
12071 $sql .=
" ORDER BY ug.nom ASC";
12073 dol_syslog(get_class($this) .
"::select_dolgroups", LOG_DEBUG);
12074 $resql = $this->db->query($sql);
12077 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
12079 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
12081 $num = $this->db->num_rows($resql);
12084 if ($show_empty && !$multiple) {
12085 $textforempty =
' ';
12086 if (!is_numeric($show_empty)) {
12089 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'>' . $textforempty .
'</option>' .
"\n";
12092 while ($i < $num) {
12093 $obj = $this->db->fetch_object($resql);
12095 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
12099 $label = $obj->name;
12100 $labelhtml = $obj->name;
12102 $label .=
" (" . $obj->label .
")";
12103 $labelhtml .=
' <span class="opacitymedium">(' . $obj->label .
')</span>';
12106 $out .=
'<option value="' . $obj->rowid .
'"';
12107 if ($disableline) {
12108 $out .=
' disabled';
12110 if ((isset($selected[0]) && is_object($selected[0]) && $selected[0]->
id == $obj->rowid)
12111 || ((!isset($selected[0]) || !is_object($selected[0])) && !empty($selected) && in_array($obj->rowid, $selected))) {
12112 $out .=
' selected';
12114 $out .=
' data-html="'.dol_escape_htmltag($labelhtml).
'"';
12117 $out .=
'</option>';
12122 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'></option>' .
"\n";
12124 $out .=
'<option value="" disabled>' . $langs->trans(
"NoUserGroupDefined") .
'</option>';
12126 $out .=
'</select>';
12145 $out =
'<div class="nowraponall">';
12146 $out .=
'<button type="submit" class="liste_titre button_search reposition" name="button_search_x" value="x"><span class="fas fa-search"></span></button>';
12147 $out .=
'<button type="submit" class="liste_titre button_removefilter reposition" name="button_removefilter_x" value="x"><span class="fas fa-times"></span></button>';
12161 public function showCheckAddButtons($cssclass =
'checkforaction', $calljsfunction = 0, $massactionname =
"massaction")
12167 if (!empty(
$conf->use_javascript_ajax)) {
12168 $out .=
'<div class="inline-block checkallactions"><input type="checkbox" id="' . $cssclass .
's" name="' . $cssclass .
's" class="checkallactions"></div>';
12170 $out .=
'<script nonce="' .
getNonce() .
'">
12171 $(document).ready(function() {
12172 $("#' . $cssclass .
's").click(function() {
12173 if($(this).is(\':checked\')){
12174 console.log("We check all ' . $cssclass .
' and trigger the change method");
12175 $(".' . $cssclass .
'").prop(\'checked\', true).trigger(\'change\');
12179 console.log("We uncheck all");
12180 $(".' . $cssclass .
'").prop(\'checked\', false).trigger(\'change\');
12182 if ($calljsfunction) {
12183 $out .=
'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0, "' . $massactionname .
'", "' . $cssclass .
'"); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }';
12187 $(".' . $cssclass .
'").change(function() {
12188 console.log("We check and change the tr class highlight after a change on .'.$cssclass.
'");
12189 var $row = $(this).closest("tr");
12191 var anyChecked = $row.find(\'input[type="checkbox"].checkforselect:checked\').length > 0;
12192 console.log("anychecked="+anyChecked);
12194 $row.removeClass("highlight");
12196 $row.addClass("highlight");
12218 $out = $this->showFilterButtons();
12219 if ($addcheckuncheckall) {
12220 $out .= $this->showCheckAddButtons($cssclass, $calljsfunction, $massactionname);
12238 public function selectExpenseCategories($selected =
'', $htmlname =
'fk_c_exp_tax_cat', $useempty = 0, $excludeid = array(), $target =
'', $default_selected = 0, $params = array(), $info_admin = 1)
12240 global $langs, $user;
12243 $sql =
"SELECT rowid, label FROM " . $this->db->prefix() .
"c_exp_tax_cat WHERE active = 1";
12244 $sql .=
" AND entity IN (0," .
getEntity(
'exp_tax_cat') .
")";
12245 if (!empty($excludeid)) {
12246 $sql .=
" AND rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeid)) .
")";
12248 $sql .=
" ORDER BY label";
12250 $resql = $this->db->query($sql);
12252 $out =
'<select id="select_' . $htmlname .
'" name="' . $htmlname .
'" class="' . $htmlname .
' flat minwidth75imp maxwidth200">';
12254 $out .=
'<option value="0"> </option>';
12257 while ($obj = $this->db->fetch_object($resql)) {
12258 $out .=
'<option ' . ($selected == $obj->rowid ?
'selected="selected"' :
'') .
' value="' . $obj->rowid .
'">' . $langs->trans($obj->label) .
'</option>';
12260 $out .=
'</select>';
12263 if (!empty($htmlname) && $user->admin && $info_admin) {
12264 $out .=
' ' .
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
12267 if (!empty($target)) {
12268 $sql =
"SELECT c.id FROM " . $this->db->prefix() .
"c_type_fees as c WHERE c.code = 'EX_KME' AND c.active = 1";
12269 $resql = $this->db->query($sql);
12271 if ($this->db->num_rows($resql) > 0) {
12272 $obj = $this->db->fetch_object($resql);
12273 $out .=
'<script nonce="' .
getNonce() .
'">
12275 $("select[name=' . $target .
']").on("change", function() {
12276 var current_val = $(this).val();
12277 if (current_val == ' . $obj->id .
') {';
12278 if (!empty($default_selected) || !empty($selected)) {
12279 $out .=
'$("select[name=' . $htmlname .
']").val("' . ($default_selected > 0 ? $default_selected : $selected) .
'");';
12283 $("select[name=' . $htmlname .
']").change();
12287 $("select[name=' . $htmlname .
']").change(function() {
12289 if ($("select[name=' . $target .
']").val() == ' . $obj->id .
') {
12290 // get price of kilometer to fill the unit price
12294 data: { fk_c_exp_tax_cat: $(this).val(), token: \'' .
currentToken() .
'\' },
12295 url:
"' . (DOL_URL_ROOT . '/expensereport/ajax/ajaxik.php?' . implode('&', $params)) . '",
12296 }).done(
function( data, textStatus, jqXHR ) {
12298 if (typeof data.up !=
"undefined") {
12299 $(
"input[name=value_unit]").val(data.up);
12300 $(
"select[name=' . $htmlname . ']").attr(
"title", data.title);
12302 $(
"input[name=value_unit]").val(
"");
12303 $(
"select[name=' . $htmlname . ']").attr(
"title",
"");
12314 dol_print_error($this->db);
12328 public function selectExpenseRanges($selected = '
', $htmlname = 'fk_range
', $useempty = 0)
12330 global $conf, $langs;
12333 $sql = "SELECT rowid, range_ik FROM " . $this->db->prefix() . "c_exp_tax_range";
12334 $sql .= " WHERE entity = " . ((int) $conf->entity) . " AND active = 1";
12336 $resql = $this->db->query($sql);
12338 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
12340 $out .= '<option value=
"0"></option>
';
12343 while ($obj = $this->db->fetch_object($resql)) {
12344 $out .= '<option
' . ($selected == $obj->rowid ? 'selected=
"selected"' : '') . ' value=
"' . $obj->rowid . '">
' . price($obj->range_ik, 0, $langs, 1, 0) . '</option>
';
12346 $out .= '</select>
';
12348 dol_print_error($this->db);
12364 public function selectExpenseFees($selected = '
', $htmlname = 'fk_c_type_fees
', $useempty = 0, $allchoice = 1, $useid = 0)
12369 $sql = "SELECT id, code, label";
12370 $sql .= " FROM ".$this->db->prefix()."c_type_fees";
12371 $sql .= " WHERE active = 1";
12373 $resql = $this->db->query($sql);
12375 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
12377 $out .= '<option value=
"0"></option>
';
12380 $out .= '<option value=
"-1">
' . $langs->trans('AllExpenseReport
') . '</option>
';
12388 while ($obj = $this->db->fetch_object($resql)) {
12389 $key = $langs->trans($obj->code);
12390 $out .= '<option
' . ($selected == $obj->{$field} ? 'selected=
"selected"' : '') . ' value=
"' . $obj->{$field} . '">
' . ($key != $obj->code ? $key : $obj->label) . '</option>
';
12392 $out .= '</select>
';
12394 $out .= ajax_combobox('select_
'.$htmlname);
12396 dol_print_error($this->db);
12420 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)
12422 global $user, $conf, $langs;
12424 require_once DOL_DOCUMENT_ROOT . '/projet/
class/project.class.php
';
12426 if (is_null($usertofilter)) {
12427 $usertofilter = $user;
12432 $hideunselectables = false;
12433 if (getDolGlobalString('INVOICE_HIDE_UNSELECTABLES
')) {
12434 $hideunselectables = true;
12437 if (empty($projectsListId)) {
12438 if (!$usertofilter->hasRight('projet
', 'all
', 'lire
')) {
12439 $projectstatic = new Project($this->db);
12440 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1);
12444 // Search all projects
12445 $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";
12446 $sql .= " FROM " . $this->db->prefix() . "facture as f";
12447 $sql .= " INNER JOIN " . $this->db->prefix() . "projet as p ON p.entity IN (" . getEntity('project
') . ") AND f.fk_projet = p.rowid";
12448 $sql .= " LEFT JOIN " . $this->db->prefix() . "societe as s ON s.rowid = p.fk_soc";
12449 $sql .= " WHERE f.fk_statut = 0"; // Draft invoices only
12450 //if ($projectsListId) $sql.= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")";
12451 //if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
12452 //if ($socid > 0) $sql.= " AND (p.fk_soc=".((int) $socid)." OR p.fk_soc IS NULL)";
12453 $sql .= " ORDER BY p.ref, f.ref ASC";
12455 $resql = $this->db->query($sql);
12457 // Use select2 selector
12458 if (!empty($conf->use_javascript_ajax)) {
12459 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
12460 $comboenhancement = ajax_combobox($htmlname, array(), 0, $forcefocus);
12461 $out .= $comboenhancement;
12462 $morecss = 'minwidth200imp maxwidth500
';
12465 if (empty($option_only)) {
12466 $out .= '<select
class=
"valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled=
"disabled"' : '') . ' id=
"' . $htmlname . '" name=
"' . $htmlname . '">
';
12468 if (!empty($show_empty)) {
12469 $out .= '<option value=
"0" class=
"optiongrey">
';
12470 if (!is_numeric($show_empty)) {
12471 $out .= $show_empty;
12475 $out .= '</option>
';
12477 $num = $this->db->num_rows($resql);
12480 while ($i < $num) {
12481 $obj = $this->db->fetch_object($resql);
12482 // 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.
12483 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$usertofilter->hasRight('societe
', 'lire
')) {
12486 if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) {
12493 if ($showproject == 'all
') {
12494 $labeltoshow .= dol_trunc($obj->ref, 18); // Invoice ref
12496 $labeltoshow .= ' -
' . $obj->name; // Soc name
12500 if ($obj->fk_statut == Project::STATUS_DRAFT) {
12502 $labeltoshow .= ' -
' . $langs->trans("Draft");
12503 } elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
12504 if ($discard_closed == 2) {
12507 $labeltoshow .= ' -
' . $langs->trans("Closed");
12508 } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
12510 $labeltoshow .= ' -
' . $langs->trans("LinkedToAnotherCompany");
12514 if (!empty($selected) && $selected == $obj->rowid) {
12515 $out .= '<option value=
"' . $obj->rowid . '" selected
';
12516 //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected
if disabled
12517 $out .=
'>' . $labeltoshow .
'</option>';
12519 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
12522 $resultat =
'<option value="' . $obj->rowid .
'"';
12524 $resultat .=
' disabled';
12529 $resultat .= $labeltoshow;
12530 $resultat .=
'</option>';
12538 if (empty($option_only)) {
12539 $out .=
'</select>';
12542 $this->db->free($resql);
12565 public function selectInvoiceRec($selected =
'', $htmlname =
'facrecid', $maxlength = 24, $option_only = 0, $show_empty =
'1', $forcefocus = 0, $disabled = 0, $morecss =
'maxwidth500')
12567 global
$conf, $langs;
12573 $sql =
'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc';
12574 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'facture_rec as f';
12575 $sql .=
" WHERE f.entity IN (" .
getEntity(
'invoice') .
")";
12576 $sql .=
" ORDER BY f.titre ASC";
12578 $resql = $this->db->query($sql);
12581 if (!empty(
$conf->use_javascript_ajax)) {
12582 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
12583 $comboenhancement =
ajax_combobox($htmlname, array(), 0, $forcefocus);
12584 $out .= $comboenhancement;
12585 $morecss =
'minwidth200imp maxwidth500';
12588 if (empty($option_only)) {
12589 $out .=
'<select class="valignmiddle flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' id="' . $htmlname .
'" name="' . $htmlname .
'">';
12591 if (!empty($show_empty)) {
12592 $out .=
'<option value="0" class="optiongrey">';
12593 if (!is_numeric($show_empty)) {
12594 $out .= $show_empty;
12598 $out .=
'</option>';
12600 $num = $this->db->num_rows($resql);
12602 while ($obj = $this->db->fetch_object($resql)) {
12603 $labeltoshow =
dol_trunc($obj->title, 18);
12606 if (!empty($obj->suspended)) {
12608 $labeltoshow .=
' - ' . $langs->trans(
"Closed");
12612 if (!empty($selected) && $selected == $obj->rowid) {
12613 $out .=
'<option value="' . $obj->rowid .
'" selected';
12615 $out .=
'>' . $labeltoshow .
'</option>';
12617 if ($disabled && ($selected != $obj->rowid)) {
12620 $resultat =
'<option value="' . $obj->rowid .
'"';
12622 $resultat .=
' disabled';
12625 $resultat .= $labeltoshow;
12626 $resultat .=
'</option>';
12632 if (empty($option_only)) {
12633 $out .=
'</select>';
12638 $this->db->free($resql);
12641 $this->errors[] = $this->db->lasterror;
12657 public function searchComponent($arrayofcriterias, $search_component_params, $arrayofinputfieldsalreadyoutput = array(), $search_component_params_hidden =
'', $arrayoffiltercriterias = array())
12660 global $langs, $form;
12665 if ($search_component_params_hidden !=
'' && !preg_match(
'/^\(.*\)$/', $search_component_params_hidden)) {
12666 $search_component_params_hidden =
'(' . $search_component_params_hidden .
')';
12669 $ret =
'<!-- searchComponent -->';
12671 $ret .=
'<div class="divadvancedsearchfieldcomp centpercent inline-block">';
12672 $ret .=
'<a href="#" class="dropdownsearch-toggle unsetcolor">';
12673 $ret .=
'<span class="fas fa-filter linkobject boxfilter paddingright pictofixedwidth" title="' .
dol_escape_htmltag($langs->trans(
"Filters")) .
'" id="idsubimgproductdistribution"></span>';
12676 $ret .=
'<div class="divadvancedsearchfieldcompinput inline-block minwidth500 maxwidth300onsmartphone">';
12679 $ret .=
'<div id="divsearch_component_params" name="divsearch_component_params" class="noborderbottom search_component_params inline-block valignmiddle">';
12681 if ($search_component_params_hidden) {
12689 foreach ($arrayofandtags as $tmpkey => $tmpval) {
12690 $errormessage =
'';
12692 if ($errormessage) {
12693 $this->error =
'ERROR in parsing search string: '.$errormessage;
12696 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
12699 $ret .=
'<span class="marginleftonlyshort valignmiddle tagsearch" data-ufilterid="'.($tmpkey + 1).
'" data-ufilter="'.
dol_escape_htmltag($tmpval).
'">';
12700 $ret .=
'<span class="tagsearchdelete select2-selection__choice__remove" data-ufilterid="'.($tmpkey + 1).
'">x</span> ';
12712 $show_search_component_params_hidden = 1;
12713 if ($show_search_component_params_hidden) {
12714 $ret .=
'<input type="hidden" name="show_search_component_params_hidden" value="1">';
12716 $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%')) -->";
12717 $ret .=
'<input type="hidden" id="search_component_params_hidden" name="search_component_params_hidden" value="' .
dol_escape_htmltag($search_component_params_hidden) .
'">';
12722 foreach ($arrayofcriterias as $criteria) {
12723 foreach ($criteria as $criteriafamilykey => $criteriafamilyval) {
12724 if (in_array(
'search_' . $criteriafamilykey, $arrayofinputfieldsalreadyoutput)) {
12727 if (in_array($criteriafamilykey, array(
'rowid',
'ref_ext',
'entity',
'extraparams'))) {
12730 if (in_array($criteriafamilyval[
'type'], array(
'date',
'datetime',
'timestamp'))) {
12731 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_start">';
12732 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startyear">';
12733 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startmonth">';
12734 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startday">';
12735 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_end">';
12736 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endyear">';
12737 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endmonth">';
12738 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endday">';
12740 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'">';
12747 $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";
12748 $ret .=
'<input type="text" placeholder="' . $langs->trans(
"Filters") .
'" id="search_component_params_input" name="search_component_params_input" class="noborderall search_component_input" value="">';
12754 jQuery(".tagsearchdelete").click(function(e) {
12755 var filterid = $(this).parents().attr("data-ufilterid");
12756 console.log("We click to delete the criteria nb "+filterid);
12758 // Regenerate the search_component_params_hidden with all data-ufilter except the one to delete, and post the page
12759 var newparamstring = \'\';
12760 $(\'.tagsearch\').each(function(index, element) {
12761 tmpfilterid = $(this).attr("data-ufilterid");
12762 if (tmpfilterid != filterid) {
12763 // We keep this criteria
12764 if (newparamstring == \'\') {
12765 newparamstring = $(this).attr("data-ufilter");
12767 newparamstring = newparamstring + \' AND \' + $(this).attr("data-ufilter");
12771 console.log("newparamstring = "+newparamstring);
12773 jQuery("#search_component_params_hidden").val(newparamstring);
12775 // We repost the form
12776 $(this).closest(\'form\').submit();
12779 jQuery("#search_component_params_input").keydown(function(e) {
12780 console.log("We press a key on the filter field that is "+jQuery("#search_component_params_input").val());
12781 console.log(e.which);
12782 if (jQuery("#search_component_params_input").val() == "" && e.which == 8) {
12783 /* We click on back when the input field is already empty */
12784 event.preventDefault();
12785 jQuery("#divsearch_component_params .tagsearch").last().remove();
12786 /* Regenerate content of search_component_params_hidden from remaining .tagsearch */
12788 jQuery("#divsearch_component_params .tagsearch").each(function( index ) {
12792 s = s + $(this).attr("data-ufilter");
12794 console.log("New value for search_component_params_hidden = "+s);
12795 jQuery("#search_component_params_hidden").val(s);
12803 $arrayoffiltercriterias_json = json_encode($arrayoffiltercriterias);
12805 var arrayoffiltercriterias = ' . $arrayoffiltercriterias_json .
';
12809 $arrayoffilterfieldslabel = array();
12810 foreach ($arrayoffiltercriterias as $key => $val) {
12811 $arrayoffilterfieldslabel[$key][
'label'] = $val[
'label'];
12812 $arrayoffilterfieldslabel[$key][
'data-type'] = $val[
'type'];
12816 $ret .=
'<div class="search-component-assistance">';
12819 $ret .=
'<p class="assistance-title">' .
img_picto(
'',
'filter') .
' ' . $langs->trans(
'FilterAssistance') .
' </p>';
12821 $ret .=
'<p class="assistance-errors error" style="display:none">' . $langs->trans(
'AllFieldsRequired') .
' </p>';
12823 $ret .=
'<div class="operand">';
12824 $ret .= $form->selectarray(
'search_filter_field', $arrayoffilterfieldslabel,
'', $langs->trans(
"Fields"), 0, 0,
'', 0, 0, 0,
'',
'width200 combolargeelem', 1);
12827 $ret .=
'<span class="separator"></span>';
12830 $ret .=
'<div class="operator">';
12831 $ret .=
'<select class="operator-selector width150" id="operator-selector"">';
12832 $ret .=
'</select>';
12833 $ret .=
'<script>$(document).ready(function() {';
12834 $ret .=
' $(".operator-selector").select2({';
12835 $ret .=
' placeholder: \'' .
dol_escape_js($langs->transnoentitiesnoconv(
'Operator')) .
'\'';
12837 $ret .=
'});</script>';
12840 $ret .=
'<span class="separator"></span>';
12842 $ret .=
'<div class="value">';
12844 $ret .=
'<input type="text" class="flat width100 value-input" placeholder="' .
dolPrintHTML($langs->trans(
'Value')) .
'">';
12848 $ret .=
'<span class="date-one" style="display:none">';
12849 $ret .= $form->selectDate(($dateOne ? $dateOne : -1),
'dateone', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'');
12853 $ret .=
'<select class="value-selector width150" id="value-selector" style="display:none">';
12854 $ret .=
'</select>';
12856 $(document).ready(function() {
12857 $("#value-selector").select2({
12858 placeholder: "' .
dol_escape_js($langs->trans(
'Value')) .
'"
12860 $("#value-selector").hide();
12861 $("#value-selector").next(".select2-container").hide();
12867 $ret .=
'<div class="btn-div">';
12868 $ret .=
'<button class="button buttongen button-save add-filter-btn" type="button">' . $langs->trans(
"addToFilter") .
'</button>';
12879 $(document).ready(function() {
12880 $("#search_component_params_input").on("click", function() {
12881 const inputPosition = $(this).offset();
12882 const inputHeight = $(this).outerHeight();
12883 $(".search-component-assistance").css({
12884 top: inputPosition.top + inputHeight + 5 + "px",
12885 left: $("#divsearch_component_params").position().left
12886 }).slideToggle(200);
12888 $(document).on("click", function(e) {
12889 if (!$(e.target).closest("#search_component_params_input, .search-component-assistance, #ui-datepicker-div").length) {
12890 $(".search-component-assistance").hide();
12897 $(document).ready(function() {
12898 $(".search_filter_field").on("change", function() {
12899 console.log("We change search_filter_field");
12902 const selectedField = $(this).find(":selected");
12903 let fieldType = selectedField.data("type");
12904 const selectedFieldValue = selectedField.val();
12906 // If the selected field has an array of values then ask toshow the value selector instead of the value input
12907 if (arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"] !== undefined) {
12908 fieldType = "select";
12911 // If the selected field may be null then ask to append the "IsDefined" and "IsNotDefined" operators
12912 if (arrayoffiltercriterias[selectedFieldValue]["maybenull"] !== undefined) {
12915 const operators = getOperatorsForFieldType(fieldType, maybenull);
12916 const operatorSelector = $(".operator-selector");
12918 // Clear existing options
12919 operatorSelector.empty();
12921 // Populate operators
12922 Object.entries(operators).forEach(function([operator, label]) {
12923 operatorSelector.append("<option value=\'" + operator + "\'>" + label + "</option>");
12926 operatorSelector.trigger("change.select2");
12928 // Clear and hide all input elements initially
12929 $(".value-input, .dateone, .datemonth, .dateyear").val("").hide();
12930 $("#datemonth, #dateyear").val(null).trigger("change.select2");
12931 $("#dateone").datepicker("setDate", null);
12932 $(".date-one, .date-month, .date-year").hide();
12933 $("#value-selector").val("").hide();
12934 $("#value-selector").next(".select2-container").hide();
12935 $("#value-selector").val(null).trigger("change.select2");
12937 if (fieldType === "date" || fieldType === "datetime" || fieldType === "timestamp") {
12938 $(".date-one").show();
12939 } else if (arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"] !== undefined) {
12940 var arrayofkeyval = arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"];
12941 var valueSelector = $("#value-selector");
12942 valueSelector.empty();
12943 Object.entries(arrayofkeyval).forEach(function([key, val]) {
12944 valueSelector.append("<option value=\'" + key + "\'>" + val + "</option>");
12946 valueSelector.trigger("change.select2");
12948 $("#value-selector").show();
12949 $("#value-selector").next(".select2-container").show();
12951 $(".value-input").show();
12955 $("#operator-selector").on("change", function() {
12956 console.log("We change operator-selector");
12958 const selectedOperator = $(this).find(":selected").val();
12959 if (selectedOperator === "IsDefined" || selectedOperator === "IsNotDefined") {
12960 // Disable all value input elements
12961 $(".value-input, .dateone, .datemonth, .dateyear").val("").prop("disabled", true);
12962 $("#datemonth, #dateyear").val(null).trigger("change.select2");
12963 $("#dateone").datepicker("setDate", null).datepicker("option", "disabled", true);
12964 $(".date-one, .date-month, .date-year").prop("disabled", true);
12965 $("#value-selector").val("").prop("disabled", true);
12966 $("#value-selector").val(null).trigger("change.select2");
12968 // Enable all value input elements
12969 $(".value-input, .dateone, .datemonth, .dateyear").prop("disabled", false);
12970 $(".date-one, .date-month, .date-year").prop("disabled", false);
12971 $("#dateone").datepicker("option", "disabled", false);
12972 $("#value-selector").prop("disabled", false);
12976 $(".add-filter-btn").on("click", function(event) {
12977 console.log("We click on add-filter-btn");
12979 event.preventDefault();
12981 const field = $(".search_filter_field").val();
12982 const operator = $(".operator-selector").val();
12983 let value = $(".value-input").val();
12984 const fieldType = $(".search_filter_field").find(":selected").data("type");
12986 if (["date", "datetime", "timestamp"].includes(fieldType)) {
12987 const year = $("#dateoneyear").val().toString().padStart(4, "0");;
12988 const month = $("#dateonemonth").val().toString().padStart(2, "0");
12989 const day = $("#dateoneday").val().toString().padStart(2, "0");
12990 value = `${year}-${month}-${day}`;
12991 console.log("value="+value);
12994 // If the selected field has an array of values then take the selected value
12995 if (arrayoffiltercriterias[field]["arrayofkeyval"] !== undefined) {
12996 value = $("#value-selector").val();
12999 // If the operator is "IsDefined" or "IsNotDefined" then set the value to 1 (it will not be used)
13000 if (operator === "IsDefined" || operator === "IsNotDefined") {
13004 const filterString = generateFilterString(field, operator, value, fieldType);
13007 if (filterString !== "" && field !== "" && operator !== "" && value !== "") {
13008 $("#search_component_params_input").val($("#search_component_params_input").val() + " " + filterString);
13009 $("#search_component_params_input").closest("form").submit();
13011 $(".assistance-errors").show();
13031 public function selectModelMail($prefix, $modelType =
'', $default = 0, $addjscombo = 0, $selected = 0, $morecss =
'')
13033 global $langs, $user;
13037 $TModels = array();
13039 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
13040 $formmail =
new FormMail($this->db);
13041 $result = $formmail->fetchAllEMailTemplate($modelType, $user, $langs);
13044 $TModels[0] = $langs->trans(
'DefaultMailModel');
13047 foreach ($formmail->lines_model as $model) {
13048 $TModels[(int) $model->id] = $model->label;
13052 $retstring .=
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" id="select_' . $prefix .
'model_mail" name="' . $prefix .
'model_mail">';
13054 foreach ($TModels as $id_model => $label_model) {
13055 $retstring .=
'<option value="' . $id_model .
'"';
13056 if (!empty($selected) && ((int) $selected) == $id_model) {
13057 $retstring .=
"selected";
13059 $retstring .=
">" . $label_model .
"</option>";
13062 $retstring .=
"</select>";
13065 $retstring .=
ajax_combobox(
'select_' . $prefix .
'model_mail');
13082 public function buttonsSaveCancel($save_label =
'Save', $cancel_label =
'Cancel', $morebuttons = array(), $withoutdiv =
false, $morecss =
'', $dol_openinpopup =
'')
13086 $buttons = array();
13090 'label_key' => $save_label,
13093 if ($save_label ==
'Create' || $save_label ==
'Add') {
13094 $save[
'name'] =
'add';
13095 } elseif ($save_label ==
'Modify') {
13096 $save[
'name'] =
'edit';
13100 'name' =>
'cancel',
13101 'label_key' =>
'Cancel',
13106 !empty($save_label) ? $buttons[] = $save :
'';
13107 if (!empty($morebuttons)) {
13108 $buttons[] = $morebuttons;
13110 !empty($cancel_label) ? $buttons[] = $cancel :
'';
13112 if (!empty($morebuttons)) {
13113 $buttons[] = $morebuttons;
13115 !empty($cancel_label) ? $buttons[] = $cancel :
'';
13116 !empty($save_label) ? $buttons[] = $save :
'';
13119 $retstring = $withoutdiv ?
'' :
'<div class="center">';
13121 foreach ($buttons as $button) {
13122 $addclass = empty($button[
'addclass']) ?
'' : $button[
'addclass'];
13123 $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'])) .
'">';
13125 $retstring .= $withoutdiv ?
'' :
'</div>';
13127 if ($dol_openinpopup) {
13128 $retstring .=
'<!-- buttons are shown into a $dol_openinpopup=' .
dol_escape_htmltag($dol_openinpopup) .
' context, so we enable the close of dialog on cancel -->' .
"\n";
13129 $retstring .=
'<script nonce="' .
getNonce() .
'">';
13130 $retstring .=
'jQuery(".button-cancel").click(function(e) {
13131 e.preventDefault(); console.log(\'We click on cancel in iframe popup ' .
dol_escape_js($dol_openinpopup) .
'\');
13132 window.parent.jQuery(\
'#idfordialog' .
dol_escape_js($dol_openinpopup) .
'\').dialog(\
'close\');
13134 $retstring .=
'</script>';
13153 $num = count($this->cache_invoice_subtype);
13160 $sql =
"SELECT rowid, code, label as label";
13161 $sql .=
" FROM " . MAIN_DB_PREFIX .
'c_invoice_subtype';
13162 $sql .=
" WHERE active = 1";
13164 $resql = $this->db->query($sql);
13166 $num = $this->db->num_rows($resql);
13168 while ($i < $num) {
13169 $obj = $this->db->fetch_object($resql);
13172 $label = ($langs->trans(
"InvoiceSubtype" . $obj->rowid) !=
"InvoiceSubtype" . $obj->rowid) ? $langs->trans(
"InvoiceSubtype" . $obj->rowid) : (($obj->label !=
'-') ? $obj->label :
'');
13173 $this->cache_invoice_subtype[$obj->rowid][
'rowid'] = $obj->rowid;
13174 $this->cache_invoice_subtype[$obj->rowid][
'code'] = $obj->code;
13175 $this->cache_invoice_subtype[$obj->rowid][
'label'] = $label;
13179 $this->cache_invoice_subtype =
dol_sort_array($this->cache_invoice_subtype,
'code',
'asc', 0, 0, 1);
13201 global $langs, $user;
13204 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
13206 $this->load_cache_invoice_subtype();
13208 $out .=
'<select id="' . $htmlname .
'" class="flat selectsubtype' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
13210 $out .=
'<option value="0"> </option>';
13213 foreach ($this->cache_invoice_subtype as $rowid => $subtype) {
13214 $label = $subtype[
'label'];
13215 $out .=
'<option value="' . $subtype[
'rowid'] .
'"';
13216 if ($selected == $subtype[
'rowid']) {
13217 $out .=
' selected="selected"';
13221 $out .=
'</option>';
13224 $out .=
'</select>';
13225 if ($user->admin && empty($noinfoadmin)) {
13226 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
13247 'type' =>
'search',
13248 'name' => $htmlName,
13250 'class' =>
"search-tool-input",
13251 'placeholder' => $langs->trans(
'Search'),
13252 'autocomplete' =>
'off'
13260 if ($dataTarget !==
false) {
13261 $attr[
'data-search-tool-target'] = $dataTarget;
13265 if (!empty($params[
'attr']) && is_array($params[
'attr'])) {
13266 foreach ($params[
'attr'] as $key => $value) {
13267 if ($key ==
'class') {
13268 $attr[
'class'] .=
' '.$value;
13269 } elseif ($key ==
'classOverride') {
13270 $attr[
'class'] = $value;
13272 $attr[$key] = $value;
13278 if (!empty($attr[
'title']) && !empty($attr[
'class']) && strpos($attr[
'class'],
'classfortooltip') ===
false) {
13279 $attr[
'class'] .=
' classfortooltip';
13282 $TCompiledAttr = [];
13283 foreach ($attr as $key => $value) {
13284 if (in_array($key, [
'data-target'])
13285 || (!empty($params[
'use_unsecured_unescapedattr']) && is_array($params[
'use_unsecured_unescapedattr']) && in_array($key, $params[
'use_unsecured_unescapedattr']))) {
13291 $TCompiledAttr[] = $key .
'="' . $value .
'"';
13294 $compiledAttributes = implode(
' ', $TCompiledAttr);
13297 return '<div class="search-tool-container"><input '.$compiledAttributes.
'></div>';
13313 public function inputType($type, $name, $value =
'',
$id =
'', $morecss =
'', $moreparam =
'', $label =
'', $addInputLabel =
'')
13316 if ($label !=
'') {
13326 $out .= ($moreparam ?
' ' . $moreparam :
'');
13327 $out .=
' />' . $addInputLabel;
13328 if ($label !=
'') {
13329 $out .= $label .
'</label>';
13347 public function inputSelectAjax($htmlName, $array,
$id, $ajaxUrl, $ajaxData = [], $morecss =
'minwidth75', $moreparam =
'')
13351 $(document).ready(function () {
13352 $('#" . $htmlName .
"').select2({
13354 url: '" . $ajaxUrl .
"',
13356 delay: 250, // wait 250 milliseconds before triggering the request
13357 data: function (params) {
13359 search: params.term,
13360 page: params.page || 1";
13361 if (!empty($ajaxData) && is_array($ajaxData)) {
13362 foreach ($ajaxData as $key => $value) {
13363 $out .=
", " . $key .
": '" . $value .
"'";
13375 $out .= $this->selectarray($htmlName, $array,
$id, 0, 0, 0, $moreparam, 0, 0, 0,
'', $morecss);
13389 public function inputHtml($htmlName, $value, $morecss =
'', $moreparam =
'')
13391 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
13392 $doleditor =
new DolEditor($htmlName, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
isModEnabled(
'fckeditor') &&
getDolGlobalInt(
'FCKEDITOR_ENABLE_SOCIETE'), ROWS_5,
'90%');
13394 return (
string) $doleditor->Create(1,
'',
true,
'',
'', $moreparam, $morecss);
13407 public function inputText($htmlName, $value, $morecss =
'', $moreparam =
'', $options = array())
13412 if (!empty($options)) {
13414 $out .= $this->selectarray($htmlName .
"_multiinput", $options,
'', 1, 0, 0, $moreparam, 0, 0, 0,
'',
"flat maxwidthonphone" . $morecss);
13415 $out .=
'<input id="' . $htmlName .
'_multiinputadd" type="button" class="button" value="' . $langs->trans(
"Add") .
'">';
13416 $out .=
"<script>";
13418 function handlemultiinputdisabling(htmlname){
13419 console.log("We handle the disabling of used options for "+htmlname+"_multiinput");
13420 multiinput = $("#"+htmlname+"_multiinput");
13421 multiinput.find("option").each(function(){
13422 tmpval = $("#"+htmlname).val();
13423 tmpvalarray = tmpval.split("\n");
13424 valtotest = $(this).val();
13425 if(tmpvalarray.includes(valtotest)){
13426 $(this).prop("disabled",true);
13428 if($(this).prop("disabled") == true){
13429 console.log(valtotest)
13430 $(this).prop("disabled", false);
13436 $(document).ready(function () {
13437 $("#' . $htmlName .
'_multiinputadd").on("click",function() {
13438 tmpval = $("#' . $htmlName .
'").val();
13439 tmpvalarray = tmpval.split(",");
13440 valtotest = $("#' . $htmlName .
'_multiinput").val();
13441 if(valtotest != -1 && !tmpvalarray.includes(valtotest)){
13442 console.log("We add the selected value to the text area ' . $htmlName .
'");
13444 tmpval = valtotest;
13446 tmpval = tmpval + "\n" + valtotest;
13448 $("#' . $htmlName .
'").val(tmpval);
13449 handlemultiinputdisabling("' . $htmlName .
'");
13450 $("#' . $htmlName .
'_multiinput").val(-1);
13452 console.log("We add nothing the text area ' . $htmlName .
'");
13455 $("#' . $htmlName .
'").on("change",function(){
13456 handlemultiinputdisabling("' . $htmlName .
'");
13458 handlemultiinputdisabling("' . $htmlName .
'");
13460 $out .=
"</script>";
13461 $value = str_replace(
',',
"\n", $value);
13464 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
13465 $doleditor =
new DolEditor($htmlName, (
string) $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
13466 $out .= (
string) $doleditor->Create(1,
'',
true,
'',
'', $moreparam, $morecss);
13481 public function inputRadio($htmlName, $options, $selectedValue, $morecss =
'', $moreparam =
'')
13484 foreach ($options as $optionKey => $optionLabel) {
13485 $selected = ((
string) $selectedValue) === ((
string) $optionKey) ?
' checked="checked"' :
'';
13486 $optionId = $htmlName .
'_' . $optionKey;
13487 $out .=
'<input class="flat' . $morecss .
'" type="radio" name="' . $htmlName .
'" id="' . $optionId .
'" value="' .
dolPrintHTMLForAttribute((
string) $optionKey) .
'"' . $selected . $moreparam .
'/><label for="' . $optionId .
'">' . $optionLabel .
'</label><br>';
13503 public function inputStars($htmlName, $size, $value, $morecss =
'', $moreparam =
'')
13505 $out =
'<input type="hidden" class="flat ' . $morecss .
'" name="' . $htmlName .
'" id="' . $htmlName .
'" value="' .
dolPrintHTMLForAttribute((
string) $value) .
'"' . $moreparam .
'>';
13506 $out .=
'<div class="star-selection" id="' . $htmlName .
'_selection">';
13507 for ($i = 1; $i <= $size; $i++) {
13508 $out .=
'<span class="star" data-value="' . $i .
'">' .
img_picto(
'',
'fontawesome_star_fas') .
'</span>';
13512 jQuery(function($) { /* commonobject.class.php 1 */
13513 let container = $("#' . $htmlName .
'_selection");
13514 let selectedStars = parseInt($("#' . $htmlName .
'").val()) || 0;
13515 container.find(".star").each(function() {
13516 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
13518 container.find(".star").on("mouseover", function() {
13519 let selectedStar = $(this).data("value");
13520 container.find(".star").each(function() {
13521 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
13524 container.on("mouseout", function() {
13525 container.find(".star").each(function() {
13526 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
13529 container.find(".star").off("click").on("click", function() {
13530 selectedStars = $(this).data("value");
13531 if (selectedStars === 1 && $("#' . $htmlName .
'").val() == 1) {
13534 $("#' . $htmlName .
'").val(selectedStars);
13535 container.find(".star").each(function() {
13536 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
13554 public function inputIcon($htmlName, $value, $morecss =
'', $moreparam =
'')
13563 $out =
'<input type="text" class="form-control icp icp-auto iconpicker-element iconpicker-input flat ' . $morecss .
' maxwidthonsmartphone"';
13564 $out .=
' name="' . $htmlName .
'" id="' . $htmlName .
'" value="' .
dolPrintHTMLForAttribute((
string) $value) .
'" ' . ((
string) $moreparam) .
'>';
13566 $out .=
'<script>';
13567 $options =
"{ title: '<b>" . $langs->trans(
"IconFieldSelector") .
"</b>', placement: 'right', showFooter: false, templates: {";
13568 $options .=
"iconpicker: '<div class=\"iconpicker\"><div style=\"background-color:#EFEFEF;\" class=\"iconpicker-items\"></div></div>',";
13569 $options .=
"iconpickerItem: '<a role=\"button\" href=\"#\" class=\"iconpicker-item\" style=\"background-color:#DDDDDD;\"><i></i></a>',";
13572 $options .=
"footer: '<div class=\"popover-footer\" style=\"background-color:#EFEFEF;\"></div>',";
13573 $options .=
"search: '<input type=\"search\" class\"form-control iconpicker-search\" placeholder=\"" . $langs->trans(
"TypeToFilter") .
"\" />',";
13574 $options .=
"popover: '<div class=\"iconpicker-popover popover\">";
13575 $options .=
" <div class=\"arrow\" ></div>";
13576 $options .=
" <div class=\"popover-title\" style=\"text-align:center;background-color:#EFEFEF;\"></div>";
13577 $options .=
" <div class=\"popover-content \" ></div>";
13578 $options .=
"</div>'}}";
13579 $out .=
"$('#" . $htmlName .
"').iconpicker(" . $options .
");";
13580 $out .=
'</script>';
13596 require_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeophp.class.php';
13597 require_once DOL_DOCUMENT_ROOT .
'/core/class/geomapeditor.class.php';
13603 if (!empty($value)) {
13604 $tmparray = $dolgeophp->parseGeoString($value);
13605 $geojson = $tmparray[
'geojson'];
13606 $centroidjson = $tmparray[
'centroidjson'];
13609 return $geomapeditor->getHtml($htmlName, $geojson, $centroidjson, $type);
13621 $toPrint = array();
13622 $values = is_array($values) ? $values : array();
13624 foreach ($values as $value) {
13625 $toPrint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $value .
'</li>';
13627 if (!empty($toPrint)) {
13628 $out =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(
' ', $toPrint) .
'</ul></div>';
13644 for ($i = 1; $i <= $size; $i++) {
13645 $out .=
'<span class="star' . ($i <= $value ?
' active' :
'') .
'" data-value="' . $i .
'">' .
img_picto(
'',
'fontawesome_star_fas') .
'</span>';
13676 if (!empty($value)) {
13677 require_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeophp.class.php';
13679 if ($type ==
'point') {
13680 $out = $dolgeophp->getXYString($value);
13682 $out = $dolgeophp->getPointString($value);
13703 public function getNomUrl(&
$object, $withpicto = 0, $option =
'', $maxlength = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'', $add_label = 0, $sep =
' - ')
13705 if (is_object(
$object) && method_exists(
$object,
'getNomUrl')) {
13706 $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.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
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 '.
currentToken()
Return the value of token currently saved into session with name 'token'.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_print_url($url, $target='_blank', $max=32, $withpicto=0, $morecss='')
Show Url link.
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_string_neverthesehtmltags($stringtoclean, $disallowed_tags=array('textarea'), $cleanalsosomestyles=0)
Clean a string from some undesirable HTML tags.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
colorIsLight($stringcolor)
Return true if the color is light.
dolIsAllowedForPreview($file)
Return if a file is qualified for preview.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
getNonce()
Return a random string to be used as a nonce value for js.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox=0, $check='restricthtml')
Sanitize a HTML to remove js, dangerous content and external links.
dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array(), $allowlink=0, $allowscript=0, $allowstyle=0, $allowphp=0)
Clean a string to keep only desirable HTML tags.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_sanitizeKeyCode($str)
Clean a string to use it as a key or code.
isModEnabled($module)
Is Dolibarr module enabled.
array_merge_recursive_distinct(array $array1, array $array2)
Recursively merges two arrays while preserving keys and replacing existing values.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_nboflines_bis($text, $maxlinesize=0, $charset='UTF-8')
Return nb of lines of a formatted text with and (WARNING: string must not have mixed and br sep...
multi select button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
commonHtmlAttributeBuilder($attr, array $unescapedAttr=[])
Builds an array of safe and properly escaped HTML attributes from a key-value pair list.
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.
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
dolPrintHTMLForAttribute($s, $escapeonlyhtmltags=0, $allowothertags=array())
Return a string ready to be output into an HTML attribute (alt, title, data-html, ....
getAdvancedPreviewUrl($modulepart, $relativepath, $alldata=0, $param='')
Return URL we can use for advanced preview links.
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.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
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
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,...