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';
297 if (preg_match(
'/^(\w+)\((\d+)\)$/', $typeofdata, $reg)) {
298 if ($reg[1] ==
'varchar') {
299 $typeofdata =
'string';
300 } elseif ($reg[1] ==
'int') {
301 $typeofdata =
'numeric';
303 return 'ErrorBadParameter ' . $typeofdata;
308 if (
getDolGlobalString(
'MAIN_USE_EDIT_IN_PLACE') && !preg_match(
'/^select;|day|datepicker|dayhour|datehourpicker/', $typeofdata)) {
309 $ret .= $this->
editInPlace(
$object, $value, $htmlname, ($perm ? 1 : 0), $typeofdata, $editvalue, $extObject, $custommsg);
311 if ($editaction ==
'') {
312 $editaction =
GETPOST(
'action',
'aZ09');
314 $editmode = ($editaction ==
'edit' . $htmlname);
316 $ret .=
"<!-- formeditfieldval -->\n";
317 $ret .=
'<form method="post" action="' . $_SERVER[
"PHP_SELF"] . ($moreparam ?
'?' . $moreparam :
'') .
'">';
318 $ret .=
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
319 $ret .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
320 $ret .=
'<input type="hidden" name="' . $paramid .
'" value="' .
$object->id .
'">';
321 if (empty($notabletag)) {
322 $ret .=
'<table class="nobordernopadding centpercent">';
324 if (empty($notabletag)) {
327 if (preg_match(
'/^(string|safehtmlstring|email|phone|url)/', $typeofdata)) {
328 $tmp = explode(
':', $typeofdata);
329 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($editvalue ? $editvalue : $value) .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus spellcheck="false">';
330 } elseif (preg_match(
'/^(integer)/', $typeofdata)) {
331 $tmp = explode(
':', $typeofdata);
332 $valuetoshow =
price2num($editvalue ? $editvalue : $value, 0);
333 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $valuetoshow .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
334 } elseif (preg_match(
'/^(numeric|amount)/', $typeofdata)) {
335 $tmp = explode(
':', $typeofdata);
336 $valuetoshow =
price2num($editvalue ? $editvalue : $value);
337 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($valuetoshow !=
'' ?
price($valuetoshow) :
'') .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
338 } elseif (preg_match(
'/^(checkbox)/', $typeofdata)) {
339 $tmp = explode(
':', $typeofdata);
340 $ret .=
'<input type="checkbox" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($value ? $value :
'on') .
'"' . ($value ?
' checked' :
'') . (empty($tmp[1]) ?
'' : $tmp[1]) .
'/>';
341 } elseif (preg_match(
'/^text/', $typeofdata) || preg_match(
'/^note/', $typeofdata)) {
342 $tmp = explode(
':', $typeofdata);
343 $cols = (empty($tmp[2]) ?
'' : $tmp[2]);
345 if (preg_match(
'/%/', $cols)) {
346 $morealt =
' style="width: ' . $cols .
'"';
349 $valuetoshow = ($editvalue ? $editvalue : $value);
350 $ret .=
'<textarea id="' . $htmlname .
'" name="' . $htmlname .
'" wrap="soft" rows="' . (empty($tmp[1]) ?
'20' : $tmp[1]) .
'"' . ($cols ?
' cols="' . $cols .
'"' :
'class="quatrevingtpercent"') . $morealt .
'" autofocus>';
353 $valuetoshow = str_replace(
'&',
'&', $valuetoshow);
355 $ret .=
'</textarea><div class="clearboth"></div>';
356 } elseif ($typeofdata ==
'day' || $typeofdata ==
'datepicker') {
357 $addnowlink = empty($moreoptions[
'addnowlink']) ? 0 : $moreoptions[
'addnowlink'];
358 $adddateof = empty($moreoptions[
'adddateof']) ?
'' : $moreoptions[
'adddateof'];
359 $labeladddateof = empty($moreoptions[
'labeladddateof']) ?
'' : $moreoptions[
'labeladddateof'];
360 $ret .= $this->
selectDate($value, $htmlname, 0, 0, 1,
'form' . $htmlname, 1, $addnowlink, 0,
'',
'', $adddateof,
'', 1, $labeladddateof,
'', $gm);
361 } elseif ($typeofdata ==
'dayhour' || $typeofdata ==
'datehourpicker') {
362 $addnowlink = empty($moreoptions[
'addnowlink']) ? 0 : $moreoptions[
'addnowlink'];
363 $adddateof = empty($moreoptions[
'adddateof']) ?
'' : $moreoptions[
'adddateof'];
364 $labeladddateof = empty($moreoptions[
'labeladddateof']) ?
'' : $moreoptions[
'labeladddateof'];
365 $ret .= $this->
selectDate($value, $htmlname, 1, 1, 1,
'form' . $htmlname, 1, $addnowlink, 0,
'',
'', $adddateof,
'', 1, $labeladddateof,
'', $gm);
366 } elseif (preg_match(
'/^select;/', $typeofdata)) {
367 $arraydata = explode(
',', preg_replace(
'/^select;/',
'', $typeofdata));
368 $arraylist = array();
369 foreach ($arraydata as $val) {
370 $tmp = explode(
':', $val);
371 $tmpkey = str_replace(
'|',
':', $tmp[0]);
372 $arraylist[$tmpkey] = $tmp[1];
374 $ret .= $this->
selectarray($htmlname, $arraylist, $value);
375 } elseif (preg_match(
'/^link/', $typeofdata)) {
377 } elseif (preg_match(
'/^ckeditor/', $typeofdata)) {
378 $tmp = explode(
':', $typeofdata);
379 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
380 $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]));
381 $ret .= $doleditor->Create(1);
382 } elseif ($typeofdata ==
'asis') {
383 $ret .= ($editvalue ? $editvalue : $value);
385 if (empty($notabletag)) {
390 if (empty($notabletag)) {
394 $ret .=
'<input type="submit" class="smallpaddingimp nomargingtop nomarginbottom button' . (empty($notabletag) ?
'' :
' ') .
'" name="modify" value="' . $langs->trans(
"Save") .
'">';
395 if (preg_match(
'/ckeditor|textarea/', $typeofdata) && empty($notabletag)) {
396 $ret .=
'<br>' .
"\n";
398 $ret .=
'<input type="submit" class="smallpaddingimp nomargingtop nomarginbottom button button-cancel' . (empty($notabletag) ?
'' :
' ') .
'" name="cancel" value="' . $langs->trans(
"Cancel") .
'">';
399 if (empty($notabletag)) {
403 if (empty($notabletag)) {
404 $ret .=
'</tr></table>' .
"\n";
406 $ret .=
'</form>' .
"\n";
408 if (preg_match(
'/^email/', $typeofdata)) {
410 } elseif (preg_match(
'/^phone/', $typeofdata)) {
412 } elseif (preg_match(
'/^url/', $typeofdata)) {
414 } elseif (preg_match(
'/^(amount|numeric)/', $typeofdata)) {
415 $ret .= ($value !=
'' ?
price($value, 0, $langs, 0, -1, -1,
$conf->currency) :
'');
416 } elseif (preg_match(
'/^checkbox/', $typeofdata)) {
417 $tmp = explode(
':', $typeofdata);
418 $ret .=
'<input type="checkbox" disabled id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $value .
'"' . ($value ?
' checked' :
'') . ($tmp[1] ? $tmp[1] :
'') .
'/>';
419 } elseif (preg_match(
'/^text/', $typeofdata) || preg_match(
'/^note/', $typeofdata)) {
421 } elseif (preg_match(
'/^(safehtmlstring|restricthtml)/', $typeofdata)) {
423 } elseif ($typeofdata ==
'day' || $typeofdata ==
'datepicker') {
424 $ret .=
'<span class="valuedate">' .
dol_print_date($value,
'day', $gm) .
'</span>';
425 } elseif ($typeofdata ==
'dayhour' || $typeofdata ==
'datehourpicker') {
426 $ret .=
'<span class="valuedate">' .
dol_print_date($value,
'dayhour', $gm) .
'</span>';
427 } elseif (preg_match(
'/^select;/', $typeofdata)) {
428 $arraydata = explode(
',', preg_replace(
'/^select;/',
'', $typeofdata));
429 $arraylist = array();
430 foreach ($arraydata as $val) {
431 $tmp = explode(
':', $val);
432 $arraylist[$tmp[0]] = $tmp[1];
434 $ret .= $arraylist[$value];
435 if ($htmlname ==
'fk_product_type') {
437 $ret =
img_picto($langs->trans(
"Product"),
'product',
'class="paddingleftonly paddingrightonly colorgrey"') . $ret;
439 $ret =
img_picto($langs->trans(
"Service"),
'service',
'class="paddingleftonly paddingrightonly colorgrey"') . $ret;
442 } elseif (preg_match(
'/^ckeditor/', $typeofdata)) {
445 $firstline = preg_replace(
'/<br>.*/',
'', $tmpcontent);
446 $firstline = preg_replace(
'/[\n\r].*/',
'', $firstline);
447 $tmpcontent = $firstline . ((strlen($firstline) != strlen($tmpcontent)) ?
'...' :
'');
453 if (empty($moreoptions[
'valuealreadyhtmlescaped'])) {
461 if ($formatfunc && method_exists(
$object, $formatfunc)) {
462 $ret =
$object->$formatfunc($ret);
482 global
$conf, $langs, $extralanguages;
487 $arrayoflangcode = array();
492 if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
493 if (!is_object($extralanguages)) {
494 include_once DOL_DOCUMENT_ROOT .
'/core/class/extralanguages.class.php';
497 $extralanguages->fetch_name_extralanguages(
'societe');
502 if (empty($extralanguages->attributes[
$object->element]) || !is_array($extralanguages->attributes[
$object->element]) || empty($extralanguages->attributes[
$object->element][$fieldname])) {
506 $result .=
'<!-- Widget for translation -->' .
"\n";
507 $result .=
'<div class="inline-block paddingleft image-' .
$object->element .
'-' . $fieldname .
'">';
508 $s =
img_picto($langs->trans(
"ShowOtherLanguages"),
'language',
'', 0, 0, 0,
'',
'fa-15 editfieldlang');
512 $result .=
'<div class="inline-block hidden field-' .
$object->element .
'-' . $fieldname .
'">';
514 $resultforextrlang =
'';
515 foreach ($arrayoflangcode as $langcode) {
516 $valuetoshow =
GETPOSTISSET(
'field-' .
$object->element .
"-" . $fieldname .
"-" . $langcode) ?
GETPOST(
'field-' .
$object->element .
'-' . $fieldname .
"-" . $langcode, $check) :
'';
517 if (empty($valuetoshow)) {
518 $object->fetchValuesForExtraLanguages();
520 $valuetoshow =
$object->array_languages[$fieldname][$langcode];
524 $resultforextrlang .= $s;
527 if ($typeofdata ==
'textarea') {
528 $resultforextrlang .=
'<textarea name="field-' .
$object->element .
"-" . $fieldname .
"-" . $langcode .
'" id="' . $fieldname .
"-" . $langcode .
'" class="' . $morecss .
'" rows="' . ROWS_2 .
'" wrap="soft">';
529 $resultforextrlang .= $valuetoshow;
530 $resultforextrlang .=
'</textarea>';
532 $resultforextrlang .=
'<input type="text" class="inputfieldforlang ' . ($morecss ?
' ' . $morecss :
'') .
'" name="field-' .
$object->element .
'-' . $fieldname .
'-' . $langcode .
'" value="' . $valuetoshow .
'">';
535 $result .= $resultforextrlang;
538 $result .=
'<script nonce="' .
getNonce() .
'">$(".image-' .
$object->element .
'-' . $fieldname .
'").click(function() { console.log("Toggle lang widget"); jQuery(".field-' .
$object->element .
'-' . $fieldname .
'").toggle(); });</script>';
557 protected function editInPlace(
$object, $value, $htmlname, $condition, $inputType =
'textarea', $editvalue =
null, $extObject =
null, $custommsg =
null)
562 if (preg_match(
'/^text/', $inputType)) {
564 } elseif (preg_match(
'/^numeric/', $inputType)) {
565 $value =
price($value);
566 } elseif ($inputType ==
'day' || $inputType ==
'datepicker') {
572 $table_element =
false;
576 $ext_element =
false;
577 $button_only =
false;
584 $table_element =
$object->table_element;
588 if (is_object($extObject)) {
589 $ext_element = $extObject->element;
592 if (preg_match(
'/^(string|email|numeric)/', $inputType)) {
593 $tmp = explode(
':', $inputType);
594 $inputType = $tmp[0];
595 if (!empty($tmp[1])) {
596 $inputOption = $tmp[1];
598 if (!empty($tmp[2])) {
599 $savemethod = $tmp[2];
601 $out .=
'<input id="width_' . $htmlname .
'" value="' . $inputOption .
'" type="hidden"/>' .
"\n";
602 } elseif ((preg_match(
'/^day$/', $inputType)) || (preg_match(
'/^datepicker/', $inputType)) || (preg_match(
'/^datehourpicker/', $inputType))) {
603 $tmp = explode(
':', $inputType);
604 $inputType = $tmp[0];
605 if (!empty($tmp[1])) {
606 $inputOption = $tmp[1];
608 if (!empty($tmp[2])) {
609 $savemethod = $tmp[2];
612 $out .=
'<input id="timestamp" type="hidden"/>' .
"\n";
613 } elseif (preg_match(
'/^(select|autocomplete)/', $inputType)) {
614 $tmp = explode(
':', $inputType);
615 $inputType = $tmp[0];
616 $loadmethod = $tmp[1];
617 if (!empty($tmp[2])) {
618 $savemethod = $tmp[2];
620 if (!empty($tmp[3])) {
623 } elseif (preg_match(
'/^textarea/', $inputType)) {
624 $tmp = explode(
':', $inputType);
625 $inputType = $tmp[0];
626 $rows = (empty($tmp[1]) ?
'8' : $tmp[1]);
627 $cols = (empty($tmp[2]) ?
'80' : $tmp[2]);
628 } elseif (preg_match(
'/^ckeditor/', $inputType)) {
629 $tmp = explode(
':', $inputType);
630 $inputType = $tmp[0];
632 if (!empty($tmp[2])) {
635 if (!empty($tmp[3])) {
638 if (!empty($tmp[4])) {
639 $savemethod = $tmp[4];
643 $out .=
'<input id="ckeditor_toolbar" value="' . $toolbar .
'" type="hidden"/>' .
"\n";
645 $inputType =
'textarea';
649 $out .=
'<input id="element_' . $htmlname .
'" value="' . $element .
'" type="hidden"/>' .
"\n";
650 $out .=
'<input id="table_element_' . $htmlname .
'" value="' . $table_element .
'" type="hidden"/>' .
"\n";
651 $out .=
'<input id="fk_element_' . $htmlname .
'" value="' . $fk_element .
'" type="hidden"/>' .
"\n";
652 $out .=
'<input id="loadmethod_' . $htmlname .
'" value="' . $loadmethod .
'" type="hidden"/>' .
"\n";
653 if (!empty($savemethod)) {
654 $out .=
'<input id="savemethod_' . $htmlname .
'" value="' . $savemethod .
'" type="hidden"/>' .
"\n";
656 if (!empty($ext_element)) {
657 $out .=
'<input id="ext_element_' . $htmlname .
'" value="' . $ext_element .
'" type="hidden"/>' .
"\n";
659 if (!empty($custommsg)) {
660 if (is_array($custommsg)) {
661 if (!empty($custommsg[
'success'])) {
662 $out .=
'<input id="successmsg_' . $htmlname .
'" value="' . $custommsg[
'success'] .
'" type="hidden"/>' .
"\n";
664 if (!empty($custommsg[
'error'])) {
665 $out .=
'<input id="errormsg_' . $htmlname .
'" value="' . $custommsg[
'error'] .
'" type="hidden"/>' .
"\n";
668 $out .=
'<input id="successmsg_' . $htmlname .
'" value="' . $custommsg .
'" type="hidden"/>' .
"\n";
671 if ($inputType ==
'textarea') {
672 $out .=
'<input id="textarea_' . $htmlname .
'_rows" value="' . $rows .
'" type="hidden"/>' .
"\n";
673 $out .=
'<input id="textarea_' . $htmlname .
'_cols" value="' . $cols .
'" type="hidden"/>' .
"\n";
675 $out .=
'<span id="viewval_' . $htmlname .
'" class="viewval_' . $inputType . ($button_only ?
' inactive' :
' active') .
'">' . $value .
'</span>' .
"\n";
676 $out .=
'<span id="editval_' . $htmlname .
'" class="editval_' . $inputType . ($button_only ?
' inactive' :
' active') .
' hideobject">' . (!empty($editvalue) ? $editvalue : $value) .
'</span>' .
"\n";
702 public function textwithtooltip($text, $htmltext, $tooltipon = 1, $direction = 0, $img =
'', $extracss =
'', $notabs = 3, $incbefore =
'', $noencodehtmltext = 0, $tooltiptrigger =
'', $forcenowrap = 0)
705 $text = $incbefore . $text;
710 $direction = (int) $direction;
720 $htmltext = str_replace(array(
"\r",
"\n"),
'', $htmltext);
723 if ($direction < 0) {
724 $extracss = ($extracss ? $extracss :
'') . ($notabs != 3 ?
' inline-block' :
'');
725 $extrastyle =
'padding: 0px; padding-left: 2px;';
727 if ($direction > 0) {
728 $extracss = ($extracss ? $extracss :
'') . ($notabs != 3 ?
' inline-block' :
'');
729 $extrastyle =
'padding: 0px; padding-right: 2px;';
732 $classfortooltip =
'classfortooltip';
737 if ($tooltiptrigger ==
'') {
738 $htmltext = str_replace(
'"',
'"', $htmltext);
740 $classfortooltip =
'classfortooltiponclick';
741 $textfordialog .=
'<div style="display: none;" id="idfortooltiponclick_' . $tooltiptrigger .
'" class="classfortooltiponclicktext"';
745 $textfordialog .=
' title="'.$langs->trans(
"Note").
'"';
747 $textfordialog .=
'>' . $htmltext .
'</div>';
749 if ($tooltipon == 2 || $tooltipon == 3) {
750 $paramfortooltipimg =
' class="' . $classfortooltip . ($notabs != 3 ?
' inline-block' :
'') . ($extracss ?
' ' . $extracss :
'') .
'" style="padding: 0px;' . ($extrastyle ?
' ' . $extrastyle :
'') .
'"';
751 if ($tooltiptrigger ==
'') {
752 $paramfortooltipimg .=
' title="' . ($noencodehtmltext ? $htmltext :
dol_escape_htmltag($htmltext, 1, 0,
'span', 0, 1)) .
'"';
754 $paramfortooltipimg .=
' dolid="' . $tooltiptrigger .
'"';
757 $paramfortooltipimg = ($extracss ?
' class="' . $extracss .
'"' :
'') . ($extrastyle ?
' style="' . $extrastyle .
'"' :
'');
759 if ($tooltipon == 1 || $tooltipon == 3) {
760 $paramfortooltiptd =
' class="' . ($tooltipon == 3 ?
'cursorpointer ' :
'') . $classfortooltip . ($tag !=
'td' ?
' inline-block' :
'') . ($extracss ?
' ' . $extracss :
'') .
'" style="padding: 0px;' . ($extrastyle ?
' ' . $extrastyle :
'') .
'" ';
761 if ($tooltiptrigger ==
'') {
762 $paramfortooltiptd .=
' title="' . ($noencodehtmltext ? $htmltext :
dol_escape_htmltag($htmltext, 1, 0,
'span', 0, 1)) .
'"';
764 $paramfortooltiptd .=
' dolid="' . $tooltiptrigger .
'"';
767 $paramfortooltiptd = ($extracss ?
' class="' . $extracss .
'"' :
'') . ($extrastyle ?
' style="' . $extrastyle .
'"' :
'');
769 if (empty($notabs)) {
770 $s .=
'<table class="nobordernopadding"><tr style="height: auto;">';
771 } elseif ($notabs == 2) {
772 $s .=
'<div class="inline-block' . ($forcenowrap ?
' nowrap' :
'') .
'">';
775 if ($direction < 0) {
776 $s .=
'<' . $tag . $paramfortooltipimg;
778 $s .=
' class="valigntop" width="14"';
780 $s .=
'>' . $textfordialog . $img .
'</' . $tag .
'>';
784 if ((
string) $text !=
'') {
785 $s .=
'<' . $tag . $paramfortooltiptd .
'>' . $text .
'</' . $tag .
'>';
788 if ($direction > 0) {
789 $s .=
'<' . $tag . $paramfortooltipimg;
791 $s .=
' class="valignmiddle" width="14"';
793 $s .=
'>' . $textfordialog . $img .
'</' . $tag .
'>';
795 if (empty($notabs)) {
796 $s .=
'</tr></table>';
797 } elseif ($notabs == 2) {
818 public function textwithpicto($text, $htmltooltip, $direction = 1, $type =
'help', $extracss =
'valignmiddle', $noencodehtmltext = 0, $notabs = 3, $tooltiptrigger =
'', $forcenowrap = 0)
820 global
$conf, $langs;
825 } elseif ($type ==
'1') {
829 $tooltiptrigger = preg_replace(
'/[^a-z0-9]/i',
'', $tooltiptrigger);
831 if (preg_match(
'/onsmartphone$/', $tooltiptrigger) && empty(
$conf->dol_no_mouse_hover)) {
832 $tooltiptrigger = preg_replace(
'/^.*onsmartphone$/',
'', $tooltiptrigger);
835 if ($tooltiptrigger) {
836 $alt = $langs->transnoentitiesnoconv(
"ClickToShowHelp");
840 if (empty(
$conf->use_javascript_ajax)) {
841 if ($type ==
'info' || $type ==
'infoclickable' || $type ==
'help' || $type ==
'helpclickable') {
850 if (!empty(
$conf->dol_no_mouse_hover) && empty($tooltiptrigger)) {
851 if ($type ==
'info' || $type ==
'infoclickable' || $type ==
'help' || $type ==
'helpclickable') {
862 if ($type ==
'info') {
863 $img =
img_help(($tooltiptrigger !=
'' ? 2 : 0), $alt);
864 } elseif ($type ==
'help') {
865 $img =
img_help(($tooltiptrigger !=
'' ? 2 : 1), $alt);
866 } elseif ($type ==
'helpclickable') {
867 $img =
img_help(($tooltiptrigger !=
'' ? 2 : 1), $alt);
868 } elseif ($type ==
'warning') {
870 } elseif ($type !=
'none') {
875 $tooltipon = ((($tooltiptrigger && !$img) || strpos($type,
'clickable')) ? 3 : 2);
877 return $this->
textwithtooltip($text, $htmltooltip, $tooltipon, $direction, $img, $extracss, $notabs,
'', $noencodehtmltext, $tooltiptrigger, $forcenowrap);
890 public function selectMassAction($selected, $arrayofaction, $alwaysvisible = 0, $name =
'massaction', $cssclass =
'checkforselect')
892 global
$conf, $langs, $hookmanager;
895 $ret =
'<div class="centpercent center">';
896 $ret .=
'<select class="flat' . (empty(
$conf->use_javascript_ajax) ?
'' :
' hideobject') .
' ' . $name .
' ' . $name .
'select valignmiddle alignstart" id="' . $name .
'" name="' . $name .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
'>';
899 $parameters = array();
900 $reshook = $hookmanager->executeHooks(
'addMoreMassActions', $parameters);
903 if (is_array($arrayofaction) && count($arrayofaction) == 0 && empty($hookmanager->resPrint)) {
906 if (empty($reshook)) {
907 $ret .=
'<option value="0"' . ($disabled ?
' disabled="disabled"' :
'') .
'>-- ' . $langs->trans(
"SelectAction") .
' --</option>';
908 if (is_array($arrayofaction)) {
909 foreach ($arrayofaction as $code => $label) {
910 $ret .=
'<option value="' . $code .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' data-html="' .
dol_escape_htmltag($label) .
'">' . $label .
'</option>';
914 $ret .= $hookmanager->resPrint;
918 if (empty(
$conf->dol_optimize_smallscreen)) {
923 $ret .=
'<input type="submit" name="confirmmassactioninvisible" style="display: none" tabindex="-1">';
924 $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")) .
'">';
927 if (!empty(
$conf->use_javascript_ajax)) {
928 $ret .=
'<!-- JS CODE TO ENABLE mass action select -->
930 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 */
931 atleastoneselected=0;
932 jQuery("."+cssclass).each(function( index ) {
933 /* console.log( index + ": " + $( this ).text() ); */
934 if ($(this).is(\':checked\')) atleastoneselected++;
937 console.log("initCheckForSelect mode="+mode+" name="+name+" cssclass="+cssclass+" atleastoneselected="+atleastoneselected);
939 if (atleastoneselected || ' . ((int) $alwaysvisible) .
') {
940 jQuery("."+name).show();
941 ' . ($selected ?
'if (atleastoneselected) { jQuery("."+name+"select").val("' . $selected .
'").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', false); }' :
'') .
'
942 ' . ($selected ?
'if (! atleastoneselected) { jQuery("."+name+"select").val("0").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', true); } ' :
'') .
'
944 jQuery("."+name).hide();
945 jQuery("."+name+"other").hide();
949 jQuery(document).ready(function () {
950 initCheckForSelect(0, "' . $name .
'", "' . $cssclass .
'");
951 jQuery(".' . $cssclass .
'").change(function() {
952 console.log("A change was done on .' . $cssclass .
'");
953 initCheckForSelect(1, "' . $name .
'", "' . $cssclass .
'");
955 jQuery(".' . $name .
'select").change(function() {
956 var massaction = $( this ).val();
957 var urlform = $( this ).closest("form").attr("action").replace("#show_files","");
958 if (massaction == "builddoc") {
959 urlform = urlform + "#show_files";
961 $( this ).closest("form").attr("action", urlform);
962 console.log("we select a mass action name=' . $name .
' massaction="+massaction+" - "+urlform);
963 /* Warning: if you set submit button to disabled, post using Enter will no more work if there is no other button */
964 if ($(this).val() != \'0\') {
965 jQuery(".' . $name .
'confirmed").prop(\'disabled\', false);
966 jQuery(".' . $name .
'other").hide(); /* To disable if another div was open */
967 jQuery(".' . $name .
'"+massaction).show();
969 jQuery(".' . $name .
'confirmed").prop(\'disabled\', true);
970 jQuery(".' . $name .
'other").hide(); /* To disable any div open */
1000 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)
1005 $langs->load(
"dict");
1007 $selected = (
string) $selected;
1011 $countryArray = array();
1012 $favorite = array();
1014 $atleastonefavorite = 0;
1016 $sql =
"SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite, eec";
1017 $sql .=
" FROM " . $this->db->prefix() .
"c_country";
1018 $sql .=
" WHERE active > 0";
1021 dol_syslog(get_class($this) .
"::select_country", LOG_DEBUG);
1023 $resql = $this->db->query($sql);
1025 $out .=
'<select id="select' . $htmlname .
'" class="flat maxwidth200onsmartphone selectcountry' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" ' . $htmloption .
'>';
1026 $num = $this->db->num_rows($resql);
1030 $obj = $this->db->fetch_object($resql);
1034 'rowid' => (
int) $obj->rowid,
1035 'code_iso' => (
string) $obj->code_iso,
1036 'code_iso3' => (
string) $obj->code_iso3,
1037 '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 :
'')),
1038 'favorite' => (
string) $obj->favorite,
1039 'eec' => (
string) $obj->eec,
1041 $favorite[$i] = $obj->favorite;
1046 if (empty($disablefavorites)) {
1047 $array1_sort_order = SORT_DESC;
1048 $array2_sort_order = SORT_ASC;
1049 array_multisort($favorite, $array1_sort_order, $label, $array2_sort_order, $countryArray);
1055 if (is_numeric($showempty)) {
1056 $out .=
'<option value=""> </option>' .
"\n";
1058 $out .=
'<option value="-1">' . $langs->trans($showempty) .
'</option>' .
"\n";
1062 if ($addspecialentries) {
1064 $out .=
'<option value="special_allnotme"' . ($selected ==
'special_allnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesExceptMe", $langs->transnoentitiesnoconv(
"Country" .
$mysoc->country_code)) .
'</option>';
1065 $out .=
'<option value="special_eec"' . ($selected ==
'special_eec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEEC") .
'</option>';
1067 $out .=
'<option value="special_eecnotme"' . ($selected ==
'special_eecnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEECExceptMe", $langs->transnoentitiesnoconv(
"Country" .
$mysoc->country_code)) .
'</option>';
1069 $out .=
'<option value="special_noteec"' . ($selected ==
'special_noteec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesNotInEEC") .
'</option>';
1070 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1073 foreach ($countryArray as $row) {
1075 if (empty($row[
'rowid'])) {
1078 if (is_array($exclude_country_code) && count($exclude_country_code) && in_array($row[
'code_iso'], $exclude_country_code)) {
1082 if (empty($disablefavorites) && $row[
'favorite'] && $row[
'code_iso']) {
1083 $atleastonefavorite++;
1085 if (empty($row[
'favorite']) && $atleastonefavorite) {
1086 $atleastonefavorite = 0;
1087 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1091 if ($row[
'label']) {
1092 $labeltoshow .=
dol_trunc($row[
'label'], $maxlength,
'middle');
1094 $labeltoshow .=
' ';
1096 if ($row[
'code_iso']) {
1097 $labeltoshow .=
' <span class="opacitymedium">(' . $row[
'code_iso'] .
')</span>';
1098 if (empty($hideflags)) {
1099 $tmpflag =
picto_from_langcode($row[
'code_iso'],
'class="saturatemedium paddingrightonly"', 1);
1100 $labeltoshow = $tmpflag .
' ' . $labeltoshow;
1104 if ($selected && $selected !=
'-1' && ($selected == $row[
'rowid'] || $selected == $row[
'code_iso'] || $selected == $row[
'code_iso3'] || $selected == $row[
'label'])) {
1105 $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']) .
'">';
1107 $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']) .
'">';
1110 $out .=
'</option>' .
"\n";
1113 $out .=
'</select>';
1119 if (empty($forcecombo)) {
1120 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1121 $out .=
ajax_combobox(
'select' . $htmlname, array(), 0, 0,
'resolve');
1137 public function selectPhoneCode($selected =
'', $htmlname =
'phone_code', $morecss =
'maxwidth150', $showempty = 0, $country_id_hint = 0)
1141 $langs->load(
"dict");
1144 $codeArray = array();
1145 $favorite = array();
1147 $atleastonefavorite = 0;
1149 $sql =
"SELECT rowid, code, label, phone_code, favorite, trunk_prefix";
1150 $sql .=
" FROM ".$this->db->prefix().
"c_country";
1151 $sql .=
" WHERE active > 0 AND phone_code IS NOT NULL AND phone_code != ''";
1153 dol_syslog(get_class($this).
"::selectPhoneCode", LOG_DEBUG);
1154 $resql = $this->db->query($sql);
1156 $num = $this->db->num_rows($resql);
1159 $obj = $this->db->fetch_object($resql);
1161 $translabel = ($obj->code && $langs->transnoentitiesnoconv(
"Country".$obj->code) !=
"Country".$obj->code) ? $langs->transnoentitiesnoconv(
"Country".$obj->code) : $obj->label;
1163 $codeArray[$i][
'rowid'] = $obj->rowid;
1164 $codeArray[$i][
'code'] = $obj->code;
1165 $codeArray[$i][
'label'] = $translabel;
1166 $codeArray[$i][
'phone_code'] =
'+'.$obj->phone_code;
1167 $codeArray[$i][
'favorite'] = $obj->favorite;
1168 $codeArray[$i][
'trunk_prefix'] = $obj->trunk_prefix;
1169 $favorite[$i] = $obj->favorite;
1174 $array1_sort_order = SORT_DESC;
1175 $array2_sort_order = SORT_ASC;
1176 array_multisort($favorite, $array1_sort_order, $label, $array2_sort_order, $codeArray);
1178 $out .=
'<select id="select'.$htmlname.
'" class="flat selectphonecode'.($morecss ?
' '.$morecss :
'').
'" name="'.$htmlname.
'">';
1181 $out .=
'<option value=""> </option>'.
"\n";
1186 $firstMatchIdx = -1;
1187 if ($selected !==
'') {
1188 foreach ($codeArray as $idx => $row) {
1189 if ($row[
'phone_code'] == $selected) {
1190 if ($firstMatchIdx < 0) {
1191 $firstMatchIdx = $idx;
1193 if ($country_id_hint > 0 && $row[
'rowid'] == $country_id_hint) {
1194 $selectedIdx = $idx;
1199 if ($selectedIdx < 0 && $firstMatchIdx >= 0) {
1200 $selectedIdx = $firstMatchIdx;
1204 foreach ($codeArray as $idx => $row) {
1205 if (empty($row[
'code'])) {
1209 if ($row[
'favorite']) {
1210 $atleastonefavorite++;
1212 if (empty($row[
'favorite']) && $atleastonefavorite) {
1213 $atleastonefavorite = 0;
1214 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1217 $tmpflag =
picto_from_langcode($row[
'code'],
'class="saturatemedium paddingrightonly"', 1);
1220 $selectlabel = ($tmpflag ? $tmpflag.
' ' :
'').$row[
'code'];
1223 $labeltoshow = ($tmpflag ? $tmpflag.
' ' :
'').$row[
'label'].
' '.$row[
'phone_code'];
1225 $out .=
'<option value="'.dol_escape_htmltag($row[
'phone_code']).
'"';
1226 if ($idx === $selectedIdx) {
1227 $out .=
' selected';
1229 $out .=
' data-html="'.dol_escape_htmltag($labeltoshow).
'"';
1230 $out .=
' data-select-html="'.dol_escape_htmltag($selectlabel).
'"';
1231 $out .=
' data-country-id="'.((int) $row[
'rowid']).
'"';
1232 $out .=
' data-trunk-prefix="'.dol_escape_htmltag((
string) $row[
'trunk_prefix']).
'"';
1235 $out .=
'</option>'.
"\n";
1237 $out .=
'</select>';
1243 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1244 $out .=
ajax_combobox(
'select'.$htmlname, array(), 0, 0,
'resolve');
1265 public function showPhoneInput($phoneValue, $htmlname, $country_id_hint = 0, $picto =
'object_phoning', $morecss =
'maxwidth150', $maxlength = 0, $countrySelectorId =
'selectcountry_id')
1269 include_once DOL_DOCUMENT_ROOT.
'/core/lib/phone.lib.php';
1271 $codename = $htmlname.
'_code';
1274 if (empty($country_id_hint) && !empty(
$mysoc->country_id)) {
1275 $country_id_hint =
$mysoc->country_id;
1282 $fullPhone = (
string) $phoneValue;
1291 $selectedCode = $phonecode;
1292 $numberValue = $parsed[
'number'];
1295 if ($numberValue !==
'' && $selectedCode !==
'') {
1297 if ($trunkPrefix !==
'' && strpos($numberValue, $trunkPrefix) !== 0) {
1298 $numberValue = $trunkPrefix.$numberValue;
1306 $out .=
img_picto(
'', $picto,
'class="pictofixedwidth"');
1309 $out .= $this->
selectPhoneCode($selectedCode, $codename,
'maxwidth75 phone_code_select', 0, $country_id_hint);
1312 $out .=
'<input type="tel" inputmode="numeric" pattern="[0-9]*" id="'.dol_escape_htmltag($htmlname).
'_input" class="'.
dol_escape_htmltag($morecss).
'"';
1313 if ($maxlength > 0) {
1314 $out .=
' maxlength="'.$maxlength.
'"';
1316 $out .=
' value="'.dol_escape_htmltag($numberValue).
'">';
1341 $selectId =
'select'.dol_escape_js($codename);
1343 $out =
"\n".
'<script type="text/javascript">'.
"\n";
1344 $out .=
'jQuery(document).ready(function() {'.
"\n";
1345 $out .=
' function syncPhoneField_'.$hiddenId.
'() {'.
"\n";
1346 $out .=
' var selectEl = jQuery("#'.$selectId.
'");'.
"\n";
1347 $out .=
' var code = selectEl.val() || "";'.
"\n";
1348 $out .=
' var number = (jQuery("#'.$inputId.
'").val() || "").replace(/[^0-9]/g, "");'.
"\n";
1349 $out .=
' if (code && number) {'.
"\n";
1350 $out .=
' var selOpt = selectEl[0] && selectEl[0].selectedOptions && selectEl[0].selectedOptions[0];'.
"\n";
1351 $out .=
' var trunkPrefix = selOpt ? (selOpt.getAttribute("data-trunk-prefix") || "") : "";'.
"\n";
1352 $out .=
' if (trunkPrefix !== "" && number.indexOf(trunkPrefix) === 0) {'.
"\n";
1353 $out .=
' number = number.substring(trunkPrefix.length);'.
"\n";
1355 $out .=
' jQuery("#'.$hiddenId.
'").val(code + " " + number);'.
"\n";
1356 $out .=
' } else if (number) {'.
"\n";
1357 $out .=
' jQuery("#'.$hiddenId.
'").val(number);'.
"\n";
1358 $out .=
' } else {'.
"\n";
1359 $out .=
' jQuery("#'.$hiddenId.
'").val("");'.
"\n";
1362 $out .=
' jQuery("#'.$selectId.
'").on("change", function() { syncPhoneField_'.$hiddenId.
'(); });'.
"\n";
1363 $out .=
' jQuery("#'.$inputId.
'").on("input change", function() { syncPhoneField_'.$hiddenId.
'(); });'.
"\n";
1365 $out .=
'</script>'.
"\n";
1381 if ($this->phoneInputSharedJsLoaded) {
1384 $this->phoneInputSharedJsLoaded =
true;
1386 $out =
"\n".
'<script type="text/javascript">'.
"\n";
1387 $out .=
'jQuery(document).ready(function() {'.
"\n";
1388 $out .=
' jQuery("#'.dol_escape_js($countrySelectorId).
'").on("change", function() {'.
"\n";
1389 $out .=
' var country_id = jQuery(this).val();'.
"\n";
1390 $out .=
' if (country_id) {'.
"\n";
1391 $out .=
' jQuery.getJSON("'.DOL_URL_ROOT.
'/core/ajax/getphonecode.php", {country_id: country_id, token: "'.
currentToken().
'"}, function(data) {'.
"\n";
1392 $out .=
' if (data.phone_code) {'.
"\n";
1393 $out .=
' jQuery(".phone_code_select").each(function() {'.
"\n";
1394 $out .=
' jQuery(this).val(data.phone_code).trigger("change");'.
"\n";
1395 $out .=
' });'.
"\n";
1397 $out .=
' });'.
"\n";
1399 $out .=
' });'.
"\n";
1401 $out .=
'</script>'.
"\n";
1422 global $langs, $form;
1424 $form =
new Form($this->db);
1426 $htmltoenteralink =
'';
1430 $htmltoenteralink .=
'<tr class="liste_titre">';
1431 $htmltoenteralink .=
'<td class="nowrap"></td>';
1432 $htmltoenteralink .=
'<td>' . $langs->trans(
"Ref") .
'</td>';
1433 $htmltoenteralink .=
'<td>' . $langs->trans(
"RefCustomer") .
'</td>';
1434 $htmltoenteralink .=
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
1435 $htmltoenteralink .=
'<td>' . $langs->trans(
"Company") .
'</td>';
1436 $htmltoenteralink .=
'</tr>';
1440 $objp = $this->db->fetch_object($resqllist);
1441 $alreadylinked =
false;
1442 if (!empty(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key])) {
1443 if (in_array($objp->rowid, array_values(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key]))) {
1444 $alreadylinked =
true;
1447 $htmltoenteralink .=
'<tr class="oddeven">';
1448 $htmltoenteralink .=
'<td>';
1449 if ($alreadylinked) {
1450 $htmltoenteralink .=
img_picto(
'',
'link');
1452 $htmltoenteralink .=
'<input type="checkbox" name="idtolinkto[' . $key .
'_' . $objp->rowid .
']" id="' . $key .
'_' . $objp->rowid .
'" value="' . $objp->rowid .
'">';
1454 $htmltoenteralink .=
'</td>';
1455 $htmltoenteralink .=
'<td>';
1456 if (!$alreadylinked) {
1457 $htmltoenteralink .=
'<label for="' . $key .
'_' . $objp->rowid .
'">';
1459 $htmltoenteralink .= $objp->ref;
1460 if (!$alreadylinked) {
1461 $htmltoenteralink .=
'</label>';
1463 $htmltoenteralink .=
'</td>';
1464 $htmltoenteralink .=
'<td>' . (!empty($objp->ref_client) ? $objp->ref_client : (!empty($objp->ref_supplier) ? $objp->ref_supplier :
'')) .
'</td>';
1465 $htmltoenteralink .=
'<td class="right">';
1466 if ($possiblelink[
'label'] ==
'LinkToContract') {
1467 $htmltoenteralink .= $form->textwithpicto(
'', $langs->trans(
"InformationOnLinkToContract")) .
' ';
1469 $htmltoenteralink .=
'<span class="amount">' . (isset($objp->total_ht) ?
price($objp->total_ht) :
'') .
'</span>';
1470 $htmltoenteralink .=
'</td>';
1471 $htmltoenteralink .=
'<td>' . $objp->name .
'</td>';
1472 $htmltoenteralink .=
'</tr>';
1476 return $htmltoenteralink;
1496 global $langs, $form;
1497 require_once DOL_DOCUMENT_ROOT .
'/eventorganization/class/conferenceorboothattendee.class.php';
1498 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
1499 require_once DOL_DOCUMENT_ROOT .
'/projet/class/project.class.php';
1501 $companystatic =
new Societe($this->db);
1502 $projectstatic =
new Project($this->db);
1504 $form =
new Form($this->db);
1506 $htmltoenteralink =
'';
1510 $htmltoenteralink .=
'<tr class="liste_titre">';
1511 $htmltoenteralink .=
'<td class="nowrap"></td>';
1512 $htmltoenteralink .=
'<td>' . $langs->trans(
"Ref") .
'</td>';
1513 $htmltoenteralink .=
'<td>' . $langs->trans(
"Name") .
'</td>';
1514 $htmltoenteralink .=
'<td>' . $langs->trans(
"Email") .
'</td>';
1515 $htmltoenteralink .=
'<td>' . $langs->trans(
"Company") .
'</td>';
1516 $htmltoenteralink .=
'<td>' . $langs->trans(
"Project") .
'</td>';
1517 $htmltoenteralink .=
'<td>' . $langs->trans(
"DateOfRegistration") .
'</td>';
1518 $htmltoenteralink .=
'</tr>';
1522 $objp = $this->db->fetch_object($resqllist);
1523 $alreadylinked =
false;
1524 if (!empty(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key])) {
1525 if (in_array($objp->rowid, array_values(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key]))) {
1526 $alreadylinked =
true;
1529 $htmltoenteralink .=
'<tr class="oddeven">';
1530 $htmltoenteralink .=
'<td>';
1531 if ($alreadylinked) {
1532 $htmltoenteralink .=
img_picto(
'',
'link');
1534 $htmltoenteralink .=
'<input type="checkbox" name="idtolinkto[' . $key .
'_' . $objp->rowid .
']" id="' . $key .
'_' . $objp->rowid .
'" value="' . $objp->rowid .
'">';
1536 $htmltoenteralink .=
'</td>';
1537 $fetchattendee = $attendeestatic->fetch($objp->rowid);
1538 if ($fetchattendee) {
1539 $htmltoenteralink .=
'<td>' . $attendeestatic->getNomUrl(0).
'</td>';
1541 $htmltoenteralink .=
'<td><label for="' . $key .
'_' . $objp->rowid .
'">' . $objp->ref .
'</label></td>';
1543 $htmltoenteralink .=
'<td>' . $objp->name .
'</td>';
1544 $htmltoenteralink .=
'<td>' . $objp->email .
'</td>';
1545 $fetchcompany = $companystatic->fetch($objp->socid);
1546 if ($fetchcompany) {
1547 $htmltoenteralink .=
'<td>' . $companystatic->getNomUrl(0).
'</td>';
1549 $htmltoenteralink .=
'<td>' . $objp->name .
'</td>';
1551 $fetchcproject = $projectstatic->fetch($objp->fk_project);
1552 if ($fetchcproject) {
1553 $htmltoenteralink .=
'<td>' . $projectstatic->getNomUrl(0).
'</td>';
1555 $htmltoenteralink .=
'<td>' . $objp->fk_project .
'</td>';
1557 $htmltoenteralink .=
'<td>' . $objp->date_subscription .
'</td>';
1558 $htmltoenteralink .=
'</tr>';
1562 return $htmltoenteralink;
1580 public function select_incoterms($selected =
'', $location_incoterms =
'', $page =
'', $htmlname =
'incoterm_id', $htmloption =
'', $forcecombo = 1, $events = array(), $disableautocomplete = 0)
1583 global
$conf, $langs;
1585 $langs->load(
"dict");
1589 $incotermArray = array();
1591 $sql =
"SELECT rowid, code";
1592 $sql .=
" FROM " . $this->db->prefix() .
"c_incoterms";
1593 $sql .=
" WHERE active > 0";
1594 $sql .=
" ORDER BY code ASC";
1596 dol_syslog(get_class($this) .
"::select_incoterm", LOG_DEBUG);
1597 $resql = $this->db->query($sql);
1599 if (
$conf->use_javascript_ajax && !$forcecombo) {
1600 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1604 if (!empty($page)) {
1605 $out .=
'<form method="post" action="' . $page .
'">';
1606 $out .=
'<input type="hidden" name="action" value="set_incoterms">';
1607 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
1610 $out .=
'<select id="' . $htmlname .
'" class="flat selectincoterm width75" name="' . $htmlname .
'" ' . $htmloption .
'>';
1611 $out .=
'<option value="0"> </option>';
1612 $num = $this->db->num_rows($resql);
1616 $obj = $this->db->fetch_object($resql);
1617 $incotermArray[$i][
'rowid'] = $obj->rowid;
1618 $incotermArray[$i][
'code'] = $obj->code;
1622 foreach ($incotermArray as $row) {
1623 if ($selected && ($selected == $row[
'rowid'] || $selected == $row[
'code'])) {
1624 $out .=
'<option value="' . $row[
'rowid'] .
'" selected>';
1626 $out .=
'<option value="' . $row[
'rowid'] .
'">';
1630 $out .= $row[
'code'];
1633 $out .=
'</option>';
1636 $out .=
'</select>';
1639 if (
$conf->use_javascript_ajax && empty($disableautocomplete)) {
1640 $out .=
ajax_multiautocompleter(
'location_incoterms', array(), DOL_URL_ROOT .
'/core/ajax/locationincoterms.php') .
"\n";
1643 $out .=
'<input id="location_incoterms" class="maxwidthonsmartphone heightofcombo" type="text" name="location_incoterms" value="' . $location_incoterms .
'">' .
"\n";
1645 if (!empty($page)) {
1646 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp nomargintop nomarginbottom" value="' . $langs->trans(
"Modify") .
'"></form>';
1670 public function select_type_of_lines($selected =
'', $htmlname =
'type', $showempty = 0, $hidetext = 0, $forceall = 0, $morecss =
"", $useajaxcombo = 1)
1678 if (empty($hidetext)) {
1679 print $langs->trans(
"Type").
'...';
1682 print
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
1684 print
'<option value="-1" class="opacitymedium"'.($useajaxcombo ?
'' :
' disabled="disabled"');
1685 if ($selected == -1) {
1689 if (is_numeric($showempty)) {
1697 print
'<option value="0"';
1698 if (0 == $selected || ($selected == -1 &&
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') ==
'product')) {
1701 print
'>' . $langs->trans(
"Product");
1704 print
'<option value="1"';
1705 if (1 == $selected || ($selected == -1 &&
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') ==
'service')) {
1708 print
'>' . $langs->trans(
"Service");
1713 if ($useajaxcombo) {
1719 print $langs->trans(
"Service");
1720 print
'<input type="hidden" name="' . $htmlname .
'" value="1">';
1723 print $langs->trans(
"Product");
1724 print
'<input type="hidden" name="' . $htmlname .
'" value="0">';
1726 if ($forceall < 0) {
1727 print
'<input type="hidden" name="' . $htmlname .
'" value="1">';
1743 $num = count($this->cache_types_fees);
1750 $langs->load(
"trips");
1752 $sql =
"SELECT c.code, c.label";
1753 $sql .=
" FROM " . $this->db->prefix() .
"c_type_fees as c";
1754 $sql .=
" WHERE active > 0";
1756 $resql = $this->db->query($sql);
1758 $num = $this->db->num_rows($resql);
1762 $obj = $this->db->fetch_object($resql);
1765 $label = ($obj->code != $langs->trans($obj->code) ? $langs->trans($obj->code) : $langs->trans($obj->label));
1766 $this->cache_types_fees[$obj->code] = $label;
1770 asort($this->cache_types_fees);
1792 global $user, $langs;
1794 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
1798 print
'<select id="select_' . $htmlname .
'" class="flat" name="' . $htmlname .
'">';
1800 print
'<option value="-1"';
1801 if ($selected == -1) {
1804 print
'> </option>';
1807 foreach ($this->cache_types_fees as $key => $value) {
1808 print
'<option value="' . $key .
'"';
1809 if ($key == $selected) {
1819 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1848 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)
1851 global
$conf, $langs;
1855 if (!empty(
$conf->use_javascript_ajax) &&
getDolGlobalString(
'COMPANY_USE_SEARCH_TO_SELECT') && !$forcecombo) {
1856 if (is_null($ajaxoptions)) {
1857 $ajaxoptions = array();
1860 require_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1864 if ($selected && empty($selected_input_value)) {
1865 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
1866 $societetmp =
new Societe($this->db);
1867 $societetmp->fetch($selected);
1868 $selected_input_value = $societetmp->name;
1873 $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 :
'');
1875 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
1876 if (empty($hidelabel)) {
1877 $out .= $langs->trans(
"RefOrLabel") .
' : ';
1878 } elseif ($hidelabel == 1 && !is_numeric($showempty)) {
1879 $placeholder = $langs->trans($showempty);
1880 } elseif ($hidelabel > 1) {
1881 $placeholder = $langs->trans(
"RefOrLabel");
1882 if ($hidelabel == 2) {
1883 $out .=
img_picto($langs->trans(
"Search"),
'search');
1886 $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" />';
1887 if ($hidelabel == 3) {
1888 $out .=
img_picto($langs->trans(
"Search"),
'search');
1893 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.
'/societe/ajax/company.php', $urloption,
getDolGlobalInt(
'COMPANY_USE_SEARCH_TO_SELECT'), 0, $ajaxoptions);
1896 $out .= $this->
select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events,
'', 0, $limit, $morecss, $moreparam, $multiple, $excludeids, $showcode);
1930 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 =
'')
1934 global
$conf, $langs;
1939 if ($nokeyifsocid && $socid > 0) {
1940 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = 0;
1943 if (!empty(
$conf->use_javascript_ajax) &&
getDolGlobalString(
'CONTACT_USE_SEARCH_TO_SELECT') && !$forcecombo) {
1944 $ajaxoptions = array();
1946 require_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1950 if ($selected && empty($selected_input_value)) {
1951 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
1952 $contacttmp =
new Contact($this->db);
1953 $contacttmp->fetch($selected);
1954 $selected_input_value = $contacttmp->getFullName($langs);
1957 if (!is_numeric($showempty)) {
1958 $placeholder = $showempty;
1962 $urloption =
'htmlname=' . urlencode((
string) (str_replace(
'.',
'_', $htmlname))) .
'&outjson=1&filter=' . urlencode((
string) ($filter)) . (empty($exclude) ?
'' :
'&exclude=' . urlencode($exclude)) . ($showsoc ?
'&showsoc=' . urlencode((
string) ($showsoc)) :
'');
1964 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
1966 $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" />';
1970 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.
'/contact/ajax/contact.php', $urloption,
getDolGlobalInt(
'CONTACT_USE_SEARCH_TO_SELECT'), 0, $ajaxoptions);
1974 $disableifempty = 0;
1978 $out .= $this->
selectcontacts($socid, $selected, $htmlname, $showempty, $exclude, $limitto, $showfunction, $morecss, $options_only, $showsoc, $forcecombo, $events, $moreparam, $htmlid, $multiple, $disableifempty);
1981 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = $sav;
2012 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)
2015 global $user, $langs;
2016 global $hookmanager;
2018 $langs->loadLangs(array(
"companies",
"suppliers"));
2022 $outarray = array();
2024 if ($selected ===
'') {
2025 $selected = array();
2026 } elseif (!is_array($selected)) {
2027 $selected = array($selected);
2031 if (function_exists(
'testSqlAndScriptInject')) {
2034 return 'SQLInjectionTryDetected';
2038 if ($filter !=
'') {
2043 if (function_exists(
'testSqlAndScriptInject')) {
2046 return 'SQLInjectionTryDetected';
2052 $sql =
"SELECT s.rowid, s.nom as name, s.name_alias, s.tva_intra, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
2054 $sql .=
", s.address, s.zip, s.town";
2055 $sql .=
", dictp.code as country_code";
2057 $sql .=
" FROM " . $this->db->prefix() .
"societe as s";
2059 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_country as dictp ON dictp.rowid = s.fk_pays";
2061 if (!$user->hasRight(
'societe',
'client',
'voir')) {
2062 $sql .=
", " . $this->db->prefix() .
"societe_commerciaux as sc";
2064 $sql .=
" WHERE s.entity IN (" .
getEntity(
'societe') .
")";
2065 if (!empty($user->socid)) {
2066 $sql .=
" AND s.rowid = " . ((int) $user->socid);
2070 $sqlwhere = $filter;
2071 $sql .=
" AND (" . $sqlwhere .
")";
2073 if (!$user->hasRight(
'societe',
'client',
'voir')) {
2074 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = " . ((int) $user->id);
2077 $sql .=
" AND s.status <> 0";
2079 if (!empty($excludeids)) {
2080 $sql .=
" AND s.rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeids)) .
")";
2083 $parameters = array();
2084 $reshook = $hookmanager->executeHooks(
'selectThirdpartyListWhere', $parameters);
2085 $sql .= $hookmanager->resPrint;
2087 if ($filterkey && $filterkey !=
'') {
2091 $search_crit = explode(
' ', $filterkey);
2093 if (count($search_crit) > 1) {
2096 foreach ($search_crit as $crit) {
2100 $sql .=
"(s.nom LIKE '" . $this->db->escape($prefix . $crit) .
"%')";
2103 if (count($search_crit) > 1) {
2107 $sql .=
" OR s.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
2109 $sql .=
" OR s.code_client LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.code_fournisseur LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
2110 $sql .=
" OR s.name_alias LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.tva_intra LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
2113 $sql .= $this->db->order(
"nom",
"ASC");
2114 $sql .= $this->db->plimit($limit, 0);
2117 dol_syslog(get_class($this).
"::select_thirdparty_list", LOG_DEBUG);
2118 $resql = $this->db->query($sql);
2121 $out .=
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
' name="' . $htmlname . ($multiple ?
'[]' :
'') .
'"' . ($multiple ?
' multiple' :
'') .
'>' .
"\n";
2123 $textifempty = (($showempty && !is_numeric($showempty)) ? $langs->trans($showempty) :
'');
2127 if ($showempty && !is_numeric($showempty)) {
2128 $textifempty = $langs->trans($showempty);
2130 $textifempty .= $langs->trans(
"All");
2134 $out .=
'<option value="-1" data-html="' .
dol_escape_htmltag(
'<span class="opacitymedium">' . ($textifempty ? $textifempty :
' ') .
'</span>') .
'">' . $textifempty .
'</option>' .
"\n";
2137 $companytemp =
new Societe($this->db);
2139 $num = $this->db->num_rows($resql);
2143 $obj = $this->db->fetch_object($resql);
2146 if (($obj->client) && (!empty($obj->code_client))) {
2147 $label = $obj->code_client .
' - ';
2149 if (($obj->fournisseur) && (!empty($obj->code_fournisseur))) {
2150 $label .= $obj->code_fournisseur .
' - ';
2152 $label .=
' ' . $obj->name;
2154 $label = $obj->name;
2157 if (!empty($obj->name_alias)) {
2158 $label .=
' (' . $obj->name_alias .
')';
2162 $label .=
' - '.$obj->tva_intra;
2165 $labelhtml = $label;
2168 $companytemp->id = $obj->rowid;
2169 $companytemp->client = $obj->client;
2170 $companytemp->fournisseur = $obj->fournisseur;
2171 $tmptype = $companytemp->getTypeUrl(1,
'', 0,
'span');
2173 $labelhtml .=
' ' . $tmptype;
2176 if ($obj->client || $obj->fournisseur) {
2179 if ($obj->client == 1 || $obj->client == 3) {
2180 $label .= $langs->trans(
"Customer");
2182 if ($obj->client == 2 || $obj->client == 3) {
2183 $label .= ($obj->client == 3 ?
', ' :
'') . $langs->trans(
"Prospect");
2185 if ($obj->fournisseur) {
2186 $label .= ($obj->client ?
', ' :
'') . $langs->trans(
"Supplier");
2188 if ($obj->client || $obj->fournisseur) {
2194 $s = ($obj->address ?
' - ' . $obj->address :
'') . ($obj->zip ?
' - ' . $obj->zip :
'') . ($obj->town ?
' ' . $obj->town :
'');
2195 if (!empty($obj->country_code)) {
2196 $s .=
', ' . $langs->trans(
'Country' . $obj->country_code);
2202 if (empty($outputmode)) {
2203 if (in_array($obj->rowid, $selected)) {
2204 $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>';
2206 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
2209 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label,
'labelhtml' => $labelhtml));
2213 if (($i % 10) == 0) {
2218 $out .=
'</select>' .
"\n";
2220 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2227 $this->result = array(
'nbofthirdparties' => $num);
2261 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 =
'')
2263 global
$conf, $user, $langs, $hookmanager, $action;
2265 $langs->load(
'companies');
2267 if (empty($htmlid)) {
2268 $htmlid = $htmlname;
2272 $outarray = array();
2274 if ($selected ===
'') {
2275 $selected = array();
2276 } elseif (!is_array($selected)) {
2277 $selected = array((
int) $selected);
2281 if (function_exists(
'testSqlAndScriptInject')) {
2284 return 'SQLInjectionTryDetected';
2288 if ($filter !=
'') {
2289 if (preg_match(
'/[\(\)]/', $filter)) {
2295 if (function_exists(
'testSqlAndScriptInject')) {
2298 return 'SQLInjectionTryDetected';
2304 dol_syslog(
"Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Filter Syntax.", LOG_WARNING);
2308 if (!is_object($hookmanager)) {
2309 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
2314 $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";
2315 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
2316 $sql .=
", s.nom as company, s.town AS company_town";
2318 $sql .=
" FROM " . $this->db->prefix() .
"socpeople as sp";
2319 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
2320 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON s.rowid = sp.fk_soc";
2322 $sql .=
" WHERE sp.entity IN (" .
getEntity(
'contact') .
")";
2323 $sql .=
" AND ((sp.fk_user_creat = ".((int) $user->id).
" AND sp.priv = 1) OR sp.priv = 0)";
2324 if ($socid > 0 || $socid == -1) {
2325 $sql .=
" AND sp.fk_soc = " . ((int) $socid);
2328 $sql .=
" AND sp.statut <> 0";
2331 if (!$user->hasRight(
'societe',
'client',
'voir') && !$user->socid) {
2332 $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 .
")";
2334 if ($user->socid > 0) {
2335 $sql .=
" AND sp.fk_soc = ".((int) $user->socid);
2340 $sanitizedfilter = $filter;
2341 $sql .=
" AND (" . $sanitizedfilter .
")";
2344 $parameters = array();
2345 $reshook = $hookmanager->executeHooks(
'selectContactListWhere', $parameters);
2346 $sql .= $hookmanager->resPrint;
2347 $sql .=
" ORDER BY sp.lastname ASC";
2349 dol_syslog(get_class($this) .
"::selectcontacts", LOG_DEBUG);
2350 $resql = $this->db->query($sql);
2352 $num = $this->db->num_rows($resql);
2354 if ($htmlname !=
'none' && !$options_only) {
2355 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlid .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . (($num || empty($disableifempty)) ?
'' :
' disabled') . ($multiple ?
'multiple' :
'') .
' ' . (!empty($moreparam) ? $moreparam :
'') .
'>';
2358 if ($showempty && !is_numeric($showempty)) {
2359 $textforempty = $showempty;
2360 $out .=
'<option class="optiongrey" value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'>' . $textforempty .
'</option>';
2362 if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) {
2363 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'> </option>';
2365 if ($showempty == 2) {
2366 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Internal") .
' --</option>';
2372 include_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
2373 $contactstatic =
new Contact($this->db);
2376 $obj = $this->db->fetch_object($resql);
2379 $extendedInfos =
'';
2381 $extendedInfos = array();
2382 $email = trim($obj->email);
2383 if (!empty($email)) {
2384 $extendedInfos[] = $email;
2386 $phone = trim($obj->phone);
2387 $phone_perso = trim($obj->phone_perso);
2388 $phone_mobile = trim($obj->phone_mobile);
2389 if (!empty($phone)) {
2390 $extendedInfos[] = $phone;
2392 if (!empty($phone_perso)) {
2393 $extendedInfos[] = $phone_perso;
2395 if (!empty($phone_mobile)) {
2396 $extendedInfos[] = $phone_mobile;
2399 $contact_town = trim($obj->contact_town);
2400 $company_town = trim($obj->company_town);
2401 if (!empty($contact_town)) {
2402 $extendedInfos[] = $contact_town;
2403 } elseif (!empty($company_town)) {
2404 $extendedInfos[] = $company_town;
2406 $extendedInfos = implode(
' - ', $extendedInfos);
2407 if (!empty($extendedInfos)) {
2408 $extendedInfos =
' - ' . $extendedInfos;
2412 $contactstatic->id = $obj->rowid;
2413 $contactstatic->lastname = $obj->lastname;
2414 $contactstatic->firstname = $obj->firstname;
2415 if ($obj->statut == 1) {
2417 if ($htmlname !=
'none') {
2419 if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) {
2422 if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) {
2425 if (!empty($selected) && in_array($obj->rowid, $selected)) {
2426 $out .=
'<option value="' . $obj->rowid .
'"';
2428 $out .=
' disabled';
2430 $out .=
' selected>';
2432 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
2433 if ($showfunction && $obj->poste) {
2434 $tmplabel .=
' (' . $obj->poste .
')';
2436 if (($showsoc > 0) && $obj->company) {
2437 $tmplabel .=
' - (' . $obj->company .
')';
2441 $out .=
'</option>';
2443 $out .=
'<option value="' . $obj->rowid .
'"';
2445 $out .=
' disabled';
2449 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
2450 if ($showfunction && $obj->poste) {
2451 $tmplabel .=
' (' . $obj->poste .
')';
2453 if (($showsoc > 0) && $obj->company) {
2454 $tmplabel .=
' - (' . $obj->company .
')';
2458 $out .=
'</option>';
2461 if (in_array($obj->rowid, $selected)) {
2462 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
2463 if ($showfunction && $obj->poste) {
2464 $tmplabel .=
' (' . $obj->poste .
')';
2466 if (($showsoc > 0) && $obj->company) {
2467 $tmplabel .=
' - (' . $obj->company .
')';
2474 if ($tmplabel !=
'') {
2475 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $tmplabel,
'label' => $tmplabel,
'labelhtml' => $tmplabel));
2481 $labeltoshow = ($socid != -1) ? ($langs->trans($socid ?
"NoContactDefinedForThirdParty" :
"NoContactDefined")) : $langs->trans(
'SelectAThirdPartyFirst');
2482 $out .=
'<option class="disabled" value="-1"' . (($showempty == 2 || $multiple) ?
'' :
' selected') .
' disabled="disabled">';
2483 $out .= $labeltoshow;
2484 $out .=
'</option>';
2487 $parameters = array(
2489 'htmlname' => $htmlname,
2492 'showfunction' => $showfunction,
2493 'showsoc' => $showsoc,
2496 $reshook = $hookmanager->executeHooks(
'afterSelectContactOptions', $parameters, $this, $action);
2498 if ($htmlname !=
'none' && !$options_only) {
2499 $out .=
'</select>';
2502 if (
$conf->use_javascript_ajax && !$forcecombo && !$options_only) {
2503 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2509 if ($options_only === 2) {
2537 global $langs,
$conf;
2540 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
2541 $sql .=
" re.description, re.fk_facture_source";
2542 $sql .=
" FROM " . $this->db->prefix() .
"societe_remise_except as re";
2543 $sql .=
" WHERE re.fk_soc = " . (int) $socid;
2544 $sql .=
" AND re.entity = " . ((int)
$conf->entity);
2546 $sanitizedfilter = $filter;
2547 $sql .=
" AND " . $sanitizedfilter;
2549 $sql .=
" ORDER BY re.description ASC";
2551 dol_syslog(get_class($this) .
"::select_remises", LOG_DEBUG);
2552 $resql = $this->db->query($sql);
2554 print
'<select id="select_' . $htmlname .
'" class="flat maxwidth200onsmartphone" name="' . $htmlname .
'">';
2555 $num = $this->db->num_rows($resql);
2557 $qualifiedlines = $num;
2561 print
'<option value="0"> </option>';
2563 $obj = $this->db->fetch_object($resql);
2564 $desc =
dol_trunc($obj->description, 40);
2565 if (preg_match(
'/\(CREDIT_NOTE\)/', $desc)) {
2566 $desc = preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $desc);
2568 if (preg_match(
'/\(DEPOSIT\)/', $desc)) {
2569 $desc = preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"Deposit"), $desc);
2571 if (preg_match(
'/\(EXCESS RECEIVED\)/', $desc)) {
2572 $desc = preg_replace(
'/\(EXCESS RECEIVED\)/', $langs->trans(
"ExcessReceived"), $desc);
2574 if (preg_match(
'/\(EXCESS PAID\)/', $desc)) {
2575 $desc = preg_replace(
'/\(EXCESS PAID\)/', $langs->trans(
"ExcessPaid"), $desc);
2579 if ($selected > 0 && $selected == $obj->rowid) {
2580 $selectstring =
' selected';
2584 if ($maxvalue > 0 && $obj->amount_ttc > $maxvalue) {
2586 $disabled =
' disabled';
2589 if (
getDolGlobalString(
'MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST') && !empty($obj->fk_facture_source)) {
2590 $tmpfac =
new Facture($this->db);
2591 if ($tmpfac->fetch($obj->fk_facture_source) > 0) {
2592 $desc = $desc .
' - ' . $tmpfac->ref;
2596 print
'<option value="' . $obj->rowid .
'"' . $selectstring . $disabled .
'>' . $desc .
' (' .
price($obj->amount_ht) .
' ' . $langs->trans(
"HT") .
' - ' .
price($obj->amount_ttc) .
' ' . $langs->trans(
"TTC") .
')</option>';
2603 return $qualifiedlines;
2628 public function select_users($selected =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include =
'', $enableonly = array(), $force_entity =
'0')
2631 print $this->
select_dolusers($selected, $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity);
2660 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)
2663 global
$conf, $user, $langs, $hookmanager;
2667 if (is_object($userselected)) {
2668 $selected = (int) $userselected->id;
2669 } elseif (is_numeric($userselected)) {
2670 $selected = (int) $userselected;
2671 } elseif (is_array($userselected)) {
2672 $selected = $userselected;
2678 if ((is_numeric($selected) && ((
int) $selected < -4 || empty($selected))) && !
getDolGlobalString(
'SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE')) {
2679 $selected = $user->id;
2683 if (!is_array($selected)) {
2684 if ($selected === -1 || $selected ===
'') {
2685 $selected = array();
2687 $selected = array($selected);
2692 $excludeUsers =
null;
2693 if (is_array($exclude)) {
2694 $excludeUsers = implode(
",", $exclude);
2698 $includeUsers =
null;
2699 $includeUsersArray = array();
2700 if (is_array($include)) {
2701 $includeUsersArray = $include;
2702 } elseif ($include ==
'hierarchy') {
2704 $includeUsersArray = $user->getAllChildIds(0);
2705 } elseif ($include ==
'hierarchyme') {
2707 $includeUsersArray = $user->getAllChildIds(1);
2722 $includeUsers = implode(
",", $includeUsersArray);
2727 $outarray = array();
2728 $outarray2 = array();
2731 $showlabelofentity =
isModEnabled(
'multicompany') && !
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE') &&
$conf->entity == 1 && !empty($user->admin) && empty($user->entity) && !preg_match(
'/^search_/', $htmlname);
2732 $userissuperadminentityone =
isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && empty($user->entity);
2735 $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";
2736 if ($showlabelofentity) {
2737 $sql .=
", e.label";
2739 $sql .=
" FROM " . $this->db->prefix() .
"user as u";
2740 if ($showlabelofentity) {
2741 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid = u.entity";
2744 if ($userissuperadminentityone && $force_entity !==
'default') {
2745 if (!empty($force_entity)) {
2746 $sql .=
" WHERE u.entity IN (0, " . $this->db->sanitize($force_entity) .
")";
2748 $sql .=
" WHERE u.entity IS NOT NULL";
2752 $sql .=
" WHERE u.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
2754 $sql .=
" WHERE u.entity IN (" .
getEntity(
'user') .
")";
2758 if (!empty($user->socid)) {
2759 $sql .=
" AND u.fk_soc = " . ((int) $user->socid);
2761 if (is_array($exclude) && $excludeUsers) {
2762 $sql .=
" AND u.rowid NOT IN (" . $this->db->sanitize($excludeUsers) .
")";
2764 if ($includeUsers) {
2765 $sql .=
" AND u.rowid IN (" . $this->db->sanitize($includeUsers) .
")";
2768 $sql .=
" AND (u.statut <> 0";
2769 if (!empty($selected)) {
2770 $sql .=
" OR rowid IN (".$this->db->sanitize(implode(
',', $selected)).
")";
2775 $sql .=
" AND u.employee <> 0";
2778 $sql .=
" AND u.fk_soc IS NULL";
2780 if (!empty($morefilter)) {
2783 if ($errormessage) {
2784 $this->errors[] = $errormessage;
2785 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2786 if ($outputmode == 0) {
2787 return 'Error bad param $morefilter';
2795 $reshook = $hookmanager->executeHooks(
'addSQLWhereFilterOnSelectUsers', array(), $this, $action);
2796 if (!empty($reshook)) {
2797 $sql .= $hookmanager->resPrint;
2801 $sql .=
" ORDER BY u.statut DESC, u.firstname ASC, u.lastname ASC";
2803 $sql .=
" ORDER BY u.statut DESC, u.lastname ASC, u.firstname ASC";
2806 dol_syslog(get_class($this) .
"::select_dolusers", LOG_DEBUG);
2808 $resql = $this->db->query($sql);
2810 $num = $this->db->num_rows($resql);
2814 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
' minwidth200') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
2815 if ($show_empty && !$multiple) {
2816 $textforempty =
' ';
2817 if (!empty(
$conf->use_javascript_ajax)) {
2818 $textforempty =
' ';
2820 if (!is_numeric($show_empty)) {
2821 $textforempty = $show_empty;
2823 $out .=
'<option class="optiongrey" value="' . ($show_empty < 0 ? $show_empty : -1) .
'"' . ((empty($selected) || in_array(-1, $selected)) ?
' selected' :
'') .
'>' . $textforempty .
'</option>' .
"\n";
2825 $outarray[($show_empty < 0 ? $show_empty : -1)] = $textforempty;
2826 $outarray2[($show_empty < 0 ? $show_empty : -1)] = array(
2827 'id' => ($show_empty < 0 ? $show_empty : -1),
2828 'label' => $textforempty,
2829 'labelhtml' => $textforempty,
2834 if ($showalso == 2 || $showalso == 3) {
2835 $out .=
'<option value="-3"' . ((in_array(-3, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"MyTeam") .
' --</option>' .
"\n";
2837 $hasAtLeastOneSubordinate = (count($user->getAllChildIds(1)) > 1);
2838 if ($hasAtLeastOneSubordinate) {
2840 $outarray[-3] =
'-- ' . $langs->trans(
"MyTeam") .
' --';
2841 $outarray2[-3] = array(
2843 'label' =>
'-- ' . $langs->trans(
"MyTeam") .
' --',
2844 'labelhtml' =>
'-- ' . $langs->trans(
"MyTeam") .
' --',
2850 if ($showalso == 1 || $showalso == 3) {
2851 $out .=
'<option value="-2"' . ((in_array(-2, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Everybody") .
' --</option>' .
"\n";
2853 $outarray[-2] =
'-- ' . $langs->trans(
"Everybody") .
' --';
2854 $outarray2[-2] = array(
2856 'label' =>
'-- ' . $langs->trans(
"Everybody") .
' --',
2857 'labelhtml' =>
'-- ' . $langs->trans(
"Everybody") .
' --',
2862 if ($showalso == 4) {
2863 $out .=
'<option value="-4"' . ((in_array(-4, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"AllProjectContacts") .
' --</option>' .
"\n";
2865 $outarray[-4] =
'-- ' . $langs->trans(
"AllProjectContacts") .
' --';
2866 $outarray2[-4] = array(
2868 'label' =>
'-- ' . $langs->trans(
"AllProjectContacts") .
' --',
2869 'labelhtml' =>
'-- ' . $langs->trans(
"AllProjectContacts") .
' --',
2875 $userstatic =
new User($this->db);
2878 $obj = $this->db->fetch_object($resql);
2880 $userstatic->id = $obj->rowid;
2881 $userstatic->lastname = $obj->lastname;
2882 $userstatic->firstname = $obj->firstname;
2883 $userstatic->photo = $obj->photo;
2884 $userstatic->status = $obj->status;
2885 $userstatic->entity = $obj->entity;
2886 $userstatic->admin = $obj->admin;
2887 $userstatic->gender = $obj->gender;
2890 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
2891 $disableline = ($enableonlytext ? $enableonlytext :
'1');
2895 $labeltoshowhtml =
'';
2902 $labeltoshow .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2903 $labeltoshowhtml .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2904 if (empty($obj->firstname) && empty($obj->lastname)) {
2905 $labeltoshow .= $obj->login;
2906 $labeltoshowhtml .= $obj->login;
2913 $moreinfo .= ($moreinfo ?
' - ' :
' (');
2914 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(');
2915 $moreinfo .= $obj->login;
2916 $moreinfohtml .= $obj->login;
2918 if ($showstatus >= 0) {
2919 if ($obj->status == 1 && $showstatus == 1) {
2920 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Enabled');
2921 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Enabled');
2923 if ($obj->status == 0 && $showstatus == 1) {
2924 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Disabled');
2925 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Disabled');
2928 if ($showlabelofentity) {
2929 if (empty($obj->entity)) {
2930 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
"AllEntities");
2931 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
"AllEntities");
2933 if ($obj->entity !=
$conf->entity) {
2934 $moreinfo .= ($moreinfo ?
' - ' :
' (') . ($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2935 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(').($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2939 $moreinfo .= (!empty($moreinfo) ?
')' :
'');
2940 $moreinfohtml .= (!empty($moreinfohtml) ?
')</span>' :
'');
2941 if (!empty($disableline) && $disableline !=
'1') {
2943 $moreinfo .=
' - ' . $disableline;
2944 $moreinfohtml .=
' - ' . $disableline;
2946 $labeltoshow .= $moreinfo;
2947 $labeltoshowhtml .= $moreinfohtml;
2949 $out .=
'<option value="' . $obj->rowid .
'"';
2950 if (!empty($disableline)) {
2951 $out .=
' disabled';
2953 if (in_array($obj->rowid, $selected)) {
2954 $out .=
' selected';
2956 $out .=
' data-html="';
2958 $outhtml = $userstatic->getNomUrl(-3,
'', 0, 1, 24, 1,
'login',
'', 1) .
' ';
2959 if ($showstatus >= 0 && $obj->status == 0) {
2960 $outhtml .=
'<strike class="opacitymediumxxx">';
2962 $outhtml .= $labeltoshowhtml;
2963 if ($showstatus >= 0 && $obj->status == 0) {
2964 $outhtml .=
'</strike>';
2966 $labeltoshowhtml = $outhtml;
2970 $out .= $labeltoshow;
2971 $out .=
'</option>';
2973 $outarray[$userstatic->id] = $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength) . $moreinfo;
2974 $outarray2[$userstatic->id] = array(
2975 'id' => $userstatic->id,
2976 'label' => $labeltoshow,
2977 'labelhtml' => $labeltoshowhtml,
2985 $out .=
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'" disabled>';
2986 $out .=
'<option value="">' . $langs->trans(
"None") .
'</option>';
2988 $out .=
'</select>';
2990 if ($num && !$forcecombo) {
2992 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3001 if ($outputmode == 2) {
3003 } elseif ($outputmode) {
3035 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)
3038 global $langs, $user;
3040 $userstatic =
new User($this->db);
3043 if (!empty($_SESSION[
'assignedtouser'])) {
3044 $assignedtouser = json_decode($_SESSION[
'assignedtouser'],
true);
3045 if (!is_array($assignedtouser)) {
3046 $assignedtouser = array();
3049 $assignedtouser = array();
3051 $nbassignetouser = count($assignedtouser);
3054 if ($nbassignetouser) {
3055 $out .=
'<ul class="attendees">';
3059 foreach ($assignedtouser as $key => $value) {
3060 if ($value[
'id'] == $ownerid) {
3066 $userstatic->fetch($value[
'id']);
3067 $out .= $userstatic->getNomUrl(-4);
3070 $ownerid = $value[
'id'];
3071 $out .=
' (' . $langs->trans(
"Owner") .
')';
3074 if ($nbassignetouser > 1 && $action !=
'view') {
3075 $canremoveassignee = 1;
3078 if (!$canremoveowner) {
3079 $canremoveassignee = 0;
3081 if (!$user->hasRight(
'agenda',
'allactions',
'create')) {
3082 $canremoveassignee = 0;
3087 if ($canremoveassignee) {
3090 $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 .
'">';
3094 if ($showproperties) {
3095 if ($ownerid == $value[
'id'] && is_array($listofuserid) && count($listofuserid) && in_array($ownerid, array_keys($listofuserid))) {
3096 $out .=
'<div class="myavailability inline-block">';
3097 $out .=
'<span class="hideonsmartphone"> - ';
3100 $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>';
3110 if ($nbassignetouser) {
3115 if ($action !=
'view') {
3117 $out .=
'<div class="divadduser'.$htmlname.
'">';
3118 $out .=
'<input type="hidden" class="removedassignedhidden" name="removedassigned" value="">';
3119 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
3120 $out .=
'jQuery(".removedassigned").click(function() { jQuery(".removedassignedhidden").val(jQuery(this).val()); });';
3121 $out .=
'jQuery(".assignedtouser").change(function() { console.log(jQuery(".assignedtouser option:selected").val());';
3122 $out .=
' if (jQuery(".assignedtouser option:selected").val() > 0) { jQuery("#' . $action .
'assignedtouser").attr("disabled", false); }';
3123 $out .=
' else { jQuery("#' . $action .
'assignedtouser").attr("disabled", true); }';
3125 $out .=
'})</script>';
3126 $out .=
img_picto(
'',
'user',
'class="pictofixedwidth"');
3127 $out .= $this->
select_dolusers(
'', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter, 0,
'',
'minwidth200');
3128 $out .=
' <button type="submit" disabled class="button valignmiddle smallpaddingimp reposition butActionAdd" id="' . $action .
'assignedtouser" name="' . $action .
'assignedtouser" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
3129 $out .= $langs->trans(
"Add").
'</button>';
3157 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())
3162 require_once DOL_DOCUMENT_ROOT.
'/resource/class/html.formresource.class.php';
3163 require_once DOL_DOCUMENT_ROOT.
'/resource/class/dolresource.class.php';
3168 if (!empty($_SESSION[
'assignedtoresource'])) {
3169 $assignedtoresource = json_decode($_SESSION[
'assignedtoresource'],
true);
3170 if (!is_array($assignedtoresource)) {
3171 $assignedtoresource = array();
3174 $assignedtoresource = array();
3176 $nbassignetoresource = count($assignedtoresource);
3179 if ($nbassignetoresource) {
3180 $out .=
'<ul class="attendees">';
3184 foreach ($assignedtoresource as $key => $value) {
3186 $resourcestatic->fetch($value[
'id']);
3187 $out .= $resourcestatic->getNomUrl(-1);
3188 if ($nbassignetoresource >= 1 && $action !=
'view') {
3189 $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 .
'">';
3192 if ($showproperties) {
3193 if (is_array($listofresourceid) && count($listofresourceid)) {
3194 $out .=
'<div class="myavailability inline-block">';
3195 $out .=
'<span class="hideonsmartphone"> - ';
3198 $out .=
' <input title="'.$langs->trans(
"Availability").
'" id="transparencyresource'.$value[
'id'].
'" class="paddingrightonly" ' . ($action ==
'view' ?
'disabled' :
'') .
' type="checkbox" name="transparency"' . ($listofresourceid[$value[
'id']][
'transparency'] ?
' checked' :
'') .
'><label for="transparencyresource'.$value[
'id'].
'">' . $langs->trans(
"Busy") .
'</label>';
3208 if ($nbassignetoresource) {
3213 if ($action !=
'view') {
3214 $out .=
'<input type="hidden" class="removedassignedresourcehidden" name="removedassignedresource" value="">';
3215 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
3216 $out .=
'jQuery(".removedassignedresource").click(function() { jQuery(".removedassignedresourcehidden").val(jQuery(this).val()); });';
3217 $out .=
'jQuery(".assignedtoresource").change(function() { console.log(jQuery(".assignedtoresource option:selected").val());';
3218 $out .=
' if (jQuery(".assignedtoresource option:selected").val() > 0) { jQuery("#' . $action .
'assignedtoresource").attr("disabled", false); }';
3219 $out .=
' else { jQuery("#' . $action .
'assignedtoresource").attr("disabled", true); }';
3221 $out .=
'})</script>';
3224 if ($nbassignetoresource) {
3227 $out .=
img_picto(
'',
'resource',
'class="pictofixedwidth"');
3229 $out .= $formresources->select_resource_list(0, $htmlname,
'', 1, 1, 0, $events,
'', 2, 0,
'minwidth200');
3231 $out .=
' <button type="submit" disabled class="button valignmiddle smallpaddingimp reposition butActionAdd" id="' . $action .
'assignedtoresource" name="' . $action .
'assignedtoresource" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
3232 $out .= $langs->trans(
"Add");
3233 $out .=
'</button>';
3271 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)
3274 global $langs,
$conf;
3279 $price_level = (!empty($price_level) ? $price_level : 0);
3280 if (is_null($ajaxoptions)) {
3281 $ajaxoptions = array();
3293 $placeholder = (is_numeric($showempty) ?
'' :
'placeholder="'.dolPrintHTML($showempty).
'"');
3295 if ($selected && empty($selected_input_value)) {
3296 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3297 $producttmpselect =
new Product($this->db);
3298 $producttmpselect->fetch($selected);
3299 $selected_input_value = $producttmpselect->ref;
3300 unset($producttmpselect);
3303 if ($filtertype ==
'') {
3311 $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;
3312 if ((
int) $warehouseId > 0) {
3313 $urloption .=
'&warehouseid=' . (int) $warehouseId;
3316 if (
isModEnabled(
'variants') && is_array($selected_combinations)) {
3322 <!-- script to auto show attributes select tags if a variant was selected -->
3323 <script nonce="' .
getNonce() .
'">
3324 // auto show attributes fields
3325 selected = ' . json_encode($selected_combinations) .
';
3328 jQuery(document).ready(function () {
3330 jQuery("input[name=\'prod_entry_mode\']").change(function () {
3331 if (jQuery(this).val() == \'free\') {
3332 jQuery(\'div#attributes_box\').empty();
3336 jQuery("'.$htmltag.
'#' . $htmlname .
'").change(function () {
3338 if (!jQuery(this).val()) {
3339 jQuery(\'div#attributes_box\').empty();
3343 console.log("A change has started. We get variants fields to inject html select");
3345 jQuery.getJSON("' . DOL_URL_ROOT .
'/variants/ajax/getCombinations.php", {
3346 id: jQuery(this).val()
3347 }, function (data) {
3348 jQuery(\'div#attributes_box\').empty();
3350 jQuery.each(data, function (key, val) {
3352 combvalues[val.id] = val.values;
3354 var span = jQuery(document.createElement(\'div\')).css({
3355 \'display\': \'table-row\'
3359 jQuery(document.createElement(\'div\')).text(val.label).css({
3360 \'font-weight\': \'bold\',
3361 \'display\': \'table-cell\'
3365 var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({
3366 \'margin-left\': \'15px\',
3367 \'white-space\': \'pre\'
3369 jQuery(document.createElement(\'option\')).val(\'\')
3372 jQuery.each(combvalues[val.id], function (key, val) {
3373 var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value);
3375 if (selected[val.fk_product_attribute] == val.id) {
3376 tag.attr(\'selected\', \'selected\');
3383 jQuery(\'div#attributes_box\').append(span);
3388 ' . ($selected ?
'jQuery("'.$htmltag.
'#' . $htmlname .
'").change();' :
'') .
'
3394 if (empty($hidelabel)) {
3396 } elseif ($hidelabel > 1) {
3398 if ($hidelabel == 2) {
3399 $out .=
img_picto($langs->trans(
"Search"),
'search');
3403 $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" />';
3404 if ($hidelabel == 3) {
3405 $out .=
img_picto($langs->trans(
"Search"),
'search');
3408 $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);
3410 $out .= $this->
select_produits_list($selected, $htmlname, $filtertype, $limit, $price_level,
'', $status, $finished, 0, $socid, $showempty, $forcecombo, $morecss, $hidepriceinlabel, $warehouseStatus, $status_purchase, $warehouseId);
3412 if (
isModEnabled(
'variants') && is_array($selected_combinations)) {
3416 $htmltag =
'select';
3418 <!-- script to auto show attributes select tags if a variant was selected -->
3419 <script nonce="' .
getNonce() .
'">
3420 // auto show attributes fields
3421 selected = ' . json_encode($selected_combinations) .
';
3424 jQuery(document).ready(function () {
3426 jQuery("input[name=\'prod_entry_mode\']").change(function () {
3427 if (jQuery(this).val() == \'free\') {
3428 jQuery(\'div#attributes_box\').empty();
3432 jQuery("'.$htmltag.
'#' . $htmlname .
'").change(function () {
3434 if (!jQuery(this).val()) {
3435 jQuery(\'div#attributes_box\').empty();
3439 console.log("A change has started. We get variants fields to inject html select");
3441 jQuery.getJSON("' . DOL_URL_ROOT .
'/variants/ajax/getCombinations.php", {
3442 id: jQuery(this).val()
3443 }, function (data) {
3444 jQuery(\'div#attributes_box\').empty();
3446 jQuery.each(data, function (key, val) {
3448 combvalues[val.id] = val.values;
3450 var span = jQuery(document.createElement(\'div\')).css({
3451 \'display\': \'table-row\'
3455 jQuery(document.createElement(\'div\')).text(val.label).css({
3456 \'font-weight\': \'bold\',
3457 \'display\': \'table-cell\'
3461 var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({
3462 \'margin-left\': \'15px\',
3463 \'white-space\': \'pre\'
3465 jQuery(document.createElement(\'option\')).val(\'\')
3468 jQuery.each(combvalues[val.id], function (key, val) {
3469 var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value);
3471 if (selected[val.fk_product_attribute] == val.id) {
3472 tag.attr(\'selected\', \'selected\');
3479 jQuery(\'div#attributes_box\').append(span);
3484 ' . ($selected ?
'jQuery("'.$htmltag.
'#' . $htmlname .
'").change();' :
'') .
'
3491 if (empty($nooutput)) {
3515 public function select_bom($selected =
'', $htmlname =
'bom_id', $limit = 0, $status = 1, $type = 0, $showempty =
'1', $morecss =
'', $nooutput =
'', $forcecombo = 0, $TProducts = [])
3519 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3525 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3530 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
3532 $sql =
'SELECT b.rowid, b.ref, b.label as bomLabel, p.label as productLabel';
3533 $sql .=
' FROM ' . $this->db->prefix() .
'bom_bom as b';
3534 $sql .=
' INNER JOIN ' . $this->db->prefix() .
'product as p ON b.fk_product = p.rowid';
3535 $sql .=
' WHERE b.entity IN (' .
getEntity(
'bom') .
')';
3536 if (!empty($status)) {
3537 $sql .=
' AND status = ' . (int) $status;
3539 if (!empty($type)) {
3540 $sql .=
' AND bomtype = ' . (int) $type;
3542 if (!empty($TProducts)) {
3543 $sql .=
' AND fk_product IN (' . $this->db->sanitize(implode(
',', $TProducts)) .
')';
3545 if (!empty($limit)) {
3546 $sql .=
' LIMIT ' . (int) $limit;
3548 $resql = $this->db->query($sql);
3551 $out .=
'<option value="-1"';
3552 if (empty($selected)) {
3553 $out .=
' selected';
3555 $out .=
'> </option>';
3557 while ($obj = $this->db->fetch_object($resql)) {
3558 $out .=
'<option value="' . $obj->rowid .
'"';
3559 if ($obj->rowid == $selected) {
3562 $out .=
'>' . $obj->ref .
' - ' . $obj->productLabel .
' - ' . $obj->bomLabel .
'</option>';
3568 $out .=
'</select>';
3569 if (empty($nooutput)) {
3604 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)
3608 global $hookmanager;
3611 $outarray = array();
3615 $langs->load(
'other');
3618 $warehouseStatusArray = array();
3619 if (!empty($warehouseStatus)) {
3620 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/entrepot.class.php';
3621 if (preg_match(
'/warehouseclosed/', $warehouseStatus)) {
3624 if (preg_match(
'/warehouseopen/', $warehouseStatus)) {
3627 if (preg_match(
'/warehouseinternal/', $warehouseStatus)) {
3632 $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";
3633 if (count($warehouseStatusArray)) {
3634 $selectFieldsGrouped =
", SUM(" . $this->db->ifsql(
"e.statut IS NULL",
"0",
"ps.reel") .
") as stock";
3636 $selectFieldsGrouped =
", " . $this->db->ifsql(
"p.stock IS NULL",
'0',
"p.stock") .
" AS stock";
3642 $parameters = array();
3643 $reshook = $hookmanager->executeHooks(
'selectProductsListSelect', $parameters);
3644 if (empty($reshook)) {
3645 $sql .= $selectFields.$selectFieldsGrouped.$hookmanager->resPrint;
3647 $sql .= $hookmanager->resPrint;
3652 $sql .=
", (SELECT " . $this->db->prefix() .
"categorie_product.fk_categorie
3653 FROM " . $this->db->prefix() .
"categorie_product
3654 WHERE " . $this->db->prefix() .
"categorie_product.fk_product = p.rowid
3656 ) AS categorie_product_id";
3661 $sql .=
', pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,';
3662 $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';
3663 $selectFields .=
", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custdefault_vat_code, custref, custdiscount_percent";
3667 $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";
3668 $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';
3673 $sql .=
", pl.label as label_translated";
3674 $sql .=
", pl.description as description_translated";
3675 $selectFields .=
", label_translated";
3676 $selectFields .=
", description_translated";
3680 $sql .=
", (SELECT pp.rowid FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
3681 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
3682 $sql .=
" AND price_level = " . ((int) $price_level);
3684 $sql .=
" ORDER BY date_price";
3685 $sql .=
" DESC LIMIT 1) as price_rowid";
3686 $sql .=
", (SELECT pp.price_by_qty FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
3687 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
3688 $sql .=
" AND price_level = " . ((int) $price_level);
3690 $sql .=
" ORDER BY date_price";
3691 $sql .=
" DESC LIMIT 1) as price_by_qty";
3692 $selectFields .=
", price_rowid, price_by_qty";
3697 $sql .=
" FROM ".$this->db->prefix().
"product as p";
3700 $sql .=
" USE INDEX (" . $this->db->sanitize(
getDolGlobalString(
'MAIN_PRODUCT_FORCE_INDEX')) .
")";
3704 $parameters = array(
3707 $reshook = $hookmanager->executeHooks(
'selectProductsListFrom', $parameters);
3708 $sql .= $hookmanager->resPrint;
3710 if (count($warehouseStatusArray)) {
3713 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_stock as ps ON ps.fk_product = p.rowid";
3714 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entrepot as e ON ps.fk_entrepot = e.rowid AND e.entity IN (" .
getEntity(
'stock') .
")";
3715 $sql .=
' AND e.statut IN (' . $this->db->sanitize($this->db->escape(implode(
',', $warehouseStatusArray))) .
')';
3721 $sql .=
" LEFT JOIN (";
3722 $sql .=
" SELECT pcp1.*";
3723 $sql .=
" FROM " . $this->db->prefix() .
"product_customer_price AS pcp1";
3724 $sql .=
" LEFT JOIN (";
3725 $sql .=
" SELECT fk_soc, fk_product, MIN(date_begin) AS date_begin";
3726 $sql .=
" FROM " . $this->db->prefix() .
"product_customer_price";
3727 $sql .=
" WHERE fk_soc = " . ((int) $socid);
3728 $sql .=
" AND date_begin <= '" . $this->db->idate($now) .
"'";
3729 $sql .=
" AND (date_end IS NULL OR '" . $this->db->idate($now) .
"' <= date_end)";
3730 $sql .=
" GROUP BY fk_soc, fk_product";
3731 $sql .=
" ) AS pcp2 ON pcp1.fk_soc = pcp2.fk_soc AND pcp1.fk_product = pcp2.fk_product AND pcp1.date_begin = pcp2.date_begin";
3732 $sql .=
" WHERE pcp2.fk_soc IS NOT NULL";
3733 $sql .=
" ) AS pcp ON pcp.fk_soc = " . ((int) $socid) .
" AND pcp.fk_product = p.rowid";
3737 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units as u ON u.rowid = p.fk_unit";
3741 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_lang as pl ON pl.fk_product = p.rowid";
3743 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
3744 $soc =
new Societe($this->db);
3745 $result = $soc->fetch($socid);
3746 if ($result > 0 && !empty($soc->default_lang)) {
3747 $sql .=
" AND pl.lang = '" . $this->db->escape($soc->default_lang) .
"'";
3749 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3752 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3757 $sql .=
' WHERE p.entity IN (' .
getEntity(
'product') .
')';
3760 if (strlen($filterkey) != 13) {
3761 $sql .=
" AND NOT EXISTS (SELECT pac.rowid FROM ".$this->db->prefix().
"product_attribute_combination as pac WHERE pac.fk_product_child = p.rowid)";
3764 $sql .=
" AND NOT EXISTS (SELECT pac.rowid FROM ".$this->db->prefix().
"product_attribute_combination as pac WHERE pac.fk_product_child = p.rowid)";
3767 if ($finished == 0) {
3768 $sql .=
" AND p.finished = " . ((int) $finished);
3769 } elseif ($finished == 1) {
3770 $sql .=
" AND p.finished = ".((int) $finished);
3773 $sql .=
" AND p.tosell = ".((int) $status);
3775 if ($status_purchase >= 0) {
3776 $sql .=
" AND p.tobuy = " . ((int) $status_purchase);
3779 if (strval($filtertype) !=
'') {
3780 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
3782 $sql .=
" AND p.fk_product_type = 1";
3784 $sql .=
" AND p.fk_product_type = 0";
3787 if ((
int) $warehouseId > 0) {
3788 $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)";
3792 $parameters = array(
3793 'filterkey' => &$filterkey,
3796 $reshook = $hookmanager->executeHooks(
'selectProductsListWhere', $parameters);
3797 $sql .= $hookmanager->resPrint;
3799 if ($filterkey !=
'') {
3800 $sqlSupplierSearch =
'';
3805 $search_crit = explode(
' ', $filterkey);
3807 if (count($search_crit) > 1) {
3810 foreach ($search_crit as $crit) {
3814 $sql .=
"(p.ref LIKE '" . $this->db->escape($prefix . $crit) .
"%' OR p.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3816 $sql .=
" OR pl.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3819 $sql .=
" OR pcp.ref_customer LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3822 $sql .=
" OR p.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3824 $sql .=
" OR pl.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3830 $sqlSupplierSearch .= !empty($sqlSupplierSearch) ?
' AND ' :
'';
3831 $sqlSupplierSearch .=
" pfp.ref_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3836 if (count($search_crit) > 1) {
3840 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3845 $sql .=
" OR EXISTS (SELECT pfp.fk_product FROM " . $this->db->prefix() .
"product_fournisseur_price as pfp WHERE p.rowid = pfp.fk_product";
3847 $sql .= $sqlSupplierSearch;
3853 if (count($warehouseStatusArray)) {
3854 $sql .=
" GROUP BY " . $this->db->sanitize($selectFields, 0, 0, 1);
3859 $sql .=
" ORDER BY categorie_product_id ".(getDolGlobalInt(
'PRODUCT_SORT_BY_CATEGORY') == 1 ?
"ASC" :
"DESC");
3861 $sql .= $this->db->order(
"p.ref");
3865 $sql .= $this->db->plimit($limit, 0);
3883 dol_syslog(get_class($this) .
"::select_produits_list search products", LOG_DEBUG);
3887 $result = $this->db->query($sql);
3890 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3891 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3892 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
3894 $num = $this->db->num_rows($result);
3899 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3903 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
3909 if ($showempty && !is_numeric($showempty)) {
3910 $textifempty = $langs->trans($showempty);
3912 $textifempty .= $langs->trans(
"All");
3915 if ($showempty && !is_numeric($showempty)) {
3916 $textifempty = $langs->trans($showempty);
3920 $out .=
'<option value="-1" selected>' . ($textifempty ? $textifempty :
' ') .
'</option>';
3924 while ($num && $i < $num) {
3927 $objp = $this->db->fetch_object($result);
3929 if ((
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1) {
3930 $sql =
"SELECT rowid, quantity, price, unitprice, remise_percent, remise, price_base_type";
3931 $sql .=
" FROM " . $this->db->prefix() .
"product_price_by_qty";
3932 $sql .=
" WHERE fk_product_price = " . ((int) $objp->price_rowid);
3933 $sql .=
" ORDER BY quantity ASC";
3935 dol_syslog(get_class($this) .
"::select_produits_list search prices by qty", LOG_DEBUG);
3936 $result2 = $this->db->query($sql);
3938 $nb_prices = $this->db->num_rows($result2);
3940 while ($nb_prices && $j < $nb_prices) {
3941 $objp2 = $this->db->fetch_object($result2);
3943 $objp->price_by_qty_rowid = $objp2->rowid;
3944 $objp->price_by_qty_price_base_type = $objp2->price_base_type;
3945 $objp->price_by_qty_quantity = $objp2->quantity;
3946 $objp->price_by_qty_unitprice = $objp2->unitprice;
3947 $objp->price_by_qty_remise_percent = $objp2->remise_percent;
3949 $objp->quantity = $objp2->quantity;
3950 $objp->price = $objp2->price;
3951 $objp->unitprice = $objp2->unitprice;
3952 $objp->remise_percent = $objp2->remise_percent;
3958 '@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';
3965 array_push($outarray, $optJson);
3969 if (
isModEnabled(
'dynamicprices') && !empty($objp->fk_price_expression)) {
3970 $price_product =
new Product($this->db);
3971 $price_product->fetch($objp->rowid,
'',
'',
'1');
3973 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3975 $price_result = $priceparser->parseProduct($price_product);
3976 if ($price_result >= 0) {
3977 $objp->price = $price_result;
3978 $objp->unitprice = $price_result;
3980 $objp->price_ttc = (float)
price2num($objp->price) * (1 + ($objp->tva_tx / 100));
3981 $objp->price_ttc =
price2num($objp->price_ttc,
'MU');
3984 if (
getDolGlobalInt(
'PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES') && !empty($objp->custprice)) {
3992 array_push($outarray, $optJson);
3998 $out .=
'</select>';
4000 $this->db->free($result);
4002 if (empty($outputmode)) {
4029 protected function constructProductListOption(&$objp, &$opt, &$optJson, $price_level, $selected, $hidepriceinlabel = 0, $filterkey =
'', $novirtualstock = 0)
4031 global $langs,
$conf, $user;
4032 global $hookmanager;
4038 $outlabel_translated =
'';
4040 $outdesc_translated =
'';
4046 $outpricebasetype =
'';
4048 $outdefault_vat_code =
'';
4054 $productlabel = $objp->label;
4055 if (!empty($objp->label_translated)) {
4056 $productlabel = $objp->label_translated;
4058 $label = $productlabel;
4059 if (!empty($filterkey) && $filterkey !=
'') {
4060 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
4063 $outkey = $objp->rowid;
4064 $outref = $objp->ref;
4065 $outrefcust = empty($objp->custref) ?
'' : $objp->custref;
4066 $outlabel = $objp->label;
4067 $outdesc = $objp->description;
4069 $outlabel_translated = $objp->label_translated;
4070 $outdesc_translated = $objp->description_translated;
4072 $outbarcode = $objp->barcode;
4073 $outorigin = $objp->fk_country;
4074 $outpbq = empty($objp->price_by_qty_rowid) ?
'' : $objp->price_by_qty_rowid;
4076 $outtype = $objp->fk_product_type;
4081 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
4087 if (!empty($objp->unit_short)) {
4088 $outvalUnits .=
' - ' . $objp->unit_short;
4092 if (!empty($objp->weight) && $objp->weight_units !==
null) {
4094 $outvalUnits .=
' - ' . $unitToShow;
4096 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
4097 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
4098 $outvalUnits .=
' - ' . $unitToShow;
4100 if (!empty($objp->surface) && $objp->surface_units !==
null) {
4102 $outvalUnits .=
' - ' . $unitToShow;
4104 if (!empty($objp->volume) && $objp->volume_units !==
null) {
4106 $outvalUnits .=
' - ' . $unitToShow;
4109 if ($outdurationvalue && $outdurationunit) {
4111 'h' => $langs->trans(
'Hour'),
4112 'd' => $langs->trans(
'Day'),
4113 'w' => $langs->trans(
'Week'),
4114 'm' => $langs->trans(
'Month'),
4115 'y' => $langs->trans(
'Year')
4117 if (isset($da[$outdurationunit])) {
4118 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
4125 if ($user->hasRight(
'stock',
'lire')) {
4126 if ($objp->stock > 0) {
4128 } elseif ($objp->stock <= 0) {
4136 $labeltosearch =
'';
4137 $labeltosearch .= $objp->ref;
4138 if (!empty($objp->custref)) {
4139 $labeltosearch .=
' (' . $objp->custref .
')';
4142 $labeltosearch .=
' (' . $outbarcode .
')';
4144 $labeltosearch .=
' - ' . $productlabel;
4146 $labeltosearch .=
' (' .
getCountry($outorigin,
'1') .
')';
4150 $labeltoshowhtml =
'';
4151 $labeltoshowhtml .= $objp->ref;
4152 if (!empty($objp->custref)) {
4153 $labeltoshowhtml .=
' (' . $objp->custref .
')';
4155 if (!empty($filterkey) && $filterkey !=
'') {
4156 $labeltoshowhtml = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $labeltoshowhtml, 1);
4159 $labeltoshowhtml .=
' (' . $outbarcode .
')';
4161 $labeltoshowhtml .=
' - ' .
dol_trunc($label, $maxlengtharticle);
4163 $labeltoshowhtml .=
' (' .
getCountry($outorigin,
'1') .
')';
4167 $labeltoshowstock =
'';
4168 $labeltoshowhtmlstock =
'';
4170 if ($user->hasRight(
'stock',
'lire')) {
4171 $labeltoshowstock .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
4173 if ($objp->stock > 0) {
4174 $labeltoshowhtmlstock .=
' - <span class="product_line_stock_ok">';
4175 } elseif ($objp->stock <= 0) {
4176 $labeltoshowhtmlstock .=
' - <span class="product_line_stock_too_low">';
4178 $labeltoshowhtmlstock .= $langs->transnoentities(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
4179 $labeltoshowhtmlstock .=
'</span>';
4181 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
4182 $langs->load(
"stocks");
4184 $tmpproduct =
new Product($this->db);
4185 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
4186 $tmpproduct->load_virtual_stock();
4187 $virtualstock = $tmpproduct->stock_theorique;
4189 $labeltoshowstock .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
4191 $labeltoshowhtmlstock .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
4192 if ($virtualstock > 0) {
4193 $labeltoshowhtmlstock .=
'<span class="product_line_stock_ok">';
4194 } elseif ($virtualstock <= 0) {
4195 $labeltoshowhtmlstock .=
'<span class="product_line_stock_too_low">';
4197 $labeltoshowhtmlstock .= $virtualstock;
4198 $labeltoshowhtmlstock .=
'</span>';
4207 $labeltoshowprice =
'';
4208 $labeltoshowhtmlprice =
'';
4211 $sql =
"SELECT price, price_ttc, price_base_type, tva_tx, default_vat_code";
4212 $sql .=
" FROM " . $this->db->prefix() .
"product_price";
4213 $sql .=
" WHERE fk_product = " . ((int) $objp->rowid);
4214 $sql .=
" AND entity IN (" .
getEntity(
'productprice') .
")";
4215 $sql .=
" AND price_level = " . ((int) $price_level);
4216 $sql .=
" ORDER BY date_price DESC, rowid DESC";
4219 dol_syslog(get_class($this) .
'::constructProductListOption search price for product ' . $objp->rowid .
' AND level ' . $price_level, LOG_DEBUG);
4220 $result2 = $this->db->query($sql);
4222 $objp2 = $this->db->fetch_object($result2);
4225 if ($objp2->price_base_type ==
'HT') {
4226 $labeltoshowprice .=
' - ' .
price($objp2->price, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
4227 $labeltoshowhtmlprice .=
' - ' .
price($objp2->price, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
4229 $labeltoshowprice .=
' - ' .
price($objp2->price_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
4230 $labeltoshowhtmlprice .=
' - ' .
price($objp2->price_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
4232 $outprice_ht =
price($objp2->price);
4233 $outprice_ttc =
price($objp2->price_ttc);
4234 $outpricebasetype = $objp2->price_base_type;
4236 $outtva_tx = $objp2->tva_tx;
4237 $outdefault_vat_code = $objp2->default_vat_code;
4239 $outtva_tx = $objp->tva_tx;
4240 $outdefault_vat_code = $objp->default_vat_code;
4249 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1 && (
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
4251 $outqty = $objp->quantity;
4252 $outdiscount = $objp->remise_percent;
4253 if ($objp->quantity == 1) {
4254 $labeltoshowprice .=
' - ' .
price($objp->unitprice, 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
4255 $labeltoshowhtmlprice .=
' - ' .
price($objp->unitprice, 0, $langs, 0, 0, -1,
$conf->currency) .
"/";
4256 $labeltoshowprice .= $langs->trans(
"Unit");
4257 $labeltoshowhtmlprice .= $langs->transnoentities(
"Unit");
4259 $labeltoshowprice .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
4260 $labeltoshowhtmlprice .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
4261 $labeltoshowprice .= $langs->trans(
"Units");
4262 $labeltoshowhtmlprice .= $langs->transnoentities(
"Units");
4265 $outprice_ht =
price($objp->unitprice);
4266 $outprice_ttc =
price($objp->unitprice * (1 + ($objp->tva_tx / 100)));
4267 $outpricebasetype = $objp->price_base_type;
4268 $outtva_tx = $objp->tva_tx;
4269 $outdefault_vat_code = $objp->default_vat_code;
4271 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1) {
4272 $labeltoshowprice .=
" (" .
price($objp->unitprice, 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->trans(
"Unit") .
")";
4273 $labeltoshowhtmlprice .=
" (" .
price($objp->unitprice, 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->transnoentities(
"Unit") .
")";
4275 if (empty($hidepriceinlabel) && !empty($objp->remise_percent) && $objp->remise_percent >= 1) {
4276 $labeltoshowprice .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4277 $labeltoshowhtmlprice .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4282 if (!empty($objp->idprodcustprice)) {
4285 if ($objp->custprice_base_type ==
'HT') {
4286 $labeltoshowprice .=
' - ' .
price($objp->custprice, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
4287 $labeltoshowhtmlprice .=
' - ' .
price($objp->custprice, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
4289 $labeltoshowprice .=
' - ' .
price($objp->custprice_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
4290 $labeltoshowhtmlprice .=
' - ' .
price($objp->custprice_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
4293 $outprice_ht =
price($objp->custprice);
4294 $outprice_ttc =
price($objp->custprice_ttc);
4295 $outpricebasetype = $objp->custprice_base_type;
4296 $outtva_tx = $objp->custtva_tx;
4297 $outdefault_vat_code = $objp->custdefault_vat_code;
4298 $outdiscount = $objp->custdiscount_percent;
4303 if (empty($hidepriceinlabel) && !$found) {
4304 if ($objp->price_base_type ==
'HT') {
4305 $labeltoshowprice .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
4306 $labeltoshowhtmlprice .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
4308 $labeltoshowprice .=
' - ' .
price($objp->price_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
4309 $labeltoshowhtmlprice .=
' - ' .
price($objp->price_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
4311 $outprice_ht =
price($objp->price);
4312 $outprice_ttc =
price($objp->price_ttc);
4313 $outpricebasetype = $objp->price_base_type;
4314 $outtva_tx = $objp->tva_tx;
4315 $outdefault_vat_code = $objp->default_vat_code;
4318 $optiontext = $labeltosearch.$outvalUnits.$labeltoshowprice.$labeltoshowstock;
4319 $optionhtml = $labeltoshowhtml.$outvalUnits.$labeltoshowhtmlprice.$labeltoshowhtmlstock;
4323 $opt =
'<option value="' . $objp->rowid .
'"';
4324 $opt .= ($objp->rowid == $selected) ?
' selected' :
'';
4325 if (!empty($objp->price_by_qty_rowid) && $objp->price_by_qty_rowid > 0) {
4326 $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 .
'"';
4329 $opt .=
' data-labeltrans="' .
dol_escape_htmltag($outlabel_translated, 0, 0,
'', 0, 1) .
'"';
4333 if ($stocktag == 1) {
4334 $opt .=
' class="product_line_stock_ok" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml, 0, array(
'strong')).dolPrintHTMLForAttribute($outvalUnits).$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
4337 if ($stocktag == -1) {
4338 $opt .=
' class="product_line_stock_too_low" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml, 0, array(
'strong')).dolPrintHTMLForAttribute($outvalUnits).$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
4341 $opt .=
' data-html="'.$optionhtmlforattribute.
'" data-select-html="'.$optionhtmlforattribute.
'"';
4347 $outval .= $labeltoshowhtml;
4350 $outval .= $outvalUnits;
4353 $outval .= $labeltoshowhtmlprice;
4356 $outval .= $labeltoshowhtmlstock;
4359 $parameters = array(
'objp' => $objp);
4360 $reshook = $hookmanager->executeHooks(
'constructProductListOption', $parameters);
4361 if (empty($reshook)) {
4362 $opt .= $hookmanager->resPrint;
4364 $opt = $hookmanager->resPrint;
4367 $opt .=
"</option>\n";
4372 'label2' => $outlabel,
4376 'price_ttc' =>
price2num($outprice_ttc),
4379 'pricebasetype' => $outpricebasetype,
4380 'tva_tx' => $outtva_tx,
4381 'default_vat_code' => $outdefault_vat_code,
4383 'discount' => $outdiscount,
4384 'duration_value' => $outdurationvalue,
4385 'duration_unit' => $outdurationunit,
4387 'labeltrans' => $outlabel_translated,
4388 'desctrans' => $outdesc_translated,
4389 'ref_customer' => $outrefcust
4411 public function select_produits_fournisseurs($socid, $selected =
'', $htmlname =
'productid', $filtertype =
'', $notused =
'', $ajaxoptions = array(), $hidelabel = 0, $alsoproductwithnosupplierprice = 0, $morecss =
'', $placeholder =
'', $nooutput = 0)
4414 global $langs,
$conf;
4415 global $price_level, $status, $finished;
4417 if (!isset($status)) {
4421 $selected_input_value =
'';
4423 if ((
int) $selected > 0) {
4424 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
4425 $producttmpselect =
new Product($this->db);
4426 $producttmpselect->fetch((
int) $selected);
4427 $selected_input_value = $producttmpselect->ref;
4428 unset($producttmpselect);
4429 } elseif (preg_match(
'/^idprod_([0-9]+)$/', (
string) $selected, $regtmpsel)) {
4431 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
4432 $producttmpselect =
new Product($this->db);
4433 $producttmpselect->fetch((
int) $regtmpsel[1]);
4434 $selected_input_value = $producttmpselect->ref;
4435 unset($producttmpselect);
4439 $urloption = ($socid > 0 ?
'socid=' . $socid .
'&' :
'') .
'htmlname=' . $htmlname .
'&outjson=1&price_level=' . $price_level .
'&type=' . $filtertype .
'&mode=2&status=' . $status .
'&finished=' . $finished .
'&alsoproductwithnosupplierprice=' . $alsoproductwithnosupplierprice;
4441 $s = ($hidelabel ?
'' : $langs->trans(
"RefOrLabel") .
' : ') .
'<input type="text" class="'.$morecss.
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . ($placeholder ?
' placeholder="' . $placeholder .
'"' :
'') .
'>';
4443 $s .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT .
'/product/ajax/products.php', $urloption,
getDolGlobalInt(
'PRODUIT_USE_SEARCH_TO_SELECT'), 0, $ajaxoptions);
4445 $s = $this->
select_produits_fournisseurs_list($socid, $selected, $htmlname, $filtertype, $notused,
'', $status, 0, 0, $alsoproductwithnosupplierprice, $morecss,
getDolGlobalInt(
'SUPPLIER_SHOW_STOCK_IN_PRODUCTS_COMBO'), $placeholder);
4475 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 =
'')
4478 global $langs,
$conf, $user;
4479 global $hookmanager;
4482 $outarray = array();
4486 $langs->load(
'stocks');
4489 $langs->load(
'other');
4492 $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,";
4493 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice, pfp.barcode";
4494 $sql .=
", pfp.multicurrency_code, pfp.multicurrency_unitprice";
4495 $sql .=
", pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.default_vat_code, pfp.fk_soc, s.nom as name";
4496 $sql .=
", pfp.supplier_reputation";
4499 $sql .=
", pfp.desc_fourn as description";
4501 $sql .=
", p.description";
4505 $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";
4510 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListSelect', $parameters);
4511 $sql .= $hookmanager->resPrint;
4513 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
4517 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListFrom', $parameters);
4518 $sql .= $hookmanager->resPrint;
4520 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN (" .
getEntity(
'product') .
") )";
4522 $sql .=
" AND pfp.fk_soc = " . ((int) $socid);
4524 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
4527 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
4529 $sql .=
" WHERE p.entity IN (" .
getEntity(
'product') .
")";
4530 if ($statut != -1) {
4531 $sql .=
" AND p.tobuy = " . ((int) $statut);
4533 if (strval($filtertype) !=
'') {
4534 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
4538 $parameters = array();
4539 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListWhere', $parameters);
4540 $sql .= $hookmanager->resPrint;
4542 if ($filterkey !=
'') {
4546 $search_crit = explode(
' ', $filterkey);
4548 if (count($search_crit) > 1) {
4551 foreach ($search_crit as $crit) {
4555 $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) .
"%'";
4557 $sql .=
" OR pfp.desc_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
4562 if (count($search_crit) > 1) {
4566 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
4567 $sql .=
" OR pfp.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
4571 $sql .=
" ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC";
4572 $sql .= $this->db->plimit($limit, 0);
4576 dol_syslog(get_class($this) .
"::select_produits_fournisseurs_list", LOG_DEBUG);
4577 $result = $this->db->query($sql);
4579 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4580 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
4582 $num = $this->db->num_rows($result);
4585 $out .=
'<select class="flat ' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'">';
4587 $out .=
'<option value="-1" selected>' . ($placeholder ? $placeholder :
' ') .
'</option>';
4589 $out .=
'<option value="-1">' . ($placeholder ? $placeholder :
' ') .
'</option>';
4594 $objp = $this->db->fetch_object($result);
4596 if (is_null($objp->idprodfournprice)) {
4598 $objp->tva_tx = $objp->tva_tx_sale;
4599 $objp->default_vat_code = $objp->default_vat_code_sale;
4602 $outkey = $objp->idprodfournprice;
4603 if (!$outkey && $alsoproductwithnosupplierprice) {
4604 $outkey =
'idprod_' . $objp->rowid;
4607 $outref = $objp->ref;
4608 $outbarcode = $objp->barcode;
4611 $outtype = $objp->fk_product_type;
4618 if (!empty($objp->unit_short)) {
4619 $outvalUnits .=
' - ' . $objp->unit_short;
4621 if (!empty($objp->weight) && $objp->weight_units !==
null) {
4623 $outvalUnits .=
' - ' . $unitToShow;
4625 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
4626 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
4627 $outvalUnits .=
' - ' . $unitToShow;
4629 if (!empty($objp->surface) && $objp->surface_units !==
null) {
4631 $outvalUnits .=
' - ' . $unitToShow;
4633 if (!empty($objp->volume) && $objp->volume_units !==
null) {
4635 $outvalUnits .=
' - ' . $unitToShow;
4637 if ($outdurationvalue && $outdurationunit) {
4639 'h' => $langs->trans(
'Hour'),
4640 'd' => $langs->trans(
'Day'),
4641 'w' => $langs->trans(
'Week'),
4642 'm' => $langs->trans(
'Month'),
4643 'y' => $langs->trans(
'Year')
4645 if (isset($da[$outdurationunit])) {
4646 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
4651 $objRef = $objp->ref;
4652 if ($filterkey && $filterkey !=
'') {
4653 $objRef = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRef, 1);
4655 $objRefFourn = $objp->ref_fourn;
4656 if ($filterkey && $filterkey !=
'') {
4657 $objRefFourn = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRefFourn, 1);
4659 $label = $objp->label;
4660 if ($filterkey && $filterkey !=
'') {
4661 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
4664 switch ($objp->fk_product_type) {
4676 if (empty($picto)) {
4679 $optlabel =
img_object(
'', $picto,
'class="paddingright classfortooltip"', 0, 0, 1);
4682 $optlabel .= $objp->ref;
4683 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
4684 $optlabel .=
' <span class="opacitymedium">(' . $objp->ref_fourn .
')</span>';
4686 if (
isModEnabled(
'barcode') && !empty($objp->barcode)) {
4687 $optlabel .=
' (' . $outbarcode .
')';
4689 $optlabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
4691 $outvallabel = $objRef;
4692 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
4693 $outvallabel .=
' (' . $objRefFourn .
')';
4695 if (
isModEnabled(
'barcode') && !empty($objp->barcode)) {
4696 $outvallabel .=
' (' . $outbarcode .
')';
4698 $outvallabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
4700 $outsearchlabel = implode(
' ', array_filter(array(
4701 (
string) $objp->ref,
4702 (
string) $objp->ref_fourn,
4703 (
string) $objp->barcode,
4704 (
string) $objp->label,
4706 ), function (
string $value):
bool {
4707 return $value !==
'';
4711 $optlabel .= $outvalUnits;
4712 $outvallabel .= $outvalUnits;
4714 if (!empty($objp->idprodfournprice)) {
4715 $outqty = $objp->quantity;
4716 $outdiscount = $objp->remise_percent;
4717 if (
isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
4719 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
4720 $prod_supplier->id = $objp->fk_product;
4721 $prod_supplier->fourn_qty = $objp->quantity;
4722 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
4723 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
4725 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4727 $price_result = $priceparser->parseProductSupplier($prod_supplier);
4728 if ($price_result >= 0) {
4729 $objp->fprice = $price_result;
4730 if ($objp->quantity >= 1) {
4731 $objp->unitprice = $objp->fprice / $objp->quantity;
4735 if ($objp->quantity == 1) {
4736 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
4737 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1,
$conf->currency) .
"/";
4738 $optlabel .= $langs->trans(
"Unit");
4739 $outvallabel .= $langs->transnoentities(
"Unit");
4741 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
4742 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
4743 $optlabel .=
' ' . $langs->trans(
"Units");
4744 $outvallabel .=
' ' . $langs->transnoentities(
"Units");
4747 if ($objp->quantity != 1) {
4748 $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") .
")";
4749 $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") .
")";
4751 if ($objp->remise_percent >= 1) {
4752 $optlabel .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4753 $outvallabel .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4755 if ($objp->duration) {
4756 $optlabel .=
" - " . $objp->duration;
4757 $outvallabel .=
" - " . $objp->duration;
4760 $optlabel .=
" - " .
dol_trunc($objp->name, 8);
4761 $outvallabel .=
" - " .
dol_trunc($objp->name, 8);
4763 if ($objp->supplier_reputation) {
4765 $reputations = array(
'' => $langs->trans(
'Standard'),
'FAVORITE' => $langs->trans(
'Favorite'),
'NOTTHGOOD' => $langs->trans(
'NotTheGoodQualitySupplier'),
'DONOTORDER' => $langs->trans(
'DoNotOrderThisProductToThisSupplier'));
4767 $optlabel .=
" - " . $reputations[$objp->supplier_reputation];
4768 $outvallabel .=
" - " . $reputations[$objp->supplier_reputation];
4771 $optlabel .=
" - <span class='opacitymedium'>" . $langs->trans(
"NoPriceDefinedForThisSupplier") .
'</span>';
4772 $outvallabel .=
' - ' . $langs->transnoentities(
"NoPriceDefinedForThisSupplier");
4776 $novirtualstock = ($showstockinlist == 2);
4778 if ($user->hasRight(
'stock',
'lire')) {
4779 $outvallabel .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
4781 if ($objp->stock > 0) {
4782 $optlabel .=
' - <span class="product_line_stock_ok">';
4783 } elseif ($objp->stock <= 0) {
4784 $optlabel .=
' - <span class="product_line_stock_too_low">';
4786 $optlabel .= $langs->transnoentities(
"Stock") .
':' .
price(
price2num($objp->stock,
'MS'));
4787 $optlabel .=
'</span>';
4788 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
4789 $langs->load(
"stocks");
4791 $tmpproduct =
new Product($this->db);
4792 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
4793 $tmpproduct->load_virtual_stock();
4794 $virtualstock = $tmpproduct->stock_theorique;
4796 $outvallabel .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
4798 $optlabel .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
4799 if ($virtualstock > 0) {
4800 $optlabel .=
'<span class="product_line_stock_ok">';
4801 } elseif ($virtualstock <= 0) {
4802 $optlabel .=
'<span class="product_line_stock_too_low">';
4804 $optlabel .= $virtualstock;
4805 $optlabel .=
'</span>';
4812 $optstart =
'<option value="' . $outkey .
'"';
4813 if ($selected && preg_match(
'/^idprod_/', (
string) $selected) && (
string) $selected ==
'idprod_'.$objp->rowid) {
4814 $optstart .=
' selected';
4815 } elseif ($selected && (
string) $selected == (
string) $objp->idprodfournprice) {
4816 $optstart .=
' selected';
4819 if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) {
4820 $optstart .=
' disabled';
4823 if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) {
4832 $optstart .=
' data-default-vat-code="' .
dol_escape_htmltag($objp->default_vat_code) .
'"';
4835 $optstart .=
' data-multicurrency-code="' .
dol_escape_htmltag($objp->multicurrency_code) .
'"';
4839 $optstart .=
' data-description="' .
dol_escape_htmltag($objp->description, 0, 1) .
'"';
4843 $outarrayentry = array(
4846 'label' => $outvallabel,
4847 'labelhtml' => $optlabel,
4849 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4850 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4851 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4852 'tva_tx_formated' =>
price($objp->tva_tx, 0, $langs, 1, -1, 2),
4854 'default_vat_code' => $objp->default_vat_code,
4855 'supplier_ref' => $objp->ref_fourn,
4856 'discount' => $outdiscount,
4858 'duration_value' => $outdurationvalue,
4859 'duration_unit' => $outdurationunit,
4860 'disabled' => empty($objp->idprodfournprice),
4861 'description' => $objp->description
4864 $outarrayentry[
'multicurrency_code'] = $objp->multicurrency_code;
4865 $outarrayentry[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4867 $parameters = array(
4869 'optstart' => &$optstart,
4870 'optlabel' => &$optlabel,
4871 'outvallabel' => &$outvallabel,
4872 'outarrayentry' => &$outarrayentry,
4875 $reshook = $hookmanager->executeHooks(
'selectProduitsFournisseurListOption', $parameters, $this);
4881 $out .= $optstart .
' data-html="' .
dol_escape_htmltag($optlabel) .
'">' . $optlabel .
"</option>\n";
4882 $outarraypush = array(
4885 'label' => $outvallabel,
4886 'labelhtml' => $optlabel,
4888 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4889 'price_qty_ht_locale' =>
price($objp->fprice),
4890 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4891 'price_unit_ht_locale' =>
price($objp->unitprice),
4892 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4893 'tva_tx_formated' =>
price($objp->tva_tx),
4895 'default_vat_code' => $objp->default_vat_code,
4896 'supplier_ref' => $objp->ref_fourn,
4897 'discount' => $outdiscount,
4899 'duration_value' => $outdurationvalue,
4900 'duration_unit' => $outdurationunit,
4901 'disabled' => empty($objp->idprodfournprice),
4902 'description' => $objp->description
4905 $outarraypush[
'multicurrency_code'] = $objp->multicurrency_code;
4906 $outarraypush[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4908 array_push($outarray, $outarraypush);
4921 $out .=
'</select>';
4923 $this->db->free($result);
4925 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
4931 if (empty($outputmode)) {
4950 global $langs,
$conf;
4952 $langs->load(
'stocks');
4954 $sql =
"SELECT p.rowid, p.ref, p.label, p.price, p.duration, pfp.fk_soc,";
4955 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.remise_percent, pfp.quantity, pfp.unitprice,";
4956 $sql .=
" pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name";
4957 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
4958 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
4959 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
4960 $sql .=
" WHERE pfp.entity IN (" .
getEntity(
'productsupplierprice') .
")";
4961 $sql .=
" AND p.tobuy = 1";
4962 $sql .=
" AND s.fournisseur = 1";
4963 $sql .=
" AND p.rowid = " . ((int) $productid);
4965 $sql .=
" ORDER BY s.nom, pfp.ref_fourn DESC";
4967 $sql .=
" ORDER BY pfp.unitprice - pfp.unitprice * pfp.remise_percent / 100 ASC";
4970 dol_syslog(get_class($this) .
"::select_product_fourn_price", LOG_DEBUG);
4971 $result = $this->db->query($sql);
4974 $num = $this->db->num_rows($result);
4976 $form =
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
4979 $form .=
'<option value="0">-- ' . $langs->trans(
"NoSupplierPriceDefinedForThisProduct") .
' --</option>';
4981 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4982 $form .=
'<option value="0"> </option>';
4986 $objp = $this->db->fetch_object($result);
4988 $opt =
'<option value="' . $objp->idprodfournprice .
'"';
4990 if ($num == 1 || ($selected_supplier > 0 && $objp->fk_soc == $selected_supplier) || ($i == 0 &&
getDolGlobalString(
'PRODUCT_BEST_SUPPLIER_PRICE_PRESELECTED'))) {
4991 $opt .=
' selected';
4993 $opt .=
'>' . $objp->name .
' - ' . $objp->ref_fourn .
' - ';
4995 if (
isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
4997 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
4998 $prod_supplier->id = $productid;
4999 $prod_supplier->fourn_qty = $objp->quantity;
5000 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
5001 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
5003 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
5005 $price_result = $priceparser->parseProductSupplier($prod_supplier);
5006 if ($price_result >= 0) {
5007 $objp->fprice = $price_result;
5008 if ($objp->quantity >= 1) {
5009 $objp->unitprice = $objp->fprice / $objp->quantity;
5013 if ($objp->quantity == 1) {
5014 $opt .=
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
5017 $opt .= $objp->quantity .
' ';
5019 if ($objp->quantity == 1) {
5020 $opt .= $langs->trans(
"Unit");
5022 $opt .= $langs->trans(
"Units");
5024 if ($objp->quantity > 1) {
5026 $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");
5028 if ($objp->duration) {
5029 $opt .=
" - " . $objp->duration;
5031 $opt .=
"</option>\n";
5038 $form .=
'</select>';
5039 $this->db->free($result);
5057 global $langs, $hookmanager;
5059 $num = count($this->cache_conditions_paiements);
5066 $this->cache_conditions_paiements = array();
5068 $sql =
"SELECT rowid, code, libelle as label, deposit_percent, entity";
5069 $sql .=
" FROM " . $this->db->prefix() .
'c_payment_term';
5070 $sql .=
" WHERE entity IN (" .
getEntity(
'c_payment_term') .
")";
5071 $sql .=
" AND active > 0";
5072 $sql .=
" ORDER BY sortorder";
5074 $resql = $this->db->query($sql);
5076 $num = $this->db->num_rows($resql);
5079 $obj = $this->db->fetch_object($resql);
5082 $label = ($langs->trans(
"PaymentConditionShort" . $obj->code) !=
"PaymentConditionShort" . $obj->code ? $langs->trans(
"PaymentConditionShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
5084 $this->cache_conditions_paiements[$obj->rowid][
'code'] = (
string) $obj->code;
5085 $this->cache_conditions_paiements[$obj->rowid][
'label'] = (
string) $label;
5086 $this->cache_conditions_paiements[$obj->rowid][
'deposit_percent'] = (
string) $obj->deposit_percent;
5087 $this->cache_conditions_paiements[$obj->rowid][
'entity'] = (int) $obj->entity;
5092 $parameters = array(
'context' =>
'paymentterm');
5093 $reshook = $hookmanager->executeHooks(
'loadDictionaryCache', $parameters, $this);
5094 if (empty($reshook)) {
5095 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
5096 $this->cache_conditions_paiements = array_merge($this->cache_conditions_paiements, $hookmanager->resArray);
5099 $this->cache_conditions_paiements = $hookmanager->resArray;
5123 $this->cache_rule_for_lines_dates = $factureRec->fields[
'rule_for_lines_dates'][
'arrayofkeyval'];
5125 if (empty($this->cache_rule_for_lines_dates)) {
5144 $num = count($this->cache_availability);
5151 $this->cache_availability = array();
5153 $langs->load(
'propal');
5155 $sql =
"SELECT rowid, code, label, position";
5156 $sql .=
" FROM " . $this->db->prefix() .
'c_availability';
5157 $sql .=
" WHERE active > 0";
5159 $resql = $this->db->query($sql);
5161 $num = $this->db->num_rows($resql);
5164 $obj = $this->db->fetch_object($resql);
5167 $label = ($langs->trans(
"AvailabilityType" . $obj->code) !=
"AvailabilityType" . $obj->code ? $langs->trans(
"AvailabilityType" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
5168 $this->cache_availability[$obj->rowid][
'code'] = (
string) $obj->code;
5169 $this->cache_availability[$obj->rowid][
'label'] = (
string) $label;
5170 $this->cache_availability[$obj->rowid][
'position'] = (int) $obj->position;
5175 $this->cache_availability =
dol_sort_array($this->cache_availability,
'position',
'asc', 0, 0, 1);
5195 public function selectAvailabilityDelay($selected =
'', $htmlname =
'availid', $filtertype =
'', $addempty = 0, $morecss =
'', $noouput = 0)
5197 global $langs, $user;
5201 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
5203 $out =
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
5205 $out .=
'<option value="-1">'.(is_numeric($addempty) ?
' ' : $langs->trans($addempty)).
'</option>';
5207 foreach ($this->cache_availability as
$id => $arrayavailability) {
5208 if ($selected ==
$id) {
5209 $out .=
'<option value="' .
$id .
'" selected>';
5211 $out .=
'<option value="' .
$id .
'">';
5214 $out .=
'</option>';
5216 $out .=
'</select>';
5218 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5235 public function loadCacheInputReason()
5239 $num = count($this->cache_demand_reason);
5244 $sql =
"SELECT rowid, code, label";
5245 $sql .=
" FROM " . $this->db->prefix() .
'c_input_reason';
5246 $sql .=
" WHERE active > 0";
5248 $resql = $this->db->query($sql);
5250 $num = $this->db->num_rows($resql);
5253 $tmparray = array();
5255 $obj = $this->db->fetch_object($resql);
5258 $label = ($obj->label !=
'-' ? (
string) $obj->label :
'');
5259 if ($langs->trans(
"DemandReasonType" . $obj->code) !=
"DemandReasonType" . $obj->code) {
5260 $label = $langs->trans(
"DemandReasonType" . $obj->code);
5262 if ($langs->trans($obj->code) != $obj->code) {
5263 $label = $langs->trans($obj->code);
5266 $tmparray[(int) $obj->rowid]
5268 'id' => (
int) $obj->rowid,
5269 'code' => (
string) $obj->code,
5275 $this->cache_demand_reason =
dol_sort_array($tmparray,
'label',
'asc', 0, 0, 1);
5297 public function selectInputReason($selected =
'', $htmlname =
'demandreasonid', $exclude =
'', $addempty = 0, $morecss =
'', $notooltip = 0)
5299 global $langs, $user;
5301 $this->loadCacheInputReason();
5303 print
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
5305 print
'<option value="0"' . (empty($selected) ?
' selected' :
'') .
'> </option>';
5307 foreach ($this->cache_demand_reason as
$id => $arraydemandreason) {
5308 if ($arraydemandreason[
'code'] == $exclude) {
5312 if ($selected && ($selected == $arraydemandreason[
'id'] || $selected == $arraydemandreason[
'code'])) {
5313 print
'<option value="' . $arraydemandreason[
'id'] .
'" selected>';
5315 print
'<option value="' . $arraydemandreason[
'id'] .
'">';
5317 $label = $arraydemandreason[
'label'];
5318 print $langs->trans($label);
5322 if ($user->admin && empty($notooltip)) {
5323 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5338 global $langs, $hookmanager;
5340 $num = count($this->cache_types_paiements);
5347 $this->cache_types_paiements = array();
5349 $sql =
"SELECT id, code, libelle as label, type, entity, active";
5350 $sql .=
" FROM " . $this->db->prefix() .
"c_paiement";
5351 $sql .=
" WHERE entity IN (" .
getEntity(
'c_paiement') .
")";
5353 $resql = $this->db->query($sql);
5355 $num = $this->db->num_rows($resql);
5358 $obj = $this->db->fetch_object($resql);
5361 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) !=
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
5362 $this->cache_types_paiements[$obj->id][
'id'] = (int) $obj->id;
5363 $this->cache_types_paiements[$obj->id][
'code'] = (
string) $obj->code;
5364 $this->cache_types_paiements[$obj->id][
'label'] = (
string) $label;
5365 $this->cache_types_paiements[$obj->id][
'type'] = (int) $obj->type;
5366 $this->cache_types_paiements[$obj->id][
'entity'] = (int) $obj->entity;
5367 $this->cache_types_paiements[$obj->id][
'active'] = (int) $obj->active;
5371 $parameters = array(
'context' =>
'paymenttype');
5372 $reshook = $hookmanager->executeHooks(
'loadDictionaryCache', $parameters, $this);
5373 if (empty($reshook)) {
5374 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
5375 $this->cache_types_paiements = array_merge($this->cache_types_paiements, $hookmanager->resArray);
5378 $this->cache_types_paiements = $hookmanager->resArray;
5381 $this->cache_types_paiements =
dol_sort_array($this->cache_types_paiements,
'label',
'asc', 0, 0, 1);
5411 public function select_conditions_paiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1, $noprint = 0)
5415 if (empty($noprint)) {
5439 public function getSelectConditionsPaiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1)
5441 global $langs, $user;
5444 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
5449 if (empty($selected) && strpos($htmlname,
'search_') !== 0 &&
getDolGlobalInt(
'MAIN_DEFAULT_PAYMENT_TERM_ID')) {
5450 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TERM_ID", LOG_NOTICE);
5454 $out .=
'<select id="' . $htmlname .
'" class="flat selectpaymentterms' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
5456 $out .=
'<option value="0"> </option>';
5459 $selectedDepositPercent =
null;
5461 foreach ($this->cache_conditions_paiements as
$id => $arrayconditions) {
5462 if ($filtertype <= 0 && !empty($arrayconditions[
'deposit_percent'])) {
5466 if ($selected ==
$id) {
5467 $selectedDepositPercent = $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'];
5468 $out .=
'<option value="' .
$id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'" selected>';
5470 $out .=
'<option value="' .
$id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'">';
5472 $label = $arrayconditions[
'label'];
5474 if (!empty($arrayconditions[
'deposit_percent'])) {
5475 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'], $label);
5479 $out .=
'</option>';
5481 $out .=
'</select>';
5482 if ($user->admin && empty($noinfoadmin)) {
5483 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5487 if ($deposit_percent >= 0) {
5488 $out .=
' <span id="' . $htmlname .
'_deposit_percent_container"' . (empty($selectedDepositPercent) ?
' style="display: none"' :
'') .
'>';
5489 $out .= $langs->trans(
'DepositPercent') .
' : ';
5490 $out .=
'<input id="' . $htmlname .
'_deposit_percent" name="' . $htmlname .
'_deposit_percent" class="maxwidth50" value="' . $deposit_percent .
'" />';
5493 <script nonce="' .
getNonce() .
'">
5494 $(document).ready(function () {
5495 $("#' . $htmlname .
'").change(function () {
5496 let $selected = $(this).find("option:selected");
5497 let depositPercent = $selected.attr("data-deposit_percent");
5499 if (depositPercent.length > 0) {
5500 $("#' . $htmlname .
'_deposit_percent_container").show().find("#' . $htmlname .
'_deposit_percent").val(depositPercent);
5502 $("#' . $htmlname .
'_deposit_percent_container").hide();
5531 $out .=
'<select id="' . $htmlname .
'" class="flat selectbillingterm" name="' . $htmlname .
'">';
5533 $out .=
'<option value="-1"> </option>';
5537 foreach ($this->cache_rule_for_lines_dates as $rule_for_lines_dates_key => $rule_for_lines_dates_name) {
5538 if ($selected == $rule_for_lines_dates_key) {
5539 $out .=
'<option value="' . $rule_for_lines_dates_key .
'" selected>';
5541 $out .=
'<option value="' . $rule_for_lines_dates_key .
'">';
5544 $out .= $langs->trans($rule_for_lines_dates_name);
5545 $out .=
'</option>';
5547 $out .=
'</select>';
5573 public function select_types_paiements($selected =
'', $htmlname =
'paiementtype', $filtertype =
'', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'', $nooutput = 0)
5576 global $langs, $user;
5580 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $filtertype .
", " . $format, LOG_DEBUG);
5582 $filterarray = array();
5583 if ($filtertype ==
'CRDT') {
5584 $filterarray = array(0, 2, 3);
5585 } elseif ($filtertype ==
'DBIT') {
5586 $filterarray = array(1, 2, 3);
5587 } elseif ($filtertype !=
'' && $filtertype !=
'-1') {
5588 $filterarray = explode(
',', $filtertype);
5594 if (empty($selected) && strpos($htmlname,
'search_') !== 0 &&
getDolGlobalString(
'MAIN_DEFAULT_PAYMENT_TYPE_ID')) {
5595 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TYPE_ID", LOG_NOTICE);
5599 $out .=
'<select id="select' . $htmlname .
'" class="flat selectpaymenttypes' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
5601 $out .=
'<option value=""> </option>';
5603 foreach ($this->cache_types_paiements as
$id => $arraytypes) {
5605 if ($active >= 0 && $arraytypes[
'active'] != $active) {
5610 if (count($filterarray) && !in_array($arraytypes[
'type'], $filterarray)) {
5615 if ($empty && empty($arraytypes[
'code'])) {
5620 $out .=
'<option value="' .
$id .
'" data-code="'.$arraytypes[
'code'].
'"';
5621 } elseif ($format == 1) {
5622 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
5623 } elseif ($format == 2) {
5624 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
5625 } elseif ($format == 3) {
5626 $out .=
'<option value="' .
$id .
'"';
5629 if ($format == 1 || $format == 2) {
5630 if ($selected == $arraytypes[
'code']) {
5631 $out .=
' selected';
5634 if ($selected ==
$id) {
5635 $out .=
' selected';
5641 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
5642 } elseif ($format == 1) {
5643 $value = $arraytypes[
'code'];
5644 } elseif ($format == 2) {
5645 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
5646 } elseif ($format == 3) {
5647 $value = $arraytypes[
'code'];
5649 $out .= $value ? $value :
' ';
5650 $out .=
'</option>';
5652 $out .=
'</select>';
5653 if ($user->admin && !$noadmininfo) {
5654 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5658 if (empty($nooutput)) {
5678 $return =
'<select class="flat maxwidth100" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
5680 'HT' => $langs->trans(
"HT"),
5681 'TTC' => $langs->trans(
"TTC")
5683 foreach ($options as
$id => $value) {
5684 if ($selected ==
$id) {
5685 $return .=
'<option value="' .
$id .
'" selected>' . $value;
5687 $return .=
'<option value="' .
$id .
'">' . $value;
5689 $return .=
'</option>';
5691 $return .=
'</select>';
5711 $num = count($this->cache_transport_mode);
5718 $this->cache_transport_mode = array();
5720 $sql =
"SELECT rowid, code, label, active";
5721 $sql .=
" FROM " . $this->db->prefix() .
"c_transport_mode";
5722 $sql .=
" WHERE entity IN (" .
getEntity(
'c_transport_mode') .
")";
5724 $resql = $this->db->query($sql);
5726 $num = $this->db->num_rows($resql);
5729 $obj = $this->db->fetch_object($resql);
5732 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) !=
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
5733 $this->cache_transport_mode[(int) $obj->rowid]
5735 'rowid' => (
int) $obj->rowid,
5736 'code' => (
string) $obj->code,
5737 'label' => (
string) $label,
5738 'active' => (int) $obj->active,
5743 $this->cache_transport_mode =
dol_sort_array($this->cache_transport_mode,
'label',
'asc', 0, 0, 1);
5765 public function selectTransportMode($selected =
'', $htmlname =
'transportmode', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'')
5767 global $langs, $user;
5769 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $format, LOG_DEBUG);
5773 print
'<select id="select' . $htmlname .
'" class="flat selectmodetransport' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
5775 print
'<option value=""> </option>';
5777 foreach ($this->cache_transport_mode as
$id => $arraytypes) {
5779 if ($active >= 0 && $arraytypes[
'active'] != $active) {
5784 if ($empty && empty($arraytypes[
'code'])) {
5789 print
'<option value="' .
$id .
'"';
5790 } elseif ($format == 1) {
5791 print
'<option value="' . $arraytypes[
'code'] .
'"';
5792 } elseif ($format == 2) {
5793 print
'<option value="' . $arraytypes[
'code'] .
'"';
5794 } elseif ($format == 3) {
5795 print
'<option value="' .
$id .
'"';
5798 if (preg_match(
'/[a-z]/i', $selected) && $selected == $arraytypes[
'code']) {
5800 } elseif ($selected ==
$id) {
5806 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
5807 } elseif ($format == 1) {
5808 $value = $arraytypes[
'code'];
5809 } elseif ($format == 2) {
5810 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
5811 } elseif ($format == 3) {
5812 $value = $arraytypes[
'code'];
5814 print $value ? $value :
' ';
5821 if ($user->admin && !$noadmininfo) {
5822 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5838 public function selectShippingMethod($selected =
'', $htmlname =
'shipping_method_id', $filtre =
'', $useempty = 0, $moreattrib =
'', $noinfoadmin = 0, $morecss =
'')
5840 global $langs, $user;
5842 $langs->loadLangs(array(
"admin",
"sendings"));
5844 $sql =
"SELECT rowid, code, libelle as label";
5845 $sql .=
" FROM " . $this->db->prefix() .
"c_shipment_mode";
5846 $sql .=
" WHERE active > 0";
5850 $sql .=
" ORDER BY libelle ASC";
5852 dol_syslog(get_class($this) .
"::selectShippingMode", LOG_DEBUG);
5854 $result = $this->db->query($sql);
5856 $num = $this->db->num_rows($result);
5859 print
'<select id="select' . $htmlname .
'" class="flat selectshippingmethod' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5860 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5861 print
'<option value="-1"> </option>';
5864 $obj = $this->db->fetch_object($result);
5865 if ($selected == $obj->rowid) {
5866 print
'<option value="' . $obj->rowid .
'" selected>';
5868 print
'<option value="' . $obj->rowid .
'">';
5870 print ($langs->trans(
"SendingMethod" . strtoupper($obj->code)) !=
"SendingMethod" . strtoupper($obj->code)) ? $langs->trans(
"SendingMethod" . strtoupper($obj->code)) : $obj->label;
5875 if ($user->admin && empty($noinfoadmin)) {
5876 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5881 print $langs->trans(
"NoShippingMethodDefined");
5901 $langs->load(
"sendings");
5903 if ($htmlname !=
"none") {
5904 print
'<form method="POST" action="' . $page .
'">';
5905 print
'<input type="hidden" name="action" value="setshippingmethod">';
5906 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5908 print
'<input type="submit" class="button valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5912 $code = $langs->getLabelFromKey($this->db, $selected,
'c_shipment_mode',
'rowid',
'code');
5913 print $langs->trans(
"SendingMethod" . strtoupper($code));
5932 $langs->load(
'bills');
5936 $sql =
"SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc";
5937 $sql .=
' FROM ' . $this->db->prefix() .
'facture';
5938 $sql .=
' WHERE entity IN (' .
getEntity(
'invoice') .
')';
5939 $sql .=
' AND situation_counter >= 1';
5940 $sql .=
' AND fk_soc = ' . (int) $socid;
5941 $sql .=
' AND type <> 2';
5942 $sql .=
' ORDER by situation_cycle_ref, situation_counter desc';
5943 $resql = $this->db->query($sql);
5945 $nbSituationInvoiceForThirdparty = 0;
5947 if ($resql && $this->db->num_rows($resql) > 0) {
5950 while ($obj = $this->db->fetch_object($resql)) {
5952 if ($obj->situation_cycle_ref != $ref) {
5954 $ref = $obj->situation_cycle_ref;
5956 if ($obj->situation_final != 1) {
5958 if (substr($obj->ref, 1, 4) !=
'PROV') {
5959 $nbSituationInvoiceForThirdparty++;
5961 if ($selected == $obj->rowid) {
5962 $opt .=
'<option value="' . $obj->rowid .
'" selected>' . $obj->ref .
'</option>';
5964 $opt .=
'<option value="' . $obj->rowid .
'">' . $obj->ref .
'</option>';
5971 dol_syslog(
"Error sql=" . $sql .
", error=" . $this->error, LOG_ERR);
5974 if ($nbSituationInvoiceForThirdparty > 0) {
5975 $opt =
'<option class="minwidth100" value="" selected> </option>'.$opt;
5977 $opt =
'<option class="minwidth100" value="-1" selected>'.$langs->trans(
'NoSituations').
'</option>';
5992 public function selectUnits($selected =
'', $htmlname =
'units', $showempty = 0, $unit_type =
'')
5996 $langs->load(
'products');
5998 $return =
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'">';
6000 $sql =
"SELECT rowid, label, code FROM " . $this->db->prefix() .
"c_units";
6001 $sql .=
' WHERE active > 0';
6002 if (!empty($unit_type)) {
6003 $sql .=
" AND unit_type = '" . $this->db->escape($unit_type) .
"'";
6005 $sql .=
" ORDER BY sortorder";
6007 $resql = $this->db->query($sql);
6008 if ($resql && $this->db->num_rows($resql) > 0) {
6010 $return .=
'<option value="-1"></option>';
6013 while ($res = $this->db->fetch_object($resql)) {
6014 $unitLabel = $res->label;
6015 if (!empty($langs->tab_translate[
'unit' . $res->code])) {
6016 $unitLabel = $langs->trans(
'unit' . $res->code) != $res->label ? $langs->trans(
'unit' . $res->code) : $res->label;
6019 if ($selected == $res->rowid) {
6020 $return .=
'<option value="' . $res->rowid .
'" selected>' . $unitLabel .
'</option>';
6022 $return .=
'<option value="' . $res->rowid .
'">' . $unitLabel .
'</option>';
6025 $return .=
'</select>';
6049 public function select_comptes($selected =
'', $htmlname =
'accountid', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'', $showcurrency = 0, $morecss =
'', $nooutput = 0, $addentrynone = 0)
6056 $langs->loadLangs(array(
"admin",
"banks"));
6059 $sql =
"SELECT rowid, label, bank, clos as status, currency_code";
6060 $sql .=
" FROM " . $this->db->prefix() .
"bank_account";
6061 $sql .=
" WHERE entity IN (" .
getEntity(
'bank_account') .
")";
6063 $sql .=
" AND clos = " . (int) $status;
6068 $sql .=
" ORDER BY label";
6070 dol_syslog(get_class($this) .
"::select_comptes", LOG_DEBUG);
6071 $result = $this->db->query($sql);
6073 $num = $this->db->num_rows($result);
6076 $out .=
'<select id="select' . $htmlname .
'" class="flat selectbankaccount' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
6080 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoActiveBankAccountDefined") .
'</span>';
6082 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoBankAccountDefined") .
'</span>';
6085 if (!empty($useempty) && !is_numeric($useempty)) {
6086 $out .=
'<option value="-1">'.$langs->trans($useempty).
'</option>';
6087 } elseif ($useempty == 1 || ($useempty == 2 && $num > 1)) {
6088 $out .=
'<option value="-1"> </option>';
6093 $obj = $this->db->fetch_object($result);
6095 $labeltoshow = trim($obj->label);
6096 $labeltoshowhtml = trim($obj->label);
6097 if ($showcurrency) {
6098 $labeltoshow .=
' (' . $obj->currency_code .
')';
6099 $labeltoshowhtml .=
' <span class="opacitymedium">(' . $obj->currency_code .
')</span>';
6101 if ($status == 2 && $obj->status == 1) {
6102 $labeltoshow .=
' (' . $langs->trans(
"Closed") .
')';
6103 $labeltoshowhtml .=
' <span class="opacitymedium">(' . $langs->trans(
"Closed") .
')</span>';
6106 if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
6107 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml).
'" selected>';
6109 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml).
'">';
6111 $out .= $labeltoshow;
6112 $out .=
'</option>';
6116 if (!empty($addentrynone)) {
6117 $out .=
'<option value="-2"'.($selected == -2 ?
' selected="selected"' :
'').
' data-html="'.
dolPrintHTMLForAttribute(
'<span class="opacitymedium">'.$langs->trans(
"None").
'</span>').
'">'.$langs->trans(
"None").
'</option>';
6120 $out .=
"</select>";
6127 if (empty($nooutput)) {
6149 public function selectRib($selected =
'', $htmlname =
'ribcompanyid', $filtre =
'', $useempty = 0, $moreattrib =
'', $showibanbic = 0, $morecss =
'', $nooutput = 0)
6156 $langs->loadLangs(array(
"admin",
"banks"));
6159 $sql =
"SELECT rowid, label, bank, status, iban_prefix, bic, default_rib";
6160 $sql .=
" FROM " . $this->db->prefix() .
"societe_rib";
6161 $sql .=
" WHERE type = 'ban'";
6165 $sql .=
" ORDER BY label";
6166 dol_syslog(get_class($this) .
"::select_comptes", LOG_DEBUG);
6167 $result = $this->db->query($sql);
6169 $num = $this->db->num_rows($result);
6172 $out .=
'<select id="select' . $htmlname .
'" class="flat selectbankaccount' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
6175 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoBankAccountDefined") .
'</span>';
6177 if (!empty($useempty) && !is_numeric($useempty)) {
6178 $out .=
'<option value="-1">'.$langs->trans($useempty).
'</option>';
6179 } elseif ($useempty == 1 || ($useempty == 2 && $num > 1)) {
6180 $out .=
'<option value="-1"> </option>';
6185 $obj = $this->db->fetch_object($result);
6187 if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
6188 $out .=
'<option value="' . $obj->rowid .
'" data-iban-prefix="' . $iban .
' data-bic="' . $obj->bic .
'" selected>';
6190 $out .=
'<option value="' . $obj->rowid .
'" data-iban-prefix="' . $iban .
' data-bic="' . $obj->bic .
'">';
6192 $out .= trim($obj->label);
6194 $out .=
' (' . $iban .
'/' .$obj->bic.
')' . ($obj->default_rib ?
' ['.$langs->trans(
"ByDefault").
']' :
'');
6196 $out .=
'</option>';
6199 $out .=
"</select>";
6206 if (empty($nooutput)) {
6226 public function selectEstablishments($selected =
'', $htmlname =
'entity', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'')
6230 $langs->load(
"admin");
6233 $sql =
"SELECT rowid, name, fk_country, status, entity";
6234 $sql .=
" FROM " . $this->db->prefix() .
"establishment";
6235 $sql .=
" WHERE 1=1";
6237 $sql .=
" AND status = " . (int) $status;
6242 $sql .=
" ORDER BY name";
6244 dol_syslog(get_class($this) .
"::select_establishment", LOG_DEBUG);
6245 $result = $this->db->query($sql);
6247 $num = $this->db->num_rows($result);
6250 print
'<select id="select' . $htmlname .
'" class="flat selectestablishment" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
6251 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
6252 print
'<option value="-1"> </option>';
6256 $obj = $this->db->fetch_object($result);
6257 if ($selected == $obj->rowid) {
6258 print
'<option value="' . $obj->rowid .
'" selected>';
6260 print
'<option value="' . $obj->rowid .
'">';
6262 print trim($obj->name);
6263 if ($status == 2 && $obj->status == 1) {
6264 print
' (' . $langs->trans(
"Closed") .
')';
6272 print
'<span class="opacitymedium">' . $langs->trans(
"NoActiveEstablishmentDefined") .
'</span>';
6274 print
'<span class="opacitymedium">' . $langs->trans(
"NoEstablishmentFound") .
'</span>';
6297 if ($htmlname !=
"none") {
6298 print
'<form method="POST" action="' . $page .
'">';
6299 print
'<input type="hidden" name="action" value="setbankaccount">';
6300 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6301 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
6302 $nbaccountfound = $this->
select_comptes($selected, $htmlname, 0,
'', $addempty);
6303 if ($nbaccountfound > 0) {
6304 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6308 $langs->load(
'banks');
6311 require_once DOL_DOCUMENT_ROOT .
'/compta/bank/class/account.class.php';
6312 $bankstatic =
new Account($this->db);
6313 $result = $bankstatic->fetch((
int) $selected);
6315 print $bankstatic->getNomUrl(1);
6334 public function formRib($page, $selected =
'', $htmlname =
'ribcompanyid', $filtre =
'', $addempty = 0, $showibanbic = 0)
6337 if ($htmlname !=
"none") {
6338 print
'<form method="POST" action="' . $page .
'">';
6339 print
'<input type="hidden" name="action" value="setbankaccountcustomer">';
6340 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6341 $nbaccountfound = $this->
selectRib($selected, $htmlname, $filtre, $addempty,
'', $showibanbic);
6342 if ($nbaccountfound > 0) {
6343 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6347 $langs->load(
'banks');
6350 require_once DOL_DOCUMENT_ROOT .
'/societe/class/companybankaccount.class.php';
6352 $result = $bankstatic->fetch((
int) $selected);
6354 print $bankstatic->label;
6356 print
' (' . $bankstatic->iban .
'/' .$bankstatic->bic.
')';
6382 $arrayselected = array();
6384 $arrayselected =
GETPOST($htmlname,
'array:int');
6387 $cats =
$c->containing(
$object->id, $categtype);
6388 $arrayselected = array();
6389 foreach ($cats as $cat) {
6390 $arrayselected[] = $cat->id;
6394 $out .=
img_picto(
'',
'category',
'class="pictofixedwidth"');
6395 $out .= $this->
multiselectarray($htmlname, $cate_arbo, $arrayselected, 0, 0,
'minwidth100 widthcentpercentminusxx', 0, 0);
6399 $jsonclose =
'doJsCodeAfterPopupClose'.dol_sanitizeKeyCode($htmlname).
'()';
6400 $urltoopen =
'/categories/categorie_list.php?type='.urlencode($categtype).
'&nosearch=1';
6405 $out .=
'<!-- Add js code to open the popup for category/edit/add -->'.
"\n";
6406 $out .=
'<script>function doJsCodeAfterPopupClose'.dol_sanitizeKeyCode($htmlname).
'() {
6407 console.log("doJsCodeAfterPopupClose'.
dol_sanitizeKeyCode($htmlname).
' has been called, we refresh the combo content + refresh select2...");
6409 // Call an ajax to reload values and update the select
6412 url: \''.DOL_URL_ROOT.
'/core/ajax/fetchCategories.php\',
6414 action: \'getCategories\',
6419 success: function (data) {
6420 var $select = $(\'#'.dol_sanitizeKeyCode($htmlname).
'\');
6421 var selectedValues = $select.val();
6422 console.log(selectedValues);
6424 $.each(data,
function (index, item) {
6425 $select.append(\
'<option value="\' + item.id + \'" data-html="\' + item.htmlforattribute + \'">\' + item.htmlforoption + \'</option>\');
6427 $select.val(selectedValues);
6429 error: function (xhr, status, error) {
6430 console.log("Error when loading ajax page : " + error);
6434 // Refresh select2 to take account of new values (enough for small change)
6437 // Alternative if change in select is complex
6469 public function select_all_categories($type, $selected =
'', $htmlname =
"parent", $maxlength = 64, $fromid = 0, $outputmode = 0, $include = 0, $morecss =
'', $useempty = 1)
6474 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
6478 if (is_numeric($type)) {
6479 $type = array_search($type, $cat->MAP_ID);
6482 $cate_arbo = $cat->get_full_arbo($type, $fromid, $include);
6484 $outarray = array();
6485 $outarrayrichhtml = array();
6488 $output =
'<select class="flat minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
6490 if (is_array($cate_arbo)) {
6491 $num = count($cate_arbo);
6494 $langs->load(
"categories");
6495 $output .=
'<option value="-1" disabled>' . $langs->trans(
"NoCategoriesDefined") .
'</option>';
6497 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
6498 $output .=
'<option value="-1"> </option>';
6500 foreach ($cate_arbo as $key => $value) {
6501 if ($cate_arbo[$key][
'id'] == $selected || ($selected ===
'auto' && count($cate_arbo) == 1)) {
6507 $labeltoshow =
img_picto(
'',
'category',
'class="pictofixedwidth"'.(empty($cate_arbo[$key][
'color']) ?
'' :
' style="color: #' . $cate_arbo[$key][
'color'] .
'"'));
6508 $labeltoshow .=
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle');
6510 $outarray[$cate_arbo[$key][
'id']] = $cate_arbo[$key][
'fulllabel'];
6512 $outarrayrichhtml[$cate_arbo[$key][
'id']] = $labeltoshow;
6514 $output .=
'<option ' . $add .
'value="' . $cate_arbo[$key][
'id'] .
'"';
6523 $output .=
'</option>';
6525 $cate_arbo[$key][
'data-html'] = $labeltoshow;
6529 $output .=
'</select>';
6534 if ($outputmode == 2) {
6537 } elseif ($outputmode == 1) {
6539 } elseif ($outputmode == 3) {
6540 return $outarrayrichhtml;
6560 $html =
'<details class="dolibarr-help-block" style="margin-top:8px;">';
6561 $html .=
'<summary style="cursor:pointer; color:#0056b3; font-weight:normal; list-style:none; font-size:0.9em; display:flex; align-items:center;">';
6562 $html .=
'<span class="fa ' . $icon .
'" style="margin-right:6px;"></span>';
6563 $html .= $langs->trans(
"Help");
6564 $html .=
'</summary>';
6565 $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;">';
6568 $html .=
'</details>';
6593 public function form_confirm($page, $title, $question, $action, $formquestion = array(), $selectedchoice =
"", $useajax = 0, $height = 170, $width = 500)
6596 dol_syslog(__METHOD__ .
': using form_confirm is deprecated. Use formconfim instead.', LOG_WARNING);
6597 print $this->
formconfirm($page, $title, $question, $action, $formquestion, $selectedchoice, $useajax, $height, $width);
6629 public function formconfirm($page, $title, $question, $action, $formquestion =
'', $selectedchoice =
'', $useajax = 0, $height = 0, $width = 600, $disableformtag = 0, $labelbuttonyes =
'Yes', $labelbuttonno =
'No', $helpContent =
'')
6631 global $langs,
$conf;
6634 $formconfirm =
'<!-- formconfirm - before call, page=' .
dol_escape_htmltag($page) .
' -->';
6640 $newselectedchoice = empty($selectedchoice) ?
"no" : $selectedchoice;
6641 if (
$conf->browser->layout ==
'phone') {
6646 if (empty($height)) {
6648 if (is_array($formquestion)) {
6649 $height += (count($formquestion) * 40);
6656 if (is_array($formquestion) && !empty($formquestion)) {
6658 foreach ($formquestion as $key => $input) {
6659 if (is_array($input) && !empty($input)) {
6660 if ($input[
'type'] ==
'hidden') {
6661 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
6662 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
6670 $moreonecolumn =
'';
6671 $more .=
'<div class="tagtable paddingtopbottomonly centpercent noborderspacing">' .
"\n";
6672 foreach ($formquestion as $key => $input) {
6673 if (is_array($input) && !empty($input)) {
6674 $size = (!empty($input[
'size']) ?
' size="' . $input[
'size'] .
'"' :
'');
6675 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
6676 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
6678 if ($input[
'type'] ==
'text' || $input[
'type'] ==
'input') {
6679 $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";
6680 } elseif ($input[
'type'] ==
'password') {
6681 $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";
6682 } elseif ($input[
'type'] ==
'textarea') {
6683 $moreonecolumn .=
'<div class="margintoponly">';
6684 $moreonecolumn .= $input[
'label'] .
'<br>';
6686 $moreonecolumn .= $input[
'value'];
6687 $moreonecolumn .=
'</textarea>';
6688 $moreonecolumn .=
'</div>';
6689 } elseif (in_array($input[
'type'], [
'select',
'multiselect'])) {
6690 if (empty($morecss)) {
6691 $morecss =
'minwidth100';
6694 $show_empty = isset($input[
'select_show_empty']) ? $input[
'select_show_empty'] : 1;
6695 $key_in_label = isset($input[
'select_key_in_label']) ? $input[
'select_key_in_label'] : 0;
6696 $value_as_key = isset($input[
'select_value_as_key']) ? $input[
'select_value_as_key'] : 0;
6697 $translate = isset($input[
'select_translate']) ? $input[
'select_translate'] : 0;
6698 $maxlen = isset($input[
'select_maxlen']) ? $input[
'select_maxlen'] : 0;
6699 $disabled = isset($input[
'select_disabled']) ? $input[
'select_disabled'] : 0;
6700 $sort = isset($input[
'select_sort']) ? $input[
'select_sort'] :
'';
6702 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">';
6703 if (!empty($input[
'label'])) {
6704 $more .= $input[
'label'] .
'</div><div class="tagtd left">';
6706 if ($input[
'type'] ==
'select') {
6707 $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);
6709 $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);
6711 $more .=
'</div></div>' .
"\n";
6712 } elseif ($input[
'type'] ==
'checkbox') {
6713 $more .=
'<div class="tagtr">';
6714 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'"><label for="' .
dol_escape_htmltag($input[
'name']) .
'">' . $input[
'label'] .
'</label></div><div class="tagtd">';
6715 $more .=
'<input type="checkbox" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' .
dol_escape_htmltag($input[
'name']) .
'" name="' .
dol_escape_htmltag($input[
'name']) .
'"' . $moreattr;
6716 if (!is_bool($input[
'value']) && $input[
'value'] !=
'false' && $input[
'value'] !=
'0' && $input[
'value'] !=
'') {
6717 $more .=
' checked';
6719 if (is_bool($input[
'value']) && $input[
'value']) {
6720 $more .=
' checked';
6722 if (isset($input[
'disabled'])) {
6723 $more .=
' disabled';
6725 $more .=
' /></div>';
6726 $more .=
'</div>' .
"\n";
6727 } elseif ($input[
'type'] ==
'radio') {
6729 foreach ($input[
'values'] as $selkey => $selval) {
6730 $more .=
'<div class="tagtr">';
6731 if (isset($input[
'label'])) {
6733 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
' tdtop' : (
' tdtop ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
6735 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' "' . $input[
'tdclass'])) .
'"> </div>';
6738 $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;
6739 if (!empty($input[
'disabled'])) {
6740 $more .=
' disabled';
6742 if (isset($input[
'default']) && $input[
'default'] === $selkey) {
6743 $more .=
' checked="checked"';
6746 $more .=
'<label for="' .
dol_escape_htmltag($input[
'name'] . $selkey) .
'" class="valignmiddle">' . $selval .
'</label>';
6747 $more .=
'</div></div>' .
"\n";
6750 } elseif ($input[
'type'] ==
'date' || $input[
'type'] ==
'datetime') {
6751 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
6752 $more .=
'<div class="tagtd">';
6753 $addnowlink = (empty($input[
'datenow']) ? 0 : 1);
6755 if ($input[
'type'] ==
'datetime') {
6756 $h = isset($input[
'hours']) ? $input[
'hours'] : 1;
6757 $m = isset($input[
'minutes']) ? $input[
'minutes'] : 1;
6759 $more .= $this->
selectDate(isset($input[
'value']) ? $input[
'value'] : -1, $input[
'name'], $h, $m, 0,
'', 1, $addnowlink);
6760 $more .=
'</div></div>'.
"\n";
6761 $formquestion[] = array(
'name' => $input[
'name'].
'day');
6762 $formquestion[] = array(
'name' => $input[
'name'].
'month');
6763 $formquestion[] = array(
'name' => $input[
'name'].
'year');
6764 $formquestion[] = array(
'name' => $input[
'name'].
'hour');
6765 $formquestion[] = array(
'name' => $input[
'name'].
'min');
6766 } elseif ($input[
'type'] ==
'other') {
6767 $more .=
'<div class="tagtr"><div class="tagtd'.(empty($input[
'tdclass']) ?
'' : (
' '.$input[
'tdclass'])).
'">';
6768 if (!empty($input[
'label'])) {
6769 $more .= $input[
'label'] .
'</div><div class="tagtd">';
6771 if (!empty($input[
'value'])) {
6772 $more .= $input[
'value'];
6774 $more .=
'</div></div>' .
"\n";
6775 } elseif ($input[
'type'] ==
'onecolumn') {
6776 $moreonecolumn .=
'<div class="margintoponly">';
6777 $moreonecolumn .= $input[
'value'];
6778 $moreonecolumn .=
'</div>' .
"\n";
6779 } elseif ($input[
'type'] ==
'hidden') {
6781 } elseif ($input[
'type'] ==
'separator') {
6784 $more .=
'Error type ' . $input[
'type'] .
' for the confirm box is not a supported type';
6788 $more .=
'</div>' .
"\n";
6789 $more .= $moreonecolumn;
6795 if (!empty(
$conf->dol_use_jmobile)) {
6798 if (empty(
$conf->use_javascript_ajax)) {
6804 $dialogconfirm =
'dialog-confirm';
6806 if (!is_numeric($useajax)) {
6810 $dialogconfirm .=
'-' . $button;
6812 $pageyes = $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=yes';
6813 $pageno = ($useajax == 2 ? $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=no' :
'');
6816 if (is_array($formquestion)) {
6817 foreach ($formquestion as $key => $input) {
6820 if (is_array($input) && isset($input[
'name'])) {
6821 if (strpos($input[
'name'],
',') > 0) {
6822 $inputok = array_merge($inputok, explode(
',', $input[
'name']));
6824 array_push($inputok, $input[
'name']);
6829 if (is_array($input) && isset($input[
'inputko']) && $input[
'inputko'] == 1 && isset($input[
'name'])) {
6830 array_push($inputko, $input[
'name']);
6837 $formconfirm .=
'<div id="' . $dialogconfirm .
'" title="' .
dol_escape_htmltag($title) .
'" style="display: none;">';
6838 $formconfirm .=
'<div style="display: flex; flex-direction: column; height: 100%;">';
6839 if (is_array($formquestion) && array_key_exists(
'text', $formquestion) && !empty($formquestion[
'text'])) {
6840 $formconfirm .=
'<div class="confirmtext">' . $formquestion[
'text'] .
'</div>' .
"\n";
6842 if (!empty($more)) {
6843 $formconfirm .=
'<div class="confirmquestions">' . $more .
'</div>' .
"\n";
6846 if (!empty($helpContent)) {
6847 $formconfirm .=
'<div style="text-align:left; margin-top:12px; padding-top:8px; border-top:1px solid #eee; clear:both;">';
6849 $formconfirm .=
'</div>';
6851 if (!empty($question)) {
6852 $formconfirm .=
'<div class="confirmmessage" style="padding-top: 15px;">';
6853 $formconfirm .=
img_help(0,
'') .
' ' . $question;
6854 $formconfirm .=
'</div>';
6856 $formconfirm .=
'</div>';
6857 $formconfirm .=
'</div>' .
"\n";
6859 $formconfirm .=
"\n<!-- begin code of popup for formconfirm page=" . $page .
" -->\n";
6860 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
6861 $formconfirm .=
"/* Code for the jQuery('#dialogforpopup').dialog() */\n";
6862 $formconfirm .=
'jQuery(document).ready(function() {
6864 $( "#' . $dialogconfirm .
'" ).dialog({
6865 autoOpen: ' . ($autoOpen ?
"true" :
"false") .
',';
6866 if ($newselectedchoice ==
'no') {
6869 $(this).parent().find("button.ui-button:eq(2)").focus();
6874 if ($useajax == 1) {
6875 $jsforcursor =
'// The call to urljump can be slow, so we set the wait cursor' .
"\n";
6876 $jsforcursor .=
'jQuery("html,body,#id-container").addClass("cursorwait");' .
"\n";
6879 $postconfirmas =
'GET';
6886 closeOnEscape:
false,
6888 "' . dol_escape_js($langs->transnoentities($labelbuttonyes)) . '":
function() {
6889 var options =
"token=' . urlencode(newToken()) . '";
6890 var inputok =
' . json_encode($inputok) . ';
6891 var page = \
'' .
dol_escape_js(!empty($page) ? $page :
'') .
'\';
6892 var pageyes = \
'' .
dol_escape_js(!empty($pageyes) ? $pageyes :
'') .
'\';
6894 if (inputok.length > 0) {
6895 $.each(inputok,
function(i, inputname) {
6898 if ($(
"input[name=\'" + inputname +
"\']").attr(
"type") ==
"radio") {
6899 inputvalue = $(
"input[name=\'" + inputname +
"\']:checked").val();
6901 if ($(
"#" + inputname).attr(
"type") ==
"checkbox") { more =
":checked"; }
6902 inputvalue = $(
"#" + inputname + more).val();
6904 if (typeof inputvalue ==
"undefined") { inputvalue=
""; }
6905 console.log(
"formconfirm check inputname="+inputname+
" inputvalue="+inputvalue);
6906 options +=
"&" + inputname +
"=" + encodeURIComponent(inputvalue);
6909 var urljump = pageyes + (pageyes.indexOf(
"?") < 0 ?
"?" :
"&") + options;
6910 if (pageyes.length > 0) {
';
6911 if ($postconfirmas == 'GET
') {
6912 $formconfirm .= 'location.href = urljump;
';
6914 $formconfirm .= $jsforcursor;
6915 $formconfirm .= 'var post = $.post(
6918 function(data) { $(
"body").html(data); jQuery(
"html,body,#id-container").removeClass(
"cursorwait"); }
6922 console.log(
"after post ok");
6924 $(
this).dialog(
"close");
6926 "' . dol_escape_js($langs->transnoentities($labelbuttonno)) . '":
function() {
6927 var options =
"token=' . urlencode(newToken()) . '";
6928 var inputko =
' . json_encode($inputko) . ';
6929 var page =
"' . dol_escape_js(!empty($page) ? $page : '') . '";
6930 var pageno=
"' . dol_escape_js(!empty($pageno) ? $pageno : '') . '";
6931 if (inputko.length > 0) {
6932 $.each(inputko,
function(i, inputname) {
6934 if ($(
"#" + inputname).attr(
"type") ==
"checkbox") { more =
":checked"; }
6935 var inputvalue = $(
"#" + inputname + more).val();
6936 if (typeof inputvalue ==
"undefined") { inputvalue=
""; }
6937 options +=
"&" + inputname +
"=" + encodeURIComponent(inputvalue);
6940 var urljump=pageno + (pageno.indexOf(
"?") < 0 ?
"?" :
"&") + options;
6942 if (pageno.length > 0) {
';
6943 if ($postconfirmas == 'GET
') {
6944 $formconfirm .= 'location.href = urljump;
';
6946 $formconfirm .= $jsforcursor;
6947 $formconfirm .= 'var post = $.post(
6950 function(data) { $(
"body").html(data); jQuery(
"html,body,#id-container").removeClass(
"cursorwait"); }
6954 console.log(
"after post ko");
6956 $(
this).dialog(
"close");
6962 var
button =
"' . $button . '";
6964 $(
"#" +
button ).click(
function() {
6965 $(
"#' . $dialogconfirm . '").dialog(
"open");
6971 $formconfirm .= "<!-- end ajax formconfirm -->\n";
6973 $formconfirm .= "\n<!-- begin formconfirm page=" . dol_escape_htmltag($page) . " -->\n";
6975 if (empty($disableformtag)) {
6976 $formconfirm .= '<form method=
"POST" action=
"' . $page . '" class=
"notoptoleftnoright">
' . "\n";
6979 $formconfirm .= '<input
type=
"hidden" name=
"action" value=
"' . $action . '">
' . "\n";
6980 $formconfirm .= '<input
type=
"hidden" name=
"token" value=
"' . newToken() . '">
' . "\n";
6982 $formconfirm .= '<div
class=
"valid">
' . "\n";
6985 $formconfirm .= '<div
class=
"validtitre">
';
6986 $formconfirm .= img_picto('', 'pictoconfirm
') . ' ' . $title;
6987 $formconfirm .= '</div>
' . "\n";
6990 if (is_array($formquestion) && array_key_exists('text
', $formquestion) && !empty($formquestion['text
'])) {
6991 $formconfirm .= '<div
class=
"valid">
' . $formquestion['text
'] . '</div>
' . "\n";
6996 $formconfirm .= '<div>
' . "\n";
6997 $formconfirm .= $more;
6998 $formconfirm .= '</div>
' . "\n";
7001 // NEW: Help block row (between form fields and question)
7002 if (!empty($helpContent)) {
7003 $formconfirm .= '<div style=
"padding-top:8px; border-top:1px solid #888;">
';
7004 $formconfirm .= $this->getHelpBlock($helpContent);
7005 $formconfirm .= '</div>
' . "\n";
7008 // Let's add a row that acts as a spacer.
7009 $formconfirm .=
'<div style="padding-top: 20px;"></div>' .
"\n";
7012 $formconfirm .=
'<div class="inline-block">' . $question .
'</div>';
7014 $formconfirm .=
'<div class="inline-block">';
7015 $formconfirm .= $this->selectyesno(
"confirm", $newselectedchoice, 0,
false, 0, 0,
'marginleftonly marginrightonly', $labelbuttonyes, $labelbuttonno);
7016 $formconfirm .=
'<input class="button valignmiddle confirmvalidatebutton small" type="submit" value="' . $langs->trans(
"Validate") .
'">';
7017 $formconfirm .=
'</div>';
7019 $formconfirm .=
'</div>';
7021 if (empty($disableformtag)) {
7022 $formconfirm .=
"</form>\n";
7024 $formconfirm .=
'<br>';
7026 if (!empty(
$conf->use_javascript_ajax)) {
7027 $formconfirm .=
'<!-- code to disable button to avoid double clic -->';
7028 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
7030 $(document).ready(function () {
7031 $(".confirmvalidatebutton").on("click", function() {
7032 console.log("We click on button confirmvalidatebutton");
7033 $(this).attr("disabled", "disabled");
7034 setTimeout(\'$(".confirmvalidatebutton").removeAttr("disabled")\', 3000);
7035 //console.log($(this).closest("form"));
7036 $(this).closest("form").submit();
7040 $formconfirm .=
'</script>' .
"\n";
7043 $formconfirm .=
"<!-- end formconfirm -->\n";
7046 return $formconfirm;
7067 public function form_project($page, $socid, $selected =
'', $htmlname =
'projectid', $discard_closed = 0, $maxlength = 20, $forcefocus = 0, $nooutput = 0, $textifnoproject =
'', $morecss =
'', $option =
'')
7072 require_once DOL_DOCUMENT_ROOT .
'/core/lib/project.lib.php';
7073 require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formprojet.class.php';
7079 $langs->load(
"project");
7080 if ($htmlname !=
"none") {
7081 $out .=
'<form method="post" action="' . $page .
'">';
7082 $out .=
'<input type="hidden" name="action" value="classin">';
7083 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7084 $out .= $formproject->select_projects($socid, $selected, $htmlname, $maxlength, 0, 1, $discard_closed, $forcefocus, 0, 0,
'', 1, 0, $morecss);
7085 $out .=
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7088 $out .=
'<span class="project_head_block">';
7089 if ($selected instanceof
Project) {
7090 $out .= $selected->getNomUrl(0, $option, 1);
7091 } elseif (is_numeric($selected)) {
7092 $projet =
new Project($this->db);
7093 $projet->fetch((
int) $selected);
7094 $out .= $projet->getNomUrl(0, $option, 1);
7096 $out .=
'<span class="opacitymedium">' . $textifnoproject .
'</span>';
7101 if (empty($nooutput)) {
7125 public function form_conditions_reglement($page, $selected =
'', $htmlname =
'cond_reglement_id', $addempty = 0, $type =
'', $filtertype = -1, $deposit_percent = -1, $nooutput = 0)
7130 $selected = (int) $selected;
7134 if ($htmlname !=
"none") {
7135 $out .=
'<form method="POST" action="' . $page .
'">';
7136 $out .=
'<input type="hidden" name="action" value="setconditions">';
7137 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7139 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
7141 $out .= $this->getSelectConditionsPaiements($selected, $htmlname, $filtertype, $addempty, 0,
'', $deposit_percent);
7142 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7146 $this->load_cache_conditions_paiements();
7148 if (isset($this->cache_conditions_paiements[$selected])) {
7149 $label = $this->cache_conditions_paiements[$selected][
'label'];
7151 if (!empty($this->cache_conditions_paiements[$selected][
'deposit_percent'])) {
7152 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $this->cache_conditions_paiements[$selected][
'deposit_percent'], $label);
7157 $langs->load(
'errors');
7158 $out .= $langs->trans(
'ErrorNotInDictionaryPaymentConditions');
7165 if (empty($nooutput)) {
7191 if ($htmlname !=
'none') {
7192 $out .=
'<form method="POST" action="' . $page .
'">';
7193 $out .=
'<input type="hidden" name="action" value="setruleforlinesdates">';
7194 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7195 $out .= $this->getSelectRuleForLinesDates($selected, $htmlname, $addempty);
7196 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7199 if (isset($selected)) {
7200 $this->load_cache_rule_for_lines_dates();
7201 if (isset($this->cache_rule_for_lines_dates[$selected])) {
7202 $label = $this->cache_rule_for_lines_dates[$selected];
7203 $out .= $langs->trans($label);
7210 if (empty($nooutput)) {
7234 if ($htmlname !=
"none") {
7235 print
'<form method="post" action="' . $page .
'">';
7236 print
'<input type="hidden" name="action" value="setavailability">';
7237 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7238 print $this->selectAvailabilityDelay($selected, $htmlname,
'', $addempty,
'', 1);
7239 print
'<input type="submit" name="modify" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7240 print
'<input type="submit" name="cancel" class="button smallpaddingimp" value="' . $langs->trans(
"Cancel") .
'">';
7244 $this->load_cache_availability();
7246 if (isset($this->cache_availability[$selected])) {
7247 print $this->cache_availability[$selected][
'label'];
7268 public function formInputReason($page, $selected =
'', $htmlname =
'demandreason', $addempty = 0, $morecss =
'')
7271 if ($htmlname !=
"none") {
7272 print
'<form method="post" action="' . $page .
'">';
7273 print
'<input type="hidden" name="action" value="setdemandreason">';
7274 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7275 $this->selectInputReason($selected, $htmlname,
'-1', $addempty, $morecss);
7276 print
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
7280 $this->loadCacheInputReason();
7281 foreach ($this->cache_demand_reason as $key => $val) {
7282 if ($val[
'id'] == $selected) {
7283 print $val[
'label'];
7308 public function form_date($page, $selected, $htmlname, $displayhour = 0, $displaymin = 0, $nooutput = 0, $type =
'')
7315 if ($htmlname !=
"none") {
7316 $ret .=
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
7317 $ret .=
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
7318 $ret .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7320 $ret .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
7322 $ret .=
'<table class="nobordernopadding">';
7324 $ret .= $this->selectDate($selected, $htmlname, $displayhour, $displaymin, 1,
'form' . $htmlname, 1, 0);
7326 $ret .=
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
7327 $ret .=
'</tr></table></form>';
7336 if (empty($nooutput)) {
7355 public function form_users($page, $selected =
'', $htmlname =
'userid', $exclude = array(), $include = array())
7360 if ($htmlname !=
"none") {
7361 print
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
7362 print
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
7363 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7364 print $this->select_dolusers($selected, $htmlname, 1, $exclude, 0, $include);
7365 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7369 require_once DOL_DOCUMENT_ROOT .
'/user/class/user.class.php';
7370 $theuser =
new User($this->db);
7371 $theuser->fetch((
int) $selected);
7372 print $theuser->getNomUrl(1);
7395 public function form_modes_reglement($page, $selected =
'', $htmlname =
'mode_reglement_id', $filtertype =
'', $active = 1, $addempty = 0, $type =
'', $nooutput = 0)
7401 if ($htmlname !=
"none") {
7402 $out .=
'<form method="POST" action="' . $page .
'">';
7403 $out .=
'<input type="hidden" name="action" value="setmode">';
7404 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7406 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
7408 $out .= $this->select_types_paiements($selected, $htmlname, $filtertype, 0, $addempty, 0, 0, $active,
'', 1);
7409 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7413 $this->load_cache_types_paiements();
7414 $out .= $this->cache_types_paiements[$selected][
'label'];
7441 if ($htmlname !=
"none") {
7442 print
'<form method="POST" action="' . $page .
'">';
7443 print
'<input type="hidden" name="action" value="settransportmode">';
7444 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7445 $this->selectTransportMode($selected, $htmlname, 0, $addempty, 0, 0, $active);
7446 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7450 $this->load_cache_transport_mode();
7451 print $this->cache_transport_mode[$selected][
'label'];
7472 if ($htmlname !=
"none") {
7473 print
'<form method="POST" action="' . $page .
'">';
7474 print
'<input type="hidden" name="action" value="setmulticurrencycode">';
7475 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7476 print $this->selectMultiCurrency($selected, $htmlname, 0);
7477 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7480 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
7481 print !empty($selected) ?
currency_name($selected, 1) :
' ';
7500 global $langs,
$conf;
7502 if ($htmlname !=
"none") {
7503 print
'<form method="POST" action="' . $page .
'">';
7504 print
'<input type="hidden" name="action" value="setmulticurrencyrate">';
7505 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7506 print
'<input type="text" class="maxwidth75" name="' . $htmlname .
'" value="' . (!empty($rate) ?
price(
price2num($rate,
'CU')) : 1) .
'" spellcheck="false" /> ';
7507 print
'<select name="calculation_mode" id="calculation_mode">';
7508 print
'<option value="1">Change ' . $langs->trans(
"PriceUHT") .
' of lines</option>';
7509 print
'<option value="2">Change ' . $langs->trans(
"PriceUHTCurrency") .
' of lines</option>';
7512 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7515 if (!empty($rate)) {
7516 print
price($rate, 1, $langs, 0, 0);
7517 if ($currency && $rate != 1) {
7524 print
' <span class="opacitymedium">(' .
price($rate_direct, 1, $langs, 0, 0) .
' ' .
$conf->currency .
' = 1 ' . $currency .
')</span>';
7526 print
' <span class="opacitymedium">(' .
price($rate, 1, $langs, 0, 0) .
' ' . $currency .
' = 1 ' .
$conf->currency .
')</span>';
7554 public function form_remise_dispo($page, $selected, $htmlname, $socid, $amount, $filter =
'', $maxvalue = 0, $more =
'', $hidelist = 0, $discount_type = 0, $filterabsolutediscount = 0, $filtercreditnote = 0)
7557 global
$conf, $langs;
7559 if ($htmlname !=
"none") {
7560 print
'<form method="post" action="' . $page .
'" class="inline-block">';
7561 print
'<input type="hidden" name="action" value="setabsolutediscount">';
7562 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7563 print
'<div class="inline-block">';
7564 if (!empty($discount_type)) {
7566 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL") {
7567 $translationKey =
'HasAbsoluteDiscountFromSupplier';
7569 $translationKey =
'HasCreditNoteFromSupplier';
7572 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
7573 $translationKey =
'HasAbsoluteDiscountFromSupplier';
7575 $translationKey =
'HasCreditNoteFromSupplier';
7580 if (!$filter || $filter ==
"fk_facture_source IS NULL") {
7581 $translationKey =
'CompanyHasAbsoluteDiscount';
7583 $translationKey =
'CompanyHasCreditNote';
7586 if (!$filter || $filter ==
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
7587 $translationKey =
'CompanyHasAbsoluteDiscount';
7589 $translationKey =
'CompanyHasCreditNote';
7593 print $langs->trans($translationKey,
price($amount, 0, $langs, 0, 0, -1,
$conf->currency));
7594 if (empty($hidelist)) {
7598 if (empty($hidelist)) {
7599 print
'<div class="inline-block" style="padding-right: 10px">';
7600 $newfilter =
'discount_type = ' . intval($discount_type);
7601 if (!empty($discount_type)) {
7602 $newfilter .=
' AND fk_invoice_supplier IS NULL AND fk_invoice_supplier_line IS NULL';
7604 $newfilter .=
' AND fk_facture IS NULL AND fk_facture_line IS NULL';
7607 $sanitizedfilter = $filter;
7608 $newfilter .=
' AND (' . $sanitizedfilter .
')';
7611 $nbqualifiedlines = $this->select_remises((
string) $selected, $htmlname, $newfilter, $socid, $maxvalue);
7612 if ($nbqualifiedlines > 0) {
7613 print
' <input type="submit" class="button smallpaddingimp" value="' .
dol_escape_htmltag($langs->trans(
"UseLine")) .
'"';
7614 if (!empty($discount_type) && $filter && $filter !=
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
7615 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
7617 if (empty($discount_type) && $filter && $filter !=
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
7618 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
7626 print
'<div class="inline-block">';
7652 public function form_contacts($page, $societe, $selected =
'', $htmlname =
'contactid')
7657 if ($htmlname !=
"none") {
7658 print
'<form method="post" action="' . $page .
'">';
7659 print
'<input type="hidden" name="action" value="set_contact">';
7660 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7661 print
'<table class="nobordernopadding">';
7663 print $this->selectcontacts($societe->id, $selected, $htmlname);
7666 $addcontact = (
getDolGlobalString(
'SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans(
"AddContact") : $langs->trans(
"AddContactAddress"));
7667 print
'<a href="' . DOL_URL_ROOT .
'/contact/card.php?socid=' . $societe->id .
'&action=create&backtoreferer=1">' . $addcontact .
'</a>';
7670 print
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
7671 print
'</tr></table></form>';
7674 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
7675 $contact =
new Contact($this->db);
7676 $contact->fetch((
int) $selected);
7677 print $contact->getFullName($langs);
7702 public function form_thirdparty($page, $selected =
'', $htmlname =
'socid', $filter =
'', $showempty = 0, $showtype = 0, $forcecombo = 0, $events = array(), $nooutput = 0, $excludeids = array(), $textifnothirdparty =
'')
7708 if ($htmlname !=
"none") {
7711 $out .=
'<form method="post" action="' . $page .
'">';
7712 $out .=
'<input type="hidden" name="action" value="set_thirdparty">';
7713 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7714 $out .= $this->select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, $limit,
'minwidth100',
'',
'', 1, array(),
false, $excludeids);
7715 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7719 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
7720 $soc =
new Societe($this->db);
7721 $soc->fetch((
int) $selected);
7722 $out .= $soc->getNomUrl(0,
'');
7724 $out .=
'<span class="opacitymedium">' . $textifnothirdparty .
'</span>';
7750 print $this->selectCurrency($selected, $htmlname);
7762 public function selectCurrency($selected =
'', $htmlname =
'currency_id', $mode = 0, $useempty =
'')
7764 global $langs, $user;
7766 $langs->loadCacheCurrencies(
'');
7770 if ($selected ==
'euro' || $selected ==
'euros') {
7774 $out .=
'<select class="flat maxwidth200onsmartphone minwidth300" name="' . $htmlname .
'" id="' . $htmlname .
'">';
7776 $out .=
'<option value="-1" selected></option>';
7778 foreach ($langs->cache_currencies as $code_iso => $currency) {
7779 $labeltoshow = $currency[
'label'];
7781 $labeltoshow .=
' <span class="opacitymedium">(' . $code_iso .
')</span>';
7782 } elseif ($mode == 2) {
7783 $labeltoshow .=
' <span class="opacitymedium">(' . $code_iso.
' - '.$langs->getCurrencySymbol($code_iso) .
')</span>';
7785 $labeltoshow .=
' <span class="opacitymedium">(' . $langs->getCurrencySymbol($code_iso) .
')</span>';
7788 if ($selected && $selected == $code_iso) {
7789 $out .=
'<option value="' . $code_iso .
'" selected data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
7791 $out .=
'<option value="' . $code_iso .
'" data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
7794 $out .=
'</option>';
7796 $out .=
'</select>';
7798 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
7802 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
7820 public function selectMultiCurrency($selected =
'', $htmlname =
'multicurrency_code', $useempty = 0, $filter =
'', $excludeConfCurrency =
false, $morecss =
'maxwidth200 widthcentpercentminusx')
7822 global
$conf, $langs;
7824 $langs->loadCacheCurrencies(
'');
7826 $TCurrency = array();
7828 $sql =
"SELECT code FROM " . $this->db->prefix() .
"multicurrency";
7829 $sql .=
" WHERE entity IN ('" .
getEntity(
'multicurrency') .
"')";
7833 $resql = $this->db->query($sql);
7835 while ($obj = $this->db->fetch_object($resql)) {
7836 $TCurrency[$obj->code] = $obj->code;
7841 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
7843 $out .=
'<option value=""> </option>';
7846 if (!in_array(
$conf->currency, $TCurrency) && !$excludeConfCurrency) {
7847 $TCurrency[
$conf->currency] =
$conf->currency;
7849 if (count($TCurrency) > 0) {
7850 foreach ($langs->cache_currencies as $code_iso => $currency) {
7851 if (isset($TCurrency[$code_iso])) {
7852 if (!empty($selected) && $selected == $code_iso) {
7853 $out .=
'<option value="' . $code_iso .
'" selected="selected">';
7855 $out .=
'<option value="' . $code_iso .
'">';
7858 $out .= $currency[
'label'];
7859 $out .=
' (' . $langs->getCurrencySymbol($code_iso) .
')';
7860 $out .=
'</option>';
7865 $out .=
'</select>';
7868 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
7885 global $langs, $user;
7887 $num = count($this->cache_vatrates);
7894 $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";
7895 $sql .=
" FROM ".$this->db->prefix().
"c_tva as t, ".$this->db->prefix().
"c_country as c";
7896 $sql .=
" WHERE t.fk_pays = c.rowid";
7897 $sql .=
" AND t.active > 0";
7898 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
7899 $sql .=
" AND c.code IN (" . $this->db->sanitize($country_code, 1) .
")";
7900 $sql .=
" ORDER BY t.code ASC, t.taux ASC, t.recuperableonly ASC";
7902 $resql = $this->db->query($sql);
7904 $num = $this->db->num_rows($resql);
7906 for ($i = 0; $i < $num; $i++) {
7907 $obj = $this->db->fetch_object($resql);
7909 $tmparray = array();
7910 $tmparray[
'rowid'] = (int) $obj->rowid;
7911 $tmparray[
'type_vat'] = ($obj->type_vat <= 0 ? 0 : $obj->type_vat);
7912 $tmparray[
'code'] = $obj->code;
7913 $tmparray[
'txtva'] = $obj->taux;
7914 $tmparray[
'nprtva'] = $obj->recuperableonly;
7915 $tmparray[
'localtax1'] = $obj->localtax1;
7916 $tmparray[
'localtax1_type'] = $obj->localtax1_type;
7917 $tmparray[
'localtax2'] = $obj->localtax2;
7918 $tmparray[
'localtax2_type'] = $obj->localtax1_type;
7919 $tmparray[
'einvoice_vatex'] = $obj->einvoice_vatex;
7921 $tmparray[
'label'] = $obj->taux .
'%' . ($obj->code ?
' (' . $obj->code .
')' :
'');
7922 $tmparray[
'labelallrates'] = $obj->taux .
'/' . ($obj->localtax1 ? $obj->localtax1 :
'0') .
'/' . ($obj->localtax2 ? $obj->localtax2 :
'0') . ($obj->code ?
' (' . $obj->code .
')' :
'');
7923 $positiverates =
'';
7925 $positiverates .= ($positiverates ?
'/' :
'') . $obj->taux;
7927 if ($obj->localtax1) {
7928 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax1;
7930 if ($obj->localtax2) {
7931 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax2;
7933 if (empty($positiverates)) {
7934 $positiverates =
'0';
7936 $tmparray[
'labelpositiverates'] = $positiverates . ($obj->code ?
' (' . $obj->code .
')' :
'');
7938 $this->cache_vatrates[$obj->rowid] = $tmparray;
7943 $this->error =
'<span class="error">';
7944 $this->error .= $langs->trans(
"ErrorNoVATRateDefinedForSellerCountry", $country_code);
7946 if (!empty($user) && $user->admin && preg_match(
'/\'(..)\'/', $country_code, $reg)) {
7947 $langs->load(
"errors");
7948 $new_country_code = $reg[1];
7949 $country_id =
dol_getIdFromCode($this->db, $new_country_code,
'c_country',
'code',
'rowid');
7950 $this->error .=
'<br>'.$langs->trans(
"ErrorFixThisHere", DOL_URL_ROOT.
'/admin/dict.php?id=10'.($country_id > 0 ?
'&countryidforinsert='.$country_id :
''));
7952 $this->error .=
'</span>';
7956 $this->error =
'<span class="error">' . $this->db->error() .
'</span>';
7985 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)
7988 global $langs,
$mysoc, $hookmanager;
7990 $langs->load(
'errors');
7994 $hookmanager->initHooks(array(
'commonobject'));
7995 $info_bits == 1 ? $is_npr = 1 : $is_npr = 0;
7996 $parameters = array(
7997 'htmlname' => $htmlname,
7998 'selectedrate' => $selectedrate,
7999 'seller' => $societe_vendeuse,
8000 'buyer' => $societe_acheteuse,
8001 'idprod' => $idprod,
8002 'is_npr' => $is_npr,
8004 'options_only' => $options_only,
8006 'type_vat' => $type_vat
8008 $reshook = $hookmanager->executeHooks(
'load_tva', $parameters);
8010 return $hookmanager->resPrint;
8011 } elseif ($reshook === 0) {
8012 $return .= $hookmanager->resPrint;
8016 $defaultnpr = ($info_bits & 0x01);
8017 $defaultnpr = (preg_match(
'/\*/', $selectedrate) ? 1 : $defaultnpr);
8018 $defaulttx = str_replace(
'*',
'', $selectedrate);
8021 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
8022 $defaultcode = $reg[1];
8023 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
8028 if (is_object($societe_vendeuse) && !$societe_vendeuse->country_code) {
8029 if ($societe_vendeuse->id ==
$mysoc->id) {
8030 $return .=
'<span class="error">' . $langs->trans(
"ErrorYourCountryIsNotDefined") .
'</span>';
8032 $return .=
'<span class="error">' . $langs->trans(
"ErrorSupplierCountryIsNotDefined") .
'</span>';
8049 $sellercountrycode = is_object($societe_vendeuse) ? $societe_vendeuse->country_code :
$mysoc->country_code;
8050 $sellercountryid = is_object($societe_vendeuse) ? $societe_vendeuse->country_id :
$mysoc->country_id;
8051 if ((
int) $sellercountryid > 0 && strlen((
string) $sellercountrycode) != 2) {
8052 $tmpcountrycode =
dol_getIdFromCode($this->db, (
string) $sellercountryid,
'c_country',
'rowid',
'code');
8053 if (!empty($tmpcountrycode) && !is_numeric($tmpcountrycode)) {
8054 $sellercountrycode = $tmpcountrycode;
8057 $code_country =
"'" . $sellercountrycode .
"'";
8060 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
8064 if (is_object($societe_vendeuse) && is_object($societe_acheteuse) &&
isInEEC($societe_vendeuse) &&
isInEEC($societe_acheteuse) && !$societe_acheteuse->isACompany()) {
8066 if (is_numeric($type)) {
8068 switch ($selectVatComboMode) {
8070 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
8073 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
8077 } elseif (!$idprod) {
8078 switch ($selectVatComboMode) {
8080 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
8083 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
8087 $prodstatic =
new Product($this->db);
8088 $prodstatic->fetch($idprod);
8090 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
8097 $this->load_cache_vatrates($code_country);
8100 $arrayofvatrates = array();
8101 foreach ($this->cache_vatrates as $cachevalue) {
8102 if (empty($cachevalue[
'type_vat']) || $cachevalue[
'type_vat'] == $type_vat) {
8103 $arrayofvatrates[] = $cachevalue;
8107 $num = count($arrayofvatrates);
8110 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
8112 $tmpthirdparty =
new Societe($this->db);
8113 $tmpthirdparty->country_code =
$mysoc->country_code;
8115 $defaulttx =
get_default_tva(is_object($societe_vendeuse) ? $societe_vendeuse : $tmpthirdparty, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
8116 $defaultnpr =
get_default_npr(is_object($societe_vendeuse) ? $societe_vendeuse : $tmpthirdparty, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
8118 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
8119 $defaultcode = $reg[1];
8120 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
8122 if (empty($defaulttx)) {
8129 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
8132 $defaulttx = $arrayofvatrates[$num - 1][
'txtva'];
8139 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
8140 $defaultcode = $reg[1];
8141 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
8149 if (is_object($societe_vendeuse) && $societe_vendeuse->id ==
$mysoc->id && empty($societe_vendeuse->tva_assuj)) {
8159 if (!$options_only) {
8160 $return .=
'<select class="flat valignmiddle minwidth75imp maxwidth100 right" id="' . $htmlname .
'" name="' . $htmlname .
'"' . ($disabled ?
' disabled' :
'') . $title .
'>';
8163 $selectedfound =
false;
8164 foreach ($arrayofvatrates as $rate) {
8166 if ($disabled && $rate[
'txtva'] != 0) {
8171 $key = $rate[
'txtva'];
8172 $key .= $rate[
'nprtva'] ?
'*' :
'';
8173 if ($mode > 0 && $rate[
'code']) {
8174 $key .=
' (' . $rate[
'code'] .
')';
8177 $key = $rate[
'rowid'];
8180 $return .=
'<option value="' . $key .
'" data-vatid="'.$rate[
'rowid'].
'"';
8181 if (!$selectedfound) {
8183 if ($defaultcode == $rate[
'code']) {
8184 $return .=
' selected';
8185 $selectedfound =
true;
8187 } elseif ($rate[
'txtva'] == $defaulttx && $rate[
'nprtva'] == $defaultnpr) {
8188 $return .=
' selected';
8189 $selectedfound =
true;
8197 $return .= $rate[
'labelpositiverates'];
8200 $return .=
vatrate($rate[
'label']);
8204 $return .= (empty($rate[
'code']) && $rate[
'nprtva']) ?
' *' :
'';
8206 $return .=
'</option>';
8209 if (!$options_only) {
8210 $return .=
'</select>';
8214 $return .= $this->error;
8248 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 =
'')
8251 dol_syslog(__METHOD__ .
': using select_date is deprecated. Use selectDate instead.', LOG_WARNING);
8252 $retstring = $this->selectDate($set_time, $prefix, $h, $m, $empty, $form_name, $d, $addnowlink, $disabled, $fullday, $addplusone, $adddateof);
8253 if (!empty($nooutput)) {
8276 public function selectDateToDate($set_time =
'', $set_time_end =
'', $prefix =
're', $empty = 0, $forcenewline = 0)
8280 $ret = $this->selectDate($set_time, $prefix .
'_start', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"from"),
'tzuserrel');
8281 if ($forcenewline) {
8284 $ret .= $this->selectDate($set_time_end, $prefix .
'_end', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
8316 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 =
'')
8318 global
$conf, $langs;
8320 if ($gm ===
'auto') {
8321 $gm = (empty(
$conf) ?
'tzserver' :
$conf->tzuserinputkey);
8326 if ($prefix ==
'') {
8337 if ($stepminutes <= 0 || $stepminutes > 30) {
8348 $orig_set_time = $set_time;
8350 if ($set_time ===
'' && $emptydate == 0) {
8351 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
8352 if ($gm ==
'tzuser' || $gm ==
'tzuserrel') {
8364 if (!empty($set_time) && preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/', (
string) $set_time, $reg)) {
8366 $syear = (!empty($reg[1]) ? $reg[1] :
'');
8367 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
8368 $sday = (!empty($reg[3]) ? $reg[3] :
'');
8369 $shour = (!empty($reg[4]) ? $reg[4] :
'');
8370 $smin = (!empty($reg[5]) ? $reg[5] :
'');
8371 } elseif (strval($set_time) !=
'' && $set_time != -1) {
8376 if ($orig_set_time !=
'') {
8390 if ($h == 3 || $h == 4) {
8401 $usecalendar =
'combo';
8407 $usecalendar =
'html';
8412 if ($usecalendar !=
'combo') {
8414 $reduceformat = (!empty(
$conf->dol_optimize_smallscreen) ? 1 : 0);
8415 if ($reduceformat) {
8416 $format = str_replace(
'%Y',
'%y', $langs->transnoentitiesnoconv(
"FormatDateShortInput"));
8417 $formatjslong = $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput");
8418 $formatjs = str_replace(
'yyyy',
'yy', $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput"));
8419 $formatjquery = str_replace(
'yyyy',
'yy', $langs->trans(
"FormatDateShortJQueryInput"));
8421 $format = $langs->transnoentitiesnoconv(
"FormatDateShortInput");
8422 $formatjslong = $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput");
8423 $formatjs = $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput");
8424 $formatjquery = $langs->trans(
"FormatDateShortJQueryInput");
8428 $formatted_date =
'';
8429 if (strval($set_time) !=
'' && $set_time != -1) {
8434 if ($usecalendar ==
"eldy") {
8460 } elseif ($usecalendar ==
'jquery' || $usecalendar ==
'html') {
8461 if (!$disabled && $usecalendar !=
'html') {
8463 $minYear =
getDolGlobalInt(
'MIN_YEAR_SELECT_DATE', (idate(
'Y') - 100));
8464 $maxYear =
getDolGlobalInt(
'MAX_YEAR_SELECT_DATE', (idate(
'Y') + 100));
8466 $retstring .=
'<!-- datepicker usecalendar='.$usecalendar.
' --><script nonce="' .
getNonce() .
'" type="text/javascript">';
8467 $retstring .=
"$(function(){ $('#" . $prefix .
"').datepicker({
8470 todayHighlight: true,
8471 yearRange: '" . $minYear .
":" . $maxYear .
"',";
8472 if (!empty(
$conf->dol_use_jmobile)) {
8474 beforeShow: function (input, datePicker) {
8475 input.disabled = true;
8477 onClose: function (dateText, datePicker) {
8478 this.disabled = false;
8484 $buttonImage = $calendarpicto ?: DOL_URL_ROOT .
"/theme/" .
dol_escape_js(
$conf->theme) .
"/img/object_calendarday.png";
8486 showOn: 'button', /* both has problem with autocompletion */
8487 buttonImage: '" . $buttonImage .
"',
8488 buttonImageOnly: true";
8492 $retstring .=
"</script>";
8496 $retstring .=
'<div class="nowraponall inline-block divfordateinput">';
8497 $retstring .=
'<input id="'.$prefix.
'" name="'.$prefix.
'" type="'.($usecalendar ==
'html' ?
"date" :
"text").
'" class="maxwidthdate'.(
getDolUserString(
'MAIN_OPTIMIZEFORTEXTBROWSER') ?
' textbrowser' :
'').
' center" maxlength="11" value="'.$formatted_date.
'"';
8498 $retstring .= ($disabled ?
' disabled' :
'');
8499 $retstring .= ($placeholder ?
' placeholder="' .
dol_escape_htmltag($placeholder) .
'"' :
'');
8500 $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
8501 $retstring .= ' autocomplete="off
">';
8505 $retstringbutton = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
">' . img_object($langs->trans("Disabled
"), 'calendarday', 'class="datecallink ui-datepicker-notrigger
"') . '</button>';
8506 $retstring .= $retstringbutton;
8509 $retstring .= '</div>';
8510 $retstring .= '<input type="hidden
" id="' . $prefix . 'day
" name="' . $prefix . 'day
" value="' . $sday . '">' . "\n
";
8511 $retstring .= '<input type="hidden
" id="' . $prefix . 'month
" name="' . $prefix . 'month
" value="' . $smonth . '">' . "\n
";
8512 $retstring .= '<input type="hidden
" id="' . $prefix . 'year
" name="' . $prefix . 'year
" value="' . $syear . '">' . "\n
";
8514 $retstring .= "Bad value of MAIN_POPUP_CALENDAR
";
8517 // Show date with combo selects
8519 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50imp
" id="' . $prefix . 'day
" name="' . $prefix . 'day
">';
8521 if ($emptydate || $set_time == -1) {
8522 $retstring .= '<option value="0
" selected> </option>';
8525 for ($day = 1; $day <= 31; $day++) {
8526 $retstring .= '<option value="' . $day . '"' . ($day == $sday ? ' selected' : '') . '>' . $day . '</option>';
8529 $retstring .= "</select>
";
8531 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'month
" name="' . $prefix . 'month
">';
8532 if ($emptydate || $set_time == -1) {
8533 $retstring .= '<option value="0
" selected> </option>';
8537 for ($month = 1; $month <= 12; $month++) {
8538 $retstring .= '<option value="' . $month . '"' . ($month == $smonth ? ' selected' : '') . '>';
8539 $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b
");
8540 $retstring .= "</option>
";
8542 $retstring .= "</select>
";
8545 if ($emptydate || $set_time == -1) {
8546 $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 . '">';
8548 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'year
" name="' . $prefix . 'year
">';
8550 $syear = (int) $syear;
8551 for ($year = $syear - 10; $year < (int) $syear + 10; $year++) {
8552 $retstring .= '<option value="' . $year . '"' . ($year == $syear ? ' selected' : '') . '>' . $year . '</option>';
8554 $retstring .= "</select>\n
";
8560 $retstring .= (($h == 2 || $h == 4) ? '<br>' : ' ');
8561 $retstring .= '<span class="nowraponall
">';
8567 if ($openinghours != '') {
8568 $openinghours = explode(',', $openinghours);
8569 $hourstart = $openinghours[0];
8570 $hourend = $openinghours[1];
8571 if ($hourend < $hourstart) {
8572 $hourend = $hourstart;
8577 $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
8578 $retstring .= ($fullday ? $fullday . 'hour
' : '') . '" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
">';
8580 $retstring .= '<option value="-1
"> </option>';
8582 for ($hour = $hourstart; $hour < $hourend; $hour++) {
8583 if (strlen($hour) < 2) {
8584 $hour = "0
" . $hour;
8586 $retstring .= '<option value="' . $hour . '"' . (($hour == $shour) ? ' selected' : '') . '>' . $hour;
8587 $retstring .= '</option>';
8589 $retstring .= '</select>';
8592 $retstring .= '<input type="hidden
" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
" value="' . $shour . '">' . "\n
";
8601 $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
8602 $retstring .= ($fullday ? $fullday . 'min
' : '') . '" id="' . $prefix . 'min
" name="' . $prefix . 'min
">';
8604 $retstring .= '<option value="-1
"> </option>';
8606 for ($min = 0; $min < 60; $min += $stepminutes) {
8607 $min_str = sprintf("%02d
", $min);
8608 $retstring .= '<option value="' . $min_str . '"' . (($min_str == $smin) ? ' selected' : '') . '>' . $min_str . '</option>';
8610 $retstring .= '</select>';
8612 $retstring .= '<input type="hidden
" id="' . $prefix . 'min
" name="' . $prefix . 'min
" value="' . $smin . '">' . "\n
";
8615 $retstring .= '<input type="hidden
" name="' . $prefix . 'sec
" value="' . $ssec . '">';
8619 $retstring .= '</span>';
8623 if (!empty($conf->use_javascript_ajax) && $addnowlink && !$disabled) {
8624 // Script which will be inserted in the onClick of the "Now
" link
8625 $reset_scripts = "";
8626 if ($addnowlink == 2) { // local computer time
8627 // pad add leading 0 on numbers
8628 $reset_scripts .= "Number.prototype.pad =
function(size) {
8629 var s = String(
this);
8630 while (s.length < (size || 2)) {s =
'0' + s;}
8633 var d =
new Date();
";
8636 // Generate the date part, depending on the use or not of the javascript calendar
8637 if ($addnowlink == 1) { // server time expressed in user time setup
8638 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
8639 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
8640 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
8641 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
8642 } elseif ($addnowlink == 2) {
8643 /* Disabled because the output does not use the string format defined by FormatDateShort key to forge the value into #prefix.
8644 * This break application for foreign languages.
8645 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(d.toLocaleDateString(\''.str_replace('_', '-', $langs->defaultlang).'\'));';
8646 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(d.getDate().pad());';
8647 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(parseInt(d.getMonth().pad()) + 1);';
8648 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(d.getFullYear());';
8650 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
8651 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
8652 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
8653 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
8655 /*if ($usecalendar == "eldy
")
8657 $base=DOL_URL_ROOT.'/core/';
8658 $reset_scripts .= 'resetDP(\''.$base.'\',\''.$prefix.'\',\''.$langs->trans("FormatDateShortJavaInput
").'\',\''.$langs->defaultlang.'\');';
8662 $reset_scripts .= 'this.form.elements[\''.$prefix.'day\'].value=formatDate(new Date(), \'d\'); ';
8663 $reset_scripts .= 'this.form.elements[\''.$prefix.'month\'].value=formatDate(new Date(), \'M\'); ';
8664 $reset_scripts .= 'this.form.elements[\''.$prefix.'year\'].value=formatDate(new Date(), \'yyyy\'); ';
8666 // Update the hour part
8669 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8671 //$reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); ';
8672 if ($addnowlink == 1) {
8673 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
8674 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
8675 } elseif ($addnowlink == 2) {
8676 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(d.getHours().pad());';
8677 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
8681 $reset_scripts .= ' } ';
8684 // Update the minute part
8687 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8689 //$reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); ';
8690 if ($addnowlink == 1) {
8691 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
8692 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
8693 } elseif ($addnowlink == 2) {
8694 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(d.getMinutes().pad());';
8695 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
8698 $reset_scripts .= ' } ';
8701 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
8702 if ($reset_scripts && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
8703 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonNow
" type="button" name="_useless
" value="now
" onClick="' . $reset_scripts . '">';
8704 $retstring .= $langs->trans("Now
");
8705 $retstring .= '</button> ';
8709 // Add a "Plus one hour
" link
8710 if ($conf->use_javascript_ajax && $addplusone && !$disabled) {
8711 // Script which will be inserted in the onClick of the "Add plusone
" link
8712 $reset_scripts = "";
8714 // Generate the date part, depending on the use or not of the javascript calendar
8715 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'dayinputnoreduce', 'tzuserrel') . '\');';
8716 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
8717 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
8718 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
8719 // Update the hour part
8722 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8724 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
8726 $reset_scripts .= ' } ';
8729 // Update the minute part
8732 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8734 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
8736 $reset_scripts .= ' } ';
8739 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
8740 if ($reset_scripts && empty($conf->dol_optimize_smallscreen)) {
8741 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonPlusOne
" type="button" name="_useless2
" value="plusone
" onClick="' . $reset_scripts . '">';
8742 $retstring .= $langs->trans("DateStartPlusOne
");
8743 $retstring .= '</button> ';
8747 // Add a link to set data
8748 if ($conf->use_javascript_ajax && !empty($adddateof) && !$disabled) {
8749 if (!is_array($adddateof)) {
8750 $arrayofdateof = array(array('adddateof' => $adddateof, 'labeladddateof' => $labeladddateof));
8752 $arrayofdateof = $adddateof;
8754 foreach ($arrayofdateof as $valuedateof) {
8755 $tmpadddateof = empty($valuedateof['adddateof']) ? 0 : $valuedateof['adddateof'];
8756 $tmplabeladddateof = empty($valuedateof['labeladddateof']) ? '' : $valuedateof['labeladddateof'];
8757 $tmparray = dol_getdate($tmpadddateof);
8758 if (empty($tmplabeladddateof)) {
8759 $tmplabeladddateof = $langs->trans("DateInvoice
");
8761 $reset_scripts = 'console.log(\'Click on now link\'); ';
8762 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(\''.dol_print_date($tmpadddateof, 'dayinputnoreduce').'\');';
8763 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(\''.$tmparray['mday'].'\');';
8764 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(\''.$tmparray['mon'].'\');';
8765 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(\''.$tmparray['year'].'\');';
8766 $retstring .= ' - <button class="dpInvisibleButtons datenowlink
" id="dateofinvoice
" type="button" name="_dateofinvoice
" value="now
" onclick="'.$reset_scripts.'">'.$tmplabeladddateof.'</button>';
8782 public function selectTypeDuration($prefix, $selected = 'i', $excludetypes = array(), $morecss = 'minwidth75 maxwidth100')
8786 $TDurationTypes = $this->getDurationTypes($langs);
8788 // Removed undesired duration types
8789 foreach ($excludetypes as $value) {
8790 unset($TDurationTypes[$value]);
8793 $retstring = '<select class="flat
'.($morecss ? ' '.$morecss : '').'" id="select_
' . $prefix . 'type_duration
" name="' . $prefix . 'type_duration
">';
8794 foreach ($TDurationTypes as $key => $typeduration) {
8795 $retstring .= '<option value="' . $key . '"';
8796 if ($key == $selected) {
8797 $retstring .= " selected
";
8799 $retstring .= ">
" . $typeduration . "</option>
";
8801 $retstring .= "</select>
";
8803 $retstring .= ajax_combobox('select_' . $prefix . 'type_duration');
8808 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
8823 public function select_duration($prefix, $iSecond = '', $disabled = 0, $typehour = 'select', $minunderhours = 0, $nooutput = 0)
8828 $retstring = '<span class="nowraponall
">';
8834 if ($iSecond != '') {
8835 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
8837 $hourSelected = convertSecondToTime($iSecond, 'allhour');
8838 $minSelected = convertSecondToTime($iSecond, 'min');
8841 if ($typehour == 'select') {
8842 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'hour
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . '>';
8843 for ($hour = 0; $hour < 25; $hour++) { // For a duration, we allow 24 hours
8844 $retstring .= '<option value="' . $hour . '"';
8845 if (is_numeric($hourSelected) && $hourSelected == $hour) {
8846 $retstring .= " selected
";
8848 $retstring .= ">
" . $hour . "</option>
";
8850 $retstring .= "</select>
";
8851 } elseif ($typehour == 'text' || $typehour == 'textselect') {
8852 $retstring .= '<input placeholder="' . $langs->trans('HourShort
') . '" type="number
" min="0
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputhour right
" value="' . (($hourSelected != '') ? ((int) $hourSelected) : '') . '">';
8854 return 'BadValueForParameterTypeHour';
8857 if ($typehour != 'text') {
8858 $retstring .= ' ' . $langs->trans('HourShort');
8860 $retstring .= '<span class="">:</span>';
8864 if ($minunderhours) {
8865 $retstring .= '<br>';
8867 if ($typehour != 'text') {
8868 $retstring .= '<span class="hideonsmartphone
"> </span>';
8872 if ($typehour == 'select' || $typehour == 'textselect') {
8873 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'min
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . '>';
8874 $step = getDolGlobalInt('MAIN_DURATION_STEP');
8875 $duration_step = ($step > 0) ? $step : 5;
8876 for ($min = 0; $min <= 59; $min += $duration_step) {
8877 $retstring .= '<option value="' . $min . '"';
8878 if (is_numeric($minSelected) && $minSelected == $min) {
8879 $retstring .= ' selected';
8881 $retstring .= '>' . $min . '</option>';
8883 $retstring .= "</select>
";
8884 } elseif ($typehour == 'text') {
8885 $retstring .= '<input placeholder="' . $langs->trans('MinuteShort
') . '" type="number
" min="0
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputminute right
" value="' . (($minSelected != '') ? ((int) $minSelected) : '') . '">';
8888 if ($typehour != 'text') {
8889 $retstring .= ' ' . $langs->trans('MinuteShort');
8892 $retstring .= "</span>
";
8894 if (!empty($nooutput)) {
8922 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)
8924 global $langs, $conf;
8929 if (is_null($ajaxoptions)) {
8930 $ajaxoptions = array();
8933 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
8936 if ($selected && empty($selected_input_value)) {
8937 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
8938 $tickettmpselect = new Ticket($this->db);
8939 $tickettmpselect->fetch((int) $selected);
8940 $selected_input_value = $tickettmpselect->ref;
8941 unset($tickettmpselect);
8945 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/ticket/ajax/tickets.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
8947 if (empty($hidelabel)) {
8948 $out .= $langs->trans("RefOrLabel
") . ' : ';
8949 } elseif ($hidelabel > 1) {
8950 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
8951 if ($hidelabel == 2) {
8952 $out .= img_picto($langs->trans("Search
"), 'search');
8955 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
8956 if ($hidelabel == 3) {
8957 $out .= img_picto($langs->trans("Search
"), 'search');
8960 $out .= $this->selectTicketsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
8963 if (empty($nooutput)) {
8988 public function selectTicketsList($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
8993 $outarray = array();
8995 $selectFields = " p.rowid, p.ref, p.message
";
8998 $sql .= $this->db->sanitize($selectFields, 0, 0, 1);
8999 $sql .= " FROM
" . $this->db->prefix() . "ticket as p
";
9000 $sql .= ' WHERE p.entity IN (' . getEntity('ticket') . ')';
9002 // Add criteria on ref/label
9003 if ($filterkey != '') {
9005 $prefix = getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '' : '%'; // Can use index if TICKET_DONOTSEARCH_ANYWHERE is on
9006 // For natural search
9007 $search_crit = explode(' ', $filterkey);
9009 if (count($search_crit) > 1) {
9012 foreach ($search_crit as $crit) {
9016 $sql .= "(p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%' OR p.subject LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
9020 if (count($search_crit) > 1) {
9026 $sql .= $this->db->plimit($limit, 0);
9028 // Build output string
9029 dol_syslog(get_class($this) . "::selectTicketsList search tickets
", LOG_DEBUG);
9030 $result = $this->db->query($sql);
9032 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
9033 require_once DOL_DOCUMENT_ROOT . '/core/lib/ticket.lib.php';
9035 $num = $this->db->num_rows($result);
9040 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
9041 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('TICKET_USE_SEARCH_TO_SELECT'));
9044 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
9047 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
9048 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
9049 if (getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
9050 if ($showempty && !is_numeric($showempty)) {
9051 $textifempty = $langs->trans($showempty);
9053 $textifempty .= $langs->trans("All
");
9056 if ($showempty && !is_numeric($showempty)) {
9057 $textifempty = $langs->trans($showempty);
9061 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
9065 while ($num && $i < $num) {
9068 $objp = $this->db->fetch_object($result);
9070 $this->constructTicketListOption($objp, $opt, $optJson, $selected, $filterkey);
9071 '@phan-var-force array{key:string,value:mixed,type:int} $optJson';
9073 // "key
" value of json key array is used by jQuery automatically as selected value
9074 // "label
" value of json key array is used by jQuery automatically as text for combo box
9076 array_push($outarray, $optJson);
9081 $out .= '</select>';
9083 $this->db->free($result);
9085 if (empty($outputmode)) {
9090 dol_print_error($this->db);
9107 protected function constructTicketListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
9113 $outkey = $objp->rowid;
9114 $outref = $objp->ref;
9116 $opt = '<option value="
' . $objp->rowid . '"';
9117 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
9120 $objRef = $objp->ref;
9121 if (!empty($filterkey) && $filterkey != '') {
9122 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1);
9125 $opt .= "</option>\n
";
9126 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
9148 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)
9150 global $langs, $conf;
9155 if (is_null($ajaxoptions)) {
9156 $ajaxoptions = array();
9159 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
9162 if ($selected && empty($selected_input_value)) {
9163 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
9164 $projecttmpselect = new Project($this->db);
9165 $projecttmpselect->fetch((int) $selected);
9166 $selected_input_value = $projecttmpselect->ref;
9167 unset($projecttmpselect);
9171 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/projet/ajax/projects.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
9173 if (empty($hidelabel)) {
9174 $out .= $langs->trans("RefOrLabel
") . ' : ';
9175 } elseif ($hidelabel > 1) {
9176 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
9177 if ($hidelabel == 2) {
9178 $out .= img_picto($langs->trans("Search
"), 'search');
9181 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
9182 if ($hidelabel == 3) {
9183 $out .= img_picto($langs->trans("Search
"), 'search');
9186 $out .= $this->selectProjectsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
9189 if (empty($nooutput)) {
9213 public function selectProjectsList($selected = '', $htmlname = 'projectid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
9215 global $langs, $conf;
9218 $outarray = array();
9220 $selectFields = " p.rowid, p.ref
";
9223 $sql .= $this->db->sanitize($selectFields, 0, 0, 1);
9224 $sql .= " FROM
" . $this->db->prefix() . "projet as p
";
9225 $sql .= ' WHERE p.entity IN (' . getEntity('project') . ')';
9227 // Add criteria on ref/label
9228 if ($filterkey != '') {
9230 $prefix = !getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
9231 // For natural search
9232 $search_crit = explode(' ', $filterkey);
9234 if (count($search_crit) > 1) {
9237 foreach ($search_crit as $crit) {
9241 $sql .= "p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
9245 if (count($search_crit) > 1) {
9251 $sql .= $this->db->plimit($limit, 0);
9253 // Build output string
9254 dol_syslog(get_class($this) . "::selectProjectsList search projects
", LOG_DEBUG);
9255 $result = $this->db->query($sql);
9257 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
9258 require_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php';
9260 $num = $this->db->num_rows($result);
9265 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
9266 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('PROJECT_USE_SEARCH_TO_SELECT'));
9269 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
9272 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
9273 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
9274 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
9275 if ($showempty && !is_numeric($showempty)) {
9276 $textifempty = $langs->trans($showempty);
9278 $textifempty .= $langs->trans("All
");
9281 if ($showempty && !is_numeric($showempty)) {
9282 $textifempty = $langs->trans($showempty);
9286 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
9290 while ($num && $i < $num) {
9293 $objp = $this->db->fetch_object($result);
9295 $this->constructProjectListOption($objp, $opt, $optJson, $selected, $filterkey);
9297 // "key
" value of json key array is used by jQuery automatically as selected value
9298 // "label
" value of json key array is used by jQuery automatically as text for combo box
9300 array_push($outarray, $optJson);
9305 $out .= '</select>';
9307 $this->db->free($result);
9309 if (empty($outputmode)) {
9314 dol_print_error($this->db);
9333 protected function constructProjectListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
9339 $label = $objp->label;
9341 $outkey = $objp->rowid;
9342 $outref = $objp->ref;
9343 $outlabel = $objp->label;
9344 $outtype = $objp->fk_product_type;
9346 $opt = '<option value="
' . $objp->rowid . '"';
9347 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
9350 $objRef = $objp->ref;
9351 if (!empty($filterkey) && $filterkey != '') {
9352 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', (string) $objRef, 1);
9355 $opt .= "</option>\n
";
9356 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
9380 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())
9382 global $langs, $conf;
9387 if (is_null($ajaxoptions)) {
9388 $ajaxoptions = array();
9391 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
9394 if ($selected && empty($selected_input_value)) {
9395 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
9396 $adherenttmpselect = new Adherent($this->db);
9397 $adherenttmpselect->fetch((int) $selected);
9398 $selected_input_value = $adherenttmpselect->ref;
9399 unset($adherenttmpselect);
9404 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/adherents/ajax/adherents.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
9406 if (empty($hidelabel)) {
9407 $out .= $langs->trans("RefOrLabel
") . ' : ';
9408 } elseif ($hidelabel > 1) {
9409 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
9410 if ($hidelabel == 2) {
9411 $out .= img_picto($langs->trans("Search
"), 'search');
9414 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
9415 if ($hidelabel == 3) {
9416 $out .= img_picto($langs->trans("Search
"), 'search');
9421 $out .= $this->selectMembersList($selected, $htmlname, $filtertype, $limit, $filterkey, $status, 0, $showempty, $forcecombo, $morecss, $excludeids);
9424 if (empty($nooutput)) {
9449 public function selectMembersList($selected = '', $htmlname = 'adherentid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '', $excludeids = array())
9451 global $langs, $conf;
9454 $outarray = array();
9456 $selectFields = " p.rowid, p.ref, p.firstname, p.lastname, p.fk_adherent_type
";
9459 $sql .= $this->db->sanitize($selectFields, 0, 0, 1);
9460 $sql .= " FROM
" . $this->db->prefix() . "adherent as p
";
9461 $sql .= ' WHERE p.entity IN (' . getEntity('adherent') . ')';
9463 // Add criteria on ref/label
9464 if ($filterkey != '') {
9466 $prefix = !getDolGlobalString('MEMBER_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
9467 // For natural search
9468 $search_crit = explode(' ', $filterkey);
9470 if (count($search_crit) > 1) {
9473 foreach ($search_crit as $crit) {
9477 $sql .= "(p.firstname LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
9478 $sql .= " OR p.lastname LIKE
'" . $this->db->escape($prefix . $crit) . "%')
";
9481 if (count($search_crit) > 1) {
9486 if ($status != -1) {
9487 $sql .= ' AND statut = ' . ((int) $status);
9489 if (!empty($excludeids)) {
9490 $sql .= " AND p.rowid NOT IN (
" . $this->db->sanitize(implode(',', $excludeids)) . ")
";
9492 $sql .= $this->db->plimit($limit, 0);
9494 // Build output string
9495 dol_syslog(get_class($this) . "::selectMembersList search adherents
", LOG_DEBUG);
9496 $result = $this->db->query($sql);
9498 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
9499 require_once DOL_DOCUMENT_ROOT . '/core/lib/member.lib.php';
9501 $num = $this->db->num_rows($result);
9506 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
9507 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('PROJECT_USE_SEARCH_TO_SELECT'));
9510 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
9513 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
9514 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
9515 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
9516 if ($showempty && !is_numeric($showempty)) {
9517 $textifempty = $langs->trans($showempty);
9519 $textifempty .= $langs->trans("All
");
9522 if ($showempty && !is_numeric($showempty)) {
9523 $textifempty = $langs->trans($showempty);
9527 $out .= '<option value="-1
" selected>' . $textifempty . '</option>';
9531 while ($num && $i < $num) {
9534 $objp = $this->db->fetch_object($result);
9536 $this->constructMemberListOption($objp, $opt, $optJson, $selected, $filterkey);
9539 // "key
" value of json key array is used by jQuery automatically as selected value
9540 // "label
" value of json key array is used by jQuery automatically as text for combo box
9542 array_push($outarray, $optJson);
9547 $out .= '</select>';
9549 $this->db->free($result);
9551 if (empty($outputmode)) {
9556 dol_print_error($this->db);
9573 protected function constructMemberListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
9579 $outkey = $objp->rowid;
9580 $outlabel = dolGetFirstLastname($objp->firstname, $objp->lastname);
9581 $outtype = $objp->fk_adherent_type;
9583 $opt = '<option value="
' . $objp->rowid . '"';
9584 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
9586 if (!empty($filterkey) && $filterkey != '') {
9587 $outlabel = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $outlabel, 1);
9590 $opt .= "</option>\n
";
9592 $optJson = array('key' => $outkey, 'value' => $outlabel, 'type' => $outtype);
9616 public function selectForForms($objectdesc, $htmlname, $preSelectedValue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $disabled = 0, $selected_input_value = '', $objectfield = '')
9618 global $conf, $extrafields, $user, $hookmanager, $action;
9620 // Example of common usage for a link to a thirdparty
9622 // We got this in a modulebuilder form of "
MyObject" of module "mymodule
".
9623 // 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
9624 // $objectdesc = 'Societe'
9625 // $objectfield = Method 1: 'myobject@mymodule:fk_soc' ('fk_soc' is code to retrieve myobject->fields['fk_soc'])
9626 // 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__))
" ...)
9628 // We got this when showing an extrafields on resource that is a link to societe
9629 // 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
9630 // $objectdesc = 'Societe'
9631 // $objectfield = Method 1: 'resource:options_link_to_societe'
9632 // Method 2 recommended (it can be the array): array("type"=>'Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))" ...)
9641 $objectdescorig = $objectdesc;
9643 $InfoFieldList = array();
9648 if (is_array($objectfield)) {
9649 $objectdesc = $objectfield[
'type'];
9650 $objectdesc = preg_replace(
'/^integer[^:]*:/',
'', $objectdesc);
9651 } elseif ($objectfield) {
9653 $tmparray = explode(
':', $objectfield);
9656 $objectforfieldstmp = fetchObjectByElement(0, strtolower($tmparray[0]));
9658 if (is_object($objectforfieldstmp)) {
9662 if (preg_match(
'/^options_(.*)$/', $tmparray[1], $reg)) {
9666 $extrafields->fetch_name_optionals_label($objectforfieldstmp->table_element);
9668 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element][
'type'][$key]) && $extrafields->attributes[$objectforfieldstmp->table_element][
'type'][$key] ==
'link') {
9669 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element][
'param'][$key][
'options'])) {
9670 $tmpextrafields = array_keys($extrafields->attributes[$objectforfieldstmp->table_element][
'param'][$key][
'options']);
9671 $objectdesc = $tmpextrafields[0];
9676 if (array_key_exists($tmparray[1], $objectforfieldstmp->fields)) {
9677 $objectdesc = $objectforfieldstmp->fields[$tmparray[1]][
'type'];
9678 $objectdesc = preg_replace(
'/^integer[^:]*:/',
'', $objectdesc);
9689 $InfoFieldList = explode(
":", $objectdesc, 4);
9690 $vartmp = (empty($InfoFieldList[3]) ?
'' : $InfoFieldList[3]);
9692 if (preg_match(
'/^.*:(\w*)$/', $vartmp, $reg)) {
9693 $InfoFieldList[4] = $reg[1];
9695 $InfoFieldList[3] = preg_replace(
'/:\w*$/',
'', $vartmp);
9697 $classname = $InfoFieldList[0];
9698 $classpath = empty($InfoFieldList[1]) ?
'' : $InfoFieldList[1];
9700 $filter = empty($InfoFieldList[3]) ?
'' : $InfoFieldList[3];
9701 $sortfield = empty($InfoFieldList[4]) ?
'' : $InfoFieldList[4];
9704 $objecttmp = fetchObjectByElement(0, strtolower($InfoFieldList[0]));
9707 if (empty($objecttmp) && !empty($classpath)) {
9710 if ($classname && class_exists($classname)) {
9711 $objecttmp =
new $classname($this->db);
9718 $sharedentities = (is_object($objecttmp) && property_exists($objecttmp,
'element')) ?
getEntity($objecttmp->element) : strtolower($classname);
9719 $filter = str_replace(
9720 array(
'__ENTITY__',
'__SHARED_ENTITIES__',
'__USER_ID__'),
9721 array(
$conf->entity, $sharedentities, $user->id),
9725 if (!is_object($objecttmp)) {
9726 dol_syslog(
'selectForForms: Error bad setup of field objectdescorig=' . $objectdescorig.
', objectfield='.(is_array($objectfield) ?
'array' : $objectfield).
', objectdesc='.$objectdesc, LOG_WARNING);
9727 return 'selectForForms: Error bad setup of field objectdescorig=' . $objectdescorig.
', objectfield='.(is_array($objectfield) ?
'array' : $objectfield).
', objectdesc='.$objectdesc;
9729 '@phan-var-force CommonObject $objecttmp';
9732 $prefixforautocompletemode = $objecttmp->element;
9733 if ($prefixforautocompletemode ==
'societe') {
9734 $prefixforautocompletemode =
'company';
9736 if ($prefixforautocompletemode ==
'product') {
9737 $prefixforautocompletemode =
'produit';
9740 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) .
'_USE_SEARCH_TO_SELECT';
9742 dol_syslog(get_class($this) .
"::selectForForms filter=" . $filter, LOG_DEBUG);
9750 if ($preSelectedValue && empty($selected_input_value)) {
9751 $objecttmp->fetch($preSelectedValue);
9752 $selected_input_value = ($prefixforautocompletemode ==
'company' ? $objecttmp->name : $objecttmp->ref);
9754 $oldValueForShowOnCombobox = 0;
9755 foreach ($objecttmp->fields as $fieldK => $fielV) {
9756 if (!array_key_exists(
'showoncombobox', $fielV) || !$fielV[
'showoncombobox'] || empty($objecttmp->$fieldK)) {
9760 if (!$oldValueForShowOnCombobox) {
9761 $selected_input_value =
'';
9764 $selected_input_value .= $oldValueForShowOnCombobox ?
' - ' :
'';
9765 $selected_input_value .= $objecttmp->$fieldK;
9766 $oldValueForShowOnCombobox = empty($fielV[
'showoncombobox']) ? 0 : $fielV[
'showoncombobox'];
9771 $urlforajaxcall = DOL_URL_ROOT .
'/core/ajax/selectobject.php';
9772 $urloption =
'htmlname=' . urlencode($htmlname) .
'&outjson=1&objectdesc=' . urlencode($objectdescorig) . (is_scalar($objectfield) ?
'&objectfield='.urlencode($objectfield) :
'') . ($sortfield ?
'&sortfield=' . urlencode($sortfield) :
'');
9776 $parameters = array(
9777 'urloption' => $urloption,
9778 'object' => $objecttmp,
9779 'htmlname' => $htmlname,
9780 'filter' => $filter,
9781 'searchkey' => $searchkey,
9783 $reshook = $hookmanager->executeHooks(
'selectForFormsListUrl', $parameters, $objecttmp, $action);
9784 if (!empty($reshook)) {
9785 $urloption = $hookmanager->resPrint;
9786 $hookmanager->resPrint =
'';
9791 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
9792 $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) .
'"' :
'') .
' />';
9795 $out .= $this->selectForFormsList($objecttmp, $htmlname, $preSelectedValue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled, $sortfield, $filter);
9823 public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty =
'', $searchkey =
'', $placeholder =
'', $morecss =
'', $moreparams =
'', $forcecombo = 0, $outputmode = 0, $disabled = 0, $sortfield =
'', $filter =
'', $sortorder =
'ASC')
9825 global $langs, $user, $hookmanager;
9829 $prefixforautocompletemode = $objecttmp->element;
9830 if ($prefixforautocompletemode ==
'societe') {
9831 $prefixforautocompletemode =
'company';
9833 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) .
'_USE_SEARCH_TO_SELECT';
9836 if (!empty($objecttmp->fields)) {
9837 $tmpfieldstoshow =
'';
9838 foreach ($objecttmp->fields as $key => $val) {
9839 if (! (
int)
dol_eval((
string) $val[
'enabled'], 1, 1,
'1')) {
9842 if (!empty($val[
'showoncombobox'])) {
9843 $tmpfieldstoshow .= ($tmpfieldstoshow ?
',' :
'') .
't.' . $key;
9846 if ($tmpfieldstoshow) {
9847 $fieldstoshow = $tmpfieldstoshow;
9849 } elseif ($objecttmp->element ===
'category') {
9850 $fieldstoshow =
't.label';
9853 $objecttmp->fields[
'ref'] = array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'enabled' => 1,
'position' => 10,
'visible' => 4,
'showoncombobox' => 1);
9856 if (empty($fieldstoshow)) {
9857 if (!empty($objecttmp->parent_element)) {
9858 $fieldstoshow =
'o.ref';
9859 if (empty($sortfield)) {
9860 $sortfield =
'o.ref';
9862 if (in_array($objecttmp->element, [
'commandedet',
'propaldet',
'facturedet',
'expeditiondet'])) {
9863 $fieldstoshow .=
',p.ref AS p_ref,p.label,t.description';
9864 $sortfield .=
', p.ref';
9866 } elseif (isset($objecttmp->fields[
'ref'])) {
9867 $fieldstoshow =
't.ref';
9869 $langs->load(
"errors");
9870 $this->error = $langs->trans(
"ErrorNoFieldWithAttributeShowoncombobox");
9871 return $langs->trans(
'ErrorNoFieldWithAttributeShowoncombobox');
9876 $outarray = array();
9877 $tmparray = array();
9881 $sanitizedfieldstoshow = $fieldstoshow;
9884 $sql =
"SELECT t.rowid, " . $sanitizedfieldstoshow .
" FROM " . $this->db->prefix() . $this->db->sanitize($objecttmp->table_element) .
" as t";
9885 if (!empty($objecttmp->isextrafieldmanaged)) {
9886 $extrafieldTable = $objecttmp->table_element;
9887 if ($extrafieldTable ==
'categorie') {
9888 $extrafieldTable =
'categories';
9890 $sql .=
" LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($extrafieldTable) .
"_extrafields as e ON t.rowid = e.fk_object";
9892 if (!empty($objecttmp->parent_element)) {
9893 '@phan-var-force CommonObjectLine $objecttmp';
9896 $sql .=
" INNER JOIN " . $this->db->prefix() . $this->db->sanitize($parent_properties[
'table_element']) .
" as o ON o.rowid = t.".$objecttmp->fk_parent_attribute;
9898 if (!empty($objecttmp->parent_element) && in_array($objecttmp->parent_element, [
'commande',
'propal',
'facture',
'expedition'])) {
9899 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product as p ON p.rowid = t.fk_product";
9901 if (!empty($objecttmp->ismultientitymanaged)) {
9902 if ($objecttmp->ismultientitymanaged == 1) {
9905 if (!is_numeric($objecttmp->ismultientitymanaged)) {
9906 $tmparray = explode(
'@', $objecttmp->ismultientitymanaged);
9907 $sql .=
" INNER JOIN " . $this->db->prefix() . $this->db->sanitize($tmparray[1]) .
" as parenttable ON parenttable.rowid = t." . $this->db->sanitize($tmparray[0]);
9912 $parameters = array(
9913 'object' => $objecttmp,
9914 'htmlname' => $htmlname,
9915 'filter' => $filter,
9916 'searchkey' => $searchkey
9919 $reshook = $hookmanager->executeHooks(
'selectForFormsListWhere', $parameters);
9920 if (!empty($hookmanager->resPrint)) {
9921 $sql .= $hookmanager->resPrint;
9923 $sql .=
" WHERE 1=1";
9926 if (!empty($objecttmp->ismultientitymanaged)) {
9927 if ($objecttmp->ismultientitymanaged == 1) {
9928 $sql .=
" AND t.entity IN (" .
getEntity($objecttmp->element) .
")";
9930 if (!is_numeric($objecttmp->ismultientitymanaged)) {
9931 $sql .=
" AND parenttable.entity = t." . $this->db->sanitize($tmparray[0]);
9935 if ($objecttmp->ismultientitymanaged ===
'fk_soc@societe') {
9936 if (!$user->hasRight(
'societe',
'client',
'voir') && empty($user->socid)) {
9937 $sql .=
" AND EXISTS (SELECT sc.rowid FROM ".$this->db->prefix() .
"societe_commerciaux as sc";
9938 $sql .=
" WHERE sc.fk_soc = t.fk_soc AND sc.fk_user = ".((int) $user->id).
")";
9944 if (!empty($user->socid)) {
9945 if ($objecttmp->element ==
'societe') {
9946 $sql .=
" AND t.rowid = " . ((int) $user->socid);
9947 } elseif (!empty($objecttmp->fields[
'fk_soc']) || !empty($objecttmp->fields[
't.fk_soc']) || property_exists($objecttmp,
'fk_soc') || property_exists($objecttmp,
'socid')) {
9948 $sql .=
" AND t.fk_soc = " . ((int) $user->socid);
9952 $splittedfieldstoshow = explode(
',', $fieldstoshow);
9953 foreach ($splittedfieldstoshow as &$field2) {
9954 if (is_numeric($pos = strpos($field2,
' '))) {
9955 $field2 = substr($field2, 0, $pos);
9958 if ($searchkey !=
'') {
9965 if ($errormessage) {
9966 return 'Error forging a SQL request from an universal criteria: ' . $errormessage;
9970 $sql .= $this->db->order($sortfield ? $sortfield : $fieldstoshow, $sortorder);
9975 $resql = $this->db->query($sql);
9978 $out .=
'<select id="' . $htmlname .
'" class="flat minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') . ($moreparams ?
' ' . $moreparams :
'') .
' name="' . $htmlname .
'">' .
"\n";
9981 $textifempty =
' ';
9985 if ($showempty && !is_numeric($showempty)) {
9986 $textifempty = $langs->trans($showempty);
9988 $textifempty .= $langs->trans(
"All");
9992 $out .=
'<option value="-1">' . $textifempty .
'</option>' .
"\n";
9995 $num = $this->db->num_rows($resql);
9999 $obj = $this->db->fetch_object($resql);
10002 $tmparray = explode(
',', $fieldstoshow);
10003 $oldvalueforshowoncombobox = 0;
10004 foreach ($tmparray as $key => $val) {
10005 $val = preg_replace(
'/(t|p|o)\./',
'', $val);
10006 $label .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val][
'showoncombobox'] ?
' - ' :
' ') :
'');
10007 $labelhtml .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val][
'showoncombobox'] ?
' - ' :
' ') :
'');
10008 $label .= $obj->$val;
10009 $labelhtml .= $obj->$val;
10011 $oldvalueforshowoncombobox = empty($objecttmp->fields[$val][
'showoncombobox']) ? 0 : $objecttmp->fields[$val][
'showoncombobox'];
10013 if (empty($outputmode)) {
10014 if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) {
10015 $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>';
10017 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
10020 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label));
10024 if (($i % 10) == 0) {
10030 $out .=
'</select>' .
"\n";
10032 if (!$forcecombo) {
10033 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
10040 $this->result = array(
'nbofelement' => $num);
10058 public static function radio($htmlName, $radioItems, $selected =
'', $moreGlobalParams = [])
10062 'disabled' =>
false,
10065 'name' => $htmlName,
10068 'labelIsHtml' => false
10075 if (!empty($radioItems)) {
10076 foreach ($radioItems as $key => $item) {
10078 if (!is_array($item)) {
10090 'value' => !isset($item[
'attr'][
'value']) ? $key :
'',
10100 if ((is_array($selected) && in_array($item[
'attr'][
'value'], $selected,
true)) || $selected === $item[
'attr'][
'value']) {
10101 $item[
'attr'][
'checked'] =
true;
10109 $text = $item[
'labelIsHtml'] ? $item[
'label'] : htmlspecialchars($item[
'label'], ENT_QUOTES | ENT_SUBSTITUTE);
10112 $out .=
'<label ' . $labelAttributes .
'><input ' . $inputAttributes .
' /> ' . $text .
'</label> ';
10143 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)
10145 global
$conf, $langs;
10152 if ($value_as_key) {
10153 $array = array_combine($array, $array);
10156 '@phan-var-force array{label:string,data-html:string,disable?:int<0,1>,css?:string} $array';
10160 if ($addjscombo < 0) {
10167 $idname = str_replace(array(
'[',
']'), array(
'',
''), $htmlname);
10168 $out .=
'<select id="' . preg_replace(
'/^\./',
'', $idname) .
'" ' . ($disabled ?
'disabled="disabled" ' :
'') .
'class="flat ' . (preg_replace(
'/^\./',
'', $htmlname)) . ($morecss ?
' ' . $morecss :
'') .
' selectformat"';
10169 $out .=
' name="' . preg_replace(
'/^\./',
'', $htmlname) .
'" ' . ($moreparam ? $moreparam :
'');
10173 $textforempty =
' ';
10174 if (!empty(
$conf->use_javascript_ajax)) {
10175 $textforempty =
' ';
10177 if (!is_numeric($show_empty)) {
10178 $textforempty = $show_empty;
10180 $out .=
'<option class="optiongrey" ' . ($moreparamonempty ? $moreparamonempty .
' ' :
'') .
'value="' . (((
int) $show_empty) < 0 ? $show_empty : -1) .
'"' . (
$id == $show_empty ?
' selected' :
'') .
'>' . $textforempty .
'</option>' .
"\n";
10182 if (is_array($array)) {
10185 foreach ($array as $key => $value) {
10186 if (!is_array($value)) {
10187 $array[$key] = $langs->trans($value);
10189 $array[$key][
'label'] = $langs->trans($value[
'label']);
10194 if ($sort ==
'ASC') {
10196 } elseif ($sort ==
'DESC') {
10200 foreach ($array as $key => $tmpvalue) {
10201 if (is_array($tmpvalue)) {
10202 $value = $tmpvalue[
'label'];
10204 $disabled = empty($tmpvalue[
'disabled']) ?
'' :
' disabled';
10205 $style = empty($tmpvalue[
'css']) ?
'' :
' class="' . $tmpvalue[
'css'] .
'"';
10207 $value = $tmpvalue;
10212 if (!empty($disablebademail)) {
10213 if (($disablebademail == 1 && !preg_match(
'/<.+@.+>/', $value))
10214 || ($disablebademail == 2 && preg_match(
'/---/', $value))) {
10215 $disabled =
' disabled';
10216 $style =
' class="warning"';
10219 if ($key_in_label) {
10220 if (empty($nohtmlescape)) {
10223 $selectOptionValue = $key .
' - ' . ($maxlen ?
dol_trunc($value, $maxlen) : $value);
10226 if (empty($nohtmlescape)) {
10229 $selectOptionValue = $maxlen ?
dol_trunc($value, $maxlen) : $value;
10231 if ($value ==
'' || $value ==
'-') {
10232 $selectOptionValue =
' ';
10235 $out .=
'<option value="' . $key .
'"';
10236 $out .= $style . $disabled;
10237 $out .= is_array($tmpvalue) && !empty($tmpvalue[
'parent']) ?
' parent="' .
dolPrintHTMLForAttribute($tmpvalue[
'parent']) .
'"' :
'';
10238 if (is_array(
$id)) {
10239 if (in_array($key,
$id) && !$disabled) {
10240 $out .=
' selected';
10244 if (
$id !=
'' && ((
$id == (
string) $key) || (
$id ==
'ifone' && count($array) == 1)) && !$disabled) {
10245 $out .=
' selected';
10249 if (is_array($tmpvalue)) {
10250 foreach ($tmpvalue as $keyforvalue => $valueforvalue) {
10251 if ($keyforvalue ==
'labelhtml') {
10252 $keyforvalue =
'data-html';
10254 if (preg_match(
'/^data-/', $keyforvalue)) {
10255 $out .=
' '.dol_escape_htmltag($keyforvalue).
'="'.
dol_escape_htmltag($valueforvalue).
'"';
10258 } elseif (!empty($nohtmlescape)) {
10263 $out .= $selectOptionValue;
10264 $out .=
"</option>\n";
10267 $out .=
"</select>";
10270 if ($addjscombo && $jsbeautify) {
10272 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
10273 $out .=
ajax_combobox($idname, array(), 0, 0,
'resolve', (((
int) $show_empty) < 0 ? (
string) $show_empty :
'-1'), $morecss);
10297 public static function selectArrayAjax($htmlname, $url,
$id =
'', $moreparam =
'', $moreparamtourl =
'', $disabled = 0, $minimumInputLength = 1, $morecss =
'', $callurlonselect = 0, $placeholder =
'', $acceptdelayedhtml = 0)
10300 global $delayedhtmlcontent;
10303 if (!
getDolGlobalString(
'MAIN_USE_JQUERY_MULTISELECT') && !defined(
'REQUIRE_JQUERY_MULTISELECT')) {
10307 $out =
'<select type="text" class="' . $htmlname . ($morecss ?
' ' . $morecss :
'') .
'" ' . ($moreparam ? $moreparam .
' ' :
'') .
'name="' . $htmlname .
'"></select>';
10310 if (!empty(
$conf->use_javascript_ajax)) {
10311 $tmpplugin =
'select2';
10312 $outdelayed =
"\n" .
'<!-- JS CODE TO ENABLE ' . $tmpplugin .
' for id ' . $htmlname .
' -->
10313 <script nonce="' .
getNonce() .
'">
10314 $(document).ready(function () {
10316 ' . ($callurlonselect ?
'var saveRemoteData = [];' :
'') .
'
10318 $(".' . $htmlname .
'").select2({
10321 url: "' . $url .
'",
10322 dataType: \'json\',
10324 data: function (params) {
10326 q: params.term, // search term
10330 processResults: function (data) {
10331 // parse the results into the format expected by Select2.
10332 // since we are using custom formatting functions we do not need to alter the remote JSON data
10333 //console.log(data);
10334 saveRemoteData = data;
10335 /* format json result for select2 */
10337 $.each( data, function( key, value ) {
10338 result.push({id: key, text: value.text});
10340 //return {results:[{id:\'none\', text:\'aa\'}, {id:\'rrr\', text:\'Red\'},{id:\'bbb\', text:\'Search a into projects\'}], more:false}
10341 //console.log(result);
10342 return {results: result, more: false}
10346 language: (typeof select2arrayoflanguage === \'undefined\') ? \'en\' : select2arrayoflanguage,
10347 containerCssClass: \':all:\', /* Line to add class from the original SELECT propagated to the new <span class="select2-selection...> tag */
10349 escapeMarkup:
function (markup) {
return markup; },
10350 minimumInputLength:
' . ((int) $minimumInputLength) . ',
10351 formatResult:
function (result, container, query, escapeMarkup) {
10352 return escapeMarkup(result.text);
10356 ' . ($callurlonselect ? '
10358 $(
".' . $htmlname . '").change(
function() {
10359 var selected = $(\
'.' .
dol_escape_js($htmlname) .
'\').val();
10360 console.log(
"We select in selectArrayAjax the entry "+selected)
10362 $.each( saveRemoteData,
function( key, value ) {
10363 if (key == selected)
10365 console.log(
"selectArrayAjax - Do a redirect to "+value.url)
10366 location.assign(value.url);
10375 if ($acceptdelayedhtml) {
10376 $delayedhtmlcontent .= $outdelayed;
10378 $out .= $outdelayed;
10402 public static function selectArrayFilter($htmlname, $array, $id = '
', $moreparam = '', $disableFiltering = 0, $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0, $textfortitle = '')
10405 global $delayedhtmlcontent; // Will be used later outside of this function
10407 // TODO Use an internal dolibarr component instead of select2
10408 if (!getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT
') && !defined('REQUIRE_JQUERY_MULTISELECT
')) {
10412 $out = '<select
type=
"text"'.($textfortitle ? ' title=
"'.dol_escape_htmltag($textfortitle).'"' : '').' id=
"'.$htmlname.'" class=
"'.$htmlname.($morecss ? ' ' . $morecss : '').'"'.($moreparam ? ' '.$moreparam : '').' name=
"'.$htmlname.'"><option></option></select>
';
10414 $formattedarrayresult = array();
10416 foreach ($array as $key => $value) {
10417 $o = new stdClass();
10419 $o->text = $value['text
'];
10420 $o->url = $value['url
'];
10421 $formattedarrayresult[] = $o;
10425 if (!empty($conf->use_javascript_ajax)) {
10426 $tmpplugin = 'select2
';
10427 $outdelayed = "\n" . '<!-- JS CODE TO ENABLE
' . $tmpplugin . ' for id ' . $htmlname . ' -->
10428 <script nonce=
"' . getNonce() . '">
10429 $(document).ready(
function () {
10430 var data =
' . json_encode($formattedarrayresult) . ';
10432 ' . ($callurlonselect ? 'var saveRemoteData =
' . json_encode($array) . ';
' : '') . '
10436 language: (typeof select2arrayoflanguage === \
'undefined\') ? \'en\' : select2arrayoflanguage,
10437 containerCssClass: \':all:\', /* Line to add class from the original SELECT propagated to the new <span class="select2-selection...> tag */
10439 escapeMarkup:
function (markup) {
return markup; },
10440 minimumInputLength:
' . ((int) $minimumInputLength) . ',
10441 formatResult:
function (result, container, query, escapeMarkup) {
10442 return escapeMarkup(result.text);
10444 matcher:
function (params, data) {
10446 if(! data.id)
return null;
';
10448 if ($callurlonselect) {
10449 // We forge the url with 'sall=
'
10452 var urlBase = data.url;
10453 var separ = urlBase.indexOf(
"?") >= 0 ?
"&" :
"?";
10456 saveRemoteData[data.id].url = urlBase + separ +
"search_all=" + encodeURIComponent(params.term.replace(/\
"/g, ""));';
10459 if (!$disableFiltering) {
10462 if(data.text.match(new RegExp(params.term))) {
10477 ' . ($callurlonselect ? '
10478 /* Code to execute a GET when we select a value */
10479 $(\'.' . dol_escape_js($htmlname) . '\').change(function() {
10480 var selected = $(\'.' . dol_escape_js($htmlname) . '\').val();
10481 console.log("We select
"+selected)
10483 $(\'.' . dol_escape_js($htmlname) . '\').val(""); /* reset visible combo value */
10484 $.each( saveRemoteData, function( key, value ) {
10485 if (key == selected)
10487 console.log("selectArrayFilter - Do a redirect to
"+value.url)
10488 location.assign(value.url);
10497 if ($acceptdelayedhtml) {
10498 $delayedhtmlcontent .= $outdelayed;
10500 $out .= $outdelayed;
10523 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)
10525 global $conf, $langs;
10528 if ($addjscombo < 0) {
10529 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
10536 $useenhancedmultiselect = 0;
10537 if (!empty($conf->use_javascript_ajax) && !defined('MAIN_DO_NOT_USE_JQUERY_MULTISELECT') && (getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') || defined('REQUIRE_JQUERY_MULTISELECT'))) {
10539 $useenhancedmultiselect = 1; // Use the js multiselect in one line. Possible only if $addjscombo not 0.
10543 $out .= '<span class="multiselectarray
'.$htmlname.'">';
10545 // We need a hidden field because when using the multiselect, if we unselect all, there is no
10546 // variable submitted at all, so no way to make a difference between variable not submitted and variable
10547 // submitted to nothing.
10548 $out .= '<input type="hidden
" name="'.$htmlname.'_multiselect
" value="1
">';
10549 // Output select component
10550 $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
";
10551 if (is_array($array) && !empty($array)) {
10552 if ($value_as_key) {
10553 $array = array_combine($array, $array);
10556 if (!empty($array)) {
10557 foreach ($array as $key => $value) {
10559 $tmplabel = $value;
10560 $tmplabelhtml = '';
10564 if (is_array($value) && array_key_exists('id', $value) && array_key_exists('label', $value)) {
10565 $tmpkey = $value['id'];
10566 $tmplabel = empty($value['label']) ? '' : $value['label'];
10567 $tmplabelhtml = empty($value['labelhtml']) ? (empty($value['data-html']) ? '' : $value['data-html']) : $value['labelhtml'];
10568 $tmpcolor = empty($value['color']) ? '' : $value['color'];
10569 $tmppicto = empty($value['picto']) ? '' : $value['picto'];
10570 $tmpdisabled = empty($value['disabled']) ? '' : $value['disabled'];
10572 $newval = ($translate ? $langs->trans($tmplabel) : $tmplabel);
10573 $newval = ($key_in_label ? $tmpkey . ' - ' . $newval : $newval);
10575 $tmplabelhtml = ($translate ? $langs->trans($tmplabelhtml) : $tmplabelhtml);
10576 $tmplabelhtml = ($key_in_label ? $tmpkey . ' - ' . $tmplabelhtml : $tmplabelhtml);
10578 $out .= '<option value="' . $tmpkey . '"';
10579 if (is_array($selected) && !empty($selected) && in_array((string) $tmpkey, $selected) && ((string) $tmpkey != '')) {
10580 $out .= ' selected';
10582 $out .= is_array($value) && array_key_exists('parent', $value) && !empty($value['parent']) ? ' parent="' . dolPrintHTMLForAttribute($value['parent
']) . '"' : '';
10583 if ($tmpdisabled) {
10586 if (!empty($tmplabelhtml)) {
10587 $out .= ' data-html="' . dolPrintHTMLForAttribute($tmplabelhtml) . '"';
10589 $tmplabelhtml = ($tmppicto ? img_picto('', $tmppicto, 'class="pictofixedwidth
" style="color: #
' . $tmpcolor . '"') : '') . $newval;
10590 $out .= ' data-html="' . dolPrintHTMLForAttribute($tmplabelhtml) . '"';
10593 $out .= dol_htmlentitiesbr($newval);
10594 $out .= '</option>' . "\n
";
10598 $out .= '</select>' . "\n
";
10602 // Add code for jquery to use multiselect
10603 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') || defined('REQUIRE_JQUERY_MULTISELECT')) {
10604 $out .= "\n
" . '<!-- JS CODE TO ENABLE select for id ' . $htmlname . ', addjscombo=' . $addjscombo . ' -->';
10605 $out .= "\n
" . '<script nonce="' . getNonce() . '">' . "\n
";
10606 if ($addjscombo == 1) {
10607 $tmpplugin = getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT', (defined('REQUIRE_JQUERY_MULTISELECT') ? constant('REQUIRE_JQUERY_MULTISELECT') : 'select2'));
10609 // If property data-html set, we decode html entities and use this.
10610 // Note that HTML content must have been sanitized from js with dol_escape_htmltag(xxx, 0, 0, '', 0, 1) when building the select option.
10611 // TODO Move this into common js ?
10612 $out .= 'function formatResult(record, container) {' . "\n
";
10613 $out .= ' if ($(record.element).attr("data-html
") != undefined && typeof htmlEntityDecodeJs === "function
") {';
10614 $out .= ' return htmlEntityDecodeJs($(record.element).attr("data-html
"));';
10616 $out .= ' return record.text;';
10617 $out .= '}' . "\n
";
10619 $out .= 'function formatSelection(record) {' . "\n
";
10620 $out .= ' return record.text;';
10621 $out .= '}' . "\n
";
10623 // Load the select2 enhancer
10624 //$out .= 'console.log(\'addjscombo=1 for htmlname=' . dol_escape_js($htmlname) . '\');';
10625 $out .= '$(document).ready(function () {
10626 $(\'#' . dol_escape_js($htmlname) . '\').' . $tmpplugin . '({';
10627 if ($placeholder) {
10631 text: \''.dol_escape_js($placeholder).'\'
10634 $out .= ' dir: \'ltr\',
10635 containerCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag (ko with multiselect) */
10636 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. */
10637 // Specify format function for dropdown item
10638 formatResult: formatResult,
10639 templateResult: formatResult, /* For 4.0 */
10640 escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
10641 // Specify format function for selected item
10642 formatSelection: formatSelection,
10643 templateSelection: formatSelection, /* For 4.0 */
10644 language: (typeof select2arrayoflanguage === \'undefined\') ? \'en\' : select2arrayoflanguage
10647 /* Add also morecss to the css .select2 that is after the #htmlname, for component that are shown dynamically after load, because select2 set
10648 the size only if component is not hidden by default on load */
10651 } elseif ($addjscombo == 2 && !defined(
'DISABLE_MULTISELECT')) {
10655 $out .=
'console.log(\'addjscombo=2 for htmlname=' .
dol_escape_js($htmlname) .
'\');
';
10656 $out .= '$(document).ready(
function () {
10658 containerHTML: \
'<div class="multi-select-container">\',
10659 menuHTML: \'<div class="multi-select-menu">\',
10660 buttonHTML: \'<span class="multi-select-button ' .
dol_escape_js($morecss) .
'">\',
10661 menuItemHTML: \'<label class="multi-select-menuitem">\',
10662 activeClass: \'multi-select-container--open\',
10667 $out .= '</script>
';
10687 public static function multiSelectArrayWithCheckbox($htmlname, &$array, $varpage, $pos = '
', $draganddrop = 0)
10689 global $conf, $langs, $user;
10691 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER
')) {
10694 if (empty($array)) {
10698 $tmpvar = "MAIN_SELECTEDFIELDS_" . $varpage; // To get list of saved selected fields to show
10700 if (!empty($user->conf->$tmpvar)) { // A list of fields was already customized for user
10701 $tmparray = explode(',
', $user->conf->$tmpvar);
10702 foreach ($array as $key => $val) {
10704 //var_dump($tmparray);
10705 if (in_array($key, $tmparray)) {
10706 $array[$key]['checked
'] = 1;
10708 $array[$key]['checked
'] = 0;
10711 } else { // There is no list of fields already customized for user
10712 foreach ($array as $key => $val) {
10713 if (!empty($array[$key]['checked
']) && $array[$key]['checked
'] < 0) {
10714 $array[$key]['checked
'] = 0;
10719 $listoffieldsforselection = '';
10720 $listcheckedstring = '';
10722 foreach ($array as $key => $val) {
10724 // var_dump(array_key_exists('enabled
', $val));
10725 // var_dump(!$val['enabled
']);
10726 if (array_key_exists('enabled
', $val) && isset($val['enabled
']) && !$val['enabled
']) {
10727 unset($array[$key]); // We don't want
this field
10730 if (!empty($val[
'type']) && $val[
'type'] ==
'separate') {
10735 if (!empty($val[
'label']) && $val[
'label']) {
10736 if (!empty($val[
'langfile']) && is_object($langs)) {
10737 $langs->load($val[
'langfile']);
10741 $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']).
'" />';
10742 $listoffieldsforselection .=
'<label for="checkbox' . $key .
'" class="paddingleft">';
10744 $listoffieldsforselection .=
'</label>';
10745 if (!empty($draganddrop)) {
10746 $listoffieldsforselection .=
img_picto($langs->trans(
"MoveField", !empty($key) ? $key :
'none'),
'grip_title',
'class="opacitymedium boxhandle hideonsmartphone cursormove marginleftonly"');
10748 $listoffieldsforselection .=
'</li>';
10749 $listcheckedstring .= (empty($val[
'checked']) ?
'' : $key .
',');
10753 $out =
'<!-- Component multiSelectArrayWithCheckbox ' . $htmlname .
' -->
10755 <dl class="dropdown">
10757 <a href="#' . $htmlname .
'" class="multiselectpicto">
10760 <input type="hidden" class="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $listcheckedstring .
'">
10762 <dd class="dropdowndd">
10763 <div class="multiselectcheckbox'.$htmlname.
'">
10764 <ul class="'.$htmlname.(((string) $pos ==
'1' || (
string) $pos ==
'left') ?
'left' :
'').(!empty($draganddrop) ?
' sortable' :
'').
'">
10765 <li class="liinputsearch">
10766 <input class="inputsearch_dropdownselectedfields width90p minwidth200imp" style="width:90%;" type="text" placeholder="'.$langs->trans(
'Search').
'">
10768 '.$listoffieldsforselection.
'
10775 function updateFieldOrder() {
10776 var positionfields = $(".sortable").sortable("toArray");
10778 url: \''.DOL_URL_ROOT.
'/core/ajax/changepositionfields.php?positionfields=\'+positionfields+\'&token='.
newToken().
'&action=listafterchangingpositionfields&contextpage='.$varpage.
'&userid='.$user->id.
'\',
10780 success: function () {
10782 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'";
10786 $( ".sortable" ).sortable({
10787 handle: \'.boxhandle\',
10788 revert: \'invalid\',
10789 items: \'.fieldsortable\',
10790 stop: function(event, ui) {
10791 console.log("We moved box so we call updateBoxOrder with ajax actions");
10792 updateFieldOrder(); /* 1 to avoid message after a move */
10797 <script nonce="' .
getNonce() .
'" type="text/javascript">
10798 jQuery(document).ready(function () {
10799 $(\'.multiselectcheckbox' . $htmlname .
' input[type="checkbox"]\').on("click", function () {
10800 console.log("A new field was added/removed, we edit field input[name=formfilteraction]");
10802 $("input:hidden[name=formfilteraction]").val(\'listafterchangingselectedfields\'); // Update field so we know we changed something on selected fields after POST
10804 var title = $(this).val() + ",";
10805 if ($(this).is(\':checked\')) {
10806 $(\'.' . $htmlname .
'\').val(title + $(\'.' . $htmlname .
'\').val());
10809 $(\'.' . $htmlname .
'\').val( $(\'.' . $htmlname .
'\').val().replace(title, \'\') )
10811 // Now, we submit page
10812 //$(this).parents(\'form:first\').submit();
10815 $("input.inputsearch_dropdownselectedfields").on("keyup", function() {
10816 console.log("keyup on inputsearch_dropdownselectedfields");
10817 var value = $(this).val().toLowerCase();
10818 $(\'.multiselectcheckbox'.$htmlname.
' li > label\').filter(function() {
10819 $(this).parent().toggle($(this).text().toLowerCase().indexOf(value) > -1)
10823 if (empty(
$conf->browser->layout) ||
$conf->browser->layout !=
'phone') {
10825 $(".dropdown dt a").on("click", function () {
10826 console.log("Click on dropdown, we set focus to search field");
10827 setTimeout(() => { $(\'.inputsearch_dropdownselectedfields\').focus(); }, 200);
10851 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
10854 $categories = $cat->containing(
$id, $type);
10856 if ($rendermode == 1 || $rendermode == 2) {
10857 $toprint = array();
10858 foreach ($categories as
$c) {
10859 $ways =
$c->print_all_ways(
'auto', ($nolink ?
'none' :
''), 0, 1, ($rendermode == 2 ? 0 : 1));
10860 foreach ($ways as $way) {
10861 $color =
$c->color;
10862 $sfortag =
'<li class="select2-search-choice-dolibarr noborderoncategories'.(empty($toprint) ?
' nomarginleft' :
'');
10863 $forced_color =
'categtextwhite';
10865 $forced_color =
'categtextblack';
10867 $sfortag .=
' '.$forced_color;
10869 $sfortag .= ($color ?
' style="background: #' . $color .
';"' :
' style="background: #bbb"');
10870 $titlestring = $ways[0];
10874 if ($rendermode == 1) {
10875 $sfortag .=
'<a href="'.DOL_URL_ROOT.
'/categories/viewcat.php?id='.((int)
$c->id).
'&type='.urlencode(
$c->type).
'" class="'.$forced_color.
'">';
10876 $sfortag .=
img_picto(
'',
'category',
'class="paddingright"');
10877 if (
$conf->dol_optimize_smallscreen) {
10882 $sfortag .=
'</a>';
10886 $sfortag .=
'</li>';
10888 $toprint[] = $sfortag;
10891 if (empty($toprint)) {
10894 return '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
10898 if ($rendermode == 0) {
10899 $arrayselected = array();
10900 $cate_arbo = $this->select_all_categories($type,
'',
'parent', 64, 0, 3);
10901 foreach ($categories as
$c) {
10902 $arrayselected[(
string)
$c->id] = (
string)
$c->id;
10905 return $this->multiselectarray(
'categories', $cate_arbo, $arrayselected, 0, 0,
'', 0,
'100%',
'disabled',
'category');
10908 return 'ErrorBadValueForParameterRenderMode';
10922 global
$conf, $langs, $hookmanager;
10928 $object->fetchObjectLinked();
10931 $hookmanager->initHooks(array(
'commonobject'));
10932 $parameters = array(
10933 'morehtmlright' => $morehtmlright,
10934 'compatibleImportElementsList' => &$compatibleImportElementsList,
10936 $reshook = $hookmanager->executeHooks(
'showLinkedObjectBlock', $parameters,
$object, $action);
10938 $nbofdifferenttypes = count(
$object->linkedObjects);
10940 if (empty($reshook)) {
10941 print
'<!-- showLinkedObjectBlock -->';
10942 print
load_fiche_titre($langs->trans($title), $morehtmlright,
'', 0,
'',
'showlinkedobjectblock');
10945 print
'<div class="div-table-responsive-no-min">';
10946 print
'<table class="noborder allwidth" data-block="showLinkedObject" data-element="' .
$object->element .
'" data-elementid="' .
$object->id .
'" >';
10948 print
'<tr class="liste_titre">';
10949 print
'<td>' . $langs->trans(
"Type") .
'</td>';
10950 print
'<td>' . $langs->trans(
"Ref") .
'</td>';
10953 print
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
10954 print
'<td class="right">' . $langs->trans(
"Status") .
'</td>';
10958 $nboftypesoutput = 0;
10960 foreach (
$object->linkedObjects as $objecttype => $objects) {
10961 $tplpath = $element = $subelement = $objecttype;
10964 global $showImportButton;
10965 $showImportButton =
false;
10966 if (!empty($compatibleImportElementsList) && in_array($element, $compatibleImportElementsList)) {
10967 $showImportButton =
true;
10972 if ($objecttype !=
'supplier_proposal' && preg_match(
'/^([^_]+)_([^_]+)/i', $objecttype, $regs)) {
10973 $element = $regs[1];
10974 $subelement = $regs[2];
10975 $tplpath = $element .
'/' . $subelement;
10977 $tplname =
'linkedobjectblock';
10980 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $objecttype, $regs)) {
10981 $element = $regs[1];
10982 $module = $regs[2];
10983 $tplpath = $module.
'/' . $element;
10984 $tplname = $tplname.
'_'.$element;
10988 if ($objecttype ==
'facture') {
10989 $tplpath =
'compta/' . $element;
10993 } elseif ($objecttype ==
'facturerec') {
10994 $tplpath =
'compta/facture';
10995 $tplname =
'linkedobjectblockForRec';
10999 } elseif ($objecttype ==
'propal') {
11000 $tplpath =
'comm/' . $element;
11004 } elseif ($objecttype ==
'supplier_proposal') {
11008 } elseif ($objecttype ==
'shipping' || $objecttype ==
'shipment' || $objecttype ==
'expedition') {
11009 $tplpath =
'expedition';
11013 } elseif ($objecttype ==
'reception') {
11014 $tplpath =
'reception';
11018 } elseif ($objecttype ==
'delivery') {
11019 $tplpath =
'delivery';
11023 } elseif ($objecttype ==
'ficheinter') {
11024 $tplpath =
'fichinter';
11028 } elseif ($objecttype ==
'invoice_supplier') {
11029 $tplpath =
'fourn/facture';
11030 } elseif ($objecttype ==
'order_supplier') {
11031 $tplpath =
'fourn/commande';
11032 } elseif ($objecttype ==
'expensereport') {
11033 $tplpath =
'expensereport';
11034 } elseif ($objecttype ==
'subscription') {
11035 $tplpath =
'adherents';
11036 } elseif ($objecttype ==
'conferenceorbooth') {
11037 $tplpath =
'eventorganization';
11038 } elseif ($objecttype ==
'conferenceorboothattendee') {
11039 $tplpath =
'eventorganization';
11040 } elseif ($objecttype ==
'mo') {
11045 } elseif ($objecttype ==
'project_task') {
11046 $tplpath =
'projet/tasks';
11049 global $linkedObjectBlock;
11050 $linkedObjectBlock = $objects;
11053 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array(
'/' . $tplpath .
'/tpl'));
11055 foreach ($dirtpls as $reldir) {
11056 $reldir = rtrim($reldir,
'/');
11057 if ($nboftypesoutput == ($nbofdifferenttypes - 1)) {
11058 global $noMoreLinkedObjectBlockAfter;
11059 $noMoreLinkedObjectBlockAfter = 1;
11061 $file =
dol_buildpath($reldir .
'/' . $tplname .
'.tpl.php');
11062 if (file_exists($file)) {
11063 $res = @include $file;
11065 $nboftypesoutput++;
11072 if (!$nboftypesoutput) {
11073 print
'<tr><td colspan="7"><span class="opacitymedium">' . $langs->trans(
"None") .
'</span></td></tr>';
11078 if (!empty($compatibleImportElementsList)) {
11079 $res = @include
dol_buildpath(
'core/tpl/objectlinked_lineimport.tpl.php');
11085 return $nbofdifferenttypes;
11099 global
$conf, $langs, $hookmanager, $form;
11104 if (empty($form)) {
11105 $form =
new Form($this->db);
11109 $linktoelemlist =
'';
11110 $listofidcompanytoscan =
'';
11112 if (!is_object(
$object->thirdparty)) {
11113 if (
$object->element ==
'subscription' && isset(
$object->fk_adherent)) {
11119 $fk_adherent = $subby->fk_adherent;
11120 $adh->fetch($fk_adherent);
11121 $thirdparty_id = $adh->fetch_thirdparty();
11124 $thirdparty_id =
$object->thirdparty->id;
11127 $possiblelinks = array();
11129 $dontIncludeCompletedItems =
getDolGlobalString(
'DONT_INCLUDE_COMPLETED_ELEMENTS_LINKS');
11131 if (!empty($thirdparty_id) && $thirdparty_id > 0) {
11132 $listofidcompanytoscan = (int) $thirdparty_id;
11134 $listofidcompanytoscan .=
',' . (int)
$object->thirdparty->parent;
11137 include_once DOL_DOCUMENT_ROOT .
'/projet/class/project.class.php';
11138 $tmpproject =
new Project($this->db);
11139 $tmpproject->fetch((
int)
$object->fk_project);
11140 if ($tmpproject->socid > 0 && ($tmpproject->socid != $thirdparty_id)) {
11141 $listofidcompanytoscan .=
',' . (int) $tmpproject->socid;
11143 unset($tmpproject);
11146 $possiblelinks = array(
11150 'label' =>
'LinkToProposal',
11151 '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' :
''),
11153 'shipping' => array(
11156 'label' =>
'LinkToExpedition',
11157 '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' :
''),
11162 'label' =>
'LinkToOrder',
11163 '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' :
''),
11164 'linkname' =>
'commande',
11166 'subscription' => array(
11169 'label' =>
'LinkToMemberSubscription',
11170 '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') .
')',
11171 'linkname' =>
'subscription',
11173 'conferenceorboothattendee' => array(
11176 'label' =>
'LinkToConferenceOrBoothAttendee',
11177 '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),
11178 'linkname' =>
'attendee'
11180 'invoice' => array(
11183 'label' =>
'LinkToInvoice',
11184 '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' :
''),
11185 'linkname' =>
'facture',
11187 'invoice_template' => array(
11190 'label' =>
'LinkToTemplateInvoice',
11191 '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') .
')',
11193 'contrat' => array(
11196 'label' =>
'LinkToContract',
11197 '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
11198 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',
11200 'fichinter' => array(
11203 'label' =>
'LinkToIntervention',
11204 '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') .
')',
11206 'supplier_proposal' => array(
11209 'label' =>
'LinkToSupplierProposal',
11210 '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' :
''),
11212 'order_supplier' => array(
11215 'label' =>
'LinkToSupplierOrder',
11216 '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' :
''),
11218 'invoice_supplier' => array(
11220 'perms' => 1,
'label' =>
'LinkToSupplierInvoice',
11221 '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' :
''),
11226 'label' =>
'LinkToTicket',
11227 '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' :
''),
11232 'label' =>
'LinkToMo',
11233 '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' :
''),
11238 if (
$object->table_element ==
'commande_fournisseur') {
11239 $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' :
'');
11240 } elseif (
$object->table_element ==
'mrp_mo') {
11241 $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' :
'');
11245 if (!empty($listofidcompanytoscan)) {
11247 $hookmanager->initHooks(array(
'commonobject'));
11248 $parameters = array(
'listofidcompanytoscan' => $listofidcompanytoscan,
'possiblelinks' => $possiblelinks);
11249 $reshook = $hookmanager->executeHooks(
'showLinkToObjectBlock', $parameters,
$object, $action);
11252 if (empty($reshook)) {
11253 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
11254 $possiblelinks = array_merge($possiblelinks, $hookmanager->resArray);
11256 } elseif ($reshook > 0) {
11257 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
11258 $possiblelinks = $hookmanager->resArray;
11262 if (!empty($possiblelinks)) {
11263 $object->fetchObjectLinked();
11267 $htmltoenteralink =
'';
11268 foreach ($possiblelinks as $key => $possiblelink) {
11270 if (empty($possiblelink[
'enabled'])) {
11277 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $key, $regs)) {
11279 $module = $regs[2];
11282 if (!empty($possiblelink[
'perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || !in_array($key, $excludelinksto))) {
11283 $htmltoenteralink .=
'<div id="' . $key .
'list"' . (empty(
$conf->use_javascript_ajax) ?
'' :
' style="display:none"') .
'>';
11287 $htmltoenteralink .=
'<br>'.
"\n";
11288 $htmltoenteralink .=
'<!-- form to add a link from anywhere -->'.
"\n";
11289 $htmltoenteralink .=
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinkedbyref' . $key .
'">';
11290 $htmltoenteralink .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
11291 $htmltoenteralink .=
'<input type="hidden" name="action" value="addlinkbyref">';
11292 $htmltoenteralink .=
'<input type="hidden" name="id" value="' .
$object->id .
'">';
11293 $htmltoenteralink .=
'<input type="hidden" name="addlink" value="' . $key .(!empty($module) ?
'@'.$module :
'').
'">';
11294 $htmltoenteralink .=
'<table class="noborder">';
11295 $htmltoenteralink .=
'<tr class="liste_titre">';
11297 $htmltoenteralink .=
'<td class="center"><input type="text" placeholder="'.dol_escape_htmltag($langs->trans(
"Ref")).
'" name="reftolinkto" value="' .
dol_escape_htmltag(
GETPOST(
'reftolinkto',
'alpha')) .
'">';
11298 $htmltoenteralink .=
'<br>';
11299 $htmltoenteralink .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
'ToLink') .
'"> ';
11300 $htmltoenteralink .=
'<input type="submit" class="button smallpaddingimp" name="cancel" value="' . $langs->trans(
'Cancel') .
'">';
11301 $htmltoenteralink .=
'</td>';
11302 $htmltoenteralink .=
'</tr>';
11303 $htmltoenteralink .=
'</table>';
11304 $htmltoenteralink .=
'</form>';
11307 $sql = $possiblelink[
'sql'];
11309 $resqllist = $this->db->query($sql);
11311 $num = $this->db->num_rows($resqllist);
11316 $htmltoenteralink .=
'<br>';
11318 $htmltoenteralink .=
'<!-- form to add a link from object to same thirdparty -->'.
"\n";
11319 $htmltoenteralink .=
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinked' . $key .
'">';
11320 $htmltoenteralink .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
11321 $htmltoenteralink .=
'<input type="hidden" name="action" value="addlink">';
11322 $htmltoenteralink .=
'<input type="hidden" name="id" value="' .
$object->id .
'">';
11323 $htmltoenteralink .=
'<input type="hidden" name="addlink" value="' . $key . (!empty($module) ?
'@'.$module :
'').
'">';
11324 $htmltoenteralink .=
'<table class="noborder">';
11327 case 'conferenceorboothattendee':
11329 $htmltoenteralink .= $this->makeAddLinkToAttendee(
$object, $key, $possiblelink, $num, $resqllist);
11334 $htmltoenteralink .= $this->makeAddLinkToObject(
$object, $key, $possiblelink, $num, $resqllist);
11338 $htmltoenteralink .=
'</table>';
11339 $htmltoenteralink .=
'<div class="center">';
11341 $htmltoenteralink .=
'<input type="submit" class="button valignmiddle marginleftonly marginrightonly smallpaddingimp" value="' . $langs->trans(
'ToLink') .
'">';
11343 if (empty(
$conf->use_javascript_ajax)) {
11344 $htmltoenteralink .=
'<input type="submit" class="button button-cancel marginleftonly marginrightonly smallpaddingimp" name="cancel" value="' . $langs->trans(
"Cancel") .
'"></div>';
11346 $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>';
11348 $htmltoenteralink .=
'</form>';
11351 $this->db->free($resqllist);
11355 $htmltoenteralink .=
'</div>';
11360 $linktoelemlist .=
'<li><a href="#linkto' . $key .
'" class="linkto dropdowncloseonclick" rel="' . $key .
'">' . $langs->trans($possiblelink[
'label']) .
' (' . $num .
')</a></li>';
11363 $linktoelemlist .=
'<li><span class="linktodisabled">' . $langs->trans($possiblelink[
'label']) .
' (0)</span></li>';
11368 if ($linktoelemlist) {
11370 <dl class="dropdown" id="linktoobjectname">
11372 if (!empty(
$conf->use_javascript_ajax)) {
11373 $linktoelem .=
'<dt><a href="#linktoobjectname"><span class="fas fa-link paddingrightonly"></span>' . $langs->trans(
"LinkTo") .
'...</a></dt>';
11375 $linktoelem .=
'<dd>
11376 <div class="multiselectlinkto">
11377 <ul class="ulselectedfields">' . $linktoelemlist .
'
11386 if (!empty(
$conf->use_javascript_ajax)) {
11387 print
'<!-- Add js to show linkto box -->
11388 <script nonce="' .
getNonce() .
'">
11389 jQuery(document).ready(function() {
11390 jQuery(".linkto").click(function() {
11391 console.log("We choose to show/hide links for rel="+jQuery(this).attr(\'rel\')+" so #"+jQuery(this).attr(\'rel\')+"list");
11392 jQuery("#"+jQuery(this).attr(\'rel\')+"list").toggle();
11400 return array(
'linktoelem' => $linktoelem,
'htmltoenteralink' => $htmltoenteralink);
11402 print $htmltoenteralink;
11405 return $linktoelem;
11422 public function selectyesno($htmlname, $value =
'', $option = 0, $disabled =
false, $useempty = 0, $addjscombo = 0, $morecss =
'yesno width75', $labelyes =
'Yes', $labelno =
'No')
11433 $disabled = ($disabled ?
' disabled' :
'');
11435 $resultyesno =
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'"' . $disabled .
'>' .
"\n";
11437 $resultyesno .=
'<option value="-1"' . (($value < 0) ?
' selected' :
'') .
'> </option>' .
"\n";
11439 if ((
"$value" ==
'yes') || ($value == 1)) {
11440 $resultyesno .=
'<option value="' . $yes .
'" selected>' . $langs->trans($labelyes) .
'</option>' .
"\n";
11441 $resultyesno .=
'<option value="' . $no .
'">' . $langs->trans($labelno) .
'</option>' .
"\n";
11443 $selected = (($useempty && $value !=
'0' && $value !=
'no') ?
'' :
' selected');
11444 $resultyesno .=
'<option value="' . $yes .
'">' . $langs->trans($labelyes) .
'</option>' .
"\n";
11445 $resultyesno .=
'<option value="' . $no .
'"' . $selected .
'>' . $langs->trans($labelno) .
'</option>' .
"\n";
11447 $resultyesno .=
'</select>' .
"\n";
11450 $resultyesno .=
ajax_combobox($htmlname, array(), 0, 0,
'resolve', ($useempty < 0 ? (
string) $useempty :
'-1'), $morecss);
11453 return $resultyesno;
11470 $sql =
"SELECT rowid, label";
11471 $sql .=
" FROM " . $this->db->prefix() .
"export_model";
11472 $sql .=
" WHERE type = '" . $this->db->escape($type) .
"'";
11473 $sql .=
" ORDER BY rowid";
11474 $result = $this->db->query($sql);
11476 print
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
11478 print
'<option value="-1"> </option>';
11481 $num = $this->db->num_rows($result);
11483 while ($i < $num) {
11484 $obj = $this->db->fetch_object($result);
11485 if ($selected == $obj->rowid) {
11486 print
'<option value="' . $obj->rowid .
'" selected>';
11488 print
'<option value="' . $obj->rowid .
'">';
11518 public function showrefnav(
$object, $paramid, $morehtml =
'', $shownav = 1, $fieldid =
'rowid', $fieldref =
'ref', $morehtmlref =
'', $moreparam =
'', $nodbprefix = 0, $morehtmlleft =
'', $morehtmlstatus =
'', $morehtmlright =
'')
11520 global
$conf, $langs, $hookmanager, $extralanguages;
11523 if (empty($fieldid)) {
11524 $fieldid =
'rowid';
11526 if (empty($fieldref)) {
11531 $addgendertxt =
'';
11532 if (property_exists(
$object,
'gender') && !empty(
$object->gender)) {
11533 $addgendertxt =
' ';
11536 $addgendertxt .=
'<i class="fas fa-mars valignmiddle"></i>';
11539 $addgendertxt .=
'<i class="fas fa-venus valignmiddle"></i>';
11542 $addgendertxt .=
'<i class="fas fa-transgender valignmiddle"></i>';
11548 if (is_object($hookmanager)) {
11549 $parameters = array(
'showrefnav' =>
true);
11550 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters,
$object);
11551 if (!empty($hookmanager->resPrint)) {
11552 if (empty(
$object->next_prev_filter) && preg_match(
'/^\s*AND/i', $hookmanager->resPrint)) {
11553 $object->next_prev_filter = (
string) preg_replace(
'/^\s*AND\s*/i',
'', $hookmanager->resPrint);
11554 } elseif (!empty(
$object->next_prev_filter) && !preg_match(
'/^\s*AND/i', $hookmanager->resPrint)) {
11555 $object->next_prev_filter .=
' AND '.$hookmanager->resPrint;
11557 $object->next_prev_filter .= $hookmanager->resPrint;
11562 $previous_ref = $next_ref =
'';
11565 $object->load_previous_next_ref((isset(
$object->next_prev_filter) ?
$object->next_prev_filter :
''), $fieldid, $nodbprefix);
11567 $navurl = $_SERVER[
"PHP_SELF"];
11570 if ($paramid ==
'api_token_card') {
11571 if (preg_match(
'/\/user\/api_token/', $navurl)) {
11572 $navurl = preg_replace(
'/card/',
'list', $navurl);
11578 if ($paramid ==
'project_ref') {
11579 if (preg_match(
'/\/tasks\/(task|contact|note|document)\.php/', $navurl)) {
11580 $navurl = preg_replace(
'/\/tasks\/(task|contact|time|note|document)\.php/',
'/tasks.php', $navurl);
11585 $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>';
11586 $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>';
11590 $ret .=
'<!-- Start banner content --><div style="vertical-align: middle">';
11593 if ($morehtmlright) {
11594 $ret .=
'<div class="inline-block floatleft">' . $morehtmlright .
'</div>';
11597 if ($previous_ref || $next_ref || $morehtml) {
11598 $ret .=
'<div class="pagination paginationref"><ul class="right">';
11600 if ($morehtml &&
getDolGlobalInt(
'MAIN_OPTIMIZEFORTEXTBROWSER') < 2) {
11601 $ret .=
'<!-- morehtml --><li class="noborder litext' . (($shownav && $previous_ref && $next_ref) ?
' clearbothonsmartphone' :
'') .
'">' . $morehtml .
'</li>';
11603 if ($shownav && ($previous_ref || $next_ref)) {
11604 $ret .=
'<li class="pagination">' . $previous_ref .
'</li>';
11605 $ret .=
'<li class="pagination">' . $next_ref .
'</li>';
11607 if ($previous_ref || $next_ref || $morehtml) {
11608 $ret .=
'</ul></div>';
11612 $parameters = array(
'morehtmlstatus' => $morehtmlstatus);
11613 $reshook = $hookmanager->executeHooks(
'moreHtmlStatus', $parameters,
$object);
11614 if (empty($reshook)) {
11615 $morehtmlstatus .= $hookmanager->resPrint;
11617 $morehtmlstatus = $hookmanager->resPrint;
11619 if ($morehtmlstatus) {
11620 $ret .=
'<!-- status --><div class="statusref">' . $morehtmlstatus .
'</div>';
11623 $parameters = array();
11624 $reshook = $hookmanager->executeHooks(
'moreHtmlRef', $parameters,
$object);
11625 if (empty($reshook)) {
11626 $morehtmlref .= $hookmanager->resPrint;
11627 } elseif ($reshook > 0) {
11628 $morehtmlref = $hookmanager->resPrint;
11632 if ($morehtmlleft) {
11633 if (
$conf->browser->layout ==
'phone') {
11634 $ret .=
'<!-- morehtmlleft --><div class="floatleft">' . $morehtmlleft .
'</div>';
11636 $ret .=
'<!-- morehtmlleft --><div class="inline-block floatleft">' . $morehtmlleft .
'</div>';
11641 $ret .=
'<!-- Ref or ID --><div class="inline-block floatleft valignmiddle maxwidth750 marginbottomonly refid' . (($shownav && ($previous_ref || $next_ref)) ?
' refidpadding' :
'') .
'">';
11644 if (
$object->element ==
'societe') {
11645 $ret .=
'<span class="valignmiddle">'.dolPrintHTML((
string)
$object->name).
'</span>';
11648 $arrayoflangcode = array();
11653 if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
11654 if (!is_object($extralanguages)) {
11655 include_once DOL_DOCUMENT_ROOT .
'/core/class/extralanguages.class.php';
11658 $extralanguages->fetch_name_extralanguages(
'societe');
11662 if (!empty($extralanguages->attributes[
'societe']) && !empty($extralanguages->attributes[
'societe'][
'name'])) {
11663 $object->fetchValuesForExtraLanguages();
11667 foreach ($arrayoflangcode as $extralangcode) {
11669 if (
$object->array_languages[
'name'][$extralangcode]) {
11670 $htmltext .=
$object->array_languages[
'name'][$extralangcode];
11672 $htmltext .=
'<span class="opacitymedium">' . $langs->trans(
"SwitchInEditModeToAddTranslation") .
'</span>';
11675 $ret .=
'<!-- Show translations of name -->' .
"\n";
11676 $ret .= $this->textwithpicto(
'', $htmltext, -1,
'language',
'opacitymedium paddingleft');
11679 } elseif (
$object->element ==
'member') {
11680 '@phan-var-force Adherent $object';
11681 $ret .=
$object->ref .
'<br>';
11682 $fullname =
$object->getFullName($langs);
11684 $ret .=
'<span class="valignmiddle">'.dolPrintHTML((
string)
$object->societe) . ((!empty($fullname) &&
$object->societe != $fullname) ?
' (' .
dol_htmlentities($fullname) . $addgendertxt .
')' :
'').
'</span>';
11686 $ret .=
'<span class="valignmiddle">'.dolPrintHTML($fullname) . $addgendertxt . ((!empty(
$object->societe) &&
$object->societe != $fullname) ?
' (' .
dol_htmlentities((
string)
$object->societe) .
')' :
'').
'</span>';
11688 } elseif (in_array(
$object->element, array(
'contact',
'user'))) {
11689 $ret .=
'<span class="valignmiddle">'.dolPrintHTML(
$object->getFullName($langs)).
'</span>'.$addgendertxt;
11690 } elseif (
$object->element ==
'usergroup') {
11692 } elseif (in_array(
$object->element, array(
'action',
'agenda'))) {
11693 '@phan-var-force ActionComm $object';
11695 } elseif (in_array(
$object->element, array(
'adherent_type'))) {
11697 } elseif (
$object->element ==
'ecm_directories') {
11699 } elseif (
$object->element ==
'accountingbookkeeping' && !empty(
$object->context[
'mode']) &&
$object->context[
'mode'] ==
'_tmp') {
11700 $ret .=
'<span class="valignmiddle">'.$langs->trans(
"Draft").
'</span>';
11702 '@phan-var-force Ticket $object';
11703 $ret .=
'<span class="valignmiddle">'.dolPrintHTML(!empty(
$object->$fieldref) ?
$object->$fieldref :
"").
'</span>';
11704 $ret .=
' <span class="nobold small" title="'.dolPrintHTMLForAttribute($langs->trans(
"TicketTrackId")).
'">('.
$object->track_id.
')</span>';
11705 } elseif ($fieldref !=
'none') {
11707 $ret .=
'<span class="valignmiddle">'.dolPrintHTML(!empty(
$object->$fieldref) ?
$object->$fieldref :
"").
'</span>';
11709 if ($morehtmlref) {
11711 if (substr($morehtmlref, 0, 4) !=
'<div') {
11715 $ret .=
'<!-- morehtmlref -->'.$morehtmlref;
11720 $ret .=
'</div><!-- End banner content -->';
11737 if (empty(
$object->barcode)) {
11742 if (empty(
$object->barcode_type_code) || empty(
$object->barcode_type_coder)) {
11744 $result =
$object->fetchBarCode();
11747 return '<!-- ErrorFetchBarcode -->';
11752 $url = DOL_URL_ROOT .
'/viewimage.php?modulepart=barcode&generator=' . urlencode(
$object->barcode_type_coder) .
'&code=' . urlencode(
$object->barcode) .
'&encoding=' . urlencode(
$object->barcode_type_code);
11753 $out =
'<!-- url barcode = ' . $url .
' -->';
11754 $out .=
'<img src="' . $url .
'"' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
'>';
11777 public static function showphoto($modulepart,
$object, $width = 100, $height = 0, $caneditfield = 0, $cssclass =
'photowithmargin', $imagesize =
'', $addlinktofullsize = 1, $cache = 0, $forcecapture =
'', $noexternsourceoverwrite = 0, $usesharelinkifavailable = 0)
11786 $originalfile =
'';
11790 if ($modulepart ==
'societe') {
11791 $dir =
$conf->societe->multidir_output[$entity];
11794 if ((
string) $imagesize ==
'mini') {
11796 } elseif ((
string) $imagesize ==
'small') {
11805 } elseif ($modulepart ==
'contact') {
11806 $dir =
$conf->societe->multidir_output[$entity] .
'/contact';
11808 if (!empty($photo)) {
11810 if ((
string) $imagesize ==
'mini') {
11812 } elseif ((
string) $imagesize ==
'small') {
11817 $originalfile =
get_exdir(0, 0, 0, 0,
$object,
'contact') .
'photos/' . $photo;
11822 } elseif ($modulepart ==
'userphoto') {
11823 $dir =
$conf->user->dir_output;
11825 if (!empty($photo)) {
11827 if ((
string) $imagesize ==
'mini') {
11829 } elseif ((
string) $imagesize ==
'small') {
11834 $originalfile =
get_exdir(0, 0, 0, 0,
$object,
'user') .
'photos/' . $photo;
11838 $altfile =
$object->id .
".jpg";
11842 } elseif ($modulepart ==
'memberphoto') {
11843 $dir =
$conf->member->dir_output;
11845 if (!empty($photo)) {
11847 if ((
string) $imagesize ==
'mini') {
11849 } elseif ((
string) $imagesize ==
'small') {
11854 $originalfile =
get_exdir(0, 0, 0, 0,
$object,
'member') .
'photos/' . $photo;
11858 $altfile =
$object->id .
".jpg";
11865 if ($modulepart !=
"unknown" && method_exists(
$object,
'getDataToShowPhoto')) {
11866 $tmpdata =
$object->getDataToShowPhoto($modulepart, $imagesize);
11868 $dir = $tmpdata[
'dir'];
11869 $file = $tmpdata[
'file'];
11870 $originalfile = $tmpdata[
'originalfile'];
11871 $altfile = $tmpdata[
'altfile'];
11872 $email = $tmpdata[
'email'];
11873 $capture = $tmpdata[
'capture'];
11877 if ($forcecapture) {
11878 $capture = $forcecapture;
11884 if ($file && file_exists($dir .
"/" . $file)) {
11885 if ($addlinktofullsize) {
11887 if ($urladvanced) {
11888 $ret .=
'<a href="' . $urladvanced .
'">';
11890 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
11895 if ($usesharelinkifavailable) {
11897 $relativefileforecm = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT.
'/',
'/').
'/',
'', $dir.
'/'.$originalfile);
11899 require_once DOL_DOCUMENT_ROOT .
'/ecm/class/ecmfiles.class.php';
11901 $ecmfiles->fetch(0,
'', $relativefileforecm);
11903 $sharekey = (
string) $ecmfiles->share;
11906 if (!empty($sharekey)) {
11907 $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) .
'">';
11909 $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) .
'">';
11911 if ($addlinktofullsize) {
11914 } elseif ($altfile && file_exists($dir .
"/" . $altfile)) {
11915 if ($addlinktofullsize) {
11917 if ($urladvanced) {
11918 $ret .=
'<a href="' . $urladvanced .
'">';
11920 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
11923 $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) .
'">';
11924 if ($addlinktofullsize) {
11928 $nophoto =
'/public/theme/common/nophoto.png';
11929 $defaultimg =
'identicon';
11930 if (in_array($modulepart, array(
'societe',
'userphoto',
'contact',
'memberphoto'))) {
11931 if ($modulepart ==
'societe' || ($modulepart ==
'memberphoto' && !empty(
$object->morphy) && strpos(
$object->morphy,
'mor') !==
false)) {
11932 $nophoto =
'company';
11934 $nophoto =
'/public/theme/common/user_anonymous.png';
11936 $nophoto =
'/public/theme/common/user_man.png';
11939 $nophoto =
'/public/theme/common/user_woman.png';
11944 if (
isModEnabled(
'gravatar') && $email && empty($noexternsourceoverwrite)) {
11946 $ret .=
'<!-- Put link to gravatar -->';
11947 $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 .
'">';
11949 if ($nophoto ==
'company') {
11950 $ret .=
'<div class="divforspanimg valignmiddle inline-block center photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
'>' .
img_picto(
'',
'company') .
'</div>';
11953 $ret .=
'<img class="photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="' . DOL_URL_ROOT . $nophoto .
'">';
11958 if ($caneditfield) {
11962 $ret .=
'<table class="nobordernopadding centpercent">';
11964 $ret .=
'<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> <label for="photodelete">' . $langs->trans(
"Delete") .
'</label><br><br></td></tr>';
11966 $ret .=
'<tr><td class="tdoverflow">';
11968 $maxmin = $maxfilesizearray[
'maxmin'];
11970 $ret .=
'<input type="hidden" name="MAX_FILE_SIZE" value="' . ($maxmin * 1024) .
'">';
11972 $ret .=
'<input type="file" class="flat maxwidth200onsmartphone" name="photo" id="photoinput" accept="image/*"' . ($capture ?
' capture="' .
dolPrintHTMLForAttribute($capture) .
'"' :
'') .
'>';
11973 $ret .=
'</td></tr>';
11974 $ret .=
'</table>';
11999 public function select_dolgroups($selected = 0, $htmlname =
'groupid', $show_empty = 0, $exclude =
'', $disabled = 0, $include =
'', $enableonly = array(), $force_entity =
'0', $multiple =
false, $morecss =
'minwidth200')
12002 global
$conf, $user, $langs;
12005 $excludeGroups =
null;
12006 if (is_array($exclude)) {
12007 $excludeGroups = implode(
",", $exclude);
12010 $includeGroups =
null;
12011 if (is_array($include)) {
12012 $includeGroups = implode(
",", $include);
12015 if (!is_array($selected)) {
12016 $selected = array($selected);
12022 $sql =
"SELECT ug.rowid, ug.nom as name";
12023 if (
isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && !$user->entity) {
12024 $sql .=
", e.label";
12026 $sql .=
" FROM " . $this->db->prefix() .
"usergroup as ug ";
12027 if (
isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && !$user->entity) {
12028 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid=ug.entity";
12029 if ($force_entity) {
12030 $sql .=
" WHERE ug.entity IN (0, " . ((int) $force_entity) .
")";
12032 $sql .=
" WHERE ug.entity IS NOT NULL";
12035 $sql .=
" WHERE ug.entity IN (0, " . ((int)
$conf->entity) .
")";
12037 if (is_array($exclude) && $excludeGroups) {
12038 $sql .=
" AND ug.rowid NOT IN (" . $this->db->sanitize($excludeGroups) .
")";
12040 if (is_array($include) && $includeGroups) {
12041 $sql .=
" AND ug.rowid IN (" . $this->db->sanitize($includeGroups) .
")";
12043 $sql .=
" ORDER BY ug.nom ASC";
12045 dol_syslog(get_class($this) .
"::select_dolgroups", LOG_DEBUG);
12046 $resql = $this->db->query($sql);
12049 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
12051 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
12053 $num = $this->db->num_rows($resql);
12056 if ($show_empty && !$multiple) {
12057 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'> </option>' .
"\n";
12060 while ($i < $num) {
12061 $obj = $this->db->fetch_object($resql);
12063 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
12067 $label = $obj->name;
12068 $labelhtml = $obj->name;
12070 $label .=
" (" . $obj->label .
")";
12071 $labelhtml .=
' <span class="opacitymedium">(' . $obj->label .
')</span>';
12074 $out .=
'<option value="' . $obj->rowid .
'"';
12075 if ($disableline) {
12076 $out .=
' disabled';
12078 if ((isset($selected[0]) && is_object($selected[0]) && $selected[0]->
id == $obj->rowid)
12079 || ((!isset($selected[0]) || !is_object($selected[0])) && !empty($selected) && in_array($obj->rowid, $selected))) {
12080 $out .=
' selected';
12082 $out .=
' data-html="'.dol_escape_htmltag($labelhtml).
'"';
12085 $out .=
'</option>';
12090 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'></option>' .
"\n";
12092 $out .=
'<option value="" disabled>' . $langs->trans(
"NoUserGroupDefined") .
'</option>';
12094 $out .=
'</select>';
12113 $out =
'<div class="nowraponall">';
12114 $out .=
'<button type="submit" class="liste_titre button_search reposition" name="button_search_x" value="x"><span class="fas fa-search"></span></button>';
12115 $out .=
'<button type="submit" class="liste_titre button_removefilter reposition" name="button_removefilter_x" value="x"><span class="fas fa-times"></span></button>';
12129 public function showCheckAddButtons($cssclass =
'checkforaction', $calljsfunction = 0, $massactionname =
"massaction")
12135 if (!empty(
$conf->use_javascript_ajax)) {
12136 $out .=
'<div class="inline-block checkallactions"><input type="checkbox" id="' . $cssclass .
's" name="' . $cssclass .
's" class="checkallactions"></div>';
12138 $out .=
'<script nonce="' .
getNonce() .
'">
12139 $(document).ready(function() {
12140 $("#' . $cssclass .
's").click(function() {
12141 if($(this).is(\':checked\')){
12142 console.log("We check all ' . $cssclass .
' and trigger the change method");
12143 $(".' . $cssclass .
'").prop(\'checked\', true).trigger(\'change\');
12147 console.log("We uncheck all");
12148 $(".' . $cssclass .
'").prop(\'checked\', false).trigger(\'change\');
12150 if ($calljsfunction) {
12151 $out .=
'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0, "' . $massactionname .
'", "' . $cssclass .
'"); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }';
12155 $(".' . $cssclass .
'").change(function() {
12156 console.log("We check and change the tr class highlight after a change on .'.$cssclass.
'");
12157 var $row = $(this).closest("tr");
12159 var anyChecked = $row.find(\'input[type="checkbox"].checkforselect:checked\').length > 0;
12160 console.log("anychecked="+anyChecked);
12162 $row.removeClass("highlight");
12164 $row.addClass("highlight");
12186 $out = $this->showFilterButtons();
12187 if ($addcheckuncheckall) {
12188 $out .= $this->showCheckAddButtons($cssclass, $calljsfunction, $massactionname);
12206 public function selectExpenseCategories($selected =
'', $htmlname =
'fk_c_exp_tax_cat', $useempty = 0, $excludeid = array(), $target =
'', $default_selected = 0, $params = array(), $info_admin = 1)
12208 global $langs, $user;
12211 $sql =
"SELECT rowid, label FROM " . $this->db->prefix() .
"c_exp_tax_cat WHERE active = 1";
12212 $sql .=
" AND entity IN (0," .
getEntity(
'exp_tax_cat') .
")";
12213 if (!empty($excludeid)) {
12214 $sql .=
" AND rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeid)) .
")";
12216 $sql .=
" ORDER BY label";
12218 $resql = $this->db->query($sql);
12220 $out =
'<select id="select_' . $htmlname .
'" name="' . $htmlname .
'" class="' . $htmlname .
' flat minwidth75imp maxwidth200">';
12222 $out .=
'<option value="0"> </option>';
12225 while ($obj = $this->db->fetch_object($resql)) {
12226 $out .=
'<option ' . ($selected == $obj->rowid ?
'selected="selected"' :
'') .
' value="' . $obj->rowid .
'">' . $langs->trans($obj->label) .
'</option>';
12228 $out .=
'</select>';
12231 if (!empty($htmlname) && $user->admin && $info_admin) {
12232 $out .=
' ' .
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
12235 if (!empty($target)) {
12236 $sql =
"SELECT c.id FROM " . $this->db->prefix() .
"c_type_fees as c WHERE c.code = 'EX_KME' AND c.active = 1";
12237 $resql = $this->db->query($sql);
12239 if ($this->db->num_rows($resql) > 0) {
12240 $obj = $this->db->fetch_object($resql);
12241 $out .=
'<script nonce="' .
getNonce() .
'">
12243 $("select[name=' . $target .
']").on("change", function() {
12244 var current_val = $(this).val();
12245 if (current_val == ' . $obj->id .
') {';
12246 if (!empty($default_selected) || !empty($selected)) {
12247 $out .=
'$("select[name=' . $htmlname .
']").val("' . ($default_selected > 0 ? $default_selected : $selected) .
'");';
12251 $("select[name=' . $htmlname .
']").change();
12255 $("select[name=' . $htmlname .
']").change(function() {
12257 if ($("select[name=' . $target .
']").val() == ' . $obj->id .
') {
12258 // get price of kilometer to fill the unit price
12262 data: { fk_c_exp_tax_cat: $(this).val(), token: \'' .
currentToken() .
'\' },
12263 url:
"' . (DOL_URL_ROOT . '/expensereport/ajax/ajaxik.php?' . implode('&', $params)) . '",
12264 }).done(
function( data, textStatus, jqXHR ) {
12266 if (typeof data.up !=
"undefined") {
12267 $(
"input[name=value_unit]").val(data.up);
12268 $(
"select[name=' . $htmlname . ']").attr(
"title", data.title);
12270 $(
"input[name=value_unit]").val(
"");
12271 $(
"select[name=' . $htmlname . ']").attr(
"title",
"");
12282 dol_print_error($this->db);
12296 public function selectExpenseRanges($selected = '
', $htmlname = 'fk_range
', $useempty = 0)
12298 global $conf, $langs;
12301 $sql = "SELECT rowid, range_ik FROM " . $this->db->prefix() . "c_exp_tax_range";
12302 $sql .= " WHERE entity = " . ((int) $conf->entity) . " AND active = 1";
12304 $resql = $this->db->query($sql);
12306 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
12308 $out .= '<option value=
"0"></option>
';
12311 while ($obj = $this->db->fetch_object($resql)) {
12312 $out .= '<option
' . ($selected == $obj->rowid ? 'selected=
"selected"' : '') . ' value=
"' . $obj->rowid . '">
' . price($obj->range_ik, 0, $langs, 1, 0) . '</option>
';
12314 $out .= '</select>
';
12316 dol_print_error($this->db);
12332 public function selectExpenseFees($selected = '
', $htmlname = 'fk_c_type_fees
', $useempty = 0, $allchoice = 1, $useid = 0)
12337 $sql = "SELECT id, code, label";
12338 $sql .= " FROM ".$this->db->prefix()."c_type_fees";
12339 $sql .= " WHERE active = 1";
12341 $resql = $this->db->query($sql);
12343 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
12345 $out .= '<option value=
"0"></option>
';
12348 $out .= '<option value=
"-1">
' . $langs->trans('AllExpenseReport
') . '</option>
';
12356 while ($obj = $this->db->fetch_object($resql)) {
12357 $key = $langs->trans($obj->code);
12358 $out .= '<option
' . ($selected == $obj->{$field} ? 'selected=
"selected"' : '') . ' value=
"' . $obj->{$field} . '">
' . ($key != $obj->code ? $key : $obj->label) . '</option>
';
12360 $out .= '</select>
';
12362 $out .= ajax_combobox('select_
'.$htmlname);
12364 dol_print_error($this->db);
12388 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)
12390 global $user, $conf, $langs;
12392 require_once DOL_DOCUMENT_ROOT . '/projet/
class/project.class.php
';
12394 if (is_null($usertofilter)) {
12395 $usertofilter = $user;
12400 $hideunselectables = false;
12401 if (getDolGlobalString('INVOICE_HIDE_UNSELECTABLES
')) {
12402 $hideunselectables = true;
12405 if (empty($projectsListId)) {
12406 if (!$usertofilter->hasRight('projet
', 'all
', 'lire
')) {
12407 $projectstatic = new Project($this->db);
12408 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1);
12412 // Search all projects
12413 $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";
12414 $sql .= " FROM " . $this->db->prefix() . "facture as f";
12415 $sql .= " INNER JOIN " . $this->db->prefix() . "projet as p ON p.entity IN (" . getEntity('project
') . ") AND f.fk_projet = p.rowid";
12416 $sql .= " LEFT JOIN " . $this->db->prefix() . "societe as s ON s.rowid = p.fk_soc";
12417 $sql .= " WHERE f.fk_statut = 0"; // Draft invoices only
12418 //if ($projectsListId) $sql.= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")";
12419 //if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
12420 //if ($socid > 0) $sql.= " AND (p.fk_soc=".((int) $socid)." OR p.fk_soc IS NULL)";
12421 $sql .= " ORDER BY p.ref, f.ref ASC";
12423 $resql = $this->db->query($sql);
12425 // Use select2 selector
12426 if (!empty($conf->use_javascript_ajax)) {
12427 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
12428 $comboenhancement = ajax_combobox($htmlname, array(), 0, $forcefocus);
12429 $out .= $comboenhancement;
12430 $morecss = 'minwidth200imp maxwidth500
';
12433 if (empty($option_only)) {
12434 $out .= '<select
class=
"valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled=
"disabled"' : '') . ' id=
"' . $htmlname . '" name=
"' . $htmlname . '">
';
12436 if (!empty($show_empty)) {
12437 $out .= '<option value=
"0" class=
"optiongrey">
';
12438 if (!is_numeric($show_empty)) {
12439 $out .= $show_empty;
12443 $out .= '</option>
';
12445 $num = $this->db->num_rows($resql);
12448 while ($i < $num) {
12449 $obj = $this->db->fetch_object($resql);
12450 // 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.
12451 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$usertofilter->hasRight('societe
', 'lire
')) {
12454 if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) {
12461 if ($showproject == 'all
') {
12462 $labeltoshow .= dol_trunc($obj->ref, 18); // Invoice ref
12464 $labeltoshow .= ' -
' . $obj->name; // Soc name
12468 if ($obj->fk_statut == Project::STATUS_DRAFT) {
12470 $labeltoshow .= ' -
' . $langs->trans("Draft");
12471 } elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
12472 if ($discard_closed == 2) {
12475 $labeltoshow .= ' -
' . $langs->trans("Closed");
12476 } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
12478 $labeltoshow .= ' -
' . $langs->trans("LinkedToAnotherCompany");
12482 if (!empty($selected) && $selected == $obj->rowid) {
12483 $out .= '<option value=
"' . $obj->rowid . '" selected
';
12484 //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected
if disabled
12485 $out .=
'>' . $labeltoshow .
'</option>';
12487 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
12490 $resultat =
'<option value="' . $obj->rowid .
'"';
12492 $resultat .=
' disabled';
12497 $resultat .= $labeltoshow;
12498 $resultat .=
'</option>';
12506 if (empty($option_only)) {
12507 $out .=
'</select>';
12510 $this->db->free($resql);
12533 public function selectInvoiceRec($selected =
'', $htmlname =
'facrecid', $maxlength = 24, $option_only = 0, $show_empty =
'1', $forcefocus = 0, $disabled = 0, $morecss =
'maxwidth500')
12535 global
$conf, $langs;
12541 $sql =
'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc';
12542 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'facture_rec as f';
12543 $sql .=
" WHERE f.entity IN (" .
getEntity(
'invoice') .
")";
12544 $sql .=
" ORDER BY f.titre ASC";
12546 $resql = $this->db->query($sql);
12549 if (!empty(
$conf->use_javascript_ajax)) {
12550 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
12551 $comboenhancement =
ajax_combobox($htmlname, array(), 0, $forcefocus);
12552 $out .= $comboenhancement;
12553 $morecss =
'minwidth200imp maxwidth500';
12556 if (empty($option_only)) {
12557 $out .=
'<select class="valignmiddle flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' id="' . $htmlname .
'" name="' . $htmlname .
'">';
12559 if (!empty($show_empty)) {
12560 $out .=
'<option value="0" class="optiongrey">';
12561 if (!is_numeric($show_empty)) {
12562 $out .= $show_empty;
12566 $out .=
'</option>';
12568 $num = $this->db->num_rows($resql);
12570 while ($obj = $this->db->fetch_object($resql)) {
12571 $labeltoshow =
dol_trunc($obj->title, 18);
12574 if (!empty($obj->suspended)) {
12576 $labeltoshow .=
' - ' . $langs->trans(
"Closed");
12580 if (!empty($selected) && $selected == $obj->rowid) {
12581 $out .=
'<option value="' . $obj->rowid .
'" selected';
12583 $out .=
'>' . $labeltoshow .
'</option>';
12585 if ($disabled && ($selected != $obj->rowid)) {
12588 $resultat =
'<option value="' . $obj->rowid .
'"';
12590 $resultat .=
' disabled';
12593 $resultat .= $labeltoshow;
12594 $resultat .=
'</option>';
12600 if (empty($option_only)) {
12601 $out .=
'</select>';
12606 $this->db->free($resql);
12609 $this->errors[] = $this->db->lasterror;
12625 public function searchComponent($arrayofcriterias, $search_component_params, $arrayofinputfieldsalreadyoutput = array(), $search_component_params_hidden =
'', $arrayoffiltercriterias = array())
12628 global $langs, $form;
12633 if ($search_component_params_hidden !=
'' && !preg_match(
'/^\(.*\)$/', $search_component_params_hidden)) {
12634 $search_component_params_hidden =
'(' . $search_component_params_hidden .
')';
12637 $ret =
'<!-- searchComponent -->';
12639 $ret .=
'<div class="divadvancedsearchfieldcomp centpercent inline-block">';
12640 $ret .=
'<a href="#" class="dropdownsearch-toggle unsetcolor">';
12641 $ret .=
'<span class="fas fa-filter linkobject boxfilter paddingright pictofixedwidth" title="' .
dol_escape_htmltag($langs->trans(
"Filters")) .
'" id="idsubimgproductdistribution"></span>';
12644 $ret .=
'<div class="divadvancedsearchfieldcompinput inline-block minwidth500 maxwidth300onsmartphone">';
12647 $ret .=
'<div id="divsearch_component_params" name="divsearch_component_params" class="noborderbottom search_component_params inline-block valignmiddle">';
12649 if ($search_component_params_hidden) {
12657 foreach ($arrayofandtags as $tmpkey => $tmpval) {
12658 $errormessage =
'';
12660 if ($errormessage) {
12661 $this->error =
'ERROR in parsing search string: '.$errormessage;
12664 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
12667 $ret .=
'<span class="marginleftonlyshort valignmiddle tagsearch" data-ufilterid="'.($tmpkey + 1).
'" data-ufilter="'.
dol_escape_htmltag($tmpval).
'">';
12668 $ret .=
'<span class="tagsearchdelete select2-selection__choice__remove" data-ufilterid="'.($tmpkey + 1).
'">x</span> ';
12680 $show_search_component_params_hidden = 1;
12681 if ($show_search_component_params_hidden) {
12682 $ret .=
'<input type="hidden" name="show_search_component_params_hidden" value="1">';
12684 $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%')) -->";
12685 $ret .=
'<input type="hidden" id="search_component_params_hidden" name="search_component_params_hidden" value="' .
dol_escape_htmltag($search_component_params_hidden) .
'">';
12690 foreach ($arrayofcriterias as $criteria) {
12691 foreach ($criteria as $criteriafamilykey => $criteriafamilyval) {
12692 if (in_array(
'search_' . $criteriafamilykey, $arrayofinputfieldsalreadyoutput)) {
12695 if (in_array($criteriafamilykey, array(
'rowid',
'ref_ext',
'entity',
'extraparams'))) {
12698 if (in_array($criteriafamilyval[
'type'], array(
'date',
'datetime',
'timestamp'))) {
12699 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_start">';
12700 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startyear">';
12701 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startmonth">';
12702 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startday">';
12703 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_end">';
12704 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endyear">';
12705 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endmonth">';
12706 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endday">';
12708 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'">';
12715 $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";
12716 $ret .=
'<input type="text" placeholder="' . $langs->trans(
"Filters") .
'" id="search_component_params_input" name="search_component_params_input" class="noborderall search_component_input" value="">';
12722 jQuery(".tagsearchdelete").click(function(e) {
12723 var filterid = $(this).parents().attr("data-ufilterid");
12724 console.log("We click to delete the criteria nb "+filterid);
12726 // Regenerate the search_component_params_hidden with all data-ufilter except the one to delete, and post the page
12727 var newparamstring = \'\';
12728 $(\'.tagsearch\').each(function(index, element) {
12729 tmpfilterid = $(this).attr("data-ufilterid");
12730 if (tmpfilterid != filterid) {
12731 // We keep this criteria
12732 if (newparamstring == \'\') {
12733 newparamstring = $(this).attr("data-ufilter");
12735 newparamstring = newparamstring + \' AND \' + $(this).attr("data-ufilter");
12739 console.log("newparamstring = "+newparamstring);
12741 jQuery("#search_component_params_hidden").val(newparamstring);
12743 // We repost the form
12744 $(this).closest(\'form\').submit();
12747 jQuery("#search_component_params_input").keydown(function(e) {
12748 console.log("We press a key on the filter field that is "+jQuery("#search_component_params_input").val());
12749 console.log(e.which);
12750 if (jQuery("#search_component_params_input").val() == "" && e.which == 8) {
12751 /* We click on back when the input field is already empty */
12752 event.preventDefault();
12753 jQuery("#divsearch_component_params .tagsearch").last().remove();
12754 /* Regenerate content of search_component_params_hidden from remaining .tagsearch */
12756 jQuery("#divsearch_component_params .tagsearch").each(function( index ) {
12760 s = s + $(this).attr("data-ufilter");
12762 console.log("New value for search_component_params_hidden = "+s);
12763 jQuery("#search_component_params_hidden").val(s);
12771 $arrayoffiltercriterias_json = json_encode($arrayoffiltercriterias);
12773 var arrayoffiltercriterias = ' . $arrayoffiltercriterias_json .
';
12777 $arrayoffilterfieldslabel = array();
12778 foreach ($arrayoffiltercriterias as $key => $val) {
12779 $arrayoffilterfieldslabel[$key][
'label'] = $val[
'label'];
12780 $arrayoffilterfieldslabel[$key][
'data-type'] = $val[
'type'];
12784 $ret .=
'<div class="search-component-assistance">';
12787 $ret .=
'<p class="assistance-title">' .
img_picto(
'',
'filter') .
' ' . $langs->trans(
'FilterAssistance') .
' </p>';
12789 $ret .=
'<p class="assistance-errors error" style="display:none">' . $langs->trans(
'AllFieldsRequired') .
' </p>';
12791 $ret .=
'<div class="operand">';
12792 $ret .= $form->selectarray(
'search_filter_field', $arrayoffilterfieldslabel,
'', $langs->trans(
"Fields"), 0, 0,
'', 0, 0, 0,
'',
'width200 combolargeelem', 1);
12795 $ret .=
'<span class="separator"></span>';
12798 $ret .=
'<div class="operator">';
12799 $ret .=
'<select class="operator-selector width150" id="operator-selector"">';
12800 $ret .=
'</select>';
12801 $ret .=
'<script>$(document).ready(function() {';
12802 $ret .=
' $(".operator-selector").select2({';
12803 $ret .=
' placeholder: \'' .
dol_escape_js($langs->transnoentitiesnoconv(
'Operator')) .
'\'';
12805 $ret .=
'});</script>';
12808 $ret .=
'<span class="separator"></span>';
12810 $ret .=
'<div class="value">';
12812 $ret .=
'<input type="text" class="flat width100 value-input" placeholder="' .
dolPrintHTML($langs->trans(
'Value')) .
'">';
12816 $ret .=
'<span class="date-one" style="display:none">';
12817 $ret .= $form->selectDate(($dateOne ? $dateOne : -1),
'dateone', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'');
12821 $ret .=
'<select class="value-selector width150" id="value-selector" style="display:none">';
12822 $ret .=
'</select>';
12824 $(document).ready(function() {
12825 $("#value-selector").select2({
12826 placeholder: "' .
dol_escape_js($langs->trans(
'Value')) .
'"
12828 $("#value-selector").hide();
12829 $("#value-selector").next(".select2-container").hide();
12835 $ret .=
'<div class="btn-div">';
12836 $ret .=
'<button class="button buttongen button-save add-filter-btn" type="button">' . $langs->trans(
"addToFilter") .
'</button>';
12847 $(document).ready(function() {
12848 $("#search_component_params_input").on("click", function() {
12849 const inputPosition = $(this).offset();
12850 const inputHeight = $(this).outerHeight();
12851 $(".search-component-assistance").css({
12852 top: inputPosition.top + inputHeight + 5 + "px",
12853 left: $("#divsearch_component_params").position().left
12854 }).slideToggle(200);
12856 $(document).on("click", function(e) {
12857 if (!$(e.target).closest("#search_component_params_input, .search-component-assistance, #ui-datepicker-div").length) {
12858 $(".search-component-assistance").hide();
12865 $(document).ready(function() {
12866 $(".search_filter_field").on("change", function() {
12867 console.log("We change search_filter_field");
12870 const selectedField = $(this).find(":selected");
12871 let fieldType = selectedField.data("type");
12872 const selectedFieldValue = selectedField.val();
12874 // If the selected field has an array of values then ask toshow the value selector instead of the value input
12875 if (arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"] !== undefined) {
12876 fieldType = "select";
12879 // If the selected field may be null then ask to append the "IsDefined" and "IsNotDefined" operators
12880 if (arrayoffiltercriterias[selectedFieldValue]["maybenull"] !== undefined) {
12883 const operators = getOperatorsForFieldType(fieldType, maybenull);
12884 const operatorSelector = $(".operator-selector");
12886 // Clear existing options
12887 operatorSelector.empty();
12889 // Populate operators
12890 Object.entries(operators).forEach(function([operator, label]) {
12891 operatorSelector.append("<option value=\'" + operator + "\'>" + label + "</option>");
12894 operatorSelector.trigger("change.select2");
12896 // Clear and hide all input elements initially
12897 $(".value-input, .dateone, .datemonth, .dateyear").val("").hide();
12898 $("#datemonth, #dateyear").val(null).trigger("change.select2");
12899 $("#dateone").datepicker("setDate", null);
12900 $(".date-one, .date-month, .date-year").hide();
12901 $("#value-selector").val("").hide();
12902 $("#value-selector").next(".select2-container").hide();
12903 $("#value-selector").val(null).trigger("change.select2");
12905 if (fieldType === "date" || fieldType === "datetime" || fieldType === "timestamp") {
12906 $(".date-one").show();
12907 } else if (arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"] !== undefined) {
12908 var arrayofkeyval = arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"];
12909 var valueSelector = $("#value-selector");
12910 valueSelector.empty();
12911 Object.entries(arrayofkeyval).forEach(function([key, val]) {
12912 valueSelector.append("<option value=\'" + key + "\'>" + val + "</option>");
12914 valueSelector.trigger("change.select2");
12916 $("#value-selector").show();
12917 $("#value-selector").next(".select2-container").show();
12919 $(".value-input").show();
12923 $("#operator-selector").on("change", function() {
12924 console.log("We change operator-selector");
12926 const selectedOperator = $(this).find(":selected").val();
12927 if (selectedOperator === "IsDefined" || selectedOperator === "IsNotDefined") {
12928 // Disable all value input elements
12929 $(".value-input, .dateone, .datemonth, .dateyear").val("").prop("disabled", true);
12930 $("#datemonth, #dateyear").val(null).trigger("change.select2");
12931 $("#dateone").datepicker("setDate", null).datepicker("option", "disabled", true);
12932 $(".date-one, .date-month, .date-year").prop("disabled", true);
12933 $("#value-selector").val("").prop("disabled", true);
12934 $("#value-selector").val(null).trigger("change.select2");
12936 // Enable all value input elements
12937 $(".value-input, .dateone, .datemonth, .dateyear").prop("disabled", false);
12938 $(".date-one, .date-month, .date-year").prop("disabled", false);
12939 $("#dateone").datepicker("option", "disabled", false);
12940 $("#value-selector").prop("disabled", false);
12944 $(".add-filter-btn").on("click", function(event) {
12945 console.log("We click on add-filter-btn");
12947 event.preventDefault();
12949 const field = $(".search_filter_field").val();
12950 const operator = $(".operator-selector").val();
12951 let value = $(".value-input").val();
12952 const fieldType = $(".search_filter_field").find(":selected").data("type");
12954 if (["date", "datetime", "timestamp"].includes(fieldType)) {
12955 const year = $("#dateoneyear").val().toString().padStart(4, "0");;
12956 const month = $("#dateonemonth").val().toString().padStart(2, "0");
12957 const day = $("#dateoneday").val().toString().padStart(2, "0");
12958 value = `${year}-${month}-${day}`;
12959 console.log("value="+value);
12962 // If the selected field has an array of values then take the selected value
12963 if (arrayoffiltercriterias[field]["arrayofkeyval"] !== undefined) {
12964 value = $("#value-selector").val();
12967 // If the operator is "IsDefined" or "IsNotDefined" then set the value to 1 (it will not be used)
12968 if (operator === "IsDefined" || operator === "IsNotDefined") {
12972 const filterString = generateFilterString(field, operator, value, fieldType);
12975 if (filterString !== "" && field !== "" && operator !== "" && value !== "") {
12976 $("#search_component_params_input").val($("#search_component_params_input").val() + " " + filterString);
12977 $("#search_component_params_input").closest("form").submit();
12979 $(".assistance-errors").show();
12999 public function selectModelMail($prefix, $modelType =
'', $default = 0, $addjscombo = 0, $selected = 0, $morecss =
'')
13001 global $langs, $user;
13005 $TModels = array();
13007 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
13008 $formmail =
new FormMail($this->db);
13009 $result = $formmail->fetchAllEMailTemplate($modelType, $user, $langs);
13012 $TModels[0] = $langs->trans(
'DefaultMailModel');
13015 foreach ($formmail->lines_model as $model) {
13016 $TModels[(int) $model->id] = $model->label;
13020 $retstring .=
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" id="select_' . $prefix .
'model_mail" name="' . $prefix .
'model_mail">';
13022 foreach ($TModels as $id_model => $label_model) {
13023 $retstring .=
'<option value="' . $id_model .
'"';
13024 if (!empty($selected) && ((int) $selected) == $id_model) {
13025 $retstring .=
"selected";
13027 $retstring .=
">" . $label_model .
"</option>";
13030 $retstring .=
"</select>";
13033 $retstring .=
ajax_combobox(
'select_' . $prefix .
'model_mail');
13050 public function buttonsSaveCancel($save_label =
'Save', $cancel_label =
'Cancel', $morebuttons = array(), $withoutdiv =
false, $morecss =
'', $dol_openinpopup =
'')
13054 $buttons = array();
13058 'label_key' => $save_label,
13061 if ($save_label ==
'Create' || $save_label ==
'Add') {
13062 $save[
'name'] =
'add';
13063 } elseif ($save_label ==
'Modify') {
13064 $save[
'name'] =
'edit';
13068 'name' =>
'cancel',
13069 'label_key' =>
'Cancel',
13074 !empty($save_label) ? $buttons[] = $save :
'';
13075 if (!empty($morebuttons)) {
13076 $buttons[] = $morebuttons;
13078 !empty($cancel_label) ? $buttons[] = $cancel :
'';
13080 if (!empty($morebuttons)) {
13081 $buttons[] = $morebuttons;
13083 !empty($cancel_label) ? $buttons[] = $cancel :
'';
13084 !empty($save_label) ? $buttons[] = $save :
'';
13087 $retstring = $withoutdiv ?
'' :
'<div class="center">';
13089 foreach ($buttons as $button) {
13090 $addclass = empty($button[
'addclass']) ?
'' : $button[
'addclass'];
13091 $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'])) .
'">';
13093 $retstring .= $withoutdiv ?
'' :
'</div>';
13095 if ($dol_openinpopup) {
13096 $retstring .=
'<!-- buttons are shown into a $dol_openinpopup=' .
dol_escape_htmltag($dol_openinpopup) .
' context, so we enable the close of dialog on cancel -->' .
"\n";
13097 $retstring .=
'<script nonce="' .
getNonce() .
'">';
13098 $retstring .=
'jQuery(".button-cancel").click(function(e) {
13099 e.preventDefault(); console.log(\'We click on cancel in iframe popup ' .
dol_escape_js($dol_openinpopup) .
'\');
13100 window.parent.jQuery(\
'#idfordialog' .
dol_escape_js($dol_openinpopup) .
'\').dialog(\
'close\');
13102 $retstring .=
'</script>';
13121 $num = count($this->cache_invoice_subtype);
13128 $sql =
"SELECT rowid, code, label as label";
13129 $sql .=
" FROM " . MAIN_DB_PREFIX .
'c_invoice_subtype';
13130 $sql .=
" WHERE active = 1";
13132 $resql = $this->db->query($sql);
13134 $num = $this->db->num_rows($resql);
13136 while ($i < $num) {
13137 $obj = $this->db->fetch_object($resql);
13140 $label = ($langs->trans(
"InvoiceSubtype" . $obj->rowid) !=
"InvoiceSubtype" . $obj->rowid) ? $langs->trans(
"InvoiceSubtype" . $obj->rowid) : (($obj->label !=
'-') ? $obj->label :
'');
13141 $this->cache_invoice_subtype[$obj->rowid][
'rowid'] = $obj->rowid;
13142 $this->cache_invoice_subtype[$obj->rowid][
'code'] = $obj->code;
13143 $this->cache_invoice_subtype[$obj->rowid][
'label'] = $label;
13147 $this->cache_invoice_subtype =
dol_sort_array($this->cache_invoice_subtype,
'code',
'asc', 0, 0, 1);
13169 global $langs, $user;
13172 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
13174 $this->load_cache_invoice_subtype();
13176 $out .=
'<select id="' . $htmlname .
'" class="flat selectsubtype' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
13178 $out .=
'<option value="0"> </option>';
13181 foreach ($this->cache_invoice_subtype as $rowid => $subtype) {
13182 $label = $subtype[
'label'];
13183 $out .=
'<option value="' . $subtype[
'rowid'] .
'"';
13184 if ($selected == $subtype[
'rowid']) {
13185 $out .=
' selected="selected"';
13189 $out .=
'</option>';
13192 $out .=
'</select>';
13193 if ($user->admin && empty($noinfoadmin)) {
13194 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
13215 'type' =>
'search',
13216 'name' => $htmlName,
13218 'class' =>
"search-tool-input",
13219 'placeholder' => $langs->trans(
'Search'),
13220 'autocomplete' =>
'off'
13228 if ($dataTarget !==
false) {
13229 $attr[
'data-search-tool-target'] = $dataTarget;
13233 if (!empty($params[
'attr']) && is_array($params[
'attr'])) {
13234 foreach ($params[
'attr'] as $key => $value) {
13235 if ($key ==
'class') {
13236 $attr[
'class'] .=
' '.$value;
13237 } elseif ($key ==
'classOverride') {
13238 $attr[
'class'] = $value;
13240 $attr[$key] = $value;
13246 if (!empty($attr[
'title']) && !empty($attr[
'class']) && strpos($attr[
'class'],
'classfortooltip') ===
false) {
13247 $attr[
'class'] .=
' classfortooltip';
13250 $TCompiledAttr = [];
13251 foreach ($attr as $key => $value) {
13252 if (in_array($key, [
'data-target'])
13253 || (!empty($params[
'use_unsecured_unescapedattr']) && is_array($params[
'use_unsecured_unescapedattr']) && in_array($key, $params[
'use_unsecured_unescapedattr']))) {
13259 $TCompiledAttr[] = $key .
'="' . $value .
'"';
13262 $compiledAttributes = implode(
' ', $TCompiledAttr);
13265 return '<div class="search-tool-container"><input '.$compiledAttributes.
'></div>';
13281 public function inputType($type, $name, $value =
'',
$id =
'', $morecss =
'', $moreparam =
'', $label =
'', $addInputLabel =
'')
13284 if ($label !=
'') {
13294 $out .= ($moreparam ?
' ' . $moreparam :
'');
13295 $out .=
' />' . $addInputLabel;
13296 if ($label !=
'') {
13297 $out .= $label .
'</label>';
13315 public function inputSelectAjax($htmlName, $array,
$id, $ajaxUrl, $ajaxData = [], $morecss =
'minwidth75', $moreparam =
'')
13319 $(document).ready(function () {
13320 $('#" . $htmlName .
"').select2({
13322 url: '" . $ajaxUrl .
"',
13324 delay: 250, // wait 250 milliseconds before triggering the request
13325 data: function (params) {
13327 search: params.term,
13328 page: params.page || 1";
13329 if (!empty($ajaxData) && is_array($ajaxData)) {
13330 foreach ($ajaxData as $key => $value) {
13331 $out .=
", " . $key .
": '" . $value .
"'";
13343 $out .= $this->selectarray($htmlName, $array,
$id, 0, 0, 0, $moreparam, 0, 0, 0,
'', $morecss);
13357 public function inputHtml($htmlName, $value, $morecss =
'', $moreparam =
'')
13359 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
13360 $doleditor =
new DolEditor($htmlName, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
isModEnabled(
'fckeditor') &&
getDolGlobalInt(
'FCKEDITOR_ENABLE_SOCIETE'), ROWS_5,
'90%');
13362 return (
string) $doleditor->Create(1,
'',
true,
'',
'', $moreparam, $morecss);
13375 public function inputText($htmlName, $value, $morecss =
'', $moreparam =
'', $options = array())
13380 if (!empty($options)) {
13382 $out .= $this->selectarray($htmlName .
"_multiinput", $options,
'', 1, 0, 0, $moreparam, 0, 0, 0,
'',
"flat maxwidthonphone" . $morecss);
13383 $out .=
'<input id="' . $htmlName .
'_multiinputadd" type="button" class="button" value="' . $langs->trans(
"Add") .
'">';
13384 $out .=
"<script>";
13386 function handlemultiinputdisabling(htmlname){
13387 console.log("We handle the disabling of used options for "+htmlname+"_multiinput");
13388 multiinput = $("#"+htmlname+"_multiinput");
13389 multiinput.find("option").each(function(){
13390 tmpval = $("#"+htmlname).val();
13391 tmpvalarray = tmpval.split("\n");
13392 valtotest = $(this).val();
13393 if(tmpvalarray.includes(valtotest)){
13394 $(this).prop("disabled",true);
13396 if($(this).prop("disabled") == true){
13397 console.log(valtotest)
13398 $(this).prop("disabled", false);
13404 $(document).ready(function () {
13405 $("#' . $htmlName .
'_multiinputadd").on("click",function() {
13406 tmpval = $("#' . $htmlName .
'").val();
13407 tmpvalarray = tmpval.split(",");
13408 valtotest = $("#' . $htmlName .
'_multiinput").val();
13409 if(valtotest != -1 && !tmpvalarray.includes(valtotest)){
13410 console.log("We add the selected value to the text area ' . $htmlName .
'");
13412 tmpval = valtotest;
13414 tmpval = tmpval + "\n" + valtotest;
13416 $("#' . $htmlName .
'").val(tmpval);
13417 handlemultiinputdisabling("' . $htmlName .
'");
13418 $("#' . $htmlName .
'_multiinput").val(-1);
13420 console.log("We add nothing the text area ' . $htmlName .
'");
13423 $("#' . $htmlName .
'").on("change",function(){
13424 handlemultiinputdisabling("' . $htmlName .
'");
13426 handlemultiinputdisabling("' . $htmlName .
'");
13428 $out .=
"</script>";
13429 $value = str_replace(
',',
"\n", $value);
13432 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
13433 $doleditor =
new DolEditor($htmlName, (
string) $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
13434 $out .= (
string) $doleditor->Create(1,
'',
true,
'',
'', $moreparam, $morecss);
13449 public function inputRadio($htmlName, $options, $selectedValue, $morecss =
'', $moreparam =
'')
13452 foreach ($options as $optionKey => $optionLabel) {
13453 $selected = ((
string) $selectedValue) === ((
string) $optionKey) ?
' checked="checked"' :
'';
13454 $optionId = $htmlName .
'_' . $optionKey;
13455 $out .=
'<input class="flat' . $morecss .
'" type="radio" name="' . $htmlName .
'" id="' . $optionId .
'" value="' .
dolPrintHTMLForAttribute((
string) $optionKey) .
'"' . $selected . $moreparam .
'/><label for="' . $optionId .
'">' . $optionLabel .
'</label><br>';
13471 public function inputStars($htmlName, $size, $value, $morecss =
'', $moreparam =
'')
13473 $out =
'<input type="hidden" class="flat ' . $morecss .
'" name="' . $htmlName .
'" id="' . $htmlName .
'" value="' .
dolPrintHTMLForAttribute((
string) $value) .
'"' . $moreparam .
'>';
13474 $out .=
'<div class="star-selection" id="' . $htmlName .
'_selection">';
13475 for ($i = 1; $i <= $size; $i++) {
13476 $out .=
'<span class="star" data-value="' . $i .
'">' .
img_picto(
'',
'fontawesome_star_fas') .
'</span>';
13480 jQuery(function($) { /* commonobject.class.php 1 */
13481 let container = $("#' . $htmlName .
'_selection");
13482 let selectedStars = parseInt($("#' . $htmlName .
'").val()) || 0;
13483 container.find(".star").each(function() {
13484 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
13486 container.find(".star").on("mouseover", function() {
13487 let selectedStar = $(this).data("value");
13488 container.find(".star").each(function() {
13489 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
13492 container.on("mouseout", function() {
13493 container.find(".star").each(function() {
13494 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
13497 container.find(".star").off("click").on("click", function() {
13498 selectedStars = $(this).data("value");
13499 if (selectedStars === 1 && $("#' . $htmlName .
'").val() == 1) {
13502 $("#' . $htmlName .
'").val(selectedStars);
13503 container.find(".star").each(function() {
13504 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
13522 public function inputIcon($htmlName, $value, $morecss =
'', $moreparam =
'')
13531 $out =
'<input type="text" class="form-control icp icp-auto iconpicker-element iconpicker-input flat ' . $morecss .
' maxwidthonsmartphone"';
13532 $out .=
' name="' . $htmlName .
'" id="' . $htmlName .
'" value="' .
dolPrintHTMLForAttribute((
string) $value) .
'" ' . ((
string) $moreparam) .
'>';
13534 $out .=
'<script>';
13535 $options =
"{ title: '<b>" . $langs->trans(
"IconFieldSelector") .
"</b>', placement: 'right', showFooter: false, templates: {";
13536 $options .=
"iconpicker: '<div class=\"iconpicker\"><div style=\"background-color:#EFEFEF;\" class=\"iconpicker-items\"></div></div>',";
13537 $options .=
"iconpickerItem: '<a role=\"button\" href=\"#\" class=\"iconpicker-item\" style=\"background-color:#DDDDDD;\"><i></i></a>',";
13540 $options .=
"footer: '<div class=\"popover-footer\" style=\"background-color:#EFEFEF;\"></div>',";
13541 $options .=
"search: '<input type=\"search\" class\"form-control iconpicker-search\" placeholder=\"" . $langs->trans(
"TypeToFilter") .
"\" />',";
13542 $options .=
"popover: '<div class=\"iconpicker-popover popover\">";
13543 $options .=
" <div class=\"arrow\" ></div>";
13544 $options .=
" <div class=\"popover-title\" style=\"text-align:center;background-color:#EFEFEF;\"></div>";
13545 $options .=
" <div class=\"popover-content \" ></div>";
13546 $options .=
"</div>'}}";
13547 $out .=
"$('#" . $htmlName .
"').iconpicker(" . $options .
");";
13548 $out .=
'</script>';
13564 require_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeophp.class.php';
13565 require_once DOL_DOCUMENT_ROOT .
'/core/class/geomapeditor.class.php';
13571 if (!empty($value)) {
13572 $tmparray = $dolgeophp->parseGeoString($value);
13573 $geojson = $tmparray[
'geojson'];
13574 $centroidjson = $tmparray[
'centroidjson'];
13577 return $geomapeditor->getHtml($htmlName, $geojson, $centroidjson, $type);
13589 $toPrint = array();
13590 $values = is_array($values) ? $values : array();
13592 foreach ($values as $value) {
13593 $toPrint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $value .
'</li>';
13595 if (!empty($toPrint)) {
13596 $out =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(
' ', $toPrint) .
'</ul></div>';
13612 for ($i = 1; $i <= $size; $i++) {
13613 $out .=
'<span class="star' . ($i <= $value ?
' active' :
'') .
'" data-value="' . $i .
'">' .
img_picto(
'',
'fontawesome_star_fas') .
'</span>';
13644 if (!empty($value)) {
13645 require_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeophp.class.php';
13647 if ($type ==
'point') {
13648 $out = $dolgeophp->getXYString($value);
13650 $out = $dolgeophp->getPointString($value);
13671 public function getNomUrl(&
$object, $withpicto = 0, $option =
'', $maxlength = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'', $add_label = 0, $sep =
' - ')
13673 if (is_object(
$object) && method_exists(
$object,
'getNomUrl')) {
13674 $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.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
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, ....
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
getAdvancedPreviewUrl($modulepart, $relativepath, $alldata=0, $param='')
Return URL we can use for advanced preview links.
colorIsLight($stringcolor)
Return true if the color is light.
dolIsAllowedForPreview($file)
Return if a file is qualified for preview.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
getNonce()
Return a random string to be used as a nonce value for js.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox=0, $check='restricthtml')
Sanitize a HTML to remove js, dangerous content and external links.
dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array(), $allowlink=0, $allowscript=0, $allowstyle=0, $allowphp=0)
Clean a string to keep only desirable HTML tags.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_sanitizeKeyCode($str)
Clean a string to use it as a key or code.
isModEnabled($module)
Is Dolibarr module enabled.
array_merge_recursive_distinct(array $array1, array $array2)
Recursively merges two arrays while preserving keys and replacing existing values.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_nboflines_bis($text, $maxlinesize=0, $charset='UTF-8')
Return nb of lines of a formatted text with and (WARNING: string must not have mixed and br sep...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
multi select button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
Class to generate the form for creating a new ticket.
dol_get_trunk_prefix($db, $phone_code)
Get the national trunk prefix for a phone code.
dol_parse_phone($phone)
Parse a stored phone number into country code and number parts.
dol_get_phone_code_from_country($db, $country_id)
Get the phone calling code for a country.
measuringUnitString($unitid, $measuring_style='', $unitscale=null, $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
$conf db name
Only used if Module[ID]Name translation string is not found.
getMaxFileSizeArray()
Return the max allowed for file upload.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.
dolDecrypt($chain, $key='', $patterntotest='')
Decode a string with a symmetric encryption.
testSqlAndScriptInject($val, $type)
Security: WAF layer for SQL Injection and XSS Injection (scripts) protection (Filters on GET,...