71 public $errors = array();
82 public $cache_types_paiements = array();
84 public $cache_conditions_paiements = array();
86 public $cache_transport_mode = array();
88 public $cache_availability = array();
90 public $cache_demand_reason = array();
92 public $cache_types_fees = array();
94 public $cache_vatrates = array();
96 public $cache_invoice_subtype = array();
98 public $cache_rule_for_lines_dates = array();
123 'y' => $langs->trans(
'Years'),
124 'm' => $langs->trans(
'Month'),
125 'w' => $langs->trans(
'Weeks'),
126 'd' => $langs->trans(
'Days'),
127 'h' => $langs->trans(
'Hours'),
128 'i' => $langs->trans(
'Minutes'),
129 's' => $langs->trans(
'Seconds'),
133 "y" => $langs->trans(
"Year"),
134 "m" => $langs->trans(
"Month"),
135 "w" => $langs->trans(
"Week"),
136 "d" => $langs->trans(
"Day"),
137 "h" => $langs->trans(
"Hour"),
138 "i" => $langs->trans(
"Minute"),
139 's' => $langs->trans(
'Second'),
143 return array_reverse($arrayoftypes);
145 return $arrayoftypes;
165 public function editfieldkey($text, $htmlname, $preselected,
$object, $perm, $typeofdata =
'string', $moreparam =
'', $fieldrequired = 0, $notabletag = 0, $paramid =
'id', $help =
'')
172 if (
getDolGlobalString(
'MAIN_USE_JQUERY_JEDITABLE') && !preg_match(
'/^select;/', $typeofdata)) {
174 $tmp = explode(
':', $typeofdata);
175 $ret .=
'<div class="editkey_' . $tmp[0] . (!empty($tmp[1]) ?
' ' . $tmp[1] :
'') .
'" id="' . $htmlname .
'">';
176 if ($fieldrequired) {
177 $ret .=
'<span class="fieldrequired">';
182 $ret .= $langs->trans($text);
184 if ($fieldrequired) {
187 $ret .=
'</div>' .
"\n";
189 if ($fieldrequired) {
190 $ret .=
'<span class="fieldrequired">';
195 $ret .= $langs->trans($text);
197 if ($fieldrequired) {
202 if (empty($notabletag) && $perm) {
203 $ret .=
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
205 if ($fieldrequired) {
206 $ret .=
'<span class="fieldrequired">';
211 $ret .= $langs->trans($text);
213 if ($fieldrequired) {
216 if (!empty($notabletag)) {
219 if (empty($notabletag) && $perm) {
222 if (empty($notabletag) && $perm) {
223 $ret .=
'<td class="right">';
225 if ($htmlname &&
GETPOST(
'action',
'aZ09') !=
'edit' . $htmlname && $perm && is_object(
$object)) {
226 $ret .=
'<a class="editfielda reposition" href="' .
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'action' =>
'edit' . $htmlname, $paramid =>
$object->id],
true) . $moreparam .
'">';
227 $ret .=
img_edit($langs->trans(
'Edit'), ($notabletag ? 0 : 1));
230 if (!empty($notabletag) && $notabletag == 1) {
237 if (!empty($notabletag) && $notabletag == 3) {
240 if (empty($notabletag) && $perm) {
243 if (empty($notabletag) && $perm) {
244 $ret .=
'</tr></table>';
274 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 =
'')
276 global $conf, $langs;
281 if (empty($typeofdata)) {
282 return 'ErrorBadParameter typeofdata is empty';
285 if ($typeofdata ==
'datetime') {
286 $typeofdata =
'dayhour';
289 if (preg_match(
'/^(\w+)\((\d+)\)$/', $typeofdata, $reg)) {
290 if ($reg[1] ==
'varchar') {
291 $typeofdata =
'string';
292 } elseif ($reg[1] ==
'int') {
293 $typeofdata =
'numeric';
295 return 'ErrorBadParameter ' . $typeofdata;
300 if (
getDolGlobalString(
'MAIN_USE_JQUERY_JEDITABLE') && !preg_match(
'/^select;|day|datepicker|dayhour|datehourpicker/', $typeofdata)) {
301 $ret .= $this->
editInPlace(
$object, $value, $htmlname, ($perm ? 1 : 0), $typeofdata, $editvalue, $extObject, $custommsg);
303 if ($editaction ==
'') {
304 $editaction =
GETPOST(
'action',
'aZ09');
306 $editmode = ($editaction ==
'edit' . $htmlname);
308 $ret .=
"<!-- formeditfieldval -->\n";
309 $ret .=
'<form method="post" action="' . $_SERVER[
"PHP_SELF"] . ($moreparam ?
'?' . $moreparam :
'') .
'">';
310 $ret .=
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
311 $ret .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
312 $ret .=
'<input type="hidden" name="' . $paramid .
'" value="' .
$object->id .
'">';
313 if (empty($notabletag)) {
314 $ret .=
'<table class="nobordernopadding centpercent">';
316 if (empty($notabletag)) {
319 if (preg_match(
'/^(string|safehtmlstring|email|phone|url)/', $typeofdata)) {
320 $tmp = explode(
':', $typeofdata);
321 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($editvalue ? $editvalue : $value) .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus spellcheck="false">';
322 } elseif (preg_match(
'/^(integer)/', $typeofdata)) {
323 $tmp = explode(
':', $typeofdata);
324 $valuetoshow =
price2num($editvalue ? $editvalue : $value, 0);
325 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $valuetoshow .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
326 } elseif (preg_match(
'/^(numeric|amount)/', $typeofdata)) {
327 $tmp = explode(
':', $typeofdata);
328 $valuetoshow =
price2num($editvalue ? $editvalue : $value);
329 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($valuetoshow !=
'' ?
price($valuetoshow) :
'') .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
330 } elseif (preg_match(
'/^(checkbox)/', $typeofdata)) {
331 $tmp = explode(
':', $typeofdata);
332 $ret .=
'<input type="checkbox" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($value ? $value :
'on') .
'"' . ($value ?
' checked' :
'') . (empty($tmp[1]) ?
'' : $tmp[1]) .
'/>';
333 } elseif (preg_match(
'/^text/', $typeofdata) || preg_match(
'/^note/', $typeofdata)) {
334 $tmp = explode(
':', $typeofdata);
335 $cols = (empty($tmp[2]) ?
'' : $tmp[2]);
337 if (preg_match(
'/%/', $cols)) {
338 $morealt =
' style="width: ' . $cols .
'"';
341 $valuetoshow = ($editvalue ? $editvalue : $value);
342 $ret .=
'<textarea id="' . $htmlname .
'" name="' . $htmlname .
'" wrap="soft" rows="' . (empty($tmp[1]) ?
'20' : $tmp[1]) .
'"' . ($cols ?
' cols="' . $cols .
'"' :
'class="quatrevingtpercent"') . $morealt .
'" autofocus>';
345 $valuetoshow = str_replace(
'&',
'&', $valuetoshow);
347 $ret .=
'</textarea><div class="clearboth"></div>';
348 } elseif ($typeofdata ==
'day' || $typeofdata ==
'datepicker') {
349 $addnowlink = empty($moreoptions[
'addnowlink']) ? 0 : $moreoptions[
'addnowlink'];
350 $adddateof = empty($moreoptions[
'adddateof']) ?
'' : $moreoptions[
'adddateof'];
351 $labeladddateof = empty($moreoptions[
'labeladddateof']) ?
'' : $moreoptions[
'labeladddateof'];
352 $ret .= $this->
selectDate($value, $htmlname, 0, 0, 1,
'form' . $htmlname, 1, $addnowlink, 0,
'',
'', $adddateof,
'', 1, $labeladddateof,
'', $gm);
353 } elseif ($typeofdata ==
'dayhour' || $typeofdata ==
'datehourpicker') {
354 $addnowlink = empty($moreoptions[
'addnowlink']) ? 0 : $moreoptions[
'addnowlink'];
355 $adddateof = empty($moreoptions[
'adddateof']) ?
'' : $moreoptions[
'adddateof'];
356 $labeladddateof = empty($moreoptions[
'labeladddateof']) ?
'' : $moreoptions[
'labeladddateof'];
357 $ret .= $this->
selectDate($value, $htmlname, 1, 1, 1,
'form' . $htmlname, 1, $addnowlink, 0,
'',
'', $adddateof,
'', 1, $labeladddateof,
'', $gm);
358 } elseif (preg_match(
'/^select;/', $typeofdata)) {
359 $arraydata = explode(
',', preg_replace(
'/^select;/',
'', $typeofdata));
360 $arraylist = array();
361 foreach ($arraydata as $val) {
362 $tmp = explode(
':', $val);
363 $tmpkey = str_replace(
'|',
':', $tmp[0]);
364 $arraylist[$tmpkey] = $tmp[1];
366 $ret .= $this->
selectarray($htmlname, $arraylist, $value);
367 } elseif (preg_match(
'/^link/', $typeofdata)) {
369 } elseif (preg_match(
'/^ckeditor/', $typeofdata)) {
370 $tmp = explode(
':', $typeofdata);
371 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
372 $doleditor =
new DolEditor($htmlname, ($editvalue ? $editvalue : $value), (empty($tmp[2]) ?
'' : $tmp[2]), (empty($tmp[3]) ? 100 : (int) $tmp[3]), (empty($tmp[1]) ?
'dolibarr_notes' : $tmp[1]),
'In', (empty($tmp[5]) ? false : (bool) $tmp[5]), (isset($tmp[8]) ? ($tmp[8] ? true :
false) :
true),
true, (empty($tmp[6]) ? 20 : (int) $tmp[6]), (empty($tmp[7]) ?
'100' : $tmp[7]));
373 $ret .= $doleditor->Create(1);
374 } elseif ($typeofdata ==
'asis') {
375 $ret .= ($editvalue ? $editvalue : $value);
377 if (empty($notabletag)) {
382 if (empty($notabletag)) {
386 $ret .=
'<input type="submit" class="smallpaddingimp nomargingtop nomarginbottom button' . (empty($notabletag) ?
'' :
' ') .
'" name="modify" value="' . $langs->trans(
"Save") .
'">';
387 if (preg_match(
'/ckeditor|textarea/', $typeofdata) && empty($notabletag)) {
388 $ret .=
'<br>' .
"\n";
390 $ret .=
'<input type="submit" class="smallpaddingimp nomargingtop nomarginbottom button button-cancel' . (empty($notabletag) ?
'' :
' ') .
'" name="cancel" value="' . $langs->trans(
"Cancel") .
'">';
391 if (empty($notabletag)) {
395 if (empty($notabletag)) {
396 $ret .=
'</tr></table>' .
"\n";
398 $ret .=
'</form>' .
"\n";
400 if (preg_match(
'/^email/', $typeofdata)) {
402 } elseif (preg_match(
'/^phone/', $typeofdata)) {
404 } elseif (preg_match(
'/^url/', $typeofdata)) {
406 } elseif (preg_match(
'/^(amount|numeric)/', $typeofdata)) {
407 $ret .= ($value !=
'' ?
price($value, 0, $langs, 0, -1, -1, $conf->currency) :
'');
408 } elseif (preg_match(
'/^checkbox/', $typeofdata)) {
409 $tmp = explode(
':', $typeofdata);
410 $ret .=
'<input type="checkbox" disabled id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $value .
'"' . ($value ?
' checked' :
'') . ($tmp[1] ? $tmp[1] :
'') .
'/>';
411 } elseif (preg_match(
'/^text/', $typeofdata) || preg_match(
'/^note/', $typeofdata)) {
413 } elseif (preg_match(
'/^(safehtmlstring|restricthtml)/', $typeofdata)) {
415 } elseif ($typeofdata ==
'day' || $typeofdata ==
'datepicker') {
416 $ret .=
'<span class="valuedate">' .
dol_print_date($value,
'day', $gm) .
'</span>';
417 } elseif ($typeofdata ==
'dayhour' || $typeofdata ==
'datehourpicker') {
418 $ret .=
'<span class="valuedate">' .
dol_print_date($value,
'dayhour', $gm) .
'</span>';
419 } elseif (preg_match(
'/^select;/', $typeofdata)) {
420 $arraydata = explode(
',', preg_replace(
'/^select;/',
'', $typeofdata));
421 $arraylist = array();
422 foreach ($arraydata as $val) {
423 $tmp = explode(
':', $val);
424 $arraylist[$tmp[0]] = $tmp[1];
426 $ret .= $arraylist[$value];
427 if ($htmlname ==
'fk_product_type') {
429 $ret =
img_picto($langs->trans(
"Product"),
'product',
'class="paddingleftonly paddingrightonly colorgrey"') . $ret;
431 $ret =
img_picto($langs->trans(
"Service"),
'service',
'class="paddingleftonly paddingrightonly colorgrey"') . $ret;
434 } elseif (preg_match(
'/^ckeditor/', $typeofdata)) {
437 $firstline = preg_replace(
'/<br>.*/',
'', $tmpcontent);
438 $firstline = preg_replace(
'/[\n\r].*/',
'', $firstline);
439 $tmpcontent = $firstline . ((strlen($firstline) != strlen($tmpcontent)) ?
'...' :
'');
445 if (empty($moreoptions[
'valuealreadyhtmlescaped'])) {
453 if ($formatfunc && method_exists(
$object, $formatfunc)) {
454 $ret =
$object->$formatfunc($ret);
474 global $conf, $langs, $extralanguages;
479 $arrayoflangcode = array();
484 if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
485 if (!is_object($extralanguages)) {
486 include_once DOL_DOCUMENT_ROOT .
'/core/class/extralanguages.class.php';
489 $extralanguages->fetch_name_extralanguages(
'societe');
494 if (empty($extralanguages->attributes[
$object->element]) || !is_array($extralanguages->attributes[
$object->element]) || empty($extralanguages->attributes[
$object->element][$fieldname])) {
498 $result .=
'<!-- Widget for translation -->' .
"\n";
499 $result .=
'<div class="inline-block paddingleft image-' .
$object->element .
'-' . $fieldname .
'">';
500 $s =
img_picto($langs->trans(
"ShowOtherLanguages"),
'language',
'', 0, 0, 0,
'',
'fa-15 editfieldlang');
504 $result .=
'<div class="inline-block hidden field-' .
$object->element .
'-' . $fieldname .
'">';
506 $resultforextrlang =
'';
507 foreach ($arrayoflangcode as $langcode) {
508 $valuetoshow = GETPOSTISSET(
'field-' .
$object->element .
"-" . $fieldname .
"-" . $langcode) ?
GETPOST(
'field-' .
$object->element .
'-' . $fieldname .
"-" . $langcode, $check) :
'';
509 if (empty($valuetoshow)) {
510 $object->fetchValuesForExtraLanguages();
512 $valuetoshow =
$object->array_languages[$fieldname][$langcode];
516 $resultforextrlang .= $s;
519 if ($typeofdata ==
'textarea') {
520 $resultforextrlang .=
'<textarea name="field-' .
$object->element .
"-" . $fieldname .
"-" . $langcode .
'" id="' . $fieldname .
"-" . $langcode .
'" class="' . $morecss .
'" rows="' . ROWS_2 .
'" wrap="soft">';
521 $resultforextrlang .= $valuetoshow;
522 $resultforextrlang .=
'</textarea>';
524 $resultforextrlang .=
'<input type="text" class="inputfieldforlang ' . ($morecss ?
' ' . $morecss :
'') .
'" name="field-' .
$object->element .
'-' . $fieldname .
'-' . $langcode .
'" value="' . $valuetoshow .
'">';
527 $result .= $resultforextrlang;
530 $result .=
'<script nonce="' .
getNonce() .
'">$(".image-' .
$object->element .
'-' . $fieldname .
'").click(function() { console.log("Toggle lang widget"); jQuery(".field-' .
$object->element .
'-' . $fieldname .
'").toggle(); });</script>';
549 protected function editInPlace(
$object, $value, $htmlname, $condition, $inputType =
'textarea', $editvalue =
null, $extObject =
null, $custommsg =
null)
554 if (preg_match(
'/^text/', $inputType)) {
556 } elseif (preg_match(
'/^numeric/', $inputType)) {
557 $value =
price($value);
558 } elseif ($inputType ==
'day' || $inputType ==
'datepicker') {
564 $table_element =
false;
568 $ext_element =
false;
569 $button_only =
false;
576 $table_element =
$object->table_element;
580 if (is_object($extObject)) {
581 $ext_element = $extObject->element;
584 if (preg_match(
'/^(string|email|numeric)/', $inputType)) {
585 $tmp = explode(
':', $inputType);
586 $inputType = $tmp[0];
587 if (!empty($tmp[1])) {
588 $inputOption = $tmp[1];
590 if (!empty($tmp[2])) {
591 $savemethod = $tmp[2];
593 $out .=
'<input id="width_' . $htmlname .
'" value="' . $inputOption .
'" type="hidden"/>' .
"\n";
594 } elseif ((preg_match(
'/^day$/', $inputType)) || (preg_match(
'/^datepicker/', $inputType)) || (preg_match(
'/^datehourpicker/', $inputType))) {
595 $tmp = explode(
':', $inputType);
596 $inputType = $tmp[0];
597 if (!empty($tmp[1])) {
598 $inputOption = $tmp[1];
600 if (!empty($tmp[2])) {
601 $savemethod = $tmp[2];
604 $out .=
'<input id="timestamp" type="hidden"/>' .
"\n";
605 } elseif (preg_match(
'/^(select|autocomplete)/', $inputType)) {
606 $tmp = explode(
':', $inputType);
607 $inputType = $tmp[0];
608 $loadmethod = $tmp[1];
609 if (!empty($tmp[2])) {
610 $savemethod = $tmp[2];
612 if (!empty($tmp[3])) {
615 } elseif (preg_match(
'/^textarea/', $inputType)) {
616 $tmp = explode(
':', $inputType);
617 $inputType = $tmp[0];
618 $rows = (empty($tmp[1]) ?
'8' : $tmp[1]);
619 $cols = (empty($tmp[2]) ?
'80' : $tmp[2]);
620 } elseif (preg_match(
'/^ckeditor/', $inputType)) {
621 $tmp = explode(
':', $inputType);
622 $inputType = $tmp[0];
624 if (!empty($tmp[2])) {
627 if (!empty($tmp[3])) {
630 if (!empty($tmp[4])) {
631 $savemethod = $tmp[4];
635 $out .=
'<input id="ckeditor_toolbar" value="' . $toolbar .
'" type="hidden"/>' .
"\n";
637 $inputType =
'textarea';
641 $out .=
'<input id="element_' . $htmlname .
'" value="' . $element .
'" type="hidden"/>' .
"\n";
642 $out .=
'<input id="table_element_' . $htmlname .
'" value="' . $table_element .
'" type="hidden"/>' .
"\n";
643 $out .=
'<input id="fk_element_' . $htmlname .
'" value="' . $fk_element .
'" type="hidden"/>' .
"\n";
644 $out .=
'<input id="loadmethod_' . $htmlname .
'" value="' . $loadmethod .
'" type="hidden"/>' .
"\n";
645 if (!empty($savemethod)) {
646 $out .=
'<input id="savemethod_' . $htmlname .
'" value="' . $savemethod .
'" type="hidden"/>' .
"\n";
648 if (!empty($ext_element)) {
649 $out .=
'<input id="ext_element_' . $htmlname .
'" value="' . $ext_element .
'" type="hidden"/>' .
"\n";
651 if (!empty($custommsg)) {
652 if (is_array($custommsg)) {
653 if (!empty($custommsg[
'success'])) {
654 $out .=
'<input id="successmsg_' . $htmlname .
'" value="' . $custommsg[
'success'] .
'" type="hidden"/>' .
"\n";
656 if (!empty($custommsg[
'error'])) {
657 $out .=
'<input id="errormsg_' . $htmlname .
'" value="' . $custommsg[
'error'] .
'" type="hidden"/>' .
"\n";
660 $out .=
'<input id="successmsg_' . $htmlname .
'" value="' . $custommsg .
'" type="hidden"/>' .
"\n";
663 if ($inputType ==
'textarea') {
664 $out .=
'<input id="textarea_' . $htmlname .
'_rows" value="' . $rows .
'" type="hidden"/>' .
"\n";
665 $out .=
'<input id="textarea_' . $htmlname .
'_cols" value="' . $cols .
'" type="hidden"/>' .
"\n";
667 $out .=
'<span id="viewval_' . $htmlname .
'" class="viewval_' . $inputType . ($button_only ?
' inactive' :
' active') .
'">' . $value .
'</span>' .
"\n";
668 $out .=
'<span id="editval_' . $htmlname .
'" class="editval_' . $inputType . ($button_only ?
' inactive' :
' active') .
' hideobject">' . (!empty($editvalue) ? $editvalue : $value) .
'</span>' .
"\n";
694 public function textwithtooltip($text, $htmltext, $tooltipon = 1, $direction = 0, $img =
'', $extracss =
'', $notabs = 3, $incbefore =
'', $noencodehtmltext = 0, $tooltiptrigger =
'', $forcenowrap = 0)
697 $text = $incbefore . $text;
702 $direction = (int) $direction;
712 $htmltext = str_replace(array(
"\r",
"\n"),
'', $htmltext);
715 if ($direction < 0) {
716 $extracss = ($extracss ? $extracss :
'') . ($notabs != 3 ?
' inline-block' :
'');
717 $extrastyle =
'padding: 0px; padding-left: 2px;';
719 if ($direction > 0) {
720 $extracss = ($extracss ? $extracss :
'') . ($notabs != 3 ?
' inline-block' :
'');
721 $extrastyle =
'padding: 0px; padding-right: 2px;';
724 $classfortooltip =
'classfortooltip';
729 if ($tooltiptrigger ==
'') {
730 $htmltext = str_replace(
'"',
'"', $htmltext);
732 $classfortooltip =
'classfortooltiponclick';
733 $textfordialog .=
'<div style="display: none;" id="idfortooltiponclick_' . $tooltiptrigger .
'" class="classfortooltiponclicktext"';
737 $textfordialog .=
' title="'.$langs->trans(
"Note").
'"';
739 $textfordialog .=
'>' . $htmltext .
'</div>';
741 if ($tooltipon == 2 || $tooltipon == 3) {
742 $paramfortooltipimg =
' class="' . $classfortooltip . ($notabs != 3 ?
' inline-block' :
'') . ($extracss ?
' ' . $extracss :
'') .
'" style="padding: 0px;' . ($extrastyle ?
' ' . $extrastyle :
'') .
'"';
743 if ($tooltiptrigger ==
'') {
744 $paramfortooltipimg .=
' title="' . ($noencodehtmltext ? $htmltext :
dol_escape_htmltag($htmltext, 1, 0,
'span', 0, 1)) .
'"';
746 $paramfortooltipimg .=
' dolid="' . $tooltiptrigger .
'"';
749 $paramfortooltipimg = ($extracss ?
' class="' . $extracss .
'"' :
'') . ($extrastyle ?
' style="' . $extrastyle .
'"' :
'');
751 if ($tooltipon == 1 || $tooltipon == 3) {
752 $paramfortooltiptd =
' class="' . ($tooltipon == 3 ?
'cursorpointer ' :
'') . $classfortooltip . ($tag !=
'td' ?
' inline-block' :
'') . ($extracss ?
' ' . $extracss :
'') .
'" style="padding: 0px;' . ($extrastyle ?
' ' . $extrastyle :
'') .
'" ';
753 if ($tooltiptrigger ==
'') {
754 $paramfortooltiptd .=
' title="' . ($noencodehtmltext ? $htmltext :
dol_escape_htmltag($htmltext, 1, 0,
'span', 0, 1)) .
'"';
756 $paramfortooltiptd .=
' dolid="' . $tooltiptrigger .
'"';
759 $paramfortooltiptd = ($extracss ?
' class="' . $extracss .
'"' :
'') . ($extrastyle ?
' style="' . $extrastyle .
'"' :
'');
761 if (empty($notabs)) {
762 $s .=
'<table class="nobordernopadding"><tr style="height: auto;">';
763 } elseif ($notabs == 2) {
764 $s .=
'<div class="inline-block' . ($forcenowrap ?
' nowrap' :
'') .
'">';
767 if ($direction < 0) {
768 $s .=
'<' . $tag . $paramfortooltipimg;
770 $s .=
' class="valigntop" width="14"';
772 $s .=
'>' . $textfordialog . $img .
'</' . $tag .
'>';
776 if ((
string) $text !=
'') {
777 $s .=
'<' . $tag . $paramfortooltiptd .
'>' . $text .
'</' . $tag .
'>';
780 if ($direction > 0) {
781 $s .=
'<' . $tag . $paramfortooltipimg;
783 $s .=
' class="valignmiddle" width="14"';
785 $s .=
'>' . $textfordialog . $img .
'</' . $tag .
'>';
787 if (empty($notabs)) {
788 $s .=
'</tr></table>';
789 } elseif ($notabs == 2) {
810 public function textwithpicto($text, $htmltooltip, $direction = 1, $type =
'help', $extracss =
'valignmiddle', $noencodehtmltext = 0, $notabs = 3, $tooltiptrigger =
'', $forcenowrap = 0)
812 global $conf, $langs;
817 } elseif ($type ==
'1') {
821 $tooltiptrigger = preg_replace(
'/[^a-z0-9]/i',
'', $tooltiptrigger);
823 if (preg_match(
'/onsmartphone$/', $tooltiptrigger) && empty($conf->dol_no_mouse_hover)) {
824 $tooltiptrigger = preg_replace(
'/^.*onsmartphone$/',
'', $tooltiptrigger);
827 if ($tooltiptrigger) {
828 $alt = $langs->transnoentitiesnoconv(
"ClickToShowHelp");
832 if (empty($conf->use_javascript_ajax)) {
833 if ($type ==
'info' || $type ==
'infoclickable' || $type ==
'help' || $type ==
'helpclickable') {
842 if (!empty($conf->dol_no_mouse_hover) && empty($tooltiptrigger)) {
843 if ($type ==
'info' || $type ==
'infoclickable' || $type ==
'help' || $type ==
'helpclickable') {
854 if ($type ==
'info') {
855 $img =
img_help(($tooltiptrigger !=
'' ? 2 : 0), $alt);
856 } elseif ($type ==
'help') {
857 $img =
img_help(($tooltiptrigger !=
'' ? 2 : 1), $alt);
858 } elseif ($type ==
'helpclickable') {
859 $img =
img_help(($tooltiptrigger !=
'' ? 2 : 1), $alt);
860 } elseif ($type ==
'warning') {
862 } elseif ($type !=
'none') {
867 $tooltipon = ((($tooltiptrigger && !$img) || strpos($type,
'clickable')) ? 3 : 2);
869 return $this->
textwithtooltip($text, $htmltooltip, $tooltipon, $direction, $img, $extracss, $notabs,
'', $noencodehtmltext, $tooltiptrigger, $forcenowrap);
882 public function selectMassAction($selected, $arrayofaction, $alwaysvisible = 0, $name =
'massaction', $cssclass =
'checkforselect')
884 global $conf, $langs, $hookmanager;
887 $ret =
'<div class="centpercent center">';
888 $ret .=
'<select class="flat' . (empty($conf->use_javascript_ajax) ?
'' :
' hideobject') .
' ' . $name .
' ' . $name .
'select valignmiddle alignstart" id="' . $name .
'" name="' . $name .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
'>';
891 $parameters = array();
892 $reshook = $hookmanager->executeHooks(
'addMoreMassActions', $parameters);
895 if (is_array($arrayofaction) && count($arrayofaction) == 0 && empty($hookmanager->resPrint)) {
898 if (empty($reshook)) {
899 $ret .=
'<option value="0"' . ($disabled ?
' disabled="disabled"' :
'') .
'>-- ' . $langs->trans(
"SelectAction") .
' --</option>';
900 if (is_array($arrayofaction)) {
901 foreach ($arrayofaction as $code => $label) {
902 $ret .=
'<option value="' . $code .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' data-html="' .
dol_escape_htmltag($label) .
'">' . $label .
'</option>';
906 $ret .= $hookmanager->resPrint;
910 if (empty($conf->dol_optimize_smallscreen)) {
915 $ret .=
'<input type="submit" name="confirmmassactioninvisible" style="display: none" tabindex="-1">';
916 $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")) .
'">';
919 if (!empty($conf->use_javascript_ajax)) {
920 $ret .=
'<!-- JS CODE TO ENABLE mass action select -->
922 function initCheckForSelect(mode, name, cssclass) { /* mode is 0 during init of page or click all, 1 when we click on 1 checkboxi, "name" refers to the class of the massaction button, "cssclass" to the class of the check for select boxes */
923 atleastoneselected=0;
924 jQuery("."+cssclass).each(function( index ) {
925 /* console.log( index + ": " + $( this ).text() ); */
926 if ($(this).is(\':checked\')) atleastoneselected++;
929 console.log("initCheckForSelect mode="+mode+" name="+name+" cssclass="+cssclass+" atleastoneselected="+atleastoneselected);
931 if (atleastoneselected || ' . ((int) $alwaysvisible) .
') {
932 jQuery("."+name).show();
933 ' . ($selected ?
'if (atleastoneselected) { jQuery("."+name+"select").val("' . $selected .
'").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', false); }' :
'') .
'
934 ' . ($selected ?
'if (! atleastoneselected) { jQuery("."+name+"select").val("0").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', true); } ' :
'') .
'
936 jQuery("."+name).hide();
937 jQuery("."+name+"other").hide();
941 jQuery(document).ready(function () {
942 initCheckForSelect(0, "' . $name .
'", "' . $cssclass .
'");
943 jQuery(".' . $cssclass .
'").change(function() {
944 console.log("A change was done on .' . $cssclass .
'");
945 initCheckForSelect(1, "' . $name .
'", "' . $cssclass .
'");
947 jQuery(".' . $name .
'select").change(function() {
948 var massaction = $( this ).val();
949 var urlform = $( this ).closest("form").attr("action").replace("#show_files","");
950 if (massaction == "builddoc") {
951 urlform = urlform + "#show_files";
953 $( this ).closest("form").attr("action", urlform);
954 console.log("we select a mass action name=' . $name .
' massaction="+massaction+" - "+urlform);
955 /* Warning: if you set submit button to disabled, post using Enter will no more work if there is no other button */
956 if ($(this).val() != \'0\') {
957 jQuery(".' . $name .
'confirmed").prop(\'disabled\', false);
958 jQuery(".' . $name .
'other").hide(); /* To disable if another div was open */
959 jQuery(".' . $name .
'"+massaction).show();
961 jQuery(".' . $name .
'confirmed").prop(\'disabled\', true);
962 jQuery(".' . $name .
'other").hide(); /* To disable any div open */
992 public function select_country($selected =
'', $htmlname =
'country_id', $htmloption =
'', $maxlength = 0, $morecss =
'minwidth300', $usecodeaskey =
'', $showempty = 1, $disablefavorites = 0, $addspecialentries = 0, $exclude_country_code = array(), $hideflags = 0, $forcecombo = 0)
997 $langs->load(
"dict");
999 $selected = (string) $selected;
1003 $countryArray = array();
1004 $favorite = array();
1006 $atleastonefavorite = 0;
1008 $sql =
"SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite, eec";
1009 $sql .=
" FROM " . $this->db->prefix() .
"c_country";
1010 $sql .=
" WHERE active > 0";
1013 dol_syslog(get_class($this) .
"::select_country", LOG_DEBUG);
1015 $resql = $this->db->query($sql);
1017 $out .=
'<select id="select' . $htmlname .
'" class="flat maxwidth200onsmartphone selectcountry' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" ' . $htmloption .
'>';
1018 $num = $this->db->num_rows($resql);
1022 $obj = $this->db->fetch_object($resql);
1026 'rowid' => (
int) $obj->rowid,
1027 'code_iso' => (
string) $obj->code_iso,
1028 'code_iso3' => (
string) $obj->code_iso3,
1029 'label' => (
string) ($obj->code_iso && $langs->transnoentitiesnoconv(
"Country" . $obj->code_iso) !=
"Country" . $obj->code_iso ? $langs->transnoentitiesnoconv(
"Country" . $obj->code_iso) : ($obj->label !=
'-' ? $obj->label :
'')),
1030 'favorite' => (string) $obj->favorite,
1031 'eec' => (string) $obj->eec,
1033 $favorite[$i] = $obj->favorite;
1038 if (empty($disablefavorites)) {
1039 $array1_sort_order = SORT_DESC;
1040 $array2_sort_order = SORT_ASC;
1041 array_multisort($favorite, $array1_sort_order, $label, $array2_sort_order, $countryArray);
1047 if (is_numeric($showempty)) {
1048 $out .=
'<option value=""> </option>' .
"\n";
1050 $out .=
'<option value="-1">' . $langs->trans($showempty) .
'</option>' .
"\n";
1054 if ($addspecialentries) {
1056 $out .=
'<option value="special_allnotme"' . ($selected ==
'special_allnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesExceptMe", $langs->transnoentitiesnoconv(
"Country" .
$mysoc->country_code)) .
'</option>';
1057 $out .=
'<option value="special_eec"' . ($selected ==
'special_eec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEEC") .
'</option>';
1059 $out .=
'<option value="special_eecnotme"' . ($selected ==
'special_eecnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEECExceptMe", $langs->transnoentitiesnoconv(
"Country" .
$mysoc->country_code)) .
'</option>';
1061 $out .=
'<option value="special_noteec"' . ($selected ==
'special_noteec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesNotInEEC") .
'</option>';
1062 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1065 foreach ($countryArray as $row) {
1067 if (empty($row[
'rowid'])) {
1070 if (is_array($exclude_country_code) && count($exclude_country_code) && in_array($row[
'code_iso'], $exclude_country_code)) {
1074 if (empty($disablefavorites) && $row[
'favorite'] && $row[
'code_iso']) {
1075 $atleastonefavorite++;
1077 if (empty($row[
'favorite']) && $atleastonefavorite) {
1078 $atleastonefavorite = 0;
1079 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1083 if ($row[
'label']) {
1084 $labeltoshow .=
dol_trunc($row[
'label'], $maxlength,
'middle');
1086 $labeltoshow .=
' ';
1088 if ($row[
'code_iso']) {
1089 $labeltoshow .=
' <span class="opacitymedium">(' . $row[
'code_iso'] .
')</span>';
1090 if (empty($hideflags)) {
1091 $tmpflag =
picto_from_langcode($row[
'code_iso'],
'class="saturatemedium paddingrightonly"', 1);
1092 $labeltoshow = $tmpflag .
' ' . $labeltoshow;
1096 if ($selected && $selected !=
'-1' && ($selected == $row[
'rowid'] || $selected == $row[
'code_iso'] || $selected == $row[
'code_iso3'] || $selected == $row[
'label'])) {
1097 $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']) .
'">';
1099 $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']) .
'">';
1102 $out .=
'</option>' .
"\n";
1105 $out .=
'</select>';
1111 if (empty($forcecombo)) {
1112 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1113 $out .=
ajax_combobox(
'select' . $htmlname, array(), 0, 0,
'resolve');
1134 public function select_incoterms($selected =
'', $location_incoterms =
'', $page =
'', $htmlname =
'incoterm_id', $htmloption =
'', $forcecombo = 1, $events = array(), $disableautocomplete = 0)
1137 global $conf, $langs;
1139 $langs->load(
"dict");
1143 $incotermArray = array();
1145 $sql =
"SELECT rowid, code";
1146 $sql .=
" FROM " . $this->db->prefix() .
"c_incoterms";
1147 $sql .=
" WHERE active > 0";
1148 $sql .=
" ORDER BY code ASC";
1150 dol_syslog(get_class($this) .
"::select_incoterm", LOG_DEBUG);
1151 $resql = $this->db->query($sql);
1153 if ($conf->use_javascript_ajax && !$forcecombo) {
1154 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1158 if (!empty($page)) {
1159 $out .=
'<form method="post" action="' . $page .
'">';
1160 $out .=
'<input type="hidden" name="action" value="set_incoterms">';
1161 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
1164 $out .=
'<select id="' . $htmlname .
'" class="flat selectincoterm width75" name="' . $htmlname .
'" ' . $htmloption .
'>';
1165 $out .=
'<option value="0"> </option>';
1166 $num = $this->db->num_rows($resql);
1170 $obj = $this->db->fetch_object($resql);
1171 $incotermArray[$i][
'rowid'] = $obj->rowid;
1172 $incotermArray[$i][
'code'] = $obj->code;
1176 foreach ($incotermArray as $row) {
1177 if ($selected && ($selected == $row[
'rowid'] || $selected == $row[
'code'])) {
1178 $out .=
'<option value="' . $row[
'rowid'] .
'" selected>';
1180 $out .=
'<option value="' . $row[
'rowid'] .
'">';
1184 $out .= $row[
'code'];
1187 $out .=
'</option>';
1190 $out .=
'</select>';
1193 if ($conf->use_javascript_ajax && empty($disableautocomplete)) {
1194 $out .=
ajax_multiautocompleter(
'location_incoterms', array(), DOL_URL_ROOT .
'/core/ajax/locationincoterms.php') .
"\n";
1197 $out .=
'<input id="location_incoterms" class="maxwidthonsmartphone heightofcombo" type="text" name="location_incoterms" value="' . $location_incoterms .
'">' .
"\n";
1199 if (!empty($page)) {
1200 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp nomargintop nomarginbottom" value="' . $langs->trans(
"Modify") .
'"></form>';
1224 public function select_type_of_lines($selected =
'', $htmlname =
'type', $showempty = 0, $hidetext = 0, $forceall = 0, $morecss =
"", $useajaxcombo = 1)
1232 if (empty($hidetext)) {
1233 print $langs->trans(
"Type").
'...';
1236 print
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
1238 print
'<option value="-1" class="opacitymedium"'.($useajaxcombo ?
'' :
' disabled="disabled"');
1239 if ($selected == -1) {
1243 if (is_numeric($showempty)) {
1251 print
'<option value="0"';
1252 if (0 == $selected || ($selected == -1 &&
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') ==
'product')) {
1255 print
'>' . $langs->trans(
"Product");
1258 print
'<option value="1"';
1259 if (1 == $selected || ($selected == -1 &&
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') ==
'service')) {
1262 print
'>' . $langs->trans(
"Service");
1267 if ($useajaxcombo) {
1273 print $langs->trans(
"Service");
1274 print
'<input type="hidden" name="' . $htmlname .
'" value="1">';
1277 print $langs->trans(
"Product");
1278 print
'<input type="hidden" name="' . $htmlname .
'" value="0">';
1280 if ($forceall < 0) {
1281 print
'<input type="hidden" name="' . $htmlname .
'" value="1">';
1297 $num = count($this->cache_types_fees);
1304 $langs->load(
"trips");
1306 $sql =
"SELECT c.code, c.label";
1307 $sql .=
" FROM " . $this->db->prefix() .
"c_type_fees as c";
1308 $sql .=
" WHERE active > 0";
1310 $resql = $this->db->query($sql);
1312 $num = $this->db->num_rows($resql);
1316 $obj = $this->db->fetch_object($resql);
1319 $label = ($obj->code != $langs->trans($obj->code) ? $langs->trans($obj->code) : $langs->trans($obj->label));
1320 $this->cache_types_fees[$obj->code] = $label;
1324 asort($this->cache_types_fees);
1346 global $user, $langs;
1348 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
1352 print
'<select id="select_' . $htmlname .
'" class="flat" name="' . $htmlname .
'">';
1354 print
'<option value="-1"';
1355 if ($selected == -1) {
1358 print
'> </option>';
1361 foreach ($this->cache_types_fees as $key => $value) {
1362 print
'<option value="' . $key .
'"';
1363 if ($key == $selected) {
1373 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1402 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)
1405 global $conf, $langs;
1409 if (!empty($conf->use_javascript_ajax) &&
getDolGlobalString(
'COMPANY_USE_SEARCH_TO_SELECT') && !$forcecombo) {
1410 if (is_null($ajaxoptions)) {
1411 $ajaxoptions = array();
1414 require_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1418 if ($selected && empty($selected_input_value)) {
1419 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
1420 $societetmp =
new Societe($this->db);
1421 $societetmp->fetch($selected);
1422 $selected_input_value = $societetmp->name;
1427 $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)) :
'');
1429 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
1430 if (empty($hidelabel)) {
1431 $out .= $langs->trans(
"RefOrLabel") .
' : ';
1432 } elseif ($hidelabel == 1 && !is_numeric($showempty)) {
1433 $placeholder = $langs->trans($showempty);
1434 } elseif ($hidelabel > 1) {
1435 $placeholder = $langs->trans(
"RefOrLabel");
1436 if ($hidelabel == 2) {
1437 $out .=
img_picto($langs->trans(
"Search"),
'search');
1440 $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' :
'') .
' />';
1441 if ($hidelabel == 3) {
1442 $out .=
img_picto($langs->trans(
"Search"),
'search');
1447 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.
'/societe/ajax/company.php', $urloption,
getDolGlobalInt(
'COMPANY_USE_SEARCH_TO_SELECT'), 0, $ajaxoptions);
1450 $out .= $this->
select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events,
'', 0, $limit, $morecss, $moreparam, $multiple, $excludeids, $showcode);
1484 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 =
'')
1488 global $conf, $langs;
1493 if ($nokeyifsocid && $socid > 0) {
1494 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = 0;
1497 if (!empty($conf->use_javascript_ajax) &&
getDolGlobalString(
'CONTACT_USE_SEARCH_TO_SELECT') && !$forcecombo) {
1498 if (is_null($events)) {
1502 require_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1506 if ($selected && empty($selected_input_value)) {
1507 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
1508 $contacttmp =
new Contact($this->db);
1509 $contacttmp->fetch($selected);
1510 $selected_input_value = $contacttmp->getFullName($langs);
1513 if (!is_numeric($showempty)) {
1514 $placeholder = $showempty;
1518 $urloption =
'htmlname=' . urlencode((
string) (str_replace(
'.',
'_', $htmlname))) .
'&outjson=1&filter=' . urlencode((
string) ($filter)) . (empty($exclude) ?
'' :
'&exclude=' . urlencode($exclude)) . ($showsoc ?
'&showsoc=' . urlencode((
string) ($showsoc)) :
'');
1520 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
1522 $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' :
'') .
' />';
1526 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.
'/contact/ajax/contact.php', $urloption,
getDolGlobalInt(
'CONTACT_USE_SEARCH_TO_SELECT'), 0, $events);
1530 $disableifempty = 0;
1534 $out .= $this->
selectcontacts($socid, $selected, $htmlname, $showempty, $exclude, $limitto, $showfunction, $morecss, $options_only, $showsoc, $forcecombo, $events, $moreparam, $htmlid, $multiple, $disableifempty);
1537 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = $sav;
1570 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)
1573 global $user, $langs;
1574 global $hookmanager;
1576 $langs->loadLangs(array(
"companies",
"suppliers"));
1580 $outarray = array();
1582 if ($selected ===
'') {
1583 $selected = array();
1584 } elseif (!is_array($selected)) {
1585 $selected = array($selected);
1589 if (function_exists(
'testSqlAndScriptInject')) {
1592 return 'SQLInjectionTryDetected';
1596 if ($filter !=
'') {
1597 if (preg_match(
'/[\(\)]/', $filter)) {
1603 if (function_exists(
'testSqlAndScriptInject')) {
1606 return 'SQLInjectionTryDetected';
1612 dol_syslog(
"Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Syntax.", LOG_WARNING);
1617 $sql =
"SELECT s.rowid, s.nom as name, s.name_alias, s.tva_intra, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
1619 $sql .=
", s.address, s.zip, s.town";
1620 $sql .=
", dictp.code as country_code";
1622 $sql .=
" FROM " . $this->db->prefix() .
"societe as s";
1624 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_country as dictp ON dictp.rowid = s.fk_pays";
1626 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1627 $sql .=
", " . $this->db->prefix() .
"societe_commerciaux as sc";
1629 $sql .=
" WHERE s.entity IN (" .
getEntity(
'societe') .
")";
1630 if (!empty($user->socid)) {
1631 $sql .=
" AND s.rowid = " . ((int) $user->socid);
1636 $sql .=
" AND (" . $filter .
")";
1638 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1639 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = " . ((int) $user->id);
1642 $sql .=
" AND s.status <> 0";
1644 if (!empty($excludeids)) {
1645 $sql .=
" AND s.rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeids)) .
")";
1648 $parameters = array();
1649 $reshook = $hookmanager->executeHooks(
'selectThirdpartyListWhere', $parameters);
1650 $sql .= $hookmanager->resPrint;
1652 if ($filterkey && $filterkey !=
'') {
1656 $search_crit = explode(
' ', $filterkey);
1658 if (count($search_crit) > 1) {
1661 foreach ($search_crit as $crit) {
1665 $sql .=
"(s.nom LIKE '" . $this->db->escape($prefix . $crit) .
"%')";
1668 if (count($search_crit) > 1) {
1672 $sql .=
" OR s.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1674 $sql .=
" OR s.code_client LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.code_fournisseur LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1675 $sql .=
" OR s.name_alias LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.tva_intra LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1678 $sql .= $this->db->order(
"nom",
"ASC");
1679 $sql .= $this->db->plimit($limit, 0);
1682 dol_syslog(get_class($this).
"::select_thirdparty_list", LOG_DEBUG);
1683 $resql = $this->db->query($sql);
1686 $out .=
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
' name="' . $htmlname . ($multiple ?
'[]' :
'') .
'"' . ($multiple ?
' multiple' :
'') .
'>' .
"\n";
1688 $textifempty = (($showempty && !is_numeric($showempty)) ? $langs->trans($showempty) :
'');
1692 if ($showempty && !is_numeric($showempty)) {
1693 $textifempty = $langs->trans($showempty);
1695 $textifempty .= $langs->trans(
"All");
1699 $out .=
'<option value="-1" data-html="' .
dol_escape_htmltag(
'<span class="opacitymedium">' . ($textifempty ? $textifempty :
' ') .
'</span>') .
'">' . $textifempty .
'</option>' .
"\n";
1702 $companytemp =
new Societe($this->db);
1704 $num = $this->db->num_rows($resql);
1708 $obj = $this->db->fetch_object($resql);
1711 if (($obj->client) && (!empty($obj->code_client))) {
1712 $label = $obj->code_client .
' - ';
1714 if (($obj->fournisseur) && (!empty($obj->code_fournisseur))) {
1715 $label .= $obj->code_fournisseur .
' - ';
1717 $label .=
' ' . $obj->name;
1719 $label = $obj->name;
1722 if (!empty($obj->name_alias)) {
1723 $label .=
' (' . $obj->name_alias .
')';
1727 $label .=
' - '.$obj->tva_intra;
1730 $labelhtml = $label;
1733 $companytemp->id = $obj->rowid;
1734 $companytemp->client = $obj->client;
1735 $companytemp->fournisseur = $obj->fournisseur;
1736 $tmptype = $companytemp->getTypeUrl(1,
'', 0,
'span');
1738 $labelhtml .=
' ' . $tmptype;
1741 if ($obj->client || $obj->fournisseur) {
1744 if ($obj->client == 1 || $obj->client == 3) {
1745 $label .= $langs->trans(
"Customer");
1747 if ($obj->client == 2 || $obj->client == 3) {
1748 $label .= ($obj->client == 3 ?
', ' :
'') . $langs->trans(
"Prospect");
1750 if ($obj->fournisseur) {
1751 $label .= ($obj->client ?
', ' :
'') . $langs->trans(
"Supplier");
1753 if ($obj->client || $obj->fournisseur) {
1759 $s = ($obj->address ?
' - ' . $obj->address :
'') . ($obj->zip ?
' - ' . $obj->zip :
'') . ($obj->town ?
' ' . $obj->town :
'');
1760 if (!empty($obj->country_code)) {
1761 $s .=
', ' . $langs->trans(
'Country' . $obj->country_code);
1767 if (empty($outputmode)) {
1768 if (in_array($obj->rowid, $selected)) {
1769 $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>';
1771 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
1774 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label,
'labelhtml' => $labelhtml));
1778 if (($i % 10) == 0) {
1783 $out .=
'</select>' .
"\n";
1785 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1792 $this->result = array(
'nbofthirdparties' => $num);
1826 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 =
'')
1828 global $conf, $user, $langs, $hookmanager, $action;
1830 $langs->load(
'companies');
1832 if (empty($htmlid)) {
1833 $htmlid = $htmlname;
1837 $outarray = array();
1839 if ($selected ===
'') {
1840 $selected = array();
1841 } elseif (!is_array($selected)) {
1842 $selected = array((
int) $selected);
1846 if (function_exists(
'testSqlAndScriptInject')) {
1849 return 'SQLInjectionTryDetected';
1853 if ($filter !=
'') {
1854 if (preg_match(
'/[\(\)]/', $filter)) {
1860 if (function_exists(
'testSqlAndScriptInject')) {
1863 return 'SQLInjectionTryDetected';
1869 dol_syslog(
"Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Filter Syntax.", LOG_WARNING);
1873 if (!is_object($hookmanager)) {
1874 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
1879 $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";
1880 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
1881 $sql .=
", s.nom as company, s.town AS company_town";
1883 $sql .=
" FROM " . $this->db->prefix() .
"socpeople as sp";
1884 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
1885 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON s.rowid = sp.fk_soc";
1887 $sql .=
" WHERE sp.entity IN (" .
getEntity(
'contact') .
")";
1888 $sql .=
" AND ((sp.fk_user_creat = ".((int) $user->id).
" AND sp.priv = 1) OR sp.priv = 0)";
1889 if ($socid > 0 || $socid == -1) {
1890 $sql .=
" AND sp.fk_soc = " . ((int) $socid);
1893 $sql .=
" AND sp.statut <> 0";
1896 if (!$user->hasRight(
'societe',
'client',
'voir') && !$user->socid) {
1897 $sql .=
" AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = sp.fk_soc AND sc.fk_user = ".(int) $user->id .
")";
1899 if ($user->socid > 0) {
1900 $sql .=
" AND sp.fk_soc = ".((int) $user->socid);
1905 $sql .=
" AND (" . $filter .
")";
1908 $parameters = array();
1909 $reshook = $hookmanager->executeHooks(
'selectContactListWhere', $parameters);
1910 $sql .= $hookmanager->resPrint;
1911 $sql .=
" ORDER BY sp.lastname ASC";
1913 dol_syslog(get_class($this) .
"::selectcontacts", LOG_DEBUG);
1914 $resql = $this->db->query($sql);
1916 $num = $this->db->num_rows($resql);
1918 if ($htmlname !=
'none' && !$options_only) {
1919 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlid .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . (($num || empty($disableifempty)) ?
'' :
' disabled') . ($multiple ?
'multiple' :
'') .
' ' . (!empty($moreparam) ? $moreparam :
'') .
'>';
1922 if ($showempty && !is_numeric($showempty)) {
1923 $textforempty = $showempty;
1924 $out .=
'<option class="optiongrey" value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'>' . $textforempty .
'</option>';
1926 if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) {
1927 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'> </option>';
1929 if ($showempty == 2) {
1930 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Internal") .
' --</option>';
1936 include_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
1937 $contactstatic =
new Contact($this->db);
1940 $obj = $this->db->fetch_object($resql);
1943 $extendedInfos =
'';
1945 $extendedInfos = array();
1946 $email = trim($obj->email);
1947 if (!empty($email)) {
1948 $extendedInfos[] = $email;
1950 $phone = trim($obj->phone);
1951 $phone_perso = trim($obj->phone_perso);
1952 $phone_mobile = trim($obj->phone_mobile);
1953 if (!empty($phone)) {
1954 $extendedInfos[] = $phone;
1956 if (!empty($phone_perso)) {
1957 $extendedInfos[] = $phone_perso;
1959 if (!empty($phone_mobile)) {
1960 $extendedInfos[] = $phone_mobile;
1963 $contact_town = trim($obj->contact_town);
1964 $company_town = trim($obj->company_town);
1965 if (!empty($contact_town)) {
1966 $extendedInfos[] = $contact_town;
1967 } elseif (!empty($company_town)) {
1968 $extendedInfos[] = $company_town;
1970 $extendedInfos = implode(
' - ', $extendedInfos);
1971 if (!empty($extendedInfos)) {
1972 $extendedInfos =
' - ' . $extendedInfos;
1976 $contactstatic->id = $obj->rowid;
1977 $contactstatic->lastname = $obj->lastname;
1978 $contactstatic->firstname = $obj->firstname;
1979 if ($obj->statut == 1) {
1981 if ($htmlname !=
'none') {
1983 if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) {
1986 if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) {
1989 if (!empty($selected) && in_array($obj->rowid, $selected)) {
1990 $out .=
'<option value="' . $obj->rowid .
'"';
1992 $out .=
' disabled';
1994 $out .=
' selected>';
1996 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1997 if ($showfunction && $obj->poste) {
1998 $tmplabel .=
' (' . $obj->poste .
')';
2000 if (($showsoc > 0) && $obj->company) {
2001 $tmplabel .=
' - (' . $obj->company .
')';
2005 $out .=
'</option>';
2007 $out .=
'<option value="' . $obj->rowid .
'"';
2009 $out .=
' disabled';
2013 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
2014 if ($showfunction && $obj->poste) {
2015 $tmplabel .=
' (' . $obj->poste .
')';
2017 if (($showsoc > 0) && $obj->company) {
2018 $tmplabel .=
' - (' . $obj->company .
')';
2022 $out .=
'</option>';
2025 if (in_array($obj->rowid, $selected)) {
2026 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
2027 if ($showfunction && $obj->poste) {
2028 $tmplabel .=
' (' . $obj->poste .
')';
2030 if (($showsoc > 0) && $obj->company) {
2031 $tmplabel .=
' - (' . $obj->company .
')';
2038 if ($tmplabel !=
'') {
2039 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $tmplabel,
'label' => $tmplabel,
'labelhtml' => $tmplabel));
2045 $labeltoshow = ($socid != -1) ? ($langs->trans($socid ?
"NoContactDefinedForThirdParty" :
"NoContactDefined")) : $langs->trans(
'SelectAThirdPartyFirst');
2046 $out .=
'<option class="disabled" value="-1"' . (($showempty == 2 || $multiple) ?
'' :
' selected') .
' disabled="disabled">';
2047 $out .= $labeltoshow;
2048 $out .=
'</option>';
2051 $parameters = array(
2053 'htmlname' => $htmlname,
2056 'showfunction' => $showfunction,
2057 'showsoc' => $showsoc,
2060 $reshook = $hookmanager->executeHooks(
'afterSelectContactOptions', $parameters, $this, $action);
2062 if ($htmlname !=
'none' && !$options_only) {
2063 $out .=
'</select>';
2066 if ($conf->use_javascript_ajax && !$forcecombo && !$options_only) {
2067 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2073 if ($options_only === 2) {
2101 global $langs, $conf;
2104 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
2105 $sql .=
" re.description, re.fk_facture_source";
2106 $sql .=
" FROM " . $this->db->prefix() .
"societe_remise_except as re";
2107 $sql .=
" WHERE re.fk_soc = " . (int) $socid;
2108 $sql .=
" AND re.entity = " . $conf->entity;
2110 $sql .=
" AND " . $filter;
2112 $sql .=
" ORDER BY re.description ASC";
2114 dol_syslog(get_class($this) .
"::select_remises", LOG_DEBUG);
2115 $resql = $this->db->query($sql);
2117 print
'<select id="select_' . $htmlname .
'" class="flat maxwidth200onsmartphone" name="' . $htmlname .
'">';
2118 $num = $this->db->num_rows($resql);
2120 $qualifiedlines = $num;
2124 print
'<option value="0"> </option>';
2126 $obj = $this->db->fetch_object($resql);
2127 $desc =
dol_trunc($obj->description, 40);
2128 if (preg_match(
'/\(CREDIT_NOTE\)/', $desc)) {
2129 $desc = preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $desc);
2131 if (preg_match(
'/\(DEPOSIT\)/', $desc)) {
2132 $desc = preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"Deposit"), $desc);
2134 if (preg_match(
'/\(EXCESS RECEIVED\)/', $desc)) {
2135 $desc = preg_replace(
'/\(EXCESS RECEIVED\)/', $langs->trans(
"ExcessReceived"), $desc);
2137 if (preg_match(
'/\(EXCESS PAID\)/', $desc)) {
2138 $desc = preg_replace(
'/\(EXCESS PAID\)/', $langs->trans(
"ExcessPaid"), $desc);
2142 if ($selected > 0 && $selected == $obj->rowid) {
2143 $selectstring =
' selected';
2147 if ($maxvalue > 0 && $obj->amount_ttc > $maxvalue) {
2149 $disabled =
' disabled';
2152 if (
getDolGlobalString(
'MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST') && !empty($obj->fk_facture_source)) {
2153 $tmpfac =
new Facture($this->db);
2154 if ($tmpfac->fetch($obj->fk_facture_source) > 0) {
2155 $desc = $desc .
' - ' . $tmpfac->ref;
2159 print
'<option value="' . $obj->rowid .
'"' . $selectstring . $disabled .
'>' . $desc .
' (' .
price($obj->amount_ht) .
' ' . $langs->trans(
"HT") .
' - ' .
price($obj->amount_ttc) .
' ' . $langs->trans(
"TTC") .
')</option>';
2166 return $qualifiedlines;
2191 public function select_users($selected =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include =
'', $enableonly = array(), $force_entity =
'0')
2194 print $this->
select_dolusers($selected, $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity);
2223 public function select_dolusers($selected =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include =
'', $enableonly =
'', $force_entity =
'', $maxlength = 0, $showstatus = 0, $morefilter =
'', $showalso = 0, $enableonlytext =
'', $morecss =
'', $notdisabled = 0, $outputmode = 0, $multiple =
false, $forcecombo = 0)
2226 global $conf, $user, $langs, $hookmanager;
2230 if ((is_numeric($selected) && ($selected < -4 || empty($selected))) && !
getDolGlobalString(
'SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE')) {
2231 $selected = $user->id;
2234 if ($selected ===
'') {
2235 $selected = array();
2236 } elseif (!is_array($selected)) {
2237 $selected = array($selected);
2241 $excludeUsers =
null;
2242 if (is_array($exclude)) {
2243 $excludeUsers = implode(
",", $exclude);
2247 $includeUsers =
null;
2248 $includeUsersArray = array();
2249 if (is_array($include)) {
2250 $includeUsersArray = $include;
2251 } elseif ($include ==
'hierarchy') {
2253 $includeUsersArray = $user->getAllChildIds(0);
2254 } elseif ($include ==
'hierarchyme') {
2256 $includeUsersArray = $user->getAllChildIds(1);
2271 $includeUsers = implode(
",", $includeUsersArray);
2276 $outarray = array();
2277 $outarray2 = array();
2280 $showlabelofentity =
isModEnabled(
'multicompany') && !
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE') && $conf->entity == 1 && !empty($user->admin) && empty($user->entity) && !preg_match(
'/^search_/', $htmlname);
2281 $userissuperadminentityone =
isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && empty($user->entity);
2284 $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";
2285 if ($showlabelofentity) {
2286 $sql .=
", e.label";
2288 $sql .=
" FROM " . $this->db->prefix() .
"user as u";
2289 if ($showlabelofentity) {
2290 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid = u.entity";
2293 if ($userissuperadminentityone && $force_entity !==
'default') {
2294 if (!empty($force_entity)) {
2295 $sql .=
" WHERE u.entity IN (0, " . $this->db->sanitize($force_entity) .
")";
2297 $sql .=
" WHERE u.entity IS NOT NULL";
2301 $sql .=
" WHERE u.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
2303 $sql .=
" WHERE u.entity IN (" .
getEntity(
'user') .
")";
2307 if (!empty($user->socid)) {
2308 $sql .=
" AND u.fk_soc = " . ((int) $user->socid);
2310 if (is_array($exclude) && $excludeUsers) {
2311 $sql .=
" AND u.rowid NOT IN (" . $this->db->sanitize($excludeUsers) .
")";
2313 if ($includeUsers) {
2314 $sql .=
" AND u.rowid IN (" . $this->db->sanitize($includeUsers) .
")";
2317 $sql .=
" AND u.statut <> 0";
2320 $sql .=
" AND u.employee <> 0";
2323 $sql .=
" AND u.fk_soc IS NULL";
2325 if (!empty($morefilter)) {
2328 if ($errormessage) {
2329 $this->errors[] = $errormessage;
2330 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2331 if ($outputmode == 0) {
2332 return 'Error bad param $morefilter';
2340 $reshook = $hookmanager->executeHooks(
'addSQLWhereFilterOnSelectUsers', array(), $this, $action);
2341 if (!empty($reshook)) {
2342 $sql .= $hookmanager->resPrint;
2346 $sql .=
" ORDER BY u.statut DESC, u.firstname ASC, u.lastname ASC";
2348 $sql .=
" ORDER BY u.statut DESC, u.lastname ASC, u.firstname ASC";
2351 dol_syslog(get_class($this) .
"::select_dolusers", LOG_DEBUG);
2353 $resql = $this->db->query($sql);
2355 $num = $this->db->num_rows($resql);
2359 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
' minwidth200') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
2360 if ($show_empty && !$multiple) {
2361 $textforempty =
' ';
2362 if (!empty($conf->use_javascript_ajax)) {
2363 $textforempty =
' ';
2365 if (!is_numeric($show_empty)) {
2366 $textforempty = $show_empty;
2368 $out .=
'<option class="optiongrey" value="' . ($show_empty < 0 ? $show_empty : -1) .
'"' . ((empty($selected) || in_array(-1, $selected)) ?
' selected' :
'') .
'>' . $textforempty .
'</option>' .
"\n";
2370 $outarray[($show_empty < 0 ? $show_empty : -1)] = $textforempty;
2371 $outarray2[($show_empty < 0 ? $show_empty : -1)] = array(
2372 'id' => ($show_empty < 0 ? $show_empty : -1),
2373 'label' => $textforempty,
2374 'labelhtml' => $textforempty,
2379 if ($showalso == 2 || $showalso == 3) {
2380 $out .=
'<option value="-3"' . ((in_array(-3, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"MyTeam") .
' --</option>' .
"\n";
2382 $hasAtLeastOneSubordinate = (count($user->getAllChildIds(1)) > 1);
2383 if ($hasAtLeastOneSubordinate) {
2385 $outarray[-3] =
'-- ' . $langs->trans(
"MyTeam") .
' --';
2386 $outarray2[-3] = array(
2388 'label' =>
'-- ' . $langs->trans(
"MyTeam") .
' --',
2389 'labelhtml' =>
'-- ' . $langs->trans(
"MyTeam") .
' --',
2395 if ($showalso == 1 || $showalso == 3) {
2396 $out .=
'<option value="-2"' . ((in_array(-2, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Everybody") .
' --</option>' .
"\n";
2398 $outarray[-2] =
'-- ' . $langs->trans(
"Everybody") .
' --';
2399 $outarray2[-2] = array(
2401 'label' =>
'-- ' . $langs->trans(
"Everybody") .
' --',
2402 'labelhtml' =>
'-- ' . $langs->trans(
"Everybody") .
' --',
2407 if ($showalso == 4) {
2408 $out .=
'<option value="-4"' . ((in_array(-4, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"AllProjectContacts") .
' --</option>' .
"\n";
2410 $outarray[-4] =
'-- ' . $langs->trans(
"AllProjectContacts") .
' --';
2411 $outarray2[-4] = array(
2413 'label' =>
'-- ' . $langs->trans(
"AllProjectContacts") .
' --',
2414 'labelhtml' =>
'-- ' . $langs->trans(
"AllProjectContacts") .
' --',
2420 $userstatic =
new User($this->db);
2423 $obj = $this->db->fetch_object($resql);
2425 $userstatic->id = $obj->rowid;
2426 $userstatic->lastname = $obj->lastname;
2427 $userstatic->firstname = $obj->firstname;
2428 $userstatic->photo = $obj->photo;
2429 $userstatic->status = $obj->status;
2430 $userstatic->entity = $obj->entity;
2431 $userstatic->admin = $obj->admin;
2432 $userstatic->gender = $obj->gender;
2435 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
2436 $disableline = ($enableonlytext ? $enableonlytext :
'1');
2440 $labeltoshowhtml =
'';
2447 $labeltoshow .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2448 $labeltoshowhtml .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2449 if (empty($obj->firstname) && empty($obj->lastname)) {
2450 $labeltoshow .= $obj->login;
2451 $labeltoshowhtml .= $obj->login;
2458 $moreinfo .= ($moreinfo ?
' - ' :
' (');
2459 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(');
2460 $moreinfo .= $obj->login;
2461 $moreinfohtml .= $obj->login;
2463 if ($showstatus >= 0) {
2464 if ($obj->status == 1 && $showstatus == 1) {
2465 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Enabled');
2466 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Enabled');
2468 if ($obj->status == 0 && $showstatus == 1) {
2469 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Disabled');
2470 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Disabled');
2473 if ($showlabelofentity) {
2474 if (empty($obj->entity)) {
2475 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
"AllEntities");
2476 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
"AllEntities");
2478 if ($obj->entity != $conf->entity) {
2479 $moreinfo .= ($moreinfo ?
' - ' :
' (') . ($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2480 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(').($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2484 $moreinfo .= (!empty($moreinfo) ?
')' :
'');
2485 $moreinfohtml .= (!empty($moreinfohtml) ?
')</span>' :
'');
2486 if (!empty($disableline) && $disableline !=
'1') {
2488 $moreinfo .=
' - ' . $disableline;
2489 $moreinfohtml .=
' - ' . $disableline;
2491 $labeltoshow .= $moreinfo;
2492 $labeltoshowhtml .= $moreinfohtml;
2494 $out .=
'<option value="' . $obj->rowid .
'"';
2495 if (!empty($disableline)) {
2496 $out .=
' disabled';
2498 if ((!empty($selected[0]) && is_object($selected[0])) ? $selected[0]->id == $obj->rowid : in_array($obj->rowid, $selected)) {
2499 $out .=
' selected';
2501 $out .=
' data-html="';
2503 $outhtml = $userstatic->getNomUrl(-3,
'', 0, 1, 24, 1,
'login',
'', 1) .
' ';
2504 if ($showstatus >= 0 && $obj->status == 0) {
2505 $outhtml .=
'<strike class="opacitymediumxxx">';
2507 $outhtml .= $labeltoshowhtml;
2508 if ($showstatus >= 0 && $obj->status == 0) {
2509 $outhtml .=
'</strike>';
2511 $labeltoshowhtml = $outhtml;
2515 $out .= $labeltoshow;
2516 $out .=
'</option>';
2518 $outarray[$userstatic->id] = $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength) . $moreinfo;
2519 $outarray2[$userstatic->id] = array(
2520 'id' => $userstatic->id,
2521 'label' => $labeltoshow,
2522 'labelhtml' => $labeltoshowhtml,
2530 $out .=
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'" disabled>';
2531 $out .=
'<option value="">' . $langs->trans(
"None") .
'</option>';
2533 $out .=
'</select>';
2535 if ($num && !$forcecombo) {
2537 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2546 if ($outputmode == 2) {
2548 } elseif ($outputmode) {
2580 public function select_dolusers_forevent($action =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include = array(), $enableonly = array(), $force_entity =
'0', $maxlength = 0, $showstatus = 0, $morefilter =
'', $showproperties = 0, $listofuserid = array(), $listofcontactid = array(), $listofotherid = array(), $canremoveowner = 1)
2583 global $langs, $user;
2585 $userstatic =
new User($this->db);
2588 if (!empty($_SESSION[
'assignedtouser'])) {
2589 $assignedtouser = json_decode($_SESSION[
'assignedtouser'],
true);
2590 if (!is_array($assignedtouser)) {
2591 $assignedtouser = array();
2594 $assignedtouser = array();
2596 $nbassignetouser = count($assignedtouser);
2599 if ($nbassignetouser) {
2600 $out .=
'<ul class="attendees">';
2604 foreach ($assignedtouser as $key => $value) {
2605 if ($value[
'id'] == $ownerid) {
2611 $userstatic->fetch($value[
'id']);
2612 $out .= $userstatic->getNomUrl(-4);
2615 $ownerid = $value[
'id'];
2616 $out .=
' (' . $langs->trans(
"Owner") .
')';
2619 if ($nbassignetouser > 1 && $action !=
'view') {
2620 $canremoveassignee = 1;
2623 if (!$canremoveowner) {
2624 $canremoveassignee = 0;
2626 if (!$user->hasRight(
'agenda',
'allactions',
'create')) {
2627 $canremoveassignee = 0;
2632 if ($canremoveassignee) {
2635 $out .=
' <input type="image" style="border: 0px;" src="' .
img_picto($langs->trans(
"Remove"),
'delete',
'', 0, 1) .
'" value="' . $userstatic->id .
'" class="noborderfocus removedassigned reposition" id="removedassigned_' . $userstatic->id .
'" name="removedassigned_' . $userstatic->id .
'">';
2639 if ($showproperties) {
2640 if ($ownerid == $value[
'id'] && is_array($listofuserid) && count($listofuserid) && in_array($ownerid, array_keys($listofuserid))) {
2641 $out .=
'<div class="myavailability inline-block">';
2642 $out .=
'<span class="hideonsmartphone"> - ';
2645 $out .=
' <input title="'.$langs->trans(
"Availability").
'" id="transparency" class="paddingrightonly" ' . ($action ==
'view' ?
'disabled' :
'') .
' type="checkbox" name="transparency"' . ($listofuserid[$ownerid][
'transparency'] ?
' checked' :
'') .
'><label for="transparency">' . $langs->trans(
"Busy") .
'</label>';
2655 if ($nbassignetouser) {
2660 if ($action !=
'view') {
2662 $out .=
'<div class="divadduser'.$htmlname.
'">';
2663 $out .=
'<input type="hidden" class="removedassignedhidden" name="removedassigned" value="">';
2664 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
2665 $out .=
'jQuery(".removedassigned").click(function() { jQuery(".removedassignedhidden").val(jQuery(this).val()); });';
2666 $out .=
'jQuery(".assignedtouser").change(function() { console.log(jQuery(".assignedtouser option:selected").val());';
2667 $out .=
' if (jQuery(".assignedtouser option:selected").val() > 0) { jQuery("#' . $action .
'assignedtouser").attr("disabled", false); }';
2668 $out .=
' else { jQuery("#' . $action .
'assignedtouser").attr("disabled", true); }';
2670 $out .=
'})</script>';
2671 $out .=
img_picto(
'',
'user',
'class="pictofixedwidth"');
2672 $out .= $this->
select_dolusers(
'', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter, 0,
'',
'minwidth200');
2673 $out .=
' <button type="submit" disabled class="button valignmiddle smallpaddingimp reposition butActionAdd" id="' . $action .
'assignedtouser" name="' . $action .
'assignedtouser" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
2674 $out .= $langs->trans(
"Add").
'</button>';
2702 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())
2707 require_once DOL_DOCUMENT_ROOT.
'/resource/class/html.formresource.class.php';
2708 require_once DOL_DOCUMENT_ROOT.
'/resource/class/dolresource.class.php';
2713 if (!empty($_SESSION[
'assignedtoresource'])) {
2714 $assignedtoresource = json_decode($_SESSION[
'assignedtoresource'],
true);
2715 if (!is_array($assignedtoresource)) {
2716 $assignedtoresource = array();
2719 $assignedtoresource = array();
2721 $nbassignetoresource = count($assignedtoresource);
2724 if ($nbassignetoresource) {
2725 $out .=
'<ul class="attendees">';
2729 foreach ($assignedtoresource as $key => $value) {
2731 $resourcestatic->fetch($value[
'id']);
2732 $out .= $resourcestatic->getNomUrl(-1);
2733 if ($nbassignetoresource >= 1 && $action !=
'view') {
2734 $out .=
' <input type="image" style="border: 0px;" src="' .
img_picto($langs->trans(
"Remove"),
'delete',
'', 0, 1) .
'" value="' . $resourcestatic->id .
'" class="removedassignedresource reposition" id="removedassignedresource_' . $resourcestatic->id .
'" name="removedassignedresource_' . $resourcestatic->id .
'">';
2737 if ($showproperties) {
2738 if (is_array($listofresourceid) && count($listofresourceid)) {
2739 $out .=
'<div class="myavailability inline-block">';
2740 $out .=
'<span class="hideonsmartphone"> - ';
2743 $out .=
' <input title="'.$langs->trans(
"Availability").
'" id="transparencyresource'.$value[
'id'].
'" class="paddingrightonly" ' . ($action ==
'view' ?
'disabled' :
'') .
' type="checkbox" name="transparency"' . ($listofresourceid[$value[
'id']][
'transparency'] ?
' checked' :
'') .
'><label for="transparencyresource'.$value[
'id'].
'">' . $langs->trans(
"Busy") .
'</label>';
2753 if ($nbassignetoresource) {
2758 if ($action !=
'view') {
2759 $out .=
'<input type="hidden" class="removedassignedresourcehidden" name="removedassignedresource" value="">';
2760 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
2761 $out .=
'jQuery(".removedassignedresource").click(function() { jQuery(".removedassignedresourcehidden").val(jQuery(this).val()); });';
2762 $out .=
'jQuery(".assignedtoresource").change(function() { console.log(jQuery(".assignedtoresource option:selected").val());';
2763 $out .=
' if (jQuery(".assignedtoresource option:selected").val() > 0) { jQuery("#' . $action .
'assignedtoresource").attr("disabled", false); }';
2764 $out .=
' else { jQuery("#' . $action .
'assignedtoresource").attr("disabled", true); }';
2766 $out .=
'})</script>';
2769 if ($nbassignetoresource) {
2772 $out .=
img_picto(
'',
'resource',
'class="pictofixedwidth"');
2774 $out .= $formresources->select_resource_list(0, $htmlname,
'', 1, 1, 0, $events,
'', 2, 0,
'minwidth200');
2776 $out .=
' <button type="submit" disabled class="button valignmiddle smallpaddingimp reposition butActionAdd" id="' . $action .
'assignedtoresource" name="' . $action .
'assignedtoresource" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
2777 $out .= $langs->trans(
"Add");
2778 $out .=
'</button>';
2816 public function select_produits($selected = 0, $htmlname =
'productid', $filtertype =
'', $limit = 0, $price_level = 0, $status = 1, $finished = 2, $selected_input_value =
'', $hidelabel = 0, $ajaxoptions = array(), $socid = 0, $showempty =
'1', $forcecombo = 0, $morecss =
'', $hidepriceinlabel = 0, $warehouseStatus =
'', $selected_combinations =
null, $nooutput = 0, $status_purchase = -1, $warehouseId = 0)
2819 global $langs, $conf;
2824 $price_level = (!empty($price_level) ? $price_level : 0);
2825 if (is_null($ajaxoptions)) {
2826 $ajaxoptions = array();
2837 if (!empty($conf->use_javascript_ajax) &&
getDolGlobalString(
'PRODUIT_USE_SEARCH_TO_SELECT')) {
2838 $placeholder = (is_numeric($showempty) ?
'' :
'placeholder="'.dolPrintHTML($showempty).
'"');
2840 if ($selected && empty($selected_input_value)) {
2841 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
2842 $producttmpselect =
new Product($this->db);
2843 $producttmpselect->fetch($selected);
2844 $selected_input_value = $producttmpselect->ref;
2845 unset($producttmpselect);
2848 if ($filtertype ==
'') {
2856 $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;
2857 if ((
int) $warehouseId > 0) {
2858 $urloption .=
'&warehouseid=' . (int) $warehouseId;
2861 if (
isModEnabled(
'variants') && is_array($selected_combinations)) {
2867 <!-- script to auto show attributes select tags if a variant was selected -->
2868 <script nonce="' .
getNonce() .
'">
2869 // auto show attributes fields
2870 selected = ' . json_encode($selected_combinations) .
';
2873 jQuery(document).ready(function () {
2875 jQuery("input[name=\'prod_entry_mode\']").change(function () {
2876 if (jQuery(this).val() == \'free\') {
2877 jQuery(\'div#attributes_box\').empty();
2881 jQuery("'.$htmltag.
'#' . $htmlname .
'").change(function () {
2883 if (!jQuery(this).val()) {
2884 jQuery(\'div#attributes_box\').empty();
2888 console.log("A change has started. We get variants fields to inject html select");
2890 jQuery.getJSON("' . DOL_URL_ROOT .
'/variants/ajax/getCombinations.php", {
2891 id: jQuery(this).val()
2892 }, function (data) {
2893 jQuery(\'div#attributes_box\').empty();
2895 jQuery.each(data, function (key, val) {
2897 combvalues[val.id] = val.values;
2899 var span = jQuery(document.createElement(\'div\')).css({
2900 \'display\': \'table-row\'
2904 jQuery(document.createElement(\'div\')).text(val.label).css({
2905 \'font-weight\': \'bold\',
2906 \'display\': \'table-cell\'
2910 var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({
2911 \'margin-left\': \'15px\',
2912 \'white-space\': \'pre\'
2914 jQuery(document.createElement(\'option\')).val(\'\')
2917 jQuery.each(combvalues[val.id], function (key, val) {
2918 var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value);
2920 if (selected[val.fk_product_attribute] == val.id) {
2921 tag.attr(\'selected\', \'selected\');
2928 jQuery(\'div#attributes_box\').append(span);
2933 ' . ($selected ?
'jQuery("'.$htmltag.
'#' . $htmlname .
'").change();' :
'') .
'
2939 if (empty($hidelabel)) {
2941 } elseif ($hidelabel > 1) {
2943 if ($hidelabel == 2) {
2944 $out .=
img_picto($langs->trans(
"Search"),
'search');
2948 $out .=
'<input type="text" class="minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . $placeholder .
' ' . (
getDolGlobalString(
'PRODUCT_SEARCH_AUTOFOCUS') ?
'autofocus' :
'') .
' spellcheck="false" />';
2949 if ($hidelabel == 3) {
2950 $out .=
img_picto($langs->trans(
"Search"),
'search');
2953 $out .=
ajax_autocompleter((
string) $selected, $htmlname, DOL_URL_ROOT .
'/product/ajax/products.php', $urloption,
getDolGlobalInt(
'PRODUIT_USE_SEARCH_TO_SELECT'),
getDolGlobalInt(
'PRODUCT_SEARCH_AUTO_SELECT_IF_ONLY_ONE', 1), $ajaxoptions);
2955 $out .= $this->
select_produits_list($selected, $htmlname, $filtertype, $limit, $price_level,
'', $status, $finished, 0, $socid, $showempty, $forcecombo, $morecss, $hidepriceinlabel, $warehouseStatus, $status_purchase, $warehouseId);
2957 if (
isModEnabled(
'variants') && is_array($selected_combinations)) {
2961 $htmltag =
'select';
2963 <!-- script to auto show attributes select tags if a variant was selected -->
2964 <script nonce="' .
getNonce() .
'">
2965 // auto show attributes fields
2966 selected = ' . json_encode($selected_combinations) .
';
2969 jQuery(document).ready(function () {
2971 jQuery("input[name=\'prod_entry_mode\']").change(function () {
2972 if (jQuery(this).val() == \'free\') {
2973 jQuery(\'div#attributes_box\').empty();
2977 jQuery("'.$htmltag.
'#' . $htmlname .
'").change(function () {
2979 if (!jQuery(this).val()) {
2980 jQuery(\'div#attributes_box\').empty();
2984 console.log("A change has started. We get variants fields to inject html select");
2986 jQuery.getJSON("' . DOL_URL_ROOT .
'/variants/ajax/getCombinations.php", {
2987 id: jQuery(this).val()
2988 }, function (data) {
2989 jQuery(\'div#attributes_box\').empty();
2991 jQuery.each(data, function (key, val) {
2993 combvalues[val.id] = val.values;
2995 var span = jQuery(document.createElement(\'div\')).css({
2996 \'display\': \'table-row\'
3000 jQuery(document.createElement(\'div\')).text(val.label).css({
3001 \'font-weight\': \'bold\',
3002 \'display\': \'table-cell\'
3006 var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({
3007 \'margin-left\': \'15px\',
3008 \'white-space\': \'pre\'
3010 jQuery(document.createElement(\'option\')).val(\'\')
3013 jQuery.each(combvalues[val.id], function (key, val) {
3014 var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value);
3016 if (selected[val.fk_product_attribute] == val.id) {
3017 tag.attr(\'selected\', \'selected\');
3024 jQuery(\'div#attributes_box\').append(span);
3029 ' . ($selected ?
'jQuery("'.$htmltag.
'#' . $htmlname .
'").change();' :
'') .
'
3036 if (empty($nooutput)) {
3060 public function select_bom($selected =
'', $htmlname =
'bom_id', $limit = 0, $status = 1, $type = 0, $showempty =
'1', $morecss =
'', $nooutput =
'', $forcecombo = 0, $TProducts = [])
3064 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3070 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3075 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
3077 $sql =
'SELECT b.rowid, b.ref, b.label as bomLabel, p.label as productLabel';
3078 $sql .=
' FROM ' . $this->db->prefix() .
'bom_bom as b';
3079 $sql .=
' INNER JOIN ' . $this->db->prefix() .
'product as p ON b.fk_product = p.rowid';
3080 $sql .=
' WHERE b.entity IN (' .
getEntity(
'bom') .
')';
3081 if (!empty($status)) {
3082 $sql .=
' AND status = ' . (int) $status;
3084 if (!empty($type)) {
3085 $sql .=
' AND bomtype = ' . (int) $type;
3087 if (!empty($TProducts)) {
3088 $sql .=
' AND fk_product IN (' . $this->db->sanitize(implode(
',', $TProducts)) .
')';
3090 if (!empty($limit)) {
3091 $sql .=
' LIMIT ' . (int) $limit;
3093 $resql = $this->db->query($sql);
3096 $out .=
'<option value="-1"';
3097 if (empty($selected)) {
3098 $out .=
' selected';
3100 $out .=
'> </option>';
3102 while ($obj = $this->db->fetch_object($resql)) {
3103 $out .=
'<option value="' . $obj->rowid .
'"';
3104 if ($obj->rowid == $selected) {
3107 $out .=
'>' . $obj->ref .
' - ' . $obj->productLabel .
' - ' . $obj->bomLabel .
'</option>';
3113 $out .=
'</select>';
3114 if (empty($nooutput)) {
3149 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, $warehouseId = 0)
3153 global $hookmanager;
3156 $outarray = array();
3160 $langs->load(
'other');
3163 $warehouseStatusArray = array();
3164 if (!empty($warehouseStatus)) {
3165 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/entrepot.class.php';
3166 if (preg_match(
'/warehouseclosed/', $warehouseStatus)) {
3169 if (preg_match(
'/warehouseopen/', $warehouseStatus)) {
3172 if (preg_match(
'/warehouseinternal/', $warehouseStatus)) {
3177 $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";
3178 if (count($warehouseStatusArray)) {
3179 $selectFieldsGrouped =
", SUM(" . $this->db->ifsql(
"e.statut IS NULL",
"0",
"ps.reel") .
") as stock";
3181 $selectFieldsGrouped =
", " . $this->db->ifsql(
"p.stock IS NULL",
'0',
"p.stock") .
" AS stock";
3187 $parameters = array();
3188 $reshook = $hookmanager->executeHooks(
'selectProductsListSelect', $parameters);
3189 if (empty($reshook)) {
3190 $sql .= $selectFields.$selectFieldsGrouped.$hookmanager->resPrint;
3192 $sql .= $hookmanager->resPrint;
3197 $sql .=
", (SELECT " . $this->db->prefix() .
"categorie_product.fk_categorie
3198 FROM " . $this->db->prefix() .
"categorie_product
3199 WHERE " . $this->db->prefix() .
"categorie_product.fk_product = p.rowid
3201 ) AS categorie_product_id";
3206 $sql .=
', pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,';
3207 $sql .=
' pcp.price_base_type as custprice_base_type, pcp.tva_tx as custtva_tx, pcp.default_vat_code as custdefault_vat_code, pcp.ref_customer as custref, pcp.discount_percent as custdiscount_percent';
3208 $selectFields .=
", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custdefault_vat_code, custref, custdiscount_percent";
3212 $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";
3213 $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';
3218 $sql .=
", pl.label as label_translated";
3219 $sql .=
", pl.description as description_translated";
3220 $selectFields .=
", label_translated";
3221 $selectFields .=
", description_translated";
3225 $sql .=
", (SELECT pp.rowid FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
3226 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
3227 $sql .=
" AND price_level = " . ((int) $price_level);
3229 $sql .=
" ORDER BY date_price";
3230 $sql .=
" DESC LIMIT 1) as price_rowid";
3231 $sql .=
", (SELECT pp.price_by_qty FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
3232 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
3233 $sql .=
" AND price_level = " . ((int) $price_level);
3235 $sql .=
" ORDER BY date_price";
3236 $sql .=
" DESC LIMIT 1) as price_by_qty";
3237 $selectFields .=
", price_rowid, price_by_qty";
3242 $sql .=
" FROM ".$this->db->prefix().
"product as p";
3245 $sql .=
" USE INDEX (" . $this->db->sanitize(
getDolGlobalString(
'MAIN_PRODUCT_FORCE_INDEX')) .
")";
3249 $parameters = array(
3252 $reshook = $hookmanager->executeHooks(
'selectProductsListFrom', $parameters);
3253 $sql .= $hookmanager->resPrint;
3255 if (count($warehouseStatusArray)) {
3258 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_stock as ps ON ps.fk_product = p.rowid";
3259 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entrepot as e ON ps.fk_entrepot = e.rowid AND e.entity IN (" .
getEntity(
'stock') .
")";
3260 $sql .=
' AND e.statut IN (' . $this->db->sanitize($this->db->escape(implode(
',', $warehouseStatusArray))) .
')';
3266 $sql .=
" LEFT JOIN (";
3267 $sql .=
" SELECT pcp1.*";
3268 $sql .=
" FROM " . $this->db->prefix() .
"product_customer_price AS pcp1";
3269 $sql .=
" LEFT JOIN (";
3270 $sql .=
" SELECT fk_soc, fk_product, MIN(date_begin) AS date_begin";
3271 $sql .=
" FROM " . $this->db->prefix() .
"product_customer_price";
3272 $sql .=
" WHERE fk_soc = " . ((int) $socid);
3273 $sql .=
" AND date_begin <= '" . $this->db->idate($now) .
"'";
3274 $sql .=
" AND (date_end IS NULL OR '" . $this->db->idate($now) .
"' <= date_end)";
3275 $sql .=
" GROUP BY fk_soc, fk_product";
3276 $sql .=
" ) AS pcp2 ON pcp1.fk_soc = pcp2.fk_soc AND pcp1.fk_product = pcp2.fk_product AND pcp1.date_begin = pcp2.date_begin";
3277 $sql .=
" WHERE pcp2.fk_soc IS NOT NULL";
3278 $sql .=
" ) AS pcp ON pcp.fk_soc = " . ((int) $socid) .
" AND pcp.fk_product = p.rowid";
3282 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units as u ON u.rowid = p.fk_unit";
3286 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_lang as pl ON pl.fk_product = p.rowid";
3288 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
3289 $soc =
new Societe($this->db);
3290 $result = $soc->fetch($socid);
3291 if ($result > 0 && !empty($soc->default_lang)) {
3292 $sql .=
" AND pl.lang = '" . $this->db->escape($soc->default_lang) .
"'";
3294 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3297 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3302 $sql .=
' WHERE p.entity IN (' .
getEntity(
'product') .
')';
3305 if (strlen($filterkey) != 13) {
3306 $sql .=
" AND NOT EXISTS (SELECT pac.rowid FROM ".$this->db->prefix().
"product_attribute_combination as pac WHERE pac.fk_product_child = p.rowid)";
3309 $sql .=
" AND NOT EXISTS (SELECT pac.rowid FROM ".$this->db->prefix().
"product_attribute_combination as pac WHERE pac.fk_product_child = p.rowid)";
3312 if ($finished == 0) {
3313 $sql .=
" AND p.finished = " . ((int) $finished);
3314 } elseif ($finished == 1) {
3315 $sql .=
" AND p.finished = ".((int) $finished);
3318 $sql .=
" AND p.tosell = ".((int) $status);
3320 if ($status_purchase >= 0) {
3321 $sql .=
" AND p.tobuy = " . ((int) $status_purchase);
3324 if (strval($filtertype) !=
'') {
3325 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
3327 $sql .=
" AND p.fk_product_type = 1";
3329 $sql .=
" AND p.fk_product_type = 0";
3332 if ((
int) $warehouseId > 0) {
3333 $sql .=
" AND EXISTS (SELECT psw.fk_product FROM " . $this->db->prefix() .
"product_stock as psw WHERE psw.reel > 0 AND psw.fk_entrepot = ".(int) $warehouseId.
" AND psw.fk_product = p.rowid)";
3337 $parameters = array(
3338 'filterkey' => &$filterkey,
3341 $reshook = $hookmanager->executeHooks(
'selectProductsListWhere', $parameters);
3342 $sql .= $hookmanager->resPrint;
3344 if ($filterkey !=
'') {
3345 $sqlSupplierSearch =
'';
3350 $search_crit = explode(
' ', $filterkey);
3352 if (count($search_crit) > 1) {
3355 foreach ($search_crit as $crit) {
3359 $sql .=
"(p.ref LIKE '" . $this->db->escape($prefix . $crit) .
"%' OR p.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3361 $sql .=
" OR pl.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3364 $sql .=
" OR pcp.ref_customer LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3367 $sql .=
" OR p.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3369 $sql .=
" OR pl.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3375 $sqlSupplierSearch .= !empty($sqlSupplierSearch) ?
' AND ' :
'';
3376 $sqlSupplierSearch .=
" pfp.ref_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3381 if (count($search_crit) > 1) {
3385 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3390 $sql .=
" OR EXISTS (SELECT pfp.fk_product FROM " . $this->db->prefix() .
"product_fournisseur_price as pfp WHERE p.rowid = pfp.fk_product";
3392 $sql .= $sqlSupplierSearch;
3398 if (count($warehouseStatusArray)) {
3399 $sql .=
" GROUP BY " . $selectFields;
3404 $sql .=
" ORDER BY categorie_product_id ".(getDolGlobalInt(
'PRODUCT_SORT_BY_CATEGORY') == 1 ?
"ASC" :
"DESC");
3406 $sql .= $this->db->order(
"p.ref");
3410 $sql .= $this->db->plimit($limit, 0);
3428 dol_syslog(get_class($this) .
"::select_produits_list search products", LOG_DEBUG);
3432 $result = $this->db->query($sql);
3435 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3436 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3437 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
3439 $num = $this->db->num_rows($result);
3444 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3448 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
3454 if ($showempty && !is_numeric($showempty)) {
3455 $textifempty = $langs->trans($showempty);
3457 $textifempty .= $langs->trans(
"All");
3460 if ($showempty && !is_numeric($showempty)) {
3461 $textifempty = $langs->trans($showempty);
3465 $out .=
'<option value="-1" selected>' . ($textifempty ? $textifempty :
' ') .
'</option>';
3469 while ($num && $i < $num) {
3472 $objp = $this->db->fetch_object($result);
3474 if ((
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1) {
3475 $sql =
"SELECT rowid, quantity, price, unitprice, remise_percent, remise, price_base_type";
3476 $sql .=
" FROM " . $this->db->prefix() .
"product_price_by_qty";
3477 $sql .=
" WHERE fk_product_price = " . ((int) $objp->price_rowid);
3478 $sql .=
" ORDER BY quantity ASC";
3480 dol_syslog(get_class($this) .
"::select_produits_list search prices by qty", LOG_DEBUG);
3481 $result2 = $this->db->query($sql);
3483 $nb_prices = $this->db->num_rows($result2);
3485 while ($nb_prices && $j < $nb_prices) {
3486 $objp2 = $this->db->fetch_object($result2);
3488 $objp->price_by_qty_rowid = $objp2->rowid;
3489 $objp->price_by_qty_price_base_type = $objp2->price_base_type;
3490 $objp->price_by_qty_quantity = $objp2->quantity;
3491 $objp->price_by_qty_unitprice = $objp2->unitprice;
3492 $objp->price_by_qty_remise_percent = $objp2->remise_percent;
3494 $objp->quantity = $objp2->quantity;
3495 $objp->price = $objp2->price;
3496 $objp->unitprice = $objp2->unitprice;
3497 $objp->remise_percent = $objp2->remise_percent;
3503 '@phan-var-force array{key:string,value:string,label:string,label2:string,desc:string,type:string,price_ht:string,price_ttc:string,price_ht_locale:string,price_ttc_locale:string,pricebasetype:string,tva_tx:string,default_vat_code:string,qty:string,discount:string,duration_value:string,duration_unit:string,pbq:string,labeltrans:string,desctrans:string,ref_customer:string} $optJson';
3510 array_push($outarray, $optJson);
3514 if (
isModEnabled(
'dynamicprices') && !empty($objp->fk_price_expression)) {
3515 $price_product =
new Product($this->db);
3516 $price_product->fetch($objp->rowid,
'',
'',
'1');
3518 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3520 $price_result = $priceparser->parseProduct($price_product);
3521 if ($price_result >= 0) {
3522 $objp->price = $price_result;
3523 $objp->unitprice = $price_result;
3525 $objp->price_ttc = (float)
price2num($objp->price) * (1 + ($objp->tva_tx / 100));
3526 $objp->price_ttc =
price2num($objp->price_ttc,
'MU');
3529 if (
getDolGlobalInt(
'PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES') && !empty($objp->custprice)) {
3537 array_push($outarray, $optJson);
3543 $out .=
'</select>';
3545 $this->db->free($result);
3547 if (empty($outputmode)) {
3574 protected function constructProductListOption(&$objp, &$opt, &$optJson, $price_level, $selected, $hidepriceinlabel = 0, $filterkey =
'', $novirtualstock = 0)
3576 global $langs, $conf, $user;
3577 global $hookmanager;
3583 $outlabel_translated =
'';
3585 $outdesc_translated =
'';
3591 $outpricebasetype =
'';
3593 $outdefault_vat_code =
'';
3599 $label = $objp->label;
3600 if (!empty($objp->label_translated)) {
3601 $label = $objp->label_translated;
3603 if (!empty($filterkey) && $filterkey !=
'') {
3604 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
3607 $outkey = $objp->rowid;
3608 $outref = $objp->ref;
3609 $outrefcust = empty($objp->custref) ?
'' : $objp->custref;
3610 $outlabel = $objp->label;
3611 $outdesc = $objp->description;
3613 $outlabel_translated = $objp->label_translated;
3614 $outdesc_translated = $objp->description_translated;
3616 $outbarcode = $objp->barcode;
3617 $outorigin = $objp->fk_country;
3618 $outpbq = empty($objp->price_by_qty_rowid) ?
'' : $objp->price_by_qty_rowid;
3620 $outtype = $objp->fk_product_type;
3625 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
3631 if (!empty($objp->unit_short)) {
3632 $outvalUnits .=
' - ' . $objp->unit_short;
3636 if (!empty($objp->weight) && $objp->weight_units !==
null) {
3638 $outvalUnits .=
' - ' . $unitToShow;
3640 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
3641 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
3642 $outvalUnits .=
' - ' . $unitToShow;
3644 if (!empty($objp->surface) && $objp->surface_units !==
null) {
3646 $outvalUnits .=
' - ' . $unitToShow;
3648 if (!empty($objp->volume) && $objp->volume_units !==
null) {
3650 $outvalUnits .=
' - ' . $unitToShow;
3653 if ($outdurationvalue && $outdurationunit) {
3655 'h' => $langs->trans(
'Hour'),
3656 'd' => $langs->trans(
'Day'),
3657 'w' => $langs->trans(
'Week'),
3658 'm' => $langs->trans(
'Month'),
3659 'y' => $langs->trans(
'Year')
3661 if (isset($da[$outdurationunit])) {
3662 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
3669 if ($user->hasRight(
'stock',
'lire')) {
3670 if ($objp->stock > 0) {
3672 } elseif ($objp->stock <= 0) {
3680 $labeltoshow .= $objp->ref;
3681 if (!empty($objp->custref)) {
3682 $labeltoshow .=
' (' . $objp->custref .
')';
3685 $labeltoshow .=
' (' . $outbarcode .
')';
3687 $labeltoshow .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3689 $labeltoshow .=
' (' .
getCountry($outorigin,
'1') .
')';
3693 $labeltoshowhtml =
'';
3694 $labeltoshowhtml .= $objp->ref;
3695 if (!empty($objp->custref)) {
3696 $labeltoshowhtml .=
' (' . $objp->custref .
')';
3698 if (!empty($filterkey) && $filterkey !=
'') {
3699 $labeltoshowhtml = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $labeltoshowhtml, 1);
3702 $labeltoshowhtml .=
' (' . $outbarcode .
')';
3704 $labeltoshowhtml .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3706 $labeltoshowhtml .=
' (' .
getCountry($outorigin,
'1') .
')';
3710 $labeltoshowstock =
'';
3711 $labeltoshowhtmlstock =
'';
3713 if ($user->hasRight(
'stock',
'lire')) {
3714 $labeltoshowstock .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
3716 if ($objp->stock > 0) {
3717 $labeltoshowhtmlstock .=
' - <span class="product_line_stock_ok">';
3718 } elseif ($objp->stock <= 0) {
3719 $labeltoshowhtmlstock .=
' - <span class="product_line_stock_too_low">';
3721 $labeltoshowhtmlstock .= $langs->transnoentities(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
3722 $labeltoshowhtmlstock .=
'</span>';
3724 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
3725 $langs->load(
"stocks");
3727 $tmpproduct =
new Product($this->db);
3728 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
3729 $tmpproduct->load_virtual_stock();
3730 $virtualstock = $tmpproduct->stock_theorique;
3732 $labeltoshowstock .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
3734 $labeltoshowhtmlstock .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
3735 if ($virtualstock > 0) {
3736 $labeltoshowhtmlstock .=
'<span class="product_line_stock_ok">';
3737 } elseif ($virtualstock <= 0) {
3738 $labeltoshowhtmlstock .=
'<span class="product_line_stock_too_low">';
3740 $labeltoshowhtmlstock .= $virtualstock;
3741 $labeltoshowhtmlstock .=
'</span>';
3750 $labeltoshowprice =
'';
3751 $labeltoshowhtmlprice =
'';
3754 $sql =
"SELECT price, price_ttc, price_base_type, tva_tx, default_vat_code";
3755 $sql .=
" FROM " . $this->db->prefix() .
"product_price";
3756 $sql .=
" WHERE fk_product = " . ((int) $objp->rowid);
3757 $sql .=
" AND entity IN (" .
getEntity(
'productprice') .
")";
3758 $sql .=
" AND price_level = " . ((int) $price_level);
3759 $sql .=
" ORDER BY date_price DESC, rowid DESC";
3762 dol_syslog(get_class($this) .
'::constructProductListOption search price for product ' . $objp->rowid .
' AND level ' . $price_level, LOG_DEBUG);
3763 $result2 = $this->db->query($sql);
3765 $objp2 = $this->db->fetch_object($result2);
3768 if ($objp2->price_base_type ==
'HT') {
3769 $labeltoshowprice .=
' - ' .
price($objp2->price, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"HT");
3770 $labeltoshowhtmlprice .=
' - ' .
price($objp2->price, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"HT");
3772 $labeltoshowprice .=
' - ' .
price($objp2->price_ttc, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"TTC");
3773 $labeltoshowhtmlprice .=
' - ' .
price($objp2->price_ttc, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3775 $outprice_ht =
price($objp2->price);
3776 $outprice_ttc =
price($objp2->price_ttc);
3777 $outpricebasetype = $objp2->price_base_type;
3779 $outtva_tx = $objp2->tva_tx;
3780 $outdefault_vat_code = $objp2->default_vat_code;
3782 $outtva_tx = $objp->tva_tx;
3783 $outdefault_vat_code = $objp->default_vat_code;
3792 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1 && (
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
3794 $outqty = $objp->quantity;
3795 $outdiscount = $objp->remise_percent;
3796 if ($objp->quantity == 1) {
3797 $labeltoshowprice .=
' - ' .
price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency) .
"/";
3798 $labeltoshowhtmlprice .=
' - ' .
price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency) .
"/";
3799 $labeltoshowprice .= $langs->trans(
"Unit");
3800 $labeltoshowhtmlprice .= $langs->transnoentities(
"Unit");
3802 $labeltoshowprice .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1, $conf->currency) .
"/" . $objp->quantity;
3803 $labeltoshowhtmlprice .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1, $conf->currency) .
"/" . $objp->quantity;
3804 $labeltoshowprice .= $langs->trans(
"Units");
3805 $labeltoshowhtmlprice .= $langs->transnoentities(
"Units");
3808 $outprice_ht =
price($objp->unitprice);
3809 $outprice_ttc =
price($objp->unitprice * (1 + ($objp->tva_tx / 100)));
3810 $outpricebasetype = $objp->price_base_type;
3811 $outtva_tx = $objp->tva_tx;
3812 $outdefault_vat_code = $objp->default_vat_code;
3814 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1) {
3815 $labeltoshowprice .=
" (" .
price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency) .
"/" . $langs->trans(
"Unit") .
")";
3816 $labeltoshowhtmlprice .=
" (" .
price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency) .
"/" . $langs->transnoentities(
"Unit") .
")";
3818 if (empty($hidepriceinlabel) && !empty($objp->remise_percent) && $objp->remise_percent >= 1) {
3819 $labeltoshowprice .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3820 $labeltoshowhtmlprice .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3825 if (!empty($objp->idprodcustprice)) {
3828 if ($objp->custprice_base_type ==
'HT') {
3829 $labeltoshowprice .=
' - ' .
price($objp->custprice, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"HT");
3830 $labeltoshowhtmlprice .=
' - ' .
price($objp->custprice, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"HT");
3832 $labeltoshowprice .=
' - ' .
price($objp->custprice_ttc, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"TTC");
3833 $labeltoshowhtmlprice .=
' - ' .
price($objp->custprice_ttc, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3836 $outprice_ht =
price($objp->custprice);
3837 $outprice_ttc =
price($objp->custprice_ttc);
3838 $outpricebasetype = $objp->custprice_base_type;
3839 $outtva_tx = $objp->custtva_tx;
3840 $outdefault_vat_code = $objp->custdefault_vat_code;
3841 $outdiscount = $objp->custdiscount_percent;
3846 if (empty($hidepriceinlabel) && !$found) {
3847 if ($objp->price_base_type ==
'HT') {
3848 $labeltoshowprice .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"HT");
3849 $labeltoshowhtmlprice .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"HT");
3851 $labeltoshowprice .=
' - ' .
price($objp->price_ttc, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"TTC");
3852 $labeltoshowhtmlprice .=
' - ' .
price($objp->price_ttc, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3854 $outprice_ht =
price($objp->price);
3855 $outprice_ttc =
price($objp->price_ttc);
3856 $outpricebasetype = $objp->price_base_type;
3857 $outtva_tx = $objp->tva_tx;
3858 $outdefault_vat_code = $objp->default_vat_code;
3862 $opt =
'<option value="' . $objp->rowid .
'"';
3863 $opt .= ($objp->rowid == $selected) ?
' selected' :
'';
3864 if (!empty($objp->price_by_qty_rowid) && $objp->price_by_qty_rowid > 0) {
3865 $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 .
'"';
3868 $opt .=
' data-labeltrans="' . $outlabel_translated .
'"';
3872 if ($stocktag == 1) {
3873 $opt .=
' class="product_line_stock_ok" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml, 0, array(
'strong')).dolPrintHTMLForAttribute($outvalUnits).$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
3876 if ($stocktag == -1) {
3877 $opt .=
' class="product_line_stock_too_low" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml, 0, array(
'strong')).dolPrintHTMLForAttribute($outvalUnits).$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
3884 $opt .= $labeltoshow;
3885 $outval .= $labeltoshowhtml;
3888 $opt .= $outvalUnits;
3889 $outval .= $outvalUnits;
3892 $opt .= $labeltoshowprice;
3893 $outval .= $labeltoshowhtmlprice;
3896 $opt .= $labeltoshowstock;
3897 $outval .= $labeltoshowhtmlstock;
3900 $parameters = array(
'objp' => $objp);
3901 $reshook = $hookmanager->executeHooks(
'constructProductListOption', $parameters);
3902 if (empty($reshook)) {
3903 $opt .= $hookmanager->resPrint;
3905 $opt = $hookmanager->resPrint;
3908 $opt .=
"</option>\n";
3913 'label2' => $outlabel,
3917 'price_ttc' =>
price2num($outprice_ttc),
3920 'pricebasetype' => $outpricebasetype,
3921 'tva_tx' => $outtva_tx,
3922 'default_vat_code' => $outdefault_vat_code,
3924 'discount' => $outdiscount,
3925 'duration_value' => $outdurationvalue,
3926 'duration_unit' => $outdurationunit,
3928 'labeltrans' => $outlabel_translated,
3929 'desctrans' => $outdesc_translated,
3930 'ref_customer' => $outrefcust
3952 public function select_produits_fournisseurs($socid, $selected =
'', $htmlname =
'productid', $filtertype =
'', $filtre =
'', $ajaxoptions = array(), $hidelabel = 0, $alsoproductwithnosupplierprice = 0, $morecss =
'', $placeholder =
'', $nooutput = 0)
3955 global $langs, $conf;
3956 global $price_level, $status, $finished;
3958 if (!isset($status)) {
3962 $selected_input_value =
'';
3963 if (!empty($conf->use_javascript_ajax) &&
getDolGlobalString(
'PRODUIT_USE_SEARCH_TO_SELECT')) {
3964 if ((
int) $selected > 0) {
3965 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3966 $producttmpselect =
new Product($this->db);
3967 $producttmpselect->fetch((
int) $selected);
3968 $selected_input_value = $producttmpselect->ref;
3969 unset($producttmpselect);
3973 $urloption = ($socid > 0 ?
'socid=' . $socid .
'&' :
'') .
'htmlname=' . $htmlname .
'&outjson=1&price_level=' . $price_level .
'&type=' . $filtertype .
'&mode=2&status=' . $status .
'&finished=' . $finished .
'&alsoproductwithnosupplierprice=' . $alsoproductwithnosupplierprice;
3975 $s =
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT .
'/product/ajax/products.php', $urloption,
getDolGlobalInt(
'PRODUIT_USE_SEARCH_TO_SELECT'), 0, $ajaxoptions);
3977 $s .= ($hidelabel ?
'' : $langs->trans(
"RefOrLabel") .
' : ') .
'<input type="text" class="'.$morecss.
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . ($placeholder ?
' placeholder="' . $placeholder .
'"' :
'') .
'>';
3979 $s = $this->
select_produits_fournisseurs_list($socid, $selected, $htmlname, $filtertype, $filtre,
'', $status, 0, 0, $alsoproductwithnosupplierprice, $morecss,
getDolGlobalInt(
'SUPPLIER_SHOW_STOCK_IN_PRODUCTS_COMBO'), $placeholder);
4009 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 =
'')
4012 global $langs, $conf, $user;
4013 global $hookmanager;
4016 $outarray = array();
4020 $langs->load(
'stocks');
4023 $langs->load(
'other');
4026 $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,";
4027 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice, pfp.barcode";
4028 $sql .=
", pfp.multicurrency_code, pfp.multicurrency_unitprice";
4029 $sql .=
", pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.default_vat_code, pfp.fk_soc, s.nom as name";
4030 $sql .=
", pfp.supplier_reputation";
4033 $sql .=
", pfp.desc_fourn as description";
4035 $sql .=
", p.description";
4039 $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";
4044 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListSelect', $parameters);
4045 $sql .= $hookmanager->resPrint;
4047 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
4051 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListFrom', $parameters);
4052 $sql .= $hookmanager->resPrint;
4054 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN (" .
getEntity(
'product') .
") )";
4056 $sql .=
" AND pfp.fk_soc = " . ((int) $socid);
4058 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
4061 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
4063 $sql .=
" WHERE p.entity IN (" .
getEntity(
'product') .
")";
4064 if ($statut != -1) {
4065 $sql .=
" AND p.tobuy = " . ((int) $statut);
4067 if (strval($filtertype) !=
'') {
4068 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
4070 if (!empty($filtre)) {
4071 $sql .=
" " . $filtre;
4074 $parameters = array();
4075 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListWhere', $parameters);
4076 $sql .= $hookmanager->resPrint;
4078 if ($filterkey !=
'') {
4082 $search_crit = explode(
' ', $filterkey);
4084 if (count($search_crit) > 1) {
4087 foreach ($search_crit as $crit) {
4091 $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) .
"%'";
4093 $sql .=
" OR pfp.desc_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
4098 if (count($search_crit) > 1) {
4102 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
4103 $sql .=
" OR pfp.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
4107 $sql .=
" ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC";
4108 $sql .= $this->db->plimit($limit, 0);
4112 dol_syslog(get_class($this) .
"::select_produits_fournisseurs_list", LOG_DEBUG);
4113 $result = $this->db->query($sql);
4115 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4116 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
4118 $num = $this->db->num_rows($result);
4121 $out .=
'<select class="flat ' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'">';
4123 $out .=
'<option value="-1" selected>' . ($placeholder ? $placeholder :
' ') .
'</option>';
4125 $out .=
'<option value="-1">' . ($placeholder ? $placeholder :
' ') .
'</option>';
4130 $objp = $this->db->fetch_object($result);
4132 if (is_null($objp->idprodfournprice)) {
4134 $objp->tva_tx = $objp->tva_tx_sale;
4135 $objp->default_vat_code = $objp->default_vat_code_sale;
4138 $outkey = $objp->idprodfournprice;
4139 if (!$outkey && $alsoproductwithnosupplierprice) {
4140 $outkey =
'idprod_' . $objp->rowid;
4143 $outref = $objp->ref;
4144 $outbarcode = $objp->barcode;
4147 $outtype = $objp->fk_product_type;
4154 if (!empty($objp->unit_short)) {
4155 $outvalUnits .=
' - ' . $objp->unit_short;
4157 if (!empty($objp->weight) && $objp->weight_units !==
null) {
4159 $outvalUnits .=
' - ' . $unitToShow;
4161 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
4162 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
4163 $outvalUnits .=
' - ' . $unitToShow;
4165 if (!empty($objp->surface) && $objp->surface_units !==
null) {
4167 $outvalUnits .=
' - ' . $unitToShow;
4169 if (!empty($objp->volume) && $objp->volume_units !==
null) {
4171 $outvalUnits .=
' - ' . $unitToShow;
4173 if ($outdurationvalue && $outdurationunit) {
4175 'h' => $langs->trans(
'Hour'),
4176 'd' => $langs->trans(
'Day'),
4177 'w' => $langs->trans(
'Week'),
4178 'm' => $langs->trans(
'Month'),
4179 'y' => $langs->trans(
'Year')
4181 if (isset($da[$outdurationunit])) {
4182 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
4187 $objRef = $objp->ref;
4188 if ($filterkey && $filterkey !=
'') {
4189 $objRef = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRef, 1);
4191 $objRefFourn = $objp->ref_fourn;
4192 if ($filterkey && $filterkey !=
'') {
4193 $objRefFourn = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRefFourn, 1);
4195 $label = $objp->label;
4196 if ($filterkey && $filterkey !=
'') {
4197 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
4200 switch ($objp->fk_product_type) {
4212 if (empty($picto)) {
4215 $optlabel =
img_object(
'', $picto,
'class="paddingright classfortooltip"', 0, 0, 1);
4218 $optlabel .= $objp->ref;
4219 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
4220 $optlabel .=
' <span class="opacitymedium">(' . $objp->ref_fourn .
')</span>';
4222 if (
isModEnabled(
'barcode') && !empty($objp->barcode)) {
4223 $optlabel .=
' (' . $outbarcode .
')';
4225 $optlabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
4227 $outvallabel = $objRef;
4228 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
4229 $outvallabel .=
' (' . $objRefFourn .
')';
4231 if (
isModEnabled(
'barcode') && !empty($objp->barcode)) {
4232 $outvallabel .=
' (' . $outbarcode .
')';
4234 $outvallabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
4237 $optlabel .= $outvalUnits;
4238 $outvallabel .= $outvalUnits;
4240 if (!empty($objp->idprodfournprice)) {
4241 $outqty = $objp->quantity;
4242 $outdiscount = $objp->remise_percent;
4243 if (
isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
4245 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
4246 $prod_supplier->id = $objp->fk_product;
4247 $prod_supplier->fourn_qty = $objp->quantity;
4248 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
4249 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
4251 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4253 $price_result = $priceparser->parseProductSupplier($prod_supplier);
4254 if ($price_result >= 0) {
4255 $objp->fprice = $price_result;
4256 if ($objp->quantity >= 1) {
4257 $objp->unitprice = $objp->fprice / $objp->quantity;
4261 if ($objp->quantity == 1) {
4262 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency) .
"/";
4263 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1, $conf->currency) .
"/";
4264 $optlabel .= $langs->trans(
"Unit");
4265 $outvallabel .= $langs->transnoentities(
"Unit");
4267 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency) .
"/" . $objp->quantity;
4268 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1, $conf->currency) .
"/" . $objp->quantity;
4269 $optlabel .=
' ' . $langs->trans(
"Units");
4270 $outvallabel .=
' ' . $langs->transnoentities(
"Units");
4273 if ($objp->quantity != 1) {
4274 $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") .
")";
4275 $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") .
")";
4277 if ($objp->remise_percent >= 1) {
4278 $optlabel .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4279 $outvallabel .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4281 if ($objp->duration) {
4282 $optlabel .=
" - " . $objp->duration;
4283 $outvallabel .=
" - " . $objp->duration;
4286 $optlabel .=
" - " .
dol_trunc($objp->name, 8);
4287 $outvallabel .=
" - " .
dol_trunc($objp->name, 8);
4289 if ($objp->supplier_reputation) {
4291 $reputations = array(
'' => $langs->trans(
'Standard'),
'FAVORITE' => $langs->trans(
'Favorite'),
'NOTTHGOOD' => $langs->trans(
'NotTheGoodQualitySupplier'),
'DONOTORDER' => $langs->trans(
'DoNotOrderThisProductToThisSupplier'));
4293 $optlabel .=
" - " . $reputations[$objp->supplier_reputation];
4294 $outvallabel .=
" - " . $reputations[$objp->supplier_reputation];
4297 $optlabel .=
" - <span class='opacitymedium'>" . $langs->trans(
"NoPriceDefinedForThisSupplier") .
'</span>';
4298 $outvallabel .=
' - ' . $langs->transnoentities(
"NoPriceDefinedForThisSupplier");
4302 $novirtualstock = ($showstockinlist == 2);
4304 if ($user->hasRight(
'stock',
'lire')) {
4305 $outvallabel .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
4307 if ($objp->stock > 0) {
4308 $optlabel .=
' - <span class="product_line_stock_ok">';
4309 } elseif ($objp->stock <= 0) {
4310 $optlabel .=
' - <span class="product_line_stock_too_low">';
4312 $optlabel .= $langs->transnoentities(
"Stock") .
':' .
price(
price2num($objp->stock,
'MS'));
4313 $optlabel .=
'</span>';
4314 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
4315 $langs->load(
"stocks");
4317 $tmpproduct =
new Product($this->db);
4318 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
4319 $tmpproduct->load_virtual_stock();
4320 $virtualstock = $tmpproduct->stock_theorique;
4322 $outvallabel .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
4324 $optlabel .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
4325 if ($virtualstock > 0) {
4326 $optlabel .=
'<span class="product_line_stock_ok">';
4327 } elseif ($virtualstock <= 0) {
4328 $optlabel .=
'<span class="product_line_stock_too_low">';
4330 $optlabel .= $virtualstock;
4331 $optlabel .=
'</span>';
4338 $optstart =
'<option value="' . $outkey .
'"';
4339 if ($selected && preg_match(
'/^idprod_/', (
string) $selected) && (
string) $selected ==
'idprod_'.$objp->rowid) {
4340 $optstart .=
' selected';
4341 } elseif ($selected && (
string) $selected == (
string) $objp->idprodfournprice) {
4342 $optstart .=
' selected';
4345 if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) {
4346 $optstart .=
' disabled';
4349 if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) {
4358 $optstart .=
' data-default-vat-code="' .
dol_escape_htmltag($objp->default_vat_code) .
'"';
4361 $optstart .=
' data-multicurrency-code="' .
dol_escape_htmltag($objp->multicurrency_code) .
'"';
4365 $optstart .=
' data-description="' .
dol_escape_htmltag($objp->description, 0, 1) .
'"';
4368 $outarrayentry = array(
4371 'label' => $outvallabel,
4372 'labelhtml' => $optlabel,
4374 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4375 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4376 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4377 'tva_tx_formated' =>
price($objp->tva_tx, 0, $langs, 1, -1, 2),
4379 'default_vat_code' => $objp->default_vat_code,
4380 'supplier_ref' => $objp->ref_fourn,
4381 'discount' => $outdiscount,
4383 'duration_value' => $outdurationvalue,
4384 'duration_unit' => $outdurationunit,
4385 'disabled' => empty($objp->idprodfournprice),
4386 'description' => $objp->description
4389 $outarrayentry[
'multicurrency_code'] = $objp->multicurrency_code;
4390 $outarrayentry[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4392 $parameters = array(
4394 'optstart' => &$optstart,
4395 'optlabel' => &$optlabel,
4396 'outvallabel' => &$outvallabel,
4397 'outarrayentry' => &$outarrayentry,
4400 $reshook = $hookmanager->executeHooks(
'selectProduitsFournisseurListOption', $parameters, $this);
4406 $out .= $optstart .
' data-html="' .
dol_escape_htmltag($optlabel) .
'">' . $optlabel .
"</option>\n";
4407 $outarraypush = array(
4410 'label' => $outvallabel,
4411 'labelhtml' => $optlabel,
4413 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4414 'price_qty_ht_locale' =>
price($objp->fprice),
4415 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4416 'price_unit_ht_locale' =>
price($objp->unitprice),
4417 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4418 'tva_tx_formated' =>
price($objp->tva_tx),
4420 'default_vat_code' => $objp->default_vat_code,
4421 'supplier_ref' => $objp->ref_fourn,
4422 'discount' => $outdiscount,
4424 'duration_value' => $outdurationvalue,
4425 'duration_unit' => $outdurationunit,
4426 'disabled' => empty($objp->idprodfournprice),
4427 'description' => $objp->description
4430 $outarraypush[
'multicurrency_code'] = $objp->multicurrency_code;
4431 $outarraypush[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4433 array_push($outarray, $outarraypush);
4446 $out .=
'</select>';
4448 $this->db->free($result);
4450 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
4456 if (empty($outputmode)) {
4475 global $langs, $conf;
4477 $langs->load(
'stocks');
4479 $sql =
"SELECT p.rowid, p.ref, p.label, p.price, p.duration, pfp.fk_soc,";
4480 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.remise_percent, pfp.quantity, pfp.unitprice,";
4481 $sql .=
" pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name";
4482 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
4483 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
4484 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
4485 $sql .=
" WHERE pfp.entity IN (" .
getEntity(
'productsupplierprice') .
")";
4486 $sql .=
" AND p.tobuy = 1";
4487 $sql .=
" AND s.fournisseur = 1";
4488 $sql .=
" AND p.rowid = " . ((int) $productid);
4490 $sql .=
" ORDER BY s.nom, pfp.ref_fourn DESC";
4492 $sql .=
" ORDER BY pfp.unitprice ASC";
4495 dol_syslog(get_class($this) .
"::select_product_fourn_price", LOG_DEBUG);
4496 $result = $this->db->query($sql);
4499 $num = $this->db->num_rows($result);
4501 $form =
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
4504 $form .=
'<option value="0">-- ' . $langs->trans(
"NoSupplierPriceDefinedForThisProduct") .
' --</option>';
4506 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4507 $form .=
'<option value="0"> </option>';
4511 $objp = $this->db->fetch_object($result);
4513 $opt =
'<option value="' . $objp->idprodfournprice .
'"';
4515 if ($num == 1 || ($selected_supplier > 0 && $objp->fk_soc == $selected_supplier) || ($i == 0 &&
getDolGlobalString(
'PRODUCT_BEST_SUPPLIER_PRICE_PRESELECTED'))) {
4516 $opt .=
' selected';
4518 $opt .=
'>' . $objp->name .
' - ' . $objp->ref_fourn .
' - ';
4520 if (
isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
4522 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
4523 $prod_supplier->id = $productid;
4524 $prod_supplier->fourn_qty = $objp->quantity;
4525 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
4526 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
4528 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4530 $price_result = $priceparser->parseProductSupplier($prod_supplier);
4531 if ($price_result >= 0) {
4532 $objp->fprice = $price_result;
4533 if ($objp->quantity >= 1) {
4534 $objp->unitprice = $objp->fprice / $objp->quantity;
4538 if ($objp->quantity == 1) {
4539 $opt .=
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency) .
"/";
4542 $opt .= $objp->quantity .
' ';
4544 if ($objp->quantity == 1) {
4545 $opt .= $langs->trans(
"Unit");
4547 $opt .= $langs->trans(
"Units");
4549 if ($objp->quantity > 1) {
4551 $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");
4553 if ($objp->duration) {
4554 $opt .=
" - " . $objp->duration;
4556 $opt .=
"</option>\n";
4563 $form .=
'</select>';
4564 $this->db->free($result);
4582 global $langs, $hookmanager;
4584 $num = count($this->cache_conditions_paiements);
4591 $this->cache_conditions_paiements = array();
4593 $sql =
"SELECT rowid, code, libelle as label, deposit_percent, entity";
4594 $sql .=
" FROM " . $this->db->prefix() .
'c_payment_term';
4595 $sql .=
" WHERE entity IN (" .
getEntity(
'c_payment_term') .
")";
4596 $sql .=
" AND active > 0";
4597 $sql .=
" ORDER BY sortorder";
4599 $resql = $this->db->query($sql);
4601 $num = $this->db->num_rows($resql);
4604 $obj = $this->db->fetch_object($resql);
4607 $label = ($langs->trans(
"PaymentConditionShort" . $obj->code) !=
"PaymentConditionShort" . $obj->code ? $langs->trans(
"PaymentConditionShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4608 $this->cache_conditions_paiements[$obj->rowid][
'code'] = (string) $obj->code;
4609 $this->cache_conditions_paiements[$obj->rowid][
'label'] = (string) $label;
4610 $this->cache_conditions_paiements[$obj->rowid][
'deposit_percent'] = (string) $obj->deposit_percent;
4611 $this->cache_conditions_paiements[$obj->rowid][
'entity'] = (int) $obj->entity;
4615 $parameters = array(
'context' =>
'paymentterm');
4616 $reshook = $hookmanager->executeHooks(
'loadDictionaryCache', $parameters, $this);
4617 if (empty($reshook)) {
4618 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
4619 $this->cache_conditions_paiements = array_merge($this->cache_conditions_paiements, $hookmanager->resArray);
4622 $this->cache_conditions_paiements = $hookmanager->resArray;
4646 $this->cache_rule_for_lines_dates = $factureRec->fields[
'rule_for_lines_dates'][
'arrayofkeyval'];
4648 if (empty($this->cache_rule_for_lines_dates)) {
4667 $num = count($this->cache_availability);
4674 $this->cache_availability = array();
4676 $langs->load(
'propal');
4678 $sql =
"SELECT rowid, code, label, position";
4679 $sql .=
" FROM " . $this->db->prefix() .
'c_availability';
4680 $sql .=
" WHERE active > 0";
4682 $resql = $this->db->query($sql);
4684 $num = $this->db->num_rows($resql);
4687 $obj = $this->db->fetch_object($resql);
4690 $label = ($langs->trans(
"AvailabilityType" . $obj->code) !=
"AvailabilityType" . $obj->code ? $langs->trans(
"AvailabilityType" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4691 $this->cache_availability[$obj->rowid][
'code'] = (string) $obj->code;
4692 $this->cache_availability[$obj->rowid][
'label'] = (string) $label;
4693 $this->cache_availability[$obj->rowid][
'position'] = (int) $obj->position;
4697 $this->cache_availability =
dol_sort_array($this->cache_availability,
'position',
'asc', 0, 0, 1);
4718 global $langs, $user;
4722 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
4724 print
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4726 print
'<option value="0"> </option>';
4728 foreach ($this->cache_availability as
$id => $arrayavailability) {
4729 if ($selected ==
$id) {
4730 print
'<option value="' .
$id .
'" selected>';
4732 print
'<option value="' .
$id .
'">';
4739 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4749 public function loadCacheInputReason()
4753 $num = count($this->cache_demand_reason);
4758 $sql =
"SELECT rowid, code, label";
4759 $sql .=
" FROM " . $this->db->prefix() .
'c_input_reason';
4760 $sql .=
" WHERE active > 0";
4762 $resql = $this->db->query($sql);
4764 $num = $this->db->num_rows($resql);
4767 $tmparray = array();
4769 $obj = $this->db->fetch_object($resql);
4772 $label = ($obj->label !=
'-' ? (string) $obj->label :
'');
4773 if ($langs->trans(
"DemandReasonType" . $obj->code) !=
"DemandReasonType" . $obj->code) {
4774 $label = $langs->trans(
"DemandReasonType" . $obj->code);
4776 if ($langs->trans($obj->code) != $obj->code) {
4777 $label = $langs->trans($obj->code);
4780 $tmparray[(int) $obj->rowid]
4782 'id' => (
int) $obj->rowid,
4783 'code' => (string) $obj->code,
4789 $this->cache_demand_reason =
dol_sort_array($tmparray,
'label',
'asc', 0, 0, 1);
4811 public function selectInputReason($selected =
'', $htmlname =
'demandreasonid', $exclude =
'', $addempty = 0, $morecss =
'', $notooltip = 0)
4813 global $langs, $user;
4815 $this->loadCacheInputReason();
4817 print
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
4819 print
'<option value="0"' . (empty($selected) ?
' selected' :
'') .
'> </option>';
4821 foreach ($this->cache_demand_reason as
$id => $arraydemandreason) {
4822 if ($arraydemandreason[
'code'] == $exclude) {
4826 if ($selected && ($selected == $arraydemandreason[
'id'] || $selected == $arraydemandreason[
'code'])) {
4827 print
'<option value="' . $arraydemandreason[
'id'] .
'" selected>';
4829 print
'<option value="' . $arraydemandreason[
'id'] .
'">';
4831 $label = $arraydemandreason[
'label'];
4832 print $langs->trans($label);
4836 if ($user->admin && empty($notooltip)) {
4837 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4852 global $langs, $hookmanager;
4854 $num = count($this->cache_types_paiements);
4861 $this->cache_types_paiements = array();
4863 $sql =
"SELECT id, code, libelle as label, type, entity, active";
4864 $sql .=
" FROM " . $this->db->prefix() .
"c_paiement";
4865 $sql .=
" WHERE entity IN (" .
getEntity(
'c_paiement') .
")";
4867 $resql = $this->db->query($sql);
4869 $num = $this->db->num_rows($resql);
4872 $obj = $this->db->fetch_object($resql);
4875 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) !=
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4876 $this->cache_types_paiements[$obj->id][
'id'] = (int) $obj->id;
4877 $this->cache_types_paiements[$obj->id][
'code'] = (string) $obj->code;
4878 $this->cache_types_paiements[$obj->id][
'label'] = (string) $label;
4879 $this->cache_types_paiements[$obj->id][
'type'] = (int) $obj->type;
4880 $this->cache_types_paiements[$obj->id][
'entity'] = (int) $obj->entity;
4881 $this->cache_types_paiements[$obj->id][
'active'] = (int) $obj->active;
4885 $parameters = array(
'context' =>
'paymenttype');
4886 $reshook = $hookmanager->executeHooks(
'loadDictionaryCache', $parameters, $this);
4887 if (empty($reshook)) {
4888 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
4889 $this->cache_types_paiements = array_merge($this->cache_types_paiements, $hookmanager->resArray);
4892 $this->cache_types_paiements = $hookmanager->resArray;
4895 $this->cache_types_paiements =
dol_sort_array($this->cache_types_paiements,
'label',
'asc', 0, 0, 1);
4925 public function select_conditions_paiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1, $noprint = 0)
4929 if (empty($noprint)) {
4953 public function getSelectConditionsPaiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1)
4955 global $langs, $user, $conf;
4958 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
4963 if (empty($selected) && strpos($htmlname,
'search_') !== 0 &&
getDolGlobalString(
'MAIN_DEFAULT_PAYMENT_TERM_ID')) {
4964 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TERM_ID", LOG_NOTICE);
4968 $out .=
'<select id="' . $htmlname .
'" class="flat selectpaymentterms' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4970 $out .=
'<option value="0"> </option>';
4973 $selectedDepositPercent =
null;
4975 foreach ($this->cache_conditions_paiements as
$id => $arrayconditions) {
4976 if ($filtertype <= 0 && !empty($arrayconditions[
'deposit_percent'])) {
4980 if ($selected ==
$id) {
4981 $selectedDepositPercent = $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'];
4982 $out .=
'<option value="' .
$id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'" selected>';
4984 $out .=
'<option value="' .
$id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'">';
4986 $label = $arrayconditions[
'label'];
4988 if (!empty($arrayconditions[
'deposit_percent'])) {
4989 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'], $label);
4993 $out .=
'</option>';
4995 $out .=
'</select>';
4996 if ($user->admin && empty($noinfoadmin)) {
4997 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5001 if ($deposit_percent >= 0) {
5002 $out .=
' <span id="' . $htmlname .
'_deposit_percent_container"' . (empty($selectedDepositPercent) ?
' style="display: none"' :
'') .
'>';
5003 $out .= $langs->trans(
'DepositPercent') .
' : ';
5004 $out .=
'<input id="' . $htmlname .
'_deposit_percent" name="' . $htmlname .
'_deposit_percent" class="maxwidth50" value="' . $deposit_percent .
'" />';
5007 <script nonce="' .
getNonce() .
'">
5008 $(document).ready(function () {
5009 $("#' . $htmlname .
'").change(function () {
5010 let $selected = $(this).find("option:selected");
5011 let depositPercent = $selected.attr("data-deposit_percent");
5013 if (depositPercent.length > 0) {
5014 $("#' . $htmlname .
'_deposit_percent_container").show().find("#' . $htmlname .
'_deposit_percent").val(depositPercent);
5016 $("#' . $htmlname .
'_deposit_percent_container").hide();
5045 $out .=
'<select id="' . $htmlname .
'" class="flat selectbillingterm" name="' . $htmlname .
'">';
5047 $out .=
'<option value="-1"> </option>';
5051 foreach ($this->cache_rule_for_lines_dates as $rule_for_lines_dates_key => $rule_for_lines_dates_name) {
5052 if ($selected == $rule_for_lines_dates_key) {
5053 $out .=
'<option value="' . $rule_for_lines_dates_key .
'" selected>';
5055 $out .=
'<option value="' . $rule_for_lines_dates_key .
'">';
5058 $out .= $langs->trans($rule_for_lines_dates_name);
5059 $out .=
'</option>';
5061 $out .=
'</select>';
5087 public function select_types_paiements($selected =
'', $htmlname =
'paiementtype', $filtertype =
'', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'', $nooutput = 0)
5090 global $langs, $user, $conf;
5094 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $filtertype .
", " . $format, LOG_DEBUG);
5096 $filterarray = array();
5097 if ($filtertype ==
'CRDT') {
5098 $filterarray = array(0, 2, 3);
5099 } elseif ($filtertype ==
'DBIT') {
5100 $filterarray = array(1, 2, 3);
5101 } elseif ($filtertype !=
'' && $filtertype !=
'-1') {
5102 $filterarray = explode(
',', $filtertype);
5108 if (empty($selected) && strpos($htmlname,
'search_') !== 0 &&
getDolGlobalString(
'MAIN_DEFAULT_PAYMENT_TYPE_ID')) {
5109 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TYPE_ID", LOG_NOTICE);
5113 $out .=
'<select id="select' . $htmlname .
'" class="flat selectpaymenttypes' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
5115 $out .=
'<option value=""> </option>';
5117 foreach ($this->cache_types_paiements as
$id => $arraytypes) {
5119 if ($active >= 0 && $arraytypes[
'active'] != $active) {
5124 if (count($filterarray) && !in_array($arraytypes[
'type'], $filterarray)) {
5129 if ($empty && empty($arraytypes[
'code'])) {
5134 $out .=
'<option value="' .
$id .
'" data-code="'.$arraytypes[
'code'].
'"';
5135 } elseif ($format == 1) {
5136 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
5137 } elseif ($format == 2) {
5138 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
5139 } elseif ($format == 3) {
5140 $out .=
'<option value="' .
$id .
'"';
5143 if ($format == 1 || $format == 2) {
5144 if ($selected == $arraytypes[
'code']) {
5145 $out .=
' selected';
5148 if ($selected ==
$id) {
5149 $out .=
' selected';
5155 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
5156 } elseif ($format == 1) {
5157 $value = $arraytypes[
'code'];
5158 } elseif ($format == 2) {
5159 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
5160 } elseif ($format == 3) {
5161 $value = $arraytypes[
'code'];
5163 $out .= $value ? $value :
' ';
5164 $out .=
'</option>';
5166 $out .=
'</select>';
5167 if ($user->admin && !$noadmininfo) {
5168 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5172 if (empty($nooutput)) {
5192 $return =
'<select class="flat maxwidth100" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
5194 'HT' => $langs->trans(
"HT"),
5195 'TTC' => $langs->trans(
"TTC")
5197 foreach ($options as
$id => $value) {
5198 if ($selected ==
$id) {
5199 $return .=
'<option value="' .
$id .
'" selected>' . $value;
5201 $return .=
'<option value="' .
$id .
'">' . $value;
5203 $return .=
'</option>';
5205 $return .=
'</select>';
5225 $num = count($this->cache_transport_mode);
5232 $this->cache_transport_mode = array();
5234 $sql =
"SELECT rowid, code, label, active";
5235 $sql .=
" FROM " . $this->db->prefix() .
"c_transport_mode";
5236 $sql .=
" WHERE entity IN (" .
getEntity(
'c_transport_mode') .
")";
5238 $resql = $this->db->query($sql);
5240 $num = $this->db->num_rows($resql);
5243 $obj = $this->db->fetch_object($resql);
5246 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) !=
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
5247 $this->cache_transport_mode[(int) $obj->rowid]
5249 'rowid' => (
int) $obj->rowid,
5250 'code' => (string) $obj->code,
5251 'label' => (
string) $label,
5252 'active' => (int) $obj->active,
5257 $this->cache_transport_mode =
dol_sort_array($this->cache_transport_mode,
'label',
'asc', 0, 0, 1);
5279 public function selectTransportMode($selected =
'', $htmlname =
'transportmode', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'')
5281 global $langs, $user;
5283 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $format, LOG_DEBUG);
5287 print
'<select id="select' . $htmlname .
'" class="flat selectmodetransport' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
5289 print
'<option value=""> </option>';
5291 foreach ($this->cache_transport_mode as
$id => $arraytypes) {
5293 if ($active >= 0 && $arraytypes[
'active'] != $active) {
5298 if ($empty && empty($arraytypes[
'code'])) {
5303 print
'<option value="' .
$id .
'"';
5304 } elseif ($format == 1) {
5305 print
'<option value="' . $arraytypes[
'code'] .
'"';
5306 } elseif ($format == 2) {
5307 print
'<option value="' . $arraytypes[
'code'] .
'"';
5308 } elseif ($format == 3) {
5309 print
'<option value="' .
$id .
'"';
5312 if (preg_match(
'/[a-z]/i', $selected) && $selected == $arraytypes[
'code']) {
5314 } elseif ($selected ==
$id) {
5320 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
5321 } elseif ($format == 1) {
5322 $value = $arraytypes[
'code'];
5323 } elseif ($format == 2) {
5324 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
5325 } elseif ($format == 3) {
5326 $value = $arraytypes[
'code'];
5328 print $value ? $value :
' ';
5335 if ($user->admin && !$noadmininfo) {
5336 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5352 public function selectShippingMethod($selected =
'', $htmlname =
'shipping_method_id', $filtre =
'', $useempty = 0, $moreattrib =
'', $noinfoadmin = 0, $morecss =
'')
5354 global $langs, $user;
5356 $langs->loadLangs(array(
"admin",
"sendings"));
5358 $sql =
"SELECT rowid, code, libelle as label";
5359 $sql .=
" FROM " . $this->db->prefix() .
"c_shipment_mode";
5360 $sql .=
" WHERE active > 0";
5362 $sql .=
" AND " . $filtre;
5364 $sql .=
" ORDER BY libelle ASC";
5366 dol_syslog(get_class($this) .
"::selectShippingMode", LOG_DEBUG);
5367 $result = $this->db->query($sql);
5369 $num = $this->db->num_rows($result);
5372 print
'<select id="select' . $htmlname .
'" class="flat selectshippingmethod' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5373 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5374 print
'<option value="-1"> </option>';
5377 $obj = $this->db->fetch_object($result);
5378 if ($selected == $obj->rowid) {
5379 print
'<option value="' . $obj->rowid .
'" selected>';
5381 print
'<option value="' . $obj->rowid .
'">';
5383 print ($langs->trans(
"SendingMethod" . strtoupper($obj->code)) !=
"SendingMethod" . strtoupper($obj->code)) ? $langs->trans(
"SendingMethod" . strtoupper($obj->code)) : $obj->label;
5388 if ($user->admin && empty($noinfoadmin)) {
5389 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5394 print $langs->trans(
"NoShippingMethodDefined");
5414 $langs->load(
"sendings");
5416 if ($htmlname !=
"none") {
5417 print
'<form method="POST" action="' . $page .
'">';
5418 print
'<input type="hidden" name="action" value="setshippingmethod">';
5419 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5421 print
'<input type="submit" class="button valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5425 $code = $langs->getLabelFromKey($this->db, $selected,
'c_shipment_mode',
'rowid',
'code');
5426 print $langs->trans(
"SendingMethod" . strtoupper($code));
5445 $langs->load(
'bills');
5449 $sql =
"SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc";
5450 $sql .=
' FROM ' . $this->db->prefix() .
'facture';
5451 $sql .=
' WHERE entity IN (' .
getEntity(
'invoice') .
')';
5452 $sql .=
' AND situation_counter >= 1';
5453 $sql .=
' AND fk_soc = ' . (int) $socid;
5454 $sql .=
' AND type <> 2';
5455 $sql .=
' ORDER by situation_cycle_ref, situation_counter desc';
5456 $resql = $this->db->query($sql);
5458 $nbSituationInvoiceForThirdparty = 0;
5460 if ($resql && $this->db->num_rows($resql) > 0) {
5463 while ($obj = $this->db->fetch_object($resql)) {
5465 if ($obj->situation_cycle_ref != $ref) {
5467 $ref = $obj->situation_cycle_ref;
5469 if ($obj->situation_final != 1) {
5471 if (substr($obj->ref, 1, 4) !=
'PROV') {
5472 $nbSituationInvoiceForThirdparty++;
5474 if ($selected == $obj->rowid) {
5475 $opt .=
'<option value="' . $obj->rowid .
'" selected>' . $obj->ref .
'</option>';
5477 $opt .=
'<option value="' . $obj->rowid .
'">' . $obj->ref .
'</option>';
5484 dol_syslog(
"Error sql=" . $sql .
", error=" . $this->error, LOG_ERR);
5487 if ($nbSituationInvoiceForThirdparty > 0) {
5488 $opt =
'<option class="minwidth100" value="" selected> </option>'.$opt;
5490 $opt =
'<option class="minwidth100" value="-1" selected>'.$langs->trans(
'NoSituations').
'</option>';
5505 public function selectUnits($selected =
'', $htmlname =
'units', $showempty = 0, $unit_type =
'')
5509 $langs->load(
'products');
5511 $return =
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'">';
5513 $sql =
"SELECT rowid, label, code FROM " . $this->db->prefix() .
"c_units";
5514 $sql .=
' WHERE active > 0';
5515 if (!empty($unit_type)) {
5516 $sql .=
" AND unit_type = '" . $this->db->escape($unit_type) .
"'";
5518 $sql .=
" ORDER BY sortorder";
5520 $resql = $this->db->query($sql);
5521 if ($resql && $this->db->num_rows($resql) > 0) {
5523 $return .=
'<option value="-1"></option>';
5526 while ($res = $this->db->fetch_object($resql)) {
5527 $unitLabel = $res->label;
5528 if (!empty($langs->tab_translate[
'unit' . $res->code])) {
5529 $unitLabel = $langs->trans(
'unit' . $res->code) != $res->label ? $langs->trans(
'unit' . $res->code) : $res->label;
5532 if ($selected == $res->rowid) {
5533 $return .=
'<option value="' . $res->rowid .
'" selected>' . $unitLabel .
'</option>';
5535 $return .=
'<option value="' . $res->rowid .
'">' . $unitLabel .
'</option>';
5538 $return .=
'</select>';
5562 public function select_comptes($selected =
'', $htmlname =
'accountid', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'', $showcurrency = 0, $morecss =
'', $nooutput = 0, $addentrynone = 0)
5569 $langs->loadLangs(array(
"admin",
"banks"));
5572 $sql =
"SELECT rowid, label, bank, clos as status, currency_code";
5573 $sql .=
" FROM " . $this->db->prefix() .
"bank_account";
5574 $sql .=
" WHERE entity IN (" .
getEntity(
'bank_account') .
")";
5576 $sql .=
" AND clos = " . (int) $status;
5579 $sql .=
" AND " . $filtre;
5581 $sql .=
" ORDER BY label";
5583 dol_syslog(get_class($this) .
"::select_comptes", LOG_DEBUG);
5584 $result = $this->db->query($sql);
5586 $num = $this->db->num_rows($result);
5589 $out .=
'<select id="select' . $htmlname .
'" class="flat selectbankaccount' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5593 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoActiveBankAccountDefined") .
'</span>';
5595 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoBankAccountDefined") .
'</span>';
5598 if (!empty($useempty) && !is_numeric($useempty)) {
5599 $out .=
'<option value="-1">'.$langs->trans($useempty).
'</option>';
5600 } elseif ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5601 $out .=
'<option value="-1"> </option>';
5606 $obj = $this->db->fetch_object($result);
5608 $labeltoshow = trim($obj->label);
5609 $labeltoshowhtml = trim($obj->label);
5610 if ($showcurrency) {
5611 $labeltoshow .=
' (' . $obj->currency_code .
')';
5612 $labeltoshowhtml .=
' <span class="opacitymedium">(' . $obj->currency_code .
')</span>';
5614 if ($status == 2 && $obj->status == 1) {
5615 $labeltoshow .=
' (' . $langs->trans(
"Closed") .
')';
5616 $labeltoshowhtml .=
' <span class="opacitymedium">(' . $langs->trans(
"Closed") .
')</span>';
5619 if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
5620 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml).
'" selected>';
5622 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml).
'">';
5624 $out .= $labeltoshow;
5625 $out .=
'</option>';
5629 if (!empty($addentrynone)) {
5630 $out .=
'<option value="-2"'.($selected == -2 ?
' selected="selected"':
'').
' data-html="'.
dolPrintHTMLForAttribute(
'<span class="opacitymedium">'.$langs->trans(
"None").
'</span>').
'">'.$langs->trans(
"None").
'</option>';
5633 $out .=
"</select>";
5640 if (empty($nooutput)) {
5662 public function selectRib($selected =
'', $htmlname =
'ribcompanyid', $filtre =
'', $useempty = 0, $moreattrib =
'', $showibanbic = 0, $morecss =
'', $nooutput = 0)
5669 $langs->loadLangs(array(
"admin",
"banks"));
5672 $sql =
"SELECT rowid, label, bank, status, iban_prefix, bic";
5673 $sql .=
" FROM " . $this->db->prefix() .
"societe_rib";
5674 $sql .=
" WHERE type = 'ban'";
5676 $sql .=
" AND " . $filtre;
5678 $sql .=
" ORDER BY label";
5679 dol_syslog(get_class($this) .
"::select_comptes", LOG_DEBUG);
5680 $result = $this->db->query($sql);
5682 $num = $this->db->num_rows($result);
5685 $out .=
'<select id="select' . $htmlname .
'" class="flat selectbankaccount' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5688 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoBankAccountDefined") .
'</span>';
5690 if (!empty($useempty) && !is_numeric($useempty)) {
5691 $out .=
'<option value="-1">'.$langs->trans($useempty).
'</option>';
5692 } elseif ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5693 $out .=
'<option value="-1"> </option>';
5698 $obj = $this->db->fetch_object($result);
5700 if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
5701 $out .=
'<option value="' . $obj->rowid .
'" data-iban-prefix="' . $iban .
' data-bic="' . $obj->bic .
'" selected>';
5703 $out .=
'<option value="' . $obj->rowid .
'" data-iban-prefix="' . $iban .
' data-bic="' . $obj->bic .
'">';
5705 $out .= trim($obj->label);
5707 $out .=
' (' . $iban .
'/' .$obj->bic.
')';
5709 $out .=
'</option>';
5712 $out .=
"</select>";
5719 if (empty($nooutput)) {
5739 public function selectEstablishments($selected =
'', $htmlname =
'entity', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'')
5743 $langs->load(
"admin");
5746 $sql =
"SELECT rowid, name, fk_country, status, entity";
5747 $sql .=
" FROM " . $this->db->prefix() .
"establishment";
5748 $sql .=
" WHERE 1=1";
5750 $sql .=
" AND status = " . (int) $status;
5753 $sql .=
" AND " . $filtre;
5755 $sql .=
" ORDER BY name";
5757 dol_syslog(get_class($this) .
"::select_establishment", LOG_DEBUG);
5758 $result = $this->db->query($sql);
5760 $num = $this->db->num_rows($result);
5763 print
'<select id="select' . $htmlname .
'" class="flat selectestablishment" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5764 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5765 print
'<option value="-1"> </option>';
5769 $obj = $this->db->fetch_object($result);
5770 if ($selected == $obj->rowid) {
5771 print
'<option value="' . $obj->rowid .
'" selected>';
5773 print
'<option value="' . $obj->rowid .
'">';
5775 print trim($obj->name);
5776 if ($status == 2 && $obj->status == 1) {
5777 print
' (' . $langs->trans(
"Closed") .
')';
5785 print
'<span class="opacitymedium">' . $langs->trans(
"NoActiveEstablishmentDefined") .
'</span>';
5787 print
'<span class="opacitymedium">' . $langs->trans(
"NoEstablishmentFound") .
'</span>';
5810 if ($htmlname !=
"none") {
5811 print
'<form method="POST" action="' . $page .
'">';
5812 print
'<input type="hidden" name="action" value="setbankaccount">';
5813 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5814 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
5815 $nbaccountfound = $this->
select_comptes($selected, $htmlname, 0,
'', $addempty);
5816 if ($nbaccountfound > 0) {
5817 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5821 $langs->load(
'banks');
5824 require_once DOL_DOCUMENT_ROOT .
'/compta/bank/class/account.class.php';
5825 $bankstatic =
new Account($this->db);
5826 $result = $bankstatic->fetch((
int) $selected);
5828 print $bankstatic->getNomUrl(1);
5847 public function formRib($page, $selected =
'', $htmlname =
'ribcompanyid', $filtre =
'', $addempty = 0, $showibanbic = 0)
5850 if ($htmlname !=
"none") {
5851 print
'<form method="POST" action="' . $page .
'">';
5852 print
'<input type="hidden" name="action" value="setbankaccountcustomer">';
5853 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5854 $nbaccountfound = $this->
selectRib($selected, $htmlname, $filtre, $addempty,
'', $showibanbic);
5855 if ($nbaccountfound > 0) {
5856 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5860 $langs->load(
'banks');
5863 require_once DOL_DOCUMENT_ROOT .
'/societe/class/companybankaccount.class.php';
5865 $result = $bankstatic->fetch((
int) $selected);
5867 print $bankstatic->label;
5869 print
' (' . $bankstatic->iban .
'/' .$bankstatic->bic.
')';
5895 $arrayselected = array();
5897 $arrayselected =
GETPOST($htmlname,
'array:int');
5900 $cats =
$c->containing(
$object->id, $categtype);
5901 $arrayselected = array();
5902 foreach ($cats as $cat) {
5903 $arrayselected[] = $cat->id;
5907 $out .=
img_picto(
'',
'category',
'class="pictofixedwidth"');
5908 $out .= $this->
multiselectarray($htmlname, $cate_arbo, $arrayselected, 0, 0,
'minwidth100 widthcentpercentminusxx', 0, 0);
5912 $jsonclose =
'doJsCodeAfterPopupClose'.$htmlname.
'()';
5913 $urltoopen =
'/categories/categorie_list.php?type='.urlencode($categtype).
'&nosearch=1';
5918 $out .=
'<!-- Add js code to open the popup for category/edit/add -->'.
"\n";
5919 $out .=
'<script>function doJsCodeAfterPopupClose'.$htmlname.
'() {
5920 console.log("doJsCodeAfterPopupClose'.$htmlname.
' has been called, we refresh the combo content + refresh select2...");
5922 // Call an ajax to reload values and update the select
5923 // $("#'.
dol_escape_js($htmlname).
'").append(new Option("Option 4", "4"));
5925 // Refresh select2 to take account of new values (enough for small change)
5928 url: \''.DOL_URL_ROOT.
'/core/ajax/fetchCategories.php\',
5930 action: \'getCategories\',
5935 success: function (data) {
5936 var $select = $(\'#'.dol_escape_js($htmlname).
'\');
5937 var selectedValues = $select.val();
5938 console.log(selectedValues);
5940 $.each(data,
function (index, item) {
5941 $select.append(\
'<option value="\' + item.id + \'" data-html="\' + item.htmlforattribute + \'">\' + item.htmlforoption + \'</option>\');
5943 $select.val(selectedValues);
5945 error: function (xhr, status, error) {
5946 console.log("Error when loading ajax page : " + error);
5951 // Alternative if change in select is complex
5983 public function select_all_categories($type, $selected =
'', $htmlname =
"parent", $maxlength = 64, $fromid = 0, $outputmode = 0, $include = 0, $morecss =
'', $useempty = 1)
5988 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
5992 if (is_numeric($type)) {
5993 $type = array_search($type, $cat->MAP_ID);
5996 $cate_arbo = $cat->get_full_arbo($type, $fromid, $include);
5998 $outarray = array();
5999 $outarrayrichhtml = array();
6002 $output =
'<select class="flat minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
6004 if (is_array($cate_arbo)) {
6005 $num = count($cate_arbo);
6008 $langs->load(
"categories");
6009 $output .=
'<option value="-1" disabled>' . $langs->trans(
"NoCategoriesDefined") .
'</option>';
6011 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
6012 $output .=
'<option value="-1"> </option>';
6014 foreach ($cate_arbo as $key => $value) {
6015 if ($cate_arbo[$key][
'id'] == $selected || ($selected ===
'auto' && count($cate_arbo) == 1)) {
6021 $labeltoshow =
img_picto(
'',
'category',
'class="pictofixedwidth"'.(empty($cate_arbo[$key][
'color']) ?
'' :
' style="color: #' . $cate_arbo[$key][
'color'] .
'"'));
6022 $labeltoshow .=
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle');
6024 $outarray[$cate_arbo[$key][
'id']] = $cate_arbo[$key][
'fulllabel'];
6026 $outarrayrichhtml[$cate_arbo[$key][
'id']] = $labeltoshow;
6028 $output .=
'<option ' . $add .
'value="' . $cate_arbo[$key][
'id'] .
'"';
6031 $output .=
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle');
6032 $output .=
'</option>';
6034 $cate_arbo[$key][
'data-html'] = $labeltoshow;
6038 $output .=
'</select>';
6043 if ($outputmode == 2) {
6046 } elseif ($outputmode == 1) {
6048 } elseif ($outputmode == 3) {
6049 return $outarrayrichhtml;
6074 public function form_confirm($page, $title, $question, $action, $formquestion = array(), $selectedchoice =
"", $useajax = 0, $height = 170, $width = 500)
6077 dol_syslog(__METHOD__ .
': using form_confirm is deprecated. Use formconfim instead.', LOG_WARNING);
6078 print $this->
formconfirm($page, $title, $question, $action, $formquestion, $selectedchoice, $useajax, $height, $width);
6107 public function formconfirm($page, $title, $question, $action, $formquestion =
'', $selectedchoice =
'', $useajax = 0, $height = 0, $width = 500, $disableformtag = 0, $labelbuttonyes =
'Yes', $labelbuttonno =
'No')
6109 global $langs, $conf;
6112 $formconfirm =
'<!-- formconfirm - before call, page=' .
dol_escape_htmltag($page) .
' -->';
6118 $newselectedchoice = empty($selectedchoice) ?
"no" : $selectedchoice;
6119 if ($conf->browser->layout ==
'phone') {
6124 if (empty($height)) {
6126 if (is_array($formquestion) && count($formquestion) > 2) {
6127 $height += ((count($formquestion) - 2) * 24) + 5;
6131 if (is_array($formquestion) && !empty($formquestion)) {
6133 foreach ($formquestion as $key => $input) {
6134 if (is_array($input) && !empty($input)) {
6135 if ($input[
'type'] ==
'hidden') {
6136 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
6137 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
6145 $moreonecolumn =
'';
6146 $more .=
'<div class="tagtable paddingtopbottomonly centpercent noborderspacing">' .
"\n";
6147 foreach ($formquestion as $key => $input) {
6148 if (is_array($input) && !empty($input)) {
6149 $size = (!empty($input[
'size']) ?
' size="' . $input[
'size'] .
'"' :
'');
6150 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
6151 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
6153 if ($input[
'type'] ==
'text' || $input[
'type'] ==
'input') {
6154 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">' . ($input[
'label'] ??
'') .
'</div><div class="tagtd"><input type="text" class="flat' . $morecss .
'" id="' .
dol_escape_htmltag($input[
'name']) .
'" name="' .
dol_escape_htmltag($input[
'name']) .
'"' . $size .
' value="' . (empty($input[
'value']) ?
'' : $input[
'value']) .
'"' . $moreattr .
' spellcheck="false" /></div></div>' .
"\n";
6155 } elseif ($input[
'type'] ==
'password') {
6156 $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";
6157 } elseif ($input[
'type'] ==
'textarea') {
6158 $moreonecolumn .=
'<div class="margintoponly">';
6159 $moreonecolumn .= $input[
'label'] .
'<br>';
6161 $moreonecolumn .= $input[
'value'];
6162 $moreonecolumn .=
'</textarea>';
6163 $moreonecolumn .=
'</div>';
6164 } elseif (in_array($input[
'type'], [
'select',
'multiselect'])) {
6165 if (empty($morecss)) {
6166 $morecss =
'minwidth100';
6169 $show_empty = isset($input[
'select_show_empty']) ? $input[
'select_show_empty'] : 1;
6170 $key_in_label = isset($input[
'select_key_in_label']) ? $input[
'select_key_in_label'] : 0;
6171 $value_as_key = isset($input[
'select_value_as_key']) ? $input[
'select_value_as_key'] : 0;
6172 $translate = isset($input[
'select_translate']) ? $input[
'select_translate'] : 0;
6173 $maxlen = isset($input[
'select_maxlen']) ? $input[
'select_maxlen'] : 0;
6174 $disabled = isset($input[
'select_disabled']) ? $input[
'select_disabled'] : 0;
6175 $sort = isset($input[
'select_sort']) ? $input[
'select_sort'] :
'';
6177 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">';
6178 if (!empty($input[
'label'])) {
6179 $more .= $input[
'label'] .
'</div><div class="tagtd left">';
6181 if ($input[
'type'] ==
'select') {
6182 $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);
6184 $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);
6186 $more .=
'</div></div>' .
"\n";
6187 } elseif ($input[
'type'] ==
'checkbox') {
6188 $more .=
'<div class="tagtr">';
6189 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'"><label for="' .
dol_escape_htmltag($input[
'name']) .
'">' . $input[
'label'] .
'</label></div><div class="tagtd">';
6190 $more .=
'<input type="checkbox" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' .
dol_escape_htmltag($input[
'name']) .
'" name="' .
dol_escape_htmltag($input[
'name']) .
'"' . $moreattr;
6191 if (isset($input[
'value']) && !is_bool($input[
'value']) && $input[
'value'] !=
'false' && $input[
'value'] !=
'0' && $input[
'value'] !=
'') {
6192 $more .=
' checked';
6194 if (isset($input[
'value']) && is_bool($input[
'value']) && $input[
'value']) {
6195 $more .=
' checked';
6197 if (isset($input[
'disabled'])) {
6198 $more .=
' disabled';
6200 $more .=
' /></div>';
6201 $more .=
'</div>' .
"\n";
6202 } elseif ($input[
'type'] ==
'radio') {
6204 foreach ($input[
'values'] as $selkey => $selval) {
6205 $more .=
'<div class="tagtr">';
6206 if (isset($input[
'label'])) {
6208 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
' tdtop' : (
' tdtop ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
6210 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' "' . $input[
'tdclass'])) .
'"> </div>';
6213 $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;
6214 if (!empty($input[
'disabled'])) {
6215 $more .=
' disabled';
6217 if (isset($input[
'default']) && $input[
'default'] === $selkey) {
6218 $more .=
' checked="checked"';
6221 $more .=
'<label for="' .
dol_escape_htmltag($input[
'name'] . $selkey) .
'" class="valignmiddle">' . $selval .
'</label>';
6222 $more .=
'</div></div>' .
"\n";
6225 } elseif ($input[
'type'] ==
'date' || $input[
'type'] ==
'datetime') {
6226 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
6227 $more .=
'<div class="tagtd">';
6228 $addnowlink = (empty($input[
'datenow']) ? 0 : 1);
6230 if ($input[
'type'] ==
'datetime') {
6231 $h = isset($input[
'hours']) ? $input[
'hours'] : 1;
6232 $m = isset($input[
'minutes']) ? $input[
'minutes'] : 1;
6234 $more .= $this->
selectDate(isset($input[
'value']) ? $input[
'value'] : -1, $input[
'name'], $h, $m, 0,
'', 1, $addnowlink);
6235 $more .=
'</div></div>'.
"\n";
6236 $formquestion[] = array(
'name' => $input[
'name'].
'day');
6237 $formquestion[] = array(
'name' => $input[
'name'].
'month');
6238 $formquestion[] = array(
'name' => $input[
'name'].
'year');
6239 $formquestion[] = array(
'name' => $input[
'name'].
'hour');
6240 $formquestion[] = array(
'name' => $input[
'name'].
'min');
6241 } elseif ($input[
'type'] ==
'other') {
6242 $more .=
'<div class="tagtr"><div class="tagtd'.(empty($input[
'tdclass']) ?
'' : (
' '.$input[
'tdclass'])).
'">';
6243 if (!empty($input[
'label'])) {
6244 $more .= $input[
'label'] .
'</div><div class="tagtd">';
6246 if (!empty($input[
'value'])) {
6247 $more .= $input[
'value'];
6249 $more .=
'</div></div>' .
"\n";
6250 } elseif ($input[
'type'] ==
'onecolumn') {
6251 $moreonecolumn .=
'<div class="margintoponly">';
6252 $moreonecolumn .= $input[
'value'];
6253 $moreonecolumn .=
'</div>' .
"\n";
6254 } elseif ($input[
'type'] ==
'hidden') {
6256 } elseif ($input[
'type'] ==
'separator') {
6259 $more .=
'Error type ' . $input[
'type'] .
' for the confirm box is not a supported type';
6263 $more .=
'</div>' .
"\n";
6264 $more .= $moreonecolumn;
6270 if (!empty($conf->dol_use_jmobile)) {
6273 if (empty($conf->use_javascript_ajax)) {
6279 $dialogconfirm =
'dialog-confirm';
6281 if (!is_numeric($useajax)) {
6285 $dialogconfirm .=
'-' . $button;
6287 $pageyes = $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=yes';
6288 $pageno = ($useajax == 2 ? $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=no' :
'');
6291 if (is_array($formquestion)) {
6292 foreach ($formquestion as $key => $input) {
6295 if (is_array($input) && isset($input[
'name'])) {
6296 if (strpos($input[
'name'],
',') > 0) {
6297 $inputok = array_merge($inputok, explode(
',', $input[
'name']));
6299 array_push($inputok, $input[
'name']);
6304 if (is_array($input) && isset($input[
'inputko']) && $input[
'inputko'] == 1 && isset($input[
'name'])) {
6305 array_push($inputko, $input[
'name']);
6311 $formconfirm .=
'<div id="' . $dialogconfirm .
'" title="' .
dol_escape_htmltag($title) .
'" style="display: none;">';
6312 if (is_array($formquestion) && array_key_exists(
'text', $formquestion) && !empty($formquestion[
'text'])) {
6313 $formconfirm .=
'<div class="confirmtext">' . $formquestion[
'text'] .
'</div>' .
"\n";
6315 if (!empty($more)) {
6316 $formconfirm .=
'<div class="confirmquestions">' . $more .
'</div>' .
"\n";
6318 $formconfirm .= ($question ?
'<div class="confirmmessage">' .
img_help(0,
'') .
' ' . $question .
'</div>' :
'');
6319 $formconfirm .=
'</div>' .
"\n";
6321 $formconfirm .=
"\n<!-- begin code of popup for formconfirm page=" . $page .
" -->\n";
6322 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
6323 $formconfirm .=
"/* Code for the jQuery('#dialogforpopup').dialog() */\n";
6324 $formconfirm .=
'jQuery(document).ready(function() {
6326 $( "#' . $dialogconfirm .
'" ).dialog({
6327 autoOpen: ' . ($autoOpen ?
"true" :
"false") .
',';
6328 if ($newselectedchoice ==
'no') {
6331 $(this).parent().find("button.ui-button:eq(2)").focus();
6336 if ($useajax == 1) {
6337 $jsforcursor =
'// The call to urljump can be slow, so we set the wait cursor' .
"\n";
6338 $jsforcursor .=
'jQuery("html,body,#id-container").addClass("cursorwait");' .
"\n";
6341 $postconfirmas =
'GET';
6348 closeOnEscape:
false,
6350 "' . dol_escape_js($langs->transnoentities($labelbuttonyes)) . '":
function() {
6351 var options =
"token=' . urlencode(newToken()) . '";
6352 var inputok =
' . json_encode($inputok) . ';
6353 var page = \
'' .
dol_escape_js(!empty($page) ? $page :
'') .
'\';
6354 var pageyes = \
'' .
dol_escape_js(!empty($pageyes) ? $pageyes :
'') .
'\';
6356 if (inputok.length > 0) {
6357 $.each(inputok,
function(i, inputname) {
6360 if ($(
"input[name=\'" + inputname +
"\']").attr(
"type") ==
"radio") {
6361 inputvalue = $(
"input[name=\'" + inputname +
"\']:checked").val();
6363 if ($(
"#" + inputname).attr(
"type") ==
"checkbox") { more =
":checked"; }
6364 inputvalue = $(
"#" + inputname + more).val();
6366 if (typeof inputvalue ==
"undefined") { inputvalue=
""; }
6367 console.log(
"formconfirm check inputname="+inputname+
" inputvalue="+inputvalue);
6368 options +=
"&" + inputname +
"=" + encodeURIComponent(inputvalue);
6371 var urljump = pageyes + (pageyes.indexOf(
"?") < 0 ?
"?" :
"&") + options;
6372 if (pageyes.length > 0) {
';
6373 if ($postconfirmas == 'GET
') {
6374 $formconfirm .= 'location.href = urljump;
';
6376 $formconfirm .= $jsforcursor;
6377 $formconfirm .= 'var post = $.post(
6380 function(data) { $(
"body").html(data); jQuery(
"html,body,#id-container").removeClass(
"cursorwait"); }
6384 console.log(
"after post ok");
6386 $(
this).dialog(
"close");
6388 "' . dol_escape_js($langs->transnoentities($labelbuttonno)) . '":
function() {
6389 var options =
"token=' . urlencode(newToken()) . '";
6390 var inputko =
' . json_encode($inputko) . ';
6391 var page =
"' . dol_escape_js(!empty($page) ? $page : '') . '";
6392 var pageno=
"' . dol_escape_js(!empty($pageno) ? $pageno : '') . '";
6393 if (inputko.length > 0) {
6394 $.each(inputko,
function(i, inputname) {
6396 if ($(
"#" + inputname).attr(
"type") ==
"checkbox") { more =
":checked"; }
6397 var inputvalue = $(
"#" + inputname + more).val();
6398 if (typeof inputvalue ==
"undefined") { inputvalue=
""; }
6399 options +=
"&" + inputname +
"=" + encodeURIComponent(inputvalue);
6402 var urljump=pageno + (pageno.indexOf(
"?") < 0 ?
"?" :
"&") + options;
6404 if (pageno.length > 0) {
';
6405 if ($postconfirmas == 'GET
') {
6406 $formconfirm .= 'location.href = urljump;
';
6408 $formconfirm .= $jsforcursor;
6409 $formconfirm .= 'var post = $.post(
6412 function(data) { $(
"body").html(data); jQuery(
"html,body,#id-container").removeClass(
"cursorwait"); }
6416 console.log(
"after post ko");
6418 $(
this).dialog(
"close");
6424 var
button =
"' . $button . '";
6426 $(
"#" +
button ).click(
function() {
6427 $(
"#' . $dialogconfirm . '").dialog(
"open");
6433 $formconfirm .= "<!-- end ajax formconfirm -->\n";
6435 $formconfirm .= "\n<!-- begin formconfirm page=" . dol_escape_htmltag($page) . " -->\n";
6437 if (empty($disableformtag)) {
6438 $formconfirm .= '<form method=
"POST" action=
"' . $page . '" class=
"notoptoleftnoright">
' . "\n";
6441 $formconfirm .= '<input
type=
"hidden" name=
"action" value=
"' . $action . '">
' . "\n";
6442 $formconfirm .= '<input
type=
"hidden" name=
"token" value=
"' . newToken() . '">
' . "\n";
6444 $formconfirm .= '<
table class=
"valid centpercent">
' . "\n";
6447 $formconfirm .= '<tr
class=
"validtitre"><td
class=
"validtitre" colspan=
"2">
';
6448 $formconfirm .= img_picto('', 'pictoconfirm
') . ' ' . $title;
6449 $formconfirm .= '</td></tr>
' . "\n";
6452 if (is_array($formquestion) && array_key_exists('text
', $formquestion) && !empty($formquestion['text
'])) {
6453 $formconfirm .= '<tr
class=
"valid"><td
class=
"valid" colspan=
"2">
' . $formquestion['text
'] . '</td></tr>
' . "\n";
6458 $formconfirm .= '<tr
class=
"valid"><td
class=
"valid" colspan=
"2">
' . "\n";
6459 $formconfirm .= $more;
6460 $formconfirm .= '</td></tr>
' . "\n";
6463 // Line with question
6464 $formconfirm .= '<tr
class=
"valid">
';
6465 $formconfirm .= '<td
class=
"valid">
' . $question . '</td>
';
6466 $formconfirm .= '<td
class=
"valid center">
';
6467 $formconfirm .= $this->selectyesno("confirm", $newselectedchoice, 0, false, 0, 0, 'marginleftonly marginrightonly
', $labelbuttonyes, $labelbuttonno);
6468 $formconfirm .= '<input
class=
"button valignmiddle confirmvalidatebutton small" type=
"submit" value=
"' . $langs->trans("Validate") . '">
';
6469 $formconfirm .= '</td>
';
6470 $formconfirm .= '</tr>
' . "\n";
6472 $formconfirm .= '</
table>
' . "\n";
6474 if (empty($disableformtag)) {
6475 $formconfirm .= "</form>\n";
6477 $formconfirm .= '<br>
';
6479 if (!empty($conf->use_javascript_ajax)) {
6480 $formconfirm .= '<!-- code to disable
button to avoid
double clic -->
';
6481 $formconfirm .= '<script nonce=
"' . getNonce() . '" type=
"text/javascript">
' . "\n";
6483 $(document).ready(
function () {
6484 $(
".confirmvalidatebutton").on(
"click",
function() {
6485 console.log(
"We click on button confirmvalidatebutton");
6486 $(
this).attr(
"disabled",
"disabled");
6487 setTimeout(\
'$(".confirmvalidatebutton").removeAttr("disabled")\', 3000);
6488 //console.log($(this).closest("form"));
6489 $(this).closest("form").submit();
6493 $formconfirm .=
'</script>' .
"\n";
6496 $formconfirm .=
"<!-- end formconfirm -->\n";
6499 return $formconfirm;
6520 public function form_project($page, $socid, $selected =
'', $htmlname =
'projectid', $discard_closed = 0, $maxlength = 20, $forcefocus = 0, $nooutput = 0, $textifnoproject =
'', $morecss =
'')
6525 require_once DOL_DOCUMENT_ROOT .
'/core/lib/project.lib.php';
6526 require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formprojet.class.php';
6532 $langs->load(
"project");
6533 if ($htmlname !=
"none") {
6534 $out .=
'<form method="post" action="' . $page .
'">';
6535 $out .=
'<input type="hidden" name="action" value="classin">';
6536 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6537 $out .= $formproject->select_projects($socid, $selected, $htmlname, $maxlength, 0, 1, $discard_closed, $forcefocus, 0, 0,
'', 1, 0, $morecss);
6538 $out .=
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6541 $out .=
'<span class="project_head_block">';
6542 if ($selected instanceof
Project) {
6543 $out .= $selected->getNomUrl(0,
'', 1);
6544 } elseif (is_numeric($selected)) {
6545 $projet =
new Project($this->db);
6546 $projet->fetch((
int) $selected);
6547 $out .= $projet->getNomUrl(0,
'', 1);
6549 $out .=
'<span class="opacitymedium">' . $textifnoproject .
'</span>';
6554 if (empty($nooutput)) {
6578 public function form_conditions_reglement($page, $selected =
'', $htmlname =
'cond_reglement_id', $addempty = 0, $type =
'', $filtertype = -1, $deposit_percent = -1, $nooutput = 0)
6585 if ($htmlname !=
"none") {
6586 $out .=
'<form method="POST" action="' . $page .
'">';
6587 $out .=
'<input type="hidden" name="action" value="setconditions">';
6588 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6590 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
6592 $out .= $this->getSelectConditionsPaiements((
int) $selected, $htmlname, $filtertype, $addempty, 0,
'', $deposit_percent);
6593 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6597 $this->load_cache_conditions_paiements();
6598 if (isset($this->cache_conditions_paiements[$selected])) {
6599 $label = $this->cache_conditions_paiements[$selected][
'label'];
6601 if (!empty($this->cache_conditions_paiements[$selected][
'deposit_percent'])) {
6602 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $this->cache_conditions_paiements[$selected][
'deposit_percent'], $label);
6607 $langs->load(
'errors');
6608 $out .= $langs->trans(
'ErrorNotInDictionaryPaymentConditions');
6615 if (empty($nooutput)) {
6641 if ($htmlname !=
'none') {
6642 $out .=
'<form method="POST" action="' . $page .
'">';
6643 $out .=
'<input type="hidden" name="action" value="setruleforlinesdates">';
6644 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6645 $out .= $this->getSelectRuleForLinesDates($selected, $htmlname, $addempty);
6646 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6649 if (isset($selected)) {
6650 $this->load_cache_rule_for_lines_dates();
6651 if (isset($this->cache_rule_for_lines_dates[$selected])) {
6652 $label = $this->cache_rule_for_lines_dates[$selected];
6653 $out .= $langs->trans($label);
6660 if (empty($nooutput)) {
6683 if ($htmlname !=
"none") {
6684 print
'<form method="post" action="' . $page .
'">';
6685 print
'<input type="hidden" name="action" value="setavailability">';
6686 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6687 $this->selectAvailabilityDelay($selected, $htmlname,
'', $addempty);
6688 print
'<input type="submit" name="modify" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6689 print
'<input type="submit" name="cancel" class="button smallpaddingimp" value="' . $langs->trans(
"Cancel") .
'">';
6693 $this->load_cache_availability();
6694 if (isset($this->cache_availability[$selected])) {
6695 print $this->cache_availability[$selected][
'label'];
6716 public function formInputReason($page, $selected =
'', $htmlname =
'demandreason', $addempty = 0, $morecss =
'')
6719 if ($htmlname !=
"none") {
6720 print
'<form method="post" action="' . $page .
'">';
6721 print
'<input type="hidden" name="action" value="setdemandreason">';
6722 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6723 $this->selectInputReason($selected, $htmlname,
'-1', $addempty, $morecss);
6724 print
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6728 $this->loadCacheInputReason();
6729 foreach ($this->cache_demand_reason as $key => $val) {
6730 if ($val[
'id'] == $selected) {
6731 print $val[
'label'];
6756 public function form_date($page, $selected, $htmlname, $displayhour = 0, $displaymin = 0, $nooutput = 0, $type =
'')
6763 if ($htmlname !=
"none") {
6764 $ret .=
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
6765 $ret .=
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
6766 $ret .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6768 $ret .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
6770 $ret .=
'<table class="nobordernopadding">';
6772 $ret .= $this->selectDate($selected, $htmlname, $displayhour, $displaymin, 1,
'form' . $htmlname, 1, 0);
6774 $ret .=
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
6775 $ret .=
'</tr></table></form>';
6784 if (empty($nooutput)) {
6803 public function form_users($page, $selected =
'', $htmlname =
'userid', $exclude = array(), $include = array())
6808 if ($htmlname !=
"none") {
6809 print
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
6810 print
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
6811 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6812 print $this->select_dolusers($selected, $htmlname, 1, $exclude, 0, $include);
6813 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6817 require_once DOL_DOCUMENT_ROOT .
'/user/class/user.class.php';
6818 $theuser =
new User($this->db);
6819 $theuser->fetch((
int) $selected);
6820 print $theuser->getNomUrl(1);
6843 public function form_modes_reglement($page, $selected =
'', $htmlname =
'mode_reglement_id', $filtertype =
'', $active = 1, $addempty = 0, $type =
'', $nooutput = 0)
6849 if ($htmlname !=
"none") {
6850 $out .=
'<form method="POST" action="' . $page .
'">';
6851 $out .=
'<input type="hidden" name="action" value="setmode">';
6852 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6854 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
6856 $out .= $this->select_types_paiements($selected, $htmlname, $filtertype, 0, $addempty, 0, 0, $active,
'', 1);
6857 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6861 $this->load_cache_types_paiements();
6862 $out .= isset($this->cache_types_paiements[$selected][
'label']) ? $this->cache_types_paiements[$selected][
'label'] :
'';
6889 if ($htmlname !=
"none") {
6890 print
'<form method="POST" action="' . $page .
'">';
6891 print
'<input type="hidden" name="action" value="settransportmode">';
6892 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6893 $this->selectTransportMode($selected, $htmlname, 0, $addempty, 0, 0, $active);
6894 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6898 $this->load_cache_transport_mode();
6899 print $this->cache_transport_mode[$selected][
'label'];
6920 if ($htmlname !=
"none") {
6921 print
'<form method="POST" action="' . $page .
'">';
6922 print
'<input type="hidden" name="action" value="setmulticurrencycode">';
6923 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6924 print $this->selectMultiCurrency($selected, $htmlname, 0);
6925 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6928 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
6929 print !empty($selected) ?
currency_name($selected, 1) :
' ';
6947 global $langs, $conf;
6949 if ($htmlname !=
"none") {
6950 print
'<form method="POST" action="' . $page .
'">';
6951 print
'<input type="hidden" name="action" value="setmulticurrencyrate">';
6952 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6953 print
'<input type="text" class="maxwidth75" name="' . $htmlname .
'" value="' . (!empty($rate) ?
price(
price2num($rate,
'CU')) : 1) .
'" spellcheck="false" /> ';
6954 print
'<select name="calculation_mode" id="calculation_mode">';
6955 print
'<option value="1">Change ' . $langs->trans(
"PriceUHT") .
' of lines</option>';
6956 print
'<option value="2">Change ' . $langs->trans(
"PriceUHTCurrency") .
' of lines</option>';
6959 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6962 if (!empty($rate)) {
6963 print
price($rate, 1, $langs, 0, 0);
6964 if ($currency && $rate != 1) {
6965 print
' <span class="opacitymedium">(' .
price($rate, 1, $langs, 0, 0) .
' ' . $currency .
' = 1 ' . $conf->currency .
')</span>';
6990 public function form_remise_dispo($page, $selected, $htmlname, $socid, $amount, $filter =
'', $maxvalue = 0, $more =
'', $hidelist = 0, $discount_type = 0)
6993 global $conf, $langs;
6995 if ($htmlname !=
"none") {
6996 print
'<form method="post" action="' . $page .
'" class="inline-block">';
6997 print
'<input type="hidden" name="action" value="setabsolutediscount">';
6998 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6999 print
'<div class="inline-block">';
7000 if (!empty($discount_type)) {
7002 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL") {
7003 $translationKey =
'HasAbsoluteDiscountFromSupplier';
7005 $translationKey =
'HasCreditNoteFromSupplier';
7008 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
7009 $translationKey =
'HasAbsoluteDiscountFromSupplier';
7011 $translationKey =
'HasCreditNoteFromSupplier';
7016 if (!$filter || $filter ==
"fk_facture_source IS NULL") {
7017 $translationKey =
'CompanyHasAbsoluteDiscount';
7019 $translationKey =
'CompanyHasCreditNote';
7022 if (!$filter || $filter ==
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
7023 $translationKey =
'CompanyHasAbsoluteDiscount';
7025 $translationKey =
'CompanyHasCreditNote';
7029 print $langs->trans($translationKey,
price($amount, 0, $langs, 0, 0, -1, $conf->currency));
7030 if (empty($hidelist)) {
7034 if (empty($hidelist)) {
7035 print
'<div class="inline-block" style="padding-right: 10px">';
7036 $newfilter =
'discount_type=' . intval($discount_type);
7037 if (!empty($discount_type)) {
7038 $newfilter .=
' AND fk_invoice_supplier IS NULL AND fk_invoice_supplier_line IS NULL';
7040 $newfilter .=
' AND fk_facture IS NULL AND fk_facture_line IS NULL';
7043 $newfilter .=
' AND (' . $filter .
')';
7046 $nbqualifiedlines = $this->select_remises((
string) $selected, $htmlname, $newfilter, $socid, $maxvalue);
7047 if ($nbqualifiedlines > 0) {
7048 print
' <input type="submit" class="button smallpaddingimp" value="' .
dol_escape_htmltag($langs->trans(
"UseLine")) .
'"';
7049 if (!empty($discount_type) && $filter && $filter !=
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
7050 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
7052 if (empty($discount_type) && $filter && $filter !=
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
7053 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
7061 print
'<div class="inline-block">';
7087 public function form_contacts($page, $societe, $selected =
'', $htmlname =
'contactid')
7092 if ($htmlname !=
"none") {
7093 print
'<form method="post" action="' . $page .
'">';
7094 print
'<input type="hidden" name="action" value="set_contact">';
7095 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7096 print
'<table class="nobordernopadding">';
7098 print $this->selectcontacts($societe->id, $selected, $htmlname);
7101 $addcontact = (
getDolGlobalString(
'SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans(
"AddContact") : $langs->trans(
"AddContactAddress"));
7102 print
'<a href="' . DOL_URL_ROOT .
'/contact/card.php?socid=' . $societe->id .
'&action=create&backtoreferer=1">' . $addcontact .
'</a>';
7105 print
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
7106 print
'</tr></table></form>';
7109 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
7110 $contact =
new Contact($this->db);
7111 $contact->fetch((
int) $selected);
7112 print $contact->getFullName($langs);
7137 public function form_thirdparty($page, $selected =
'', $htmlname =
'socid', $filter =
'', $showempty = 0, $showtype = 0, $forcecombo = 0, $events = array(), $nooutput = 0, $excludeids = array(), $textifnothirdparty =
'')
7143 if ($htmlname !=
"none") {
7144 $out .=
'<form method="post" action="' . $page .
'">';
7145 $out .=
'<input type="hidden" name="action" value="set_thirdparty">';
7146 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7147 $out .= $this->select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, 0,
'minwidth100',
'',
'', 1, array(),
false, $excludeids);
7148 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7152 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
7153 $soc =
new Societe($this->db);
7154 $soc->fetch((
int) $selected);
7155 $out .= $soc->getNomUrl(0,
'');
7157 $out .=
'<span class="opacitymedium">' . $textifnothirdparty .
'</span>';
7183 print $this->selectCurrency($selected, $htmlname);
7195 public function selectCurrency($selected =
'', $htmlname =
'currency_id', $mode = 0, $useempty =
'')
7197 global $langs, $user;
7199 $langs->loadCacheCurrencies(
'');
7203 if ($selected ==
'euro' || $selected ==
'euros') {
7207 $out .=
'<select class="flat maxwidth200onsmartphone minwidth300" name="' . $htmlname .
'" id="' . $htmlname .
'">';
7209 $out .=
'<option value="-1" selected></option>';
7211 foreach ($langs->cache_currencies as $code_iso => $currency) {
7212 $labeltoshow = $currency[
'label'];
7214 $labeltoshow .=
' <span class="opacitymedium">(' . $code_iso .
')</span>';
7215 } elseif ($mode == 2) {
7216 $labeltoshow .=
' <span class="opacitymedium">(' . $code_iso.
' - '.$langs->getCurrencySymbol($code_iso) .
')</span>';
7218 $labeltoshow .=
' <span class="opacitymedium">(' . $langs->getCurrencySymbol($code_iso) .
')</span>';
7221 if ($selected && $selected == $code_iso) {
7222 $out .=
'<option value="' . $code_iso .
'" selected data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
7224 $out .=
'<option value="' . $code_iso .
'" data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
7227 $out .=
'</option>';
7229 $out .=
'</select>';
7231 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
7235 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
7253 public function selectMultiCurrency($selected =
'', $htmlname =
'multicurrency_code', $useempty = 0, $filter =
'', $excludeConfCurrency =
false, $morecss =
'maxwidth200 widthcentpercentminusx')
7255 global $conf, $langs;
7257 $langs->loadCacheCurrencies(
'');
7259 $TCurrency = array();
7261 $sql =
"SELECT code FROM " . $this->db->prefix() .
"multicurrency";
7262 $sql .=
" WHERE entity IN ('" .
getEntity(
'multicurrency') .
"')";
7264 $sql .=
" AND " . $filter;
7266 $resql = $this->db->query($sql);
7268 while ($obj = $this->db->fetch_object($resql)) {
7269 $TCurrency[$obj->code] = $obj->code;
7274 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
7276 $out .=
'<option value=""> </option>';
7279 if (!in_array($conf->currency, $TCurrency) && !$excludeConfCurrency) {
7280 $TCurrency[$conf->currency] = $conf->currency;
7282 if (count($TCurrency) > 0) {
7283 foreach ($langs->cache_currencies as $code_iso => $currency) {
7284 if (isset($TCurrency[$code_iso])) {
7285 if (!empty($selected) && $selected == $code_iso) {
7286 $out .=
'<option value="' . $code_iso .
'" selected="selected">';
7288 $out .=
'<option value="' . $code_iso .
'">';
7291 $out .= $currency[
'label'];
7292 $out .=
' (' . $langs->getCurrencySymbol($code_iso) .
')';
7293 $out .=
'</option>';
7298 $out .=
'</select>';
7301 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
7318 global $langs, $user;
7320 $num = count($this->cache_vatrates);
7327 $sql =
"SELECT t.rowid, t.type_vat, t.code, t.taux, t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.recuperableonly";
7328 $sql .=
" FROM ".$this->db->prefix().
"c_tva as t, ".$this->db->prefix().
"c_country as c";
7329 $sql .=
" WHERE t.fk_pays = c.rowid";
7330 $sql .=
" AND t.active > 0";
7331 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
7332 $sql .=
" AND c.code IN (" . $this->db->sanitize($country_code, 1) .
")";
7333 $sql .=
" ORDER BY t.code ASC, t.taux ASC, t.recuperableonly ASC";
7335 $resql = $this->db->query($sql);
7337 $num = $this->db->num_rows($resql);
7339 for ($i = 0; $i < $num; $i++) {
7340 $obj = $this->db->fetch_object($resql);
7342 $tmparray = array();
7343 $tmparray[
'rowid'] = (int) $obj->rowid;
7344 $tmparray[
'type_vat'] = ($obj->type_vat <= 0 ? 0 : $obj->type_vat);
7345 $tmparray[
'code'] = $obj->code;
7346 $tmparray[
'txtva'] = $obj->taux;
7347 $tmparray[
'nprtva'] = $obj->recuperableonly;
7348 $tmparray[
'localtax1'] = $obj->localtax1;
7349 $tmparray[
'localtax1_type'] = $obj->localtax1_type;
7350 $tmparray[
'localtax2'] = $obj->localtax2;
7351 $tmparray[
'localtax2_type'] = $obj->localtax1_type;
7352 $tmparray[
'label'] = $obj->taux .
'%' . ($obj->code ?
' (' . $obj->code .
')' :
'');
7353 $tmparray[
'labelallrates'] = $obj->taux .
'/' . ($obj->localtax1 ? $obj->localtax1 :
'0') .
'/' . ($obj->localtax2 ? $obj->localtax2 :
'0') . ($obj->code ?
' (' . $obj->code .
')' :
'');
7354 $positiverates =
'';
7356 $positiverates .= ($positiverates ?
'/' :
'') . $obj->taux;
7358 if ($obj->localtax1) {
7359 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax1;
7361 if ($obj->localtax2) {
7362 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax2;
7364 if (empty($positiverates)) {
7365 $positiverates =
'0';
7367 $tmparray[
'labelpositiverates'] = $positiverates . ($obj->code ?
' (' . $obj->code .
')' :
'');
7369 $this->cache_vatrates[$obj->rowid] = $tmparray;
7374 $this->error =
'<span class="error">';
7375 $this->error .= $langs->trans(
"ErrorNoVATRateDefinedForSellerCountry", $country_code);
7377 if (!empty($user) && $user->admin && preg_match(
'/\'(..)\'/', $country_code, $reg)) {
7378 $langs->load(
"errors");
7379 $new_country_code = $reg[1];
7380 $country_id =
dol_getIdFromCode($this->db, $new_country_code,
'c_country',
'code',
'rowid');
7381 $this->error .=
'<br>'.$langs->trans(
"ErrorFixThisHere", DOL_URL_ROOT.
'/admin/dict.php?id=10'.($country_id > 0 ?
'&countryidforinsert='.$country_id :
''));
7383 $this->error .=
'</span>';
7387 $this->error =
'<span class="error">' . $this->db->error() .
'</span>';
7416 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)
7419 global $langs,
$mysoc, $hookmanager;
7421 $langs->load(
'errors');
7425 $hookmanager->initHooks(array(
'commonobject'));
7426 $info_bits == 1 ? $is_npr = 1 : $is_npr = 0;
7427 $parameters = array(
7428 'htmlname' => $htmlname,
7429 'selectedrate' => $selectedrate,
7430 'seller' => $societe_vendeuse,
7431 'buyer' => $societe_acheteuse,
7432 'idprod' => $idprod,
7433 'is_npr' => $is_npr,
7435 'options_only' => $options_only,
7437 'type_vat' => $type_vat
7439 $reshook = $hookmanager->executeHooks(
'load_tva', $parameters);
7441 return $hookmanager->resPrint;
7442 } elseif ($reshook === 0) {
7443 $return .= $hookmanager->resPrint;
7447 $defaultnpr = ($info_bits & 0x01);
7448 $defaultnpr = (preg_match(
'/\*/', $selectedrate) ? 1 : $defaultnpr);
7449 $defaulttx = str_replace(
'*',
'', $selectedrate);
7452 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
7453 $defaultcode = $reg[1];
7454 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
7459 if (is_object($societe_vendeuse) && !$societe_vendeuse->country_code) {
7460 if ($societe_vendeuse->id ==
$mysoc->id) {
7461 $return .=
'<span class="error">' . $langs->trans(
"ErrorYourCountryIsNotDefined") .
'</span>';
7463 $return .=
'<span class="error">' . $langs->trans(
"ErrorSupplierCountryIsNotDefined") .
'</span>';
7474 if (is_object($societe_vendeuse)) {
7475 $code_country =
"'" . $societe_vendeuse->country_code .
"'";
7477 $code_country =
"'" .
$mysoc->country_code .
"'";
7481 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
7485 if (is_object($societe_vendeuse) && is_object($societe_acheteuse) &&
isInEEC($societe_vendeuse) &&
isInEEC($societe_acheteuse) && !$societe_acheteuse->isACompany()) {
7487 if (is_numeric($type)) {
7489 switch ($selectVatComboMode) {
7491 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
7494 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
7498 } elseif (!$idprod) {
7499 switch ($selectVatComboMode) {
7501 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
7504 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
7508 $prodstatic =
new Product($this->db);
7509 $prodstatic->fetch($idprod);
7511 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
7518 $this->load_cache_vatrates($code_country);
7521 $arrayofvatrates = array();
7522 foreach ($this->cache_vatrates as $cachevalue) {
7523 if ($type_vat == 0 || empty($cachevalue[
'type_vat']) || $cachevalue[
'type_vat'] == $type_vat) {
7524 $arrayofvatrates[] = $cachevalue;
7528 $num = count($arrayofvatrates);
7531 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
7533 $tmpthirdparty =
new Societe($this->db);
7534 $tmpthirdparty->country_code =
$mysoc->country_code;
7536 $defaulttx =
get_default_tva(is_object($societe_vendeuse) ? $societe_vendeuse : $tmpthirdparty, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
7537 $defaultnpr =
get_default_npr(is_object($societe_vendeuse) ? $societe_vendeuse : $tmpthirdparty, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
7539 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
7540 $defaultcode = $reg[1];
7541 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
7543 if (empty($defaulttx)) {
7550 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
7553 $defaulttx = $arrayofvatrates[$num - 1][
'txtva'];
7560 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
7561 $defaultcode = $reg[1];
7562 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
7570 if (is_object($societe_vendeuse) && $societe_vendeuse->id ==
$mysoc->id && empty($societe_vendeuse->tva_assuj)) {
7580 if (!$options_only) {
7581 $return .=
'<select class="flat valignmiddle minwidth75imp maxwidth100 right" id="' . $htmlname .
'" name="' . $htmlname .
'"' . ($disabled ?
' disabled' :
'') . $title .
'>';
7584 $selectedfound =
false;
7585 foreach ($arrayofvatrates as $rate) {
7587 if ($disabled && $rate[
'txtva'] != 0) {
7592 $key = $rate[
'txtva'];
7593 $key .= $rate[
'nprtva'] ?
'*' :
'';
7594 if ($mode > 0 && $rate[
'code']) {
7595 $key .=
' (' . $rate[
'code'] .
')';
7598 $key = $rate[
'rowid'];
7601 $return .=
'<option value="' . $key .
'" data-vatid="'.$rate[
'rowid'].
'"';
7602 if (!$selectedfound) {
7604 if ($defaultcode == $rate[
'code']) {
7605 $return .=
' selected';
7606 $selectedfound =
true;
7608 } elseif ($rate[
'txtva'] == $defaulttx && $rate[
'nprtva'] == $defaultnpr) {
7609 $return .=
' selected';
7610 $selectedfound =
true;
7618 $return .= $rate[
'labelpositiverates'];
7621 $return .=
vatrate($rate[
'label']);
7625 $return .= (empty($rate[
'code']) && $rate[
'nprtva']) ?
' *' :
'';
7627 $return .=
'</option>';
7630 if (!$options_only) {
7631 $return .=
'</select>';
7635 $return .= $this->error;
7669 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 =
'')
7672 dol_syslog(__METHOD__ .
': using select_date is deprecated. Use selectDate instead.', LOG_WARNING);
7673 $retstring = $this->selectDate($set_time, $prefix, $h, $m, $empty, $form_name, $d, $addnowlink, $disabled, $fullday, $addplusone, $adddateof);
7674 if (!empty($nooutput)) {
7697 public function selectDateToDate($set_time =
'', $set_time_end =
'', $prefix =
're', $empty = 0, $forcenewline = 0)
7701 $ret = $this->selectDate($set_time, $prefix .
'_start', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"from"),
'tzuserrel');
7702 if ($forcenewline) {
7705 $ret .= $this->selectDate($set_time_end, $prefix .
'_end', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
7737 public function selectDate($set_time =
'', $prefix =
're', $h = 0, $m = 0, $empty = 0, $form_name =
"", $d = 1, $addnowlink = 0, $disabled = 0, $fullday =
'', $addplusone =
'', $adddateof =
'', $openinghours =
'', $stepminutes = 1, $labeladddateof =
'', $placeholder =
'', $gm =
'auto', $calendarpicto =
'')
7739 global $conf, $langs;
7741 if ($gm ===
'auto') {
7742 $gm = (empty($conf) ?
'tzserver' : $conf->tzuserinputkey);
7747 if ($prefix ==
'') {
7758 if ($stepminutes <= 0 || $stepminutes > 30) {
7769 $orig_set_time = $set_time;
7771 if ($set_time ===
'' && $emptydate == 0) {
7772 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
7773 if ($gm ==
'tzuser' || $gm ==
'tzuserrel') {
7785 if (!empty($set_time) && preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/', (
string) $set_time, $reg)) {
7787 $syear = (!empty($reg[1]) ? $reg[1] :
'');
7788 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
7789 $sday = (!empty($reg[3]) ? $reg[3] :
'');
7790 $shour = (!empty($reg[4]) ? $reg[4] :
'');
7791 $smin = (!empty($reg[5]) ? $reg[5] :
'');
7792 } elseif (strval($set_time) !=
'' && $set_time != -1) {
7797 if ($orig_set_time !=
'') {
7811 if ($h == 3 || $h == 4) {
7822 $usecalendar =
'combo';
7828 $usecalendar =
'html';
7833 if ($usecalendar !=
'combo') {
7835 $reduceformat = (!empty($conf->dol_optimize_smallscreen) ? 1 : 0);
7836 if ($reduceformat) {
7837 $format = str_replace(
'%Y',
'%y', $langs->transnoentitiesnoconv(
"FormatDateShortInput"));
7838 $formatjslong = $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput");
7839 $formatjs = str_replace(
'yyyy',
'yy', $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput"));
7840 $formatjquery = str_replace(
'yyyy',
'yy', $langs->trans(
"FormatDateShortJQueryInput"));
7842 $format = $langs->transnoentitiesnoconv(
"FormatDateShortInput");
7843 $formatjslong = $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput");
7844 $formatjs = $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput");
7845 $formatjquery = $langs->trans(
"FormatDateShortJQueryInput");
7849 $formatted_date =
'';
7850 if (strval($set_time) !=
'' && $set_time != -1) {
7855 if ($usecalendar ==
"eldy") {
7881 } elseif ($usecalendar ==
'jquery' || $usecalendar ==
'html') {
7882 if (!$disabled && $usecalendar !=
'html') {
7884 $minYear =
getDolGlobalInt(
'MIN_YEAR_SELECT_DATE', (idate(
'Y') - 100));
7885 $maxYear =
getDolGlobalInt(
'MAX_YEAR_SELECT_DATE', (idate(
'Y') + 100));
7887 $retstring .=
'<!-- datepicker usecalendar='.$usecalendar.
' --><script nonce="' .
getNonce() .
'" type="text/javascript">';
7888 $retstring .=
"$(function(){ $('#" . $prefix .
"').datepicker({
7891 todayHighlight: true,
7892 yearRange: '" . $minYear .
":" . $maxYear .
"',";
7893 if (!empty($conf->dol_use_jmobile)) {
7895 beforeShow: function (input, datePicker) {
7896 input.disabled = true;
7898 onClose: function (dateText, datePicker) {
7899 this.disabled = false;
7905 $buttonImage = $calendarpicto ?: DOL_URL_ROOT .
"/theme/" .
dol_escape_js($conf->theme) .
"/img/object_calendarday.png";
7907 showOn: 'button', /* both has problem with autocompletion */
7908 buttonImage: '" . $buttonImage .
"',
7909 buttonImageOnly: true";
7913 $retstring .=
"</script>";
7917 $retstring .=
'<div class="nowraponall inline-block divfordateinput">';
7918 $retstring .=
'<input id="'.$prefix.
'" name="'.$prefix.
'" type="'.($usecalendar ==
'html' ?
"date" :
"text").
'" class="maxwidthdate'.(
getDolUserString(
'MAIN_OPTIMIZEFORTEXTBROWSER') ?
' textbrowser' :
'').
' center" maxlength="11" value="'.$formatted_date.
'"';
7919 $retstring .= ($disabled ?
' disabled' :
'');
7920 $retstring .= ($placeholder ?
' placeholder="' .
dol_escape_htmltag($placeholder) .
'"' :
'');
7921 $retstring .=
' onChange="dpChangeDay(\'' .
dol_escape_js($prefix) .
'\',\
'' .
dol_escape_js($usecalendar ==
'html' ?
'yyyy-mm-dd' : $formatjslong) .
'\');
"'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
7922 $retstring .= ' autocomplete="off
">';
7926 $retstringbutton = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
">' . img_object($langs->trans("Disabled
"), 'calendarday', 'class="datecallink ui-datepicker-notrigger
"') . '</button>';
7927 $retstring .= $retstringbutton;
7930 $retstring .= '</div>';
7931 $retstring .= '<input type="hidden
" id="' . $prefix . 'day
" name="' . $prefix . 'day
" value="' . $sday . '">' . "\n
";
7932 $retstring .= '<input type="hidden
" id="' . $prefix . 'month
" name="' . $prefix . 'month
" value="' . $smonth . '">' . "\n
";
7933 $retstring .= '<input type="hidden
" id="' . $prefix . 'year
" name="' . $prefix . 'year
" value="' . $syear . '">' . "\n
";
7935 $retstring .= "Bad value of MAIN_POPUP_CALENDAR
";
7938 // Show date with combo selects
7940 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50imp
" id="' . $prefix . 'day
" name="' . $prefix . 'day
">';
7942 if ($emptydate || $set_time == -1) {
7943 $retstring .= '<option value="0
" selected> </option>';
7946 for ($day = 1; $day <= 31; $day++) {
7947 $retstring .= '<option value="' . $day . '"' . ($day == $sday ? ' selected' : '') . '>' . $day . '</option>';
7950 $retstring .= "</select>
";
7952 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'month
" name="' . $prefix . 'month
">';
7953 if ($emptydate || $set_time == -1) {
7954 $retstring .= '<option value="0
" selected> </option>';
7958 for ($month = 1; $month <= 12; $month++) {
7959 $retstring .= '<option value="' . $month . '"' . ($month == $smonth ? ' selected' : '') . '>';
7960 $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b
");
7961 $retstring .= "</option>
";
7963 $retstring .= "</select>
";
7966 if ($emptydate || $set_time == -1) {
7967 $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 . '">';
7969 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'year
" name="' . $prefix . 'year
">';
7971 $syear = (int) $syear;
7972 for ($year = $syear - 10; $year < (int) $syear + 10; $year++) {
7973 $retstring .= '<option value="' . $year . '"' . ($year == $syear ? ' selected' : '') . '>' . $year . '</option>';
7975 $retstring .= "</select>\n
";
7981 $retstring .= (($h == 2 || $h == 4) ? '<br>' : ' ');
7982 $retstring .= '<span class="nowraponall
">';
7988 if ($openinghours != '') {
7989 $openinghours = explode(',', $openinghours);
7990 $hourstart = $openinghours[0];
7991 $hourend = $openinghours[1];
7992 if ($hourend < $hourstart) {
7993 $hourend = $hourstart;
7998 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75
'; // Note maxwidth50 generates truncated number on some desktops even with same version of chrome that works on others
7999 $retstring .= ($fullday ? $fullday . 'hour
' : '') . '" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
">';
8001 $retstring .= '<option value="-1
"> </option>';
8003 for ($hour = $hourstart; $hour < $hourend; $hour++) {
8004 if (strlen($hour) < 2) {
8005 $hour = "0
" . $hour;
8007 $retstring .= '<option value="' . $hour . '"' . (($hour == $shour) ? ' selected' : '') . '>' . $hour;
8008 $retstring .= '</option>';
8010 $retstring .= '</select>';
8013 $retstring .= '<input type="hidden
" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
" value="' . $shour . '">' . "\n
";
8022 $retstring .= '<select ' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75
'; // Note maxwidth50 generates truncated number on some desktops even with same version of chrome that works on others
8023 $retstring .= ($fullday ? $fullday . 'min
' : '') . '" id="' . $prefix . 'min
" name="' . $prefix . 'min
">';
8025 $retstring .= '<option value="-1
"> </option>';
8027 for ($min = 0; $min < 60; $min += $stepminutes) {
8028 $min_str = sprintf("%02d
", $min);
8029 $retstring .= '<option value="' . $min_str . '"' . (($min_str == $smin) ? ' selected' : '') . '>' . $min_str . '</option>';
8031 $retstring .= '</select>';
8033 $retstring .= '<input type="hidden
" id="' . $prefix . 'min
" name="' . $prefix . 'min
" value="' . $smin . '">' . "\n
";
8036 $retstring .= '<input type="hidden
" name="' . $prefix . 'sec
" value="' . $ssec . '">';
8040 $retstring .= '</span>';
8044 if (!empty($conf->use_javascript_ajax) && $addnowlink && !$disabled) {
8045 // Script which will be inserted in the onClick of the "Now
" link
8046 $reset_scripts = "";
8047 if ($addnowlink == 2) { // local computer time
8048 // pad add leading 0 on numbers
8049 $reset_scripts .= "Number.prototype.pad =
function(size) {
8050 var s = String(
this);
8051 while (s.length < (size || 2)) {s =
'0' + s;}
8054 var d =
new Date();
";
8057 // Generate the date part, depending on the use or not of the javascript calendar
8058 if ($addnowlink == 1) { // server time expressed in user time setup
8059 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
8060 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
8061 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
8062 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
8063 } elseif ($addnowlink == 2) {
8064 /* Disabled because the output does not use the string format defined by FormatDateShort key to forge the value into #prefix.
8065 * This break application for foreign languages.
8066 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(d.toLocaleDateString(\''.str_replace('_', '-', $langs->defaultlang).'\'));';
8067 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(d.getDate().pad());';
8068 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(parseInt(d.getMonth().pad()) + 1);';
8069 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(d.getFullYear());';
8071 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
8072 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
8073 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
8074 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
8076 /*if ($usecalendar == "eldy
")
8078 $base=DOL_URL_ROOT.'/core/';
8079 $reset_scripts .= 'resetDP(\''.$base.'\',\''.$prefix.'\',\''.$langs->trans("FormatDateShortJavaInput
").'\',\''.$langs->defaultlang.'\');';
8083 $reset_scripts .= 'this.form.elements[\''.$prefix.'day\'].value=formatDate(new Date(), \'d\'); ';
8084 $reset_scripts .= 'this.form.elements[\''.$prefix.'month\'].value=formatDate(new Date(), \'M\'); ';
8085 $reset_scripts .= 'this.form.elements[\''.$prefix.'year\'].value=formatDate(new Date(), \'yyyy\'); ';
8087 // Update the hour part
8090 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8092 //$reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); ';
8093 if ($addnowlink == 1) {
8094 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
8095 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
8096 } elseif ($addnowlink == 2) {
8097 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(d.getHours().pad());';
8098 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
8102 $reset_scripts .= ' } ';
8105 // Update the minute part
8108 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8110 //$reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); ';
8111 if ($addnowlink == 1) {
8112 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
8113 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
8114 } elseif ($addnowlink == 2) {
8115 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(d.getMinutes().pad());';
8116 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
8119 $reset_scripts .= ' } ';
8122 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
8123 if ($reset_scripts && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
8124 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonNow
" type="button" name="_useless
" value="now
" onClick="' . $reset_scripts . '">';
8125 $retstring .= $langs->trans("Now
");
8126 $retstring .= '</button> ';
8130 // Add a "Plus one hour
" link
8131 if ($conf->use_javascript_ajax && $addplusone && !$disabled) {
8132 // Script which will be inserted in the onClick of the "Add plusone
" link
8133 $reset_scripts = "";
8135 // Generate the date part, depending on the use or not of the javascript calendar
8136 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'dayinputnoreduce', 'tzuserrel') . '\');';
8137 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
8138 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
8139 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
8140 // Update the hour part
8143 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8145 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
8147 $reset_scripts .= ' } ';
8150 // Update the minute part
8153 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8155 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
8157 $reset_scripts .= ' } ';
8160 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
8161 if ($reset_scripts && empty($conf->dol_optimize_smallscreen)) {
8162 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonPlusOne
" type="button" name="_useless2
" value="plusone
" onClick="' . $reset_scripts . '">';
8163 $retstring .= $langs->trans("DateStartPlusOne
");
8164 $retstring .= '</button> ';
8168 // Add a link to set data
8169 if ($conf->use_javascript_ajax && !empty($adddateof) && !$disabled) {
8170 if (!is_array($adddateof)) {
8171 $arrayofdateof = array(array('adddateof' => $adddateof, 'labeladddateof' => $labeladddateof));
8173 $arrayofdateof = $adddateof;
8175 foreach ($arrayofdateof as $valuedateof) {
8176 $tmpadddateof = empty($valuedateof['adddateof']) ? 0 : $valuedateof['adddateof'];
8177 $tmplabeladddateof = empty($valuedateof['labeladddateof']) ? '' : $valuedateof['labeladddateof'];
8178 $tmparray = dol_getdate($tmpadddateof);
8179 if (empty($tmplabeladddateof)) {
8180 $tmplabeladddateof = $langs->trans("DateInvoice
");
8182 $reset_scripts = 'console.log(\'Click on now link\'); ';
8183 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(\''.dol_print_date($tmpadddateof, 'dayinputnoreduce').'\');';
8184 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(\''.$tmparray['mday'].'\');';
8185 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(\''.$tmparray['mon'].'\');';
8186 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(\''.$tmparray['year'].'\');';
8187 $retstring .= ' - <button class="dpInvisibleButtons datenowlink
" id="dateofinvoice
" type="button" name="_dateofinvoice
" value="now
" onclick="'.$reset_scripts.'">'.$tmplabeladddateof.'</button>';
8203 public function selectTypeDuration($prefix, $selected = 'i', $excludetypes = array(), $morecss = 'minwidth75 maxwidth100')
8207 $TDurationTypes = $this->getDurationTypes($langs);
8209 // Removed undesired duration types
8210 foreach ($excludetypes as $value) {
8211 unset($TDurationTypes[$value]);
8214 $retstring = '<select class="flat
'.($morecss ? ' '.$morecss : '').'" id="select_
' . $prefix . 'type_duration
" name="' . $prefix . 'type_duration
">';
8215 foreach ($TDurationTypes as $key => $typeduration) {
8216 $retstring .= '<option value="' . $key . '"';
8217 if ($key == $selected) {
8218 $retstring .= " selected
";
8220 $retstring .= ">
" . $typeduration . "</option>
";
8222 $retstring .= "</select>
";
8224 $retstring .= ajax_combobox('select_' . $prefix . 'type_duration');
8229 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
8244 public function select_duration($prefix, $iSecond = '', $disabled = 0, $typehour = 'select', $minunderhours = 0, $nooutput = 0)
8249 $retstring = '<span class="nowraponall
">';
8255 if ($iSecond != '') {
8256 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
8258 $hourSelected = convertSecondToTime($iSecond, 'allhour');
8259 $minSelected = convertSecondToTime($iSecond, 'min');
8262 if ($typehour == 'select') {
8263 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'hour
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . '>';
8264 for ($hour = 0; $hour < 25; $hour++) { // For a duration, we allow 24 hours
8265 $retstring .= '<option value="' . $hour . '"';
8266 if (is_numeric($hourSelected) && $hourSelected == $hour) {
8267 $retstring .= " selected
";
8269 $retstring .= ">
" . $hour . "</option>
";
8271 $retstring .= "</select>
";
8272 } elseif ($typehour == 'text' || $typehour == 'textselect') {
8273 $retstring .= '<input placeholder="' . $langs->trans('HourShort
') . '" type="number
" min="0
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputhour right
" value="' . (($hourSelected != '') ? ((int) $hourSelected) : '') . '">';
8275 return 'BadValueForParameterTypeHour';
8278 if ($typehour != 'text') {
8279 $retstring .= ' ' . $langs->trans('HourShort');
8281 $retstring .= '<span class="">:</span>';
8285 if ($minunderhours) {
8286 $retstring .= '<br>';
8288 if ($typehour != 'text') {
8289 $retstring .= '<span class="hideonsmartphone
"> </span>';
8293 if ($typehour == 'select' || $typehour == 'textselect') {
8294 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'min
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . '>';
8295 $step = getDolGlobalInt('MAIN_DURATION_STEP');
8296 $duration_step = ($step > 0) ? $step : 5;
8297 for ($min = 0; $min <= 59; $min += $duration_step) {
8298 $retstring .= '<option value="' . $min . '"';
8299 if (is_numeric($minSelected) && $minSelected == $min) {
8300 $retstring .= ' selected';
8302 $retstring .= '>' . $min . '</option>';
8304 $retstring .= "</select>
";
8305 } elseif ($typehour == 'text') {
8306 $retstring .= '<input placeholder="' . $langs->trans('MinuteShort
') . '" type="number
" min="0
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputminute right
" value="' . (($minSelected != '') ? ((int) $minSelected) : '') . '">';
8309 if ($typehour != 'text') {
8310 $retstring .= ' ' . $langs->trans('MinuteShort');
8313 $retstring .= "</span>
";
8315 if (!empty($nooutput)) {
8343 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)
8345 global $langs, $conf;
8350 if (is_null($ajaxoptions)) {
8351 $ajaxoptions = array();
8354 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
8357 if ($selected && empty($selected_input_value)) {
8358 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
8359 $tickettmpselect = new Ticket($this->db);
8360 $tickettmpselect->fetch((int) $selected);
8361 $selected_input_value = $tickettmpselect->ref;
8362 unset($tickettmpselect);
8366 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/ticket/ajax/tickets.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
8368 if (empty($hidelabel)) {
8369 $out .= $langs->trans("RefOrLabel
") . ' : ';
8370 } elseif ($hidelabel > 1) {
8371 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
8372 if ($hidelabel == 2) {
8373 $out .= img_picto($langs->trans("Search
"), 'search');
8376 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
8377 if ($hidelabel == 3) {
8378 $out .= img_picto($langs->trans("Search
"), 'search');
8381 $out .= $this->selectTicketsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
8384 if (empty($nooutput)) {
8409 public function selectTicketsList($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
8414 $outarray = array();
8416 $selectFields = " p.rowid, p.ref, p.message
";
8419 $sql .= $selectFields;
8420 $sql .= " FROM
" . $this->db->prefix() . "ticket as p
";
8421 $sql .= ' WHERE p.entity IN (' . getEntity('ticket') . ')';
8423 // Add criteria on ref/label
8424 if ($filterkey != '') {
8426 $prefix = getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '' : '%'; // Can use index if TICKET_DONOTSEARCH_ANYWHERE is on
8427 // For natural search
8428 $search_crit = explode(' ', $filterkey);
8430 if (count($search_crit) > 1) {
8433 foreach ($search_crit as $crit) {
8437 $sql .= "(p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%' OR p.subject LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
8441 if (count($search_crit) > 1) {
8447 $sql .= $this->db->plimit($limit, 0);
8449 // Build output string
8450 dol_syslog(get_class($this) . "::selectTicketsList search tickets
", LOG_DEBUG);
8451 $result = $this->db->query($sql);
8453 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
8454 require_once DOL_DOCUMENT_ROOT . '/core/lib/ticket.lib.php';
8456 $num = $this->db->num_rows($result);
8461 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
8462 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('TICKET_USE_SEARCH_TO_SELECT'));
8465 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
8468 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
8469 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
8470 if (getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
8471 if ($showempty && !is_numeric($showempty)) {
8472 $textifempty = $langs->trans($showempty);
8474 $textifempty .= $langs->trans("All
");
8477 if ($showempty && !is_numeric($showempty)) {
8478 $textifempty = $langs->trans($showempty);
8482 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
8486 while ($num && $i < $num) {
8489 $objp = $this->db->fetch_object($result);
8491 $this->constructTicketListOption($objp, $opt, $optJson, $selected, $filterkey);
8492 '@phan-var-force array{key:string,value:mixed,type:int} $optJson';
8494 // "key
" value of json key array is used by jQuery automatically as selected value
8495 // "label
" value of json key array is used by jQuery automatically as text for combo box
8497 array_push($outarray, $optJson);
8502 $out .= '</select>';
8504 $this->db->free($result);
8506 if (empty($outputmode)) {
8511 dol_print_error($this->db);
8528 protected function constructTicketListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
8534 $outkey = $objp->rowid;
8535 $outref = $objp->ref;
8537 $opt = '<option value="
' . $objp->rowid . '"';
8538 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
8541 $objRef = $objp->ref;
8542 if (!empty($filterkey) && $filterkey != '') {
8543 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1);
8546 $opt .= "</option>\n
";
8547 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
8569 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)
8571 global $langs, $conf;
8576 if (is_null($ajaxoptions)) {
8577 $ajaxoptions = array();
8580 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
8583 if ($selected && empty($selected_input_value)) {
8584 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
8585 $projecttmpselect = new Project($this->db);
8586 $projecttmpselect->fetch((int) $selected);
8587 $selected_input_value = $projecttmpselect->ref;
8588 unset($projecttmpselect);
8592 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/projet/ajax/projects.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
8594 if (empty($hidelabel)) {
8595 $out .= $langs->trans("RefOrLabel
") . ' : ';
8596 } elseif ($hidelabel > 1) {
8597 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
8598 if ($hidelabel == 2) {
8599 $out .= img_picto($langs->trans("Search
"), 'search');
8602 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
8603 if ($hidelabel == 3) {
8604 $out .= img_picto($langs->trans("Search
"), 'search');
8607 $out .= $this->selectProjectsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
8610 if (empty($nooutput)) {
8634 public function selectProjectsList($selected = '', $htmlname = 'projectid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
8636 global $langs, $conf;
8639 $outarray = array();
8641 $selectFields = " p.rowid, p.ref
";
8644 $sql .= $selectFields;
8645 $sql .= " FROM
" . $this->db->prefix() . "projet as p
";
8646 $sql .= ' WHERE p.entity IN (' . getEntity('project') . ')';
8648 // Add criteria on ref/label
8649 if ($filterkey != '') {
8651 $prefix = !getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
8652 // For natural search
8653 $search_crit = explode(' ', $filterkey);
8655 if (count($search_crit) > 1) {
8658 foreach ($search_crit as $crit) {
8662 $sql .= "p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
8666 if (count($search_crit) > 1) {
8672 $sql .= $this->db->plimit($limit, 0);
8674 // Build output string
8675 dol_syslog(get_class($this) . "::selectProjectsList search projects
", LOG_DEBUG);
8676 $result = $this->db->query($sql);
8678 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
8679 require_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php';
8681 $num = $this->db->num_rows($result);
8686 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
8687 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('PROJECT_USE_SEARCH_TO_SELECT'));
8690 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
8693 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
8694 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
8695 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
8696 if ($showempty && !is_numeric($showempty)) {
8697 $textifempty = $langs->trans($showempty);
8699 $textifempty .= $langs->trans("All
");
8702 if ($showempty && !is_numeric($showempty)) {
8703 $textifempty = $langs->trans($showempty);
8707 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
8711 while ($num && $i < $num) {
8714 $objp = $this->db->fetch_object($result);
8716 $this->constructProjectListOption($objp, $opt, $optJson, $selected, $filterkey);
8718 // "key
" value of json key array is used by jQuery automatically as selected value
8719 // "label
" value of json key array is used by jQuery automatically as text for combo box
8721 array_push($outarray, $optJson);
8726 $out .= '</select>';
8728 $this->db->free($result);
8730 if (empty($outputmode)) {
8735 dol_print_error($this->db);
8754 protected function constructProjectListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
8760 $label = $objp->label;
8762 $outkey = $objp->rowid;
8763 $outref = $objp->ref;
8764 $outlabel = $objp->label;
8765 $outtype = $objp->fk_product_type;
8767 $opt = '<option value="
' . $objp->rowid . '"';
8768 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
8771 $objRef = $objp->ref;
8772 if (!empty($filterkey) && $filterkey != '') {
8773 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1);
8776 $opt .= "</option>\n
";
8777 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
8801 public function selectMembers($selected = '', $htmlname = 'adherentid', $filtertype = '', $limit = 0, $status = 1, $selected_input_value = '', $hidelabel = 0, $ajaxoptions = array(), $socid = 0, $showempty = '1', $forcecombo = 0, $morecss = '', $selected_combinations = null, $nooutput = 0, $excludeids = array())
8803 global $langs, $conf;
8808 if (is_null($ajaxoptions)) {
8809 $ajaxoptions = array();
8812 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
8815 if ($selected && empty($selected_input_value)) {
8816 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
8817 $adherenttmpselect = new Adherent($this->db);
8818 $adherenttmpselect->fetch((int) $selected);
8819 $selected_input_value = $adherenttmpselect->ref;
8820 unset($adherenttmpselect);
8825 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/adherents/ajax/adherents.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
8827 if (empty($hidelabel)) {
8828 $out .= $langs->trans("RefOrLabel
") . ' : ';
8829 } elseif ($hidelabel > 1) {
8830 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
8831 if ($hidelabel == 2) {
8832 $out .= img_picto($langs->trans("Search
"), 'search');
8835 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
8836 if ($hidelabel == 3) {
8837 $out .= img_picto($langs->trans("Search
"), 'search');
8842 $out .= $this->selectMembersList($selected, $htmlname, $filtertype, $limit, $filterkey, $status, 0, $showempty, $forcecombo, $morecss, $excludeids);
8845 if (empty($nooutput)) {
8870 public function selectMembersList($selected = '', $htmlname = 'adherentid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '', $excludeids = array())
8872 global $langs, $conf;
8875 $outarray = array();
8877 $selectFields = " p.rowid, p.ref, p.firstname, p.lastname, p.fk_adherent_type
";
8880 $sql .= $selectFields;
8881 $sql .= " FROM
" . $this->db->prefix() . "adherent as p
";
8882 $sql .= ' WHERE p.entity IN (' . getEntity('adherent') . ')';
8884 // Add criteria on ref/label
8885 if ($filterkey != '') {
8887 $prefix = !getDolGlobalString('MEMBER_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
8888 // For natural search
8889 $search_crit = explode(' ', $filterkey);
8891 if (count($search_crit) > 1) {
8894 foreach ($search_crit as $crit) {
8898 $sql .= "(p.firstname LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
8899 $sql .= " OR p.lastname LIKE
'" . $this->db->escape($prefix . $crit) . "%')
";
8902 if (count($search_crit) > 1) {
8907 if ($status != -1) {
8908 $sql .= ' AND statut = ' . ((int) $status);
8910 if (!empty($excludeids)) {
8911 $sql .= " AND p.rowid NOT IN (
" . $this->db->sanitize(implode(',', $excludeids)) . ")
";
8913 $sql .= $this->db->plimit($limit, 0);
8915 // Build output string
8916 dol_syslog(get_class($this) . "::selectMembersList search adherents
", LOG_DEBUG);
8917 $result = $this->db->query($sql);
8919 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
8920 require_once DOL_DOCUMENT_ROOT . '/core/lib/member.lib.php';
8922 $num = $this->db->num_rows($result);
8927 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
8928 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('PROJECT_USE_SEARCH_TO_SELECT'));
8931 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
8934 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
8935 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
8936 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
8937 if ($showempty && !is_numeric($showempty)) {
8938 $textifempty = $langs->trans($showempty);
8940 $textifempty .= $langs->trans("All
");
8943 if ($showempty && !is_numeric($showempty)) {
8944 $textifempty = $langs->trans($showempty);
8948 $out .= '<option value="-1
" selected>' . $textifempty . '</option>';
8952 while ($num && $i < $num) {
8955 $objp = $this->db->fetch_object($result);
8957 $this->constructMemberListOption($objp, $opt, $optJson, $selected, $filterkey);
8960 // "key
" value of json key array is used by jQuery automatically as selected value
8961 // "label
" value of json key array is used by jQuery automatically as text for combo box
8963 array_push($outarray, $optJson);
8968 $out .= '</select>';
8970 $this->db->free($result);
8972 if (empty($outputmode)) {
8977 dol_print_error($this->db);
8994 protected function constructMemberListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
9000 $outkey = $objp->rowid;
9001 $outlabel = dolGetFirstLastname($objp->firstname, $objp->lastname);
9002 $outtype = $objp->fk_adherent_type;
9004 $opt = '<option value="
' . $objp->rowid . '"';
9005 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
9007 if (!empty($filterkey) && $filterkey != '') {
9008 $outlabel = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $outlabel, 1);
9011 $opt .= "</option>\n
";
9013 $optJson = array('key' => $outkey, 'value' => $outlabel, 'type' => $outtype);
9037 public function selectForForms($objectdesc, $htmlname, $preSelectedValue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $disabled = 0, $selected_input_value = '', $objectfield = '')
9039 global $conf, $extrafields, $user;
9041 // Example of common usage for a link to a thirdparty
9043 // We got this in a modulebuilder form of "
MyObject" of module "mymodule
".
9044 // When ->fields is array( ... "fk_soc
" => array("type"=>"integer:
Societe:societe/
class/societe.class.php:1:((
status:=:1) AND (entity:IN:__SHARED_ENTITIES__))
" ...), we have
9045 // $objectdesc = 'Societe'
9046 // $objectfield = Method 1: 'myobject@mymodule:fk_soc' ('fk_soc' is code to retrieve myobject->fields['fk_soc'])
9047 // Method 2 recommended (it can be the array): array("type"=>"integer:
Societe:societe/class/societe.class.php:1:((
status:=:1) AND (entity:IN:__SHARED_ENTITIES__))
" ...)
9049 // We got this when showing an extrafields on resource that is a link to societe
9050 // When extrafields 'link_to_societe' for object Resource is 'link' to 'Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))', we have
9051 // $objectdesc = 'Societe'
9052 // $objectfield = Method 1: 'resource:options_link_to_societe'
9053 // Method 2 recommended (it can be the array): array("type"=>'Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))" ...)
9062 $objectdescorig = $objectdesc;
9064 $InfoFieldList = array();
9069 if (is_array($objectfield)) {
9070 $objectdesc = $objectfield[
'type'];
9071 $objectdesc = preg_replace(
'/^integer[^:]*:/',
'', $objectdesc);
9072 } elseif ($objectfield) {
9074 $tmparray = explode(
':', $objectfield);
9077 $objectforfieldstmp = fetchObjectByElement(0, strtolower($tmparray[0]));
9079 if (is_object($objectforfieldstmp)) {
9083 if (preg_match(
'/^options_(.*)$/', $tmparray[1], $reg)) {
9087 $extrafields->fetch_name_optionals_label($objectforfieldstmp->table_element);
9089 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element][
'type'][$key]) && $extrafields->attributes[$objectforfieldstmp->table_element][
'type'][$key] ==
'link') {
9090 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element][
'param'][$key][
'options'])) {
9091 $tmpextrafields = array_keys($extrafields->attributes[$objectforfieldstmp->table_element][
'param'][$key][
'options']);
9092 $objectdesc = $tmpextrafields[0];
9097 if (array_key_exists($tmparray[1], $objectforfieldstmp->fields)) {
9098 $objectdesc = $objectforfieldstmp->fields[$tmparray[1]][
'type'];
9099 $objectdesc = preg_replace(
'/^integer[^:]*:/',
'', $objectdesc);
9110 $InfoFieldList = explode(
":", $objectdesc, 4);
9111 $vartmp = (empty($InfoFieldList[3]) ?
'' : $InfoFieldList[3]);
9113 if (preg_match(
'/^.*:(\w*)$/', $vartmp, $reg)) {
9114 $InfoFieldList[4] = $reg[1];
9116 $InfoFieldList[3] = preg_replace(
'/:\w*$/',
'', $vartmp);
9118 $classname = $InfoFieldList[0];
9119 $classpath = empty($InfoFieldList[1]) ?
'' : $InfoFieldList[1];
9121 $filter = empty($InfoFieldList[3]) ?
'' : $InfoFieldList[3];
9122 $sortfield = empty($InfoFieldList[4]) ?
'' : $InfoFieldList[4];
9125 $objecttmp = fetchObjectByElement(0, strtolower($InfoFieldList[0]));
9128 if (empty($objecttmp) && !empty($classpath)) {
9131 if ($classname && class_exists($classname)) {
9132 $objecttmp =
new $classname($this->db);
9139 $sharedentities = (is_object($objecttmp) && property_exists($objecttmp,
'element')) ?
getEntity($objecttmp->element) : strtolower($classname);
9140 $filter = str_replace(
9141 array(
'__ENTITY__',
'__SHARED_ENTITIES__',
'__USER_ID__'),
9142 array($conf->entity, $sharedentities, $user->id),
9146 if (!is_object($objecttmp)) {
9147 dol_syslog(
'selectForForms: Error bad setup of field objectdescorig=' . $objectdescorig.
', objectfield='.(is_array($objectfield) ?
'array' : $objectfield).
', objectdesc='.$objectdesc, LOG_WARNING);
9148 return 'selectForForms: Error bad setup of field objectdescorig=' . $objectdescorig.
', objectfield='.(is_array($objectfield) ?
'array' : $objectfield).
', objectdesc='.$objectdesc;
9150 '@phan-var-force CommonObject $objecttmp';
9153 $prefixforautocompletemode = $objecttmp->element;
9154 if ($prefixforautocompletemode ==
'societe') {
9155 $prefixforautocompletemode =
'company';
9157 if ($prefixforautocompletemode ==
'product') {
9158 $prefixforautocompletemode =
'produit';
9161 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) .
'_USE_SEARCH_TO_SELECT';
9163 dol_syslog(get_class($this) .
"::selectForForms filter=" . $filter, LOG_DEBUG);
9167 if (!empty($conf->use_javascript_ajax) &&
getDolGlobalString($confkeyforautocompletemode) && !$forcecombo) {
9171 if ($preSelectedValue && empty($selected_input_value)) {
9172 $objecttmp->fetch($preSelectedValue);
9173 $selected_input_value = ($prefixforautocompletemode ==
'company' ? $objecttmp->name : $objecttmp->ref);
9175 $oldValueForShowOnCombobox = 0;
9176 foreach ($objecttmp->fields as $fieldK => $fielV) {
9177 if (!array_key_exists(
'showoncombobox', $fielV) || !$fielV[
'showoncombobox'] || empty($objecttmp->$fieldK)) {
9181 if (!$oldValueForShowOnCombobox) {
9182 $selected_input_value =
'';
9185 $selected_input_value .= $oldValueForShowOnCombobox ?
' - ' :
'';
9186 $selected_input_value .= $objecttmp->$fieldK;
9187 $oldValueForShowOnCombobox = empty($fielV[
'showoncombobox']) ? 0 : $fielV[
'showoncombobox'];
9192 $urlforajaxcall = DOL_URL_ROOT .
'/core/ajax/selectobject.php';
9193 $urloption =
'htmlname=' . urlencode($htmlname) .
'&outjson=1&objectdesc=' . urlencode($objectdescorig) . (is_scalar($objectfield) ?
'&objectfield='.urlencode($objectfield) :
'') . ($sortfield ?
'&sortfield=' . urlencode($sortfield) :
'');
9198 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
9199 $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) .
'"' :
'') .
' />';
9202 $out .= $this->selectForFormsList($objecttmp, $htmlname, $preSelectedValue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled, $sortfield, $filter);
9230 public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty =
'', $searchkey =
'', $placeholder =
'', $morecss =
'', $moreparams =
'', $forcecombo = 0, $outputmode = 0, $disabled = 0, $sortfield =
'', $filter =
'', $sortorder =
'ASC')
9232 global $langs, $user, $hookmanager;
9236 $prefixforautocompletemode = $objecttmp->element;
9237 if ($prefixforautocompletemode ==
'societe') {
9238 $prefixforautocompletemode =
'company';
9240 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) .
'_USE_SEARCH_TO_SELECT';
9242 if (!empty($objecttmp->fields)) {
9243 $tmpfieldstoshow =
'';
9244 foreach ($objecttmp->fields as $key => $val) {
9245 if (! (
int)
dol_eval((
string) $val[
'enabled'], 1, 1,
'1')) {
9248 if (!empty($val[
'showoncombobox'])) {
9249 $tmpfieldstoshow .= ($tmpfieldstoshow ?
',' :
'') .
't.' . $key;
9252 if ($tmpfieldstoshow) {
9253 $fieldstoshow = $tmpfieldstoshow;
9255 } elseif ($objecttmp->element ===
'category') {
9256 $fieldstoshow =
't.label';
9259 $objecttmp->fields[
'ref'] = array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'enabled' => 1,
'position' => 10,
'visible' => 4,
'showoncombobox' => 1);
9262 if (empty($fieldstoshow)) {
9263 if (!empty($objecttmp->parent_element)) {
9264 $fieldstoshow =
'o.ref';
9265 if (empty($sortfield)) {
9266 $sortfield =
'o.ref';
9268 if (in_array($objecttmp->element, [
'commandedet',
'propaldet',
'facturedet',
'expeditiondet'])) {
9269 $fieldstoshow .=
',p.ref AS p_ref,p.label,t.description';
9270 $sortfield .=
', p.ref';
9272 } elseif (isset($objecttmp->fields[
'ref'])) {
9273 $fieldstoshow =
't.ref';
9275 $langs->load(
"errors");
9276 $this->error = $langs->trans(
"ErrorNoFieldWithAttributeShowoncombobox");
9277 return $langs->trans(
'ErrorNoFieldWithAttributeShowoncombobox');
9282 $outarray = array();
9283 $tmparray = array();
9288 $sql =
"SELECT t.rowid, " . $fieldstoshow .
" FROM " . $this->db->prefix() . $this->db->sanitize($objecttmp->table_element) .
" as t";
9289 if (!empty($objecttmp->isextrafieldmanaged)) {
9290 $extrafieldTable = $objecttmp->table_element;
9291 if ($extrafieldTable ==
'categorie') {
9292 $extrafieldTable =
'categories';
9294 $sql .=
" LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($extrafieldTable) .
"_extrafields as e ON t.rowid = e.fk_object";
9296 if (!empty($objecttmp->parent_element)) {
9297 '@phan-var-force CommonObjectLine $objecttmp';
9299 $sql .=
" INNER JOIN " . $this->db->prefix() . $this->db->sanitize($parent_properties[
'table_element']) .
" as o ON o.rowid = t.".$objecttmp->fk_parent_attribute;
9301 if (!empty($objecttmp->parent_element) && in_array($objecttmp->parent_element, [
'commande',
'propal',
'facture',
'expedition'])) {
9302 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product as p ON p.rowid = t.fk_product";
9304 if (!empty($objecttmp->ismultientitymanaged)) {
9305 if ($objecttmp->ismultientitymanaged == 1) {
9308 if (!is_numeric($objecttmp->ismultientitymanaged)) {
9309 $tmparray = explode(
'@', $objecttmp->ismultientitymanaged);
9310 $sql .=
" INNER JOIN " . $this->db->prefix() . $this->db->sanitize($tmparray[1]) .
" as parenttable ON parenttable.rowid = t." . $this->db->sanitize($tmparray[0]);
9315 $parameters = array(
9316 'object' => $objecttmp,
9317 'htmlname' => $htmlname,
9318 'filter' => $filter,
9319 'searchkey' => $searchkey
9322 $reshook = $hookmanager->executeHooks(
'selectForFormsListWhere', $parameters);
9323 if (!empty($hookmanager->resPrint)) {
9324 $sql .= $hookmanager->resPrint;
9326 $sql .=
" WHERE 1=1";
9329 if (!empty($objecttmp->ismultientitymanaged)) {
9330 if ($objecttmp->ismultientitymanaged == 1) {
9331 $sql .=
" AND t.entity IN (" .
getEntity($objecttmp->element) .
")";
9333 if (!is_numeric($objecttmp->ismultientitymanaged)) {
9334 $sql .=
" AND parenttable.entity = t." . $this->db->sanitize($tmparray[0]);
9338 if ($objecttmp->ismultientitymanaged ===
'fk_soc@societe') {
9339 if (!$user->hasRight(
'societe',
'client',
'voir') && empty($user->socid)) {
9340 $sql .=
" AND EXISTS (SELECT sc.rowid FROM ".$this->db->prefix() .
"societe_commerciaux as sc";
9341 $sql .=
" WHERE sc.fk_soc = t.fk_soc AND sc.fk_user = ".((int) $user->id).
")";
9347 if (!empty($user->socid)) {
9348 if ($objecttmp->element ==
'societe') {
9349 $sql .=
" AND t.rowid = " . ((int) $user->socid);
9350 } elseif (!empty($objecttmp->fields[
'fk_soc']) || !empty($objecttmp->fields[
't.fk_soc']) || property_exists($objecttmp,
'fk_soc') || property_exists($objecttmp,
'socid')) {
9351 $sql .=
" AND t.fk_soc = " . ((int) $user->socid);
9355 $splittedfieldstoshow = explode(
',', $fieldstoshow);
9356 foreach ($splittedfieldstoshow as &$field2) {
9357 if (is_numeric($pos = strpos($field2,
' '))) {
9358 $field2 = substr($field2, 0, $pos);
9361 if ($searchkey !=
'') {
9368 if ($errormessage) {
9369 return 'Error forging a SQL request from an universal criteria: ' . $errormessage;
9373 $sql .= $this->db->order($sortfield ? $sortfield : $fieldstoshow, $sortorder);
9378 $resql = $this->db->query($sql);
9381 $out .=
'<select id="' . $htmlname .
'" class="flat minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') . ($moreparams ?
' ' . $moreparams :
'') .
' name="' . $htmlname .
'">' .
"\n";
9384 $textifempty =
' ';
9388 if ($showempty && !is_numeric($showempty)) {
9389 $textifempty = $langs->trans($showempty);
9391 $textifempty .= $langs->trans(
"All");
9395 $out .=
'<option value="-1">' . $textifempty .
'</option>' .
"\n";
9398 $num = $this->db->num_rows($resql);
9402 $obj = $this->db->fetch_object($resql);
9405 $tmparray = explode(
',', $fieldstoshow);
9406 $oldvalueforshowoncombobox = 0;
9407 foreach ($tmparray as $key => $val) {
9408 $val = preg_replace(
'/(t|p|o)\./',
'', $val);
9409 $label .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val][
'showoncombobox'] ?
' - ' :
' ') :
'');
9410 $labelhtml .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val][
'showoncombobox'] ?
' - ' :
' ') :
'');
9411 $label .= $obj->$val;
9412 $labelhtml .= $obj->$val;
9414 $oldvalueforshowoncombobox = empty($objecttmp->fields[$val][
'showoncombobox']) ? 0 : $objecttmp->fields[$val][
'showoncombobox'];
9416 if (empty($outputmode)) {
9417 if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) {
9418 $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>';
9420 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
9423 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label));
9427 if (($i % 10) == 0) {
9433 $out .=
'</select>' .
"\n";
9436 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
9443 $this->result = array(
'nbofelement' => $num);
9461 public static function radio($htmlName, $radioItems, $selected =
'', $moreGlobalParams = [])
9465 'disabled' =>
false,
9468 'name' => $htmlName,
9470 'unescapedAttr' => [],
9472 'unescapedAttrLabel' => [],
9473 'labelIsHtml' => false
9480 if (!empty($radioItems)) {
9481 foreach ($radioItems as $key => $item) {
9483 if (!is_array($item)) {
9495 'value' => !isset($item[
'attr'][
'value']) ? $key :
'',
9505 if ((is_array($selected) && in_array($item[
'attr'][
'value'], $selected,
true)) || $selected === $item[
'attr'][
'value']) {
9506 $item[
'attr'][
'checked'] =
true;
9514 $text = $item[
'labelIsHtml'] ? $item[
'label'] : htmlspecialchars($item[
'label'], ENT_QUOTES | ENT_SUBSTITUTE);
9517 $out .=
'<label ' . $labelAttributes .
'><input ' . $inputAttributes .
' /> ' . $text .
'</label> ';
9548 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)
9550 global $conf, $langs;
9557 if ($value_as_key) {
9558 $array = array_combine($array, $array);
9561 '@phan-var-force array{label:string,data-html:string,disable?:int<0,1>,css?:string} $array';
9565 if ($addjscombo < 0) {
9572 $idname = str_replace(array(
'[',
']'), array(
'',
''), $htmlname);
9573 $out .=
'<select id="' . preg_replace(
'/^\./',
'', $idname) .
'" ' . ($disabled ?
'disabled="disabled" ' :
'') .
'class="flat ' . (preg_replace(
'/^\./',
'', $htmlname)) . ($morecss ?
' ' . $morecss :
'') .
' selectformat"';
9574 $out .=
' name="' . preg_replace(
'/^\./',
'', $htmlname) .
'" ' . ($moreparam ? $moreparam :
'');
9578 $textforempty =
' ';
9579 if (!empty($conf->use_javascript_ajax)) {
9580 $textforempty =
' ';
9582 if (!is_numeric($show_empty)) {
9583 $textforempty = $show_empty;
9585 $out .=
'<option class="optiongrey" ' . ($moreparamonempty ? $moreparamonempty .
' ' :
'') .
'value="' . (((
int) $show_empty) < 0 ? $show_empty : -1) .
'"' . (
$id == $show_empty ?
' selected' :
'') .
'>' . $textforempty .
'</option>' .
"\n";
9587 if (is_array($array)) {
9590 foreach ($array as $key => $value) {
9591 if (!is_array($value)) {
9592 $array[$key] = $langs->trans($value);
9594 $array[$key][
'label'] = $langs->trans($value[
'label']);
9599 if ($sort ==
'ASC') {
9601 } elseif ($sort ==
'DESC') {
9605 foreach ($array as $key => $tmpvalue) {
9606 if (is_array($tmpvalue)) {
9607 $value = $tmpvalue[
'label'];
9609 $disabled = empty($tmpvalue[
'disabled']) ?
'' :
' disabled';
9610 $style = empty($tmpvalue[
'css']) ?
'' :
' class="' . $tmpvalue[
'css'] .
'"';
9617 if (!empty($disablebademail)) {
9618 if (($disablebademail == 1 && !preg_match(
'/<.+@.+>/', $value))
9619 || ($disablebademail == 2 && preg_match(
'/---/', $value))) {
9620 $disabled =
' disabled';
9621 $style =
' class="warning"';
9624 if ($key_in_label) {
9625 if (empty($nohtmlescape)) {
9628 $selectOptionValue = $key .
' - ' . ($maxlen ?
dol_trunc($value, $maxlen) : $value);
9631 if (empty($nohtmlescape)) {
9634 $selectOptionValue = $maxlen ?
dol_trunc($value, $maxlen) : $value;
9636 if ($value ==
'' || $value ==
'-') {
9637 $selectOptionValue =
' ';
9640 $out .=
'<option value="' . $key .
'"';
9641 $out .= $style . $disabled;
9642 $out .= is_array($tmpvalue) && !empty($tmpvalue[
'parent']) ?
' parent="' .
dolPrintHTMLForAttribute($tmpvalue[
'parent']) .
'"' :
'';
9643 if (is_array(
$id)) {
9644 if (in_array($key,
$id) && !$disabled) {
9645 $out .=
' selected';
9649 if (
$id !=
'' && ((
$id == (
string) $key) || (
$id ==
'ifone' && count($array) == 1)) && !$disabled) {
9650 $out .=
' selected';
9654 if (is_array($tmpvalue)) {
9655 foreach ($tmpvalue as $keyforvalue => $valueforvalue) {
9656 if ($keyforvalue ==
'labelhtml') {
9657 $keyforvalue =
'data-html';
9659 if (preg_match(
'/^data-/', $keyforvalue)) {
9660 $out .=
' '.dol_escape_htmltag($keyforvalue).
'="'.
dol_escape_htmltag($valueforvalue).
'"';
9663 } elseif (!empty($nohtmlescape)) {
9668 $out .= $selectOptionValue;
9669 $out .=
"</option>\n";
9672 $out .=
"</select>";
9675 if ($addjscombo && $jsbeautify) {
9677 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
9678 $out .=
ajax_combobox($idname, array(), 0, 0,
'resolve', (((
int) $show_empty) < 0 ? (
string) $show_empty :
'-1'), $morecss);
9702 public static function selectArrayAjax($htmlname, $url,
$id =
'', $moreparam =
'', $moreparamtourl =
'', $disabled = 0, $minimumInputLength = 1, $morecss =
'', $callurlonselect = 0, $placeholder =
'', $acceptdelayedhtml = 0)
9705 global $delayedhtmlcontent;
9708 if (!
getDolGlobalString(
'MAIN_USE_JQUERY_MULTISELECT') && !defined(
'REQUIRE_JQUERY_MULTISELECT')) {
9712 $out =
'<select type="text" class="' . $htmlname . ($morecss ?
' ' . $morecss :
'') .
'" ' . ($moreparam ? $moreparam .
' ' :
'') .
'name="' . $htmlname .
'"></select>';
9715 if (!empty($conf->use_javascript_ajax)) {
9716 $tmpplugin =
'select2';
9717 $outdelayed =
"\n" .
'<!-- JS CODE TO ENABLE ' . $tmpplugin .
' for id ' . $htmlname .
' -->
9718 <script nonce="' .
getNonce() .
'">
9719 $(document).ready(function () {
9721 ' . ($callurlonselect ?
'var saveRemoteData = [];' :
'') .
'
9723 $(".' . $htmlname .
'").select2({
9726 url: "' . $url .
'",
9729 data: function (params) {
9731 q: params.term, // search term
9735 processResults: function (data) {
9736 // parse the results into the format expected by Select2.
9737 // since we are using custom formatting functions we do not need to alter the remote JSON data
9738 //console.log(data);
9739 saveRemoteData = data;
9740 /* format json result for select2 */
9742 $.each( data, function( key, value ) {
9743 result.push({id: key, text: value.text});
9745 //return {results:[{id:\'none\', text:\'aa\'}, {id:\'rrr\', text:\'Red\'},{id:\'bbb\', text:\'Search a into projects\'}], more:false}
9746 //console.log(result);
9747 return {results: result, more: false}
9751 language: (typeof select2arrayoflanguage === \'undefined\') ? \'en\' : select2arrayoflanguage,
9752 containerCssClass: \':all:\', /* Line to add class from the original SELECT propagated to the new <span class="select2-selection...> tag */
9754 escapeMarkup:
function (markup) {
return markup; },
9755 minimumInputLength:
' . ((int) $minimumInputLength) . ',
9756 formatResult:
function (result, container, query, escapeMarkup) {
9757 return escapeMarkup(result.text);
9761 ' . ($callurlonselect ? '
9763 $(
".' . $htmlname . '").change(
function() {
9764 var selected = $(\
'.' .
dol_escape_js($htmlname) .
'\').val();
9765 console.log(
"We select in selectArrayAjax the entry "+selected)
9767 $.each( saveRemoteData,
function( key, value ) {
9768 if (key == selected)
9770 console.log(
"selectArrayAjax - Do a redirect to "+value.url)
9771 location.assign(value.url);
9780 if ($acceptdelayedhtml) {
9781 $delayedhtmlcontent .= $outdelayed;
9783 $out .= $outdelayed;
9807 public static function selectArrayFilter($htmlname, $array, $id = '
', $moreparam = '', $disableFiltering = 0, $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0, $textfortitle = '')
9810 global $delayedhtmlcontent; // Will be used later outside of this function
9812 // TODO Use an internal dolibarr component instead of select2
9813 if (!getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT
') && !defined('REQUIRE_JQUERY_MULTISELECT
')) {
9817 $out = '<select
type=
"text"'.($textfortitle ? ' title=
"'.dol_escape_htmltag($textfortitle).'"' : '').' id=
"'.$htmlname.'" class=
"'.$htmlname.($morecss ? ' ' . $morecss : '').'"'.($moreparam ? ' '.$moreparam : '').' name=
"'.$htmlname.'"><option></option></select>
';
9819 $formattedarrayresult = array();
9821 foreach ($array as $key => $value) {
9822 $o = new stdClass();
9824 $o->text = $value['text
'];
9825 $o->url = $value['url
'];
9826 $formattedarrayresult[] = $o;
9830 if (!empty($conf->use_javascript_ajax)) {
9831 $tmpplugin = 'select2
';
9832 $outdelayed = "\n" . '<!-- JS CODE TO ENABLE
' . $tmpplugin . ' for id ' . $htmlname . ' -->
9833 <script nonce=
"' . getNonce() . '">
9834 $(document).ready(
function () {
9835 var data =
' . json_encode($formattedarrayresult) . ';
9837 ' . ($callurlonselect ? 'var saveRemoteData =
' . json_encode($array) . ';
' : '') . '
9841 language: (typeof select2arrayoflanguage === \
'undefined\') ? \'en\' : select2arrayoflanguage,
9842 containerCssClass: \':all:\', /* Line to add class from the original SELECT propagated to the new <span class="select2-selection...> tag */
9844 escapeMarkup:
function (markup) {
return markup; },
9845 minimumInputLength:
' . ((int) $minimumInputLength) . ',
9846 formatResult:
function (result, container, query, escapeMarkup) {
9847 return escapeMarkup(result.text);
9849 matcher:
function (params, data) {
9851 if(! data.id)
return null;
';
9853 if ($callurlonselect) {
9854 // We forge the url with 'sall=
'
9857 var urlBase = data.url;
9858 var separ = urlBase.indexOf(
"?") >= 0 ?
"&" :
"?";
9861 saveRemoteData[data.id].url = urlBase + separ +
"search_all=" + encodeURIComponent(params.term.replace(/\
"/g, ""));';
9864 if (!$disableFiltering) {
9867 if(data.text.match(new RegExp(params.term))) {
9882 ' . ($callurlonselect ? '
9883 /* Code to execute a GET when we select a value */
9884 $(\'.' . dol_escape_js($htmlname) . '\').change(function() {
9885 var selected = $(\'.' . dol_escape_js($htmlname) . '\').val();
9886 console.log("We select
"+selected)
9888 $(\'.' . dol_escape_js($htmlname) . '\').val(""); /* reset visible combo value */
9889 $.each( saveRemoteData, function( key, value ) {
9890 if (key == selected)
9892 console.log("selectArrayFilter - Do a redirect to
"+value.url)
9893 location.assign(value.url);
9902 if ($acceptdelayedhtml) {
9903 $delayedhtmlcontent .= $outdelayed;
9905 $out .= $outdelayed;
9928 public static function multiselectarray($htmlname, $array, $selected = array(), $key_in_label = 0, $value_as_key = 0, $morecss = '', $translate = 0, $width = 0, $moreattrib = '', $nu = '', $placeholder = '', $addjscombo = -1)
9930 global $conf, $langs;
9933 if ($addjscombo < 0) {
9934 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
9941 $useenhancedmultiselect = 0;
9942 if (!empty($conf->use_javascript_ajax) && !defined('MAIN_DO_NOT_USE_JQUERY_MULTISELECT') && (getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') || defined('REQUIRE_JQUERY_MULTISELECT'))) {
9944 $useenhancedmultiselect = 1; // Use the js multiselect in one line. Possible only if $addjscombo not 0.
9948 $out .= '<span class="multiselectarray
'.$htmlname.'">';
9950 // We need a hidden field because when using the multiselect, if we unselect all, there is no
9951 // variable submitted at all, so no way to make a difference between variable not submitted and variable
9952 // submitted to nothing.
9953 $out .= '<input type="hidden
" name="'.$htmlname.'_multiselect
" value="1
">';
9954 // Output select component
9955 $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
";
9956 if (is_array($array) && !empty($array)) {
9957 if ($value_as_key) {
9958 $array = array_combine($array, $array);
9961 if (!empty($array)) {
9962 foreach ($array as $key => $value) {
9969 if (is_array($value) && array_key_exists('id', $value) && array_key_exists('label', $value)) {
9970 $tmpkey = $value['id'];
9971 $tmplabel = empty($value['label']) ? '' : $value['label'];
9972 $tmplabelhtml = empty($value['labelhtml']) ? (empty($value['data-html']) ? '' : $value['data-html']) : $value['labelhtml'];
9973 $tmpcolor = empty($value['color']) ? '' : $value['color'];
9974 $tmppicto = empty($value['picto']) ? '' : $value['picto'];
9975 $tmpdisabled = empty($value['disabled']) ? '' : $value['disabled'];
9977 $newval = ($translate ? $langs->trans($tmplabel) : $tmplabel);
9978 $newval = ($key_in_label ? $tmpkey . ' - ' . $newval : $newval);
9980 $tmplabelhtml = ($translate ? $langs->trans($tmplabelhtml) : $tmplabelhtml);
9981 $tmplabelhtml = ($key_in_label ? $tmpkey . ' - ' . $tmplabelhtml : $tmplabelhtml);
9983 $out .= '<option value="' . $tmpkey . '"';
9984 if (is_array($selected) && !empty($selected) && in_array((string) $tmpkey, $selected) && ((string) $tmpkey != '')) {
9985 $out .= ' selected';
9987 $out .= is_array($value) && array_key_exists('parent', $value) && !empty($value['parent']) ? ' parent="' . dolPrintHTMLForAttribute($value['parent
']) . '"' : '';
9991 if (!empty($tmplabelhtml)) {
9992 $out .= ' data-html="' . dolPrintHTMLForAttribute($tmplabelhtml) . '"';
9994 $tmplabelhtml = ($tmppicto ? img_picto('', $tmppicto, 'class="pictofixedwidth
" style="color: #
' . $tmpcolor . '"') : '') . $newval;
9995 $out .= ' data-html="' . dolPrintHTMLForAttribute($tmplabelhtml) . '"';
9998 $out .= dol_htmlentitiesbr($newval);
9999 $out .= '</option>' . "\n
";
10003 $out .= '</select>' . "\n
";
10007 // Add code for jquery to use multiselect
10008 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') || defined('REQUIRE_JQUERY_MULTISELECT')) {
10009 $out .= "\n
" . '<!-- JS CODE TO ENABLE select for id ' . $htmlname . ', addjscombo=' . $addjscombo . ' -->';
10010 $out .= "\n
" . '<script nonce="' . getNonce() . '">' . "\n
";
10011 if ($addjscombo == 1) {
10012 $tmpplugin = getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT', (defined('REQUIRE_JQUERY_MULTISELECT') ? constant('REQUIRE_JQUERY_MULTISELECT') : 'select2'));
10014 // If property data-html set, we decode html entities and use this.
10015 // Note that HTML content must have been sanitized from js with dol_escape_htmltag(xxx, 0, 0, '', 0, 1) when building the select option.
10016 // TODO Move this into common js ?
10017 $out .= 'function formatResult(record, container) {' . "\n
";
10018 $out .= ' if ($(record.element).attr("data-html
") != undefined && typeof htmlEntityDecodeJs === "function
") {';
10019 $out .= ' return htmlEntityDecodeJs($(record.element).attr("data-html
"));';
10021 $out .= ' return record.text;';
10022 $out .= '}' . "\n
";
10024 $out .= 'function formatSelection(record) {' . "\n
";
10025 $out .= ' return record.text;';
10026 $out .= '}' . "\n
";
10028 // Load the select2 enhancer
10029 //$out .= 'console.log(\'addjscombo=1 for htmlname=' . dol_escape_js($htmlname) . '\');';
10030 $out .= '$(document).ready(function () {
10031 $(\'#' . dol_escape_js($htmlname) . '\').' . $tmpplugin . '({';
10032 if ($placeholder) {
10036 text: \''.dol_escape_js($placeholder).'\'
10039 $out .= ' dir: \'ltr\',
10040 containerCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag (ko with multiselect) */
10041 dropdownCssClass: \
'' .
dol_escape_js($morecss) .
'\', /* Line to add class on the new <span class="select2-selection...> tag (ok with multiselect). Need full version of select2. */
10042 // Specify format function for dropdown item
10043 formatResult: formatResult,
10044 templateResult: formatResult, /* For 4.0 */
10045 escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
10046 // Specify format function for selected item
10047 formatSelection: formatSelection,
10048 templateSelection: formatSelection, /* For 4.0 */
10049 language: (typeof select2arrayoflanguage === \'undefined\') ? \'en\' : select2arrayoflanguage
10052 /* Add also morecss to the css .select2 that is after the #htmlname, for component that are shown dynamically after load, because select2 set
10053 the size only if component is not hidden by default on load */
10056 } elseif ($addjscombo == 2 && !defined(
'DISABLE_MULTISELECT')) {
10060 $out .=
'console.log(\'addjscombo=2 for htmlname=' .
dol_escape_js($htmlname) .
'\');
';
10061 $out .= '$(document).ready(
function () {
10063 containerHTML: \
'<div class="multi-select-container">\',
10064 menuHTML: \'<div class="multi-select-menu">\',
10065 buttonHTML: \'<span class="multi-select-button ' .
dol_escape_js($morecss) .
'">\',
10066 menuItemHTML: \'<label class="multi-select-menuitem">\',
10067 activeClass: \'multi-select-container--open\',
10072 $out .= '</script>
';
10090 public static function multiSelectArrayWithCheckbox($htmlname, &$array, $varpage, $pos = '
')
10092 global $conf, $langs, $user;
10094 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER
')) {
10097 if (empty($array)) {
10101 $tmpvar = "MAIN_SELECTEDFIELDS_" . $varpage; // To get list of saved selected fields to show
10103 if (!empty($user->conf->$tmpvar)) { // A list of fields was already customized for user
10104 $tmparray = explode(',
', $user->conf->$tmpvar);
10105 foreach ($array as $key => $val) {
10107 //var_dump($tmparray);
10108 if (in_array($key, $tmparray)) {
10109 $array[$key]['checked
'] = 1;
10111 $array[$key]['checked
'] = 0;
10114 } else { // There is no list of fields already customized for user
10115 foreach ($array as $key => $val) {
10116 if (!empty($array[$key]['checked
']) && $array[$key]['checked
'] < 0) {
10117 $array[$key]['checked
'] = 0;
10122 $listoffieldsforselection = '';
10123 $listcheckedstring = '';
10125 foreach ($array as $key => $val) {
10127 // var_dump(array_key_exists('enabled
', $val));
10128 // var_dump(!$val['enabled
']);
10129 if (array_key_exists('enabled
', $val) && isset($val['enabled
']) && !$val['enabled
']) {
10130 unset($array[$key]); // We don't want
this field
10133 if (!empty($val[
'type']) && $val[
'type'] ==
'separate') {
10138 if (!empty($val[
'label']) && $val[
'label']) {
10139 if (!empty($val[
'langfile']) && is_object($langs)) {
10140 $langs->load($val[
'langfile']);
10144 $listoffieldsforselection .=
'<li><input type="checkbox" id="checkbox' . $key .
'" value="' . $key .
'"' . ((!array_key_exists(
'checked', $val) || empty($val[
'checked']) || $val[
'checked'] ==
'-1') ?
'' :
' checked="checked"') .
' data-position="'.(empty($val[
'position']) ?
'' : $val[
'position']).
'" />';
10145 $listoffieldsforselection .=
'<label for="checkbox' . $key .
'" class="paddingleft">';
10147 $listoffieldsforselection .=
'</label></li>';
10148 $listcheckedstring .= (empty($val[
'checked']) ?
'' : $key .
',');
10152 $out =
'<!-- Component multiSelectArrayWithCheckbox ' . $htmlname .
' -->
10154 <dl class="dropdown">
10156 <a href="#' . $htmlname .
'" class="multiselectpicto">
10159 <input type="hidden" class="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $listcheckedstring .
'">
10161 <dd class="dropdowndd">
10162 <div class="multiselectcheckbox'.$htmlname.
'">
10163 <ul class="'.$htmlname.(((string) $pos ==
'1' || (
string) $pos ==
'left') ?
'left' :
'').
'">
10164 <li class="liinputsearch">
10165 <input class="inputsearch_dropdownselectedfields width90p minwidth200imp" style="width:90%;" type="text" placeholder="'.$langs->trans(
'Search').
'">
10167 '.$listoffieldsforselection.
'
10173 <script nonce="' .
getNonce() .
'" type="text/javascript">
10174 jQuery(document).ready(function () {
10175 $(\'.multiselectcheckbox' . $htmlname .
' input[type="checkbox"]\').on("click", function () {
10176 console.log("A new field was added/removed, we edit field input[name=formfilteraction]");
10178 $("input:hidden[name=formfilteraction]").val(\'listafterchangingselectedfields\'); // Update field so we know we changed something on selected fields after POST
10180 var title = $(this).val() + ",";
10181 if ($(this).is(\':checked\')) {
10182 $(\'.' . $htmlname .
'\').val(title + $(\'.' . $htmlname .
'\').val());
10185 $(\'.' . $htmlname .
'\').val( $(\'.' . $htmlname .
'\').val().replace(title, \'\') )
10187 // Now, we submit page
10188 //$(this).parents(\'form:first\').submit();
10191 $("input.inputsearch_dropdownselectedfields").on("keyup", function() {
10192 console.log("keyup on inputsearch_dropdownselectedfields");
10193 var value = $(this).val().toLowerCase();
10194 $(\'.multiselectcheckbox'.$htmlname.
' li > label\').filter(function() {
10195 $(this).parent().toggle($(this).text().toLowerCase().indexOf(value) > -1)
10199 if (empty($conf->browser->layout) || $conf->browser->layout !=
'phone') {
10201 $(".dropdown dt a").on("click", function () {
10202 console.log("Click on dropdown, we set focus to search field");
10203 setTimeout(() => { $(\'.inputsearch_dropdownselectedfields\').focus(); }, 200);
10225 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
10228 $categories = $cat->containing(
$id, $type);
10230 if ($rendermode == 1) {
10231 $toprint = array();
10232 foreach ($categories as
$c) {
10233 $ways =
$c->print_all_ways(
'auto', ($nolink ?
'none' :
''), 0, 1);
10234 foreach ($ways as $way) {
10235 $color =
$c->color;
10236 $sfortag =
'<li class="select2-search-choice-dolibarr noborderoncategories'.(empty($toprint) ?
' nomarginleft' :
'').
'"' . ($color ?
' style="background: #' . $color .
';"' :
' style="background: #bbb"') .
'>';
10238 $sfortag .=
'</li>';
10239 $toprint[] = $sfortag;
10242 if (empty($toprint)) {
10245 return '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
10249 if ($rendermode == 0) {
10250 $arrayselected = array();
10251 $cate_arbo = $this->select_all_categories($type,
'',
'parent', 64, 0, 3);
10252 foreach ($categories as
$c) {
10253 $arrayselected[(string)
$c->id] = (
string)
$c->id;
10256 return $this->multiselectarray(
'categories', $cate_arbo, $arrayselected, 0, 0,
'', 0,
'100%',
'disabled',
'category');
10259 return 'ErrorBadValueForParameterRenderMode';
10273 global $conf, $langs, $hookmanager;
10277 $object->fetchObjectLinked();
10280 $hookmanager->initHooks(array(
'commonobject'));
10281 $parameters = array(
10282 'morehtmlright' => $morehtmlright,
10283 'compatibleImportElementsList' => &$compatibleImportElementsList,
10285 $reshook = $hookmanager->executeHooks(
'showLinkedObjectBlock', $parameters,
$object, $action);
10287 $nbofdifferenttypes = count(
$object->linkedObjects);
10289 if (empty($reshook)) {
10290 print
'<!-- showLinkedObjectBlock -->';
10291 print
load_fiche_titre($langs->trans($title), $morehtmlright,
'', 0,
'',
'showlinkedobjectblock');
10294 print
'<div class="div-table-responsive-no-min">';
10295 print
'<table class="noborder allwidth" data-block="showLinkedObject" data-element="' .
$object->element .
'" data-elementid="' .
$object->id .
'" >';
10297 print
'<tr class="liste_titre">';
10298 print
'<td>' . $langs->trans(
"Type") .
'</td>';
10299 print
'<td>' . $langs->trans(
"Ref") .
'</td>';
10300 print
'<td class="center"></td>';
10301 print
'<td class="center">' . $langs->trans(
"Date") .
'</td>';
10302 print
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
10303 print
'<td class="right">' . $langs->trans(
"Status") .
'</td>';
10307 $nboftypesoutput = 0;
10309 foreach (
$object->linkedObjects as $objecttype => $objects) {
10310 $tplpath = $element = $subelement = $objecttype;
10313 global $showImportButton;
10314 $showImportButton =
false;
10315 if (!empty($compatibleImportElementsList) && in_array($element, $compatibleImportElementsList)) {
10316 $showImportButton =
true;
10321 if ($objecttype !=
'supplier_proposal' && preg_match(
'/^([^_]+)_([^_]+)/i', $objecttype, $regs)) {
10322 $element = $regs[1];
10323 $subelement = $regs[2];
10324 $tplpath = $element .
'/' . $subelement;
10326 $tplname =
'linkedobjectblock';
10329 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $objecttype, $regs)) {
10330 $element = $regs[1];
10331 $module = $regs[2];
10332 $tplpath = $module.
'/' . $element;
10333 $tplname = $tplname.
'_'.$element;
10337 if ($objecttype ==
'facture') {
10338 $tplpath =
'compta/' . $element;
10342 } elseif ($objecttype ==
'facturerec') {
10343 $tplpath =
'compta/facture';
10344 $tplname =
'linkedobjectblockForRec';
10348 } elseif ($objecttype ==
'propal') {
10349 $tplpath =
'comm/' . $element;
10353 } elseif ($objecttype ==
'supplier_proposal') {
10357 } elseif ($objecttype ==
'shipping' || $objecttype ==
'shipment' || $objecttype ==
'expedition') {
10358 $tplpath =
'expedition';
10362 } elseif ($objecttype ==
'reception') {
10363 $tplpath =
'reception';
10367 } elseif ($objecttype ==
'delivery') {
10368 $tplpath =
'delivery';
10372 } elseif ($objecttype ==
'ficheinter') {
10373 $tplpath =
'fichinter';
10377 } elseif ($objecttype ==
'invoice_supplier') {
10378 $tplpath =
'fourn/facture';
10379 } elseif ($objecttype ==
'order_supplier') {
10380 $tplpath =
'fourn/commande';
10381 } elseif ($objecttype ==
'expensereport') {
10382 $tplpath =
'expensereport';
10383 } elseif ($objecttype ==
'subscription') {
10384 $tplpath =
'adherents';
10385 } elseif ($objecttype ==
'conferenceorbooth') {
10386 $tplpath =
'eventorganization';
10387 } elseif ($objecttype ==
'conferenceorboothattendee') {
10388 $tplpath =
'eventorganization';
10389 } elseif ($objecttype ==
'mo') {
10394 } elseif ($objecttype ==
'project_task') {
10395 $tplpath =
'projet/tasks';
10398 global $linkedObjectBlock;
10399 $linkedObjectBlock = $objects;
10402 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array(
'/' . $tplpath .
'/tpl'));
10404 foreach ($dirtpls as $reldir) {
10405 $reldir = rtrim($reldir,
'/');
10406 if ($nboftypesoutput == ($nbofdifferenttypes - 1)) {
10407 global $noMoreLinkedObjectBlockAfter;
10408 $noMoreLinkedObjectBlockAfter = 1;
10410 $file =
dol_buildpath($reldir .
'/' . $tplname .
'.tpl.php');
10411 if (file_exists($file)) {
10412 $res = @include $file;
10414 $nboftypesoutput++;
10421 if (!$nboftypesoutput) {
10422 print
'<tr><td colspan="7"><span class="opacitymedium">' . $langs->trans(
"None") .
'</span></td></tr>';
10427 if (!empty($compatibleImportElementsList)) {
10428 $res = @include
dol_buildpath(
'core/tpl/objectlinked_lineimport.tpl.php');
10434 return $nbofdifferenttypes;
10448 global $conf, $langs, $hookmanager, $form;
10451 if (empty($form)) {
10452 $form =
new Form($this->db);
10456 $linktoelemlist =
'';
10457 $listofidcompanytoscan =
'';
10459 if (!is_object(
$object->thirdparty)) {
10463 $possiblelinks = array();
10465 $dontIncludeCompletedItems =
getDolGlobalString(
'DONT_INCLUDE_COMPLETED_ELEMENTS_LINKS');
10467 if (is_object(
$object->thirdparty) && !empty(
$object->thirdparty->id) &&
$object->thirdparty->id > 0) {
10468 $listofidcompanytoscan = (int)
$object->thirdparty->id;
10470 $listofidcompanytoscan .=
',' . (int)
$object->thirdparty->parent;
10473 include_once DOL_DOCUMENT_ROOT .
'/projet/class/project.class.php';
10474 $tmpproject =
new Project($this->db);
10475 $tmpproject->fetch(
$object->fk_project);
10476 if ($tmpproject->socid > 0 && ($tmpproject->socid !=
$object->thirdparty->id)) {
10477 $listofidcompanytoscan .=
',' . (int) $tmpproject->socid;
10479 unset($tmpproject);
10482 $possiblelinks = array(
10486 'label' =>
'LinkToProposal',
10487 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"propal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'propal') .
')'.($dontIncludeCompletedItems ?
' AND t.fk_statut < 4' :
''),
10489 'shipping' => array(
10492 'label' =>
'LinkToExpedition',
10493 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"expedition as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'shipping') .
')'.($dontIncludeCompletedItems ?
' AND t.fk_statut < 2' :
''),
10498 'label' =>
'LinkToOrder',
10499 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"commande as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'commande') .
')'.($dontIncludeCompletedItems ?
' AND t.facture < 1' :
''),
10500 'linkname' =>
'commande',
10501 'subscription' => array(
10504 'label' =>
'LinkToMemberSubscription',
10505 'sql' =>
"SELECT a.fk_soc as socid, CONCAT(a.firstname, ' ', a.lastname) as name, a.entity as client, sub.rowid, sub.note as ref, '' as ref_client, sub.subscription as total_ht FROM " . $this->db->prefix() .
"adherent as a, " . $this->db->prefix() .
"subscription as sub WHERE sub.fk_adherent = a.rowid AND a.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND a.entity IN (' .
getEntity(
'subscription') .
')',
10506 'linkname' =>
'subscription'),
10508 'invoice' => array(
10511 'label' =>
'LinkToInvoice',
10512 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"facture as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'invoice') .
')'.($dontIncludeCompletedItems ?
' AND t.paye < 1' :
''),
10513 'linkname' =>
'facture',
10515 'invoice_template' => array(
10518 'label' =>
'LinkToTemplateInvoice',
10519 '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') .
')',
10521 'contrat' => array(
10524 'label' =>
'LinkToContract',
10525 '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
10526 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',
10528 'fichinter' => array(
10531 'label' =>
'LinkToIntervention',
10532 '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') .
')',
10534 'supplier_proposal' => array(
10537 'label' =>
'LinkToSupplierProposal',
10538 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, '' as ref_supplier, t.total_ht FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"supplier_proposal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'supplier_proposal') .
')'.($dontIncludeCompletedItems ?
' AND t.fk_statut < 4' :
''),
10540 'order_supplier' => array(
10543 'label' =>
'LinkToSupplierOrder',
10544 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"commande_fournisseur as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'commande_fournisseur') .
')'.($dontIncludeCompletedItems ?
' AND t.billed < 1' :
''),
10546 'invoice_supplier' => array(
10548 'perms' => 1,
'label' =>
'LinkToSupplierInvoice',
10549 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"facture_fourn as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'facture_fourn') .
')'.($dontIncludeCompletedItems ?
' AND t.paye < 1' :
''),
10554 'label' =>
'LinkToTicket',
10555 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.track_id, '0' as total_ht FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"ticket as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'ticket') .
')'.($dontIncludeCompletedItems ?
' AND t.fk_statut < 8' :
''),
10560 'label' =>
'LinkToMo',
10561 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.rowid, '0' as total_ht FROM " . $this->db->prefix() .
"societe as s INNER JOIN " . $this->db->prefix() .
"mrp_mo as t ON t.fk_soc = s.rowid WHERE t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'mo') .
')'.($dontIncludeCompletedItems ?
' AND t.status < 3' :
''),
10566 if (
$object->table_element ==
'commande_fournisseur') {
10567 $possiblelinks[
'mo'][
'sql'] =
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.rowid, '0' as total_ht FROM ".$this->db->prefix().
"societe as s INNER JOIN ".$this->db->prefix().
'mrp_mo as t ON t.fk_soc = s.rowid WHERE t.entity IN ('.
getEntity(
'mo').
')'.($dontIncludeCompletedItems ?
' AND t.status < 3' :
'');
10568 } elseif (
$object->table_element ==
'mrp_mo') {
10569 $possiblelinks[
'order_supplier'][
'sql'] =
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".$this->db->prefix().
"societe as s, ".$this->db->prefix().
'commande_fournisseur as t WHERE t.fk_soc = s.rowid AND t.entity IN ('.
getEntity(
'commande_fournisseur').
')'.($dontIncludeCompletedItems ?
' AND t.billed < 1' :
'');
10573 if (!empty($listofidcompanytoscan)) {
10575 $hookmanager->initHooks(array(
'commonobject'));
10576 $parameters = array(
'listofidcompanytoscan' => $listofidcompanytoscan,
'possiblelinks' => $possiblelinks);
10577 $reshook = $hookmanager->executeHooks(
'showLinkToObjectBlock', $parameters,
$object, $action);
10580 if (empty($reshook)) {
10581 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
10582 $possiblelinks = array_merge($possiblelinks, $hookmanager->resArray);
10584 } elseif ($reshook > 0) {
10585 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
10586 $possiblelinks = $hookmanager->resArray;
10590 if (!empty($possiblelinks)) {
10591 $object->fetchObjectLinked();
10595 $htmltoenteralink =
'';
10596 foreach ($possiblelinks as $key => $possiblelink) {
10598 if (empty($possiblelink[
'enabled'])) {
10605 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $key, $regs)) {
10607 $module = $regs[2];
10610 if (!empty($possiblelink[
'perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || !in_array($key, $excludelinksto))) {
10611 $htmltoenteralink .=
'<div id="' . $key .
'list"' . (empty($conf->use_javascript_ajax) ?
'' :
' style="display:none"') .
'>';
10615 $htmltoenteralink .=
'<br>'.
"\n";
10616 $htmltoenteralink .=
'<!-- form to add a link from anywhere -->'.
"\n";
10617 $htmltoenteralink .=
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinkedbyref' . $key .
'">';
10618 $htmltoenteralink .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
10619 $htmltoenteralink .=
'<input type="hidden" name="action" value="addlinkbyref">';
10620 $htmltoenteralink .=
'<input type="hidden" name="id" value="' .
$object->id .
'">';
10621 $htmltoenteralink .=
'<input type="hidden" name="addlink" value="' . $key .(!empty($module) ?
'@'.$module :
'').
'">';
10622 $htmltoenteralink .=
'<table class="noborder">';
10623 $htmltoenteralink .=
'<tr class="liste_titre">';
10625 $htmltoenteralink .=
'<td class="center"><input type="text" placeholder="'.dol_escape_htmltag($langs->trans(
"Ref")).
'" name="reftolinkto" value="' .
dol_escape_htmltag(
GETPOST(
'reftolinkto',
'alpha')) .
'"> ';
10626 $htmltoenteralink .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
'ToLink') .
'"> ';
10627 $htmltoenteralink .=
'<input type="submit" class="button smallpaddingimp" name="cancel" value="' . $langs->trans(
'Cancel') .
'"></td>';
10628 $htmltoenteralink .=
'</tr>';
10629 $htmltoenteralink .=
'</table>';
10630 $htmltoenteralink .=
'</form>';
10633 $sql = $possiblelink[
'sql'];
10635 $resqllist = $this->db->query($sql);
10637 $num = $this->db->num_rows($resqllist);
10643 $htmltoenteralink .=
'<br>';
10645 $htmltoenteralink .=
'<!-- form to add a link from object to same thirdparty -->'.
"\n";
10646 $htmltoenteralink .=
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinked' . $key .
'">';
10647 $htmltoenteralink .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
10648 $htmltoenteralink .=
'<input type="hidden" name="action" value="addlink">';
10649 $htmltoenteralink .=
'<input type="hidden" name="id" value="' .
$object->id .
'">';
10650 $htmltoenteralink .=
'<input type="hidden" name="addlink" value="' . $key . (!empty($module) ?
'@'.$module :
'').
'">';
10651 $htmltoenteralink .=
'<table class="noborder">';
10652 $htmltoenteralink .=
'<tr class="liste_titre">';
10653 $htmltoenteralink .=
'<td class="nowrap"></td>';
10654 $htmltoenteralink .=
'<td>' . $langs->trans(
"Ref") .
'</td>';
10655 $htmltoenteralink .=
'<td>' . $langs->trans(
"RefCustomer") .
'</td>';
10656 $htmltoenteralink .=
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
10657 $htmltoenteralink .=
'<td>' . $langs->trans(
"Company") .
'</td>';
10658 $htmltoenteralink .=
'</tr>';
10659 while ($i < $num) {
10660 $objp = $this->db->fetch_object($resqllist);
10661 $alreadylinked =
false;
10662 if (!empty(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key])) {
10663 if (in_array($objp->rowid, array_values(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key]))) {
10664 $alreadylinked =
true;
10667 $htmltoenteralink .=
'<tr class="oddeven">';
10668 $htmltoenteralink .=
'<td>';
10669 if ($alreadylinked) {
10670 $htmltoenteralink .=
img_picto(
'',
'link');
10672 $htmltoenteralink .=
'<input type="checkbox" name="idtolinkto[' . $key .
'_' . $objp->rowid .
']" id="' . $key .
'_' . $objp->rowid .
'" value="' . $objp->rowid .
'">';
10674 $htmltoenteralink .=
'</td>';
10675 $htmltoenteralink .=
'<td><label for="' . $key .
'_' . $objp->rowid .
'">' . $objp->ref .
'</label></td>';
10676 $htmltoenteralink .=
'<td>' . (!empty($objp->ref_client) ? $objp->ref_client : (!empty($objp->ref_supplier) ? $objp->ref_supplier :
'')) .
'</td>';
10677 $htmltoenteralink .=
'<td class="right">';
10678 if ($possiblelink[
'label'] ==
'LinkToContract') {
10679 $htmltoenteralink .= $form->textwithpicto(
'', $langs->trans(
"InformationOnLinkToContract")) .
' ';
10681 $htmltoenteralink .=
'<span class="amount">' . (isset($objp->total_ht) ?
price($objp->total_ht) :
'') .
'</span>';
10682 $htmltoenteralink .=
'</td>';
10683 $htmltoenteralink .=
'<td>' . $objp->name .
'</td>';
10684 $htmltoenteralink .=
'</tr>';
10687 $htmltoenteralink .=
'</table>';
10688 $htmltoenteralink .=
'<div class="center">';
10690 $htmltoenteralink .=
'<input type="submit" class="button valignmiddle marginleftonly marginrightonly smallpaddingimp" value="' . $langs->trans(
'ToLink') .
'">';
10692 if (empty($conf->use_javascript_ajax)) {
10693 $htmltoenteralink .=
'<input type="submit" class="button button-cancel marginleftonly marginrightonly smallpaddingimp" name="cancel" value="' . $langs->trans(
"Cancel") .
'"></div>';
10695 $htmltoenteralink .=
'<input type="submit" onclick="jQuery(\'#' . $key .
'list\').toggle(); return false;" class="button button-cancel marginleftonly marginrightonly smallpaddingimp" name="cancel" value="' . $langs->trans(
"Cancel") .
'"></div>';
10697 $htmltoenteralink .=
'</form>';
10700 $this->db->free($resqllist);
10704 $htmltoenteralink .=
'</div>';
10709 $linktoelemlist .=
'<li><a href="#linkto' . $key .
'" class="linkto dropdowncloseonclick" rel="' . $key .
'">' . $langs->trans($possiblelink[
'label']) .
' (' . $num .
')</a></li>';
10712 $linktoelemlist .=
'<li><span class="linktodisabled">' . $langs->trans($possiblelink[
'label']) .
' (0)</span></li>';
10717 if ($linktoelemlist) {
10719 <dl class="dropdown" id="linktoobjectname">
10721 if (!empty($conf->use_javascript_ajax)) {
10722 $linktoelem .=
'<dt><a href="#linktoobjectname"><span class="fas fa-link paddingrightonly"></span>' . $langs->trans(
"LinkTo") .
'...</a></dt>';
10724 $linktoelem .=
'<dd>
10725 <div class="multiselectlinkto">
10726 <ul class="ulselectedfields">' . $linktoelemlist .
'
10735 if (!empty($conf->use_javascript_ajax)) {
10736 print
'<!-- Add js to show linkto box -->
10737 <script nonce="' .
getNonce() .
'">
10738 jQuery(document).ready(function() {
10739 jQuery(".linkto").click(function() {
10740 console.log("We choose to show/hide links for rel="+jQuery(this).attr(\'rel\')+" so #"+jQuery(this).attr(\'rel\')+"list");
10741 jQuery("#"+jQuery(this).attr(\'rel\')+"list").toggle();
10749 return array(
'linktoelem' => $linktoelem,
'htmltoenteralink' => $htmltoenteralink);
10751 print $htmltoenteralink;
10754 return $linktoelem;
10771 public function selectyesno($htmlname, $value =
'', $option = 0, $disabled =
false, $useempty = 0, $addjscombo = 0, $morecss =
'yesno width75', $labelyes =
'Yes', $labelno =
'No')
10782 $disabled = ($disabled ?
' disabled' :
'');
10784 $resultyesno =
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'"' . $disabled .
'>' .
"\n";
10786 $resultyesno .=
'<option value="-1"' . (($value < 0) ?
' selected' :
'') .
'> </option>' .
"\n";
10788 if ((
"$value" ==
'yes') || ($value == 1)) {
10789 $resultyesno .=
'<option value="' . $yes .
'" selected>' . $langs->trans($labelyes) .
'</option>' .
"\n";
10790 $resultyesno .=
'<option value="' . $no .
'">' . $langs->trans($labelno) .
'</option>' .
"\n";
10792 $selected = (($useempty && $value !=
'0' && $value !=
'no') ?
'' :
' selected');
10793 $resultyesno .=
'<option value="' . $yes .
'">' . $langs->trans($labelyes) .
'</option>' .
"\n";
10794 $resultyesno .=
'<option value="' . $no .
'"' . $selected .
'>' . $langs->trans($labelno) .
'</option>' .
"\n";
10796 $resultyesno .=
'</select>' .
"\n";
10799 $resultyesno .=
ajax_combobox($htmlname, array(), 0, 0,
'resolve', ($useempty < 0 ? (
string) $useempty :
'-1'), $morecss);
10802 return $resultyesno;
10819 $sql =
"SELECT rowid, label";
10820 $sql .=
" FROM " . $this->db->prefix() .
"export_model";
10821 $sql .=
" WHERE type = '" . $this->db->escape($type) .
"'";
10822 $sql .=
" ORDER BY rowid";
10823 $result = $this->db->query($sql);
10825 print
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
10827 print
'<option value="-1"> </option>';
10830 $num = $this->db->num_rows($result);
10832 while ($i < $num) {
10833 $obj = $this->db->fetch_object($result);
10834 if ($selected == $obj->rowid) {
10835 print
'<option value="' . $obj->rowid .
'" selected>';
10837 print
'<option value="' . $obj->rowid .
'">';
10867 public function showrefnav(
$object, $paramid, $morehtml =
'', $shownav = 1, $fieldid =
'rowid', $fieldref =
'ref', $morehtmlref =
'', $moreparam =
'', $nodbprefix = 0, $morehtmlleft =
'', $morehtmlstatus =
'', $morehtmlright =
'')
10869 global $conf, $langs, $hookmanager, $extralanguages;
10872 if (empty($fieldid)) {
10873 $fieldid =
'rowid';
10875 if (empty($fieldref)) {
10880 $addgendertxt =
'';
10881 if (property_exists(
$object,
'gender') && !empty(
$object->gender)) {
10882 $addgendertxt =
' ';
10885 $addgendertxt .=
'<i class="fas fa-mars valignmiddle"></i>';
10888 $addgendertxt .=
'<i class="fas fa-venus valignmiddle"></i>';
10891 $addgendertxt .=
'<i class="fas fa-transgender valignmiddle"></i>';
10897 if (is_object($hookmanager)) {
10898 $parameters = array(
'showrefnav' =>
true);
10899 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters,
$object);
10900 if (!empty($hookmanager->resPrint)) {
10901 if (empty(
$object->next_prev_filter) && preg_match(
'/^\s*AND/i', $hookmanager->resPrint)) {
10902 $object->next_prev_filter = preg_replace(
'/^\s*AND\s*/i',
'', $hookmanager->resPrint);
10903 } elseif (!empty(
$object->next_prev_filter) && !preg_match(
'/^\s*AND/i', $hookmanager->resPrint)) {
10904 $object->next_prev_filter .=
' AND '.$hookmanager->resPrint;
10906 $object->next_prev_filter .= $hookmanager->resPrint;
10911 $previous_ref = $next_ref =
'';
10914 $object->load_previous_next_ref((isset(
$object->next_prev_filter) ?
$object->next_prev_filter :
''), $fieldid, $nodbprefix);
10916 $navurl = $_SERVER[
"PHP_SELF"];
10919 if ($paramid ==
'api_token_card') {
10920 if (preg_match(
'/\/user\/api_token/', $navurl)) {
10921 $navurl = preg_replace(
'/card/',
'list', $navurl);
10927 if ($paramid ==
'project_ref') {
10928 if (preg_match(
'/\/tasks\/(task|contact|note|document)\.php/', $navurl)) {
10929 $navurl = preg_replace(
'/\/tasks\/(task|contact|time|note|document)\.php/',
'/tasks.php', $navurl);
10934 $previous_ref =
$object->ref_previous ?
'<a accesskey="p" alt="'.dol_escape_htmltag($langs->trans(
"Previous")).
'" title="' . $conf->browser->stringforfirstkey .
' p" class="classfortooltip reposition" href="' . $navurl .
'?' . $paramid .
'=' . urlencode(
$object->ref_previous) . $moreparam .
'"><i class="fa fa-chevron-left"></i></a>' :
'<span class="inactive"><i class="fa fa-chevron-left opacitymedium"></i></span>';
10935 $next_ref =
$object->ref_next ?
'<a accesskey="n" alt="'.dol_escape_htmltag($langs->trans(
"Next")).
'" title="' . $conf->browser->stringforfirstkey .
' n" class="classfortooltip reposition" href="' . $navurl .
'?' . $paramid .
'=' . urlencode(
$object->ref_next) . $moreparam .
'"><i class="fa fa-chevron-right"></i></a>' :
'<span class="inactive"><i class="fa fa-chevron-right opacitymedium"></i></span>';
10939 $ret .=
'<!-- Start banner content --><div style="vertical-align: middle">';
10942 if ($morehtmlright) {
10943 $ret .=
'<div class="inline-block floatleft">' . $morehtmlright .
'</div>';
10946 if ($previous_ref || $next_ref || $morehtml) {
10947 $ret .=
'<div class="pagination paginationref"><ul class="right">';
10949 if ($morehtml &&
getDolGlobalInt(
'MAIN_OPTIMIZEFORTEXTBROWSER') < 2) {
10950 $ret .=
'<!-- morehtml --><li class="noborder litext' . (($shownav && $previous_ref && $next_ref) ?
' clearbothonsmartphone' :
'') .
'">' . $morehtml .
'</li>';
10952 if ($shownav && ($previous_ref || $next_ref)) {
10953 $ret .=
'<li class="pagination">' . $previous_ref .
'</li>';
10954 $ret .=
'<li class="pagination">' . $next_ref .
'</li>';
10956 if ($previous_ref || $next_ref || $morehtml) {
10957 $ret .=
'</ul></div>';
10961 $parameters = array(
'morehtmlstatus' => $morehtmlstatus);
10962 $reshook = $hookmanager->executeHooks(
'moreHtmlStatus', $parameters,
$object);
10963 if (empty($reshook)) {
10964 $morehtmlstatus .= $hookmanager->resPrint;
10966 $morehtmlstatus = $hookmanager->resPrint;
10968 if ($morehtmlstatus) {
10969 $ret .=
'<!-- status --><div class="statusref">' . $morehtmlstatus .
'</div>';
10972 $parameters = array();
10973 $reshook = $hookmanager->executeHooks(
'moreHtmlRef', $parameters,
$object);
10974 if (empty($reshook)) {
10975 $morehtmlref .= $hookmanager->resPrint;
10976 } elseif ($reshook > 0) {
10977 $morehtmlref = $hookmanager->resPrint;
10981 if ($morehtmlleft) {
10982 if ($conf->browser->layout ==
'phone') {
10983 $ret .=
'<!-- morehtmlleft --><div class="floatleft">' . $morehtmlleft .
'</div>';
10985 $ret .=
'<!-- morehtmlleft --><div class="inline-block floatleft">' . $morehtmlleft .
'</div>';
10990 $ret .=
'<!-- Ref or ID --><div class="inline-block floatleft valignmiddle maxwidth750 marginbottomonly refid' . (($shownav && ($previous_ref || $next_ref)) ?
' refidpadding' :
'') .
'">';
10993 if (
$object->element ==
'societe') {
10994 $ret .=
'<span class="valignmiddle">'.dol_htmlentities((
string)
$object->name).
'</span>';
10997 $arrayoflangcode = array();
11002 if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
11003 if (!is_object($extralanguages)) {
11004 include_once DOL_DOCUMENT_ROOT .
'/core/class/extralanguages.class.php';
11007 $extralanguages->fetch_name_extralanguages(
'societe');
11011 if (!empty($extralanguages->attributes[
'societe']) && !empty($extralanguages->attributes[
'societe'][
'name'])) {
11012 $object->fetchValuesForExtraLanguages();
11016 foreach ($arrayoflangcode as $extralangcode) {
11018 if (
$object->array_languages[
'name'][$extralangcode]) {
11019 $htmltext .=
$object->array_languages[
'name'][$extralangcode];
11021 $htmltext .=
'<span class="opacitymedium">' . $langs->trans(
"SwitchInEditModeToAddTranslation") .
'</span>';
11024 $ret .=
'<!-- Show translations of name -->' .
"\n";
11025 $ret .= $this->textwithpicto(
'', $htmltext, -1,
'language',
'opacitymedium paddingleft');
11028 } elseif (
$object->element ==
'member') {
11029 '@phan-var-force Adherent $object';
11030 $ret .=
$object->ref .
'<br>';
11031 $fullname =
$object->getFullName($langs);
11033 $ret .=
'<span class="valignmiddle">'.dol_htmlentities((
string)
$object->societe) . ((!empty($fullname) &&
$object->societe != $fullname) ?
' (' .
dol_htmlentities($fullname) . $addgendertxt .
')' :
'').
'</span>';
11035 $ret .=
'<span class="valignmiddle">'.dol_htmlentities($fullname) . $addgendertxt . ((!empty(
$object->societe) &&
$object->societe != $fullname) ?
' (' .
dol_htmlentities((
string)
$object->societe) .
')' :
'').
'</span>';
11037 } elseif (in_array(
$object->element, array(
'contact',
'user'))) {
11038 $ret .=
'<span class="valignmiddle">'.dol_htmlentities(
$object->getFullName($langs)).
'</span>'.$addgendertxt;
11039 } elseif (
$object->element ==
'usergroup') {
11041 } elseif (in_array(
$object->element, array(
'action',
'agenda'))) {
11042 '@phan-var-force ActionComm $object';
11044 } elseif (in_array(
$object->element, array(
'adherent_type'))) {
11046 } elseif (
$object->element ==
'ecm_directories') {
11048 } elseif (
$object->element ==
'accountingbookkeeping' && !empty(
$object->context[
'mode']) &&
$object->context[
'mode'] ==
'_tmp') {
11049 $ret .=
'<span class="valignmiddle">'.$langs->trans(
"Draft").
'</span>';
11050 } elseif ($fieldref !=
'none') {
11051 $ret .=
'<span class="valignmiddle">'.dol_htmlentities(!empty(
$object->$fieldref) ?
$object->$fieldref :
"").
'</span>';
11053 if ($morehtmlref) {
11055 if (substr($morehtmlref, 0, 4) !=
'<div') {
11059 $ret .=
'<!-- morehtmlref -->'.$morehtmlref;
11064 $ret .=
'</div><!-- End banner content -->';
11083 if (empty(
$object->barcode)) {
11088 if (empty(
$object->barcode_type_code) || empty(
$object->barcode_type_coder)) {
11090 $result =
$object->fetchBarCode();
11093 return '<!-- ErrorFetchBarcode -->';
11098 $url = DOL_URL_ROOT .
'/viewimage.php?modulepart=barcode&generator=' . urlencode(
$object->barcode_type_coder) .
'&code=' . urlencode(
$object->barcode) .
'&encoding=' . urlencode(
$object->barcode_type_code);
11099 $out =
'<!-- url barcode = ' . $url .
' -->';
11100 $out .=
'<img src="' . $url .
'"' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
'>';
11123 public static function showphoto($modulepart,
$object, $width = 100, $height = 0, $caneditfield = 0, $cssclass =
'photowithmargin', $imagesize =
'', $addlinktofullsize = 1, $cache = 0, $forcecapture =
'', $noexternsourceoverwrite = 0, $usesharelinkifavailable = 0)
11125 global $conf, $db, $langs;
11127 $entity = (empty(
$object->entity) ? $conf->entity :
$object->entity);
11132 $originalfile =
'';
11136 if ($modulepart ==
'societe') {
11137 $dir = $conf->societe->multidir_output[$entity];
11140 if ((
string) $imagesize ==
'mini') {
11142 } elseif ((
string) $imagesize ==
'small') {
11151 } elseif ($modulepart ==
'contact') {
11152 $dir = $conf->societe->multidir_output[$entity] .
'/contact';
11154 if (!empty($photo)) {
11156 if ((
string) $imagesize ==
'mini') {
11158 } elseif ((
string) $imagesize ==
'small') {
11163 $originalfile =
get_exdir(0, 0, 0, 0,
$object,
'contact') .
'photos/' . $photo;
11168 } elseif ($modulepart ==
'userphoto') {
11169 $dir = $conf->user->dir_output;
11171 if (!empty($photo)) {
11173 if ((
string) $imagesize ==
'mini') {
11175 } elseif ((
string) $imagesize ==
'small') {
11180 $originalfile =
get_exdir(0, 0, 0, 0,
$object,
'user') .
'photos/' . $photo;
11184 $altfile =
$object->id .
".jpg";
11188 } elseif ($modulepart ==
'memberphoto') {
11189 $dir = $conf->adherent->dir_output;
11191 if (!empty($photo)) {
11193 if ((
string) $imagesize ==
'mini') {
11195 } elseif ((
string) $imagesize ==
'small') {
11200 $originalfile =
get_exdir(0, 0, 0, 0,
$object,
'member') .
'photos/' . $photo;
11204 $altfile =
$object->id .
".jpg";
11211 if ($modulepart !=
"unknown" && method_exists(
$object,
'getDataToShowPhoto')) {
11212 $tmpdata =
$object->getDataToShowPhoto($modulepart, $imagesize);
11214 $dir = $tmpdata[
'dir'];
11215 $file = $tmpdata[
'file'];
11216 $originalfile = $tmpdata[
'originalfile'];
11217 $altfile = $tmpdata[
'altfile'];
11218 $email = $tmpdata[
'email'];
11219 $capture = $tmpdata[
'capture'];
11223 if ($forcecapture) {
11224 $capture = $forcecapture;
11230 if ($file && file_exists($dir .
"/" . $file)) {
11231 if ($addlinktofullsize) {
11233 if ($urladvanced) {
11234 $ret .=
'<a href="' . $urladvanced .
'">';
11236 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
11241 if ($usesharelinkifavailable) {
11243 $relativefileforecm = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT.
'/',
'/').
'/',
'', $dir.
'/'.$originalfile);
11245 require_once DOL_DOCUMENT_ROOT .
'/ecm/class/ecmfiles.class.php';
11247 $ecmfiles->fetch(0,
'', $relativefileforecm);
11249 $sharekey = (string) $ecmfiles->share;
11252 if (!empty($sharekey)) {
11253 $ret .=
'<img alt="" class="photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
' photologo' . (preg_replace(
'/[^a-z]/i',
'_', $file)) .
'" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="' . DOL_URL_ROOT .
'/viewimage.php?hashp=' . urlencode($sharekey) .
'&cache=' . urlencode((
string) $cache) .
'">';
11255 $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 .
'">';
11257 if ($addlinktofullsize) {
11260 } elseif ($altfile && file_exists($dir .
"/" . $altfile)) {
11261 if ($addlinktofullsize) {
11263 if ($urladvanced) {
11264 $ret .=
'<a href="' . $urladvanced .
'">';
11266 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
11269 $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 .
'">';
11270 if ($addlinktofullsize) {
11274 $nophoto =
'/public/theme/common/nophoto.png';
11275 $defaultimg =
'identicon';
11276 if (in_array($modulepart, array(
'societe',
'userphoto',
'contact',
'memberphoto'))) {
11277 if ($modulepart ==
'societe' || ($modulepart ==
'memberphoto' && !empty(
$object->morphy) && strpos(
$object->morphy,
'mor') !==
false)) {
11278 $nophoto =
'company';
11280 $nophoto =
'/public/theme/common/user_anonymous.png';
11282 $nophoto =
'/public/theme/common/user_man.png';
11285 $nophoto =
'/public/theme/common/user_woman.png';
11290 if (
isModEnabled(
'gravatar') && $email && empty($noexternsourceoverwrite)) {
11292 $ret .=
'<!-- Put link to gravatar -->';
11293 $ret .=
'<img class="gravatar photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" title="'.
dolPrintHTMLForAttribute(
'Gravatar avatar - '.$email).
'" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="https://www.gravatar.com/avatar/' .
dol_hash(strtolower(trim($email)),
'sha256', 1) .
'?s=' . $width .
'&d=' . $defaultimg .
'">';
11295 if ($nophoto ==
'company') {
11296 $ret .=
'<div class="divforspanimg valignmiddle center photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
'>' .
img_picto(
'',
'company') .
'</div>';
11299 $ret .=
'<img class="photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="' . DOL_URL_ROOT . $nophoto .
'">';
11304 if ($caneditfield) {
11308 $ret .=
'<table class="nobordernopadding centpercent">';
11310 $ret .=
'<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> <label for="photodelete">' . $langs->trans(
"Delete") .
'</label><br><br></td></tr>';
11312 $ret .=
'<tr><td class="tdoverflow">';
11314 $maxmin = $maxfilesizearray[
'maxmin'];
11316 $ret .=
'<input type="hidden" name="MAX_FILE_SIZE" value="' . ($maxmin * 1024) .
'">';
11318 $ret .=
'<input type="file" class="flat maxwidth200onsmartphone" name="photo" id="photoinput" accept="image/*"' . ($capture ?
' capture="' .
dolPrintHTMLForAttribute($capture) .
'"' :
'') .
'>';
11319 $ret .=
'</td></tr>';
11320 $ret .=
'</table>';
11345 public function select_dolgroups($selected = 0, $htmlname =
'groupid', $show_empty = 0, $exclude =
'', $disabled = 0, $include =
'', $enableonly = array(), $force_entity =
'0', $multiple =
false, $morecss =
'minwidth200')
11348 global $conf, $user, $langs;
11351 $excludeGroups =
null;
11352 if (is_array($exclude)) {
11353 $excludeGroups = implode(
",", $exclude);
11356 $includeGroups =
null;
11357 if (is_array($include)) {
11358 $includeGroups = implode(
",", $include);
11361 if (!is_array($selected)) {
11362 $selected = array($selected);
11368 $sql =
"SELECT ug.rowid, ug.nom as name";
11369 if (
isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
11370 $sql .=
", e.label";
11372 $sql .=
" FROM " . $this->db->prefix() .
"usergroup as ug ";
11373 if (
isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
11374 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid=ug.entity";
11375 if ($force_entity) {
11376 $sql .=
" WHERE ug.entity IN (0, " . $force_entity .
")";
11378 $sql .=
" WHERE ug.entity IS NOT NULL";
11381 $sql .=
" WHERE ug.entity IN (0, " . $conf->entity .
")";
11383 if (is_array($exclude) && $excludeGroups) {
11384 $sql .=
" AND ug.rowid NOT IN (" . $this->db->sanitize($excludeGroups) .
")";
11386 if (is_array($include) && $includeGroups) {
11387 $sql .=
" AND ug.rowid IN (" . $this->db->sanitize($includeGroups) .
")";
11389 $sql .=
" ORDER BY ug.nom ASC";
11391 dol_syslog(get_class($this) .
"::select_dolgroups", LOG_DEBUG);
11392 $resql = $this->db->query($sql);
11395 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
11397 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
11399 $num = $this->db->num_rows($resql);
11402 if ($show_empty && !$multiple) {
11403 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'> </option>' .
"\n";
11406 while ($i < $num) {
11407 $obj = $this->db->fetch_object($resql);
11409 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
11413 $label = $obj->name;
11414 $labelhtml = $obj->name;
11416 $label .=
" (" . $obj->label .
")";
11417 $labelhtml .=
' <span class="opacitymedium">(' . $obj->label .
')</span>';
11420 $out .=
'<option value="' . $obj->rowid .
'"';
11421 if ($disableline) {
11422 $out .=
' disabled';
11424 if ((isset($selected[0]) && is_object($selected[0]) && $selected[0]->
id == $obj->rowid)
11425 || ((!isset($selected[0]) || !is_object($selected[0])) && !empty($selected) && in_array($obj->rowid, $selected))) {
11426 $out .=
' selected';
11428 $out .=
' data-html="'.dol_escape_htmltag($labelhtml).
'"';
11431 $out .=
'</option>';
11436 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'></option>' .
"\n";
11438 $out .=
'<option value="" disabled>' . $langs->trans(
"NoUserGroupDefined") .
'</option>';
11440 $out .=
'</select>';
11459 $out =
'<div class="nowraponall">';
11460 $out .=
'<button type="submit" class="liste_titre button_search reposition" name="button_search_x" value="x"><span class="fas fa-search"></span></button>';
11461 $out .=
'<button type="submit" class="liste_titre button_removefilter reposition" name="button_removefilter_x" value="x"><span class="fas fa-times"></span></button>';
11475 public function showCheckAddButtons($cssclass =
'checkforaction', $calljsfunction = 0, $massactionname =
"massaction")
11481 if (!empty($conf->use_javascript_ajax)) {
11482 $out .=
'<div class="inline-block checkallactions"><input type="checkbox" id="' . $cssclass .
's" name="' . $cssclass .
's" class="checkallactions"></div>';
11484 $out .=
'<script nonce="' .
getNonce() .
'">
11485 $(document).ready(function() {
11486 $("#' . $cssclass .
's").click(function() {
11487 if($(this).is(\':checked\')){
11488 console.log("We check all ' . $cssclass .
' and trigger the change method");
11489 $(".' . $cssclass .
'").prop(\'checked\', true).trigger(\'change\');
11493 console.log("We uncheck all");
11494 $(".' . $cssclass .
'").prop(\'checked\', false).trigger(\'change\');
11496 if ($calljsfunction) {
11497 $out .=
'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0, "' . $massactionname .
'", "' . $cssclass .
'"); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }';
11501 $(".' . $cssclass .
'").change(function() {
11502 console.log("We check and change the tr class highlight after a change on .'.$cssclass.
'");
11503 var $row = $(this).closest("tr");
11505 var anyChecked = $row.find(\'input[type="checkbox"].checkforselect:checked\').length > 0;
11506 console.log("anychecked="+anyChecked);
11508 $row.removeClass("highlight");
11510 $row.addClass("highlight");
11532 $out = $this->showFilterButtons();
11533 if ($addcheckuncheckall) {
11534 $out .= $this->showCheckAddButtons($cssclass, $calljsfunction, $massactionname);
11552 public function selectExpenseCategories($selected =
'', $htmlname =
'fk_c_exp_tax_cat', $useempty = 0, $excludeid = array(), $target =
'', $default_selected = 0, $params = array(), $info_admin = 1)
11554 global $langs, $user;
11557 $sql =
"SELECT rowid, label FROM " . $this->db->prefix() .
"c_exp_tax_cat WHERE active = 1";
11558 $sql .=
" AND entity IN (0," .
getEntity(
'exp_tax_cat') .
")";
11559 if (!empty($excludeid)) {
11560 $sql .=
" AND rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeid)) .
")";
11562 $sql .=
" ORDER BY label";
11564 $resql = $this->db->query($sql);
11566 $out =
'<select id="select_' . $htmlname .
'" name="' . $htmlname .
'" class="' . $htmlname .
' flat minwidth75imp maxwidth200">';
11568 $out .=
'<option value="0"> </option>';
11571 while ($obj = $this->db->fetch_object($resql)) {
11572 $out .=
'<option ' . ($selected == $obj->rowid ?
'selected="selected"' :
'') .
' value="' . $obj->rowid .
'">' . $langs->trans($obj->label) .
'</option>';
11574 $out .=
'</select>';
11577 if (!empty($htmlname) && $user->admin && $info_admin) {
11578 $out .=
' ' .
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
11581 if (!empty($target)) {
11582 $sql =
"SELECT c.id FROM " . $this->db->prefix() .
"c_type_fees as c WHERE c.code = 'EX_KME' AND c.active = 1";
11583 $resql = $this->db->query($sql);
11585 if ($this->db->num_rows($resql) > 0) {
11586 $obj = $this->db->fetch_object($resql);
11587 $out .=
'<script nonce="' .
getNonce() .
'">
11589 $("select[name=' . $target .
']").on("change", function() {
11590 var current_val = $(this).val();
11591 if (current_val == ' . $obj->id .
') {';
11592 if (!empty($default_selected) || !empty($selected)) {
11593 $out .=
'$("select[name=' . $htmlname .
']").val("' . ($default_selected > 0 ? $default_selected : $selected) .
'");';
11597 $("select[name=' . $htmlname .
']").change();
11601 $("select[name=' . $htmlname .
']").change(function() {
11603 if ($("select[name=' . $target .
']").val() == ' . $obj->id .
') {
11604 // get price of kilometer to fill the unit price
11608 data: { fk_c_exp_tax_cat: $(this).val(), token: \'' .
currentToken() .
'\' },
11609 url:
"' . (DOL_URL_ROOT . '/expensereport/ajax/ajaxik.php?' . implode('&', $params)) . '",
11610 }).done(
function( data, textStatus, jqXHR ) {
11612 if (typeof data.up !=
"undefined") {
11613 $(
"input[name=value_unit]").val(data.up);
11614 $(
"select[name=' . $htmlname . ']").attr(
"title", data.title);
11616 $(
"input[name=value_unit]").val(
"");
11617 $(
"select[name=' . $htmlname . ']").attr(
"title",
"");
11628 dol_print_error($this->db);
11642 public function selectExpenseRanges($selected = '
', $htmlname = 'fk_range
', $useempty = 0)
11644 global $conf, $langs;
11647 $sql = "SELECT rowid, range_ik FROM " . $this->db->prefix() . "c_exp_tax_range";
11648 $sql .= " WHERE entity = " . $conf->entity . " AND active = 1";
11650 $resql = $this->db->query($sql);
11652 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
11654 $out .= '<option value=
"0"></option>
';
11657 while ($obj = $this->db->fetch_object($resql)) {
11658 $out .= '<option
' . ($selected == $obj->rowid ? 'selected=
"selected"' : '') . ' value=
"' . $obj->rowid . '">
' . price($obj->range_ik, 0, $langs, 1, 0) . '</option>
';
11660 $out .= '</select>
';
11662 dol_print_error($this->db);
11678 public function selectExpenseFees($selected = '
', $htmlname = 'fk_c_type_fees
', $useempty = 0, $allchoice = 1, $useid = 0)
11683 $sql = "SELECT id, code, label";
11684 $sql .= " FROM ".$this->db->prefix()."c_type_fees";
11685 $sql .= " WHERE active = 1";
11687 $resql = $this->db->query($sql);
11689 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
11691 $out .= '<option value=
"0"></option>
';
11694 $out .= '<option value=
"-1">
' . $langs->trans('AllExpenseReport
') . '</option>
';
11702 while ($obj = $this->db->fetch_object($resql)) {
11703 $key = $langs->trans($obj->code);
11704 $out .= '<option
' . ($selected == $obj->{$field} ? 'selected=
"selected"' : '') . ' value=
"' . $obj->{$field} . '">
' . ($key != $obj->code ? $key : $obj->label) . '</option>
';
11706 $out .= '</select>
';
11708 $out .= ajax_combobox('select_
'.$htmlname);
11710 dol_print_error($this->db);
11734 public function selectInvoiceForTimeProject($socid = -1, $selected = '
', $htmlname = 'invoiceid
', $maxlength = 24, $option_only = 0, $show_empty = '1
', $discard_closed = 0, $forcefocus = 0, $disabled = 0, $morecss = 'maxwidth500
', $projectsListId = '', $showproject = 'all
', $usertofilter = null)
11736 global $user, $conf, $langs;
11738 require_once DOL_DOCUMENT_ROOT . '/projet/
class/project.class.php
';
11740 if (is_null($usertofilter)) {
11741 $usertofilter = $user;
11746 $hideunselectables = false;
11747 if (getDolGlobalString('INVOICE_HIDE_UNSELECTABLES
')) {
11748 $hideunselectables = true;
11751 if (empty($projectsListId)) {
11752 if (!$usertofilter->hasRight('projet
', 'all
', 'lire
')) {
11753 $projectstatic = new Project($this->db);
11754 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1);
11758 // Search all projects
11759 $sql = "SELECT f.rowid, f.ref as fref, 'nolabel
' as flabel, p.rowid as pid, f.ref, p.title, p.fk_soc, p.fk_statut, p.public, s.nom as name";
11760 $sql .= " FROM " . $this->db->prefix() . "facture as f";
11761 $sql .= " INNER JOIN " . $this->db->prefix() . "projet as p ON p.entity IN (" . getEntity('project
') . ") AND f.fk_projet = p.rowid";
11762 $sql .= " LEFT JOIN " . $this->db->prefix() . "societe as s ON s.rowid = p.fk_soc";
11763 $sql .= " WHERE f.fk_statut = 0"; // Draft invoices only
11764 //if ($projectsListId) $sql.= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")";
11765 //if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
11766 //if ($socid > 0) $sql.= " AND (p.fk_soc=".((int) $socid)." OR p.fk_soc IS NULL)";
11767 $sql .= " ORDER BY p.ref, f.ref ASC";
11769 $resql = $this->db->query($sql);
11771 // Use select2 selector
11772 if (!empty($conf->use_javascript_ajax)) {
11773 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
11774 $comboenhancement = ajax_combobox($htmlname, array(), 0, $forcefocus);
11775 $out .= $comboenhancement;
11776 $morecss = 'minwidth200imp maxwidth500
';
11779 if (empty($option_only)) {
11780 $out .= '<select
class=
"valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled=
"disabled"' : '') . ' id=
"' . $htmlname . '" name=
"' . $htmlname . '">
';
11782 if (!empty($show_empty)) {
11783 $out .= '<option value=
"0" class=
"optiongrey">
';
11784 if (!is_numeric($show_empty)) {
11785 $out .= $show_empty;
11789 $out .= '</option>
';
11791 $num = $this->db->num_rows($resql);
11794 while ($i < $num) {
11795 $obj = $this->db->fetch_object($resql);
11796 // 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.
11797 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$usertofilter->hasRight('societe
', 'lire
')) {
11800 if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) {
11807 if ($showproject == 'all
') {
11808 $labeltoshow .= dol_trunc($obj->ref, 18); // Invoice ref
11810 $labeltoshow .= ' -
' . $obj->name; // Soc name
11814 if ($obj->fk_statut == Project::STATUS_DRAFT) {
11816 $labeltoshow .= ' -
' . $langs->trans("Draft");
11817 } elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
11818 if ($discard_closed == 2) {
11821 $labeltoshow .= ' -
' . $langs->trans("Closed");
11822 } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
11824 $labeltoshow .= ' -
' . $langs->trans("LinkedToAnotherCompany");
11828 if (!empty($selected) && $selected == $obj->rowid) {
11829 $out .= '<option value=
"' . $obj->rowid . '" selected
';
11830 //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected
if disabled
11831 $out .=
'>' . $labeltoshow .
'</option>';
11833 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
11836 $resultat =
'<option value="' . $obj->rowid .
'"';
11838 $resultat .=
' disabled';
11843 $resultat .= $labeltoshow;
11844 $resultat .=
'</option>';
11852 if (empty($option_only)) {
11853 $out .=
'</select>';
11856 $this->db->free($resql);
11879 public function selectInvoiceRec($selected =
'', $htmlname =
'facrecid', $maxlength = 24, $option_only = 0, $show_empty =
'1', $forcefocus = 0, $disabled = 0, $morecss =
'maxwidth500')
11881 global $conf, $langs;
11887 $sql =
'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc';
11888 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'facture_rec as f';
11889 $sql .=
" WHERE f.entity IN (" .
getEntity(
'invoice') .
")";
11890 $sql .=
" ORDER BY f.titre ASC";
11892 $resql = $this->db->query($sql);
11895 if (!empty($conf->use_javascript_ajax)) {
11896 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
11897 $comboenhancement =
ajax_combobox($htmlname, array(), 0, $forcefocus);
11898 $out .= $comboenhancement;
11899 $morecss =
'minwidth200imp maxwidth500';
11902 if (empty($option_only)) {
11903 $out .=
'<select class="valignmiddle flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' id="' . $htmlname .
'" name="' . $htmlname .
'">';
11905 if (!empty($show_empty)) {
11906 $out .=
'<option value="0" class="optiongrey">';
11907 if (!is_numeric($show_empty)) {
11908 $out .= $show_empty;
11912 $out .=
'</option>';
11914 $num = $this->db->num_rows($resql);
11916 while ($obj = $this->db->fetch_object($resql)) {
11917 $labeltoshow =
dol_trunc($obj->title, 18);
11920 if (!empty($obj->suspended)) {
11922 $labeltoshow .=
' - ' . $langs->trans(
"Closed");
11926 if (!empty($selected) && $selected == $obj->rowid) {
11927 $out .=
'<option value="' . $obj->rowid .
'" selected';
11929 $out .=
'>' . $labeltoshow .
'</option>';
11931 if ($disabled && ($selected != $obj->rowid)) {
11934 $resultat =
'<option value="' . $obj->rowid .
'"';
11936 $resultat .=
' disabled';
11939 $resultat .= $labeltoshow;
11940 $resultat .=
'</option>';
11946 if (empty($option_only)) {
11947 $out .=
'</select>';
11952 $this->db->free($resql);
11955 $this->errors[] = $this->db->lasterror;
11971 public function searchComponent($arrayofcriterias, $search_component_params, $arrayofinputfieldsalreadyoutput = array(), $search_component_params_hidden =
'', $arrayoffiltercriterias = array())
11974 global $langs, $form;
11979 if ($search_component_params_hidden !=
'' && !preg_match(
'/^\(.*\)$/', $search_component_params_hidden)) {
11980 $search_component_params_hidden =
'(' . $search_component_params_hidden .
')';
11983 $ret =
'<!-- searchComponent -->';
11985 $ret .=
'<div class="divadvancedsearchfieldcomp centpercent inline-block">';
11986 $ret .=
'<a href="#" class="dropdownsearch-toggle unsetcolor">';
11987 $ret .=
'<span class="fas fa-filter linkobject boxfilter paddingright pictofixedwidth" title="' .
dol_escape_htmltag($langs->trans(
"Filters")) .
'" id="idsubimgproductdistribution"></span>';
11990 $ret .=
'<div class="divadvancedsearchfieldcompinput inline-block minwidth500 maxwidth300onsmartphone">';
11993 $ret .=
'<div id="divsearch_component_params" name="divsearch_component_params" class="noborderbottom search_component_params inline-block valignmiddle">';
11995 if ($search_component_params_hidden) {
12003 foreach ($arrayofandtags as $tmpkey => $tmpval) {
12004 $errormessage =
'';
12006 if ($errormessage) {
12007 $this->error =
'ERROR in parsing search string: '.$errormessage;
12010 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
12013 $ret .=
'<span class="marginleftonlyshort valignmiddle tagsearch" data-ufilterid="'.($tmpkey + 1).
'" data-ufilter="'.
dol_escape_htmltag($tmpval).
'">';
12014 $ret .=
'<span class="tagsearchdelete select2-selection__choice__remove" data-ufilterid="'.($tmpkey + 1).
'">x</span> ';
12026 $show_search_component_params_hidden = 1;
12027 if ($show_search_component_params_hidden) {
12028 $ret .=
'<input type="hidden" name="show_search_component_params_hidden" value="1">';
12030 $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%')) -->";
12031 $ret .=
'<input type="hidden" id="search_component_params_hidden" name="search_component_params_hidden" value="' .
dol_escape_htmltag($search_component_params_hidden) .
'">';
12036 foreach ($arrayofcriterias as $criteria) {
12037 foreach ($criteria as $criteriafamilykey => $criteriafamilyval) {
12038 if (in_array(
'search_' . $criteriafamilykey, $arrayofinputfieldsalreadyoutput)) {
12041 if (in_array($criteriafamilykey, array(
'rowid',
'ref_ext',
'entity',
'extraparams'))) {
12044 if (in_array($criteriafamilyval[
'type'], array(
'date',
'datetime',
'timestamp'))) {
12045 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_start">';
12046 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startyear">';
12047 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startmonth">';
12048 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startday">';
12049 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_end">';
12050 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endyear">';
12051 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endmonth">';
12052 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endday">';
12054 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'">';
12061 $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";
12062 $ret .=
'<input type="text" placeholder="' . $langs->trans(
"Filters") .
'" id="search_component_params_input" name="search_component_params_input" class="noborderall search_component_input" value="">';
12068 jQuery(".tagsearchdelete").click(function(e) {
12069 var filterid = $(this).parents().attr("data-ufilterid");
12070 console.log("We click to delete the criteria nb "+filterid);
12072 // Regenerate the search_component_params_hidden with all data-ufilter except the one to delete, and post the page
12073 var newparamstring = \'\';
12074 $(\'.tagsearch\').each(function(index, element) {
12075 tmpfilterid = $(this).attr("data-ufilterid");
12076 if (tmpfilterid != filterid) {
12077 // We keep this criteria
12078 if (newparamstring == \'\') {
12079 newparamstring = $(this).attr("data-ufilter");
12081 newparamstring = newparamstring + \' AND \' + $(this).attr("data-ufilter");
12085 console.log("newparamstring = "+newparamstring);
12087 jQuery("#search_component_params_hidden").val(newparamstring);
12089 // We repost the form
12090 $(this).closest(\'form\').submit();
12093 jQuery("#search_component_params_input").keydown(function(e) {
12094 console.log("We press a key on the filter field that is "+jQuery("#search_component_params_input").val());
12095 console.log(e.which);
12096 if (jQuery("#search_component_params_input").val() == "" && e.which == 8) {
12097 /* We click on back when the input field is already empty */
12098 event.preventDefault();
12099 jQuery("#divsearch_component_params .tagsearch").last().remove();
12100 /* Regenerate content of search_component_params_hidden from remaining .tagsearch */
12102 jQuery("#divsearch_component_params .tagsearch").each(function( index ) {
12106 s = s + $(this).attr("data-ufilter");
12108 console.log("New value for search_component_params_hidden = "+s);
12109 jQuery("#search_component_params_hidden").val(s);
12117 $arrayoffiltercriterias_json = json_encode($arrayoffiltercriterias);
12119 var arrayoffiltercriterias = ' . $arrayoffiltercriterias_json .
';
12123 $arrayoffilterfieldslabel = array();
12124 foreach ($arrayoffiltercriterias as $key => $val) {
12125 $arrayoffilterfieldslabel[$key][
'label'] = $val[
'label'];
12126 $arrayoffilterfieldslabel[$key][
'data-type'] = $val[
'type'];
12130 $ret .=
'<div class="search-component-assistance">';
12133 $ret .=
'<p class="assistance-title">' .
img_picto(
'',
'filter') .
' ' . $langs->trans(
'FilterAssistance') .
' </p>';
12135 $ret .=
'<p class="assistance-errors error" style="display:none">' . $langs->trans(
'AllFieldsRequired') .
' </p>';
12137 $ret .=
'<div class="operand">';
12138 $ret .= $form->selectarray(
'search_filter_field', $arrayoffilterfieldslabel,
'', $langs->trans(
"Fields"), 0, 0,
'', 0, 0, 0,
'',
'width200 combolargeelem', 1);
12141 $ret .=
'<span class="separator"></span>';
12144 $ret .=
'<div class="operator">';
12145 $ret .=
'<select class="operator-selector width150" id="operator-selector"">';
12146 $ret .=
'</select>';
12147 $ret .=
'<script>$(document).ready(function() {';
12148 $ret .=
' $(".operator-selector").select2({';
12149 $ret .=
' placeholder: \'' .
dol_escape_js($langs->transnoentitiesnoconv(
'Operator')) .
'\'';
12151 $ret .=
'});</script>';
12154 $ret .=
'<span class="separator"></span>';
12156 $ret .=
'<div class="value">';
12158 $ret .=
'<input type="text" class="flat width100 value-input" placeholder="' .
dolPrintHTML($langs->trans(
'Value')) .
'">';
12162 $ret .=
'<span class="date-one" style="display:none">';
12163 $ret .= $form->selectDate(($dateOne ? $dateOne : -1),
'dateone', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'');
12167 $ret .=
'<select class="value-selector width150" id="value-selector" style="display:none">';
12168 $ret .=
'</select>';
12170 $(document).ready(function() {
12171 $("#value-selector").select2({
12172 placeholder: "' .
dol_escape_js($langs->trans(
'Value')) .
'"
12174 $("#value-selector").hide();
12175 $("#value-selector").next(".select2-container").hide();
12181 $ret .=
'<div class="btn-div">';
12182 $ret .=
'<button class="button buttongen button-save add-filter-btn" type="button">' . $langs->trans(
"addToFilter") .
'</button>';
12193 $(document).ready(function() {
12194 $("#search_component_params_input").on("click", function() {
12195 const inputPosition = $(this).offset();
12196 const inputHeight = $(this).outerHeight();
12197 $(".search-component-assistance").css({
12198 top: inputPosition.top + inputHeight + 5 + "px",
12199 left: $("#divsearch_component_params").position().left
12200 }).slideToggle(200);
12202 $(document).on("click", function(e) {
12203 if (!$(e.target).closest("#search_component_params_input, .search-component-assistance, #ui-datepicker-div").length) {
12204 $(".search-component-assistance").hide();
12211 $(document).ready(function() {
12212 $(".search_filter_field").on("change", function() {
12213 console.log("We change search_filter_field");
12216 const selectedField = $(this).find(":selected");
12217 let fieldType = selectedField.data("type");
12218 const selectedFieldValue = selectedField.val();
12220 // If the selected field has an array of values then ask toshow the value selector instead of the value input
12221 if (arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"] !== undefined) {
12222 fieldType = "select";
12225 // If the selected field may be null then ask to append the "IsDefined" and "IsNotDefined" operators
12226 if (arrayoffiltercriterias[selectedFieldValue]["maybenull"] !== undefined) {
12229 const operators = getOperatorsForFieldType(fieldType, maybenull);
12230 const operatorSelector = $(".operator-selector");
12232 // Clear existing options
12233 operatorSelector.empty();
12235 // Populate operators
12236 Object.entries(operators).forEach(function([operator, label]) {
12237 operatorSelector.append("<option value=\'" + operator + "\'>" + label + "</option>");
12240 operatorSelector.trigger("change.select2");
12242 // Clear and hide all input elements initially
12243 $(".value-input, .dateone, .datemonth, .dateyear").val("").hide();
12244 $("#datemonth, #dateyear").val(null).trigger("change.select2");
12245 $("#dateone").datepicker("setDate", null);
12246 $(".date-one, .date-month, .date-year").hide();
12247 $("#value-selector").val("").hide();
12248 $("#value-selector").next(".select2-container").hide();
12249 $("#value-selector").val(null).trigger("change.select2");
12251 if (fieldType === "date" || fieldType === "datetime" || fieldType === "timestamp") {
12252 $(".date-one").show();
12253 } else if (arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"] !== undefined) {
12254 var arrayofkeyval = arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"];
12255 var valueSelector = $("#value-selector");
12256 valueSelector.empty();
12257 Object.entries(arrayofkeyval).forEach(function([key, val]) {
12258 valueSelector.append("<option value=\'" + key + "\'>" + val + "</option>");
12260 valueSelector.trigger("change.select2");
12262 $("#value-selector").show();
12263 $("#value-selector").next(".select2-container").show();
12265 $(".value-input").show();
12269 $("#operator-selector").on("change", function() {
12270 console.log("We change operator-selector");
12272 const selectedOperator = $(this).find(":selected").val();
12273 if (selectedOperator === "IsDefined" || selectedOperator === "IsNotDefined") {
12274 // Disable all value input elements
12275 $(".value-input, .dateone, .datemonth, .dateyear").val("").prop("disabled", true);
12276 $("#datemonth, #dateyear").val(null).trigger("change.select2");
12277 $("#dateone").datepicker("setDate", null).datepicker("option", "disabled", true);
12278 $(".date-one, .date-month, .date-year").prop("disabled", true);
12279 $("#value-selector").val("").prop("disabled", true);
12280 $("#value-selector").val(null).trigger("change.select2");
12282 // Enable all value input elements
12283 $(".value-input, .dateone, .datemonth, .dateyear").prop("disabled", false);
12284 $(".date-one, .date-month, .date-year").prop("disabled", false);
12285 $("#dateone").datepicker("option", "disabled", false);
12286 $("#value-selector").prop("disabled", false);
12290 $(".add-filter-btn").on("click", function(event) {
12291 console.log("We click on add-filter-btn");
12293 event.preventDefault();
12295 const field = $(".search_filter_field").val();
12296 const operator = $(".operator-selector").val();
12297 let value = $(".value-input").val();
12298 const fieldType = $(".search_filter_field").find(":selected").data("type");
12300 if (["date", "datetime", "timestamp"].includes(fieldType)) {
12301 const year = $("#dateoneyear").val().toString().padStart(4, "0");;
12302 const month = $("#dateonemonth").val().toString().padStart(2, "0");
12303 const day = $("#dateoneday").val().toString().padStart(2, "0");
12304 value = `${year}-${month}-${day}`;
12305 console.log("value="+value);
12308 // If the selected field has an array of values then take the selected value
12309 if (arrayoffiltercriterias[field]["arrayofkeyval"] !== undefined) {
12310 value = $("#value-selector").val();
12313 // If the operator is "IsDefined" or "IsNotDefined" then set the value to 1 (it will not be used)
12314 if (operator === "IsDefined" || operator === "IsNotDefined") {
12318 const filterString = generateFilterString(field, operator, value, fieldType);
12321 if (filterString !== "" && field !== "" && operator !== "" && value !== "") {
12322 $("#search_component_params_input").val($("#search_component_params_input").val() + " " + filterString);
12323 $("#search_component_params_input").closest("form").submit();
12325 $(".assistance-errors").show();
12345 public function selectModelMail($prefix, $modelType =
'', $default = 0, $addjscombo = 0, $selected = 0, $morecss =
'')
12347 global $langs, $user;
12351 $TModels = array();
12353 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
12354 $formmail =
new FormMail($this->db);
12355 $result = $formmail->fetchAllEMailTemplate($modelType, $user, $langs);
12358 $TModels[0] = $langs->trans(
'DefaultMailModel');
12361 foreach ($formmail->lines_model as $model) {
12362 $TModels[(int) $model->id] = $model->label;
12366 $retstring .=
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" id="select_' . $prefix .
'model_mail" name="' . $prefix .
'model_mail">';
12368 foreach ($TModels as $id_model => $label_model) {
12369 $retstring .=
'<option value="' . $id_model .
'"';
12370 if (!empty($selected) && ((int) $selected) == $id_model) {
12371 $retstring .=
"selected";
12373 $retstring .=
">" . $label_model .
"</option>";
12376 $retstring .=
"</select>";
12379 $retstring .=
ajax_combobox(
'select_' . $prefix .
'model_mail');
12396 public function buttonsSaveCancel($save_label =
'Save', $cancel_label =
'Cancel', $morebuttons = array(), $withoutdiv =
false, $morecss =
'', $dol_openinpopup =
'')
12400 $buttons = array();
12404 'label_key' => $save_label,
12407 if ($save_label ==
'Create' || $save_label ==
'Add') {
12408 $save[
'name'] =
'add';
12409 } elseif ($save_label ==
'Modify') {
12410 $save[
'name'] =
'edit';
12414 'name' =>
'cancel',
12415 'label_key' =>
'Cancel',
12420 !empty($save_label) ? $buttons[] = $save :
'';
12421 if (!empty($morebuttons)) {
12422 $buttons[] = $morebuttons;
12424 !empty($cancel_label) ? $buttons[] = $cancel :
'';
12426 if (!empty($morebuttons)) {
12427 $buttons[] = $morebuttons;
12429 !empty($cancel_label) ? $buttons[] = $cancel :
'';
12430 !empty($save_label) ? $buttons[] = $save :
'';
12433 $retstring = $withoutdiv ?
'' :
'<div class="center">';
12435 foreach ($buttons as $button) {
12436 $addclass = empty($button[
'addclass']) ?
'' : $button[
'addclass'];
12437 $retstring .=
'<input type="submit" class="button marginleftonly marginrightonly button-' . $button[
'name'] . ($morecss ?
' ' . $morecss :
'') .
' ' . $addclass .
'" name="' . $button[
'name'] .
'" value="' .
dol_escape_htmltag($langs->transnoentities($button[
'label_key'])) .
'">';
12439 $retstring .= $withoutdiv ?
'' :
'</div>';
12441 if ($dol_openinpopup) {
12442 $retstring .=
'<!-- buttons are shown into a $dol_openinpopup=' .
dol_escape_htmltag($dol_openinpopup) .
' context, so we enable the close of dialog on cancel -->' .
"\n";
12443 $retstring .=
'<script nonce="' .
getNonce() .
'">';
12444 $retstring .=
'jQuery(".button-cancel").click(function(e) {
12445 e.preventDefault(); console.log(\'We click on cancel in iframe popup ' .
dol_escape_js($dol_openinpopup) .
'\');
12446 window.parent.jQuery(\
'#idfordialog' .
dol_escape_js($dol_openinpopup) .
'\').dialog(\
'close\');
12448 $retstring .=
'</script>';
12467 $num = count($this->cache_invoice_subtype);
12474 $sql =
"SELECT rowid, code, label as label";
12475 $sql .=
" FROM " . MAIN_DB_PREFIX .
'c_invoice_subtype';
12476 $sql .=
" WHERE active = 1";
12478 $resql = $this->db->query($sql);
12480 $num = $this->db->num_rows($resql);
12482 while ($i < $num) {
12483 $obj = $this->db->fetch_object($resql);
12486 $label = ($langs->trans(
"InvoiceSubtype" . $obj->rowid) !=
"InvoiceSubtype" . $obj->rowid) ? $langs->trans(
"InvoiceSubtype" . $obj->rowid) : (($obj->label !=
'-') ? $obj->label :
'');
12487 $this->cache_invoice_subtype[$obj->rowid][
'rowid'] = $obj->rowid;
12488 $this->cache_invoice_subtype[$obj->rowid][
'code'] = $obj->code;
12489 $this->cache_invoice_subtype[$obj->rowid][
'label'] = $label;
12493 $this->cache_invoice_subtype =
dol_sort_array($this->cache_invoice_subtype,
'code',
'asc', 0, 0, 1);
12515 global $langs, $user;
12518 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
12520 $this->load_cache_invoice_subtype();
12522 $out .=
'<select id="' . $htmlname .
'" class="flat selectsubtype' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
12524 $out .=
'<option value="0"> </option>';
12527 foreach ($this->cache_invoice_subtype as $rowid => $subtype) {
12528 $label = $subtype[
'label'];
12529 $out .=
'<option value="' . $subtype[
'rowid'] .
'"';
12530 if ($selected == $subtype[
'rowid']) {
12531 $out .=
' selected="selected"';
12535 $out .=
'</option>';
12538 $out .=
'</select>';
12539 if ($user->admin && empty($noinfoadmin)) {
12540 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
12561 'type' =>
'search',
12562 'name' => $htmlName,
12564 'class' =>
"search-tool-input",
12565 'placeholder' => $langs->trans(
'Search'),
12566 'autocomplete' =>
'off'
12574 if ($dataTarget !==
false) {
12575 $attr[
'data-search-tool-target'] = $dataTarget;
12579 if (!empty($params[
'attr']) && is_array($params[
'attr'])) {
12580 foreach ($params[
'attr'] as $key => $value) {
12581 if ($key ==
'class') {
12582 $attr[
'class'] .=
' '.$value;
12583 } elseif ($key ==
'classOverride') {
12584 $attr[
'class'] = $value;
12586 $attr[$key] = $value;
12592 if (!empty($attr[
'title']) && !empty($attr[
'class']) && strpos($attr[
'class'],
'classfortooltip') ===
false) {
12593 $attr[
'class'] .=
' classfortooltip';
12596 $TCompiledAttr = [];
12597 foreach ($attr as $key => $value) {
12598 if (in_array($key, [
'data-target'])
12599 || (!empty($params[
'use_unsecured_unescapedattr']) && is_array($params[
'use_unsecured_unescapedattr']) && in_array($key, $params[
'use_unsecured_unescapedattr']))) {
12605 $TCompiledAttr[] = $key .
'="' . $value .
'"';
12608 $compiledAttributes = implode(
' ', $TCompiledAttr);
12611 return '<div class="search-tool-container"><input '.$compiledAttributes.
'></div>';
12627 public function inputType($type, $name, $value =
'',
$id =
'', $morecss =
'', $moreparam =
'', $label =
'', $addInputLabel =
'')
12630 if ($label !=
'') {
12640 $out .= ($moreparam ?
' ' . $moreparam :
'');
12641 $out .=
' />' . $addInputLabel;
12642 if ($label !=
'') {
12643 $out .= $label .
'</label>';
12661 public function inputSelectAjax($htmlName, $array,
$id, $ajaxUrl, $ajaxData = [], $morecss =
'minwidth75', $moreparam =
'')
12665 $(document).ready(function () {
12666 $('#" . $htmlName .
"').select2({
12668 url: '" . $ajaxUrl .
"',
12670 delay: 250, // wait 250 milliseconds before triggering the request
12671 data: function (params) {
12673 search: params.term,
12674 page: params.page || 1";
12675 if (!empty($ajaxData) && is_array($ajaxData)) {
12676 foreach ($ajaxData as $key => $value) {
12677 $out .=
", " . $key .
": '" . $value .
"'";
12689 $out .= $this->selectarray($htmlName, $array,
$id, 0, 0, 0, $moreparam, 0, 0, 0,
'', $morecss);
12703 public function inputHtml($htmlName, $value, $morecss =
'', $moreparam =
'')
12705 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
12706 $doleditor =
new DolEditor($htmlName, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
isModEnabled(
'fckeditor') &&
getDolGlobalInt(
'FCKEDITOR_ENABLE_SOCIETE'), ROWS_5,
'90%');
12708 return (
string) $doleditor->Create(1,
'',
true,
'',
'', $moreparam, $morecss);
12721 public function inputText($htmlName, $value, $morecss =
'', $moreparam =
'', $options = array())
12726 if (!empty($options)) {
12728 $out .= $this->selectarray($htmlName .
"_multiinput", $options,
'', 1, 0, 0, $moreparam, 0, 0, 0,
'',
"flat maxwidthonphone" . $morecss);
12729 $out .=
'<input id="' . $htmlName .
'_multiinputadd" type="button" class="button" value="' . $langs->trans(
"Add") .
'">';
12730 $out .=
"<script>";
12732 function handlemultiinputdisabling(htmlname){
12733 console.log("We handle the disabling of used options for "+htmlname+"_multiinput");
12734 multiinput = $("#"+htmlname+"_multiinput");
12735 multiinput.find("option").each(function(){
12736 tmpval = $("#"+htmlname).val();
12737 tmpvalarray = tmpval.split("\n");
12738 valtotest = $(this).val();
12739 if(tmpvalarray.includes(valtotest)){
12740 $(this).prop("disabled",true);
12742 if($(this).prop("disabled") == true){
12743 console.log(valtotest)
12744 $(this).prop("disabled", false);
12750 $(document).ready(function () {
12751 $("#' . $htmlName .
'_multiinputadd").on("click",function() {
12752 tmpval = $("#' . $htmlName .
'").val();
12753 tmpvalarray = tmpval.split(",");
12754 valtotest = $("#' . $htmlName .
'_multiinput").val();
12755 if(valtotest != -1 && !tmpvalarray.includes(valtotest)){
12756 console.log("We add the selected value to the text area ' . $htmlName .
'");
12758 tmpval = valtotest;
12760 tmpval = tmpval + "\n" + valtotest;
12762 $("#' . $htmlName .
'").val(tmpval);
12763 handlemultiinputdisabling("' . $htmlName .
'");
12764 $("#' . $htmlName .
'_multiinput").val(-1);
12766 console.log("We add nothing the text area ' . $htmlName .
'");
12769 $("#' . $htmlName .
'").on("change",function(){
12770 handlemultiinputdisabling("' . $htmlName .
'");
12772 handlemultiinputdisabling("' . $htmlName .
'");
12774 $out .=
"</script>";
12775 $value = str_replace(
',',
"\n", $value);
12778 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
12779 $doleditor =
new DolEditor($htmlName, (
string) $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
12780 $out .= (string) $doleditor->Create(1,
'',
true,
'',
'', $moreparam, $morecss);
12795 public function inputRadio($htmlName, $options, $selectedValue, $morecss =
'', $moreparam =
'')
12798 foreach ($options as $optionKey => $optionLabel) {
12799 $selected = ((string) $selectedValue) === ((string) $optionKey) ?
' checked="checked"' :
'';
12800 $optionId = $htmlName .
'_' . $optionKey;
12801 $out .=
'<input class="flat' . $morecss .
'" type="radio" name="' . $htmlName .
'" id="' . $optionId .
'" value="' .
dolPrintHTMLForAttribute((
string) $optionKey) .
'"' . $selected . $moreparam .
'/><label for="' . $optionId .
'">' . $optionLabel .
'</label><br>';
12817 public function inputStars($htmlName, $size, $value, $morecss =
'', $moreparam =
'')
12819 $out =
'<input type="hidden" class="flat ' . $morecss .
'" name="' . $htmlName .
'" id="' . $htmlName .
'" value="' .
dolPrintHTMLForAttribute((
string) $value) .
'"' . $moreparam .
'>';
12820 $out .=
'<div class="star-selection" id="' . $htmlName .
'_selection">';
12821 for ($i = 1; $i <= $size; $i++) {
12822 $out .=
'<span class="star" data-value="' . $i .
'">' .
img_picto(
'',
'fontawesome_star_fas') .
'</span>';
12826 jQuery(function($) { /* commonobject.class.php 1 */
12827 let container = $("#' . $htmlName .
'_selection");
12828 let selectedStars = parseInt($("#' . $htmlName .
'").val()) || 0;
12829 container.find(".star").each(function() {
12830 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
12832 container.find(".star").on("mouseover", function() {
12833 let selectedStar = $(this).data("value");
12834 container.find(".star").each(function() {
12835 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
12838 container.on("mouseout", function() {
12839 container.find(".star").each(function() {
12840 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
12843 container.find(".star").off("click").on("click", function() {
12844 selectedStars = $(this).data("value");
12845 if (selectedStars === 1 && $("#' . $htmlName .
'").val() == 1) {
12848 $("#' . $htmlName .
'").val(selectedStars);
12849 container.find(".star").each(function() {
12850 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
12868 public function inputIcon($htmlName, $value, $morecss =
'', $moreparam =
'')
12877 $out =
'<input type="text" class="form-control icp icp-auto iconpicker-element iconpicker-input flat ' . $morecss .
' maxwidthonsmartphone"';
12878 $out .=
' name="' . $htmlName .
'" id="' . $htmlName .
'" value="' .
dolPrintHTMLForAttribute((
string) $value) .
'" ' . ((string) $moreparam) .
'>';
12880 $out .=
'<script>';
12881 $options =
"{ title: '<b>" . $langs->trans(
"IconFieldSelector") .
"</b>', placement: 'right', showFooter: false, templates: {";
12882 $options .=
"iconpicker: '<div class=\"iconpicker\"><div style=\"background-color:#EFEFEF;\" class=\"iconpicker-items\"></div></div>',";
12883 $options .=
"iconpickerItem: '<a role=\"button\" href=\"#\" class=\"iconpicker-item\" style=\"background-color:#DDDDDD;\"><i></i></a>',";
12886 $options .=
"footer: '<div class=\"popover-footer\" style=\"background-color:#EFEFEF;\"></div>',";
12887 $options .=
"search: '<input type=\"search\" class\"form-control iconpicker-search\" placeholder=\"" . $langs->trans(
"TypeToFilter") .
"\" />',";
12888 $options .=
"popover: '<div class=\"iconpicker-popover popover\">";
12889 $options .=
" <div class=\"arrow\" ></div>";
12890 $options .=
" <div class=\"popover-title\" style=\"text-align:center;background-color:#EFEFEF;\"></div>";
12891 $options .=
" <div class=\"popover-content \" ></div>";
12892 $options .=
"</div>'}}";
12893 $out .=
"$('#" . $htmlName .
"').iconpicker(" . $options .
");";
12894 $out .=
'</script>';
12910 require_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeophp.class.php';
12911 require_once DOL_DOCUMENT_ROOT .
'/core/class/geomapeditor.class.php';
12917 if (!empty($value)) {
12918 $tmparray = $dolgeophp->parseGeoString($value);
12919 $geojson = $tmparray[
'geojson'];
12920 $centroidjson = $tmparray[
'centroidjson'];
12923 return $geomapeditor->getHtml($htmlName, $geojson, $centroidjson, $type);
12935 $toPrint = array();
12936 $values = is_array($values) ? $values : array();
12938 foreach ($values as $value) {
12939 $toPrint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $value .
'</li>';
12941 if (!empty($toPrint)) {
12942 $out =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(
' ', $toPrint) .
'</ul></div>';
12958 for ($i = 1; $i <= $size; $i++) {
12959 $out .=
'<span class="star' . ($i <= $value ?
' active' :
'') .
'" data-value="' . $i .
'">' .
img_picto(
'',
'fontawesome_star_fas') .
'</span>';
12990 if (!empty($value)) {
12991 require_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeophp.class.php';
12993 if ($type ==
'point') {
12994 $out = $dolgeophp->getXYString($value);
12996 $out = $dolgeophp->getPointString($value);
13017 public function getNomUrl(&
$object, $withpicto = 0, $option =
'', $maxlength = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'', $add_label = 0, $sep =
' - ')
13019 if (is_object(
$object) && method_exists(
$object,
'getNomUrl')) {
13020 $out =
$object->getNomUrl($withpicto, $option, $maxlength, $save_lastsearch_value, $notooltip, $morecss, $add_label, $sep);
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLength=2, $autoselect=0, $ajaxoptions=array(), $moreparams='')
Generic function that return javascript to add to transform a common input text or select field into ...
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
ajax_multiautocompleter($htmlname, $fields, $url, $option='', $minLength=2, $autoselect=0)
Generic function that return javascript to add to a page to transform a common input text field into ...
ajax_event($htmlname, $events)
Add event management script.
Class to manage bank accounts.
Class to manage categories.
Class to manage bank accounts description of third parties.
Class to manage a WYSIWYG editor.
Class to manage Geo processing Usage: $dolgeophp=new DolGeoPHP($db);.
Class to manage ECM files.
const STATUS_OPEN_INTERNAL
Warehouse open and only operations for stock transfers/corrections allowed (not for customer shipping...
const STATUS_OPEN_ALL
Warehouse open and any operations are allowed (customer shipping, supplier dispatch,...
const STATUS_CLOSED
Warehouse closed, inactive.
Class to manage invoices.
Class to manage invoice templates.
Class to manage a Leaflet map width geometrics objects.
Class to parse product price expressions.
Class to manage predefined suppliers products.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
Class toolbox to validate values.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
currency_name($code_iso, $withcode=0, $outputlangs=null)
Return label of currency or code+label.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
getServerTimeZoneInt($refgmtdate='now')
Return server timezone int.
removeGlobalParenthesis($string)
Remove first and last parenthesis but only if first is the opening and last the closing of the same g...
dol_now($mode='gmt')
Return date for now.
dol_print_email($email, $contactid=0, $socid=0, $addlink=0, $max=0, $showinvalid=2, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
dolForgeExplodeAnd($sqlfilters)
Explode an universal search string with AND parts.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
commonHtmlAttributeBuilder($attr, array $unescapedAttr=[])
Builds an array of safe and properly escaped HTML attributes from a key-value pair list.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dolBuildUrl($url, $params=[], $addtoken=false)
Return path of url.
dolPrintHTML($s, $allowiframe=0)
Return a string (that can be on several lines) ready to be output on a HTML page.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled='', $morecss='classlink button bordertransp', $jsonopen='', $jsonclose='', $accesskey='')
Return HTML code to output a button to open a dialog popup box.
currentToken()
Return the value of token currently saved into session with name 'token'.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_print_url($url, $target='_blank', $max=32, $withpicto=0, $morecss='')
Show Url link.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolUserString($key, $default='', $tmpuser=null)
Return Dolibarr user constant string value.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
GETPOSTISARRAY($paramname, $method=0)
Return true if the parameter $paramname is submit from a POST OR GET as an array.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getElementProperties($elementType)
Get an array with properties of an element.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
dol_string_neverthesehtmltags($stringtoclean, $disallowed_tags=array('textarea'), $cleanalsosomestyles=0)
Clean a string from some undesirable HTML tags.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
dolPrintHTMLForAttribute($s, $escapeonlyhtmltags=0, $allowothertags=array())
Return a string ready to be output into an HTML attribute (alt, title, data-html, ....
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
getAdvancedPreviewUrl($modulepart, $relativepath, $alldata=0, $param='')
Return URL we can use for advanced preview links.
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_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getNonce()
Return a random string to be used as a nonce value for js.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox=0, $check='restricthtml')
Sanitize a HTML to remove js, dangerous content and external links.
dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array(), $allowlink=0, $allowscript=0, $allowstyle=0, $allowphp=0)
Clean a string to keep only desirable HTML tags.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
array_merge_recursive_distinct(array $array1, array $array2)
Recursively merges two arrays while preserving keys and replacing existing values.
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...
multi select button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
treeview li table
No Email.
measuringUnitString($unitid, $measuring_style='', $unitscale=null, $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
$conf db name
Only used if Module[ID]Name translation string is not found.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.
getMaxFileSizeArray()
Return the max allowed for file upload.
dolDecrypt($chain, $key='')
Decode a string with a symmetric encryption.
testSqlAndScriptInject($val, $type)
Security: WAF layer for SQL Injection and XSS Injection (scripts) protection (Filters on GET,...