70 public $errors = array();
79 public $cache_types_paiements = array();
80 public $cache_conditions_paiements = array();
81 public $cache_transport_mode = array();
82 public $cache_availability = array();
83 public $cache_demand_reason = array();
84 public $cache_types_fees = array();
85 public $cache_vatrates = array();
86 public $cache_invoice_subtype = array();
115 public function editfieldkey($text, $htmlname, $preselected,
$object, $perm, $typeofdata =
'string', $moreparam =
'', $fieldrequired = 0, $notabletag = 0, $paramid =
'id', $help =
'')
122 if (
getDolGlobalString(
'MAIN_USE_JQUERY_JEDITABLE') && !preg_match(
'/^select;/', $typeofdata)) {
124 $tmp = explode(
':', $typeofdata);
125 $ret .=
'<div class="editkey_' . $tmp[0] . (!empty($tmp[1]) ?
' ' . $tmp[1] :
'') .
'" id="' . $htmlname .
'">';
126 if ($fieldrequired) {
127 $ret .=
'<span class="fieldrequired">';
132 $ret .= $langs->trans($text);
134 if ($fieldrequired) {
137 $ret .=
'</div>' .
"\n";
139 if ($fieldrequired) {
140 $ret .=
'<span class="fieldrequired">';
145 $ret .= $langs->trans($text);
147 if ($fieldrequired) {
152 if (empty($notabletag) && $perm) {
153 $ret .=
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
155 if ($fieldrequired) {
156 $ret .=
'<span class="fieldrequired">';
161 $ret .= $langs->trans($text);
163 if ($fieldrequired) {
166 if (!empty($notabletag)) {
169 if (empty($notabletag) && $perm) {
172 if (empty($notabletag) && $perm) {
173 $ret .=
'<td class="right">';
175 if ($htmlname &&
GETPOST(
'action',
'aZ09') !=
'edit' . $htmlname && $perm) {
176 $ret .=
'<a class="editfielda reposition" href="' . $_SERVER[
"PHP_SELF"] .
'?action=edit' . $htmlname .
'&token=' . newToken() .
'&' . $paramid .
'=' .
$object->id . $moreparam .
'">' .
img_edit($langs->trans(
'Edit'), ($notabletag ? 0 : 1)) .
'</a>';
178 if (!empty($notabletag) && $notabletag == 1) {
185 if (!empty($notabletag) && $notabletag == 3) {
188 if (empty($notabletag) && $perm) {
191 if (empty($notabletag) && $perm) {
192 $ret .=
'</tr></table>';
222 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 =
'')
224 global $conf, $langs;
229 if (empty($typeofdata)) {
230 return 'ErrorBadParameter typeofdata is empty';
233 if ($typeofdata ==
'datetime') {
234 $typeofdata =
'dayhour';
237 if (preg_match(
'/^(\w+)\((\d+)\)$/', $typeofdata, $reg)) {
238 if ($reg[1] ==
'varchar') {
239 $typeofdata =
'string';
240 } elseif ($reg[1] ==
'int') {
241 $typeofdata =
'numeric';
243 return 'ErrorBadParameter ' . $typeofdata;
248 if (
getDolGlobalString(
'MAIN_USE_JQUERY_JEDITABLE') && !preg_match(
'/^select;|day|datepicker|dayhour|datehourpicker/', $typeofdata)) {
249 $ret .= $this->
editInPlace(
$object, $value, $htmlname, ($perm ? 1 : 0), $typeofdata, $editvalue, $extObject, $custommsg);
251 if ($editaction ==
'') {
252 $editaction =
GETPOST(
'action',
'aZ09');
254 $editmode = ($editaction ==
'edit' . $htmlname);
257 $ret .=
'<form method="post" action="' . $_SERVER[
"PHP_SELF"] . ($moreparam ?
'?' . $moreparam :
'') .
'">';
258 $ret .=
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
259 $ret .=
'<input type="hidden" name="token" value="' . newToken() .
'">';
260 $ret .=
'<input type="hidden" name="' . $paramid .
'" value="' .
$object->id .
'">';
261 if (empty($notabletag)) {
262 $ret .=
'<table class="nobordernopadding centpercent">';
264 if (empty($notabletag)) {
267 if (preg_match(
'/^(string|safehtmlstring|email|phone|url)/', $typeofdata)) {
268 $tmp = explode(
':', $typeofdata);
269 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($editvalue ? $editvalue : $value) .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
270 } elseif (preg_match(
'/^(integer)/', $typeofdata)) {
271 $tmp = explode(
':', $typeofdata);
272 $valuetoshow =
price2num($editvalue ? $editvalue : $value, 0);
273 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $valuetoshow .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
274 } elseif (preg_match(
'/^(numeric|amount)/', $typeofdata)) {
275 $tmp = explode(
':', $typeofdata);
276 $valuetoshow =
price2num($editvalue ? $editvalue : $value);
277 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($valuetoshow !=
'' ?
price($valuetoshow) :
'') .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
278 } elseif (preg_match(
'/^(checkbox)/', $typeofdata)) {
279 $tmp = explode(
':', $typeofdata);
280 $ret .=
'<input type="checkbox" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($value ? $value :
'on') .
'"' . ($value ?
' checked' :
'') . (empty($tmp[1]) ?
'' : $tmp[1]) .
'/>';
281 } elseif (preg_match(
'/^text/', $typeofdata) || preg_match(
'/^note/', $typeofdata)) {
282 $tmp = explode(
':', $typeofdata);
283 $cols = (empty($tmp[2]) ?
'' : $tmp[2]);
285 if (preg_match(
'/%/', $cols)) {
286 $morealt =
' style="width: ' . $cols .
'"';
289 $valuetoshow = ($editvalue ? $editvalue : $value);
290 $ret .=
'<textarea id="' . $htmlname .
'" name="' . $htmlname .
'" wrap="soft" rows="' . (empty($tmp[1]) ?
'20' : $tmp[1]) .
'"' . ($cols ?
' cols="' . $cols .
'"' :
'class="quatrevingtpercent"') . $morealt .
'" autofocus>';
293 $valuetoshow = str_replace(
'&',
'&', $valuetoshow);
295 $ret .=
'</textarea>';
296 } elseif ($typeofdata ==
'day' || $typeofdata ==
'datepicker') {
297 $addnowlink = empty($moreoptions[
'addnowlink']) ? 0 : $moreoptions[
'addnowlink'];
298 $adddateof = empty($moreoptions[
'adddateof']) ?
'' : $moreoptions[
'adddateof'];
299 $labeladddateof = empty($moreoptions[
'labeladddateof']) ?
'' : $moreoptions[
'labeladddateof'];
300 $ret .= $this->
selectDate($value, $htmlname, 0, 0, 1,
'form' . $htmlname, 1, $addnowlink, 0,
'',
'', $adddateof,
'', 1, $labeladddateof,
'', $gm);
301 } elseif ($typeofdata ==
'dayhour' || $typeofdata ==
'datehourpicker') {
302 $addnowlink = empty($moreoptions[
'addnowlink']) ? 0 : $moreoptions[
'addnowlink'];
303 $adddateof = empty($moreoptions[
'adddateof']) ?
'' : $moreoptions[
'adddateof'];
304 $labeladddateof = empty($moreoptions[
'labeladddateof']) ?
'' : $moreoptions[
'labeladddateof'];
305 $ret .= $this->
selectDate($value, $htmlname, 1, 1, 1,
'form' . $htmlname, 1, $addnowlink, 0,
'',
'', $adddateof,
'', 1, $labeladddateof,
'', $gm);
306 } elseif (preg_match(
'/^select;/', $typeofdata)) {
307 $arraydata = explode(
',', preg_replace(
'/^select;/',
'', $typeofdata));
308 $arraylist = array();
309 foreach ($arraydata as $val) {
310 $tmp = explode(
':', $val);
311 $tmpkey = str_replace(
'|',
':', $tmp[0]);
312 $arraylist[$tmpkey] = $tmp[1];
314 $ret .= $this->
selectarray($htmlname, $arraylist, $value);
315 } elseif (preg_match(
'/^link/', $typeofdata)) {
317 } elseif (preg_match(
'/^ckeditor/', $typeofdata)) {
318 $tmp = explode(
':', $typeofdata);
319 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
320 $doleditor =
new DolEditor($htmlname, ($editvalue ? $editvalue : $value), (empty($tmp[2]) ?
'' : $tmp[2]), (empty($tmp[3]) ?
'100' : $tmp[3]), (empty($tmp[1]) ?
'dolibarr_notes' : $tmp[1]),
'In', (empty($tmp[5]) ? 0 : $tmp[5]), (isset($tmp[8]) ? ($tmp[8] ? true :
false) :
true),
true, (empty($tmp[6]) ?
'20' : $tmp[6]), (empty($tmp[7]) ?
'100' : $tmp[7]));
321 $ret .= $doleditor->Create(1);
322 } elseif ($typeofdata ==
'asis') {
323 $ret .= ($editvalue ? $editvalue : $value);
325 if (empty($notabletag)) {
330 if (empty($notabletag)) {
334 $ret .=
'<input type="submit" class="smallpaddingimp button' . (empty($notabletag) ?
'' :
' ') .
'" name="modify" value="' . $langs->trans(
"Modify") .
'">';
335 if (preg_match(
'/ckeditor|textarea/', $typeofdata) && empty($notabletag)) {
336 $ret .=
'<br>' .
"\n";
338 $ret .=
'<input type="submit" class="smallpaddingimp button button-cancel' . (empty($notabletag) ?
'' :
' ') .
'" name="cancel" value="' . $langs->trans(
"Cancel") .
'">';
339 if (empty($notabletag)) {
343 if (empty($notabletag)) {
344 $ret .=
'</tr></table>' .
"\n";
346 $ret .=
'</form>' .
"\n";
348 if (preg_match(
'/^email/', $typeofdata)) {
350 } elseif (preg_match(
'/^phone/', $typeofdata)) {
352 } elseif (preg_match(
'/^url/', $typeofdata)) {
354 } elseif (preg_match(
'/^(amount|numeric)/', $typeofdata)) {
355 $ret .= ($value !=
'' ?
price($value, 0, $langs, 0, -1, -1, $conf->currency) :
'');
356 } elseif (preg_match(
'/^checkbox/', $typeofdata)) {
357 $tmp = explode(
':', $typeofdata);
358 $ret .=
'<input type="checkbox" disabled id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $value .
'"' . ($value ?
' checked' :
'') . ($tmp[1] ? $tmp[1] :
'') .
'/>';
359 } elseif (preg_match(
'/^text/', $typeofdata) || preg_match(
'/^note/', $typeofdata)) {
361 } elseif (preg_match(
'/^(safehtmlstring|restricthtml)/', $typeofdata)) {
363 } elseif ($typeofdata ==
'day' || $typeofdata ==
'datepicker') {
364 $ret .=
'<span class="valuedate">' .
dol_print_date($value,
'day', $gm) .
'</span>';
365 } elseif ($typeofdata ==
'dayhour' || $typeofdata ==
'datehourpicker') {
366 $ret .=
'<span class="valuedate">' .
dol_print_date($value,
'dayhour', $gm) .
'</span>';
367 } elseif (preg_match(
'/^select;/', $typeofdata)) {
368 $arraydata = explode(
',', preg_replace(
'/^select;/',
'', $typeofdata));
369 $arraylist = array();
370 foreach ($arraydata as $val) {
371 $tmp = explode(
':', $val);
372 $arraylist[$tmp[0]] = $tmp[1];
374 $ret .= $arraylist[$value];
375 if ($htmlname ==
'fk_product_type') {
377 $ret =
img_picto($langs->trans(
"Product"),
'product',
'class="paddingleftonly paddingrightonly colorgrey"') . $ret;
379 $ret =
img_picto($langs->trans(
"Service"),
'service',
'class="paddingleftonly paddingrightonly colorgrey"') . $ret;
382 } elseif (preg_match(
'/^ckeditor/', $typeofdata)) {
385 $firstline = preg_replace(
'/<br>.*/',
'', $tmpcontent);
386 $firstline = preg_replace(
'/[\n\r].*/',
'', $firstline);
387 $tmpcontent = $firstline . ((strlen($firstline) != strlen($tmpcontent)) ?
'...' :
'');
393 if (empty($moreoptions[
'valuealreadyhtmlescaped'])) {
401 if ($formatfunc && method_exists(
$object, $formatfunc)) {
402 $ret =
$object->$formatfunc($ret);
422 global $conf, $langs, $extralanguages;
427 $arrayoflangcode = array();
432 if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
433 if (!is_object($extralanguages)) {
434 include_once DOL_DOCUMENT_ROOT .
'/core/class/extralanguages.class.php';
437 $extralanguages->fetch_name_extralanguages(
'societe');
439 if (!is_array($extralanguages->attributes[
$object->element]) || empty($extralanguages->attributes[
$object->element][$fieldname])) {
443 $result .=
'<!-- Widget for translation -->' .
"\n";
444 $result .=
'<div class="inline-block paddingleft image-' .
$object->element .
'-' . $fieldname .
'">';
445 $s =
img_picto($langs->trans(
"ShowOtherLanguages"),
'language',
'',
false, 0, 0,
'',
'fa-15 editfieldlang');
449 $result .=
'<div class="inline-block hidden field-' .
$object->element .
'-' . $fieldname .
'">';
451 $resultforextrlang =
'';
452 foreach ($arrayoflangcode as $langcode) {
453 $valuetoshow = GETPOSTISSET(
'field-' .
$object->element .
"-" . $fieldname .
"-" . $langcode) ?
GETPOST(
'field-' .
$object->element .
'-' . $fieldname .
"-" . $langcode, $check) :
'';
454 if (empty($valuetoshow)) {
455 $object->fetchValuesForExtraLanguages();
457 $valuetoshow =
$object->array_languages[$fieldname][$langcode];
461 $resultforextrlang .= $s;
464 if ($typeofdata ==
'textarea') {
465 $resultforextrlang .=
'<textarea name="field-' .
$object->element .
"-" . $fieldname .
"-" . $langcode .
'" id="' . $fieldname .
"-" . $langcode .
'" class="' . $morecss .
'" rows="' . ROWS_2 .
'" wrap="soft">';
466 $resultforextrlang .= $valuetoshow;
467 $resultforextrlang .=
'</textarea>';
469 $resultforextrlang .=
'<input type="text" class="inputfieldforlang ' . ($morecss ?
' ' . $morecss :
'') .
'" name="field-' .
$object->element .
'-' . $fieldname .
'-' . $langcode .
'" value="' . $valuetoshow .
'">';
472 $result .= $resultforextrlang;
475 $result .=
'<script nonce="' .
getNonce() .
'">$(".image-' .
$object->element .
'-' . $fieldname .
'").click(function() { console.log("Toggle lang widget"); jQuery(".field-' .
$object->element .
'-' . $fieldname .
'").toggle(); });</script>';
494 protected function editInPlace(
$object, $value, $htmlname, $condition, $inputType =
'textarea', $editvalue =
null, $extObject =
null, $custommsg =
null)
499 if (preg_match(
'/^text/', $inputType)) {
501 } elseif (preg_match(
'/^numeric/', $inputType)) {
502 $value =
price($value);
503 } elseif ($inputType ==
'day' || $inputType ==
'datepicker') {
509 $table_element =
false;
513 $ext_element =
false;
514 $button_only =
false;
521 $table_element =
$object->table_element;
525 if (is_object($extObject)) {
526 $ext_element = $extObject->element;
529 if (preg_match(
'/^(string|email|numeric)/', $inputType)) {
530 $tmp = explode(
':', $inputType);
531 $inputType = $tmp[0];
532 if (!empty($tmp[1])) {
533 $inputOption = $tmp[1];
535 if (!empty($tmp[2])) {
536 $savemethod = $tmp[2];
538 $out .=
'<input id="width_' . $htmlname .
'" value="' . $inputOption .
'" type="hidden"/>' .
"\n";
539 } elseif ((preg_match(
'/^day$/', $inputType)) || (preg_match(
'/^datepicker/', $inputType)) || (preg_match(
'/^datehourpicker/', $inputType))) {
540 $tmp = explode(
':', $inputType);
541 $inputType = $tmp[0];
542 if (!empty($tmp[1])) {
543 $inputOption = $tmp[1];
545 if (!empty($tmp[2])) {
546 $savemethod = $tmp[2];
549 $out .=
'<input id="timestamp" type="hidden"/>' .
"\n";
550 } elseif (preg_match(
'/^(select|autocomplete)/', $inputType)) {
551 $tmp = explode(
':', $inputType);
552 $inputType = $tmp[0];
553 $loadmethod = $tmp[1];
554 if (!empty($tmp[2])) {
555 $savemethod = $tmp[2];
557 if (!empty($tmp[3])) {
560 } elseif (preg_match(
'/^textarea/', $inputType)) {
561 $tmp = explode(
':', $inputType);
562 $inputType = $tmp[0];
563 $rows = (empty($tmp[1]) ?
'8' : $tmp[1]);
564 $cols = (empty($tmp[2]) ?
'80' : $tmp[2]);
565 } elseif (preg_match(
'/^ckeditor/', $inputType)) {
566 $tmp = explode(
':', $inputType);
567 $inputType = $tmp[0];
569 if (!empty($tmp[2])) {
572 if (!empty($tmp[3])) {
575 if (!empty($tmp[4])) {
576 $savemethod = $tmp[4];
579 if (isModEnabled(
'fckeditor')) {
580 $out .=
'<input id="ckeditor_toolbar" value="' . $toolbar .
'" type="hidden"/>' .
"\n";
582 $inputType =
'textarea';
586 $out .=
'<input id="element_' . $htmlname .
'" value="' . $element .
'" type="hidden"/>' .
"\n";
587 $out .=
'<input id="table_element_' . $htmlname .
'" value="' . $table_element .
'" type="hidden"/>' .
"\n";
588 $out .=
'<input id="fk_element_' . $htmlname .
'" value="' . $fk_element .
'" type="hidden"/>' .
"\n";
589 $out .=
'<input id="loadmethod_' . $htmlname .
'" value="' . $loadmethod .
'" type="hidden"/>' .
"\n";
590 if (!empty($savemethod)) {
591 $out .=
'<input id="savemethod_' . $htmlname .
'" value="' . $savemethod .
'" type="hidden"/>' .
"\n";
593 if (!empty($ext_element)) {
594 $out .=
'<input id="ext_element_' . $htmlname .
'" value="' . $ext_element .
'" type="hidden"/>' .
"\n";
596 if (!empty($custommsg)) {
597 if (is_array($custommsg)) {
598 if (!empty($custommsg[
'success'])) {
599 $out .=
'<input id="successmsg_' . $htmlname .
'" value="' . $custommsg[
'success'] .
'" type="hidden"/>' .
"\n";
601 if (!empty($custommsg[
'error'])) {
602 $out .=
'<input id="errormsg_' . $htmlname .
'" value="' . $custommsg[
'error'] .
'" type="hidden"/>' .
"\n";
605 $out .=
'<input id="successmsg_' . $htmlname .
'" value="' . $custommsg .
'" type="hidden"/>' .
"\n";
608 if ($inputType ==
'textarea') {
609 $out .=
'<input id="textarea_' . $htmlname .
'_rows" value="' . $rows .
'" type="hidden"/>' .
"\n";
610 $out .=
'<input id="textarea_' . $htmlname .
'_cols" value="' . $cols .
'" type="hidden"/>' .
"\n";
612 $out .=
'<span id="viewval_' . $htmlname .
'" class="viewval_' . $inputType . ($button_only ?
' inactive' :
' active') .
'">' . $value .
'</span>' .
"\n";
613 $out .=
'<span id="editval_' . $htmlname .
'" class="editval_' . $inputType . ($button_only ?
' inactive' :
' active') .
' hideobject">' . (!empty($editvalue) ? $editvalue : $value) .
'</span>' .
"\n";
639 public function textwithtooltip($text, $htmltext, $tooltipon = 1, $direction = 0, $img =
'', $extracss =
'', $notabs = 3, $incbefore =
'', $noencodehtmltext = 0, $tooltiptrigger =
'', $forcenowrap = 0)
642 $text = $incbefore . $text;
647 $direction = (int) $direction;
657 $htmltext = str_replace(array(
"\r",
"\n"),
'', $htmltext);
660 if ($direction < 0) {
661 $extracss = ($extracss ? $extracss .
' ' :
'') . ($notabs != 3 ?
'inline-block' :
'');
662 $extrastyle =
'padding: 0px; padding-left: 2px;';
664 if ($direction > 0) {
665 $extracss = ($extracss ? $extracss .
' ' :
'') . ($notabs != 3 ?
'inline-block' :
'');
666 $extrastyle =
'padding: 0px; padding-right: 2px;';
669 $classfortooltip =
'classfortooltip';
674 if ($tooltiptrigger ==
'') {
675 $htmltext = str_replace(
'"',
'"', $htmltext);
677 $classfortooltip =
'classfortooltiponclick';
678 $textfordialog .=
'<div style="display: none;" id="idfortooltiponclick_' . $tooltiptrigger .
'" class="classfortooltiponclicktext">' . $htmltext .
'</div>';
680 if ($tooltipon == 2 || $tooltipon == 3) {
681 $paramfortooltipimg =
' class="' . $classfortooltip . ($notabs != 3 ?
' inline-block' :
'') . ($extracss ?
' ' . $extracss :
'') .
'" style="padding: 0px;' . ($extrastyle ?
' ' . $extrastyle :
'') .
'"';
682 if ($tooltiptrigger ==
'') {
683 $paramfortooltipimg .=
' title="' . ($noencodehtmltext ? $htmltext :
dol_escape_htmltag($htmltext, 1)) .
'"';
685 $paramfortooltipimg .=
' dolid="' . $tooltiptrigger .
'"';
688 $paramfortooltipimg = ($extracss ?
' class="' . $extracss .
'"' :
'') . ($extrastyle ?
' style="' . $extrastyle .
'"' :
'');
690 if ($tooltipon == 1 || $tooltipon == 3) {
691 $paramfortooltiptd =
' class="' . ($tooltipon == 3 ?
'cursorpointer ' :
'') . $classfortooltip .
' inline-block' . ($extracss ?
' ' . $extracss :
'') .
'" style="padding: 0px;' . ($extrastyle ?
' ' . $extrastyle :
'') .
'" ';
692 if ($tooltiptrigger ==
'') {
693 $paramfortooltiptd .=
' title="' . ($noencodehtmltext ? $htmltext :
dol_escape_htmltag($htmltext, 1)) .
'"';
695 $paramfortooltiptd .=
' dolid="' . $tooltiptrigger .
'"';
698 $paramfortooltiptd = ($extracss ?
' class="' . $extracss .
'"' :
'') . ($extrastyle ?
' style="' . $extrastyle .
'"' :
'');
700 if (empty($notabs)) {
701 $s .=
'<table class="nobordernopadding"><tr style="height: auto;">';
702 } elseif ($notabs == 2) {
703 $s .=
'<div class="inline-block' . ($forcenowrap ?
' nowrap' :
'') .
'">';
706 if ($direction < 0) {
707 $s .=
'<' . $tag . $paramfortooltipimg;
709 $s .=
' class="valigntop" width="14"';
711 $s .=
'>' . $textfordialog . $img .
'</' . $tag .
'>';
715 if ((
string) $text !=
'') {
716 $s .=
'<' . $tag . $paramfortooltiptd .
'>' . $text .
'</' . $tag .
'>';
719 if ($direction > 0) {
720 $s .=
'<' . $tag . $paramfortooltipimg;
722 $s .=
' class="valignmiddle" width="14"';
724 $s .=
'>' . $textfordialog . $img .
'</' . $tag .
'>';
726 if (empty($notabs)) {
727 $s .=
'</tr></table>';
728 } elseif ($notabs == 2) {
749 public function textwithpicto($text, $htmltext, $direction = 1, $type =
'help', $extracss =
'', $noencodehtmltext = 0, $notabs = 3, $tooltiptrigger =
'', $forcenowrap = 0)
751 global $conf, $langs;
756 } elseif ($type ==
'1') {
760 $tooltiptrigger = preg_replace(
'/[^a-z0-9]/i',
'', $tooltiptrigger);
762 if (preg_match(
'/onsmartphone$/', $tooltiptrigger) && empty($conf->dol_no_mouse_hover)) {
763 $tooltiptrigger = preg_replace(
'/^.*onsmartphone$/',
'', $tooltiptrigger);
766 if ($tooltiptrigger) {
767 $alt = $langs->transnoentitiesnoconv(
"ClickToShowHelp");
771 if (empty($conf->use_javascript_ajax)) {
772 if ($type ==
'info' || $type ==
'infoclickable' || $type ==
'help' || $type ==
'helpclickable') {
781 if (!empty($conf->dol_no_mouse_hover) && empty($tooltiptrigger)) {
782 if ($type ==
'info' || $type ==
'infoclickable' || $type ==
'help' || $type ==
'helpclickable') {
793 if ($type ==
'info') {
795 } elseif ($type ==
'help') {
796 $img =
img_help(($tooltiptrigger !=
'' ? 2 : 1), $alt);
797 } elseif ($type ==
'helpclickable') {
798 $img =
img_help(($tooltiptrigger !=
'' ? 2 : 1), $alt);
799 } elseif ($type ==
'superadmin') {
802 } elseif ($type ==
'admin') {
805 } elseif ($type ==
'warning') {
807 } elseif ($type !=
'none') {
812 return $this->
textwithtooltip($text, $htmltext, ((($tooltiptrigger && !$img) || strpos($type,
'clickable')) ? 3 : 2), $direction, $img, $extracss, $notabs,
'', $noencodehtmltext, $tooltiptrigger, $forcenowrap);
825 public function selectMassAction($selected, $arrayofaction, $alwaysvisible = 0, $name =
'massaction', $cssclass =
'checkforselect')
827 global $conf, $langs, $hookmanager;
830 $ret =
'<div class="centpercent center">';
831 $ret .=
'<select class="flat' . (empty($conf->use_javascript_ajax) ?
'' :
' hideobject') .
' ' . $name .
' ' . $name .
'select valignmiddle alignstart" id="' . $name .
'" name="' . $name .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
'>';
834 $parameters = array();
835 $reshook = $hookmanager->executeHooks(
'addMoreMassActions', $parameters);
838 if (is_array($arrayofaction) && count($arrayofaction) == 0 && empty($hookmanager->resPrint)) {
841 if (empty($reshook)) {
842 $ret .=
'<option value="0"' . ($disabled ?
' disabled="disabled"' :
'') .
'>-- ' . $langs->trans(
"SelectAction") .
' --</option>';
843 if (is_array($arrayofaction)) {
844 foreach ($arrayofaction as $code => $label) {
845 $ret .=
'<option value="' . $code .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' data-html="' .
dol_escape_htmltag($label) .
'">' . $label .
'</option>';
849 $ret .= $hookmanager->resPrint;
853 if (empty($conf->dol_optimize_smallscreen)) {
858 $ret .=
'<input type="submit" name="confirmmassactioninvisible" style="display: none" tabindex="-1">';
859 $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")) .
'">';
862 if (!empty($conf->use_javascript_ajax)) {
863 $ret .=
'<!-- JS CODE TO ENABLE mass action select -->
865 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 checkfor select boxes */
867 atleastoneselected=0;
868 jQuery("."+cssclass).each(function( index ) {
869 /* console.log( index + ": " + $( this ).text() ); */
870 if ($(this).is(\':checked\')) atleastoneselected++;
873 console.log("initCheckForSelect mode="+mode+" name="+name+" cssclass="+cssclass+" atleastoneselected="+atleastoneselected);
875 if (atleastoneselected || ' . $alwaysvisible .
')
877 jQuery("."+name).show();
878 ' . ($selected ?
'if (atleastoneselected) { jQuery("."+name+"select").val("' . $selected .
'").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', false); }' :
'') .
'
879 ' . ($selected ?
'if (! atleastoneselected) { jQuery("."+name+"select").val("0").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', true); } ' :
'') .
'
883 jQuery("."+name).hide();
884 jQuery("."+name+"other").hide();
888 jQuery(document).ready(function () {
889 initCheckForSelect(0, "' . $name .
'", "' . $cssclass .
'");
890 jQuery(".' . $cssclass .
'").click(function() {
891 initCheckForSelect(1, "' . $name .
'", "' . $cssclass .
'");
893 jQuery(".' . $name .
'select").change(function() {
894 var massaction = $( this ).val();
895 var urlform = $( this ).closest("form").attr("action").replace("#show_files","");
896 if (massaction == "builddoc")
898 urlform = urlform + "#show_files";
900 $( this ).closest("form").attr("action", urlform);
901 console.log("we select a mass action name=' . $name .
' massaction="+massaction+" - "+urlform);
902 /* Warning: if you set submit button to disabled, post using Enter will no more work if there is no other button */
903 if ($(this).val() != \'0\')
905 jQuery(".' . $name .
'confirmed").prop(\'disabled\', false);
906 jQuery(".' . $name .
'other").hide(); /* To disable if another div was open */
907 jQuery(".' . $name .
'"+massaction).show();
911 jQuery(".' . $name .
'confirmed").prop(\'disabled\', true);
912 jQuery(".' . $name .
'other").hide(); /* To disable any div open */
941 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)
944 global $conf, $langs, $mysoc;
946 $langs->load(
"dict");
949 $countryArray = array();
952 $atleastonefavorite = 0;
954 $sql =
"SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite, eec";
955 $sql .=
" FROM " . $this->db->prefix() .
"c_country";
956 $sql .=
" WHERE active > 0";
959 dol_syslog(get_class($this) .
"::select_country", LOG_DEBUG);
960 $resql = $this->db->query($sql);
962 $out .=
'<select id="select' . $htmlname .
'" class="flat maxwidth200onsmartphone selectcountry' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" ' . $htmloption .
'>';
963 $num = $this->db->num_rows($resql);
967 $obj = $this->db->fetch_object($resql);
969 $countryArray[$i][
'rowid'] = $obj->rowid;
970 $countryArray[$i][
'code_iso'] = $obj->code_iso;
971 $countryArray[$i][
'code_iso3'] = $obj->code_iso3;
972 $countryArray[$i][
'label'] = ($obj->code_iso && $langs->transnoentitiesnoconv(
"Country" . $obj->code_iso) !=
"Country" . $obj->code_iso ? $langs->transnoentitiesnoconv(
"Country" . $obj->code_iso) : ($obj->label !=
'-' ? $obj->label :
''));
973 $countryArray[$i][
'favorite'] = $obj->favorite;
974 $countryArray[$i][
'eec'] = $obj->eec;
975 $favorite[$i] = $obj->favorite;
980 if (empty($disablefavorites)) {
981 $array1_sort_order = SORT_DESC;
982 $array2_sort_order = SORT_ASC;
983 array_multisort($favorite, $array1_sort_order, $label, $array2_sort_order, $countryArray);
989 if (is_numeric($showempty)) {
990 $out .=
'<option value=""> </option>' .
"\n";
992 $out .=
'<option value="-1">' . $langs->trans($showempty) .
'</option>' .
"\n";
996 if ($addspecialentries) {
998 $out .=
'<option value="special_allnotme"' . ($selected ==
'special_allnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesExceptMe", $langs->transnoentitiesnoconv(
"Country" . $mysoc->country_code)) .
'</option>';
999 $out .=
'<option value="special_eec"' . ($selected ==
'special_eec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEEC") .
'</option>';
1000 if ($mysoc->isInEEC()) {
1001 $out .=
'<option value="special_eecnotme"' . ($selected ==
'special_eecnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEECExceptMe", $langs->transnoentitiesnoconv(
"Country" . $mysoc->country_code)) .
'</option>';
1003 $out .=
'<option value="special_noteec"' . ($selected ==
'special_noteec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesNotInEEC") .
'</option>';
1004 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1007 foreach ($countryArray as $row) {
1009 if (empty($row[
'rowid'])) {
1012 if (is_array($exclude_country_code) && count($exclude_country_code) && in_array($row[
'code_iso'], $exclude_country_code)) {
1016 if (empty($disablefavorites) && $row[
'favorite'] && $row[
'code_iso']) {
1017 $atleastonefavorite++;
1019 if (empty($row[
'favorite']) && $atleastonefavorite) {
1020 $atleastonefavorite = 0;
1021 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1025 if ($row[
'label']) {
1026 $labeltoshow .=
dol_trunc($row[
'label'], $maxlength,
'middle');
1028 $labeltoshow .=
' ';
1030 if ($row[
'code_iso']) {
1031 $labeltoshow .=
' <span class="opacitymedium">(' . $row[
'code_iso'] .
')</span>';
1032 if (empty($hideflags)) {
1033 $tmpflag =
picto_from_langcode($row[
'code_iso'],
'class="saturatemedium paddingrightonly"', 1);
1034 $labeltoshow = $tmpflag .
' ' . $labeltoshow;
1038 if ($selected && $selected !=
'-1' && ($selected == $row[
'rowid'] || $selected == $row[
'code_iso'] || $selected == $row[
'code_iso3'] || $selected == $row[
'label'])) {
1039 $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']) .
'">';
1041 $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']) .
'">';
1043 $out .= $labeltoshow;
1044 $out .=
'</option>' .
"\n";
1047 $out .=
'</select>';
1053 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1054 $out .=
ajax_combobox(
'select' . $htmlname, array(), 0, 0,
'resolve');
1074 public function select_incoterms($selected =
'', $location_incoterms =
'', $page =
'', $htmlname =
'incoterm_id', $htmloption =
'', $forcecombo = 1, $events = array(), $disableautocomplete = 0)
1077 global $conf, $langs;
1079 $langs->load(
"dict");
1083 $incotermArray = array();
1085 $sql =
"SELECT rowid, code";
1086 $sql .=
" FROM " . $this->db->prefix() .
"c_incoterms";
1087 $sql .=
" WHERE active > 0";
1088 $sql .=
" ORDER BY code ASC";
1090 dol_syslog(get_class($this) .
"::select_incoterm", LOG_DEBUG);
1091 $resql = $this->db->query($sql);
1093 if ($conf->use_javascript_ajax && !$forcecombo) {
1094 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1098 if (!empty($page)) {
1099 $out .=
'<form method="post" action="' . $page .
'">';
1100 $out .=
'<input type="hidden" name="action" value="set_incoterms">';
1101 $out .=
'<input type="hidden" name="token" value="' . newToken() .
'">';
1104 $out .=
'<select id="' . $htmlname .
'" class="flat selectincoterm width75" name="' . $htmlname .
'" ' . $htmloption .
'>';
1105 $out .=
'<option value="0"> </option>';
1106 $num = $this->db->num_rows($resql);
1110 $obj = $this->db->fetch_object($resql);
1111 $incotermArray[$i][
'rowid'] = $obj->rowid;
1112 $incotermArray[$i][
'code'] = $obj->code;
1116 foreach ($incotermArray as $row) {
1117 if ($selected && ($selected == $row[
'rowid'] || $selected == $row[
'code'])) {
1118 $out .=
'<option value="' . $row[
'rowid'] .
'" selected>';
1120 $out .=
'<option value="' . $row[
'rowid'] .
'">';
1124 $out .= $row[
'code'];
1127 $out .=
'</option>';
1130 $out .=
'</select>';
1132 if ($conf->use_javascript_ajax && empty($disableautocomplete)) {
1133 $out .=
ajax_multiautocompleter(
'location_incoterms', array(), DOL_URL_ROOT .
'/core/ajax/locationincoterms.php') .
"\n";
1134 $moreattrib .=
' autocomplete="off"';
1136 $out .=
'<input id="location_incoterms" class="maxwidthonsmartphone type="text" name="location_incoterms" value="' . $location_incoterms .
'">' .
"\n";
1138 if (!empty($page)) {
1139 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp nomargintop nomarginbottom" value="' . $langs->trans(
"Modify") .
'"></form>';
1162 public function select_type_of_lines($selected =
'', $htmlname =
'type', $showempty = 0, $hidetext = 0, $forceall = 0, $morecss =
"")
1168 if ($forceall == 1 || (empty($forceall) && isModEnabled(
"product") && isModEnabled(
"service"))
1169 || (empty($forceall) && !isModEnabled(
'product') && !isModEnabled(
'service'))) {
1170 if (empty($hidetext)) {
1171 print $langs->trans(
"Type") .
': ';
1173 print
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
1175 print
'<option value="-1"';
1176 if ($selected == -1) {
1180 if (is_numeric($showempty)) {
1188 print
'<option value="0"';
1189 if (0 == $selected || ($selected == -1 &&
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') ==
'product')) {
1192 print
'>' . $langs->trans(
"Product");
1194 print
'<option value="1"';
1195 if (1 == $selected || ($selected == -1 &&
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') ==
'service')) {
1198 print
'>' . $langs->trans(
"Service");
1204 if ((empty($forceall) && !isModEnabled(
'product') && isModEnabled(
"service")) || $forceall == 3) {
1205 print $langs->trans(
"Service");
1206 print
'<input type="hidden" name="' . $htmlname .
'" value="1">';
1208 if ((empty($forceall) && isModEnabled(
"product") && !isModEnabled(
'service')) || $forceall == 2) {
1209 print $langs->trans(
"Product");
1210 print
'<input type="hidden" name="' . $htmlname .
'" value="0">';
1212 if ($forceall < 0) {
1213 print
'<input type="hidden" name="' . $htmlname .
'" value="1">';
1229 $num = count($this->cache_types_fees);
1236 $langs->load(
"trips");
1238 $sql =
"SELECT c.code, c.label";
1239 $sql .=
" FROM " . $this->db->prefix() .
"c_type_fees as c";
1240 $sql .=
" WHERE active > 0";
1242 $resql = $this->db->query($sql);
1244 $num = $this->db->num_rows($resql);
1248 $obj = $this->db->fetch_object($resql);
1251 $label = ($obj->code != $langs->trans($obj->code) ? $langs->trans($obj->code) : $langs->trans($obj->label));
1252 $this->cache_types_fees[$obj->code] = $label;
1256 asort($this->cache_types_fees);
1278 global $user, $langs;
1280 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
1284 print
'<select id="select_' . $htmlname .
'" class="flat" name="' . $htmlname .
'">';
1286 print
'<option value="-1"';
1287 if ($selected == -1) {
1290 print
'> </option>';
1293 foreach ($this->cache_types_fees as $key => $value) {
1294 print
'<option value="' . $key .
'"';
1295 if ($key == $selected) {
1305 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1334 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)
1337 global $conf, $langs;
1341 if (!empty($conf->use_javascript_ajax) &&
getDolGlobalString(
'COMPANY_USE_SEARCH_TO_SELECT') && !$forcecombo) {
1342 if (is_null($ajaxoptions)) {
1343 $ajaxoptions = array();
1346 require_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1350 if ($selected && empty($selected_input_value)) {
1351 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
1352 $societetmp =
new Societe($this->db);
1353 $societetmp->fetch($selected);
1354 $selected_input_value = $societetmp->name;
1359 $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)) :
'');
1361 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
1362 if (empty($hidelabel)) {
1363 print $langs->trans(
"RefOrLabel") .
' : ';
1364 } elseif ($hidelabel > 1) {
1365 $placeholder = $langs->trans(
"RefOrLabel");
1366 if ($hidelabel == 2) {
1367 $out .=
img_picto($langs->trans(
"Search"),
'search');
1370 $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' :
'') .
' />';
1371 if ($hidelabel == 3) {
1372 $out .=
img_picto($langs->trans(
"Search"),
'search');
1380 $out .= $this->
select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events,
'', 0, $limit, $morecss, $moreparam, $multiple, $excludeids, $showcode);
1414 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 =
'')
1418 global $conf, $langs;
1423 if ($nokeyifsocid && $socid > 0) {
1424 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = 0;
1427 if (!empty($conf->use_javascript_ajax) &&
getDolGlobalString(
'CONTACT_USE_SEARCH_TO_SELECT') && !$forcecombo) {
1428 if (is_null($events)) {
1432 require_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1436 if ($selected && empty($selected_input_value)) {
1437 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
1438 $contacttmp =
new Contact($this->db);
1439 $contacttmp->fetch($selected);
1440 $selected_input_value = $contacttmp->getFullName($langs);
1443 if (!is_numeric($showempty)) {
1444 $placeholder = $showempty;
1448 $urloption =
'htmlname=' . urlencode((
string) (str_replace(
'.',
'_', $htmlname))) .
'&outjson=1&filter=' . urlencode((
string) ($filter)) . (empty($exclude) ?
'' :
'&exclude=' . urlencode($exclude)) . ($showsoc ?
'&showsoc=' . urlencode((
string) ($showsoc)) :
'');
1450 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
1452 $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' :
'') .
' />';
1460 $disableifempty = 0;
1464 $out .= $this->
selectcontacts($socid, $selected, $htmlname, $showempty, $exclude, $limitto, $showfunction, $morecss, $options_only, $showsoc, $forcecombo, $events, $moreparam, $htmlid, $multiple, $disableifempty);
1467 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = $sav;
1499 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)
1502 global $user, $langs;
1503 global $hookmanager;
1507 $outarray = array();
1509 if ($selected ===
'') {
1510 $selected = array();
1511 } elseif (!is_array($selected)) {
1512 $selected = array($selected);
1516 if (function_exists(
'testSqlAndScriptInject')) {
1519 return 'SQLInjectionTryDetected';
1523 if ($filter !=
'') {
1524 if (preg_match(
'/[\(\)]/', $filter)) {
1530 if (function_exists(
'testSqlAndScriptInject')) {
1533 return 'SQLInjectionTryDetected';
1539 dol_syslog(
"Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Syntax.", LOG_WARNING);
1544 $sql =
"SELECT s.rowid, s.nom as name, s.name_alias, s.tva_intra, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
1546 $sql .=
", s.address, s.zip, s.town";
1547 $sql .=
", dictp.code as country_code";
1549 $sql .=
" FROM " . $this->db->prefix() .
"societe as s";
1551 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_country as dictp ON dictp.rowid = s.fk_pays";
1553 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1554 $sql .=
", " . $this->db->prefix() .
"societe_commerciaux as sc";
1556 $sql .=
" WHERE s.entity IN (" .
getEntity(
'societe') .
")";
1557 if (!empty($user->socid)) {
1558 $sql .=
" AND s.rowid = " . ((int) $user->socid);
1563 $sql .=
" AND (" . $filter .
")";
1565 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1566 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = " . ((int) $user->id);
1569 $sql .=
" AND s.status <> 0";
1571 if (!empty($excludeids)) {
1572 $sql .=
" AND s.rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeids)) .
")";
1575 $parameters = array();
1576 $reshook = $hookmanager->executeHooks(
'selectThirdpartyListWhere', $parameters);
1577 $sql .= $hookmanager->resPrint;
1579 if ($filterkey && $filterkey !=
'') {
1583 $search_crit = explode(
' ', $filterkey);
1585 if (count($search_crit) > 1) {
1588 foreach ($search_crit as $crit) {
1592 $sql .=
"(s.nom LIKE '" . $this->db->escape($prefix . $crit) .
"%')";
1595 if (count($search_crit) > 1) {
1598 if (isModEnabled(
'barcode')) {
1599 $sql .=
" OR s.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1601 $sql .=
" OR s.code_client LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.code_fournisseur LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1602 $sql .=
" OR s.name_alias LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.tva_intra LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1605 $sql .= $this->db->order(
"nom",
"ASC");
1606 $sql .= $this->db->plimit($limit, 0);
1609 dol_syslog(get_class($this).
"::select_thirdparty_list", LOG_DEBUG);
1610 $resql = $this->db->query($sql);
1613 $out .=
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
' name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
'>' .
"\n";
1615 $textifempty = (($showempty && !is_numeric($showempty)) ? $langs->trans($showempty) :
'');
1619 if ($showempty && !is_numeric($showempty)) {
1620 $textifempty = $langs->trans($showempty);
1622 $textifempty .= $langs->trans(
"All");
1626 $out .=
'<option value="-1" data-html="' .
dol_escape_htmltag(
'<span class="opacitymedium">' . ($textifempty ? $textifempty :
' ') .
'</span>') .
'">' . $textifempty .
'</option>' .
"\n";
1629 $companytemp =
new Societe($this->db);
1631 $num = $this->db->num_rows($resql);
1635 $obj = $this->db->fetch_object($resql);
1638 if (($obj->client) && (!empty($obj->code_client))) {
1639 $label = $obj->code_client .
' - ';
1641 if (($obj->fournisseur) && (!empty($obj->code_fournisseur))) {
1642 $label .= $obj->code_fournisseur .
' - ';
1644 $label .=
' ' . $obj->name;
1646 $label = $obj->name;
1649 if (!empty($obj->name_alias)) {
1650 $label .=
' (' . $obj->name_alias .
')';
1654 $label .=
' - '.$obj->tva_intra;
1657 $labelhtml = $label;
1660 $companytemp->id = $obj->rowid;
1661 $companytemp->client = $obj->client;
1662 $companytemp->fournisseur = $obj->fournisseur;
1663 $tmptype = $companytemp->getTypeUrl(1,
'', 0,
'span');
1665 $labelhtml .=
' ' . $tmptype;
1668 if ($obj->client || $obj->fournisseur) {
1671 if ($obj->client == 1 || $obj->client == 3) {
1672 $label .= $langs->trans(
"Customer");
1674 if ($obj->client == 2 || $obj->client == 3) {
1675 $label .= ($obj->client == 3 ?
', ' :
'') . $langs->trans(
"Prospect");
1677 if ($obj->fournisseur) {
1678 $label .= ($obj->client ?
', ' :
'') . $langs->trans(
"Supplier");
1680 if ($obj->client || $obj->fournisseur) {
1686 $s = ($obj->address ?
' - ' . $obj->address :
'') . ($obj->zip ?
' - ' . $obj->zip :
'') . ($obj->town ?
' ' . $obj->town :
'');
1687 if (!empty($obj->country_code)) {
1688 $s .=
', ' . $langs->trans(
'Country' . $obj->country_code);
1694 if (empty($outputmode)) {
1695 if (in_array($obj->rowid, $selected)) {
1696 $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>';
1698 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
1701 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label,
'labelhtml' => $labelhtml));
1705 if (($i % 10) == 0) {
1710 $out .=
'</select>' .
"\n";
1712 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1719 $this->result = array(
'nbofthirdparties' => $num);
1754 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 =
'')
1756 global $conf, $langs, $hookmanager, $action;
1758 $langs->load(
'companies');
1760 if (empty($htmlid)) {
1761 $htmlid = $htmlname;
1765 $outarray = array();
1767 if ($selected ===
'') {
1768 $selected = array();
1769 } elseif (!is_array($selected)) {
1770 $selected = array((
int) $selected);
1774 if (function_exists(
'testSqlAndScriptInject')) {
1777 return 'SQLInjectionTryDetected';
1781 if ($filter !=
'') {
1782 if (preg_match(
'/[\(\)]/', $filter)) {
1788 if (function_exists(
'testSqlAndScriptInject')) {
1791 return 'SQLInjectionTryDetected';
1797 dol_syslog(
"Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Syntax.", LOG_WARNING);
1801 if (!is_object($hookmanager)) {
1802 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
1807 $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";
1808 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
1809 $sql .=
", s.nom as company, s.town AS company_town";
1811 $sql .=
" FROM " . $this->db->prefix() .
"socpeople as sp";
1812 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
1813 $sql .=
" LEFT OUTER JOIN " . $this->db->prefix() .
"societe as s ON s.rowid=sp.fk_soc";
1815 $sql .=
" WHERE sp.entity IN (" .
getEntity(
'contact') .
")";
1816 if ($socid > 0 || $socid == -1) {
1817 $sql .=
" AND sp.fk_soc = " . ((int) $socid);
1820 $sql .=
" AND sp.statut <> 0";
1825 $sql .=
" AND (" . $filter .
")";
1828 $parameters = array();
1829 $reshook = $hookmanager->executeHooks(
'selectContactListWhere', $parameters);
1830 $sql .= $hookmanager->resPrint;
1831 $sql .=
" ORDER BY sp.lastname ASC";
1833 dol_syslog(get_class($this) .
"::selectcontacts", LOG_DEBUG);
1834 $resql = $this->db->query($sql);
1836 $num = $this->db->num_rows($resql);
1838 if ($htmlname !=
'none' && !$options_only) {
1839 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlid .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . (($num || empty($disableifempty)) ?
'' :
' disabled') . ($multiple ?
'multiple' :
'') .
' ' . (!empty($moreparam) ? $moreparam :
'') .
'>';
1842 if ($showempty && !is_numeric($showempty)) {
1843 $textforempty = $showempty;
1844 $out .=
'<option class="optiongrey" value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'>' . $textforempty .
'</option>';
1846 if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) {
1847 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'> </option>';
1849 if ($showempty == 2) {
1850 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Internal") .
' --</option>';
1856 include_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
1857 $contactstatic =
new Contact($this->db);
1860 $obj = $this->db->fetch_object($resql);
1863 $extendedInfos =
'';
1865 $extendedInfos = array();
1866 $email = trim($obj->email);
1867 if (!empty($email)) {
1868 $extendedInfos[] = $email;
1870 $phone = trim($obj->phone);
1871 $phone_perso = trim($obj->phone_perso);
1872 $phone_mobile = trim($obj->phone_mobile);
1873 if (!empty($phone)) {
1874 $extendedInfos[] = $phone;
1876 if (!empty($phone_perso)) {
1877 $extendedInfos[] = $phone_perso;
1879 if (!empty($phone_mobile)) {
1880 $extendedInfos[] = $phone_mobile;
1883 $contact_town = trim($obj->contact_town);
1884 $company_town = trim($obj->company_town);
1885 if (!empty($contact_town)) {
1886 $extendedInfos[] = $contact_town;
1887 } elseif (!empty($company_town)) {
1888 $extendedInfos[] = $company_town;
1890 $extendedInfos = implode(
' - ', $extendedInfos);
1891 if (!empty($extendedInfos)) {
1892 $extendedInfos =
' - ' . $extendedInfos;
1896 $contactstatic->id = $obj->rowid;
1897 $contactstatic->lastname = $obj->lastname;
1898 $contactstatic->firstname = $obj->firstname;
1899 if ($obj->statut == 1) {
1901 if ($htmlname !=
'none') {
1903 if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) {
1906 if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) {
1909 if (!empty($selected) && in_array($obj->rowid, $selected)) {
1910 $out .=
'<option value="' . $obj->rowid .
'"';
1912 $out .=
' disabled';
1914 $out .=
' selected>';
1916 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1917 if ($showfunction && $obj->poste) {
1918 $tmplabel .=
' (' . $obj->poste .
')';
1920 if (($showsoc > 0) && $obj->company) {
1921 $tmplabel .=
' - (' . $obj->company .
')';
1925 $out .=
'</option>';
1927 $out .=
'<option value="' . $obj->rowid .
'"';
1929 $out .=
' disabled';
1933 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1934 if ($showfunction && $obj->poste) {
1935 $tmplabel .=
' (' . $obj->poste .
')';
1937 if (($showsoc > 0) && $obj->company) {
1938 $tmplabel .=
' - (' . $obj->company .
')';
1942 $out .=
'</option>';
1945 if (in_array($obj->rowid, $selected)) {
1946 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1947 if ($showfunction && $obj->poste) {
1948 $tmplabel .=
' (' . $obj->poste .
')';
1950 if (($showsoc > 0) && $obj->company) {
1951 $tmplabel .=
' - (' . $obj->company .
')';
1958 if ($tmplabel !=
'') {
1959 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $tmplabel,
'label' => $tmplabel,
'labelhtml' => $tmplabel));
1965 $labeltoshow = ($socid != -1) ? ($langs->trans($socid ?
"NoContactDefinedForThirdParty" :
"NoContactDefined")) : $langs->trans(
'SelectAThirdPartyFirst');
1966 $out .=
'<option class="disabled" value="-1"' . (($showempty == 2 || $multiple) ?
'' :
' selected') .
' disabled="disabled">';
1967 $out .= $labeltoshow;
1968 $out .=
'</option>';
1971 $parameters = array(
1973 'htmlname' => $htmlname,
1976 'showfunction' => $showfunction,
1977 'showsoc' => $showsoc,
1980 $reshook = $hookmanager->executeHooks(
'afterSelectContactOptions', $parameters, $this, $action);
1982 if ($htmlname !=
'none' && !$options_only) {
1983 $out .=
'</select>';
1986 if ($conf->use_javascript_ajax && !$forcecombo && !$options_only) {
1987 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1993 if ($options_only === 2) {
2021 global $langs, $conf;
2024 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
2025 $sql .=
" re.description, re.fk_facture_source";
2026 $sql .=
" FROM " . $this->db->prefix() .
"societe_remise_except as re";
2027 $sql .=
" WHERE re.fk_soc = " . (int) $socid;
2028 $sql .=
" AND re.entity = " . $conf->entity;
2030 $sql .=
" AND " . $filter;
2032 $sql .=
" ORDER BY re.description ASC";
2034 dol_syslog(get_class($this) .
"::select_remises", LOG_DEBUG);
2035 $resql = $this->db->query($sql);
2037 print
'<select id="select_' . $htmlname .
'" class="flat maxwidthonsmartphone" name="' . $htmlname .
'">';
2038 $num = $this->db->num_rows($resql);
2040 $qualifiedlines = $num;
2044 print
'<option value="0"> </option>';
2046 $obj = $this->db->fetch_object($resql);
2047 $desc =
dol_trunc($obj->description, 40);
2048 if (preg_match(
'/\(CREDIT_NOTE\)/', $desc)) {
2049 $desc = preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $desc);
2051 if (preg_match(
'/\(DEPOSIT\)/', $desc)) {
2052 $desc = preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"Deposit"), $desc);
2054 if (preg_match(
'/\(EXCESS RECEIVED\)/', $desc)) {
2055 $desc = preg_replace(
'/\(EXCESS RECEIVED\)/', $langs->trans(
"ExcessReceived"), $desc);
2057 if (preg_match(
'/\(EXCESS PAID\)/', $desc)) {
2058 $desc = preg_replace(
'/\(EXCESS PAID\)/', $langs->trans(
"ExcessPaid"), $desc);
2062 if ($selected > 0 && $selected == $obj->rowid) {
2063 $selectstring =
' selected';
2067 if ($maxvalue > 0 && $obj->amount_ttc > $maxvalue) {
2069 $disabled =
' disabled';
2072 if (
getDolGlobalString(
'MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST') && !empty($obj->fk_facture_source)) {
2073 $tmpfac =
new Facture($this->db);
2074 if ($tmpfac->fetch($obj->fk_facture_source) > 0) {
2075 $desc = $desc .
' - ' . $tmpfac->ref;
2079 print
'<option value="' . $obj->rowid .
'"' . $selectstring . $disabled .
'>' . $desc .
' (' .
price($obj->amount_ht) .
' ' . $langs->trans(
"HT") .
' - ' .
price($obj->amount_ttc) .
' ' . $langs->trans(
"TTC") .
')</option>';
2086 return $qualifiedlines;
2111 public function select_users($selected =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include =
'', $enableonly = array(), $force_entity =
'0')
2114 print $this->
select_dolusers($selected, $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity);
2143 public function select_dolusers($selected =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include =
'', $enableonly =
'', $force_entity =
'', $maxlength = 0, $showstatus = 0, $morefilter =
'', $show_every = 0, $enableonlytext =
'', $morecss =
'', $notdisabled = 0, $outputmode = 0, $multiple =
false, $forcecombo = 0)
2146 global $conf, $user, $langs, $hookmanager;
2150 if ((is_numeric($selected) && ($selected < -2 || empty($selected))) && !
getDolGlobalString(
'SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE')) {
2151 $selected = $user->id;
2154 if ($selected ===
'') {
2155 $selected = array();
2156 } elseif (!is_array($selected)) {
2157 $selected = array($selected);
2160 $excludeUsers =
null;
2161 $includeUsers =
null;
2164 if (is_array($exclude)) {
2165 $excludeUsers = implode(
",", $exclude);
2168 if (is_array($include)) {
2169 $includeUsers = implode(
",", $include);
2170 } elseif ($include ==
'hierarchy') {
2172 $includeUsers = implode(
",", $user->getAllChildIds(0));
2173 } elseif ($include ==
'hierarchyme') {
2175 $includeUsers = implode(
",", $user->getAllChildIds(1));
2181 $outarray = array();
2182 $outarray2 = array();
2185 $showlabelofentity = isModEnabled(
'multicompany') && !
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE') && $conf->entity == 1 && !empty($user->admin) && empty($user->entity);
2186 $userissuperadminentityone = isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && empty($user->entity);
2189 $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";
2190 if ($showlabelofentity) {
2191 $sql .=
", e.label";
2193 $sql .=
" FROM " . $this->db->prefix() .
"user as u";
2194 if ($showlabelofentity) {
2195 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid = u.entity";
2198 if ($userissuperadminentityone && $force_entity !=
'default') {
2199 if (!empty($force_entity)) {
2200 $sql .=
" WHERE u.entity IN (0, " . $this->db->sanitize($force_entity) .
")";
2202 $sql .=
" WHERE u.entity IS NOT NULL";
2205 if (isModEnabled(
'multicompany') &&
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE')) {
2206 $sql .=
" WHERE u.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
2208 $sql .=
" WHERE u.entity IN (" .
getEntity(
'user') .
")";
2212 if (!empty($user->socid)) {
2213 $sql .=
" AND u.fk_soc = " . ((int) $user->socid);
2215 if (is_array($exclude) && $excludeUsers) {
2216 $sql .=
" AND u.rowid NOT IN (" . $this->db->sanitize($excludeUsers) .
")";
2218 if ($includeUsers) {
2219 $sql .=
" AND u.rowid IN (" . $this->db->sanitize($includeUsers) .
")";
2222 $sql .=
" AND u.statut <> 0";
2225 $sql .=
" AND u.employee <> 0";
2228 $sql .=
" AND u.fk_soc IS NULL";
2230 if (!empty($morefilter)) {
2231 $sql .=
" " . $morefilter;
2235 $reshook = $hookmanager->executeHooks(
'addSQLWhereFilterOnSelectUsers', array(), $this, $action);
2236 if (!empty($reshook)) {
2237 $sql .= $hookmanager->resPrint;
2241 $sql .=
" ORDER BY u.statut DESC, u.firstname ASC, u.lastname ASC";
2243 $sql .=
" ORDER BY u.statut DESC, u.lastname ASC, u.firstname ASC";
2246 dol_syslog(get_class($this) .
"::select_dolusers", LOG_DEBUG);
2248 $resql = $this->db->query($sql);
2250 $num = $this->db->num_rows($resql);
2254 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
' minwidth200') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
2255 if ($show_empty && !$multiple) {
2256 $textforempty =
' ';
2257 if (!empty($conf->use_javascript_ajax)) {
2258 $textforempty =
' ';
2260 if (!is_numeric($show_empty)) {
2261 $textforempty = $show_empty;
2263 $out .=
'<option class="optiongrey" value="' . ($show_empty < 0 ? $show_empty : -1) .
'"' . ((empty($selected) || in_array(-1, $selected)) ?
' selected' :
'') .
'>' . $textforempty .
'</option>' .
"\n";
2266 $out .=
'<option value="-2"' . ((in_array(-2, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Everybody") .
' --</option>' .
"\n";
2269 $userstatic =
new User($this->db);
2272 $obj = $this->db->fetch_object($resql);
2274 $userstatic->id = $obj->rowid;
2275 $userstatic->lastname = $obj->lastname;
2276 $userstatic->firstname = $obj->firstname;
2277 $userstatic->photo = $obj->photo;
2278 $userstatic->status = $obj->status;
2279 $userstatic->entity = $obj->entity;
2280 $userstatic->admin = $obj->admin;
2281 $userstatic->gender = $obj->gender;
2284 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
2285 $disableline = ($enableonlytext ? $enableonlytext :
'1');
2289 $labeltoshowhtml =
'';
2296 $labeltoshow .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2297 $labeltoshowhtml .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2298 if (empty($obj->firstname) && empty($obj->lastname)) {
2299 $labeltoshow .= $obj->login;
2300 $labeltoshowhtml .= $obj->login;
2307 $moreinfo .= ($moreinfo ?
' - ' :
' (');
2308 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(');
2309 $moreinfo .= $obj->login;
2310 $moreinfohtml .= $obj->login;
2312 if ($showstatus >= 0) {
2313 if ($obj->status == 1 && $showstatus == 1) {
2314 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Enabled');
2315 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Enabled');
2317 if ($obj->status == 0 && $showstatus == 1) {
2318 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Disabled');
2319 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Disabled');
2322 if ($showlabelofentity) {
2323 if (empty($obj->entity)) {
2324 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
"AllEntities");
2325 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
"AllEntities");
2327 if ($obj->entity != $conf->entity) {
2328 $moreinfo .= ($moreinfo ?
' - ' :
' (') . ($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2329 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(').($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2333 $moreinfo .= (!empty($moreinfo) ?
')' :
'');
2334 $moreinfohtml .= (!empty($moreinfohtml) ?
')</span>' :
'');
2335 if (!empty($disableline) && $disableline !=
'1') {
2337 $moreinfo .=
' - ' . $disableline;
2338 $moreinfohtml .=
' - ' . $disableline;
2340 $labeltoshow .= $moreinfo;
2341 $labeltoshowhtml .= $moreinfohtml;
2343 $out .=
'<option value="' . $obj->rowid .
'"';
2344 if (!empty($disableline)) {
2345 $out .=
' disabled';
2347 if ((!empty($selected[0]) && is_object($selected[0])) ? $selected[0]->id == $obj->rowid : in_array($obj->rowid, $selected)) {
2348 $out .=
' selected';
2350 $out .=
' data-html="';
2352 $outhtml = $userstatic->getNomUrl(-3,
'', 0, 1, 24, 1,
'login',
'', 1) .
' ';
2353 if ($showstatus >= 0 && $obj->status == 0) {
2354 $outhtml .=
'<strike class="opacitymediumxxx">';
2356 $outhtml .= $labeltoshowhtml;
2357 if ($showstatus >= 0 && $obj->status == 0) {
2358 $outhtml .=
'</strike>';
2360 $labeltoshowhtml = $outhtml;
2364 $out .= $labeltoshow;
2365 $out .=
'</option>';
2367 $outarray[$userstatic->id] = $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength) . $moreinfo;
2368 $outarray2[$userstatic->id] = array(
2369 'id' => $userstatic->id,
2370 'label' => $labeltoshow,
2371 'labelhtml' => $labeltoshowhtml,
2379 $out .=
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'" disabled>';
2380 $out .=
'<option value="">' . $langs->trans(
"None") .
'</option>';
2382 $out .=
'</select>';
2384 if ($num && !$forcecombo) {
2386 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2395 if ($outputmode == 2) {
2397 } elseif ($outputmode) {
2428 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())
2433 $userstatic =
new User($this->db);
2436 if (!empty($_SESSION[
'assignedtouser'])) {
2437 $assignedtouser = json_decode($_SESSION[
'assignedtouser'],
true);
2438 if (!is_array($assignedtouser)) {
2439 $assignedtouser = array();
2442 $assignedtouser = array();
2444 $nbassignetouser = count($assignedtouser);
2447 if ($nbassignetouser) {
2448 $out .=
'<ul class="attendees">';
2452 foreach ($assignedtouser as $key => $value) {
2453 if ($value[
'id'] == $ownerid) {
2458 $userstatic->fetch($value[
'id']);
2459 $out .= $userstatic->getNomUrl(-1);
2461 $ownerid = $value[
'id'];
2462 $out .=
' (' . $langs->trans(
"Owner") .
')';
2464 if ($nbassignetouser > 1 && $action !=
'view') {
2465 $out .=
' <input type="image" style="border: 0px;" src="' .
img_picto($langs->trans(
"Remove"),
'delete',
'', 0, 1) .
'" value="' . $userstatic->id .
'" class="removedassigned reposition" id="removedassigned_' . $userstatic->id .
'" name="removedassigned_' . $userstatic->id .
'">';
2468 if ($showproperties) {
2469 if ($ownerid == $value[
'id'] && is_array($listofuserid) && count($listofuserid) && in_array($ownerid, array_keys($listofuserid))) {
2470 $out .=
'<div class="myavailability inline-block">';
2471 $out .=
'<span class="hideonsmartphone"> - <span class="opacitymedium">' . $langs->trans(
"Availability") .
':</span> </span><input id="transparency" class="paddingrightonly" ' . ($action ==
'view' ?
'disabled' :
'') .
' type="checkbox" name="transparency"' . ($listofuserid[$ownerid][
'transparency'] ?
' checked' :
'') .
'><label for="transparency">' . $langs->trans(
"Busy") .
'</label>';
2481 if ($nbassignetouser) {
2486 if ($action !=
'view') {
2487 $out .=
'<input type="hidden" class="removedassignedhidden" name="removedassigned" value="">';
2488 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
2489 $out .=
'jQuery(".removedassigned").click(function() { jQuery(".removedassignedhidden").val(jQuery(this).val()); });';
2490 $out .=
'jQuery(".assignedtouser").change(function() { console.log(jQuery(".assignedtouser option:selected").val());';
2491 $out .=
' if (jQuery(".assignedtouser option:selected").val() > 0) { jQuery("#' . $action .
'assignedtouser").attr("disabled", false); }';
2492 $out .=
' else { jQuery("#' . $action .
'assignedtouser").attr("disabled", true); }';
2494 $out .=
'})</script>';
2495 $out .= $this->
select_dolusers(
'', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter);
2496 $out .=
' <input type="submit" disabled class="button valignmiddle smallpaddingimp reposition" id="' . $action .
'assignedtouser" name="' . $action .
'assignedtouser" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
2523 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())
2528 require_once DOL_DOCUMENT_ROOT.
'/resource/class/html.formresource.class.php';
2529 require_once DOL_DOCUMENT_ROOT.
'/resource/class/dolresource.class.php';
2534 if (!empty($_SESSION[
'assignedtoresource'])) {
2535 $assignedtoresource = json_decode($_SESSION[
'assignedtoresource'],
true);
2536 if (!is_array($assignedtoresource)) {
2537 $assignedtoresource = array();
2540 $assignedtoresource = array();
2542 $nbassignetoresource = count($assignedtoresource);
2545 if ($nbassignetoresource) {
2546 $out .=
'<ul class="attendees">';
2550 foreach ($assignedtoresource as $key => $value) {
2552 $resourcestatic->fetch($value[
'id']);
2553 $out .= $resourcestatic->getNomUrl(-1);
2554 if ($nbassignetoresource > 1 && $action !=
'view') {
2555 $out .=
' <input type="image" style="border: 0px;" src="' .
img_picto($langs->trans(
"Remove"),
'delete',
'', 0, 1) .
'" value="' . $resourcestatic->id .
'" class="removedassigned reposition" id="removedassignedresource_' . $resourcestatic->id .
'" name="removedassignedresource_' . $resourcestatic->id .
'">';
2558 if ($showproperties) {
2559 if (is_array($listofresourceid) && count($listofresourceid)) {
2560 $out .=
'<div class="myavailability inline-block">';
2561 $out .=
'<span class="hideonsmartphone"> - <span class="opacitymedium">' . $langs->trans(
"Availability") .
':</span> </span><input id="transparencyresource" class="paddingrightonly" ' . ($action ==
'view' ?
'disabled' :
'') .
' type="checkbox" name="transparency"' . ($listofresourceid[$value[
'id']][
'transparency'] ?
' checked' :
'') .
'><label for="transparency">' . $langs->trans(
"Busy") .
'</label>';
2571 if ($nbassignetoresource) {
2576 if ($action !=
'view') {
2577 $out .=
'<input type="hidden" class="removedassignedhidden" name="removedassignedresource" value="">';
2578 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
2579 $out .=
'jQuery(".removedassignedresource").click(function() { jQuery(".removedassignedresourcehidden").val(jQuery(this).val()); });';
2580 $out .=
'jQuery(".assignedtoresource").change(function() { console.log(jQuery(".assignedtoresource option:selected").val());';
2581 $out .=
' if (jQuery(".assignedtoresource option:selected").val() > 0) { jQuery("#' . $action .
'assignedtoresource").attr("disabled", false); }';
2582 $out .=
' else { jQuery("#' . $action .
'assignedtoresource").attr("disabled", true); }';
2584 $out .=
'})</script>';
2587 $out .=
img_picto(
'',
'resource',
'class="pictofixedwidth"');
2588 $out .= $formresources->select_resource_list(0, $htmlname, [], 1, 1, 0, $events, array(), 2, 0);
2590 $out .=
' <input type="submit" disabled class="button valignmiddle smallpaddingimp reposition" id="' . $action .
'assignedtoresource" name="' . $action .
'assignedtoresource" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
2627 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)
2630 global $langs, $conf;
2635 $price_level = (!empty($price_level) ? $price_level : 0);
2636 if (is_null($ajaxoptions)) {
2637 $ajaxoptions = array();
2640 if (strval($filtertype) ===
'' && (isModEnabled(
"product") || isModEnabled(
"service"))) {
2641 if (isModEnabled(
"product") && !isModEnabled(
'service')) {
2643 } elseif (!isModEnabled(
'product') && isModEnabled(
"service")) {
2648 if (!empty($conf->use_javascript_ajax) &&
getDolGlobalString(
'PRODUIT_USE_SEARCH_TO_SELECT')) {
2651 if ($selected && empty($selected_input_value)) {
2652 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
2653 $producttmpselect =
new Product($this->db);
2654 $producttmpselect->fetch($selected);
2655 $selected_input_value = $producttmpselect->ref;
2656 unset($producttmpselect);
2659 if ($filtertype ==
'') {
2660 if (!isModEnabled(
'product')) {
2662 } elseif (!isModEnabled(
'service')) {
2667 $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;
2668 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT .
'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
2670 if (isModEnabled(
'variants') && is_array($selected_combinations)) {
2674 <!-- script to auto show attributes select tags if a variant was selected -->
2675 <script nonce="' .
getNonce() .
'">
2676 // auto show attributes fields
2677 selected = ' . json_encode($selected_combinations) .
';
2680 jQuery(document).ready(function () {
2682 jQuery("input[name=\'prod_entry_mode\']").change(function () {
2683 if (jQuery(this).val() == \'free\') {
2684 jQuery(\'div#attributes_box\').empty();
2688 jQuery("input#' . $htmlname .
'").change(function () {
2690 if (!jQuery(this).val()) {
2691 jQuery(\'div#attributes_box\').empty();
2695 console.log("A change has started. We get variants fields to inject html select");
2697 jQuery.getJSON("' . DOL_URL_ROOT .
'/variants/ajax/getCombinations.php", {
2698 id: jQuery(this).val()
2699 }, function (data) {
2700 jQuery(\'div#attributes_box\').empty();
2702 jQuery.each(data, function (key, val) {
2704 combvalues[val.id] = val.values;
2706 var span = jQuery(document.createElement(\'div\')).css({
2707 \'display\': \'table-row\'
2711 jQuery(document.createElement(\'div\')).text(val.label).css({
2712 \'font-weight\': \'bold\',
2713 \'display\': \'table-cell\'
2717 var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({
2718 \'margin-left\': \'15px\',
2719 \'white-space\': \'pre\'
2721 jQuery(document.createElement(\'option\')).val(\'\')
2724 jQuery.each(combvalues[val.id], function (key, val) {
2725 var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value);
2727 if (selected[val.fk_product_attribute] == val.id) {
2728 tag.attr(\'selected\', \'selected\');
2735 jQuery(\'div#attributes_box\').append(span);
2740 ' . ($selected ?
'jQuery("input#' . $htmlname .
'").change();' :
'') .
'
2746 if (empty($hidelabel)) {
2747 $out .= $langs->trans(
"RefOrLabel") .
' : ';
2748 } elseif ($hidelabel > 1) {
2749 $placeholder =
' placeholder="' . $langs->trans(
"RefOrLabel") .
'"';
2750 if ($hidelabel == 2) {
2751 $out .=
img_picto($langs->trans(
"Search"),
'search');
2754 $out .=
'<input type="text" class="minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . $placeholder .
' ' . (
getDolGlobalString(
'PRODUCT_SEARCH_AUTOFOCUS') ?
'autofocus' :
'') .
' />';
2755 if ($hidelabel == 3) {
2756 $out .=
img_picto($langs->trans(
"Search"),
'search');
2759 $out .= $this->
select_produits_list($selected, $htmlname, $filtertype, $limit, $price_level,
'', $status, $finished, 0, $socid, $showempty, $forcecombo, $morecss, $hidepriceinlabel, $warehouseStatus, $status_purchase);
2762 if (empty($nooutput)) {
2786 public function select_bom($selected =
'', $htmlname =
'bom_id', $limit = 0, $status = 1, $type = 0, $showempty =
'1', $morecss =
'', $nooutput =
'', $forcecombo = 0, $TProducts = [])
2791 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
2797 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2802 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
2804 $sql =
'SELECT b.rowid, b.ref, b.label, b.fk_product';
2805 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'bom_bom as b';
2806 $sql .=
' WHERE b.entity IN (' .
getEntity(
'bom') .
')';
2807 if (!empty($status)) {
2808 $sql .=
' AND status = ' . (int) $status;
2810 if (!empty($type)) {
2811 $sql .=
' AND bomtype = ' . (int) $type;
2813 if (!empty($TProducts)) {
2814 $sql .=
' AND fk_product IN (' . $this->db->sanitize(implode(
',', $TProducts)) .
')';
2816 if (!empty($limit)) {
2817 $sql .=
' LIMIT ' . (int) $limit;
2819 $resql = $db->query($sql);
2822 $out .=
'<option value="-1"';
2823 if (empty($selected)) {
2824 $out .=
' selected';
2826 $out .=
'> </option>';
2828 while ($obj = $db->fetch_object($resql)) {
2830 $res = $product->fetch($obj->fk_product);
2831 $out .=
'<option value="' . $obj->rowid .
'"';
2832 if ($obj->rowid == $selected) {
2835 $out .=
'>' . $obj->ref .
' - ' . $product->label .
' - ' . $obj->label .
'</option>';
2841 $out .=
'</select>';
2842 if (empty($nooutput)) {
2876 public function select_produits_list($selected = 0, $htmlname =
'productid', $filtertype =
'', $limit = 20, $price_level = 0, $filterkey =
'', $status = 1, $finished = 2, $outputmode = 0, $socid = 0, $showempty =
'1', $forcecombo = 0, $morecss =
'maxwidth500', $hidepriceinlabel = 0, $warehouseStatus =
'', $status_purchase = -1)
2880 global $hookmanager;
2883 $outarray = array();
2887 $langs->load(
'other');
2890 $warehouseStatusArray = array();
2891 if (!empty($warehouseStatus)) {
2892 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/entrepot.class.php';
2893 if (preg_match(
'/warehouseclosed/', $warehouseStatus)) {
2896 if (preg_match(
'/warehouseopen/', $warehouseStatus)) {
2899 if (preg_match(
'/warehouseinternal/', $warehouseStatus)) {
2904 $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";
2905 if (count($warehouseStatusArray)) {
2906 $selectFieldsGrouped =
", sum(" . $this->db->ifsql(
"e.statut IS NULL",
"0",
"ps.reel") .
") as stock";
2908 $selectFieldsGrouped =
", " . $this->db->ifsql(
"p.stock IS NULL", 0,
"p.stock") .
" AS stock";
2914 $parameters = array();
2915 $reshook = $hookmanager->executeHooks(
'selectProductsListSelect', $parameters);
2916 if (empty($reshook)) {
2917 $sql .= $selectFields.$selectFieldsGrouped.$hookmanager->resPrint;
2919 $sql .= $hookmanager->resPrint;
2924 $sql .=
", (SELECT " . $this->db->prefix() .
"categorie_product.fk_categorie
2925 FROM " . $this->db->prefix() .
"categorie_product
2926 WHERE " . $this->db->prefix() .
"categorie_product.fk_product=p.rowid
2928 ) AS categorie_product_id ";
2933 $sql .=
', pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,';
2934 $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';
2935 $selectFields .=
", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custdefault_vat_code, custref";
2939 $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";
2940 $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';
2945 $sql .=
", pl.label as label_translated";
2946 $sql .=
", pl.description as description_translated";
2947 $selectFields .=
", label_translated";
2948 $selectFields .=
", description_translated";
2952 $sql .=
", (SELECT pp.rowid FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
2953 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
2954 $sql .=
" AND price_level = " . ((int) $price_level);
2956 $sql .=
" ORDER BY date_price";
2957 $sql .=
" DESC LIMIT 1) as price_rowid";
2958 $sql .=
", (SELECT pp.price_by_qty FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
2959 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
2960 $sql .=
" AND price_level = " . ((int) $price_level);
2962 $sql .=
" ORDER BY date_price";
2963 $sql .=
" DESC LIMIT 1) as price_by_qty";
2964 $selectFields .=
", price_rowid, price_by_qty";
2967 $sql .=
" FROM ".$this->db->prefix().
"product as p";
2970 $sql .=
" USE INDEX (" . $this->db->sanitize(
getDolGlobalString(
'MAIN_PRODUCT_FORCE_INDEX')) .
")";
2974 $parameters = array();
2975 $reshook = $hookmanager->executeHooks(
'selectProductsListFrom', $parameters);
2976 $sql .= $hookmanager->resPrint;
2978 if (count($warehouseStatusArray)) {
2979 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_stock as ps on ps.fk_product = p.rowid";
2980 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entrepot as e on ps.fk_entrepot = e.rowid AND e.entity IN (" .
getEntity(
'stock') .
")";
2981 $sql .=
' AND e.statut IN (' . $this->db->sanitize($this->db->escape(implode(
',', $warehouseStatusArray))) .
')';
2986 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
2991 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_customer_price as pcp ON pcp.fk_soc=" . ((int) $socid) .
" AND pcp.fk_product=p.rowid";
2995 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
2999 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_lang as pl ON pl.fk_product = p.rowid ";
3001 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
3002 $soc =
new Societe($this->db);
3003 $result = $soc->fetch($socid);
3004 if ($result > 0 && !empty($soc->default_lang)) {
3005 $sql .=
" AND pl.lang = '" . $this->db->escape($soc->default_lang) .
"'";
3007 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3010 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3015 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_attribute_combination pac ON pac.fk_product_child = p.rowid";
3018 $sql .=
' WHERE p.entity IN (' .
getEntity(
'product') .
')';
3021 $sql .=
" AND pac.rowid IS NULL";
3024 if ($finished == 0) {
3025 $sql .=
" AND p.finished = " . ((int) $finished);
3026 } elseif ($finished == 1) {
3027 $sql .=
" AND p.finished = ".((int) $finished);
3030 $sql .=
" AND p.tosell = ".((int) $status);
3032 if ($status_purchase >= 0) {
3033 $sql .=
" AND p.tobuy = " . ((int) $status_purchase);
3036 if (strval($filtertype) !=
'') {
3037 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
3038 } elseif (!isModEnabled(
'product')) {
3039 $sql .=
" AND p.fk_product_type = 1";
3040 } elseif (!isModEnabled(
'service')) {
3041 $sql .=
" AND p.fk_product_type = 0";
3044 $parameters = array();
3045 $reshook = $hookmanager->executeHooks(
'selectProductsListWhere', $parameters);
3046 $sql .= $hookmanager->resPrint;
3048 if ($filterkey !=
'') {
3052 $search_crit = explode(
' ', $filterkey);
3054 if (count($search_crit) > 1) {
3057 foreach ($search_crit as $crit) {
3061 $sql .=
"(p.ref LIKE '" . $this->db->escape($prefix . $crit) .
"%' OR p.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3063 $sql .=
" OR pl.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3066 $sql .=
" OR pcp.ref_customer LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3069 $sql .=
" OR p.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3071 $sql .=
" OR pl.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3075 $sql .=
" OR pfp.ref_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3080 if (count($search_crit) > 1) {
3083 if (isModEnabled(
'barcode')) {
3084 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3088 if (count($warehouseStatusArray)) {
3089 $sql .=
" GROUP BY " . $selectFields;
3094 $sql .=
" ORDER BY categorie_product_id ";
3096 (
getDolGlobalInt(
'PRODUCT_SORT_BY_CATEGORY') == 1) ? $sql .=
"ASC" : $sql .=
"DESC";
3098 $sql .= $this->db->order(
"p.ref");
3101 $sql .= $this->db->plimit($limit, 0);
3104 dol_syslog(get_class($this) .
"::select_produits_list search products", LOG_DEBUG);
3105 $result = $this->db->query($sql);
3107 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3108 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3109 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
3111 $num = $this->db->num_rows($result);
3116 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3120 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
3126 if ($showempty && !is_numeric($showempty)) {
3127 $textifempty = $langs->trans($showempty);
3129 $textifempty .= $langs->trans(
"All");
3132 if ($showempty && !is_numeric($showempty)) {
3133 $textifempty = $langs->trans($showempty);
3137 $out .=
'<option value="-1" selected>' . ($textifempty ? $textifempty :
' ') .
'</option>';
3141 while ($num && $i < $num) {
3144 $objp = $this->db->fetch_object($result);
3146 if ((
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1) {
3147 $sql =
"SELECT rowid, quantity, price, unitprice, remise_percent, remise, price_base_type";
3148 $sql .=
" FROM " . $this->db->prefix() .
"product_price_by_qty";
3149 $sql .=
" WHERE fk_product_price = " . ((int) $objp->price_rowid);
3150 $sql .=
" ORDER BY quantity ASC";
3152 dol_syslog(get_class($this) .
"::select_produits_list search prices by qty", LOG_DEBUG);
3153 $result2 = $this->db->query($sql);
3155 $nb_prices = $this->db->num_rows($result2);
3157 while ($nb_prices && $j < $nb_prices) {
3158 $objp2 = $this->db->fetch_object($result2);
3160 $objp->price_by_qty_rowid = $objp2->rowid;
3161 $objp->price_by_qty_price_base_type = $objp2->price_base_type;
3162 $objp->price_by_qty_quantity = $objp2->quantity;
3163 $objp->price_by_qty_unitprice = $objp2->unitprice;
3164 $objp->price_by_qty_remise_percent = $objp2->remise_percent;
3166 $objp->quantity = $objp2->quantity;
3167 $objp->price = $objp2->price;
3168 $objp->unitprice = $objp2->unitprice;
3169 $objp->remise_percent = $objp2->remise_percent;
3182 array_push($outarray, $optJson);
3186 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_price_expression)) {
3187 $price_product =
new Product($this->db);
3188 $price_product->fetch($objp->rowid,
'',
'', 1);
3190 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3192 $price_result = $priceparser->parseProduct($price_product);
3193 if ($price_result >= 0) {
3194 $objp->price = $price_result;
3195 $objp->unitprice = $price_result;
3197 $objp->price_ttc = (float)
price2num($objp->price) * (1 + ($objp->tva_tx / 100));
3198 $objp->price_ttc =
price2num($objp->price_ttc,
'MU');
3207 array_push($outarray, $optJson);
3213 $out .=
'</select>';
3215 $this->db->free($result);
3217 if (empty($outputmode)) {
3244 protected function constructProductListOption(&$objp, &$opt, &$optJson, $price_level, $selected, $hidepriceinlabel = 0, $filterkey =
'', $novirtualstock = 0)
3246 global $langs, $conf, $user;
3247 global $hookmanager;
3253 $outlabel_translated =
'';
3255 $outdesc_translated =
'';
3261 $outpricebasetype =
'';
3263 $outdefault_vat_code =
'';
3267 $maxlengtharticle = (!
getDolGlobalString(
'PRODUCT_MAX_LENGTH_COMBO') ? 48 : $conf->global->PRODUCT_MAX_LENGTH_COMBO);
3269 $label = $objp->label;
3270 if (!empty($objp->label_translated)) {
3271 $label = $objp->label_translated;
3273 if (!empty($filterkey) && $filterkey !=
'') {
3274 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
3277 $outkey = $objp->rowid;
3278 $outref = $objp->ref;
3279 $outrefcust = empty($objp->custref) ?
'' : $objp->custref;
3280 $outlabel = $objp->label;
3281 $outdesc = $objp->description;
3283 $outlabel_translated = $objp->label_translated;
3284 $outdesc_translated = $objp->description_translated;
3286 $outbarcode = $objp->barcode;
3287 $outorigin = $objp->fk_country;
3288 $outpbq = empty($objp->price_by_qty_rowid) ?
'' : $objp->price_by_qty_rowid;
3290 $outtype = $objp->fk_product_type;
3295 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
3301 if (!empty($objp->unit_short)) {
3302 $outvalUnits .=
' - ' . $objp->unit_short;
3306 if (!empty($objp->weight) && $objp->weight_units !==
null) {
3308 $outvalUnits .=
' - ' . $unitToShow;
3310 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
3311 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
3312 $outvalUnits .=
' - ' . $unitToShow;
3314 if (!empty($objp->surface) && $objp->surface_units !==
null) {
3316 $outvalUnits .=
' - ' . $unitToShow;
3318 if (!empty($objp->volume) && $objp->volume_units !==
null) {
3320 $outvalUnits .=
' - ' . $unitToShow;
3323 if ($outdurationvalue && $outdurationunit) {
3325 'h' => $langs->trans(
'Hour'),
3326 'd' => $langs->trans(
'Day'),
3327 'w' => $langs->trans(
'Week'),
3328 'm' => $langs->trans(
'Month'),
3329 'y' => $langs->trans(
'Year')
3331 if (isset($da[$outdurationunit])) {
3332 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
3339 if ($user->hasRight(
'stock',
'lire')) {
3340 if ($objp->stock > 0) {
3342 } elseif ($objp->stock <= 0) {
3350 $labeltoshow .= $objp->ref;
3351 if (!empty($objp->custref)) {
3352 $labeltoshow .=
' (' . $objp->custref .
')';
3355 $labeltoshow .=
' (' . $outbarcode .
')';
3357 $labeltoshow .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3359 $labeltoshow .=
' (' .
getCountry($outorigin, 1) .
')';
3363 $labeltoshowhtml =
'';
3364 $labeltoshowhtml .= $objp->ref;
3365 if (!empty($objp->custref)) {
3366 $labeltoshowhtml .=
' (' . $objp->custref .
')';
3368 if (!empty($filterkey) && $filterkey !=
'') {
3369 $labeltoshowhtml = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $labeltoshowhtml, 1);
3372 $labeltoshowhtml .=
' (' . $outbarcode .
')';
3374 $labeltoshowhtml .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3376 $labeltoshowhtml .=
' (' .
getCountry($outorigin, 1) .
')';
3380 $labeltoshowstock =
'';
3381 $labeltoshowhtmlstock =
'';
3383 if ($user->hasRight(
'stock',
'lire')) {
3384 $labeltoshowstock .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'));
3386 if ($objp->stock > 0) {
3387 $labeltoshowhtmlstock .=
' - <span class="product_line_stock_ok">';
3388 } elseif ($objp->stock <= 0) {
3389 $labeltoshowhtmlstock .=
' - <span class="product_line_stock_too_low">';
3391 $labeltoshowhtmlstock .= $langs->transnoentities(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'));
3392 $labeltoshowhtmlstock .=
'</span>';
3394 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
3395 $langs->load(
"stocks");
3397 $tmpproduct =
new Product($this->db);
3398 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
3399 $tmpproduct->load_virtual_stock();
3400 $virtualstock = $tmpproduct->stock_theorique;
3402 $labeltoshowstock .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
3404 $labeltoshowhtmlstock .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
3405 if ($virtualstock > 0) {
3406 $labeltoshowhtmlstock .=
'<span class="product_line_stock_ok">';
3407 } elseif ($virtualstock <= 0) {
3408 $labeltoshowhtmlstock .=
'<span class="product_line_stock_too_low">';
3410 $labeltoshowhtmlstock .= $virtualstock;
3411 $labeltoshowhtmlstock .=
'</span>';
3420 $labeltoshowprice =
'';
3421 $labeltoshowhtmlprice =
'';
3424 $sql =
"SELECT price, price_ttc, price_base_type, tva_tx, default_vat_code";
3425 $sql .=
" FROM " . $this->db->prefix() .
"product_price";
3426 $sql .=
" WHERE fk_product = " . ((int) $objp->rowid);
3427 $sql .=
" AND entity IN (" .
getEntity(
'productprice') .
")";
3428 $sql .=
" AND price_level = " . ((int) $price_level);
3429 $sql .=
" ORDER BY date_price DESC, rowid DESC";
3432 dol_syslog(get_class($this) .
'::constructProductListOption search price for product ' . $objp->rowid .
' AND level ' . $price_level, LOG_DEBUG);
3433 $result2 = $this->db->query($sql);
3435 $objp2 = $this->db->fetch_object($result2);
3438 if ($objp2->price_base_type ==
'HT') {
3439 $labeltoshowprice .=
' - ' .
price($objp2->price, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"HT");
3440 $labeltoshowhtmlprice .=
' - ' .
price($objp2->price, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"HT");
3442 $labeltoshowprice .=
' - ' .
price($objp2->price_ttc, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"TTC");
3443 $labeltoshowhtmlprice .=
' - ' .
price($objp2->price_ttc, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3445 $outprice_ht =
price($objp2->price);
3446 $outprice_ttc =
price($objp2->price_ttc);
3447 $outpricebasetype = $objp2->price_base_type;
3449 $outtva_tx = $objp2->tva_tx;
3450 $outdefault_vat_code = $objp2->default_vat_code;
3452 $outtva_tx = $objp->tva_tx;
3453 $outdefault_vat_code = $objp->default_vat_code;
3462 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1 && (
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
3464 $outqty = $objp->quantity;
3465 $outdiscount = $objp->remise_percent;
3466 if ($objp->quantity == 1) {
3467 $labeltoshowprice .=
' - ' .
price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency) .
"/";
3468 $labeltoshowhtmlprice .=
' - ' .
price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency) .
"/";
3469 $labeltoshowprice .= $langs->trans(
"Unit");
3470 $labeltoshowhtmlprice .= $langs->transnoentities(
"Unit");
3472 $labeltoshowprice .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1, $conf->currency) .
"/" . $objp->quantity;
3473 $labeltoshowhtmlprice .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1, $conf->currency) .
"/" . $objp->quantity;
3474 $labeltoshowprice .= $langs->trans(
"Units");
3475 $labeltoshowhtmlprice .= $langs->transnoentities(
"Units");
3478 $outprice_ht =
price($objp->unitprice);
3479 $outprice_ttc =
price($objp->unitprice * (1 + ($objp->tva_tx / 100)));
3480 $outpricebasetype = $objp->price_base_type;
3481 $outtva_tx = $objp->tva_tx;
3482 $outdefault_vat_code = $objp->default_vat_code;
3484 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1) {
3485 $labeltoshowprice .=
" (" .
price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency) .
"/" . $langs->trans(
"Unit") .
")";
3486 $labeltoshowhtmlprice .=
" (" .
price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency) .
"/" . $langs->transnoentities(
"Unit") .
")";
3488 if (empty($hidepriceinlabel) && !empty($objp->remise_percent) && $objp->remise_percent >= 1) {
3489 $labeltoshowprice .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3490 $labeltoshowhtmlprice .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3495 if (!empty($objp->idprodcustprice)) {
3498 if ($objp->custprice_base_type ==
'HT') {
3499 $labeltoshowprice .=
' - ' .
price($objp->custprice, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"HT");
3500 $labeltoshowhtmlprice .=
' - ' .
price($objp->custprice, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"HT");
3502 $labeltoshowprice .=
' - ' .
price($objp->custprice_ttc, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"TTC");
3503 $labeltoshowhtmlprice .=
' - ' .
price($objp->custprice_ttc, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3506 $outprice_ht =
price($objp->custprice);
3507 $outprice_ttc =
price($objp->custprice_ttc);
3508 $outpricebasetype = $objp->custprice_base_type;
3509 $outtva_tx = $objp->custtva_tx;
3510 $outdefault_vat_code = $objp->custdefault_vat_code;
3515 if (empty($hidepriceinlabel) && !$found) {
3516 if ($objp->price_base_type ==
'HT') {
3517 $labeltoshowprice .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"HT");
3518 $labeltoshowhtmlprice .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"HT");
3520 $labeltoshowprice .=
' - ' .
price($objp->price_ttc, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"TTC");
3521 $labeltoshowhtmlprice .=
' - ' .
price($objp->price_ttc, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3523 $outprice_ht =
price($objp->price);
3524 $outprice_ttc =
price($objp->price_ttc);
3525 $outpricebasetype = $objp->price_base_type;
3526 $outtva_tx = $objp->tva_tx;
3527 $outdefault_vat_code = $objp->default_vat_code;
3532 $opt =
'<option value="' . $objp->rowid .
'"';
3533 $opt .= ($objp->rowid == $selected) ?
' selected' :
'';
3534 if (!empty($objp->price_by_qty_rowid) && $objp->price_by_qty_rowid > 0) {
3535 $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 .
'"';
3538 $opt .=
' data-labeltrans="' . $outlabel_translated .
'"';
3542 if ($stocktag == 1) {
3543 $opt .=
' class="product_line_stock_ok" data-html="'.$labeltoshowhtml.$outvalUnits.$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
3546 if ($stocktag == -1) {
3547 $opt .=
' class="product_line_stock_too_low" data-html="'.$labeltoshowhtml.$outvalUnits.$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
3554 $opt .= $labeltoshow;
3555 $outval .= $labeltoshowhtml;
3558 $opt .= $outvalUnits;
3559 $outval .= $outvalUnits;
3562 $opt .= $labeltoshowprice;
3563 $outval .= $labeltoshowhtmlprice;
3566 $opt .= $labeltoshowstock;
3567 $outval .= $labeltoshowhtmlstock;
3570 $parameters = array(
'objp' => $objp);
3571 $reshook = $hookmanager->executeHooks(
'constructProductListOption', $parameters);
3572 if (empty($reshook)) {
3573 $opt .= $hookmanager->resPrint;
3575 $opt = $hookmanager->resPrint;
3578 $opt .=
"</option>\n";
3583 'label2' => $outlabel,
3587 'price_ttc' =>
price2num($outprice_ttc),
3590 'pricebasetype' => $outpricebasetype,
3591 'tva_tx' => $outtva_tx,
3592 'default_vat_code' => $outdefault_vat_code,
3594 'discount' => $outdiscount,
3595 'duration_value' => $outdurationvalue,
3596 'duration_unit' => $outdurationunit,
3598 'labeltrans' => $outlabel_translated,
3599 'desctrans' => $outdesc_translated,
3600 'ref_customer' => $outrefcust
3621 public function select_produits_fournisseurs($socid, $selected =
'', $htmlname =
'productid', $filtertype =
'', $filtre =
'', $ajaxoptions = array(), $hidelabel = 0, $alsoproductwithnosupplierprice = 0, $morecss =
'', $placeholder =
'')
3624 global $langs, $conf;
3625 global $price_level, $status, $finished;
3627 if (!isset($status)) {
3631 $selected_input_value =
'';
3632 if (!empty($conf->use_javascript_ajax) &&
getDolGlobalString(
'PRODUIT_USE_SEARCH_TO_SELECT')) {
3633 if ($selected > 0) {
3634 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3635 $producttmpselect =
new Product($this->db);
3636 $producttmpselect->fetch($selected);
3637 $selected_input_value = $producttmpselect->ref;
3638 unset($producttmpselect);
3642 $urloption = ($socid > 0 ?
'socid=' . $socid .
'&' :
'') .
'htmlname=' . $htmlname .
'&outjson=1&price_level=' . $price_level .
'&type=' . $filtertype .
'&mode=2&status=' . $status .
'&finished=' . $finished .
'&alsoproductwithnosupplierprice=' . $alsoproductwithnosupplierprice;
3645 print($hidelabel ?
'' : $langs->trans(
"RefOrLabel") .
' : ') .
'<input type="text" class="'.$morecss.
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . ($placeholder ?
' placeholder="' . $placeholder .
'"' :
'') .
'>';
3647 print $this->
select_produits_fournisseurs_list($socid, $selected, $htmlname, $filtertype, $filtre,
'', $status, 0, 0, $alsoproductwithnosupplierprice, $morecss, 0, $placeholder);
3671 public function select_produits_fournisseurs_list($socid, $selected =
'', $htmlname =
'productid', $filtertype =
'', $filtre =
'', $filterkey =
'', $statut = -1, $outputmode = 0, $limit = 100, $alsoproductwithnosupplierprice = 0, $morecss =
'', $showstockinlist = 0, $placeholder =
'')
3674 global $langs, $conf, $user;
3675 global $hookmanager;
3678 $outarray = array();
3680 $maxlengtharticle = (!
getDolGlobalString(
'PRODUCT_MAX_LENGTH_COMBO') ? 48 : $conf->global->PRODUCT_MAX_LENGTH_COMBO);
3682 $langs->load(
'stocks');
3685 $langs->load(
'other');
3688 $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,";
3689 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice, pfp.barcode";
3690 if (isModEnabled(
'multicurrency')) {
3691 $sql .=
", pfp.multicurrency_code, pfp.multicurrency_unitprice";
3693 $sql .=
", pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.default_vat_code, pfp.fk_soc, s.nom as name";
3694 $sql .=
", pfp.supplier_reputation";
3697 $sql .=
", pfp.desc_fourn as description";
3699 $sql .=
", p.description";
3703 $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";
3705 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
3706 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN (" .
getEntity(
'product') .
") )";
3708 $sql .=
" AND pfp.fk_soc = " . ((int) $socid);
3710 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
3713 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
3715 $sql .=
" WHERE p.entity IN (" .
getEntity(
'product') .
")";
3716 if ($statut != -1) {
3717 $sql .=
" AND p.tobuy = " . ((int) $statut);
3719 if (strval($filtertype) !=
'') {
3720 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
3722 if (!empty($filtre)) {
3723 $sql .=
" " . $filtre;
3726 $parameters = array();
3727 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListWhere', $parameters);
3728 $sql .= $hookmanager->resPrint;
3730 if ($filterkey !=
'') {
3734 $search_crit = explode(
' ', $filterkey);
3736 if (count($search_crit) > 1) {
3739 foreach ($search_crit as $crit) {
3743 $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) .
"%'";
3745 $sql .=
" OR pfp.desc_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3750 if (count($search_crit) > 1) {
3753 if (isModEnabled(
'barcode')) {
3754 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3755 $sql .=
" OR pfp.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3759 $sql .=
" ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC";
3760 $sql .= $this->db->plimit($limit, 0);
3764 dol_syslog(get_class($this) .
"::select_produits_fournisseurs_list", LOG_DEBUG);
3765 $result = $this->db->query($sql);
3767 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3768 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
3770 $num = $this->db->num_rows($result);
3773 $out .=
'<select class="flat ' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'">';
3775 $out .=
'<option value="-1" selected>' . ($placeholder ? $placeholder :
' ') .
'</option>';
3777 $out .=
'<option value="-1">' . ($placeholder ? $placeholder :
' ') .
'</option>';
3782 $objp = $this->db->fetch_object($result);
3784 if (is_null($objp->idprodfournprice)) {
3786 $objp->tva_tx = $objp->tva_tx_sale;
3787 $objp->default_vat_code = $objp->default_vat_code_sale;
3790 $outkey = $objp->idprodfournprice;
3791 if (!$outkey && $alsoproductwithnosupplierprice) {
3792 $outkey =
'idprod_' . $objp->rowid;
3795 $outref = $objp->ref;
3796 $outbarcode = $objp->barcode;
3799 $outtype = $objp->fk_product_type;
3806 if (!empty($objp->unit_short)) {
3807 $outvalUnits .=
' - ' . $objp->unit_short;
3809 if (!empty($objp->weight) && $objp->weight_units !==
null) {
3811 $outvalUnits .=
' - ' . $unitToShow;
3813 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
3814 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
3815 $outvalUnits .=
' - ' . $unitToShow;
3817 if (!empty($objp->surface) && $objp->surface_units !==
null) {
3819 $outvalUnits .=
' - ' . $unitToShow;
3821 if (!empty($objp->volume) && $objp->volume_units !==
null) {
3823 $outvalUnits .=
' - ' . $unitToShow;
3825 if ($outdurationvalue && $outdurationunit) {
3827 'h' => $langs->trans(
'Hour'),
3828 'd' => $langs->trans(
'Day'),
3829 'w' => $langs->trans(
'Week'),
3830 'm' => $langs->trans(
'Month'),
3831 'y' => $langs->trans(
'Year')
3833 if (isset($da[$outdurationunit])) {
3834 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
3839 $objRef = $objp->ref;
3840 if ($filterkey && $filterkey !=
'') {
3841 $objRef = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRef, 1);
3843 $objRefFourn = $objp->ref_fourn;
3844 if ($filterkey && $filterkey !=
'') {
3845 $objRefFourn = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRefFourn, 1);
3847 $label = $objp->label;
3848 if ($filterkey && $filterkey !=
'') {
3849 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
3852 switch ($objp->fk_product_type) {
3864 if (empty($picto)) {
3867 $optlabel =
img_object(
'', $picto,
'class="paddingright classfortooltip"', 0, 0, 1);
3870 $optlabel .= $objp->ref;
3871 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
3872 $optlabel .=
' <span class="opacitymedium">(' . $objp->ref_fourn .
')</span>';
3874 if (isModEnabled(
'barcode') && !empty($objp->barcode)) {
3875 $optlabel .=
' (' . $outbarcode .
')';
3877 $optlabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3879 $outvallabel = $objRef;
3880 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
3881 $outvallabel .=
' (' . $objRefFourn .
')';
3883 if (isModEnabled(
'barcode') && !empty($objp->barcode)) {
3884 $outvallabel .=
' (' . $outbarcode .
')';
3886 $outvallabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3889 $optlabel .= $outvalUnits;
3890 $outvallabel .= $outvalUnits;
3892 if (!empty($objp->idprodfournprice)) {
3893 $outqty = $objp->quantity;
3894 $outdiscount = $objp->remise_percent;
3895 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
3897 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
3898 $prod_supplier->id = $objp->fk_product;
3899 $prod_supplier->fourn_qty = $objp->quantity;
3900 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
3901 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
3903 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3905 $price_result = $priceparser->parseProductSupplier($prod_supplier);
3906 if ($price_result >= 0) {
3907 $objp->fprice = $price_result;
3908 if ($objp->quantity >= 1) {
3909 $objp->unitprice = $objp->fprice / $objp->quantity;
3913 if ($objp->quantity == 1) {
3914 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency) .
"/";
3915 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1, $conf->currency) .
"/";
3916 $optlabel .= $langs->trans(
"Unit");
3917 $outvallabel .= $langs->transnoentities(
"Unit");
3919 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency) .
"/" . $objp->quantity;
3920 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1, $conf->currency) .
"/" . $objp->quantity;
3921 $optlabel .=
' ' . $langs->trans(
"Units");
3922 $outvallabel .=
' ' . $langs->transnoentities(
"Units");
3925 if ($objp->quantity > 1) {
3926 $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") .
")";
3927 $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") .
")";
3929 if ($objp->remise_percent >= 1) {
3930 $optlabel .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3931 $outvallabel .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3933 if ($objp->duration) {
3934 $optlabel .=
" - " . $objp->duration;
3935 $outvallabel .=
" - " . $objp->duration;
3938 $optlabel .=
" - " .
dol_trunc($objp->name, 8);
3939 $outvallabel .=
" - " .
dol_trunc($objp->name, 8);
3941 if ($objp->supplier_reputation) {
3943 $reputations = array(
'' => $langs->trans(
'Standard'),
'FAVORITE' => $langs->trans(
'Favorite'),
'NOTTHGOOD' => $langs->trans(
'NotTheGoodQualitySupplier'),
'DONOTORDER' => $langs->trans(
'DoNotOrderThisProductToThisSupplier'));
3945 $optlabel .=
" - " . $reputations[$objp->supplier_reputation];
3946 $outvallabel .=
" - " . $reputations[$objp->supplier_reputation];
3949 $optlabel .=
" - <span class='opacitymedium'>" . $langs->trans(
"NoPriceDefinedForThisSupplier") .
'</span>';
3950 $outvallabel .=
' - ' . $langs->transnoentities(
"NoPriceDefinedForThisSupplier");
3954 $novirtualstock = ($showstockinlist == 2);
3956 if ($user->hasRight(
'stock',
'lire')) {
3957 $outvallabel .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'));
3959 if ($objp->stock > 0) {
3960 $optlabel .=
' - <span class="product_line_stock_ok">';
3961 } elseif ($objp->stock <= 0) {
3962 $optlabel .=
' - <span class="product_line_stock_too_low">';
3964 $optlabel .= $langs->transnoentities(
"Stock") .
':' .
price(
price2num($objp->stock,
'MS'));
3965 $optlabel .=
'</span>';
3966 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
3967 $langs->load(
"stocks");
3969 $tmpproduct =
new Product($this->db);
3970 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
3971 $tmpproduct->load_virtual_stock();
3972 $virtualstock = $tmpproduct->stock_theorique;
3974 $outvallabel .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
3976 $optlabel .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
3977 if ($virtualstock > 0) {
3978 $optlabel .=
'<span class="product_line_stock_ok">';
3979 } elseif ($virtualstock <= 0) {
3980 $optlabel .=
'<span class="product_line_stock_too_low">';
3982 $optlabel .= $virtualstock;
3983 $optlabel .=
'</span>';
3990 $optstart =
'<option value="' . $outkey .
'"';
3991 if ($selected && $selected == $objp->idprodfournprice) {
3992 $optstart .=
' selected';
3994 if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) {
3995 $optstart .=
' disabled';
3998 if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) {
4007 $optstart .=
' data-default-vat-code="' .
dol_escape_htmltag($objp->default_vat_code) .
'"';
4009 if (isModEnabled(
'multicurrency')) {
4010 $optstart .=
' data-multicurrency-code="' .
dol_escape_htmltag($objp->multicurrency_code) .
'"';
4011 $optstart .=
' data-multicurrency-up="' .
dol_escape_htmltag($objp->multicurrency_unitprice) .
'"';
4014 $optstart .=
' data-description="' .
dol_escape_htmltag($objp->description, 0, 1) .
'"';
4016 $outarrayentry = array(
4019 'label' => $outvallabel,
4021 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4022 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4023 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4024 'tva_tx_formated' =>
price($objp->tva_tx, 0, $langs, 1, -1, 2),
4026 'default_vat_code' => $objp->default_vat_code,
4027 'supplier_ref' => $objp->ref_fourn,
4028 'discount' => $outdiscount,
4030 'duration_value' => $outdurationvalue,
4031 'duration_unit' => $outdurationunit,
4032 'disabled' => empty($objp->idprodfournprice),
4033 'description' => $objp->description
4035 if (isModEnabled(
'multicurrency')) {
4036 $outarrayentry[
'multicurrency_code'] = $objp->multicurrency_code;
4037 $outarrayentry[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4040 $parameters = array(
4042 'optstart' => &$optstart,
4043 'optlabel' => &$optlabel,
4044 'outvallabel' => &$outvallabel,
4045 'outarrayentry' => &$outarrayentry
4047 $reshook = $hookmanager->executeHooks(
'selectProduitsFournisseurListOption', $parameters, $this);
4053 $out .= $optstart .
' data-html="' .
dol_escape_htmltag($optlabel) .
'">' . $optlabel .
"</option>\n";
4054 $outarraypush = array(
4057 'label' => $outvallabel,
4059 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4060 'price_qty_ht_locale' =>
price($objp->fprice),
4061 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4062 'price_unit_ht_locale' =>
price($objp->unitprice),
4063 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4064 'tva_tx_formated' =>
price($objp->tva_tx),
4066 'default_vat_code' => $objp->default_vat_code,
4067 'supplier_ref' => $objp->ref_fourn,
4068 'discount' => $outdiscount,
4070 'duration_value' => $outdurationvalue,
4071 'duration_unit' => $outdurationunit,
4072 'disabled' => empty($objp->idprodfournprice),
4073 'description' => $objp->description
4075 if (isModEnabled(
'multicurrency')) {
4076 $outarraypush[
'multicurrency_code'] = $objp->multicurrency_code;
4077 $outarraypush[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4079 array_push($outarray, $outarraypush);
4092 $out .=
'</select>';
4094 $this->db->free($result);
4096 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
4102 if (empty($outputmode)) {
4121 global $langs, $conf;
4123 $langs->load(
'stocks');
4125 $sql =
"SELECT p.rowid, p.ref, p.label, p.price, p.duration, pfp.fk_soc,";
4126 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.remise_percent, pfp.quantity, pfp.unitprice,";
4127 $sql .=
" pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name";
4128 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
4129 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
4130 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
4131 $sql .=
" WHERE pfp.entity IN (" .
getEntity(
'productsupplierprice') .
")";
4132 $sql .=
" AND p.tobuy = 1";
4133 $sql .=
" AND s.fournisseur = 1";
4134 $sql .=
" AND p.rowid = " . ((int) $productid);
4136 $sql .=
" ORDER BY s.nom, pfp.ref_fourn DESC";
4138 $sql .=
" ORDER BY pfp.unitprice ASC";
4141 dol_syslog(get_class($this) .
"::select_product_fourn_price", LOG_DEBUG);
4142 $result = $this->db->query($sql);
4145 $num = $this->db->num_rows($result);
4147 $form =
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
4150 $form .=
'<option value="0">-- ' . $langs->trans(
"NoSupplierPriceDefinedForThisProduct") .
' --</option>';
4152 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4153 $form .=
'<option value="0"> </option>';
4157 $objp = $this->db->fetch_object($result);
4159 $opt =
'<option value="' . $objp->idprodfournprice .
'"';
4161 if ($num == 1 || ($selected_supplier > 0 && $objp->fk_soc == $selected_supplier) || ($i == 0 &&
getDolGlobalString(
'PRODUCT_BEST_SUPPLIER_PRICE_PRESELECTED'))) {
4162 $opt .=
' selected';
4164 $opt .=
'>' . $objp->name .
' - ' . $objp->ref_fourn .
' - ';
4166 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
4168 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
4169 $prod_supplier->id = $productid;
4170 $prod_supplier->fourn_qty = $objp->quantity;
4171 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
4172 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
4174 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4176 $price_result = $priceparser->parseProductSupplier($prod_supplier);
4177 if ($price_result >= 0) {
4178 $objp->fprice = $price_result;
4179 if ($objp->quantity >= 1) {
4180 $objp->unitprice = $objp->fprice / $objp->quantity;
4184 if ($objp->quantity == 1) {
4185 $opt .=
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency) .
"/";
4188 $opt .= $objp->quantity .
' ';
4190 if ($objp->quantity == 1) {
4191 $opt .= $langs->trans(
"Unit");
4193 $opt .= $langs->trans(
"Units");
4195 if ($objp->quantity > 1) {
4197 $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");
4199 if ($objp->duration) {
4200 $opt .=
" - " . $objp->duration;
4202 $opt .=
"</option>\n";
4209 $form .=
'</select>';
4210 $this->db->free($result);
4230 $num = count($this->cache_conditions_paiements);
4237 $sql =
"SELECT rowid, code, libelle as label, deposit_percent";
4238 $sql .=
" FROM " . $this->db->prefix() .
'c_payment_term';
4239 $sql .=
" WHERE entity IN (" .
getEntity(
'c_payment_term') .
")";
4240 $sql .=
" AND active > 0";
4241 $sql .=
" ORDER BY sortorder";
4243 $resql = $this->db->query($sql);
4245 $num = $this->db->num_rows($resql);
4248 $obj = $this->db->fetch_object($resql);
4251 $label = ($langs->trans(
"PaymentConditionShort" . $obj->code) !=
"PaymentConditionShort" . $obj->code ? $langs->trans(
"PaymentConditionShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4252 $this->cache_conditions_paiements[$obj->rowid][
'code'] = $obj->code;
4253 $this->cache_conditions_paiements[$obj->rowid][
'label'] = $label;
4254 $this->cache_conditions_paiements[$obj->rowid][
'deposit_percent'] = $obj->deposit_percent;
4279 $num = count($this->cache_availability);
4286 $langs->load(
'propal');
4288 $sql =
"SELECT rowid, code, label, position";
4289 $sql .=
" FROM " . $this->db->prefix() .
'c_availability';
4290 $sql .=
" WHERE active > 0";
4292 $resql = $this->db->query($sql);
4294 $num = $this->db->num_rows($resql);
4297 $obj = $this->db->fetch_object($resql);
4300 $label = ($langs->trans(
"AvailabilityType" . $obj->code) !=
"AvailabilityType" . $obj->code ? $langs->trans(
"AvailabilityType" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4301 $this->cache_availability[$obj->rowid][
'code'] = $obj->code;
4302 $this->cache_availability[$obj->rowid][
'label'] = $label;
4303 $this->cache_availability[$obj->rowid][
'position'] = $obj->position;
4307 $this->cache_availability =
dol_sort_array($this->cache_availability,
'position',
'asc', 0, 0, 1);
4328 global $langs, $user;
4332 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
4334 print
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4336 print
'<option value="0"> </option>';
4338 foreach ($this->cache_availability as $id => $arrayavailability) {
4339 if ($selected == $id) {
4340 print
'<option value="' . $id .
'" selected>';
4342 print
'<option value="' . $id .
'">';
4349 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4363 $num = count($this->cache_demand_reason);
4368 $sql =
"SELECT rowid, code, label";
4369 $sql .=
" FROM " . $this->db->prefix() .
'c_input_reason';
4370 $sql .=
" WHERE active > 0";
4372 $resql = $this->db->query($sql);
4374 $num = $this->db->num_rows($resql);
4376 $tmparray = array();
4378 $obj = $this->db->fetch_object($resql);
4381 $label = ($obj->label !=
'-' ? $obj->label :
'');
4382 if ($langs->trans(
"DemandReasonType" . $obj->code) !=
"DemandReasonType" . $obj->code) {
4383 $label = $langs->trans(
"DemandReasonType" . $obj->code);
4385 if ($langs->trans($obj->code) != $obj->code) {
4386 $label = $langs->trans($obj->code);
4389 $tmparray[$obj->rowid][
'id'] = $obj->rowid;
4390 $tmparray[$obj->rowid][
'code'] = $obj->code;
4391 $tmparray[$obj->rowid][
'label'] = $label;
4395 $this->cache_demand_reason =
dol_sort_array($tmparray,
'label',
'asc', 0, 0, 1);
4417 public function selectInputReason($selected =
'', $htmlname =
'demandreasonid', $exclude =
'', $addempty = 0, $morecss =
'', $notooltip = 0)
4419 global $langs, $user;
4423 print
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
4425 print
'<option value="0"' . (empty($selected) ?
' selected' :
'') .
'> </option>';
4427 foreach ($this->cache_demand_reason as $id => $arraydemandreason) {
4428 if ($arraydemandreason[
'code'] == $exclude) {
4432 if ($selected && ($selected == $arraydemandreason[
'id'] || $selected == $arraydemandreason[
'code'])) {
4433 print
'<option value="' . $arraydemandreason[
'id'] .
'" selected>';
4435 print
'<option value="' . $arraydemandreason[
'id'] .
'">';
4437 $label = $arraydemandreason[
'label'];
4438 print $langs->trans($label);
4442 if ($user->admin && empty($notooltip)) {
4443 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4460 $num = count($this->cache_types_paiements);
4467 $this->cache_types_paiements = array();
4469 $sql =
"SELECT id, code, libelle as label, type, active";
4470 $sql .=
" FROM " . $this->db->prefix() .
"c_paiement";
4471 $sql .=
" WHERE entity IN (" .
getEntity(
'c_paiement') .
")";
4473 $resql = $this->db->query($sql);
4475 $num = $this->db->num_rows($resql);
4478 $obj = $this->db->fetch_object($resql);
4481 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) !=
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4482 $this->cache_types_paiements[$obj->id][
'id'] = $obj->id;
4483 $this->cache_types_paiements[$obj->id][
'code'] = $obj->code;
4484 $this->cache_types_paiements[$obj->id][
'label'] = $label;
4485 $this->cache_types_paiements[$obj->id][
'type'] = $obj->type;
4486 $this->cache_types_paiements[$obj->id][
'active'] = $obj->active;
4490 $this->cache_types_paiements =
dol_sort_array($this->cache_types_paiements,
'label',
'asc', 0, 0, 1);
4520 public function select_conditions_paiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1, $noprint = 0)
4524 if (empty($noprint)) {
4548 public function getSelectConditionsPaiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1)
4550 global $langs, $user, $conf;
4553 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
4559 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TERM_ID", LOG_NOTICE);
4563 $out .=
'<select id="' . $htmlname .
'" class="flat selectpaymentterms' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4565 $out .=
'<option value="0"> </option>';
4568 $selectedDepositPercent =
null;
4570 foreach ($this->cache_conditions_paiements as $id => $arrayconditions) {
4571 if ($filtertype <= 0 && !empty($arrayconditions[
'deposit_percent'])) {
4575 if ($selected == $id) {
4576 $selectedDepositPercent = $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'];
4577 $out .=
'<option value="' . $id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'" selected>';
4579 $out .=
'<option value="' . $id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'">';
4581 $label = $arrayconditions[
'label'];
4583 if (!empty($arrayconditions[
'deposit_percent'])) {
4584 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'], $label);
4588 $out .=
'</option>';
4590 $out .=
'</select>';
4591 if ($user->admin && empty($noinfoadmin)) {
4592 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4596 if ($deposit_percent >= 0) {
4597 $out .=
' <span id="' . $htmlname .
'_deposit_percent_container"' . (empty($selectedDepositPercent) ?
' style="display: none"' :
'') .
'>';
4598 $out .= $langs->trans(
'DepositPercent') .
' : ';
4599 $out .=
'<input id="' . $htmlname .
'_deposit_percent" name="' . $htmlname .
'_deposit_percent" class="maxwidth50" value="' . $deposit_percent .
'" />';
4602 <script nonce="' .
getNonce() .
'">
4603 $(document).ready(function () {
4604 $("#' . $htmlname .
'").change(function () {
4605 let $selected = $(this).find("option:selected");
4606 let depositPercent = $selected.attr("data-deposit_percent");
4608 if (depositPercent.length > 0) {
4609 $("#' . $htmlname .
'_deposit_percent_container").show().find("#' . $htmlname .
'_deposit_percent").val(depositPercent);
4611 $("#' . $htmlname .
'_deposit_percent_container").hide();
4642 public function select_types_paiements($selected =
'', $htmlname =
'paiementtype', $filtertype =
'', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'', $nooutput = 0)
4645 global $langs, $user, $conf;
4649 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $filtertype .
", " . $format, LOG_DEBUG);
4651 $filterarray = array();
4652 if ($filtertype ==
'CRDT') {
4653 $filterarray = array(0, 2, 3);
4654 } elseif ($filtertype ==
'DBIT') {
4655 $filterarray = array(1, 2, 3);
4656 } elseif ($filtertype !=
'' && $filtertype !=
'-1') {
4657 $filterarray = explode(
',', $filtertype);
4664 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TYPE_ID", LOG_NOTICE);
4668 $out .=
'<select id="select' . $htmlname .
'" class="flat selectpaymenttypes' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4670 $out .=
'<option value=""> </option>';
4672 foreach ($this->cache_types_paiements as $id => $arraytypes) {
4674 if ($active >= 0 && $arraytypes[
'active'] != $active) {
4679 if (count($filterarray) && !in_array($arraytypes[
'type'], $filterarray)) {
4684 if ($empty && empty($arraytypes[
'code'])) {
4689 $out .=
'<option value="' . $id .
'"';
4690 } elseif ($format == 1) {
4691 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
4692 } elseif ($format == 2) {
4693 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
4694 } elseif ($format == 3) {
4695 $out .=
'<option value="' . $id .
'"';
4698 if ($format == 1 || $format == 2) {
4699 if ($selected == $arraytypes[
'code']) {
4700 $out .=
' selected';
4703 if ($selected == $id) {
4704 $out .=
' selected';
4710 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4711 } elseif ($format == 1) {
4712 $value = $arraytypes[
'code'];
4713 } elseif ($format == 2) {
4714 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4715 } elseif ($format == 3) {
4716 $value = $arraytypes[
'code'];
4718 $out .= $value ? $value :
' ';
4719 $out .=
'</option>';
4721 $out .=
'</select>';
4722 if ($user->admin && !$noadmininfo) {
4723 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4727 if (empty($nooutput)) {
4747 $return =
'<select class="flat maxwidth100" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
4749 'HT' => $langs->trans(
"HT"),
4750 'TTC' => $langs->trans(
"TTC")
4752 foreach ($options as $id => $value) {
4753 if ($selected == $id) {
4754 $return .=
'<option value="' . $id .
'" selected>' . $value;
4756 $return .=
'<option value="' . $id .
'">' . $value;
4758 $return .=
'</option>';
4760 $return .=
'</select>';
4780 $num = count($this->cache_transport_mode);
4787 $this->cache_transport_mode = array();
4789 $sql =
"SELECT rowid, code, label, active";
4790 $sql .=
" FROM " . $this->db->prefix() .
"c_transport_mode";
4791 $sql .=
" WHERE entity IN (" .
getEntity(
'c_transport_mode') .
")";
4793 $resql = $this->db->query($sql);
4795 $num = $this->db->num_rows($resql);
4798 $obj = $this->db->fetch_object($resql);
4801 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) !=
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4802 $this->cache_transport_mode[$obj->rowid][
'rowid'] = $obj->rowid;
4803 $this->cache_transport_mode[$obj->rowid][
'code'] = $obj->code;
4804 $this->cache_transport_mode[$obj->rowid][
'label'] = $label;
4805 $this->cache_transport_mode[$obj->rowid][
'active'] = $obj->active;
4809 $this->cache_transport_mode =
dol_sort_array($this->cache_transport_mode,
'label',
'asc', 0, 0, 1);
4831 public function selectTransportMode($selected =
'', $htmlname =
'transportmode', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'')
4833 global $langs, $user;
4835 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $format, LOG_DEBUG);
4839 print
'<select id="select' . $htmlname .
'" class="flat selectmodetransport' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4841 print
'<option value=""> </option>';
4843 foreach ($this->cache_transport_mode as $id => $arraytypes) {
4845 if ($active >= 0 && $arraytypes[
'active'] != $active) {
4850 if ($empty && empty($arraytypes[
'code'])) {
4855 print
'<option value="' . $id .
'"';
4856 } elseif ($format == 1) {
4857 print
'<option value="' . $arraytypes[
'code'] .
'"';
4858 } elseif ($format == 2) {
4859 print
'<option value="' . $arraytypes[
'code'] .
'"';
4860 } elseif ($format == 3) {
4861 print
'<option value="' . $id .
'"';
4864 if (preg_match(
'/[a-z]/i', $selected) && $selected == $arraytypes[
'code']) {
4866 } elseif ($selected == $id) {
4872 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4873 } elseif ($format == 1) {
4874 $value = $arraytypes[
'code'];
4875 } elseif ($format == 2) {
4876 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4877 } elseif ($format == 3) {
4878 $value = $arraytypes[
'code'];
4880 print $value ? $value :
' ';
4884 if ($user->admin && !$noadmininfo) {
4885 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4901 public function selectShippingMethod($selected =
'', $htmlname =
'shipping_method_id', $filtre =
'', $useempty = 0, $moreattrib =
'', $noinfoadmin = 0, $morecss =
'')
4903 global $langs, $user;
4905 $langs->load(
"admin");
4906 $langs->load(
"deliveries");
4908 $sql =
"SELECT rowid, code, libelle as label";
4909 $sql .=
" FROM " . $this->db->prefix() .
"c_shipment_mode";
4910 $sql .=
" WHERE active > 0";
4912 $sql .=
" AND " . $filtre;
4914 $sql .=
" ORDER BY libelle ASC";
4916 dol_syslog(get_class($this) .
"::selectShippingMode", LOG_DEBUG);
4917 $result = $this->db->query($sql);
4919 $num = $this->db->num_rows($result);
4922 print
'<select id="select' . $htmlname .
'" class="flat selectshippingmethod' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
4923 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
4924 print
'<option value="-1"> </option>';
4927 $obj = $this->db->fetch_object($result);
4928 if ($selected == $obj->rowid) {
4929 print
'<option value="' . $obj->rowid .
'" selected>';
4931 print
'<option value="' . $obj->rowid .
'">';
4933 print ($langs->trans(
"SendingMethod" . strtoupper($obj->code)) !=
"SendingMethod" . strtoupper($obj->code)) ? $langs->trans(
"SendingMethod" . strtoupper($obj->code)) : $obj->label;
4938 if ($user->admin && empty($noinfoadmin)) {
4939 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4944 print $langs->trans(
"NoShippingMethodDefined");
4964 $langs->load(
"deliveries");
4966 if ($htmlname !=
"none") {
4967 print
'<form method="POST" action="' . $page .
'">';
4968 print
'<input type="hidden" name="action" value="setshippingmethod">';
4969 print
'<input type="hidden" name="token" value="' . newToken() .
'">';
4971 print
'<input type="submit" class="button valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
4975 $code = $langs->getLabelFromKey($this->db, $selected,
'c_shipment_mode',
'rowid',
'code');
4976 print $langs->trans(
"SendingMethod" . strtoupper($code));
4995 $langs->load(
'bills');
4997 $opt =
'<option value="" selected></option>';
4998 $sql =
"SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc";
4999 $sql .=
' FROM ' . $this->db->prefix() .
'facture';
5000 $sql .=
' WHERE entity IN (' .
getEntity(
'invoice') .
')';
5001 $sql .=
' AND situation_counter >= 1';
5002 $sql .=
' AND fk_soc = ' . (int) $socid;
5003 $sql .=
' AND type <> 2';
5004 $sql .=
' ORDER by situation_cycle_ref, situation_counter desc';
5005 $resql = $this->db->query($sql);
5007 if ($resql && $this->db->num_rows($resql) > 0) {
5010 while ($obj = $this->db->fetch_object($resql)) {
5012 if ($obj->situation_cycle_ref != $ref) {
5014 $ref = $obj->situation_cycle_ref;
5016 if ($obj->situation_final != 1) {
5018 if (substr($obj->ref, 1, 4) !=
'PROV') {
5019 if ($selected == $obj->rowid) {
5020 $opt .=
'<option value="' . $obj->rowid .
'" selected>' . $obj->ref .
'</option>';
5022 $opt .=
'<option value="' . $obj->rowid .
'">' . $obj->ref .
'</option>';
5029 dol_syslog(
"Error sql=" . $sql .
", error=" . $this->error, LOG_ERR);
5031 if ($opt ==
'<option value ="" selected></option>') {
5032 $opt =
'<option value ="0" selected>' . $langs->trans(
'NoSituations') .
'</option>';
5046 public function selectUnits($selected =
'', $htmlname =
'units', $showempty = 0, $unit_type =
'')
5050 $langs->load(
'products');
5052 $return =
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'">';
5054 $sql =
"SELECT rowid, label, code FROM " . $this->db->prefix() .
"c_units";
5055 $sql .=
' WHERE active > 0';
5056 if (!empty($unit_type)) {
5057 $sql .=
" AND unit_type = '" . $this->db->escape($unit_type) .
"'";
5059 $sql .=
" ORDER BY sortorder";
5061 $resql = $this->db->query($sql);
5062 if ($resql && $this->db->num_rows($resql) > 0) {
5064 $return .=
'<option value="none"></option>';
5067 while ($res = $this->db->fetch_object($resql)) {
5068 $unitLabel = $res->label;
5069 if (!empty($langs->tab_translate[
'unit' . $res->code])) {
5070 $unitLabel = $langs->trans(
'unit' . $res->code) != $res->label ? $langs->trans(
'unit' . $res->code) : $res->label;
5073 if ($selected == $res->rowid) {
5074 $return .=
'<option value="' . $res->rowid .
'" selected>' . $unitLabel .
'</option>';
5076 $return .=
'<option value="' . $res->rowid .
'">' . $unitLabel .
'</option>';
5079 $return .=
'</select>';
5100 public function select_comptes($selected =
'', $htmlname =
'accountid', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'', $showcurrency = 0, $morecss =
'', $nooutput = 0)
5107 $langs->load(
"admin");
5110 $sql =
"SELECT rowid, label, bank, clos as status, currency_code";
5111 $sql .=
" FROM " . $this->db->prefix() .
"bank_account";
5112 $sql .=
" WHERE entity IN (" .
getEntity(
'bank_account') .
")";
5114 $sql .=
" AND clos = " . (int) $status;
5117 $sql .=
" AND " . $filtre;
5119 $sql .=
" ORDER BY label";
5121 dol_syslog(get_class($this) .
"::select_comptes", LOG_DEBUG);
5122 $result = $this->db->query($sql);
5124 $num = $this->db->num_rows($result);
5127 $out .=
'<select id="select' . $htmlname .
'" class="flat selectbankaccount' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5129 if (!empty($useempty) && !is_numeric($useempty)) {
5130 $out .=
'<option value="-1">'.$langs->trans($useempty).
'</option>';
5131 } elseif ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5132 $out .=
'<option value="-1"> </option>';
5136 $obj = $this->db->fetch_object($result);
5137 if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
5138 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'" selected>';
5140 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'">';
5142 $out .= trim($obj->label);
5143 if ($showcurrency) {
5144 $out .=
' (' . $obj->currency_code .
')';
5146 if ($status == 2 && $obj->status == 1) {
5147 $out .=
' (' . $langs->trans(
"Closed") .
')';
5149 $out .=
'</option>';
5152 $out .=
"</select>";
5156 $out .=
'<span class="opacitymedium">' . $langs->trans(
"NoActiveBankAccountDefined") .
'</span>';
5158 $out .=
'<span class="opacitymedium">' . $langs->trans(
"NoBankAccountFound") .
'</span>';
5166 if (empty($nooutput)) {
5186 public function selectEstablishments($selected =
'', $htmlname =
'entity', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'')
5190 $langs->load(
"admin");
5193 $sql =
"SELECT rowid, name, fk_country, status, entity";
5194 $sql .=
" FROM " . $this->db->prefix() .
"establishment";
5195 $sql .=
" WHERE 1=1";
5197 $sql .=
" AND status = " . (int) $status;
5200 $sql .=
" AND " . $filtre;
5202 $sql .=
" ORDER BY name";
5204 dol_syslog(get_class($this) .
"::select_establishment", LOG_DEBUG);
5205 $result = $this->db->query($sql);
5207 $num = $this->db->num_rows($result);
5210 print
'<select id="select' . $htmlname .
'" class="flat selectestablishment" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5211 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5212 print
'<option value="-1"> </option>';
5216 $obj = $this->db->fetch_object($result);
5217 if ($selected == $obj->rowid) {
5218 print
'<option value="' . $obj->rowid .
'" selected>';
5220 print
'<option value="' . $obj->rowid .
'">';
5222 print trim($obj->name);
5223 if ($status == 2 && $obj->status == 1) {
5224 print
' (' . $langs->trans(
"Closed") .
')';
5232 print
'<span class="opacitymedium">' . $langs->trans(
"NoActiveEstablishmentDefined") .
'</span>';
5234 print
'<span class="opacitymedium">' . $langs->trans(
"NoEstablishmentFound") .
'</span>';
5257 if ($htmlname !=
"none") {
5258 print
'<form method="POST" action="' . $page .
'">';
5259 print
'<input type="hidden" name="action" value="setbankaccount">';
5260 print
'<input type="hidden" name="token" value="' . newToken() .
'">';
5261 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
5262 $nbaccountfound = $this->
select_comptes($selected, $htmlname, 0,
'', $addempty);
5263 if ($nbaccountfound > 0) {
5264 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5268 $langs->load(
'banks');
5271 require_once DOL_DOCUMENT_ROOT .
'/compta/bank/class/account.class.php';
5272 $bankstatic =
new Account($this->db);
5273 $result = $bankstatic->fetch($selected);
5275 print $bankstatic->getNomUrl(1);
5304 public function select_all_categories($type, $selected =
'', $htmlname =
"parent", $maxlength = 64, $fromid = 0, $outputmode = 0, $include = 0, $morecss =
'', $useempty = 1)
5307 global $conf, $langs;
5308 $langs->load(
"categories");
5310 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
5313 if (is_numeric($type)) {
5314 dol_syslog(__METHOD__ .
': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING);
5317 if ($type === Categorie::TYPE_BANK_LINE) {
5319 $cate_arbo = array();
5320 $sql =
"SELECT c.label, c.rowid";
5321 $sql .=
" FROM " . $this->db->prefix() .
"category_bank as c";
5322 $sql .=
" WHERE entity = " . $conf->entity;
5323 $sql .=
" ORDER BY c.label";
5324 $result = $this->db->query($sql);
5326 $num = $this->db->num_rows($result);
5329 $objp = $this->db->fetch_object($result);
5331 $cate_arbo[$objp->rowid] = array(
'id' => $objp->rowid,
'fulllabel' => $objp->label,
'color' =>
'',
'picto' =>
'category');
5335 $this->db->free($result);
5341 $cate_arbo = $cat->get_full_arbo($type, $fromid, $include);
5344 $outarray = array();
5345 $outarrayrichhtml = array();
5348 $output =
'<select class="flat minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
5349 if (is_array($cate_arbo)) {
5350 $num = count($cate_arbo);
5353 $output .=
'<option value="-1" disabled>' . $langs->trans(
"NoCategoriesDefined") .
'</option>';
5355 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5356 $output .=
'<option value="-1"> </option>';
5358 foreach ($cate_arbo as $key => $value) {
5359 if ($cate_arbo[$key][
'id'] == $selected || ($selected ===
'auto' && count($cate_arbo) == 1)) {
5365 $labeltoshow =
img_picto(
'',
'category',
'class="pictofixedwidth" style="color: #' . $cate_arbo[$key][
'color'] .
'"');
5366 $labeltoshow .=
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle');
5368 $outarray[$cate_arbo[$key][
'id']] = $cate_arbo[$key][
'fulllabel'];
5370 $outarrayrichhtml[$cate_arbo[$key][
'id']] = $labeltoshow;
5372 $output .=
'<option ' . $add .
'value="' . $cate_arbo[$key][
'id'] .
'"';
5375 $output .=
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle');
5376 $output .=
'</option>';
5378 $cate_arbo[$key][
'data-html'] = $labeltoshow;
5382 $output .=
'</select>';
5385 if ($outputmode == 2) {
5388 } elseif ($outputmode == 1) {
5390 } elseif ($outputmode == 3) {
5391 return $outarrayrichhtml;
5414 public function form_confirm($page, $title, $question, $action, $formquestion = array(), $selectedchoice =
"", $useajax = 0, $height = 170, $width = 500)
5417 dol_syslog(__METHOD__ .
': using form_confirm is deprecated. Use formconfim instead.', LOG_WARNING);
5418 print $this->
formconfirm($page, $title, $question, $action, $formquestion, $selectedchoice, $useajax, $height, $width);
5448 public function formconfirm($page, $title, $question, $action, $formquestion =
'', $selectedchoice =
'', $useajax = 0, $height = 0, $width = 500, $disableformtag = 0, $labelbuttonyes =
'Yes', $labelbuttonno =
'No')
5450 global $langs, $conf;
5452 $more =
'<!-- formconfirm - before call, page=' .
dol_escape_htmltag($page) .
' -->';
5458 $newselectedchoice = empty($selectedchoice) ?
"no" : $selectedchoice;
5459 if ($conf->browser->layout ==
'phone') {
5464 if (empty($height)) {
5466 if (is_array($formquestion) && count($formquestion) > 2) {
5467 $height += ((count($formquestion) - 2) * 24);
5471 if (is_array($formquestion) && !empty($formquestion)) {
5473 foreach ($formquestion as $key => $input) {
5474 if (is_array($input) && !empty($input)) {
5475 if ($input[
'type'] ==
'hidden') {
5476 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
5477 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
5485 $moreonecolumn =
'';
5486 $more .=
'<div class="tagtable paddingtopbottomonly centpercent noborderspacing">' .
"\n";
5487 foreach ($formquestion as $key => $input) {
5488 if (is_array($input) && !empty($input)) {
5489 $size = (!empty($input[
'size']) ?
' size="' . $input[
'size'] .
'"' :
'');
5490 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
5491 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
5493 if ($input[
'type'] ==
'text') {
5494 $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 .
' /></div></div>' .
"\n";
5495 } elseif ($input[
'type'] ==
'password') {
5496 $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";
5497 } elseif ($input[
'type'] ==
'textarea') {
5503 $moreonecolumn .=
'<div class="margintoponly">';
5504 $moreonecolumn .= $input[
'label'] .
'<br>';
5506 $moreonecolumn .= $input[
'value'];
5507 $moreonecolumn .=
'</textarea>';
5508 $moreonecolumn .=
'</div>';
5509 } elseif (in_array($input[
'type'], [
'select',
'multiselect'])) {
5510 if (empty($morecss)) {
5511 $morecss =
'minwidth100';
5514 $show_empty = isset($input[
'select_show_empty']) ? $input[
'select_show_empty'] : 1;
5515 $key_in_label = isset($input[
'select_key_in_label']) ? $input[
'select_key_in_label'] : 0;
5516 $value_as_key = isset($input[
'select_value_as_key']) ? $input[
'select_value_as_key'] : 0;
5517 $translate = isset($input[
'select_translate']) ? $input[
'select_translate'] : 0;
5518 $maxlen = isset($input[
'select_maxlen']) ? $input[
'select_maxlen'] : 0;
5519 $disabled = isset($input[
'select_disabled']) ? $input[
'select_disabled'] : 0;
5520 $sort = isset($input[
'select_sort']) ? $input[
'select_sort'] :
'';
5522 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">';
5523 if (!empty($input[
'label'])) {
5524 $more .= $input[
'label'] .
'</div><div class="tagtd left">';
5526 if ($input[
'type'] ==
'select') {
5527 $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);
5529 $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);
5531 $more .=
'</div></div>' .
"\n";
5532 } elseif ($input[
'type'] ==
'checkbox') {
5533 $more .=
'<div class="tagtr">';
5534 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'"><label for="' .
dol_escape_htmltag($input[
'name']) .
'">' . $input[
'label'] .
'</label></div><div class="tagtd">';
5535 $more .=
'<input type="checkbox" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' .
dol_escape_htmltag($input[
'name']) .
'" name="' .
dol_escape_htmltag($input[
'name']) .
'"' . $moreattr;
5536 if (!is_bool($input[
'value']) && $input[
'value'] !=
'false' && $input[
'value'] !=
'0' && $input[
'value'] !=
'') {
5537 $more .=
' checked';
5539 if (is_bool($input[
'value']) && $input[
'value']) {
5540 $more .=
' checked';
5542 if (isset($input[
'disabled'])) {
5543 $more .=
' disabled';
5545 $more .=
' /></div>';
5546 $more .=
'</div>' .
"\n";
5547 } elseif ($input[
'type'] ==
'radio') {
5549 foreach ($input[
'values'] as $selkey => $selval) {
5550 $more .=
'<div class="tagtr">';
5551 if (isset($input[
'label'])) {
5553 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
' tdtop' : (
' tdtop ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
5555 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' "' . $input[
'tdclass'])) .
'"> </div>';
5558 $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;
5559 if (!empty($input[
'disabled'])) {
5560 $more .=
' disabled';
5562 if (isset($input[
'default']) && $input[
'default'] === $selkey) {
5563 $more .=
' checked="checked"';
5566 $more .=
'<label for="' .
dol_escape_htmltag($input[
'name'] . $selkey) .
'" class="valignmiddle">' . $selval .
'</label>';
5567 $more .=
'</div></div>' .
"\n";
5570 } elseif ($input[
'type'] ==
'date' || $input[
'type'] ==
'datetime') {
5571 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
5572 $more .=
'<div class="tagtd">';
5573 $addnowlink = (empty($input[
'datenow']) ? 0 : 1);
5575 if ($input[
'type'] ==
'datetime') {
5576 $h = isset($input[
'hours']) ? $input[
'hours'] : 1;
5577 $m = isset($input[
'minutes']) ? $input[
'minutes'] : 1;
5579 $more .= $this->
selectDate(isset($input[
'value']) ? $input[
'value'] : -1, $input[
'name'], $h, $m, 0,
'', 1, $addnowlink);
5580 $more .=
'</div></div>'.
"\n";
5581 $formquestion[] = array(
'name' => $input[
'name'].
'day');
5582 $formquestion[] = array(
'name' => $input[
'name'].
'month');
5583 $formquestion[] = array(
'name' => $input[
'name'].
'year');
5584 $formquestion[] = array(
'name' => $input[
'name'].
'hour');
5585 $formquestion[] = array(
'name' => $input[
'name'].
'min');
5586 } elseif ($input[
'type'] ==
'other') {
5587 $more .=
'<div class="tagtr"><div class="tagtd'.(empty($input[
'tdclass']) ?
'' : (
' '.$input[
'tdclass'])).
'">';
5588 if (!empty($input[
'label'])) {
5589 $more .= $input[
'label'] .
'</div><div class="tagtd">';
5591 $more .= $input[
'value'];
5592 $more .=
'</div></div>' .
"\n";
5593 } elseif ($input[
'type'] ==
'onecolumn') {
5594 $moreonecolumn .=
'<div class="margintoponly">';
5595 $moreonecolumn .= $input[
'value'];
5596 $moreonecolumn .=
'</div>' .
"\n";
5597 } elseif ($input[
'type'] ==
'hidden') {
5599 } elseif ($input[
'type'] ==
'separator') {
5602 $more .=
'Error type ' . $input[
'type'] .
' for the confirm box is not a supported type';
5606 $more .=
'</div>' .
"\n";
5607 $more .= $moreonecolumn;
5613 if (!empty($conf->dol_use_jmobile)) {
5616 if (empty($conf->use_javascript_ajax)) {
5622 $dialogconfirm =
'dialog-confirm';
5624 if (!is_numeric($useajax)) {
5628 $dialogconfirm .=
'-' . $button;
5630 $pageyes = $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=yes';
5631 $pageno = ($useajax == 2 ? $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=no' :
'');
5634 if (is_array($formquestion)) {
5635 foreach ($formquestion as $key => $input) {
5638 if (is_array($input) && isset($input[
'name'])) {
5639 if (strpos($input[
'name'],
',') > 0) {
5640 $inputok = array_merge($inputok, explode(
',', $input[
'name']));
5642 array_push($inputok, $input[
'name']);
5647 if (is_array($input) && isset($input[
'inputko']) && $input[
'inputko'] == 1 && isset($input[
'name'])) {
5648 array_push($inputko, $input[
'name']);
5654 $formconfirm .=
'<div id="' . $dialogconfirm .
'" title="' .
dol_escape_htmltag($title) .
'" style="display: none;">';
5655 if (is_array($formquestion) && array_key_exists(
'text', $formquestion) && !empty($formquestion[
'text'])) {
5656 $formconfirm .=
'<div class="confirmtext">' . $formquestion[
'text'] .
'</div>' .
"\n";
5658 if (!empty($more)) {
5659 $formconfirm .=
'<div class="confirmquestions">' . $more .
'</div>' .
"\n";
5661 $formconfirm .= ($question ?
'<div class="confirmmessage">' .
img_help(0,
'') .
' ' . $question .
'</div>' :
'');
5662 $formconfirm .=
'</div>' .
"\n";
5664 $formconfirm .=
"\n<!-- begin code of popup for formconfirm page=" . $page .
" -->\n";
5665 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
5666 $formconfirm .=
"/* Code for the jQuery('#dialogforpopup').dialog() */\n";
5667 $formconfirm .=
'jQuery(document).ready(function() {
5669 $( "#' . $dialogconfirm .
'" ).dialog(
5671 autoOpen: ' . ($autoOpen ?
"true" :
"false") .
',';
5672 if ($newselectedchoice ==
'no') {
5675 $(this).parent().find("button.ui-button:eq(2)").focus();
5680 if ($useajax == 1) {
5681 $jsforcursor =
'// The call to urljump can be slow, so we set the wait cursor' .
"\n";
5682 $jsforcursor .=
'jQuery("html,body,#id-container").addClass("cursorwait");' .
"\n";
5685 $postconfirmas =
'GET';
5689 height: "' . $height .
'",
5690 width: "' . $width .
'",
5692 closeOnEscape: false,
5694 "' .
dol_escape_js($langs->transnoentities($labelbuttonyes)) .
'": function() {
5695 var options = "token=' . urlencode(newToken()) .
'";
5696 var inputok = ' . json_encode($inputok) .
'; /* List of fields into form */
5697 var page = "' .
dol_escape_js(!empty($page) ? $page :
'') .
'";
5698 var pageyes = "' .
dol_escape_js(!empty($pageyes) ? $pageyes :
'') .
'";
5700 if (inputok.length > 0) {
5701 $.each(inputok, function(i, inputname) {
5704 if ($("input[name=\'" + inputname + "\']").attr("type") == "radio") {
5705 inputvalue = $("input[name=\'" + inputname + "\']:checked").val();
5707 if ($("#" + inputname).attr("type") == "checkbox") { more = ":checked"; }
5708 inputvalue = $("#" + inputname + more).val();
5710 if (typeof inputvalue == "undefined") { inputvalue=""; }
5711 console.log("formconfirm check inputname="+inputname+" inputvalue="+inputvalue);
5712 options += "&" + inputname + "=" + encodeURIComponent(inputvalue);
5715 var urljump = pageyes + (pageyes.indexOf("?") < 0 ? "?" : "&") + options;
5716 if (pageyes.length > 0) {';
5717 if ($postconfirmas ==
'GET') {
5718 $formconfirm .=
'location.href = urljump;';
5720 $formconfirm .= $jsforcursor;
5721 $formconfirm .=
'var post = $.post(
5724 function(data) { $("body").html(data); jQuery("html,body,#id-container").removeClass("cursorwait"); }
5728 console.log("after post ok");
5730 $(this).dialog("close");
5732 "' .
dol_escape_js($langs->transnoentities($labelbuttonno)) .
'": function() {
5733 var options = "token=' . urlencode(newToken()) .
'";
5734 var inputko = ' . json_encode($inputko) .
'; /* List of fields into form */
5735 var page = "' .
dol_escape_js(!empty($page) ? $page :
'') .
'";
5736 var pageno="' .
dol_escape_js(!empty($pageno) ? $pageno :
'') .
'";
5737 if (inputko.length > 0) {
5738 $.each(inputko, function(i, inputname) {
5740 if ($("#" + inputname).attr("type") == "checkbox") { more = ":checked"; }
5741 var inputvalue = $("#" + inputname + more).val();
5742 if (typeof inputvalue == "undefined") { inputvalue=""; }
5743 options += "&" + inputname + "=" + encodeURIComponent(inputvalue);
5746 var urljump=pageno + (pageno.indexOf("?") < 0 ? "?" : "&") + options;
5748 if (pageno.length > 0) {';
5749 if ($postconfirmas ==
'GET') {
5750 $formconfirm .=
'location.href = urljump;';
5752 $formconfirm .= $jsforcursor;
5753 $formconfirm .=
'var post = $.post(
5756 function(data) { $("body").html(data); jQuery("html,body,#id-container").removeClass("cursorwait"); }
5760 console.log("after post ko");
5762 $(this).dialog("close");
5768 var button = "' . $button .
'";
5769 if (button.length > 0) {
5770 $( "#" + button ).click(function() {
5771 $("#' . $dialogconfirm .
'").dialog("open");
5777 $formconfirm .=
"<!-- end ajax formconfirm -->\n";
5779 $formconfirm .=
"\n<!-- begin formconfirm page=" .
dol_escape_htmltag($page) .
" -->\n";
5781 if (empty($disableformtag)) {
5782 $formconfirm .=
'<form method="POST" action="' . $page .
'" class="notoptoleftroright">' .
"\n";
5785 $formconfirm .=
'<input type="hidden" name="action" value="' . $action .
'">' .
"\n";
5786 $formconfirm .=
'<input type="hidden" name="token" value="' . newToken() .
'">' .
"\n";
5788 $formconfirm .=
'<table class="valid centpercent">' .
"\n";
5791 $formconfirm .=
'<tr class="validtitre"><td class="validtitre" colspan="2">';
5792 $formconfirm .=
img_picto(
'',
'pictoconfirm') .
' ' . $title;
5793 $formconfirm .=
'</td></tr>' .
"\n";
5796 if (is_array($formquestion) && array_key_exists(
'text', $formquestion) && !empty($formquestion[
'text'])) {
5797 $formconfirm .=
'<tr class="valid"><td class="valid" colspan="2">' . $formquestion[
'text'] .
'</td></tr>' .
"\n";
5802 $formconfirm .=
'<tr class="valid"><td class="valid" colspan="2">' .
"\n";
5803 $formconfirm .= $more;
5804 $formconfirm .=
'</td></tr>' .
"\n";
5808 $formconfirm .=
'<tr class="valid">';
5809 $formconfirm .=
'<td class="valid">' . $question .
'</td>';
5810 $formconfirm .=
'<td class="valid center">';
5811 $formconfirm .= $this->
selectyesno(
"confirm", $newselectedchoice, 0,
false, 0, 0,
'marginleftonly marginrightonly', $labelbuttonyes, $labelbuttonno);
5812 $formconfirm .=
'<input class="button valignmiddle confirmvalidatebutton small" type="submit" value="' . $langs->trans(
"Validate") .
'">';
5813 $formconfirm .=
'</td>';
5814 $formconfirm .=
'</tr>' .
"\n";
5816 $formconfirm .=
'</table>' .
"\n";
5818 if (empty($disableformtag)) {
5819 $formconfirm .=
"</form>\n";
5821 $formconfirm .=
'<br>';
5823 if (!empty($conf->use_javascript_ajax)) {
5824 $formconfirm .=
'<!-- code to disable button to avoid double clic -->';
5825 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
5827 $(document).ready(function () {
5828 $(".confirmvalidatebutton").on("click", function() {
5829 console.log("We click on button confirmvalidatebutton");
5830 $(this).attr("disabled", "disabled");
5831 setTimeout(\'$(".confirmvalidatebutton").removeAttr("disabled")\', 3000);
5832 //console.log($(this).closest("form"));
5833 $(this).closest("form").submit();
5837 $formconfirm .=
'</script>' .
"\n";
5840 $formconfirm .=
"<!-- end formconfirm -->\n";
5843 return $formconfirm;
5864 public function form_project($page, $socid, $selected =
'', $htmlname =
'projectid', $discard_closed = 0, $maxlength = 20, $forcefocus = 0, $nooutput = 0, $textifnoproject =
'', $morecss =
'')
5869 require_once DOL_DOCUMENT_ROOT .
'/core/lib/project.lib.php';
5870 require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formprojet.class.php';
5876 $langs->load(
"project");
5877 if ($htmlname !=
"none") {
5878 $out .=
'<form method="post" action="' . $page .
'">';
5879 $out .=
'<input type="hidden" name="action" value="classin">';
5880 $out .=
'<input type="hidden" name="token" value="' . newToken() .
'">';
5881 $out .= $formproject->select_projects($socid, $selected, $htmlname, $maxlength, 0, 1, $discard_closed, $forcefocus, 0, 0,
'', 1, 0, $morecss);
5882 $out .=
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
5885 $out .=
'<span class="project_head_block">';
5887 $projet =
new Project($this->db);
5888 $projet->fetch($selected);
5889 $out .= $projet->getNomUrl(0,
'', 1);
5891 $out .=
'<span class="opacitymedium">' . $textifnoproject .
'</span>';
5896 if (empty($nooutput)) {
5920 public function form_conditions_reglement($page, $selected =
'', $htmlname =
'cond_reglement_id', $addempty = 0, $type =
'', $filtertype = -1, $deposit_percent = -1, $nooutput = 0)
5927 if ($htmlname !=
"none") {
5928 $out .=
'<form method="POST" action="' . $page .
'">';
5929 $out .=
'<input type="hidden" name="action" value="setconditions">';
5930 $out .=
'<input type="hidden" name="token" value="' . newToken() .
'">';
5932 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
5935 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
5940 if (isset($this->cache_conditions_paiements[$selected])) {
5941 $label = $this->cache_conditions_paiements[$selected][
'label'];
5943 if (!empty($this->cache_conditions_paiements[$selected][
'deposit_percent'])) {
5944 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $this->cache_conditions_paiements[$selected][
'deposit_percent'], $label);
5949 $langs->load(
'errors');
5950 $out .= $langs->trans(
'ErrorNotInDictionaryPaymentConditions');
5957 if (empty($nooutput)) {
5979 if ($htmlname !=
"none") {
5980 print
'<form method="post" action="' . $page .
'">';
5981 print
'<input type="hidden" name="action" value="setavailability">';
5982 print
'<input type="hidden" name="token" value="' . newToken() .
'">';
5984 print
'<input type="submit" name="modify" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
5985 print
'<input type="submit" name="cancel" class="button smallpaddingimp" value="' . $langs->trans(
"Cancel") .
'">';
5990 print $this->cache_availability[$selected][
'label'];
6007 public function formInputReason($page, $selected =
'', $htmlname =
'demandreason', $addempty = 0)
6010 if ($htmlname !=
"none") {
6011 print
'<form method="post" action="' . $page .
'">';
6012 print
'<input type="hidden" name="action" value="setdemandreason">';
6013 print
'<input type="hidden" name="token" value="' . newToken() .
'">';
6015 print
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6020 foreach ($this->cache_demand_reason as $key => $val) {
6021 if ($val[
'id'] == $selected) {
6022 print $val[
'label'];
6047 public function form_date($page, $selected, $htmlname, $displayhour = 0, $displaymin = 0, $nooutput = 0, $type =
'')
6054 if ($htmlname !=
"none") {
6055 $ret .=
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
6056 $ret .=
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
6057 $ret .=
'<input type="hidden" name="token" value="' . newToken() .
'">';
6059 $ret .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
6061 $ret .=
'<table class="nobordernopadding">';
6063 $ret .= $this->
selectDate($selected, $htmlname, $displayhour, $displaymin, 1,
'form' . $htmlname, 1, 0);
6065 $ret .=
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
6066 $ret .=
'</tr></table></form>';
6075 if (empty($nooutput)) {
6094 public function form_users($page, $selected =
'', $htmlname =
'userid', $exclude = array(), $include = array())
6099 if ($htmlname !=
"none") {
6100 print
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
6101 print
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
6102 print
'<input type="hidden" name="token" value="' . newToken() .
'">';
6103 print $this->
select_dolusers($selected, $htmlname, 1, $exclude, 0, $include);
6104 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6108 require_once DOL_DOCUMENT_ROOT .
'/user/class/user.class.php';
6109 $theuser =
new User($this->db);
6110 $theuser->fetch($selected);
6111 print $theuser->getNomUrl(1);
6134 public function form_modes_reglement($page, $selected =
'', $htmlname =
'mode_reglement_id', $filtertype =
'', $active = 1, $addempty = 0, $type =
'', $nooutput = 0)
6140 if ($htmlname !=
"none") {
6141 $out .=
'<form method="POST" action="' . $page .
'">';
6142 $out .=
'<input type="hidden" name="action" value="setmode">';
6143 $out .=
'<input type="hidden" name="token" value="' . newToken() .
'">';
6145 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
6147 $out .= $this->
select_types_paiements($selected, $htmlname, $filtertype, 0, $addempty, 0, 0, $active,
'', 1);
6148 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6153 $out .= $this->cache_types_paiements[$selected][
'label'];
6180 if ($htmlname !=
"none") {
6181 print
'<form method="POST" action="' . $page .
'">';
6182 print
'<input type="hidden" name="action" value="settransportmode">';
6183 print
'<input type="hidden" name="token" value="' . newToken() .
'">';
6185 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6190 print $this->cache_transport_mode[$selected][
'label'];
6211 if ($htmlname !=
"none") {
6212 print
'<form method="POST" action="' . $page .
'">';
6213 print
'<input type="hidden" name="action" value="setmulticurrencycode">';
6214 print
'<input type="hidden" name="token" value="' . newToken() .
'">';
6216 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6219 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
6220 print !empty($selected) ?
currency_name($selected, 1) :
' ';
6238 global $langs, $mysoc, $conf;
6240 if ($htmlname !=
"none") {
6241 print
'<form method="POST" action="' . $page .
'">';
6242 print
'<input type="hidden" name="action" value="setmulticurrencyrate">';
6243 print
'<input type="hidden" name="token" value="' . newToken() .
'">';
6244 print
'<input type="text" class="maxwidth100" name="' . $htmlname .
'" value="' . (!empty($rate) ?
price(
price2num($rate,
'CU')) : 1) .
'" /> ';
6245 print
'<select name="calculation_mode">';
6246 print
'<option value="1">Change ' . $langs->trans(
"PriceUHT") .
' of lines</option>';
6247 print
'<option value="2">Change ' . $langs->trans(
"PriceUHTCurrency") .
' of lines</option>';
6249 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6252 if (!empty($rate)) {
6253 print
price($rate, 1, $langs, 0, 0);
6254 if ($currency && $rate != 1) {
6255 print
' (' .
price($rate, 1, $langs, 0, 0) .
' ' . $currency .
' = 1 ' . $conf->currency .
')';
6281 public function form_remise_dispo($page, $selected, $htmlname, $socid, $amount, $filter =
'', $maxvalue = 0, $more =
'', $hidelist = 0, $discount_type = 0)
6284 global $conf, $langs;
6285 if ($htmlname !=
"none") {
6286 print
'<form method="post" action="' . $page .
'">';
6287 print
'<input type="hidden" name="action" value="setabsolutediscount">';
6288 print
'<input type="hidden" name="token" value="' . newToken() .
'">';
6289 print
'<div class="inline-block">';
6290 if (!empty($discount_type)) {
6292 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL") {
6293 $translationKey =
'HasAbsoluteDiscountFromSupplier';
6295 $translationKey =
'HasCreditNoteFromSupplier';
6298 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
6299 $translationKey =
'HasAbsoluteDiscountFromSupplier';
6301 $translationKey =
'HasCreditNoteFromSupplier';
6306 if (!$filter || $filter ==
"fk_facture_source IS NULL") {
6307 $translationKey =
'CompanyHasAbsoluteDiscount';
6309 $translationKey =
'CompanyHasCreditNote';
6312 if (!$filter || $filter ==
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
6313 $translationKey =
'CompanyHasAbsoluteDiscount';
6315 $translationKey =
'CompanyHasCreditNote';
6319 print $langs->trans($translationKey,
price($amount, 0, $langs, 0, 0, -1, $conf->currency));
6320 if (empty($hidelist)) {
6324 if (empty($hidelist)) {
6325 print
'<div class="inline-block" style="padding-right: 10px">';
6326 $newfilter =
'discount_type=' . intval($discount_type);
6327 if (!empty($discount_type)) {
6328 $newfilter .=
' AND fk_invoice_supplier IS NULL AND fk_invoice_supplier_line IS NULL';
6330 $newfilter .=
' AND fk_facture IS NULL AND fk_facture_line IS NULL';
6333 $newfilter .=
' AND (' . $filter .
')';
6336 $nbqualifiedlines = $this->
select_remises($selected, $htmlname, $newfilter, $socid, $maxvalue);
6337 if ($nbqualifiedlines > 0) {
6338 print
' <input type="submit" class="button smallpaddingimp" value="' .
dol_escape_htmltag($langs->trans(
"UseLine")) .
'"';
6339 if (!empty($discount_type) && $filter && $filter !=
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
6340 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
6342 if (empty($discount_type) && $filter && $filter !=
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
6343 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
6351 print
'<div class="inline-block">';
6377 public function form_contacts($page, $societe, $selected =
'', $htmlname =
'contactid')
6382 if ($htmlname !=
"none") {
6383 print
'<form method="post" action="' . $page .
'">';
6384 print
'<input type="hidden" name="action" value="set_contact">';
6385 print
'<input type="hidden" name="token" value="' . newToken() .
'">';
6386 print
'<table class="nobordernopadding">';
6391 $addcontact = (
getDolGlobalString(
'SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans(
"AddContact") : $langs->trans(
"AddContactAddress"));
6392 print
'<a href="' . DOL_URL_ROOT .
'/contact/card.php?socid=' . $societe->id .
'&action=create&backtoreferer=1">' . $addcontact .
'</a>';
6395 print
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
6396 print
'</tr></table></form>';
6399 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
6400 $contact =
new Contact($this->db);
6401 $contact->fetch($selected);
6402 print $contact->getFullName($langs);
6427 public function form_thirdparty($page, $selected =
'', $htmlname =
'socid', $filter =
'', $showempty = 0, $showtype = 0, $forcecombo = 0, $events = array(), $nooutput = 0, $excludeids = array(), $textifnothirdparty =
'')
6433 if ($htmlname !=
"none") {
6434 $out .=
'<form method="post" action="' . $page .
'">';
6435 $out .=
'<input type="hidden" name="action" value="set_thirdparty">';
6436 $out .=
'<input type="hidden" name="token" value="' . newToken() .
'">';
6437 $out .= $this->
select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, 0,
'minwidth100',
'',
'', 1, array(),
false, $excludeids);
6438 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6442 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
6443 $soc =
new Societe($this->db);
6444 $soc->fetch($selected);
6445 $out .= $soc->getNomUrl(0,
'');
6447 $out .=
'<span class="opacitymedium">' . $textifnothirdparty .
'</span>';
6485 public function selectCurrency($selected =
'', $htmlname =
'currency_id', $mode = 0, $useempty =
'')
6487 global $langs, $user;
6489 $langs->loadCacheCurrencies(
'');
6493 if ($selected ==
'euro' || $selected ==
'euros') {
6497 $out .=
'<select class="flat maxwidth200onsmartphone minwidth300" name="' . $htmlname .
'" id="' . $htmlname .
'">';
6499 $out .=
'<option value="-1" selected></option>';
6501 foreach ($langs->cache_currencies as $code_iso => $currency) {
6502 $labeltoshow = $currency[
'label'];
6504 $labeltoshow .=
' <span class="opacitymedium">(' . $code_iso .
')</span>';
6506 $labeltoshow .=
' <span class="opacitymedium">(' . $langs->getCurrencySymbol($code_iso) .
')</span>';
6509 if ($selected && $selected == $code_iso) {
6510 $out .=
'<option value="' . $code_iso .
'" selected data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
6512 $out .=
'<option value="' . $code_iso .
'" data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
6514 $out .= $labeltoshow;
6515 $out .=
'</option>';
6517 $out .=
'</select>';
6519 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
6523 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
6541 public function selectMultiCurrency($selected =
'', $htmlname =
'multicurrency_code', $useempty = 0, $filter =
'', $excludeConfCurrency =
false, $morecss =
'')
6543 global $conf, $langs;
6545 $langs->loadCacheCurrencies(
'');
6547 $TCurrency = array();
6549 $sql =
"SELECT code FROM " . $this->db->prefix() .
"multicurrency";
6550 $sql .=
" WHERE entity IN ('" .
getEntity(
'mutlicurrency') .
"')";
6552 $sql .=
" AND " . $filter;
6554 $resql = $this->db->query($sql);
6556 while ($obj = $this->db->fetch_object($resql)) {
6557 $TCurrency[$obj->code] = $obj->code;
6562 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
6564 $out .=
'<option value=""> </option>';
6567 if (!in_array($conf->currency, $TCurrency) && !$excludeConfCurrency) {
6568 $TCurrency[$conf->currency] = $conf->currency;
6570 if (count($TCurrency) > 0) {
6571 foreach ($langs->cache_currencies as $code_iso => $currency) {
6572 if (isset($TCurrency[$code_iso])) {
6573 if (!empty($selected) && $selected == $code_iso) {
6574 $out .=
'<option value="' . $code_iso .
'" selected="selected">';
6576 $out .=
'<option value="' . $code_iso .
'">';
6579 $out .= $currency[
'label'];
6580 $out .=
' (' . $langs->getCurrencySymbol($code_iso) .
')';
6581 $out .=
'</option>';
6586 $out .=
'</select>';
6589 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
6606 global $langs, $user;
6608 $num = count($this->cache_vatrates);
6615 $sql =
"SELECT t.rowid, t.type_vat, t.code, t.taux, t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.recuperableonly";
6616 $sql .=
" FROM ".$this->db->prefix().
"c_tva as t, ".$this->db->prefix().
"c_country as c";
6617 $sql .=
" WHERE t.fk_pays = c.rowid";
6618 $sql .=
" AND t.active > 0";
6619 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
6620 $sql .=
" AND c.code IN (" . $this->db->sanitize($country_code, 1) .
")";
6621 $sql .=
" ORDER BY t.code ASC, t.taux ASC, t.recuperableonly ASC";
6623 $resql = $this->db->query($sql);
6625 $num = $this->db->num_rows($resql);
6627 for ($i = 0; $i < $num; $i++) {
6628 $obj = $this->db->fetch_object($resql);
6630 $tmparray = array();
6631 $tmparray[
'rowid'] = $obj->rowid;
6632 $tmparray[
'type_vat'] = $obj->type_vat;
6633 $tmparray[
'code'] = $obj->code;
6634 $tmparray[
'txtva'] = $obj->taux;
6635 $tmparray[
'nprtva'] = $obj->recuperableonly;
6636 $tmparray[
'localtax1'] = $obj->localtax1;
6637 $tmparray[
'localtax1_type'] = $obj->localtax1_type;
6638 $tmparray[
'localtax2'] = $obj->localtax2;
6639 $tmparray[
'localtax2_type'] = $obj->localtax1_type;
6640 $tmparray[
'label'] = $obj->taux .
'%' . ($obj->code ?
' (' . $obj->code .
')' :
'');
6641 $tmparray[
'labelallrates'] = $obj->taux .
'/' . ($obj->localtax1 ? $obj->localtax1 :
'0') .
'/' . ($obj->localtax2 ? $obj->localtax2 :
'0') . ($obj->code ?
' (' . $obj->code .
')' :
'');
6642 $positiverates =
'';
6644 $positiverates .= ($positiverates ?
'/' :
'') . $obj->taux;
6646 if ($obj->localtax1) {
6647 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax1;
6649 if ($obj->localtax2) {
6650 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax2;
6652 if (empty($positiverates)) {
6653 $positiverates =
'0';
6655 $tmparray[
'labelpositiverates'] = $positiverates . ($obj->code ?
' (' . $obj->code .
')' :
'');
6657 $this->cache_vatrates[$obj->rowid] = $tmparray;
6662 $this->error =
'<span class="error">';
6663 $this->error .= $langs->trans(
"ErrorNoVATRateDefinedForSellerCountry", $country_code);
6665 if (!empty($user) && $user->admin && preg_match(
'/\'(..)\'/', $country_code, $reg)) {
6666 $langs->load(
"errors");
6667 $new_country_code = $reg[1];
6668 $country_id =
dol_getIdFromCode($this->db, $new_country_code,
'c_pays',
'code',
'rowid');
6669 $this->error .=
'<br>'.$langs->trans(
"ErrorFixThisHere", DOL_URL_ROOT.
'/admin/dict.php?id=10'.($country_id > 0 ?
'&countryidforinsert='.$country_id :
''));
6671 $this->error .=
'</span>';
6675 $this->error =
'<span class="error">' . $this->db->error() .
'</span>';
6704 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)
6707 global $langs, $mysoc;
6709 $langs->load(
'errors');
6714 $defaultnpr = ($info_bits & 0x01);
6715 $defaultnpr = (preg_match(
'/\*/', $selectedrate) ? 1 : $defaultnpr);
6716 $defaulttx = str_replace(
'*',
'', $selectedrate);
6719 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
6720 $defaultcode = $reg[1];
6721 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
6726 if (is_object($societe_vendeuse) && !$societe_vendeuse->country_code) {
6727 if ($societe_vendeuse->id == $mysoc->id) {
6728 $return .=
'<span class="error">' . $langs->trans(
"ErrorYourCountryIsNotDefined") .
'</span>';
6730 $return .=
'<span class="error">' . $langs->trans(
"ErrorSupplierCountryIsNotDefined") .
'</span>';
6741 if (is_object($societe_vendeuse)) {
6742 $code_country =
"'" . $societe_vendeuse->country_code .
"'";
6744 $code_country =
"'" . $mysoc->country_code .
"'";
6747 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
6751 if (
isInEEC($societe_vendeuse) &&
isInEEC($societe_acheteuse) && !$societe_acheteuse->isACompany()) {
6753 if (is_numeric($type)) {
6755 switch ($selectVatComboMode) {
6757 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
6760 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
6764 } elseif (!$idprod) {
6765 switch ($selectVatComboMode) {
6767 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
6770 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
6774 $prodstatic =
new Product($this->db);
6775 $prodstatic->fetch($idprod);
6777 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
6787 $arrayofvatrates = array();
6788 foreach ($this->cache_vatrates as $cachevalue) {
6789 if (empty($cachevalue[
'type_vat']) || $cachevalue[
'type_vat'] != $type_vat) {
6790 $arrayofvatrates[] = $cachevalue;
6794 $num = count($arrayofvatrates);
6798 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
6799 $tmpthirdparty =
new Societe($this->db);
6801 $defaulttx =
get_default_tva($societe_vendeuse, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
6802 $defaultnpr =
get_default_npr($societe_vendeuse, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
6804 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
6805 $defaultcode = $reg[1];
6806 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
6808 if (empty($defaulttx)) {
6815 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
6818 $defaulttx = $arrayofvatrates[$num - 1][
'txtva'];
6825 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
6826 $defaultcode = $reg[1];
6827 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
6835 if (is_object($societe_vendeuse) && $societe_vendeuse->id == $mysoc->id && $societe_vendeuse->tva_assuj ==
"0") {
6844 if (!$options_only) {
6845 $return .=
'<select class="flat minwidth75imp maxwidth100 right" id="' . $htmlname .
'" name="' . $htmlname .
'"' . ($disabled ?
' disabled' :
'') . $title .
'>';
6848 $selectedfound =
false;
6849 foreach ($arrayofvatrates as $rate) {
6851 if ($disabled && $rate[
'txtva'] != 0) {
6856 $key = $rate[
'txtva'];
6857 $key .= $rate[
'nprtva'] ?
'*' :
'';
6858 if ($mode > 0 && $rate[
'code']) {
6859 $key .=
' (' . $rate[
'code'] .
')';
6862 $key = $rate[
'rowid'];
6865 $return .=
'<option value="' . $key .
'"';
6866 if (!$selectedfound) {
6868 if ($defaultcode == $rate[
'code']) {
6869 $return .=
' selected';
6870 $selectedfound =
true;
6872 } elseif ($rate[
'txtva'] == $defaulttx && $rate[
'nprtva'] == $defaultnpr) {
6873 $return .=
' selected';
6874 $selectedfound =
true;
6880 if ($mysoc->country_code ==
'IN' ||
getDolGlobalString(
'MAIN_VAT_LABEL_IS_POSITIVE_RATES')) {
6882 $return .= $rate[
'labelpositiverates'];
6885 $return .=
vatrate($rate[
'label']);
6889 $return .= (empty($rate[
'code']) && $rate[
'nprtva']) ?
' *' :
'';
6891 $return .=
'</option>';
6894 if (!$options_only) {
6895 $return .=
'</select>';
6899 $return .= $this->error;
6933 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 =
'')
6936 dol_syslog(__METHOD__ .
': using select_date is deprecated. Use selectDate instead.', LOG_WARNING);
6937 $retstring = $this->
selectDate($set_time, $prefix, $h, $m, $empty, $form_name, $d, $addnowlink, $disabled, $fullday, $addplusone, $adddateof);
6938 if (!empty($nooutput)) {
6961 public function selectDateToDate($set_time =
'', $set_time_end =
'', $prefix =
're', $empty = 0, $forcenewline = 0)
6965 $ret = $this->
selectDate($set_time, $prefix .
'_start', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"from"),
'tzuserrel');
6966 if ($forcenewline) {
6969 $ret .= $this->
selectDate($set_time_end, $prefix .
'_end', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
7000 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')
7002 global $conf, $langs;
7004 if ($gm ===
'auto') {
7005 $gm = (empty($conf) ?
'tzserver' : $conf->tzuserinputkey);
7010 if ($prefix ==
'') {
7021 if ($stepminutes <= 0 || $stepminutes > 30) {
7032 $orig_set_time = $set_time;
7034 if ($set_time ===
'' && $emptydate == 0) {
7035 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
7036 if ($gm ==
'tzuser' || $gm ==
'tzuserrel') {
7048 if (preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/', $set_time, $reg)) {
7050 $syear = (!empty($reg[1]) ? $reg[1] :
'');
7051 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
7052 $sday = (!empty($reg[3]) ? $reg[3] :
'');
7053 $shour = (!empty($reg[4]) ? $reg[4] :
'');
7054 $smin = (!empty($reg[5]) ? $reg[5] :
'');
7055 } elseif (strval($set_time) !=
'' && $set_time != -1) {
7060 if ($orig_set_time !=
'') {
7074 if ($h == 3 || $h == 4) {
7085 $usecalendar =
'combo';
7091 $usecalendar =
'html';
7096 if ($usecalendar !=
'combo') {
7097 $formated_date =
'';
7099 if (strval($set_time) !=
'' && $set_time != -1) {
7101 $formated_date =
dol_print_date($set_time, $langs->trans(
"FormatDateShortInput"), $gm);
7105 if ($usecalendar ==
"eldy") {
7107 $retstring .=
'<input id="' . $prefix .
'" name="' . $prefix .
'" type="text" class="maxwidthdate center" maxlength="11" value="' . $formated_date .
'"';
7108 $retstring .= ($disabled ?
' disabled' :
'');
7109 $retstring .=
' onChange="dpChangeDay(\'' . $prefix .
'\',\
'' . $langs->trans(
"FormatDateShortJavaInput") .
'\');
"'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
7110 $retstring .= ' autocomplete="off
">';
7113 $retstringbuttom = '';
7115 $retstringbuttom = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
"';
7116 $base = DOL_URL_ROOT . '/core/';
7117 $retstringbuttom .= ' onClick="showDP(\
'' . $base .
'\',\
'' . $prefix .
'\',\
'' . $langs->trans(
"FormatDateShortJavaInput") .
'\',\
'' . $langs->defaultlang .
'\');
"';
7118 $retstringbuttom .= '>' . img_object($langs->trans("SelectDate
"), 'calendarday', 'class="datecallink
"') . '</button>';
7120 $retstringbuttom = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
">' . img_object($langs->trans("Disabled
"), 'calendarday', 'class="datecallink
"') . '</button>';
7122 $retstring = $retstringbuttom . $retstring;
7124 $retstring .= '<input type="hidden
" id="' . $prefix . 'day
" name="' . $prefix . 'day
" value="' . $sday . '">' . "\n
";
7125 $retstring .= '<input type="hidden
" id="' . $prefix . 'month
" name="' . $prefix . 'month
" value="' . $smonth . '">' . "\n
";
7126 $retstring .= '<input type="hidden
" id="' . $prefix . 'year
" name="' . $prefix . 'year
" value="' . $syear . '">' . "\n
";
7127 } elseif ($usecalendar == 'jquery' || $usecalendar == 'html') {
7128 if (!$disabled && $usecalendar != 'html') {
7129 // Output javascript for datepicker
7130 $minYear = getDolGlobalInt('MIN_YEAR_SELECT_DATE', (idate('Y') - 100));
7131 $maxYear = getDolGlobalInt('MAX_YEAR_SELECT_DATE', (idate('Y') + 100));
7133 $retstring .= '<script nonce="' . getNonce() . '" type="text/javascript
">';
7134 $retstring .= "$(
function(){ $(
'#" . $prefix . "').datepicker({
7135 dateFormat:
'" . $langs->trans("FormatDateShortJQueryInput") . "',
7137 todayHighlight:
true,
7138 yearRange:
'" . $minYear . ":" . $maxYear . "',
";
7139 if (!empty($conf->dol_use_jmobile)) {
7141 beforeShow:
function (input, datePicker) {
7142 input.disabled =
true;
7144 onClose:
function (dateText, datePicker) {
7149 // Note: We don't need monthNames, monthNamesShort, dayNames, dayNamesShort, dayNamesMin, they are set globally on datepicker component in lib_head.js.php
7150 if (!getDolGlobalString('MAIN_POPUP_CALENDAR_ON_FOCUS')) {
7153 buttonImage:
'" . DOL_URL_ROOT . "/theme/" . dol_escape_js($conf->theme) . "/img/object_calendarday.png',
7154 buttonImageOnly:
true";
7158 $retstring .= "</script>
";
7161 // Input area to enter date manually
7162 $retstring .= '<div class="nowraponall
inline-block divfordateinput
">';
7163 $retstring .= '<input id="'.$prefix.'" name="'.$prefix.'" type="text
" class="maxwidthdate center
" maxlength="11
" value="'.$formated_date.'"';
7164 $retstring .= ($disabled ? ' disabled' : '');
7165 $retstring .= ($placeholder ? ' placeholder="' . dol_escape_htmltag($placeholder) . '"' : '');
7166 $retstring .= ' onChange="dpChangeDay(\
'' .
dol_escape_js($prefix) .
'\',\
'' .
dol_escape_js($langs->trans(
"FormatDateShortJavaInput")) .
'\');
"'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
7167 $retstring .= ' autocomplete="off
">';
7171 $retstringbutton = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
">' . img_object($langs->trans("Disabled
"), 'calendarday', 'class="datecallink
"') . '</button>';
7172 $retstring = $retstringbutton . $retstring;
7175 $retstring .= '</div>';
7176 $retstring .= '<input type="hidden
" id="' . $prefix . 'day
" name="' . $prefix . 'day
" value="' . $sday . '">' . "\n
";
7177 $retstring .= '<input type="hidden
" id="' . $prefix . 'month
" name="' . $prefix . 'month
" value="' . $smonth . '">' . "\n
";
7178 $retstring .= '<input type="hidden
" id="' . $prefix . 'year
" name="' . $prefix . 'year
" value="' . $syear . '">' . "\n
";
7180 $retstring .= "Bad value of MAIN_POPUP_CALENDAR
";
7183 // Show date with combo selects
7185 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50imp
" id="' . $prefix . 'day
" name="' . $prefix . 'day
">';
7187 if ($emptydate || $set_time == -1) {
7188 $retstring .= '<option value="0
" selected> </option>';
7191 for ($day = 1; $day <= 31; $day++) {
7192 $retstring .= '<option value="' . $day . '"' . ($day == $sday ? ' selected' : '') . '>' . $day . '</option>';
7195 $retstring .= "</select>
";
7197 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'month
" name="' . $prefix . 'month
">';
7198 if ($emptydate || $set_time == -1) {
7199 $retstring .= '<option value="0
" selected> </option>';
7203 for ($month = 1; $month <= 12; $month++) {
7204 $retstring .= '<option value="' . $month . '"' . ($month == $smonth ? ' selected' : '') . '>';
7205 $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b
");
7206 $retstring .= "</option>
";
7208 $retstring .= "</select>
";
7211 if ($emptydate || $set_time == -1) {
7212 $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 . '">';
7214 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'year
" name="' . $prefix . 'year
">';
7216 $syear = (int) $syear;
7217 for ($year = $syear - 10; $year < (int) $syear + 10; $year++) {
7218 $retstring .= '<option value="' . $year . '"' . ($year == $syear ? ' selected' : '') . '>' . $year . '</option>';
7220 $retstring .= "</select>\n
";
7226 $retstring .= (($h == 2 || $h == 4) ? '<br>' : ' ');
7227 $retstring .= '<span class="nowraponall
">';
7233 if ($openinghours != '') {
7234 $openinghours = explode(',', $openinghours);
7235 $hourstart = $openinghours[0];
7236 $hourend = $openinghours[1];
7237 if ($hourend < $hourstart) {
7238 $hourend = $hourstart;
7242 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50
' . ($fullday ? $fullday . 'hour
' : '') . '" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
">';
7244 $retstring .= '<option value="-1
"> </option>';
7246 for ($hour = $hourstart; $hour < $hourend; $hour++) {
7247 if (strlen($hour) < 2) {
7248 $hour = "0
" . $hour;
7250 $retstring .= '<option value="' . $hour . '"' . (($hour == $shour) ? ' selected' : '') . '>' . $hour;
7251 //$retstring .= (empty($conf->dol_optimize_smallscreen) ? '' : 'H');
7252 $retstring .= '</option>';
7254 $retstring .= '</select>';
7255 //if ($m && empty($conf->dol_optimize_smallscreen)) $retstring .= ":
";
7263 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50
' . ($fullday ? $fullday . 'min
' : '') . '" id="' . $prefix . 'min
" name="' . $prefix . 'min
">';
7265 $retstring .= '<option value="-1
"> </option>';
7267 for ($min = 0; $min < 60; $min += $stepminutes) {
7268 $min_str = sprintf("%02d
", $min);
7269 $retstring .= '<option value="' . $min_str . '"' . (($min_str == $smin) ? ' selected' : '') . '>' . $min_str . '</option>';
7271 $retstring .= '</select>';
7273 $retstring .= '<input type="hidden
" name="' . $prefix . 'sec
" value="' . $ssec . '">';
7277 $retstring .= '</span>';
7281 if (!empty($conf->use_javascript_ajax) && $addnowlink) {
7282 // Script which will be inserted in the onClick of the "Now
" link
7283 $reset_scripts = "";
7284 if ($addnowlink == 2) { // local computer time
7285 // pad add leading 0 on numbers
7286 $reset_scripts .= "Number.prototype.pad =
function(size) {
7287 var s = String(
this);
7288 while (s.length < (size || 2)) {s =
'0' + s;}
7291 var d =
new Date();
";
7294 // Generate the date part, depending on the use or not of the javascript calendar
7295 if ($addnowlink == 1) { // server time expressed in user time setup
7296 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
7297 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
7298 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
7299 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
7300 } elseif ($addnowlink == 2) {
7301 /* Disabled because the output does not use the string format defined by FormatDateShort key to forge the value into #prefix.
7302 * This break application for foreign languages.
7303 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(d.toLocaleDateString(\''.str_replace('_', '-', $langs->defaultlang).'\'));';
7304 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(d.getDate().pad());';
7305 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(parseInt(d.getMonth().pad()) + 1);';
7306 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(d.getFullYear());';
7308 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
7309 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
7310 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
7311 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
7313 /*if ($usecalendar == "eldy
")
7315 $base=DOL_URL_ROOT.'/core/';
7316 $reset_scripts .= 'resetDP(\''.$base.'\',\''.$prefix.'\',\''.$langs->trans("FormatDateShortJavaInput
").'\',\''.$langs->defaultlang.'\');';
7320 $reset_scripts .= 'this.form.elements[\''.$prefix.'day\'].value=formatDate(new Date(), \'d\'); ';
7321 $reset_scripts .= 'this.form.elements[\''.$prefix.'month\'].value=formatDate(new Date(), \'M\'); ';
7322 $reset_scripts .= 'this.form.elements[\''.$prefix.'year\'].value=formatDate(new Date(), \'yyyy\'); ';
7324 // Update the hour part
7327 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7329 //$reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); ';
7330 if ($addnowlink == 1) {
7331 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
7332 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
7333 } elseif ($addnowlink == 2) {
7334 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(d.getHours().pad());';
7335 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
7339 $reset_scripts .= ' } ';
7342 // Update the minute part
7345 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7347 //$reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); ';
7348 if ($addnowlink == 1) {
7349 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
7350 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
7351 } elseif ($addnowlink == 2) {
7352 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(d.getMinutes().pad());';
7353 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
7356 $reset_scripts .= ' } ';
7359 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
7360 if ($reset_scripts && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
7361 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonNow
" type="button" name="_useless
" value="now
" onClick="' . $reset_scripts . '">';
7362 $retstring .= $langs->trans("Now
");
7363 $retstring .= '</button> ';
7367 // Add a "Plus one hour
" link
7368 if ($conf->use_javascript_ajax && $addplusone) {
7369 // Script which will be inserted in the onClick of the "Add plusone
" link
7370 $reset_scripts = "";
7372 // Generate the date part, depending on the use or not of the javascript calendar
7373 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'dayinputnoreduce', 'tzuserrel') . '\');';
7374 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
7375 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
7376 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
7377 // Update the hour part
7380 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7382 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
7384 $reset_scripts .= ' } ';
7387 // Update the minute part
7390 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7392 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
7394 $reset_scripts .= ' } ';
7397 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
7398 if ($reset_scripts && empty($conf->dol_optimize_smallscreen)) {
7399 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonPlusOne
" type="button" name="_useless2
" value="plusone
" onClick="' . $reset_scripts . '">';
7400 $retstring .= $langs->trans("DateStartPlusOne
");
7401 $retstring .= '</button> ';
7405 // Add a link to set data
7406 if ($conf->use_javascript_ajax && !empty($adddateof)) {
7407 if (!is_array($adddateof)) {
7408 $arrayofdateof = array(array('adddateof' => $adddateof, 'labeladddateof' => $labeladddateof));
7410 $arrayofdateof = $adddateof;
7412 foreach ($arrayofdateof as $valuedateof) {
7413 $tmpadddateof = empty($valuedateof['adddateof']) ? 0 : $valuedateof['adddateof'];
7414 $tmplabeladddateof = empty($valuedateof['labeladddateof']) ? '' : $valuedateof['labeladddateof'];
7415 $tmparray = dol_getdate($tmpadddateof);
7416 if (empty($tmplabeladddateof)) {
7417 $tmplabeladddateof = $langs->trans("DateInvoice
");
7419 $reset_scripts = 'console.log(\'Click on now link\'); ';
7420 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(\''.dol_print_date($tmpadddateof, 'dayinputnoreduce').'\');';
7421 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(\''.$tmparray['mday'].'\');';
7422 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(\''.$tmparray['mon'].'\');';
7423 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(\''.$tmparray['year'].'\');';
7424 $retstring .= ' - <button class="dpInvisibleButtons datenowlink
" id="dateofinvoice
" type="button" name="_dateofinvoice
" value="now
" onclick="'.$reset_scripts.'">'.$tmplabeladddateof.'</button>';
7439 public function selectTypeDuration($prefix, $selected = 'i', $excludetypes = array())
7443 $TDurationTypes = array(
7444 'y' => $langs->trans('Years'),
7445 'm' => $langs->trans('Month'),
7446 'w' => $langs->trans('Weeks'),
7447 'd' => $langs->trans('Days'),
7448 'h' => $langs->trans('Hours'),
7449 'i' => $langs->trans('Minutes')
7452 // Removed undesired duration types
7453 foreach ($excludetypes as $value) {
7454 unset($TDurationTypes[$value]);
7457 $retstring = '<select class="flat minwidth75 maxwidth100
" id="select_
' . $prefix . 'type_duration
" name="' . $prefix . 'type_duration
">';
7458 foreach ($TDurationTypes as $key => $typeduration) {
7459 $retstring .= '<option value="' . $key . '"';
7460 if ($key == $selected) {
7461 $retstring .= " selected
";
7463 $retstring .= ">
" . $typeduration . "</option>
";
7465 $retstring .= "</select>
";
7467 $retstring .= ajax_combobox('select_' . $prefix . 'type_duration');
7472 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
7487 public function select_duration($prefix, $iSecond = '', $disabled = 0, $typehour = 'select', $minunderhours = 0, $nooutput = 0)
7492 $retstring = '<span class="nowraponall
">';
7498 if ($iSecond != '') {
7499 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
7501 $hourSelected = convertSecondToTime($iSecond, 'allhour');
7502 $minSelected = convertSecondToTime($iSecond, 'min');
7505 if ($typehour == 'select') {
7506 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'hour
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . '>';
7507 for ($hour = 0; $hour < 25; $hour++) { // For a duration, we allow 24 hours
7508 $retstring .= '<option value="' . $hour . '"';
7509 if (is_numeric($hourSelected) && $hourSelected == $hour) {
7510 $retstring .= " selected
";
7512 $retstring .= ">
" . $hour . "</option>
";
7514 $retstring .= "</select>
";
7515 } elseif ($typehour == 'text' || $typehour == 'textselect') {
7516 $retstring .= '<input placeholder="' . $langs->trans('HourShort
') . '" type="number
" min="0
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputhour right
" value="' . (($hourSelected != '') ? ((int) $hourSelected) : '') . '">';
7518 return 'BadValueForParameterTypeHour';
7521 if ($typehour != 'text') {
7522 $retstring .= ' ' . $langs->trans('HourShort');
7524 $retstring .= '<span class="">:</span>';
7528 if ($minunderhours) {
7529 $retstring .= '<br>';
7531 if ($typehour != 'text') {
7532 $retstring .= '<span class="hideonsmartphone
"> </span>';
7536 if ($typehour == 'select' || $typehour == 'textselect') {
7537 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'min
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . '>';
7538 for ($min = 0; $min <= 55; $min += 5) {
7539 $retstring .= '<option value="' . $min . '"';
7540 if (is_numeric($minSelected) && $minSelected == $min) {
7541 $retstring .= ' selected';
7543 $retstring .= '>' . $min . '</option>';
7545 $retstring .= "</select>
";
7546 } elseif ($typehour == 'text') {
7547 $retstring .= '<input placeholder="' . $langs->trans('MinuteShort
') . '" type="number
" min="0
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputminute right
" value="' . (($minSelected != '') ? ((int) $minSelected) : '') . '">';
7550 if ($typehour != 'text') {
7551 $retstring .= ' ' . $langs->trans('MinuteShort');
7554 $retstring .= "</span>
";
7556 if (!empty($nooutput)) {
7584 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)
7586 global $langs, $conf;
7591 if (is_null($ajaxoptions)) {
7592 $ajaxoptions = array();
7595 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
7598 if ($selected && empty($selected_input_value)) {
7599 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
7600 $tickettmpselect = new Ticket($this->db);
7601 $tickettmpselect->fetch($selected);
7602 $selected_input_value = $tickettmpselect->ref;
7603 unset($tickettmpselect);
7607 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/ticket/ajax/tickets.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
7609 if (empty($hidelabel)) {
7610 $out .= $langs->trans("RefOrLabel
") . ' : ';
7611 } elseif ($hidelabel > 1) {
7612 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
7613 if ($hidelabel == 2) {
7614 $out .= img_picto($langs->trans("Search
"), 'search');
7617 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
7618 if ($hidelabel == 3) {
7619 $out .= img_picto($langs->trans("Search
"), 'search');
7622 $out .= $this->selectTicketsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
7625 if (empty($nooutput)) {
7650 public function selectTicketsList($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
7652 global $langs, $conf;
7655 $outarray = array();
7657 $selectFields = " p.rowid, p.ref, p.message
";
7660 $sql .= $selectFields;
7661 $sql .= " FROM
" . $this->db->prefix() . "ticket as p
";
7662 $sql .= ' WHERE p.entity IN (' . getEntity('ticket') . ')';
7664 // Add criteria on ref/label
7665 if ($filterkey != '') {
7667 $prefix = !getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
7668 // For natural search
7669 $search_crit = explode(' ', $filterkey);
7671 if (count($search_crit) > 1) {
7674 foreach ($search_crit as $crit) {
7678 $sql .= "(p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%' OR p.subject LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
7682 if (count($search_crit) > 1) {
7688 $sql .= $this->db->plimit($limit, 0);
7690 // Build output string
7692 $result = $this->db->query($sql);
7694 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
7695 require_once DOL_DOCUMENT_ROOT . '/core/lib/ticket.lib.php';
7697 $num = $this->db->num_rows($result);
7702 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
7703 $out .= ajax_combobox($htmlname, $events, $conf->global->TICKET_USE_SEARCH_TO_SELECT);
7706 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
7709 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
7710 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
7711 if (getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
7712 if ($showempty && !is_numeric($showempty)) {
7713 $textifempty = $langs->trans($showempty);
7715 $textifempty .= $langs->trans("All
");
7718 if ($showempty && !is_numeric($showempty)) {
7719 $textifempty = $langs->trans($showempty);
7723 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
7727 while ($num && $i < $num) {
7730 $objp = $this->db->fetch_object($result);
7732 $this->constructTicketListOption($objp, $opt, $optJson, $selected, $filterkey);
7734 // "key
" value of json key array is used by jQuery automatically as selected value
7735 // "label
" value of json key array is used by jQuery automatically as text for combo box
7737 array_push($outarray, $optJson);
7742 $out .= '</select>';
7744 $this->db->free($result);
7746 if (empty($outputmode)) {
7751 dol_print_error($this->db);
7768 protected function constructTicketListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
7774 $outkey = $objp->rowid;
7775 $outref = $objp->ref;
7776 $outtype = $objp->fk_product_type;
7778 $opt = '<option value="
' . $objp->rowid . '"';
7779 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
7782 $objRef = $objp->ref;
7783 if (!empty($filterkey) && $filterkey != '') {
7784 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1);
7787 $opt .= "</option>\n
";
7788 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
7810 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)
7812 global $langs, $conf;
7817 if (is_null($ajaxoptions)) {
7818 $ajaxoptions = array();
7821 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
7824 if ($selected && empty($selected_input_value)) {
7825 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
7826 $projecttmpselect = new Project($this->db);
7827 $projecttmpselect->fetch($selected);
7828 $selected_input_value = $projecttmpselect->ref;
7829 unset($projecttmpselect);
7833 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/projet/ajax/projects.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
7835 if (empty($hidelabel)) {
7836 $out .= $langs->trans("RefOrLabel
") . ' : ';
7837 } elseif ($hidelabel > 1) {
7838 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
7839 if ($hidelabel == 2) {
7840 $out .= img_picto($langs->trans("Search
"), 'search');
7843 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
7844 if ($hidelabel == 3) {
7845 $out .= img_picto($langs->trans("Search
"), 'search');
7848 $out .= $this->selectProjectsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
7851 if (empty($nooutput)) {
7875 public function selectProjectsList($selected = '', $htmlname = 'projectid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
7877 global $langs, $conf;
7880 $outarray = array();
7882 $selectFields = " p.rowid, p.ref
";
7885 $sql .= $selectFields;
7886 $sql .= " FROM
" . $this->db->prefix() . "projet as p
";
7887 $sql .= ' WHERE p.entity IN (' . getEntity('project') . ')';
7889 // Add criteria on ref/label
7890 if ($filterkey != '') {
7892 $prefix = !getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
7893 // For natural search
7894 $search_crit = explode(' ', $filterkey);
7896 if (count($search_crit) > 1) {
7899 foreach ($search_crit as $crit) {
7903 $sql .= "p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
7907 if (count($search_crit) > 1) {
7913 $sql .= $this->db->plimit($limit, 0);
7915 // Build output string
7917 $result = $this->db->query($sql);
7919 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
7920 require_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php';
7922 $num = $this->db->num_rows($result);
7927 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
7928 $out .= ajax_combobox($htmlname, $events, $conf->global->PROJECT_USE_SEARCH_TO_SELECT);
7931 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
7934 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
7935 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
7936 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
7937 if ($showempty && !is_numeric($showempty)) {
7938 $textifempty = $langs->trans($showempty);
7940 $textifempty .= $langs->trans("All
");
7943 if ($showempty && !is_numeric($showempty)) {
7944 $textifempty = $langs->trans($showempty);
7948 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
7952 while ($num && $i < $num) {
7955 $objp = $this->db->fetch_object($result);
7957 $this->constructProjectListOption($objp, $opt, $optJson, $selected, $filterkey);
7959 // "key
" value of json key array is used by jQuery automatically as selected value
7960 // "label
" value of json key array is used by jQuery automatically as text for combo box
7962 array_push($outarray, $optJson);
7967 $out .= '</select>';
7969 $this->db->free($result);
7971 if (empty($outputmode)) {
7976 dol_print_error($this->db);
7993 protected function constructProjectListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
7999 $label = $objp->label;
8001 $outkey = $objp->rowid;
8002 $outref = $objp->ref;
8003 $outlabel = $objp->label;
8004 $outtype = $objp->fk_product_type;
8006 $opt = '<option value="
' . $objp->rowid . '"';
8007 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
8010 $objRef = $objp->ref;
8011 if (!empty($filterkey) && $filterkey != '') {
8012 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1);
8015 $opt .= "</option>\n
";
8016 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
8039 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)
8041 global $langs, $conf;
8046 if (is_null($ajaxoptions)) {
8047 $ajaxoptions = array();
8050 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
8053 if ($selected && empty($selected_input_value)) {
8054 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
8055 $adherenttmpselect = new Adherent($this->db);
8056 $adherenttmpselect->fetch($selected);
8057 $selected_input_value = $adherenttmpselect->ref;
8058 unset($adherenttmpselect);
8063 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/adherents/ajax/adherents.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
8065 if (empty($hidelabel)) {
8066 $out .= $langs->trans("RefOrLabel
") . ' : ';
8067 } elseif ($hidelabel > 1) {
8068 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
8069 if ($hidelabel == 2) {
8070 $out .= img_picto($langs->trans("Search
"), 'search');
8073 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
8074 if ($hidelabel == 3) {
8075 $out .= img_picto($langs->trans("Search
"), 'search');
8080 $out .= $this->selectMembersList($selected, $htmlname, $filtertype, $limit, $filterkey, $status, 0, $showempty, $forcecombo, $morecss);
8083 if (empty($nooutput)) {
8107 public function selectMembersList($selected = '', $htmlname = 'adherentid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
8109 global $langs, $conf;
8112 $outarray = array();
8114 $selectFields = " p.rowid, p.ref, p.firstname, p.lastname, p.fk_adherent_type
";
8117 $sql .= $selectFields;
8118 $sql .= " FROM
" . $this->db->prefix() . "adherent as p
";
8119 $sql .= ' WHERE p.entity IN (' . getEntity('adherent') . ')';
8121 // Add criteria on ref/label
8122 if ($filterkey != '') {
8124 $prefix = !getDolGlobalString('MEMBER_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
8125 // For natural search
8126 $search_crit = explode(' ', $filterkey);
8128 if (count($search_crit) > 1) {
8131 foreach ($search_crit as $crit) {
8135 $sql .= "(p.firstname LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
8136 $sql .= " OR p.lastname LIKE
'" . $this->db->escape($prefix . $crit) . "%')
";
8139 if (count($search_crit) > 1) {
8144 if ($status != -1) {
8145 $sql .= ' AND statut = ' . ((int) $status);
8147 $sql .= $this->db->plimit($limit, 0);
8149 // Build output string
8151 $result = $this->db->query($sql);
8153 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
8154 require_once DOL_DOCUMENT_ROOT . '/core/lib/member.lib.php';
8156 $num = $this->db->num_rows($result);
8161 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
8162 $out .= ajax_combobox($htmlname, $events, getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT') ? $conf->global->PROJECT_USE_SEARCH_TO_SELECT : '');
8165 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
8168 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
8169 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
8170 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
8171 if ($showempty && !is_numeric($showempty)) {
8172 $textifempty = $langs->trans($showempty);
8174 $textifempty .= $langs->trans("All
");
8177 if ($showempty && !is_numeric($showempty)) {
8178 $textifempty = $langs->trans($showempty);
8182 $out .= '<option value="-1
" selected>' . $textifempty . '</option>';
8186 while ($num && $i < $num) {
8189 $objp = $this->db->fetch_object($result);
8191 $this->constructMemberListOption($objp, $opt, $optJson, $selected, $filterkey);
8194 // "key
" value of json key array is used by jQuery automatically as selected value
8195 // "label
" value of json key array is used by jQuery automatically as text for combo box
8197 array_push($outarray, $optJson);
8202 $out .= '</select>';
8204 $this->db->free($result);
8206 if (empty($outputmode)) {
8211 dol_print_error($this->db);
8228 protected function constructMemberListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
8234 $outkey = $objp->rowid;
8235 $outlabel = dolGetFirstLastname($objp->firstname, $objp->lastname);
8236 $outtype = $objp->fk_adherent_type;
8238 $opt = '<option value="
' . $objp->rowid . '"';
8239 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
8241 if (!empty($filterkey) && $filterkey != '') {
8242 $outlabel = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $outlabel, 1);
8245 $opt .= "</option>\n
";
8247 $optJson = array('key' => $outkey, 'value' => $outlabel, 'type' => $outtype);
8270 public function selectForForms($objectdesc, $htmlname, $preSelectedValue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $disabled = 0, $selected_input_value = '', $objectfield = '')
8272 global $conf, $extrafields, $user;
8274 //var_dump($objectdesc); debug_print_backtrace();
8276 $objectdescorig = $objectdesc;
8278 $InfoFieldList = array();
8280 $filter = ''; // Ensure filter has value (for static analysis)
8281 $sortfield = ''; // Ensure filter has value (for static analysis)
8283 if ($objectfield) { // We must retrieve the objectdesc from the field or extrafield
8284 // Example: $objectfield = 'product:options_package' or 'myobject@mymodule:options_myfield'
8285 $tmparray = explode(':', $objectfield);
8287 // Get instance of object from $element
8288 $objectforfieldstmp = fetchObjectByElement(0, strtolower($tmparray[0]));
8290 if (is_object($objectforfieldstmp)) {
8294 if (preg_match('/^options_(.*)$/', $tmparray[1], $reg)) {
8295 // For a property in extrafields
8297 // fetch optionals attributes and labels
8298 $extrafields->fetch_name_optionals_label($objectforfieldstmp->table_element);
8300 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element]['type'][$key]) && $extrafields->attributes[$objectforfieldstmp->table_element]['type'][$key] == 'link') {
8301 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element]['param'][$key]['options'])) {
8302 $tmpextrafields = array_keys($extrafields->attributes[$objectforfieldstmp->table_element]['param'][$key]['options']);
8303 $objectdesc = $tmpextrafields[0];
8307 // For a property in ->fields
8308 if (array_key_exists($tmparray[1], $objectforfieldstmp->fields)) {
8309 $objectdesc = $objectforfieldstmp->fields[$tmparray[1]]['type'];
8310 $objectdesc = preg_replace('/^integer[^:]*:/', '', $objectdesc);
8317 // Example of value for $objectdesc:
8318 // Bom:bom/class/bom.class.php:0:t.status=1
8319 // Bom:bom/class/bom.class.php:0:t.status=1:ref
8320 // Bom:bom/class/bom.class.php:0:(t.status:=:1) OR (t.field2:=:2):ref
8321 $InfoFieldList = explode(":
", $objectdesc, 4);
8322 $vartmp = (empty($InfoFieldList[3]) ? '' : $InfoFieldList[3]);
8324 if (preg_match('/^.*:(\w*)$/', $vartmp, $reg)) {
8325 $InfoFieldList[4] = $reg[1]; // take the sort field
8327 $InfoFieldList[3] = preg_replace('/:\w*$/', '', $vartmp); // take the filter field
8329 $classname = $InfoFieldList[0];
8330 $classpath = empty($InfoFieldList[1]) ? '' : $InfoFieldList[1];
8331 //$addcreatebuttonornot = empty($InfoFieldList[2]) ? 0 : $InfoFieldList[2];
8332 $filter = empty($InfoFieldList[3]) ? '' : $InfoFieldList[3];
8333 $sortfield = empty($InfoFieldList[4]) ? '' : $InfoFieldList[4];
8335 // Load object according to $id and $element
8336 $objecttmp = fetchObjectByElement(0, strtolower($InfoFieldList[0]));
8338 // Fallback to another solution to get $objecttmp
8339 if (empty($objecttmp) && !empty($classpath)) {
8340 dol_include_once($classpath);
8342 if ($classname && class_exists($classname)) {
8343 $objecttmp = new $classname($this->db);
8348 // Make some replacement in $filter. May not be used if we used the ajax mode with $objectfield. In such a case
8349 // we propagate the $objectfield and not the filter and replacement is done by the ajax/selectobject.php component.
8350 $sharedentities = (is_object($objecttmp) && property_exists($objecttmp, 'element')) ? getEntity($objecttmp->element) : strtolower($classname);
8351 $filter = str_replace(
8352 array('__ENTITY__', '__SHARED_ENTITIES__', '__USER_ID__'),
8353 array($conf->entity, $sharedentities, $user->id),
8357 if (!is_object($objecttmp)) {
8358 dol_syslog('selectForForms: Error bad setup of field objectdescorig=' . $objectdescorig.', objectfield='.$objectfield.', objectdesc='.$objectdesc, LOG_WARNING);
8359 return 'selectForForms: Error bad setup of field objectdescorig=' . $objectdescorig.', objectfield='.$objectfield.', objectdesc='.$objectdesc;
8361 '@phan-var-force CommonObject $objecttmp';
8363 //var_dump($filter);
8364 $prefixforautocompletemode = $objecttmp->element;
8365 if ($prefixforautocompletemode == 'societe') {
8366 $prefixforautocompletemode = 'company';
8368 if ($prefixforautocompletemode == 'product') {
8369 $prefixforautocompletemode = 'produit';
8371 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) . '_USE_SEARCH_TO_SELECT'; // For example COMPANY_USE_SEARCH_TO_SELECT
8373 dol_syslog(get_class($this) . "::selectForForms filter=
" . $filter, LOG_DEBUG);
8375 // Generate the combo HTML component
8377 if (!empty($conf->use_javascript_ajax) && getDolGlobalString($confkeyforautocompletemode) && !$forcecombo) {
8378 // No immediate load of all database
8381 if ($preSelectedValue && empty($selected_input_value)) {
8382 $objecttmp->fetch($preSelectedValue);
8383 $selected_input_value = ($prefixforautocompletemode == 'company' ? $objecttmp->name : $objecttmp->ref);
8385 $oldValueForShowOnCombobox = 0;
8386 foreach ($objecttmp->fields as $fieldK => $fielV) {
8387 if (empty($fielV['showoncombobox']) || empty($objecttmp->$fieldK)) {
8391 if (!$oldValueForShowOnCombobox) {
8392 $selected_input_value = '';
8395 $selected_input_value .= $oldValueForShowOnCombobox ? ' - ' : '';
8396 $selected_input_value .= $objecttmp->$fieldK;
8397 $oldValueForShowOnCombobox = empty($fielV['showoncombobox']) ? 0 : $fielV['showoncombobox'];
8401 // Set url and param to call to get json of the search results
8402 $urlforajaxcall = DOL_URL_ROOT . '/core/ajax/selectobject.php';
8403 $urloption = 'htmlname=' . urlencode($htmlname) . '&outjson=1&objectdesc=' . urlencode($objectdescorig) . '&objectfield='.urlencode($objectfield) . ($sortfield ? '&sortfield=' . urlencode($sortfield) : '');
8405 // Activate the auto complete using ajax call.
8406 $out .= ajax_autocompleter($preSelectedValue, $htmlname, $urlforajaxcall, $urloption, getDolGlobalString($confkeyforautocompletemode), 0);
8407 $out .= '<!-- force css to be higher than dialog popup --><style type="text/css
">.ui-autocomplete { z-index: 1010; }</style>';
8408 $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) . '"' : '') . ' />';
8410 // Immediate load of table record.
8411 $out .= $this->selectForFormsList($objecttmp, $htmlname, $preSelectedValue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled, $sortfield, $filter);
8438 public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $outputmode = 0, $disabled = 0, $sortfield = '', $filter = '')
8440 global $langs, $user, $hookmanager;
8442 //print "$htmlname, $preselectedvalue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, $outputmode, $disabled
";
8444 $prefixforautocompletemode = $objecttmp->element;
8445 if ($prefixforautocompletemode == 'societe') {
8446 $prefixforautocompletemode = 'company';
8448 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) . '_USE_SEARCH_TO_SELECT'; // For example COMPANY_USE_SEARCH_TO_SELECT
8450 if (!empty($objecttmp->fields)) { // For object that declare it, it is better to use declared fields (like societe, contact, ...)
8451 $tmpfieldstoshow = '';
8452 foreach ($objecttmp->fields as $key => $val) {
8453 if (! (int) dol_eval($val['enabled'], 1, 1, '1')) {
8456 if (!empty($val['showoncombobox'])) {
8457 $tmpfieldstoshow .= ($tmpfieldstoshow ? ',' : '') . 't.' . $key;
8460 if ($tmpfieldstoshow) {
8461 $fieldstoshow = $tmpfieldstoshow;
8464 // For backward compatibility
8465 $objecttmp->fields['ref'] = array('type' => 'varchar(30)', 'label' => 'Ref', 'showoncombobox' => 1);
8468 if (empty($fieldstoshow)) {
8469 if (isset($objecttmp->fields['ref'])) {
8470 $fieldstoshow = 't.ref';
8472 $langs->load("errors
");
8473 $this->error = $langs->trans("ErrorNoFieldWithAttributeShowoncombobox
");
8474 return $langs->trans('ErrorNoFieldWithAttributeShowoncombobox');
8479 $outarray = array();
8480 $tmparray = array();
8485 $sql = "SELECT t.
rowid,
" . $fieldstoshow . " FROM
" . $this->db->prefix() . $objecttmp->table_element . " as t
";
8486 if (!empty($objecttmp->isextrafieldmanaged)) {
8487 $sql .= " LEFT JOIN
" . $this->db->prefix() . $objecttmp->table_element . "_extrafields as e ON t.
rowid=e.fk_object
";
8489 if (isset($objecttmp->ismultientitymanaged)) {
8490 if (!is_numeric($objecttmp->ismultientitymanaged)) {
8491 $tmparray = explode('@', $objecttmp->ismultientitymanaged);
8492 $sql .= " INNER JOIN
" . $this->db->prefix() . $tmparray[1] . " as parenttable ON parenttable.
rowid = t.
" . $tmparray[0];
8494 if ($objecttmp->ismultientitymanaged === 'fk_soc@societe') {
8495 if (!$user->hasRight('societe', 'client', 'voir')) {
8496 $sql .= ",
" . $this->db->prefix() . "societe_commerciaux as sc
";
8501 // Add where from hooks
8502 $parameters = array(
8503 'object' => $objecttmp,
8504 'htmlname' => $htmlname,
8505 'filter' => $filter,
8506 'searchkey' => $searchkey
8509 $reshook = $hookmanager->executeHooks('selectForFormsListWhere', $parameters); // Note that $action and $object may have been modified by hook
8510 if (!empty($hookmanager->resPrint)) {
8511 $sql .= $hookmanager->resPrint;
8513 $sql .= " WHERE 1=1
";
8514 if (isset($objecttmp->ismultientitymanaged)) {
8515 if ($objecttmp->ismultientitymanaged == 1) {
8516 $sql .= " AND t.entity IN (
" . getEntity($objecttmp->table_element) . ")
";
8518 if (!is_numeric($objecttmp->ismultientitymanaged)) {
8519 $sql .= " AND parenttable.entity = t.
" . $tmparray[0];
8521 if ($objecttmp->ismultientitymanaged == 1 && !empty($user->socid)) {
8522 if ($objecttmp->element == 'societe') {
8523 $sql .= " AND t.
rowid =
" . ((int) $user->socid);
8525 $sql .= " AND t.fk_soc =
" . ((int) $user->socid);
8528 if ($objecttmp->ismultientitymanaged === 'fk_soc@societe') {
8529 if (!$user->hasRight('societe', 'client', 'voir')) {
8530 $sql .= " AND t.
rowid = sc.fk_soc AND sc.fk_user =
" . ((int) $user->id);
8534 if ($searchkey != '') {
8535 $sql .= natural_search(explode(',', $fieldstoshow), $searchkey);
8538 if ($filter) { // Syntax example "(t.
ref:like:
'SO-%') and (t.date_creation:<:
'20160101')
"
8540 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
8541 if ($errormessage) {
8542 return 'Error forging a SQL request from an universal criteria: ' . $errormessage;
8546 $sql .= $this->db->order($sortfield ? $sortfield : $fieldstoshow, "ASC
");
8547 //$sql.=$this->db->plimit($limit, 0);
8550 // Build output string
8551 $resql = $this->db->query($sql);
8553 // Construct $out and $outarray
8554 $out .= '<select id="' . $htmlname . '" class="flat minwidth100
' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled="disabled"' : '') . ($moreparams ? ' ' . $moreparams : '') . ' name="' . $htmlname . '">' . "\n
";
8556 // Warning: Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'. Seems it is no more true with selec2 v4
8557 $textifempty = ' ';
8559 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
8560 if (getDolGlobalInt($confkeyforautocompletemode)) {
8561 if ($showempty && !is_numeric($showempty)) {
8562 $textifempty = $langs->trans($showempty);
8564 $textifempty .= $langs->trans("All
");
8568 $out .= '<option value="-1
">' . $textifempty . '</option>' . "\n
";
8571 $num = $this->db->num_rows($resql);
8575 $obj = $this->db->fetch_object($resql);
8578 $tmparray = explode(',', $fieldstoshow);
8579 $oldvalueforshowoncombobox = 0;
8580 foreach ($tmparray as $key => $val) {
8581 $val = preg_replace('/t\./', '', $val);
8582 $label .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val]['showoncombobox'] ? ' - ' : ' ') : '');
8583 $labelhtml .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val]['showoncombobox'] ? ' - ' : ' ') : '');
8584 $label .= $obj->$val;
8585 $labelhtml .= $obj->$val;
8587 $oldvalueforshowoncombobox = empty($objecttmp->fields[$val]['showoncombobox']) ? 0 : $objecttmp->fields[$val]['showoncombobox'];
8589 if (empty($outputmode)) {
8590 if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) {
8591 $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>';
8593 $out .= '<option value="' . $obj->rowid . '" data-html="' . dol_escape_htmltag($labelhtml, 0, 0, '', 0, 1) . '">' . dol_escape_htmltag($label, 0, 0, '', 0, 1) . '</option>';
8596 array_push($outarray, array('key' => $obj->rowid, 'value' => $label, 'label' => $label));
8600 if (($i % 10) == 0) {
8606 $out .= '</select>' . "\n
";
8609 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
8610 $out .= ajax_combobox($htmlname, array(), getDolGlobalInt($confkeyforautocompletemode, 0));
8613 dol_print_error($this->db);
8616 $this->result = array('nbofelement' => $num);
8648 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)
8650 global $conf, $langs;
8652 // Do we want a multiselect ?
8654 //if (preg_match('/^multi/',$htmlname)) $jsbeautify = 1;
8657 if ($value_as_key) {
8658 $array = array_combine($array, $array);
8661 '@phan-var-force array{label:string,data-html:string,disable?:int<0,1>,css?:string} $array'; // Array combine breaks information
8665 if ($addjscombo < 0) {
8666 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
8672 $idname = str_replace(array('[', ']'), array('', ''), $htmlname);
8673 $out .= '<select id="
' . preg_replace('/^\./
', '', $idname) . '" ' . ($disabled ? 'disabled="disabled" ' : '') . 'class="flat
' . (preg_replace('/^\./
', '', $htmlname)) . ($morecss ? ' ' . $morecss : '') . ' selectformat
"';
8674 $out .= ' name="' . preg_replace('/^\./
', '', $htmlname) . '" ' . ($moreparam ? $moreparam : '');
8678 $textforempty = ' ';
8679 if (!empty($conf->use_javascript_ajax)) {
8680 $textforempty = ' '; // If we use ajaxcombo, we need here to avoid to have an empty element that is too small.
8682 if (!is_numeric($show_empty)) {
8683 $textforempty = $show_empty;
8685 $out .= '<option class="optiongrey
" ' . ($moreparamonempty ? $moreparamonempty . ' ' : '') . 'value="' . (((int) $show_empty) < 0 ? $show_empty : -1) . '"' . ($id == $show_empty ? ' selected' : '') . '>' . $textforempty . '</option>' . "\n
";
8687 if (is_array($array)) {
8690 foreach ($array as $key => $value) {
8691 if (!is_array($value)) {
8692 $array[$key] = $langs->trans($value);
8694 $array[$key]['label'] = $langs->trans($value['label']);
8699 if ($sort == 'ASC') {
8701 } elseif ($sort == 'DESC') {
8705 foreach ($array as $key => $tmpvalue) {
8706 if (is_array($tmpvalue)) {
8707 $value = $tmpvalue['label'];
8708 //$valuehtml = empty($tmpvalue['data-html']) ? $value : $tmpvalue['data-html'];
8709 $disabled = empty($tmpvalue['disabled']) ? '' : ' disabled';
8710 $style = empty($tmpvalue['css']) ? '' : ' class="' . $tmpvalue['css
'] . '"';
8713 //$valuehtml = $tmpvalue;
8717 if (!empty($disablebademail)) {
8718 if (($disablebademail == 1 && !preg_match('/<.+@.+>/', $value))
8719 || ($disablebademail == 2 && preg_match('/---/', $value))) {
8720 $disabled = ' disabled';
8721 $style = ' class="warning
"';
8724 if ($key_in_label) {
8725 if (empty($nohtmlescape)) {
8726 $selectOptionValue = dol_escape_htmltag($key . ' - ' . ($maxlen ? dol_trunc($value, $maxlen) : $value));
8728 $selectOptionValue = $key . ' - ' . ($maxlen ? dol_trunc($value, $maxlen) : $value);
8731 if (empty($nohtmlescape)) {
8732 $selectOptionValue = dol_escape_htmltag($maxlen ? dol_trunc($value, $maxlen) : $value);
8734 $selectOptionValue = $maxlen ? dol_trunc($value, $maxlen) : $value;
8736 if ($value == '' || $value == '-') {
8737 $selectOptionValue = ' ';
8740 $out .= '<option value="' . $key . '"';
8741 $out .= $style . $disabled;
8742 if (is_array($id)) {
8743 if (in_array($key, $id) && !$disabled) {
8744 $out .= ' selected'; // To preselect a value
8747 $id = (string) $id; // if $id = 0, then $id = '0'
8748 if ($id != '' && ($id == $key || ($id == 'ifone' && count($array) == 1)) && !$disabled) {
8749 $out .= ' selected'; // To preselect a value
8752 if (!empty($nohtmlescape)) { // deprecated. Use instead the key 'data-html' into input $array, managed at next step to use HTML content.
8753 $out .= ' data-html="' . dol_escape_htmltag($selectOptionValue) . '"';
8756 if (is_array($tmpvalue)) {
8757 foreach ($tmpvalue as $keyforvalue => $valueforvalue) {
8758 if (preg_match('/^data-/', $keyforvalue)) { // The best solution if you want to use HTML values into the list is to use data-html.
8759 $out .= ' '.dol_escape_htmltag($keyforvalue).'="'.dol_escape_htmltag($valueforvalue).'"';
8764 $out .= $selectOptionValue;
8765 $out .= "</option>\n
";
8768 $out .= "</select>
";
8770 // Add code for jquery to use multiselect
8771 if ($addjscombo && $jsbeautify) {
8772 // Enhance with select2
8773 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
8774 $out .= ajax_combobox($idname, array(), 0, 0, 'resolve', (((int) $show_empty) < 0 ? (string) $show_empty : '-1'), $morecss);
8798 public static function selectArrayAjax($htmlname, $url, $id = '', $moreparam = '', $moreparamtourl = '', $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0)
8800 global $conf, $langs;
8801 global $delayedhtmlcontent; // Will be used later outside of this function
8803 // TODO Use an internal dolibarr component instead of select2
8804 if (!getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') && !defined('REQUIRE_JQUERY_MULTISELECT')) {
8808 $out = '<select type="text
" class="' . $htmlname . ($morecss ? ' ' . $morecss : '') . '" ' . ($moreparam ? $moreparam . ' ' : '') . 'name="' . $htmlname . '"></select>';
8811 if (!empty($conf->use_javascript_ajax)) {
8812 $tmpplugin = 'select2';
8813 $outdelayed = "\n
" . '<!-- JS CODE TO ENABLE ' . $tmpplugin . ' for id ' . $htmlname . ' -->
8814 <script nonce="' . getNonce() . '">
8815 $(document).ready(function () {
8817 ' . ($callurlonselect ? 'var saveRemoteData = [];' : '') . '
8819 $(".
' . $htmlname . '").select2({
8822 url: "' . $url . '",
8825 data: function (params) {
8827 q: params.term, // search term
8831 processResults: function (data) {
8832 // parse the results into the format expected by Select2.
8833 // since we are using custom formatting functions we do not need to alter the remote JSON data
8834 //console.log(data);
8835 saveRemoteData = data;
8836 /* format json result for select2 */
8838 $.each( data, function( key, value ) {
8839 result.push({id: key, text: value.text});
8841 //return {results:[{id:\'none\', text:\'aa\'}, {id:\'rrr\', text:\'Red\'},{id:\'bbb\', text:\'Search a into projects\'}], more:false}
8842 //console.log(result);
8843 return {results: result, more: false}
8847 language: select2arrayoflanguage,
8848 containerCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag */
8849 placeholder:
"' . dol_escape_js($placeholder) . '",
8850 escapeMarkup: function (markup) {
return markup; },
8851 minimumInputLength:
' . ((int) $minimumInputLength) . ',
8852 formatResult:
function (result, container, query, escapeMarkup) {
8853 return escapeMarkup(result.text);
8857 ' . ($callurlonselect ? '
8859 $(
".' . $htmlname . '").change(
function() {
8860 var selected = $(
".' . $htmlname . '").val();
8861 console.log(
"We select in selectArrayAjax the entry "+selected)
8862 $(
".' . $htmlname . '").val(
"");
8863 $.each( saveRemoteData,
function( key, value ) {
8864 if (key == selected)
8866 console.log(
"selectArrayAjax - Do a redirect to "+value.url)
8867 location.assign(value.url);
8876 if ($acceptdelayedhtml) {
8877 $delayedhtmlcontent .= $outdelayed;
8879 $out .= $outdelayed;
8903 public static function selectArrayFilter($htmlname, $array, $id = '
', $moreparam = '', $disableFiltering = 0, $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0, $textfortitle = '')
8905 global $conf, $langs;
8906 global $delayedhtmlcontent; // Will be used later outside of this function
8908 // TODO Use an internal dolibarr component instead of select2
8909 if (!getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT
') && !defined('REQUIRE_JQUERY_MULTISELECT
')) {
8913 $out = '<select
type=
"text"'.($textfortitle ? ' title=
"'.dol_escape_htmltag($textfortitle).'"' : '').' id=
"'.$htmlname.'" class=
"'.$htmlname.($morecss ? ' ' . $morecss : '').'"'.($moreparam ? ' '.$moreparam : '').' name=
"'.$htmlname.'"><option></option></select>
';
8915 $formattedarrayresult = array();
8917 foreach ($array as $key => $value) {
8918 $o = new stdClass();
8920 $o->text = $value['text
'];
8921 $o->url = $value['url
'];
8922 $formattedarrayresult[] = $o;
8926 if (!empty($conf->use_javascript_ajax)) {
8927 $tmpplugin = 'select2
';
8928 $outdelayed = "\n" . '<!-- JS CODE TO ENABLE
' . $tmpplugin . ' for id ' . $htmlname . ' -->
8929 <script nonce=
"' . getNonce() . '">
8930 $(document).ready(
function () {
8931 var data =
' . json_encode($formattedarrayresult) . ';
8933 ' . ($callurlonselect ? 'var saveRemoteData =
' . json_encode($array) . ';
' : '') . '
8935 $(
".' . $htmlname . '").select2({
8937 language: select2arrayoflanguage,
8938 containerCssClass: \
':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag */
8940 escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
8941 minimumInputLength: ' . $minimumInputLength .
',
8942 formatResult: function (result, container, query, escapeMarkup) {
8943 return escapeMarkup(result.text);
8945 matcher: function (params, data) {
8947 if(! data.id) return null;';
8949 if ($callurlonselect) {
8953 var urlBase = data.url;
8954 var separ = urlBase.indexOf("?") >= 0 ? "&" : "?";
8955 /* console.log("params.term="+params.term); */
8956 /* console.log("params.term encoded="+encodeURIComponent(params.term)); */
8957 saveRemoteData[data.id].url = urlBase + separ + "search_all=" + encodeURIComponent(params.term.replace(/\"/g, ""));';
8960 if (!$disableFiltering) {
8963 if(data.text.match(new RegExp(params.term))) {
8978 ' . ($callurlonselect ?
'
8979 /* Code to execute a GET when we select a value */
8980 $(".' . $htmlname .
'").change(function() {
8981 var selected = $(".' . $htmlname .
'").val();
8982 console.log("We select "+selected)
8984 $(".' . $htmlname .
'").val(""); /* reset visible combo value */
8985 $.each( saveRemoteData, function( key, value ) {
8986 if (key == selected)
8988 console.log("selectArrayFilter - Do a redirect to "+value.url)
8989 location.assign(value.url);
8998 if ($acceptdelayedhtml) {
8999 $delayedhtmlcontent .= $outdelayed;
9001 $out .= $outdelayed;
9024 public static function multiselectarray($htmlname, $array, $selected = array(), $key_in_label = 0, $value_as_key = 0, $morecss =
'', $translate = 0, $width = 0, $moreattrib =
'', $elemtype =
'', $placeholder =
'', $addjscombo = -1)
9026 global $conf, $langs;
9030 if ($addjscombo < 0) {
9038 $useenhancedmultiselect = 0;
9039 if (!empty($conf->use_javascript_ajax) && !defined(
'MAIN_DO_NOT_USE_JQUERY_MULTISELECT') && (
getDolGlobalString(
'MAIN_USE_JQUERY_MULTISELECT') || defined(
'REQUIRE_JQUERY_MULTISELECT'))) {
9041 $useenhancedmultiselect = 1;
9048 $out .=
'<input type="hidden" name="'.$htmlname.
'_multiselect" value="1">';
9050 $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";
9051 if (is_array($array) && !empty($array)) {
9052 if ($value_as_key) {
9053 $array = array_combine($array, $array);
9056 if (!empty($array)) {
9057 foreach ($array as $key => $value) {
9063 if (is_array($value) && array_key_exists(
'id', $value) && array_key_exists(
'label', $value)) {
9064 $tmpkey = $value[
'id'];
9065 $tmpvalue = empty($value[
'label']) ?
'' : $value[
'label'];
9066 $tmpcolor = empty($value[
'color']) ?
'' : $value[
'color'];
9067 $tmppicto = empty($value[
'picto']) ?
'' : $value[
'picto'];
9068 $tmplabelhtml = empty($value[
'labelhtml']) ? (empty($value[
'data-html']) ?
'' : $value[
'data-html']): $value[
'labelhtml'];
9070 $newval = ($translate ? $langs->trans($tmpvalue) : $tmpvalue);
9071 $newval = ($key_in_label ? $tmpkey .
' - ' . $newval : $newval);
9073 $out .=
'<option value="' . $tmpkey .
'"';
9074 if (is_array($selected) && !empty($selected) && in_array((
string) $tmpkey, $selected) && ((string) $tmpkey !=
'')) {
9075 $out .=
' selected';
9077 if (!empty($tmplabelhtml)) {
9080 $tmplabelhtml = ($tmppicto ?
img_picto(
'', $tmppicto,
'class="pictofixedwidth" style="color: #' . $tmpcolor .
'"') :
'') . $newval;
9085 $out .=
'</option>' .
"\n";
9089 $out .=
'</select>' .
"\n";
9092 if (!empty($conf->use_javascript_ajax) &&
getDolGlobalString(
'MAIN_USE_JQUERY_MULTISELECT') || defined(
'REQUIRE_JQUERY_MULTISELECT')) {
9093 $out .=
"\n" .
'<!-- JS CODE TO ENABLE select for id ' . $htmlname .
', addjscombo=' . $addjscombo .
' -->';
9094 $out .=
"\n" .
'<script nonce="' .
getNonce() .
'">' .
"\n";
9095 if ($addjscombo == 1) {
9096 $tmpplugin = !
getDolGlobalString(
'MAIN_USE_JQUERY_MULTISELECT') ? constant(
'REQUIRE_JQUERY_MULTISELECT') : $conf->global->MAIN_USE_JQUERY_MULTISELECT;
9097 $out .=
'function formatResult(record, container) {' .
"\n";
9100 $out .=
' if ($(record.element).attr("data-html") != undefined && typeof htmlEntityDecodeJs === "function") {';
9102 $out .=
' return htmlEntityDecodeJs($(record.element).attr("data-html"));';
9104 $out .=
' return record.text;';
9106 $out .=
'function formatSelection(record) {' .
"\n";
9107 if ($elemtype ==
'category') {
9108 $out .=
'return \'<span><img src="' . DOL_URL_ROOT .
'/theme/eldy/img/object_category.png"> \'+record.text+\'</span>\';';
9110 $out .=
'return record.text;';
9113 $out .=
'$(document).ready(function () {
9114 $(\'#' . $htmlname .
'\').
' . $tmpplugin . '({
';
9122 $out .= ' dir: \
'ltr\',
9123 containerCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag (ko with multiselect) */
9124 dropdownCssClass: \'' . $morecss .
'\',
9126 formatResult: formatResult,
9127 templateResult: formatResult,
9128 escapeMarkup:
function (markup) {
return markup; },
9130 formatSelection: formatSelection,
9131 templateSelection: formatSelection
9136 $(\
'#' . $htmlname .
' + .select2\').addClass(\'' . $morecss .
'\');
9138 } elseif ($addjscombo == 2 && !defined('DISABLE_MULTISELECT
')) {
9140 // TODO external lib multiselect/jquery.multi-select.js must have been loaded to use this multiselect plugin
9142 $out .= 'console.log(\
'addjscombo=2 for htmlname=' . $htmlname .
'\');
';
9143 $out .= '$(document).ready(
function () {
9144 $(\
'#' . $htmlname .
'\').multiSelect({
9145 containerHTML: \
'<div class="multi-select-container">\',
9146 menuHTML: \'<div class="multi-select-menu">\',
9147 buttonHTML: \'<span class="multi-select-button ' . $morecss .
'">\',
9148 menuItemHTML: \'<label class="multi-select-menuitem">\',
9149 activeClass: \'multi-select-container--open\',
9150 noneText: \'' . $placeholder .
'\'
9154 $out .= '</script>
';
9172 public static function multiSelectArrayWithCheckbox($htmlname, &$array, $varpage, $pos = '
')
9174 global $langs, $user;
9176 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER
')) {
9179 if (empty($array)) {
9183 $tmpvar = "MAIN_SELECTEDFIELDS_" . $varpage; // To get list of saved selected fields to show
9185 if (!empty($user->conf->$tmpvar)) { // A list of fields was already customized for user
9186 $tmparray = explode(',
', $user->conf->$tmpvar);
9187 foreach ($array as $key => $val) {
9189 //var_dump($tmparray);
9190 if (in_array($key, $tmparray)) {
9191 $array[$key]['checked
'] = 1;
9193 $array[$key]['checked
'] = 0;
9196 } else { // There is no list of fields already customized for user
9197 foreach ($array as $key => $val) {
9198 if (!empty($array[$key]['checked
']) && $array[$key]['checked
'] < 0) {
9199 $array[$key]['checked
'] = 0;
9204 $listoffieldsforselection = '';
9205 $listcheckedstring = '';
9207 foreach ($array as $key => $val) {
9209 // var_dump(array_key_exists('enabled
', $val));
9210 // var_dump(!$val['enabled
']);
9211 if (array_key_exists('enabled
', $val) && isset($val['enabled
']) && !$val['enabled
']) {
9212 unset($array[$key]); // We don't want
this field
9215 if (!empty($val[
'type']) && $val[
'type'] ==
'separate') {
9220 if (!empty($val[
'label']) && $val[
'label']) {
9221 if (!empty($val[
'langfile']) && is_object($langs)) {
9222 $langs->load($val[
'langfile']);
9226 $listoffieldsforselection .=
'<li><input type="checkbox" id="checkbox' . $key .
'" value="' . $key .
'"' . ((!array_key_exists(
'checked', $val) || empty($val[
'checked']) || $val[
'checked'] ==
'-1') ?
'' :
' checked="checked"') .
'/><label for="checkbox' . $key .
'">' .
dol_escape_htmltag($langs->trans($val[
'label'])) .
'</label></li>';
9227 $listcheckedstring .= (empty($val[
'checked']) ?
'' : $key .
',');
9231 $out =
'<!-- Component multiSelectArrayWithCheckbox ' . $htmlname .
' -->
9233 <dl class="dropdown">
9235 <a href="#' . $htmlname .
'">
9238 <input type="hidden" class="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $listcheckedstring .
'">
9240 <dd class="dropdowndd">
9241 <div class="multiselectcheckbox'.$htmlname.
'">
9242 <ul class="'.$htmlname.($pos ==
'1' ?
'left' :
'').
'">
9243 <li><input class="inputsearch_dropdownselectedfields width90p minwidth200imp" style="width:90%;" type="text" placeholder="'.$langs->trans(
'Search').
'"></li>
9244 '.$listoffieldsforselection.
'
9250 <script nonce="' .
getNonce() .
'" type="text/javascript">
9251 jQuery(document).ready(function () {
9252 $(\'.multiselectcheckbox' . $htmlname .
' input[type="checkbox"]\').on(\'click\', function () {
9253 console.log("A new field was added/removed, we edit field input[name=formfilteraction]");
9255 $("input:hidden[name=formfilteraction]").val(\'listafterchangingselectedfields\'); // Update field so we know we changed something on selected fields after POST
9257 var title = $(this).val() + ",";
9258 if ($(this).is(\':checked\')) {
9259 $(\'.' . $htmlname .
'\').val(title + $(\
'.' . $htmlname .
'\').val());
9262 $(\
'.' . $htmlname .
'\').val( $(\
'.' . $htmlname .
'\').val().replace(title, \
'\') )
9267 $(
"input.inputsearch_dropdownselectedfields").on(
"keyup",
function() {
9268 var value = $(
this).val().toLowerCase();
9269 $(\
'.multiselectcheckbox'.$htmlname.
' li > label\').filter(function() {
9270 $(this).parent().toggle($(this).text().toLowerCase().indexOf(value) > -1)
9293 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
9296 $categories = $cat->containing($id, $type);
9298 if ($rendermode == 1) {
9300 foreach ($categories as $c) {
9301 $ways = $c->print_all_ways(
' >> ', ($nolink ?
'none' :
''), 0, 1);
9302 foreach ($ways as $way) {
9303 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ?
' style="background: #' . $c->color .
';"' :
' style="background: #bbb"') .
'>' . $way .
'</li>';
9306 return '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
9309 if ($rendermode == 0) {
9310 $arrayselected = array();
9312 foreach ($categories as $c) {
9313 $arrayselected[] = $c->id;
9316 return $this->
multiselectarray(
'categories', $cate_arbo, $arrayselected, 0, 0,
'', 0,
'100%',
'disabled',
'category');
9319 return 'ErrorBadValueForParameterRenderMode';
9333 global $conf, $langs, $hookmanager;
9334 global $bc, $action;
9339 $hookmanager->initHooks(array(
'commonobject'));
9340 $parameters = array(
9341 'morehtmlright' => $morehtmlright,
9342 'compatibleImportElementsList' => &$compatibleImportElementsList,
9344 $reshook = $hookmanager->executeHooks(
'showLinkedObjectBlock', $parameters,
$object, $action);
9346 $nbofdifferenttypes = count(
$object->linkedObjects);
9348 if (empty($reshook)) {
9349 print
'<!-- showLinkedObjectBlock -->';
9350 print
load_fiche_titre($langs->trans($title), $morehtmlright,
'', 0, 0,
'showlinkedobjectblock');
9353 print
'<div class="div-table-responsive-no-min">';
9354 print
'<table class="noborder allwidth" data-block="showLinkedObject" data-element="' .
$object->element .
'" data-elementid="' .
$object->id .
'" >';
9356 print
'<tr class="liste_titre">';
9357 print
'<td>' . $langs->trans(
"Type") .
'</td>';
9358 print
'<td>' . $langs->trans(
"Ref") .
'</td>';
9359 print
'<td class="center"></td>';
9360 print
'<td class="center">' . $langs->trans(
"Date") .
'</td>';
9361 print
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
9362 print
'<td class="right">' . $langs->trans(
"Status") .
'</td>';
9366 $nboftypesoutput = 0;
9368 foreach (
$object->linkedObjects as $objecttype => $objects) {
9369 $tplpath = $element = $subelement = $objecttype;
9372 $showImportButton =
false;
9373 if (!empty($compatibleImportElementsList) && in_array($element, $compatibleImportElementsList)) {
9374 $showImportButton =
true;
9378 if ($objecttype !=
'supplier_proposal' && preg_match(
'/^([^_]+)_([^_]+)/i', $objecttype, $regs)) {
9379 $element = $regs[1];
9380 $subelement = $regs[2];
9381 $tplpath = $element .
'/' . $subelement;
9383 $tplname =
'linkedobjectblock';
9386 if ($objecttype ==
'facture') {
9387 $tplpath =
'compta/' . $element;
9388 if (!isModEnabled(
'invoice')) {
9391 } elseif ($objecttype ==
'facturerec') {
9392 $tplpath =
'compta/facture';
9393 $tplname =
'linkedobjectblockForRec';
9394 if (!isModEnabled(
'invoice')) {
9397 } elseif ($objecttype ==
'propal') {
9398 $tplpath =
'comm/' . $element;
9399 if (!isModEnabled(
'propal')) {
9402 } elseif ($objecttype ==
'supplier_proposal') {
9403 if (!isModEnabled(
'supplier_proposal')) {
9406 } elseif ($objecttype ==
'shipping' || $objecttype ==
'shipment' || $objecttype ==
'expedition') {
9407 $tplpath =
'expedition';
9408 if (!isModEnabled(
'shipping')) {
9411 } elseif ($objecttype ==
'reception') {
9412 $tplpath =
'reception';
9413 if (!isModEnabled(
'reception')) {
9416 } elseif ($objecttype ==
'delivery') {
9417 $tplpath =
'delivery';
9421 } elseif ($objecttype ==
'ficheinter') {
9422 $tplpath =
'fichinter';
9423 if (!isModEnabled(
'intervention')) {
9426 } elseif ($objecttype ==
'invoice_supplier') {
9427 $tplpath =
'fourn/facture';
9428 } elseif ($objecttype ==
'order_supplier') {
9429 $tplpath =
'fourn/commande';
9430 } elseif ($objecttype ==
'expensereport') {
9431 $tplpath =
'expensereport';
9432 } elseif ($objecttype ==
'subscription') {
9433 $tplpath =
'adherents';
9434 } elseif ($objecttype ==
'conferenceorbooth') {
9435 $tplpath =
'eventorganization';
9436 } elseif ($objecttype ==
'conferenceorboothattendee') {
9437 $tplpath =
'eventorganization';
9438 } elseif ($objecttype ==
'mo') {
9440 if (!isModEnabled(
'mrp')) {
9445 global $linkedObjectBlock;
9446 $linkedObjectBlock = $objects;
9449 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array(
'/' . $tplpath .
'/tpl'));
9450 foreach ($dirtpls as $reldir) {
9451 $reldir = rtrim($reldir,
'/');
9452 if ($nboftypesoutput == ($nbofdifferenttypes - 1)) {
9453 global $noMoreLinkedObjectBlockAfter;
9454 $noMoreLinkedObjectBlockAfter = 1;
9457 $res = @include
dol_buildpath($reldir .
'/' . $tplname .
'.tpl.php');
9465 if (!$nboftypesoutput) {
9466 print
'<tr><td class="impair" colspan="7"><span class="opacitymedium">' . $langs->trans(
"None") .
'</span></td></tr>';
9471 if (!empty($compatibleImportElementsList)) {
9472 $res = @include
dol_buildpath(
'core/tpl/objectlinked_lineimport.tpl.php');
9478 return $nbofdifferenttypes;
9491 global $conf, $langs, $hookmanager;
9495 $linktoelemlist =
'';
9496 $listofidcompanytoscan =
'';
9498 if (!is_object(
$object->thirdparty)) {
9502 $possiblelinks = array();
9503 if (is_object(
$object->thirdparty) && !empty(
$object->thirdparty->id) &&
$object->thirdparty->id > 0) {
9504 $listofidcompanytoscan =
$object->thirdparty->id;
9506 $listofidcompanytoscan .=
',' .
$object->thirdparty->parent;
9509 include_once DOL_DOCUMENT_ROOT .
'/projet/class/project.class.php';
9510 $tmpproject =
new Project($this->db);
9511 $tmpproject->fetch(
$object->fk_project);
9512 if ($tmpproject->socid > 0 && ($tmpproject->socid !=
$object->thirdparty->id)) {
9513 $listofidcompanytoscan .=
',' . $tmpproject->socid;
9518 $possiblelinks = array(
9520 'enabled' => isModEnabled(
'propal'),
9522 'label' =>
'LinkToProposal',
9523 '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') .
')'),
9524 'shipping' => array(
9525 'enabled' => isModEnabled(
'shipping'),
9527 'label' =>
'LinkToExpedition',
9528 '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') .
')'),
9530 'enabled' => isModEnabled(
'order'),
9532 'label' =>
'LinkToOrder',
9533 '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') .
')'),
9535 'enabled' => isModEnabled(
'invoice'),
9537 'label' =>
'LinkToInvoice',
9538 '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') .
')'),
9539 'invoice_template' => array(
9540 'enabled' => isModEnabled(
'invoice'),
9542 'label' =>
'LinkToTemplateInvoice',
9543 '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') .
')'),
9545 'enabled' => isModEnabled(
'contract'),
9547 'label' =>
'LinkToContract',
9548 '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
9549 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'
9551 'fichinter' => array(
9552 'enabled' => isModEnabled(
'intervention'),
9554 'label' =>
'LinkToIntervention',
9555 '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') .
')'),
9556 'supplier_proposal' => array(
9557 'enabled' => isModEnabled(
'supplier_proposal'),
9559 'label' =>
'LinkToSupplierProposal',
9560 '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') .
')'),
9561 'order_supplier' => array(
9562 'enabled' => isModEnabled(
"supplier_order"),
9564 'label' =>
'LinkToSupplierOrder',
9565 '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') .
')'),
9566 'invoice_supplier' => array(
9567 'enabled' => isModEnabled(
"supplier_invoice"),
9568 'perms' => 1,
'label' =>
'LinkToSupplierInvoice',
9569 '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') .
')'),
9571 'enabled' => isModEnabled(
'ticket'),
9573 'label' =>
'LinkToTicket',
9574 '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') .
')'),
9576 'enabled' => isModEnabled(
'mrp'),
9578 'label' =>
'LinkToMo',
9579 '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') .
')')
9583 if (
$object->table_element ==
'commande_fournisseur') {
9584 $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').
')';
9585 } elseif (
$object->table_element ==
'mrp_mo') {
9586 $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').
')';
9590 if (!empty($listofidcompanytoscan)) {
9592 $hookmanager->initHooks(array(
'commonobject'));
9593 $parameters = array(
'listofidcompanytoscan' => $listofidcompanytoscan,
'possiblelinks' => $possiblelinks);
9594 $reshook = $hookmanager->executeHooks(
'showLinkToObjectBlock', $parameters,
$object, $action);
9597 if (empty($reshook)) {
9598 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
9599 $possiblelinks = array_merge($possiblelinks, $hookmanager->resArray);
9601 } elseif ($reshook > 0) {
9602 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
9603 $possiblelinks = $hookmanager->resArray;
9607 foreach ($possiblelinks as $key => $possiblelink) {
9610 if (empty($possiblelink[
'enabled'])) {
9614 if (!empty($possiblelink[
'perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || !in_array($key, $excludelinksto))) {
9615 print
'<div id="' . $key .
'list"' . (empty($conf->use_javascript_ajax) ?
'' :
' style="display:none"') .
'>';
9619 print
'<!-- form to add a link from anywhere -->'.
"\n";
9620 print
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinkedbyref' . $key .
'">';
9621 print
'<input type="hidden" name="id" value="' .
$object->id .
'">';
9622 print
'<input type="hidden" name="action" value="addlinkbyref">';
9623 print
'<input type="hidden" name="token" value="' . newToken() .
'">';
9624 print
'<input type="hidden" name="addlink" value="' . $key .
'">';
9625 print
'<table class="noborder">';
9628 print
'<td class="center"><input type="text" placeholder="'.dol_escape_htmltag($langs->trans(
"Ref")).
'" name="reftolinkto" value="' .
dol_escape_htmltag(
GETPOST(
'reftolinkto',
'alpha')) .
'"> ';
9629 print
'<input type="submit" class="button small valignmiddle" value="' . $langs->trans(
'ToLink') .
'"> ';
9630 print
'<input type="submit" class="button small" name="cancel" value="' . $langs->trans(
'Cancel') .
'"></td>';
9636 $sql = $possiblelink[
'sql'];
9638 $resqllist = $this->db->query($sql);
9640 $num = $this->db->num_rows($resqllist);
9644 print
'<!-- form to add a link from object to same thirdparty -->'.
"\n";
9645 print
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinked' . $key .
'">';
9646 print
'<input type="hidden" name="action" value="addlink">';
9647 print
'<input type="hidden" name="token" value="' . newToken() .
'">';
9648 print
'<input type="hidden" name="id" value="' .
$object->id .
'">';
9649 print
'<input type="hidden" name="addlink" value="' . $key .
'">';
9650 print
'<table class="noborder">';
9651 print
'<tr class="liste_titre">';
9652 print
'<td class="nowrap"></td>';
9653 print
'<td class="center">' . $langs->trans(
"Ref") .
'</td>';
9654 print
'<td class="left">' . $langs->trans(
"RefCustomer") .
'</td>';
9655 print
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
9656 print
'<td class="left">' . $langs->trans(
"Company") .
'</td>';
9659 $objp = $this->db->fetch_object($resqllist);
9661 print
'<tr class="oddeven">';
9662 print
'<td class="left">';
9663 print
'<input type="radio" name="idtolinkto" id="' . $key .
'_' . $objp->rowid .
'" value="' . $objp->rowid .
'">';
9665 print
'<td class="center"><label for="' . $key .
'_' . $objp->rowid .
'">' . $objp->ref .
'</label></td>';
9666 print
'<td>' . (!empty($objp->ref_client) ? $objp->ref_client : (!empty($objp->ref_supplier) ? $objp->ref_supplier :
'')) .
'</td>';
9667 print
'<td class="right">';
9668 if ($possiblelink[
'label'] ==
'LinkToContract') {
9669 $form =
new Form($this->db);
9670 print $form->textwithpicto(
'', $langs->trans(
"InformationOnLinkToContract")) .
' ';
9672 print
'<span class="amount">' . (isset($objp->total_ht) ?
price($objp->total_ht) :
'') .
'</span>';
9674 print
'<td>' . $objp->name .
'</td>';
9679 print
'<div class="center">';
9681 print
'<input type="submit" class="button valignmiddle marginleftonly marginrightonly small" value="' . $langs->trans(
'ToLink') .
'">';
9683 if (empty($conf->use_javascript_ajax)) {
9684 print
'<input type="submit" class="button button-cancel marginleftonly marginrightonly small" name="cancel" value="' . $langs->trans(
"Cancel") .
'"></div>';
9686 print
'<input type="submit" onclick="jQuery(\'#' . $key .
'list\').toggle(); return false;" class="button button-cancel marginleftonly marginrightonly small" name="cancel" value="' . $langs->trans(
"Cancel") .
'"></div>';
9689 $this->db->free($resqllist);
9697 $linktoelemlist .=
'<li><a href="#linkto' . $key .
'" class="linkto dropdowncloseonclick" rel="' . $key .
'">' . $langs->trans($possiblelink[
'label']) .
' (' . $num .
')</a></li>';
9700 $linktoelemlist .=
'<li><span class="linktodisabled">' . $langs->trans($possiblelink[
'label']) .
' (0)</span></li>';
9705 if ($linktoelemlist) {
9707 <dl class="dropdown" id="linktoobjectname">
9709 if (!empty($conf->use_javascript_ajax)) {
9710 $linktoelem .=
'<dt><a href="#linktoobjectname"><span class="fas fa-link paddingrightonly"></span>' . $langs->trans(
"LinkTo") .
'...</a></dt>';
9712 $linktoelem .=
'<dd>
9713 <div class="multiselectlinkto">
9714 <ul class="ulselectedfields">' . $linktoelemlist .
'
9723 if (!empty($conf->use_javascript_ajax)) {
9724 print
'<!-- Add js to show linkto box -->
9725 <script nonce="' .
getNonce() .
'">
9726 jQuery(document).ready(function() {
9727 jQuery(".linkto").click(function() {
9728 console.log("We choose to show/hide links for rel="+jQuery(this).attr(\'rel\')+" so #"+jQuery(this).attr(\'rel\')+"list");
9729 jQuery("#"+jQuery(this).attr(\'rel\')+"list").toggle();
9753 public function selectyesno($htmlname, $value =
'', $option = 0, $disabled =
false, $useempty = 0, $addjscombo = 0, $morecss =
'width75', $labelyes =
'Yes', $labelno =
'No')
9764 $disabled = ($disabled ?
' disabled' :
'');
9766 $resultyesno =
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'"' . $disabled .
'>' .
"\n";
9768 $resultyesno .=
'<option value="-1"' . (($value < 0) ?
' selected' :
'') .
'> </option>' .
"\n";
9770 if ((
"$value" ==
'yes') || ($value == 1)) {
9771 $resultyesno .=
'<option value="' . $yes .
'" selected>' . $langs->trans($labelyes) .
'</option>' .
"\n";
9772 $resultyesno .=
'<option value="' . $no .
'">' . $langs->trans($labelno) .
'</option>' .
"\n";
9774 $selected = (($useempty && $value !=
'0' && $value !=
'no') ?
'' :
' selected');
9775 $resultyesno .=
'<option value="' . $yes .
'">' . $langs->trans($labelyes) .
'</option>' .
"\n";
9776 $resultyesno .=
'<option value="' . $no .
'"' . $selected .
'>' . $langs->trans($labelno) .
'</option>' .
"\n";
9778 $resultyesno .=
'</select>' .
"\n";
9781 $resultyesno .=
ajax_combobox($htmlname, array(), 0, 0,
'resolve', ($useempty < 0 ? (
string) $useempty :
'-1'), $morecss);
9784 return $resultyesno;
9801 $sql =
"SELECT rowid, label";
9802 $sql .=
" FROM " . $this->db->prefix() .
"export_model";
9803 $sql .=
" WHERE type = '" . $this->db->escape($type) .
"'";
9804 $sql .=
" ORDER BY rowid";
9805 $result = $this->db->query($sql);
9807 print
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
9809 print
'<option value="-1"> </option>';
9812 $num = $this->db->num_rows($result);
9815 $obj = $this->db->fetch_object($result);
9816 if ($selected == $obj->rowid) {
9817 print
'<option value="' . $obj->rowid .
'" selected>';
9819 print
'<option value="' . $obj->rowid .
'">';
9849 public function showrefnav(
$object, $paramid, $morehtml =
'', $shownav = 1, $fieldid =
'rowid', $fieldref =
'ref', $morehtmlref =
'', $moreparam =
'', $nodbprefix = 0, $morehtmlleft =
'', $morehtmlstatus =
'', $morehtmlright =
'')
9851 global $conf, $langs, $hookmanager, $extralanguages;
9854 if (empty($fieldid)) {
9857 if (empty($fieldref)) {
9863 if (property_exists(
$object,
'gender') && !empty(
$object->gender)) {
9864 $addgendertxt =
' ';
9867 $addgendertxt .=
'<i class="fas fa-mars"></i>';
9870 $addgendertxt .=
'<i class="fas fa-venus"></i>';
9873 $addgendertxt .=
'<i class="fas fa-transgender"></i>';
9879 if (is_object($hookmanager)) {
9880 $parameters = array(
'showrefnav' =>
true);
9881 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters,
$object);
9882 $object->next_prev_filter .= $hookmanager->resPrint;
9885 $previous_ref = $next_ref =
'';
9888 $object->load_previous_next_ref((isset(
$object->next_prev_filter) ?
$object->next_prev_filter :
''), $fieldid, $nodbprefix);
9890 $navurl = $_SERVER[
"PHP_SELF"];
9892 if ($paramid ==
'project_ref') {
9893 if (preg_match(
'/\/tasks\/(task|contact|note|document)\.php/', $navurl)) {
9894 $navurl = preg_replace(
'/\/tasks\/(task|contact|time|note|document)\.php/',
'/tasks.php', $navurl);
9901 $stringforfirstkey = $langs->trans(
"KeyboardShortcut");
9902 if ($conf->browser->name ==
'chrome') {
9903 $stringforfirstkey .=
' ALT +';
9904 } elseif ($conf->browser->name ==
'firefox') {
9905 $stringforfirstkey .=
' ALT + SHIFT +';
9907 $stringforfirstkey .=
' CTL +';
9910 $previous_ref =
$object->ref_previous ?
'<a accesskey="p" alt="'.dol_escape_htmltag($langs->trans(
"Previous")).
'" title="' . $stringforfirstkey .
' p" class="classfortooltip" 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>';
9911 $next_ref =
$object->ref_next ?
'<a accesskey="n" alt="'.dol_escape_htmltag($langs->trans(
"Next")).
'" title="' . $stringforfirstkey .
' n" class="classfortooltip" 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>';
9915 $ret .=
'<!-- Start banner content --><div style="vertical-align: middle">';
9918 if ($morehtmlright) {
9919 $ret .=
'<div class="inline-block floatleft">' . $morehtmlright .
'</div>';
9922 if ($previous_ref || $next_ref || $morehtml) {
9923 $ret .=
'<div class="pagination paginationref"><ul class="right">';
9925 if ($morehtml &&
getDolGlobalInt(
'MAIN_OPTIMIZEFORTEXTBROWSER') < 2) {
9926 $ret .=
'<!-- morehtml --><li class="noborder litext' . (($shownav && $previous_ref && $next_ref) ?
' clearbothonsmartphone' :
'') .
'">' . $morehtml .
'</li>';
9928 if ($shownav && ($previous_ref || $next_ref)) {
9929 $ret .=
'<li class="pagination">' . $previous_ref .
'</li>';
9930 $ret .=
'<li class="pagination">' . $next_ref .
'</li>';
9932 if ($previous_ref || $next_ref || $morehtml) {
9933 $ret .=
'</ul></div>';
9937 $parameters = array(
'morehtmlstatus' => $morehtmlstatus);
9938 $reshook = $hookmanager->executeHooks(
'moreHtmlStatus', $parameters,
$object);
9939 if (empty($reshook)) {
9940 $morehtmlstatus .= $hookmanager->resPrint;
9942 $morehtmlstatus = $hookmanager->resPrint;
9944 if ($morehtmlstatus) {
9945 $ret .=
'<div class="statusref">' . $morehtmlstatus .
'</div>';
9948 $parameters = array();
9949 $reshook = $hookmanager->executeHooks(
'moreHtmlRef', $parameters,
$object);
9950 if (empty($reshook)) {
9951 $morehtmlref .= $hookmanager->resPrint;
9952 } elseif ($reshook > 0) {
9953 $morehtmlref = $hookmanager->resPrint;
9957 if ($morehtmlleft) {
9958 if ($conf->browser->layout ==
'phone') {
9959 $ret .=
'<!-- morehtmlleft --><div class="floatleft">' . $morehtmlleft .
'</div>';
9961 $ret .=
'<!-- morehtmlleft --><div class="inline-block floatleft">' . $morehtmlleft .
'</div>';
9966 $ret .=
'<div class="inline-block floatleft valignmiddle maxwidth750 marginbottomonly refid' . (($shownav && ($previous_ref || $next_ref)) ?
' refidpadding' :
'') .
'">';
9969 if (
$object->element ==
'societe') {
9973 $arrayoflangcode = array();
9978 if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
9979 if (!is_object($extralanguages)) {
9980 include_once DOL_DOCUMENT_ROOT .
'/core/class/extralanguages.class.php';
9983 $extralanguages->fetch_name_extralanguages(
'societe');
9985 if (!empty($extralanguages->attributes[
'societe'][
'name'])) {
9986 $object->fetchValuesForExtraLanguages();
9990 foreach ($arrayoflangcode as $extralangcode) {
9992 if (
$object->array_languages[
'name'][$extralangcode]) {
9993 $htmltext .=
$object->array_languages[
'name'][$extralangcode];
9995 $htmltext .=
'<span class="opacitymedium">' . $langs->trans(
"SwitchInEditModeToAddTranslation") .
'</span>';
9998 $ret .=
'<!-- Show translations of name -->' .
"\n";
9999 $ret .= $this->
textwithpicto(
'', $htmltext, -1,
'language',
'opacitymedium paddingleft');
10002 } elseif (
$object->element ==
'member') {
10003 '@phan-var-force Adherent $object';
10004 $ret .=
$object->ref .
'<br>';
10005 $fullname =
$object->getFullName($langs);
10011 } elseif (in_array(
$object->element, array(
'contact',
'user'))) {
10013 } elseif (
$object->element ==
'usergroup') {
10015 } elseif (in_array(
$object->element, array(
'action',
'agenda'))) {
10016 '@phan-var-force ActionComm $object';
10018 } elseif (in_array(
$object->element, array(
'adherent_type'))) {
10020 } elseif (
$object->element ==
'ecm_directories') {
10022 } elseif ($fieldref !=
'none') {
10025 if ($morehtmlref) {
10027 if (substr($morehtmlref, 0, 4) !=
'<div') {
10031 $ret .= $morehtmlref;
10036 $ret .=
'</div><!-- End banner content -->';
10055 if (empty(
$object->barcode)) {
10060 if (empty(
$object->barcode_type_code) || empty(
$object->barcode_type_coder)) {
10062 $result =
$object->fetch_barcode();
10065 return '<!-- ErrorFetchBarcode -->';
10070 $url = DOL_URL_ROOT .
'/viewimage.php?modulepart=barcode&generator=' . urlencode(
$object->barcode_type_coder) .
'&code=' . urlencode(
$object->barcode) .
'&encoding=' . urlencode(
$object->barcode_type_code);
10071 $out =
'<!-- url barcode = ' . $url .
' -->';
10072 $out .=
'<img src="' . $url .
'"' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
'>';
10094 public static function showphoto($modulepart,
$object, $width = 100, $height = 0, $caneditfield = 0, $cssclass =
'photowithmargin', $imagesize =
'', $addlinktofullsize = 1, $cache = 0, $forcecapture =
'', $noexternsourceoverwrite = 0)
10096 global $conf, $langs;
10098 $entity = (empty(
$object->entity) ? $conf->entity :
$object->entity);
10103 $originalfile =
'';
10107 if ($modulepart ==
'societe') {
10108 $dir = $conf->societe->multidir_output[$entity];
10111 if ((
string) $imagesize ==
'mini') {
10113 } elseif ((
string) $imagesize ==
'small') {
10122 } elseif ($modulepart ==
'contact') {
10123 $dir = $conf->societe->multidir_output[$entity] .
'/contact';
10124 if (!empty(
$object->photo)) {
10126 if ((
string) $imagesize ==
'mini') {
10128 } elseif ((
string) $imagesize ==
'small') {
10138 } elseif ($modulepart ==
'userphoto') {
10139 $dir = $conf->user->dir_output;
10140 if (!empty(
$object->photo)) {
10142 if ((
string) $imagesize ==
'mini') {
10144 } elseif ((
string) $imagesize ==
'small') {
10153 $altfile =
$object->id .
".jpg";
10157 } elseif ($modulepart ==
'memberphoto') {
10158 $dir = $conf->adherent->dir_output;
10159 if (!empty(
$object->photo)) {
10161 if ((
string) $imagesize ==
'mini') {
10163 } elseif ((
string) $imagesize ==
'small') {
10172 $altfile =
$object->id .
".jpg";
10179 if ($modulepart !=
"unknown" && method_exists(
$object,
'getDataToShowPhoto')) {
10180 $tmpdata =
$object->getDataToShowPhoto($modulepart, $imagesize);
10182 $dir = $tmpdata[
'dir'];
10183 $file = $tmpdata[
'file'];
10184 $originalfile = $tmpdata[
'originalfile'];
10185 $altfile = $tmpdata[
'altfile'];
10186 $email = $tmpdata[
'email'];
10187 $capture = $tmpdata[
'capture'];
10191 if ($forcecapture) {
10192 $capture = $forcecapture;
10198 if ($file && file_exists($dir .
"/" . $file)) {
10199 if ($addlinktofullsize) {
10201 if ($urladvanced) {
10202 $ret .=
'<a href="' . $urladvanced .
'">';
10204 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
10207 $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=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($file) .
'&cache=' . $cache .
'">';
10208 if ($addlinktofullsize) {
10211 } elseif ($altfile && file_exists($dir .
"/" . $altfile)) {
10212 if ($addlinktofullsize) {
10214 if ($urladvanced) {
10215 $ret .=
'<a href="' . $urladvanced .
'">';
10217 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
10220 $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=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($altfile) .
'&cache=' . $cache .
'">';
10221 if ($addlinktofullsize) {
10225 $nophoto =
'/public/theme/common/nophoto.png';
10226 $defaultimg =
'identicon';
10227 if (in_array($modulepart, array(
'societe',
'userphoto',
'contact',
'memberphoto'))) {
10228 if ($modulepart ==
'societe' || ($modulepart ==
'memberphoto' && !empty(
$object->morphy) && strpos(
$object->morphy,
'mor') !==
false)) {
10229 $nophoto =
'company';
10231 $nophoto =
'/public/theme/common/user_anonymous.png';
10233 $nophoto =
'/public/theme/common/user_man.png';
10236 $nophoto =
'/public/theme/common/user_woman.png';
10241 if (isModEnabled(
'gravatar') && $email && empty($noexternsourceoverwrite)) {
10243 $ret .=
'<!-- Put link to gravatar -->';
10244 $ret .=
'<img class="photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" title="' . $email .
' Gravatar avatar" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="https://www.gravatar.com/avatar/' .
dol_hash(strtolower(trim($email)),
'sha256', 1) .
'?s=' . $width .
'&d=' . $defaultimg .
'">';
10246 if ($nophoto ==
'company') {
10247 $ret .=
'<div class="divforspanimg valignmiddle center photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
'>' .
img_picto(
'',
'company') .
'</div>';
10250 $ret .=
'<img class="photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="' . DOL_URL_ROOT . $nophoto .
'">';
10255 if ($caneditfield) {
10259 $ret .=
'<table class="nobordernopadding centpercent">';
10261 $ret .=
'<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> <label for="photodelete">' . $langs->trans(
"Delete") .
'</label><br><br></td></tr>';
10263 $ret .=
'<tr><td class="tdoverflow">';
10265 $maxmin = $maxfilesizearray[
'maxmin'];
10267 $ret .=
'<input type="hidden" name="MAX_FILE_SIZE" value="' . ($maxmin * 1024) .
'">';
10269 $ret .=
'<input type="file" class="flat maxwidth200onsmartphone" name="photo" id="photoinput" accept="image/*"' . ($capture ?
' capture="' . $capture .
'"' :
'') .
'>';
10270 $ret .=
'</td></tr>';
10271 $ret .=
'</table>';
10296 public function select_dolgroups($selected = 0, $htmlname =
'groupid', $show_empty = 0, $exclude =
'', $disabled = 0, $include =
'', $enableonly = array(), $force_entity =
'0', $multiple =
false, $morecss =
'minwidth200')
10299 global $conf, $user, $langs;
10302 $excludeGroups =
null;
10303 if (is_array($exclude)) {
10304 $excludeGroups = implode(
",", $exclude);
10307 $includeGroups =
null;
10308 if (is_array($include)) {
10309 $includeGroups = implode(
",", $include);
10312 if (!is_array($selected)) {
10313 $selected = array($selected);
10319 $sql =
"SELECT ug.rowid, ug.nom as name";
10320 if (isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
10321 $sql .=
", e.label";
10323 $sql .=
" FROM " . $this->db->prefix() .
"usergroup as ug ";
10324 if (isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
10325 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid=ug.entity";
10326 if ($force_entity) {
10327 $sql .=
" WHERE ug.entity IN (0, " . $force_entity .
")";
10329 $sql .=
" WHERE ug.entity IS NOT NULL";
10332 $sql .=
" WHERE ug.entity IN (0, " . $conf->entity .
")";
10334 if (is_array($exclude) && $excludeGroups) {
10335 $sql .=
" AND ug.rowid NOT IN (" . $this->db->sanitize($excludeGroups) .
")";
10337 if (is_array($include) && $includeGroups) {
10338 $sql .=
" AND ug.rowid IN (" . $this->db->sanitize($includeGroups) .
")";
10340 $sql .=
" ORDER BY ug.nom ASC";
10342 dol_syslog(get_class($this) .
"::select_dolgroups", LOG_DEBUG);
10343 $resql = $this->db->query($sql);
10346 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
10348 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
10350 $num = $this->db->num_rows($resql);
10353 if ($show_empty && !$multiple) {
10354 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'> </option>' .
"\n";
10357 while ($i < $num) {
10358 $obj = $this->db->fetch_object($resql);
10360 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
10364 $label = $obj->name;
10365 $labelhtml = $obj->name;
10366 if (isModEnabled(
'multicompany') && !
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE') && $conf->entity == 1) {
10367 $label .=
" (" . $obj->label .
")";
10368 $labelhtml .=
' <span class="opacitymedium">(' . $obj->label .
')</span>';
10371 $out .=
'<option value="' . $obj->rowid .
'"';
10372 if ($disableline) {
10373 $out .=
' disabled';
10375 if ((isset($selected[0]) && is_object($selected[0]) && $selected[0]->
id == $obj->rowid)
10376 || ((!isset($selected[0]) || !is_object($selected[0])) && !empty($selected) && in_array($obj->rowid, $selected))) {
10377 $out .=
' selected';
10379 $out .=
' data-html="'.dol_escape_htmltag($labelhtml).
'"';
10382 $out .=
'</option>';
10387 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'></option>' .
"\n";
10389 $out .=
'<option value="" disabled>' . $langs->trans(
"NoUserGroupDefined") .
'</option>';
10391 $out .=
'</select>';
10410 $out =
'<div class="nowraponall">';
10411 $out .=
'<button type="submit" class="liste_titre button_search reposition" name="button_search_x" value="x"><span class="fas fa-search"></span></button>';
10412 $out .=
'<button type="submit" class="liste_titre button_removefilter reposition" name="button_removefilter_x" value="x"><span class="fas fa-times"></span></button>';
10426 public function showCheckAddButtons($cssclass =
'checkforaction', $calljsfunction = 0, $massactionname =
"massaction")
10432 if (!empty($conf->use_javascript_ajax)) {
10433 $out .=
'<div class="inline-block checkallactions"><input type="checkbox" id="' . $cssclass .
's" name="' . $cssclass .
's" class="checkallactions"></div>';
10435 $out .=
'<script nonce="' .
getNonce() .
'">
10436 $(document).ready(function() {
10437 $("#' . $cssclass .
's").click(function() {
10438 if($(this).is(\':checked\')){
10439 console.log("We check all ' . $cssclass .
' and trigger the change method");
10440 $(".' . $cssclass .
'").prop(\'checked\', true).trigger(\'change\');
10444 console.log("We uncheck all");
10445 $(".' . $cssclass .
'").prop(\'checked\', false).trigger(\'change\');
10447 if ($calljsfunction) {
10448 $out .=
'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0, "' . $massactionname .
'", "' . $cssclass .
'"); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }';
10451 $(".' . $cssclass .
'").change(function() {
10452 $(this).closest("tr").toggleClass("highlight", this.checked);
10472 if ($addcheckuncheckall) {
10491 public function selectExpenseCategories($selected =
'', $htmlname =
'fk_c_exp_tax_cat', $useempty = 0, $excludeid = array(), $target =
'', $default_selected = 0, $params = array(), $info_admin = 1)
10493 global $langs, $user;
10496 $sql =
"SELECT rowid, label FROM " . $this->db->prefix() .
"c_exp_tax_cat WHERE active = 1";
10497 $sql .=
" AND entity IN (0," .
getEntity(
'exp_tax_cat') .
")";
10498 if (!empty($excludeid)) {
10499 $sql .=
" AND rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeid)) .
")";
10501 $sql .=
" ORDER BY label";
10503 $resql = $this->db->query($sql);
10505 $out =
'<select id="select_' . $htmlname .
'" name="' . $htmlname .
'" class="' . $htmlname .
' flat minwidth75imp maxwidth200">';
10507 $out .=
'<option value="0"> </option>';
10510 while ($obj = $this->db->fetch_object($resql)) {
10511 $out .=
'<option ' . ($selected == $obj->rowid ?
'selected="selected"' :
'') .
' value="' . $obj->rowid .
'">' . $langs->trans($obj->label) .
'</option>';
10513 $out .=
'</select>';
10516 if (!empty($htmlname) && $user->admin && $info_admin) {
10517 $out .=
' ' .
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
10520 if (!empty($target)) {
10521 $sql =
"SELECT c.id FROM " . $this->db->prefix() .
"c_type_fees as c WHERE c.code = 'EX_KME' AND c.active = 1";
10522 $resql = $this->db->query($sql);
10524 if ($this->db->num_rows($resql) > 0) {
10525 $obj = $this->db->fetch_object($resql);
10526 $out .=
'<script nonce="' .
getNonce() .
'">
10528 $("select[name=' . $target .
']").on("change", function() {
10529 var current_val = $(this).val();
10530 if (current_val == ' . $obj->id .
') {';
10531 if (!empty($default_selected) || !empty($selected)) {
10532 $out .=
'$("select[name=' . $htmlname .
']").val("' . ($default_selected > 0 ? $default_selected : $selected) .
'");';
10536 $("select[name=' . $htmlname .
']").change();
10540 $("select[name=' . $htmlname .
']").change(function() {
10542 if ($("select[name=' . $target .
']").val() == ' . $obj->id .
') {
10543 // get price of kilometer to fill the unit price
10547 data: { fk_c_exp_tax_cat: $(this).val(), token: \'' .
currentToken() .
'\' },
10548 url:
"' . (DOL_URL_ROOT . '/expensereport/ajax/ajaxik.php?' . implode('&', $params)) . '",
10549 }).done(
function( data, textStatus, jqXHR ) {
10551 if (typeof data.up !=
"undefined") {
10552 $(
"input[name=value_unit]").val(data.up);
10553 $(
"select[name=' . $htmlname . ']").attr(
"title", data.title);
10555 $(
"input[name=value_unit]").val(
"");
10556 $(
"select[name=' . $htmlname . ']").attr(
"title",
"");
10567 dol_print_error($this->db);
10581 public function selectExpenseRanges($selected = '
', $htmlname = 'fk_range
', $useempty = 0)
10583 global $conf, $langs;
10586 $sql = "SELECT rowid, range_ik FROM " . $this->db->prefix() . "c_exp_tax_range";
10587 $sql .= " WHERE entity = " . $conf->entity . " AND active = 1";
10589 $resql = $this->db->query($sql);
10591 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
10593 $out .= '<option value=
"0"></option>
';
10596 while ($obj = $this->db->fetch_object($resql)) {
10597 $out .= '<option
' . ($selected == $obj->rowid ? 'selected=
"selected"' : '') . ' value=
"' . $obj->rowid . '">
' . price($obj->range_ik, 0, $langs, 1, 0) . '</option>
';
10599 $out .= '</select>
';
10601 dol_print_error($this->db);
10617 public function selectExpense($selected = '
', $htmlname = 'fk_c_type_fees
', $useempty = 0, $allchoice = 1, $useid = 0)
10622 $sql = "SELECT id, code, label";
10623 $sql .= " FROM ".$this->db->prefix()."c_type_fees";
10624 $sql .= " WHERE active = 1";
10626 $resql = $this->db->query($sql);
10628 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
10630 $out .= '<option value=
"0"></option>
';
10633 $out .= '<option value=
"-1">
' . $langs->trans('AllExpenseReport
') . '</option>
';
10641 while ($obj = $this->db->fetch_object($resql)) {
10642 $key = $langs->trans($obj->code);
10643 $out .= '<option
' . ($selected == $obj->{$field} ? 'selected=
"selected"' : '') . ' value=
"' . $obj->{$field} . '">
' . ($key != $obj->code ? $key : $obj->label) . '</option>
';
10645 $out .= '</select>
';
10647 $out .= ajax_combobox('select_
'.$htmlname);
10649 dol_print_error($this->db);
10673 public function selectInvoice($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)
10675 global $user, $conf, $langs;
10677 require_once DOL_DOCUMENT_ROOT . '/projet/
class/project.class.php
';
10679 if (is_null($usertofilter)) {
10680 $usertofilter = $user;
10685 $hideunselectables = false;
10686 if (getDolGlobalString('PROJECT_HIDE_UNSELECTABLES
')) {
10687 $hideunselectables = true;
10690 if (empty($projectsListId)) {
10691 if (!$usertofilter->hasRight('projet
', 'all
', 'lire
')) {
10692 $projectstatic = new Project($this->db);
10693 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1);
10697 // Search all projects
10698 $sql = "SELECT f.rowid, f.ref as fref, 'nolabel
' as flabel, p.rowid as pid, f.ref,
10699 p.title, p.fk_soc, p.fk_statut, p.public,";
10700 $sql .= ' s.nom as
name';
10701 $sql .= ' FROM
' . $this->db->prefix() . 'projet as p
';
10702 $sql .= ' LEFT JOIN
' . $this->db->prefix() . 'societe as s ON s.rowid = p.fk_soc,
';
10703 $sql .= ' ' . $this->db->prefix() . 'facture as f
';
10704 $sql .= " WHERE p.entity IN (" . getEntity('project
') . ")";
10705 $sql .= " AND f.fk_projet = p.rowid AND f.fk_statut=0"; //Brouillons seulement
10706 //if ($projectsListId) $sql.= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")";
10707 //if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
10708 //if ($socid > 0) $sql.= " AND (p.fk_soc=".((int) $socid)." OR p.fk_soc IS NULL)";
10709 $sql .= " ORDER BY p.ref, f.ref ASC";
10711 $resql = $this->db->query($sql);
10713 // Use select2 selector
10714 if (!empty($conf->use_javascript_ajax)) {
10715 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
10716 $comboenhancement = ajax_combobox($htmlname, array(), 0, $forcefocus);
10717 $out .= $comboenhancement;
10718 $morecss = 'minwidth200imp maxwidth500
';
10721 if (empty($option_only)) {
10722 $out .= '<select
class=
"valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled=
"disabled"' : '') . ' id=
"' . $htmlname . '" name=
"' . $htmlname . '">
';
10724 if (!empty($show_empty)) {
10725 $out .= '<option value=
"0" class=
"optiongrey">
';
10726 if (!is_numeric($show_empty)) {
10727 $out .= $show_empty;
10731 $out .= '</option>
';
10733 $num = $this->db->num_rows($resql);
10736 while ($i < $num) {
10737 $obj = $this->db->fetch_object($resql);
10738 // 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.
10739 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$usertofilter->hasRight('societe
', 'lire
')) {
10742 if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) {
10749 if ($showproject == 'all
') {
10750 $labeltoshow .= dol_trunc($obj->ref, 18); // Invoice ref
10752 $labeltoshow .= ' -
' . $obj->name; // Soc name
10756 if ($obj->fk_statut == Project::STATUS_DRAFT) {
10758 $labeltoshow .= ' -
' . $langs->trans("Draft");
10759 } elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
10760 if ($discard_closed == 2) {
10763 $labeltoshow .= ' -
' . $langs->trans("Closed");
10764 } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
10766 $labeltoshow .= ' -
' . $langs->trans("LinkedToAnotherCompany");
10770 if (!empty($selected) && $selected == $obj->rowid) {
10771 $out .= '<option value=
"' . $obj->rowid . '" selected
';
10772 //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected
if disabled
10773 $out .=
'>' . $labeltoshow .
'</option>';
10775 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
10778 $resultat =
'<option value="' . $obj->rowid .
'"';
10780 $resultat .=
' disabled';
10785 $resultat .= $labeltoshow;
10786 $resultat .=
'</option>';
10794 if (empty($option_only)) {
10795 $out .=
'</select>';
10798 $this->db->free($resql);
10820 public function selectInvoiceRec($selected =
'', $htmlname =
'facrecid', $maxlength = 24, $option_only = 0, $show_empty =
'1', $forcefocus = 0, $disabled = 0, $morecss =
'maxwidth500')
10822 global $conf, $langs;
10828 $sql =
'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc';
10830 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'facture_rec as f';
10831 $sql .=
" WHERE f.entity IN (" .
getEntity(
'invoice') .
")";
10832 $sql .=
" ORDER BY f.titre ASC";
10834 $resql = $this->db->query($sql);
10837 if (!empty($conf->use_javascript_ajax)) {
10838 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
10839 $comboenhancement =
ajax_combobox($htmlname, array(), 0, $forcefocus);
10840 $out .= $comboenhancement;
10841 $morecss =
'minwidth200imp maxwidth500';
10844 if (empty($option_only)) {
10845 $out .=
'<select class="valignmiddle flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' id="' . $htmlname .
'" name="' . $htmlname .
'">';
10847 if (!empty($show_empty)) {
10848 $out .=
'<option value="0" class="optiongrey">';
10849 if (!is_numeric($show_empty)) {
10850 $out .= $show_empty;
10854 $out .=
'</option>';
10856 $num = $this->db->num_rows($resql);
10858 while ($obj = $this->db->fetch_object($resql)) {
10859 $labeltoshow =
dol_trunc($obj->title, 18);
10862 if (!empty($obj->suspended)) {
10864 $labeltoshow .=
' - ' . $langs->trans(
"Closed");
10868 if (!empty($selected) && $selected == $obj->rowid) {
10869 $out .=
'<option value="' . $obj->rowid .
'" selected';
10871 $out .=
'>' . $labeltoshow .
'</option>';
10873 if ($disabled && ($selected != $obj->rowid)) {
10876 $resultat =
'<option value="' . $obj->rowid .
'"';
10878 $resultat .=
' disabled';
10881 $resultat .= $labeltoshow;
10882 $resultat .=
'</option>';
10888 if (empty($option_only)) {
10889 $out .=
'</select>';
10894 $this->db->free($resql);
10897 $this->errors[] = $this->db->lasterror;
10911 public function searchComponent($arrayofcriterias, $search_component_params, $arrayofinputfieldsalreadyoutput = array(), $search_component_params_hidden =
'')
10915 if ($search_component_params_hidden !=
'' && !preg_match(
'/^\(.*\)$/', $search_component_params_hidden)) {
10916 $search_component_params_hidden =
'(' . $search_component_params_hidden .
')';
10921 $ret .=
'<div class="divadvancedsearchfieldcomp centpercent inline-block">';
10922 $ret .=
'<a href="#" class="dropdownsearch-toggle unsetcolor">';
10923 $ret .=
'<span class="fas fa-filter linkobject boxfilter paddingright pictofixedwidth" title="' .
dol_escape_htmltag($langs->trans(
"Filters")) .
'" id="idsubimgproductdistribution"></span>';
10926 $ret .=
'<div class="divadvancedsearchfieldcompinput inline-block minwidth500 maxwidth300onsmartphone">';
10929 $ret .=
'<div id="divsearch_component_params" name="divsearch_component_params" class="noborderbottom search_component_params inline-block valignmiddle">';
10931 if ($search_component_params_hidden) {
10939 foreach ($arrayofandtags as $tmpkey => $tmpval) {
10940 $errormessage =
'';
10942 if ($errormessage) {
10943 $this->error =
'ERROR in parsing search string: '.$errormessage;
10946 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
10949 $ret .=
'<span class="marginleftonlyshort valignmiddle tagsearch" data-ufilterid="'.($tmpkey + 1).
'" data-ufilter="'.
dol_escape_htmltag($tmpval).
'">';
10950 $ret .=
'<span class="tagsearchdelete select2-selection__choice__remove" data-ufilterid="'.($tmpkey + 1).
'">x</span> ';
10962 $show_search_component_params_hidden = 1;
10963 if ($show_search_component_params_hidden) {
10964 $ret .=
'<input type="hidden" name="show_search_component_params_hidden" value="1">';
10966 $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%')) -->";
10967 $ret .=
'<input type="hidden" id="search_component_params_hidden" name="search_component_params_hidden" value="' .
dol_escape_htmltag($search_component_params_hidden) .
'">';
10971 foreach ($arrayofcriterias as $criteria) {
10972 foreach ($criteria as $criteriafamilykey => $criteriafamilyval) {
10973 if (in_array(
'search_' . $criteriafamilykey, $arrayofinputfieldsalreadyoutput)) {
10976 if (in_array($criteriafamilykey, array(
'rowid',
'ref_ext',
'entity',
'extraparams'))) {
10979 if (in_array($criteriafamilyval[
'type'], array(
'date',
'datetime',
'timestamp'))) {
10980 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_start">';
10981 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startyear">';
10982 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startmonth">';
10983 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startday">';
10984 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_end">';
10985 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endyear">';
10986 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endmonth">';
10987 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endday">';
10989 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'">';
10996 $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";
10997 $ret .=
'<input type="text" placeholder="' . $langs->trans(
"Filters") .
'" id="search_component_params_input" name="search_component_params_input" class="noborderbottom search_component_input" value="">';
11003 jQuery(".tagsearchdelete").click(function(e) {
11004 var filterid = $(this).parents().attr("data-ufilterid");
11005 console.log("We click to delete the criteria nb "+filterid);
11007 // Regenerate the search_component_params_hidden with all data-ufilter except the one to delete, and post the page
11008 var newparamstring = \'\';
11009 $(\'.tagsearch\').each(function(index, element) {
11010 tmpfilterid = $(this).attr("data-ufilterid");
11011 if (tmpfilterid != filterid) {
11012 // We keep this criteria
11013 if (newparamstring == \'\') {
11014 newparamstring = $(this).attr("data-ufilter");
11016 newparamstring = newparamstring + \' AND \' + $(this).attr("data-ufilter");
11020 console.log("newparamstring = "+newparamstring);
11022 jQuery("#search_component_params_hidden").val(newparamstring);
11024 // We repost the form
11025 $(this).closest(\'form\').submit();
11028 jQuery("#search_component_params_input").keydown(function(e) {
11029 console.log("We press a key on the filter field that is "+jQuery("#search_component_params_input").val());
11030 console.log(e.which);
11031 if (jQuery("#search_component_params_input").val() == "" && e.which == 8) {
11032 /* We click on back when the input field is already empty */
11033 event.preventDefault();
11034 jQuery("#divsearch_component_params .tagsearch").last().remove();
11035 /* Regenerate content of search_component_params_hidden from remaining .tagsearch */
11037 jQuery("#divsearch_component_params .tagsearch").each(function( index ) {
11041 s = s + $(this).attr("data-ufilter");
11043 console.log("New value for search_component_params_hidden = "+s);
11044 jQuery("#search_component_params_hidden").val(s);
11065 global $langs, $user;
11069 $TModels = array();
11071 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
11072 $formmail =
new FormMail($this->db);
11073 $result = $formmail->fetchAllEMailTemplate($modelType, $user, $langs);
11076 $TModels[0] = $langs->trans(
'DefaultMailModel');
11079 foreach ($formmail->lines_model as $model) {
11080 $TModels[$model->id] = $model->label;
11084 $retstring .=
'<select class="flat" id="select_' . $prefix .
'model_mail" name="' . $prefix .
'model_mail">';
11086 foreach ($TModels as $id_model => $label_model) {
11087 $retstring .=
'<option value="' . $id_model .
'"';
11088 $retstring .=
">" . $label_model .
"</option>";
11091 $retstring .=
"</select>";
11094 $retstring .=
ajax_combobox(
'select_' . $prefix .
'model_mail');
11111 public function buttonsSaveCancel($save_label =
'Save', $cancel_label =
'Cancel', $morebuttons = array(), $withoutdiv =
false, $morecss =
'', $dol_openinpopup =
'')
11115 $buttons = array();
11119 'label_key' => $save_label,
11122 if ($save_label ==
'Create' || $save_label ==
'Add') {
11123 $save[
'name'] =
'add';
11124 } elseif ($save_label ==
'Modify') {
11125 $save[
'name'] =
'edit';
11129 'name' =>
'cancel',
11130 'label_key' =>
'Cancel',
11133 !empty($save_label) ? $buttons[] = $save :
'';
11135 if (!empty($morebuttons)) {
11136 $buttons[] = $morebuttons;
11139 !empty($cancel_label) ? $buttons[] = $cancel :
'';
11141 $retstring = $withoutdiv ?
'' :
'<div class="center">';
11143 foreach ($buttons as $button) {
11144 $addclass = empty($button[
'addclass']) ?
'' : $button[
'addclass'];
11145 $retstring .=
'<input type="submit" class="button button-' . $button[
'name'] . ($morecss ?
' ' . $morecss :
'') .
' ' . $addclass .
'" name="' . $button[
'name'] .
'" value="' .
dol_escape_htmltag($langs->trans($button[
'label_key'])) .
'">';
11147 $retstring .= $withoutdiv ?
'' :
'</div>';
11149 if ($dol_openinpopup) {
11150 $retstring .=
'<!-- buttons are shown into a $dol_openinpopup=' . $dol_openinpopup .
' context, so we enable the close of dialog on cancel -->' .
"\n";
11151 $retstring .=
'<script nonce="' .
getNonce() .
'">';
11152 $retstring .=
'jQuery(".button-cancel").click(function(e) {
11153 e.preventDefault(); console.log(\'We click on cancel in iframe popup ' . $dol_openinpopup .
'\');
11154 window.parent.jQuery(\
'#idfordialog' . $dol_openinpopup .
'\').dialog(\
'close\');
11156 $retstring .=
'</script>';
11175 $num = count($this->cache_invoice_subtype);
11182 $sql =
"SELECT rowid, code, label as label";
11183 $sql .=
" FROM " . MAIN_DB_PREFIX .
'c_invoice_subtype';
11184 $sql .=
" WHERE active = 1";
11186 $resql = $this->db->query($sql);
11188 $num = $this->db->num_rows($resql);
11190 while ($i < $num) {
11191 $obj = $this->db->fetch_object($resql);
11194 $label = ($langs->trans(
"InvoiceSubtype" . $obj->rowid) !=
"InvoiceSubtype" . $obj->rowid) ? $langs->trans(
"InvoiceSubtype" . $obj->rowid) : (($obj->label !=
'-') ? $obj->label :
'');
11195 $this->cache_invoice_subtype[$obj->rowid][
'rowid'] = $obj->rowid;
11196 $this->cache_invoice_subtype[$obj->rowid][
'code'] = $obj->code;
11197 $this->cache_invoice_subtype[$obj->rowid][
'label'] = $label;
11201 $this->cache_invoice_subtype =
dol_sort_array($this->cache_invoice_subtype,
'code',
'asc', 0, 0, 1);
11223 global $langs, $user;
11226 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
11228 $this->load_cache_invoice_subtype();
11230 $out .=
'<select id="' . $htmlname .
'" class="flat selectsubtype' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
11232 $out .=
'<option value="0"> </option>';
11235 foreach ($this->cache_invoice_subtype as $rowid => $subtype) {
11236 $label = $subtype[
'label'];
11237 $out .=
'<option value="' . $subtype[
'rowid'] .
'"';
11238 if ($selected == $subtype[
'rowid']) {
11239 $out .=
' selected="selected"';
11243 $out .=
'</option>';
11246 $out .=
'</select>';
11247 if ($user->admin && empty($noinfoadmin)) {
11248 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $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 categories.
Class to manage a WYSIWYG editor.
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 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 Dolibarr users.
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dolForgeExplodeAnd($sqlfilters)
Explode an universal search string with AND parts.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='')
Format phone numbers according to country.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
currentToken()
Return the value of token currently saved into session with name 'token'.
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.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0)
Show EMail link formatted for HTML output.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array(), $allowlink=0)
Clean a string to keep only desirable HTML tags.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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...
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
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.
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getNonce()
Return a random string to be used as a nonce value for js.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox=0, $check='restricthtml')
Sanitize a HTML to remove js, dangerous content and external link.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
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...
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_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...
ui state ui widget content ui state ui widget header ui state a ui button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
testSqlAndScriptInject($val, $type)
Security: WAF layer for SQL Injection and XSS Injection (scripts) protection (Filters on GET,...
measuringUnitString($unit, $measuring_style='', $scale='', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
$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)
Returns a hash (non reversible encryption) of a string.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e rowid