74 public $errors = array();
85 public $cache_types_paiements = array();
87 public $cache_conditions_paiements = array();
89 public $cache_transport_mode = array();
91 public $cache_availability = array();
93 public $cache_demand_reason = array();
95 public $cache_types_fees = array();
97 public $cache_vatrates = array();
99 public $cache_invoice_subtype = array();
101 public $cache_rule_for_lines_dates = array();
106 private $phoneInputSharedJsLoaded =
false;
131 'y' => $langs->trans(
'Years'),
132 'm' => $langs->trans(
'Month'),
133 'w' => $langs->trans(
'Weeks'),
134 'd' => $langs->trans(
'Days'),
135 'h' => $langs->trans(
'Hours'),
136 'i' => $langs->trans(
'Minutes'),
137 's' => $langs->trans(
'Seconds'),
141 "y" => $langs->trans(
"Year"),
142 "m" => $langs->trans(
"Month"),
143 "w" => $langs->trans(
"Week"),
144 "d" => $langs->trans(
"Day"),
145 "h" => $langs->trans(
"Hour"),
146 "i" => $langs->trans(
"Minute"),
147 's' => $langs->trans(
'Second'),
151 return array_reverse($arrayoftypes);
153 return $arrayoftypes;
173 public function editfieldkey($text, $htmlname, $preselected,
$object, $perm, $typeofdata =
'string', $moreparam =
'', $fieldrequired = 0, $notabletag = 0, $paramid =
'id', $help =
'')
180 if (
getDolGlobalString(
'MAIN_USE_EDIT_IN_PLACE') && !preg_match(
'/^select;/', $typeofdata)) {
182 $tmp = explode(
':', $typeofdata);
183 $ret .=
'<div class="editkey_' . $tmp[0] . (!empty($tmp[1]) ?
' ' . $tmp[1] :
'') .
'" id="' . $htmlname .
'">';
184 if ($fieldrequired) {
185 $ret .=
'<span class="fieldrequired">';
190 $ret .= $langs->trans($text);
192 if ($fieldrequired) {
195 $ret .=
'</div>' .
"\n";
197 if ($fieldrequired) {
198 $ret .=
'<span class="fieldrequired">';
203 $ret .= $langs->trans($text);
205 if ($fieldrequired) {
210 if (empty($notabletag) && $perm) {
211 $ret .=
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
213 if ($fieldrequired) {
214 $ret .=
'<span class="fieldrequired">';
219 $ret .= $langs->trans($text);
221 if ($fieldrequired) {
224 if (!empty($notabletag)) {
227 if (empty($notabletag) && $perm) {
230 if (empty($notabletag) && $perm) {
231 $ret .=
'<td class="right">';
233 if ($htmlname &&
GETPOST(
'action',
'aZ09') !=
'edit' . $htmlname && $perm && is_object(
$object)) {
234 $ret .=
'<a class="editfielda reposition" href="' .
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'action' =>
'edit' . $htmlname, $paramid =>
$object->id],
true) . $moreparam .
'">';
235 $ret .=
img_edit($langs->trans(
'Edit'), ($notabletag ? 0 : 1));
238 if (!empty($notabletag) && $notabletag == 1) {
245 if (!empty($notabletag) && $notabletag == 3) {
248 if (empty($notabletag) && $perm) {
251 if (empty($notabletag) && $perm) {
252 $ret .=
'</tr></table>';
282 public function editfieldval($text, $htmlname, $value,
$object, $perm, $typeofdata =
'string', $editvalue =
'', $extObject =
null, $custommsg =
null, $moreparam =
'', $notabletag = 1, $formatfunc =
'', $paramid =
'id', $gm =
'auto', $moreoptions = array(), $editaction =
'')
284 global
$conf, $langs;
289 if (empty($typeofdata)) {
290 return 'ErrorBadParameter typeofdata is empty';
293 if ($typeofdata ==
'datetime') {
294 $typeofdata =
'dayhour';
296 if ($typeofdata ==
'date') {
300 if (preg_match(
'/^(\w+)\((\d+)\)$/', $typeofdata, $reg)) {
301 if ($reg[1] ==
'varchar') {
302 $typeofdata =
'string';
303 } elseif ($reg[1] ==
'int') {
304 $typeofdata =
'numeric';
306 return 'ErrorBadParameter ' . $typeofdata;
311 if (
getDolGlobalString(
'MAIN_USE_EDIT_IN_PLACE') && !preg_match(
'/^select;|day|datepicker|dayhour|datehourpicker/', $typeofdata)) {
312 $ret .= $this->
editInPlace(
$object, $value, $htmlname, ($perm ? 1 : 0), $typeofdata, $editvalue, $extObject, $custommsg);
314 if ($editaction ==
'') {
315 $editaction =
GETPOST(
'action',
'aZ09');
317 $editmode = ($editaction ==
'edit' . $htmlname);
319 $ret .=
"<!-- formeditfieldval -->\n";
320 $ret .=
'<form method="post" action="' . $_SERVER[
"PHP_SELF"] . ($moreparam ?
'?' . $moreparam :
'') .
'">';
321 $ret .=
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
322 $ret .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
323 $ret .=
'<input type="hidden" name="' . $paramid .
'" value="' .
$object->id .
'">';
324 if (empty($notabletag)) {
325 $ret .=
'<table class="nobordernopadding centpercent">';
327 if (empty($notabletag)) {
330 if (preg_match(
'/^(string|safehtmlstring|email|phone|url)/', $typeofdata)) {
331 $tmp = explode(
':', $typeofdata);
332 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($editvalue ? $editvalue : $value) .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus spellcheck="false">';
333 } elseif (preg_match(
'/^(integer)/', $typeofdata)) {
334 $tmp = explode(
':', $typeofdata);
335 $valuetoshow =
price2num($editvalue ? $editvalue : $value, 0);
336 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $valuetoshow .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
337 } elseif (preg_match(
'/^(numeric|amount)/', $typeofdata)) {
338 $tmp = explode(
':', $typeofdata);
339 $valuetoshow =
price2num($editvalue ? $editvalue : $value);
340 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($valuetoshow !=
'' ?
price($valuetoshow) :
'') .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
341 } elseif (preg_match(
'/^(checkbox)/', $typeofdata)) {
342 $tmp = explode(
':', $typeofdata);
343 $ret .=
'<input type="checkbox" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($value ? $value :
'on') .
'"' . ($value ?
' checked' :
'') . (empty($tmp[1]) ?
'' : $tmp[1]) .
'/>';
344 } elseif (preg_match(
'/^text/', $typeofdata) || preg_match(
'/^note/', $typeofdata)) {
345 $tmp = explode(
':', $typeofdata);
346 $cols = (empty($tmp[2]) ?
'' : $tmp[2]);
348 if (preg_match(
'/%/', $cols)) {
349 $morealt =
' style="width: ' . $cols .
'"';
352 $valuetoshow = ($editvalue ? $editvalue : $value);
353 $ret .=
'<textarea id="' . $htmlname .
'" name="' . $htmlname .
'" wrap="soft" rows="' . (empty($tmp[1]) ?
'20' : $tmp[1]) .
'"' . ($cols ?
' cols="' . $cols .
'"' :
'class="quatrevingtpercent"') . $morealt .
'" autofocus>';
356 $valuetoshow = str_replace(
'&',
'&', $valuetoshow);
358 $ret .=
'</textarea><div class="clearboth"></div>';
359 } elseif ($typeofdata ==
'day' || $typeofdata ==
'datepicker') {
360 $addnowlink = empty($moreoptions[
'addnowlink']) ? 0 : $moreoptions[
'addnowlink'];
361 $adddateof = empty($moreoptions[
'adddateof']) ?
'' : $moreoptions[
'adddateof'];
362 $labeladddateof = empty($moreoptions[
'labeladddateof']) ?
'' : $moreoptions[
'labeladddateof'];
363 $ret .= $this->
selectDate($value, $htmlname, 0, 0, 1,
'form' . $htmlname, 1, $addnowlink, 0,
'',
'', $adddateof,
'', 1, $labeladddateof,
'', $gm);
364 } elseif ($typeofdata ==
'dayhour' || $typeofdata ==
'datehourpicker') {
365 $addnowlink = empty($moreoptions[
'addnowlink']) ? 0 : $moreoptions[
'addnowlink'];
366 $adddateof = empty($moreoptions[
'adddateof']) ?
'' : $moreoptions[
'adddateof'];
367 $labeladddateof = empty($moreoptions[
'labeladddateof']) ?
'' : $moreoptions[
'labeladddateof'];
368 $ret .= $this->
selectDate($value, $htmlname, 1, 1, 1,
'form' . $htmlname, 1, $addnowlink, 0,
'',
'', $adddateof,
'', 1, $labeladddateof,
'', $gm);
369 } elseif (preg_match(
'/^select;/', $typeofdata)) {
370 $arraydata = explode(
',', preg_replace(
'/^select;/',
'', $typeofdata));
371 $arraylist = array();
372 foreach ($arraydata as $val) {
373 $tmp = explode(
':', $val);
374 $tmpkey = str_replace(
'|',
':', $tmp[0]);
375 $arraylist[$tmpkey] = $tmp[1];
377 $ret .= $this->
selectarray($htmlname, $arraylist, $value);
378 } elseif (preg_match(
'/^link/', $typeofdata)) {
380 } elseif (preg_match(
'/^ckeditor/', $typeofdata)) {
381 $tmp = explode(
':', $typeofdata);
382 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
383 $doleditor =
new DolEditor($htmlname, ($editvalue ? $editvalue : $value), (empty($tmp[2]) ?
'' : $tmp[2]), (empty($tmp[3]) ? 100 : (int) $tmp[3]), (empty($tmp[1]) ?
'dolibarr_notes' : $tmp[1]),
'In', (empty($tmp[5]) ? false : (bool) $tmp[5]), (isset($tmp[8]) ? ($tmp[8] ? true :
false) :
true),
true, (empty($tmp[6]) ? 20 : (int) $tmp[6]), (empty($tmp[7]) ?
'100' : $tmp[7]));
384 $ret .= $doleditor->Create(1);
385 } elseif ($typeofdata ==
'asis') {
386 $ret .= ($editvalue ? $editvalue : $value);
388 if (empty($notabletag)) {
393 if (empty($notabletag)) {
397 $ret .=
'<input type="submit" class="smallpaddingimp nomargingtop nomarginbottom button' . (empty($notabletag) ?
'' :
' ') .
'" name="modify" value="' . $langs->trans(
"Save") .
'">';
398 if (preg_match(
'/ckeditor|textarea/', $typeofdata) && empty($notabletag)) {
399 $ret .=
'<br>' .
"\n";
401 $ret .=
'<input type="submit" class="smallpaddingimp nomargingtop nomarginbottom button button-cancel' . (empty($notabletag) ?
'' :
' ') .
'" name="cancel" value="' . $langs->trans(
"Cancel") .
'">';
402 if (empty($notabletag)) {
406 if (empty($notabletag)) {
407 $ret .=
'</tr></table>' .
"\n";
409 $ret .=
'</form>' .
"\n";
411 if (preg_match(
'/^email/', $typeofdata)) {
413 } elseif (preg_match(
'/^phone/', $typeofdata)) {
415 } elseif (preg_match(
'/^url/', $typeofdata)) {
417 } elseif (preg_match(
'/^(amount|numeric)/', $typeofdata)) {
418 $ret .= ($value !=
'' ?
price($value, 0, $langs, 0, -1, -1,
$conf->currency) :
'');
419 } elseif (preg_match(
'/^checkbox/', $typeofdata)) {
420 $tmp = explode(
':', $typeofdata);
421 $ret .=
'<input type="checkbox" disabled id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $value .
'"' . ($value ?
' checked' :
'') . ($tmp[1] ? $tmp[1] :
'') .
'/>';
422 } elseif (preg_match(
'/^text/', $typeofdata) || preg_match(
'/^note/', $typeofdata)) {
424 } elseif (preg_match(
'/^(safehtmlstring|restricthtml)/', $typeofdata)) {
426 } elseif ($typeofdata ==
'day' || $typeofdata ==
'datepicker') {
427 $ret .=
'<span class="valuedate">' .
dol_print_date($value,
'day', $gm) .
'</span>';
428 } elseif ($typeofdata ==
'dayhour' || $typeofdata ==
'datehourpicker') {
429 $ret .=
'<span class="valuedate">' .
dol_print_date($value,
'dayhour', $gm) .
'</span>';
430 } elseif (preg_match(
'/^select;/', $typeofdata)) {
431 $arraydata = explode(
',', preg_replace(
'/^select;/',
'', $typeofdata));
432 $arraylist = array();
433 foreach ($arraydata as $val) {
434 $tmp = explode(
':', $val);
435 $arraylist[$tmp[0]] = $tmp[1];
437 $ret .= $arraylist[$value];
438 if ($htmlname ==
'fk_product_type') {
440 $ret =
img_picto($langs->trans(
"Product"),
'product',
'class="paddingleftonly paddingrightonly colorgrey"') . $ret;
442 $ret =
img_picto($langs->trans(
"Service"),
'service',
'class="paddingleftonly paddingrightonly colorgrey"') . $ret;
445 } elseif (preg_match(
'/^ckeditor/', $typeofdata)) {
448 $firstline = preg_replace(
'/<br>.*/',
'', $tmpcontent);
449 $firstline = preg_replace(
'/[\n\r].*/',
'', $firstline);
450 $tmpcontent = $firstline . ((strlen($firstline) != strlen($tmpcontent)) ?
'...' :
'');
456 if (empty($moreoptions[
'valuealreadyhtmlescaped'])) {
464 if ($formatfunc && method_exists(
$object, $formatfunc)) {
465 $ret =
$object->$formatfunc($ret);
485 global
$conf, $langs, $extralanguages;
490 $arrayoflangcode = array();
495 if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
496 if (!is_object($extralanguages)) {
497 include_once DOL_DOCUMENT_ROOT .
'/core/class/extralanguages.class.php';
500 $extralanguages->fetch_name_extralanguages(
'societe');
505 if (empty($extralanguages->attributes[
$object->element]) || !is_array($extralanguages->attributes[
$object->element]) || empty($extralanguages->attributes[
$object->element][$fieldname])) {
509 $result .=
'<!-- Widget for translation -->' .
"\n";
510 $result .=
'<div class="inline-block paddingleft image-' .
$object->element .
'-' . $fieldname .
'">';
511 $s =
img_picto($langs->trans(
"ShowOtherLanguages"),
'language',
'', 0, 0, 0,
'',
'fa-15 editfieldlang');
515 $result .=
'<div class="inline-block hidden field-' .
$object->element .
'-' . $fieldname .
'">';
517 $resultforextrlang =
'';
518 foreach ($arrayoflangcode as $langcode) {
519 $valuetoshow =
GETPOSTISSET(
'field-' .
$object->element .
"-" . $fieldname .
"-" . $langcode) ?
GETPOST(
'field-' .
$object->element .
'-' . $fieldname .
"-" . $langcode, $check) :
'';
520 if (empty($valuetoshow)) {
521 $object->fetchValuesForExtraLanguages();
523 $valuetoshow =
$object->array_languages[$fieldname][$langcode];
527 $resultforextrlang .= $s;
530 if ($typeofdata ==
'textarea') {
531 $resultforextrlang .=
'<textarea name="field-' .
$object->element .
"-" . $fieldname .
"-" . $langcode .
'" id="' . $fieldname .
"-" . $langcode .
'" class="' . $morecss .
'" rows="' . ROWS_2 .
'" wrap="soft">';
532 $resultforextrlang .= $valuetoshow;
533 $resultforextrlang .=
'</textarea>';
535 $resultforextrlang .=
'<input type="text" class="inputfieldforlang ' . ($morecss ?
' ' . $morecss :
'') .
'" name="field-' .
$object->element .
'-' . $fieldname .
'-' . $langcode .
'" value="' . $valuetoshow .
'">';
538 $result .= $resultforextrlang;
541 $result .=
'<script nonce="' .
getNonce() .
'">$(".image-' .
$object->element .
'-' . $fieldname .
'").click(function() { console.log("Toggle lang widget"); jQuery(".field-' .
$object->element .
'-' . $fieldname .
'").toggle(); });</script>';
560 protected function editInPlace(
$object, $value, $htmlname, $condition, $inputType =
'textarea', $editvalue =
null, $extObject =
null, $custommsg =
null)
565 if (preg_match(
'/^text/', $inputType)) {
567 } elseif (preg_match(
'/^numeric/', $inputType)) {
568 $value =
price($value);
569 } elseif ($inputType ==
'day' || $inputType ==
'datepicker') {
575 $table_element =
false;
579 $ext_element =
false;
580 $button_only =
false;
587 $table_element =
$object->table_element;
591 if (is_object($extObject)) {
592 $ext_element = $extObject->element;
595 if (preg_match(
'/^(string|email|numeric)/', $inputType)) {
596 $tmp = explode(
':', $inputType);
597 $inputType = $tmp[0];
598 if (!empty($tmp[1])) {
599 $inputOption = $tmp[1];
601 if (!empty($tmp[2])) {
602 $savemethod = $tmp[2];
604 $out .=
'<input id="width_' . $htmlname .
'" value="' . $inputOption .
'" type="hidden"/>' .
"\n";
605 } elseif ((preg_match(
'/^day$/', $inputType)) || (preg_match(
'/^datepicker/', $inputType)) || (preg_match(
'/^datehourpicker/', $inputType))) {
606 $tmp = explode(
':', $inputType);
607 $inputType = $tmp[0];
608 if (!empty($tmp[1])) {
609 $inputOption = $tmp[1];
611 if (!empty($tmp[2])) {
612 $savemethod = $tmp[2];
615 $out .=
'<input id="timestamp" type="hidden"/>' .
"\n";
616 } elseif (preg_match(
'/^(select|autocomplete)/', $inputType)) {
617 $tmp = explode(
':', $inputType);
618 $inputType = $tmp[0];
619 $loadmethod = $tmp[1];
620 if (!empty($tmp[2])) {
621 $savemethod = $tmp[2];
623 if (!empty($tmp[3])) {
626 } elseif (preg_match(
'/^textarea/', $inputType)) {
627 $tmp = explode(
':', $inputType);
628 $inputType = $tmp[0];
629 $rows = (empty($tmp[1]) ?
'8' : $tmp[1]);
630 $cols = (empty($tmp[2]) ?
'80' : $tmp[2]);
631 } elseif (preg_match(
'/^ckeditor/', $inputType)) {
632 $tmp = explode(
':', $inputType);
633 $inputType = $tmp[0];
635 if (!empty($tmp[2])) {
638 if (!empty($tmp[3])) {
641 if (!empty($tmp[4])) {
642 $savemethod = $tmp[4];
646 $out .=
'<input id="ckeditor_toolbar" value="' . $toolbar .
'" type="hidden"/>' .
"\n";
648 $inputType =
'textarea';
652 $out .=
'<input id="element_' . $htmlname .
'" value="' . $element .
'" type="hidden"/>' .
"\n";
653 $out .=
'<input id="table_element_' . $htmlname .
'" value="' . $table_element .
'" type="hidden"/>' .
"\n";
654 $out .=
'<input id="fk_element_' . $htmlname .
'" value="' . $fk_element .
'" type="hidden"/>' .
"\n";
655 $out .=
'<input id="loadmethod_' . $htmlname .
'" value="' . $loadmethod .
'" type="hidden"/>' .
"\n";
656 if (!empty($savemethod)) {
657 $out .=
'<input id="savemethod_' . $htmlname .
'" value="' . $savemethod .
'" type="hidden"/>' .
"\n";
659 if (!empty($ext_element)) {
660 $out .=
'<input id="ext_element_' . $htmlname .
'" value="' . $ext_element .
'" type="hidden"/>' .
"\n";
662 if (!empty($custommsg)) {
663 if (is_array($custommsg)) {
664 if (!empty($custommsg[
'success'])) {
665 $out .=
'<input id="successmsg_' . $htmlname .
'" value="' . $custommsg[
'success'] .
'" type="hidden"/>' .
"\n";
667 if (!empty($custommsg[
'error'])) {
668 $out .=
'<input id="errormsg_' . $htmlname .
'" value="' . $custommsg[
'error'] .
'" type="hidden"/>' .
"\n";
671 $out .=
'<input id="successmsg_' . $htmlname .
'" value="' . $custommsg .
'" type="hidden"/>' .
"\n";
674 if ($inputType ==
'textarea') {
675 $out .=
'<input id="textarea_' . $htmlname .
'_rows" value="' . $rows .
'" type="hidden"/>' .
"\n";
676 $out .=
'<input id="textarea_' . $htmlname .
'_cols" value="' . $cols .
'" type="hidden"/>' .
"\n";
678 $out .=
'<span id="viewval_' . $htmlname .
'" class="viewval_' . $inputType . ($button_only ?
' inactive' :
' active') .
'">' . $value .
'</span>' .
"\n";
679 $out .=
'<span id="editval_' . $htmlname .
'" class="editval_' . $inputType . ($button_only ?
' inactive' :
' active') .
' hideobject">' . (!empty($editvalue) ? $editvalue : $value) .
'</span>' .
"\n";
705 public function textwithtooltip($text, $htmltext, $tooltipon = 1, $direction = 0, $img =
'', $extracss =
'', $notabs = 3, $incbefore =
'', $noencodehtmltext = 0, $tooltiptrigger =
'', $forcenowrap = 0)
708 $text = $incbefore . $text;
713 $direction = (int) $direction;
723 $htmltext = str_replace(array(
"\r",
"\n"),
'', $htmltext);
726 if ($direction < 0) {
727 $extracss = ($extracss ? $extracss :
'') . ($notabs != 3 ?
' inline-block' :
'');
728 $extrastyle =
'padding: 0px; padding-left: 2px;';
730 if ($direction > 0) {
731 $extracss = ($extracss ? $extracss :
'') . ($notabs != 3 ?
' inline-block' :
'');
732 $extrastyle =
'padding: 0px; padding-right: 2px;';
735 $classfortooltip =
'classfortooltip';
740 if ($tooltiptrigger ==
'') {
741 $htmltext = str_replace(
'"',
'"', $htmltext);
743 $classfortooltip =
'classfortooltiponclick';
744 $textfordialog .=
'<div style="display: none;" id="idfortooltiponclick_' . $tooltiptrigger .
'" class="classfortooltiponclicktext"';
748 $textfordialog .=
' title="'.$langs->trans(
"Note").
'"';
750 $textfordialog .=
'>' . $htmltext .
'</div>';
752 if ($tooltipon == 2 || $tooltipon == 3) {
753 $paramfortooltipimg =
' class="' . $classfortooltip . ($notabs != 3 ?
' inline-block' :
'') . ($extracss ?
' ' . $extracss :
'') .
'" style="padding: 0px;' . ($extrastyle ?
' ' . $extrastyle :
'') .
'"';
754 if ($tooltiptrigger ==
'') {
755 $paramfortooltipimg .=
' title="' . ($noencodehtmltext ? $htmltext :
dol_escape_htmltag($htmltext, 1, 0,
'span', 0, 1)) .
'"';
757 $paramfortooltipimg .=
' dolid="' . $tooltiptrigger .
'"';
760 $paramfortooltipimg = ($extracss ?
' class="' . $extracss .
'"' :
'') . ($extrastyle ?
' style="' . $extrastyle .
'"' :
'');
762 if ($tooltipon == 1 || $tooltipon == 3) {
763 $paramfortooltiptd =
' class="' . ($tooltipon == 3 ?
'cursorpointer ' :
'') . $classfortooltip . ($tag !=
'td' ?
' inline-block' :
'') . ($extracss ?
' ' . $extracss :
'') .
'" style="padding: 0px;' . ($extrastyle ?
' ' . $extrastyle :
'') .
'" ';
764 if ($tooltiptrigger ==
'') {
765 $paramfortooltiptd .=
' title="' . ($noencodehtmltext ? $htmltext :
dol_escape_htmltag($htmltext, 1, 0,
'span', 0, 1)) .
'"';
767 $paramfortooltiptd .=
' dolid="' . $tooltiptrigger .
'"';
770 $paramfortooltiptd = ($extracss ?
' class="' . $extracss .
'"' :
'') . ($extrastyle ?
' style="' . $extrastyle .
'"' :
'');
772 if (empty($notabs)) {
773 $s .=
'<table class="nobordernopadding"><tr style="height: auto;">';
774 } elseif ($notabs == 2) {
775 $s .=
'<div class="inline-block' . ($forcenowrap ?
' nowrap' :
'') .
'">';
778 if ($direction < 0) {
779 $s .=
'<' . $tag . $paramfortooltipimg;
781 $s .=
' class="valigntop" width="14"';
783 $s .=
'>' . $textfordialog . $img .
'</' . $tag .
'>';
787 if ((
string) $text !=
'') {
788 $s .=
'<' . $tag . $paramfortooltiptd .
'>' . $text .
'</' . $tag .
'>';
791 if ($direction > 0) {
792 $s .=
'<' . $tag . $paramfortooltipimg;
794 $s .=
' class="valignmiddle" width="14"';
796 $s .=
'>' . $textfordialog . $img .
'</' . $tag .
'>';
798 if (empty($notabs)) {
799 $s .=
'</tr></table>';
800 } elseif ($notabs == 2) {
821 public function textwithpicto($text, $htmltooltip, $direction = 1, $type =
'help', $extracss =
'valignmiddle', $noencodehtmltext = 0, $notabs = 3, $tooltiptrigger =
'', $forcenowrap = 0)
823 global
$conf, $langs;
828 } elseif ($type ==
'1') {
832 $tooltiptrigger = preg_replace(
'/[^a-z0-9]/i',
'', $tooltiptrigger);
834 if (preg_match(
'/onsmartphone$/', $tooltiptrigger) && empty(
$conf->dol_no_mouse_hover)) {
835 $tooltiptrigger = preg_replace(
'/^.*onsmartphone$/',
'', $tooltiptrigger);
838 if ($tooltiptrigger) {
839 $alt = $langs->transnoentitiesnoconv(
"ClickToShowHelp");
843 if (empty(
$conf->use_javascript_ajax)) {
844 if ($type ==
'info' || $type ==
'infoclickable' || $type ==
'help' || $type ==
'helpclickable') {
853 if (!empty(
$conf->dol_no_mouse_hover) && empty($tooltiptrigger)) {
854 if ($type ==
'info' || $type ==
'infoclickable' || $type ==
'help' || $type ==
'helpclickable') {
865 if ($type ==
'info') {
866 $img =
img_help(($tooltiptrigger !=
'' ? 2 : 0), $alt);
867 } elseif ($type ==
'help') {
868 $img =
img_help(($tooltiptrigger !=
'' ? 2 : 1), $alt);
869 } elseif ($type ==
'helpclickable') {
870 $img =
img_help(($tooltiptrigger !=
'' ? 2 : 1), $alt);
871 } elseif ($type ==
'warning') {
873 } elseif ($type !=
'none') {
878 $tooltipon = ((($tooltiptrigger && !$img) || strpos($type,
'clickable')) ? 3 : 2);
880 return $this->
textwithtooltip($text, $htmltooltip, $tooltipon, $direction, $img, $extracss, $notabs,
'', $noencodehtmltext, $tooltiptrigger, $forcenowrap);
893 public function selectMassAction($selected, $arrayofaction, $alwaysvisible = 0, $name =
'massaction', $cssclass =
'checkforselect')
895 global
$conf, $langs, $hookmanager;
898 $ret =
'<div class="centpercent center">';
899 $ret .=
'<select class="flat' . (empty(
$conf->use_javascript_ajax) ?
'' :
' hideobject') .
' ' . $name .
' ' . $name .
'select valignmiddle alignstart" id="' . $name .
'" name="' . $name .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
'>';
902 $parameters = array();
903 $reshook = $hookmanager->executeHooks(
'addMoreMassActions', $parameters);
906 if (is_array($arrayofaction) && count($arrayofaction) == 0 && empty($hookmanager->resPrint)) {
909 if (empty($reshook)) {
910 $ret .=
'<option value="0"' . ($disabled ?
' disabled="disabled"' :
'') .
'>-- ' . $langs->trans(
"SelectAction") .
' --</option>';
911 if (is_array($arrayofaction)) {
912 foreach ($arrayofaction as $code => $label) {
913 $ret .=
'<option value="' . $code .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' data-html="' .
dol_escape_htmltag($label) .
'">' . $label .
'</option>';
917 $ret .= $hookmanager->resPrint;
921 if (empty(
$conf->dol_optimize_smallscreen)) {
926 $ret .=
'<input type="submit" name="confirmmassactioninvisible" style="display: none" tabindex="-1">';
927 $ret .=
'<input type="submit" disabled name="confirmmassaction"' . (empty(
$conf->use_javascript_ajax) ?
'' :
' style="display: none"') .
' class="reposition button smallpaddingimp' . (empty(
$conf->use_javascript_ajax) ?
'' :
' hideobject') .
' ' . $name .
' ' . $name .
'confirmed" value="' .
dol_escape_htmltag($langs->trans(
"Confirm")) .
'">';
930 if (!empty(
$conf->use_javascript_ajax)) {
931 $ret .=
'<!-- JS CODE TO ENABLE mass action select -->
933 function initCheckForSelect(mode, name, cssclass) { /* mode is 0 during init of page or click all, 1 when we click on 1 checkboxi, "name" refers to the class of the massaction button, "cssclass" to the class of the check for select boxes */
934 atleastoneselected=0;
935 jQuery("."+cssclass).each(function( index ) {
936 /* console.log( index + ": " + $( this ).text() ); */
937 if ($(this).is(\':checked\')) atleastoneselected++;
940 console.log("initCheckForSelect mode="+mode+" name="+name+" cssclass="+cssclass+" atleastoneselected="+atleastoneselected);
942 if (atleastoneselected || ' . ((int) $alwaysvisible) .
') {
943 jQuery("."+name).show();
944 ' . ($selected ?
'if (atleastoneselected) { jQuery("."+name+"select").val("' . $selected .
'").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', false); }' :
'') .
'
945 ' . ($selected ?
'if (! atleastoneselected) { jQuery("."+name+"select").val("0").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', true); } ' :
'') .
'
947 jQuery("."+name).hide();
948 jQuery("."+name+"other").hide();
952 jQuery(document).ready(function () {
953 initCheckForSelect(0, "' . $name .
'", "' . $cssclass .
'");
954 jQuery(".' . $cssclass .
'").change(function() {
955 console.log("A change was done on .' . $cssclass .
'");
956 initCheckForSelect(1, "' . $name .
'", "' . $cssclass .
'");
958 jQuery(".' . $name .
'select").change(function() {
959 var massaction = $( this ).val();
960 var urlform = $( this ).closest("form").attr("action").replace("#show_files","");
961 if (massaction == "builddoc") {
962 urlform = urlform + "#show_files";
964 $( this ).closest("form").attr("action", urlform);
965 console.log("we select a mass action name=' . $name .
' massaction="+massaction+" - "+urlform);
966 /* Warning: if you set submit button to disabled, post using Enter will no more work if there is no other button */
967 if ($(this).val() != \'0\') {
968 jQuery(".' . $name .
'confirmed").prop(\'disabled\', false);
969 jQuery(".' . $name .
'other").hide(); /* To disable if another div was open */
970 jQuery(".' . $name .
'"+massaction).show();
972 jQuery(".' . $name .
'confirmed").prop(\'disabled\', true);
973 jQuery(".' . $name .
'other").hide(); /* To disable any div open */
1003 public function select_country($selected =
'', $htmlname =
'country_id', $htmloption =
'', $maxlength = 0, $morecss =
'minwidth300', $usecodeaskey =
'', $showempty = 1, $disablefavorites = 0, $addspecialentries = 0, $exclude_country_code = array(), $hideflags = 0, $forcecombo = 0)
1008 $langs->load(
"dict");
1010 $selected = (
string) $selected;
1014 $countryArray = array();
1015 $favorite = array();
1017 $atleastonefavorite = 0;
1019 $sql =
"SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite, eec";
1020 $sql .=
" FROM " . $this->db->prefix() .
"c_country";
1021 $sql .=
" WHERE active > 0";
1024 dol_syslog(get_class($this) .
"::select_country", LOG_DEBUG);
1026 $resql = $this->db->query($sql);
1028 $out .=
'<select id="select' . $htmlname .
'" class="flat maxwidth200onsmartphone selectcountry' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" ' . $htmloption .
'>';
1029 $num = $this->db->num_rows($resql);
1033 $obj = $this->db->fetch_object($resql);
1037 'rowid' => (
int) $obj->rowid,
1038 'code_iso' => (
string) $obj->code_iso,
1039 'code_iso3' => (
string) $obj->code_iso3,
1040 'label' => (
string) ($obj->code_iso && $langs->transnoentitiesnoconv(
"Country" . $obj->code_iso) !=
"Country" . $obj->code_iso ? $langs->transnoentitiesnoconv(
"Country" . $obj->code_iso) : ($obj->label !=
'-' ? $obj->label :
'')),
1041 'favorite' => (
string) $obj->favorite,
1042 'eec' => (
string) $obj->eec,
1044 $favorite[$i] = $obj->favorite;
1049 if (empty($disablefavorites)) {
1050 $array1_sort_order = SORT_DESC;
1051 $array2_sort_order = SORT_ASC;
1052 array_multisort($favorite, $array1_sort_order, $label, $array2_sort_order, $countryArray);
1058 if (is_numeric($showempty)) {
1059 $out .=
'<option value=""> </option>' .
"\n";
1061 $out .=
'<option value="-1">' . $langs->trans($showempty) .
'</option>' .
"\n";
1065 if ($addspecialentries) {
1067 $out .=
'<option value="special_allnotme"' . ($selected ==
'special_allnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesExceptMe", $langs->transnoentitiesnoconv(
"Country" .
$mysoc->country_code)) .
'</option>';
1068 $out .=
'<option value="special_eec"' . ($selected ==
'special_eec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEEC") .
'</option>';
1070 $out .=
'<option value="special_eecnotme"' . ($selected ==
'special_eecnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEECExceptMe", $langs->transnoentitiesnoconv(
"Country" .
$mysoc->country_code)) .
'</option>';
1072 $out .=
'<option value="special_noteec"' . ($selected ==
'special_noteec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesNotInEEC") .
'</option>';
1073 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1076 foreach ($countryArray as $row) {
1078 if (empty($row[
'rowid'])) {
1081 if (is_array($exclude_country_code) && count($exclude_country_code) && in_array($row[
'code_iso'], $exclude_country_code)) {
1085 if (empty($disablefavorites) && $row[
'favorite'] && $row[
'code_iso']) {
1086 $atleastonefavorite++;
1088 if (empty($row[
'favorite']) && $atleastonefavorite) {
1089 $atleastonefavorite = 0;
1090 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1094 if ($row[
'label']) {
1095 $labeltoshow .=
dol_trunc($row[
'label'], $maxlength,
'middle');
1097 $labeltoshow .=
' ';
1099 if ($row[
'code_iso']) {
1100 $labeltoshow .=
' <span class="opacitymedium">(' . $row[
'code_iso'] .
')</span>';
1101 if (empty($hideflags)) {
1102 $tmpflag =
picto_from_langcode($row[
'code_iso'],
'class="saturatemedium paddingrightonly"', 1);
1103 $labeltoshow = $tmpflag .
' ' . $labeltoshow;
1107 if ($selected && $selected !=
'-1' && ($selected == $row[
'rowid'] || $selected == $row[
'code_iso'] || $selected == $row[
'code_iso3'] || $selected == $row[
'label'])) {
1108 $out .=
'<option value="' . ($usecodeaskey ? ($usecodeaskey ==
'code2' ? $row[
'code_iso'] : $row[
'code_iso3']) : $row[
'rowid']) .
'" selected data-html="' .
dol_escape_htmltag($labeltoshow) .
'" data-eec="' . ((int) $row[
'eec']) .
'">';
1110 $out .=
'<option value="' . ($usecodeaskey ? ($usecodeaskey ==
'code2' ? $row[
'code_iso'] : $row[
'code_iso3']) : $row[
'rowid']) .
'" data-html="' .
dol_escape_htmltag($labeltoshow) .
'" data-eec="' . ((int) $row[
'eec']) .
'">';
1113 $out .=
'</option>' .
"\n";
1116 $out .=
'</select>';
1122 if (empty($forcecombo)) {
1123 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1124 $out .=
ajax_combobox(
'select' . $htmlname, array(), 0, 0,
'resolve');
1140 public function selectPhoneCode($selected =
'', $htmlname =
'phone_code', $morecss =
'maxwidth150', $showempty = 0, $country_id_hint = 0)
1144 $langs->load(
"dict");
1147 $codeArray = array();
1148 $favorite = array();
1150 $atleastonefavorite = 0;
1152 $sql =
"SELECT rowid, code, label, phone_code, favorite, trunk_prefix";
1153 $sql .=
" FROM ".$this->db->prefix().
"c_country";
1155 $sql .=
" WHERE active > 0 AND phone_code IS NOT NULL AND phone_code != 0";
1157 dol_syslog(get_class($this).
"::selectPhoneCode", LOG_DEBUG);
1158 $resql = $this->db->query($sql);
1160 $num = $this->db->num_rows($resql);
1163 $obj = $this->db->fetch_object($resql);
1165 $translabel = ($obj->code && $langs->transnoentitiesnoconv(
"Country".$obj->code) !=
"Country".$obj->code) ? $langs->transnoentitiesnoconv(
"Country".$obj->code) : $obj->label;
1167 $codeArray[$i][
'rowid'] = $obj->rowid;
1168 $codeArray[$i][
'code'] = $obj->code;
1169 $codeArray[$i][
'label'] = $translabel;
1170 $codeArray[$i][
'phone_code'] =
'+'.$obj->phone_code;
1171 $codeArray[$i][
'favorite'] = $obj->favorite;
1172 $codeArray[$i][
'trunk_prefix'] = $obj->trunk_prefix;
1173 $favorite[$i] = $obj->favorite;
1178 $array1_sort_order = SORT_DESC;
1179 $array2_sort_order = SORT_ASC;
1180 array_multisort($favorite, $array1_sort_order, $label, $array2_sort_order, $codeArray);
1182 $out .=
'<select id="select'.$htmlname.
'" class="flat selectphonecode'.($morecss ?
' '.$morecss :
'').
'" name="'.$htmlname.
'">';
1185 $out .=
'<option value=""> </option>'.
"\n";
1190 $firstMatchIdx = -1;
1191 if ($selected !==
'') {
1192 foreach ($codeArray as $idx => $row) {
1193 if ($row[
'phone_code'] == $selected) {
1194 if ($firstMatchIdx < 0) {
1195 $firstMatchIdx = $idx;
1197 if ($country_id_hint > 0 && $row[
'rowid'] == $country_id_hint) {
1198 $selectedIdx = $idx;
1203 if ($selectedIdx < 0 && $firstMatchIdx >= 0) {
1204 $selectedIdx = $firstMatchIdx;
1208 foreach ($codeArray as $idx => $row) {
1209 if (empty($row[
'code'])) {
1213 if ($row[
'favorite']) {
1214 $atleastonefavorite++;
1216 if (empty($row[
'favorite']) && $atleastonefavorite) {
1217 $atleastonefavorite = 0;
1218 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1221 $tmpflag =
picto_from_langcode($row[
'code'],
'class="saturatemedium paddingrightonly"', 1);
1224 $selectlabel = ($tmpflag ? $tmpflag.
' ' :
'').$row[
'code'];
1227 $labeltoshow = ($tmpflag ? $tmpflag.
' ' :
'').$row[
'label'].
' '.$row[
'phone_code'];
1229 $out .=
'<option value="'.dol_escape_htmltag($row[
'phone_code']).
'"';
1230 if ($idx === $selectedIdx) {
1231 $out .=
' selected';
1233 $out .=
' data-html="'.dol_escape_htmltag($labeltoshow).
'"';
1234 $out .=
' data-select-html="'.dol_escape_htmltag($selectlabel).
'"';
1235 $out .=
' data-country-id="'.((int) $row[
'rowid']).
'"';
1236 $out .=
' data-trunk-prefix="'.dol_escape_htmltag((
string) $row[
'trunk_prefix']).
'"';
1239 $out .=
'</option>'.
"\n";
1241 $out .=
'</select>';
1247 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1248 $out .=
ajax_combobox(
'select'.$htmlname, array(), 0, 0,
'resolve');
1269 public function showPhoneInput($phoneValue, $htmlname, $country_id_hint = 0, $picto =
'object_phoning', $morecss =
'maxwidth150', $maxlength = 0, $countrySelectorId =
'selectcountry_id')
1273 include_once DOL_DOCUMENT_ROOT.
'/core/lib/phone.lib.php';
1275 $codename = $htmlname.
'_code';
1278 if (empty($country_id_hint) && !empty(
$mysoc->country_id)) {
1279 $country_id_hint =
$mysoc->country_id;
1286 $fullPhone = (
string) $phoneValue;
1295 $selectedCode = $phonecode;
1296 $numberValue = $parsed[
'number'];
1300 if ($numberValue !==
'' && $selectedCode !==
'' && strpos($numberValue,
'+') !== 0) {
1302 if ($trunkPrefix !==
'' && strpos($numberValue, $trunkPrefix) !== 0) {
1303 $numberValue = $trunkPrefix.$numberValue;
1308 $numberValue = preg_replace(
'/[^0-9]/',
'', $numberValue);
1314 $out .=
img_picto(
'', $picto,
'class="pictofixedwidth"');
1317 $out .= $this->
selectPhoneCode($selectedCode, $codename,
'maxwidth75 phone_code_select', 0, $country_id_hint);
1320 $out .=
'<input type="tel" inputmode="numeric" pattern="[0-9]*" id="'.dol_escape_htmltag($htmlname).
'_input" class="'.
dol_escape_htmltag($morecss).
'"';
1321 if ($maxlength > 0) {
1322 $out .=
' maxlength="'.$maxlength.
'"';
1324 $out .=
' value="'.dol_escape_htmltag($numberValue).
'">';
1349 $selectId =
'select'.dol_escape_js($codename);
1351 $out =
"\n".
'<script type="text/javascript">'.
"\n";
1352 $out .=
'jQuery(document).ready(function() {'.
"\n";
1353 $out .=
' function syncPhoneField_'.$hiddenId.
'() {'.
"\n";
1354 $out .=
' var selectEl = jQuery("#'.$selectId.
'");'.
"\n";
1355 $out .=
' var code = selectEl.val() || "";'.
"\n";
1356 $out .=
' var number = (jQuery("#'.$inputId.
'").val() || "").replace(/[^0-9]/g, "");'.
"\n";
1357 $out .=
' if (code && number) {'.
"\n";
1358 $out .=
' var selOpt = selectEl[0] && selectEl[0].selectedOptions && selectEl[0].selectedOptions[0];'.
"\n";
1359 $out .=
' var trunkPrefix = selOpt ? (selOpt.getAttribute("data-trunk-prefix") || "") : "";'.
"\n";
1360 $out .=
' if (trunkPrefix !== "" && number.indexOf(trunkPrefix) === 0) {'.
"\n";
1361 $out .=
' number = number.substring(trunkPrefix.length);'.
"\n";
1363 $out .=
' jQuery("#'.$hiddenId.
'").val(code + " " + number);'.
"\n";
1364 $out .=
' } else if (number) {'.
"\n";
1365 $out .=
' jQuery("#'.$hiddenId.
'").val(number);'.
"\n";
1366 $out .=
' } else {'.
"\n";
1367 $out .=
' jQuery("#'.$hiddenId.
'").val("");'.
"\n";
1370 $out .=
' jQuery("#'.$selectId.
'").on("change", function() { syncPhoneField_'.$hiddenId.
'(); });'.
"\n";
1371 $out .=
' jQuery("#'.$inputId.
'").on("input change", function() { syncPhoneField_'.$hiddenId.
'(); });'.
"\n";
1373 $out .=
'</script>'.
"\n";
1389 if ($this->phoneInputSharedJsLoaded) {
1392 $this->phoneInputSharedJsLoaded =
true;
1394 $out =
"\n".
'<script type="text/javascript">'.
"\n";
1395 $out .=
'jQuery(document).ready(function() {'.
"\n";
1396 $out .=
' jQuery("#'.dol_escape_js($countrySelectorId).
'").on("change", function() {'.
"\n";
1397 $out .=
' var country_id = jQuery(this).val();'.
"\n";
1398 $out .=
' if (country_id) {'.
"\n";
1399 $out .=
' jQuery.getJSON("'.DOL_URL_ROOT.
'/core/ajax/getphonecode.php", {country_id: country_id, token: "'.
currentToken().
'"}, function(data) {'.
"\n";
1400 $out .=
' if (data.phone_code) {'.
"\n";
1401 $out .=
' jQuery(".phone_code_select").each(function() {'.
"\n";
1402 $out .=
' jQuery(this).val(data.phone_code).trigger("change");'.
"\n";
1403 $out .=
' });'.
"\n";
1405 $out .=
' });'.
"\n";
1407 $out .=
' });'.
"\n";
1409 $out .=
'</script>'.
"\n";
1430 global $langs, $form;
1432 $form =
new Form($this->db);
1434 $htmltoenteralink =
'';
1438 $htmltoenteralink .=
'<tr class="liste_titre">';
1439 $htmltoenteralink .=
'<td class="nowrap"></td>';
1440 $htmltoenteralink .=
'<td>' . $langs->trans(
"Ref") .
'</td>';
1441 $htmltoenteralink .=
'<td>' . $langs->trans(
"RefCustomer") .
'</td>';
1442 $htmltoenteralink .=
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
1443 $htmltoenteralink .=
'<td>' . $langs->trans(
"Company") .
'</td>';
1444 $htmltoenteralink .=
'</tr>';
1448 $objp = $this->db->fetch_object($resqllist);
1449 $alreadylinked =
false;
1450 if (!empty(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key])) {
1451 if (in_array($objp->rowid, array_values(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key]))) {
1452 $alreadylinked =
true;
1455 $htmltoenteralink .=
'<tr class="oddeven">';
1456 $htmltoenteralink .=
'<td>';
1457 if ($alreadylinked) {
1458 $htmltoenteralink .=
img_picto(
'',
'link');
1460 $htmltoenteralink .=
'<input type="checkbox" name="idtolinkto[' . $key .
'_' . $objp->rowid .
']" id="' . $key .
'_' . $objp->rowid .
'" value="' . $objp->rowid .
'">';
1462 $htmltoenteralink .=
'</td>';
1463 $htmltoenteralink .=
'<td>';
1464 if (!$alreadylinked) {
1465 $htmltoenteralink .=
'<label for="' . $key .
'_' . $objp->rowid .
'">';
1467 $htmltoenteralink .= $objp->ref;
1468 if (!$alreadylinked) {
1469 $htmltoenteralink .=
'</label>';
1471 $htmltoenteralink .=
'</td>';
1472 $htmltoenteralink .=
'<td>' . (!empty($objp->ref_client) ? $objp->ref_client : (!empty($objp->ref_supplier) ? $objp->ref_supplier :
'')) .
'</td>';
1473 $htmltoenteralink .=
'<td class="right">';
1474 if ($possiblelink[
'label'] ==
'LinkToContract') {
1475 $htmltoenteralink .= $form->textwithpicto(
'', $langs->trans(
"InformationOnLinkToContract")) .
' ';
1477 $htmltoenteralink .=
'<span class="amount">' . (isset($objp->total_ht) ?
price($objp->total_ht) :
'') .
'</span>';
1478 $htmltoenteralink .=
'</td>';
1479 $htmltoenteralink .=
'<td>' . $objp->name .
'</td>';
1480 $htmltoenteralink .=
'</tr>';
1484 return $htmltoenteralink;
1504 global $langs, $form;
1505 require_once DOL_DOCUMENT_ROOT .
'/eventorganization/class/conferenceorboothattendee.class.php';
1506 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
1507 require_once DOL_DOCUMENT_ROOT .
'/projet/class/project.class.php';
1509 $companystatic =
new Societe($this->db);
1510 $projectstatic =
new Project($this->db);
1512 $form =
new Form($this->db);
1514 $htmltoenteralink =
'';
1518 $htmltoenteralink .=
'<tr class="liste_titre">';
1519 $htmltoenteralink .=
'<td class="nowrap"></td>';
1520 $htmltoenteralink .=
'<td>' . $langs->trans(
"Ref") .
'</td>';
1521 $htmltoenteralink .=
'<td>' . $langs->trans(
"Name") .
'</td>';
1522 $htmltoenteralink .=
'<td>' . $langs->trans(
"Email") .
'</td>';
1523 $htmltoenteralink .=
'<td>' . $langs->trans(
"Company") .
'</td>';
1524 $htmltoenteralink .=
'<td>' . $langs->trans(
"Project") .
'</td>';
1525 $htmltoenteralink .=
'<td>' . $langs->trans(
"DateOfRegistration") .
'</td>';
1526 $htmltoenteralink .=
'</tr>';
1530 $objp = $this->db->fetch_object($resqllist);
1531 $alreadylinked =
false;
1532 if (!empty(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key])) {
1533 if (in_array($objp->rowid, array_values(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key]))) {
1534 $alreadylinked =
true;
1537 $htmltoenteralink .=
'<tr class="oddeven">';
1538 $htmltoenteralink .=
'<td>';
1539 if ($alreadylinked) {
1540 $htmltoenteralink .=
img_picto(
'',
'link');
1542 $htmltoenteralink .=
'<input type="checkbox" name="idtolinkto[' . $key .
'_' . $objp->rowid .
']" id="' . $key .
'_' . $objp->rowid .
'" value="' . $objp->rowid .
'">';
1544 $htmltoenteralink .=
'</td>';
1545 $fetchattendee = $attendeestatic->fetch($objp->rowid);
1546 if ($fetchattendee) {
1547 $htmltoenteralink .=
'<td>' . $attendeestatic->getNomUrl(0).
'</td>';
1549 $htmltoenteralink .=
'<td><label for="' . $key .
'_' . $objp->rowid .
'">' . $objp->ref .
'</label></td>';
1551 $htmltoenteralink .=
'<td>' . $objp->name .
'</td>';
1552 $htmltoenteralink .=
'<td>' . $objp->email .
'</td>';
1553 $fetchcompany = $companystatic->fetch($objp->socid);
1554 if ($fetchcompany) {
1555 $htmltoenteralink .=
'<td>' . $companystatic->getNomUrl(0).
'</td>';
1557 $htmltoenteralink .=
'<td>' . $objp->name .
'</td>';
1559 $fetchcproject = $projectstatic->fetch($objp->fk_project);
1560 if ($fetchcproject) {
1561 $htmltoenteralink .=
'<td>' . $projectstatic->getNomUrl(0).
'</td>';
1563 $htmltoenteralink .=
'<td>' . $objp->fk_project .
'</td>';
1565 $htmltoenteralink .=
'<td>' . $objp->date_subscription .
'</td>';
1566 $htmltoenteralink .=
'</tr>';
1570 return $htmltoenteralink;
1588 public function select_incoterms($selected =
'', $location_incoterms =
'', $page =
'', $htmlname =
'incoterm_id', $htmloption =
'', $forcecombo = 1, $events = array(), $disableautocomplete = 0)
1591 global
$conf, $langs;
1593 $langs->load(
"dict");
1597 $incotermArray = array();
1599 $sql =
"SELECT rowid, code";
1600 $sql .=
" FROM " . $this->db->prefix() .
"c_incoterms";
1601 $sql .=
" WHERE active > 0";
1602 $sql .=
" ORDER BY code ASC";
1604 dol_syslog(get_class($this) .
"::select_incoterm", LOG_DEBUG);
1605 $resql = $this->db->query($sql);
1607 if (
$conf->use_javascript_ajax && !$forcecombo) {
1608 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1612 if (!empty($page)) {
1613 $out .=
'<form method="post" action="' . $page .
'">';
1614 $out .=
'<input type="hidden" name="action" value="set_incoterms">';
1615 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
1618 $out .=
'<select id="' . $htmlname .
'" class="flat selectincoterm width75" name="' . $htmlname .
'" ' . $htmloption .
'>';
1619 $out .=
'<option value="0"> </option>';
1620 $num = $this->db->num_rows($resql);
1624 $obj = $this->db->fetch_object($resql);
1625 $incotermArray[$i][
'rowid'] = $obj->rowid;
1626 $incotermArray[$i][
'code'] = $obj->code;
1630 foreach ($incotermArray as $row) {
1631 if ($selected && ($selected == $row[
'rowid'] || $selected == $row[
'code'])) {
1632 $out .=
'<option value="' . $row[
'rowid'] .
'" selected>';
1634 $out .=
'<option value="' . $row[
'rowid'] .
'">';
1638 $out .= $row[
'code'];
1641 $out .=
'</option>';
1644 $out .=
'</select>';
1647 if (
$conf->use_javascript_ajax && empty($disableautocomplete)) {
1648 $out .=
ajax_multiautocompleter(
'location_incoterms', array(), DOL_URL_ROOT .
'/core/ajax/locationincoterms.php') .
"\n";
1651 $out .=
'<input id="location_incoterms" class="maxwidthonsmartphone heightofcombo" type="text" name="location_incoterms" value="' . $location_incoterms .
'">' .
"\n";
1653 if (!empty($page)) {
1654 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp nomargintop nomarginbottom" value="' . $langs->trans(
"Modify") .
'"></form>';
1678 public function select_type_of_lines($selected =
'', $htmlname =
'type', $showempty = 0, $hidetext = 0, $forceall = 0, $morecss =
"", $useajaxcombo = 1)
1686 if (empty($hidetext)) {
1687 print $langs->trans(
"Type").
'...';
1690 print
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
1692 print
'<option value="-1" class="opacitymedium"'.($useajaxcombo ?
'' :
' disabled="disabled"');
1693 if ($selected == -1) {
1697 if (is_numeric($showempty)) {
1705 print
'<option value="0"';
1706 if (0 == $selected || ($selected == -1 &&
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') ==
'product')) {
1709 print
'>' . $langs->trans(
"Product");
1712 print
'<option value="1"';
1713 if (1 == $selected || ($selected == -1 &&
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') ==
'service')) {
1716 print
'>' . $langs->trans(
"Service");
1721 if ($useajaxcombo) {
1727 print $langs->trans(
"Service");
1728 print
'<input type="hidden" name="' . $htmlname .
'" value="1">';
1731 print $langs->trans(
"Product");
1732 print
'<input type="hidden" name="' . $htmlname .
'" value="0">';
1734 if ($forceall < 0) {
1735 print
'<input type="hidden" name="' . $htmlname .
'" value="1">';
1751 $num = count($this->cache_types_fees);
1758 $langs->load(
"trips");
1760 $sql =
"SELECT c.code, c.label";
1761 $sql .=
" FROM " . $this->db->prefix() .
"c_type_fees as c";
1762 $sql .=
" WHERE active > 0";
1764 $resql = $this->db->query($sql);
1766 $num = $this->db->num_rows($resql);
1770 $obj = $this->db->fetch_object($resql);
1773 $label = ($obj->code != $langs->trans($obj->code) ? $langs->trans($obj->code) : $langs->trans($obj->label));
1774 $this->cache_types_fees[$obj->code] = $label;
1778 asort($this->cache_types_fees);
1800 global $user, $langs;
1802 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
1806 print
'<select id="select_' . $htmlname .
'" class="flat" name="' . $htmlname .
'">';
1808 print
'<option value="-1"';
1809 if ($selected == -1) {
1812 print
'> </option>';
1815 foreach ($this->cache_types_fees as $key => $value) {
1816 print
'<option value="' . $key .
'"';
1817 if ($key == $selected) {
1827 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1856 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)
1859 global
$conf, $langs;
1863 if (!empty(
$conf->use_javascript_ajax) &&
getDolGlobalString(
'COMPANY_USE_SEARCH_TO_SELECT') && !$forcecombo) {
1864 if (is_null($ajaxoptions)) {
1865 $ajaxoptions = array();
1868 require_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1872 if ($selected && empty($selected_input_value)) {
1873 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
1874 $societetmp =
new Societe($this->db);
1875 $societetmp->fetch($selected);
1876 $selected_input_value = $societetmp->name;
1881 $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 :
'');
1883 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
1884 if (empty($hidelabel)) {
1885 $out .= $langs->trans(
"RefOrLabel") .
' : ';
1886 } elseif ($hidelabel == 1 && !is_numeric($showempty)) {
1887 $placeholder = $langs->trans($showempty);
1888 } elseif ($hidelabel > 1) {
1889 $placeholder = $langs->trans(
"RefOrLabel");
1890 if ($hidelabel == 2) {
1891 $out .=
img_picto($langs->trans(
"Search"),
'search');
1894 $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" />';
1895 if ($hidelabel == 3) {
1896 $out .=
img_picto($langs->trans(
"Search"),
'search');
1901 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.
'/societe/ajax/company.php', $urloption,
getDolGlobalInt(
'COMPANY_USE_SEARCH_TO_SELECT'), 0, $ajaxoptions);
1904 $out .= $this->
select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events,
'', 0, $limit, $morecss, $moreparam, $multiple, $excludeids, $showcode);
1938 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 =
'')
1942 global
$conf, $langs;
1947 if ($nokeyifsocid && $socid > 0) {
1948 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = 0;
1951 if (!empty(
$conf->use_javascript_ajax) &&
getDolGlobalString(
'CONTACT_USE_SEARCH_TO_SELECT') && !$forcecombo) {
1952 $ajaxoptions = array();
1954 require_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1958 if ($selected && empty($selected_input_value)) {
1959 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
1960 $contacttmp =
new Contact($this->db);
1961 $contacttmp->fetch($selected);
1962 $selected_input_value = $contacttmp->getFullName($langs);
1965 if (!is_numeric($showempty)) {
1966 $placeholder = $showempty;
1970 $urloption =
'htmlname=' . urlencode((
string) (str_replace(
'.',
'_', $htmlname))) .
'&outjson=1&filter=' . urlencode((
string) ($filter)) . (empty($exclude) ?
'' :
'&exclude=' . urlencode($exclude)) . ($showsoc ?
'&showsoc=' . urlencode((
string) ($showsoc)) :
'');
1972 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
1974 $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" />';
1978 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.
'/contact/ajax/contact.php', $urloption,
getDolGlobalInt(
'CONTACT_USE_SEARCH_TO_SELECT'), 0, $ajaxoptions);
1982 $disableifempty = 0;
1986 $out .= $this->
selectcontacts($socid, $selected, $htmlname, $showempty, $exclude, $limitto, $showfunction, $morecss, $options_only, $showsoc, $forcecombo, $events, $moreparam, $htmlid, $multiple, $disableifempty);
1989 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = $sav;
2020 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)
2023 global $user, $langs;
2024 global $hookmanager;
2026 $langs->loadLangs(array(
"companies",
"suppliers"));
2030 $outarray = array();
2032 if ($selected ===
'') {
2033 $selected = array();
2034 } elseif (!is_array($selected)) {
2035 $selected = array($selected);
2039 if (function_exists(
'testSqlAndScriptInject')) {
2042 return 'SQLInjectionTryDetected';
2046 if ($filter !=
'') {
2051 if (function_exists(
'testSqlAndScriptInject')) {
2054 return 'SQLInjectionTryDetected';
2060 $sql =
"SELECT s.rowid, s.nom as name, s.name_alias, s.tva_intra, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
2062 $sql .=
", s.address, s.zip, s.town";
2063 $sql .=
", dictp.code as country_code";
2065 $sql .=
" FROM " . $this->db->prefix() .
"societe as s";
2067 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_country as dictp ON dictp.rowid = s.fk_pays";
2069 if (!$user->hasRight(
'societe',
'client',
'voir')) {
2070 $sql .=
", " . $this->db->prefix() .
"societe_commerciaux as sc";
2072 $sql .=
" WHERE s.entity IN (" .
getEntity(
'societe') .
")";
2073 if (!empty($user->socid)) {
2074 $sql .=
" AND s.rowid = " . ((int) $user->socid);
2078 $sqlwhere = $filter;
2079 $sql .=
" AND (" . $sqlwhere .
")";
2081 if (!$user->hasRight(
'societe',
'client',
'voir')) {
2082 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = " . ((int) $user->id);
2085 $sql .=
" AND s.status <> 0";
2087 if (!empty($excludeids)) {
2088 $sql .=
" AND s.rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeids)) .
")";
2091 $parameters = array();
2092 $reshook = $hookmanager->executeHooks(
'selectThirdpartyListWhere', $parameters);
2093 $sql .= $hookmanager->resPrint;
2095 if ($filterkey && $filterkey !=
'') {
2099 $search_crit = explode(
' ', $filterkey);
2101 if (count($search_crit) > 1) {
2104 foreach ($search_crit as $crit) {
2108 $sql .=
"(s.nom LIKE '" . $this->db->escape($prefix . $crit) .
"%')";
2111 if (count($search_crit) > 1) {
2115 $sql .=
" OR s.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
2117 $sql .=
" OR s.code_client LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.code_fournisseur LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
2118 $sql .=
" OR s.name_alias LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.tva_intra LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
2121 $sql .= $this->db->order(
"nom",
"ASC");
2122 $sql .= $this->db->plimit($limit, 0);
2125 dol_syslog(get_class($this).
"::select_thirdparty_list", LOG_DEBUG);
2126 $resql = $this->db->query($sql);
2129 $out .=
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
' name="' . $htmlname . ($multiple ?
'[]' :
'') .
'"' . ($multiple ?
' multiple' :
'') .
'>' .
"\n";
2131 $textifempty = (($showempty && !is_numeric($showempty)) ? $langs->trans($showempty) :
'');
2135 if ($showempty && !is_numeric($showempty)) {
2136 $textifempty = $langs->trans($showempty);
2138 $textifempty .= $langs->trans(
"All");
2142 $out .=
'<option value="-1" data-html="' .
dol_escape_htmltag(
'<span class="opacitymedium">' . ($textifempty ? $textifempty :
' ') .
'</span>') .
'">' . $textifempty .
'</option>' .
"\n";
2145 $companytemp =
new Societe($this->db);
2147 $num = $this->db->num_rows($resql);
2151 $obj = $this->db->fetch_object($resql);
2154 if (($obj->client) && (!empty($obj->code_client))) {
2155 $label = $obj->code_client .
' - ';
2157 if (($obj->fournisseur) && (!empty($obj->code_fournisseur))) {
2158 $label .= $obj->code_fournisseur .
' - ';
2160 $label .=
' ' . $obj->name;
2162 $label = $obj->name;
2165 if (!empty($obj->name_alias)) {
2166 $label .=
' (' . $obj->name_alias .
')';
2170 $label .=
' - '.$obj->tva_intra;
2173 $labelhtml = $label;
2176 $companytemp->id = $obj->rowid;
2177 $companytemp->client = $obj->client;
2178 $companytemp->fournisseur = $obj->fournisseur;
2179 $tmptype = $companytemp->getTypeUrl(1,
'', 0,
'span');
2181 $labelhtml .=
' ' . $tmptype;
2184 if ($obj->client || $obj->fournisseur) {
2187 if ($obj->client == 1 || $obj->client == 3) {
2188 $label .= $langs->trans(
"Customer");
2190 if ($obj->client == 2 || $obj->client == 3) {
2191 $label .= ($obj->client == 3 ?
', ' :
'') . $langs->trans(
"Prospect");
2193 if ($obj->fournisseur) {
2194 $label .= ($obj->client ?
', ' :
'') . $langs->trans(
"Supplier");
2196 if ($obj->client || $obj->fournisseur) {
2202 $s = ($obj->address ?
' - ' . $obj->address :
'') . ($obj->zip ?
' - ' . $obj->zip :
'') . ($obj->town ?
' ' . $obj->town :
'');
2203 if (!empty($obj->country_code)) {
2204 $s .=
', ' . $langs->trans(
'Country' . $obj->country_code);
2210 if (empty($outputmode)) {
2211 if (in_array($obj->rowid, $selected)) {
2212 $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>';
2214 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
2217 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label,
'labelhtml' => $labelhtml));
2221 if (($i % 10) == 0) {
2226 $out .=
'</select>' .
"\n";
2228 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2235 $this->result = array(
'nbofthirdparties' => $num);
2269 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 =
'')
2271 global
$conf, $user, $langs, $hookmanager, $action;
2273 $langs->load(
'companies');
2275 if (empty($htmlid)) {
2276 $htmlid = $htmlname;
2280 $outarray = array();
2282 if ($selected ===
'') {
2283 $selected = array();
2284 } elseif (!is_array($selected)) {
2285 $selected = array((
int) $selected);
2289 if (function_exists(
'testSqlAndScriptInject')) {
2292 return 'SQLInjectionTryDetected';
2296 if ($filter !=
'') {
2297 if (preg_match(
'/[\(\)]/', $filter)) {
2303 if (function_exists(
'testSqlAndScriptInject')) {
2306 return 'SQLInjectionTryDetected';
2312 dol_syslog(
"Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Filter Syntax.", LOG_WARNING);
2316 if (!is_object($hookmanager)) {
2317 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
2322 $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";
2323 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
2324 $sql .=
", s.nom as company, s.town AS company_town";
2326 $sql .=
" FROM " . $this->db->prefix() .
"socpeople as sp";
2327 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
2328 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON s.rowid = sp.fk_soc";
2330 $sql .=
" WHERE sp.entity IN (" .
getEntity(
'contact') .
")";
2331 $sql .=
" AND ((sp.fk_user_creat = ".((int) $user->id).
" AND sp.priv = 1) OR sp.priv = 0)";
2332 if ($socid > 0 || $socid == -1) {
2333 $sql .=
" AND sp.fk_soc = " . ((int) $socid);
2336 $sql .=
" AND sp.statut <> 0";
2339 if (!$user->hasRight(
'societe',
'client',
'voir') && !$user->socid) {
2340 $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 .
")";
2342 if ($user->socid > 0) {
2343 $sql .=
" AND sp.fk_soc = ".((int) $user->socid);
2348 $sanitizedfilter = $filter;
2349 $sql .=
" AND (" . $sanitizedfilter .
")";
2352 $parameters = array();
2353 $reshook = $hookmanager->executeHooks(
'selectContactListWhere', $parameters);
2354 $sql .= $hookmanager->resPrint;
2355 $sql .=
" ORDER BY sp.lastname ASC";
2357 dol_syslog(get_class($this) .
"::selectcontacts", LOG_DEBUG);
2358 $resql = $this->db->query($sql);
2360 $num = $this->db->num_rows($resql);
2362 if ($htmlname !=
'none' && !$options_only) {
2363 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlid .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . (($num || empty($disableifempty)) ?
'' :
' disabled') . ($multiple ?
'multiple' :
'') .
' ' . (!empty($moreparam) ? $moreparam :
'') .
'>';
2366 if ($showempty && !is_numeric($showempty)) {
2367 $textforempty = $showempty;
2368 $out .=
'<option class="optiongrey" value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'>' . $textforempty .
'</option>';
2370 if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) {
2371 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'> </option>';
2373 if ($showempty == 2) {
2374 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Internal") .
' --</option>';
2380 include_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
2381 $contactstatic =
new Contact($this->db);
2384 $obj = $this->db->fetch_object($resql);
2387 $extendedInfos =
'';
2389 $extendedInfos = array();
2390 $email = trim($obj->email);
2391 if (!empty($email)) {
2392 $extendedInfos[] = $email;
2394 $phone = trim($obj->phone);
2395 $phone_perso = trim($obj->phone_perso);
2396 $phone_mobile = trim($obj->phone_mobile);
2397 if (!empty($phone)) {
2398 $extendedInfos[] = $phone;
2400 if (!empty($phone_perso)) {
2401 $extendedInfos[] = $phone_perso;
2403 if (!empty($phone_mobile)) {
2404 $extendedInfos[] = $phone_mobile;
2407 $contact_town = trim($obj->contact_town);
2408 $company_town = trim($obj->company_town);
2409 if (!empty($contact_town)) {
2410 $extendedInfos[] = $contact_town;
2411 } elseif (!empty($company_town)) {
2412 $extendedInfos[] = $company_town;
2414 $extendedInfos = implode(
' - ', $extendedInfos);
2415 if (!empty($extendedInfos)) {
2416 $extendedInfos =
' - ' . $extendedInfos;
2420 $contactstatic->id = $obj->rowid;
2421 $contactstatic->lastname = $obj->lastname;
2422 $contactstatic->firstname = $obj->firstname;
2423 if ($obj->statut == 1) {
2425 if ($htmlname !=
'none') {
2427 if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) {
2430 if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) {
2433 if (!empty($selected) && in_array($obj->rowid, $selected)) {
2434 $out .=
'<option value="' . $obj->rowid .
'"';
2436 $out .=
' disabled';
2438 $out .=
' selected>';
2440 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
2441 if ($showfunction && $obj->poste) {
2442 $tmplabel .=
' (' . $obj->poste .
')';
2444 if (($showsoc > 0) && $obj->company) {
2445 $tmplabel .=
' - (' . $obj->company .
')';
2449 $out .=
'</option>';
2451 $out .=
'<option value="' . $obj->rowid .
'"';
2453 $out .=
' disabled';
2457 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
2458 if ($showfunction && $obj->poste) {
2459 $tmplabel .=
' (' . $obj->poste .
')';
2461 if (($showsoc > 0) && $obj->company) {
2462 $tmplabel .=
' - (' . $obj->company .
')';
2466 $out .=
'</option>';
2469 if (in_array($obj->rowid, $selected)) {
2470 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
2471 if ($showfunction && $obj->poste) {
2472 $tmplabel .=
' (' . $obj->poste .
')';
2474 if (($showsoc > 0) && $obj->company) {
2475 $tmplabel .=
' - (' . $obj->company .
')';
2482 if ($tmplabel !=
'') {
2483 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $tmplabel,
'label' => $tmplabel,
'labelhtml' => $tmplabel));
2489 $labeltoshow = ($socid != -1) ? ($langs->trans($socid ?
"NoContactDefinedForThirdParty" :
"NoContactDefined")) : $langs->trans(
'SelectAThirdPartyFirst');
2490 $out .=
'<option class="disabled" value="-1"' . (($showempty == 2 || $multiple) ?
'' :
' selected') .
' disabled="disabled">';
2491 $out .= $labeltoshow;
2492 $out .=
'</option>';
2495 $parameters = array(
2497 'htmlname' => $htmlname,
2500 'showfunction' => $showfunction,
2501 'showsoc' => $showsoc,
2504 $reshook = $hookmanager->executeHooks(
'afterSelectContactOptions', $parameters, $this, $action);
2506 if ($htmlname !=
'none' && !$options_only) {
2507 $out .=
'</select>';
2510 if (
$conf->use_javascript_ajax && !$forcecombo && !$options_only) {
2511 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2517 if ($options_only === 2) {
2545 global $langs,
$conf;
2548 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
2549 $sql .=
" re.description, re.fk_facture_source";
2550 $sql .=
" FROM " . $this->db->prefix() .
"societe_remise_except as re";
2551 $sql .=
" WHERE re.fk_soc = " . (int) $socid;
2552 $sql .=
" AND re.entity = " . ((int)
$conf->entity);
2554 $sanitizedfilter = $filter;
2555 $sql .=
" AND " . $sanitizedfilter;
2557 $sql .=
" ORDER BY re.description ASC";
2559 dol_syslog(get_class($this) .
"::select_remises", LOG_DEBUG);
2560 $resql = $this->db->query($sql);
2562 print
'<select id="select_' . $htmlname .
'" class="flat maxwidth200onsmartphone" name="' . $htmlname .
'">';
2563 $num = $this->db->num_rows($resql);
2565 $qualifiedlines = $num;
2569 print
'<option value="0"> </option>';
2571 $obj = $this->db->fetch_object($resql);
2572 $desc =
dol_trunc($obj->description, 40);
2573 if (preg_match(
'/\(CREDIT_NOTE\)/', $desc)) {
2574 $desc = preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $desc);
2576 if (preg_match(
'/\(DEPOSIT\)/', $desc)) {
2577 $desc = preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"Deposit"), $desc);
2579 if (preg_match(
'/\(EXCESS RECEIVED\)/', $desc)) {
2580 $desc = preg_replace(
'/\(EXCESS RECEIVED\)/', $langs->trans(
"ExcessReceived"), $desc);
2582 if (preg_match(
'/\(EXCESS PAID\)/', $desc)) {
2583 $desc = preg_replace(
'/\(EXCESS PAID\)/', $langs->trans(
"ExcessPaid"), $desc);
2587 if ($selected > 0 && $selected == $obj->rowid) {
2588 $selectstring =
' selected';
2592 if ($maxvalue > 0 && $obj->amount_ttc > $maxvalue) {
2594 $disabled =
' disabled';
2597 if (
getDolGlobalString(
'MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST') && !empty($obj->fk_facture_source)) {
2598 $tmpfac =
new Facture($this->db);
2599 if ($tmpfac->fetch($obj->fk_facture_source) > 0) {
2600 $desc = $desc .
' - ' . $tmpfac->ref;
2604 print
'<option value="' . $obj->rowid .
'"' . $selectstring . $disabled .
'>' . $desc .
' (' .
price($obj->amount_ht) .
' ' . $langs->trans(
"HT") .
' - ' .
price($obj->amount_ttc) .
' ' . $langs->trans(
"TTC") .
')</option>';
2611 return $qualifiedlines;
2636 public function select_users($selected =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include =
'', $enableonly = array(), $force_entity =
'0')
2639 print $this->
select_dolusers($selected, $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity);
2668 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)
2671 global
$conf, $user, $langs, $hookmanager;
2675 if (is_object($userselected)) {
2676 $selected = (int) $userselected->id;
2677 } elseif (is_numeric($userselected)) {
2678 $selected = (int) $userselected;
2679 } elseif (is_array($userselected)) {
2680 $selected = $userselected;
2686 if ((is_numeric($selected) && ((
int) $selected < -4 || empty($selected))) && !
getDolGlobalString(
'SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE')) {
2687 $selected = $user->id;
2691 if (!is_array($selected)) {
2692 if ($selected === -1 || $selected ===
'') {
2693 $selected = array();
2695 $selected = array($selected);
2700 $excludeUsers =
null;
2701 if (is_array($exclude)) {
2702 $excludeUsers = implode(
",", $exclude);
2706 $includeUsers =
null;
2707 $includeUsersArray = array();
2708 if (is_array($include)) {
2709 $includeUsersArray = $include;
2710 } elseif ($include ==
'hierarchy') {
2712 $includeUsersArray = $user->getAllChildIds(0);
2713 } elseif ($include ==
'hierarchyme') {
2715 $includeUsersArray = $user->getAllChildIds(1);
2730 $includeUsers = implode(
",", $includeUsersArray);
2735 $outarray = array();
2736 $outarray2 = array();
2739 $showlabelofentity =
isModEnabled(
'multicompany') && !
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE') &&
$conf->entity == 1 && !empty($user->admin) && empty($user->entity) && !preg_match(
'/^search_/', $htmlname);
2740 $userissuperadminentityone =
isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && empty($user->entity);
2743 $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";
2744 if ($showlabelofentity) {
2745 $sql .=
", e.label";
2747 $sql .=
" FROM " . $this->db->prefix() .
"user as u";
2748 if ($showlabelofentity) {
2749 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid = u.entity";
2752 if ($userissuperadminentityone && $force_entity !==
'default') {
2753 if (!empty($force_entity)) {
2754 $sql .=
" WHERE u.entity IN (0, " . $this->db->sanitize($force_entity) .
")";
2756 $sql .=
" WHERE u.entity IS NOT NULL";
2760 $sql .=
" WHERE u.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
2762 $sql .=
" WHERE u.entity IN (" .
getEntity(
'user') .
")";
2766 if (!empty($user->socid)) {
2767 $sql .=
" AND u.fk_soc = " . ((int) $user->socid);
2769 if (is_array($exclude) && $excludeUsers) {
2770 $sql .=
" AND u.rowid NOT IN (" . $this->db->sanitize($excludeUsers) .
")";
2772 if ($includeUsers) {
2773 $sql .=
" AND u.rowid IN (" . $this->db->sanitize($includeUsers) .
")";
2776 $sql .=
" AND (u.statut <> 0";
2777 if (!empty($selected)) {
2778 $sql .=
" OR u.rowid IN (".$this->db->sanitize(implode(
',', $selected)).
")";
2783 $sql .=
" AND u.employee <> 0";
2786 $sql .=
" AND u.fk_soc IS NULL";
2788 if (!empty($morefilter)) {
2791 if ($errormessage) {
2792 $this->errors[] = $errormessage;
2793 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2794 if ($outputmode == 0) {
2795 return 'Error bad param $morefilter';
2803 $reshook = $hookmanager->executeHooks(
'addSQLWhereFilterOnSelectUsers', array(), $this, $action);
2804 if (!empty($reshook)) {
2805 $sql .= $hookmanager->resPrint;
2809 $sql .=
" ORDER BY u.statut DESC, u.firstname ASC, u.lastname ASC";
2811 $sql .=
" ORDER BY u.statut DESC, u.lastname ASC, u.firstname ASC";
2814 dol_syslog(get_class($this) .
"::select_dolusers", LOG_DEBUG);
2816 $resql = $this->db->query($sql);
2818 $num = $this->db->num_rows($resql);
2822 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
' minwidth200') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
2823 if ($show_empty && !$multiple) {
2824 $textforempty =
' ';
2825 if (!empty(
$conf->use_javascript_ajax)) {
2826 $textforempty =
' ';
2828 if (!is_numeric($show_empty)) {
2829 $textforempty = $show_empty;
2831 $out .=
'<option class="optiongrey" value="' . ($show_empty < 0 ? $show_empty : -1) .
'"' . ((empty($selected) || in_array(-1, $selected)) ?
' selected' :
'') .
'>' . $textforempty .
'</option>' .
"\n";
2833 $outarray[($show_empty < 0 ? $show_empty : -1)] = $textforempty;
2834 $outarray2[($show_empty < 0 ? $show_empty : -1)] = array(
2835 'id' => ($show_empty < 0 ? $show_empty : -1),
2836 'label' => $textforempty,
2837 'labelhtml' => $textforempty,
2842 if ($showalso == 2 || $showalso == 3) {
2843 $out .=
'<option value="-3"' . ((in_array(-3, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"MyTeam") .
' --</option>' .
"\n";
2845 $hasAtLeastOneSubordinate = (count($user->getAllChildIds(1)) > 1);
2846 if ($hasAtLeastOneSubordinate) {
2848 $outarray[-3] =
'-- ' . $langs->trans(
"MyTeam") .
' --';
2849 $outarray2[-3] = array(
2851 'label' =>
'-- ' . $langs->trans(
"MyTeam") .
' --',
2852 'labelhtml' =>
'-- ' . $langs->trans(
"MyTeam") .
' --',
2858 if ($showalso == 1 || $showalso == 3) {
2859 $out .=
'<option value="-2"' . ((in_array(-2, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Everybody") .
' --</option>' .
"\n";
2861 $outarray[-2] =
'-- ' . $langs->trans(
"Everybody") .
' --';
2862 $outarray2[-2] = array(
2864 'label' =>
'-- ' . $langs->trans(
"Everybody") .
' --',
2865 'labelhtml' =>
'-- ' . $langs->trans(
"Everybody") .
' --',
2870 if ($showalso == 4) {
2871 $out .=
'<option value="-4"' . ((in_array(-4, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"AllProjectContacts") .
' --</option>' .
"\n";
2873 $outarray[-4] =
'-- ' . $langs->trans(
"AllProjectContacts") .
' --';
2874 $outarray2[-4] = array(
2876 'label' =>
'-- ' . $langs->trans(
"AllProjectContacts") .
' --',
2877 'labelhtml' =>
'-- ' . $langs->trans(
"AllProjectContacts") .
' --',
2883 $userstatic =
new User($this->db);
2886 $obj = $this->db->fetch_object($resql);
2888 $userstatic->id = $obj->rowid;
2889 $userstatic->lastname = $obj->lastname;
2890 $userstatic->firstname = $obj->firstname;
2891 $userstatic->photo = $obj->photo;
2892 $userstatic->status = $obj->status;
2893 $userstatic->entity = $obj->entity;
2894 $userstatic->admin = $obj->admin;
2895 $userstatic->gender = $obj->gender;
2898 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
2899 $disableline = ($enableonlytext ? $enableonlytext :
'1');
2903 $labeltoshowhtml =
'';
2910 $labeltoshow .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2911 $labeltoshowhtml .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2912 if (empty($obj->firstname) && empty($obj->lastname)) {
2913 $labeltoshow .= $obj->login;
2914 $labeltoshowhtml .= $obj->login;
2921 $moreinfo .= ($moreinfo ?
' - ' :
' (');
2922 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(');
2923 $moreinfo .= $obj->login;
2924 $moreinfohtml .= $obj->login;
2926 if ($showstatus >= 0) {
2927 if ($obj->status == 1 && $showstatus == 1) {
2928 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Enabled');
2929 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Enabled');
2931 if ($obj->status == 0 && $showstatus == 1) {
2932 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Disabled');
2933 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Disabled');
2936 if ($showlabelofentity) {
2937 if (empty($obj->entity)) {
2938 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
"AllEntities");
2939 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
"AllEntities");
2941 if ($obj->entity !=
$conf->entity) {
2942 $moreinfo .= ($moreinfo ?
' - ' :
' (') . ($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2943 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(').($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2947 $moreinfo .= (!empty($moreinfo) ?
')' :
'');
2948 $moreinfohtml .= (!empty($moreinfohtml) ?
')</span>' :
'');
2949 if (!empty($disableline) && $disableline !=
'1') {
2951 $moreinfo .=
' - ' . $disableline;
2952 $moreinfohtml .=
' - ' . $disableline;
2954 $labeltoshow .= $moreinfo;
2955 $labeltoshowhtml .= $moreinfohtml;
2957 $out .=
'<option value="' . $obj->rowid .
'"';
2958 if (!empty($disableline)) {
2959 $out .=
' disabled';
2961 if (in_array($obj->rowid, $selected)) {
2962 $out .=
' selected';
2964 $out .=
' data-html="';
2966 $outhtml = $userstatic->getNomUrl(-3,
'', 0, 1, 24, 1,
'login',
'', 1) .
' ';
2967 if ($showstatus >= 0 && $obj->status == 0) {
2968 $outhtml .=
'<strike class="opacitymediumxxx">';
2970 $outhtml .= $labeltoshowhtml;
2971 if ($showstatus >= 0 && $obj->status == 0) {
2972 $outhtml .=
'</strike>';
2974 $labeltoshowhtml = $outhtml;
2978 $out .= $labeltoshow;
2979 $out .=
'</option>';
2981 $outarray[$userstatic->id] = $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength) . $moreinfo;
2982 $outarray2[$userstatic->id] = array(
2983 'id' => $userstatic->id,
2984 'label' => $labeltoshow,
2985 'labelhtml' => $labeltoshowhtml,
2993 $out .=
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'" disabled>';
2994 $out .=
'<option value="">' . $langs->trans(
"None") .
'</option>';
2996 $out .=
'</select>';
2998 if ($num && !$forcecombo) {
3000 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3009 if ($outputmode == 2) {
3011 } elseif ($outputmode) {
3043 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)
3046 global $langs, $user;
3048 $userstatic =
new User($this->db);
3054 if (!empty($listofuserid)) {
3055 $assignedtouser = $listofuserid;
3056 } elseif (!empty($_SESSION[
'assignedtouser'])) {
3057 $assignedtouser = json_decode($_SESSION[
'assignedtouser'],
true);
3058 if (!is_array($assignedtouser)) {
3059 $assignedtouser = array();
3062 $assignedtouser = array();
3064 $nbassignetouser = count($assignedtouser);
3067 if ($nbassignetouser) {
3068 $out .=
'<ul class="attendees">';
3072 foreach ($assignedtouser as $key => $value) {
3073 if ($value[
'id'] == $ownerid) {
3079 $userstatic->fetch($value[
'id']);
3080 $out .= $userstatic->getNomUrl(-4);
3083 $ownerid = $value[
'id'];
3084 $out .=
' (' . $langs->trans(
"Owner") .
')';
3087 if ($nbassignetouser > 1 && $action !=
'view') {
3088 $canremoveassignee = 1;
3091 if (!$canremoveowner) {
3092 $canremoveassignee = 0;
3094 if (!$user->hasRight(
'agenda',
'allactions',
'create')) {
3095 $canremoveassignee = 0;
3100 if ($canremoveassignee) {
3103 $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 .
'">';
3107 if ($showproperties) {
3108 if ($ownerid == $value[
'id'] && is_array($listofuserid) && count($listofuserid) && in_array($ownerid, array_keys($listofuserid))) {
3109 $out .=
'<div class="myavailability inline-block">';
3110 $out .=
'<span class="hideonsmartphone"> - ';
3113 $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>';
3123 if ($nbassignetouser) {
3128 if ($action !=
'view') {
3130 $out .=
'<div class="divadduser'.$htmlname.
'">';
3131 $out .=
'<input type="hidden" class="removedassignedhidden" name="removedassigned" value="">';
3132 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
3133 $out .=
'jQuery(".removedassigned").click(function() { jQuery(".removedassignedhidden").val(jQuery(this).val()); });';
3134 $out .=
'jQuery(".assignedtouser").change(function() { console.log(jQuery(".assignedtouser option:selected").val());';
3135 $out .=
' if (jQuery(".assignedtouser option:selected").val() > 0) { jQuery("#' . $action .
'assignedtouser").attr("disabled", false); }';
3136 $out .=
' else { jQuery("#' . $action .
'assignedtouser").attr("disabled", true); }';
3138 $out .=
'})</script>';
3139 $out .=
img_picto(
'',
'user',
'class="pictofixedwidth"');
3140 $out .= $this->
select_dolusers(
'', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter, 0,
'',
'minwidth200');
3141 $out .=
' <button type="submit" disabled class="button valignmiddle smallpaddingimp reposition butActionAdd" id="' . $action .
'assignedtouser" name="' . $action .
'assignedtouser" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
3142 $out .= $langs->trans(
"Add").
'</button>';
3170 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())
3175 require_once DOL_DOCUMENT_ROOT.
'/resource/class/html.formresource.class.php';
3176 require_once DOL_DOCUMENT_ROOT.
'/resource/class/dolresource.class.php';
3184 if (!empty($listofresourceid)) {
3185 $assignedtoresource = $listofresourceid;
3186 } elseif (!empty($_SESSION[
'assignedtoresource'])) {
3187 $assignedtoresource = json_decode($_SESSION[
'assignedtoresource'],
true);
3188 if (!is_array($assignedtoresource)) {
3189 $assignedtoresource = array();
3192 $assignedtoresource = array();
3194 $nbassignetoresource = count($assignedtoresource);
3197 if ($nbassignetoresource) {
3198 $out .=
'<ul class="attendees">';
3202 foreach ($assignedtoresource as $key => $value) {
3204 $resourcestatic->fetch($value[
'id']);
3205 $out .= $resourcestatic->getNomUrl(-1);
3206 if ($nbassignetoresource >= 1 && $action !=
'view') {
3207 $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 .
'">';
3210 if ($showproperties) {
3211 if (is_array($listofresourceid) && count($listofresourceid)) {
3212 $out .=
'<div class="myavailability inline-block">';
3213 $out .=
'<span class="hideonsmartphone"> - ';
3216 $out .=
' <input title="'.$langs->trans(
"Availability").
'" id="transparencyresource'.$value[
'id'].
'" class="paddingrightonly" ' . ($action ==
'view' ?
'disabled' :
'') .
' type="checkbox" name="transparency"' . (!empty($listofresourceid[$value[
'id']][
'transparency']) ?
' checked' :
'') .
'><label for="transparencyresource'.$value[
'id'].
'">' . $langs->trans(
"Busy") .
'</label>';
3226 if ($nbassignetoresource) {
3231 if ($action !=
'view') {
3232 $out .=
'<input type="hidden" class="removedassignedresourcehidden" name="removedassignedresource" value="">';
3233 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
3234 $out .=
'jQuery(".removedassignedresource").click(function() { jQuery(".removedassignedresourcehidden").val(jQuery(this).val()); });';
3235 $out .=
'jQuery(".assignedtoresource").change(function() { console.log(jQuery(".assignedtoresource option:selected").val());';
3236 $out .=
' if (jQuery(".assignedtoresource option:selected").val() > 0) { jQuery("#' . $action .
'assignedtoresource").attr("disabled", false); }';
3237 $out .=
' else { jQuery("#' . $action .
'assignedtoresource").attr("disabled", true); }';
3239 $out .=
'})</script>';
3242 if ($nbassignetoresource) {
3245 $out .=
img_picto(
'',
'resource',
'class="pictofixedwidth"');
3247 $out .= $formresources->select_resource_list(0, $htmlname,
'', 1, 1, 0, $events,
'', 2, 0,
'minwidth200');
3249 $out .=
' <button type="submit" disabled class="button valignmiddle smallpaddingimp reposition butActionAdd" id="' . $action .
'assignedtoresource" name="' . $action .
'assignedtoresource" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
3250 $out .= $langs->trans(
"Add");
3251 $out .=
'</button>';
3289 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)
3292 global $langs,
$conf;
3297 $price_level = (!empty($price_level) ? $price_level : 0);
3298 if (is_null($ajaxoptions)) {
3299 $ajaxoptions = array();
3311 $placeholder = (is_numeric($showempty) ?
'' :
'placeholder="'.dolPrintHTML($showempty).
'"');
3313 if ($selected && empty($selected_input_value)) {
3314 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3315 $producttmpselect =
new Product($this->db);
3316 $producttmpselect->fetch($selected);
3317 $selected_input_value = $producttmpselect->ref;
3318 unset($producttmpselect);
3321 if ($filtertype ==
'') {
3329 $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;
3330 if ((
int) $warehouseId > 0) {
3331 $urloption .=
'&warehouseid=' . (int) $warehouseId;
3334 if (
isModEnabled(
'variants') && is_array($selected_combinations)) {
3340 <!-- script to auto show attributes select tags if a variant was selected -->
3341 <script nonce="' .
getNonce() .
'">
3342 // auto show attributes fields
3343 selected = ' . json_encode($selected_combinations) .
';
3346 jQuery(document).ready(function () {
3348 jQuery("input[name=\'prod_entry_mode\']").change(function () {
3349 if (jQuery(this).val() == \'free\') {
3350 jQuery(\'div#attributes_box\').empty();
3354 jQuery("'.$htmltag.
'#' . $htmlname .
'").change(function () {
3356 if (!jQuery(this).val()) {
3357 jQuery(\'div#attributes_box\').empty();
3361 console.log("A change has started. We get variants fields to inject html select");
3363 jQuery.getJSON("' . DOL_URL_ROOT .
'/variants/ajax/getCombinations.php", {
3364 id: jQuery(this).val()
3365 }, function (data) {
3366 jQuery(\'div#attributes_box\').empty();
3368 jQuery.each(data, function (key, val) {
3370 combvalues[val.id] = val.values;
3372 var span = jQuery(document.createElement(\'div\')).css({
3373 \'display\': \'table-row\'
3377 jQuery(document.createElement(\'div\')).text(val.label).css({
3378 \'font-weight\': \'bold\',
3379 \'display\': \'table-cell\'
3383 var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({
3384 \'margin-left\': \'15px\',
3385 \'white-space\': \'pre\'
3387 jQuery(document.createElement(\'option\')).val(\'\')
3390 jQuery.each(combvalues[val.id], function (key, val) {
3391 var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value);
3393 if (selected[val.fk_product_attribute] == val.id) {
3394 tag.attr(\'selected\', \'selected\');
3401 jQuery(\'div#attributes_box\').append(span);
3406 ' . ($selected ?
'jQuery("'.$htmltag.
'#' . $htmlname .
'").change();' :
'') .
'
3412 if (empty($hidelabel)) {
3414 } elseif ($hidelabel > 1) {
3416 if ($hidelabel == 2) {
3417 $out .=
img_picto($langs->trans(
"Search"),
'search');
3421 $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" />';
3422 if ($hidelabel == 3) {
3423 $out .=
img_picto($langs->trans(
"Search"),
'search');
3426 $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);
3428 $out .= $this->
select_produits_list($selected, $htmlname, $filtertype, $limit, $price_level,
'', $status, $finished, 0, $socid, $showempty, $forcecombo, $morecss, $hidepriceinlabel, $warehouseStatus, $status_purchase, $warehouseId);
3430 if (
isModEnabled(
'variants') && is_array($selected_combinations)) {
3434 $htmltag =
'select';
3436 <!-- script to auto show attributes select tags if a variant was selected -->
3437 <script nonce="' .
getNonce() .
'">
3438 // auto show attributes fields
3439 selected = ' . json_encode($selected_combinations) .
';
3442 jQuery(document).ready(function () {
3444 jQuery("input[name=\'prod_entry_mode\']").change(function () {
3445 if (jQuery(this).val() == \'free\') {
3446 jQuery(\'div#attributes_box\').empty();
3450 jQuery("'.$htmltag.
'#' . $htmlname .
'").change(function () {
3452 if (!jQuery(this).val()) {
3453 jQuery(\'div#attributes_box\').empty();
3457 console.log("A change has started. We get variants fields to inject html select");
3459 jQuery.getJSON("' . DOL_URL_ROOT .
'/variants/ajax/getCombinations.php", {
3460 id: jQuery(this).val()
3461 }, function (data) {
3462 jQuery(\'div#attributes_box\').empty();
3464 jQuery.each(data, function (key, val) {
3466 combvalues[val.id] = val.values;
3468 var span = jQuery(document.createElement(\'div\')).css({
3469 \'display\': \'table-row\'
3473 jQuery(document.createElement(\'div\')).text(val.label).css({
3474 \'font-weight\': \'bold\',
3475 \'display\': \'table-cell\'
3479 var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({
3480 \'margin-left\': \'15px\',
3481 \'white-space\': \'pre\'
3483 jQuery(document.createElement(\'option\')).val(\'\')
3486 jQuery.each(combvalues[val.id], function (key, val) {
3487 var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value);
3489 if (selected[val.fk_product_attribute] == val.id) {
3490 tag.attr(\'selected\', \'selected\');
3497 jQuery(\'div#attributes_box\').append(span);
3502 ' . ($selected ?
'jQuery("'.$htmltag.
'#' . $htmlname .
'").change();' :
'') .
'
3509 if (empty($nooutput)) {
3533 public function select_bom($selected =
'', $htmlname =
'bom_id', $limit = 0, $status = 1, $type = 0, $showempty =
'1', $morecss =
'', $nooutput =
'', $forcecombo = 0, $TProducts = [])
3537 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3543 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3548 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
3550 $sql =
'SELECT b.rowid, b.ref, b.label as bomLabel, p.label as productLabel';
3551 $sql .=
' FROM ' . $this->db->prefix() .
'bom_bom as b';
3552 $sql .=
' INNER JOIN ' . $this->db->prefix() .
'product as p ON b.fk_product = p.rowid';
3553 $sql .=
' WHERE b.entity IN (' .
getEntity(
'bom') .
')';
3554 if (!empty($status)) {
3555 $sql .=
' AND status = ' . (int) $status;
3557 if (!empty($type)) {
3558 $sql .=
' AND bomtype = ' . (int) $type;
3560 if (!empty($TProducts)) {
3561 $sql .=
' AND fk_product IN (' . $this->db->sanitize(implode(
',', $TProducts)) .
')';
3563 if (!empty($limit)) {
3564 $sql .=
' LIMIT ' . (int) $limit;
3566 $resql = $this->db->query($sql);
3569 $out .=
'<option value="-1"';
3570 if (empty($selected)) {
3571 $out .=
' selected';
3573 $out .=
'> </option>';
3575 while ($obj = $this->db->fetch_object($resql)) {
3576 $out .=
'<option value="' . $obj->rowid .
'"';
3577 if ($obj->rowid == $selected) {
3580 $out .=
'>' . $obj->ref .
' - ' . $obj->productLabel .
' - ' . $obj->bomLabel .
'</option>';
3586 $out .=
'</select>';
3587 if (empty($nooutput)) {
3622 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)
3626 global $hookmanager;
3629 $outarray = array();
3633 $langs->load(
'other');
3636 $warehouseStatusArray = array();
3637 if (!empty($warehouseStatus)) {
3638 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/entrepot.class.php';
3639 if (preg_match(
'/warehouseclosed/', $warehouseStatus)) {
3642 if (preg_match(
'/warehouseopen/', $warehouseStatus)) {
3645 if (preg_match(
'/warehouseinternal/', $warehouseStatus)) {
3650 $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";
3651 if (count($warehouseStatusArray)) {
3652 $selectFieldsGrouped =
", SUM(" . $this->db->ifsql(
"e.statut IS NULL",
"0",
"ps.reel") .
") as stock";
3654 $selectFieldsGrouped =
", " . $this->db->ifsql(
"p.stock IS NULL",
'0',
"p.stock") .
" AS stock";
3660 $parameters = array();
3661 $reshook = $hookmanager->executeHooks(
'selectProductsListSelect', $parameters);
3662 if (empty($reshook)) {
3663 $sql .= $selectFields.$selectFieldsGrouped.$hookmanager->resPrint;
3665 $sql .= $hookmanager->resPrint;
3670 $sql .=
", (SELECT " . $this->db->prefix() .
"categorie_product.fk_categorie
3671 FROM " . $this->db->prefix() .
"categorie_product
3672 WHERE " . $this->db->prefix() .
"categorie_product.fk_product = p.rowid
3674 ) AS categorie_product_id";
3679 $sql .=
', pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,';
3680 $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';
3681 $selectFields .=
", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custdefault_vat_code, custref, custdiscount_percent";
3685 $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";
3686 $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';
3691 $sql .=
", pl.label as label_translated";
3692 $sql .=
", pl.description as description_translated";
3693 $selectFields .=
", label_translated";
3694 $selectFields .=
", description_translated";
3698 $sql .=
", (SELECT pp.rowid FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
3699 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
3700 $sql .=
" AND price_level = " . ((int) $price_level);
3702 $sql .=
" ORDER BY date_price";
3703 $sql .=
" DESC LIMIT 1) as price_rowid";
3704 $sql .=
", (SELECT pp.price_by_qty FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
3705 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
3706 $sql .=
" AND price_level = " . ((int) $price_level);
3708 $sql .=
" ORDER BY date_price";
3709 $sql .=
" DESC LIMIT 1) as price_by_qty";
3710 $selectFields .=
", price_rowid, price_by_qty";
3715 $sql .=
" FROM ".$this->db->prefix().
"product as p";
3718 $sql .=
" USE INDEX (" . $this->db->sanitize(
getDolGlobalString(
'MAIN_PRODUCT_FORCE_INDEX')) .
")";
3722 $parameters = array(
3725 $reshook = $hookmanager->executeHooks(
'selectProductsListFrom', $parameters);
3726 $sql .= $hookmanager->resPrint;
3728 if (count($warehouseStatusArray)) {
3731 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_stock as ps ON ps.fk_product = p.rowid";
3732 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entrepot as e ON ps.fk_entrepot = e.rowid AND e.entity IN (" .
getEntity(
'stock') .
")";
3733 $sql .=
' AND e.statut IN (' . $this->db->sanitize($this->db->escape(implode(
',', $warehouseStatusArray))) .
')';
3739 $sql .=
" LEFT JOIN (";
3740 $sql .=
" SELECT pcp1.*";
3741 $sql .=
" FROM " . $this->db->prefix() .
"product_customer_price AS pcp1";
3742 $sql .=
" LEFT JOIN (";
3743 $sql .=
" SELECT fk_soc, fk_product, MIN(date_begin) AS date_begin";
3744 $sql .=
" FROM " . $this->db->prefix() .
"product_customer_price";
3745 $sql .=
" WHERE fk_soc = " . ((int) $socid);
3746 $sql .=
" AND date_begin <= '" . $this->db->idate($now) .
"'";
3747 $sql .=
" AND (date_end IS NULL OR '" . $this->db->idate($now) .
"' <= date_end)";
3748 $sql .=
" GROUP BY fk_soc, fk_product";
3749 $sql .=
" ) AS pcp2 ON pcp1.fk_soc = pcp2.fk_soc AND pcp1.fk_product = pcp2.fk_product AND pcp1.date_begin = pcp2.date_begin";
3750 $sql .=
" WHERE pcp2.fk_soc IS NOT NULL";
3751 $sql .=
" ) AS pcp ON pcp.fk_soc = " . ((int) $socid) .
" AND pcp.fk_product = p.rowid";
3755 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units as u ON u.rowid = p.fk_unit";
3759 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_lang as pl ON pl.fk_product = p.rowid";
3761 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
3762 $soc =
new Societe($this->db);
3763 $result = $soc->fetch($socid);
3764 if ($result > 0 && !empty($soc->default_lang)) {
3765 $sql .=
" AND pl.lang = '" . $this->db->escape($soc->default_lang) .
"'";
3767 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3770 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3775 $sql .=
' WHERE p.entity IN (' .
getEntity(
'product') .
')';
3778 if (strlen($filterkey) != 13) {
3779 $sql .=
" AND NOT EXISTS (SELECT pac.rowid FROM ".$this->db->prefix().
"product_attribute_combination as pac WHERE pac.fk_product_child = p.rowid)";
3782 $sql .=
" AND NOT EXISTS (SELECT pac.rowid FROM ".$this->db->prefix().
"product_attribute_combination as pac WHERE pac.fk_product_child = p.rowid)";
3785 if ($finished == 0) {
3786 $sql .=
" AND p.finished = " . ((int) $finished);
3787 } elseif ($finished == 1) {
3788 $sql .=
" AND p.finished = ".((int) $finished);
3791 $sql .=
" AND p.tosell = ".((int) $status);
3793 if ($status_purchase >= 0) {
3794 $sql .=
" AND p.tobuy = " . ((int) $status_purchase);
3797 if (strval($filtertype) !=
'') {
3798 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
3800 $sql .=
" AND p.fk_product_type = 1";
3802 $sql .=
" AND p.fk_product_type = 0";
3805 if ((
int) $warehouseId > 0) {
3806 $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)";
3810 $parameters = array(
3811 'filterkey' => &$filterkey,
3814 $reshook = $hookmanager->executeHooks(
'selectProductsListWhere', $parameters);
3815 $sql .= $hookmanager->resPrint;
3817 if ($filterkey !=
'') {
3818 $sqlSupplierSearch =
'';
3823 $search_crit = explode(
' ', $filterkey);
3825 if (count($search_crit) > 1) {
3828 foreach ($search_crit as $crit) {
3832 $sql .=
"(p.ref LIKE '" . $this->db->escape($prefix . $crit) .
"%' OR p.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3834 $sql .=
" OR pl.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3837 $sql .=
" OR pcp.ref_customer LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3840 $sql .=
" OR p.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3842 $sql .=
" OR pl.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3848 $sqlSupplierSearch .= !empty($sqlSupplierSearch) ?
' AND ' :
'';
3849 $sqlSupplierSearch .=
" pfp.ref_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3854 if (count($search_crit) > 1) {
3858 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3863 $sql .=
" OR EXISTS (SELECT pfp.fk_product FROM " . $this->db->prefix() .
"product_fournisseur_price as pfp WHERE p.rowid = pfp.fk_product";
3865 $sql .= $sqlSupplierSearch;
3871 if (count($warehouseStatusArray)) {
3872 $sql .=
" GROUP BY " . $this->db->sanitize($selectFields, 0, 0, 1);
3878 $sql .=
" ORDER BY".((int) $selected > 0 ?
" CASE WHEN p.rowid = ".((
int) $selected).
" THEN 0 ELSE 1 END," :
"").
" categorie_product_id ".(
getDolGlobalInt(
'PRODUCT_SORT_BY_CATEGORY') == 1 ?
"ASC" :
"DESC");
3879 } elseif ((
int) $selected > 0) {
3880 $sql .=
" ORDER BY CASE WHEN p.rowid = ".((int) $selected).
" THEN 0 ELSE 1 END, p.ref ASC";
3882 $sql .= $this->db->order(
"p.ref");
3886 $sql .= $this->db->plimit($limit, 0);
3904 dol_syslog(get_class($this) .
"::select_produits_list search products", LOG_DEBUG);
3908 $result = $this->db->query($sql);
3911 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3912 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3913 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
3915 $num = $this->db->num_rows($result);
3920 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3924 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
3930 if ($showempty && !is_numeric($showempty)) {
3931 $textifempty = $langs->trans($showempty);
3933 $textifempty .= $langs->trans(
"All");
3936 if ($showempty && !is_numeric($showempty)) {
3937 $textifempty = $langs->trans($showempty);
3941 $out .=
'<option value="-1" selected>' . ($textifempty ? $textifempty :
' ') .
'</option>';
3945 while ($num && $i < $num) {
3948 $objp = $this->db->fetch_object($result);
3950 if ((
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1) {
3951 $sql =
"SELECT rowid, quantity, price, unitprice, remise_percent, remise, price_base_type";
3952 $sql .=
" FROM " . $this->db->prefix() .
"product_price_by_qty";
3953 $sql .=
" WHERE fk_product_price = " . ((int) $objp->price_rowid);
3954 $sql .=
" ORDER BY quantity ASC";
3956 dol_syslog(get_class($this) .
"::select_produits_list search prices by qty", LOG_DEBUG);
3957 $result2 = $this->db->query($sql);
3959 $nb_prices = $this->db->num_rows($result2);
3961 while ($nb_prices && $j < $nb_prices) {
3962 $objp2 = $this->db->fetch_object($result2);
3964 $objp->price_by_qty_rowid = $objp2->rowid;
3965 $objp->price_by_qty_price_base_type = $objp2->price_base_type;
3966 $objp->price_by_qty_quantity = $objp2->quantity;
3967 $objp->price_by_qty_unitprice = $objp2->unitprice;
3968 $objp->price_by_qty_remise_percent = $objp2->remise_percent;
3970 $objp->quantity = $objp2->quantity;
3971 $objp->price = $objp2->price;
3972 $objp->unitprice = $objp2->unitprice;
3973 $objp->remise_percent = $objp2->remise_percent;
3979 '@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';
3986 array_push($outarray, $optJson);
3990 if (
isModEnabled(
'dynamicprices') && !empty($objp->fk_price_expression)) {
3991 $price_product =
new Product($this->db);
3992 $price_product->fetch($objp->rowid,
'',
'',
'1');
3994 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3996 $price_result = $priceparser->parseProduct($price_product);
3997 if ($price_result >= 0) {
3998 $objp->price = $price_result;
3999 $objp->unitprice = $price_result;
4001 $objp->price_ttc = (float)
price2num($objp->price) * (1 + ($objp->tva_tx / 100));
4002 $objp->price_ttc =
price2num($objp->price_ttc,
'MU');
4005 if (
getDolGlobalInt(
'PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES') && !empty($objp->custprice)) {
4013 array_push($outarray, $optJson);
4019 $out .=
'</select>';
4021 $this->db->free($result);
4023 if (empty($outputmode)) {
4050 protected function constructProductListOption(&$objp, &$opt, &$optJson, $price_level, $selected, $hidepriceinlabel = 0, $filterkey =
'', $novirtualstock = 0)
4052 global $langs,
$conf, $user;
4053 global $hookmanager;
4059 $outlabel_translated =
'';
4061 $outdesc_translated =
'';
4067 $outpricebasetype =
'';
4069 $outdefault_vat_code =
'';
4075 $productlabel = $objp->label;
4076 if (!empty($objp->label_translated)) {
4077 $productlabel = $objp->label_translated;
4079 $label = $productlabel;
4080 if (!empty($filterkey) && $filterkey !=
'') {
4081 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
4084 $outkey = $objp->rowid;
4085 $outref = $objp->ref;
4086 $outrefcust = empty($objp->custref) ?
'' : $objp->custref;
4087 $outlabel = $objp->label;
4088 $outdesc = $objp->description;
4090 $outlabel_translated = $objp->label_translated;
4091 $outdesc_translated = $objp->description_translated;
4093 $outbarcode = $objp->barcode;
4094 $outorigin = $objp->fk_country;
4095 $outpbq = empty($objp->price_by_qty_rowid) ?
'' : $objp->price_by_qty_rowid;
4097 $outtype = $objp->fk_product_type;
4102 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
4108 if (!empty($objp->unit_short)) {
4109 $outvalUnits .=
' - ' . $objp->unit_short;
4113 if (!empty($objp->weight) && $objp->weight_units !==
null) {
4115 $outvalUnits .=
' - ' . $unitToShow;
4117 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
4118 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
4119 $outvalUnits .=
' - ' . $unitToShow;
4121 if (!empty($objp->surface) && $objp->surface_units !==
null) {
4123 $outvalUnits .=
' - ' . $unitToShow;
4125 if (!empty($objp->volume) && $objp->volume_units !==
null) {
4127 $outvalUnits .=
' - ' . $unitToShow;
4130 if ($outdurationvalue && $outdurationunit) {
4132 'h' => $langs->trans(
'Hour'),
4133 'd' => $langs->trans(
'Day'),
4134 'w' => $langs->trans(
'Week'),
4135 'm' => $langs->trans(
'Month'),
4136 'y' => $langs->trans(
'Year')
4138 if (isset($da[$outdurationunit])) {
4139 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
4146 if ($user->hasRight(
'stock',
'lire')) {
4147 if ($objp->stock > 0) {
4149 } elseif ($objp->stock <= 0) {
4157 $labeltosearch =
'';
4158 $labeltosearch .= $objp->ref;
4159 if (!empty($objp->custref)) {
4160 $labeltosearch .=
' (' . $objp->custref .
')';
4163 $labeltosearch .=
' (' . $outbarcode .
')';
4165 $labeltosearch .=
' - ' . $productlabel;
4167 $labeltosearch .=
' (' .
getCountry($outorigin,
'1') .
')';
4171 $labeltoshowhtml =
'';
4172 $labeltoshowhtml .= $objp->ref;
4173 if (!empty($objp->custref)) {
4174 $labeltoshowhtml .=
' (' . $objp->custref .
')';
4176 if (!empty($filterkey) && $filterkey !=
'') {
4177 $labeltoshowhtml = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $labeltoshowhtml, 1);
4180 $labeltoshowhtml .=
' (' . $outbarcode .
')';
4182 $labeltoshowhtml .=
' - ' .
dol_trunc($label, $maxlengtharticle);
4184 $labeltoshowhtml .=
' (' .
getCountry($outorigin,
'1') .
')';
4188 $labeltoshowstock =
'';
4189 $labeltoshowhtmlstock =
'';
4191 if ($user->hasRight(
'stock',
'lire')) {
4192 $labeltoshowstock .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
4194 if ($objp->stock > 0) {
4195 $labeltoshowhtmlstock .=
' - <span class="product_line_stock_ok">';
4196 } elseif ($objp->stock <= 0) {
4197 $labeltoshowhtmlstock .=
' - <span class="product_line_stock_too_low">';
4199 $labeltoshowhtmlstock .= $langs->transnoentities(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
4200 $labeltoshowhtmlstock .=
'</span>';
4202 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
4203 $langs->load(
"stocks");
4205 $tmpproduct =
new Product($this->db);
4206 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
4207 $tmpproduct->load_virtual_stock();
4208 $virtualstock = $tmpproduct->stock_theorique;
4210 $labeltoshowstock .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
4212 $labeltoshowhtmlstock .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
4213 if ($virtualstock > 0) {
4214 $labeltoshowhtmlstock .=
'<span class="product_line_stock_ok">';
4215 } elseif ($virtualstock <= 0) {
4216 $labeltoshowhtmlstock .=
'<span class="product_line_stock_too_low">';
4218 $labeltoshowhtmlstock .= $virtualstock;
4219 $labeltoshowhtmlstock .=
'</span>';
4228 $labeltoshowprice =
'';
4229 $labeltoshowhtmlprice =
'';
4232 $sql =
"SELECT price, price_ttc, price_base_type, tva_tx, default_vat_code";
4233 $sql .=
" FROM " . $this->db->prefix() .
"product_price";
4234 $sql .=
" WHERE fk_product = " . ((int) $objp->rowid);
4235 $sql .=
" AND entity IN (" .
getEntity(
'productprice') .
")";
4236 $sql .=
" AND price_level = " . ((int) $price_level);
4237 $sql .=
" ORDER BY date_price DESC, rowid DESC";
4240 dol_syslog(get_class($this) .
'::constructProductListOption search price for product ' . $objp->rowid .
' AND level ' . $price_level, LOG_DEBUG);
4241 $result2 = $this->db->query($sql);
4243 $objp2 = $this->db->fetch_object($result2);
4246 if ($objp2->price_base_type ==
'HT') {
4247 $labeltoshowprice .=
' - ' .
price($objp2->price, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
4248 $labeltoshowhtmlprice .=
' - ' .
price($objp2->price, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
4250 $labeltoshowprice .=
' - ' .
price($objp2->price_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
4251 $labeltoshowhtmlprice .=
' - ' .
price($objp2->price_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
4253 $outprice_ht =
price($objp2->price);
4254 $outprice_ttc =
price($objp2->price_ttc);
4255 $outpricebasetype = $objp2->price_base_type;
4257 $outtva_tx = $objp2->tva_tx;
4258 $outdefault_vat_code = $objp2->default_vat_code;
4260 $outtva_tx = $objp->tva_tx;
4261 $outdefault_vat_code = $objp->default_vat_code;
4270 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1 && (
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
4272 $outqty = $objp->quantity;
4273 $outdiscount = $objp->remise_percent;
4274 if ($objp->quantity == 1) {
4275 $labeltoshowprice .=
' - ' .
price($objp->unitprice, 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
4276 $labeltoshowhtmlprice .=
' - ' .
price($objp->unitprice, 0, $langs, 0, 0, -1,
$conf->currency) .
"/";
4277 $labeltoshowprice .= $langs->trans(
"Unit");
4278 $labeltoshowhtmlprice .= $langs->transnoentities(
"Unit");
4280 $labeltoshowprice .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
4281 $labeltoshowhtmlprice .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
4282 $labeltoshowprice .= $langs->trans(
"Units");
4283 $labeltoshowhtmlprice .= $langs->transnoentities(
"Units");
4286 $outprice_ht =
price($objp->unitprice);
4287 $outprice_ttc =
price($objp->unitprice * (1 + ($objp->tva_tx / 100)));
4288 $outpricebasetype = $objp->price_base_type;
4289 $outtva_tx = $objp->tva_tx;
4290 $outdefault_vat_code = $objp->default_vat_code;
4292 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1) {
4293 $labeltoshowprice .=
" (" .
price($objp->unitprice, 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->trans(
"Unit") .
")";
4294 $labeltoshowhtmlprice .=
" (" .
price($objp->unitprice, 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->transnoentities(
"Unit") .
")";
4296 if (empty($hidepriceinlabel) && !empty($objp->remise_percent) && $objp->remise_percent >= 1) {
4297 $labeltoshowprice .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4298 $labeltoshowhtmlprice .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4303 if (!empty($objp->idprodcustprice)) {
4306 if ($objp->custprice_base_type ==
'HT') {
4307 $labeltoshowprice .=
' - ' .
price($objp->custprice, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
4308 $labeltoshowhtmlprice .=
' - ' .
price($objp->custprice, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
4310 $labeltoshowprice .=
' - ' .
price($objp->custprice_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
4311 $labeltoshowhtmlprice .=
' - ' .
price($objp->custprice_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
4314 $outprice_ht =
price($objp->custprice);
4315 $outprice_ttc =
price($objp->custprice_ttc);
4316 $outpricebasetype = $objp->custprice_base_type;
4317 $outtva_tx = $objp->custtva_tx;
4318 $outdefault_vat_code = $objp->custdefault_vat_code;
4319 $outdiscount = $objp->custdiscount_percent;
4324 if (empty($hidepriceinlabel) && !$found) {
4325 if ($objp->price_base_type ==
'HT') {
4326 $labeltoshowprice .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
4327 $labeltoshowhtmlprice .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
4329 $labeltoshowprice .=
' - ' .
price($objp->price_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
4330 $labeltoshowhtmlprice .=
' - ' .
price($objp->price_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
4332 $outprice_ht =
price($objp->price);
4333 $outprice_ttc =
price($objp->price_ttc);
4334 $outpricebasetype = $objp->price_base_type;
4335 $outtva_tx = $objp->tva_tx;
4336 $outdefault_vat_code = $objp->default_vat_code;
4339 $optiontext = $labeltosearch.$outvalUnits.$labeltoshowprice.$labeltoshowstock;
4340 $optionhtml = $labeltoshowhtml.$outvalUnits.$labeltoshowhtmlprice.$labeltoshowhtmlstock;
4344 $opt =
'<option value="' . $objp->rowid .
'"';
4345 $opt .= ($objp->rowid == $selected) ?
' selected' :
'';
4346 if (!empty($objp->price_by_qty_rowid) && $objp->price_by_qty_rowid > 0) {
4347 $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 .
'"';
4350 $opt .=
' data-labeltrans="' .
dol_escape_htmltag($outlabel_translated, 0, 0,
'', 0, 1) .
'"';
4354 if ($stocktag == 1) {
4355 $opt .=
' class="product_line_stock_ok" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml, 0, array(
'strong')).dolPrintHTMLForAttribute($outvalUnits).$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
4358 if ($stocktag == -1) {
4359 $opt .=
' class="product_line_stock_too_low" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml, 0, array(
'strong')).dolPrintHTMLForAttribute($outvalUnits).$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
4362 $opt .=
' data-html="'.$optionhtmlforattribute.
'" data-select-html="'.$optionhtmlforattribute.
'"';
4368 $outval .= $labeltoshowhtml;
4371 $outval .= $outvalUnits;
4374 $outval .= $labeltoshowhtmlprice;
4377 $outval .= $labeltoshowhtmlstock;
4380 $parameters = array(
'objp' => $objp);
4381 $reshook = $hookmanager->executeHooks(
'constructProductListOption', $parameters);
4382 if (empty($reshook)) {
4383 $opt .= $hookmanager->resPrint;
4385 $opt = $hookmanager->resPrint;
4388 $opt .=
"</option>\n";
4393 'label2' => $outlabel,
4397 'price_ttc' =>
price2num($outprice_ttc),
4400 'pricebasetype' => $outpricebasetype,
4401 'tva_tx' => $outtva_tx,
4402 'default_vat_code' => $outdefault_vat_code,
4404 'discount' => $outdiscount,
4405 'duration_value' => $outdurationvalue,
4406 'duration_unit' => $outdurationunit,
4408 'labeltrans' => $outlabel_translated,
4409 'desctrans' => $outdesc_translated,
4410 'ref_customer' => $outrefcust
4432 public function select_produits_fournisseurs($socid, $selected =
'', $htmlname =
'productid', $filtertype =
'', $notused =
'', $ajaxoptions = array(), $hidelabel = 0, $alsoproductwithnosupplierprice = 0, $morecss =
'', $placeholder =
'', $nooutput = 0)
4435 global $langs,
$conf;
4436 global $price_level, $status, $finished;
4438 if (!isset($status)) {
4442 $selected_input_value =
'';
4444 if ((
int) $selected > 0) {
4445 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
4446 $producttmpselect =
new Product($this->db);
4447 $producttmpselect->fetch((
int) $selected);
4448 $selected_input_value = $producttmpselect->ref;
4449 unset($producttmpselect);
4450 } elseif (preg_match(
'/^idprod_([0-9]+)$/', (
string) $selected, $regtmpsel)) {
4452 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
4453 $producttmpselect =
new Product($this->db);
4454 $producttmpselect->fetch((
int) $regtmpsel[1]);
4455 $selected_input_value = $producttmpselect->ref;
4456 unset($producttmpselect);
4460 $urloption = ($socid > 0 ?
'socid=' . $socid .
'&' :
'') .
'htmlname=' . $htmlname .
'&outjson=1&price_level=' . $price_level .
'&type=' . $filtertype .
'&mode=2&status=' . $status .
'&finished=' . $finished .
'&alsoproductwithnosupplierprice=' . $alsoproductwithnosupplierprice;
4462 $s = ($hidelabel ?
'' : $langs->trans(
"RefOrLabel") .
' : ') .
'<input type="text" class="'.$morecss.
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . ($placeholder ?
' placeholder="' . $placeholder .
'"' :
'') .
'>';
4464 $s .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT .
'/product/ajax/products.php', $urloption,
getDolGlobalInt(
'PRODUIT_USE_SEARCH_TO_SELECT'), 0, $ajaxoptions);
4466 $s = $this->
select_produits_fournisseurs_list($socid, $selected, $htmlname, $filtertype, $notused,
'', $status, 0, 0, $alsoproductwithnosupplierprice, $morecss,
getDolGlobalInt(
'SUPPLIER_SHOW_STOCK_IN_PRODUCTS_COMBO'), $placeholder);
4496 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 =
'')
4499 global $langs,
$conf, $user;
4500 global $hookmanager;
4503 $outarray = array();
4507 $langs->load(
'stocks');
4510 $langs->load(
'other');
4513 $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,";
4514 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice, pfp.barcode";
4515 $sql .=
", pfp.multicurrency_code, pfp.multicurrency_unitprice";
4516 $sql .=
", pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.default_vat_code, pfp.fk_soc, s.nom as name";
4517 $sql .=
", pfp.supplier_reputation";
4520 $sql .=
", pfp.desc_fourn as description";
4522 $sql .=
", p.description";
4526 $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";
4531 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListSelect', $parameters);
4532 $sql .= $hookmanager->resPrint;
4534 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
4538 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListFrom', $parameters);
4539 $sql .= $hookmanager->resPrint;
4541 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN (" .
getEntity(
'product') .
") )";
4543 $sql .=
" AND pfp.fk_soc = " . ((int) $socid);
4545 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
4548 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
4550 $sql .=
" WHERE p.entity IN (" .
getEntity(
'product') .
")";
4551 if ($statut != -1) {
4552 $sql .=
" AND p.tobuy = " . ((int) $statut);
4554 if (strval($filtertype) !=
'') {
4555 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
4559 $parameters = array();
4560 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListWhere', $parameters);
4561 $sql .= $hookmanager->resPrint;
4563 if ($filterkey !=
'') {
4567 $search_crit = explode(
' ', $filterkey);
4569 if (count($search_crit) > 1) {
4572 foreach ($search_crit as $crit) {
4576 $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) .
"%'";
4578 $sql .=
" OR pfp.desc_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
4583 if (count($search_crit) > 1) {
4587 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
4588 $sql .=
" OR pfp.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
4592 $sql .=
" ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC";
4593 $sql .= $this->db->plimit($limit, 0);
4597 dol_syslog(get_class($this) .
"::select_produits_fournisseurs_list", LOG_DEBUG);
4598 $result = $this->db->query($sql);
4600 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4601 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
4603 $num = $this->db->num_rows($result);
4606 $out .=
'<select class="flat ' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'">';
4608 $out .=
'<option value="-1" selected>' . ($placeholder ? $placeholder :
' ') .
'</option>';
4610 $out .=
'<option value="-1">' . ($placeholder ? $placeholder :
' ') .
'</option>';
4615 $objp = $this->db->fetch_object($result);
4617 if (is_null($objp->idprodfournprice)) {
4619 $objp->tva_tx = $objp->tva_tx_sale;
4620 $objp->default_vat_code = $objp->default_vat_code_sale;
4623 $outkey = $objp->idprodfournprice;
4624 if (!$outkey && $alsoproductwithnosupplierprice) {
4625 $outkey =
'idprod_' . $objp->rowid;
4628 $outref = $objp->ref;
4629 $outbarcode = $objp->barcode;
4632 $outtype = $objp->fk_product_type;
4639 if (!empty($objp->unit_short)) {
4640 $outvalUnits .=
' - ' . $objp->unit_short;
4642 if (!empty($objp->weight) && $objp->weight_units !==
null) {
4644 $outvalUnits .=
' - ' . $unitToShow;
4646 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
4647 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
4648 $outvalUnits .=
' - ' . $unitToShow;
4650 if (!empty($objp->surface) && $objp->surface_units !==
null) {
4652 $outvalUnits .=
' - ' . $unitToShow;
4654 if (!empty($objp->volume) && $objp->volume_units !==
null) {
4656 $outvalUnits .=
' - ' . $unitToShow;
4658 if ($outdurationvalue && $outdurationunit) {
4660 'h' => $langs->trans(
'Hour'),
4661 'd' => $langs->trans(
'Day'),
4662 'w' => $langs->trans(
'Week'),
4663 'm' => $langs->trans(
'Month'),
4664 'y' => $langs->trans(
'Year')
4666 if (isset($da[$outdurationunit])) {
4667 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
4672 $objRef = $objp->ref;
4673 if ($filterkey && $filterkey !=
'') {
4674 $objRef = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRef, 1);
4676 $objRefFourn = $objp->ref_fourn;
4677 if ($filterkey && $filterkey !=
'') {
4678 $objRefFourn = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRefFourn, 1);
4680 $label = $objp->label;
4681 if ($filterkey && $filterkey !=
'') {
4682 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
4685 switch ($objp->fk_product_type) {
4697 if (empty($picto)) {
4700 $optlabel =
img_object(
'', $picto,
'class="paddingright classfortooltip"', 0, 0, 1);
4703 $optlabel .= $objp->ref;
4704 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
4705 $optlabel .=
' <span class="opacitymedium">(' . $objp->ref_fourn .
')</span>';
4707 if (
isModEnabled(
'barcode') && !empty($objp->barcode)) {
4708 $optlabel .=
' (' . $outbarcode .
')';
4710 $optlabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
4712 $outvallabel = $objRef;
4713 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
4714 $outvallabel .=
' (' . $objRefFourn .
')';
4716 if (
isModEnabled(
'barcode') && !empty($objp->barcode)) {
4717 $outvallabel .=
' (' . $outbarcode .
')';
4719 $outvallabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
4721 $outsearchlabel = implode(
' ', array_filter(array(
4722 (
string) $objp->ref,
4723 (
string) $objp->ref_fourn,
4724 (
string) $objp->barcode,
4725 (
string) $objp->label,
4727 ), function (
string $value):
bool {
4728 return $value !==
'';
4732 $optlabel .= $outvalUnits;
4733 $outvallabel .= $outvalUnits;
4735 if (!empty($objp->idprodfournprice)) {
4736 $outqty = $objp->quantity;
4737 $outdiscount = $objp->remise_percent;
4738 if (
isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
4740 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
4741 $prod_supplier->id = $objp->fk_product;
4742 $prod_supplier->fourn_qty = $objp->quantity;
4743 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
4744 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
4746 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4748 $price_result = $priceparser->parseProductSupplier($prod_supplier);
4749 if ($price_result >= 0) {
4750 $objp->fprice = $price_result;
4751 if ($objp->quantity >= 1) {
4752 $objp->unitprice = $objp->fprice / $objp->quantity;
4756 if ($objp->quantity == 1) {
4757 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
4758 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1,
$conf->currency) .
"/";
4759 $optlabel .= $langs->trans(
"Unit");
4760 $outvallabel .= $langs->transnoentities(
"Unit");
4762 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
4763 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
4764 $optlabel .=
' ' . $langs->trans(
"Units");
4765 $outvallabel .=
' ' . $langs->transnoentities(
"Units");
4768 if ($objp->quantity != 1) {
4769 $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") .
")";
4770 $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") .
")";
4772 if ($objp->remise_percent >= 1) {
4773 $optlabel .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4774 $outvallabel .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4776 if ($objp->duration) {
4777 $optlabel .=
" - " . $objp->duration;
4778 $outvallabel .=
" - " . $objp->duration;
4781 $optlabel .=
" - " .
dol_trunc($objp->name, 8);
4782 $outvallabel .=
" - " .
dol_trunc($objp->name, 8);
4784 if ($objp->supplier_reputation) {
4786 $reputations = array(
'' => $langs->trans(
'Standard'),
'FAVORITE' => $langs->trans(
'Favorite'),
'NOTTHGOOD' => $langs->trans(
'NotTheGoodQualitySupplier'),
'DONOTORDER' => $langs->trans(
'DoNotOrderThisProductToThisSupplier'));
4788 $optlabel .=
" - " . $reputations[$objp->supplier_reputation];
4789 $outvallabel .=
" - " . $reputations[$objp->supplier_reputation];
4792 $optlabel .=
" - <span class='opacitymedium'>" . $langs->trans(
"NoPriceDefinedForThisSupplier") .
'</span>';
4793 $outvallabel .=
' - ' . $langs->transnoentities(
"NoPriceDefinedForThisSupplier");
4797 $novirtualstock = ($showstockinlist == 2);
4799 if ($user->hasRight(
'stock',
'lire')) {
4800 $outvallabel .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
4802 if ($objp->stock > 0) {
4803 $optlabel .=
' - <span class="product_line_stock_ok">';
4804 } elseif ($objp->stock <= 0) {
4805 $optlabel .=
' - <span class="product_line_stock_too_low">';
4807 $optlabel .= $langs->transnoentities(
"Stock") .
':' .
price(
price2num($objp->stock,
'MS'));
4808 $optlabel .=
'</span>';
4809 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
4810 $langs->load(
"stocks");
4812 $tmpproduct =
new Product($this->db);
4813 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
4814 $tmpproduct->load_virtual_stock();
4815 $virtualstock = $tmpproduct->stock_theorique;
4817 $outvallabel .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
4819 $optlabel .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
4820 if ($virtualstock > 0) {
4821 $optlabel .=
'<span class="product_line_stock_ok">';
4822 } elseif ($virtualstock <= 0) {
4823 $optlabel .=
'<span class="product_line_stock_too_low">';
4825 $optlabel .= $virtualstock;
4826 $optlabel .=
'</span>';
4833 $optstart =
'<option value="' . $outkey .
'"';
4834 if ($selected && preg_match(
'/^idprod_/', (
string) $selected) && (
string) $selected ==
'idprod_'.$objp->rowid) {
4835 $optstart .=
' selected';
4836 } elseif ($selected && (
string) $selected == (
string) $objp->idprodfournprice) {
4837 $optstart .=
' selected';
4840 if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) {
4841 $optstart .=
' disabled';
4844 if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) {
4853 $optstart .=
' data-default-vat-code="' .
dol_escape_htmltag($objp->default_vat_code) .
'"';
4856 $optstart .=
' data-multicurrency-code="' .
dol_escape_htmltag($objp->multicurrency_code) .
'"';
4860 $optstart .=
' data-description="' .
dol_escape_htmltag($objp->description, 0, 1) .
'"';
4864 $outarrayentry = array(
4867 'label' => $outvallabel,
4868 'labelhtml' => $optlabel,
4870 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4871 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4872 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4873 'tva_tx_formated' =>
price($objp->tva_tx, 0, $langs, 1, -1, 2),
4875 'default_vat_code' => $objp->default_vat_code,
4876 'supplier_ref' => $objp->ref_fourn,
4877 'discount' => $outdiscount,
4879 'duration_value' => $outdurationvalue,
4880 'duration_unit' => $outdurationunit,
4881 'disabled' => empty($objp->idprodfournprice),
4882 'description' => $objp->description
4885 $outarrayentry[
'multicurrency_code'] = $objp->multicurrency_code;
4886 $outarrayentry[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4888 $parameters = array(
4890 'optstart' => &$optstart,
4891 'optlabel' => &$optlabel,
4892 'outvallabel' => &$outvallabel,
4893 'outarrayentry' => &$outarrayentry,
4896 $reshook = $hookmanager->executeHooks(
'selectProduitsFournisseurListOption', $parameters, $this);
4902 $out .= $optstart .
' data-html="' .
dol_escape_htmltag($optlabel) .
'">' . $optlabel .
"</option>\n";
4903 $outarraypush = array(
4906 'label' => $outvallabel,
4907 'labelhtml' => $optlabel,
4909 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4910 'price_qty_ht_locale' =>
price($objp->fprice),
4911 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4912 'price_unit_ht_locale' =>
price($objp->unitprice),
4913 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4914 'tva_tx_formated' =>
price($objp->tva_tx),
4916 'default_vat_code' => $objp->default_vat_code,
4917 'supplier_ref' => $objp->ref_fourn,
4918 'discount' => $outdiscount,
4920 'duration_value' => $outdurationvalue,
4921 'duration_unit' => $outdurationunit,
4922 'disabled' => empty($objp->idprodfournprice),
4923 'description' => $objp->description
4926 $outarraypush[
'multicurrency_code'] = $objp->multicurrency_code;
4927 $outarraypush[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4929 array_push($outarray, $outarraypush);
4942 $out .=
'</select>';
4944 $this->db->free($result);
4946 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
4952 if (empty($outputmode)) {
4971 global $langs,
$conf;
4973 $langs->load(
'stocks');
4975 $sql =
"SELECT p.rowid, p.ref, p.label, p.price, p.duration, pfp.fk_soc,";
4976 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.remise_percent, pfp.quantity, pfp.unitprice,";
4977 $sql .=
" pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name";
4978 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
4979 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
4980 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
4981 $sql .=
" WHERE pfp.entity IN (" .
getEntity(
'productsupplierprice') .
")";
4982 $sql .=
" AND p.tobuy = 1";
4983 $sql .=
" AND s.fournisseur = 1";
4984 $sql .=
" AND p.rowid = " . ((int) $productid);
4986 $sql .=
" ORDER BY s.nom, pfp.ref_fourn DESC";
4988 $sql .=
" ORDER BY pfp.unitprice - pfp.unitprice * pfp.remise_percent / 100 ASC";
4991 dol_syslog(get_class($this) .
"::select_product_fourn_price", LOG_DEBUG);
4992 $result = $this->db->query($sql);
4995 $num = $this->db->num_rows($result);
4997 $form =
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
5000 $form .=
'<option value="0">-- ' . $langs->trans(
"NoSupplierPriceDefinedForThisProduct") .
' --</option>';
5002 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
5003 $form .=
'<option value="0"> </option>';
5007 $objp = $this->db->fetch_object($result);
5009 $opt =
'<option value="' . $objp->idprodfournprice .
'"';
5011 if ($num == 1 || ($selected_supplier > 0 && $objp->fk_soc == $selected_supplier) || ($i == 0 &&
getDolGlobalString(
'PRODUCT_BEST_SUPPLIER_PRICE_PRESELECTED'))) {
5012 $opt .=
' selected';
5014 $opt .=
'>' . $objp->name .
' - ' . $objp->ref_fourn .
' - ';
5016 if (
isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
5018 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
5019 $prod_supplier->id = $productid;
5020 $prod_supplier->fourn_qty = $objp->quantity;
5021 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
5022 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
5024 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
5026 $price_result = $priceparser->parseProductSupplier($prod_supplier);
5027 if ($price_result >= 0) {
5028 $objp->fprice = $price_result;
5029 if ($objp->quantity >= 1) {
5030 $objp->unitprice = $objp->fprice / $objp->quantity;
5034 if ($objp->quantity == 1) {
5035 $opt .=
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
5038 $opt .= $objp->quantity .
' ';
5040 if ($objp->quantity == 1) {
5041 $opt .= $langs->trans(
"Unit");
5043 $opt .= $langs->trans(
"Units");
5045 if ($objp->quantity > 1) {
5047 $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");
5049 if ($objp->duration) {
5050 $opt .=
" - " . $objp->duration;
5052 $opt .=
"</option>\n";
5059 $form .=
'</select>';
5060 $this->db->free($result);
5078 global $langs, $hookmanager;
5080 $num = count($this->cache_conditions_paiements);
5087 $this->cache_conditions_paiements = array();
5089 $sql =
"SELECT rowid, code, libelle as label, deposit_percent, entity";
5090 $sql .=
" FROM " . $this->db->prefix() .
'c_payment_term';
5091 $sql .=
" WHERE entity IN (" .
getEntity(
'c_payment_term') .
")";
5092 $sql .=
" AND active > 0";
5093 $sql .=
" ORDER BY sortorder";
5095 $resql = $this->db->query($sql);
5097 $num = $this->db->num_rows($resql);
5100 $obj = $this->db->fetch_object($resql);
5103 $label = ($langs->trans(
"PaymentConditionShort" . $obj->code) !=
"PaymentConditionShort" . $obj->code ? $langs->trans(
"PaymentConditionShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
5105 $this->cache_conditions_paiements[$obj->rowid][
'code'] = (
string) $obj->code;
5106 $this->cache_conditions_paiements[$obj->rowid][
'label'] = (
string) $label;
5107 $this->cache_conditions_paiements[$obj->rowid][
'deposit_percent'] = (
string) $obj->deposit_percent;
5108 $this->cache_conditions_paiements[$obj->rowid][
'entity'] = (int) $obj->entity;
5113 $parameters = array(
'context' =>
'paymentterm');
5114 $reshook = $hookmanager->executeHooks(
'loadDictionaryCache', $parameters, $this);
5115 if (empty($reshook)) {
5116 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
5117 $this->cache_conditions_paiements = array_merge($this->cache_conditions_paiements, $hookmanager->resArray);
5120 $this->cache_conditions_paiements = $hookmanager->resArray;
5144 $this->cache_rule_for_lines_dates = $factureRec->fields[
'rule_for_lines_dates'][
'arrayofkeyval'];
5146 if (empty($this->cache_rule_for_lines_dates)) {
5165 $num = count($this->cache_availability);
5172 $this->cache_availability = array();
5174 $langs->load(
'propal');
5176 $sql =
"SELECT rowid, code, label, position";
5177 $sql .=
" FROM " . $this->db->prefix() .
'c_availability';
5178 $sql .=
" WHERE active > 0";
5180 $resql = $this->db->query($sql);
5182 $num = $this->db->num_rows($resql);
5185 $obj = $this->db->fetch_object($resql);
5188 $label = ($langs->trans(
"AvailabilityType" . $obj->code) !=
"AvailabilityType" . $obj->code ? $langs->trans(
"AvailabilityType" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
5189 $this->cache_availability[$obj->rowid][
'code'] = (
string) $obj->code;
5190 $this->cache_availability[$obj->rowid][
'label'] = (
string) $label;
5191 $this->cache_availability[$obj->rowid][
'position'] = (int) $obj->position;
5196 $this->cache_availability =
dol_sort_array($this->cache_availability,
'position',
'asc', 0, 0, 1);
5216 public function selectAvailabilityDelay($selected =
'', $htmlname =
'availid', $filtertype =
'', $addempty = 0, $morecss =
'', $noouput = 0)
5218 global $langs, $user;
5222 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
5224 $out =
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
5226 $out .=
'<option value="-1">'.(is_numeric($addempty) ?
' ' : $langs->trans($addempty)).
'</option>';
5228 foreach ($this->cache_availability as
$id => $arrayavailability) {
5229 if ($selected ==
$id) {
5230 $out .=
'<option value="' .
$id .
'" selected>';
5232 $out .=
'<option value="' .
$id .
'">';
5235 $out .=
'</option>';
5237 $out .=
'</select>';
5239 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5256 public function loadCacheInputReason()
5260 $num = count($this->cache_demand_reason);
5265 $sql =
"SELECT rowid, code, label";
5266 $sql .=
" FROM " . $this->db->prefix() .
'c_input_reason';
5267 $sql .=
" WHERE active > 0";
5269 $resql = $this->db->query($sql);
5271 $num = $this->db->num_rows($resql);
5274 $tmparray = array();
5276 $obj = $this->db->fetch_object($resql);
5279 $label = ($obj->label !=
'-' ? (
string) $obj->label :
'');
5280 if ($langs->trans(
"DemandReasonType" . $obj->code) !=
"DemandReasonType" . $obj->code) {
5281 $label = $langs->trans(
"DemandReasonType" . $obj->code);
5283 if ($langs->trans($obj->code) != $obj->code) {
5284 $label = $langs->trans($obj->code);
5287 $tmparray[(int) $obj->rowid]
5289 'id' => (
int) $obj->rowid,
5290 'code' => (
string) $obj->code,
5296 $this->cache_demand_reason =
dol_sort_array($tmparray,
'label',
'asc', 0, 0, 1);
5318 public function selectInputReason($selected =
'', $htmlname =
'demandreasonid', $exclude =
'', $addempty = 0, $morecss =
'', $notooltip = 0)
5320 global $langs, $user;
5322 $this->loadCacheInputReason();
5324 print
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
5326 print
'<option value="0"' . (empty($selected) ?
' selected' :
'') .
'> </option>';
5328 foreach ($this->cache_demand_reason as
$id => $arraydemandreason) {
5329 if ($arraydemandreason[
'code'] == $exclude) {
5333 if ($selected && ($selected == $arraydemandreason[
'id'] || $selected == $arraydemandreason[
'code'])) {
5334 print
'<option value="' . $arraydemandreason[
'id'] .
'" selected>';
5336 print
'<option value="' . $arraydemandreason[
'id'] .
'">';
5338 $label = $arraydemandreason[
'label'];
5339 print $langs->trans($label);
5343 if ($user->admin && empty($notooltip)) {
5344 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5359 global $langs, $hookmanager;
5361 $num = count($this->cache_types_paiements);
5368 $this->cache_types_paiements = array();
5370 $sql =
"SELECT id, code, libelle as label, type, entity, active";
5371 $sql .=
" FROM " . $this->db->prefix() .
"c_paiement";
5372 $sql .=
" WHERE entity IN (" .
getEntity(
'c_paiement') .
")";
5374 $resql = $this->db->query($sql);
5376 $num = $this->db->num_rows($resql);
5379 $obj = $this->db->fetch_object($resql);
5382 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) !=
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
5383 $this->cache_types_paiements[(int) $obj->id][
'id'] = (
int) $obj->id;
5384 $this->cache_types_paiements[(int) $obj->id][
'code'] = (
string) $obj->code;
5385 $this->cache_types_paiements[(int) $obj->id][
'label'] = (
string) $label;
5386 $this->cache_types_paiements[(int) $obj->id][
'type'] = (
int) $obj->type;
5387 $this->cache_types_paiements[(int) $obj->id][
'entity'] = (
int) $obj->entity;
5388 $this->cache_types_paiements[(int) $obj->id][
'active'] = (
int) $obj->active;
5392 $parameters = array(
'context' =>
'paymenttype');
5393 $reshook = $hookmanager->executeHooks(
'loadDictionaryCache', $parameters, $this);
5394 if (empty($reshook)) {
5395 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
5396 $this->cache_types_paiements = array_merge($this->cache_types_paiements, $hookmanager->resArray);
5399 $this->cache_types_paiements = $hookmanager->resArray;
5402 $this->cache_types_paiements =
dol_sort_array($this->cache_types_paiements,
'label',
'asc', 0, 0, 1);
5432 public function select_conditions_paiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1, $noprint = 0)
5436 if (empty($noprint)) {
5460 public function getSelectConditionsPaiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1)
5462 global $langs, $user;
5465 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
5470 if (empty($selected) && strpos($htmlname,
'search_') !== 0 &&
getDolGlobalInt(
'MAIN_DEFAULT_PAYMENT_TERM_ID')) {
5471 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TERM_ID", LOG_NOTICE);
5475 $out .=
'<select id="' . $htmlname .
'" class="flat selectpaymentterms' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
5477 $out .=
'<option value="0"> </option>';
5480 $selectedDepositPercent =
null;
5482 foreach ($this->cache_conditions_paiements as
$id => $arrayconditions) {
5483 if ($filtertype <= 0 && !empty($arrayconditions[
'deposit_percent'])) {
5487 if ($selected ==
$id) {
5488 $selectedDepositPercent = $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'];
5489 $out .=
'<option value="' .
$id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'" selected>';
5491 $out .=
'<option value="' .
$id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'">';
5493 $label = $arrayconditions[
'label'];
5495 if (!empty($arrayconditions[
'deposit_percent'])) {
5496 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'], $label);
5500 $out .=
'</option>';
5502 $out .=
'</select>';
5503 if ($user->admin && empty($noinfoadmin)) {
5504 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5508 if ($deposit_percent >= 0) {
5509 $out .=
' <span id="' . $htmlname .
'_deposit_percent_container"' . (empty($selectedDepositPercent) ?
' style="display: none"' :
'') .
'>';
5510 $out .= $langs->trans(
'DepositPercent') .
' : ';
5511 $out .=
'<input id="' . $htmlname .
'_deposit_percent" name="' . $htmlname .
'_deposit_percent" class="maxwidth50" value="' . $deposit_percent .
'" />';
5514 <script nonce="' .
getNonce() .
'">
5515 $(document).ready(function () {
5516 $("#' . $htmlname .
'").change(function () {
5517 let $selected = $(this).find("option:selected");
5518 let depositPercent = $selected.attr("data-deposit_percent");
5520 if (depositPercent.length > 0) {
5521 $("#' . $htmlname .
'_deposit_percent_container").show().find("#' . $htmlname .
'_deposit_percent").val(depositPercent);
5523 $("#' . $htmlname .
'_deposit_percent_container").hide();
5552 $out .=
'<select id="' . $htmlname .
'" class="flat selectbillingterm" name="' . $htmlname .
'">';
5554 $out .=
'<option value="-1"> </option>';
5558 foreach ($this->cache_rule_for_lines_dates as $rule_for_lines_dates_key => $rule_for_lines_dates_name) {
5559 if ($selected == $rule_for_lines_dates_key) {
5560 $out .=
'<option value="' . $rule_for_lines_dates_key .
'" selected>';
5562 $out .=
'<option value="' . $rule_for_lines_dates_key .
'">';
5565 $out .= $langs->trans($rule_for_lines_dates_name);
5566 $out .=
'</option>';
5568 $out .=
'</select>';
5594 public function select_types_paiements($selected =
'', $htmlname =
'paiementtype', $filtertype =
'', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'', $nooutput = 0)
5597 global $langs, $user;
5601 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $filtertype .
", " . $format, LOG_DEBUG);
5603 $filterarray = array();
5604 if ($filtertype ==
'CRDT') {
5605 $filterarray = array(0, 2, 3);
5606 } elseif ($filtertype ==
'DBIT') {
5607 $filterarray = array(1, 2, 3);
5608 } elseif ($filtertype !=
'' && $filtertype !=
'-1') {
5609 $filterarray = explode(
',', $filtertype);
5615 if (empty($selected) && strpos($htmlname,
'search_') !== 0 &&
getDolGlobalString(
'MAIN_DEFAULT_PAYMENT_TYPE_ID')) {
5616 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TYPE_ID", LOG_NOTICE);
5620 $out .=
'<select id="select' . $htmlname .
'" class="flat selectpaymenttypes' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
5622 $out .=
'<option value=""> </option>';
5624 foreach ($this->cache_types_paiements as
$id => $arraytypes) {
5626 if ($active >= 0 && $arraytypes[
'active'] != $active) {
5631 if (count($filterarray) && !in_array($arraytypes[
'type'], $filterarray)) {
5636 if ($empty && empty($arraytypes[
'code'])) {
5641 $out .=
'<option value="' .
$id .
'" data-code="'.$arraytypes[
'code'].
'"';
5642 } elseif ($format == 1) {
5643 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
5644 } elseif ($format == 2) {
5645 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
5646 } elseif ($format == 3) {
5647 $out .=
'<option value="' .
$id .
'"';
5650 if ($format == 1 || $format == 2) {
5651 if ($selected == $arraytypes[
'code']) {
5652 $out .=
' selected';
5655 if ($selected ==
$id) {
5656 $out .=
' selected';
5662 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
5663 } elseif ($format == 1) {
5664 $value = $arraytypes[
'code'];
5665 } elseif ($format == 2) {
5666 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
5667 } elseif ($format == 3) {
5668 $value = $arraytypes[
'code'];
5670 $out .= $value ? $value :
' ';
5671 $out .=
'</option>';
5673 $out .=
'</select>';
5674 if ($user->admin && !$noadmininfo) {
5675 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5679 if (empty($nooutput)) {
5699 $return =
'<select class="flat maxwidth100" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
5701 'HT' => $langs->trans(
"HT"),
5702 'TTC' => $langs->trans(
"TTC")
5704 foreach ($options as
$id => $value) {
5705 if ($selected ==
$id) {
5706 $return .=
'<option value="' .
$id .
'" selected>' . $value;
5708 $return .=
'<option value="' .
$id .
'">' . $value;
5710 $return .=
'</option>';
5712 $return .=
'</select>';
5732 $num = count($this->cache_transport_mode);
5739 $this->cache_transport_mode = array();
5741 $sql =
"SELECT rowid, code, label, active";
5742 $sql .=
" FROM " . $this->db->prefix() .
"c_transport_mode";
5743 $sql .=
" WHERE entity IN (" .
getEntity(
'c_transport_mode') .
")";
5745 $resql = $this->db->query($sql);
5747 $num = $this->db->num_rows($resql);
5750 $obj = $this->db->fetch_object($resql);
5753 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) !=
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
5754 $this->cache_transport_mode[(int) $obj->rowid]
5756 'rowid' => (
int) $obj->rowid,
5757 'code' => (
string) $obj->code,
5758 'label' => (
string) $label,
5759 'active' => (int) $obj->active,
5764 $this->cache_transport_mode =
dol_sort_array($this->cache_transport_mode,
'label',
'asc', 0, 0, 1);
5786 public function selectTransportMode($selected =
'', $htmlname =
'transportmode', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'')
5788 global $langs, $user;
5790 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $format, LOG_DEBUG);
5794 print
'<select id="select' . $htmlname .
'" class="flat selectmodetransport' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
5796 print
'<option value=""> </option>';
5798 foreach ($this->cache_transport_mode as
$id => $arraytypes) {
5800 if ($active >= 0 && $arraytypes[
'active'] != $active) {
5805 if ($empty && empty($arraytypes[
'code'])) {
5810 print
'<option value="' .
$id .
'"';
5811 } elseif ($format == 1) {
5812 print
'<option value="' . $arraytypes[
'code'] .
'"';
5813 } elseif ($format == 2) {
5814 print
'<option value="' . $arraytypes[
'code'] .
'"';
5815 } elseif ($format == 3) {
5816 print
'<option value="' .
$id .
'"';
5819 if (preg_match(
'/[a-z]/i', $selected) && $selected == $arraytypes[
'code']) {
5821 } elseif ($selected ==
$id) {
5827 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
5828 } elseif ($format == 1) {
5829 $value = $arraytypes[
'code'];
5830 } elseif ($format == 2) {
5831 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
5832 } elseif ($format == 3) {
5833 $value = $arraytypes[
'code'];
5835 print $value ? $value :
' ';
5842 if ($user->admin && !$noadmininfo) {
5843 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5859 public function selectShippingMethod($selected =
'', $htmlname =
'shipping_method_id', $filtre =
'', $useempty = 0, $moreattrib =
'', $noinfoadmin = 0, $morecss =
'')
5861 global $langs, $user;
5863 $langs->loadLangs(array(
"admin",
"sendings"));
5865 $sql =
"SELECT rowid, code, libelle as label";
5866 $sql .=
" FROM " . $this->db->prefix() .
"c_shipment_mode";
5867 $sql .=
" WHERE active > 0";
5871 $sql .=
" ORDER BY libelle ASC";
5873 dol_syslog(get_class($this) .
"::selectShippingMode", LOG_DEBUG);
5875 $result = $this->db->query($sql);
5877 $num = $this->db->num_rows($result);
5880 print
'<select id="select' . $htmlname .
'" class="flat selectshippingmethod' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5881 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5882 print
'<option value="-1"> </option>';
5885 $obj = $this->db->fetch_object($result);
5886 if ($selected == $obj->rowid) {
5887 print
'<option value="' . $obj->rowid .
'" selected>';
5889 print
'<option value="' . $obj->rowid .
'">';
5891 print ($langs->trans(
"SendingMethod" . strtoupper($obj->code)) !=
"SendingMethod" . strtoupper($obj->code)) ? $langs->trans(
"SendingMethod" . strtoupper($obj->code)) : $obj->label;
5896 if ($user->admin && empty($noinfoadmin)) {
5897 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5902 print $langs->trans(
"NoShippingMethodDefined");
5922 $langs->load(
"sendings");
5924 if ($htmlname !=
"none") {
5925 print
'<form method="POST" action="' . $page .
'">';
5926 print
'<input type="hidden" name="action" value="setshippingmethod">';
5927 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5929 print
'<input type="submit" class="button valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5933 $code = $langs->getLabelFromKey($this->db, $selected,
'c_shipment_mode',
'rowid',
'code');
5934 print $langs->trans(
"SendingMethod" . strtoupper($code));
5953 $langs->load(
'bills');
5957 $sql =
"SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc";
5958 $sql .=
' FROM ' . $this->db->prefix() .
'facture';
5959 $sql .=
' WHERE entity IN (' .
getEntity(
'invoice') .
')';
5960 $sql .=
' AND situation_counter >= 1';
5961 $sql .=
' AND fk_soc = ' . (int) $socid;
5962 $sql .=
' AND type <> 2';
5963 $sql .=
' ORDER by situation_cycle_ref, situation_counter desc';
5964 $resql = $this->db->query($sql);
5966 $nbSituationInvoiceForThirdparty = 0;
5968 if ($resql && $this->db->num_rows($resql) > 0) {
5971 while ($obj = $this->db->fetch_object($resql)) {
5973 if ($obj->situation_cycle_ref != $ref) {
5975 $ref = $obj->situation_cycle_ref;
5977 if ($obj->situation_final != 1) {
5979 if (substr($obj->ref, 1, 4) !=
'PROV') {
5980 $nbSituationInvoiceForThirdparty++;
5982 if ($selected == $obj->rowid) {
5983 $opt .=
'<option value="' . $obj->rowid .
'" selected>' . $obj->ref .
'</option>';
5985 $opt .=
'<option value="' . $obj->rowid .
'">' . $obj->ref .
'</option>';
5992 dol_syslog(
"Error sql=" . $sql .
", error=" . $this->error, LOG_ERR);
5995 if ($nbSituationInvoiceForThirdparty > 0) {
5996 $opt =
'<option class="minwidth100" value="" selected> </option>'.$opt;
5998 $opt =
'<option class="minwidth100" value="-1" selected>'.$langs->trans(
'NoSituations').
'</option>';
6013 public function selectUnits($selected =
'', $htmlname =
'units', $showempty = 0, $unit_type =
'')
6017 $langs->load(
'products');
6019 $return =
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'">';
6021 $sql =
"SELECT rowid, label, code FROM " . $this->db->prefix() .
"c_units";
6022 $sql .=
' WHERE active > 0';
6023 if (!empty($unit_type)) {
6024 $sql .=
" AND unit_type = '" . $this->db->escape($unit_type) .
"'";
6026 $sql .=
" ORDER BY sortorder";
6028 $resql = $this->db->query($sql);
6029 if ($resql && $this->db->num_rows($resql) > 0) {
6031 $return .=
'<option value="-1"></option>';
6034 while ($res = $this->db->fetch_object($resql)) {
6035 $unitLabel = $res->label;
6036 if (!empty($langs->tab_translate[
'unit' . $res->code])) {
6037 $unitLabel = $langs->trans(
'unit' . $res->code) != $res->label ? $langs->trans(
'unit' . $res->code) : $res->label;
6040 if ($selected == $res->rowid) {
6041 $return .=
'<option value="' . $res->rowid .
'" selected>' . $unitLabel .
'</option>';
6043 $return .=
'<option value="' . $res->rowid .
'">' . $unitLabel .
'</option>';
6046 $return .=
'</select>';
6070 public function select_comptes($selected =
'', $htmlname =
'accountid', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'', $showcurrency = 0, $morecss =
'', $nooutput = 0, $addentrynone = 0)
6077 $langs->loadLangs(array(
"admin",
"banks"));
6080 $sql =
"SELECT rowid, label, bank, clos as status, currency_code";
6081 $sql .=
" FROM " . $this->db->prefix() .
"bank_account";
6082 $sql .=
" WHERE entity IN (" .
getEntity(
'bank_account') .
")";
6084 $sql .=
" AND clos = " . (int) $status;
6089 $sql .=
" ORDER BY label";
6091 dol_syslog(get_class($this) .
"::select_comptes", LOG_DEBUG);
6092 $result = $this->db->query($sql);
6094 $num = $this->db->num_rows($result);
6097 $out .=
'<select id="select' . $htmlname .
'" class="flat selectbankaccount' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
6101 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoActiveBankAccountDefined") .
'</span>';
6103 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoBankAccountDefined") .
'</span>';
6106 if (!empty($useempty) && !is_numeric($useempty)) {
6107 $out .=
'<option value="-1">'.$langs->trans($useempty).
'</option>';
6108 } elseif ($useempty == 1 || ($useempty == 2 && $num > 1)) {
6109 $out .=
'<option value="-1"> </option>';
6114 $obj = $this->db->fetch_object($result);
6116 $labeltoshow = trim($obj->label);
6117 $labeltoshowhtml = trim($obj->label);
6118 if ($showcurrency) {
6119 $labeltoshow .=
' (' . $obj->currency_code .
')';
6120 $labeltoshowhtml .=
' <span class="opacitymedium">(' . $obj->currency_code .
')</span>';
6122 if ($status == 2 && $obj->status == 1) {
6123 $labeltoshow .=
' (' . $langs->trans(
"Closed") .
')';
6124 $labeltoshowhtml .=
' <span class="opacitymedium">(' . $langs->trans(
"Closed") .
')</span>';
6127 if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
6128 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml).
'" selected>';
6130 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml).
'">';
6132 $out .= $labeltoshow;
6133 $out .=
'</option>';
6137 if (!empty($addentrynone)) {
6138 $out .=
'<option value="-2"'.($selected == -2 ?
' selected="selected"' :
'').
' data-html="'.
dolPrintHTMLForAttribute(
'<span class="opacitymedium">'.$langs->trans(
"None").
'</span>').
'">'.$langs->trans(
"None").
'</option>';
6141 $out .=
"</select>";
6148 if (empty($nooutput)) {
6170 public function selectRib($selected =
'', $htmlname =
'ribcompanyid', $filtre =
'', $useempty = 0, $moreattrib =
'', $showibanbic = 0, $morecss =
'', $nooutput = 0)
6177 $langs->loadLangs(array(
"admin",
"banks"));
6180 $sql =
"SELECT rowid, label, bank, status, iban_prefix, bic, default_rib";
6181 $sql .=
" FROM " . $this->db->prefix() .
"societe_rib";
6182 $sql .=
" WHERE type = 'ban'";
6186 $sql .=
" ORDER BY label";
6187 dol_syslog(get_class($this) .
"::select_comptes", LOG_DEBUG);
6188 $result = $this->db->query($sql);
6190 $num = $this->db->num_rows($result);
6193 $out .=
'<select id="select' . $htmlname .
'" class="flat selectbankaccount' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
6196 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoBankAccountDefined") .
'</span>';
6198 if (!empty($useempty) && !is_numeric($useempty)) {
6199 $out .=
'<option value="-1">'.$langs->trans($useempty).
'</option>';
6200 } elseif ($useempty == 1 || ($useempty == 2 && $num > 1)) {
6201 $out .=
'<option value="-1"> </option>';
6206 $obj = $this->db->fetch_object($result);
6208 if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
6209 $out .=
'<option value="' . $obj->rowid .
'" data-iban-prefix="' . $iban .
' data-bic="' . $obj->bic .
'" selected>';
6211 $out .=
'<option value="' . $obj->rowid .
'" data-iban-prefix="' . $iban .
' data-bic="' . $obj->bic .
'">';
6213 $out .= trim($obj->label);
6215 $out .=
' (' . $iban .
'/' .$obj->bic.
')' . ($obj->default_rib ?
' ['.$langs->trans(
"ByDefault").
']' :
'');
6217 $out .=
'</option>';
6220 $out .=
"</select>";
6227 if (empty($nooutput)) {
6247 public function selectEstablishments($selected =
'', $htmlname =
'entity', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'')
6251 $langs->load(
"admin");
6254 $sql =
"SELECT rowid, name, fk_country, status, entity";
6255 $sql .=
" FROM " . $this->db->prefix() .
"establishment";
6256 $sql .=
" WHERE 1=1";
6258 $sql .=
" AND status = " . (int) $status;
6263 $sql .=
" ORDER BY name";
6265 dol_syslog(get_class($this) .
"::select_establishment", LOG_DEBUG);
6266 $result = $this->db->query($sql);
6268 $num = $this->db->num_rows($result);
6271 print
'<select id="select' . $htmlname .
'" class="flat selectestablishment" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
6272 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
6273 print
'<option value="-1"> </option>';
6277 $obj = $this->db->fetch_object($result);
6278 if ($selected == $obj->rowid) {
6279 print
'<option value="' . $obj->rowid .
'" selected>';
6281 print
'<option value="' . $obj->rowid .
'">';
6283 print trim($obj->name);
6284 if ($status == 2 && $obj->status == 1) {
6285 print
' (' . $langs->trans(
"Closed") .
')';
6293 print
'<span class="opacitymedium">' . $langs->trans(
"NoActiveEstablishmentDefined") .
'</span>';
6295 print
'<span class="opacitymedium">' . $langs->trans(
"NoEstablishmentFound") .
'</span>';
6318 if ($htmlname !=
"none") {
6319 print
'<form method="POST" action="' . $page .
'">';
6320 print
'<input type="hidden" name="action" value="setbankaccount">';
6321 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6322 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
6323 $nbaccountfound = $this->
select_comptes($selected, $htmlname, 0,
'', $addempty);
6324 if ($nbaccountfound > 0) {
6325 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6329 $langs->load(
'banks');
6332 require_once DOL_DOCUMENT_ROOT .
'/compta/bank/class/account.class.php';
6333 $bankstatic =
new Account($this->db);
6334 $result = $bankstatic->fetch((
int) $selected);
6336 print $bankstatic->getNomUrl(1);
6355 public function formRib($page, $selected =
'', $htmlname =
'ribcompanyid', $filtre =
'', $addempty = 0, $showibanbic = 0)
6358 if ($htmlname !=
"none") {
6359 print
'<form method="POST" action="' . $page .
'">';
6360 print
'<input type="hidden" name="action" value="setbankaccountcustomer">';
6361 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6362 $nbaccountfound = $this->
selectRib($selected, $htmlname, $filtre, $addempty,
'', $showibanbic);
6363 if ($nbaccountfound > 0) {
6364 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6368 $langs->load(
'banks');
6371 require_once DOL_DOCUMENT_ROOT .
'/societe/class/companybankaccount.class.php';
6373 $result = $bankstatic->fetch((
int) $selected);
6375 print $bankstatic->label;
6377 print
' (' . $bankstatic->iban .
'/' .$bankstatic->bic.
')';
6403 $arrayselected = array();
6405 $arrayselected =
GETPOST($htmlname,
'array:int');
6408 $cats =
$c->containing(
$object->id, $categtype);
6409 $arrayselected = array();
6410 foreach ($cats as $cat) {
6411 $arrayselected[] = $cat->id;
6415 $out .=
img_picto(
'',
'category',
'class="pictofixedwidth"');
6416 $out .= $this->
multiselectarray($htmlname, $cate_arbo, $arrayselected, 0, 0,
'minwidth100 widthcentpercentminusxx', 0, 0);
6420 $jsonclose =
'doJsCodeAfterPopupClose'.dol_sanitizeKeyCode($htmlname).
'()';
6421 $urltoopen =
'/categories/categorie_list.php?type='.urlencode($categtype).
'&nosearch=1';
6426 $out .=
'<!-- Add js code to open the popup for category/edit/add -->'.
"\n";
6427 $out .=
'<script>function doJsCodeAfterPopupClose'.dol_sanitizeKeyCode($htmlname).
'() {
6428 console.log("doJsCodeAfterPopupClose'.
dol_sanitizeKeyCode($htmlname).
' has been called, we refresh the combo content + refresh select2...");
6430 // Call an ajax to reload values and update the select
6433 url: \''.DOL_URL_ROOT.
'/core/ajax/fetchCategories.php\',
6435 action: \'getCategories\',
6440 success: function (data) {
6441 var $select = $(\'#'.dol_sanitizeKeyCode($htmlname).
'\');
6442 var selectedValues = $select.val();
6443 console.log(selectedValues);
6445 $.each(data,
function (index, item) {
6446 $select.append(\
'<option value="\' + item.id + \'" data-html="\' + item.htmlforattribute + \'">\' + item.htmlforoption + \'</option>\');
6448 $select.val(selectedValues);
6450 error: function (xhr, status, error) {
6451 console.log("Error when loading ajax page : " + error);
6455 // Refresh select2 to take account of new values (enough for small change)
6458 // Alternative if change in select is complex
6490 public function select_all_categories($type, $selected =
'', $htmlname =
"parent", $maxlength = 64, $fromid = 0, $outputmode = 0, $include = 0, $morecss =
'', $useempty = 1)
6495 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
6499 if (is_numeric($type)) {
6500 $type = array_search($type, $cat->MAP_ID);
6503 $cate_arbo = $cat->get_full_arbo($type, $fromid, $include);
6505 $outarray = array();
6506 $outarrayrichhtml = array();
6509 $output =
'<select class="flat minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
6511 if (is_array($cate_arbo)) {
6512 $num = count($cate_arbo);
6515 $langs->load(
"categories");
6516 $output .=
'<option value="-1" disabled>' . $langs->trans(
"NoCategoriesDefined") .
'</option>';
6518 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
6519 $output .=
'<option value="-1"> </option>';
6521 foreach ($cate_arbo as $key => $value) {
6522 if ($cate_arbo[$key][
'id'] == $selected || ($selected ===
'auto' && count($cate_arbo) == 1)) {
6528 $labeltoshow =
img_picto(
'',
'category',
'class="pictofixedwidth"'.(empty($cate_arbo[$key][
'color']) ?
'' :
' style="color: #' . $cate_arbo[$key][
'color'] .
'"'));
6529 $labeltoshow .=
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle');
6531 $outarray[$cate_arbo[$key][
'id']] = $cate_arbo[$key][
'fulllabel'];
6533 $outarrayrichhtml[$cate_arbo[$key][
'id']] = $labeltoshow;
6535 $output .=
'<option ' . $add .
'value="' . $cate_arbo[$key][
'id'] .
'"';
6544 $output .=
'</option>';
6546 $cate_arbo[$key][
'data-html'] = $labeltoshow;
6550 $output .=
'</select>';
6555 if ($outputmode == 2) {
6558 } elseif ($outputmode == 1) {
6560 } elseif ($outputmode == 3) {
6561 return $outarrayrichhtml;
6581 $html =
'<details class="dolibarr-help-block" style="margin-top:8px;">';
6582 $html .=
'<summary style="cursor:pointer; color:#0056b3; font-weight:normal; list-style:none; font-size:0.9em; display:flex; align-items:center;">';
6583 $html .=
'<span class="fa ' . $icon .
'" style="margin-right:6px;"></span>';
6584 $html .= $langs->trans(
"Help");
6585 $html .=
'</summary>';
6586 $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;">';
6589 $html .=
'</details>';
6614 public function form_confirm($page, $title, $question, $action, $formquestion = array(), $selectedchoice =
"", $useajax = 0, $height = 170, $width = 500)
6617 dol_syslog(__METHOD__ .
': using form_confirm is deprecated. Use formconfim instead.', LOG_WARNING);
6618 print $this->
formconfirm($page, $title, $question, $action, $formquestion, $selectedchoice, $useajax, $height, $width);
6650 public function formconfirm($page, $title, $question, $action, $formquestion =
'', $selectedchoice =
'', $useajax = 0, $height = 0, $width = 600, $disableformtag = 0, $labelbuttonyes =
'Yes', $labelbuttonno =
'No', $helpContent =
'')
6652 global $langs,
$conf;
6655 $formconfirm =
'<!-- formconfirm - before call, page=' .
dol_escape_htmltag($page) .
' -->';
6661 $newselectedchoice = empty($selectedchoice) ?
"no" : $selectedchoice;
6662 if (
$conf->browser->layout ==
'phone') {
6667 if (empty($height)) {
6669 if (is_array($formquestion)) {
6670 $height += (count($formquestion) * 40);
6677 if (is_array($formquestion) && !empty($formquestion)) {
6679 foreach ($formquestion as $key => $input) {
6680 if (is_array($input) && !empty($input)) {
6681 if ($input[
'type'] ==
'hidden') {
6682 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
6683 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
6691 $moreonecolumn =
'';
6692 $more .=
'<div class="tagtable paddingtopbottomonly centpercent noborderspacing">' .
"\n";
6693 foreach ($formquestion as $key => $input) {
6694 if (is_array($input) && !empty($input)) {
6695 $size = (!empty($input[
'size']) ?
' size="' . $input[
'size'] .
'"' :
'');
6696 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
6697 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
6699 if ($input[
'type'] ==
'text' || $input[
'type'] ==
'input') {
6700 $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";
6701 } elseif ($input[
'type'] ==
'password') {
6702 $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";
6703 } elseif ($input[
'type'] ==
'textarea') {
6704 $moreonecolumn .=
'<div class="margintoponly">';
6705 $moreonecolumn .= $input[
'label'] .
'<br>';
6707 $moreonecolumn .= $input[
'value'];
6708 $moreonecolumn .=
'</textarea>';
6709 $moreonecolumn .=
'</div>';
6710 } elseif (in_array($input[
'type'], [
'select',
'multiselect'])) {
6711 if (empty($morecss)) {
6712 $morecss =
'minwidth100';
6715 $show_empty = isset($input[
'select_show_empty']) ? $input[
'select_show_empty'] : 1;
6716 $key_in_label = isset($input[
'select_key_in_label']) ? $input[
'select_key_in_label'] : 0;
6717 $value_as_key = isset($input[
'select_value_as_key']) ? $input[
'select_value_as_key'] : 0;
6718 $translate = isset($input[
'select_translate']) ? $input[
'select_translate'] : 0;
6719 $maxlen = isset($input[
'select_maxlen']) ? $input[
'select_maxlen'] : 0;
6720 $disabled = isset($input[
'select_disabled']) ? $input[
'select_disabled'] : 0;
6721 $sort = isset($input[
'select_sort']) ? $input[
'select_sort'] :
'';
6723 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">';
6724 if (!empty($input[
'label'])) {
6725 $more .= $input[
'label'] .
'</div><div class="tagtd left">';
6727 if ($input[
'type'] ==
'select') {
6728 $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);
6730 $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);
6732 $more .=
'</div></div>' .
"\n";
6733 } elseif ($input[
'type'] ==
'checkbox') {
6734 $more .=
'<div class="tagtr">';
6735 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'"><label for="' .
dol_escape_htmltag($input[
'name']) .
'">' . $input[
'label'] .
'</label></div><div class="tagtd">';
6736 $more .=
'<input type="checkbox" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' .
dol_escape_htmltag($input[
'name']) .
'" name="' .
dol_escape_htmltag($input[
'name']) .
'"' . $moreattr;
6737 if (isset($input[
'value']) && !is_bool($input[
'value']) && $input[
'value'] !=
'false' && $input[
'value'] !=
'0' && $input[
'value'] !=
'') {
6738 $more .=
' checked';
6740 if (isset($input[
'value']) && is_bool($input[
'value']) && $input[
'value']) {
6741 $more .=
' checked';
6743 if (isset($input[
'disabled'])) {
6744 $more .=
' disabled';
6746 $more .=
' /></div>';
6747 $more .=
'</div>' .
"\n";
6748 } elseif ($input[
'type'] ==
'radio') {
6750 foreach ($input[
'values'] as $selkey => $selval) {
6751 $more .=
'<div class="tagtr">';
6752 if (isset($input[
'label'])) {
6754 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
' tdtop' : (
' tdtop ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
6756 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' "' . $input[
'tdclass'])) .
'"> </div>';
6759 $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;
6760 if (!empty($input[
'disabled'])) {
6761 $more .=
' disabled';
6763 if (isset($input[
'default']) && $input[
'default'] === $selkey) {
6764 $more .=
' checked="checked"';
6767 $more .=
'<label for="' .
dol_escape_htmltag($input[
'name'] . $selkey) .
'" class="valignmiddle">' . $selval .
'</label>';
6768 $more .=
'</div></div>' .
"\n";
6771 } elseif ($input[
'type'] ==
'date' || $input[
'type'] ==
'datetime') {
6772 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
6773 $more .=
'<div class="tagtd">';
6774 $addnowlink = (empty($input[
'datenow']) ? 0 : 1);
6776 if ($input[
'type'] ==
'datetime') {
6777 $h = isset($input[
'hours']) ? $input[
'hours'] : 1;
6778 $m = isset($input[
'minutes']) ? $input[
'minutes'] : 1;
6780 $more .= $this->
selectDate(isset($input[
'value']) ? $input[
'value'] : -1, $input[
'name'], $h, $m, 0,
'', 1, $addnowlink);
6781 $more .=
'</div></div>'.
"\n";
6782 $formquestion[] = array(
'name' => $input[
'name'].
'day');
6783 $formquestion[] = array(
'name' => $input[
'name'].
'month');
6784 $formquestion[] = array(
'name' => $input[
'name'].
'year');
6785 $formquestion[] = array(
'name' => $input[
'name'].
'hour');
6786 $formquestion[] = array(
'name' => $input[
'name'].
'min');
6787 } elseif ($input[
'type'] ==
'other') {
6788 $more .=
'<div class="tagtr"><div class="tagtd'.(empty($input[
'tdclass']) ?
'' : (
' '.$input[
'tdclass'])).
'">';
6789 if (!empty($input[
'label'])) {
6790 $more .= $input[
'label'] .
'</div><div class="tagtd">';
6792 if (!empty($input[
'value'])) {
6793 $more .= $input[
'value'];
6795 $more .=
'</div></div>' .
"\n";
6796 } elseif ($input[
'type'] ==
'onecolumn') {
6797 $moreonecolumn .=
'<div class="margintoponly">';
6798 $moreonecolumn .= $input[
'value'];
6799 $moreonecolumn .=
'</div>' .
"\n";
6800 } elseif ($input[
'type'] ==
'hidden') {
6802 } elseif ($input[
'type'] ==
'separator') {
6805 $more .=
'Error type ' . $input[
'type'] .
' for the confirm box is not a supported type';
6809 $more .=
'</div>' .
"\n";
6810 $more .= $moreonecolumn;
6816 if (!empty(
$conf->dol_use_jmobile)) {
6819 if (empty(
$conf->use_javascript_ajax)) {
6825 $dialogconfirm =
'dialog-confirm';
6827 if (!is_numeric($useajax)) {
6831 $dialogconfirm .=
'-' . $button;
6833 $pageyes = $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=yes';
6834 $pageno = ($useajax == 2 ? $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=no' :
'');
6837 if (is_array($formquestion)) {
6838 foreach ($formquestion as $key => $input) {
6841 if (is_array($input) && isset($input[
'name'])) {
6842 if (strpos($input[
'name'],
',') > 0) {
6843 $inputok = array_merge($inputok, explode(
',', $input[
'name']));
6845 array_push($inputok, $input[
'name']);
6850 if (is_array($input) && isset($input[
'inputko']) && $input[
'inputko'] == 1 && isset($input[
'name'])) {
6851 array_push($inputko, $input[
'name']);
6858 $formconfirm .=
'<div id="' . $dialogconfirm .
'" title="' .
dol_escape_htmltag($title) .
'" style="display: none;">';
6859 $formconfirm .=
'<div style="display: flex; flex-direction: column; height: 100%;">';
6860 if (is_array($formquestion) && array_key_exists(
'text', $formquestion) && !empty($formquestion[
'text'])) {
6861 $formconfirm .=
'<div class="confirmtext">' . $formquestion[
'text'] .
'</div>' .
"\n";
6863 if (!empty($more)) {
6864 $formconfirm .=
'<div class="confirmquestions">' . $more .
'</div>' .
"\n";
6867 if (!empty($helpContent)) {
6868 $formconfirm .=
'<div style="text-align:left; margin-top:12px; padding-top:8px; border-top:1px solid #eee; clear:both;">';
6870 $formconfirm .=
'</div>';
6872 if (!empty($question)) {
6873 $formconfirm .=
'<div class="confirmmessage" style="padding-top: 15px;">';
6874 $formconfirm .=
img_help(0,
'') .
' ' . $question;
6875 $formconfirm .=
'</div>';
6877 $formconfirm .=
'</div>';
6878 $formconfirm .=
'</div>' .
"\n";
6880 $formconfirm .=
"\n<!-- begin code of popup for formconfirm page=" . $page .
" -->\n";
6881 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
6882 $formconfirm .=
"/* Code for the jQuery('#dialogforpopup').dialog() */\n";
6883 $formconfirm .=
'jQuery(document).ready(function() {
6885 $( "#' . $dialogconfirm .
'" ).dialog({
6886 autoOpen: ' . ($autoOpen ?
"true" :
"false") .
',';
6887 if ($newselectedchoice ==
'no') {
6890 $(this).parent().find("button.ui-button:eq(2)").focus();
6895 if ($useajax == 1) {
6896 $jsforcursor =
'// The call to urljump can be slow, so we set the wait cursor' .
"\n";
6897 $jsforcursor .=
'jQuery("html,body,#id-container").addClass("cursorwait");' .
"\n";
6900 $postconfirmas =
'GET';
6907 closeOnEscape:
false,
6909 "' . dol_escape_js($langs->transnoentities($labelbuttonyes)) . '":
function() {
6910 var options =
"token=' . urlencode(newToken()) . '";
6911 var inputok =
' . json_encode($inputok) . ';
6912 var page = \
'' .
dol_escape_js(!empty($page) ? $page :
'') .
'\';
6913 var pageyes = \
'' .
dol_escape_js(!empty($pageyes) ? $pageyes :
'') .
'\';
6915 if (inputok.length > 0) {
6916 $.each(inputok,
function(i, inputname) {
6919 if ($(
"input[name=\'" + inputname +
"\']").attr(
"type") ==
"radio") {
6920 inputvalue = $(
"input[name=\'" + inputname +
"\']:checked").val();
6922 if ($(
"#" + inputname).attr(
"type") ==
"checkbox") { more =
":checked"; }
6923 inputvalue = $(
"#" + inputname + more).val();
6925 if (typeof inputvalue ==
"undefined") { inputvalue=
""; }
6926 console.log(
"formconfirm check inputname="+inputname+
" inputvalue="+inputvalue);
6927 options +=
"&" + inputname +
"=" + encodeURIComponent(inputvalue);
6930 var urljump = pageyes + (pageyes.indexOf(
"?") < 0 ?
"?" :
"&") + options;
6931 if (pageyes.length > 0) {
';
6932 if ($postconfirmas == 'GET
') {
6933 $formconfirm .= 'location.href = urljump;
';
6935 $formconfirm .= $jsforcursor;
6936 $formconfirm .= 'var post = $.post(
6939 function(data) { $(
"body").html(data); jQuery(
"html,body,#id-container").removeClass(
"cursorwait"); }
6943 console.log(
"after post ok");
6945 $(
this).dialog(
"close");
6947 "' . dol_escape_js($langs->transnoentities($labelbuttonno)) . '":
function() {
6948 var options =
"token=' . urlencode(newToken()) . '";
6949 var inputko =
' . json_encode($inputko) . ';
6950 var page =
"' . dol_escape_js(!empty($page) ? $page : '') . '";
6951 var pageno=
"' . dol_escape_js(!empty($pageno) ? $pageno : '') . '";
6952 if (inputko.length > 0) {
6953 $.each(inputko,
function(i, inputname) {
6955 if ($(
"#" + inputname).attr(
"type") ==
"checkbox") { more =
":checked"; }
6956 var inputvalue = $(
"#" + inputname + more).val();
6957 if (typeof inputvalue ==
"undefined") { inputvalue=
""; }
6958 options +=
"&" + inputname +
"=" + encodeURIComponent(inputvalue);
6961 var urljump=pageno + (pageno.indexOf(
"?") < 0 ?
"?" :
"&") + options;
6963 if (pageno.length > 0) {
';
6964 if ($postconfirmas == 'GET
') {
6965 $formconfirm .= 'location.href = urljump;
';
6967 $formconfirm .= $jsforcursor;
6968 $formconfirm .= 'var post = $.post(
6971 function(data) { $(
"body").html(data); jQuery(
"html,body,#id-container").removeClass(
"cursorwait"); }
6975 console.log(
"after post ko");
6977 $(
this).dialog(
"close");
6983 var
button =
"' . $button . '";
6985 $(
"#" +
button ).click(
function() {
6986 $(
"#' . $dialogconfirm . '").dialog(
"open");
6992 $formconfirm .= "<!-- end ajax formconfirm -->\n";
6994 $formconfirm .= "\n<!-- begin formconfirm page=" . dol_escape_htmltag($page) . " -->\n";
6996 if (empty($disableformtag)) {
6997 $formconfirm .= '<form method=
"POST" action=
"' . $page . '" class=
"notoptoleftnoright">
' . "\n";
7000 $formconfirm .= '<input
type=
"hidden" name=
"action" value=
"' . $action . '">
' . "\n";
7001 $formconfirm .= '<input
type=
"hidden" name=
"token" value=
"' . newToken() . '">
' . "\n";
7003 $formconfirm .= '<div
class=
"valid">
' . "\n";
7006 $formconfirm .= '<div
class=
"validtitre">
';
7007 $formconfirm .= img_picto('', 'pictoconfirm
') . ' ' . $title;
7008 $formconfirm .= '</div>
' . "\n";
7011 if (is_array($formquestion) && array_key_exists('text
', $formquestion) && !empty($formquestion['text
'])) {
7012 $formconfirm .= '<div
class=
"valid">
' . $formquestion['text
'] . '</div>
' . "\n";
7017 $formconfirm .= '<div>
' . "\n";
7018 $formconfirm .= $more;
7019 $formconfirm .= '</div>
' . "\n";
7022 // NEW: Help block row (between form fields and question)
7023 if (!empty($helpContent)) {
7024 $formconfirm .= '<div style=
"padding-top:8px; border-top:1px solid #888;">
';
7025 $formconfirm .= $this->getHelpBlock($helpContent);
7026 $formconfirm .= '</div>
' . "\n";
7029 // Let's add a row that acts as a spacer.
7030 $formconfirm .=
'<div style="padding-top: 20px;"></div>' .
"\n";
7033 $formconfirm .=
'<div class="inline-block">' . $question .
'</div>';
7035 $formconfirm .=
'<div class="inline-block">';
7036 $formconfirm .= $this->selectyesno(
"confirm", $newselectedchoice, 0,
false, 0, 0,
'marginleftonly marginrightonly', $labelbuttonyes, $labelbuttonno);
7037 $formconfirm .=
'<input class="button valignmiddle confirmvalidatebutton small" type="submit" value="' . $langs->trans(
"Validate") .
'">';
7038 $formconfirm .=
'</div>';
7040 $formconfirm .=
'</div>';
7042 if (empty($disableformtag)) {
7043 $formconfirm .=
"</form>\n";
7045 $formconfirm .=
'<br>';
7047 if (!empty(
$conf->use_javascript_ajax)) {
7048 $formconfirm .=
'<!-- code to disable button to avoid double clic -->';
7049 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
7051 $(document).ready(function () {
7052 $(".confirmvalidatebutton").on("click", function() {
7053 console.log("We click on button confirmvalidatebutton");
7054 $(this).attr("disabled", "disabled");
7055 setTimeout(\'$(".confirmvalidatebutton").removeAttr("disabled")\', 3000);
7056 //console.log($(this).closest("form"));
7057 $(this).closest("form").submit();
7061 $formconfirm .=
'</script>' .
"\n";
7064 $formconfirm .=
"<!-- end formconfirm -->\n";
7067 return $formconfirm;
7088 public function form_project($page, $socid, $selected =
'', $htmlname =
'projectid', $discard_closed = 0, $maxlength = 20, $forcefocus = 0, $nooutput = 0, $textifnoproject =
'', $morecss =
'', $option =
'')
7093 require_once DOL_DOCUMENT_ROOT .
'/core/lib/project.lib.php';
7094 require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formprojet.class.php';
7100 $langs->load(
"project");
7101 if ($htmlname !=
"none") {
7102 $out .=
'<form method="post" action="' . $page .
'">';
7103 $out .=
'<input type="hidden" name="action" value="classin">';
7104 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7105 $out .= $formproject->select_projects($socid, $selected, $htmlname, $maxlength, 0, 1, $discard_closed, $forcefocus, 0, 0,
'', 1, 0, $morecss);
7106 $out .=
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7109 $out .=
'<span class="project_head_block">';
7110 if ($selected instanceof
Project) {
7111 $out .= $selected->getNomUrl(0, $option, 1);
7112 } elseif (is_numeric($selected)) {
7113 $projet =
new Project($this->db);
7114 $projet->fetch((
int) $selected);
7115 $out .= $projet->getNomUrl(0, $option, 1);
7117 $out .=
'<span class="opacitymedium">' . $textifnoproject .
'</span>';
7122 if (empty($nooutput)) {
7146 public function form_conditions_reglement($page, $selected =
'', $htmlname =
'cond_reglement_id', $addempty = 0, $type =
'', $filtertype = -1, $deposit_percent = -1, $nooutput = 0)
7151 $selected = (int) $selected;
7155 if ($htmlname !=
"none") {
7156 $out .=
'<form method="POST" action="' . $page .
'">';
7157 $out .=
'<input type="hidden" name="action" value="setconditions">';
7158 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7160 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
7162 $out .= $this->getSelectConditionsPaiements($selected, $htmlname, $filtertype, $addempty, 0,
'', $deposit_percent);
7163 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7167 $this->load_cache_conditions_paiements();
7169 if (isset($this->cache_conditions_paiements[$selected])) {
7170 $label = $this->cache_conditions_paiements[$selected][
'label'];
7172 if (!empty($this->cache_conditions_paiements[$selected][
'deposit_percent'])) {
7173 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $this->cache_conditions_paiements[$selected][
'deposit_percent'], $label);
7178 $langs->load(
'errors');
7179 $out .= $langs->trans(
'ErrorNotInDictionaryPaymentConditions', $selected);
7186 if (empty($nooutput)) {
7212 if ($htmlname !=
'none') {
7213 $out .=
'<form method="POST" action="' . $page .
'">';
7214 $out .=
'<input type="hidden" name="action" value="setruleforlinesdates">';
7215 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7216 $out .= $this->getSelectRuleForLinesDates($selected, $htmlname, $addempty);
7217 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7220 if (isset($selected)) {
7221 $this->load_cache_rule_for_lines_dates();
7222 if (isset($this->cache_rule_for_lines_dates[$selected])) {
7223 $label = $this->cache_rule_for_lines_dates[$selected];
7224 $out .= $langs->trans($label);
7231 if (empty($nooutput)) {
7255 if ($htmlname !=
"none") {
7256 print
'<form method="post" action="' . $page .
'">';
7257 print
'<input type="hidden" name="action" value="setavailability">';
7258 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7259 print $this->selectAvailabilityDelay($selected, $htmlname,
'', $addempty,
'', 1);
7260 print
'<input type="submit" name="modify" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7261 print
'<input type="submit" name="cancel" class="button smallpaddingimp" value="' . $langs->trans(
"Cancel") .
'">';
7265 $this->load_cache_availability();
7267 if (isset($this->cache_availability[$selected])) {
7268 print $this->cache_availability[$selected][
'label'];
7289 public function formInputReason($page, $selected =
'', $htmlname =
'demandreason', $addempty = 0, $morecss =
'')
7292 if ($htmlname !=
"none") {
7293 print
'<form method="post" action="' . $page .
'">';
7294 print
'<input type="hidden" name="action" value="setdemandreason">';
7295 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7296 $this->selectInputReason($selected, $htmlname,
'-1', $addempty, $morecss);
7297 print
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7301 $this->loadCacheInputReason();
7302 foreach ($this->cache_demand_reason as $key => $val) {
7303 if ($val[
'id'] == $selected) {
7304 print $val[
'label'];
7329 public function form_date($page, $selected, $htmlname, $displayhour = 0, $displaymin = 0, $nooutput = 0, $type =
'')
7336 if ($htmlname !=
"none") {
7337 $ret .=
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
7338 $ret .=
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
7339 $ret .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7341 $ret .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
7343 $ret .=
'<table class="nobordernopadding">';
7345 $ret .= $this->selectDate($selected, $htmlname, $displayhour, $displaymin, 1,
'form' . $htmlname, 1, 0);
7347 $ret .=
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
7348 $ret .=
'</tr></table></form>';
7357 if (empty($nooutput)) {
7376 public function form_users($page, $selected =
'', $htmlname =
'userid', $exclude = array(), $include = array())
7381 if ($htmlname !=
"none") {
7382 print
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
7383 print
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
7384 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7385 print $this->select_dolusers($selected, $htmlname, 1, $exclude, 0, $include);
7386 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7390 require_once DOL_DOCUMENT_ROOT .
'/user/class/user.class.php';
7391 $theuser =
new User($this->db);
7392 $theuser->fetch((
int) $selected);
7393 print $theuser->getNomUrl(1);
7416 public function form_modes_reglement($page, $selected =
'', $htmlname =
'mode_reglement_id', $filtertype =
'', $active = 1, $addempty = 0, $type =
'', $nooutput = 0)
7422 if ($htmlname !=
"none") {
7423 $out .=
'<form method="POST" action="' . $page .
'">';
7424 $out .=
'<input type="hidden" name="action" value="setmode">';
7425 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7427 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
7429 $out .= $this->select_types_paiements($selected, $htmlname, $filtertype, 0, $addempty, 0, 0, $active,
'', 1);
7430 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7434 $this->load_cache_types_paiements();
7436 $out .= isset($this->cache_types_paiements[(
int) $selected][
'label']) ? $this->cache_types_paiements[(int) $selected][
'label'] :
'';
7463 if ($htmlname !=
"none") {
7464 print
'<form method="POST" action="' . $page .
'">';
7465 print
'<input type="hidden" name="action" value="settransportmode">';
7466 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7467 $this->selectTransportMode($selected, $htmlname, 0, $addempty, 0, 0, $active);
7468 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7472 $this->load_cache_transport_mode();
7473 print $this->cache_transport_mode[$selected][
'label'];
7494 if ($htmlname !=
"none") {
7495 print
'<form method="POST" action="' . $page .
'">';
7496 print
'<input type="hidden" name="action" value="setmulticurrencycode">';
7497 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7498 print $this->selectMultiCurrency($selected, $htmlname, 0);
7499 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7502 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
7503 print !empty($selected) ?
currency_name($selected, 1) :
' ';
7522 global $langs,
$conf;
7524 if ($htmlname !=
"none") {
7525 print
'<form method="POST" action="' . $page .
'">';
7526 print
'<input type="hidden" name="action" value="setmulticurrencyrate">';
7527 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7528 print
'<input type="text" class="maxwidth75" name="' . $htmlname .
'" value="' . (!empty($rate) ?
price(
price2num($rate,
'CU')) : 1) .
'" spellcheck="false" /> ';
7529 print
'<select name="calculation_mode" id="calculation_mode">';
7530 print
'<option value="1">Change ' . $langs->trans(
"PriceUHT") .
' of lines</option>';
7531 print
'<option value="2">Change ' . $langs->trans(
"PriceUHTCurrency") .
' of lines</option>';
7534 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7537 if (!empty($rate)) {
7538 print
price($rate, 1, $langs, 0, 0);
7539 if ($currency && $rate != 1) {
7546 print
' <span class="opacitymedium">(' .
price($rate_direct, 1, $langs, 0, 0) .
' ' .
$conf->currency .
' = 1 ' . $currency .
')</span>';
7548 print
' <span class="opacitymedium">(' .
price($rate, 1, $langs, 0, 0) .
' ' . $currency .
' = 1 ' .
$conf->currency .
')</span>';
7576 public function form_remise_dispo($page, $selected, $htmlname, $socid, $amount, $filter =
'', $maxvalue = 0, $more =
'', $hidelist = 0, $discount_type = 0, $filterabsolutediscount = 0, $filtercreditnote = 0)
7579 global
$conf, $langs;
7581 if ($htmlname !=
"none") {
7582 print
'<form method="post" action="' . $page .
'" class="inline-block">';
7583 print
'<input type="hidden" name="action" value="setabsolutediscount">';
7584 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7585 print
'<div class="inline-block">';
7586 if (!empty($discount_type)) {
7588 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL") {
7589 $translationKey =
'HasAbsoluteDiscountFromSupplier';
7591 $translationKey =
'HasCreditNoteFromSupplier';
7594 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
7595 $translationKey =
'HasAbsoluteDiscountFromSupplier';
7597 $translationKey =
'HasCreditNoteFromSupplier';
7602 if (!$filter || $filter ==
"fk_facture_source IS NULL") {
7603 $translationKey =
'CompanyHasAbsoluteDiscount';
7605 $translationKey =
'CompanyHasCreditNote';
7608 if (!$filter || $filter ==
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
7609 $translationKey =
'CompanyHasAbsoluteDiscount';
7611 $translationKey =
'CompanyHasCreditNote';
7615 print $langs->trans($translationKey,
price($amount, 0, $langs, 0, 0, -1,
$conf->currency));
7616 if (empty($hidelist)) {
7620 if (empty($hidelist)) {
7621 print
'<div class="inline-block" style="padding-right: 10px">';
7622 $newfilter =
'discount_type = ' . intval($discount_type);
7623 if (!empty($discount_type)) {
7624 $newfilter .=
' AND fk_invoice_supplier IS NULL AND fk_invoice_supplier_line IS NULL';
7626 $newfilter .=
' AND fk_facture IS NULL AND fk_facture_line IS NULL';
7629 $sanitizedfilter = $filter;
7630 $newfilter .=
' AND (' . $sanitizedfilter .
')';
7633 $nbqualifiedlines = $this->select_remises((
string) $selected, $htmlname, $newfilter, $socid, $maxvalue);
7634 if ($nbqualifiedlines > 0) {
7635 print
' <input type="submit" class="button smallpaddingimp" value="' .
dol_escape_htmltag($langs->trans(
"UseLine")) .
'"';
7636 if (!empty($discount_type) && $filter && $filter !=
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
7637 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
7639 if (empty($discount_type) && $filter && $filter !=
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
7640 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
7648 print
'<div class="inline-block">';
7674 public function form_contacts($page, $societe, $selected =
'', $htmlname =
'contactid')
7679 if ($htmlname !=
"none") {
7680 print
'<form method="post" action="' . $page .
'">';
7681 print
'<input type="hidden" name="action" value="set_contact">';
7682 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7683 print
'<table class="nobordernopadding">';
7685 print $this->selectcontacts($societe->id, $selected, $htmlname);
7688 $addcontact = (
getDolGlobalString(
'SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans(
"AddContact") : $langs->trans(
"AddContactAddress"));
7689 print
'<a href="' . DOL_URL_ROOT .
'/contact/card.php?socid=' . $societe->id .
'&action=create&backtoreferer=1">' . $addcontact .
'</a>';
7692 print
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
7693 print
'</tr></table></form>';
7696 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
7697 $contact =
new Contact($this->db);
7698 $contact->fetch((
int) $selected);
7699 print $contact->getFullName($langs);
7724 public function form_thirdparty($page, $selected =
'', $htmlname =
'socid', $filter =
'', $showempty = 0, $showtype = 0, $forcecombo = 0, $events = array(), $nooutput = 0, $excludeids = array(), $textifnothirdparty =
'')
7730 if ($htmlname !=
"none") {
7733 $out .=
'<form method="post" action="' . $page .
'">';
7734 $out .=
'<input type="hidden" name="action" value="set_thirdparty">';
7735 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7736 $out .= $this->select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, $limit,
'minwidth100',
'',
'', 1, array(),
false, $excludeids);
7737 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7741 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
7742 $soc =
new Societe($this->db);
7743 $soc->fetch((
int) $selected);
7744 $out .= $soc->getNomUrl(0,
'');
7746 $out .=
'<span class="opacitymedium">' . $textifnothirdparty .
'</span>';
7772 print $this->selectCurrency($selected, $htmlname);
7784 public function selectCurrency($selected =
'', $htmlname =
'currency_id', $mode = 0, $useempty =
'')
7786 global $langs, $user;
7788 $langs->loadCacheCurrencies(
'');
7792 if ($selected ==
'euro' || $selected ==
'euros') {
7796 $out .=
'<select class="flat maxwidth200onsmartphone minwidth300" name="' . $htmlname .
'" id="' . $htmlname .
'">';
7798 $out .=
'<option value="-1" selected></option>';
7800 foreach ($langs->cache_currencies as $code_iso => $currency) {
7801 $labeltoshow = $currency[
'label'];
7803 $labeltoshow .=
' <span class="opacitymedium">(' . $code_iso .
')</span>';
7804 } elseif ($mode == 2) {
7805 $labeltoshow .=
' <span class="opacitymedium">(' . $code_iso.
' - '.$langs->getCurrencySymbol($code_iso) .
')</span>';
7807 $labeltoshow .=
' <span class="opacitymedium">(' . $langs->getCurrencySymbol($code_iso) .
')</span>';
7810 if ($selected && $selected == $code_iso) {
7811 $out .=
'<option value="' . $code_iso .
'" selected data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
7813 $out .=
'<option value="' . $code_iso .
'" data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
7816 $out .=
'</option>';
7818 $out .=
'</select>';
7820 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
7824 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
7842 public function selectMultiCurrency($selected =
'', $htmlname =
'multicurrency_code', $useempty = 0, $filter =
'', $excludeConfCurrency =
false, $morecss =
'maxwidth200 widthcentpercentminusx')
7844 global
$conf, $langs;
7846 $langs->loadCacheCurrencies(
'');
7848 $TCurrency = array();
7850 $sql =
"SELECT code FROM " . $this->db->prefix() .
"multicurrency";
7851 $sql .=
" WHERE entity IN ('" .
getEntity(
'multicurrency') .
"')";
7855 $resql = $this->db->query($sql);
7857 while ($obj = $this->db->fetch_object($resql)) {
7858 $TCurrency[$obj->code] = $obj->code;
7863 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
7865 $out .=
'<option value=""> </option>';
7868 if (!in_array(
$conf->currency, $TCurrency) && !$excludeConfCurrency) {
7869 $TCurrency[
$conf->currency] =
$conf->currency;
7871 if (count($TCurrency) > 0) {
7872 foreach ($langs->cache_currencies as $code_iso => $currency) {
7873 if (isset($TCurrency[$code_iso])) {
7874 if (!empty($selected) && $selected == $code_iso) {
7875 $out .=
'<option value="' . $code_iso .
'" selected="selected">';
7877 $out .=
'<option value="' . $code_iso .
'">';
7880 $out .= $currency[
'label'];
7881 $out .=
' (' . $langs->getCurrencySymbol($code_iso) .
')';
7882 $out .=
'</option>';
7887 $out .=
'</select>';
7890 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
7907 global $langs, $user;
7909 $num = count($this->cache_vatrates);
7916 $sql =
"SELECT t.rowid, t.type_vat, t.code, t.taux, t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.recuperableonly, t.einvoice_vatex";
7917 $sql .=
" FROM ".$this->db->prefix().
"c_tva as t, ".$this->db->prefix().
"c_country as c";
7918 $sql .=
" WHERE t.fk_pays = c.rowid";
7919 $sql .=
" AND t.active > 0";
7920 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
7921 $sql .=
" AND c.code IN (" . $this->db->sanitize($country_code, 1) .
")";
7922 $sql .=
" ORDER BY t.code ASC, t.taux ASC, t.recuperableonly ASC";
7924 $resql = $this->db->query($sql);
7926 $num = $this->db->num_rows($resql);
7928 for ($i = 0; $i < $num; $i++) {
7929 $obj = $this->db->fetch_object($resql);
7931 $tmparray = array();
7932 $tmparray[
'rowid'] = (int) $obj->rowid;
7933 $tmparray[
'type_vat'] = ($obj->type_vat <= 0 ? 0 : $obj->type_vat);
7934 $tmparray[
'code'] = $obj->code;
7935 $tmparray[
'txtva'] = $obj->taux;
7936 $tmparray[
'nprtva'] = $obj->recuperableonly;
7937 $tmparray[
'localtax1'] = $obj->localtax1;
7938 $tmparray[
'localtax1_type'] = $obj->localtax1_type;
7939 $tmparray[
'localtax2'] = $obj->localtax2;
7940 $tmparray[
'localtax2_type'] = $obj->localtax1_type;
7941 $tmparray[
'einvoice_vatex'] = $obj->einvoice_vatex;
7943 $tmparray[
'label'] = $obj->taux .
'%' . ($obj->code ?
' (' . $obj->code .
')' :
'');
7944 $tmparray[
'labelallrates'] = $obj->taux .
'/' . ($obj->localtax1 ? $obj->localtax1 :
'0') .
'/' . ($obj->localtax2 ? $obj->localtax2 :
'0') . ($obj->code ?
' (' . $obj->code .
')' :
'');
7945 $positiverates =
'';
7947 $positiverates .= ($positiverates ?
'/' :
'') . $obj->taux;
7949 if ($obj->localtax1) {
7950 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax1;
7952 if ($obj->localtax2) {
7953 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax2;
7955 if (empty($positiverates)) {
7956 $positiverates =
'0';
7958 $tmparray[
'labelpositiverates'] = $positiverates . ($obj->code ?
' (' . $obj->code .
')' :
'');
7960 $this->cache_vatrates[$obj->rowid] = $tmparray;
7965 $this->error =
'<span class="error">';
7966 $this->error .= $langs->trans(
"ErrorNoVATRateDefinedForSellerCountry", $country_code);
7968 if (!empty($user) && $user->admin && preg_match(
'/\'(..)\'/', $country_code, $reg)) {
7969 $langs->load(
"errors");
7970 $new_country_code = $reg[1];
7971 $country_id =
dol_getIdFromCode($this->db, $new_country_code,
'c_country',
'code',
'rowid');
7972 $this->error .=
'<br>'.$langs->trans(
"ErrorFixThisHere", DOL_URL_ROOT.
'/admin/dict.php?id=10'.($country_id > 0 ?
'&countryidforinsert='.$country_id :
''));
7974 $this->error .=
'</span>';
7978 $this->error =
'<span class="error">' . $this->db->error() .
'</span>';
8007 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)
8010 global $langs,
$mysoc, $hookmanager;
8012 $langs->load(
'errors');
8016 $hookmanager->initHooks(array(
'commonobject'));
8017 $info_bits == 1 ? $is_npr = 1 : $is_npr = 0;
8018 $parameters = array(
8019 'htmlname' => $htmlname,
8020 'selectedrate' => $selectedrate,
8021 'seller' => $societe_vendeuse,
8022 'buyer' => $societe_acheteuse,
8023 'idprod' => $idprod,
8024 'is_npr' => $is_npr,
8026 'options_only' => $options_only,
8028 'type_vat' => $type_vat
8030 $reshook = $hookmanager->executeHooks(
'load_tva', $parameters);
8032 return $hookmanager->resPrint;
8033 } elseif ($reshook === 0) {
8034 $return .= $hookmanager->resPrint;
8038 $defaultnpr = ($info_bits & 0x01);
8039 $defaultnpr = (preg_match(
'/\*/', $selectedrate) ? 1 : $defaultnpr);
8040 $defaulttx = str_replace(
'*',
'', $selectedrate);
8043 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
8044 $defaultcode = $reg[1];
8045 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
8050 if (is_object($societe_vendeuse) && !$societe_vendeuse->country_code) {
8051 if ($societe_vendeuse->id ==
$mysoc->id) {
8052 $return .=
'<span class="error">' . $langs->trans(
"ErrorYourCountryIsNotDefined") .
'</span>';
8054 $return .=
'<span class="error">' . $langs->trans(
"ErrorSupplierCountryIsNotDefined") .
'</span>';
8071 $sellercountrycode = is_object($societe_vendeuse) ? $societe_vendeuse->country_code :
$mysoc->country_code;
8072 $sellercountryid = is_object($societe_vendeuse) ? $societe_vendeuse->country_id :
$mysoc->country_id;
8073 if ((
int) $sellercountryid > 0 && strlen((
string) $sellercountrycode) != 2) {
8074 $tmpcountrycode =
dol_getIdFromCode($this->db, (
string) $sellercountryid,
'c_country',
'rowid',
'code');
8075 if (!empty($tmpcountrycode) && !is_numeric($tmpcountrycode)) {
8076 $sellercountrycode = $tmpcountrycode;
8079 $code_country =
"'" . $sellercountrycode .
"'";
8082 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
8086 if (is_object($societe_vendeuse) && is_object($societe_acheteuse) &&
isInEEC($societe_vendeuse) &&
isInEEC($societe_acheteuse) && !$societe_acheteuse->isACompany()) {
8088 if (is_numeric($type)) {
8090 switch ($selectVatComboMode) {
8092 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
8095 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
8099 } elseif (!$idprod) {
8100 switch ($selectVatComboMode) {
8102 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
8105 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
8109 $prodstatic =
new Product($this->db);
8110 $prodstatic->fetch($idprod);
8112 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
8119 $this->load_cache_vatrates($code_country);
8122 $arrayofvatrates = array();
8123 foreach ($this->cache_vatrates as $cachevalue) {
8124 if ($type_vat == 0 || empty($cachevalue[
'type_vat']) || $cachevalue[
'type_vat'] == $type_vat) {
8125 $arrayofvatrates[] = $cachevalue;
8129 $num = count($arrayofvatrates);
8132 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
8134 $tmpthirdparty =
new Societe($this->db);
8135 $tmpthirdparty->country_code =
$mysoc->country_code;
8137 $defaulttx =
get_default_tva(is_object($societe_vendeuse) ? $societe_vendeuse : $tmpthirdparty, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
8138 $defaultnpr =
get_default_npr(is_object($societe_vendeuse) ? $societe_vendeuse : $tmpthirdparty, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
8140 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
8141 $defaultcode = $reg[1];
8142 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
8144 if (empty($defaulttx)) {
8151 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
8154 $defaulttx = $arrayofvatrates[$num - 1][
'txtva'];
8161 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
8162 $defaultcode = $reg[1];
8163 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
8171 if (is_object($societe_vendeuse) && $societe_vendeuse->id ==
$mysoc->id && empty($societe_vendeuse->tva_assuj)) {
8181 if (!$options_only) {
8182 $return .=
'<select class="flat valignmiddle minwidth75imp maxwidth100 right" id="' . $htmlname .
'" name="' . $htmlname .
'"' . ($disabled ?
' disabled' :
'') . $title .
'>';
8185 $selectedfound =
false;
8186 foreach ($arrayofvatrates as $rate) {
8188 if ($disabled && $rate[
'txtva'] != 0) {
8193 $key = $rate[
'txtva'];
8194 $key .= $rate[
'nprtva'] ?
'*' :
'';
8195 if ($mode > 0 && $rate[
'code']) {
8196 $key .=
' (' . $rate[
'code'] .
')';
8199 $key = $rate[
'rowid'];
8202 $return .=
'<option value="' . $key .
'" data-vatid="'.$rate[
'rowid'].
'"';
8203 if (!$selectedfound) {
8205 if ($defaultcode == $rate[
'code']) {
8206 $return .=
' selected';
8207 $selectedfound =
true;
8209 } elseif ($rate[
'txtva'] == $defaulttx && $rate[
'nprtva'] == $defaultnpr) {
8210 $return .=
' selected';
8211 $selectedfound =
true;
8219 $return .= $rate[
'labelpositiverates'];
8222 $return .=
vatrate($rate[
'label']);
8226 $return .= (empty($rate[
'code']) && $rate[
'nprtva']) ?
' *' :
'';
8228 $return .=
'</option>';
8231 if (!$options_only) {
8232 $return .=
'</select>';
8236 $return .= $this->error;
8270 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 =
'')
8273 dol_syslog(__METHOD__ .
': using select_date is deprecated. Use selectDate instead.', LOG_WARNING);
8274 $retstring = $this->selectDate($set_time, $prefix, $h, $m, $empty, $form_name, $d, $addnowlink, $disabled, $fullday, $addplusone, $adddateof);
8275 if (!empty($nooutput)) {
8298 public function selectDateToDate($set_time =
'', $set_time_end =
'', $prefix =
're', $empty = 0, $forcenewline = 0)
8302 $ret = $this->selectDate($set_time, $prefix .
'_start', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"from"),
'tzuserrel');
8303 if ($forcenewline) {
8306 $ret .= $this->selectDate($set_time_end, $prefix .
'_end', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
8338 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 =
'')
8340 global
$conf, $langs;
8342 if ($gm ===
'auto') {
8343 $gm = (empty(
$conf) ?
'tzserver' :
$conf->tzuserinputkey);
8348 if ($prefix ==
'') {
8359 if ($stepminutes <= 0 || $stepminutes > 30) {
8370 $orig_set_time = $set_time;
8372 if ($set_time ===
'' && $emptydate == 0) {
8373 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
8374 if ($gm ==
'tzuser' || $gm ==
'tzuserrel') {
8386 if (!empty($set_time) && preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/', (
string) $set_time, $reg)) {
8388 $syear = (!empty($reg[1]) ? $reg[1] :
'');
8389 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
8390 $sday = (!empty($reg[3]) ? $reg[3] :
'');
8391 $shour = (!empty($reg[4]) ? $reg[4] :
'');
8392 $smin = (!empty($reg[5]) ? $reg[5] :
'');
8393 } elseif (strval($set_time) !=
'' && $set_time != -1) {
8398 if ($orig_set_time !=
'') {
8412 if ($h == 3 || $h == 4) {
8423 $usecalendar =
'combo';
8429 $usecalendar =
'html';
8434 if ($usecalendar !=
'combo') {
8436 $reduceformat = (!empty(
$conf->dol_optimize_smallscreen) ? 1 : 0);
8437 if ($reduceformat) {
8438 $format = str_replace(
'%Y',
'%y', $langs->transnoentitiesnoconv(
"FormatDateShortInput"));
8439 $formatjslong = $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput");
8440 $formatjs = str_replace(
'yyyy',
'yy', $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput"));
8441 $formatjquery = str_replace(
'yyyy',
'yy', $langs->trans(
"FormatDateShortJQueryInput"));
8443 $format = $langs->transnoentitiesnoconv(
"FormatDateShortInput");
8444 $formatjslong = $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput");
8445 $formatjs = $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput");
8446 $formatjquery = $langs->trans(
"FormatDateShortJQueryInput");
8450 $formatted_date =
'';
8451 if (strval($set_time) !=
'' && $set_time != -1) {
8456 if ($usecalendar ==
"eldy") {
8482 } elseif ($usecalendar ==
'jquery' || $usecalendar ==
'html') {
8483 if (!$disabled && $usecalendar !=
'html') {
8485 $minYear =
getDolGlobalInt(
'MIN_YEAR_SELECT_DATE', (idate(
'Y') - 100));
8486 $maxYear =
getDolGlobalInt(
'MAX_YEAR_SELECT_DATE', (idate(
'Y') + 100));
8488 $retstring .=
'<!-- datepicker usecalendar='.$usecalendar.
' --><script nonce="' .
getNonce() .
'" type="text/javascript">';
8489 $retstring .=
"$(function(){ $('#" . $prefix .
"').datepicker({
8492 todayHighlight: true,
8493 yearRange: '" . $minYear .
":" . $maxYear .
"',";
8494 if (!empty(
$conf->dol_use_jmobile)) {
8496 beforeShow: function (input, datePicker) {
8497 input.disabled = true;
8499 onClose: function (dateText, datePicker) {
8500 this.disabled = false;
8506 $buttonImage = $calendarpicto ?: DOL_URL_ROOT .
"/theme/" .
dol_escape_js(
$conf->theme) .
"/img/object_calendarday.png";
8508 showOn: 'button', /* both has problem with autocompletion */
8509 buttonImage: '" . $buttonImage .
"',
8510 buttonImageOnly: true";
8514 $retstring .=
"</script>";
8518 $retstring .=
'<div class="nowraponall inline-block divfordateinput">';
8519 $retstring .=
'<input id="'.$prefix.
'" name="'.$prefix.
'" type="'.($usecalendar ==
'html' ?
"date" :
"text").
'" class="maxwidthdate'.(
getDolUserString(
'MAIN_OPTIMIZEFORTEXTBROWSER') ?
' textbrowser' :
'').
' center" maxlength="11" value="'.$formatted_date.
'"';
8520 $retstring .= ($disabled ?
' disabled' :
'');
8521 $retstring .= ($placeholder ?
' placeholder="' .
dol_escape_htmltag($placeholder) .
'"' :
'');
8522 $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
8523 $retstring .= ' autocomplete="off
">';
8527 $retstringbutton = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
">' . img_object($langs->trans("Disabled
"), 'calendarday', 'class="datecallink ui-datepicker-notrigger
"') . '</button>';
8528 $retstring .= $retstringbutton;
8531 $retstring .= '</div>';
8532 $retstring .= '<input type="hidden
" id="' . $prefix . 'day
" name="' . $prefix . 'day
" value="' . $sday . '">' . "\n
";
8533 $retstring .= '<input type="hidden
" id="' . $prefix . 'month
" name="' . $prefix . 'month
" value="' . $smonth . '">' . "\n
";
8534 $retstring .= '<input type="hidden
" id="' . $prefix . 'year
" name="' . $prefix . 'year
" value="' . $syear . '">' . "\n
";
8536 $retstring .= "Bad value of MAIN_POPUP_CALENDAR
";
8539 // Show date with combo selects
8541 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50imp
" id="' . $prefix . 'day
" name="' . $prefix . 'day
">';
8543 if ($emptydate || $set_time == -1) {
8544 $retstring .= '<option value="0
" selected> </option>';
8547 for ($day = 1; $day <= 31; $day++) {
8548 $retstring .= '<option value="' . $day . '"' . ($day == $sday ? ' selected' : '') . '>' . $day . '</option>';
8551 $retstring .= "</select>
";
8553 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'month
" name="' . $prefix . 'month
">';
8554 if ($emptydate || $set_time == -1) {
8555 $retstring .= '<option value="0
" selected> </option>';
8559 for ($month = 1; $month <= 12; $month++) {
8560 $retstring .= '<option value="' . $month . '"' . ($month == $smonth ? ' selected' : '') . '>';
8561 $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b
");
8562 $retstring .= "</option>
";
8564 $retstring .= "</select>
";
8567 if ($emptydate || $set_time == -1) {
8568 $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 . '">';
8570 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'year
" name="' . $prefix . 'year
">';
8572 $syear = (int) $syear;
8573 for ($year = $syear - 10; $year < (int) $syear + 10; $year++) {
8574 $retstring .= '<option value="' . $year . '"' . ($year == $syear ? ' selected' : '') . '>' . $year . '</option>';
8576 $retstring .= "</select>\n
";
8582 $retstring .= (($h == 2 || $h == 4) ? '<br>' : ' ');
8583 $retstring .= '<span class="nowraponall
">';
8589 if ($openinghours != '') {
8590 $openinghours = explode(',', $openinghours);
8591 $hourstart = $openinghours[0];
8592 $hourend = $openinghours[1];
8593 if ($hourend < $hourstart) {
8594 $hourend = $hourstart;
8599 $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
8600 $retstring .= ($fullday ? $fullday . 'hour
' : '') . '" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
">';
8602 $retstring .= '<option value="-1
"> </option>';
8604 for ($hour = $hourstart; $hour < $hourend; $hour++) {
8605 if (strlen($hour) < 2) {
8606 $hour = "0
" . $hour;
8608 $retstring .= '<option value="' . $hour . '"' . (($hour == $shour) ? ' selected' : '') . '>' . $hour;
8609 $retstring .= '</option>';
8611 $retstring .= '</select>';
8614 $retstring .= '<input type="hidden
" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
" value="' . $shour . '">' . "\n
";
8623 $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
8624 $retstring .= ($fullday ? $fullday . 'min
' : '') . '" id="' . $prefix . 'min
" name="' . $prefix . 'min
">';
8626 $retstring .= '<option value="-1
"> </option>';
8628 for ($min = 0; $min < 60; $min += $stepminutes) {
8629 $min_str = sprintf("%02d
", $min);
8630 $retstring .= '<option value="' . $min_str . '"' . (($min_str == $smin) ? ' selected' : '') . '>' . $min_str . '</option>';
8632 $retstring .= '</select>';
8634 $retstring .= '<input type="hidden
" id="' . $prefix . 'min
" name="' . $prefix . 'min
" value="' . $smin . '">' . "\n
";
8637 $retstring .= '<input type="hidden
" name="' . $prefix . 'sec
" value="' . $ssec . '">';
8641 $retstring .= '</span>';
8645 if (!empty($conf->use_javascript_ajax) && $addnowlink && !$disabled) {
8646 // Script which will be inserted in the onClick of the "Now
" link
8647 $reset_scripts = "";
8648 if ($addnowlink == 2) { // local computer time
8649 // pad add leading 0 on numbers
8650 $reset_scripts .= "Number.prototype.pad =
function(size) {
8651 var s = String(
this);
8652 while (s.length < (size || 2)) {s =
'0' + s;}
8655 var d =
new Date();
";
8658 // Generate the date part, depending on the use or not of the javascript calendar
8659 if ($addnowlink == 1) { // server time expressed in user time setup
8660 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
8661 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
8662 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
8663 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
8664 } elseif ($addnowlink == 2) {
8665 /* Disabled because the output does not use the string format defined by FormatDateShort key to forge the value into #prefix.
8666 * This break application for foreign languages.
8667 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(d.toLocaleDateString(\''.str_replace('_', '-', $langs->defaultlang).'\'));';
8668 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(d.getDate().pad());';
8669 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(parseInt(d.getMonth().pad()) + 1);';
8670 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(d.getFullYear());';
8672 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
8673 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
8674 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
8675 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
8677 /*if ($usecalendar == "eldy
")
8679 $base=DOL_URL_ROOT.'/core/';
8680 $reset_scripts .= 'resetDP(\''.$base.'\',\''.$prefix.'\',\''.$langs->trans("FormatDateShortJavaInput
").'\',\''.$langs->defaultlang.'\');';
8684 $reset_scripts .= 'this.form.elements[\''.$prefix.'day\'].value=formatDate(new Date(), \'d\'); ';
8685 $reset_scripts .= 'this.form.elements[\''.$prefix.'month\'].value=formatDate(new Date(), \'M\'); ';
8686 $reset_scripts .= 'this.form.elements[\''.$prefix.'year\'].value=formatDate(new Date(), \'yyyy\'); ';
8688 // Update the hour part
8691 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8693 //$reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); ';
8694 if ($addnowlink == 1) {
8695 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
8696 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
8697 } elseif ($addnowlink == 2) {
8698 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(d.getHours().pad());';
8699 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
8703 $reset_scripts .= ' } ';
8706 // Update the minute part
8709 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8711 //$reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); ';
8712 if ($addnowlink == 1) {
8713 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
8714 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
8715 } elseif ($addnowlink == 2) {
8716 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(d.getMinutes().pad());';
8717 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
8720 $reset_scripts .= ' } ';
8723 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
8724 if ($reset_scripts && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
8725 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonNow
" type="button" name="_useless
" value="now
" onClick="' . $reset_scripts . '">';
8726 $retstring .= $langs->trans("Now
");
8727 $retstring .= '</button> ';
8731 // Add a "Plus one hour
" link
8732 if ($conf->use_javascript_ajax && $addplusone && !$disabled) {
8733 // Script which will be inserted in the onClick of the "Add plusone
" link
8734 $reset_scripts = "";
8736 // Generate the date part, depending on the use or not of the javascript calendar
8737 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'dayinputnoreduce', 'tzuserrel') . '\');';
8738 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
8739 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
8740 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
8741 // Update the hour part
8744 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8746 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
8748 $reset_scripts .= ' } ';
8751 // Update the minute part
8754 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8756 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
8758 $reset_scripts .= ' } ';
8761 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
8762 if ($reset_scripts && empty($conf->dol_optimize_smallscreen)) {
8763 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonPlusOne
" type="button" name="_useless2
" value="plusone
" onClick="' . $reset_scripts . '">';
8764 $retstring .= $langs->trans("DateStartPlusOne
");
8765 $retstring .= '</button> ';
8769 // Add a link to set data
8770 if ($conf->use_javascript_ajax && !empty($adddateof) && !$disabled) {
8771 if (!is_array($adddateof)) {
8772 $arrayofdateof = array(array('adddateof' => $adddateof, 'labeladddateof' => $labeladddateof));
8774 $arrayofdateof = $adddateof;
8776 foreach ($arrayofdateof as $valuedateof) {
8777 $tmpadddateof = empty($valuedateof['adddateof']) ? 0 : $valuedateof['adddateof'];
8778 $tmplabeladddateof = empty($valuedateof['labeladddateof']) ? '' : $valuedateof['labeladddateof'];
8779 $tmparray = dol_getdate($tmpadddateof);
8780 if (empty($tmplabeladddateof)) {
8781 $tmplabeladddateof = $langs->trans("DateInvoice
");
8783 $reset_scripts = 'console.log(\'Click on now link\'); ';
8784 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(\''.dol_print_date($tmpadddateof, 'dayinputnoreduce').'\');';
8785 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(\''.$tmparray['mday'].'\');';
8786 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(\''.$tmparray['mon'].'\');';
8787 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(\''.$tmparray['year'].'\');';
8788 $retstring .= ' - <button class="dpInvisibleButtons datenowlink
" id="dateofinvoice
" type="button" name="_dateofinvoice
" value="now
" onclick="'.$reset_scripts.'">'.$tmplabeladddateof.'</button>';
8804 public function selectTypeDuration($prefix, $selected = 'i', $excludetypes = array(), $morecss = 'minwidth75 maxwidth100')
8808 $TDurationTypes = $this->getDurationTypes($langs);
8810 // Removed undesired duration types
8811 foreach ($excludetypes as $value) {
8812 unset($TDurationTypes[$value]);
8815 $retstring = '<select class="flat
'.($morecss ? ' '.$morecss : '').'" id="select_
' . $prefix . 'type_duration
" name="' . $prefix . 'type_duration
">';
8816 foreach ($TDurationTypes as $key => $typeduration) {
8817 $retstring .= '<option value="' . $key . '"';
8818 if ($key == $selected) {
8819 $retstring .= " selected
";
8821 $retstring .= ">
" . $typeduration . "</option>
";
8823 $retstring .= "</select>
";
8825 $retstring .= ajax_combobox('select_' . $prefix . 'type_duration');
8830 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
8845 public function select_duration($prefix, $iSecond = '', $disabled = 0, $typehour = 'select', $minunderhours = 0, $nooutput = 0)
8850 $retstring = '<span class="nowraponall
">';
8856 if ($iSecond != '') {
8857 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
8859 $hourSelected = convertSecondToTime($iSecond, 'allhour');
8860 $minSelected = convertSecondToTime($iSecond, 'min');
8863 if ($typehour == 'select') {
8864 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'hour
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . '>';
8865 for ($hour = 0; $hour < 25; $hour++) { // For a duration, we allow 24 hours
8866 $retstring .= '<option value="' . $hour . '"';
8867 if (is_numeric($hourSelected) && $hourSelected == $hour) {
8868 $retstring .= " selected
";
8870 $retstring .= ">
" . $hour . "</option>
";
8872 $retstring .= "</select>
";
8873 } elseif ($typehour == 'text' || $typehour == 'textselect') {
8874 $retstring .= '<input placeholder="' . $langs->trans('HourShort
') . '" type="number
" min="0
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputhour right
" value="' . (($hourSelected != '') ? ((int) $hourSelected) : '') . '">';
8876 return 'BadValueForParameterTypeHour';
8879 if ($typehour != 'text') {
8880 $retstring .= ' ' . $langs->trans('HourShort');
8882 $retstring .= '<span class="">:</span>';
8886 if ($minunderhours) {
8887 $retstring .= '<br>';
8889 if ($typehour != 'text') {
8890 $retstring .= '<span class="hideonsmartphone
"> </span>';
8894 if ($typehour == 'select' || $typehour == 'textselect') {
8895 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'min
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . '>';
8896 $step = getDolGlobalInt('MAIN_DURATION_STEP');
8897 $duration_step = ($step > 0) ? $step : 5;
8898 for ($min = 0; $min <= 59; $min += $duration_step) {
8899 $retstring .= '<option value="' . $min . '"';
8900 if (is_numeric($minSelected) && $minSelected == $min) {
8901 $retstring .= ' selected';
8903 $retstring .= '>' . $min . '</option>';
8905 $retstring .= "</select>
";
8906 } elseif ($typehour == 'text') {
8907 $retstring .= '<input placeholder="' . $langs->trans('MinuteShort
') . '" type="number
" min="0
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputminute right
" value="' . (($minSelected != '') ? ((int) $minSelected) : '') . '">';
8910 if ($typehour != 'text') {
8911 $retstring .= ' ' . $langs->trans('MinuteShort');
8914 $retstring .= "</span>
";
8916 if (!empty($nooutput)) {
8944 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)
8946 global $langs, $conf;
8951 if (is_null($ajaxoptions)) {
8952 $ajaxoptions = array();
8955 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
8958 if ($selected && empty($selected_input_value)) {
8959 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
8960 $tickettmpselect = new Ticket($this->db);
8961 $tickettmpselect->fetch((int) $selected);
8962 $selected_input_value = $tickettmpselect->ref;
8963 unset($tickettmpselect);
8967 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/ticket/ajax/tickets.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
8969 if (empty($hidelabel)) {
8970 $out .= $langs->trans("RefOrLabel
") . ' : ';
8971 } elseif ($hidelabel > 1) {
8972 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
8973 if ($hidelabel == 2) {
8974 $out .= img_picto($langs->trans("Search
"), 'search');
8977 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
8978 if ($hidelabel == 3) {
8979 $out .= img_picto($langs->trans("Search
"), 'search');
8982 $out .= $this->selectTicketsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
8985 if (empty($nooutput)) {
9010 public function selectTicketsList($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
9015 $outarray = array();
9017 $selectFields = " p.rowid, p.ref, p.message
";
9020 $sql .= $this->db->sanitize($selectFields, 0, 0, 1);
9021 $sql .= " FROM
" . $this->db->prefix() . "ticket as p
";
9022 $sql .= ' WHERE p.entity IN (' . getEntity('ticket') . ')';
9024 // Add criteria on ref/label
9025 if ($filterkey != '') {
9027 $prefix = getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '' : '%'; // Can use index if TICKET_DONOTSEARCH_ANYWHERE is on
9028 // For natural search
9029 $search_crit = explode(' ', $filterkey);
9031 if (count($search_crit) > 1) {
9034 foreach ($search_crit as $crit) {
9038 $sql .= "(p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%' OR p.subject LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
9042 if (count($search_crit) > 1) {
9048 $sql .= $this->db->plimit($limit, 0);
9050 // Build output string
9051 dol_syslog(get_class($this) . "::selectTicketsList search tickets
", LOG_DEBUG);
9052 $result = $this->db->query($sql);
9054 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
9055 require_once DOL_DOCUMENT_ROOT . '/core/lib/ticket.lib.php';
9057 $num = $this->db->num_rows($result);
9062 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
9063 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('TICKET_USE_SEARCH_TO_SELECT'));
9066 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
9069 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
9070 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
9071 if (getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
9072 if ($showempty && !is_numeric($showempty)) {
9073 $textifempty = $langs->trans($showempty);
9075 $textifempty .= $langs->trans("All
");
9078 if ($showempty && !is_numeric($showempty)) {
9079 $textifempty = $langs->trans($showempty);
9083 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
9087 while ($num && $i < $num) {
9090 $objp = $this->db->fetch_object($result);
9092 $this->constructTicketListOption($objp, $opt, $optJson, $selected, $filterkey);
9093 '@phan-var-force array{key:string,value:mixed,type:int} $optJson';
9095 // "key
" value of json key array is used by jQuery automatically as selected value
9096 // "label
" value of json key array is used by jQuery automatically as text for combo box
9098 array_push($outarray, $optJson);
9103 $out .= '</select>';
9105 $this->db->free($result);
9107 if (empty($outputmode)) {
9112 dol_print_error($this->db);
9129 protected function constructTicketListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
9135 $outkey = $objp->rowid;
9136 $outref = $objp->ref;
9138 $opt = '<option value="
' . $objp->rowid . '"';
9139 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
9142 $objRef = $objp->ref;
9143 if (!empty($filterkey) && $filterkey != '') {
9144 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1);
9147 $opt .= "</option>\n
";
9148 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
9170 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)
9172 global $langs, $conf;
9177 if (is_null($ajaxoptions)) {
9178 $ajaxoptions = array();
9181 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
9184 if ($selected && empty($selected_input_value)) {
9185 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
9186 $projecttmpselect = new Project($this->db);
9187 $projecttmpselect->fetch((int) $selected);
9188 $selected_input_value = $projecttmpselect->ref;
9189 unset($projecttmpselect);
9193 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/projet/ajax/projects.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
9195 if (empty($hidelabel)) {
9196 $out .= $langs->trans("RefOrLabel
") . ' : ';
9197 } elseif ($hidelabel > 1) {
9198 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
9199 if ($hidelabel == 2) {
9200 $out .= img_picto($langs->trans("Search
"), 'search');
9203 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
9204 if ($hidelabel == 3) {
9205 $out .= img_picto($langs->trans("Search
"), 'search');
9208 $out .= $this->selectProjectsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
9211 if (empty($nooutput)) {
9235 public function selectProjectsList($selected = '', $htmlname = 'projectid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
9237 global $langs, $conf;
9240 $outarray = array();
9242 $selectFields = " p.rowid, p.ref
";
9245 $sql .= $this->db->sanitize($selectFields, 0, 0, 1);
9246 $sql .= " FROM
" . $this->db->prefix() . "projet as p
";
9247 $sql .= ' WHERE p.entity IN (' . getEntity('project') . ')';
9249 // Add criteria on ref/label
9250 if ($filterkey != '') {
9252 $prefix = !getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
9253 // For natural search
9254 $search_crit = explode(' ', $filterkey);
9256 if (count($search_crit) > 1) {
9259 foreach ($search_crit as $crit) {
9263 $sql .= "p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
9267 if (count($search_crit) > 1) {
9273 $sql .= $this->db->plimit($limit, 0);
9275 // Build output string
9276 dol_syslog(get_class($this) . "::selectProjectsList search projects
", LOG_DEBUG);
9277 $result = $this->db->query($sql);
9279 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
9280 require_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php';
9282 $num = $this->db->num_rows($result);
9287 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
9288 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('PROJECT_USE_SEARCH_TO_SELECT'));
9291 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
9294 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
9295 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
9296 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
9297 if ($showempty && !is_numeric($showempty)) {
9298 $textifempty = $langs->trans($showempty);
9300 $textifempty .= $langs->trans("All
");
9303 if ($showempty && !is_numeric($showempty)) {
9304 $textifempty = $langs->trans($showempty);
9308 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
9312 while ($num && $i < $num) {
9315 $objp = $this->db->fetch_object($result);
9317 $this->constructProjectListOption($objp, $opt, $optJson, $selected, $filterkey);
9319 // "key
" value of json key array is used by jQuery automatically as selected value
9320 // "label
" value of json key array is used by jQuery automatically as text for combo box
9322 array_push($outarray, $optJson);
9327 $out .= '</select>';
9329 $this->db->free($result);
9331 if (empty($outputmode)) {
9336 dol_print_error($this->db);
9355 protected function constructProjectListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
9361 $label = $objp->label;
9363 $outkey = $objp->rowid;
9364 $outref = $objp->ref;
9365 $outlabel = $objp->label;
9366 $outtype = $objp->fk_product_type;
9368 $opt = '<option value="
' . $objp->rowid . '"';
9369 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
9372 $objRef = $objp->ref;
9373 if (!empty($filterkey) && $filterkey != '') {
9374 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', (string) $objRef, 1);
9377 $opt .= "</option>\n
";
9378 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
9402 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())
9404 global $langs, $conf;
9409 if (is_null($ajaxoptions)) {
9410 $ajaxoptions = array();
9413 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
9416 if ($selected && empty($selected_input_value)) {
9417 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
9418 $adherenttmpselect = new Adherent($this->db);
9419 $adherenttmpselect->fetch((int) $selected);
9420 $selected_input_value = $adherenttmpselect->ref;
9421 unset($adherenttmpselect);
9426 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/adherents/ajax/adherents.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
9428 if (empty($hidelabel)) {
9429 $out .= $langs->trans("RefOrLabel
") . ' : ';
9430 } elseif ($hidelabel > 1) {
9431 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
9432 if ($hidelabel == 2) {
9433 $out .= img_picto($langs->trans("Search
"), 'search');
9436 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
9437 if ($hidelabel == 3) {
9438 $out .= img_picto($langs->trans("Search
"), 'search');
9443 $out .= $this->selectMembersList($selected, $htmlname, $filtertype, $limit, $filterkey, $status, 0, $showempty, $forcecombo, $morecss, $excludeids);
9446 if (empty($nooutput)) {
9471 public function selectMembersList($selected = '', $htmlname = 'adherentid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '', $excludeids = array())
9473 global $langs, $conf;
9476 $outarray = array();
9478 $selectFields = " p.rowid, p.ref, p.firstname, p.lastname, p.fk_adherent_type
";
9481 $sql .= $this->db->sanitize($selectFields, 0, 0, 1);
9482 $sql .= " FROM
" . $this->db->prefix() . "adherent as p
";
9483 $sql .= ' WHERE p.entity IN (' . getEntity('adherent') . ')';
9485 // Add criteria on ref/label
9486 if ($filterkey != '') {
9488 $prefix = !getDolGlobalString('MEMBER_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
9489 // For natural search
9490 $search_crit = explode(' ', $filterkey);
9492 if (count($search_crit) > 1) {
9495 foreach ($search_crit as $crit) {
9499 $sql .= "(p.firstname LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
9500 $sql .= " OR p.lastname LIKE
'" . $this->db->escape($prefix . $crit) . "%')
";
9503 if (count($search_crit) > 1) {
9508 if ($status != -1) {
9509 $sql .= ' AND statut = ' . ((int) $status);
9511 if (!empty($excludeids)) {
9512 $sql .= " AND p.rowid NOT IN (
" . $this->db->sanitize(implode(',', $excludeids)) . ")
";
9514 $sql .= $this->db->plimit($limit, 0);
9516 // Build output string
9517 dol_syslog(get_class($this) . "::selectMembersList search adherents
", LOG_DEBUG);
9518 $result = $this->db->query($sql);
9520 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
9521 require_once DOL_DOCUMENT_ROOT . '/core/lib/member.lib.php';
9523 $num = $this->db->num_rows($result);
9528 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
9529 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('PROJECT_USE_SEARCH_TO_SELECT'));
9532 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
9535 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
9536 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
9537 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
9538 if ($showempty && !is_numeric($showempty)) {
9539 $textifempty = $langs->trans($showempty);
9541 $textifempty .= $langs->trans("All
");
9544 if ($showempty && !is_numeric($showempty)) {
9545 $textifempty = $langs->trans($showempty);
9549 $out .= '<option value="-1
" selected>' . $textifempty . '</option>';
9553 while ($num && $i < $num) {
9556 $objp = $this->db->fetch_object($result);
9558 $this->constructMemberListOption($objp, $opt, $optJson, $selected, $filterkey);
9561 // "key
" value of json key array is used by jQuery automatically as selected value
9562 // "label
" value of json key array is used by jQuery automatically as text for combo box
9564 array_push($outarray, $optJson);
9569 $out .= '</select>';
9571 $this->db->free($result);
9573 if (empty($outputmode)) {
9578 dol_print_error($this->db);
9595 protected function constructMemberListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
9601 $outkey = $objp->rowid;
9602 $outlabel = dolGetFirstLastname($objp->firstname, $objp->lastname);
9603 $outtype = $objp->fk_adherent_type;
9605 $opt = '<option value="
' . $objp->rowid . '"';
9606 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
9608 if (!empty($filterkey) && $filterkey != '') {
9609 $outlabel = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $outlabel, 1);
9612 $opt .= "</option>\n
";
9614 $optJson = array('key' => $outkey, 'value' => $outlabel, 'type' => $outtype);
9638 public function selectForForms($objectdesc, $htmlname, $preSelectedValue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $disabled = 0, $selected_input_value = '', $objectfield = '')
9640 global $conf, $extrafields, $user, $hookmanager, $action;
9642 // Example of common usage for a link to a thirdparty
9644 // We got this in a modulebuilder form of "
MyObject" of module "mymodule
".
9645 // 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
9646 // $objectdesc = 'Societe'
9647 // $objectfield = Method 1: 'myobject@mymodule:fk_soc' ('fk_soc' is code to retrieve myobject->fields['fk_soc'])
9648 // 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__))
" ...)
9650 // We got this when showing an extrafields on resource that is a link to societe
9651 // 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
9652 // $objectdesc = 'Societe'
9653 // $objectfield = Method 1: 'resource:options_link_to_societe'
9654 // Method 2 recommended (it can be the array): array("type"=>'Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))" ...)
9663 $objectdescorig = $objectdesc;
9665 $InfoFieldList = array();
9670 if (is_array($objectfield)) {
9671 $objectdesc = $objectfield[
'type'];
9672 $objectdesc = preg_replace(
'/^integer[^:]*:/',
'', $objectdesc);
9673 } elseif ($objectfield) {
9675 $tmparray = explode(
':', $objectfield);
9678 $objectforfieldstmp = fetchObjectByElement(0, strtolower($tmparray[0]));
9680 if (is_object($objectforfieldstmp)) {
9684 if (preg_match(
'/^options_(.*)$/', $tmparray[1], $reg)) {
9688 $extrafields->fetch_name_optionals_label($objectforfieldstmp->table_element);
9690 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element][
'type'][$key]) && $extrafields->attributes[$objectforfieldstmp->table_element][
'type'][$key] ==
'link') {
9691 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element][
'param'][$key][
'options'])) {
9692 $tmpextrafields = array_keys($extrafields->attributes[$objectforfieldstmp->table_element][
'param'][$key][
'options']);
9693 $objectdesc = $tmpextrafields[0];
9698 if (array_key_exists($tmparray[1], $objectforfieldstmp->fields)) {
9699 $objectdesc = $objectforfieldstmp->fields[$tmparray[1]][
'type'];
9700 $objectdesc = preg_replace(
'/^integer[^:]*:/',
'', $objectdesc);
9711 $InfoFieldList = explode(
":", $objectdesc, 4);
9712 $vartmp = (empty($InfoFieldList[3]) ?
'' : $InfoFieldList[3]);
9714 if (preg_match(
'/^.*:(\w*)$/', $vartmp, $reg)) {
9715 $InfoFieldList[4] = $reg[1];
9717 $InfoFieldList[3] = preg_replace(
'/:\w*$/',
'', $vartmp);
9719 $classname = $InfoFieldList[0];
9720 $classpath = empty($InfoFieldList[1]) ?
'' : $InfoFieldList[1];
9722 $filter = empty($InfoFieldList[3]) ?
'' : $InfoFieldList[3];
9723 $sortfield = empty($InfoFieldList[4]) ?
'' : $InfoFieldList[4];
9726 $objecttmp = fetchObjectByElement(0, strtolower($InfoFieldList[0]));
9729 if (empty($objecttmp) && !empty($classpath)) {
9732 if ($classname && class_exists($classname)) {
9733 $objecttmp =
new $classname($this->db);
9740 $sharedentities = (is_object($objecttmp) && property_exists($objecttmp,
'element')) ?
getEntity($objecttmp->element) : strtolower($classname);
9741 $filter = str_replace(
9742 array(
'__ENTITY__',
'__SHARED_ENTITIES__',
'__USER_ID__'),
9743 array(
$conf->entity, $sharedentities, $user->id),
9747 if (!is_object($objecttmp)) {
9748 dol_syslog(
'selectForForms: Error bad setup of field objectdescorig=' . $objectdescorig.
', objectfield='.(is_array($objectfield) ?
'array' : $objectfield).
', objectdesc='.$objectdesc, LOG_WARNING);
9749 return 'selectForForms: Error bad setup of field objectdescorig=' . $objectdescorig.
', objectfield='.(is_array($objectfield) ?
'array' : $objectfield).
', objectdesc='.$objectdesc;
9751 '@phan-var-force CommonObject $objecttmp';
9754 $prefixforautocompletemode = $objecttmp->element;
9755 if ($prefixforautocompletemode ==
'societe') {
9756 $prefixforautocompletemode =
'company';
9758 if ($prefixforautocompletemode ==
'product') {
9759 $prefixforautocompletemode =
'produit';
9762 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) .
'_USE_SEARCH_TO_SELECT';
9764 dol_syslog(get_class($this) .
"::selectForForms filter=" . $filter, LOG_DEBUG);
9772 if ($preSelectedValue && empty($selected_input_value)) {
9773 $objecttmp->fetch($preSelectedValue);
9774 $selected_input_value = ($prefixforautocompletemode ==
'company' ? $objecttmp->name : $objecttmp->ref);
9776 $oldValueForShowOnCombobox = 0;
9777 foreach ($objecttmp->fields as $fieldK => $fielV) {
9778 if (!array_key_exists(
'showoncombobox', $fielV) || !$fielV[
'showoncombobox'] || empty($objecttmp->$fieldK)) {
9782 if (!$oldValueForShowOnCombobox) {
9783 $selected_input_value =
'';
9786 $selected_input_value .= $oldValueForShowOnCombobox ?
' - ' :
'';
9787 $selected_input_value .= $objecttmp->$fieldK;
9788 $oldValueForShowOnCombobox = empty($fielV[
'showoncombobox']) ? 0 : $fielV[
'showoncombobox'];
9793 $urlforajaxcall = DOL_URL_ROOT .
'/core/ajax/selectobject.php';
9794 $urloption =
'htmlname=' . urlencode($htmlname) .
'&outjson=1&objectdesc=' . urlencode($objectdescorig) . (is_scalar($objectfield) ?
'&objectfield='.urlencode($objectfield) :
'') . ($sortfield ?
'&sortfield=' . urlencode($sortfield) :
'');
9798 $parameters = array(
9799 'urloption' => $urloption,
9800 'object' => $objecttmp,
9801 'htmlname' => $htmlname,
9802 'filter' => $filter,
9803 'searchkey' => $searchkey,
9805 $reshook = $hookmanager->executeHooks(
'selectForFormsListUrl', $parameters, $objecttmp, $action);
9806 if (!empty($reshook)) {
9807 $urloption = $hookmanager->resPrint;
9808 $hookmanager->resPrint =
'';
9813 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
9814 $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) .
'"' :
'') .
' />';
9817 $out .= $this->selectForFormsList($objecttmp, $htmlname, $preSelectedValue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled, $sortfield, $filter);
9845 public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty =
'', $searchkey =
'', $placeholder =
'', $morecss =
'', $moreparams =
'', $forcecombo = 0, $outputmode = 0, $disabled = 0, $sortfield =
'', $filter =
'', $sortorder =
'ASC')
9847 global $langs, $user, $hookmanager;
9851 $prefixforautocompletemode = $objecttmp->element;
9852 if ($prefixforautocompletemode ==
'societe') {
9853 $prefixforautocompletemode =
'company';
9855 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) .
'_USE_SEARCH_TO_SELECT';
9858 if (!empty($objecttmp->fields)) {
9859 $tmpfieldstoshow =
'';
9860 foreach ($objecttmp->fields as $key => $val) {
9861 if (! (
int)
dol_eval((
string) $val[
'enabled'], 1, 1,
'1')) {
9864 if (!empty($val[
'showoncombobox'])) {
9865 $tmpfieldstoshow .= ($tmpfieldstoshow ?
',' :
'') .
't.' . $key;
9868 if ($tmpfieldstoshow) {
9869 $fieldstoshow = $tmpfieldstoshow;
9871 } elseif ($objecttmp->element ===
'category') {
9872 $fieldstoshow =
't.label';
9875 $objecttmp->fields[
'ref'] = array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'enabled' => 1,
'position' => 10,
'visible' => 4,
'showoncombobox' => 1);
9878 if (empty($fieldstoshow)) {
9879 if (!empty($objecttmp->parent_element)) {
9880 $fieldstoshow =
'o.ref';
9881 if (empty($sortfield)) {
9882 $sortfield =
'o.ref';
9884 if (in_array($objecttmp->element, [
'commandedet',
'propaldet',
'facturedet',
'expeditiondet'])) {
9885 $fieldstoshow .=
',p.ref AS p_ref,p.label,t.description';
9886 $sortfield .=
', p.ref';
9888 } elseif (isset($objecttmp->fields[
'ref'])) {
9889 $fieldstoshow =
't.ref';
9891 $langs->load(
"errors");
9892 $this->error = $langs->trans(
"ErrorNoFieldWithAttributeShowoncombobox");
9893 return $langs->trans(
'ErrorNoFieldWithAttributeShowoncombobox');
9898 $outarray = array();
9899 $tmparray = array();
9903 $sanitizedfieldstoshow = $fieldstoshow;
9906 $sql =
"SELECT t.rowid, " . $sanitizedfieldstoshow .
" FROM " . $this->db->prefix() . $this->db->sanitize($objecttmp->table_element) .
" as t";
9907 if (!empty($objecttmp->isextrafieldmanaged)) {
9908 $extrafieldTable = $objecttmp->table_element;
9909 if ($extrafieldTable ==
'categorie') {
9910 $extrafieldTable =
'categories';
9912 $sql .=
" LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($extrafieldTable) .
"_extrafields as e ON t.rowid = e.fk_object";
9914 if (!empty($objecttmp->parent_element)) {
9915 '@phan-var-force CommonObjectLine $objecttmp';
9918 $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);
9920 if (!empty($objecttmp->parent_element) && in_array($objecttmp->parent_element, [
'commande',
'propal',
'facture',
'expedition'])) {
9921 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product as p ON p.rowid = t.fk_product";
9923 if (!empty($objecttmp->ismultientitymanaged)) {
9924 if ($objecttmp->ismultientitymanaged == 1) {
9927 if (!is_numeric($objecttmp->ismultientitymanaged)) {
9928 $tmparray = explode(
'@', $objecttmp->ismultientitymanaged);
9929 $sql .=
" INNER JOIN " . $this->db->prefix() . $this->db->sanitize($tmparray[1]) .
" as parenttable ON parenttable.rowid = t." . $this->db->sanitize($tmparray[0]);
9934 $parameters = array(
9935 'object' => $objecttmp,
9936 'htmlname' => $htmlname,
9937 'filter' => $filter,
9938 'searchkey' => $searchkey
9941 $reshook = $hookmanager->executeHooks(
'selectForFormsListWhere', $parameters);
9942 if (!empty($hookmanager->resPrint)) {
9943 $sql .= $hookmanager->resPrint;
9945 $sql .=
" WHERE 1=1";
9948 if (!empty($objecttmp->ismultientitymanaged)) {
9949 if ($objecttmp->ismultientitymanaged == 1) {
9950 $sql .=
" AND t.entity IN (" .
getEntity($objecttmp->element) .
")";
9952 if (!is_numeric($objecttmp->ismultientitymanaged)) {
9953 $sql .=
" AND parenttable.entity = t." . $this->db->sanitize($tmparray[0]);
9957 if ($objecttmp->ismultientitymanaged ===
'fk_soc@societe') {
9958 if (!$user->hasRight(
'societe',
'client',
'voir') && empty($user->socid)) {
9959 $sql .=
" AND EXISTS (SELECT sc.rowid FROM ".$this->db->prefix() .
"societe_commerciaux as sc";
9960 $sql .=
" WHERE sc.fk_soc = t.fk_soc AND sc.fk_user = ".((int) $user->id).
")";
9966 if (!empty($user->socid)) {
9967 if ($objecttmp->element ==
'societe') {
9968 $sql .=
" AND t.rowid = " . ((int) $user->socid);
9969 } elseif (!empty($objecttmp->fields[
'fk_soc']) || !empty($objecttmp->fields[
't.fk_soc']) || property_exists($objecttmp,
'fk_soc') || property_exists($objecttmp,
'socid')) {
9970 $sql .=
" AND t.fk_soc = " . ((int) $user->socid);
9971 } elseif (!empty($objecttmp->parent_element)) {
9972 $tmpparent = fetchObjectByElement(0, $objecttmp->parent_element,
'', 1);
9973 if (is_object($tmpparent) && (!empty($tmpparent->fields[
'fk_soc']) || !empty($tmpparent->fields[
't.fk_soc']) || property_exists($tmpparent,
'fk_soc') || property_exists($tmpparent,
'socid'))) {
9974 $sql .=
" AND o.fk_soc = " . ((int) $user->socid);
9979 $splittedfieldstoshow = explode(
',', $fieldstoshow);
9980 foreach ($splittedfieldstoshow as &$field2) {
9981 if (is_numeric($pos = strpos($field2,
' '))) {
9982 $field2 = substr($field2, 0, $pos);
9985 if ($searchkey !=
'') {
9992 if ($errormessage) {
9993 return 'Error forging a SQL request from an universal criteria: ' . $errormessage;
9997 $sql .= $this->db->order($sortfield ? $sortfield : $fieldstoshow, $sortorder);
10002 $resql = $this->db->query($sql);
10005 $out .=
'<select id="' . $htmlname .
'" class="flat minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') . ($moreparams ?
' ' . $moreparams :
'') .
' name="' . $htmlname .
'">' .
"\n";
10008 $textifempty =
' ';
10012 if ($showempty && !is_numeric($showempty)) {
10013 $textifempty = $langs->trans($showempty);
10015 $textifempty .= $langs->trans(
"All");
10019 $out .=
'<option value="-1">' . $textifempty .
'</option>' .
"\n";
10022 $num = $this->db->num_rows($resql);
10025 while ($i < $num) {
10026 $obj = $this->db->fetch_object($resql);
10029 $tmparray = explode(
',', $fieldstoshow);
10030 $oldvalueforshowoncombobox = 0;
10031 foreach ($tmparray as $key => $val) {
10032 $val = preg_replace(
'/(t|p|o)\./',
'', $val);
10033 $label .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val][
'showoncombobox'] ?
' - ' :
' ') :
'');
10034 $labelhtml .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val][
'showoncombobox'] ?
' - ' :
' ') :
'');
10035 $label .= $obj->$val;
10036 $labelhtml .= $obj->$val;
10038 $oldvalueforshowoncombobox = empty($objecttmp->fields[$val][
'showoncombobox']) ? 0 : $objecttmp->fields[$val][
'showoncombobox'];
10040 if (empty($outputmode)) {
10041 if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) {
10042 $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>';
10044 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
10047 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label));
10051 if (($i % 10) == 0) {
10057 $out .=
'</select>' .
"\n";
10059 if (!$forcecombo) {
10060 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
10067 $this->result = array(
'nbofelement' => $num);
10085 public static function radio($htmlName, $radioItems, $selected =
'', $moreGlobalParams = [])
10089 'disabled' =>
false,
10092 'name' => $htmlName,
10095 'labelIsHtml' => false
10102 if (!empty($radioItems)) {
10103 foreach ($radioItems as $key => $item) {
10105 if (!is_array($item)) {
10117 'value' => !isset($item[
'attr'][
'value']) ? $key :
'',
10127 if ((is_array($selected) && in_array($item[
'attr'][
'value'], $selected,
true)) || $selected === $item[
'attr'][
'value']) {
10128 $item[
'attr'][
'checked'] =
true;
10136 $text = $item[
'labelIsHtml'] ? $item[
'label'] : htmlspecialchars($item[
'label'], ENT_QUOTES | ENT_SUBSTITUTE);
10139 $out .=
'<label ' . $labelAttributes .
'><input ' . $inputAttributes .
' /> ' . $text .
'</label> ';
10170 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)
10172 global
$conf, $langs;
10179 if ($value_as_key) {
10180 $array = array_combine($array, $array);
10183 '@phan-var-force array{label:string,data-html:string,disable?:int<0,1>,css?:string} $array';
10187 if ($addjscombo < 0) {
10194 $idname = str_replace(array(
'[',
']'), array(
'',
''), $htmlname);
10195 $out .=
'<select id="' . preg_replace(
'/^\./',
'', $idname) .
'" ' . ($disabled ?
'disabled="disabled" ' :
'') .
'class="flat ' . (preg_replace(
'/^\./',
'', $htmlname)) . ($morecss ?
' ' . $morecss :
'') .
' selectformat"';
10196 $out .=
' name="' . preg_replace(
'/^\./',
'', $htmlname) .
'" ' . ($moreparam ? $moreparam :
'');
10200 $textforempty =
' ';
10201 if (!empty(
$conf->use_javascript_ajax)) {
10202 $textforempty =
' ';
10204 if (!is_numeric($show_empty)) {
10205 $textforempty = $show_empty;
10207 $out .=
'<option class="optiongrey" ' . ($moreparamonempty ? $moreparamonempty .
' ' :
'') .
'value="' . (((
int) $show_empty) < 0 ? $show_empty : -1) .
'"' . (
$id == $show_empty ?
' selected' :
'') .
'>' . $textforempty .
'</option>' .
"\n";
10209 if (is_array($array)) {
10212 foreach ($array as $key => $value) {
10213 if (!is_array($value)) {
10214 $array[$key] = $langs->trans($value);
10216 $array[$key][
'label'] = $langs->trans($value[
'label']);
10221 if ($sort ==
'ASC') {
10223 } elseif ($sort ==
'DESC') {
10227 foreach ($array as $key => $tmpvalue) {
10228 if (is_array($tmpvalue)) {
10229 $value = $tmpvalue[
'label'];
10231 $disabled = empty($tmpvalue[
'disabled']) ?
'' :
' disabled';
10232 $style = empty($tmpvalue[
'css']) ?
'' :
' class="' . $tmpvalue[
'css'] .
'"';
10234 $value = $tmpvalue;
10239 if (!empty($disablebademail)) {
10240 if (($disablebademail == 1 && !preg_match(
'/<.+@.+>/', $value))
10241 || ($disablebademail == 2 && preg_match(
'/---/', $value))) {
10242 $disabled =
' disabled';
10243 $style =
' class="warning"';
10246 if ($key_in_label) {
10247 if (empty($nohtmlescape)) {
10250 $selectOptionValue = $key .
' - ' . ($maxlen ?
dol_trunc($value, $maxlen) : $value);
10253 if (empty($nohtmlescape)) {
10256 $selectOptionValue = $maxlen ?
dol_trunc($value, $maxlen) : $value;
10258 if ($value ==
'' || $value ==
'-') {
10259 $selectOptionValue =
' ';
10262 $out .=
'<option value="' . $key .
'"';
10263 $out .= $style . $disabled;
10264 $out .= is_array($tmpvalue) && !empty($tmpvalue[
'parent']) ?
' parent="' .
dolPrintHTMLForAttribute($tmpvalue[
'parent']) .
'"' :
'';
10265 if (is_array(
$id)) {
10266 if (in_array($key,
$id) && !$disabled) {
10267 $out .=
' selected';
10271 if (
$id !=
'' && ((
$id == (
string) $key) || (
$id ==
'ifone' && count($array) == 1)) && !$disabled) {
10272 $out .=
' selected';
10276 if (is_array($tmpvalue)) {
10277 foreach ($tmpvalue as $keyforvalue => $valueforvalue) {
10278 if ($keyforvalue ==
'labelhtml') {
10279 $keyforvalue =
'data-html';
10281 if (preg_match(
'/^data-/', $keyforvalue)) {
10282 $out .=
' '.dol_escape_htmltag($keyforvalue).
'="'.
dol_escape_htmltag($valueforvalue).
'"';
10285 } elseif (!empty($nohtmlescape)) {
10290 $out .= $selectOptionValue;
10291 $out .=
"</option>\n";
10294 $out .=
"</select>";
10297 if ($addjscombo && $jsbeautify) {
10299 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
10300 $out .=
ajax_combobox($idname, array(), 0, 0,
'resolve', (((
int) $show_empty) < 0 ? (
string) $show_empty :
'-1'), $morecss);
10324 public static function selectArrayAjax($htmlname, $url,
$id =
'', $moreparam =
'', $moreparamtourl =
'', $disabled = 0, $minimumInputLength = 1, $morecss =
'', $callurlonselect = 0, $placeholder =
'', $acceptdelayedhtml = 0)
10327 global $delayedhtmlcontent;
10330 if (!
getDolGlobalString(
'MAIN_USE_JQUERY_MULTISELECT') && !defined(
'REQUIRE_JQUERY_MULTISELECT')) {
10334 $out =
'<select type="text" class="' . $htmlname . ($morecss ?
' ' . $morecss :
'') .
'" ' . ($moreparam ? $moreparam .
' ' :
'') .
'name="' . $htmlname .
'"></select>';
10337 if (!empty(
$conf->use_javascript_ajax)) {
10338 $tmpplugin =
'select2';
10339 $outdelayed =
"\n" .
'<!-- JS CODE TO ENABLE ' . $tmpplugin .
' for id ' . $htmlname .
' -->
10340 <script nonce="' .
getNonce() .
'">
10341 $(document).ready(function () {
10343 ' . ($callurlonselect ?
'var saveRemoteData = [];' :
'') .
'
10345 $(".' . $htmlname .
'").select2({
10348 url: "' . $url .
'",
10349 dataType: \'json\',
10351 data: function (params) {
10353 q: params.term, // search term
10357 processResults: function (data) {
10358 // parse the results into the format expected by Select2.
10359 // since we are using custom formatting functions we do not need to alter the remote JSON data
10360 //console.log(data);
10361 saveRemoteData = data;
10362 /* format json result for select2 */
10364 $.each( data, function( key, value ) {
10365 result.push({id: key, text: value.text});
10367 //return {results:[{id:\'none\', text:\'aa\'}, {id:\'rrr\', text:\'Red\'},{id:\'bbb\', text:\'Search a into projects\'}], more:false}
10368 //console.log(result);
10369 return {results: result, more: false}
10373 language: (typeof select2arrayoflanguage === \'undefined\') ? \'en\' : select2arrayoflanguage,
10374 containerCssClass: \':all:\', /* Line to add class from the original SELECT propagated to the new <span class="select2-selection...> tag */
10376 escapeMarkup:
function (markup) {
return markup; },
10377 minimumInputLength:
' . ((int) $minimumInputLength) . ',
10378 formatResult:
function (result, container, query, escapeMarkup) {
10379 return escapeMarkup(result.text);
10383 ' . ($callurlonselect ? '
10385 $(
".' . $htmlname . '").change(
function() {
10386 var selected = $(\
'.' .
dol_escape_js($htmlname) .
'\').val();
10387 console.log(
"We select in selectArrayAjax the entry "+selected)
10389 $.each( saveRemoteData,
function( key, value ) {
10390 if (key == selected)
10392 console.log(
"selectArrayAjax - Do a redirect to "+value.url)
10393 location.assign(value.url);
10402 if ($acceptdelayedhtml) {
10403 $delayedhtmlcontent .= $outdelayed;
10405 $out .= $outdelayed;
10429 public static function selectArrayFilter($htmlname, $array, $id = '
', $moreparam = '', $disableFiltering = 0, $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0, $textfortitle = '')
10432 global $delayedhtmlcontent; // Will be used later outside of this function
10434 // TODO Use an internal dolibarr component instead of select2
10435 if (!getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT
') && !defined('REQUIRE_JQUERY_MULTISELECT
')) {
10439 $out = '<select
type=
"text"'.($textfortitle ? ' title=
"'.dol_escape_htmltag($textfortitle).'"' : '').' id=
"'.$htmlname.'" class=
"'.$htmlname.($morecss ? ' ' . $morecss : '').'"'.($moreparam ? ' '.$moreparam : '').' name=
"'.$htmlname.'"><option></option></select>
';
10441 $formattedarrayresult = array();
10443 foreach ($array as $key => $value) {
10444 $o = new stdClass();
10446 $o->text = $value['text
'];
10447 $o->url = $value['url
'];
10448 $formattedarrayresult[] = $o;
10452 if (!empty($conf->use_javascript_ajax)) {
10453 $tmpplugin = 'select2
';
10454 $outdelayed = "\n" . '<!-- JS CODE TO ENABLE
' . $tmpplugin . ' for id ' . $htmlname . ' -->
10455 <script nonce=
"' . getNonce() . '">
10456 $(document).ready(
function () {
10457 var data =
' . json_encode($formattedarrayresult) . ';
10459 ' . ($callurlonselect ? 'var saveRemoteData =
' . json_encode($array) . ';
' : '') . '
10463 language: (typeof select2arrayoflanguage === \
'undefined\') ? \'en\' : select2arrayoflanguage,
10464 containerCssClass: \':all:\', /* Line to add class from the original SELECT propagated to the new <span class="select2-selection...> tag */
10466 escapeMarkup:
function (markup) {
return markup; },
10467 minimumInputLength:
' . ((int) $minimumInputLength) . ',
10468 formatResult:
function (result, container, query, escapeMarkup) {
10469 return escapeMarkup(result.text);
10471 matcher:
function (params, data) {
10473 if(! data.id)
return null;
';
10475 if ($callurlonselect) {
10476 // We forge the url with 'sall=
'
10479 var urlBase = data.url;
10480 var separ = urlBase.indexOf(
"?") >= 0 ?
"&" :
"?";
10483 saveRemoteData[data.id].url = urlBase + separ +
"search_all=" + encodeURIComponent(params.term.replace(/\
"/g, ""));';
10486 if (!$disableFiltering) {
10489 if(data.text.match(new RegExp(params.term))) {
10504 ' . ($callurlonselect ? '
10505 /* Code to execute a GET when we select a value */
10506 $(\'.' . dol_escape_js($htmlname) . '\').change(function() {
10507 var selected = $(\'.' . dol_escape_js($htmlname) . '\').val();
10508 console.log("We select
"+selected)
10510 $(\'.' . dol_escape_js($htmlname) . '\').val(""); /* reset visible combo value */
10511 $.each( saveRemoteData, function( key, value ) {
10512 if (key == selected)
10514 console.log("selectArrayFilter - Do a redirect to
"+value.url)
10515 location.assign(value.url);
10524 if ($acceptdelayedhtml) {
10525 $delayedhtmlcontent .= $outdelayed;
10527 $out .= $outdelayed;
10550 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)
10552 global $conf, $langs;
10555 if ($addjscombo < 0) {
10556 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
10563 $useenhancedmultiselect = 0;
10564 if (!empty($conf->use_javascript_ajax) && !defined('MAIN_DO_NOT_USE_JQUERY_MULTISELECT') && (getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') || defined('REQUIRE_JQUERY_MULTISELECT'))) {
10566 $useenhancedmultiselect = 1; // Use the js multiselect in one line. Possible only if $addjscombo not 0.
10570 $out .= '<span class="multiselectarray
'.$htmlname.'">';
10572 // We need a hidden field because when using the multiselect, if we unselect all, there is no
10573 // variable submitted at all, so no way to make a difference between variable not submitted and variable
10574 // submitted to nothing.
10575 $out .= '<input type="hidden
" name="'.$htmlname.'_multiselect
" value="1
">';
10576 // Output select component
10577 $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
";
10578 if (is_array($array) && !empty($array)) {
10579 if ($value_as_key) {
10580 $array = array_combine($array, $array);
10583 if (!empty($array)) {
10584 foreach ($array as $key => $value) {
10586 $tmplabel = $value;
10587 $tmplabelhtml = '';
10591 if (is_array($value) && array_key_exists('id', $value) && array_key_exists('label', $value)) {
10592 $tmpkey = $value['id'];
10593 $tmplabel = empty($value['label']) ? '' : $value['label'];
10594 $tmplabelhtml = empty($value['labelhtml']) ? (empty($value['data-html']) ? '' : $value['data-html']) : $value['labelhtml'];
10595 $tmpcolor = empty($value['color']) ? '' : $value['color'];
10596 $tmppicto = empty($value['picto']) ? '' : $value['picto'];
10597 $tmpdisabled = empty($value['disabled']) ? '' : $value['disabled'];
10599 $newval = ($translate ? $langs->trans($tmplabel) : $tmplabel);
10600 $newval = ($key_in_label ? $tmpkey . ' - ' . $newval : $newval);
10602 $tmplabelhtml = ($translate ? $langs->trans($tmplabelhtml) : $tmplabelhtml);
10603 $tmplabelhtml = ($key_in_label ? $tmpkey . ' - ' . $tmplabelhtml : $tmplabelhtml);
10605 $out .= '<option value="' . $tmpkey . '"';
10606 if (is_array($selected) && !empty($selected) && in_array((string) $tmpkey, $selected) && ((string) $tmpkey != '')) {
10607 $out .= ' selected';
10609 $out .= is_array($value) && array_key_exists('parent', $value) && !empty($value['parent']) ? ' parent="' . dolPrintHTMLForAttribute($value['parent
']) . '"' : '';
10610 if ($tmpdisabled) {
10613 if (!empty($tmplabelhtml)) {
10614 $out .= ' data-html="' . dolPrintHTMLForAttribute($tmplabelhtml) . '"';
10616 $tmplabelhtml = ($tmppicto ? img_picto('', $tmppicto, 'class="pictofixedwidth
" style="color: #
' . $tmpcolor . '"') : '') . $newval;
10617 $out .= ' data-html="' . dolPrintHTMLForAttribute($tmplabelhtml) . '"';
10620 $out .= dol_htmlentitiesbr($newval);
10621 $out .= '</option>' . "\n
";
10625 $out .= '</select>' . "\n
";
10629 // Add code for jquery to use multiselect
10630 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') || defined('REQUIRE_JQUERY_MULTISELECT')) {
10631 $out .= "\n
" . '<!-- JS CODE TO ENABLE select for id ' . $htmlname . ', addjscombo=' . $addjscombo . ' -->';
10632 $out .= "\n
" . '<script nonce="' . getNonce() . '">' . "\n
";
10633 if ($addjscombo == 1) {
10634 $tmpplugin = getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT', (defined('REQUIRE_JQUERY_MULTISELECT') ? constant('REQUIRE_JQUERY_MULTISELECT') : 'select2'));
10636 // If property data-html set, we decode html entities and use this.
10637 // Note that HTML content must have been sanitized from js with dol_escape_htmltag(xxx, 0, 0, '', 0, 1) when building the select option.
10638 // TODO Move this into common js ?
10639 $out .= 'function formatResult(record, container) {' . "\n
";
10640 $out .= ' if ($(record.element).attr("data-html
") != undefined && typeof htmlEntityDecodeJs === "function
") {';
10641 $out .= ' return htmlEntityDecodeJs($(record.element).attr("data-html
"));';
10643 $out .= ' return record.text;';
10644 $out .= '}' . "\n
";
10646 $out .= 'function formatSelection(record) {' . "\n
";
10647 $out .= ' return record.text;';
10648 $out .= '}' . "\n
";
10650 // Load the select2 enhancer
10651 //$out .= 'console.log(\'addjscombo=1 for htmlname=' . dol_escape_js($htmlname) . '\');';
10652 $out .= '$(document).ready(function () {
10653 $(\'#' . dol_escape_js($htmlname) . '\').' . $tmpplugin . '({';
10654 if ($placeholder) {
10658 text: \''.dol_escape_js($placeholder).'\'
10661 $out .= ' dir: \'ltr\',
10662 containerCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag (ko with multiselect) */
10663 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. */
10664 // Specify format function for dropdown item
10665 formatResult: formatResult,
10666 templateResult: formatResult, /* For 4.0 */
10667 escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
10668 // Specify format function for selected item
10669 formatSelection: formatSelection,
10670 templateSelection: formatSelection, /* For 4.0 */
10671 language: (typeof select2arrayoflanguage === \'undefined\') ? \'en\' : select2arrayoflanguage
10674 /* Add also morecss to the css .select2 that is after the #htmlname, for component that are shown dynamically after load, because select2 set
10675 the size only if component is not hidden by default on load */
10678 } elseif ($addjscombo == 2 && !defined(
'DISABLE_MULTISELECT')) {
10682 $out .=
'console.log(\'addjscombo=2 for htmlname=' .
dol_escape_js($htmlname) .
'\');
';
10683 $out .= '$(document).ready(
function () {
10685 containerHTML: \
'<div class="multi-select-container">\',
10686 menuHTML: \'<div class="multi-select-menu">\',
10687 buttonHTML: \'<span class="multi-select-button ' .
dol_escape_js($morecss) .
'">\',
10688 menuItemHTML: \'<label class="multi-select-menuitem">\',
10689 activeClass: \'multi-select-container--open\',
10694 $out .= '</script>
';
10714 public static function multiSelectArrayWithCheckbox($htmlname, &$array, $varpage, $pos = '
', $draganddrop = 0)
10716 global $conf, $langs, $user;
10718 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER
')) {
10721 if (empty($array)) {
10725 $tmpvar = "MAIN_SELECTEDFIELDS_" . $varpage; // To get list of saved selected fields to show
10727 if (!empty($user->conf->$tmpvar)) { // A list of fields was already customized for user
10728 $tmparray = explode(',
', $user->conf->$tmpvar);
10729 foreach ($array as $key => $val) {
10731 //var_dump($tmparray);
10732 if (in_array($key, $tmparray)) {
10733 $array[$key]['checked
'] = 1;
10735 $array[$key]['checked
'] = 0;
10738 } else { // There is no list of fields already customized for user
10739 foreach ($array as $key => $val) {
10740 if (!empty($array[$key]['checked
']) && $array[$key]['checked
'] < 0) {
10741 $array[$key]['checked
'] = 0;
10746 $listoffieldsforselection = '';
10747 $listcheckedstring = '';
10749 foreach ($array as $key => $val) {
10751 // var_dump(array_key_exists('enabled
', $val));
10752 // var_dump(!$val['enabled
']);
10753 if (array_key_exists('enabled
', $val) && isset($val['enabled
']) && !$val['enabled
']) {
10754 unset($array[$key]); // We don't want
this field
10757 if (!empty($val[
'type']) && $val[
'type'] ==
'separate') {
10762 if (!empty($val[
'label']) && $val[
'label']) {
10763 if (!empty($val[
'langfile']) && is_object($langs)) {
10764 $langs->load($val[
'langfile']);
10768 $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']).
'" />';
10769 $listoffieldsforselection .=
'<label for="checkbox' . $key .
'" class="paddingleft">';
10771 $listoffieldsforselection .=
'</label>';
10772 if (!empty($draganddrop)) {
10773 $listoffieldsforselection .=
img_picto($langs->trans(
"MoveField", !empty($key) ? $key :
'none'),
'grip_title',
'class="opacitymedium boxhandle hideonsmartphone cursormove marginleftonly"');
10775 $listoffieldsforselection .=
'</li>';
10776 $listcheckedstring .= (empty($val[
'checked']) ?
'' : $key .
',');
10780 $out =
'<!-- Component multiSelectArrayWithCheckbox ' . $htmlname .
' -->
10782 <dl class="dropdown">
10784 <a href="#' . $htmlname .
'" class="multiselectpicto">
10787 <input type="hidden" class="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $listcheckedstring .
'">
10789 <dd class="dropdowndd">
10790 <div class="multiselectcheckbox'.$htmlname.
'">
10791 <ul class="'.$htmlname.(((string) $pos ==
'1' || (
string) $pos ==
'left') ?
'left' :
'').(!empty($draganddrop) ?
' sortable' :
'').
'">
10792 <li class="liinputsearch">
10793 <input class="inputsearch_dropdownselectedfields width90p minwidth200imp" style="width:90%;" type="text" placeholder="'.$langs->trans(
'Search').
'">
10795 '.$listoffieldsforselection.
'
10802 function updateFieldOrder() {
10803 var positionfields = $(".sortable").sortable("toArray");
10805 url: \''.DOL_URL_ROOT.
'/core/ajax/changepositionfields.php?positionfields=\'+positionfields+\'&token='.
newToken().
'&action=listafterchangingpositionfields&contextpage='.$varpage.
'&userid='.$user->id.
'\',
10807 success: function () {
10809 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'";
10813 $( ".sortable" ).sortable({
10814 handle: \'.boxhandle\',
10815 revert: \'invalid\',
10816 items: \'.fieldsortable\',
10817 stop: function(event, ui) {
10818 console.log("We moved box so we call updateBoxOrder with ajax actions");
10819 updateFieldOrder(); /* 1 to avoid message after a move */
10824 <script nonce="' .
getNonce() .
'" type="text/javascript">
10825 jQuery(document).ready(function () {
10826 $(\'.multiselectcheckbox' . $htmlname .
' input[type="checkbox"]\').on("click", function () {
10827 console.log("A new field was added/removed, we edit field input[name=formfilteraction]");
10829 $("input:hidden[name=formfilteraction]").val(\'listafterchangingselectedfields\'); // Update field so we know we changed something on selected fields after POST
10831 var title = $(this).val() + ",";
10832 if ($(this).is(\':checked\')) {
10833 $(\'.' . $htmlname .
'\').val(title + $(\'.' . $htmlname .
'\').val());
10836 $(\'.' . $htmlname .
'\').val( $(\'.' . $htmlname .
'\').val().replace(title, \'\') )
10838 // Now, we submit page
10839 //$(this).parents(\'form:first\').submit();
10842 $("input.inputsearch_dropdownselectedfields").on("keyup", function() {
10843 console.log("keyup on inputsearch_dropdownselectedfields");
10844 var value = $(this).val().toLowerCase();
10845 $(\'.multiselectcheckbox'.$htmlname.
' li > label\').filter(function() {
10846 $(this).parent().toggle($(this).text().toLowerCase().indexOf(value) > -1)
10850 if (empty(
$conf->browser->layout) ||
$conf->browser->layout !=
'phone') {
10852 $(".dropdown dt a").on("click", function () {
10853 console.log("Click on dropdown, we set focus to search field");
10854 setTimeout(() => { $(\'.inputsearch_dropdownselectedfields\').focus(); }, 200);
10878 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
10881 $categories = $cat->containing(
$id, $type);
10883 if ($rendermode == 1 || $rendermode == 2) {
10884 $toprint = array();
10885 foreach ($categories as
$c) {
10886 $ways =
$c->print_all_ways(
'auto', ($nolink ?
'none' :
''), 0, 1, ($rendermode == 2 ? 0 : 1));
10887 foreach ($ways as $way) {
10888 $color =
$c->color;
10889 $sfortag =
'<li class="select2-search-choice-dolibarr noborderoncategories'.(empty($toprint) ?
' nomarginleft' :
'');
10890 $forced_color =
'categtextwhite';
10892 $forced_color =
'categtextblack';
10894 $sfortag .=
' '.$forced_color;
10896 $sfortag .= ($color ?
' style="background: #' . $color .
';"' :
' style="background: #bbb"');
10897 $titlestring = $ways[0];
10901 if ($rendermode == 1) {
10902 $sfortag .=
'<a href="'.DOL_URL_ROOT.
'/categories/viewcat.php?id='.((int)
$c->id).
'&type='.urlencode(
$c->type).
'" class="'.$forced_color.
'">';
10903 $sfortag .=
img_picto(
'',
'category',
'class="paddingright"');
10904 if (
$conf->dol_optimize_smallscreen) {
10909 $sfortag .=
'</a>';
10913 $sfortag .=
'</li>';
10915 $toprint[] = $sfortag;
10918 if (empty($toprint)) {
10921 return '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
10925 if ($rendermode == 0) {
10926 $arrayselected = array();
10927 $cate_arbo = $this->select_all_categories($type,
'',
'parent', 64, 0, 3);
10928 foreach ($categories as
$c) {
10929 $arrayselected[(
string)
$c->id] = (
string)
$c->id;
10932 return $this->multiselectarray(
'categories', $cate_arbo, $arrayselected, 0, 0,
'', 0,
'100%',
'disabled',
'category');
10935 return 'ErrorBadValueForParameterRenderMode';
10949 global
$conf, $langs, $hookmanager;
10955 $object->fetchObjectLinked();
10958 $hookmanager->initHooks(array(
'commonobject'));
10959 $parameters = array(
10960 'morehtmlright' => $morehtmlright,
10961 'compatibleImportElementsList' => &$compatibleImportElementsList,
10963 $reshook = $hookmanager->executeHooks(
'showLinkedObjectBlock', $parameters,
$object, $action);
10965 $nbofdifferenttypes = count(
$object->linkedObjects);
10967 if (empty($reshook)) {
10968 print
'<!-- showLinkedObjectBlock -->';
10969 print
load_fiche_titre($langs->trans($title), $morehtmlright,
'', 0,
'',
'showlinkedobjectblock');
10972 print
'<div class="div-table-responsive-no-min">';
10973 print
'<table class="noborder allwidth" data-block="showLinkedObject" data-element="' .
$object->element .
'" data-elementid="' .
$object->id .
'" >';
10975 print
'<tr class="liste_titre">';
10976 print
'<td>' . $langs->trans(
"Type") .
'</td>';
10977 print
'<td>' . $langs->trans(
"Ref") .
'</td>';
10980 print
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
10981 print
'<td class="right">' . $langs->trans(
"Status") .
'</td>';
10985 $nboftypesoutput = 0;
10987 foreach (
$object->linkedObjects as $objecttype => $objects) {
10988 $tplpath = $element = $subelement = $objecttype;
10991 global $showImportButton;
10992 $showImportButton =
false;
10993 if (!empty($compatibleImportElementsList) && in_array($element, $compatibleImportElementsList)) {
10994 $showImportButton =
true;
10999 if ($objecttype !=
'supplier_proposal' && preg_match(
'/^([^_]+)_([^_]+)/i', $objecttype, $regs)) {
11000 $element = $regs[1];
11001 $subelement = $regs[2];
11002 $tplpath = $element .
'/' . $subelement;
11004 $tplname =
'linkedobjectblock';
11007 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $objecttype, $regs)) {
11008 $element = $regs[1];
11009 $module = $regs[2];
11010 $tplpath = $module.
'/' . $element;
11011 $tplname = $tplname.
'_'.$element;
11015 if ($objecttype ==
'facture') {
11016 $tplpath =
'compta/' . $element;
11020 } elseif ($objecttype ==
'facturerec') {
11021 $tplpath =
'compta/facture';
11022 $tplname =
'linkedobjectblockForRec';
11026 } elseif ($objecttype ==
'propal') {
11027 $tplpath =
'comm/' . $element;
11031 } elseif ($objecttype ==
'supplier_proposal') {
11035 } elseif ($objecttype ==
'shipping' || $objecttype ==
'shipment' || $objecttype ==
'expedition') {
11036 $tplpath =
'expedition';
11040 } elseif ($objecttype ==
'reception') {
11041 $tplpath =
'reception';
11045 } elseif ($objecttype ==
'delivery') {
11046 $tplpath =
'delivery';
11050 } elseif ($objecttype ==
'ficheinter') {
11051 $tplpath =
'fichinter';
11055 } elseif ($objecttype ==
'invoice_supplier') {
11056 $tplpath =
'fourn/facture';
11057 } elseif ($objecttype ==
'order_supplier') {
11058 $tplpath =
'fourn/commande';
11059 } elseif ($objecttype ==
'expensereport') {
11060 $tplpath =
'expensereport';
11061 } elseif ($objecttype ==
'subscription') {
11062 $tplpath =
'adherents';
11063 } elseif ($objecttype ==
'conferenceorbooth') {
11064 $tplpath =
'eventorganization';
11065 } elseif ($objecttype ==
'conferenceorboothattendee') {
11066 $tplpath =
'eventorganization';
11067 } elseif ($objecttype ==
'mo') {
11072 } elseif ($objecttype ==
'project_task') {
11073 $tplpath =
'projet/tasks';
11076 global $linkedObjectBlock;
11077 $linkedObjectBlock = $objects;
11080 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array(
'/' . $tplpath .
'/tpl'));
11082 foreach ($dirtpls as $reldir) {
11083 $reldir = rtrim($reldir,
'/');
11084 if ($nboftypesoutput == ($nbofdifferenttypes - 1)) {
11085 global $noMoreLinkedObjectBlockAfter;
11086 $noMoreLinkedObjectBlockAfter = 1;
11088 $file =
dol_buildpath($reldir .
'/' . $tplname .
'.tpl.php');
11089 if (file_exists($file)) {
11090 $res = @include $file;
11092 $nboftypesoutput++;
11099 if (!$nboftypesoutput) {
11100 print
'<tr><td colspan="7"><span class="opacitymedium">' . $langs->trans(
"None") .
'</span></td></tr>';
11105 if (!empty($compatibleImportElementsList)) {
11106 $res = @include
dol_buildpath(
'core/tpl/objectlinked_lineimport.tpl.php');
11112 return $nbofdifferenttypes;
11126 global
$conf, $langs, $hookmanager, $form;
11131 if (empty($form)) {
11132 $form =
new Form($this->db);
11136 $linktoelemlist =
'';
11137 $listofidcompanytoscan =
'';
11139 if (!is_object(
$object->thirdparty)) {
11140 if (
$object->element ==
'subscription' && isset(
$object->fk_adherent)) {
11146 $fk_adherent = $subby->fk_adherent;
11147 $adh->fetch($fk_adherent);
11148 $thirdparty_id = $adh->fetch_thirdparty();
11151 $thirdparty_id =
$object->thirdparty->id;
11154 $possiblelinks = array();
11156 $dontIncludeCompletedItems =
getDolGlobalString(
'DONT_INCLUDE_COMPLETED_ELEMENTS_LINKS');
11158 if (!empty($thirdparty_id) && $thirdparty_id > 0) {
11159 $listofidcompanytoscan = (int) $thirdparty_id;
11161 $listofidcompanytoscan .=
',' . (int)
$object->thirdparty->parent;
11164 include_once DOL_DOCUMENT_ROOT .
'/projet/class/project.class.php';
11165 $tmpproject =
new Project($this->db);
11166 $tmpproject->fetch((
int)
$object->fk_project);
11167 if ($tmpproject->socid > 0 && ($tmpproject->socid != $thirdparty_id)) {
11168 $listofidcompanytoscan .=
',' . (int) $tmpproject->socid;
11170 unset($tmpproject);
11173 $possiblelinks = array(
11177 'label' =>
'LinkToProposal',
11178 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"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' :
''),
11180 'shipping' => array(
11183 'label' =>
'LinkToExpedition',
11184 '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' :
''),
11189 'label' =>
'LinkToOrder',
11190 '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' :
''),
11191 'linkname' =>
'commande',
11193 'subscription' => array(
11196 'label' =>
'LinkToMemberSubscription',
11197 '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') .
')',
11198 'linkname' =>
'subscription',
11200 'conferenceorboothattendee' => array(
11203 'label' =>
'LinkToConferenceOrBoothAttendee',
11204 'sql' =>
"SELECT s.rowid as socid, CONCAT(a.firstname, ' ', a.lastname) as name, a.rowid as rowid, a.fk_project as fk_project, a.ref as ref, a.email as email, a.date_subscription as date_subscription FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"eventorganization_conferenceorboothattendee as a WHERE a.fk_soc = s.rowid AND a.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND s.entity IN (' .
getEntity(
'conferenceorboothattendee') .
')' . (empty(
$object->fk_project) ?
'' :
' AND a.fk_project = ' . (int)
$object->fk_project),
11205 'linkname' =>
'attendee'
11207 'invoice' => array(
11210 'label' =>
'LinkToInvoice',
11211 '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' :
''),
11212 'linkname' =>
'facture',
11214 'invoice_template' => array(
11217 'label' =>
'LinkToTemplateInvoice',
11218 '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') .
')',
11220 'contrat' => array(
11223 'label' =>
'LinkToContract',
11224 '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
11225 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',
11227 'fichinter' => array(
11230 'label' =>
'LinkToIntervention',
11231 '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') .
')',
11233 'supplier_proposal' => array(
11236 'label' =>
'LinkToSupplierProposal',
11237 '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' :
''),
11239 'order_supplier' => array(
11242 'label' =>
'LinkToSupplierOrder',
11243 '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' :
''),
11245 'invoice_supplier' => array(
11247 'perms' => 1,
'label' =>
'LinkToSupplierInvoice',
11248 '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' :
''),
11253 'label' =>
'LinkToTicket',
11254 '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' :
''),
11259 'label' =>
'LinkToMo',
11260 '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' :
''),
11265 if (
$object->table_element ==
'commande_fournisseur') {
11266 $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' :
'');
11267 } elseif (
$object->table_element ==
'mrp_mo') {
11268 $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' :
'');
11272 if (!empty($listofidcompanytoscan)) {
11274 $hookmanager->initHooks(array(
'commonobject'));
11275 $parameters = array(
'listofidcompanytoscan' => $listofidcompanytoscan,
'possiblelinks' => $possiblelinks);
11276 $reshook = $hookmanager->executeHooks(
'showLinkToObjectBlock', $parameters,
$object, $action);
11279 if (empty($reshook)) {
11280 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
11281 $possiblelinks = array_merge($possiblelinks, $hookmanager->resArray);
11283 } elseif ($reshook > 0) {
11284 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
11285 $possiblelinks = $hookmanager->resArray;
11289 if (!empty($possiblelinks)) {
11290 $object->fetchObjectLinked();
11294 $htmltoenteralink =
'';
11295 foreach ($possiblelinks as $key => $possiblelink) {
11297 if (empty($possiblelink[
'enabled'])) {
11304 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $key, $regs)) {
11306 $module = $regs[2];
11309 if (!empty($possiblelink[
'perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || !in_array($key, $excludelinksto))) {
11310 $htmltoenteralink .=
'<div id="' . $key .
'list"' . (empty(
$conf->use_javascript_ajax) ?
'' :
' style="display:none"') .
'>';
11314 $htmltoenteralink .=
'<br>'.
"\n";
11315 $htmltoenteralink .=
'<!-- form to add a link from anywhere -->'.
"\n";
11316 $htmltoenteralink .=
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinkedbyref' . $key .
'">';
11317 $htmltoenteralink .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
11318 $htmltoenteralink .=
'<input type="hidden" name="action" value="addlinkbyref">';
11319 $htmltoenteralink .=
'<input type="hidden" name="id" value="' .
$object->id .
'">';
11320 $htmltoenteralink .=
'<input type="hidden" name="addlink" value="' . $key .(!empty($module) ?
'@'.$module :
'').
'">';
11321 $htmltoenteralink .=
'<table class="noborder">';
11322 $htmltoenteralink .=
'<tr class="liste_titre">';
11324 $htmltoenteralink .=
'<td class="center"><input type="text" placeholder="'.dol_escape_htmltag($langs->trans(
"Ref")).
'" name="reftolinkto" value="' .
dol_escape_htmltag(
GETPOST(
'reftolinkto',
'alpha')) .
'">';
11325 $htmltoenteralink .=
'<br>';
11326 $htmltoenteralink .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
'ToLink') .
'"> ';
11327 $htmltoenteralink .=
'<input type="submit" class="button smallpaddingimp" name="cancel" value="' . $langs->trans(
'Cancel') .
'">';
11328 $htmltoenteralink .=
'</td>';
11329 $htmltoenteralink .=
'</tr>';
11330 $htmltoenteralink .=
'</table>';
11331 $htmltoenteralink .=
'</form>';
11334 $sql = $possiblelink[
'sql'];
11336 $resqllist = $this->db->query($sql);
11338 $num = $this->db->num_rows($resqllist);
11343 $htmltoenteralink .=
'<br>';
11345 $htmltoenteralink .=
'<!-- form to add a link from object to same thirdparty -->'.
"\n";
11346 $htmltoenteralink .=
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinked' . $key .
'">';
11347 $htmltoenteralink .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
11348 $htmltoenteralink .=
'<input type="hidden" name="action" value="addlink">';
11349 $htmltoenteralink .=
'<input type="hidden" name="id" value="' .
$object->id .
'">';
11350 $htmltoenteralink .=
'<input type="hidden" name="addlink" value="' . $key . (!empty($module) ?
'@'.$module :
'').
'">';
11351 $htmltoenteralink .=
'<table class="noborder">';
11354 case 'conferenceorboothattendee':
11356 $htmltoenteralink .= $this->makeAddLinkToAttendee(
$object, $key, $possiblelink, $num, $resqllist);
11361 $htmltoenteralink .= $this->makeAddLinkToObject(
$object, $key, $possiblelink, $num, $resqllist);
11365 $htmltoenteralink .=
'</table>';
11366 $htmltoenteralink .=
'<div class="center">';
11368 $htmltoenteralink .=
'<input type="submit" class="button valignmiddle marginleftonly marginrightonly smallpaddingimp" value="' . $langs->trans(
'ToLink') .
'">';
11370 if (empty(
$conf->use_javascript_ajax)) {
11371 $htmltoenteralink .=
'<input type="submit" class="button button-cancel marginleftonly marginrightonly smallpaddingimp" name="cancel" value="' . $langs->trans(
"Cancel") .
'"></div>';
11373 $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>';
11375 $htmltoenteralink .=
'</form>';
11378 $this->db->free($resqllist);
11382 $htmltoenteralink .=
'</div>';
11387 $linktoelemlist .=
'<li><a href="#linkto' . $key .
'" class="linkto dropdowncloseonclick" rel="' . $key .
'">' . $langs->trans($possiblelink[
'label']) .
' (' . $num .
')</a></li>';
11390 $linktoelemlist .=
'<li><span class="linktodisabled">' . $langs->trans($possiblelink[
'label']) .
' (0)</span></li>';
11395 if ($linktoelemlist) {
11397 <dl class="dropdown" id="linktoobjectname">
11399 if (!empty(
$conf->use_javascript_ajax)) {
11400 $linktoelem .=
'<dt><a href="#linktoobjectname"><span class="fas fa-link paddingrightonly"></span>' . $langs->trans(
"LinkTo") .
'...</a></dt>';
11402 $linktoelem .=
'<dd>
11403 <div class="multiselectlinkto">
11404 <ul class="ulselectedfields">' . $linktoelemlist .
'
11413 if (!empty(
$conf->use_javascript_ajax)) {
11414 print
'<!-- Add js to show linkto box -->
11415 <script nonce="' .
getNonce() .
'">
11416 jQuery(document).ready(function() {
11417 jQuery(".linkto").click(function() {
11418 console.log("We choose to show/hide links for rel="+jQuery(this).attr(\'rel\')+" so #"+jQuery(this).attr(\'rel\')+"list");
11419 jQuery("#"+jQuery(this).attr(\'rel\')+"list").toggle();
11427 return array(
'linktoelem' => $linktoelem,
'htmltoenteralink' => $htmltoenteralink);
11429 print $htmltoenteralink;
11432 return $linktoelem;
11449 public function selectyesno($htmlname, $value =
'', $option = 0, $disabled =
false, $useempty = 0, $addjscombo = 0, $morecss =
'yesno width75', $labelyes =
'Yes', $labelno =
'No')
11460 $disabled = ($disabled ?
' disabled' :
'');
11462 $resultyesno =
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'"' . $disabled .
'>' .
"\n";
11464 $resultyesno .=
'<option value="-1"' . (($value < 0) ?
' selected' :
'') .
'> </option>' .
"\n";
11466 if ((
"$value" ==
'yes') || ($value == 1)) {
11467 $resultyesno .=
'<option value="' . $yes .
'" selected>' . $langs->trans($labelyes) .
'</option>' .
"\n";
11468 $resultyesno .=
'<option value="' . $no .
'">' . $langs->trans($labelno) .
'</option>' .
"\n";
11470 $selected = (($useempty && $value !=
'0' && $value !=
'no') ?
'' :
' selected');
11471 $resultyesno .=
'<option value="' . $yes .
'">' . $langs->trans($labelyes) .
'</option>' .
"\n";
11472 $resultyesno .=
'<option value="' . $no .
'"' . $selected .
'>' . $langs->trans($labelno) .
'</option>' .
"\n";
11474 $resultyesno .=
'</select>' .
"\n";
11477 $resultyesno .=
ajax_combobox($htmlname, array(), 0, 0,
'resolve', ($useempty < 0 ? (
string) $useempty :
'-1'), $morecss);
11480 return $resultyesno;
11497 $sql =
"SELECT rowid, label";
11498 $sql .=
" FROM " . $this->db->prefix() .
"export_model";
11499 $sql .=
" WHERE type = '" . $this->db->escape($type) .
"'";
11500 $sql .=
" ORDER BY rowid";
11501 $result = $this->db->query($sql);
11503 print
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
11505 print
'<option value="-1"> </option>';
11508 $num = $this->db->num_rows($result);
11510 while ($i < $num) {
11511 $obj = $this->db->fetch_object($result);
11512 if ($selected == $obj->rowid) {
11513 print
'<option value="' . $obj->rowid .
'" selected>';
11515 print
'<option value="' . $obj->rowid .
'">';
11545 public function showrefnav(
$object, $paramid, $morehtml =
'', $shownav = 1, $fieldid =
'rowid', $fieldref =
'ref', $morehtmlref =
'', $moreparam =
'', $nodbprefix = 0, $morehtmlleft =
'', $morehtmlstatus =
'', $morehtmlright =
'')
11547 global
$conf, $langs, $hookmanager, $extralanguages;
11550 if (empty($fieldid)) {
11551 $fieldid =
'rowid';
11553 if (empty($fieldref)) {
11558 $addgendertxt =
'';
11559 if (property_exists(
$object,
'gender') && !empty(
$object->gender)) {
11560 $addgendertxt =
' ';
11563 $addgendertxt .=
'<i class="fas fa-mars valignmiddle"></i>';
11566 $addgendertxt .=
'<i class="fas fa-venus valignmiddle"></i>';
11569 $addgendertxt .=
'<i class="fas fa-transgender valignmiddle"></i>';
11575 if (is_object($hookmanager)) {
11576 $parameters = array(
'showrefnav' =>
true);
11577 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters,
$object);
11578 if (!empty($hookmanager->resPrint)) {
11579 if (empty(
$object->next_prev_filter) && preg_match(
'/^\s*AND/i', $hookmanager->resPrint)) {
11580 $object->next_prev_filter = (
string) preg_replace(
'/^\s*AND\s*/i',
'', $hookmanager->resPrint);
11581 } elseif (!empty(
$object->next_prev_filter) && !preg_match(
'/^\s*AND/i', $hookmanager->resPrint)) {
11582 $object->next_prev_filter .=
' AND '.$hookmanager->resPrint;
11584 $object->next_prev_filter .= $hookmanager->resPrint;
11589 $previous_ref = $next_ref =
'';
11592 $object->load_previous_next_ref((isset(
$object->next_prev_filter) ?
$object->next_prev_filter :
''), $fieldid, $nodbprefix);
11594 $navurl = $_SERVER[
"PHP_SELF"];
11597 if ($paramid ==
'api_token_card') {
11598 if (preg_match(
'/\/user\/api_token/', $navurl)) {
11599 $navurl = preg_replace(
'/card/',
'list', $navurl);
11605 if ($paramid ==
'project_ref') {
11606 if (preg_match(
'/\/tasks\/(task|contact|note|document)\.php/', $navurl)) {
11607 $navurl = preg_replace(
'/\/tasks\/(task|contact|time|note|document)\.php/',
'/tasks.php', $navurl);
11612 $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>';
11613 $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>';
11617 $ret .=
'<!-- Start banner content --><div style="vertical-align: middle">';
11620 if ($morehtmlright) {
11621 $ret .=
'<div class="inline-block floatleft">' . $morehtmlright .
'</div>';
11624 if ($previous_ref || $next_ref || $morehtml) {
11625 $ret .=
'<div class="pagination paginationref"><ul class="right">';
11627 if ($morehtml &&
getDolGlobalInt(
'MAIN_OPTIMIZEFORTEXTBROWSER') < 2) {
11628 $ret .=
'<!-- morehtml --><li class="noborder litext' . (($shownav && $previous_ref && $next_ref) ?
' clearbothonsmartphone' :
'') .
'">' . $morehtml .
'</li>';
11630 if ($shownav && ($previous_ref || $next_ref)) {
11631 $ret .=
'<li class="pagination">' . $previous_ref .
'</li>';
11632 $ret .=
'<li class="pagination">' . $next_ref .
'</li>';
11634 if ($previous_ref || $next_ref || $morehtml) {
11635 $ret .=
'</ul></div>';
11639 $parameters = array(
'morehtmlstatus' => $morehtmlstatus);
11640 $reshook = $hookmanager->executeHooks(
'moreHtmlStatus', $parameters,
$object);
11641 if (empty($reshook)) {
11642 $morehtmlstatus .= $hookmanager->resPrint;
11644 $morehtmlstatus = $hookmanager->resPrint;
11646 if ($morehtmlstatus) {
11647 $ret .=
'<!-- status --><div class="statusref">' . $morehtmlstatus .
'</div>';
11650 $parameters = array();
11651 $reshook = $hookmanager->executeHooks(
'moreHtmlRef', $parameters,
$object);
11652 if (empty($reshook)) {
11653 $morehtmlref .= $hookmanager->resPrint;
11654 } elseif ($reshook > 0) {
11655 $morehtmlref = $hookmanager->resPrint;
11659 if ($morehtmlleft) {
11660 if (
$conf->browser->layout ==
'phone') {
11661 $ret .=
'<!-- morehtmlleft --><div class="floatleft">' . $morehtmlleft .
'</div>';
11663 $ret .=
'<!-- morehtmlleft --><div class="inline-block floatleft">' . $morehtmlleft .
'</div>';
11668 $ret .=
'<!-- Ref or ID --><div class="inline-block floatleft valignmiddle maxwidth750 marginbottomonly refid' . (($shownav && ($previous_ref || $next_ref)) ?
' refidpadding' :
'') .
'">';
11671 if (
$object->element ==
'societe') {
11672 $ret .=
'<span class="valignmiddle">'.dolPrintHTML((
string)
$object->name).
'</span>';
11675 $arrayoflangcode = array();
11680 if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
11681 if (!is_object($extralanguages)) {
11682 include_once DOL_DOCUMENT_ROOT .
'/core/class/extralanguages.class.php';
11685 $extralanguages->fetch_name_extralanguages(
'societe');
11689 if (!empty($extralanguages->attributes[
'societe']) && !empty($extralanguages->attributes[
'societe'][
'name'])) {
11690 $object->fetchValuesForExtraLanguages();
11694 foreach ($arrayoflangcode as $extralangcode) {
11696 if (
$object->array_languages[
'name'][$extralangcode]) {
11697 $htmltext .=
$object->array_languages[
'name'][$extralangcode];
11699 $htmltext .=
'<span class="opacitymedium">' . $langs->trans(
"SwitchInEditModeToAddTranslation") .
'</span>';
11702 $ret .=
'<!-- Show translations of name -->' .
"\n";
11703 $ret .= $this->textwithpicto(
'', $htmltext, -1,
'language',
'opacitymedium paddingleft');
11706 } elseif (
$object->element ==
'member') {
11707 '@phan-var-force Adherent $object';
11708 $ret .=
$object->ref .
'<br>';
11709 $fullname =
$object->getFullName($langs);
11711 $ret .=
'<span class="valignmiddle">'.dolPrintHTML((
string)
$object->societe) . ((!empty($fullname) &&
$object->societe != $fullname) ?
' (' .
dol_htmlentities($fullname) . $addgendertxt .
')' :
'').
'</span>';
11713 $ret .=
'<span class="valignmiddle">'.dolPrintHTML($fullname) . $addgendertxt . ((!empty(
$object->societe) &&
$object->societe != $fullname) ?
' (' .
dol_htmlentities((
string)
$object->societe) .
')' :
'').
'</span>';
11715 } elseif (in_array(
$object->element, array(
'contact',
'user'))) {
11716 $ret .=
'<span class="valignmiddle">'.dolPrintHTML(
$object->getFullName($langs)).
'</span>'.$addgendertxt;
11717 } elseif (
$object->element ==
'usergroup') {
11719 } elseif (in_array(
$object->element, array(
'action',
'agenda'))) {
11720 '@phan-var-force ActionComm $object';
11722 } elseif (in_array(
$object->element, array(
'adherent_type'))) {
11724 } elseif (
$object->element ==
'ecm_directories') {
11726 } elseif (
$object->element ==
'accountingbookkeeping' && !empty(
$object->context[
'mode']) &&
$object->context[
'mode'] ==
'_tmp') {
11727 $ret .=
'<span class="valignmiddle">'.$langs->trans(
"Draft").
'</span>';
11729 '@phan-var-force Ticket $object';
11730 $ret .=
'<span class="valignmiddle">'.dolPrintHTML(!empty(
$object->$fieldref) ?
$object->$fieldref :
"").
'</span>';
11731 $ret .=
' <span class="nobold small" title="'.dolPrintHTMLForAttribute($langs->trans(
"TicketTrackId")).
'">('.
$object->track_id.
')</span>';
11732 } elseif ($fieldref !=
'none') {
11734 $ret .=
'<span class="valignmiddle">'.dolPrintHTML(!empty(
$object->$fieldref) ?
$object->$fieldref :
"").
'</span>';
11736 if ($morehtmlref) {
11738 if (substr($morehtmlref, 0, 4) !=
'<div') {
11742 $ret .=
'<!-- morehtmlref -->'.$morehtmlref;
11747 $ret .=
'</div><!-- End banner content -->';
11764 if (empty(
$object->barcode)) {
11769 if (empty(
$object->barcode_type_code) || empty(
$object->barcode_type_coder)) {
11771 $result =
$object->fetchBarCode();
11774 return '<!-- ErrorFetchBarcode -->';
11779 $url = DOL_URL_ROOT .
'/viewimage.php?modulepart=barcode&generator=' . urlencode(
$object->barcode_type_coder) .
'&code=' . urlencode(
$object->barcode) .
'&encoding=' . urlencode(
$object->barcode_type_code);
11780 $out =
'<!-- url barcode = ' . $url .
' -->';
11781 $out .=
'<img src="' . $url .
'"' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
'>';
11804 public static function showphoto($modulepart,
$object, $width = 100, $height = 0, $caneditfield = 0, $cssclass =
'photowithmargin', $imagesize =
'', $addlinktofullsize = 1, $cache = 0, $forcecapture =
'', $noexternsourceoverwrite = 0, $usesharelinkifavailable = 0)
11813 $originalfile =
'';
11817 if ($modulepart ==
'societe') {
11818 $dir =
$conf->societe->multidir_output[$entity];
11821 if ((
string) $imagesize ==
'mini') {
11823 } elseif ((
string) $imagesize ==
'small') {
11832 } elseif ($modulepart ==
'contact') {
11833 $dir =
$conf->societe->multidir_output[$entity] .
'/contact';
11835 if (!empty($photo)) {
11837 if ((
string) $imagesize ==
'mini') {
11839 } elseif ((
string) $imagesize ==
'small') {
11844 $originalfile =
get_exdir(0, 0, 0, 0,
$object,
'contact') .
'photos/' . $photo;
11849 } elseif ($modulepart ==
'userphoto') {
11850 $dir =
$conf->user->dir_output;
11852 if (!empty($photo)) {
11854 if ((
string) $imagesize ==
'mini') {
11856 } elseif ((
string) $imagesize ==
'small') {
11861 $originalfile =
get_exdir(0, 0, 0, 0,
$object,
'user') .
'photos/' . $photo;
11865 $altfile =
$object->id .
".jpg";
11869 } elseif ($modulepart ==
'memberphoto') {
11870 $dir =
$conf->member->dir_output;
11872 if (!empty($photo)) {
11874 if ((
string) $imagesize ==
'mini') {
11876 } elseif ((
string) $imagesize ==
'small') {
11881 $originalfile =
get_exdir(0, 0, 0, 0,
$object,
'member') .
'photos/' . $photo;
11885 $altfile =
$object->id .
".jpg";
11892 if ($modulepart !=
"unknown" && method_exists(
$object,
'getDataToShowPhoto')) {
11893 $tmpdata =
$object->getDataToShowPhoto($modulepart, $imagesize);
11895 $dir = $tmpdata[
'dir'];
11896 $file = $tmpdata[
'file'];
11897 $originalfile = $tmpdata[
'originalfile'];
11898 $altfile = $tmpdata[
'altfile'];
11899 $email = $tmpdata[
'email'];
11900 $capture = $tmpdata[
'capture'];
11904 if ($forcecapture) {
11905 $capture = $forcecapture;
11911 if ($file && file_exists($dir .
"/" . $file)) {
11912 if ($addlinktofullsize) {
11914 if ($urladvanced) {
11915 $ret .=
'<a href="' . $urladvanced .
'">';
11917 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
11922 if ($usesharelinkifavailable) {
11924 $relativefileforecm = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT.
'/',
'/').
'/',
'', $dir.
'/'.$originalfile);
11926 require_once DOL_DOCUMENT_ROOT .
'/ecm/class/ecmfiles.class.php';
11928 $ecmfiles->fetch(0,
'', $relativefileforecm);
11930 $sharekey = (
string) $ecmfiles->share;
11933 if (!empty($sharekey)) {
11934 $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) .
'">';
11936 $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) .
'">';
11938 if ($addlinktofullsize) {
11941 } elseif ($altfile && file_exists($dir .
"/" . $altfile)) {
11942 if ($addlinktofullsize) {
11944 if ($urladvanced) {
11945 $ret .=
'<a href="' . $urladvanced .
'">';
11947 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
11950 $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) .
'">';
11951 if ($addlinktofullsize) {
11955 $nophoto =
'/public/theme/common/nophoto.png';
11956 $defaultimg =
'identicon';
11957 if (in_array($modulepart, array(
'societe',
'userphoto',
'contact',
'memberphoto'))) {
11958 if ($modulepart ==
'societe' || ($modulepart ==
'memberphoto' && !empty(
$object->morphy) && strpos(
$object->morphy,
'mor') !==
false)) {
11959 $nophoto =
'company';
11961 $nophoto =
'/public/theme/common/user_anonymous.png';
11963 $nophoto =
'/public/theme/common/user_man.png';
11966 $nophoto =
'/public/theme/common/user_woman.png';
11971 if (
isModEnabled(
'gravatar') && $email && empty($noexternsourceoverwrite)) {
11973 $ret .=
'<!-- Put link to gravatar -->';
11974 $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 .
'">';
11976 if ($nophoto ==
'company') {
11977 $ret .=
'<div class="divforspanimg valignmiddle inline-block center photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
'>' .
img_picto(
'',
'company') .
'</div>';
11980 $ret .=
'<img class="photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="' . DOL_URL_ROOT . $nophoto .
'">';
11985 if ($caneditfield) {
11989 $ret .=
'<table class="nobordernopadding centpercent">';
11991 $ret .=
'<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> <label for="photodelete">' . $langs->trans(
"Delete") .
'</label><br><br></td></tr>';
11993 $ret .=
'<tr><td class="tdoverflow">';
11995 $maxmin = $maxfilesizearray[
'maxmin'];
11997 $ret .=
'<input type="hidden" name="MAX_FILE_SIZE" value="' . ($maxmin * 1024) .
'">';
11999 $ret .=
'<input type="file" class="flat maxwidth200onsmartphone" name="photo" id="photoinput" accept="image/*"' . ($capture ?
' capture="' .
dolPrintHTMLForAttribute($capture) .
'"' :
'') .
'>';
12000 $ret .=
'</td></tr>';
12001 $ret .=
'</table>';
12026 public function select_dolgroups($selected = 0, $htmlname =
'groupid', $show_empty = 0, $exclude =
'', $disabled = 0, $include =
'', $enableonly = array(), $force_entity =
'0', $multiple =
false, $morecss =
'minwidth200')
12029 global
$conf, $user, $langs;
12032 $excludeGroups =
null;
12033 if (is_array($exclude)) {
12034 $excludeGroups = implode(
",", $exclude);
12037 $includeGroups =
null;
12038 if (is_array($include)) {
12039 $includeGroups = implode(
",", $include);
12042 if (!is_array($selected)) {
12043 $selected = array($selected);
12049 $sql =
"SELECT ug.rowid, ug.nom as name";
12050 if (
isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && !$user->entity) {
12051 $sql .=
", e.label";
12053 $sql .=
" FROM " . $this->db->prefix() .
"usergroup as ug ";
12054 if (
isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && !$user->entity) {
12055 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid=ug.entity";
12056 if ($force_entity) {
12057 $sql .=
" WHERE ug.entity IN (0, " . ((int) $force_entity) .
")";
12059 $sql .=
" WHERE ug.entity IS NOT NULL";
12062 $sql .=
" WHERE ug.entity IN (0, " . ((int)
$conf->entity) .
")";
12064 if (is_array($exclude) && $excludeGroups) {
12065 $sql .=
" AND ug.rowid NOT IN (" . $this->db->sanitize($excludeGroups) .
")";
12067 if (is_array($include) && $includeGroups) {
12068 $sql .=
" AND ug.rowid IN (" . $this->db->sanitize($includeGroups) .
")";
12070 $sql .=
" ORDER BY ug.nom ASC";
12072 dol_syslog(get_class($this) .
"::select_dolgroups", LOG_DEBUG);
12073 $resql = $this->db->query($sql);
12076 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
12078 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
12080 $num = $this->db->num_rows($resql);
12083 if ($show_empty && !$multiple) {
12084 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'> </option>' .
"\n";
12087 while ($i < $num) {
12088 $obj = $this->db->fetch_object($resql);
12090 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
12094 $label = $obj->name;
12095 $labelhtml = $obj->name;
12097 $label .=
" (" . $obj->label .
")";
12098 $labelhtml .=
' <span class="opacitymedium">(' . $obj->label .
')</span>';
12101 $out .=
'<option value="' . $obj->rowid .
'"';
12102 if ($disableline) {
12103 $out .=
' disabled';
12105 if ((isset($selected[0]) && is_object($selected[0]) && $selected[0]->
id == $obj->rowid)
12106 || ((!isset($selected[0]) || !is_object($selected[0])) && !empty($selected) && in_array($obj->rowid, $selected))) {
12107 $out .=
' selected';
12109 $out .=
' data-html="'.dol_escape_htmltag($labelhtml).
'"';
12112 $out .=
'</option>';
12117 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'></option>' .
"\n";
12119 $out .=
'<option value="" disabled>' . $langs->trans(
"NoUserGroupDefined") .
'</option>';
12121 $out .=
'</select>';
12140 $out =
'<div class="nowraponall">';
12141 $out .=
'<button type="submit" class="liste_titre button_search reposition" name="button_search_x" value="x"><span class="fas fa-search"></span></button>';
12142 $out .=
'<button type="submit" class="liste_titre button_removefilter reposition" name="button_removefilter_x" value="x"><span class="fas fa-times"></span></button>';
12156 public function showCheckAddButtons($cssclass =
'checkforaction', $calljsfunction = 0, $massactionname =
"massaction")
12162 if (!empty(
$conf->use_javascript_ajax)) {
12163 $out .=
'<div class="inline-block checkallactions"><input type="checkbox" id="' . $cssclass .
's" name="' . $cssclass .
's" class="checkallactions"></div>';
12165 $out .=
'<script nonce="' .
getNonce() .
'">
12166 $(document).ready(function() {
12167 $("#' . $cssclass .
's").click(function() {
12168 if($(this).is(\':checked\')){
12169 console.log("We check all ' . $cssclass .
' and trigger the change method");
12170 $(".' . $cssclass .
'").prop(\'checked\', true).trigger(\'change\');
12174 console.log("We uncheck all");
12175 $(".' . $cssclass .
'").prop(\'checked\', false).trigger(\'change\');
12177 if ($calljsfunction) {
12178 $out .=
'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0, "' . $massactionname .
'", "' . $cssclass .
'"); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }';
12182 $(".' . $cssclass .
'").change(function() {
12183 console.log("We check and change the tr class highlight after a change on .'.$cssclass.
'");
12184 var $row = $(this).closest("tr");
12186 var anyChecked = $row.find(\'input[type="checkbox"].checkforselect:checked\').length > 0;
12187 console.log("anychecked="+anyChecked);
12189 $row.removeClass("highlight");
12191 $row.addClass("highlight");
12213 $out = $this->showFilterButtons();
12214 if ($addcheckuncheckall) {
12215 $out .= $this->showCheckAddButtons($cssclass, $calljsfunction, $massactionname);
12233 public function selectExpenseCategories($selected =
'', $htmlname =
'fk_c_exp_tax_cat', $useempty = 0, $excludeid = array(), $target =
'', $default_selected = 0, $params = array(), $info_admin = 1)
12235 global $langs, $user;
12238 $sql =
"SELECT rowid, label FROM " . $this->db->prefix() .
"c_exp_tax_cat WHERE active = 1";
12239 $sql .=
" AND entity IN (0," .
getEntity(
'c_exp_tax_cat') .
")";
12240 if (!empty($excludeid)) {
12241 $sql .=
" AND rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeid)) .
")";
12243 $sql .=
" ORDER BY label";
12245 $resql = $this->db->query($sql);
12247 $out =
'<select id="select_' . $htmlname .
'" name="' . $htmlname .
'" class="' . $htmlname .
' flat minwidth75imp maxwidth200">';
12249 $out .=
'<option value="0"> </option>';
12252 while ($obj = $this->db->fetch_object($resql)) {
12253 $out .=
'<option ' . ($selected == $obj->rowid ?
'selected="selected"' :
'') .
' value="' . $obj->rowid .
'">' . $langs->trans($obj->label) .
'</option>';
12255 $out .=
'</select>';
12258 if (!empty($htmlname) && $user->admin && $info_admin) {
12259 $out .=
' ' .
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
12262 if (!empty($target)) {
12263 $sql =
"SELECT c.id FROM " . $this->db->prefix() .
"c_type_fees as c WHERE c.code = 'EX_KME' AND c.active = 1";
12264 $resql = $this->db->query($sql);
12266 if ($this->db->num_rows($resql) > 0) {
12267 $obj = $this->db->fetch_object($resql);
12268 $out .=
'<script nonce="' .
getNonce() .
'">
12270 $("select[name=' . $target .
']").on("change", function() {
12271 var current_val = $(this).val();
12272 if (current_val == ' . $obj->id .
') {';
12273 if (!empty($default_selected) || !empty($selected)) {
12274 $out .=
'$("select[name=' . $htmlname .
']").val("' . ($default_selected > 0 ? $default_selected : $selected) .
'");';
12278 $("select[name=' . $htmlname .
']").change();
12282 $("select[name=' . $htmlname .
']").change(function() {
12284 if ($("select[name=' . $target .
']").val() == ' . $obj->id .
') {
12285 // get price of kilometer to fill the unit price
12289 data: { fk_c_exp_tax_cat: $(this).val(), token: \'' .
currentToken() .
'\' },
12290 url:
"' . (DOL_URL_ROOT . '/expensereport/ajax/ajaxik.php?' . implode('&', $params)) . '",
12291 }).done(
function( data, textStatus, jqXHR ) {
12293 if (typeof data.up !=
"undefined") {
12294 $(
"input[name=value_unit]").val(data.up);
12295 $(
"select[name=' . $htmlname . ']").attr(
"title", data.title);
12297 $(
"input[name=value_unit]").val(
"");
12298 $(
"select[name=' . $htmlname . ']").attr(
"title",
"");
12309 dol_print_error($this->db);
12323 public function selectExpenseRanges($selected = '
', $htmlname = 'fk_range
', $useempty = 0)
12328 $sql = "SELECT rowid, range_ik FROM " . $this->db->prefix() . "c_exp_tax_range";
12329 $sql .= " WHERE entity IN (0," . getEntity('c_exp_tax_range
') . ") AND active = 1";
12331 $resql = $this->db->query($sql);
12333 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
12335 $out .= '<option value=
"0"></option>
';
12338 while ($obj = $this->db->fetch_object($resql)) {
12339 $out .= '<option
' . ($selected == $obj->rowid ? 'selected=
"selected"' : '') . ' value=
"' . $obj->rowid . '">
' . price($obj->range_ik, 0, $langs, 1, 0) . '</option>
';
12341 $out .= '</select>
';
12343 dol_print_error($this->db);
12359 public function selectExpenseFees($selected = '
', $htmlname = 'fk_c_type_fees
', $useempty = 0, $allchoice = 1, $useid = 0)
12364 $sql = "SELECT id, code, label";
12365 $sql .= " FROM ".$this->db->prefix()."c_type_fees";
12366 $sql .= " WHERE active = 1";
12368 $resql = $this->db->query($sql);
12370 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
12372 $out .= '<option value=
"0"></option>
';
12375 $out .= '<option value=
"-1">
' . $langs->trans('AllExpenseReport
') . '</option>
';
12383 while ($obj = $this->db->fetch_object($resql)) {
12384 $key = $langs->trans($obj->code);
12385 $out .= '<option
' . ($selected == $obj->{$field} ? 'selected=
"selected"' : '') . ' value=
"' . $obj->{$field} . '">
' . ($key != $obj->code ? $key : $obj->label) . '</option>
';
12387 $out .= '</select>
';
12389 $out .= ajax_combobox('select_
'.$htmlname);
12391 dol_print_error($this->db);
12415 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)
12417 global $user, $conf, $langs;
12419 require_once DOL_DOCUMENT_ROOT . '/projet/
class/project.class.php
';
12421 if (is_null($usertofilter)) {
12422 $usertofilter = $user;
12427 $hideunselectables = false;
12428 if (getDolGlobalString('INVOICE_HIDE_UNSELECTABLES
')) {
12429 $hideunselectables = true;
12432 if (empty($projectsListId)) {
12433 if (!$usertofilter->hasRight('projet
', 'all
', 'lire
')) {
12434 $projectstatic = new Project($this->db);
12435 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1);
12439 // Search all projects
12440 $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";
12441 $sql .= " FROM " . $this->db->prefix() . "facture as f";
12442 $sql .= " INNER JOIN " . $this->db->prefix() . "projet as p ON p.entity IN (" . getEntity('project
') . ") AND f.fk_projet = p.rowid";
12443 $sql .= " LEFT JOIN " . $this->db->prefix() . "societe as s ON s.rowid = p.fk_soc";
12444 $sql .= " WHERE f.fk_statut = 0"; // Draft invoices only
12445 //if ($projectsListId) $sql.= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")";
12446 //if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
12447 //if ($socid > 0) $sql.= " AND (p.fk_soc=".((int) $socid)." OR p.fk_soc IS NULL)";
12448 $sql .= " ORDER BY p.ref, f.ref ASC";
12450 $resql = $this->db->query($sql);
12452 // Use select2 selector
12453 if (!empty($conf->use_javascript_ajax)) {
12454 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
12455 $comboenhancement = ajax_combobox($htmlname, array(), 0, $forcefocus);
12456 $out .= $comboenhancement;
12457 $morecss = 'minwidth200imp maxwidth500
';
12460 if (empty($option_only)) {
12461 $out .= '<select
class=
"valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled=
"disabled"' : '') . ' id=
"' . $htmlname . '" name=
"' . $htmlname . '">
';
12463 if (!empty($show_empty)) {
12464 $out .= '<option value=
"0" class=
"optiongrey">
';
12465 if (!is_numeric($show_empty)) {
12466 $out .= $show_empty;
12470 $out .= '</option>
';
12472 $num = $this->db->num_rows($resql);
12475 while ($i < $num) {
12476 $obj = $this->db->fetch_object($resql);
12477 // 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.
12478 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$usertofilter->hasRight('societe
', 'lire
')) {
12481 if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) {
12488 if ($showproject == 'all
') {
12489 $labeltoshow .= dol_trunc($obj->ref, 18); // Invoice ref
12491 $labeltoshow .= ' -
' . $obj->name; // Soc name
12495 if ($obj->fk_statut == Project::STATUS_DRAFT) {
12497 $labeltoshow .= ' -
' . $langs->trans("Draft");
12498 } elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
12499 if ($discard_closed == 2) {
12502 $labeltoshow .= ' -
' . $langs->trans("Closed");
12503 } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
12505 $labeltoshow .= ' -
' . $langs->trans("LinkedToAnotherCompany");
12509 if (!empty($selected) && $selected == $obj->rowid) {
12510 $out .= '<option value=
"' . $obj->rowid . '" selected
';
12511 //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected
if disabled
12512 $out .=
'>' . $labeltoshow .
'</option>';
12514 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
12517 $resultat =
'<option value="' . $obj->rowid .
'"';
12519 $resultat .=
' disabled';
12524 $resultat .= $labeltoshow;
12525 $resultat .=
'</option>';
12533 if (empty($option_only)) {
12534 $out .=
'</select>';
12537 $this->db->free($resql);
12560 public function selectInvoiceRec($selected =
'', $htmlname =
'facrecid', $maxlength = 24, $option_only = 0, $show_empty =
'1', $forcefocus = 0, $disabled = 0, $morecss =
'maxwidth500')
12562 global
$conf, $langs;
12568 $sql =
'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc';
12569 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'facture_rec as f';
12570 $sql .=
" WHERE f.entity IN (" .
getEntity(
'invoice') .
")";
12571 $sql .=
" ORDER BY f.titre ASC";
12573 $resql = $this->db->query($sql);
12576 if (!empty(
$conf->use_javascript_ajax)) {
12577 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
12578 $comboenhancement =
ajax_combobox($htmlname, array(), 0, $forcefocus);
12579 $out .= $comboenhancement;
12580 $morecss =
'minwidth200imp maxwidth500';
12583 if (empty($option_only)) {
12584 $out .=
'<select class="valignmiddle flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' id="' . $htmlname .
'" name="' . $htmlname .
'">';
12586 if (!empty($show_empty)) {
12587 $out .=
'<option value="0" class="optiongrey">';
12588 if (!is_numeric($show_empty)) {
12589 $out .= $show_empty;
12593 $out .=
'</option>';
12595 $num = $this->db->num_rows($resql);
12597 while ($obj = $this->db->fetch_object($resql)) {
12598 $labeltoshow =
dol_trunc($obj->title, 18);
12601 if (!empty($obj->suspended)) {
12603 $labeltoshow .=
' - ' . $langs->trans(
"Closed");
12607 if (!empty($selected) && $selected == $obj->rowid) {
12608 $out .=
'<option value="' . $obj->rowid .
'" selected';
12610 $out .=
'>' . $labeltoshow .
'</option>';
12612 if ($disabled && ($selected != $obj->rowid)) {
12615 $resultat =
'<option value="' . $obj->rowid .
'"';
12617 $resultat .=
' disabled';
12620 $resultat .= $labeltoshow;
12621 $resultat .=
'</option>';
12627 if (empty($option_only)) {
12628 $out .=
'</select>';
12633 $this->db->free($resql);
12636 $this->errors[] = $this->db->lasterror;
12652 public function searchComponent($arrayofcriterias, $search_component_params, $arrayofinputfieldsalreadyoutput = array(), $search_component_params_hidden =
'', $arrayoffiltercriterias = array())
12655 global $langs, $form;
12660 if ($search_component_params_hidden !=
'' && !preg_match(
'/^\(.*\)$/', $search_component_params_hidden)) {
12661 $search_component_params_hidden =
'(' . $search_component_params_hidden .
')';
12664 $ret =
'<!-- searchComponent -->';
12666 $ret .=
'<div class="divadvancedsearchfieldcomp centpercent inline-block">';
12667 $ret .=
'<a href="#" class="dropdownsearch-toggle unsetcolor">';
12668 $ret .=
'<span class="fas fa-filter linkobject boxfilter paddingright pictofixedwidth" title="' .
dol_escape_htmltag($langs->trans(
"Filters")) .
'" id="idsubimgproductdistribution"></span>';
12671 $ret .=
'<div class="divadvancedsearchfieldcompinput inline-block minwidth500 maxwidth300onsmartphone">';
12674 $ret .=
'<div id="divsearch_component_params" name="divsearch_component_params" class="noborderbottom search_component_params inline-block valignmiddle">';
12676 if ($search_component_params_hidden) {
12684 foreach ($arrayofandtags as $tmpkey => $tmpval) {
12685 $errormessage =
'';
12687 if ($errormessage) {
12688 $this->error =
'ERROR in parsing search string: '.$errormessage;
12691 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
12694 $ret .=
'<span class="marginleftonlyshort valignmiddle tagsearch" data-ufilterid="'.($tmpkey + 1).
'" data-ufilter="'.
dol_escape_htmltag($tmpval).
'">';
12695 $ret .=
'<span class="tagsearchdelete select2-selection__choice__remove" data-ufilterid="'.($tmpkey + 1).
'">x</span> ';
12707 $show_search_component_params_hidden = 1;
12708 if ($show_search_component_params_hidden) {
12709 $ret .=
'<input type="hidden" name="show_search_component_params_hidden" value="1">';
12711 $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%')) -->";
12712 $ret .=
'<input type="hidden" id="search_component_params_hidden" name="search_component_params_hidden" value="' .
dol_escape_htmltag($search_component_params_hidden) .
'">';
12717 foreach ($arrayofcriterias as $criteria) {
12718 foreach ($criteria as $criteriafamilykey => $criteriafamilyval) {
12719 if (in_array(
'search_' . $criteriafamilykey, $arrayofinputfieldsalreadyoutput)) {
12722 if (in_array($criteriafamilykey, array(
'rowid',
'ref_ext',
'entity',
'extraparams'))) {
12725 if (in_array($criteriafamilyval[
'type'], array(
'date',
'datetime',
'timestamp'))) {
12726 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_start">';
12727 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startyear">';
12728 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startmonth">';
12729 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startday">';
12730 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_end">';
12731 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endyear">';
12732 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endmonth">';
12733 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endday">';
12735 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'">';
12742 $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";
12743 $ret .=
'<input type="text" placeholder="' . $langs->trans(
"Filters") .
'" id="search_component_params_input" name="search_component_params_input" class="noborderall search_component_input" value="">';
12749 jQuery(".tagsearchdelete").click(function(e) {
12750 var filterid = $(this).parents().attr("data-ufilterid");
12751 console.log("We click to delete the criteria nb "+filterid);
12753 // Regenerate the search_component_params_hidden with all data-ufilter except the one to delete, and post the page
12754 var newparamstring = \'\';
12755 $(\'.tagsearch\').each(function(index, element) {
12756 tmpfilterid = $(this).attr("data-ufilterid");
12757 if (tmpfilterid != filterid) {
12758 // We keep this criteria
12759 if (newparamstring == \'\') {
12760 newparamstring = $(this).attr("data-ufilter");
12762 newparamstring = newparamstring + \' AND \' + $(this).attr("data-ufilter");
12766 console.log("newparamstring = "+newparamstring);
12768 jQuery("#search_component_params_hidden").val(newparamstring);
12770 // We repost the form
12771 $(this).closest(\'form\').submit();
12774 jQuery("#search_component_params_input").keydown(function(e) {
12775 console.log("We press a key on the filter field that is "+jQuery("#search_component_params_input").val());
12776 console.log(e.which);
12777 if (jQuery("#search_component_params_input").val() == "" && e.which == 8) {
12778 /* We click on back when the input field is already empty */
12779 event.preventDefault();
12780 jQuery("#divsearch_component_params .tagsearch").last().remove();
12781 /* Regenerate content of search_component_params_hidden from remaining .tagsearch */
12783 jQuery("#divsearch_component_params .tagsearch").each(function( index ) {
12787 s = s + $(this).attr("data-ufilter");
12789 console.log("New value for search_component_params_hidden = "+s);
12790 jQuery("#search_component_params_hidden").val(s);
12798 $arrayoffiltercriterias_json = json_encode($arrayoffiltercriterias);
12800 var arrayoffiltercriterias = ' . $arrayoffiltercriterias_json .
';
12804 $arrayoffilterfieldslabel = array();
12805 foreach ($arrayoffiltercriterias as $key => $val) {
12806 $arrayoffilterfieldslabel[$key][
'label'] = $val[
'label'];
12807 $arrayoffilterfieldslabel[$key][
'data-type'] = $val[
'type'];
12811 $ret .=
'<div class="search-component-assistance">';
12814 $ret .=
'<p class="assistance-title">' .
img_picto(
'',
'filter') .
' ' . $langs->trans(
'FilterAssistance') .
' </p>';
12816 $ret .=
'<p class="assistance-errors error" style="display:none">' . $langs->trans(
'AllFieldsRequired') .
' </p>';
12818 $ret .=
'<div class="operand">';
12819 $ret .= $form->selectarray(
'search_filter_field', $arrayoffilterfieldslabel,
'', $langs->trans(
"Fields"), 0, 0,
'', 0, 0, 0,
'',
'width200 combolargeelem', 1);
12822 $ret .=
'<span class="separator"></span>';
12825 $ret .=
'<div class="operator">';
12826 $ret .=
'<select class="operator-selector width150" id="operator-selector"">';
12827 $ret .=
'</select>';
12828 $ret .=
'<script>$(document).ready(function() {';
12829 $ret .=
' $(".operator-selector").select2({';
12830 $ret .=
' placeholder: \'' .
dol_escape_js($langs->transnoentitiesnoconv(
'Operator')) .
'\'';
12832 $ret .=
'});</script>';
12835 $ret .=
'<span class="separator"></span>';
12837 $ret .=
'<div class="value">';
12839 $ret .=
'<input type="text" class="flat width100 value-input" placeholder="' .
dolPrintHTML($langs->trans(
'Value')) .
'">';
12843 $ret .=
'<span class="date-one" style="display:none">';
12844 $ret .= $form->selectDate(($dateOne ? $dateOne : -1),
'dateone', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'');
12848 $ret .=
'<select class="value-selector width150" id="value-selector" style="display:none">';
12849 $ret .=
'</select>';
12851 $(document).ready(function() {
12852 $("#value-selector").select2({
12853 placeholder: "' .
dol_escape_js($langs->trans(
'Value')) .
'"
12855 $("#value-selector").hide();
12856 $("#value-selector").next(".select2-container").hide();
12862 $ret .=
'<div class="btn-div">';
12863 $ret .=
'<button class="button buttongen button-save add-filter-btn" type="button">' . $langs->trans(
"addToFilter") .
'</button>';
12874 $(document).ready(function() {
12875 $("#search_component_params_input").on("click", function() {
12876 const inputPosition = $(this).offset();
12877 const inputHeight = $(this).outerHeight();
12878 $(".search-component-assistance").css({
12879 top: inputPosition.top + inputHeight + 5 + "px",
12880 left: $("#divsearch_component_params").position().left
12881 }).slideToggle(200);
12883 $(document).on("click", function(e) {
12884 if (!$(e.target).closest("#search_component_params_input, .search-component-assistance, #ui-datepicker-div").length) {
12885 $(".search-component-assistance").hide();
12892 $(document).ready(function() {
12893 $(".search_filter_field").on("change", function() {
12894 console.log("We change search_filter_field");
12897 const selectedField = $(this).find(":selected");
12898 let fieldType = selectedField.data("type");
12899 const selectedFieldValue = selectedField.val();
12901 // If the selected field has an array of values then ask toshow the value selector instead of the value input
12902 if (arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"] !== undefined) {
12903 fieldType = "select";
12906 // If the selected field may be null then ask to append the "IsDefined" and "IsNotDefined" operators
12907 if (arrayoffiltercriterias[selectedFieldValue]["maybenull"] !== undefined) {
12910 const operators = getOperatorsForFieldType(fieldType, maybenull);
12911 const operatorSelector = $(".operator-selector");
12913 // Clear existing options
12914 operatorSelector.empty();
12916 // Populate operators
12917 Object.entries(operators).forEach(function([operator, label]) {
12918 operatorSelector.append("<option value=\'" + operator + "\'>" + label + "</option>");
12921 operatorSelector.trigger("change.select2");
12923 // Clear and hide all input elements initially
12924 $(".value-input, .dateone, .datemonth, .dateyear").val("").hide();
12925 $("#datemonth, #dateyear").val(null).trigger("change.select2");
12926 $("#dateone").datepicker("setDate", null);
12927 $(".date-one, .date-month, .date-year").hide();
12928 $("#value-selector").val("").hide();
12929 $("#value-selector").next(".select2-container").hide();
12930 $("#value-selector").val(null).trigger("change.select2");
12932 if (fieldType === "date" || fieldType === "datetime" || fieldType === "timestamp") {
12933 $(".date-one").show();
12934 } else if (arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"] !== undefined) {
12935 var arrayofkeyval = arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"];
12936 var valueSelector = $("#value-selector");
12937 valueSelector.empty();
12938 Object.entries(arrayofkeyval).forEach(function([key, val]) {
12939 valueSelector.append("<option value=\'" + key + "\'>" + val + "</option>");
12941 valueSelector.trigger("change.select2");
12943 $("#value-selector").show();
12944 $("#value-selector").next(".select2-container").show();
12946 $(".value-input").show();
12950 $("#operator-selector").on("change", function() {
12951 console.log("We change operator-selector");
12953 const selectedOperator = $(this).find(":selected").val();
12954 if (selectedOperator === "IsDefined" || selectedOperator === "IsNotDefined") {
12955 // Disable all value input elements
12956 $(".value-input, .dateone, .datemonth, .dateyear").val("").prop("disabled", true);
12957 $("#datemonth, #dateyear").val(null).trigger("change.select2");
12958 $("#dateone").datepicker("setDate", null).datepicker("option", "disabled", true);
12959 $(".date-one, .date-month, .date-year").prop("disabled", true);
12960 $("#value-selector").val("").prop("disabled", true);
12961 $("#value-selector").val(null).trigger("change.select2");
12963 // Enable all value input elements
12964 $(".value-input, .dateone, .datemonth, .dateyear").prop("disabled", false);
12965 $(".date-one, .date-month, .date-year").prop("disabled", false);
12966 $("#dateone").datepicker("option", "disabled", false);
12967 $("#value-selector").prop("disabled", false);
12971 $(".add-filter-btn").on("click", function(event) {
12972 console.log("We click on add-filter-btn");
12974 event.preventDefault();
12976 const field = $(".search_filter_field").val();
12977 const operator = $(".operator-selector").val();
12978 let value = $(".value-input").val();
12979 const fieldType = $(".search_filter_field").find(":selected").data("type");
12981 if (["date", "datetime", "timestamp"].includes(fieldType)) {
12982 const year = $("#dateoneyear").val().toString().padStart(4, "0");;
12983 const month = $("#dateonemonth").val().toString().padStart(2, "0");
12984 const day = $("#dateoneday").val().toString().padStart(2, "0");
12985 value = `${year}-${month}-${day}`;
12986 console.log("value="+value);
12989 // If the selected field has an array of values then take the selected value
12990 if (arrayoffiltercriterias[field]["arrayofkeyval"] !== undefined) {
12991 value = $("#value-selector").val();
12994 // If the operator is "IsDefined" or "IsNotDefined" then set the value to 1 (it will not be used)
12995 if (operator === "IsDefined" || operator === "IsNotDefined") {
12999 const filterString = generateFilterString(field, operator, value, fieldType);
13002 if (filterString !== "" && field !== "" && operator !== "" && value !== "") {
13003 $("#search_component_params_input").val($("#search_component_params_input").val() + " " + filterString);
13004 $("#search_component_params_input").closest("form").submit();
13006 $(".assistance-errors").show();
13026 public function selectModelMail($prefix, $modelType =
'', $default = 0, $addjscombo = 0, $selected = 0, $morecss =
'')
13028 global $langs, $user;
13032 $TModels = array();
13034 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
13035 $formmail =
new FormMail($this->db);
13036 $result = $formmail->fetchAllEMailTemplate($modelType, $user, $langs);
13039 $TModels[0] = $langs->trans(
'DefaultMailModel');
13042 foreach ($formmail->lines_model as $model) {
13043 $TModels[(int) $model->id] = $model->label;
13047 $retstring .=
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" id="select_' . $prefix .
'model_mail" name="' . $prefix .
'model_mail">';
13049 foreach ($TModels as $id_model => $label_model) {
13050 $retstring .=
'<option value="' . $id_model .
'"';
13051 if (!empty($selected) && ((int) $selected) == $id_model) {
13052 $retstring .=
"selected";
13054 $retstring .=
">" . $label_model .
"</option>";
13057 $retstring .=
"</select>";
13060 $retstring .=
ajax_combobox(
'select_' . $prefix .
'model_mail');
13077 public function buttonsSaveCancel($save_label =
'Save', $cancel_label =
'Cancel', $morebuttons = array(), $withoutdiv =
false, $morecss =
'', $dol_openinpopup =
'')
13081 $buttons = array();
13085 'label_key' => $save_label,
13088 if ($save_label ==
'Create' || $save_label ==
'Add') {
13089 $save[
'name'] =
'add';
13090 } elseif ($save_label ==
'Modify') {
13091 $save[
'name'] =
'edit';
13095 'name' =>
'cancel',
13096 'label_key' =>
'Cancel',
13101 !empty($save_label) ? $buttons[] = $save :
'';
13102 if (!empty($morebuttons)) {
13103 $buttons[] = $morebuttons;
13105 !empty($cancel_label) ? $buttons[] = $cancel :
'';
13107 if (!empty($morebuttons)) {
13108 $buttons[] = $morebuttons;
13110 !empty($cancel_label) ? $buttons[] = $cancel :
'';
13111 !empty($save_label) ? $buttons[] = $save :
'';
13114 $retstring = $withoutdiv ?
'' :
'<div class="center">';
13116 foreach ($buttons as $button) {
13117 $addclass = empty($button[
'addclass']) ?
'' : $button[
'addclass'];
13118 $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'])) .
'">';
13120 $retstring .= $withoutdiv ?
'' :
'</div>';
13122 if ($dol_openinpopup) {
13123 $retstring .=
'<!-- buttons are shown into a $dol_openinpopup=' .
dol_escape_htmltag($dol_openinpopup) .
' context, so we enable the close of dialog on cancel -->' .
"\n";
13124 $retstring .=
'<script nonce="' .
getNonce() .
'">';
13125 $retstring .=
'jQuery(".button-cancel").click(function(e) {
13126 e.preventDefault(); console.log(\'We click on cancel in iframe popup ' .
dol_escape_js($dol_openinpopup) .
'\');
13127 window.parent.jQuery(\
'#idfordialog' .
dol_escape_js($dol_openinpopup) .
'\').dialog(\
'close\');
13129 $retstring .=
'</script>';
13148 $num = count($this->cache_invoice_subtype);
13155 $sql =
"SELECT rowid, code, label as label";
13156 $sql .=
" FROM " . MAIN_DB_PREFIX .
'c_invoice_subtype';
13157 $sql .=
" WHERE active = 1";
13159 $resql = $this->db->query($sql);
13161 $num = $this->db->num_rows($resql);
13163 while ($i < $num) {
13164 $obj = $this->db->fetch_object($resql);
13167 $label = ($langs->trans(
"InvoiceSubtype" . $obj->rowid) !=
"InvoiceSubtype" . $obj->rowid) ? $langs->trans(
"InvoiceSubtype" . $obj->rowid) : (($obj->label !=
'-') ? $obj->label :
'');
13168 $this->cache_invoice_subtype[$obj->rowid][
'rowid'] = $obj->rowid;
13169 $this->cache_invoice_subtype[$obj->rowid][
'code'] = $obj->code;
13170 $this->cache_invoice_subtype[$obj->rowid][
'label'] = $label;
13174 $this->cache_invoice_subtype =
dol_sort_array($this->cache_invoice_subtype,
'code',
'asc', 0, 0, 1);
13196 global $langs, $user;
13199 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
13201 $this->load_cache_invoice_subtype();
13203 $out .=
'<select id="' . $htmlname .
'" class="flat selectsubtype' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
13205 $out .=
'<option value="0"> </option>';
13208 foreach ($this->cache_invoice_subtype as $rowid => $subtype) {
13209 $label = $subtype[
'label'];
13210 $out .=
'<option value="' . $subtype[
'rowid'] .
'"';
13211 if ($selected == $subtype[
'rowid']) {
13212 $out .=
' selected="selected"';
13216 $out .=
'</option>';
13219 $out .=
'</select>';
13220 if ($user->admin && empty($noinfoadmin)) {
13221 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
13242 'type' =>
'search',
13243 'name' => $htmlName,
13245 'class' =>
"search-tool-input",
13246 'placeholder' => $langs->trans(
'Search'),
13247 'autocomplete' =>
'off'
13255 if ($dataTarget !==
false) {
13256 $attr[
'data-search-tool-target'] = $dataTarget;
13260 if (!empty($params[
'attr']) && is_array($params[
'attr'])) {
13261 foreach ($params[
'attr'] as $key => $value) {
13262 if ($key ==
'class') {
13263 $attr[
'class'] .=
' '.$value;
13264 } elseif ($key ==
'classOverride') {
13265 $attr[
'class'] = $value;
13267 $attr[$key] = $value;
13273 if (!empty($attr[
'title']) && !empty($attr[
'class']) && strpos($attr[
'class'],
'classfortooltip') ===
false) {
13274 $attr[
'class'] .=
' classfortooltip';
13277 $TCompiledAttr = [];
13278 foreach ($attr as $key => $value) {
13279 if (in_array($key, [
'data-target'])
13280 || (!empty($params[
'use_unsecured_unescapedattr']) && is_array($params[
'use_unsecured_unescapedattr']) && in_array($key, $params[
'use_unsecured_unescapedattr']))) {
13286 $TCompiledAttr[] = $key .
'="' . $value .
'"';
13289 $compiledAttributes = implode(
' ', $TCompiledAttr);
13292 return '<div class="search-tool-container"><input '.$compiledAttributes.
'></div>';
13308 public function inputType($type, $name, $value =
'',
$id =
'', $morecss =
'', $moreparam =
'', $label =
'', $addInputLabel =
'')
13311 if ($label !=
'') {
13321 $out .= ($moreparam ?
' ' . $moreparam :
'');
13322 $out .=
' />' . $addInputLabel;
13323 if ($label !=
'') {
13324 $out .= $label .
'</label>';
13342 public function inputSelectAjax($htmlName, $array,
$id, $ajaxUrl, $ajaxData = [], $morecss =
'minwidth75', $moreparam =
'')
13346 $(document).ready(function () {
13347 $('#" . $htmlName .
"').select2({
13349 url: '" . $ajaxUrl .
"',
13351 delay: 250, // wait 250 milliseconds before triggering the request
13352 data: function (params) {
13354 search: params.term,
13355 page: params.page || 1";
13356 if (!empty($ajaxData) && is_array($ajaxData)) {
13357 foreach ($ajaxData as $key => $value) {
13358 $out .=
", " . $key .
": '" . $value .
"'";
13370 $out .= $this->selectarray($htmlName, $array,
$id, 0, 0, 0, $moreparam, 0, 0, 0,
'', $morecss);
13384 public function inputHtml($htmlName, $value, $morecss =
'', $moreparam =
'')
13386 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
13387 $doleditor =
new DolEditor($htmlName, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
isModEnabled(
'fckeditor') &&
getDolGlobalInt(
'FCKEDITOR_ENABLE_SOCIETE'), ROWS_5,
'90%');
13389 return (
string) $doleditor->Create(1,
'',
true,
'',
'', $moreparam, $morecss);
13402 public function inputText($htmlName, $value, $morecss =
'', $moreparam =
'', $options = array())
13407 if (!empty($options)) {
13409 $out .= $this->selectarray($htmlName .
"_multiinput", $options,
'', 1, 0, 0, $moreparam, 0, 0, 0,
'',
"flat maxwidthonphone" . $morecss);
13410 $out .=
'<input id="' . $htmlName .
'_multiinputadd" type="button" class="button" value="' . $langs->trans(
"Add") .
'">';
13411 $out .=
"<script>";
13413 function handlemultiinputdisabling(htmlname){
13414 console.log("We handle the disabling of used options for "+htmlname+"_multiinput");
13415 multiinput = $("#"+htmlname+"_multiinput");
13416 multiinput.find("option").each(function(){
13417 tmpval = $("#"+htmlname).val();
13418 tmpvalarray = tmpval.split("\n");
13419 valtotest = $(this).val();
13420 if(tmpvalarray.includes(valtotest)){
13421 $(this).prop("disabled",true);
13423 if($(this).prop("disabled") == true){
13424 console.log(valtotest)
13425 $(this).prop("disabled", false);
13431 $(document).ready(function () {
13432 $("#' . $htmlName .
'_multiinputadd").on("click",function() {
13433 tmpval = $("#' . $htmlName .
'").val();
13434 tmpvalarray = tmpval.split(",");
13435 valtotest = $("#' . $htmlName .
'_multiinput").val();
13436 if(valtotest != -1 && !tmpvalarray.includes(valtotest)){
13437 console.log("We add the selected value to the text area ' . $htmlName .
'");
13439 tmpval = valtotest;
13441 tmpval = tmpval + "\n" + valtotest;
13443 $("#' . $htmlName .
'").val(tmpval);
13444 handlemultiinputdisabling("' . $htmlName .
'");
13445 $("#' . $htmlName .
'_multiinput").val(-1);
13447 console.log("We add nothing the text area ' . $htmlName .
'");
13450 $("#' . $htmlName .
'").on("change",function(){
13451 handlemultiinputdisabling("' . $htmlName .
'");
13453 handlemultiinputdisabling("' . $htmlName .
'");
13455 $out .=
"</script>";
13456 $value = str_replace(
',',
"\n", $value);
13459 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
13460 $doleditor =
new DolEditor($htmlName, (
string) $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
13461 $out .= (
string) $doleditor->Create(1,
'',
true,
'',
'', $moreparam, $morecss);
13476 public function inputRadio($htmlName, $options, $selectedValue, $morecss =
'', $moreparam =
'')
13479 foreach ($options as $optionKey => $optionLabel) {
13480 $selected = ((
string) $selectedValue) === ((
string) $optionKey) ?
' checked="checked"' :
'';
13481 $optionId = $htmlName .
'_' . $optionKey;
13482 $out .=
'<input class="flat' . $morecss .
'" type="radio" name="' . $htmlName .
'" id="' . $optionId .
'" value="' .
dolPrintHTMLForAttribute((
string) $optionKey) .
'"' . $selected . $moreparam .
'/><label for="' . $optionId .
'">' . $optionLabel .
'</label><br>';
13498 public function inputStars($htmlName, $size, $value, $morecss =
'', $moreparam =
'')
13500 $out =
'<input type="hidden" class="flat ' . $morecss .
'" name="' . $htmlName .
'" id="' . $htmlName .
'" value="' .
dolPrintHTMLForAttribute((
string) $value) .
'"' . $moreparam .
'>';
13501 $out .=
'<div class="star-selection" id="' . $htmlName .
'_selection">';
13502 for ($i = 1; $i <= $size; $i++) {
13503 $out .=
'<span class="star" data-value="' . $i .
'">' .
img_picto(
'',
'fontawesome_star_fas') .
'</span>';
13507 jQuery(function($) { /* commonobject.class.php 1 */
13508 let container = $("#' . $htmlName .
'_selection");
13509 let selectedStars = parseInt($("#' . $htmlName .
'").val()) || 0;
13510 container.find(".star").each(function() {
13511 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
13513 container.find(".star").on("mouseover", function() {
13514 let selectedStar = $(this).data("value");
13515 container.find(".star").each(function() {
13516 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
13519 container.on("mouseout", function() {
13520 container.find(".star").each(function() {
13521 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
13524 container.find(".star").off("click").on("click", function() {
13525 selectedStars = $(this).data("value");
13526 if (selectedStars === 1 && $("#' . $htmlName .
'").val() == 1) {
13529 $("#' . $htmlName .
'").val(selectedStars);
13530 container.find(".star").each(function() {
13531 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
13549 public function inputIcon($htmlName, $value, $morecss =
'', $moreparam =
'')
13558 $out =
'<input type="text" class="form-control icp icp-auto iconpicker-element iconpicker-input flat ' . $morecss .
' maxwidthonsmartphone"';
13559 $out .=
' name="' . $htmlName .
'" id="' . $htmlName .
'" value="' .
dolPrintHTMLForAttribute((
string) $value) .
'" ' . ((
string) $moreparam) .
'>';
13561 $out .=
'<script>';
13562 $options =
"{ title: '<b>" . $langs->trans(
"IconFieldSelector") .
"</b>', placement: 'right', showFooter: false, templates: {";
13563 $options .=
"iconpicker: '<div class=\"iconpicker\"><div style=\"background-color:#EFEFEF;\" class=\"iconpicker-items\"></div></div>',";
13564 $options .=
"iconpickerItem: '<a role=\"button\" href=\"#\" class=\"iconpicker-item\" style=\"background-color:#DDDDDD;\"><i></i></a>',";
13567 $options .=
"footer: '<div class=\"popover-footer\" style=\"background-color:#EFEFEF;\"></div>',";
13568 $options .=
"search: '<input type=\"search\" class\"form-control iconpicker-search\" placeholder=\"" . $langs->trans(
"TypeToFilter") .
"\" />',";
13569 $options .=
"popover: '<div class=\"iconpicker-popover popover\">";
13570 $options .=
" <div class=\"arrow\" ></div>";
13571 $options .=
" <div class=\"popover-title\" style=\"text-align:center;background-color:#EFEFEF;\"></div>";
13572 $options .=
" <div class=\"popover-content \" ></div>";
13573 $options .=
"</div>'}}";
13574 $out .=
"$('#" . $htmlName .
"').iconpicker(" . $options .
");";
13575 $out .=
'</script>';
13591 require_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeophp.class.php';
13592 require_once DOL_DOCUMENT_ROOT .
'/core/class/geomapeditor.class.php';
13598 if (!empty($value)) {
13599 $tmparray = $dolgeophp->parseGeoString($value);
13600 $geojson = $tmparray[
'geojson'];
13601 $centroidjson = $tmparray[
'centroidjson'];
13604 return $geomapeditor->getHtml($htmlName, $geojson, $centroidjson, $type);
13616 $toPrint = array();
13617 $values = is_array($values) ? $values : array();
13619 foreach ($values as $value) {
13620 $toPrint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $value .
'</li>';
13622 if (!empty($toPrint)) {
13623 $out =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(
' ', $toPrint) .
'</ul></div>';
13639 for ($i = 1; $i <= $size; $i++) {
13640 $out .=
'<span class="star' . ($i <= $value ?
' active' :
'') .
'" data-value="' . $i .
'">' .
img_picto(
'',
'fontawesome_star_fas') .
'</span>';
13671 if (!empty($value)) {
13672 require_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeophp.class.php';
13674 if ($type ==
'point') {
13675 $out = $dolgeophp->getXYString($value);
13677 $out = $dolgeophp->getPointString($value);
13698 public function getNomUrl(&
$object, $withpicto = 0, $option =
'', $maxlength = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'', $add_label = 0, $sep =
' - ')
13700 if (is_object(
$object) && method_exists(
$object,
'getNomUrl')) {
13701 $out =
$object->getNomUrl($withpicto, $option, $maxlength, $save_lastsearch_value, $notooltip, $morecss, $add_label, $sep);
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLength=2, $autoselect=0, $ajaxoptions=array(), $moreparams='')
Generic function that return javascript to add to transform a common input text or select field into ...
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
ajax_multiautocompleter($htmlname, $fields, $url, $option='', $minLength=2, $autoselect=0)
Generic function that return javascript to add to a page to transform a common input text field into ...
ajax_event($htmlname, $events)
Add event management script.
Class to manage bank accounts.
Class to manage members of a foundation.
Class to manage categories.
Class to manage bank accounts description of third parties.
Class for ConferenceOrBoothAttendee.
Class to manage a WYSIWYG editor.
Class to manage Geo processing Usage: $dolgeophp=new DolGeoPHP($db);.
Class to manage ECM files.
const STATUS_OPEN_INTERNAL
Warehouse open and only operations for stock transfers/corrections allowed (not for customer shipping...
const STATUS_OPEN_ALL
Warehouse open and any operations are allowed (customer shipping, supplier dispatch,...
const STATUS_CLOSED
Warehouse closed, inactive.
Class to manage invoices.
Class to manage invoice templates.
Class to manage a Leaflet map width geometrics objects.
Class to parse product price expressions.
Class to manage predefined suppliers products.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage subscriptions of foundation members.
Class to manage translations.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
currency_name($code_iso, $withcode=0, $outputlangs=null)
Return label of currency or code+label.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
getServerTimeZoneInt($refgmtdate='now')
Return server timezone int.
removeGlobalParenthesis($string)
Remove first and last parenthesis but only if first is the opening and last the closing of the same g...
dol_now($mode='gmt')
Return date for now.
dol_print_email($email, $contactid=0, $socid=0, $addlink=0, $max=0, $showinvalid=2, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
dolForgeExplodeAnd($sqlfilters)
Explode an universal search string with AND parts.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
commonHtmlAttributeBuilder($attr, array $unescapedAttr=[])
Builds an array of safe and properly escaped HTML attributes from a key-value pair list.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dolPrintHTML($s, $allowiframe=0, $moreallowedtags=array())
Return a string (that can be on several lines) ready to be output on a HTML page.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled='', $morecss='classlink button bordertransp', $jsonopen='', $jsonclose='', $accesskey='')
Return HTML code to output a button to open a dialog popup box.
currentToken()
Return the value of token currently saved into session with name 'token'.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_print_url($url, $target='_blank', $max=32, $withpicto=0, $morecss='')
Show Url link.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolUserString($key, $default='', $tmpuser=null)
Return Dolibarr user constant string value.
GETPOSTISARRAY($paramname, $method=0)
Return true if the parameter $paramname is submit from a POST OR GET as an array.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getElementProperties($elementType)
Get an array with properties of an element.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_string_neverthesehtmltags($stringtoclean, $disallowed_tags=array('textarea'), $cleanalsosomestyles=0)
Clean a string from some undesirable HTML tags.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
dolPrintHTMLForAttribute($s, $escapeonlyhtmltags=0, $allowothertags=array())
Return a string ready to be output into an HTML attribute (alt, title, data-html, ....
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
getAdvancedPreviewUrl($modulepart, $relativepath, $alldata=0, $param='')
Return URL we can use for advanced preview links.
colorIsLight($stringcolor)
Return true if the color is light.
dolIsAllowedForPreview($file)
Return if a file is qualified for preview.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
getNonce()
Return a random string to be used as a nonce value for js.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox=0, $check='restricthtml')
Sanitize a HTML to remove js, dangerous content and external links.
dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array(), $allowlink=0, $allowscript=0, $allowstyle=0, $allowphp=0)
Clean a string to keep only desirable HTML tags.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_sanitizeKeyCode($str)
Clean a string to use it as a key or code.
isModEnabled($module)
Is Dolibarr module enabled.
array_merge_recursive_distinct(array $array1, array $array2)
Recursively merges two arrays while preserving keys and replacing existing values.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_nboflines_bis($text, $maxlinesize=0, $charset='UTF-8')
Return nb of lines of a formatted text with and (WARNING: string must not have mixed and br sep...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
multi select button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
Class to generate the form for creating a new ticket.
dol_get_trunk_prefix($db, $phone_code)
Get the national trunk prefix for a phone code.
dol_parse_phone($phone, $db=null)
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,...