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, $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;
1461 $options_only =
false;
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);
1753 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 =
'')
1755 global $conf, $langs, $hookmanager, $action;
1757 $langs->load(
'companies');
1759 if (empty($htmlid)) {
1760 $htmlid = $htmlname;
1764 $outarray = array();
1766 if ($selected ===
'') {
1767 $selected = array();
1768 } elseif (!is_array($selected)) {
1769 $selected = array((
int) $selected);
1773 if (function_exists(
'testSqlAndScriptInject')) {
1776 return 'SQLInjectionTryDetected';
1780 if ($filter !=
'') {
1781 if (preg_match(
'/[\(\)]/', $filter)) {
1787 if (function_exists(
'testSqlAndScriptInject')) {
1790 return 'SQLInjectionTryDetected';
1796 dol_syslog(
"Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Filter Syntax.", LOG_WARNING);
1800 if (!is_object($hookmanager)) {
1801 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
1806 $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";
1807 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
1808 $sql .=
", s.nom as company, s.town AS company_town";
1810 $sql .=
" FROM " . $this->db->prefix() .
"socpeople as sp";
1811 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
1812 $sql .=
" LEFT OUTER JOIN " . $this->db->prefix() .
"societe as s ON s.rowid=sp.fk_soc";
1814 $sql .=
" WHERE sp.entity IN (" .
getEntity(
'contact') .
")";
1815 if ($socid > 0 || $socid == -1) {
1816 $sql .=
" AND sp.fk_soc = " . ((int) $socid);
1819 $sql .=
" AND sp.statut <> 0";
1824 $sql .=
" AND (" . $filter .
")";
1827 $parameters = array();
1828 $reshook = $hookmanager->executeHooks(
'selectContactListWhere', $parameters);
1829 $sql .= $hookmanager->resPrint;
1830 $sql .=
" ORDER BY sp.lastname ASC";
1832 dol_syslog(get_class($this) .
"::selectcontacts", LOG_DEBUG);
1833 $resql = $this->db->query($sql);
1835 $num = $this->db->num_rows($resql);
1837 if ($htmlname !=
'none' && !$options_only) {
1838 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlid .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . (($num || empty($disableifempty)) ?
'' :
' disabled') . ($multiple ?
'multiple' :
'') .
' ' . (!empty($moreparam) ? $moreparam :
'') .
'>';
1841 if ($showempty && !is_numeric($showempty)) {
1842 $textforempty = $showempty;
1843 $out .=
'<option class="optiongrey" value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'>' . $textforempty .
'</option>';
1845 if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) {
1846 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'> </option>';
1848 if ($showempty == 2) {
1849 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Internal") .
' --</option>';
1855 include_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
1856 $contactstatic =
new Contact($this->db);
1859 $obj = $this->db->fetch_object($resql);
1862 $extendedInfos =
'';
1864 $extendedInfos = array();
1865 $email = trim($obj->email);
1866 if (!empty($email)) {
1867 $extendedInfos[] = $email;
1869 $phone = trim($obj->phone);
1870 $phone_perso = trim($obj->phone_perso);
1871 $phone_mobile = trim($obj->phone_mobile);
1872 if (!empty($phone)) {
1873 $extendedInfos[] = $phone;
1875 if (!empty($phone_perso)) {
1876 $extendedInfos[] = $phone_perso;
1878 if (!empty($phone_mobile)) {
1879 $extendedInfos[] = $phone_mobile;
1882 $contact_town = trim($obj->contact_town);
1883 $company_town = trim($obj->company_town);
1884 if (!empty($contact_town)) {
1885 $extendedInfos[] = $contact_town;
1886 } elseif (!empty($company_town)) {
1887 $extendedInfos[] = $company_town;
1889 $extendedInfos = implode(
' - ', $extendedInfos);
1890 if (!empty($extendedInfos)) {
1891 $extendedInfos =
' - ' . $extendedInfos;
1895 $contactstatic->id = $obj->rowid;
1896 $contactstatic->lastname = $obj->lastname;
1897 $contactstatic->firstname = $obj->firstname;
1898 if ($obj->statut == 1) {
1900 if ($htmlname !=
'none') {
1902 if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) {
1905 if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) {
1908 if (!empty($selected) && in_array($obj->rowid, $selected)) {
1909 $out .=
'<option value="' . $obj->rowid .
'"';
1911 $out .=
' disabled';
1913 $out .=
' selected>';
1915 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1916 if ($showfunction && $obj->poste) {
1917 $tmplabel .=
' (' . $obj->poste .
')';
1919 if (($showsoc > 0) && $obj->company) {
1920 $tmplabel .=
' - (' . $obj->company .
')';
1924 $out .=
'</option>';
1926 $out .=
'<option value="' . $obj->rowid .
'"';
1928 $out .=
' disabled';
1932 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1933 if ($showfunction && $obj->poste) {
1934 $tmplabel .=
' (' . $obj->poste .
')';
1936 if (($showsoc > 0) && $obj->company) {
1937 $tmplabel .=
' - (' . $obj->company .
')';
1941 $out .=
'</option>';
1944 if (in_array($obj->rowid, $selected)) {
1945 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1946 if ($showfunction && $obj->poste) {
1947 $tmplabel .=
' (' . $obj->poste .
')';
1949 if (($showsoc > 0) && $obj->company) {
1950 $tmplabel .=
' - (' . $obj->company .
')';
1957 if ($tmplabel !=
'') {
1958 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $tmplabel,
'label' => $tmplabel,
'labelhtml' => $tmplabel));
1964 $labeltoshow = ($socid != -1) ? ($langs->trans($socid ?
"NoContactDefinedForThirdParty" :
"NoContactDefined")) : $langs->trans(
'SelectAThirdPartyFirst');
1965 $out .=
'<option class="disabled" value="-1"' . (($showempty == 2 || $multiple) ?
'' :
' selected') .
' disabled="disabled">';
1966 $out .= $labeltoshow;
1967 $out .=
'</option>';
1970 $parameters = array(
1972 'htmlname' => $htmlname,
1975 'showfunction' => $showfunction,
1976 'showsoc' => $showsoc,
1979 $reshook = $hookmanager->executeHooks(
'afterSelectContactOptions', $parameters, $this, $action);
1981 if ($htmlname !=
'none' && !$options_only) {
1982 $out .=
'</select>';
1985 if ($conf->use_javascript_ajax && !$forcecombo && !$options_only) {
1986 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1992 if ($options_only === 2) {
2020 global $langs, $conf;
2023 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
2024 $sql .=
" re.description, re.fk_facture_source";
2025 $sql .=
" FROM " . $this->db->prefix() .
"societe_remise_except as re";
2026 $sql .=
" WHERE re.fk_soc = " . (int) $socid;
2027 $sql .=
" AND re.entity = " . $conf->entity;
2029 $sql .=
" AND " . $filter;
2031 $sql .=
" ORDER BY re.description ASC";
2033 dol_syslog(get_class($this) .
"::select_remises", LOG_DEBUG);
2034 $resql = $this->db->query($sql);
2036 print
'<select id="select_' . $htmlname .
'" class="flat maxwidthonsmartphone" name="' . $htmlname .
'">';
2037 $num = $this->db->num_rows($resql);
2039 $qualifiedlines = $num;
2043 print
'<option value="0"> </option>';
2045 $obj = $this->db->fetch_object($resql);
2046 $desc =
dol_trunc($obj->description, 40);
2047 if (preg_match(
'/\(CREDIT_NOTE\)/', $desc)) {
2048 $desc = preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $desc);
2050 if (preg_match(
'/\(DEPOSIT\)/', $desc)) {
2051 $desc = preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"Deposit"), $desc);
2053 if (preg_match(
'/\(EXCESS RECEIVED\)/', $desc)) {
2054 $desc = preg_replace(
'/\(EXCESS RECEIVED\)/', $langs->trans(
"ExcessReceived"), $desc);
2056 if (preg_match(
'/\(EXCESS PAID\)/', $desc)) {
2057 $desc = preg_replace(
'/\(EXCESS PAID\)/', $langs->trans(
"ExcessPaid"), $desc);
2061 if ($selected > 0 && $selected == $obj->rowid) {
2062 $selectstring =
' selected';
2066 if ($maxvalue > 0 && $obj->amount_ttc > $maxvalue) {
2068 $disabled =
' disabled';
2071 if (
getDolGlobalString(
'MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST') && !empty($obj->fk_facture_source)) {
2072 $tmpfac =
new Facture($this->db);
2073 if ($tmpfac->fetch($obj->fk_facture_source) > 0) {
2074 $desc = $desc .
' - ' . $tmpfac->ref;
2078 print
'<option value="' . $obj->rowid .
'"' . $selectstring . $disabled .
'>' . $desc .
' (' .
price($obj->amount_ht) .
' ' . $langs->trans(
"HT") .
' - ' .
price($obj->amount_ttc) .
' ' . $langs->trans(
"TTC") .
')</option>';
2085 return $qualifiedlines;
2110 public function select_users($selected =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include =
'', $enableonly = array(), $force_entity =
'0')
2113 print $this->
select_dolusers($selected, $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity);
2142 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)
2145 global $conf, $user, $langs, $hookmanager;
2149 if ((is_numeric($selected) && ($selected < -2 || empty($selected))) && !
getDolGlobalString(
'SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE')) {
2150 $selected = $user->id;
2153 if ($selected ===
'') {
2154 $selected = array();
2155 } elseif (!is_array($selected)) {
2156 $selected = array($selected);
2159 $excludeUsers =
null;
2160 $includeUsers =
null;
2163 if (is_array($exclude)) {
2164 $excludeUsers = implode(
",", $exclude);
2167 if (is_array($include)) {
2168 $includeUsers = implode(
",", $include);
2169 } elseif ($include ==
'hierarchy') {
2171 $includeUsers = implode(
",", $user->getAllChildIds(0));
2172 } elseif ($include ==
'hierarchyme') {
2174 $includeUsers = implode(
",", $user->getAllChildIds(1));
2180 $outarray = array();
2181 $outarray2 = array();
2184 $showlabelofentity = isModEnabled(
'multicompany') && !
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE') && $conf->entity == 1 && !empty($user->admin) && empty($user->entity);
2185 $userissuperadminentityone = isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && empty($user->entity);
2188 $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";
2189 if ($showlabelofentity) {
2190 $sql .=
", e.label";
2192 $sql .=
" FROM " . $this->db->prefix() .
"user as u";
2193 if ($showlabelofentity) {
2194 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid = u.entity";
2197 if ($userissuperadminentityone && $force_entity !=
'default') {
2198 if (!empty($force_entity)) {
2199 $sql .=
" WHERE u.entity IN (0, " . $this->db->sanitize($force_entity) .
")";
2201 $sql .=
" WHERE u.entity IS NOT NULL";
2204 if (isModEnabled(
'multicompany') &&
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE')) {
2205 $sql .=
" WHERE u.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
2207 $sql .=
" WHERE u.entity IN (" .
getEntity(
'user') .
")";
2211 if (!empty($user->socid)) {
2212 $sql .=
" AND u.fk_soc = " . ((int) $user->socid);
2214 if (is_array($exclude) && $excludeUsers) {
2215 $sql .=
" AND u.rowid NOT IN (" . $this->db->sanitize($excludeUsers) .
")";
2217 if ($includeUsers) {
2218 $sql .=
" AND u.rowid IN (" . $this->db->sanitize($includeUsers) .
")";
2221 $sql .=
" AND u.statut <> 0";
2224 $sql .=
" AND u.employee <> 0";
2227 $sql .=
" AND u.fk_soc IS NULL";
2229 if (!empty($morefilter)) {
2230 $sql .=
" " . $morefilter;
2234 $reshook = $hookmanager->executeHooks(
'addSQLWhereFilterOnSelectUsers', array(), $this, $action);
2235 if (!empty($reshook)) {
2236 $sql .= $hookmanager->resPrint;
2240 $sql .=
" ORDER BY u.statut DESC, u.firstname ASC, u.lastname ASC";
2242 $sql .=
" ORDER BY u.statut DESC, u.lastname ASC, u.firstname ASC";
2245 dol_syslog(get_class($this) .
"::select_dolusers", LOG_DEBUG);
2247 $resql = $this->db->query($sql);
2249 $num = $this->db->num_rows($resql);
2253 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
' minwidth200') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
2254 if ($show_empty && !$multiple) {
2255 $textforempty =
' ';
2256 if (!empty($conf->use_javascript_ajax)) {
2257 $textforempty =
' ';
2259 if (!is_numeric($show_empty)) {
2260 $textforempty = $show_empty;
2262 $out .=
'<option class="optiongrey" value="' . ($show_empty < 0 ? $show_empty : -1) .
'"' . ((empty($selected) || in_array(-1, $selected)) ?
' selected' :
'') .
'>' . $textforempty .
'</option>' .
"\n";
2265 $out .=
'<option value="-2"' . ((in_array(-2, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Everybody") .
' --</option>' .
"\n";
2268 $userstatic =
new User($this->db);
2271 $obj = $this->db->fetch_object($resql);
2273 $userstatic->id = $obj->rowid;
2274 $userstatic->lastname = $obj->lastname;
2275 $userstatic->firstname = $obj->firstname;
2276 $userstatic->photo = $obj->photo;
2277 $userstatic->status = $obj->status;
2278 $userstatic->entity = $obj->entity;
2279 $userstatic->admin = $obj->admin;
2280 $userstatic->gender = $obj->gender;
2283 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
2284 $disableline = ($enableonlytext ? $enableonlytext :
'1');
2288 $labeltoshowhtml =
'';
2295 $labeltoshow .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2296 $labeltoshowhtml .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2297 if (empty($obj->firstname) && empty($obj->lastname)) {
2298 $labeltoshow .= $obj->login;
2299 $labeltoshowhtml .= $obj->login;
2306 $moreinfo .= ($moreinfo ?
' - ' :
' (');
2307 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(');
2308 $moreinfo .= $obj->login;
2309 $moreinfohtml .= $obj->login;
2311 if ($showstatus >= 0) {
2312 if ($obj->status == 1 && $showstatus == 1) {
2313 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Enabled');
2314 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Enabled');
2316 if ($obj->status == 0 && $showstatus == 1) {
2317 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Disabled');
2318 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Disabled');
2321 if ($showlabelofentity) {
2322 if (empty($obj->entity)) {
2323 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
"AllEntities");
2324 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
"AllEntities");
2326 if ($obj->entity != $conf->entity) {
2327 $moreinfo .= ($moreinfo ?
' - ' :
' (') . ($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2328 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(').($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2332 $moreinfo .= (!empty($moreinfo) ?
')' :
'');
2333 $moreinfohtml .= (!empty($moreinfohtml) ?
')</span>' :
'');
2334 if (!empty($disableline) && $disableline !=
'1') {
2336 $moreinfo .=
' - ' . $disableline;
2337 $moreinfohtml .=
' - ' . $disableline;
2339 $labeltoshow .= $moreinfo;
2340 $labeltoshowhtml .= $moreinfohtml;
2342 $out .=
'<option value="' . $obj->rowid .
'"';
2343 if (!empty($disableline)) {
2344 $out .=
' disabled';
2346 if ((!empty($selected[0]) && is_object($selected[0])) ? $selected[0]->id == $obj->rowid : in_array($obj->rowid, $selected)) {
2347 $out .=
' selected';
2349 $out .=
' data-html="';
2351 $outhtml = $userstatic->getNomUrl(-3,
'', 0, 1, 24, 1,
'login',
'', 1) .
' ';
2352 if ($showstatus >= 0 && $obj->status == 0) {
2353 $outhtml .=
'<strike class="opacitymediumxxx">';
2355 $outhtml .= $labeltoshowhtml;
2356 if ($showstatus >= 0 && $obj->status == 0) {
2357 $outhtml .=
'</strike>';
2359 $labeltoshowhtml = $outhtml;
2363 $out .= $labeltoshow;
2364 $out .=
'</option>';
2366 $outarray[$userstatic->id] = $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength) . $moreinfo;
2367 $outarray2[$userstatic->id] = array(
2368 'id' => $userstatic->id,
2369 'label' => $labeltoshow,
2370 'labelhtml' => $labeltoshowhtml,
2378 $out .=
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'" disabled>';
2379 $out .=
'<option value="">' . $langs->trans(
"None") .
'</option>';
2381 $out .=
'</select>';
2383 if ($num && !$forcecombo) {
2385 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2394 if ($outputmode == 2) {
2396 } elseif ($outputmode) {
2427 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())
2432 $userstatic =
new User($this->db);
2435 if (!empty($_SESSION[
'assignedtouser'])) {
2436 $assignedtouser = json_decode($_SESSION[
'assignedtouser'],
true);
2437 if (!is_array($assignedtouser)) {
2438 $assignedtouser = array();
2441 $assignedtouser = array();
2443 $nbassignetouser = count($assignedtouser);
2446 if ($nbassignetouser) {
2447 $out .=
'<ul class="attendees">';
2451 foreach ($assignedtouser as $key => $value) {
2452 if ($value[
'id'] == $ownerid) {
2457 $userstatic->fetch($value[
'id']);
2458 $out .= $userstatic->getNomUrl(-1);
2460 $ownerid = $value[
'id'];
2461 $out .=
' (' . $langs->trans(
"Owner") .
')';
2463 if ($nbassignetouser > 1 && $action !=
'view') {
2464 $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 .
'">';
2467 if ($showproperties) {
2468 if ($ownerid == $value[
'id'] && is_array($listofuserid) && count($listofuserid) && in_array($ownerid, array_keys($listofuserid))) {
2469 $out .=
'<div class="myavailability inline-block">';
2470 $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>';
2480 if ($nbassignetouser) {
2485 if ($action !=
'view') {
2486 $out .=
'<input type="hidden" class="removedassignedhidden" name="removedassigned" value="">';
2487 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
2488 $out .=
'jQuery(".removedassigned").click(function() { jQuery(".removedassignedhidden").val(jQuery(this).val()); });';
2489 $out .=
'jQuery(".assignedtouser").change(function() { console.log(jQuery(".assignedtouser option:selected").val());';
2490 $out .=
' if (jQuery(".assignedtouser option:selected").val() > 0) { jQuery("#' . $action .
'assignedtouser").attr("disabled", false); }';
2491 $out .=
' else { jQuery("#' . $action .
'assignedtouser").attr("disabled", true); }';
2493 $out .=
'})</script>';
2494 $out .= $this->
select_dolusers(
'', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter);
2495 $out .=
' <input type="submit" disabled class="button valignmiddle smallpaddingimp reposition" id="' . $action .
'assignedtouser" name="' . $action .
'assignedtouser" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
2522 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())
2527 require_once DOL_DOCUMENT_ROOT.
'/resource/class/html.formresource.class.php';
2528 require_once DOL_DOCUMENT_ROOT.
'/resource/class/dolresource.class.php';
2533 if (!empty($_SESSION[
'assignedtoresource'])) {
2534 $assignedtoresource = json_decode($_SESSION[
'assignedtoresource'],
true);
2535 if (!is_array($assignedtoresource)) {
2536 $assignedtoresource = array();
2539 $assignedtoresource = array();
2541 $nbassignetoresource = count($assignedtoresource);
2544 if ($nbassignetoresource) {
2545 $out .=
'<ul class="attendees">';
2549 foreach ($assignedtoresource as $key => $value) {
2551 $resourcestatic->fetch($value[
'id']);
2552 $out .= $resourcestatic->getNomUrl(-1);
2553 if ($nbassignetoresource > 1 && $action !=
'view') {
2554 $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 .
'">';
2557 if ($showproperties) {
2558 if (is_array($listofresourceid) && count($listofresourceid)) {
2559 $out .=
'<div class="myavailability inline-block">';
2560 $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>';
2570 if ($nbassignetoresource) {
2575 if ($action !=
'view') {
2576 $out .=
'<input type="hidden" class="removedassignedhidden" name="removedassignedresource" value="">';
2577 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
2578 $out .=
'jQuery(".removedassignedresource").click(function() { jQuery(".removedassignedresourcehidden").val(jQuery(this).val()); });';
2579 $out .=
'jQuery(".assignedtoresource").change(function() { console.log(jQuery(".assignedtoresource option:selected").val());';
2580 $out .=
' if (jQuery(".assignedtoresource option:selected").val() > 0) { jQuery("#' . $action .
'assignedtoresource").attr("disabled", false); }';
2581 $out .=
' else { jQuery("#' . $action .
'assignedtoresource").attr("disabled", true); }';
2583 $out .=
'})</script>';
2586 $out .=
img_picto(
'',
'resource',
'class="pictofixedwidth"');
2587 $out .= $formresources->select_resource_list(0, $htmlname, [], 1, 1, 0, $events, array(), 2, 0);
2589 $out .=
' <input type="submit" disabled class="button valignmiddle smallpaddingimp reposition" id="' . $action .
'assignedtoresource" name="' . $action .
'assignedtoresource" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
2626 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)
2629 global $langs, $conf;
2634 $price_level = (!empty($price_level) ? $price_level : 0);
2635 if (is_null($ajaxoptions)) {
2636 $ajaxoptions = array();
2639 if (strval($filtertype) ===
'' && (isModEnabled(
"product") || isModEnabled(
"service"))) {
2640 if (isModEnabled(
"product") && !isModEnabled(
'service')) {
2642 } elseif (!isModEnabled(
'product') && isModEnabled(
"service")) {
2647 if (!empty($conf->use_javascript_ajax) &&
getDolGlobalString(
'PRODUIT_USE_SEARCH_TO_SELECT')) {
2650 if ($selected && empty($selected_input_value)) {
2651 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
2652 $producttmpselect =
new Product($this->db);
2653 $producttmpselect->fetch($selected);
2654 $selected_input_value = $producttmpselect->ref;
2655 unset($producttmpselect);
2658 if ($filtertype ==
'') {
2659 if (!isModEnabled(
'product')) {
2661 } elseif (!isModEnabled(
'service')) {
2666 $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;
2667 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT .
'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
2669 if (isModEnabled(
'variants') && is_array($selected_combinations)) {
2673 <!-- script to auto show attributes select tags if a variant was selected -->
2674 <script nonce="' .
getNonce() .
'">
2675 // auto show attributes fields
2676 selected = ' . json_encode($selected_combinations) .
';
2679 jQuery(document).ready(function () {
2681 jQuery("input[name=\'prod_entry_mode\']").change(function () {
2682 if (jQuery(this).val() == \'free\') {
2683 jQuery(\'div#attributes_box\').empty();
2687 jQuery("input#' . $htmlname .
'").change(function () {
2689 if (!jQuery(this).val()) {
2690 jQuery(\'div#attributes_box\').empty();
2694 console.log("A change has started. We get variants fields to inject html select");
2696 jQuery.getJSON("' . DOL_URL_ROOT .
'/variants/ajax/getCombinations.php", {
2697 id: jQuery(this).val()
2698 }, function (data) {
2699 jQuery(\'div#attributes_box\').empty();
2701 jQuery.each(data, function (key, val) {
2703 combvalues[val.id] = val.values;
2705 var span = jQuery(document.createElement(\'div\')).css({
2706 \'display\': \'table-row\'
2710 jQuery(document.createElement(\'div\')).text(val.label).css({
2711 \'font-weight\': \'bold\',
2712 \'display\': \'table-cell\'
2716 var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({
2717 \'margin-left\': \'15px\',
2718 \'white-space\': \'pre\'
2720 jQuery(document.createElement(\'option\')).val(\'\')
2723 jQuery.each(combvalues[val.id], function (key, val) {
2724 var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value);
2726 if (selected[val.fk_product_attribute] == val.id) {
2727 tag.attr(\'selected\', \'selected\');
2734 jQuery(\'div#attributes_box\').append(span);
2739 ' . ($selected ?
'jQuery("input#' . $htmlname .
'").change();' :
'') .
'
2745 if (empty($hidelabel)) {
2746 $out .= $langs->trans(
"RefOrLabel") .
' : ';
2747 } elseif ($hidelabel > 1) {
2748 $placeholder =
' placeholder="' . $langs->trans(
"RefOrLabel") .
'"';
2749 if ($hidelabel == 2) {
2750 $out .=
img_picto($langs->trans(
"Search"),
'search');
2753 $out .=
'<input type="text" class="minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . $placeholder .
' ' . (
getDolGlobalString(
'PRODUCT_SEARCH_AUTOFOCUS') ?
'autofocus' :
'') .
' />';
2754 if ($hidelabel == 3) {
2755 $out .=
img_picto($langs->trans(
"Search"),
'search');
2758 $out .= $this->
select_produits_list($selected, $htmlname, $filtertype, $limit, $price_level,
'', $status, $finished, 0, $socid, $showempty, $forcecombo, $morecss, $hidepriceinlabel, $warehouseStatus, $status_purchase);
2761 if (empty($nooutput)) {
2785 public function select_bom($selected =
'', $htmlname =
'bom_id', $limit = 0, $status = 1, $type = 0, $showempty =
'1', $morecss =
'', $nooutput =
'', $forcecombo = 0, $TProducts = [])
2790 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
2796 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2801 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
2803 $sql =
'SELECT b.rowid, b.ref, b.label, b.fk_product';
2804 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'bom_bom as b';
2805 $sql .=
' WHERE b.entity IN (' .
getEntity(
'bom') .
')';
2806 if (!empty($status)) {
2807 $sql .=
' AND status = ' . (int) $status;
2809 if (!empty($type)) {
2810 $sql .=
' AND bomtype = ' . (int) $type;
2812 if (!empty($TProducts)) {
2813 $sql .=
' AND fk_product IN (' . $this->db->sanitize(implode(
',', $TProducts)) .
')';
2815 if (!empty($limit)) {
2816 $sql .=
' LIMIT ' . (int) $limit;
2818 $resql = $db->query($sql);
2821 $out .=
'<option value="-1"';
2822 if (empty($selected)) {
2823 $out .=
' selected';
2825 $out .=
'> </option>';
2827 while ($obj = $db->fetch_object($resql)) {
2829 $res = $product->fetch($obj->fk_product);
2830 $out .=
'<option value="' . $obj->rowid .
'"';
2831 if ($obj->rowid == $selected) {
2834 $out .=
'>' . $obj->ref .
' - ' . $product->label .
' - ' . $obj->label .
'</option>';
2840 $out .=
'</select>';
2841 if (empty($nooutput)) {
2875 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)
2879 global $hookmanager;
2882 $outarray = array();
2886 $langs->load(
'other');
2889 $warehouseStatusArray = array();
2890 if (!empty($warehouseStatus)) {
2891 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/entrepot.class.php';
2892 if (preg_match(
'/warehouseclosed/', $warehouseStatus)) {
2895 if (preg_match(
'/warehouseopen/', $warehouseStatus)) {
2898 if (preg_match(
'/warehouseinternal/', $warehouseStatus)) {
2903 $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";
2904 if (count($warehouseStatusArray)) {
2905 $selectFieldsGrouped =
", sum(" . $this->db->ifsql(
"e.statut IS NULL",
"0",
"ps.reel") .
") as stock";
2907 $selectFieldsGrouped =
", " . $this->db->ifsql(
"p.stock IS NULL", 0,
"p.stock") .
" AS stock";
2913 $parameters = array();
2914 $reshook = $hookmanager->executeHooks(
'selectProductsListSelect', $parameters);
2915 if (empty($reshook)) {
2916 $sql .= $selectFields.$selectFieldsGrouped.$hookmanager->resPrint;
2918 $sql .= $hookmanager->resPrint;
2923 $sql .=
", (SELECT " . $this->db->prefix() .
"categorie_product.fk_categorie
2924 FROM " . $this->db->prefix() .
"categorie_product
2925 WHERE " . $this->db->prefix() .
"categorie_product.fk_product=p.rowid
2927 ) AS categorie_product_id ";
2932 $sql .=
', pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,';
2933 $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';
2934 $selectFields .=
", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custdefault_vat_code, custref";
2938 $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";
2939 $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';
2944 $sql .=
", pl.label as label_translated";
2945 $sql .=
", pl.description as description_translated";
2946 $selectFields .=
", label_translated";
2947 $selectFields .=
", description_translated";
2951 $sql .=
", (SELECT pp.rowid FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
2952 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
2953 $sql .=
" AND price_level = " . ((int) $price_level);
2955 $sql .=
" ORDER BY date_price";
2956 $sql .=
" DESC LIMIT 1) as price_rowid";
2957 $sql .=
", (SELECT pp.price_by_qty FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
2958 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
2959 $sql .=
" AND price_level = " . ((int) $price_level);
2961 $sql .=
" ORDER BY date_price";
2962 $sql .=
" DESC LIMIT 1) as price_by_qty";
2963 $selectFields .=
", price_rowid, price_by_qty";
2966 $sql .=
" FROM ".$this->db->prefix().
"product as p";
2969 $sql .=
" USE INDEX (" . $this->db->sanitize(
getDolGlobalString(
'MAIN_PRODUCT_FORCE_INDEX')) .
")";
2973 $parameters = array();
2974 $reshook = $hookmanager->executeHooks(
'selectProductsListFrom', $parameters);
2975 $sql .= $hookmanager->resPrint;
2977 if (count($warehouseStatusArray)) {
2978 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_stock as ps on ps.fk_product = p.rowid";
2979 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entrepot as e on ps.fk_entrepot = e.rowid AND e.entity IN (" .
getEntity(
'stock') .
")";
2980 $sql .=
' AND e.statut IN (' . $this->db->sanitize($this->db->escape(implode(
',', $warehouseStatusArray))) .
')';
2985 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
2990 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_customer_price as pcp ON pcp.fk_soc=" . ((int) $socid) .
" AND pcp.fk_product=p.rowid";
2994 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
2998 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_lang as pl ON pl.fk_product = p.rowid ";
3000 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
3001 $soc =
new Societe($this->db);
3002 $result = $soc->fetch($socid);
3003 if ($result > 0 && !empty($soc->default_lang)) {
3004 $sql .=
" AND pl.lang = '" . $this->db->escape($soc->default_lang) .
"'";
3006 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3009 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3014 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_attribute_combination pac ON pac.fk_product_child = p.rowid";
3017 $sql .=
' WHERE p.entity IN (' .
getEntity(
'product') .
')';
3020 $sql .=
" AND pac.rowid IS NULL";
3023 if ($finished == 0) {
3024 $sql .=
" AND p.finished = " . ((int) $finished);
3025 } elseif ($finished == 1) {
3026 $sql .=
" AND p.finished = ".((int) $finished);
3029 $sql .=
" AND p.tosell = ".((int) $status);
3031 if ($status_purchase >= 0) {
3032 $sql .=
" AND p.tobuy = " . ((int) $status_purchase);
3035 if (strval($filtertype) !=
'') {
3036 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
3037 } elseif (!isModEnabled(
'product')) {
3038 $sql .=
" AND p.fk_product_type = 1";
3039 } elseif (!isModEnabled(
'service')) {
3040 $sql .=
" AND p.fk_product_type = 0";
3043 $parameters = array();
3044 $reshook = $hookmanager->executeHooks(
'selectProductsListWhere', $parameters);
3045 $sql .= $hookmanager->resPrint;
3047 if ($filterkey !=
'') {
3051 $search_crit = explode(
' ', $filterkey);
3053 if (count($search_crit) > 1) {
3056 foreach ($search_crit as $crit) {
3060 $sql .=
"(p.ref LIKE '" . $this->db->escape($prefix . $crit) .
"%' OR p.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3062 $sql .=
" OR pl.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3065 $sql .=
" OR pcp.ref_customer LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3068 $sql .=
" OR p.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3070 $sql .=
" OR pl.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3074 $sql .=
" OR pfp.ref_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3079 if (count($search_crit) > 1) {
3082 if (isModEnabled(
'barcode')) {
3083 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3087 if (count($warehouseStatusArray)) {
3088 $sql .=
" GROUP BY " . $selectFields;
3093 $sql .=
" ORDER BY categorie_product_id ";
3095 (
getDolGlobalInt(
'PRODUCT_SORT_BY_CATEGORY') == 1) ? $sql .=
"ASC" : $sql .=
"DESC";
3097 $sql .= $this->db->order(
"p.ref");
3100 $sql .= $this->db->plimit($limit, 0);
3103 dol_syslog(get_class($this) .
"::select_produits_list search products", LOG_DEBUG);
3104 $result = $this->db->query($sql);
3106 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3107 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3108 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
3110 $num = $this->db->num_rows($result);
3115 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3119 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
3125 if ($showempty && !is_numeric($showempty)) {
3126 $textifempty = $langs->trans($showempty);
3128 $textifempty .= $langs->trans(
"All");
3131 if ($showempty && !is_numeric($showempty)) {
3132 $textifempty = $langs->trans($showempty);
3136 $out .=
'<option value="-1" selected>' . ($textifempty ? $textifempty :
' ') .
'</option>';
3140 while ($num && $i < $num) {
3143 $objp = $this->db->fetch_object($result);
3145 if ((
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1) {
3146 $sql =
"SELECT rowid, quantity, price, unitprice, remise_percent, remise, price_base_type";
3147 $sql .=
" FROM " . $this->db->prefix() .
"product_price_by_qty";
3148 $sql .=
" WHERE fk_product_price = " . ((int) $objp->price_rowid);
3149 $sql .=
" ORDER BY quantity ASC";
3151 dol_syslog(get_class($this) .
"::select_produits_list search prices by qty", LOG_DEBUG);
3152 $result2 = $this->db->query($sql);
3154 $nb_prices = $this->db->num_rows($result2);
3156 while ($nb_prices && $j < $nb_prices) {
3157 $objp2 = $this->db->fetch_object($result2);
3159 $objp->price_by_qty_rowid = $objp2->rowid;
3160 $objp->price_by_qty_price_base_type = $objp2->price_base_type;
3161 $objp->price_by_qty_quantity = $objp2->quantity;
3162 $objp->price_by_qty_unitprice = $objp2->unitprice;
3163 $objp->price_by_qty_remise_percent = $objp2->remise_percent;
3165 $objp->quantity = $objp2->quantity;
3166 $objp->price = $objp2->price;
3167 $objp->unitprice = $objp2->unitprice;
3168 $objp->remise_percent = $objp2->remise_percent;
3181 array_push($outarray, $optJson);
3185 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_price_expression)) {
3186 $price_product =
new Product($this->db);
3187 $price_product->fetch($objp->rowid,
'',
'', 1);
3189 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3191 $price_result = $priceparser->parseProduct($price_product);
3192 if ($price_result >= 0) {
3193 $objp->price = $price_result;
3194 $objp->unitprice = $price_result;
3196 $objp->price_ttc = (float)
price2num($objp->price) * (1 + ($objp->tva_tx / 100));
3197 $objp->price_ttc =
price2num($objp->price_ttc,
'MU');
3206 array_push($outarray, $optJson);
3212 $out .=
'</select>';
3214 $this->db->free($result);
3216 if (empty($outputmode)) {
3243 protected function constructProductListOption(&$objp, &$opt, &$optJson, $price_level, $selected, $hidepriceinlabel = 0, $filterkey =
'', $novirtualstock = 0)
3245 global $langs, $conf, $user;
3246 global $hookmanager;
3252 $outlabel_translated =
'';
3254 $outdesc_translated =
'';
3260 $outpricebasetype =
'';
3262 $outdefault_vat_code =
'';
3266 $maxlengtharticle = (!
getDolGlobalString(
'PRODUCT_MAX_LENGTH_COMBO') ? 48 : $conf->global->PRODUCT_MAX_LENGTH_COMBO);
3268 $label = $objp->label;
3269 if (!empty($objp->label_translated)) {
3270 $label = $objp->label_translated;
3272 if (!empty($filterkey) && $filterkey !=
'') {
3273 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
3276 $outkey = $objp->rowid;
3277 $outref = $objp->ref;
3278 $outrefcust = empty($objp->custref) ?
'' : $objp->custref;
3279 $outlabel = $objp->label;
3280 $outdesc = $objp->description;
3282 $outlabel_translated = $objp->label_translated;
3283 $outdesc_translated = $objp->description_translated;
3285 $outbarcode = $objp->barcode;
3286 $outorigin = $objp->fk_country;
3287 $outpbq = empty($objp->price_by_qty_rowid) ?
'' : $objp->price_by_qty_rowid;
3289 $outtype = $objp->fk_product_type;
3294 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
3300 if (!empty($objp->unit_short)) {
3301 $outvalUnits .=
' - ' . $objp->unit_short;
3305 if (!empty($objp->weight) && $objp->weight_units !==
null) {
3307 $outvalUnits .=
' - ' . $unitToShow;
3309 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
3310 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
3311 $outvalUnits .=
' - ' . $unitToShow;
3313 if (!empty($objp->surface) && $objp->surface_units !==
null) {
3315 $outvalUnits .=
' - ' . $unitToShow;
3317 if (!empty($objp->volume) && $objp->volume_units !==
null) {
3319 $outvalUnits .=
' - ' . $unitToShow;
3322 if ($outdurationvalue && $outdurationunit) {
3324 'h' => $langs->trans(
'Hour'),
3325 'd' => $langs->trans(
'Day'),
3326 'w' => $langs->trans(
'Week'),
3327 'm' => $langs->trans(
'Month'),
3328 'y' => $langs->trans(
'Year')
3330 if (isset($da[$outdurationunit])) {
3331 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
3335 $opt =
'<option value="' . $objp->rowid .
'"';
3336 $opt .= ($objp->rowid == $selected) ?
' selected' :
'';
3337 if (!empty($objp->price_by_qty_rowid) && $objp->price_by_qty_rowid > 0) {
3338 $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 .
'"';
3341 if ($user->hasRight(
'stock',
'lire')) {
3342 if ($objp->stock > 0) {
3343 $opt .=
' class="product_line_stock_ok"';
3344 } elseif ($objp->stock <= 0) {
3345 $opt .=
' class="product_line_stock_too_low"';
3350 $opt .=
' data-labeltrans="' . $outlabel_translated .
'"';
3355 if (!empty($objp->custref)) {
3356 $opt .=
' (' . $objp->custref .
')';
3359 $opt .=
' (' . $outbarcode .
')';
3361 $opt .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3363 $opt .=
' (' .
getCountry($outorigin, 1) .
')';
3366 $objRef = $objp->ref;
3367 if (!empty($objp->custref)) {
3368 $objRef .=
' (' . $objp->custref .
')';
3370 if (!empty($filterkey) && $filterkey !=
'') {
3371 $objRef = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRef, 1);
3375 $outval .=
' (' . $outbarcode .
')';
3377 $outval .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3379 $outval .=
' (' .
getCountry($outorigin, 1) .
')';
3383 $opt .= $outvalUnits;
3384 $outval .= $outvalUnits;
3391 $sql =
"SELECT price, price_ttc, price_base_type, tva_tx, default_vat_code";
3392 $sql .=
" FROM " . $this->db->prefix() .
"product_price";
3393 $sql .=
" WHERE fk_product = " . ((int) $objp->rowid);
3394 $sql .=
" AND entity IN (" .
getEntity(
'productprice') .
")";
3395 $sql .=
" AND price_level = " . ((int) $price_level);
3396 $sql .=
" ORDER BY date_price DESC, rowid DESC";
3399 dol_syslog(get_class($this) .
'::constructProductListOption search price for product ' . $objp->rowid .
' AND level ' . $price_level, LOG_DEBUG);
3400 $result2 = $this->db->query($sql);
3402 $objp2 = $this->db->fetch_object($result2);
3405 if ($objp2->price_base_type ==
'HT') {
3406 $opt .=
' - ' .
price($objp2->price, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"HT");
3407 $outval .=
' - ' .
price($objp2->price, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"HT");
3409 $opt .=
' - ' .
price($objp2->price_ttc, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"TTC");
3410 $outval .=
' - ' .
price($objp2->price_ttc, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3412 $outprice_ht =
price($objp2->price);
3413 $outprice_ttc =
price($objp2->price_ttc);
3414 $outpricebasetype = $objp2->price_base_type;
3416 $outtva_tx = $objp2->tva_tx;
3417 $outdefault_vat_code = $objp2->default_vat_code;
3419 $outtva_tx = $objp->tva_tx;
3420 $outdefault_vat_code = $objp->default_vat_code;
3429 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1 && (
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
3431 $outqty = $objp->quantity;
3432 $outdiscount = $objp->remise_percent;
3433 if ($objp->quantity == 1) {
3434 $opt .=
' - ' .
price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency) .
"/";
3435 $outval .=
' - ' .
price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency) .
"/";
3436 $opt .= $langs->trans(
"Unit");
3437 $outval .= $langs->transnoentities(
"Unit");
3439 $opt .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1, $conf->currency) .
"/" . $objp->quantity;
3440 $outval .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1, $conf->currency) .
"/" . $objp->quantity;
3441 $opt .= $langs->trans(
"Units");
3442 $outval .= $langs->transnoentities(
"Units");
3445 $outprice_ht =
price($objp->unitprice);
3446 $outprice_ttc =
price($objp->unitprice * (1 + ($objp->tva_tx / 100)));
3447 $outpricebasetype = $objp->price_base_type;
3448 $outtva_tx = $objp->tva_tx;
3449 $outdefault_vat_code = $objp->default_vat_code;
3451 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1) {
3452 $opt .=
" (" .
price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency) .
"/" . $langs->trans(
"Unit") .
")";
3453 $outval .=
" (" .
price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency) .
"/" . $langs->transnoentities(
"Unit") .
")";
3455 if (empty($hidepriceinlabel) && !empty($objp->remise_percent) && $objp->remise_percent >= 1) {
3456 $opt .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3457 $outval .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3462 if (!empty($objp->idprodcustprice)) {
3465 if ($objp->custprice_base_type ==
'HT') {
3466 $opt .=
' - ' .
price($objp->custprice, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"HT");
3467 $outval .=
' - ' .
price($objp->custprice, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"HT");
3469 $opt .=
' - ' .
price($objp->custprice_ttc, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"TTC");
3470 $outval .=
' - ' .
price($objp->custprice_ttc, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3473 $outprice_ht =
price($objp->custprice);
3474 $outprice_ttc =
price($objp->custprice_ttc);
3475 $outpricebasetype = $objp->custprice_base_type;
3476 $outtva_tx = $objp->custtva_tx;
3477 $outdefault_vat_code = $objp->custdefault_vat_code;
3482 if (empty($hidepriceinlabel) && !$found) {
3483 if ($objp->price_base_type ==
'HT') {
3484 $opt .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"HT");
3485 $outval .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"HT");
3487 $opt .=
' - ' .
price($objp->price_ttc, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"TTC");
3488 $outval .=
' - ' .
price($objp->price_ttc, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3490 $outprice_ht =
price($objp->price);
3491 $outprice_ttc =
price($objp->price_ttc);
3492 $outpricebasetype = $objp->price_base_type;
3493 $outtva_tx = $objp->tva_tx;
3494 $outdefault_vat_code = $objp->default_vat_code;
3498 if ($user->hasRight(
'stock',
'lire')) {
3499 $opt .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'));
3501 if ($objp->stock > 0) {
3502 $outval .=
' - <span class="product_line_stock_ok">';
3503 } elseif ($objp->stock <= 0) {
3504 $outval .=
' - <span class="product_line_stock_too_low">';
3506 $outval .= $langs->transnoentities(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'));
3507 $outval .=
'</span>';
3508 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
3509 $langs->load(
"stocks");
3511 $tmpproduct =
new Product($this->db);
3512 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
3513 $tmpproduct->load_virtual_stock();
3514 $virtualstock = $tmpproduct->stock_theorique;
3516 $opt .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
3518 $outval .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
3519 if ($virtualstock > 0) {
3520 $outval .=
'<span class="product_line_stock_ok">';
3521 } elseif ($virtualstock <= 0) {
3522 $outval .=
'<span class="product_line_stock_too_low">';
3524 $outval .= $virtualstock;
3525 $outval .=
'</span>';
3532 $parameters = array(
'objp' => $objp);
3533 $reshook = $hookmanager->executeHooks(
'constructProductListOption', $parameters);
3534 if (empty($reshook)) {
3535 $opt .= $hookmanager->resPrint;
3537 $opt = $hookmanager->resPrint;
3540 $opt .=
"</option>\n";
3545 'label2' => $outlabel,
3549 'price_ttc' =>
price2num($outprice_ttc),
3552 'pricebasetype' => $outpricebasetype,
3553 'tva_tx' => $outtva_tx,
3554 'default_vat_code' => $outdefault_vat_code,
3556 'discount' => $outdiscount,
3557 'duration_value' => $outdurationvalue,
3558 'duration_unit' => $outdurationunit,
3560 'labeltrans' => $outlabel_translated,
3561 'desctrans' => $outdesc_translated,
3562 'ref_customer' => $outrefcust
3583 public function select_produits_fournisseurs($socid, $selected =
'', $htmlname =
'productid', $filtertype =
'', $filtre =
'', $ajaxoptions = array(), $hidelabel = 0, $alsoproductwithnosupplierprice = 0, $morecss =
'', $placeholder =
'')
3586 global $langs, $conf;
3587 global $price_level, $status, $finished;
3589 if (!isset($status)) {
3593 $selected_input_value =
'';
3594 if (!empty($conf->use_javascript_ajax) &&
getDolGlobalString(
'PRODUIT_USE_SEARCH_TO_SELECT')) {
3595 if ($selected > 0) {
3596 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3597 $producttmpselect =
new Product($this->db);
3598 $producttmpselect->fetch($selected);
3599 $selected_input_value = $producttmpselect->ref;
3600 unset($producttmpselect);
3604 $urloption = ($socid > 0 ?
'socid=' . $socid .
'&' :
'') .
'htmlname=' . $htmlname .
'&outjson=1&price_level=' . $price_level .
'&type=' . $filtertype .
'&mode=2&status=' . $status .
'&finished=' . $finished .
'&alsoproductwithnosupplierprice=' . $alsoproductwithnosupplierprice;
3607 print($hidelabel ?
'' : $langs->trans(
"RefOrLabel") .
' : ') .
'<input type="text" class="'.$morecss.
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . ($placeholder ?
' placeholder="' . $placeholder .
'"' :
'') .
'>';
3609 print $this->
select_produits_fournisseurs_list($socid, $selected, $htmlname, $filtertype, $filtre,
'', $status, 0, 0, $alsoproductwithnosupplierprice, $morecss, 0, $placeholder);
3633 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 =
'')
3636 global $langs, $conf, $user;
3637 global $hookmanager;
3640 $outarray = array();
3642 $maxlengtharticle = (!
getDolGlobalString(
'PRODUCT_MAX_LENGTH_COMBO') ? 48 : $conf->global->PRODUCT_MAX_LENGTH_COMBO);
3644 $langs->load(
'stocks');
3647 $langs->load(
'other');
3650 $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,";
3651 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice, pfp.barcode";
3652 if (isModEnabled(
'multicurrency')) {
3653 $sql .=
", pfp.multicurrency_code, pfp.multicurrency_unitprice";
3655 $sql .=
", pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.default_vat_code, pfp.fk_soc, s.nom as name";
3656 $sql .=
", pfp.supplier_reputation";
3659 $sql .=
", pfp.desc_fourn as description";
3661 $sql .=
", p.description";
3665 $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";
3667 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
3668 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN (" .
getEntity(
'product') .
") )";
3670 $sql .=
" AND pfp.fk_soc = " . ((int) $socid);
3672 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
3675 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
3677 $sql .=
" WHERE p.entity IN (" .
getEntity(
'product') .
")";
3678 if ($statut != -1) {
3679 $sql .=
" AND p.tobuy = " . ((int) $statut);
3681 if (strval($filtertype) !=
'') {
3682 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
3684 if (!empty($filtre)) {
3685 $sql .=
" " . $filtre;
3688 $parameters = array();
3689 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListWhere', $parameters);
3690 $sql .= $hookmanager->resPrint;
3692 if ($filterkey !=
'') {
3696 $search_crit = explode(
' ', $filterkey);
3698 if (count($search_crit) > 1) {
3701 foreach ($search_crit as $crit) {
3705 $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) .
"%'";
3707 $sql .=
" OR pfp.desc_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3712 if (count($search_crit) > 1) {
3715 if (isModEnabled(
'barcode')) {
3716 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3717 $sql .=
" OR pfp.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3721 $sql .=
" ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC";
3722 $sql .= $this->db->plimit($limit, 0);
3726 dol_syslog(get_class($this) .
"::select_produits_fournisseurs_list", LOG_DEBUG);
3727 $result = $this->db->query($sql);
3729 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3730 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
3732 $num = $this->db->num_rows($result);
3735 $out .=
'<select class="flat ' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'">';
3737 $out .=
'<option value="-1" selected>' . ($placeholder ? $placeholder :
' ') .
'</option>';
3739 $out .=
'<option value="-1">' . ($placeholder ? $placeholder :
' ') .
'</option>';
3744 $objp = $this->db->fetch_object($result);
3746 if (is_null($objp->idprodfournprice)) {
3748 $objp->tva_tx = $objp->tva_tx_sale;
3749 $objp->default_vat_code = $objp->default_vat_code_sale;
3752 $outkey = $objp->idprodfournprice;
3753 if (!$outkey && $alsoproductwithnosupplierprice) {
3754 $outkey =
'idprod_' . $objp->rowid;
3757 $outref = $objp->ref;
3758 $outbarcode = $objp->barcode;
3761 $outtype = $objp->fk_product_type;
3768 if (!empty($objp->unit_short)) {
3769 $outvalUnits .=
' - ' . $objp->unit_short;
3771 if (!empty($objp->weight) && $objp->weight_units !==
null) {
3773 $outvalUnits .=
' - ' . $unitToShow;
3775 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
3776 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
3777 $outvalUnits .=
' - ' . $unitToShow;
3779 if (!empty($objp->surface) && $objp->surface_units !==
null) {
3781 $outvalUnits .=
' - ' . $unitToShow;
3783 if (!empty($objp->volume) && $objp->volume_units !==
null) {
3785 $outvalUnits .=
' - ' . $unitToShow;
3787 if ($outdurationvalue && $outdurationunit) {
3789 'h' => $langs->trans(
'Hour'),
3790 'd' => $langs->trans(
'Day'),
3791 'w' => $langs->trans(
'Week'),
3792 'm' => $langs->trans(
'Month'),
3793 'y' => $langs->trans(
'Year')
3795 if (isset($da[$outdurationunit])) {
3796 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
3801 $objRef = $objp->ref;
3802 if ($filterkey && $filterkey !=
'') {
3803 $objRef = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRef, 1);
3805 $objRefFourn = $objp->ref_fourn;
3806 if ($filterkey && $filterkey !=
'') {
3807 $objRefFourn = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRefFourn, 1);
3809 $label = $objp->label;
3810 if ($filterkey && $filterkey !=
'') {
3811 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
3814 switch ($objp->fk_product_type) {
3826 if (empty($picto)) {
3829 $optlabel =
img_object(
'', $picto,
'class="paddingright classfortooltip"', 0, 0, 1);
3832 $optlabel .= $objp->ref;
3833 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
3834 $optlabel .=
' <span class="opacitymedium">(' . $objp->ref_fourn .
')</span>';
3836 if (isModEnabled(
'barcode') && !empty($objp->barcode)) {
3837 $optlabel .=
' (' . $outbarcode .
')';
3839 $optlabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3841 $outvallabel = $objRef;
3842 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
3843 $outvallabel .=
' (' . $objRefFourn .
')';
3845 if (isModEnabled(
'barcode') && !empty($objp->barcode)) {
3846 $outvallabel .=
' (' . $outbarcode .
')';
3848 $outvallabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3851 $optlabel .= $outvalUnits;
3852 $outvallabel .= $outvalUnits;
3854 if (!empty($objp->idprodfournprice)) {
3855 $outqty = $objp->quantity;
3856 $outdiscount = $objp->remise_percent;
3857 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
3859 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
3860 $prod_supplier->id = $objp->fk_product;
3861 $prod_supplier->fourn_qty = $objp->quantity;
3862 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
3863 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
3865 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3867 $price_result = $priceparser->parseProductSupplier($prod_supplier);
3868 if ($price_result >= 0) {
3869 $objp->fprice = $price_result;
3870 if ($objp->quantity >= 1) {
3871 $objp->unitprice = $objp->fprice / $objp->quantity;
3875 if ($objp->quantity == 1) {
3876 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency) .
"/";
3877 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1, $conf->currency) .
"/";
3878 $optlabel .= $langs->trans(
"Unit");
3879 $outvallabel .= $langs->transnoentities(
"Unit");
3881 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency) .
"/" . $objp->quantity;
3882 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1, $conf->currency) .
"/" . $objp->quantity;
3883 $optlabel .=
' ' . $langs->trans(
"Units");
3884 $outvallabel .=
' ' . $langs->transnoentities(
"Units");
3887 if ($objp->quantity > 1) {
3888 $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") .
")";
3889 $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") .
")";
3891 if ($objp->remise_percent >= 1) {
3892 $optlabel .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3893 $outvallabel .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3895 if ($objp->duration) {
3896 $optlabel .=
" - " . $objp->duration;
3897 $outvallabel .=
" - " . $objp->duration;
3900 $optlabel .=
" - " .
dol_trunc($objp->name, 8);
3901 $outvallabel .=
" - " .
dol_trunc($objp->name, 8);
3903 if ($objp->supplier_reputation) {
3905 $reputations = array(
'' => $langs->trans(
'Standard'),
'FAVORITE' => $langs->trans(
'Favorite'),
'NOTTHGOOD' => $langs->trans(
'NotTheGoodQualitySupplier'),
'DONOTORDER' => $langs->trans(
'DoNotOrderThisProductToThisSupplier'));
3907 $optlabel .=
" - " . $reputations[$objp->supplier_reputation];
3908 $outvallabel .=
" - " . $reputations[$objp->supplier_reputation];
3911 $optlabel .=
" - <span class='opacitymedium'>" . $langs->trans(
"NoPriceDefinedForThisSupplier") .
'</span>';
3912 $outvallabel .=
' - ' . $langs->transnoentities(
"NoPriceDefinedForThisSupplier");
3916 $novirtualstock = ($showstockinlist == 2);
3918 if ($user->hasRight(
'stock',
'lire')) {
3919 $outvallabel .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'));
3921 if ($objp->stock > 0) {
3922 $optlabel .=
' - <span class="product_line_stock_ok">';
3923 } elseif ($objp->stock <= 0) {
3924 $optlabel .=
' - <span class="product_line_stock_too_low">';
3926 $optlabel .= $langs->transnoentities(
"Stock") .
':' .
price(
price2num($objp->stock,
'MS'));
3927 $optlabel .=
'</span>';
3928 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
3929 $langs->load(
"stocks");
3931 $tmpproduct =
new Product($this->db);
3932 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
3933 $tmpproduct->load_virtual_stock();
3934 $virtualstock = $tmpproduct->stock_theorique;
3936 $outvallabel .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
3938 $optlabel .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
3939 if ($virtualstock > 0) {
3940 $optlabel .=
'<span class="product_line_stock_ok">';
3941 } elseif ($virtualstock <= 0) {
3942 $optlabel .=
'<span class="product_line_stock_too_low">';
3944 $optlabel .= $virtualstock;
3945 $optlabel .=
'</span>';
3952 $optstart =
'<option value="' . $outkey .
'"';
3953 if ($selected && $selected == $objp->idprodfournprice) {
3954 $optstart .=
' selected';
3956 if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) {
3957 $optstart .=
' disabled';
3960 if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) {
3969 $optstart .=
' data-default-vat-code="' .
dol_escape_htmltag($objp->default_vat_code) .
'"';
3971 if (isModEnabled(
'multicurrency')) {
3972 $optstart .=
' data-multicurrency-code="' .
dol_escape_htmltag($objp->multicurrency_code) .
'"';
3973 $optstart .=
' data-multicurrency-up="' .
dol_escape_htmltag($objp->multicurrency_unitprice) .
'"';
3976 $optstart .=
' data-description="' .
dol_escape_htmltag($objp->description, 0, 1) .
'"';
3978 $outarrayentry = array(
3981 'label' => $outvallabel,
3983 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
3984 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
3985 'price_ht' =>
price2num($objp->unitprice,
'MU'),
3986 'tva_tx_formated' =>
price($objp->tva_tx, 0, $langs, 1, -1, 2),
3988 'default_vat_code' => $objp->default_vat_code,
3989 'supplier_ref' => $objp->ref_fourn,
3990 'discount' => $outdiscount,
3992 'duration_value' => $outdurationvalue,
3993 'duration_unit' => $outdurationunit,
3994 'disabled' => empty($objp->idprodfournprice),
3995 'description' => $objp->description
3997 if (isModEnabled(
'multicurrency')) {
3998 $outarrayentry[
'multicurrency_code'] = $objp->multicurrency_code;
3999 $outarrayentry[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4002 $parameters = array(
4004 'optstart' => &$optstart,
4005 'optlabel' => &$optlabel,
4006 'outvallabel' => &$outvallabel,
4007 'outarrayentry' => &$outarrayentry
4009 $reshook = $hookmanager->executeHooks(
'selectProduitsFournisseurListOption', $parameters, $this);
4015 $out .= $optstart .
' data-html="' .
dol_escape_htmltag($optlabel) .
'">' . $optlabel .
"</option>\n";
4016 $outarraypush = array(
4019 'label' => $outvallabel,
4021 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4022 'price_qty_ht_locale' =>
price($objp->fprice),
4023 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4024 'price_unit_ht_locale' =>
price($objp->unitprice),
4025 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4026 'tva_tx_formated' =>
price($objp->tva_tx),
4028 'default_vat_code' => $objp->default_vat_code,
4029 'supplier_ref' => $objp->ref_fourn,
4030 'discount' => $outdiscount,
4032 'duration_value' => $outdurationvalue,
4033 'duration_unit' => $outdurationunit,
4034 'disabled' => empty($objp->idprodfournprice),
4035 'description' => $objp->description
4037 if (isModEnabled(
'multicurrency')) {
4038 $outarraypush[
'multicurrency_code'] = $objp->multicurrency_code;
4039 $outarraypush[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4041 array_push($outarray, $outarraypush);
4054 $out .=
'</select>';
4056 $this->db->free($result);
4058 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
4064 if (empty($outputmode)) {
4083 global $langs, $conf;
4085 $langs->load(
'stocks');
4087 $sql =
"SELECT p.rowid, p.ref, p.label, p.price, p.duration, pfp.fk_soc,";
4088 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.remise_percent, pfp.quantity, pfp.unitprice,";
4089 $sql .=
" pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name";
4090 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
4091 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
4092 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
4093 $sql .=
" WHERE pfp.entity IN (" .
getEntity(
'productsupplierprice') .
")";
4094 $sql .=
" AND p.tobuy = 1";
4095 $sql .=
" AND s.fournisseur = 1";
4096 $sql .=
" AND p.rowid = " . ((int) $productid);
4098 $sql .=
" ORDER BY s.nom, pfp.ref_fourn DESC";
4100 $sql .=
" ORDER BY pfp.unitprice ASC";
4103 dol_syslog(get_class($this) .
"::select_product_fourn_price", LOG_DEBUG);
4104 $result = $this->db->query($sql);
4107 $num = $this->db->num_rows($result);
4109 $form =
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
4112 $form .=
'<option value="0">-- ' . $langs->trans(
"NoSupplierPriceDefinedForThisProduct") .
' --</option>';
4114 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4115 $form .=
'<option value="0"> </option>';
4119 $objp = $this->db->fetch_object($result);
4121 $opt =
'<option value="' . $objp->idprodfournprice .
'"';
4123 if ($num == 1 || ($selected_supplier > 0 && $objp->fk_soc == $selected_supplier) || ($i == 0 &&
getDolGlobalString(
'PRODUCT_BEST_SUPPLIER_PRICE_PRESELECTED'))) {
4124 $opt .=
' selected';
4126 $opt .=
'>' . $objp->name .
' - ' . $objp->ref_fourn .
' - ';
4128 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
4130 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
4131 $prod_supplier->id = $productid;
4132 $prod_supplier->fourn_qty = $objp->quantity;
4133 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
4134 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
4136 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4138 $price_result = $priceparser->parseProductSupplier($prod_supplier);
4139 if ($price_result >= 0) {
4140 $objp->fprice = $price_result;
4141 if ($objp->quantity >= 1) {
4142 $objp->unitprice = $objp->fprice / $objp->quantity;
4146 if ($objp->quantity == 1) {
4147 $opt .=
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency) .
"/";
4150 $opt .= $objp->quantity .
' ';
4152 if ($objp->quantity == 1) {
4153 $opt .= $langs->trans(
"Unit");
4155 $opt .= $langs->trans(
"Units");
4157 if ($objp->quantity > 1) {
4159 $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");
4161 if ($objp->duration) {
4162 $opt .=
" - " . $objp->duration;
4164 $opt .=
"</option>\n";
4171 $form .=
'</select>';
4172 $this->db->free($result);
4192 $num = count($this->cache_conditions_paiements);
4199 $sql =
"SELECT rowid, code, libelle as label, deposit_percent";
4200 $sql .=
" FROM " . $this->db->prefix() .
'c_payment_term';
4201 $sql .=
" WHERE entity IN (" .
getEntity(
'c_payment_term') .
")";
4202 $sql .=
" AND active > 0";
4203 $sql .=
" ORDER BY sortorder";
4205 $resql = $this->db->query($sql);
4207 $num = $this->db->num_rows($resql);
4210 $obj = $this->db->fetch_object($resql);
4213 $label = ($langs->trans(
"PaymentConditionShort" . $obj->code) !=
"PaymentConditionShort" . $obj->code ? $langs->trans(
"PaymentConditionShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4214 $this->cache_conditions_paiements[$obj->rowid][
'code'] = $obj->code;
4215 $this->cache_conditions_paiements[$obj->rowid][
'label'] = $label;
4216 $this->cache_conditions_paiements[$obj->rowid][
'deposit_percent'] = $obj->deposit_percent;
4241 $num = count($this->cache_availability);
4248 $langs->load(
'propal');
4250 $sql =
"SELECT rowid, code, label, position";
4251 $sql .=
" FROM " . $this->db->prefix() .
'c_availability';
4252 $sql .=
" WHERE active > 0";
4254 $resql = $this->db->query($sql);
4256 $num = $this->db->num_rows($resql);
4259 $obj = $this->db->fetch_object($resql);
4262 $label = ($langs->trans(
"AvailabilityType" . $obj->code) !=
"AvailabilityType" . $obj->code ? $langs->trans(
"AvailabilityType" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4263 $this->cache_availability[$obj->rowid][
'code'] = $obj->code;
4264 $this->cache_availability[$obj->rowid][
'label'] = $label;
4265 $this->cache_availability[$obj->rowid][
'position'] = $obj->position;
4269 $this->cache_availability =
dol_sort_array($this->cache_availability,
'position',
'asc', 0, 0, 1);
4290 global $langs, $user;
4294 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
4296 print
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4298 print
'<option value="0"> </option>';
4300 foreach ($this->cache_availability as $id => $arrayavailability) {
4301 if ($selected == $id) {
4302 print
'<option value="' . $id .
'" selected>';
4304 print
'<option value="' . $id .
'">';
4311 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4325 $num = count($this->cache_demand_reason);
4330 $sql =
"SELECT rowid, code, label";
4331 $sql .=
" FROM " . $this->db->prefix() .
'c_input_reason';
4332 $sql .=
" WHERE active > 0";
4334 $resql = $this->db->query($sql);
4336 $num = $this->db->num_rows($resql);
4338 $tmparray = array();
4340 $obj = $this->db->fetch_object($resql);
4343 $label = ($obj->label !=
'-' ? $obj->label :
'');
4344 if ($langs->trans(
"DemandReasonType" . $obj->code) !=
"DemandReasonType" . $obj->code) {
4345 $label = $langs->trans(
"DemandReasonType" . $obj->code);
4347 if ($langs->trans($obj->code) != $obj->code) {
4348 $label = $langs->trans($obj->code);
4351 $tmparray[$obj->rowid][
'id'] = $obj->rowid;
4352 $tmparray[$obj->rowid][
'code'] = $obj->code;
4353 $tmparray[$obj->rowid][
'label'] = $label;
4357 $this->cache_demand_reason =
dol_sort_array($tmparray,
'label',
'asc', 0, 0, 1);
4379 public function selectInputReason($selected =
'', $htmlname =
'demandreasonid', $exclude =
'', $addempty = 0, $morecss =
'', $notooltip = 0)
4381 global $langs, $user;
4385 print
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
4387 print
'<option value="0"' . (empty($selected) ?
' selected' :
'') .
'> </option>';
4389 foreach ($this->cache_demand_reason as $id => $arraydemandreason) {
4390 if ($arraydemandreason[
'code'] == $exclude) {
4394 if ($selected && ($selected == $arraydemandreason[
'id'] || $selected == $arraydemandreason[
'code'])) {
4395 print
'<option value="' . $arraydemandreason[
'id'] .
'" selected>';
4397 print
'<option value="' . $arraydemandreason[
'id'] .
'">';
4399 $label = $arraydemandreason[
'label'];
4400 print $langs->trans($label);
4404 if ($user->admin && empty($notooltip)) {
4405 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4422 $num = count($this->cache_types_paiements);
4429 $this->cache_types_paiements = array();
4431 $sql =
"SELECT id, code, libelle as label, type, active";
4432 $sql .=
" FROM " . $this->db->prefix() .
"c_paiement";
4433 $sql .=
" WHERE entity IN (" .
getEntity(
'c_paiement') .
")";
4435 $resql = $this->db->query($sql);
4437 $num = $this->db->num_rows($resql);
4440 $obj = $this->db->fetch_object($resql);
4443 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) !=
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4444 $this->cache_types_paiements[$obj->id][
'id'] = $obj->id;
4445 $this->cache_types_paiements[$obj->id][
'code'] = $obj->code;
4446 $this->cache_types_paiements[$obj->id][
'label'] = $label;
4447 $this->cache_types_paiements[$obj->id][
'type'] = $obj->type;
4448 $this->cache_types_paiements[$obj->id][
'active'] = $obj->active;
4452 $this->cache_types_paiements =
dol_sort_array($this->cache_types_paiements,
'label',
'asc', 0, 0, 1);
4482 public function select_conditions_paiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1, $noprint = 0)
4486 if (empty($noprint)) {
4510 public function getSelectConditionsPaiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1)
4512 global $langs, $user, $conf;
4515 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
4521 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TERM_ID", LOG_NOTICE);
4525 $out .=
'<select id="' . $htmlname .
'" class="flat selectpaymentterms' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4527 $out .=
'<option value="0"> </option>';
4530 $selectedDepositPercent =
null;
4532 foreach ($this->cache_conditions_paiements as $id => $arrayconditions) {
4533 if ($filtertype <= 0 && !empty($arrayconditions[
'deposit_percent'])) {
4537 if ($selected == $id) {
4538 $selectedDepositPercent = $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'];
4539 $out .=
'<option value="' . $id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'" selected>';
4541 $out .=
'<option value="' . $id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'">';
4543 $label = $arrayconditions[
'label'];
4545 if (!empty($arrayconditions[
'deposit_percent'])) {
4546 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'], $label);
4550 $out .=
'</option>';
4552 $out .=
'</select>';
4553 if ($user->admin && empty($noinfoadmin)) {
4554 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4558 if ($deposit_percent >= 0) {
4559 $out .=
' <span id="' . $htmlname .
'_deposit_percent_container"' . (empty($selectedDepositPercent) ?
' style="display: none"' :
'') .
'>';
4560 $out .= $langs->trans(
'DepositPercent') .
' : ';
4561 $out .=
'<input id="' . $htmlname .
'_deposit_percent" name="' . $htmlname .
'_deposit_percent" class="maxwidth50" value="' . $deposit_percent .
'" />';
4564 <script nonce="' .
getNonce() .
'">
4565 $(document).ready(function () {
4566 $("#' . $htmlname .
'").change(function () {
4567 let $selected = $(this).find("option:selected");
4568 let depositPercent = $selected.attr("data-deposit_percent");
4570 if (depositPercent.length > 0) {
4571 $("#' . $htmlname .
'_deposit_percent_container").show().find("#' . $htmlname .
'_deposit_percent").val(depositPercent);
4573 $("#' . $htmlname .
'_deposit_percent_container").hide();
4604 public function select_types_paiements($selected =
'', $htmlname =
'paiementtype', $filtertype =
'', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'', $nooutput = 0)
4607 global $langs, $user, $conf;
4611 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $filtertype .
", " . $format, LOG_DEBUG);
4613 $filterarray = array();
4614 if ($filtertype ==
'CRDT') {
4615 $filterarray = array(0, 2, 3);
4616 } elseif ($filtertype ==
'DBIT') {
4617 $filterarray = array(1, 2, 3);
4618 } elseif ($filtertype !=
'' && $filtertype !=
'-1') {
4619 $filterarray = explode(
',', $filtertype);
4626 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TYPE_ID", LOG_NOTICE);
4630 $out .=
'<select id="select' . $htmlname .
'" class="flat selectpaymenttypes' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4632 $out .=
'<option value=""> </option>';
4634 foreach ($this->cache_types_paiements as $id => $arraytypes) {
4636 if ($active >= 0 && $arraytypes[
'active'] != $active) {
4641 if (count($filterarray) && !in_array($arraytypes[
'type'], $filterarray)) {
4646 if ($empty && empty($arraytypes[
'code'])) {
4651 $out .=
'<option value="' . $id .
'"';
4652 } elseif ($format == 1) {
4653 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
4654 } elseif ($format == 2) {
4655 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
4656 } elseif ($format == 3) {
4657 $out .=
'<option value="' . $id .
'"';
4660 if ($format == 1 || $format == 2) {
4661 if ($selected == $arraytypes[
'code']) {
4662 $out .=
' selected';
4665 if ($selected == $id) {
4666 $out .=
' selected';
4672 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4673 } elseif ($format == 1) {
4674 $value = $arraytypes[
'code'];
4675 } elseif ($format == 2) {
4676 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4677 } elseif ($format == 3) {
4678 $value = $arraytypes[
'code'];
4680 $out .= $value ? $value :
' ';
4681 $out .=
'</option>';
4683 $out .=
'</select>';
4684 if ($user->admin && !$noadmininfo) {
4685 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4689 if (empty($nooutput)) {
4709 $return =
'<select class="flat maxwidth100" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
4711 'HT' => $langs->trans(
"HT"),
4712 'TTC' => $langs->trans(
"TTC")
4714 foreach ($options as $id => $value) {
4715 if ($selected == $id) {
4716 $return .=
'<option value="' . $id .
'" selected>' . $value;
4718 $return .=
'<option value="' . $id .
'">' . $value;
4720 $return .=
'</option>';
4722 $return .=
'</select>';
4742 $num = count($this->cache_transport_mode);
4749 $this->cache_transport_mode = array();
4751 $sql =
"SELECT rowid, code, label, active";
4752 $sql .=
" FROM " . $this->db->prefix() .
"c_transport_mode";
4753 $sql .=
" WHERE entity IN (" .
getEntity(
'c_transport_mode') .
")";
4755 $resql = $this->db->query($sql);
4757 $num = $this->db->num_rows($resql);
4760 $obj = $this->db->fetch_object($resql);
4763 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) !=
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4764 $this->cache_transport_mode[$obj->rowid][
'rowid'] = $obj->rowid;
4765 $this->cache_transport_mode[$obj->rowid][
'code'] = $obj->code;
4766 $this->cache_transport_mode[$obj->rowid][
'label'] = $label;
4767 $this->cache_transport_mode[$obj->rowid][
'active'] = $obj->active;
4771 $this->cache_transport_mode =
dol_sort_array($this->cache_transport_mode,
'label',
'asc', 0, 0, 1);
4793 public function selectTransportMode($selected =
'', $htmlname =
'transportmode', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'')
4795 global $langs, $user;
4797 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $format, LOG_DEBUG);
4801 print
'<select id="select' . $htmlname .
'" class="flat selectmodetransport' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4803 print
'<option value=""> </option>';
4805 foreach ($this->cache_transport_mode as $id => $arraytypes) {
4807 if ($active >= 0 && $arraytypes[
'active'] != $active) {
4812 if ($empty && empty($arraytypes[
'code'])) {
4817 print
'<option value="' . $id .
'"';
4818 } elseif ($format == 1) {
4819 print
'<option value="' . $arraytypes[
'code'] .
'"';
4820 } elseif ($format == 2) {
4821 print
'<option value="' . $arraytypes[
'code'] .
'"';
4822 } elseif ($format == 3) {
4823 print
'<option value="' . $id .
'"';
4826 if (preg_match(
'/[a-z]/i', $selected) && $selected == $arraytypes[
'code']) {
4828 } elseif ($selected == $id) {
4834 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4835 } elseif ($format == 1) {
4836 $value = $arraytypes[
'code'];
4837 } elseif ($format == 2) {
4838 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4839 } elseif ($format == 3) {
4840 $value = $arraytypes[
'code'];
4842 print $value ? $value :
' ';
4846 if ($user->admin && !$noadmininfo) {
4847 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4863 public function selectShippingMethod($selected =
'', $htmlname =
'shipping_method_id', $filtre =
'', $useempty = 0, $moreattrib =
'', $noinfoadmin = 0, $morecss =
'')
4865 global $langs, $user;
4867 $langs->load(
"admin");
4868 $langs->load(
"deliveries");
4870 $sql =
"SELECT rowid, code, libelle as label";
4871 $sql .=
" FROM " . $this->db->prefix() .
"c_shipment_mode";
4872 $sql .=
" WHERE active > 0";
4874 $sql .=
" AND " . $filtre;
4876 $sql .=
" ORDER BY libelle ASC";
4878 dol_syslog(get_class($this) .
"::selectShippingMode", LOG_DEBUG);
4879 $result = $this->db->query($sql);
4881 $num = $this->db->num_rows($result);
4884 print
'<select id="select' . $htmlname .
'" class="flat selectshippingmethod' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
4885 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
4886 print
'<option value="-1"> </option>';
4889 $obj = $this->db->fetch_object($result);
4890 if ($selected == $obj->rowid) {
4891 print
'<option value="' . $obj->rowid .
'" selected>';
4893 print
'<option value="' . $obj->rowid .
'">';
4895 print ($langs->trans(
"SendingMethod" . strtoupper($obj->code)) !=
"SendingMethod" . strtoupper($obj->code)) ? $langs->trans(
"SendingMethod" . strtoupper($obj->code)) : $obj->label;
4900 if ($user->admin && empty($noinfoadmin)) {
4901 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4906 print $langs->trans(
"NoShippingMethodDefined");
4926 $langs->load(
"deliveries");
4928 if ($htmlname !=
"none") {
4929 print
'<form method="POST" action="' . $page .
'">';
4930 print
'<input type="hidden" name="action" value="setshippingmethod">';
4931 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
4933 print
'<input type="submit" class="button valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
4937 $code = $langs->getLabelFromKey($this->db, $selected,
'c_shipment_mode',
'rowid',
'code');
4938 print $langs->trans(
"SendingMethod" . strtoupper($code));
4957 $langs->load(
'bills');
4959 $opt =
'<option value="" selected></option>';
4960 $sql =
"SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc";
4961 $sql .=
' FROM ' . $this->db->prefix() .
'facture';
4962 $sql .=
' WHERE entity IN (' .
getEntity(
'invoice') .
')';
4963 $sql .=
' AND situation_counter >= 1';
4964 $sql .=
' AND fk_soc = ' . (int) $socid;
4965 $sql .=
' AND type <> 2';
4966 $sql .=
' ORDER by situation_cycle_ref, situation_counter desc';
4967 $resql = $this->db->query($sql);
4969 if ($resql && $this->db->num_rows($resql) > 0) {
4972 while ($obj = $this->db->fetch_object($resql)) {
4974 if ($obj->situation_cycle_ref != $ref) {
4976 $ref = $obj->situation_cycle_ref;
4978 if ($obj->situation_final != 1) {
4980 if (substr($obj->ref, 1, 4) !=
'PROV') {
4981 if ($selected == $obj->rowid) {
4982 $opt .=
'<option value="' . $obj->rowid .
'" selected>' . $obj->ref .
'</option>';
4984 $opt .=
'<option value="' . $obj->rowid .
'">' . $obj->ref .
'</option>';
4991 dol_syslog(
"Error sql=" . $sql .
", error=" . $this->error, LOG_ERR);
4993 if ($opt ==
'<option value ="" selected></option>') {
4994 $opt =
'<option value ="0" selected>' . $langs->trans(
'NoSituations') .
'</option>';
5008 public function selectUnits($selected =
'', $htmlname =
'units', $showempty = 0, $unit_type =
'')
5012 $langs->load(
'products');
5014 $return =
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'">';
5016 $sql =
"SELECT rowid, label, code FROM " . $this->db->prefix() .
"c_units";
5017 $sql .=
' WHERE active > 0';
5018 if (!empty($unit_type)) {
5019 $sql .=
" AND unit_type = '" . $this->db->escape($unit_type) .
"'";
5021 $sql .=
" ORDER BY sortorder";
5023 $resql = $this->db->query($sql);
5024 if ($resql && $this->db->num_rows($resql) > 0) {
5026 $return .=
'<option value="none"></option>';
5029 while ($res = $this->db->fetch_object($resql)) {
5030 $unitLabel = $res->label;
5031 if (!empty($langs->tab_translate[
'unit' . $res->code])) {
5032 $unitLabel = $langs->trans(
'unit' . $res->code) != $res->label ? $langs->trans(
'unit' . $res->code) : $res->label;
5035 if ($selected == $res->rowid) {
5036 $return .=
'<option value="' . $res->rowid .
'" selected>' . $unitLabel .
'</option>';
5038 $return .=
'<option value="' . $res->rowid .
'">' . $unitLabel .
'</option>';
5041 $return .=
'</select>';
5062 public function select_comptes($selected =
'', $htmlname =
'accountid', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'', $showcurrency = 0, $morecss =
'', $nooutput = 0)
5069 $langs->load(
"admin");
5072 $sql =
"SELECT rowid, label, bank, clos as status, currency_code";
5073 $sql .=
" FROM " . $this->db->prefix() .
"bank_account";
5074 $sql .=
" WHERE entity IN (" .
getEntity(
'bank_account') .
")";
5076 $sql .=
" AND clos = " . (int) $status;
5079 $sql .=
" AND " . $filtre;
5081 $sql .=
" ORDER BY label";
5083 dol_syslog(get_class($this) .
"::select_comptes", LOG_DEBUG);
5084 $result = $this->db->query($sql);
5086 $num = $this->db->num_rows($result);
5089 $out .=
'<select id="select' . $htmlname .
'" class="flat selectbankaccount' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5091 if (!empty($useempty) && !is_numeric($useempty)) {
5092 $out .=
'<option value="-1">'.$langs->trans($useempty).
'</option>';
5093 } elseif ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5094 $out .=
'<option value="-1"> </option>';
5098 $obj = $this->db->fetch_object($result);
5099 if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
5100 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'" selected>';
5102 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'">';
5104 $out .= trim($obj->label);
5105 if ($showcurrency) {
5106 $out .=
' (' . $obj->currency_code .
')';
5108 if ($status == 2 && $obj->status == 1) {
5109 $out .=
' (' . $langs->trans(
"Closed") .
')';
5111 $out .=
'</option>';
5114 $out .=
"</select>";
5118 $out .=
'<span class="opacitymedium">' . $langs->trans(
"NoActiveBankAccountDefined") .
'</span>';
5120 $out .=
'<span class="opacitymedium">' . $langs->trans(
"NoBankAccountFound") .
'</span>';
5128 if (empty($nooutput)) {
5148 public function selectEstablishments($selected =
'', $htmlname =
'entity', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'')
5152 $langs->load(
"admin");
5155 $sql =
"SELECT rowid, name, fk_country, status, entity";
5156 $sql .=
" FROM " . $this->db->prefix() .
"establishment";
5157 $sql .=
" WHERE 1=1";
5159 $sql .=
" AND status = " . (int) $status;
5162 $sql .=
" AND " . $filtre;
5164 $sql .=
" ORDER BY name";
5166 dol_syslog(get_class($this) .
"::select_establishment", LOG_DEBUG);
5167 $result = $this->db->query($sql);
5169 $num = $this->db->num_rows($result);
5172 print
'<select id="select' . $htmlname .
'" class="flat selectestablishment" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5173 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5174 print
'<option value="-1"> </option>';
5178 $obj = $this->db->fetch_object($result);
5179 if ($selected == $obj->rowid) {
5180 print
'<option value="' . $obj->rowid .
'" selected>';
5182 print
'<option value="' . $obj->rowid .
'">';
5184 print trim($obj->name);
5185 if ($status == 2 && $obj->status == 1) {
5186 print
' (' . $langs->trans(
"Closed") .
')';
5194 print
'<span class="opacitymedium">' . $langs->trans(
"NoActiveEstablishmentDefined") .
'</span>';
5196 print
'<span class="opacitymedium">' . $langs->trans(
"NoEstablishmentFound") .
'</span>';
5219 if ($htmlname !=
"none") {
5220 print
'<form method="POST" action="' . $page .
'">';
5221 print
'<input type="hidden" name="action" value="setbankaccount">';
5222 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5223 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
5224 $nbaccountfound = $this->
select_comptes($selected, $htmlname, 0,
'', $addempty);
5225 if ($nbaccountfound > 0) {
5226 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5230 $langs->load(
'banks');
5233 require_once DOL_DOCUMENT_ROOT .
'/compta/bank/class/account.class.php';
5234 $bankstatic =
new Account($this->db);
5235 $result = $bankstatic->fetch($selected);
5237 print $bankstatic->getNomUrl(1);
5266 public function select_all_categories($type, $selected =
'', $htmlname =
"parent", $maxlength = 64, $fromid = 0, $outputmode = 0, $include = 0, $morecss =
'', $useempty = 1)
5269 global $conf, $langs;
5270 $langs->load(
"categories");
5272 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
5275 if (is_numeric($type)) {
5276 dol_syslog(__METHOD__ .
': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING);
5279 if ($type === Categorie::TYPE_BANK_LINE) {
5281 $cate_arbo = array();
5282 $sql =
"SELECT c.label, c.rowid";
5283 $sql .=
" FROM " . $this->db->prefix() .
"bank_categ as c";
5284 $sql .=
" WHERE entity = " . $conf->entity;
5285 $sql .=
" ORDER BY c.label";
5286 $result = $this->db->query($sql);
5288 $num = $this->db->num_rows($result);
5291 $objp = $this->db->fetch_object($result);
5293 $cate_arbo[$objp->rowid] = array(
'id' => $objp->rowid,
'fulllabel' => $objp->label,
'color' =>
'',
'picto' =>
'category');
5297 $this->db->free($result);
5303 $cate_arbo = $cat->get_full_arbo($type, $fromid, $include);
5306 $outarray = array();
5307 $outarrayrichhtml = array();
5310 $output =
'<select class="flat minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
5311 if (is_array($cate_arbo)) {
5312 $num = count($cate_arbo);
5315 $output .=
'<option value="-1" disabled>' . $langs->trans(
"NoCategoriesDefined") .
'</option>';
5317 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5318 $output .=
'<option value="-1"> </option>';
5320 foreach ($cate_arbo as $key => $value) {
5321 if ($cate_arbo[$key][
'id'] == $selected || ($selected ===
'auto' && count($cate_arbo) == 1)) {
5327 $labeltoshow =
img_picto(
'',
'category',
'class="pictofixedwidth" style="color: #' . $cate_arbo[$key][
'color'] .
'"');
5328 $labeltoshow .=
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle');
5330 $outarray[$cate_arbo[$key][
'id']] = $cate_arbo[$key][
'fulllabel'];
5332 $outarrayrichhtml[$cate_arbo[$key][
'id']] = $labeltoshow;
5334 $output .=
'<option ' . $add .
'value="' . $cate_arbo[$key][
'id'] .
'"';
5337 $output .=
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle');
5338 $output .=
'</option>';
5340 $cate_arbo[$key][
'data-html'] = $labeltoshow;
5344 $output .=
'</select>';
5347 if ($outputmode == 2) {
5350 } elseif ($outputmode == 1) {
5352 } elseif ($outputmode == 3) {
5353 return $outarrayrichhtml;
5376 public function form_confirm($page, $title, $question, $action, $formquestion = array(), $selectedchoice =
"", $useajax = 0, $height = 170, $width = 500)
5379 dol_syslog(__METHOD__ .
': using form_confirm is deprecated. Use formconfim instead.', LOG_WARNING);
5380 print $this->
formconfirm($page, $title, $question, $action, $formquestion, $selectedchoice, $useajax, $height, $width);
5410 public function formconfirm($page, $title, $question, $action, $formquestion =
'', $selectedchoice =
'', $useajax = 0, $height = 0, $width = 500, $disableformtag = 0, $labelbuttonyes =
'Yes', $labelbuttonno =
'No')
5412 global $langs, $conf;
5414 $more =
'<!-- formconfirm - before call, page=' .
dol_escape_htmltag($page) .
' -->';
5420 $newselectedchoice = empty($selectedchoice) ?
"no" : $selectedchoice;
5421 if ($conf->browser->layout ==
'phone') {
5426 if (empty($height)) {
5428 if (is_array($formquestion) && count($formquestion) > 2) {
5429 $height += ((count($formquestion) - 2) * 24);
5433 if (is_array($formquestion) && !empty($formquestion)) {
5435 foreach ($formquestion as $key => $input) {
5436 if (is_array($input) && !empty($input)) {
5437 if ($input[
'type'] ==
'hidden') {
5438 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
5439 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
5447 $moreonecolumn =
'';
5448 $more .=
'<div class="tagtable paddingtopbottomonly centpercent noborderspacing">' .
"\n";
5449 foreach ($formquestion as $key => $input) {
5450 if (is_array($input) && !empty($input)) {
5451 $size = (!empty($input[
'size']) ?
' size="' . $input[
'size'] .
'"' :
'');
5452 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
5453 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
5455 if ($input[
'type'] ==
'text') {
5456 $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";
5457 } elseif ($input[
'type'] ==
'password') {
5458 $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";
5459 } elseif ($input[
'type'] ==
'textarea') {
5465 $moreonecolumn .=
'<div class="margintoponly">';
5466 $moreonecolumn .= $input[
'label'] .
'<br>';
5468 $moreonecolumn .= $input[
'value'];
5469 $moreonecolumn .=
'</textarea>';
5470 $moreonecolumn .=
'</div>';
5471 } elseif (in_array($input[
'type'], [
'select',
'multiselect'])) {
5472 if (empty($morecss)) {
5473 $morecss =
'minwidth100';
5476 $show_empty = isset($input[
'select_show_empty']) ? $input[
'select_show_empty'] : 1;
5477 $key_in_label = isset($input[
'select_key_in_label']) ? $input[
'select_key_in_label'] : 0;
5478 $value_as_key = isset($input[
'select_value_as_key']) ? $input[
'select_value_as_key'] : 0;
5479 $translate = isset($input[
'select_translate']) ? $input[
'select_translate'] : 0;
5480 $maxlen = isset($input[
'select_maxlen']) ? $input[
'select_maxlen'] : 0;
5481 $disabled = isset($input[
'select_disabled']) ? $input[
'select_disabled'] : 0;
5482 $sort = isset($input[
'select_sort']) ? $input[
'select_sort'] :
'';
5484 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">';
5485 if (!empty($input[
'label'])) {
5486 $more .= $input[
'label'] .
'</div><div class="tagtd left">';
5488 if ($input[
'type'] ==
'select') {
5489 $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);
5491 $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);
5493 $more .=
'</div></div>' .
"\n";
5494 } elseif ($input[
'type'] ==
'checkbox') {
5495 $more .=
'<div class="tagtr">';
5496 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'"><label for="' .
dol_escape_htmltag($input[
'name']) .
'">' . $input[
'label'] .
'</label></div><div class="tagtd">';
5497 $more .=
'<input type="checkbox" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' .
dol_escape_htmltag($input[
'name']) .
'" name="' .
dol_escape_htmltag($input[
'name']) .
'"' . $moreattr;
5498 if (!is_bool($input[
'value']) && $input[
'value'] !=
'false' && $input[
'value'] !=
'0' && $input[
'value'] !=
'') {
5499 $more .=
' checked';
5501 if (is_bool($input[
'value']) && $input[
'value']) {
5502 $more .=
' checked';
5504 if (isset($input[
'disabled'])) {
5505 $more .=
' disabled';
5507 $more .=
' /></div>';
5508 $more .=
'</div>' .
"\n";
5509 } elseif ($input[
'type'] ==
'radio') {
5511 foreach ($input[
'values'] as $selkey => $selval) {
5512 $more .=
'<div class="tagtr">';
5513 if (isset($input[
'label'])) {
5515 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
' tdtop' : (
' tdtop ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
5517 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' "' . $input[
'tdclass'])) .
'"> </div>';
5520 $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;
5521 if (!empty($input[
'disabled'])) {
5522 $more .=
' disabled';
5524 if (isset($input[
'default']) && $input[
'default'] === $selkey) {
5525 $more .=
' checked="checked"';
5528 $more .=
'<label for="' .
dol_escape_htmltag($input[
'name'] . $selkey) .
'" class="valignmiddle">' . $selval .
'</label>';
5529 $more .=
'</div></div>' .
"\n";
5532 } elseif ($input[
'type'] ==
'date' || $input[
'type'] ==
'datetime') {
5533 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
5534 $more .=
'<div class="tagtd">';
5535 $addnowlink = (empty($input[
'datenow']) ? 0 : 1);
5537 if ($input[
'type'] ==
'datetime') {
5538 $h = isset($input[
'hours']) ? $input[
'hours'] : 1;
5539 $m = isset($input[
'minutes']) ? $input[
'minutes'] : 1;
5541 $more .= $this->
selectDate(isset($input[
'value']) ? $input[
'value'] : -1, $input[
'name'], $h, $m, 0,
'', 1, $addnowlink);
5542 $more .=
'</div></div>'.
"\n";
5543 $formquestion[] = array(
'name' => $input[
'name'].
'day');
5544 $formquestion[] = array(
'name' => $input[
'name'].
'month');
5545 $formquestion[] = array(
'name' => $input[
'name'].
'year');
5546 $formquestion[] = array(
'name' => $input[
'name'].
'hour');
5547 $formquestion[] = array(
'name' => $input[
'name'].
'min');
5548 } elseif ($input[
'type'] ==
'other') {
5549 $more .=
'<div class="tagtr"><div class="tagtd'.(empty($input[
'tdclass']) ?
'' : (
' '.$input[
'tdclass'])).
'">';
5550 if (!empty($input[
'label'])) {
5551 $more .= $input[
'label'] .
'</div><div class="tagtd">';
5553 $more .= $input[
'value'];
5554 $more .=
'</div></div>' .
"\n";
5555 } elseif ($input[
'type'] ==
'onecolumn') {
5556 $moreonecolumn .=
'<div class="margintoponly">';
5557 $moreonecolumn .= $input[
'value'];
5558 $moreonecolumn .=
'</div>' .
"\n";
5559 } elseif ($input[
'type'] ==
'hidden') {
5561 } elseif ($input[
'type'] ==
'separator') {
5564 $more .=
'Error type ' . $input[
'type'] .
' for the confirm box is not a supported type';
5568 $more .=
'</div>' .
"\n";
5569 $more .= $moreonecolumn;
5575 if (!empty($conf->dol_use_jmobile)) {
5578 if (empty($conf->use_javascript_ajax)) {
5584 $dialogconfirm =
'dialog-confirm';
5586 if (!is_numeric($useajax)) {
5590 $dialogconfirm .=
'-' . $button;
5592 $pageyes = $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=yes';
5593 $pageno = ($useajax == 2 ? $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=no' :
'');
5596 if (is_array($formquestion)) {
5597 foreach ($formquestion as $key => $input) {
5600 if (is_array($input) && isset($input[
'name'])) {
5601 if (strpos($input[
'name'],
',') > 0) {
5602 $inputok = array_merge($inputok, explode(
',', $input[
'name']));
5604 array_push($inputok, $input[
'name']);
5609 if (is_array($input) && isset($input[
'inputko']) && $input[
'inputko'] == 1 && isset($input[
'name'])) {
5610 array_push($inputko, $input[
'name']);
5616 $formconfirm .=
'<div id="' . $dialogconfirm .
'" title="' .
dol_escape_htmltag($title) .
'" style="display: none;">';
5617 if (is_array($formquestion) && array_key_exists(
'text', $formquestion) && !empty($formquestion[
'text'])) {
5618 $formconfirm .=
'<div class="confirmtext">' . $formquestion[
'text'] .
'</div>' .
"\n";
5620 if (!empty($more)) {
5621 $formconfirm .=
'<div class="confirmquestions">' . $more .
'</div>' .
"\n";
5623 $formconfirm .= ($question ?
'<div class="confirmmessage">' .
img_help(0,
'') .
' ' . $question .
'</div>' :
'');
5624 $formconfirm .=
'</div>' .
"\n";
5626 $formconfirm .=
"\n<!-- begin code of popup for formconfirm page=" . $page .
" -->\n";
5627 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
5628 $formconfirm .=
"/* Code for the jQuery('#dialogforpopup').dialog() */\n";
5629 $formconfirm .=
'jQuery(document).ready(function() {
5631 $( "#' . $dialogconfirm .
'" ).dialog(
5633 autoOpen: ' . ($autoOpen ?
"true" :
"false") .
',';
5634 if ($newselectedchoice ==
'no') {
5637 $(this).parent().find("button.ui-button:eq(2)").focus();
5642 if ($useajax == 1) {
5643 $jsforcursor =
'// The call to urljump can be slow, so we set the wait cursor' .
"\n";
5644 $jsforcursor .=
'jQuery("html,body,#id-container").addClass("cursorwait");' .
"\n";
5647 $postconfirmas =
'GET';
5651 height: "' . $height .
'",
5652 width: "' . $width .
'",
5654 closeOnEscape: false,
5656 "' .
dol_escape_js($langs->transnoentities($labelbuttonyes)) .
'": function() {
5657 var options = "token=' . urlencode(
newToken()) .
'";
5658 var inputok = ' . json_encode($inputok) .
'; /* List of fields into form */
5659 var page = "' .
dol_escape_js(!empty($page) ? $page :
'') .
'";
5660 var pageyes = "' .
dol_escape_js(!empty($pageyes) ? $pageyes :
'') .
'";
5662 if (inputok.length > 0) {
5663 $.each(inputok, function(i, inputname) {
5666 if ($("input[name=\'" + inputname + "\']").attr("type") == "radio") {
5667 inputvalue = $("input[name=\'" + inputname + "\']:checked").val();
5669 if ($("#" + inputname).attr("type") == "checkbox") { more = ":checked"; }
5670 inputvalue = $("#" + inputname + more).val();
5672 if (typeof inputvalue == "undefined") { inputvalue=""; }
5673 console.log("formconfirm check inputname="+inputname+" inputvalue="+inputvalue);
5674 options += "&" + inputname + "=" + encodeURIComponent(inputvalue);
5677 var urljump = pageyes + (pageyes.indexOf("?") < 0 ? "?" : "&") + options;
5678 if (pageyes.length > 0) {';
5679 if ($postconfirmas ==
'GET') {
5680 $formconfirm .=
'location.href = urljump;';
5682 $formconfirm .= $jsforcursor;
5683 $formconfirm .=
'var post = $.post(
5686 function(data) { $("body").html(data); jQuery("html,body,#id-container").removeClass("cursorwait"); }
5690 console.log("after post ok");
5692 $(this).dialog("close");
5694 "' .
dol_escape_js($langs->transnoentities($labelbuttonno)) .
'": function() {
5695 var options = "token=' . urlencode(
newToken()) .
'";
5696 var inputko = ' . json_encode($inputko) .
'; /* List of fields into form */
5697 var page = "' .
dol_escape_js(!empty($page) ? $page :
'') .
'";
5698 var pageno="' .
dol_escape_js(!empty($pageno) ? $pageno :
'') .
'";
5699 if (inputko.length > 0) {
5700 $.each(inputko, function(i, inputname) {
5702 if ($("#" + inputname).attr("type") == "checkbox") { more = ":checked"; }
5703 var inputvalue = $("#" + inputname + more).val();
5704 if (typeof inputvalue == "undefined") { inputvalue=""; }
5705 options += "&" + inputname + "=" + encodeURIComponent(inputvalue);
5708 var urljump=pageno + (pageno.indexOf("?") < 0 ? "?" : "&") + options;
5710 if (pageno.length > 0) {';
5711 if ($postconfirmas ==
'GET') {
5712 $formconfirm .=
'location.href = urljump;';
5714 $formconfirm .= $jsforcursor;
5715 $formconfirm .=
'var post = $.post(
5718 function(data) { $("body").html(data); jQuery("html,body,#id-container").removeClass("cursorwait"); }
5722 console.log("after post ko");
5724 $(this).dialog("close");
5730 var button = "' . $button .
'";
5731 if (button.length > 0) {
5732 $( "#" + button ).click(function() {
5733 $("#' . $dialogconfirm .
'").dialog("open");
5739 $formconfirm .=
"<!-- end ajax formconfirm -->\n";
5741 $formconfirm .=
"\n<!-- begin formconfirm page=" .
dol_escape_htmltag($page) .
" -->\n";
5743 if (empty($disableformtag)) {
5744 $formconfirm .=
'<form method="POST" action="' . $page .
'" class="notoptoleftroright">' .
"\n";
5747 $formconfirm .=
'<input type="hidden" name="action" value="' . $action .
'">' .
"\n";
5748 $formconfirm .=
'<input type="hidden" name="token" value="' .
newToken() .
'">' .
"\n";
5750 $formconfirm .=
'<table class="valid centpercent">' .
"\n";
5753 $formconfirm .=
'<tr class="validtitre"><td class="validtitre" colspan="2">';
5754 $formconfirm .=
img_picto(
'',
'pictoconfirm') .
' ' . $title;
5755 $formconfirm .=
'</td></tr>' .
"\n";
5758 if (is_array($formquestion) && array_key_exists(
'text', $formquestion) && !empty($formquestion[
'text'])) {
5759 $formconfirm .=
'<tr class="valid"><td class="valid" colspan="2">' . $formquestion[
'text'] .
'</td></tr>' .
"\n";
5764 $formconfirm .=
'<tr class="valid"><td class="valid" colspan="2">' .
"\n";
5765 $formconfirm .= $more;
5766 $formconfirm .=
'</td></tr>' .
"\n";
5770 $formconfirm .=
'<tr class="valid">';
5771 $formconfirm .=
'<td class="valid">' . $question .
'</td>';
5772 $formconfirm .=
'<td class="valid center">';
5773 $formconfirm .= $this->
selectyesno(
"confirm", $newselectedchoice, 0,
false, 0, 0,
'marginleftonly marginrightonly', $labelbuttonyes, $labelbuttonno);
5774 $formconfirm .=
'<input class="button valignmiddle confirmvalidatebutton small" type="submit" value="' . $langs->trans(
"Validate") .
'">';
5775 $formconfirm .=
'</td>';
5776 $formconfirm .=
'</tr>' .
"\n";
5778 $formconfirm .=
'</table>' .
"\n";
5780 if (empty($disableformtag)) {
5781 $formconfirm .=
"</form>\n";
5783 $formconfirm .=
'<br>';
5785 if (!empty($conf->use_javascript_ajax)) {
5786 $formconfirm .=
'<!-- code to disable button to avoid double clic -->';
5787 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
5789 $(document).ready(function () {
5790 $(".confirmvalidatebutton").on("click", function() {
5791 console.log("We click on button confirmvalidatebutton");
5792 $(this).attr("disabled", "disabled");
5793 setTimeout(\'$(".confirmvalidatebutton").removeAttr("disabled")\', 3000);
5794 //console.log($(this).closest("form"));
5795 $(this).closest("form").submit();
5799 $formconfirm .=
'</script>' .
"\n";
5802 $formconfirm .=
"<!-- end formconfirm -->\n";
5805 return $formconfirm;
5826 public function form_project($page, $socid, $selected =
'', $htmlname =
'projectid', $discard_closed = 0, $maxlength = 20, $forcefocus = 0, $nooutput = 0, $textifnoproject =
'', $morecss =
'')
5831 require_once DOL_DOCUMENT_ROOT .
'/core/lib/project.lib.php';
5832 require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formprojet.class.php';
5838 $langs->load(
"project");
5839 if ($htmlname !=
"none") {
5840 $out .=
'<form method="post" action="' . $page .
'">';
5841 $out .=
'<input type="hidden" name="action" value="classin">';
5842 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5843 $out .= $formproject->select_projects($socid, $selected, $htmlname, $maxlength, 0, 1, $discard_closed, $forcefocus, 0, 0,
'', 1, 0, $morecss);
5844 $out .=
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
5847 $out .=
'<span class="project_head_block">';
5849 $projet =
new Project($this->db);
5850 $projet->fetch($selected);
5851 $out .= $projet->getNomUrl(0,
'', 1);
5853 $out .=
'<span class="opacitymedium">' . $textifnoproject .
'</span>';
5858 if (empty($nooutput)) {
5882 public function form_conditions_reglement($page, $selected =
'', $htmlname =
'cond_reglement_id', $addempty = 0, $type =
'', $filtertype = -1, $deposit_percent = -1, $nooutput = 0)
5889 if ($htmlname !=
"none") {
5890 $out .=
'<form method="POST" action="' . $page .
'">';
5891 $out .=
'<input type="hidden" name="action" value="setconditions">';
5892 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5894 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
5897 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
5902 if (isset($this->cache_conditions_paiements[$selected])) {
5903 $label = $this->cache_conditions_paiements[$selected][
'label'];
5905 if (!empty($this->cache_conditions_paiements[$selected][
'deposit_percent'])) {
5906 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $this->cache_conditions_paiements[$selected][
'deposit_percent'], $label);
5911 $langs->load(
'errors');
5912 $out .= $langs->trans(
'ErrorNotInDictionaryPaymentConditions');
5919 if (empty($nooutput)) {
5941 if ($htmlname !=
"none") {
5942 print
'<form method="post" action="' . $page .
'">';
5943 print
'<input type="hidden" name="action" value="setavailability">';
5944 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5946 print
'<input type="submit" name="modify" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
5947 print
'<input type="submit" name="cancel" class="button smallpaddingimp" value="' . $langs->trans(
"Cancel") .
'">';
5952 print $this->cache_availability[$selected][
'label'];
5969 public function formInputReason($page, $selected =
'', $htmlname =
'demandreason', $addempty = 0)
5972 if ($htmlname !=
"none") {
5973 print
'<form method="post" action="' . $page .
'">';
5974 print
'<input type="hidden" name="action" value="setdemandreason">';
5975 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5977 print
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
5982 foreach ($this->cache_demand_reason as $key => $val) {
5983 if ($val[
'id'] == $selected) {
5984 print $val[
'label'];
6009 public function form_date($page, $selected, $htmlname, $displayhour = 0, $displaymin = 0, $nooutput = 0, $type =
'')
6016 if ($htmlname !=
"none") {
6017 $ret .=
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
6018 $ret .=
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
6019 $ret .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6021 $ret .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
6023 $ret .=
'<table class="nobordernopadding">';
6025 $ret .= $this->
selectDate($selected, $htmlname, $displayhour, $displaymin, 1,
'form' . $htmlname, 1, 0);
6027 $ret .=
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
6028 $ret .=
'</tr></table></form>';
6037 if (empty($nooutput)) {
6056 public function form_users($page, $selected =
'', $htmlname =
'userid', $exclude = array(), $include = array())
6061 if ($htmlname !=
"none") {
6062 print
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
6063 print
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
6064 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6065 print $this->
select_dolusers($selected, $htmlname, 1, $exclude, 0, $include);
6066 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6070 require_once DOL_DOCUMENT_ROOT .
'/user/class/user.class.php';
6071 $theuser =
new User($this->db);
6072 $theuser->fetch($selected);
6073 print $theuser->getNomUrl(1);
6096 public function form_modes_reglement($page, $selected =
'', $htmlname =
'mode_reglement_id', $filtertype =
'', $active = 1, $addempty = 0, $type =
'', $nooutput = 0)
6102 if ($htmlname !=
"none") {
6103 $out .=
'<form method="POST" action="' . $page .
'">';
6104 $out .=
'<input type="hidden" name="action" value="setmode">';
6105 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6107 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
6109 $out .= $this->
select_types_paiements($selected, $htmlname, $filtertype, 0, $addempty, 0, 0, $active,
'', 1);
6110 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6115 $out .= $this->cache_types_paiements[$selected][
'label'];
6142 if ($htmlname !=
"none") {
6143 print
'<form method="POST" action="' . $page .
'">';
6144 print
'<input type="hidden" name="action" value="settransportmode">';
6145 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6147 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6152 print $this->cache_transport_mode[$selected][
'label'];
6173 if ($htmlname !=
"none") {
6174 print
'<form method="POST" action="' . $page .
'">';
6175 print
'<input type="hidden" name="action" value="setmulticurrencycode">';
6176 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6178 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6181 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
6182 print !empty($selected) ?
currency_name($selected, 1) :
' ';
6200 global $langs, $mysoc, $conf;
6202 if ($htmlname !=
"none") {
6203 print
'<form method="POST" action="' . $page .
'">';
6204 print
'<input type="hidden" name="action" value="setmulticurrencyrate">';
6205 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6206 print
'<input type="text" class="maxwidth100" name="' . $htmlname .
'" value="' . (!empty($rate) ?
price(
price2num($rate,
'CU')) : 1) .
'" /> ';
6207 print
'<select name="calculation_mode">';
6208 print
'<option value="1">Change ' . $langs->trans(
"PriceUHT") .
' of lines</option>';
6209 print
'<option value="2">Change ' . $langs->trans(
"PriceUHTCurrency") .
' of lines</option>';
6211 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6214 if (!empty($rate)) {
6215 print
price($rate, 1, $langs, 0, 0);
6216 if ($currency && $rate != 1) {
6217 print
' (' .
price($rate, 1, $langs, 0, 0) .
' ' . $currency .
' = 1 ' . $conf->currency .
')';
6243 public function form_remise_dispo($page, $selected, $htmlname, $socid, $amount, $filter =
'', $maxvalue = 0, $more =
'', $hidelist = 0, $discount_type = 0)
6246 global $conf, $langs;
6247 if ($htmlname !=
"none") {
6248 print
'<form method="post" action="' . $page .
'">';
6249 print
'<input type="hidden" name="action" value="setabsolutediscount">';
6250 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6251 print
'<div class="inline-block">';
6252 if (!empty($discount_type)) {
6254 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL") {
6255 $translationKey =
'HasAbsoluteDiscountFromSupplier';
6257 $translationKey =
'HasCreditNoteFromSupplier';
6260 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
6261 $translationKey =
'HasAbsoluteDiscountFromSupplier';
6263 $translationKey =
'HasCreditNoteFromSupplier';
6268 if (!$filter || $filter ==
"fk_facture_source IS NULL") {
6269 $translationKey =
'CompanyHasAbsoluteDiscount';
6271 $translationKey =
'CompanyHasCreditNote';
6274 if (!$filter || $filter ==
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
6275 $translationKey =
'CompanyHasAbsoluteDiscount';
6277 $translationKey =
'CompanyHasCreditNote';
6281 print $langs->trans($translationKey,
price($amount, 0, $langs, 0, 0, -1, $conf->currency));
6282 if (empty($hidelist)) {
6286 if (empty($hidelist)) {
6287 print
'<div class="inline-block" style="padding-right: 10px">';
6288 $newfilter =
'discount_type=' . intval($discount_type);
6289 if (!empty($discount_type)) {
6290 $newfilter .=
' AND fk_invoice_supplier IS NULL AND fk_invoice_supplier_line IS NULL';
6292 $newfilter .=
' AND fk_facture IS NULL AND fk_facture_line IS NULL';
6295 $newfilter .=
' AND (' . $filter .
')';
6298 $nbqualifiedlines = $this->
select_remises($selected, $htmlname, $newfilter, $socid, $maxvalue);
6299 if ($nbqualifiedlines > 0) {
6300 print
' <input type="submit" class="button smallpaddingimp" value="' .
dol_escape_htmltag($langs->trans(
"UseLine")) .
'"';
6301 if (!empty($discount_type) && $filter && $filter !=
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
6302 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
6304 if (empty($discount_type) && $filter && $filter !=
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
6305 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
6313 print
'<div class="inline-block">';
6339 public function form_contacts($page, $societe, $selected =
'', $htmlname =
'contactid')
6344 if ($htmlname !=
"none") {
6345 print
'<form method="post" action="' . $page .
'">';
6346 print
'<input type="hidden" name="action" value="set_contact">';
6347 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6348 print
'<table class="nobordernopadding">';
6353 $addcontact = (
getDolGlobalString(
'SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans(
"AddContact") : $langs->trans(
"AddContactAddress"));
6354 print
'<a href="' . DOL_URL_ROOT .
'/contact/card.php?socid=' . $societe->id .
'&action=create&backtoreferer=1">' . $addcontact .
'</a>';
6357 print
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
6358 print
'</tr></table></form>';
6361 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
6362 $contact =
new Contact($this->db);
6363 $contact->fetch($selected);
6364 print $contact->getFullName($langs);
6389 public function form_thirdparty($page, $selected =
'', $htmlname =
'socid', $filter =
'', $showempty = 0, $showtype = 0, $forcecombo = 0, $events = array(), $nooutput = 0, $excludeids = array(), $textifnothirdparty =
'')
6395 if ($htmlname !=
"none") {
6396 $out .=
'<form method="post" action="' . $page .
'">';
6397 $out .=
'<input type="hidden" name="action" value="set_thirdparty">';
6398 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6399 $out .= $this->
select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, 0,
'minwidth100',
'',
'', 1, array(),
false, $excludeids);
6400 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6404 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
6405 $soc =
new Societe($this->db);
6406 $soc->fetch($selected);
6407 $out .= $soc->getNomUrl(0,
'');
6409 $out .=
'<span class="opacitymedium">' . $textifnothirdparty .
'</span>';
6447 public function selectCurrency($selected =
'', $htmlname =
'currency_id', $mode = 0, $useempty =
'')
6449 global $langs, $user;
6451 $langs->loadCacheCurrencies(
'');
6455 if ($selected ==
'euro' || $selected ==
'euros') {
6459 $out .=
'<select class="flat maxwidth200onsmartphone minwidth300" name="' . $htmlname .
'" id="' . $htmlname .
'">';
6461 $out .=
'<option value="-1" selected></option>';
6463 foreach ($langs->cache_currencies as $code_iso => $currency) {
6464 $labeltoshow = $currency[
'label'];
6466 $labeltoshow .=
' <span class="opacitymedium">(' . $code_iso .
')</span>';
6468 $labeltoshow .=
' <span class="opacitymedium">(' . $langs->getCurrencySymbol($code_iso) .
')</span>';
6471 if ($selected && $selected == $code_iso) {
6472 $out .=
'<option value="' . $code_iso .
'" selected data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
6474 $out .=
'<option value="' . $code_iso .
'" data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
6476 $out .= $labeltoshow;
6477 $out .=
'</option>';
6479 $out .=
'</select>';
6481 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
6485 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
6503 public function selectMultiCurrency($selected =
'', $htmlname =
'multicurrency_code', $useempty = 0, $filter =
'', $excludeConfCurrency =
false, $morecss =
'')
6505 global $conf, $langs;
6507 $langs->loadCacheCurrencies(
'');
6509 $TCurrency = array();
6511 $sql =
"SELECT code FROM " . $this->db->prefix() .
"multicurrency";
6512 $sql .=
" WHERE entity IN ('" .
getEntity(
'mutlicurrency') .
"')";
6514 $sql .=
" AND " . $filter;
6516 $resql = $this->db->query($sql);
6518 while ($obj = $this->db->fetch_object($resql)) {
6519 $TCurrency[$obj->code] = $obj->code;
6524 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
6526 $out .=
'<option value=""> </option>';
6529 if (!in_array($conf->currency, $TCurrency) && !$excludeConfCurrency) {
6530 $TCurrency[$conf->currency] = $conf->currency;
6532 if (count($TCurrency) > 0) {
6533 foreach ($langs->cache_currencies as $code_iso => $currency) {
6534 if (isset($TCurrency[$code_iso])) {
6535 if (!empty($selected) && $selected == $code_iso) {
6536 $out .=
'<option value="' . $code_iso .
'" selected="selected">';
6538 $out .=
'<option value="' . $code_iso .
'">';
6541 $out .= $currency[
'label'];
6542 $out .=
' (' . $langs->getCurrencySymbol($code_iso) .
')';
6543 $out .=
'</option>';
6548 $out .=
'</select>';
6551 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
6568 global $langs, $user;
6570 $num = count($this->cache_vatrates);
6577 $sql =
"SELECT t.rowid, t.type_vat, t.code, t.taux, t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.recuperableonly";
6578 $sql .=
" FROM ".$this->db->prefix().
"c_tva as t, ".$this->db->prefix().
"c_country as c";
6579 $sql .=
" WHERE t.fk_pays = c.rowid";
6580 $sql .=
" AND t.active > 0";
6581 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
6582 $sql .=
" AND c.code IN (" . $this->db->sanitize($country_code, 1) .
")";
6583 $sql .=
" ORDER BY t.code ASC, t.taux ASC, t.recuperableonly ASC";
6585 $resql = $this->db->query($sql);
6587 $num = $this->db->num_rows($resql);
6589 for ($i = 0; $i < $num; $i++) {
6590 $obj = $this->db->fetch_object($resql);
6592 $tmparray = array();
6593 $tmparray[
'rowid'] = $obj->rowid;
6594 $tmparray[
'type_vat'] = $obj->type_vat;
6595 $tmparray[
'code'] = $obj->code;
6596 $tmparray[
'txtva'] = $obj->taux;
6597 $tmparray[
'nprtva'] = $obj->recuperableonly;
6598 $tmparray[
'localtax1'] = $obj->localtax1;
6599 $tmparray[
'localtax1_type'] = $obj->localtax1_type;
6600 $tmparray[
'localtax2'] = $obj->localtax2;
6601 $tmparray[
'localtax2_type'] = $obj->localtax1_type;
6602 $tmparray[
'label'] = $obj->taux .
'%' . ($obj->code ?
' (' . $obj->code .
')' :
'');
6603 $tmparray[
'labelallrates'] = $obj->taux .
'/' . ($obj->localtax1 ? $obj->localtax1 :
'0') .
'/' . ($obj->localtax2 ? $obj->localtax2 :
'0') . ($obj->code ?
' (' . $obj->code .
')' :
'');
6604 $positiverates =
'';
6606 $positiverates .= ($positiverates ?
'/' :
'') . $obj->taux;
6608 if ($obj->localtax1) {
6609 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax1;
6611 if ($obj->localtax2) {
6612 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax2;
6614 if (empty($positiverates)) {
6615 $positiverates =
'0';
6617 $tmparray[
'labelpositiverates'] = $positiverates . ($obj->code ?
' (' . $obj->code .
')' :
'');
6619 $this->cache_vatrates[$obj->rowid] = $tmparray;
6624 $this->error =
'<span class="error">';
6625 $this->error .= $langs->trans(
"ErrorNoVATRateDefinedForSellerCountry", $country_code);
6627 if (!empty($user) && $user->admin && preg_match(
'/\'(..)\'/', $country_code, $reg)) {
6628 $langs->load(
"errors");
6629 $new_country_code = $reg[1];
6630 $country_id =
dol_getIdFromCode($this->db, $new_country_code,
'c_pays',
'code',
'rowid');
6631 $this->error .=
'<br>'.$langs->trans(
"ErrorFixThisHere", DOL_URL_ROOT.
'/admin/dict.php?id=10'.($country_id > 0 ?
'&countryidforinsert='.$country_id :
''));
6633 $this->error .=
'</span>';
6637 $this->error =
'<span class="error">' . $this->db->error() .
'</span>';
6666 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)
6669 global $langs, $mysoc;
6671 $langs->load(
'errors');
6676 $defaultnpr = ($info_bits & 0x01);
6677 $defaultnpr = (preg_match(
'/\*/', $selectedrate) ? 1 : $defaultnpr);
6678 $defaulttx = str_replace(
'*',
'', $selectedrate);
6681 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
6682 $defaultcode = $reg[1];
6683 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
6688 if (is_object($societe_vendeuse) && !$societe_vendeuse->country_code) {
6689 if ($societe_vendeuse->id == $mysoc->id) {
6690 $return .=
'<span class="error">' . $langs->trans(
"ErrorYourCountryIsNotDefined") .
'</span>';
6692 $return .=
'<span class="error">' . $langs->trans(
"ErrorSupplierCountryIsNotDefined") .
'</span>';
6703 if (is_object($societe_vendeuse)) {
6704 $code_country =
"'" . $societe_vendeuse->country_code .
"'";
6706 $code_country =
"'" . $mysoc->country_code .
"'";
6709 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
6713 if (
isInEEC($societe_vendeuse) &&
isInEEC($societe_acheteuse) && !$societe_acheteuse->isACompany()) {
6715 if (is_numeric($type)) {
6717 switch ($selectVatComboMode) {
6719 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
6722 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
6726 } elseif (!$idprod) {
6727 switch ($selectVatComboMode) {
6729 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
6732 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
6736 $prodstatic =
new Product($this->db);
6737 $prodstatic->fetch($idprod);
6739 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
6749 $arrayofvatrates = array();
6750 foreach ($this->cache_vatrates as $cachevalue) {
6751 if (empty($cachevalue[
'type_vat']) || $cachevalue[
'type_vat'] != $type_vat) {
6752 $arrayofvatrates[] = $cachevalue;
6756 $num = count($arrayofvatrates);
6760 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
6761 $tmpthirdparty =
new Societe($this->db);
6763 $defaulttx =
get_default_tva($societe_vendeuse, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
6764 $defaultnpr =
get_default_npr($societe_vendeuse, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
6766 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
6767 $defaultcode = $reg[1];
6768 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
6770 if (empty($defaulttx)) {
6777 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
6780 $defaulttx = $arrayofvatrates[$num - 1][
'txtva'];
6787 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
6788 $defaultcode = $reg[1];
6789 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
6797 if (is_object($societe_vendeuse) && $societe_vendeuse->id == $mysoc->id && $societe_vendeuse->tva_assuj ==
"0") {
6806 if (!$options_only) {
6807 $return .=
'<select class="flat minwidth75imp maxwidth100 right" id="' . $htmlname .
'" name="' . $htmlname .
'"' . ($disabled ?
' disabled' :
'') . $title .
'>';
6810 $selectedfound =
false;
6811 foreach ($arrayofvatrates as $rate) {
6813 if ($disabled && $rate[
'txtva'] != 0) {
6818 $key = $rate[
'txtva'];
6819 $key .= $rate[
'nprtva'] ?
'*' :
'';
6820 if ($mode > 0 && $rate[
'code']) {
6821 $key .=
' (' . $rate[
'code'] .
')';
6824 $key = $rate[
'rowid'];
6827 $return .=
'<option value="' . $key .
'"';
6828 if (!$selectedfound) {
6830 if ($defaultcode == $rate[
'code']) {
6831 $return .=
' selected';
6832 $selectedfound =
true;
6834 } elseif ($rate[
'txtva'] == $defaulttx && $rate[
'nprtva'] == $defaultnpr) {
6835 $return .=
' selected';
6836 $selectedfound =
true;
6842 if ($mysoc->country_code ==
'IN' ||
getDolGlobalString(
'MAIN_VAT_LABEL_IS_POSITIVE_RATES')) {
6844 $return .= $rate[
'labelpositiverates'];
6847 $return .=
vatrate($rate[
'label']);
6851 $return .= (empty($rate[
'code']) && $rate[
'nprtva']) ?
' *' :
'';
6853 $return .=
'</option>';
6856 if (!$options_only) {
6857 $return .=
'</select>';
6861 $return .= $this->error;
6895 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 =
'')
6898 dol_syslog(__METHOD__ .
': using select_date is deprecated. Use selectDate instead.', LOG_WARNING);
6899 $retstring = $this->
selectDate($set_time, $prefix, $h, $m, $empty, $form_name, $d, $addnowlink, $disabled, $fullday, $addplusone, $adddateof);
6900 if (!empty($nooutput)) {
6923 public function selectDateToDate($set_time =
'', $set_time_end =
'', $prefix =
're', $empty = 0, $forcenewline = 0)
6927 $ret = $this->
selectDate($set_time, $prefix .
'_start', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"from"),
'tzuserrel');
6928 if ($forcenewline) {
6931 $ret .= $this->
selectDate($set_time_end, $prefix .
'_end', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
6962 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')
6964 global $conf, $langs;
6966 if ($gm ===
'auto') {
6967 $gm = (empty($conf) ?
'tzserver' : $conf->tzuserinputkey);
6972 if ($prefix ==
'') {
6983 if ($stepminutes <= 0 || $stepminutes > 30) {
6994 $orig_set_time = $set_time;
6996 if ($set_time ===
'' && $emptydate == 0) {
6997 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
6998 if ($gm ==
'tzuser' || $gm ==
'tzuserrel') {
7010 if (preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/', $set_time, $reg)) {
7012 $syear = (!empty($reg[1]) ? $reg[1] :
'');
7013 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
7014 $sday = (!empty($reg[3]) ? $reg[3] :
'');
7015 $shour = (!empty($reg[4]) ? $reg[4] :
'');
7016 $smin = (!empty($reg[5]) ? $reg[5] :
'');
7017 } elseif (strval($set_time) !=
'' && $set_time != -1) {
7022 if ($orig_set_time !=
'') {
7036 if ($h == 3 || $h == 4) {
7047 $usecalendar =
'combo';
7053 $usecalendar =
'html';
7058 if ($usecalendar !=
'combo') {
7059 $formated_date =
'';
7061 if (strval($set_time) !=
'' && $set_time != -1) {
7063 $formated_date =
dol_print_date($set_time, $langs->trans(
"FormatDateShortInput"), $gm);
7067 if ($usecalendar ==
"eldy") {
7069 $retstring .=
'<input id="' . $prefix .
'" name="' . $prefix .
'" type="text" class="maxwidthdate center" maxlength="11" value="' . $formated_date .
'"';
7070 $retstring .= ($disabled ?
' disabled' :
'');
7071 $retstring .=
' onChange="dpChangeDay(\'' . $prefix .
'\',\
'' . $langs->trans(
"FormatDateShortJavaInput") .
'\');
"'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
7072 $retstring .= ' autocomplete="off
">';
7075 $retstringbuttom = '';
7077 $retstringbuttom = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
"';
7078 $base = DOL_URL_ROOT . '/core/';
7079 $retstringbuttom .= ' onClick="showDP(\
'' . $base .
'\',\
'' . $prefix .
'\',\
'' . $langs->trans(
"FormatDateShortJavaInput") .
'\',\
'' . $langs->defaultlang .
'\');
"';
7080 $retstringbuttom .= '>' . img_object($langs->trans("SelectDate
"), 'calendarday', 'class="datecallink
"') . '</button>';
7082 $retstringbuttom = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
">' . img_object($langs->trans("Disabled
"), 'calendarday', 'class="datecallink
"') . '</button>';
7084 $retstring = $retstringbuttom . $retstring;
7086 $retstring .= '<input type="hidden
" id="' . $prefix . 'day
" name="' . $prefix . 'day
" value="' . $sday . '">' . "\n
";
7087 $retstring .= '<input type="hidden
" id="' . $prefix . 'month
" name="' . $prefix . 'month
" value="' . $smonth . '">' . "\n
";
7088 $retstring .= '<input type="hidden
" id="' . $prefix . 'year
" name="' . $prefix . 'year
" value="' . $syear . '">' . "\n
";
7089 } elseif ($usecalendar == 'jquery' || $usecalendar == 'html') {
7090 if (!$disabled && $usecalendar != 'html') {
7091 // Output javascript for datepicker
7092 $minYear = getDolGlobalInt('MIN_YEAR_SELECT_DATE', (idate('Y') - 100));
7093 $maxYear = getDolGlobalInt('MAX_YEAR_SELECT_DATE', (idate('Y') + 100));
7095 $retstring .= '<script nonce="' . getNonce() . '" type="text/javascript
">';
7096 $retstring .= "$(
function(){ $(
'#" . $prefix . "').datepicker({
7097 dateFormat:
'" . $langs->trans("FormatDateShortJQueryInput") . "',
7099 todayHighlight:
true,
7100 yearRange:
'" . $minYear . ":" . $maxYear . "',
";
7101 if (!empty($conf->dol_use_jmobile)) {
7103 beforeShow:
function (input, datePicker) {
7104 input.disabled =
true;
7106 onClose:
function (dateText, datePicker) {
7111 // Note: We don't need monthNames, monthNamesShort, dayNames, dayNamesShort, dayNamesMin, they are set globally on datepicker component in lib_head.js.php
7112 if (!getDolGlobalString('MAIN_POPUP_CALENDAR_ON_FOCUS')) {
7115 buttonImage:
'" . DOL_URL_ROOT . "/theme/" . dol_escape_js($conf->theme) . "/img/object_calendarday.png',
7116 buttonImageOnly:
true";
7120 $retstring .= "</script>
";
7123 // Input area to enter date manually
7124 $retstring .= '<div class="nowraponall
inline-block divfordateinput
">';
7125 $retstring .= '<input id="'.$prefix.'" name="'.$prefix.'" type="text
" class="maxwidthdate center
" maxlength="11
" value="'.$formated_date.'"';
7126 $retstring .= ($disabled ? ' disabled' : '');
7127 $retstring .= ($placeholder ? ' placeholder="' . dol_escape_htmltag($placeholder) . '"' : '');
7128 $retstring .= ' onChange="dpChangeDay(\
'' .
dol_escape_js($prefix) .
'\',\
'' .
dol_escape_js($langs->trans(
"FormatDateShortJavaInput")) .
'\');
"'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
7129 $retstring .= ' autocomplete="off
">';
7133 $retstringbutton = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
">' . img_object($langs->trans("Disabled
"), 'calendarday', 'class="datecallink
"') . '</button>';
7134 $retstring = $retstringbutton . $retstring;
7137 $retstring .= '</div>';
7138 $retstring .= '<input type="hidden
" id="' . $prefix . 'day
" name="' . $prefix . 'day
" value="' . $sday . '">' . "\n
";
7139 $retstring .= '<input type="hidden
" id="' . $prefix . 'month
" name="' . $prefix . 'month
" value="' . $smonth . '">' . "\n
";
7140 $retstring .= '<input type="hidden
" id="' . $prefix . 'year
" name="' . $prefix . 'year
" value="' . $syear . '">' . "\n
";
7142 $retstring .= "Bad value of MAIN_POPUP_CALENDAR
";
7145 // Show date with combo selects
7147 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50imp
" id="' . $prefix . 'day
" name="' . $prefix . 'day
">';
7149 if ($emptydate || $set_time == -1) {
7150 $retstring .= '<option value="0
" selected> </option>';
7153 for ($day = 1; $day <= 31; $day++) {
7154 $retstring .= '<option value="' . $day . '"' . ($day == $sday ? ' selected' : '') . '>' . $day . '</option>';
7157 $retstring .= "</select>
";
7159 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'month
" name="' . $prefix . 'month
">';
7160 if ($emptydate || $set_time == -1) {
7161 $retstring .= '<option value="0
" selected> </option>';
7165 for ($month = 1; $month <= 12; $month++) {
7166 $retstring .= '<option value="' . $month . '"' . ($month == $smonth ? ' selected' : '') . '>';
7167 $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b
");
7168 $retstring .= "</option>
";
7170 $retstring .= "</select>
";
7173 if ($emptydate || $set_time == -1) {
7174 $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 . '">';
7176 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'year
" name="' . $prefix . 'year
">';
7178 $syear = (int) $syear;
7179 for ($year = $syear - 10; $year < (int) $syear + 10; $year++) {
7180 $retstring .= '<option value="' . $year . '"' . ($year == $syear ? ' selected' : '') . '>' . $year . '</option>';
7182 $retstring .= "</select>\n
";
7188 $retstring .= (($h == 2 || $h == 4) ? '<br>' : ' ');
7189 $retstring .= '<span class="nowraponall
">';
7195 if ($openinghours != '') {
7196 $openinghours = explode(',', $openinghours);
7197 $hourstart = $openinghours[0];
7198 $hourend = $openinghours[1];
7199 if ($hourend < $hourstart) {
7200 $hourend = $hourstart;
7204 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50
' . ($fullday ? $fullday . 'hour
' : '') . '" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
">';
7206 $retstring .= '<option value="-1
"> </option>';
7208 for ($hour = $hourstart; $hour < $hourend; $hour++) {
7209 if (strlen($hour) < 2) {
7210 $hour = "0
" . $hour;
7212 $retstring .= '<option value="' . $hour . '"' . (($hour == $shour) ? ' selected' : '') . '>' . $hour;
7213 //$retstring .= (empty($conf->dol_optimize_smallscreen) ? '' : 'H');
7214 $retstring .= '</option>';
7216 $retstring .= '</select>';
7217 //if ($m && empty($conf->dol_optimize_smallscreen)) $retstring .= ":
";
7225 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50
' . ($fullday ? $fullday . 'min
' : '') . '" id="' . $prefix . 'min
" name="' . $prefix . 'min
">';
7227 $retstring .= '<option value="-1
"> </option>';
7229 for ($min = 0; $min < 60; $min += $stepminutes) {
7230 $min_str = sprintf("%02d
", $min);
7231 $retstring .= '<option value="' . $min_str . '"' . (($min_str == $smin) ? ' selected' : '') . '>' . $min_str . '</option>';
7233 $retstring .= '</select>';
7235 $retstring .= '<input type="hidden
" name="' . $prefix . 'sec
" value="' . $ssec . '">';
7239 $retstring .= '</span>';
7243 if (!empty($conf->use_javascript_ajax) && $addnowlink) {
7244 // Script which will be inserted in the onClick of the "Now
" link
7245 $reset_scripts = "";
7246 if ($addnowlink == 2) { // local computer time
7247 // pad add leading 0 on numbers
7248 $reset_scripts .= "Number.prototype.pad =
function(size) {
7249 var s = String(
this);
7250 while (s.length < (size || 2)) {s =
'0' + s;}
7253 var d =
new Date();
";
7256 // Generate the date part, depending on the use or not of the javascript calendar
7257 if ($addnowlink == 1) { // server time expressed in user time setup
7258 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
7259 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
7260 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
7261 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
7262 } elseif ($addnowlink == 2) {
7263 /* Disabled because the output does not use the string format defined by FormatDateShort key to forge the value into #prefix.
7264 * This break application for foreign languages.
7265 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(d.toLocaleDateString(\''.str_replace('_', '-', $langs->defaultlang).'\'));';
7266 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(d.getDate().pad());';
7267 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(parseInt(d.getMonth().pad()) + 1);';
7268 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(d.getFullYear());';
7270 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
7271 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
7272 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
7273 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
7275 /*if ($usecalendar == "eldy
")
7277 $base=DOL_URL_ROOT.'/core/';
7278 $reset_scripts .= 'resetDP(\''.$base.'\',\''.$prefix.'\',\''.$langs->trans("FormatDateShortJavaInput
").'\',\''.$langs->defaultlang.'\');';
7282 $reset_scripts .= 'this.form.elements[\''.$prefix.'day\'].value=formatDate(new Date(), \'d\'); ';
7283 $reset_scripts .= 'this.form.elements[\''.$prefix.'month\'].value=formatDate(new Date(), \'M\'); ';
7284 $reset_scripts .= 'this.form.elements[\''.$prefix.'year\'].value=formatDate(new Date(), \'yyyy\'); ';
7286 // Update the hour part
7289 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7291 //$reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); ';
7292 if ($addnowlink == 1) {
7293 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
7294 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
7295 } elseif ($addnowlink == 2) {
7296 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(d.getHours().pad());';
7297 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
7301 $reset_scripts .= ' } ';
7304 // Update the minute part
7307 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7309 //$reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); ';
7310 if ($addnowlink == 1) {
7311 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
7312 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
7313 } elseif ($addnowlink == 2) {
7314 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(d.getMinutes().pad());';
7315 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
7318 $reset_scripts .= ' } ';
7321 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
7322 if ($reset_scripts && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
7323 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonNow
" type="button" name="_useless
" value="now
" onClick="' . $reset_scripts . '">';
7324 $retstring .= $langs->trans("Now
");
7325 $retstring .= '</button> ';
7329 // Add a "Plus one hour
" link
7330 if ($conf->use_javascript_ajax && $addplusone) {
7331 // Script which will be inserted in the onClick of the "Add plusone
" link
7332 $reset_scripts = "";
7334 // Generate the date part, depending on the use or not of the javascript calendar
7335 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'dayinputnoreduce', 'tzuserrel') . '\');';
7336 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
7337 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
7338 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
7339 // Update the hour part
7342 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7344 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
7346 $reset_scripts .= ' } ';
7349 // Update the minute part
7352 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7354 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
7356 $reset_scripts .= ' } ';
7359 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
7360 if ($reset_scripts && empty($conf->dol_optimize_smallscreen)) {
7361 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonPlusOne
" type="button" name="_useless2
" value="plusone
" onClick="' . $reset_scripts . '">';
7362 $retstring .= $langs->trans("DateStartPlusOne
");
7363 $retstring .= '</button> ';
7367 // Add a link to set data
7368 if ($conf->use_javascript_ajax && !empty($adddateof)) {
7369 if (!is_array($adddateof)) {
7370 $arrayofdateof = array(array('adddateof' => $adddateof, 'labeladddateof' => $labeladddateof));
7372 $arrayofdateof = $adddateof;
7374 foreach ($arrayofdateof as $valuedateof) {
7375 $tmpadddateof = empty($valuedateof['adddateof']) ? 0 : $valuedateof['adddateof'];
7376 $tmplabeladddateof = empty($valuedateof['labeladddateof']) ? '' : $valuedateof['labeladddateof'];
7377 $tmparray = dol_getdate($tmpadddateof);
7378 if (empty($tmplabeladddateof)) {
7379 $tmplabeladddateof = $langs->trans("DateInvoice
");
7381 $reset_scripts = 'console.log(\'Click on now link\'); ';
7382 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(\''.dol_print_date($tmpadddateof, 'dayinputnoreduce').'\');';
7383 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(\''.$tmparray['mday'].'\');';
7384 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(\''.$tmparray['mon'].'\');';
7385 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(\''.$tmparray['year'].'\');';
7386 $retstring .= ' - <button class="dpInvisibleButtons datenowlink
" id="dateofinvoice
" type="button" name="_dateofinvoice
" value="now
" onclick="'.$reset_scripts.'">'.$tmplabeladddateof.'</button>';
7401 public function selectTypeDuration($prefix, $selected = 'i', $excludetypes = array())
7405 $TDurationTypes = array(
7406 'y' => $langs->trans('Years'),
7407 'm' => $langs->trans('Month'),
7408 'w' => $langs->trans('Weeks'),
7409 'd' => $langs->trans('Days'),
7410 'h' => $langs->trans('Hours'),
7411 'i' => $langs->trans('Minutes')
7414 // Removed undesired duration types
7415 foreach ($excludetypes as $value) {
7416 unset($TDurationTypes[$value]);
7419 $retstring = '<select class="flat minwidth75 maxwidth100
" id="select_
' . $prefix . 'type_duration
" name="' . $prefix . 'type_duration
">';
7420 foreach ($TDurationTypes as $key => $typeduration) {
7421 $retstring .= '<option value="' . $key . '"';
7422 if ($key == $selected) {
7423 $retstring .= " selected
";
7425 $retstring .= ">
" . $typeduration . "</option>
";
7427 $retstring .= "</select>
";
7429 $retstring .= ajax_combobox('select_' . $prefix . 'type_duration');
7434 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
7449 public function select_duration($prefix, $iSecond = '', $disabled = 0, $typehour = 'select', $minunderhours = 0, $nooutput = 0)
7454 $retstring = '<span class="nowraponall
">';
7460 if ($iSecond != '') {
7461 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
7463 $hourSelected = convertSecondToTime($iSecond, 'allhour');
7464 $minSelected = convertSecondToTime($iSecond, 'min');
7467 if ($typehour == 'select') {
7468 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'hour
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . '>';
7469 for ($hour = 0; $hour < 25; $hour++) { // For a duration, we allow 24 hours
7470 $retstring .= '<option value="' . $hour . '"';
7471 if (is_numeric($hourSelected) && $hourSelected == $hour) {
7472 $retstring .= " selected
";
7474 $retstring .= ">
" . $hour . "</option>
";
7476 $retstring .= "</select>
";
7477 } elseif ($typehour == 'text' || $typehour == 'textselect') {
7478 $retstring .= '<input placeholder="' . $langs->trans('HourShort
') . '" type="number
" min="0
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputhour right
" value="' . (($hourSelected != '') ? ((int) $hourSelected) : '') . '">';
7480 return 'BadValueForParameterTypeHour';
7483 if ($typehour != 'text') {
7484 $retstring .= ' ' . $langs->trans('HourShort');
7486 $retstring .= '<span class="">:</span>';
7490 if ($minunderhours) {
7491 $retstring .= '<br>';
7493 if ($typehour != 'text') {
7494 $retstring .= '<span class="hideonsmartphone
"> </span>';
7498 if ($typehour == 'select' || $typehour == 'textselect') {
7499 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'min
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . '>';
7500 for ($min = 0; $min <= 55; $min += 5) {
7501 $retstring .= '<option value="' . $min . '"';
7502 if (is_numeric($minSelected) && $minSelected == $min) {
7503 $retstring .= ' selected';
7505 $retstring .= '>' . $min . '</option>';
7507 $retstring .= "</select>
";
7508 } elseif ($typehour == 'text') {
7509 $retstring .= '<input placeholder="' . $langs->trans('MinuteShort
') . '" type="number
" min="0
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputminute right
" value="' . (($minSelected != '') ? ((int) $minSelected) : '') . '">';
7512 if ($typehour != 'text') {
7513 $retstring .= ' ' . $langs->trans('MinuteShort');
7516 $retstring .= "</span>
";
7518 if (!empty($nooutput)) {
7546 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)
7548 global $langs, $conf;
7553 if (is_null($ajaxoptions)) {
7554 $ajaxoptions = array();
7557 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
7560 if ($selected && empty($selected_input_value)) {
7561 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
7562 $tickettmpselect = new Ticket($this->db);
7563 $tickettmpselect->fetch($selected);
7564 $selected_input_value = $tickettmpselect->ref;
7565 unset($tickettmpselect);
7569 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/ticket/ajax/tickets.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
7571 if (empty($hidelabel)) {
7572 $out .= $langs->trans("RefOrLabel
") . ' : ';
7573 } elseif ($hidelabel > 1) {
7574 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
7575 if ($hidelabel == 2) {
7576 $out .= img_picto($langs->trans("Search
"), 'search');
7579 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
7580 if ($hidelabel == 3) {
7581 $out .= img_picto($langs->trans("Search
"), 'search');
7584 $out .= $this->selectTicketsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
7587 if (empty($nooutput)) {
7612 public function selectTicketsList($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
7614 global $langs, $conf;
7617 $outarray = array();
7619 $selectFields = " p.rowid, p.ref, p.message
";
7622 $sql .= $selectFields;
7623 $sql .= " FROM
" . $this->db->prefix() . "ticket as p
";
7624 $sql .= ' WHERE p.entity IN (' . getEntity('ticket') . ')';
7626 // Add criteria on ref/label
7627 if ($filterkey != '') {
7629 $prefix = !getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
7630 // For natural search
7631 $search_crit = explode(' ', $filterkey);
7633 if (count($search_crit) > 1) {
7636 foreach ($search_crit as $crit) {
7640 $sql .= "(p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%' OR p.subject LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
7644 if (count($search_crit) > 1) {
7650 $sql .= $this->db->plimit($limit, 0);
7652 // Build output string
7654 $result = $this->db->query($sql);
7656 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
7657 require_once DOL_DOCUMENT_ROOT . '/core/lib/ticket.lib.php';
7659 $num = $this->db->num_rows($result);
7664 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
7665 $out .= ajax_combobox($htmlname, $events, $conf->global->TICKET_USE_SEARCH_TO_SELECT);
7668 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
7671 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
7672 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
7673 if (getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
7674 if ($showempty && !is_numeric($showempty)) {
7675 $textifempty = $langs->trans($showempty);
7677 $textifempty .= $langs->trans("All
");
7680 if ($showempty && !is_numeric($showempty)) {
7681 $textifempty = $langs->trans($showempty);
7685 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
7689 while ($num && $i < $num) {
7692 $objp = $this->db->fetch_object($result);
7694 $this->constructTicketListOption($objp, $opt, $optJson, $selected, $filterkey);
7696 // "key
" value of json key array is used by jQuery automatically as selected value
7697 // "label
" value of json key array is used by jQuery automatically as text for combo box
7699 array_push($outarray, $optJson);
7704 $out .= '</select>';
7706 $this->db->free($result);
7708 if (empty($outputmode)) {
7713 dol_print_error($this->db);
7730 protected function constructTicketListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
7736 $outkey = $objp->rowid;
7737 $outref = $objp->ref;
7738 $outtype = $objp->fk_product_type;
7740 $opt = '<option value="
' . $objp->rowid . '"';
7741 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
7744 $objRef = $objp->ref;
7745 if (!empty($filterkey) && $filterkey != '') {
7746 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1);
7749 $opt .= "</option>\n
";
7750 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
7772 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)
7774 global $langs, $conf;
7779 if (is_null($ajaxoptions)) {
7780 $ajaxoptions = array();
7783 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
7786 if ($selected && empty($selected_input_value)) {
7787 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
7788 $projecttmpselect = new Project($this->db);
7789 $projecttmpselect->fetch($selected);
7790 $selected_input_value = $projecttmpselect->ref;
7791 unset($projecttmpselect);
7795 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/projet/ajax/projects.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
7797 if (empty($hidelabel)) {
7798 $out .= $langs->trans("RefOrLabel
") . ' : ';
7799 } elseif ($hidelabel > 1) {
7800 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
7801 if ($hidelabel == 2) {
7802 $out .= img_picto($langs->trans("Search
"), 'search');
7805 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
7806 if ($hidelabel == 3) {
7807 $out .= img_picto($langs->trans("Search
"), 'search');
7810 $out .= $this->selectProjectsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
7813 if (empty($nooutput)) {
7837 public function selectProjectsList($selected = '', $htmlname = 'projectid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
7839 global $langs, $conf;
7842 $outarray = array();
7844 $selectFields = " p.rowid, p.ref
";
7847 $sql .= $selectFields;
7848 $sql .= " FROM
" . $this->db->prefix() . "projet as p
";
7849 $sql .= ' WHERE p.entity IN (' . getEntity('project') . ')';
7851 // Add criteria on ref/label
7852 if ($filterkey != '') {
7854 $prefix = !getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
7855 // For natural search
7856 $search_crit = explode(' ', $filterkey);
7858 if (count($search_crit) > 1) {
7861 foreach ($search_crit as $crit) {
7865 $sql .= "p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
7869 if (count($search_crit) > 1) {
7875 $sql .= $this->db->plimit($limit, 0);
7877 // Build output string
7879 $result = $this->db->query($sql);
7881 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
7882 require_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php';
7884 $num = $this->db->num_rows($result);
7889 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
7890 $out .= ajax_combobox($htmlname, $events, $conf->global->PROJECT_USE_SEARCH_TO_SELECT);
7893 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
7896 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
7897 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
7898 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
7899 if ($showempty && !is_numeric($showempty)) {
7900 $textifempty = $langs->trans($showempty);
7902 $textifempty .= $langs->trans("All
");
7905 if ($showempty && !is_numeric($showempty)) {
7906 $textifempty = $langs->trans($showempty);
7910 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
7914 while ($num && $i < $num) {
7917 $objp = $this->db->fetch_object($result);
7919 $this->constructProjectListOption($objp, $opt, $optJson, $selected, $filterkey);
7921 // "key
" value of json key array is used by jQuery automatically as selected value
7922 // "label
" value of json key array is used by jQuery automatically as text for combo box
7924 array_push($outarray, $optJson);
7929 $out .= '</select>';
7931 $this->db->free($result);
7933 if (empty($outputmode)) {
7938 dol_print_error($this->db);
7955 protected function constructProjectListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
7961 $label = $objp->label;
7963 $outkey = $objp->rowid;
7964 $outref = $objp->ref;
7965 $outlabel = $objp->label;
7966 $outtype = $objp->fk_product_type;
7968 $opt = '<option value="
' . $objp->rowid . '"';
7969 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
7972 $objRef = $objp->ref;
7973 if (!empty($filterkey) && $filterkey != '') {
7974 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1);
7977 $opt .= "</option>\n
";
7978 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
8001 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)
8003 global $langs, $conf;
8008 if (is_null($ajaxoptions)) {
8009 $ajaxoptions = array();
8012 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
8015 if ($selected && empty($selected_input_value)) {
8016 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
8017 $adherenttmpselect = new Adherent($this->db);
8018 $adherenttmpselect->fetch($selected);
8019 $selected_input_value = $adherenttmpselect->ref;
8020 unset($adherenttmpselect);
8025 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/adherents/ajax/adherents.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
8027 if (empty($hidelabel)) {
8028 $out .= $langs->trans("RefOrLabel
") . ' : ';
8029 } elseif ($hidelabel > 1) {
8030 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
8031 if ($hidelabel == 2) {
8032 $out .= img_picto($langs->trans("Search
"), 'search');
8035 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
8036 if ($hidelabel == 3) {
8037 $out .= img_picto($langs->trans("Search
"), 'search');
8042 $out .= $this->selectMembersList($selected, $htmlname, $filtertype, $limit, $filterkey, $status, 0, $showempty, $forcecombo, $morecss);
8045 if (empty($nooutput)) {
8069 public function selectMembersList($selected = '', $htmlname = 'adherentid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
8071 global $langs, $conf;
8074 $outarray = array();
8076 $selectFields = " p.rowid, p.ref, p.firstname, p.lastname, p.fk_adherent_type
";
8079 $sql .= $selectFields;
8080 $sql .= " FROM
" . $this->db->prefix() . "adherent as p
";
8081 $sql .= ' WHERE p.entity IN (' . getEntity('adherent') . ')';
8083 // Add criteria on ref/label
8084 if ($filterkey != '') {
8086 $prefix = !getDolGlobalString('MEMBER_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
8087 // For natural search
8088 $search_crit = explode(' ', $filterkey);
8090 if (count($search_crit) > 1) {
8093 foreach ($search_crit as $crit) {
8097 $sql .= "(p.firstname LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
8098 $sql .= " OR p.lastname LIKE
'" . $this->db->escape($prefix . $crit) . "%')
";
8101 if (count($search_crit) > 1) {
8106 if ($status != -1) {
8107 $sql .= ' AND statut = ' . ((int) $status);
8109 $sql .= $this->db->plimit($limit, 0);
8111 // Build output string
8113 $result = $this->db->query($sql);
8115 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
8116 require_once DOL_DOCUMENT_ROOT . '/core/lib/member.lib.php';
8118 $num = $this->db->num_rows($result);
8123 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
8124 $out .= ajax_combobox($htmlname, $events, getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT') ? $conf->global->PROJECT_USE_SEARCH_TO_SELECT : '');
8127 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
8130 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
8131 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
8132 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
8133 if ($showempty && !is_numeric($showempty)) {
8134 $textifempty = $langs->trans($showempty);
8136 $textifempty .= $langs->trans("All
");
8139 if ($showempty && !is_numeric($showempty)) {
8140 $textifempty = $langs->trans($showempty);
8144 $out .= '<option value="-1
" selected>' . $textifempty . '</option>';
8148 while ($num && $i < $num) {
8151 $objp = $this->db->fetch_object($result);
8153 $this->constructMemberListOption($objp, $opt, $optJson, $selected, $filterkey);
8156 // "key
" value of json key array is used by jQuery automatically as selected value
8157 // "label
" value of json key array is used by jQuery automatically as text for combo box
8159 array_push($outarray, $optJson);
8164 $out .= '</select>';
8166 $this->db->free($result);
8168 if (empty($outputmode)) {
8173 dol_print_error($this->db);
8190 protected function constructMemberListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
8196 $outkey = $objp->rowid;
8197 $outlabel = dolGetFirstLastname($objp->firstname, $objp->lastname);
8198 $outtype = $objp->fk_adherent_type;
8200 $opt = '<option value="
' . $objp->rowid . '"';
8201 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
8203 if (!empty($filterkey) && $filterkey != '') {
8204 $outlabel = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $outlabel, 1);
8207 $opt .= "</option>\n
";
8209 $optJson = array('key' => $outkey, 'value' => $outlabel, 'type' => $outtype);
8232 public function selectForForms($objectdesc, $htmlname, $preSelectedValue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $disabled = 0, $selected_input_value = '', $objectfield = '')
8234 global $conf, $extrafields, $user;
8236 //var_dump($objectdesc); debug_print_backtrace();
8238 $objectdescorig = $objectdesc;
8240 $InfoFieldList = array();
8242 $filter = ''; // Ensure filter has value (for static analysis)
8243 $sortfield = ''; // Ensure filter has value (for static analysis)
8245 if ($objectfield) { // We must retrieve the objectdesc from the field or extrafield
8246 // Example: $objectfield = 'product:options_package' or 'myobject@mymodule:options_myfield'
8247 $tmparray = explode(':', $objectfield);
8249 // Get instance of object from $element
8250 $objectforfieldstmp = fetchObjectByElement(0, strtolower($tmparray[0]));
8252 if (is_object($objectforfieldstmp)) {
8256 if (preg_match('/^options_(.*)$/', $tmparray[1], $reg)) {
8257 // For a property in extrafields
8259 // fetch optionals attributes and labels
8260 $extrafields->fetch_name_optionals_label($objectforfieldstmp->table_element);
8262 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element]['type'][$key]) && $extrafields->attributes[$objectforfieldstmp->table_element]['type'][$key] == 'link') {
8263 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element]['param'][$key]['options'])) {
8264 $tmpextrafields = array_keys($extrafields->attributes[$objectforfieldstmp->table_element]['param'][$key]['options']);
8265 $objectdesc = $tmpextrafields[0];
8269 // For a property in ->fields
8270 if (array_key_exists($tmparray[1], $objectforfieldstmp->fields)) {
8271 $objectdesc = $objectforfieldstmp->fields[$tmparray[1]]['type'];
8272 $objectdesc = preg_replace('/^integer[^:]*:/', '', $objectdesc);
8279 // Example of value for $objectdesc:
8280 // Bom:bom/class/bom.class.php:0:t.status=1
8281 // Bom:bom/class/bom.class.php:0:t.status=1:ref
8282 // Bom:bom/class/bom.class.php:0:(t.status:=:1) OR (t.field2:=:2):ref
8283 $InfoFieldList = explode(":
", $objectdesc, 4);
8284 $vartmp = (empty($InfoFieldList[3]) ? '' : $InfoFieldList[3]);
8286 if (preg_match('/^.*:(\w*)$/', $vartmp, $reg)) {
8287 $InfoFieldList[4] = $reg[1]; // take the sort field
8289 $InfoFieldList[3] = preg_replace('/:\w*$/', '', $vartmp); // take the filter field
8291 $classname = $InfoFieldList[0];
8292 $classpath = empty($InfoFieldList[1]) ? '' : $InfoFieldList[1];
8293 //$addcreatebuttonornot = empty($InfoFieldList[2]) ? 0 : $InfoFieldList[2];
8294 $filter = empty($InfoFieldList[3]) ? '' : $InfoFieldList[3];
8295 $sortfield = empty($InfoFieldList[4]) ? '' : $InfoFieldList[4];
8297 // Load object according to $id and $element
8298 $objecttmp = fetchObjectByElement(0, strtolower($InfoFieldList[0]));
8300 // Fallback to another solution to get $objecttmp
8301 if (empty($objecttmp) && !empty($classpath)) {
8302 dol_include_once($classpath);
8304 if ($classname && class_exists($classname)) {
8305 $objecttmp = new $classname($this->db);
8310 // Make some replacement in $filter. May not be used if we used the ajax mode with $objectfield. In such a case
8311 // we propagate the $objectfield and not the filter and replacement is done by the ajax/selectobject.php component.
8312 $sharedentities = (is_object($objecttmp) && property_exists($objecttmp, 'element')) ? getEntity($objecttmp->element) : strtolower($classname);
8313 $filter = str_replace(
8314 array('__ENTITY__', '__SHARED_ENTITIES__', '__USER_ID__'),
8315 array($conf->entity, $sharedentities, $user->id),
8319 if (!is_object($objecttmp)) {
8320 dol_syslog('selectForForms: Error bad setup of field objectdescorig=' . $objectdescorig.', objectfield='.$objectfield.', objectdesc='.$objectdesc, LOG_WARNING);
8321 return 'selectForForms: Error bad setup of field objectdescorig=' . $objectdescorig.', objectfield='.$objectfield.', objectdesc='.$objectdesc;
8323 '@phan-var-force CommonObject $objecttmp';
8325 //var_dump($filter);
8326 $prefixforautocompletemode = $objecttmp->element;
8327 if ($prefixforautocompletemode == 'societe') {
8328 $prefixforautocompletemode = 'company';
8330 if ($prefixforautocompletemode == 'product') {
8331 $prefixforautocompletemode = 'produit';
8333 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) . '_USE_SEARCH_TO_SELECT'; // For example COMPANY_USE_SEARCH_TO_SELECT
8335 dol_syslog(get_class($this) . "::selectForForms filter=
" . $filter, LOG_DEBUG);
8337 // Generate the combo HTML component
8339 if (!empty($conf->use_javascript_ajax) && getDolGlobalString($confkeyforautocompletemode) && !$forcecombo) {
8340 // No immediate load of all database
8343 if ($preSelectedValue && empty($selected_input_value)) {
8344 $objecttmp->fetch($preSelectedValue);
8345 $selected_input_value = ($prefixforautocompletemode == 'company' ? $objecttmp->name : $objecttmp->ref);
8347 $oldValueForShowOnCombobox = 0;
8348 foreach ($objecttmp->fields as $fieldK => $fielV) {
8349 if (!array_key_exists('showoncombobox', $fielV) || !$fielV['showoncombobox'] || empty($objecttmp->$fieldK)) {
8353 if (!$oldValueForShowOnCombobox) {
8354 $selected_input_value = '';
8357 $selected_input_value .= $oldValueForShowOnCombobox ? ' - ' : '';
8358 $selected_input_value .= $objecttmp->$fieldK;
8359 $oldValueForShowOnCombobox = empty($fielV['showoncombobox']) ? 0 : $fielV['showoncombobox'];
8363 // Set url and param to call to get json of the search results
8364 $urlforajaxcall = DOL_URL_ROOT . '/core/ajax/selectobject.php';
8365 $urloption = 'htmlname=' . urlencode($htmlname) . '&outjson=1&objectdesc=' . urlencode($objectdescorig) . '&objectfield='.urlencode($objectfield) . ($sortfield ? '&sortfield=' . urlencode($sortfield) : '');
8367 // Activate the auto complete using ajax call.
8368 $out .= ajax_autocompleter($preSelectedValue, $htmlname, $urlforajaxcall, $urloption, getDolGlobalString($confkeyforautocompletemode), 0);
8369 $out .= '<!-- force css to be higher than dialog popup --><style type="text/css
">.ui-autocomplete { z-index: 1010; }</style>';
8370 $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) . '"' : '') . ' />';
8372 // Immediate load of table record.
8373 $out .= $this->selectForFormsList($objecttmp, $htmlname, $preSelectedValue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled, $sortfield, $filter);
8400 public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $outputmode = 0, $disabled = 0, $sortfield = '', $filter = '')
8402 global $langs, $user, $hookmanager;
8404 //print "$htmlname, $preselectedvalue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, $outputmode, $disabled
";
8406 $prefixforautocompletemode = $objecttmp->element;
8407 if ($prefixforautocompletemode == 'societe') {
8408 $prefixforautocompletemode = 'company';
8410 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) . '_USE_SEARCH_TO_SELECT'; // For example COMPANY_USE_SEARCH_TO_SELECT
8412 if (!empty($objecttmp->fields)) { // For object that declare it, it is better to use declared fields (like societe, contact, ...)
8413 $tmpfieldstoshow = '';
8414 foreach ($objecttmp->fields as $key => $val) {
8415 if (! (int) dol_eval($val['enabled'], 1, 1, '1')) {
8418 if (!empty($val['showoncombobox'])) {
8419 $tmpfieldstoshow .= ($tmpfieldstoshow ? ',' : '') . 't.' . $key;
8422 if ($tmpfieldstoshow) {
8423 $fieldstoshow = $tmpfieldstoshow;
8426 // For backward compatibility
8427 $objecttmp->fields['ref'] = array('type' => 'varchar(30)', 'label' => 'Ref', 'showoncombobox' => 1);
8430 if (empty($fieldstoshow)) {
8431 if (isset($objecttmp->fields['ref'])) {
8432 $fieldstoshow = 't.ref';
8434 $langs->load("errors
");
8435 $this->error = $langs->trans("ErrorNoFieldWithAttributeShowoncombobox
");
8436 return $langs->trans('ErrorNoFieldWithAttributeShowoncombobox');
8441 $outarray = array();
8442 $tmparray = array();
8447 $sql = "SELECT t.
rowid,
" . $fieldstoshow . " FROM
" . $this->db->prefix() . $objecttmp->table_element . " as t
";
8448 if (!empty($objecttmp->isextrafieldmanaged)) {
8449 $sql .= " LEFT JOIN
" . $this->db->prefix() . $objecttmp->table_element . "_extrafields as e ON t.
rowid=e.fk_object
";
8451 if (isset($objecttmp->ismultientitymanaged)) {
8452 if (!is_numeric($objecttmp->ismultientitymanaged)) {
8453 $tmparray = explode('@', $objecttmp->ismultientitymanaged);
8454 $sql .= " INNER JOIN
" . $this->db->prefix() . $tmparray[1] . " as parenttable ON parenttable.
rowid = t.
" . $tmparray[0];
8456 if ($objecttmp->ismultientitymanaged === 'fk_soc@societe') {
8457 if (!$user->hasRight('societe', 'client', 'voir')) {
8458 $sql .= ",
" . $this->db->prefix() . "societe_commerciaux as sc
";
8463 // Add where from hooks
8464 $parameters = array(
8465 'object' => $objecttmp,
8466 'htmlname' => $htmlname,
8467 'filter' => $filter,
8468 'searchkey' => $searchkey
8471 $reshook = $hookmanager->executeHooks('selectForFormsListWhere', $parameters); // Note that $action and $object may have been modified by hook
8472 if (!empty($hookmanager->resPrint)) {
8473 $sql .= $hookmanager->resPrint;
8475 $sql .= " WHERE 1=1
";
8476 if (isset($objecttmp->ismultientitymanaged)) {
8477 if ($objecttmp->ismultientitymanaged == 1) {
8478 $sql .= " AND t.entity IN (
" . getEntity($objecttmp->table_element) . ")
";
8480 if (!is_numeric($objecttmp->ismultientitymanaged)) {
8481 $sql .= " AND parenttable.entity = t.
" . $tmparray[0];
8483 if ($objecttmp->ismultientitymanaged == 1 && !empty($user->socid)) {
8484 if ($objecttmp->element == 'societe') {
8485 $sql .= " AND t.
rowid =
" . ((int) $user->socid);
8487 $sql .= " AND t.fk_soc =
" . ((int) $user->socid);
8490 if ($objecttmp->ismultientitymanaged === 'fk_soc@societe') {
8491 if (!$user->hasRight('societe', 'client', 'voir')) {
8492 $sql .= " AND t.
rowid = sc.fk_soc AND sc.fk_user =
" . ((int) $user->id);
8496 if ($searchkey != '') {
8497 $sql .= natural_search(explode(',', $fieldstoshow), $searchkey);
8500 if ($filter) { // Syntax example "(t.
ref:like:
'SO-%') and (t.date_creation:<:
'20160101')
"
8502 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
8503 if ($errormessage) {
8504 return 'Error forging a SQL request from an universal criteria: ' . $errormessage;
8508 $sql .= $this->db->order($sortfield ? $sortfield : $fieldstoshow, "ASC
");
8509 //$sql.=$this->db->plimit($limit, 0);
8512 // Build output string
8513 $resql = $this->db->query($sql);
8515 // Construct $out and $outarray
8516 $out .= '<select id="' . $htmlname . '" class="flat minwidth100
' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled="disabled"' : '') . ($moreparams ? ' ' . $moreparams : '') . ' name="' . $htmlname . '">' . "\n
";
8518 // Warning: Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'. Seems it is no more true with selec2 v4
8519 $textifempty = ' ';
8521 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
8522 if (getDolGlobalInt($confkeyforautocompletemode)) {
8523 if ($showempty && !is_numeric($showempty)) {
8524 $textifempty = $langs->trans($showempty);
8526 $textifempty .= $langs->trans("All
");
8530 $out .= '<option value="-1
">' . $textifempty . '</option>' . "\n
";
8533 $num = $this->db->num_rows($resql);
8537 $obj = $this->db->fetch_object($resql);
8540 $tmparray = explode(',', $fieldstoshow);
8541 $oldvalueforshowoncombobox = 0;
8542 foreach ($tmparray as $key => $val) {
8543 $val = preg_replace('/t\./', '', $val);
8544 $label .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val]['showoncombobox'] ? ' - ' : ' ') : '');
8545 $labelhtml .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val]['showoncombobox'] ? ' - ' : ' ') : '');
8546 $label .= $obj->$val;
8547 $labelhtml .= $obj->$val;
8549 $oldvalueforshowoncombobox = empty($objecttmp->fields[$val]['showoncombobox']) ? 0 : $objecttmp->fields[$val]['showoncombobox'];
8551 if (empty($outputmode)) {
8552 if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) {
8553 $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>';
8555 $out .= '<option value="' . $obj->rowid . '" data-html="' . dol_escape_htmltag($labelhtml, 0, 0, '', 0, 1) . '">' . dol_escape_htmltag($label, 0, 0, '', 0, 1) . '</option>';
8558 array_push($outarray, array('key' => $obj->rowid, 'value' => $label, 'label' => $label));
8562 if (($i % 10) == 0) {
8568 $out .= '</select>' . "\n
";
8571 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
8572 $out .= ajax_combobox($htmlname, array(), getDolGlobalInt($confkeyforautocompletemode, 0));
8575 dol_print_error($this->db);
8578 $this->result = array('nbofelement' => $num);
8610 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)
8612 global $conf, $langs;
8614 // Do we want a multiselect ?
8616 //if (preg_match('/^multi/',$htmlname)) $jsbeautify = 1;
8619 if ($value_as_key) {
8620 $array = array_combine($array, $array);
8623 '@phan-var-force array{label:string,data-html:string,disable?:int<0,1>,css?:string} $array'; // Array combine breaks information
8627 if ($addjscombo < 0) {
8628 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
8634 $idname = str_replace(array('[', ']'), array('', ''), $htmlname);
8635 $out .= '<select id="
' . preg_replace('/^\./
', '', $idname) . '" ' . ($disabled ? 'disabled="disabled" ' : '') . 'class="flat
' . (preg_replace('/^\./
', '', $htmlname)) . ($morecss ? ' ' . $morecss : '') . ' selectformat
"';
8636 $out .= ' name="' . preg_replace('/^\./
', '', $htmlname) . '" ' . ($moreparam ? $moreparam : '');
8640 $textforempty = ' ';
8641 if (!empty($conf->use_javascript_ajax)) {
8642 $textforempty = ' '; // If we use ajaxcombo, we need here to avoid to have an empty element that is too small.
8644 if (!is_numeric($show_empty)) {
8645 $textforempty = $show_empty;
8647 $out .= '<option class="optiongrey
" ' . ($moreparamonempty ? $moreparamonempty . ' ' : '') . 'value="' . (((int) $show_empty) < 0 ? $show_empty : -1) . '"' . ($id == $show_empty ? ' selected' : '') . '>' . $textforempty . '</option>' . "\n
";
8649 if (is_array($array)) {
8652 foreach ($array as $key => $value) {
8653 if (!is_array($value)) {
8654 $array[$key] = $langs->trans($value);
8656 $array[$key]['label'] = $langs->trans($value['label']);
8661 if ($sort == 'ASC') {
8663 } elseif ($sort == 'DESC') {
8667 foreach ($array as $key => $tmpvalue) {
8668 if (is_array($tmpvalue)) {
8669 $value = $tmpvalue['label'];
8670 //$valuehtml = empty($tmpvalue['data-html']) ? $value : $tmpvalue['data-html'];
8671 $disabled = empty($tmpvalue['disabled']) ? '' : ' disabled';
8672 $style = empty($tmpvalue['css']) ? '' : ' class="' . $tmpvalue['css
'] . '"';
8675 //$valuehtml = $tmpvalue;
8679 if (!empty($disablebademail)) {
8680 if (($disablebademail == 1 && !preg_match('/<.+@.+>/', $value))
8681 || ($disablebademail == 2 && preg_match('/---/', $value))) {
8682 $disabled = ' disabled';
8683 $style = ' class="warning
"';
8686 if ($key_in_label) {
8687 if (empty($nohtmlescape)) {
8688 $selectOptionValue = dol_escape_htmltag($key . ' - ' . ($maxlen ? dol_trunc($value, $maxlen) : $value));
8690 $selectOptionValue = $key . ' - ' . ($maxlen ? dol_trunc($value, $maxlen) : $value);
8693 if (empty($nohtmlescape)) {
8694 $selectOptionValue = dol_escape_htmltag($maxlen ? dol_trunc($value, $maxlen) : $value);
8696 $selectOptionValue = $maxlen ? dol_trunc($value, $maxlen) : $value;
8698 if ($value == '' || $value == '-') {
8699 $selectOptionValue = ' ';
8702 $out .= '<option value="' . $key . '"';
8703 $out .= $style . $disabled;
8704 if (is_array($id)) {
8705 if (in_array($key, $id) && !$disabled) {
8706 $out .= ' selected'; // To preselect a value
8709 $id = (string) $id; // if $id = 0, then $id = '0'
8710 if ($id != '' && (($id == (string) $key) || ($id == 'ifone' && count($array) == 1)) && !$disabled) {
8711 $out .= ' selected'; // To preselect a value
8714 if (!empty($nohtmlescape)) { // deprecated. Use instead the key 'data-html' into input $array, managed at next step to use HTML content.
8715 $out .= ' data-html="' . dol_escape_htmltag($selectOptionValue) . '"';
8718 if (is_array($tmpvalue)) {
8719 foreach ($tmpvalue as $keyforvalue => $valueforvalue) {
8720 if (preg_match('/^data-/', $keyforvalue)) { // The best solution if you want to use HTML values into the list is to use data-html.
8721 $out .= ' '.dol_escape_htmltag($keyforvalue).'="'.dol_escape_htmltag($valueforvalue).'"';
8726 $out .= $selectOptionValue;
8727 $out .= "</option>\n
";
8730 $out .= "</select>
";
8732 // Add code for jquery to use multiselect
8733 if ($addjscombo && $jsbeautify) {
8734 // Enhance with select2
8735 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
8736 $out .= ajax_combobox($idname, array(), 0, 0, 'resolve', (((int) $show_empty) < 0 ? (string) $show_empty : '-1'), $morecss);
8760 public static function selectArrayAjax($htmlname, $url, $id = '', $moreparam = '', $moreparamtourl = '', $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0)
8762 global $conf, $langs;
8763 global $delayedhtmlcontent; // Will be used later outside of this function
8765 // TODO Use an internal dolibarr component instead of select2
8766 if (!getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') && !defined('REQUIRE_JQUERY_MULTISELECT')) {
8770 $out = '<select type="text
" class="' . $htmlname . ($morecss ? ' ' . $morecss : '') . '" ' . ($moreparam ? $moreparam . ' ' : '') . 'name="' . $htmlname . '"></select>';
8773 if (!empty($conf->use_javascript_ajax)) {
8774 $tmpplugin = 'select2';
8775 $outdelayed = "\n
" . '<!-- JS CODE TO ENABLE ' . $tmpplugin . ' for id ' . $htmlname . ' -->
8776 <script nonce="' . getNonce() . '">
8777 $(document).ready(function () {
8779 ' . ($callurlonselect ? 'var saveRemoteData = [];' : '') . '
8781 $(".
' . $htmlname . '").select2({
8784 url: "' . $url . '",
8787 data: function (params) {
8789 q: params.term, // search term
8793 processResults: function (data) {
8794 // parse the results into the format expected by Select2.
8795 // since we are using custom formatting functions we do not need to alter the remote JSON data
8796 //console.log(data);
8797 saveRemoteData = data;
8798 /* format json result for select2 */
8800 $.each( data, function( key, value ) {
8801 result.push({id: key, text: value.text});
8803 //return {results:[{id:\'none\', text:\'aa\'}, {id:\'rrr\', text:\'Red\'},{id:\'bbb\', text:\'Search a into projects\'}], more:false}
8804 //console.log(result);
8805 return {results: result, more: false}
8809 language: select2arrayoflanguage,
8810 containerCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag */
8811 placeholder:
"' . dol_escape_js($placeholder) . '",
8812 escapeMarkup: function (markup) {
return markup; },
8813 minimumInputLength:
' . ((int) $minimumInputLength) . ',
8814 formatResult:
function (result, container, query, escapeMarkup) {
8815 return escapeMarkup(result.text);
8819 ' . ($callurlonselect ? '
8821 $(
".' . $htmlname . '").change(
function() {
8822 var selected = $(
".' . $htmlname . '").val();
8823 console.log(
"We select in selectArrayAjax the entry "+selected)
8824 $(
".' . $htmlname . '").val(
"");
8825 $.each( saveRemoteData,
function( key, value ) {
8826 if (key == selected)
8828 console.log(
"selectArrayAjax - Do a redirect to "+value.url)
8829 location.assign(value.url);
8838 if ($acceptdelayedhtml) {
8839 $delayedhtmlcontent .= $outdelayed;
8841 $out .= $outdelayed;
8865 public static function selectArrayFilter($htmlname, $array, $id = '
', $moreparam = '', $disableFiltering = 0, $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0, $textfortitle = '')
8867 global $conf, $langs;
8868 global $delayedhtmlcontent; // Will be used later outside of this function
8870 // TODO Use an internal dolibarr component instead of select2
8871 if (!getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT
') && !defined('REQUIRE_JQUERY_MULTISELECT
')) {
8875 $out = '<select
type=
"text"'.($textfortitle ? ' title=
"'.dol_escape_htmltag($textfortitle).'"' : '').' id=
"'.$htmlname.'" class=
"'.$htmlname.($morecss ? ' ' . $morecss : '').'"'.($moreparam ? ' '.$moreparam : '').' name=
"'.$htmlname.'"><option></option></select>
';
8877 $formattedarrayresult = array();
8879 foreach ($array as $key => $value) {
8880 $o = new stdClass();
8882 $o->text = $value['text
'];
8883 $o->url = $value['url
'];
8884 $formattedarrayresult[] = $o;
8888 if (!empty($conf->use_javascript_ajax)) {
8889 $tmpplugin = 'select2
';
8890 $outdelayed = "\n" . '<!-- JS CODE TO ENABLE
' . $tmpplugin . ' for id ' . $htmlname . ' -->
8891 <script nonce=
"' . getNonce() . '">
8892 $(document).ready(
function () {
8893 var data =
' . json_encode($formattedarrayresult) . ';
8895 ' . ($callurlonselect ? 'var saveRemoteData =
' . json_encode($array) . ';
' : '') . '
8897 $(
".' . $htmlname . '").select2({
8899 language: select2arrayoflanguage,
8900 containerCssClass: \
':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag */
8902 escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
8903 minimumInputLength: ' . $minimumInputLength .
',
8904 formatResult: function (result, container, query, escapeMarkup) {
8905 return escapeMarkup(result.text);
8907 matcher: function (params, data) {
8909 if(! data.id) return null;';
8911 if ($callurlonselect) {
8915 var urlBase = data.url;
8916 var separ = urlBase.indexOf("?") >= 0 ? "&" : "?";
8917 /* console.log("params.term="+params.term); */
8918 /* console.log("params.term encoded="+encodeURIComponent(params.term)); */
8919 saveRemoteData[data.id].url = urlBase + separ + "search_all=" + encodeURIComponent(params.term.replace(/\"/g, ""));';
8922 if (!$disableFiltering) {
8925 if(data.text.match(new RegExp(params.term))) {
8940 ' . ($callurlonselect ?
'
8941 /* Code to execute a GET when we select a value */
8942 $(".' . $htmlname .
'").change(function() {
8943 var selected = $(".' . $htmlname .
'").val();
8944 console.log("We select "+selected)
8946 $(".' . $htmlname .
'").val(""); /* reset visible combo value */
8947 $.each( saveRemoteData, function( key, value ) {
8948 if (key == selected)
8950 console.log("selectArrayFilter - Do a redirect to "+value.url)
8951 location.assign(value.url);
8960 if ($acceptdelayedhtml) {
8961 $delayedhtmlcontent .= $outdelayed;
8963 $out .= $outdelayed;
8986 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)
8988 global $conf, $langs;
8992 if ($addjscombo < 0) {
9000 $useenhancedmultiselect = 0;
9001 if (!empty($conf->use_javascript_ajax) && !defined(
'MAIN_DO_NOT_USE_JQUERY_MULTISELECT') && (
getDolGlobalString(
'MAIN_USE_JQUERY_MULTISELECT') || defined(
'REQUIRE_JQUERY_MULTISELECT'))) {
9003 $useenhancedmultiselect = 1;
9010 $out .=
'<input type="hidden" name="'.$htmlname.
'_multiselect" value="1">';
9012 $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";
9013 if (is_array($array) && !empty($array)) {
9014 if ($value_as_key) {
9015 $array = array_combine($array, $array);
9018 if (!empty($array)) {
9019 foreach ($array as $key => $value) {
9025 if (is_array($value) && array_key_exists(
'id', $value) && array_key_exists(
'label', $value)) {
9026 $tmpkey = $value[
'id'];
9027 $tmpvalue = empty($value[
'label']) ?
'' : $value[
'label'];
9028 $tmpcolor = empty($value[
'color']) ?
'' : $value[
'color'];
9029 $tmppicto = empty($value[
'picto']) ?
'' : $value[
'picto'];
9030 $tmplabelhtml = empty($value[
'labelhtml']) ? (empty($value[
'data-html']) ?
'' : $value[
'data-html']): $value[
'labelhtml'];
9032 $newval = ($translate ? $langs->trans($tmpvalue) : $tmpvalue);
9033 $newval = ($key_in_label ? $tmpkey .
' - ' . $newval : $newval);
9035 $out .=
'<option value="' . $tmpkey .
'"';
9036 if (is_array($selected) && !empty($selected) && in_array((
string) $tmpkey, $selected) && ((string) $tmpkey !=
'')) {
9037 $out .=
' selected';
9039 if (!empty($tmplabelhtml)) {
9042 $tmplabelhtml = ($tmppicto ?
img_picto(
'', $tmppicto,
'class="pictofixedwidth" style="color: #' . $tmpcolor .
'"') :
'') . $newval;
9047 $out .=
'</option>' .
"\n";
9051 $out .=
'</select>' .
"\n";
9054 if (!empty($conf->use_javascript_ajax) &&
getDolGlobalString(
'MAIN_USE_JQUERY_MULTISELECT') || defined(
'REQUIRE_JQUERY_MULTISELECT')) {
9055 $out .=
"\n" .
'<!-- JS CODE TO ENABLE select for id ' . $htmlname .
', addjscombo=' . $addjscombo .
' -->';
9056 $out .=
"\n" .
'<script nonce="' .
getNonce() .
'">' .
"\n";
9057 if ($addjscombo == 1) {
9058 $tmpplugin = !
getDolGlobalString(
'MAIN_USE_JQUERY_MULTISELECT') ? constant(
'REQUIRE_JQUERY_MULTISELECT') : $conf->global->MAIN_USE_JQUERY_MULTISELECT;
9059 $out .=
'function formatResult(record, container) {' .
"\n";
9062 $out .=
' if ($(record.element).attr("data-html") != undefined && typeof htmlEntityDecodeJs === "function") {';
9064 $out .=
' return htmlEntityDecodeJs($(record.element).attr("data-html"));';
9066 $out .=
' return record.text;';
9068 $out .=
'function formatSelection(record) {' .
"\n";
9069 if ($elemtype ==
'category') {
9070 $out .=
'return \'<span><img src="' . DOL_URL_ROOT .
'/theme/eldy/img/object_category.png"> \'+record.text+\'</span>\';';
9072 $out .=
'return record.text;';
9075 $out .=
'$(document).ready(function () {
9076 $(\'#' . $htmlname .
'\').
' . $tmpplugin . '({
';
9084 $out .= ' dir: \
'ltr\',
9085 containerCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag (ko with multiselect) */
9086 dropdownCssClass: \'' . $morecss .
'\',
9088 formatResult: formatResult,
9089 templateResult: formatResult,
9090 escapeMarkup:
function (markup) {
return markup; },
9092 formatSelection: formatSelection,
9093 templateSelection: formatSelection
9098 $(\
'#' . $htmlname .
' + .select2\').addClass(\'' . $morecss .
'\');
9100 } elseif ($addjscombo == 2 && !defined('DISABLE_MULTISELECT
')) {
9102 // TODO external lib multiselect/jquery.multi-select.js must have been loaded to use this multiselect plugin
9104 $out .= 'console.log(\
'addjscombo=2 for htmlname=' . $htmlname .
'\');
';
9105 $out .= '$(document).ready(
function () {
9106 $(\
'#' . $htmlname .
'\').multiSelect({
9107 containerHTML: \
'<div class="multi-select-container">\',
9108 menuHTML: \'<div class="multi-select-menu">\',
9109 buttonHTML: \'<span class="multi-select-button ' . $morecss .
'">\',
9110 menuItemHTML: \'<label class="multi-select-menuitem">\',
9111 activeClass: \'multi-select-container--open\',
9112 noneText: \'' . $placeholder .
'\'
9116 $out .= '</script>
';
9134 public static function multiSelectArrayWithCheckbox($htmlname, &$array, $varpage, $pos = '
')
9136 global $langs, $user;
9138 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER
')) {
9141 if (empty($array)) {
9145 $tmpvar = "MAIN_SELECTEDFIELDS_" . $varpage; // To get list of saved selected fields to show
9147 if (!empty($user->conf->$tmpvar)) { // A list of fields was already customized for user
9148 $tmparray = explode(',
', $user->conf->$tmpvar);
9149 foreach ($array as $key => $val) {
9151 //var_dump($tmparray);
9152 if (in_array($key, $tmparray)) {
9153 $array[$key]['checked
'] = 1;
9155 $array[$key]['checked
'] = 0;
9158 } else { // There is no list of fields already customized for user
9159 foreach ($array as $key => $val) {
9160 if (!empty($array[$key]['checked
']) && $array[$key]['checked
'] < 0) {
9161 $array[$key]['checked
'] = 0;
9166 $listoffieldsforselection = '';
9167 $listcheckedstring = '';
9169 foreach ($array as $key => $val) {
9171 // var_dump(array_key_exists('enabled
', $val));
9172 // var_dump(!$val['enabled
']);
9173 if (array_key_exists('enabled
', $val) && isset($val['enabled
']) && !$val['enabled
']) {
9174 unset($array[$key]); // We don't want
this field
9177 if (!empty($val[
'type']) && $val[
'type'] ==
'separate') {
9182 if (!empty($val[
'label']) && $val[
'label']) {
9183 if (!empty($val[
'langfile']) && is_object($langs)) {
9184 $langs->load($val[
'langfile']);
9188 $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>';
9189 $listcheckedstring .= (empty($val[
'checked']) ?
'' : $key .
',');
9193 $out =
'<!-- Component multiSelectArrayWithCheckbox ' . $htmlname .
' -->
9195 <dl class="dropdown">
9197 <a href="#' . $htmlname .
'">
9200 <input type="hidden" class="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $listcheckedstring .
'">
9202 <dd class="dropdowndd">
9203 <div class="multiselectcheckbox'.$htmlname.
'">
9204 <ul class="'.$htmlname.($pos ==
'1' ?
'left' :
'').
'">
9205 <li><input class="inputsearch_dropdownselectedfields width90p minwidth200imp" style="width:90%;" type="text" placeholder="'.$langs->trans(
'Search').
'"></li>
9206 '.$listoffieldsforselection.
'
9212 <script nonce="' .
getNonce() .
'" type="text/javascript">
9213 jQuery(document).ready(function () {
9214 $(\'.multiselectcheckbox' . $htmlname .
' input[type="checkbox"]\').on(\'click\', function () {
9215 console.log("A new field was added/removed, we edit field input[name=formfilteraction]");
9217 $("input:hidden[name=formfilteraction]").val(\'listafterchangingselectedfields\'); // Update field so we know we changed something on selected fields after POST
9219 var title = $(this).val() + ",";
9220 if ($(this).is(\':checked\')) {
9221 $(\'.' . $htmlname .
'\').val(title + $(\
'.' . $htmlname .
'\').val());
9224 $(\
'.' . $htmlname .
'\').val( $(\
'.' . $htmlname .
'\').val().replace(title, \
'\') )
9229 $(
"input.inputsearch_dropdownselectedfields").on(
"keyup",
function() {
9230 var value = $(
this).val().toLowerCase();
9231 $(\
'.multiselectcheckbox'.$htmlname.
' li > label\').filter(function() {
9232 $(this).parent().toggle($(this).text().toLowerCase().indexOf(value) > -1)
9255 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
9258 $categories = $cat->containing($id, $type);
9260 if ($rendermode == 1) {
9262 foreach ($categories as $c) {
9263 $ways = $c->print_all_ways(
' >> ', ($nolink ?
'none' :
''), 0, 1);
9264 foreach ($ways as $way) {
9265 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ?
' style="background: #' . $c->color .
';"' :
' style="background: #bbb"') .
'>' . $way .
'</li>';
9268 if (empty($toprint)) {
9271 return '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
9275 if ($rendermode == 0) {
9276 $arrayselected = array();
9278 foreach ($categories as $c) {
9279 $arrayselected[] = $c->id;
9282 return $this->
multiselectarray(
'categories', $cate_arbo, $arrayselected, 0, 0,
'', 0,
'100%',
'disabled',
'category');
9285 return 'ErrorBadValueForParameterRenderMode';
9299 global $conf, $langs, $hookmanager;
9300 global $bc, $action;
9305 $hookmanager->initHooks(array(
'commonobject'));
9306 $parameters = array(
9307 'morehtmlright' => $morehtmlright,
9308 'compatibleImportElementsList' => &$compatibleImportElementsList,
9310 $reshook = $hookmanager->executeHooks(
'showLinkedObjectBlock', $parameters,
$object, $action);
9312 $nbofdifferenttypes = count(
$object->linkedObjects);
9314 if (empty($reshook)) {
9315 print
'<!-- showLinkedObjectBlock -->';
9316 print
load_fiche_titre($langs->trans($title), $morehtmlright,
'', 0, 0,
'showlinkedobjectblock');
9319 print
'<div class="div-table-responsive-no-min">';
9320 print
'<table class="noborder allwidth" data-block="showLinkedObject" data-element="' .
$object->element .
'" data-elementid="' .
$object->id .
'" >';
9322 print
'<tr class="liste_titre">';
9323 print
'<td>' . $langs->trans(
"Type") .
'</td>';
9324 print
'<td>' . $langs->trans(
"Ref") .
'</td>';
9325 print
'<td class="center"></td>';
9326 print
'<td class="center">' . $langs->trans(
"Date") .
'</td>';
9327 print
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
9328 print
'<td class="right">' . $langs->trans(
"Status") .
'</td>';
9332 $nboftypesoutput = 0;
9334 foreach (
$object->linkedObjects as $objecttype => $objects) {
9335 $tplpath = $element = $subelement = $objecttype;
9338 $showImportButton =
false;
9339 if (!empty($compatibleImportElementsList) && in_array($element, $compatibleImportElementsList)) {
9340 $showImportButton =
true;
9344 if ($objecttype !=
'supplier_proposal' && preg_match(
'/^([^_]+)_([^_]+)/i', $objecttype, $regs)) {
9345 $element = $regs[1];
9346 $subelement = $regs[2];
9347 $tplpath = $element .
'/' . $subelement;
9349 $tplname =
'linkedobjectblock';
9352 if ($objecttype ==
'facture') {
9353 $tplpath =
'compta/' . $element;
9354 if (!isModEnabled(
'invoice')) {
9357 } elseif ($objecttype ==
'facturerec') {
9358 $tplpath =
'compta/facture';
9359 $tplname =
'linkedobjectblockForRec';
9360 if (!isModEnabled(
'invoice')) {
9363 } elseif ($objecttype ==
'propal') {
9364 $tplpath =
'comm/' . $element;
9365 if (!isModEnabled(
'propal')) {
9368 } elseif ($objecttype ==
'supplier_proposal') {
9369 if (!isModEnabled(
'supplier_proposal')) {
9372 } elseif ($objecttype ==
'shipping' || $objecttype ==
'shipment' || $objecttype ==
'expedition') {
9373 $tplpath =
'expedition';
9374 if (!isModEnabled(
'shipping')) {
9377 } elseif ($objecttype ==
'reception') {
9378 $tplpath =
'reception';
9379 if (!isModEnabled(
'reception')) {
9382 } elseif ($objecttype ==
'delivery') {
9383 $tplpath =
'delivery';
9387 } elseif ($objecttype ==
'ficheinter') {
9388 $tplpath =
'fichinter';
9389 if (!isModEnabled(
'intervention')) {
9392 } elseif ($objecttype ==
'invoice_supplier') {
9393 $tplpath =
'fourn/facture';
9394 } elseif ($objecttype ==
'order_supplier') {
9395 $tplpath =
'fourn/commande';
9396 } elseif ($objecttype ==
'expensereport') {
9397 $tplpath =
'expensereport';
9398 } elseif ($objecttype ==
'subscription') {
9399 $tplpath =
'adherents';
9400 } elseif ($objecttype ==
'conferenceorbooth') {
9401 $tplpath =
'eventorganization';
9402 } elseif ($objecttype ==
'conferenceorboothattendee') {
9403 $tplpath =
'eventorganization';
9404 } elseif ($objecttype ==
'mo') {
9406 if (!isModEnabled(
'mrp')) {
9411 global $linkedObjectBlock;
9412 $linkedObjectBlock = $objects;
9415 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array(
'/' . $tplpath .
'/tpl'));
9416 foreach ($dirtpls as $reldir) {
9417 $reldir = rtrim($reldir,
'/');
9418 if ($nboftypesoutput == ($nbofdifferenttypes - 1)) {
9419 global $noMoreLinkedObjectBlockAfter;
9420 $noMoreLinkedObjectBlockAfter = 1;
9423 $res = @include
dol_buildpath($reldir .
'/' . $tplname .
'.tpl.php');
9431 if (!$nboftypesoutput) {
9432 print
'<tr><td class="impair" colspan="7"><span class="opacitymedium">' . $langs->trans(
"None") .
'</span></td></tr>';
9437 if (!empty($compatibleImportElementsList)) {
9438 $res = @include
dol_buildpath(
'core/tpl/objectlinked_lineimport.tpl.php');
9444 return $nbofdifferenttypes;
9457 global $conf, $langs, $hookmanager;
9461 $linktoelemlist =
'';
9462 $listofidcompanytoscan =
'';
9464 if (!is_object(
$object->thirdparty)) {
9468 $possiblelinks = array();
9469 if (is_object(
$object->thirdparty) && !empty(
$object->thirdparty->id) &&
$object->thirdparty->id > 0) {
9470 $listofidcompanytoscan =
$object->thirdparty->id;
9472 $listofidcompanytoscan .=
',' .
$object->thirdparty->parent;
9475 include_once DOL_DOCUMENT_ROOT .
'/projet/class/project.class.php';
9476 $tmpproject =
new Project($this->db);
9477 $tmpproject->fetch(
$object->fk_project);
9478 if ($tmpproject->socid > 0 && ($tmpproject->socid !=
$object->thirdparty->id)) {
9479 $listofidcompanytoscan .=
',' . $tmpproject->socid;
9484 $possiblelinks = array(
9486 'enabled' => isModEnabled(
'propal'),
9488 'label' =>
'LinkToProposal',
9489 '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') .
')'),
9490 'shipping' => array(
9491 'enabled' => isModEnabled(
'shipping'),
9493 'label' =>
'LinkToExpedition',
9494 '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') .
')'),
9496 'enabled' => isModEnabled(
'order'),
9498 'label' =>
'LinkToOrder',
9499 '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') .
')'),
9501 'enabled' => isModEnabled(
'invoice'),
9503 'label' =>
'LinkToInvoice',
9504 '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') .
')'),
9505 'invoice_template' => array(
9506 'enabled' => isModEnabled(
'invoice'),
9508 'label' =>
'LinkToTemplateInvoice',
9509 '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') .
')'),
9511 'enabled' => isModEnabled(
'contract'),
9513 'label' =>
'LinkToContract',
9514 '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
9515 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'
9517 'fichinter' => array(
9518 'enabled' => isModEnabled(
'intervention'),
9520 'label' =>
'LinkToIntervention',
9521 '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') .
')'),
9522 'supplier_proposal' => array(
9523 'enabled' => isModEnabled(
'supplier_proposal'),
9525 'label' =>
'LinkToSupplierProposal',
9526 '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') .
')'),
9527 'order_supplier' => array(
9528 'enabled' => isModEnabled(
"supplier_order"),
9530 'label' =>
'LinkToSupplierOrder',
9531 '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') .
')'),
9532 'invoice_supplier' => array(
9533 'enabled' => isModEnabled(
"supplier_invoice"),
9534 'perms' => 1,
'label' =>
'LinkToSupplierInvoice',
9535 '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') .
')'),
9537 'enabled' => isModEnabled(
'ticket'),
9539 'label' =>
'LinkToTicket',
9540 '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') .
')'),
9542 'enabled' => isModEnabled(
'mrp'),
9544 'label' =>
'LinkToMo',
9545 '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') .
')')
9549 if (
$object->table_element ==
'commande_fournisseur') {
9550 $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').
')';
9551 } elseif (
$object->table_element ==
'mrp_mo') {
9552 $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').
')';
9556 if (!empty($listofidcompanytoscan)) {
9558 $hookmanager->initHooks(array(
'commonobject'));
9559 $parameters = array(
'listofidcompanytoscan' => $listofidcompanytoscan,
'possiblelinks' => $possiblelinks);
9560 $reshook = $hookmanager->executeHooks(
'showLinkToObjectBlock', $parameters,
$object, $action);
9563 if (empty($reshook)) {
9564 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
9565 $possiblelinks = array_merge($possiblelinks, $hookmanager->resArray);
9567 } elseif ($reshook > 0) {
9568 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
9569 $possiblelinks = $hookmanager->resArray;
9573 foreach ($possiblelinks as $key => $possiblelink) {
9576 if (empty($possiblelink[
'enabled'])) {
9580 if (!empty($possiblelink[
'perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || !in_array($key, $excludelinksto))) {
9581 print
'<div id="' . $key .
'list"' . (empty($conf->use_javascript_ajax) ?
'' :
' style="display:none"') .
'>';
9585 print
'<!-- form to add a link from anywhere -->'.
"\n";
9586 print
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinkedbyref' . $key .
'">';
9587 print
'<input type="hidden" name="id" value="' .
$object->id .
'">';
9588 print
'<input type="hidden" name="action" value="addlinkbyref">';
9589 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
9590 print
'<input type="hidden" name="addlink" value="' . $key .
'">';
9591 print
'<table class="noborder">';
9594 print
'<td class="center"><input type="text" placeholder="'.dol_escape_htmltag($langs->trans(
"Ref")).
'" name="reftolinkto" value="' .
dol_escape_htmltag(
GETPOST(
'reftolinkto',
'alpha')) .
'"> ';
9595 print
'<input type="submit" class="button small valignmiddle" value="' . $langs->trans(
'ToLink') .
'"> ';
9596 print
'<input type="submit" class="button small" name="cancel" value="' . $langs->trans(
'Cancel') .
'"></td>';
9602 $sql = $possiblelink[
'sql'];
9604 $resqllist = $this->db->query($sql);
9606 $num = $this->db->num_rows($resqllist);
9610 print
'<!-- form to add a link from object to same thirdparty -->'.
"\n";
9611 print
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinked' . $key .
'">';
9612 print
'<input type="hidden" name="action" value="addlink">';
9613 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
9614 print
'<input type="hidden" name="id" value="' .
$object->id .
'">';
9615 print
'<input type="hidden" name="addlink" value="' . $key .
'">';
9616 print
'<table class="noborder">';
9617 print
'<tr class="liste_titre">';
9618 print
'<td class="nowrap"></td>';
9619 print
'<td class="center">' . $langs->trans(
"Ref") .
'</td>';
9620 print
'<td class="left">' . $langs->trans(
"RefCustomer") .
'</td>';
9621 print
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
9622 print
'<td class="left">' . $langs->trans(
"Company") .
'</td>';
9625 $objp = $this->db->fetch_object($resqllist);
9627 print
'<tr class="oddeven">';
9628 print
'<td class="left">';
9629 print
'<input type="radio" name="idtolinkto" id="' . $key .
'_' . $objp->rowid .
'" value="' . $objp->rowid .
'">';
9631 print
'<td class="center"><label for="' . $key .
'_' . $objp->rowid .
'">' . $objp->ref .
'</label></td>';
9632 print
'<td>' . (!empty($objp->ref_client) ? $objp->ref_client : (!empty($objp->ref_supplier) ? $objp->ref_supplier :
'')) .
'</td>';
9633 print
'<td class="right">';
9634 if ($possiblelink[
'label'] ==
'LinkToContract') {
9635 $form =
new Form($this->db);
9636 print $form->textwithpicto(
'', $langs->trans(
"InformationOnLinkToContract")) .
' ';
9638 print
'<span class="amount">' . (isset($objp->total_ht) ?
price($objp->total_ht) :
'') .
'</span>';
9640 print
'<td>' . $objp->name .
'</td>';
9645 print
'<div class="center">';
9647 print
'<input type="submit" class="button valignmiddle marginleftonly marginrightonly small" value="' . $langs->trans(
'ToLink') .
'">';
9649 if (empty($conf->use_javascript_ajax)) {
9650 print
'<input type="submit" class="button button-cancel marginleftonly marginrightonly small" name="cancel" value="' . $langs->trans(
"Cancel") .
'"></div>';
9652 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>';
9655 $this->db->free($resqllist);
9663 $linktoelemlist .=
'<li><a href="#linkto' . $key .
'" class="linkto dropdowncloseonclick" rel="' . $key .
'">' . $langs->trans($possiblelink[
'label']) .
' (' . $num .
')</a></li>';
9666 $linktoelemlist .=
'<li><span class="linktodisabled">' . $langs->trans($possiblelink[
'label']) .
' (0)</span></li>';
9671 if ($linktoelemlist) {
9673 <dl class="dropdown" id="linktoobjectname">
9675 if (!empty($conf->use_javascript_ajax)) {
9676 $linktoelem .=
'<dt><a href="#linktoobjectname"><span class="fas fa-link paddingrightonly"></span>' . $langs->trans(
"LinkTo") .
'...</a></dt>';
9678 $linktoelem .=
'<dd>
9679 <div class="multiselectlinkto">
9680 <ul class="ulselectedfields">' . $linktoelemlist .
'
9689 if (!empty($conf->use_javascript_ajax)) {
9690 print
'<!-- Add js to show linkto box -->
9691 <script nonce="' .
getNonce() .
'">
9692 jQuery(document).ready(function() {
9693 jQuery(".linkto").click(function() {
9694 console.log("We choose to show/hide links for rel="+jQuery(this).attr(\'rel\')+" so #"+jQuery(this).attr(\'rel\')+"list");
9695 jQuery("#"+jQuery(this).attr(\'rel\')+"list").toggle();
9719 public function selectyesno($htmlname, $value =
'', $option = 0, $disabled =
false, $useempty = 0, $addjscombo = 0, $morecss =
'', $labelyes =
'Yes', $labelno =
'No')
9730 $disabled = ($disabled ?
' disabled' :
'');
9732 $resultyesno =
'<select class="flat width75' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'"' . $disabled .
'>' .
"\n";
9734 $resultyesno .=
'<option value="-1"' . (($value < 0) ?
' selected' :
'') .
'> </option>' .
"\n";
9736 if ((
"$value" ==
'yes') || ($value == 1)) {
9737 $resultyesno .=
'<option value="' . $yes .
'" selected>' . $langs->trans($labelyes) .
'</option>' .
"\n";
9738 $resultyesno .=
'<option value="' . $no .
'">' . $langs->trans($labelno) .
'</option>' .
"\n";
9740 $selected = (($useempty && $value !=
'0' && $value !=
'no') ?
'' :
' selected');
9741 $resultyesno .=
'<option value="' . $yes .
'">' . $langs->trans($labelyes) .
'</option>' .
"\n";
9742 $resultyesno .=
'<option value="' . $no .
'"' . $selected .
'>' . $langs->trans($labelno) .
'</option>' .
"\n";
9744 $resultyesno .=
'</select>' .
"\n";
9747 $resultyesno .=
ajax_combobox($htmlname, array(), 0, 0,
'resolve', ($useempty < 0 ? (
string) $useempty :
'-1'), $morecss);
9750 return $resultyesno;
9767 $sql =
"SELECT rowid, label";
9768 $sql .=
" FROM " . $this->db->prefix() .
"export_model";
9769 $sql .=
" WHERE type = '" . $this->db->escape($type) .
"'";
9770 $sql .=
" ORDER BY rowid";
9771 $result = $this->db->query($sql);
9773 print
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
9775 print
'<option value="-1"> </option>';
9778 $num = $this->db->num_rows($result);
9781 $obj = $this->db->fetch_object($result);
9782 if ($selected == $obj->rowid) {
9783 print
'<option value="' . $obj->rowid .
'" selected>';
9785 print
'<option value="' . $obj->rowid .
'">';
9815 public function showrefnav(
$object, $paramid, $morehtml =
'', $shownav = 1, $fieldid =
'rowid', $fieldref =
'ref', $morehtmlref =
'', $moreparam =
'', $nodbprefix = 0, $morehtmlleft =
'', $morehtmlstatus =
'', $morehtmlright =
'')
9817 global $conf, $langs, $hookmanager, $extralanguages;
9820 if (empty($fieldid)) {
9823 if (empty($fieldref)) {
9829 if (property_exists(
$object,
'gender') && !empty(
$object->gender)) {
9830 $addgendertxt =
' ';
9833 $addgendertxt .=
'<i class="fas fa-mars"></i>';
9836 $addgendertxt .=
'<i class="fas fa-venus"></i>';
9839 $addgendertxt .=
'<i class="fas fa-transgender"></i>';
9845 if (is_object($hookmanager)) {
9846 $parameters = array(
'showrefnav' =>
true);
9847 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters,
$object);
9848 $object->next_prev_filter .= $hookmanager->resPrint;
9851 $previous_ref = $next_ref =
'';
9854 $object->load_previous_next_ref((isset(
$object->next_prev_filter) ?
$object->next_prev_filter :
''), $fieldid, $nodbprefix);
9856 $navurl = $_SERVER[
"PHP_SELF"];
9858 if ($paramid ==
'project_ref') {
9859 if (preg_match(
'/\/tasks\/(task|contact|note|document)\.php/', $navurl)) {
9860 $navurl = preg_replace(
'/\/tasks\/(task|contact|time|note|document)\.php/',
'/tasks.php', $navurl);
9867 $stringforfirstkey = $langs->trans(
"KeyboardShortcut");
9868 if ($conf->browser->name ==
'chrome') {
9869 $stringforfirstkey .=
' ALT +';
9870 } elseif ($conf->browser->name ==
'firefox') {
9871 $stringforfirstkey .=
' ALT + SHIFT +';
9873 $stringforfirstkey .=
' CTL +';
9876 $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>';
9877 $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>';
9881 $ret .=
'<!-- Start banner content --><div style="vertical-align: middle">';
9884 if ($morehtmlright) {
9885 $ret .=
'<div class="inline-block floatleft">' . $morehtmlright .
'</div>';
9888 if ($previous_ref || $next_ref || $morehtml) {
9889 $ret .=
'<div class="pagination paginationref"><ul class="right">';
9891 if ($morehtml &&
getDolGlobalInt(
'MAIN_OPTIMIZEFORTEXTBROWSER') < 2) {
9892 $ret .=
'<!-- morehtml --><li class="noborder litext' . (($shownav && $previous_ref && $next_ref) ?
' clearbothonsmartphone' :
'') .
'">' . $morehtml .
'</li>';
9894 if ($shownav && ($previous_ref || $next_ref)) {
9895 $ret .=
'<li class="pagination">' . $previous_ref .
'</li>';
9896 $ret .=
'<li class="pagination">' . $next_ref .
'</li>';
9898 if ($previous_ref || $next_ref || $morehtml) {
9899 $ret .=
'</ul></div>';
9903 $parameters = array(
'morehtmlstatus' => $morehtmlstatus);
9904 $reshook = $hookmanager->executeHooks(
'moreHtmlStatus', $parameters,
$object);
9905 if (empty($reshook)) {
9906 $morehtmlstatus .= $hookmanager->resPrint;
9908 $morehtmlstatus = $hookmanager->resPrint;
9910 if ($morehtmlstatus) {
9911 $ret .=
'<div class="statusref">' . $morehtmlstatus .
'</div>';
9914 $parameters = array();
9915 $reshook = $hookmanager->executeHooks(
'moreHtmlRef', $parameters,
$object);
9916 if (empty($reshook)) {
9917 $morehtmlref .= $hookmanager->resPrint;
9918 } elseif ($reshook > 0) {
9919 $morehtmlref = $hookmanager->resPrint;
9923 if ($morehtmlleft) {
9924 if ($conf->browser->layout ==
'phone') {
9925 $ret .=
'<!-- morehtmlleft --><div class="floatleft">' . $morehtmlleft .
'</div>';
9927 $ret .=
'<!-- morehtmlleft --><div class="inline-block floatleft">' . $morehtmlleft .
'</div>';
9932 $ret .=
'<div class="inline-block floatleft valignmiddle maxwidth750 marginbottomonly refid' . (($shownav && ($previous_ref || $next_ref)) ?
' refidpadding' :
'') .
'">';
9935 if (
$object->element ==
'societe') {
9939 $arrayoflangcode = array();
9944 if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
9945 if (!is_object($extralanguages)) {
9946 include_once DOL_DOCUMENT_ROOT .
'/core/class/extralanguages.class.php';
9949 $extralanguages->fetch_name_extralanguages(
'societe');
9951 if (!empty($extralanguages->attributes[
'societe'][
'name'])) {
9952 $object->fetchValuesForExtraLanguages();
9956 foreach ($arrayoflangcode as $extralangcode) {
9958 if (
$object->array_languages[
'name'][$extralangcode]) {
9959 $htmltext .=
$object->array_languages[
'name'][$extralangcode];
9961 $htmltext .=
'<span class="opacitymedium">' . $langs->trans(
"SwitchInEditModeToAddTranslation") .
'</span>';
9964 $ret .=
'<!-- Show translations of name -->' .
"\n";
9965 $ret .= $this->
textwithpicto(
'', $htmltext, -1,
'language',
'opacitymedium paddingleft');
9968 } elseif (
$object->element ==
'member') {
9969 '@phan-var-force Adherent $object';
9970 $ret .=
$object->ref .
'<br>';
9971 $fullname =
$object->getFullName($langs);
9977 } elseif (in_array(
$object->element, array(
'contact',
'user'))) {
9979 } elseif (
$object->element ==
'usergroup') {
9981 } elseif (in_array(
$object->element, array(
'action',
'agenda'))) {
9982 '@phan-var-force ActionComm $object';
9984 } elseif (in_array(
$object->element, array(
'adherent_type'))) {
9986 } elseif (
$object->element ==
'ecm_directories') {
9988 } elseif ($fieldref !=
'none') {
9993 if (substr($morehtmlref, 0, 4) !=
'<div') {
9997 $ret .= $morehtmlref;
10002 $ret .=
'</div><!-- End banner content -->';
10021 if (empty(
$object->barcode)) {
10026 if (empty(
$object->barcode_type_code) || empty(
$object->barcode_type_coder)) {
10028 $result =
$object->fetch_barcode();
10031 return '<!-- ErrorFetchBarcode -->';
10036 $url = DOL_URL_ROOT .
'/viewimage.php?modulepart=barcode&generator=' . urlencode(
$object->barcode_type_coder) .
'&code=' . urlencode(
$object->barcode) .
'&encoding=' . urlencode(
$object->barcode_type_code);
10037 $out =
'<!-- url barcode = ' . $url .
' -->';
10038 $out .=
'<img src="' . $url .
'"' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
'>';
10060 public static function showphoto($modulepart,
$object, $width = 100, $height = 0, $caneditfield = 0, $cssclass =
'photowithmargin', $imagesize =
'', $addlinktofullsize = 1, $cache = 0, $forcecapture =
'', $noexternsourceoverwrite = 0)
10062 global $conf, $langs;
10064 $entity = (empty(
$object->entity) ? $conf->entity :
$object->entity);
10069 $originalfile =
'';
10073 if ($modulepart ==
'societe') {
10074 $dir = $conf->societe->multidir_output[$entity];
10077 if ((
string) $imagesize ==
'mini') {
10079 } elseif ((
string) $imagesize ==
'small') {
10088 } elseif ($modulepart ==
'contact') {
10089 $dir = $conf->societe->multidir_output[$entity] .
'/contact';
10090 if (!empty(
$object->photo)) {
10092 if ((
string) $imagesize ==
'mini') {
10094 } elseif ((
string) $imagesize ==
'small') {
10104 } elseif ($modulepart ==
'userphoto') {
10105 $dir = $conf->user->dir_output;
10106 if (!empty(
$object->photo)) {
10108 if ((
string) $imagesize ==
'mini') {
10110 } elseif ((
string) $imagesize ==
'small') {
10119 $altfile =
$object->id .
".jpg";
10123 } elseif ($modulepart ==
'memberphoto') {
10124 $dir = $conf->adherent->dir_output;
10125 if (!empty(
$object->photo)) {
10127 if ((
string) $imagesize ==
'mini') {
10129 } elseif ((
string) $imagesize ==
'small') {
10138 $altfile =
$object->id .
".jpg";
10145 if ($modulepart !=
"unknown" && method_exists(
$object,
'getDataToShowPhoto')) {
10146 $tmpdata =
$object->getDataToShowPhoto($modulepart, $imagesize);
10148 $dir = $tmpdata[
'dir'];
10149 $file = $tmpdata[
'file'];
10150 $originalfile = $tmpdata[
'originalfile'];
10151 $altfile = $tmpdata[
'altfile'];
10152 $email = $tmpdata[
'email'];
10153 $capture = $tmpdata[
'capture'];
10157 if ($forcecapture) {
10158 $capture = $forcecapture;
10164 if ($file && file_exists($dir .
"/" . $file)) {
10165 if ($addlinktofullsize) {
10167 if ($urladvanced) {
10168 $ret .=
'<a href="' . $urladvanced .
'">';
10170 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
10173 $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 .
'">';
10174 if ($addlinktofullsize) {
10177 } elseif ($altfile && file_exists($dir .
"/" . $altfile)) {
10178 if ($addlinktofullsize) {
10180 if ($urladvanced) {
10181 $ret .=
'<a href="' . $urladvanced .
'">';
10183 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
10186 $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 .
'">';
10187 if ($addlinktofullsize) {
10191 $nophoto =
'/public/theme/common/nophoto.png';
10192 $defaultimg =
'identicon';
10193 if (in_array($modulepart, array(
'societe',
'userphoto',
'contact',
'memberphoto'))) {
10194 if ($modulepart ==
'societe' || ($modulepart ==
'memberphoto' && !empty(
$object->morphy) && strpos(
$object->morphy,
'mor') !==
false)) {
10195 $nophoto =
'company';
10197 $nophoto =
'/public/theme/common/user_anonymous.png';
10199 $nophoto =
'/public/theme/common/user_man.png';
10202 $nophoto =
'/public/theme/common/user_woman.png';
10207 if (isModEnabled(
'gravatar') && $email && empty($noexternsourceoverwrite)) {
10209 $ret .=
'<!-- Put link to gravatar -->';
10210 $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 .
'">';
10212 if ($nophoto ==
'company') {
10213 $ret .=
'<div class="divforspanimg valignmiddle center photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
'>' .
img_picto(
'',
'company') .
'</div>';
10216 $ret .=
'<img class="photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="' . DOL_URL_ROOT . $nophoto .
'">';
10221 if ($caneditfield) {
10225 $ret .=
'<table class="nobordernopadding centpercent">';
10227 $ret .=
'<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> <label for="photodelete">' . $langs->trans(
"Delete") .
'</label><br><br></td></tr>';
10229 $ret .=
'<tr><td class="tdoverflow">';
10231 $maxmin = $maxfilesizearray[
'maxmin'];
10233 $ret .=
'<input type="hidden" name="MAX_FILE_SIZE" value="' . ($maxmin * 1024) .
'">';
10235 $ret .=
'<input type="file" class="flat maxwidth200onsmartphone" name="photo" id="photoinput" accept="image/*"' . ($capture ?
' capture="' . $capture .
'"' :
'') .
'>';
10236 $ret .=
'</td></tr>';
10237 $ret .=
'</table>';
10262 public function select_dolgroups($selected = 0, $htmlname =
'groupid', $show_empty = 0, $exclude =
'', $disabled = 0, $include =
'', $enableonly = array(), $force_entity =
'0', $multiple =
false, $morecss =
'minwidth200')
10265 global $conf, $user, $langs;
10268 $excludeGroups =
null;
10269 if (is_array($exclude)) {
10270 $excludeGroups = implode(
",", $exclude);
10273 $includeGroups =
null;
10274 if (is_array($include)) {
10275 $includeGroups = implode(
",", $include);
10278 if (!is_array($selected)) {
10279 $selected = array($selected);
10285 $sql =
"SELECT ug.rowid, ug.nom as name";
10286 if (isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
10287 $sql .=
", e.label";
10289 $sql .=
" FROM " . $this->db->prefix() .
"usergroup as ug ";
10290 if (isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
10291 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid=ug.entity";
10292 if ($force_entity) {
10293 $sql .=
" WHERE ug.entity IN (0, " . $force_entity .
")";
10295 $sql .=
" WHERE ug.entity IS NOT NULL";
10298 $sql .=
" WHERE ug.entity IN (0, " . $conf->entity .
")";
10300 if (is_array($exclude) && $excludeGroups) {
10301 $sql .=
" AND ug.rowid NOT IN (" . $this->db->sanitize($excludeGroups) .
")";
10303 if (is_array($include) && $includeGroups) {
10304 $sql .=
" AND ug.rowid IN (" . $this->db->sanitize($includeGroups) .
")";
10306 $sql .=
" ORDER BY ug.nom ASC";
10308 dol_syslog(get_class($this) .
"::select_dolgroups", LOG_DEBUG);
10309 $resql = $this->db->query($sql);
10312 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
10314 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
10316 $num = $this->db->num_rows($resql);
10319 if ($show_empty && !$multiple) {
10320 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'> </option>' .
"\n";
10323 while ($i < $num) {
10324 $obj = $this->db->fetch_object($resql);
10326 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
10330 $label = $obj->name;
10331 $labelhtml = $obj->name;
10332 if (isModEnabled(
'multicompany') && !
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE') && $conf->entity == 1) {
10333 $label .=
" (" . $obj->label .
")";
10334 $labelhtml .=
' <span class="opacitymedium">(' . $obj->label .
')</span>';
10337 $out .=
'<option value="' . $obj->rowid .
'"';
10338 if ($disableline) {
10339 $out .=
' disabled';
10341 if ((isset($selected[0]) && is_object($selected[0]) && $selected[0]->
id == $obj->rowid)
10342 || ((!isset($selected[0]) || !is_object($selected[0])) && !empty($selected) && in_array($obj->rowid, $selected))) {
10343 $out .=
' selected';
10345 $out .=
' data-html="'.dol_escape_htmltag($labelhtml).
'"';
10348 $out .=
'</option>';
10353 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'></option>' .
"\n";
10355 $out .=
'<option value="" disabled>' . $langs->trans(
"NoUserGroupDefined") .
'</option>';
10357 $out .=
'</select>';
10376 $out =
'<div class="nowraponall">';
10377 $out .=
'<button type="submit" class="liste_titre button_search reposition" name="button_search_x" value="x"><span class="fas fa-search"></span></button>';
10378 $out .=
'<button type="submit" class="liste_titre button_removefilter reposition" name="button_removefilter_x" value="x"><span class="fas fa-times"></span></button>';
10392 public function showCheckAddButtons($cssclass =
'checkforaction', $calljsfunction = 0, $massactionname =
"massaction")
10398 if (!empty($conf->use_javascript_ajax)) {
10399 $out .=
'<div class="inline-block checkallactions"><input type="checkbox" id="' . $cssclass .
's" name="' . $cssclass .
's" class="checkallactions"></div>';
10401 $out .=
'<script nonce="' .
getNonce() .
'">
10402 $(document).ready(function() {
10403 $("#' . $cssclass .
's").click(function() {
10404 if($(this).is(\':checked\')){
10405 console.log("We check all ' . $cssclass .
' and trigger the change method");
10406 $(".' . $cssclass .
'").prop(\'checked\', true).trigger(\'change\');
10410 console.log("We uncheck all");
10411 $(".' . $cssclass .
'").prop(\'checked\', false).trigger(\'change\');
10413 if ($calljsfunction) {
10414 $out .=
'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0, "' . $massactionname .
'", "' . $cssclass .
'"); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }';
10417 $(".' . $cssclass .
'").change(function() {
10418 $(this).closest("tr").toggleClass("highlight", this.checked);
10438 if ($addcheckuncheckall) {
10457 public function selectExpenseCategories($selected =
'', $htmlname =
'fk_c_exp_tax_cat', $useempty = 0, $excludeid = array(), $target =
'', $default_selected = 0, $params = array(), $info_admin = 1)
10459 global $langs, $user;
10462 $sql =
"SELECT rowid, label FROM " . $this->db->prefix() .
"c_exp_tax_cat WHERE active = 1";
10463 $sql .=
" AND entity IN (0," .
getEntity(
'exp_tax_cat') .
")";
10464 if (!empty($excludeid)) {
10465 $sql .=
" AND rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeid)) .
")";
10467 $sql .=
" ORDER BY label";
10469 $resql = $this->db->query($sql);
10471 $out =
'<select id="select_' . $htmlname .
'" name="' . $htmlname .
'" class="' . $htmlname .
' flat minwidth75imp maxwidth200">';
10473 $out .=
'<option value="0"> </option>';
10476 while ($obj = $this->db->fetch_object($resql)) {
10477 $out .=
'<option ' . ($selected == $obj->rowid ?
'selected="selected"' :
'') .
' value="' . $obj->rowid .
'">' . $langs->trans($obj->label) .
'</option>';
10479 $out .=
'</select>';
10482 if (!empty($htmlname) && $user->admin && $info_admin) {
10483 $out .=
' ' .
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
10486 if (!empty($target)) {
10487 $sql =
"SELECT c.id FROM " . $this->db->prefix() .
"c_type_fees as c WHERE c.code = 'EX_KME' AND c.active = 1";
10488 $resql = $this->db->query($sql);
10490 if ($this->db->num_rows($resql) > 0) {
10491 $obj = $this->db->fetch_object($resql);
10492 $out .=
'<script nonce="' .
getNonce() .
'">
10494 $("select[name=' . $target .
']").on("change", function() {
10495 var current_val = $(this).val();
10496 if (current_val == ' . $obj->id .
') {';
10497 if (!empty($default_selected) || !empty($selected)) {
10498 $out .=
'$("select[name=' . $htmlname .
']").val("' . ($default_selected > 0 ? $default_selected : $selected) .
'");';
10502 $("select[name=' . $htmlname .
']").change();
10506 $("select[name=' . $htmlname .
']").change(function() {
10508 if ($("select[name=' . $target .
']").val() == ' . $obj->id .
') {
10509 // get price of kilometer to fill the unit price
10513 data: { fk_c_exp_tax_cat: $(this).val(), token: \'' .
currentToken() .
'\' },
10514 url:
"' . (DOL_URL_ROOT . '/expensereport/ajax/ajaxik.php?' . implode('&', $params)) . '",
10515 }).done(
function( data, textStatus, jqXHR ) {
10517 if (typeof data.up !=
"undefined") {
10518 $(
"input[name=value_unit]").val(data.up);
10519 $(
"select[name=' . $htmlname . ']").attr(
"title", data.title);
10521 $(
"input[name=value_unit]").val(
"");
10522 $(
"select[name=' . $htmlname . ']").attr(
"title",
"");
10533 dol_print_error($this->db);
10547 public function selectExpenseRanges($selected = '
', $htmlname = 'fk_range
', $useempty = 0)
10549 global $conf, $langs;
10552 $sql = "SELECT rowid, range_ik FROM " . $this->db->prefix() . "c_exp_tax_range";
10553 $sql .= " WHERE entity = " . $conf->entity . " AND active = 1";
10555 $resql = $this->db->query($sql);
10557 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
10559 $out .= '<option value=
"0"></option>
';
10562 while ($obj = $this->db->fetch_object($resql)) {
10563 $out .= '<option
' . ($selected == $obj->rowid ? 'selected=
"selected"' : '') . ' value=
"' . $obj->rowid . '">
' . price($obj->range_ik, 0, $langs, 1, 0) . '</option>
';
10565 $out .= '</select>
';
10567 dol_print_error($this->db);
10583 public function selectExpense($selected = '
', $htmlname = 'fk_c_type_fees
', $useempty = 0, $allchoice = 1, $useid = 0)
10588 $sql = "SELECT id, code, label";
10589 $sql .= " FROM ".$this->db->prefix()."c_type_fees";
10590 $sql .= " WHERE active = 1";
10592 $resql = $this->db->query($sql);
10594 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
10596 $out .= '<option value=
"0"></option>
';
10599 $out .= '<option value=
"-1">
' . $langs->trans('AllExpenseReport
') . '</option>
';
10607 while ($obj = $this->db->fetch_object($resql)) {
10608 $key = $langs->trans($obj->code);
10609 $out .= '<option
' . ($selected == $obj->{$field} ? 'selected=
"selected"' : '') . ' value=
"' . $obj->{$field} . '">
' . ($key != $obj->code ? $key : $obj->label) . '</option>
';
10611 $out .= '</select>
';
10613 $out .= ajax_combobox('select_
'.$htmlname);
10615 dol_print_error($this->db);
10639 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)
10641 global $user, $conf, $langs;
10643 require_once DOL_DOCUMENT_ROOT . '/projet/
class/project.class.php
';
10645 if (is_null($usertofilter)) {
10646 $usertofilter = $user;
10651 $hideunselectables = false;
10652 if (getDolGlobalString('PROJECT_HIDE_UNSELECTABLES
')) {
10653 $hideunselectables = true;
10656 if (empty($projectsListId)) {
10657 if (!$usertofilter->hasRight('projet
', 'all
', 'lire
')) {
10658 $projectstatic = new Project($this->db);
10659 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1);
10663 // Search all projects
10664 $sql = "SELECT f.rowid, f.ref as fref, 'nolabel
' as flabel, p.rowid as pid, f.ref,
10665 p.title, p.fk_soc, p.fk_statut, p.public,";
10666 $sql .= ' s.nom as
name';
10667 $sql .= ' FROM
' . $this->db->prefix() . 'projet as p
';
10668 $sql .= ' LEFT JOIN
' . $this->db->prefix() . 'societe as s ON s.rowid = p.fk_soc,
';
10669 $sql .= ' ' . $this->db->prefix() . 'facture as f
';
10670 $sql .= " WHERE p.entity IN (" . getEntity('project
') . ")";
10671 $sql .= " AND f.fk_projet = p.rowid AND f.fk_statut=0"; //Brouillons seulement
10672 //if ($projectsListId) $sql.= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")";
10673 //if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
10674 //if ($socid > 0) $sql.= " AND (p.fk_soc=".((int) $socid)." OR p.fk_soc IS NULL)";
10675 $sql .= " ORDER BY p.ref, f.ref ASC";
10677 $resql = $this->db->query($sql);
10679 // Use select2 selector
10680 if (!empty($conf->use_javascript_ajax)) {
10681 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
10682 $comboenhancement = ajax_combobox($htmlname, array(), 0, $forcefocus);
10683 $out .= $comboenhancement;
10684 $morecss = 'minwidth200imp maxwidth500
';
10687 if (empty($option_only)) {
10688 $out .= '<select
class=
"valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled=
"disabled"' : '') . ' id=
"' . $htmlname . '" name=
"' . $htmlname . '">
';
10690 if (!empty($show_empty)) {
10691 $out .= '<option value=
"0" class=
"optiongrey">
';
10692 if (!is_numeric($show_empty)) {
10693 $out .= $show_empty;
10697 $out .= '</option>
';
10699 $num = $this->db->num_rows($resql);
10702 while ($i < $num) {
10703 $obj = $this->db->fetch_object($resql);
10704 // 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.
10705 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$usertofilter->hasRight('societe
', 'lire
')) {
10708 if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) {
10715 if ($showproject == 'all
') {
10716 $labeltoshow .= dol_trunc($obj->ref, 18); // Invoice ref
10718 $labeltoshow .= ' -
' . $obj->name; // Soc name
10722 if ($obj->fk_statut == Project::STATUS_DRAFT) {
10724 $labeltoshow .= ' -
' . $langs->trans("Draft");
10725 } elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
10726 if ($discard_closed == 2) {
10729 $labeltoshow .= ' -
' . $langs->trans("Closed");
10730 } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
10732 $labeltoshow .= ' -
' . $langs->trans("LinkedToAnotherCompany");
10736 if (!empty($selected) && $selected == $obj->rowid) {
10737 $out .= '<option value=
"' . $obj->rowid . '" selected
';
10738 //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected
if disabled
10739 $out .=
'>' . $labeltoshow .
'</option>';
10741 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
10744 $resultat =
'<option value="' . $obj->rowid .
'"';
10746 $resultat .=
' disabled';
10751 $resultat .= $labeltoshow;
10752 $resultat .=
'</option>';
10760 if (empty($option_only)) {
10761 $out .=
'</select>';
10764 $this->db->free($resql);
10786 public function selectInvoiceRec($selected =
'', $htmlname =
'facrecid', $maxlength = 24, $option_only = 0, $show_empty =
'1', $forcefocus = 0, $disabled = 0, $morecss =
'maxwidth500')
10788 global $conf, $langs;
10794 $sql =
'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc';
10796 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'facture_rec as f';
10797 $sql .=
" WHERE f.entity IN (" .
getEntity(
'invoice') .
")";
10798 $sql .=
" ORDER BY f.titre ASC";
10800 $resql = $this->db->query($sql);
10803 if (!empty($conf->use_javascript_ajax)) {
10804 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
10805 $comboenhancement =
ajax_combobox($htmlname, array(), 0, $forcefocus);
10806 $out .= $comboenhancement;
10807 $morecss =
'minwidth200imp maxwidth500';
10810 if (empty($option_only)) {
10811 $out .=
'<select class="valignmiddle flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' id="' . $htmlname .
'" name="' . $htmlname .
'">';
10813 if (!empty($show_empty)) {
10814 $out .=
'<option value="0" class="optiongrey">';
10815 if (!is_numeric($show_empty)) {
10816 $out .= $show_empty;
10820 $out .=
'</option>';
10822 $num = $this->db->num_rows($resql);
10824 while ($obj = $this->db->fetch_object($resql)) {
10825 $labeltoshow =
dol_trunc($obj->title, 18);
10828 if (!empty($obj->suspended)) {
10830 $labeltoshow .=
' - ' . $langs->trans(
"Closed");
10834 if (!empty($selected) && $selected == $obj->rowid) {
10835 $out .=
'<option value="' . $obj->rowid .
'" selected';
10837 $out .=
'>' . $labeltoshow .
'</option>';
10839 if ($disabled && ($selected != $obj->rowid)) {
10842 $resultat =
'<option value="' . $obj->rowid .
'"';
10844 $resultat .=
' disabled';
10847 $resultat .= $labeltoshow;
10848 $resultat .=
'</option>';
10854 if (empty($option_only)) {
10855 $out .=
'</select>';
10860 $this->db->free($resql);
10863 $this->errors[] = $this->db->lasterror;
10877 public function searchComponent($arrayofcriterias, $search_component_params, $arrayofinputfieldsalreadyoutput = array(), $search_component_params_hidden =
'')
10881 if ($search_component_params_hidden !=
'' && !preg_match(
'/^\(.*\)$/', $search_component_params_hidden)) {
10882 $search_component_params_hidden =
'(' . $search_component_params_hidden .
')';
10887 $ret .=
'<div class="divadvancedsearchfieldcomp centpercent inline-block">';
10888 $ret .=
'<a href="#" class="dropdownsearch-toggle unsetcolor">';
10889 $ret .=
'<span class="fas fa-filter linkobject boxfilter paddingright pictofixedwidth" title="' .
dol_escape_htmltag($langs->trans(
"Filters")) .
'" id="idsubimgproductdistribution"></span>';
10892 $ret .=
'<div class="divadvancedsearchfieldcompinput inline-block minwidth500 maxwidth300onsmartphone">';
10895 $ret .=
'<div id="divsearch_component_params" name="divsearch_component_params" class="noborderbottom search_component_params inline-block valignmiddle">';
10897 if ($search_component_params_hidden) {
10905 foreach ($arrayofandtags as $tmpkey => $tmpval) {
10906 $errormessage =
'';
10908 if ($errormessage) {
10909 $this->error =
'ERROR in parsing search string: '.$errormessage;
10912 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
10915 $ret .=
'<span class="marginleftonlyshort valignmiddle tagsearch" data-ufilterid="'.($tmpkey + 1).
'" data-ufilter="'.
dol_escape_htmltag($tmpval).
'">';
10916 $ret .=
'<span class="tagsearchdelete select2-selection__choice__remove" data-ufilterid="'.($tmpkey + 1).
'">x</span> ';
10928 $show_search_component_params_hidden = 1;
10929 if ($show_search_component_params_hidden) {
10930 $ret .=
'<input type="hidden" name="show_search_component_params_hidden" value="1">';
10932 $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%')) -->";
10933 $ret .=
'<input type="hidden" id="search_component_params_hidden" name="search_component_params_hidden" value="' .
dol_escape_htmltag($search_component_params_hidden) .
'">';
10937 foreach ($arrayofcriterias as $criteria) {
10938 foreach ($criteria as $criteriafamilykey => $criteriafamilyval) {
10939 if (in_array(
'search_' . $criteriafamilykey, $arrayofinputfieldsalreadyoutput)) {
10942 if (in_array($criteriafamilykey, array(
'rowid',
'ref_ext',
'entity',
'extraparams'))) {
10945 if (in_array($criteriafamilyval[
'type'], array(
'date',
'datetime',
'timestamp'))) {
10946 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_start">';
10947 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startyear">';
10948 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startmonth">';
10949 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startday">';
10950 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_end">';
10951 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endyear">';
10952 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endmonth">';
10953 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endday">';
10955 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'">';
10962 $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";
10963 $ret .=
'<input type="text" placeholder="' . $langs->trans(
"Filters") .
'" id="search_component_params_input" name="search_component_params_input" class="noborderbottom search_component_input" value="">';
10969 jQuery(".tagsearchdelete").click(function(e) {
10970 var filterid = $(this).parents().attr("data-ufilterid");
10971 console.log("We click to delete the criteria nb "+filterid);
10973 // Regenerate the search_component_params_hidden with all data-ufilter except the one to delete, and post the page
10974 var newparamstring = \'\';
10975 $(\'.tagsearch\').each(function(index, element) {
10976 tmpfilterid = $(this).attr("data-ufilterid");
10977 if (tmpfilterid != filterid) {
10978 // We keep this criteria
10979 if (newparamstring == \'\') {
10980 newparamstring = $(this).attr("data-ufilter");
10982 newparamstring = newparamstring + \' AND \' + $(this).attr("data-ufilter");
10986 console.log("newparamstring = "+newparamstring);
10988 jQuery("#search_component_params_hidden").val(newparamstring);
10990 // We repost the form
10991 $(this).closest(\'form\').submit();
10994 jQuery("#search_component_params_input").keydown(function(e) {
10995 console.log("We press a key on the filter field that is "+jQuery("#search_component_params_input").val());
10996 console.log(e.which);
10997 if (jQuery("#search_component_params_input").val() == "" && e.which == 8) {
10998 /* We click on back when the input field is already empty */
10999 event.preventDefault();
11000 jQuery("#divsearch_component_params .tagsearch").last().remove();
11001 /* Regenerate content of search_component_params_hidden from remaining .tagsearch */
11003 jQuery("#divsearch_component_params .tagsearch").each(function( index ) {
11007 s = s + $(this).attr("data-ufilter");
11009 console.log("New value for search_component_params_hidden = "+s);
11010 jQuery("#search_component_params_hidden").val(s);
11031 global $langs, $user;
11035 $TModels = array();
11037 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
11038 $formmail =
new FormMail($this->db);
11039 $result = $formmail->fetchAllEMailTemplate($modelType, $user, $langs);
11042 $TModels[0] = $langs->trans(
'DefaultMailModel');
11045 foreach ($formmail->lines_model as $model) {
11046 $TModels[$model->id] = $model->label;
11050 $retstring .=
'<select class="flat" id="select_' . $prefix .
'model_mail" name="' . $prefix .
'model_mail">';
11052 foreach ($TModels as $id_model => $label_model) {
11053 $retstring .=
'<option value="' . $id_model .
'"';
11054 $retstring .=
">" . $label_model .
"</option>";
11057 $retstring .=
"</select>";
11060 $retstring .=
ajax_combobox(
'select_' . $prefix .
'model_mail');
11077 public function buttonsSaveCancel($save_label =
'Save', $cancel_label =
'Cancel', $morebuttons = array(), $withoutdiv =
false, $morecss =
'', $dol_openinpopup =
'')
11081 $buttons = array();
11085 'label_key' => $save_label,
11088 if ($save_label ==
'Create' || $save_label ==
'Add') {
11089 $save[
'name'] =
'add';
11090 } elseif ($save_label ==
'Modify') {
11091 $save[
'name'] =
'edit';
11095 'name' =>
'cancel',
11096 'label_key' =>
'Cancel',
11099 !empty($save_label) ? $buttons[] = $save :
'';
11101 if (!empty($morebuttons)) {
11102 $buttons[] = $morebuttons;
11105 !empty($cancel_label) ? $buttons[] = $cancel :
'';
11107 $retstring = $withoutdiv ?
'' :
'<div class="center">';
11109 foreach ($buttons as $button) {
11110 $addclass = empty($button[
'addclass']) ?
'' : $button[
'addclass'];
11111 $retstring .=
'<input type="submit" class="button button-' . $button[
'name'] . ($morecss ?
' ' . $morecss :
'') .
' ' . $addclass .
'" name="' . $button[
'name'] .
'" value="' .
dol_escape_htmltag($langs->trans($button[
'label_key'])) .
'">';
11113 $retstring .= $withoutdiv ?
'' :
'</div>';
11115 if ($dol_openinpopup) {
11116 $retstring .=
'<!-- buttons are shown into a $dol_openinpopup=' .
dol_escape_htmltag($dol_openinpopup) .
' context, so we enable the close of dialog on cancel -->' .
"\n";
11117 $retstring .=
'<script nonce="' .
getNonce() .
'">';
11118 $retstring .=
'jQuery(".button-cancel").click(function(e) {
11119 e.preventDefault(); console.log(\'We click on cancel in iframe popup ' .
dol_escape_js($dol_openinpopup) .
'\');
11120 window.parent.jQuery(\
'#idfordialog' .
dol_escape_js($dol_openinpopup) .
'\').dialog(\
'close\');
11122 $retstring .=
'</script>';
11141 $num = count($this->cache_invoice_subtype);
11148 $sql =
"SELECT rowid, code, label as label";
11149 $sql .=
" FROM " . MAIN_DB_PREFIX .
'c_invoice_subtype';
11150 $sql .=
" WHERE active = 1";
11152 $resql = $this->db->query($sql);
11154 $num = $this->db->num_rows($resql);
11156 while ($i < $num) {
11157 $obj = $this->db->fetch_object($resql);
11160 $label = ($langs->trans(
"InvoiceSubtype" . $obj->rowid) !=
"InvoiceSubtype" . $obj->rowid) ? $langs->trans(
"InvoiceSubtype" . $obj->rowid) : (($obj->label !=
'-') ? $obj->label :
'');
11161 $this->cache_invoice_subtype[$obj->rowid][
'rowid'] = $obj->rowid;
11162 $this->cache_invoice_subtype[$obj->rowid][
'code'] = $obj->code;
11163 $this->cache_invoice_subtype[$obj->rowid][
'label'] = $label;
11167 $this->cache_invoice_subtype =
dol_sort_array($this->cache_invoice_subtype,
'code',
'asc', 0, 0, 1);
11189 global $langs, $user;
11192 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
11194 $this->load_cache_invoice_subtype();
11196 $out .=
'<select id="' . $htmlname .
'" class="flat selectsubtype' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
11198 $out .=
'<option value="0"> </option>';
11201 foreach ($this->cache_invoice_subtype as $rowid => $subtype) {
11202 $label = $subtype[
'label'];
11203 $out .=
'<option value="' . $subtype[
'rowid'] .
'"';
11204 if ($selected == $subtype[
'rowid']) {
11205 $out .=
' selected="selected"';
11209 $out .=
'</option>';
11212 $out .=
'</select>';
11213 if ($user->admin && empty($noinfoadmin)) {
11214 $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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
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