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="'.$labeltoshowhtml.$outvalUnits.$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
3876 if ($stocktag == -1) {
3877 $opt .=
' class="product_line_stock_too_low" data-html="'.$labeltoshowhtml.$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 .
'">';
6003 if (is_array($cate_arbo)) {
6004 $num = count($cate_arbo);
6007 $langs->load(
"categories");
6008 $output .=
'<option value="-1" disabled>' . $langs->trans(
"NoCategoriesDefined") .
'</option>';
6010 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
6011 $output .=
'<option value="-1"> </option>';
6013 foreach ($cate_arbo as $key => $value) {
6014 if ($cate_arbo[$key][
'id'] == $selected || ($selected ===
'auto' && count($cate_arbo) == 1)) {
6020 $labeltoshow =
img_picto(
'',
'category',
'class="pictofixedwidth"'.(empty($cate_arbo[$key][
'color']) ?
'' :
' style="color: #' . $cate_arbo[$key][
'color'] .
'"'));
6021 $labeltoshow .=
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle');
6023 $outarray[$cate_arbo[$key][
'id']] = $cate_arbo[$key][
'fulllabel'];
6025 $outarrayrichhtml[$cate_arbo[$key][
'id']] = $labeltoshow;
6027 $output .=
'<option ' . $add .
'value="' . $cate_arbo[$key][
'id'] .
'"';
6030 $output .=
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle');
6031 $output .=
'</option>';
6033 $cate_arbo[$key][
'data-html'] = $labeltoshow;
6037 $output .=
'</select>';
6040 $this->num = count($cate_arbo);
6042 if ($outputmode == 2) {
6045 } elseif ($outputmode == 1) {
6047 } elseif ($outputmode == 3) {
6048 return $outarrayrichhtml;
6073 public function form_confirm($page, $title, $question, $action, $formquestion = array(), $selectedchoice =
"", $useajax = 0, $height = 170, $width = 500)
6076 dol_syslog(__METHOD__ .
': using form_confirm is deprecated. Use formconfim instead.', LOG_WARNING);
6077 print $this->
formconfirm($page, $title, $question, $action, $formquestion, $selectedchoice, $useajax, $height, $width);
6106 public function formconfirm($page, $title, $question, $action, $formquestion =
'', $selectedchoice =
'', $useajax = 0, $height = 0, $width = 500, $disableformtag = 0, $labelbuttonyes =
'Yes', $labelbuttonno =
'No')
6108 global $langs, $conf;
6111 $formconfirm =
'<!-- formconfirm - before call, page=' .
dol_escape_htmltag($page) .
' -->';
6117 $newselectedchoice = empty($selectedchoice) ?
"no" : $selectedchoice;
6118 if ($conf->browser->layout ==
'phone') {
6123 if (empty($height)) {
6125 if (is_array($formquestion) && count($formquestion) > 2) {
6126 $height += ((count($formquestion) - 2) * 24) + 5;
6130 if (is_array($formquestion) && !empty($formquestion)) {
6132 foreach ($formquestion as $key => $input) {
6133 if (is_array($input) && !empty($input)) {
6134 if ($input[
'type'] ==
'hidden') {
6135 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
6136 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
6144 $moreonecolumn =
'';
6145 $more .=
'<div class="tagtable paddingtopbottomonly centpercent noborderspacing">' .
"\n";
6146 foreach ($formquestion as $key => $input) {
6147 if (is_array($input) && !empty($input)) {
6148 $size = (!empty($input[
'size']) ?
' size="' . $input[
'size'] .
'"' :
'');
6149 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
6150 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
6152 if ($input[
'type'] ==
'text' || $input[
'type'] ==
'input') {
6153 $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";
6154 } elseif ($input[
'type'] ==
'password') {
6155 $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";
6156 } elseif ($input[
'type'] ==
'textarea') {
6157 $moreonecolumn .=
'<div class="margintoponly">';
6158 $moreonecolumn .= $input[
'label'] .
'<br>';
6160 $moreonecolumn .= $input[
'value'];
6161 $moreonecolumn .=
'</textarea>';
6162 $moreonecolumn .=
'</div>';
6163 } elseif (in_array($input[
'type'], [
'select',
'multiselect'])) {
6164 if (empty($morecss)) {
6165 $morecss =
'minwidth100';
6168 $show_empty = isset($input[
'select_show_empty']) ? $input[
'select_show_empty'] : 1;
6169 $key_in_label = isset($input[
'select_key_in_label']) ? $input[
'select_key_in_label'] : 0;
6170 $value_as_key = isset($input[
'select_value_as_key']) ? $input[
'select_value_as_key'] : 0;
6171 $translate = isset($input[
'select_translate']) ? $input[
'select_translate'] : 0;
6172 $maxlen = isset($input[
'select_maxlen']) ? $input[
'select_maxlen'] : 0;
6173 $disabled = isset($input[
'select_disabled']) ? $input[
'select_disabled'] : 0;
6174 $sort = isset($input[
'select_sort']) ? $input[
'select_sort'] :
'';
6176 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">';
6177 if (!empty($input[
'label'])) {
6178 $more .= $input[
'label'] .
'</div><div class="tagtd left">';
6180 if ($input[
'type'] ==
'select') {
6181 $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);
6183 $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);
6185 $more .=
'</div></div>' .
"\n";
6186 } elseif ($input[
'type'] ==
'checkbox') {
6187 $more .=
'<div class="tagtr">';
6188 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'"><label for="' .
dol_escape_htmltag($input[
'name']) .
'">' . $input[
'label'] .
'</label></div><div class="tagtd">';
6189 $more .=
'<input type="checkbox" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' .
dol_escape_htmltag($input[
'name']) .
'" name="' .
dol_escape_htmltag($input[
'name']) .
'"' . $moreattr;
6190 if (!is_bool($input[
'value']) && $input[
'value'] !=
'false' && $input[
'value'] !=
'0' && $input[
'value'] !=
'') {
6191 $more .=
' checked';
6193 if (is_bool($input[
'value']) && $input[
'value']) {
6194 $more .=
' checked';
6196 if (isset($input[
'disabled'])) {
6197 $more .=
' disabled';
6199 $more .=
' /></div>';
6200 $more .=
'</div>' .
"\n";
6201 } elseif ($input[
'type'] ==
'radio') {
6203 foreach ($input[
'values'] as $selkey => $selval) {
6204 $more .=
'<div class="tagtr">';
6205 if (isset($input[
'label'])) {
6207 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
' tdtop' : (
' tdtop ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
6209 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' "' . $input[
'tdclass'])) .
'"> </div>';
6212 $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;
6213 if (!empty($input[
'disabled'])) {
6214 $more .=
' disabled';
6216 if (isset($input[
'default']) && $input[
'default'] === $selkey) {
6217 $more .=
' checked="checked"';
6220 $more .=
'<label for="' .
dol_escape_htmltag($input[
'name'] . $selkey) .
'" class="valignmiddle">' . $selval .
'</label>';
6221 $more .=
'</div></div>' .
"\n";
6224 } elseif ($input[
'type'] ==
'date' || $input[
'type'] ==
'datetime') {
6225 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
6226 $more .=
'<div class="tagtd">';
6227 $addnowlink = (empty($input[
'datenow']) ? 0 : 1);
6229 if ($input[
'type'] ==
'datetime') {
6230 $h = isset($input[
'hours']) ? $input[
'hours'] : 1;
6231 $m = isset($input[
'minutes']) ? $input[
'minutes'] : 1;
6233 $more .= $this->
selectDate(isset($input[
'value']) ? $input[
'value'] : -1, $input[
'name'], $h, $m, 0,
'', 1, $addnowlink);
6234 $more .=
'</div></div>'.
"\n";
6235 $formquestion[] = array(
'name' => $input[
'name'].
'day');
6236 $formquestion[] = array(
'name' => $input[
'name'].
'month');
6237 $formquestion[] = array(
'name' => $input[
'name'].
'year');
6238 $formquestion[] = array(
'name' => $input[
'name'].
'hour');
6239 $formquestion[] = array(
'name' => $input[
'name'].
'min');
6240 } elseif ($input[
'type'] ==
'other') {
6241 $more .=
'<div class="tagtr"><div class="tagtd'.(empty($input[
'tdclass']) ?
'' : (
' '.$input[
'tdclass'])).
'">';
6242 if (!empty($input[
'label'])) {
6243 $more .= $input[
'label'] .
'</div><div class="tagtd">';
6245 if (!empty($input[
'value'])) {
6246 $more .= $input[
'value'];
6248 $more .=
'</div></div>' .
"\n";
6249 } elseif ($input[
'type'] ==
'onecolumn') {
6250 $moreonecolumn .=
'<div class="margintoponly">';
6251 $moreonecolumn .= $input[
'value'];
6252 $moreonecolumn .=
'</div>' .
"\n";
6253 } elseif ($input[
'type'] ==
'hidden') {
6255 } elseif ($input[
'type'] ==
'separator') {
6258 $more .=
'Error type ' . $input[
'type'] .
' for the confirm box is not a supported type';
6262 $more .=
'</div>' .
"\n";
6263 $more .= $moreonecolumn;
6269 if (!empty($conf->dol_use_jmobile)) {
6272 if (empty($conf->use_javascript_ajax)) {
6278 $dialogconfirm =
'dialog-confirm';
6280 if (!is_numeric($useajax)) {
6284 $dialogconfirm .=
'-' . $button;
6286 $pageyes = $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=yes';
6287 $pageno = ($useajax == 2 ? $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=no' :
'');
6290 if (is_array($formquestion)) {
6291 foreach ($formquestion as $key => $input) {
6294 if (is_array($input) && isset($input[
'name'])) {
6295 if (strpos($input[
'name'],
',') > 0) {
6296 $inputok = array_merge($inputok, explode(
',', $input[
'name']));
6298 array_push($inputok, $input[
'name']);
6303 if (is_array($input) && isset($input[
'inputko']) && $input[
'inputko'] == 1 && isset($input[
'name'])) {
6304 array_push($inputko, $input[
'name']);
6310 $formconfirm .=
'<div id="' . $dialogconfirm .
'" title="' .
dol_escape_htmltag($title) .
'" style="display: none;">';
6311 if (is_array($formquestion) && array_key_exists(
'text', $formquestion) && !empty($formquestion[
'text'])) {
6312 $formconfirm .=
'<div class="confirmtext">' . $formquestion[
'text'] .
'</div>' .
"\n";
6314 if (!empty($more)) {
6315 $formconfirm .=
'<div class="confirmquestions">' . $more .
'</div>' .
"\n";
6317 $formconfirm .= ($question ?
'<div class="confirmmessage">' .
img_help(0,
'') .
' ' . $question .
'</div>' :
'');
6318 $formconfirm .=
'</div>' .
"\n";
6320 $formconfirm .=
"\n<!-- begin code of popup for formconfirm page=" . $page .
" -->\n";
6321 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
6322 $formconfirm .=
"/* Code for the jQuery('#dialogforpopup').dialog() */\n";
6323 $formconfirm .=
'jQuery(document).ready(function() {
6325 $( "#' . $dialogconfirm .
'" ).dialog({
6326 autoOpen: ' . ($autoOpen ?
"true" :
"false") .
',';
6327 if ($newselectedchoice ==
'no') {
6330 $(this).parent().find("button.ui-button:eq(2)").focus();
6335 if ($useajax == 1) {
6336 $jsforcursor =
'// The call to urljump can be slow, so we set the wait cursor' .
"\n";
6337 $jsforcursor .=
'jQuery("html,body,#id-container").addClass("cursorwait");' .
"\n";
6340 $postconfirmas =
'GET';
6347 closeOnEscape:
false,
6349 "' . dol_escape_js($langs->transnoentities($labelbuttonyes)) . '":
function() {
6350 var options =
"token=' . urlencode(newToken()) . '";
6351 var inputok =
' . json_encode($inputok) . ';
6352 var page = \
'' .
dol_escape_js(!empty($page) ? $page :
'') .
'\';
6353 var pageyes = \
'' .
dol_escape_js(!empty($pageyes) ? $pageyes :
'') .
'\';
6355 if (inputok.length > 0) {
6356 $.each(inputok,
function(i, inputname) {
6359 if ($(
"input[name=\'" + inputname +
"\']").attr(
"type") ==
"radio") {
6360 inputvalue = $(
"input[name=\'" + inputname +
"\']:checked").val();
6362 if ($(
"#" + inputname).attr(
"type") ==
"checkbox") { more =
":checked"; }
6363 inputvalue = $(
"#" + inputname + more).val();
6365 if (typeof inputvalue ==
"undefined") { inputvalue=
""; }
6366 console.log(
"formconfirm check inputname="+inputname+
" inputvalue="+inputvalue);
6367 options +=
"&" + inputname +
"=" + encodeURIComponent(inputvalue);
6370 var urljump = pageyes + (pageyes.indexOf(
"?") < 0 ?
"?" :
"&") + options;
6371 if (pageyes.length > 0) {
';
6372 if ($postconfirmas == 'GET
') {
6373 $formconfirm .= 'location.href = urljump;
';
6375 $formconfirm .= $jsforcursor;
6376 $formconfirm .= 'var post = $.post(
6379 function(data) { $(
"body").html(data); jQuery(
"html,body,#id-container").removeClass(
"cursorwait"); }
6383 console.log(
"after post ok");
6385 $(
this).dialog(
"close");
6387 "' . dol_escape_js($langs->transnoentities($labelbuttonno)) . '":
function() {
6388 var options =
"token=' . urlencode(newToken()) . '";
6389 var inputko =
' . json_encode($inputko) . ';
6390 var page =
"' . dol_escape_js(!empty($page) ? $page : '') . '";
6391 var pageno=
"' . dol_escape_js(!empty($pageno) ? $pageno : '') . '";
6392 if (inputko.length > 0) {
6393 $.each(inputko,
function(i, inputname) {
6395 if ($(
"#" + inputname).attr(
"type") ==
"checkbox") { more =
":checked"; }
6396 var inputvalue = $(
"#" + inputname + more).val();
6397 if (typeof inputvalue ==
"undefined") { inputvalue=
""; }
6398 options +=
"&" + inputname +
"=" + encodeURIComponent(inputvalue);
6401 var urljump=pageno + (pageno.indexOf(
"?") < 0 ?
"?" :
"&") + options;
6403 if (pageno.length > 0) {
';
6404 if ($postconfirmas == 'GET
') {
6405 $formconfirm .= 'location.href = urljump;
';
6407 $formconfirm .= $jsforcursor;
6408 $formconfirm .= 'var post = $.post(
6411 function(data) { $(
"body").html(data); jQuery(
"html,body,#id-container").removeClass(
"cursorwait"); }
6415 console.log(
"after post ko");
6417 $(
this).dialog(
"close");
6423 var
button =
"' . $button . '";
6425 $(
"#" +
button ).click(
function() {
6426 $(
"#' . $dialogconfirm . '").dialog(
"open");
6432 $formconfirm .= "<!-- end ajax formconfirm -->\n";
6434 $formconfirm .= "\n<!-- begin formconfirm page=" . dol_escape_htmltag($page) . " -->\n";
6436 if (empty($disableformtag)) {
6437 $formconfirm .= '<form method=
"POST" action=
"' . $page . '" class=
"notoptoleftnoright">
' . "\n";
6440 $formconfirm .= '<input
type=
"hidden" name=
"action" value=
"' . $action . '">
' . "\n";
6441 $formconfirm .= '<input
type=
"hidden" name=
"token" value=
"' . newToken() . '">
' . "\n";
6443 $formconfirm .= '<
table class=
"valid centpercent">
' . "\n";
6446 $formconfirm .= '<tr
class=
"validtitre"><td
class=
"validtitre" colspan=
"2">
';
6447 $formconfirm .= img_picto('', 'pictoconfirm
') . ' ' . $title;
6448 $formconfirm .= '</td></tr>
' . "\n";
6451 if (is_array($formquestion) && array_key_exists('text
', $formquestion) && !empty($formquestion['text
'])) {
6452 $formconfirm .= '<tr
class=
"valid"><td
class=
"valid" colspan=
"2">
' . $formquestion['text
'] . '</td></tr>
' . "\n";
6457 $formconfirm .= '<tr
class=
"valid"><td
class=
"valid" colspan=
"2">
' . "\n";
6458 $formconfirm .= $more;
6459 $formconfirm .= '</td></tr>
' . "\n";
6462 // Line with question
6463 $formconfirm .= '<tr
class=
"valid">
';
6464 $formconfirm .= '<td
class=
"valid">
' . $question . '</td>
';
6465 $formconfirm .= '<td
class=
"valid center">
';
6466 $formconfirm .= $this->selectyesno("confirm", $newselectedchoice, 0, false, 0, 0, 'marginleftonly marginrightonly
', $labelbuttonyes, $labelbuttonno);
6467 $formconfirm .= '<input
class=
"button valignmiddle confirmvalidatebutton small" type=
"submit" value=
"' . $langs->trans("Validate") . '">
';
6468 $formconfirm .= '</td>
';
6469 $formconfirm .= '</tr>
' . "\n";
6471 $formconfirm .= '</
table>
' . "\n";
6473 if (empty($disableformtag)) {
6474 $formconfirm .= "</form>\n";
6476 $formconfirm .= '<br>
';
6478 if (!empty($conf->use_javascript_ajax)) {
6479 $formconfirm .= '<!-- code to disable
button to avoid
double clic -->
';
6480 $formconfirm .= '<script nonce=
"' . getNonce() . '" type=
"text/javascript">
' . "\n";
6482 $(document).ready(
function () {
6483 $(
".confirmvalidatebutton").on(
"click",
function() {
6484 console.log(
"We click on button confirmvalidatebutton");
6485 $(
this).attr(
"disabled",
"disabled");
6486 setTimeout(\
'$(".confirmvalidatebutton").removeAttr("disabled")\', 3000);
6487 //console.log($(this).closest("form"));
6488 $(this).closest("form").submit();
6492 $formconfirm .=
'</script>' .
"\n";
6495 $formconfirm .=
"<!-- end formconfirm -->\n";
6498 return $formconfirm;
6519 public function form_project($page, $socid, $selected =
'', $htmlname =
'projectid', $discard_closed = 0, $maxlength = 20, $forcefocus = 0, $nooutput = 0, $textifnoproject =
'', $morecss =
'')
6524 require_once DOL_DOCUMENT_ROOT .
'/core/lib/project.lib.php';
6525 require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formprojet.class.php';
6531 $langs->load(
"project");
6532 if ($htmlname !=
"none") {
6533 $out .=
'<form method="post" action="' . $page .
'">';
6534 $out .=
'<input type="hidden" name="action" value="classin">';
6535 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6536 $out .= $formproject->select_projects($socid, $selected, $htmlname, $maxlength, 0, 1, $discard_closed, $forcefocus, 0, 0,
'', 1, 0, $morecss);
6537 $out .=
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6540 $out .=
'<span class="project_head_block">';
6541 if ($selected instanceof
Project) {
6542 $out .= $selected->getNomUrl(0,
'', 1);
6543 } elseif (is_numeric($selected)) {
6544 $projet =
new Project($this->db);
6545 $projet->fetch((
int) $selected);
6546 $out .= $projet->getNomUrl(0,
'', 1);
6548 $out .=
'<span class="opacitymedium">' . $textifnoproject .
'</span>';
6553 if (empty($nooutput)) {
6577 public function form_conditions_reglement($page, $selected =
'', $htmlname =
'cond_reglement_id', $addempty = 0, $type =
'', $filtertype = -1, $deposit_percent = -1, $nooutput = 0)
6584 if ($htmlname !=
"none") {
6585 $out .=
'<form method="POST" action="' . $page .
'">';
6586 $out .=
'<input type="hidden" name="action" value="setconditions">';
6587 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6589 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
6591 $out .= $this->getSelectConditionsPaiements((
int) $selected, $htmlname, $filtertype, $addempty, 0,
'', $deposit_percent);
6592 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6596 $this->load_cache_conditions_paiements();
6597 if (isset($this->cache_conditions_paiements[$selected])) {
6598 $label = $this->cache_conditions_paiements[$selected][
'label'];
6600 if (!empty($this->cache_conditions_paiements[$selected][
'deposit_percent'])) {
6601 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $this->cache_conditions_paiements[$selected][
'deposit_percent'], $label);
6606 $langs->load(
'errors');
6607 $out .= $langs->trans(
'ErrorNotInDictionaryPaymentConditions');
6614 if (empty($nooutput)) {
6640 if ($htmlname !=
'none') {
6641 $out .=
'<form method="POST" action="' . $page .
'">';
6642 $out .=
'<input type="hidden" name="action" value="setruleforlinesdates">';
6643 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6644 $out .= $this->getSelectRuleForLinesDates($selected, $htmlname, $addempty);
6645 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6648 if (isset($selected)) {
6649 $this->load_cache_rule_for_lines_dates();
6650 if (isset($this->cache_rule_for_lines_dates[$selected])) {
6651 $label = $this->cache_rule_for_lines_dates[$selected];
6652 $out .= $langs->trans($label);
6659 if (empty($nooutput)) {
6682 if ($htmlname !=
"none") {
6683 print
'<form method="post" action="' . $page .
'">';
6684 print
'<input type="hidden" name="action" value="setavailability">';
6685 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6686 $this->selectAvailabilityDelay($selected, $htmlname,
'', $addempty);
6687 print
'<input type="submit" name="modify" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6688 print
'<input type="submit" name="cancel" class="button smallpaddingimp" value="' . $langs->trans(
"Cancel") .
'">';
6692 $this->load_cache_availability();
6693 if (isset($this->cache_availability[$selected])) {
6694 print $this->cache_availability[$selected][
'label'];
6715 public function formInputReason($page, $selected =
'', $htmlname =
'demandreason', $addempty = 0, $morecss =
'')
6718 if ($htmlname !=
"none") {
6719 print
'<form method="post" action="' . $page .
'">';
6720 print
'<input type="hidden" name="action" value="setdemandreason">';
6721 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6722 $this->selectInputReason($selected, $htmlname,
'-1', $addempty, $morecss);
6723 print
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6727 $this->loadCacheInputReason();
6728 foreach ($this->cache_demand_reason as $key => $val) {
6729 if ($val[
'id'] == $selected) {
6730 print $val[
'label'];
6755 public function form_date($page, $selected, $htmlname, $displayhour = 0, $displaymin = 0, $nooutput = 0, $type =
'')
6762 if ($htmlname !=
"none") {
6763 $ret .=
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
6764 $ret .=
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
6765 $ret .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6767 $ret .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
6769 $ret .=
'<table class="nobordernopadding">';
6771 $ret .= $this->selectDate($selected, $htmlname, $displayhour, $displaymin, 1,
'form' . $htmlname, 1, 0);
6773 $ret .=
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
6774 $ret .=
'</tr></table></form>';
6783 if (empty($nooutput)) {
6802 public function form_users($page, $selected =
'', $htmlname =
'userid', $exclude = array(), $include = array())
6807 if ($htmlname !=
"none") {
6808 print
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
6809 print
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
6810 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6811 print $this->select_dolusers($selected, $htmlname, 1, $exclude, 0, $include);
6812 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6816 require_once DOL_DOCUMENT_ROOT .
'/user/class/user.class.php';
6817 $theuser =
new User($this->db);
6818 $theuser->fetch((
int) $selected);
6819 print $theuser->getNomUrl(1);
6842 public function form_modes_reglement($page, $selected =
'', $htmlname =
'mode_reglement_id', $filtertype =
'', $active = 1, $addempty = 0, $type =
'', $nooutput = 0)
6848 if ($htmlname !=
"none") {
6849 $out .=
'<form method="POST" action="' . $page .
'">';
6850 $out .=
'<input type="hidden" name="action" value="setmode">';
6851 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6853 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
6855 $out .= $this->select_types_paiements($selected, $htmlname, $filtertype, 0, $addempty, 0, 0, $active,
'', 1);
6856 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6860 $this->load_cache_types_paiements();
6861 $out .= $this->cache_types_paiements[$selected][
'label'];
6888 if ($htmlname !=
"none") {
6889 print
'<form method="POST" action="' . $page .
'">';
6890 print
'<input type="hidden" name="action" value="settransportmode">';
6891 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6892 $this->selectTransportMode($selected, $htmlname, 0, $addempty, 0, 0, $active);
6893 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6897 $this->load_cache_transport_mode();
6898 print $this->cache_transport_mode[$selected][
'label'];
6919 if ($htmlname !=
"none") {
6920 print
'<form method="POST" action="' . $page .
'">';
6921 print
'<input type="hidden" name="action" value="setmulticurrencycode">';
6922 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6923 print $this->selectMultiCurrency($selected, $htmlname, 0);
6924 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6927 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
6928 print !empty($selected) ?
currency_name($selected, 1) :
' ';
6946 global $langs, $conf;
6948 if ($htmlname !=
"none") {
6949 print
'<form method="POST" action="' . $page .
'">';
6950 print
'<input type="hidden" name="action" value="setmulticurrencyrate">';
6951 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6952 print
'<input type="text" class="maxwidth75" name="' . $htmlname .
'" value="' . (!empty($rate) ?
price(
price2num($rate,
'CU')) : 1) .
'" spellcheck="false" /> ';
6953 print
'<select name="calculation_mode" id="calculation_mode">';
6954 print
'<option value="1">Change ' . $langs->trans(
"PriceUHT") .
' of lines</option>';
6955 print
'<option value="2">Change ' . $langs->trans(
"PriceUHTCurrency") .
' of lines</option>';
6958 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6961 if (!empty($rate)) {
6962 print
price($rate, 1, $langs, 0, 0);
6963 if ($currency && $rate != 1) {
6964 print
' <span class="opacitymedium">(' .
price($rate, 1, $langs, 0, 0) .
' ' . $currency .
' = 1 ' . $conf->currency .
')</span>';
6989 public function form_remise_dispo($page, $selected, $htmlname, $socid, $amount, $filter =
'', $maxvalue = 0, $more =
'', $hidelist = 0, $discount_type = 0)
6992 global $conf, $langs;
6994 if ($htmlname !=
"none") {
6995 print
'<form method="post" action="' . $page .
'" class="inline-block">';
6996 print
'<input type="hidden" name="action" value="setabsolutediscount">';
6997 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6998 print
'<div class="inline-block">';
6999 if (!empty($discount_type)) {
7001 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL") {
7002 $translationKey =
'HasAbsoluteDiscountFromSupplier';
7004 $translationKey =
'HasCreditNoteFromSupplier';
7007 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
7008 $translationKey =
'HasAbsoluteDiscountFromSupplier';
7010 $translationKey =
'HasCreditNoteFromSupplier';
7015 if (!$filter || $filter ==
"fk_facture_source IS NULL") {
7016 $translationKey =
'CompanyHasAbsoluteDiscount';
7018 $translationKey =
'CompanyHasCreditNote';
7021 if (!$filter || $filter ==
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
7022 $translationKey =
'CompanyHasAbsoluteDiscount';
7024 $translationKey =
'CompanyHasCreditNote';
7028 print $langs->trans($translationKey,
price($amount, 0, $langs, 0, 0, -1, $conf->currency));
7029 if (empty($hidelist)) {
7033 if (empty($hidelist)) {
7034 print
'<div class="inline-block" style="padding-right: 10px">';
7035 $newfilter =
'discount_type=' . intval($discount_type);
7036 if (!empty($discount_type)) {
7037 $newfilter .=
' AND fk_invoice_supplier IS NULL AND fk_invoice_supplier_line IS NULL';
7039 $newfilter .=
' AND fk_facture IS NULL AND fk_facture_line IS NULL';
7042 $newfilter .=
' AND (' . $filter .
')';
7045 $nbqualifiedlines = $this->select_remises((
string) $selected, $htmlname, $newfilter, $socid, $maxvalue);
7046 if ($nbqualifiedlines > 0) {
7047 print
' <input type="submit" class="button smallpaddingimp" value="' .
dol_escape_htmltag($langs->trans(
"UseLine")) .
'"';
7048 if (!empty($discount_type) && $filter && $filter !=
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
7049 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
7051 if (empty($discount_type) && $filter && $filter !=
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
7052 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
7060 print
'<div class="inline-block">';
7086 public function form_contacts($page, $societe, $selected =
'', $htmlname =
'contactid')
7091 if ($htmlname !=
"none") {
7092 print
'<form method="post" action="' . $page .
'">';
7093 print
'<input type="hidden" name="action" value="set_contact">';
7094 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7095 print
'<table class="nobordernopadding">';
7097 print $this->selectcontacts($societe->id, $selected, $htmlname);
7100 $addcontact = (
getDolGlobalString(
'SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans(
"AddContact") : $langs->trans(
"AddContactAddress"));
7101 print
'<a href="' . DOL_URL_ROOT .
'/contact/card.php?socid=' . $societe->id .
'&action=create&backtoreferer=1">' . $addcontact .
'</a>';
7104 print
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
7105 print
'</tr></table></form>';
7108 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
7109 $contact =
new Contact($this->db);
7110 $contact->fetch((
int) $selected);
7111 print $contact->getFullName($langs);
7136 public function form_thirdparty($page, $selected =
'', $htmlname =
'socid', $filter =
'', $showempty = 0, $showtype = 0, $forcecombo = 0, $events = array(), $nooutput = 0, $excludeids = array(), $textifnothirdparty =
'')
7142 if ($htmlname !=
"none") {
7143 $out .=
'<form method="post" action="' . $page .
'">';
7144 $out .=
'<input type="hidden" name="action" value="set_thirdparty">';
7145 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7146 $out .= $this->select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, 0,
'minwidth100',
'',
'', 1, array(),
false, $excludeids);
7147 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7151 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
7152 $soc =
new Societe($this->db);
7153 $soc->fetch((
int) $selected);
7154 $out .= $soc->getNomUrl(0,
'');
7156 $out .=
'<span class="opacitymedium">' . $textifnothirdparty .
'</span>';
7182 print $this->selectCurrency($selected, $htmlname);
7194 public function selectCurrency($selected =
'', $htmlname =
'currency_id', $mode = 0, $useempty =
'')
7196 global $langs, $user;
7198 $langs->loadCacheCurrencies(
'');
7202 if ($selected ==
'euro' || $selected ==
'euros') {
7206 $out .=
'<select class="flat maxwidth200onsmartphone minwidth300" name="' . $htmlname .
'" id="' . $htmlname .
'">';
7208 $out .=
'<option value="-1" selected></option>';
7210 foreach ($langs->cache_currencies as $code_iso => $currency) {
7211 $labeltoshow = $currency[
'label'];
7213 $labeltoshow .=
' <span class="opacitymedium">(' . $code_iso .
')</span>';
7214 } elseif ($mode == 2) {
7215 $labeltoshow .=
' <span class="opacitymedium">(' . $code_iso.
' - '.$langs->getCurrencySymbol($code_iso) .
')</span>';
7217 $labeltoshow .=
' <span class="opacitymedium">(' . $langs->getCurrencySymbol($code_iso) .
')</span>';
7220 if ($selected && $selected == $code_iso) {
7221 $out .=
'<option value="' . $code_iso .
'" selected data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
7223 $out .=
'<option value="' . $code_iso .
'" data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
7226 $out .=
'</option>';
7228 $out .=
'</select>';
7230 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
7234 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
7252 public function selectMultiCurrency($selected =
'', $htmlname =
'multicurrency_code', $useempty = 0, $filter =
'', $excludeConfCurrency =
false, $morecss =
'maxwidth200 widthcentpercentminusx')
7254 global $conf, $langs;
7256 $langs->loadCacheCurrencies(
'');
7258 $TCurrency = array();
7260 $sql =
"SELECT code FROM " . $this->db->prefix() .
"multicurrency";
7261 $sql .=
" WHERE entity IN ('" .
getEntity(
'multicurrency') .
"')";
7263 $sql .=
" AND " . $filter;
7265 $resql = $this->db->query($sql);
7267 while ($obj = $this->db->fetch_object($resql)) {
7268 $TCurrency[$obj->code] = $obj->code;
7273 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
7275 $out .=
'<option value=""> </option>';
7278 if (!in_array($conf->currency, $TCurrency) && !$excludeConfCurrency) {
7279 $TCurrency[$conf->currency] = $conf->currency;
7281 if (count($TCurrency) > 0) {
7282 foreach ($langs->cache_currencies as $code_iso => $currency) {
7283 if (isset($TCurrency[$code_iso])) {
7284 if (!empty($selected) && $selected == $code_iso) {
7285 $out .=
'<option value="' . $code_iso .
'" selected="selected">';
7287 $out .=
'<option value="' . $code_iso .
'">';
7290 $out .= $currency[
'label'];
7291 $out .=
' (' . $langs->getCurrencySymbol($code_iso) .
')';
7292 $out .=
'</option>';
7297 $out .=
'</select>';
7300 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
7317 global $langs, $user;
7319 $num = count($this->cache_vatrates);
7326 $sql =
"SELECT t.rowid, t.type_vat, t.code, t.taux, t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.recuperableonly";
7327 $sql .=
" FROM ".$this->db->prefix().
"c_tva as t, ".$this->db->prefix().
"c_country as c";
7328 $sql .=
" WHERE t.fk_pays = c.rowid";
7329 $sql .=
" AND t.active > 0";
7330 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
7331 $sql .=
" AND c.code IN (" . $this->db->sanitize($country_code, 1) .
")";
7332 $sql .=
" ORDER BY t.code ASC, t.taux ASC, t.recuperableonly ASC";
7334 $resql = $this->db->query($sql);
7336 $num = $this->db->num_rows($resql);
7338 for ($i = 0; $i < $num; $i++) {
7339 $obj = $this->db->fetch_object($resql);
7341 $tmparray = array();
7342 $tmparray[
'rowid'] = (int) $obj->rowid;
7343 $tmparray[
'type_vat'] = ($obj->type_vat <= 0 ? 0 : $obj->type_vat);
7344 $tmparray[
'code'] = $obj->code;
7345 $tmparray[
'txtva'] = $obj->taux;
7346 $tmparray[
'nprtva'] = $obj->recuperableonly;
7347 $tmparray[
'localtax1'] = $obj->localtax1;
7348 $tmparray[
'localtax1_type'] = $obj->localtax1_type;
7349 $tmparray[
'localtax2'] = $obj->localtax2;
7350 $tmparray[
'localtax2_type'] = $obj->localtax1_type;
7351 $tmparray[
'label'] = $obj->taux .
'%' . ($obj->code ?
' (' . $obj->code .
')' :
'');
7352 $tmparray[
'labelallrates'] = $obj->taux .
'/' . ($obj->localtax1 ? $obj->localtax1 :
'0') .
'/' . ($obj->localtax2 ? $obj->localtax2 :
'0') . ($obj->code ?
' (' . $obj->code .
')' :
'');
7353 $positiverates =
'';
7355 $positiverates .= ($positiverates ?
'/' :
'') . $obj->taux;
7357 if ($obj->localtax1) {
7358 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax1;
7360 if ($obj->localtax2) {
7361 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax2;
7363 if (empty($positiverates)) {
7364 $positiverates =
'0';
7366 $tmparray[
'labelpositiverates'] = $positiverates . ($obj->code ?
' (' . $obj->code .
')' :
'');
7368 $this->cache_vatrates[$obj->rowid] = $tmparray;
7373 $this->error =
'<span class="error">';
7374 $this->error .= $langs->trans(
"ErrorNoVATRateDefinedForSellerCountry", $country_code);
7376 if (!empty($user) && $user->admin && preg_match(
'/\'(..)\'/', $country_code, $reg)) {
7377 $langs->load(
"errors");
7378 $new_country_code = $reg[1];
7379 $country_id =
dol_getIdFromCode($this->db, $new_country_code,
'c_country',
'code',
'rowid');
7380 $this->error .=
'<br>'.$langs->trans(
"ErrorFixThisHere", DOL_URL_ROOT.
'/admin/dict.php?id=10'.($country_id > 0 ?
'&countryidforinsert='.$country_id :
''));
7382 $this->error .=
'</span>';
7386 $this->error =
'<span class="error">' . $this->db->error() .
'</span>';
7415 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)
7418 global $langs,
$mysoc, $hookmanager;
7420 $langs->load(
'errors');
7424 $hookmanager->initHooks(array(
'commonobject'));
7425 $info_bits == 1 ? $is_npr = 1 : $is_npr = 0;
7426 $parameters = array(
7427 'htmlname' => $htmlname,
7428 'selectedrate' => $selectedrate,
7429 'seller' => $societe_vendeuse,
7430 'buyer' => $societe_acheteuse,
7431 'idprod' => $idprod,
7432 'is_npr' => $is_npr,
7434 'options_only' => $options_only,
7436 'type_vat' => $type_vat
7438 $reshook = $hookmanager->executeHooks(
'load_tva', $parameters);
7440 return $hookmanager->resPrint;
7441 } elseif ($reshook === 0) {
7442 $return .= $hookmanager->resPrint;
7446 $defaultnpr = ($info_bits & 0x01);
7447 $defaultnpr = (preg_match(
'/\*/', $selectedrate) ? 1 : $defaultnpr);
7448 $defaulttx = str_replace(
'*',
'', $selectedrate);
7451 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
7452 $defaultcode = $reg[1];
7453 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
7458 if (is_object($societe_vendeuse) && !$societe_vendeuse->country_code) {
7459 if ($societe_vendeuse->id ==
$mysoc->id) {
7460 $return .=
'<span class="error">' . $langs->trans(
"ErrorYourCountryIsNotDefined") .
'</span>';
7462 $return .=
'<span class="error">' . $langs->trans(
"ErrorSupplierCountryIsNotDefined") .
'</span>';
7473 if (is_object($societe_vendeuse)) {
7474 $code_country =
"'" . $societe_vendeuse->country_code .
"'";
7476 $code_country =
"'" .
$mysoc->country_code .
"'";
7480 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
7484 if (is_object($societe_vendeuse) && is_object($societe_acheteuse) &&
isInEEC($societe_vendeuse) &&
isInEEC($societe_acheteuse) && !$societe_acheteuse->isACompany()) {
7486 if (is_numeric($type)) {
7488 switch ($selectVatComboMode) {
7490 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
7493 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
7497 } elseif (!$idprod) {
7498 switch ($selectVatComboMode) {
7500 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
7503 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
7507 $prodstatic =
new Product($this->db);
7508 $prodstatic->fetch($idprod);
7510 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
7517 $this->load_cache_vatrates($code_country);
7520 $arrayofvatrates = array();
7521 foreach ($this->cache_vatrates as $cachevalue) {
7522 if (empty($cachevalue[
'type_vat']) || $cachevalue[
'type_vat'] == $type_vat) {
7523 $arrayofvatrates[] = $cachevalue;
7527 $num = count($arrayofvatrates);
7530 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
7532 $tmpthirdparty =
new Societe($this->db);
7533 $tmpthirdparty->country_code =
$mysoc->country_code;
7535 $defaulttx =
get_default_tva(is_object($societe_vendeuse) ? $societe_vendeuse : $tmpthirdparty, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
7536 $defaultnpr =
get_default_npr(is_object($societe_vendeuse) ? $societe_vendeuse : $tmpthirdparty, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
7538 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
7539 $defaultcode = $reg[1];
7540 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
7542 if (empty($defaulttx)) {
7549 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
7552 $defaulttx = $arrayofvatrates[$num - 1][
'txtva'];
7559 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
7560 $defaultcode = $reg[1];
7561 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
7569 if (is_object($societe_vendeuse) && $societe_vendeuse->id ==
$mysoc->id && empty($societe_vendeuse->tva_assuj)) {
7579 if (!$options_only) {
7580 $return .=
'<select class="flat valignmiddle minwidth75imp maxwidth100 right" id="' . $htmlname .
'" name="' . $htmlname .
'"' . ($disabled ?
' disabled' :
'') . $title .
'>';
7583 $selectedfound =
false;
7584 foreach ($arrayofvatrates as $rate) {
7586 if ($disabled && $rate[
'txtva'] != 0) {
7591 $key = $rate[
'txtva'];
7592 $key .= $rate[
'nprtva'] ?
'*' :
'';
7593 if ($mode > 0 && $rate[
'code']) {
7594 $key .=
' (' . $rate[
'code'] .
')';
7597 $key = $rate[
'rowid'];
7600 $return .=
'<option value="' . $key .
'" data-vatid="'.$rate[
'rowid'].
'"';
7601 if (!$selectedfound) {
7603 if ($defaultcode == $rate[
'code']) {
7604 $return .=
' selected';
7605 $selectedfound =
true;
7607 } elseif ($rate[
'txtva'] == $defaulttx && $rate[
'nprtva'] == $defaultnpr) {
7608 $return .=
' selected';
7609 $selectedfound =
true;
7617 $return .= $rate[
'labelpositiverates'];
7620 $return .=
vatrate($rate[
'label']);
7624 $return .= (empty($rate[
'code']) && $rate[
'nprtva']) ?
' *' :
'';
7626 $return .=
'</option>';
7629 if (!$options_only) {
7630 $return .=
'</select>';
7634 $return .= $this->error;
7668 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 =
'')
7671 dol_syslog(__METHOD__ .
': using select_date is deprecated. Use selectDate instead.', LOG_WARNING);
7672 $retstring = $this->selectDate($set_time, $prefix, $h, $m, $empty, $form_name, $d, $addnowlink, $disabled, $fullday, $addplusone, $adddateof);
7673 if (!empty($nooutput)) {
7696 public function selectDateToDate($set_time =
'', $set_time_end =
'', $prefix =
're', $empty = 0, $forcenewline = 0)
7700 $ret = $this->selectDate($set_time, $prefix .
'_start', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"from"),
'tzuserrel');
7701 if ($forcenewline) {
7704 $ret .= $this->selectDate($set_time_end, $prefix .
'_end', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
7736 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 =
'')
7738 global $conf, $langs;
7740 if ($gm ===
'auto') {
7741 $gm = (empty($conf) ?
'tzserver' : $conf->tzuserinputkey);
7746 if ($prefix ==
'') {
7757 if ($stepminutes <= 0 || $stepminutes > 30) {
7768 $orig_set_time = $set_time;
7770 if ($set_time ===
'' && $emptydate == 0) {
7771 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
7772 if ($gm ==
'tzuser' || $gm ==
'tzuserrel') {
7784 if (!empty($set_time) && preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/', (
string) $set_time, $reg)) {
7786 $syear = (!empty($reg[1]) ? $reg[1] :
'');
7787 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
7788 $sday = (!empty($reg[3]) ? $reg[3] :
'');
7789 $shour = (!empty($reg[4]) ? $reg[4] :
'');
7790 $smin = (!empty($reg[5]) ? $reg[5] :
'');
7791 } elseif (strval($set_time) !=
'' && $set_time != -1) {
7796 if ($orig_set_time !=
'') {
7810 if ($h == 3 || $h == 4) {
7821 $usecalendar =
'combo';
7827 $usecalendar =
'html';
7832 if ($usecalendar !=
'combo') {
7834 $reduceformat = (!empty($conf->dol_optimize_smallscreen) ? 1 : 0);
7835 if ($reduceformat) {
7836 $format = str_replace(
'%Y',
'%y', $langs->transnoentitiesnoconv(
"FormatDateShortInput"));
7837 $formatjslong = $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput");
7838 $formatjs = str_replace(
'yyyy',
'yy', $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput"));
7839 $formatjquery = str_replace(
'yyyy',
'yy', $langs->trans(
"FormatDateShortJQueryInput"));
7841 $format = $langs->transnoentitiesnoconv(
"FormatDateShortInput");
7842 $formatjslong = $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput");
7843 $formatjs = $langs->transnoentitiesnoconv(
"FormatDateShortJavaInput");
7844 $formatjquery = $langs->trans(
"FormatDateShortJQueryInput");
7848 $formatted_date =
'';
7849 if (strval($set_time) !=
'' && $set_time != -1) {
7854 if ($usecalendar ==
"eldy") {
7880 } elseif ($usecalendar ==
'jquery' || $usecalendar ==
'html') {
7881 if (!$disabled && $usecalendar !=
'html') {
7883 $minYear =
getDolGlobalInt(
'MIN_YEAR_SELECT_DATE', (idate(
'Y') - 100));
7884 $maxYear =
getDolGlobalInt(
'MAX_YEAR_SELECT_DATE', (idate(
'Y') + 100));
7886 $retstring .=
'<!-- datepicker usecalendar='.$usecalendar.
' --><script nonce="' .
getNonce() .
'" type="text/javascript">';
7887 $retstring .=
"$(function(){ $('#" . $prefix .
"').datepicker({
7890 todayHighlight: true,
7891 yearRange: '" . $minYear .
":" . $maxYear .
"',";
7892 if (!empty($conf->dol_use_jmobile)) {
7894 beforeShow: function (input, datePicker) {
7895 input.disabled = true;
7897 onClose: function (dateText, datePicker) {
7898 this.disabled = false;
7904 $buttonImage = $calendarpicto ?: DOL_URL_ROOT .
"/theme/" .
dol_escape_js($conf->theme) .
"/img/object_calendarday.png";
7906 showOn: 'button', /* both has problem with autocompletion */
7907 buttonImage: '" . $buttonImage .
"',
7908 buttonImageOnly: true";
7912 $retstring .=
"</script>";
7916 $retstring .=
'<div class="nowraponall inline-block divfordateinput">';
7917 $retstring .=
'<input id="'.$prefix.
'" name="'.$prefix.
'" type="'.($usecalendar ==
'html' ?
"date" :
"text").
'" class="maxwidthdate'.(
getDolUserString(
'MAIN_OPTIMIZEFORTEXTBROWSER') ?
' textbrowser' :
'').
' center" maxlength="11" value="'.$formatted_date.
'"';
7918 $retstring .= ($disabled ?
' disabled' :
'');
7919 $retstring .= ($placeholder ?
' placeholder="' .
dol_escape_htmltag($placeholder) .
'"' :
'');
7920 $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
7921 $retstring .= ' autocomplete="off
">';
7925 $retstringbutton = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
">' . img_object($langs->trans("Disabled
"), 'calendarday', 'class="datecallink ui-datepicker-notrigger
"') . '</button>';
7926 $retstring .= $retstringbutton;
7929 $retstring .= '</div>';
7930 $retstring .= '<input type="hidden
" id="' . $prefix . 'day
" name="' . $prefix . 'day
" value="' . $sday . '">' . "\n
";
7931 $retstring .= '<input type="hidden
" id="' . $prefix . 'month
" name="' . $prefix . 'month
" value="' . $smonth . '">' . "\n
";
7932 $retstring .= '<input type="hidden
" id="' . $prefix . 'year
" name="' . $prefix . 'year
" value="' . $syear . '">' . "\n
";
7934 $retstring .= "Bad value of MAIN_POPUP_CALENDAR
";
7937 // Show date with combo selects
7939 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50imp
" id="' . $prefix . 'day
" name="' . $prefix . 'day
">';
7941 if ($emptydate || $set_time == -1) {
7942 $retstring .= '<option value="0
" selected> </option>';
7945 for ($day = 1; $day <= 31; $day++) {
7946 $retstring .= '<option value="' . $day . '"' . ($day == $sday ? ' selected' : '') . '>' . $day . '</option>';
7949 $retstring .= "</select>
";
7951 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'month
" name="' . $prefix . 'month
">';
7952 if ($emptydate || $set_time == -1) {
7953 $retstring .= '<option value="0
" selected> </option>';
7957 for ($month = 1; $month <= 12; $month++) {
7958 $retstring .= '<option value="' . $month . '"' . ($month == $smonth ? ' selected' : '') . '>';
7959 $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b
");
7960 $retstring .= "</option>
";
7962 $retstring .= "</select>
";
7965 if ($emptydate || $set_time == -1) {
7966 $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 . '">';
7968 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'year
" name="' . $prefix . 'year
">';
7970 $syear = (int) $syear;
7971 for ($year = $syear - 10; $year < (int) $syear + 10; $year++) {
7972 $retstring .= '<option value="' . $year . '"' . ($year == $syear ? ' selected' : '') . '>' . $year . '</option>';
7974 $retstring .= "</select>\n
";
7980 $retstring .= (($h == 2 || $h == 4) ? '<br>' : ' ');
7981 $retstring .= '<span class="nowraponall
">';
7987 if ($openinghours != '') {
7988 $openinghours = explode(',', $openinghours);
7989 $hourstart = $openinghours[0];
7990 $hourend = $openinghours[1];
7991 if ($hourend < $hourstart) {
7992 $hourend = $hourstart;
7997 $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
7998 $retstring .= ($fullday ? $fullday . 'hour
' : '') . '" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
">';
8000 $retstring .= '<option value="-1
"> </option>';
8002 for ($hour = $hourstart; $hour < $hourend; $hour++) {
8003 if (strlen($hour) < 2) {
8004 $hour = "0
" . $hour;
8006 $retstring .= '<option value="' . $hour . '"' . (($hour == $shour) ? ' selected' : '') . '>' . $hour;
8007 $retstring .= '</option>';
8009 $retstring .= '</select>';
8012 $retstring .= '<input type="hidden
" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
" value="' . $shour . '">' . "\n
";
8021 $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
8022 $retstring .= ($fullday ? $fullday . 'min
' : '') . '" id="' . $prefix . 'min
" name="' . $prefix . 'min
">';
8024 $retstring .= '<option value="-1
"> </option>';
8026 for ($min = 0; $min < 60; $min += $stepminutes) {
8027 $min_str = sprintf("%02d
", $min);
8028 $retstring .= '<option value="' . $min_str . '"' . (($min_str == $smin) ? ' selected' : '') . '>' . $min_str . '</option>';
8030 $retstring .= '</select>';
8032 $retstring .= '<input type="hidden
" id="' . $prefix . 'min
" name="' . $prefix . 'min
" value="' . $smin . '">' . "\n
";
8035 $retstring .= '<input type="hidden
" name="' . $prefix . 'sec
" value="' . $ssec . '">';
8039 $retstring .= '</span>';
8043 if (!empty($conf->use_javascript_ajax) && $addnowlink && !$disabled) {
8044 // Script which will be inserted in the onClick of the "Now
" link
8045 $reset_scripts = "";
8046 if ($addnowlink == 2) { // local computer time
8047 // pad add leading 0 on numbers
8048 $reset_scripts .= "Number.prototype.pad =
function(size) {
8049 var s = String(
this);
8050 while (s.length < (size || 2)) {s =
'0' + s;}
8053 var d =
new Date();
";
8056 // Generate the date part, depending on the use or not of the javascript calendar
8057 if ($addnowlink == 1) { // server time expressed in user time setup
8058 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
8059 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
8060 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
8061 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
8062 } elseif ($addnowlink == 2) {
8063 /* Disabled because the output does not use the string format defined by FormatDateShort key to forge the value into #prefix.
8064 * This break application for foreign languages.
8065 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(d.toLocaleDateString(\''.str_replace('_', '-', $langs->defaultlang).'\'));';
8066 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(d.getDate().pad());';
8067 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(parseInt(d.getMonth().pad()) + 1);';
8068 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(d.getFullYear());';
8070 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
8071 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
8072 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
8073 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
8075 /*if ($usecalendar == "eldy
")
8077 $base=DOL_URL_ROOT.'/core/';
8078 $reset_scripts .= 'resetDP(\''.$base.'\',\''.$prefix.'\',\''.$langs->trans("FormatDateShortJavaInput
").'\',\''.$langs->defaultlang.'\');';
8082 $reset_scripts .= 'this.form.elements[\''.$prefix.'day\'].value=formatDate(new Date(), \'d\'); ';
8083 $reset_scripts .= 'this.form.elements[\''.$prefix.'month\'].value=formatDate(new Date(), \'M\'); ';
8084 $reset_scripts .= 'this.form.elements[\''.$prefix.'year\'].value=formatDate(new Date(), \'yyyy\'); ';
8086 // Update the hour part
8089 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8091 //$reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); ';
8092 if ($addnowlink == 1) {
8093 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
8094 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
8095 } elseif ($addnowlink == 2) {
8096 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(d.getHours().pad());';
8097 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
8101 $reset_scripts .= ' } ';
8104 // Update the minute part
8107 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8109 //$reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); ';
8110 if ($addnowlink == 1) {
8111 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
8112 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
8113 } elseif ($addnowlink == 2) {
8114 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(d.getMinutes().pad());';
8115 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
8118 $reset_scripts .= ' } ';
8121 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
8122 if ($reset_scripts && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
8123 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonNow
" type="button" name="_useless
" value="now
" onClick="' . $reset_scripts . '">';
8124 $retstring .= $langs->trans("Now
");
8125 $retstring .= '</button> ';
8129 // Add a "Plus one hour
" link
8130 if ($conf->use_javascript_ajax && $addplusone && !$disabled) {
8131 // Script which will be inserted in the onClick of the "Add plusone
" link
8132 $reset_scripts = "";
8134 // Generate the date part, depending on the use or not of the javascript calendar
8135 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'dayinputnoreduce', 'tzuserrel') . '\');';
8136 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
8137 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
8138 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
8139 // Update the hour part
8142 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8144 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
8146 $reset_scripts .= ' } ';
8149 // Update the minute part
8152 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8154 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
8156 $reset_scripts .= ' } ';
8159 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
8160 if ($reset_scripts && empty($conf->dol_optimize_smallscreen)) {
8161 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonPlusOne
" type="button" name="_useless2
" value="plusone
" onClick="' . $reset_scripts . '">';
8162 $retstring .= $langs->trans("DateStartPlusOne
");
8163 $retstring .= '</button> ';
8167 // Add a link to set data
8168 if ($conf->use_javascript_ajax && !empty($adddateof) && !$disabled) {
8169 if (!is_array($adddateof)) {
8170 $arrayofdateof = array(array('adddateof' => $adddateof, 'labeladddateof' => $labeladddateof));
8172 $arrayofdateof = $adddateof;
8174 foreach ($arrayofdateof as $valuedateof) {
8175 $tmpadddateof = empty($valuedateof['adddateof']) ? 0 : $valuedateof['adddateof'];
8176 $tmplabeladddateof = empty($valuedateof['labeladddateof']) ? '' : $valuedateof['labeladddateof'];
8177 $tmparray = dol_getdate($tmpadddateof);
8178 if (empty($tmplabeladddateof)) {
8179 $tmplabeladddateof = $langs->trans("DateInvoice
");
8181 $reset_scripts = 'console.log(\'Click on now link\'); ';
8182 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(\''.dol_print_date($tmpadddateof, 'dayinputnoreduce').'\');';
8183 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(\''.$tmparray['mday'].'\');';
8184 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(\''.$tmparray['mon'].'\');';
8185 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(\''.$tmparray['year'].'\');';
8186 $retstring .= ' - <button class="dpInvisibleButtons datenowlink
" id="dateofinvoice
" type="button" name="_dateofinvoice
" value="now
" onclick="'.$reset_scripts.'">'.$tmplabeladddateof.'</button>';
8202 public function selectTypeDuration($prefix, $selected = 'i', $excludetypes = array(), $morecss = 'minwidth75 maxwidth100')
8206 $TDurationTypes = $this->getDurationTypes($langs);
8208 // Removed undesired duration types
8209 foreach ($excludetypes as $value) {
8210 unset($TDurationTypes[$value]);
8213 $retstring = '<select class="flat
'.($morecss ? ' '.$morecss : '').'" id="select_
' . $prefix . 'type_duration
" name="' . $prefix . 'type_duration
">';
8214 foreach ($TDurationTypes as $key => $typeduration) {
8215 $retstring .= '<option value="' . $key . '"';
8216 if ($key == $selected) {
8217 $retstring .= " selected
";
8219 $retstring .= ">
" . $typeduration . "</option>
";
8221 $retstring .= "</select>
";
8223 $retstring .= ajax_combobox('select_' . $prefix . 'type_duration');
8228 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
8243 public function select_duration($prefix, $iSecond = '', $disabled = 0, $typehour = 'select', $minunderhours = 0, $nooutput = 0)
8248 $retstring = '<span class="nowraponall
">';
8254 if ($iSecond != '') {
8255 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
8257 $hourSelected = convertSecondToTime($iSecond, 'allhour');
8258 $minSelected = convertSecondToTime($iSecond, 'min');
8261 if ($typehour == 'select') {
8262 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'hour
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . '>';
8263 for ($hour = 0; $hour < 25; $hour++) { // For a duration, we allow 24 hours
8264 $retstring .= '<option value="' . $hour . '"';
8265 if (is_numeric($hourSelected) && $hourSelected == $hour) {
8266 $retstring .= " selected
";
8268 $retstring .= ">
" . $hour . "</option>
";
8270 $retstring .= "</select>
";
8271 } elseif ($typehour == 'text' || $typehour == 'textselect') {
8272 $retstring .= '<input placeholder="' . $langs->trans('HourShort
') . '" type="number
" min="0
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputhour right
" value="' . (($hourSelected != '') ? ((int) $hourSelected) : '') . '">';
8274 return 'BadValueForParameterTypeHour';
8277 if ($typehour != 'text') {
8278 $retstring .= ' ' . $langs->trans('HourShort');
8280 $retstring .= '<span class="">:</span>';
8284 if ($minunderhours) {
8285 $retstring .= '<br>';
8287 if ($typehour != 'text') {
8288 $retstring .= '<span class="hideonsmartphone
"> </span>';
8292 if ($typehour == 'select' || $typehour == 'textselect') {
8293 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'min
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . '>';
8294 $step = getDolGlobalInt('MAIN_DURATION_STEP');
8295 $duration_step = ($step > 0) ? $step : 5;
8296 for ($min = 0; $min <= 59; $min += $duration_step) {
8297 $retstring .= '<option value="' . $min . '"';
8298 if (is_numeric($minSelected) && $minSelected == $min) {
8299 $retstring .= ' selected';
8301 $retstring .= '>' . $min . '</option>';
8303 $retstring .= "</select>
";
8304 } elseif ($typehour == 'text') {
8305 $retstring .= '<input placeholder="' . $langs->trans('MinuteShort
') . '" type="number
" min="0
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputminute right
" value="' . (($minSelected != '') ? ((int) $minSelected) : '') . '">';
8308 if ($typehour != 'text') {
8309 $retstring .= ' ' . $langs->trans('MinuteShort');
8312 $retstring .= "</span>
";
8314 if (!empty($nooutput)) {
8342 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)
8344 global $langs, $conf;
8349 if (is_null($ajaxoptions)) {
8350 $ajaxoptions = array();
8353 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
8356 if ($selected && empty($selected_input_value)) {
8357 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
8358 $tickettmpselect = new Ticket($this->db);
8359 $tickettmpselect->fetch((int) $selected);
8360 $selected_input_value = $tickettmpselect->ref;
8361 unset($tickettmpselect);
8365 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/ticket/ajax/tickets.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
8367 if (empty($hidelabel)) {
8368 $out .= $langs->trans("RefOrLabel
") . ' : ';
8369 } elseif ($hidelabel > 1) {
8370 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
8371 if ($hidelabel == 2) {
8372 $out .= img_picto($langs->trans("Search
"), 'search');
8375 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
8376 if ($hidelabel == 3) {
8377 $out .= img_picto($langs->trans("Search
"), 'search');
8380 $out .= $this->selectTicketsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
8383 if (empty($nooutput)) {
8408 public function selectTicketsList($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
8413 $outarray = array();
8415 $selectFields = " p.rowid, p.ref, p.message
";
8418 $sql .= $selectFields;
8419 $sql .= " FROM
" . $this->db->prefix() . "ticket as p
";
8420 $sql .= ' WHERE p.entity IN (' . getEntity('ticket') . ')';
8422 // Add criteria on ref/label
8423 if ($filterkey != '') {
8425 $prefix = getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '' : '%'; // Can use index if TICKET_DONOTSEARCH_ANYWHERE is on
8426 // For natural search
8427 $search_crit = explode(' ', $filterkey);
8429 if (count($search_crit) > 1) {
8432 foreach ($search_crit as $crit) {
8436 $sql .= "(p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%' OR p.subject LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
8440 if (count($search_crit) > 1) {
8446 $sql .= $this->db->plimit($limit, 0);
8448 // Build output string
8449 dol_syslog(get_class($this) . "::selectTicketsList search tickets
", LOG_DEBUG);
8450 $result = $this->db->query($sql);
8452 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
8453 require_once DOL_DOCUMENT_ROOT . '/core/lib/ticket.lib.php';
8455 $num = $this->db->num_rows($result);
8460 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
8461 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('TICKET_USE_SEARCH_TO_SELECT'));
8464 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
8467 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
8468 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
8469 if (getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
8470 if ($showempty && !is_numeric($showempty)) {
8471 $textifempty = $langs->trans($showempty);
8473 $textifempty .= $langs->trans("All
");
8476 if ($showempty && !is_numeric($showempty)) {
8477 $textifempty = $langs->trans($showempty);
8481 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
8485 while ($num && $i < $num) {
8488 $objp = $this->db->fetch_object($result);
8490 $this->constructTicketListOption($objp, $opt, $optJson, $selected, $filterkey);
8491 '@phan-var-force array{key:string,value:mixed,type:int} $optJson';
8493 // "key
" value of json key array is used by jQuery automatically as selected value
8494 // "label
" value of json key array is used by jQuery automatically as text for combo box
8496 array_push($outarray, $optJson);
8501 $out .= '</select>';
8503 $this->db->free($result);
8505 if (empty($outputmode)) {
8510 dol_print_error($this->db);
8527 protected function constructTicketListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
8533 $outkey = $objp->rowid;
8534 $outref = $objp->ref;
8536 $opt = '<option value="
' . $objp->rowid . '"';
8537 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
8540 $objRef = $objp->ref;
8541 if (!empty($filterkey) && $filterkey != '') {
8542 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1);
8545 $opt .= "</option>\n
";
8546 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
8568 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)
8570 global $langs, $conf;
8575 if (is_null($ajaxoptions)) {
8576 $ajaxoptions = array();
8579 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
8582 if ($selected && empty($selected_input_value)) {
8583 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
8584 $projecttmpselect = new Project($this->db);
8585 $projecttmpselect->fetch((int) $selected);
8586 $selected_input_value = $projecttmpselect->ref;
8587 unset($projecttmpselect);
8591 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/projet/ajax/projects.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
8593 if (empty($hidelabel)) {
8594 $out .= $langs->trans("RefOrLabel
") . ' : ';
8595 } elseif ($hidelabel > 1) {
8596 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
8597 if ($hidelabel == 2) {
8598 $out .= img_picto($langs->trans("Search
"), 'search');
8601 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
8602 if ($hidelabel == 3) {
8603 $out .= img_picto($langs->trans("Search
"), 'search');
8606 $out .= $this->selectProjectsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
8609 if (empty($nooutput)) {
8633 public function selectProjectsList($selected = '', $htmlname = 'projectid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
8635 global $langs, $conf;
8638 $outarray = array();
8640 $selectFields = " p.rowid, p.ref
";
8643 $sql .= $selectFields;
8644 $sql .= " FROM
" . $this->db->prefix() . "projet as p
";
8645 $sql .= ' WHERE p.entity IN (' . getEntity('project') . ')';
8647 // Add criteria on ref/label
8648 if ($filterkey != '') {
8650 $prefix = !getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
8651 // For natural search
8652 $search_crit = explode(' ', $filterkey);
8654 if (count($search_crit) > 1) {
8657 foreach ($search_crit as $crit) {
8661 $sql .= "p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
8665 if (count($search_crit) > 1) {
8671 $sql .= $this->db->plimit($limit, 0);
8673 // Build output string
8674 dol_syslog(get_class($this) . "::selectProjectsList search projects
", LOG_DEBUG);
8675 $result = $this->db->query($sql);
8677 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
8678 require_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php';
8680 $num = $this->db->num_rows($result);
8685 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
8686 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('PROJECT_USE_SEARCH_TO_SELECT'));
8689 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
8692 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
8693 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
8694 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
8695 if ($showempty && !is_numeric($showempty)) {
8696 $textifempty = $langs->trans($showempty);
8698 $textifempty .= $langs->trans("All
");
8701 if ($showempty && !is_numeric($showempty)) {
8702 $textifempty = $langs->trans($showempty);
8706 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
8710 while ($num && $i < $num) {
8713 $objp = $this->db->fetch_object($result);
8715 $this->constructProjectListOption($objp, $opt, $optJson, $selected, $filterkey);
8717 // "key
" value of json key array is used by jQuery automatically as selected value
8718 // "label
" value of json key array is used by jQuery automatically as text for combo box
8720 array_push($outarray, $optJson);
8725 $out .= '</select>';
8727 $this->db->free($result);
8729 if (empty($outputmode)) {
8734 dol_print_error($this->db);
8753 protected function constructProjectListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
8759 $label = $objp->label;
8761 $outkey = $objp->rowid;
8762 $outref = $objp->ref;
8763 $outlabel = $objp->label;
8764 $outtype = $objp->fk_product_type;
8766 $opt = '<option value="
' . $objp->rowid . '"';
8767 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
8770 $objRef = $objp->ref;
8771 if (!empty($filterkey) && $filterkey != '') {
8772 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1);
8775 $opt .= "</option>\n
";
8776 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
8800 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())
8802 global $langs, $conf;
8807 if (is_null($ajaxoptions)) {
8808 $ajaxoptions = array();
8811 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
8814 if ($selected && empty($selected_input_value)) {
8815 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
8816 $adherenttmpselect = new Adherent($this->db);
8817 $adherenttmpselect->fetch((int) $selected);
8818 $selected_input_value = $adherenttmpselect->ref;
8819 unset($adherenttmpselect);
8824 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/adherents/ajax/adherents.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
8826 if (empty($hidelabel)) {
8827 $out .= $langs->trans("RefOrLabel
") . ' : ';
8828 } elseif ($hidelabel > 1) {
8829 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
8830 if ($hidelabel == 2) {
8831 $out .= img_picto($langs->trans("Search
"), 'search');
8834 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
8835 if ($hidelabel == 3) {
8836 $out .= img_picto($langs->trans("Search
"), 'search');
8841 $out .= $this->selectMembersList($selected, $htmlname, $filtertype, $limit, $filterkey, $status, 0, $showempty, $forcecombo, $morecss, $excludeids);
8844 if (empty($nooutput)) {
8869 public function selectMembersList($selected = '', $htmlname = 'adherentid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '', $excludeids = array())
8871 global $langs, $conf;
8874 $outarray = array();
8876 $selectFields = " p.rowid, p.ref, p.firstname, p.lastname, p.fk_adherent_type
";
8879 $sql .= $selectFields;
8880 $sql .= " FROM
" . $this->db->prefix() . "adherent as p
";
8881 $sql .= ' WHERE p.entity IN (' . getEntity('adherent') . ')';
8883 // Add criteria on ref/label
8884 if ($filterkey != '') {
8886 $prefix = !getDolGlobalString('MEMBER_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
8887 // For natural search
8888 $search_crit = explode(' ', $filterkey);
8890 if (count($search_crit) > 1) {
8893 foreach ($search_crit as $crit) {
8897 $sql .= "(p.firstname LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
8898 $sql .= " OR p.lastname LIKE
'" . $this->db->escape($prefix . $crit) . "%')
";
8901 if (count($search_crit) > 1) {
8906 if ($status != -1) {
8907 $sql .= ' AND statut = ' . ((int) $status);
8909 if (!empty($excludeids)) {
8910 $sql .= " AND p.rowid NOT IN (
" . $this->db->sanitize(implode(',', $excludeids)) . ")
";
8912 $sql .= $this->db->plimit($limit, 0);
8914 // Build output string
8915 dol_syslog(get_class($this) . "::selectMembersList search adherents
", LOG_DEBUG);
8916 $result = $this->db->query($sql);
8918 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
8919 require_once DOL_DOCUMENT_ROOT . '/core/lib/member.lib.php';
8921 $num = $this->db->num_rows($result);
8926 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
8927 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('PROJECT_USE_SEARCH_TO_SELECT'));
8930 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
8933 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
8934 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
8935 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
8936 if ($showempty && !is_numeric($showempty)) {
8937 $textifempty = $langs->trans($showempty);
8939 $textifempty .= $langs->trans("All
");
8942 if ($showempty && !is_numeric($showempty)) {
8943 $textifempty = $langs->trans($showempty);
8947 $out .= '<option value="-1
" selected>' . $textifempty . '</option>';
8951 while ($num && $i < $num) {
8954 $objp = $this->db->fetch_object($result);
8956 $this->constructMemberListOption($objp, $opt, $optJson, $selected, $filterkey);
8959 // "key
" value of json key array is used by jQuery automatically as selected value
8960 // "label
" value of json key array is used by jQuery automatically as text for combo box
8962 array_push($outarray, $optJson);
8967 $out .= '</select>';
8969 $this->db->free($result);
8971 if (empty($outputmode)) {
8976 dol_print_error($this->db);
8993 protected function constructMemberListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
8999 $outkey = $objp->rowid;
9000 $outlabel = dolGetFirstLastname($objp->firstname, $objp->lastname);
9001 $outtype = $objp->fk_adherent_type;
9003 $opt = '<option value="
' . $objp->rowid . '"';
9004 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
9006 if (!empty($filterkey) && $filterkey != '') {
9007 $outlabel = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $outlabel, 1);
9010 $opt .= "</option>\n
";
9012 $optJson = array('key' => $outkey, 'value' => $outlabel, 'type' => $outtype);
9036 public function selectForForms($objectdesc, $htmlname, $preSelectedValue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $disabled = 0, $selected_input_value = '', $objectfield = '')
9038 global $conf, $extrafields, $user;
9040 // Example of common usage for a link to a thirdparty
9042 // We got this in a modulebuilder form of "
MyObject" of module "mymodule
".
9043 // 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
9044 // $objectdesc = 'Societe'
9045 // $objectfield = Method 1: 'myobject@mymodule:fk_soc' ('fk_soc' is code to retrieve myobject->fields['fk_soc'])
9046 // 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__))
" ...)
9048 // We got this when showing an extrafields on resource that is a link to societe
9049 // 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
9050 // $objectdesc = 'Societe'
9051 // $objectfield = Method 1: 'resource:options_link_to_societe'
9052 // Method 2 recommended (it can be the array): array("type"=>'Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))" ...)
9061 $objectdescorig = $objectdesc;
9063 $InfoFieldList = array();
9068 if (is_array($objectfield)) {
9069 $objectdesc = $objectfield[
'type'];
9070 $objectdesc = preg_replace(
'/^integer[^:]*:/',
'', $objectdesc);
9071 } elseif ($objectfield) {
9073 $tmparray = explode(
':', $objectfield);
9076 $objectforfieldstmp = fetchObjectByElement(0, strtolower($tmparray[0]));
9078 if (is_object($objectforfieldstmp)) {
9082 if (preg_match(
'/^options_(.*)$/', $tmparray[1], $reg)) {
9086 $extrafields->fetch_name_optionals_label($objectforfieldstmp->table_element);
9088 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element][
'type'][$key]) && $extrafields->attributes[$objectforfieldstmp->table_element][
'type'][$key] ==
'link') {
9089 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element][
'param'][$key][
'options'])) {
9090 $tmpextrafields = array_keys($extrafields->attributes[$objectforfieldstmp->table_element][
'param'][$key][
'options']);
9091 $objectdesc = $tmpextrafields[0];
9096 if (array_key_exists($tmparray[1], $objectforfieldstmp->fields)) {
9097 $objectdesc = $objectforfieldstmp->fields[$tmparray[1]][
'type'];
9098 $objectdesc = preg_replace(
'/^integer[^:]*:/',
'', $objectdesc);
9109 $InfoFieldList = explode(
":", $objectdesc, 4);
9110 $vartmp = (empty($InfoFieldList[3]) ?
'' : $InfoFieldList[3]);
9112 if (preg_match(
'/^.*:(\w*)$/', $vartmp, $reg)) {
9113 $InfoFieldList[4] = $reg[1];
9115 $InfoFieldList[3] = preg_replace(
'/:\w*$/',
'', $vartmp);
9117 $classname = $InfoFieldList[0];
9118 $classpath = empty($InfoFieldList[1]) ?
'' : $InfoFieldList[1];
9120 $filter = empty($InfoFieldList[3]) ?
'' : $InfoFieldList[3];
9121 $sortfield = empty($InfoFieldList[4]) ?
'' : $InfoFieldList[4];
9124 $objecttmp = fetchObjectByElement(0, strtolower($InfoFieldList[0]));
9127 if (empty($objecttmp) && !empty($classpath)) {
9130 if ($classname && class_exists($classname)) {
9131 $objecttmp =
new $classname($this->db);
9138 $sharedentities = (is_object($objecttmp) && property_exists($objecttmp,
'element')) ?
getEntity($objecttmp->element) : strtolower($classname);
9139 $filter = str_replace(
9140 array(
'__ENTITY__',
'__SHARED_ENTITIES__',
'__USER_ID__'),
9141 array($conf->entity, $sharedentities, $user->id),
9145 if (!is_object($objecttmp)) {
9146 dol_syslog(
'selectForForms: Error bad setup of field objectdescorig=' . $objectdescorig.
', objectfield='.(is_array($objectfield) ?
'array' : $objectfield).
', objectdesc='.$objectdesc, LOG_WARNING);
9147 return 'selectForForms: Error bad setup of field objectdescorig=' . $objectdescorig.
', objectfield='.(is_array($objectfield) ?
'array' : $objectfield).
', objectdesc='.$objectdesc;
9149 '@phan-var-force CommonObject $objecttmp';
9152 $prefixforautocompletemode = $objecttmp->element;
9153 if ($prefixforautocompletemode ==
'societe') {
9154 $prefixforautocompletemode =
'company';
9156 if ($prefixforautocompletemode ==
'product') {
9157 $prefixforautocompletemode =
'produit';
9160 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) .
'_USE_SEARCH_TO_SELECT';
9162 dol_syslog(get_class($this) .
"::selectForForms filter=" . $filter, LOG_DEBUG);
9166 if (!empty($conf->use_javascript_ajax) &&
getDolGlobalString($confkeyforautocompletemode) && !$forcecombo) {
9170 if ($preSelectedValue && empty($selected_input_value)) {
9171 $objecttmp->fetch($preSelectedValue);
9172 $selected_input_value = ($prefixforautocompletemode ==
'company' ? $objecttmp->name : $objecttmp->ref);
9174 $oldValueForShowOnCombobox = 0;
9175 foreach ($objecttmp->fields as $fieldK => $fielV) {
9176 if (!array_key_exists(
'showoncombobox', $fielV) || !$fielV[
'showoncombobox'] || empty($objecttmp->$fieldK)) {
9180 if (!$oldValueForShowOnCombobox) {
9181 $selected_input_value =
'';
9184 $selected_input_value .= $oldValueForShowOnCombobox ?
' - ' :
'';
9185 $selected_input_value .= $objecttmp->$fieldK;
9186 $oldValueForShowOnCombobox = empty($fielV[
'showoncombobox']) ? 0 : $fielV[
'showoncombobox'];
9191 $urlforajaxcall = DOL_URL_ROOT .
'/core/ajax/selectobject.php';
9192 $urloption =
'htmlname=' . urlencode($htmlname) .
'&outjson=1&objectdesc=' . urlencode($objectdescorig) . (is_scalar($objectfield) ?
'&objectfield='.urlencode($objectfield) :
'') . ($sortfield ?
'&sortfield=' . urlencode($sortfield) :
'');
9197 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
9198 $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) .
'"' :
'') .
' />';
9201 $out .= $this->selectForFormsList($objecttmp, $htmlname, $preSelectedValue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled, $sortfield, $filter);
9229 public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty =
'', $searchkey =
'', $placeholder =
'', $morecss =
'', $moreparams =
'', $forcecombo = 0, $outputmode = 0, $disabled = 0, $sortfield =
'', $filter =
'', $sortorder =
'ASC')
9231 global $langs, $user, $hookmanager;
9235 $prefixforautocompletemode = $objecttmp->element;
9236 if ($prefixforautocompletemode ==
'societe') {
9237 $prefixforautocompletemode =
'company';
9239 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) .
'_USE_SEARCH_TO_SELECT';
9241 if (!empty($objecttmp->fields)) {
9242 $tmpfieldstoshow =
'';
9243 foreach ($objecttmp->fields as $key => $val) {
9244 if (! (
int)
dol_eval((
string) $val[
'enabled'], 1, 1,
'1')) {
9247 if (!empty($val[
'showoncombobox'])) {
9248 $tmpfieldstoshow .= ($tmpfieldstoshow ?
',' :
'') .
't.' . $key;
9251 if ($tmpfieldstoshow) {
9252 $fieldstoshow = $tmpfieldstoshow;
9254 } elseif ($objecttmp->element ===
'category') {
9255 $fieldstoshow =
't.label';
9258 $objecttmp->fields[
'ref'] = array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'enabled' => 1,
'position' => 10,
'visible' => 4,
'showoncombobox' => 1);
9261 if (empty($fieldstoshow)) {
9262 if (!empty($objecttmp->parent_element)) {
9263 $fieldstoshow =
'o.ref';
9264 if (empty($sortfield)) {
9265 $sortfield =
'o.ref';
9267 if (in_array($objecttmp->element, [
'commandedet',
'propaldet',
'facturedet',
'expeditiondet'])) {
9268 $fieldstoshow .=
',p.ref AS p_ref,p.label,t.description';
9269 $sortfield .=
', p.ref';
9271 } elseif (isset($objecttmp->fields[
'ref'])) {
9272 $fieldstoshow =
't.ref';
9274 $langs->load(
"errors");
9275 $this->error = $langs->trans(
"ErrorNoFieldWithAttributeShowoncombobox");
9276 return $langs->trans(
'ErrorNoFieldWithAttributeShowoncombobox');
9281 $outarray = array();
9282 $tmparray = array();
9287 $sql =
"SELECT t.rowid, " . $fieldstoshow .
" FROM " . $this->db->prefix() . $this->db->sanitize($objecttmp->table_element) .
" as t";
9288 if (!empty($objecttmp->isextrafieldmanaged)) {
9289 $extrafieldTable = $objecttmp->table_element;
9290 if ($extrafieldTable ==
'categorie') {
9291 $extrafieldTable =
'categories';
9293 $sql .=
" LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($extrafieldTable) .
"_extrafields as e ON t.rowid = e.fk_object";
9295 if (!empty($objecttmp->parent_element)) {
9296 '@phan-var-force CommonObjectLine $objecttmp';
9298 $sql .=
" INNER JOIN " . $this->db->prefix() . $this->db->sanitize($parent_properties[
'table_element']) .
" as o ON o.rowid = t.".$objecttmp->fk_parent_attribute;
9300 if (!empty($objecttmp->parent_element) && in_array($objecttmp->parent_element, [
'commande',
'propal',
'facture',
'expedition'])) {
9301 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product as p ON p.rowid = t.fk_product";
9303 if (!empty($objecttmp->ismultientitymanaged)) {
9304 if ($objecttmp->ismultientitymanaged == 1) {
9307 if (!is_numeric($objecttmp->ismultientitymanaged)) {
9308 $tmparray = explode(
'@', $objecttmp->ismultientitymanaged);
9309 $sql .=
" INNER JOIN " . $this->db->prefix() . $this->db->sanitize($tmparray[1]) .
" as parenttable ON parenttable.rowid = t." . $this->db->sanitize($tmparray[0]);
9314 $parameters = array(
9315 'object' => $objecttmp,
9316 'htmlname' => $htmlname,
9317 'filter' => $filter,
9318 'searchkey' => $searchkey
9321 $reshook = $hookmanager->executeHooks(
'selectForFormsListWhere', $parameters);
9322 if (!empty($hookmanager->resPrint)) {
9323 $sql .= $hookmanager->resPrint;
9325 $sql .=
" WHERE 1=1";
9328 if (!empty($objecttmp->ismultientitymanaged)) {
9329 if ($objecttmp->ismultientitymanaged == 1) {
9330 $sql .=
" AND t.entity IN (" .
getEntity($objecttmp->element) .
")";
9332 if (!is_numeric($objecttmp->ismultientitymanaged)) {
9333 $sql .=
" AND parenttable.entity = t." . $this->db->sanitize($tmparray[0]);
9337 if ($objecttmp->ismultientitymanaged ===
'fk_soc@societe') {
9338 if (!$user->hasRight(
'societe',
'client',
'voir') && empty($user->socid)) {
9339 $sql .=
" AND EXISTS (SELECT sc.rowid FROM ".$this->db->prefix() .
"societe_commerciaux as sc";
9340 $sql .=
" WHERE sc.fk_soc = t.fk_soc AND sc.fk_user = ".((int) $user->id).
")";
9346 if (!empty($user->socid)) {
9347 if ($objecttmp->element ==
'societe') {
9348 $sql .=
" AND t.rowid = " . ((int) $user->socid);
9349 } elseif (!empty($objecttmp->fields[
'fk_soc']) || !empty($objecttmp->fields[
't.fk_soc']) || property_exists($objecttmp,
'fk_soc') || property_exists($objecttmp,
'socid')) {
9350 $sql .=
" AND t.fk_soc = " . ((int) $user->socid);
9354 $splittedfieldstoshow = explode(
',', $fieldstoshow);
9355 foreach ($splittedfieldstoshow as &$field2) {
9356 if (is_numeric($pos = strpos($field2,
' '))) {
9357 $field2 = substr($field2, 0, $pos);
9360 if ($searchkey !=
'') {
9367 if ($errormessage) {
9368 return 'Error forging a SQL request from an universal criteria: ' . $errormessage;
9372 $sql .= $this->db->order($sortfield ? $sortfield : $fieldstoshow, $sortorder);
9377 $resql = $this->db->query($sql);
9380 $out .=
'<select id="' . $htmlname .
'" class="flat minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') . ($moreparams ?
' ' . $moreparams :
'') .
' name="' . $htmlname .
'">' .
"\n";
9383 $textifempty =
' ';
9387 if ($showempty && !is_numeric($showempty)) {
9388 $textifempty = $langs->trans($showempty);
9390 $textifempty .= $langs->trans(
"All");
9394 $out .=
'<option value="-1">' . $textifempty .
'</option>' .
"\n";
9397 $num = $this->db->num_rows($resql);
9401 $obj = $this->db->fetch_object($resql);
9404 $tmparray = explode(
',', $fieldstoshow);
9405 $oldvalueforshowoncombobox = 0;
9406 foreach ($tmparray as $key => $val) {
9407 $val = preg_replace(
'/(t|p|o)\./',
'', $val);
9408 $label .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val][
'showoncombobox'] ?
' - ' :
' ') :
'');
9409 $labelhtml .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val][
'showoncombobox'] ?
' - ' :
' ') :
'');
9410 $label .= $obj->$val;
9411 $labelhtml .= $obj->$val;
9413 $oldvalueforshowoncombobox = empty($objecttmp->fields[$val][
'showoncombobox']) ? 0 : $objecttmp->fields[$val][
'showoncombobox'];
9415 if (empty($outputmode)) {
9416 if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) {
9417 $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>';
9419 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
9422 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label));
9426 if (($i % 10) == 0) {
9432 $out .=
'</select>' .
"\n";
9435 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
9442 $this->result = array(
'nbofelement' => $num);
9460 public static function radio($htmlName, $radioItems, $selected =
'', $moreGlobalParams = [])
9464 'disabled' =>
false,
9467 'name' => $htmlName,
9469 'unescapedAttr' => [],
9471 'unescapedAttrLabel' => [],
9472 'labelIsHtml' => false
9479 if (!empty($radioItems)) {
9480 foreach ($radioItems as $key => $item) {
9482 if (!is_array($item)) {
9494 'value' => !isset($item[
'attr'][
'value']) ? $key :
'',
9504 if ((is_array($selected) && in_array($item[
'attr'][
'value'], $selected,
true)) || $selected === $item[
'attr'][
'value']) {
9505 $item[
'attr'][
'checked'] =
true;
9513 $text = $item[
'labelIsHtml'] ? $item[
'label'] : htmlspecialchars($item[
'label'], ENT_QUOTES | ENT_SUBSTITUTE);
9516 $out .=
'<label ' . $labelAttributes .
'><input ' . $inputAttributes .
' /> ' . $text .
'</label> ';
9547 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)
9549 global $conf, $langs;
9556 if ($value_as_key) {
9557 $array = array_combine($array, $array);
9560 '@phan-var-force array{label:string,data-html:string,disable?:int<0,1>,css?:string} $array';
9564 if ($addjscombo < 0) {
9571 $idname = str_replace(array(
'[',
']'), array(
'',
''), $htmlname);
9572 $out .=
'<select id="' . preg_replace(
'/^\./',
'', $idname) .
'" ' . ($disabled ?
'disabled="disabled" ' :
'') .
'class="flat ' . (preg_replace(
'/^\./',
'', $htmlname)) . ($morecss ?
' ' . $morecss :
'') .
' selectformat"';
9573 $out .=
' name="' . preg_replace(
'/^\./',
'', $htmlname) .
'" ' . ($moreparam ? $moreparam :
'');
9577 $textforempty =
' ';
9578 if (!empty($conf->use_javascript_ajax)) {
9579 $textforempty =
' ';
9581 if (!is_numeric($show_empty)) {
9582 $textforempty = $show_empty;
9584 $out .=
'<option class="optiongrey" ' . ($moreparamonempty ? $moreparamonempty .
' ' :
'') .
'value="' . (((
int) $show_empty) < 0 ? $show_empty : -1) .
'"' . (
$id == $show_empty ?
' selected' :
'') .
'>' . $textforempty .
'</option>' .
"\n";
9586 if (is_array($array)) {
9589 foreach ($array as $key => $value) {
9590 if (!is_array($value)) {
9591 $array[$key] = $langs->trans($value);
9593 $array[$key][
'label'] = $langs->trans($value[
'label']);
9598 if ($sort ==
'ASC') {
9600 } elseif ($sort ==
'DESC') {
9604 foreach ($array as $key => $tmpvalue) {
9605 if (is_array($tmpvalue)) {
9606 $value = $tmpvalue[
'label'];
9608 $disabled = empty($tmpvalue[
'disabled']) ?
'' :
' disabled';
9609 $style = empty($tmpvalue[
'css']) ?
'' :
' class="' . $tmpvalue[
'css'] .
'"';
9616 if (!empty($disablebademail)) {
9617 if (($disablebademail == 1 && !preg_match(
'/<.+@.+>/', $value))
9618 || ($disablebademail == 2 && preg_match(
'/---/', $value))) {
9619 $disabled =
' disabled';
9620 $style =
' class="warning"';
9623 if ($key_in_label) {
9624 if (empty($nohtmlescape)) {
9627 $selectOptionValue = $key .
' - ' . ($maxlen ?
dol_trunc($value, $maxlen) : $value);
9630 if (empty($nohtmlescape)) {
9633 $selectOptionValue = $maxlen ?
dol_trunc($value, $maxlen) : $value;
9635 if ($value ==
'' || $value ==
'-') {
9636 $selectOptionValue =
' ';
9639 $out .=
'<option value="' . $key .
'"';
9640 $out .= $style . $disabled;
9641 $out .= is_array($tmpvalue) && !empty($tmpvalue[
'parent']) ?
' parent="' .
dolPrintHTMLForAttribute($tmpvalue[
'parent']) .
'"' :
'';
9642 if (is_array(
$id)) {
9643 if (in_array($key,
$id) && !$disabled) {
9644 $out .=
' selected';
9648 if (
$id !=
'' && ((
$id == (
string) $key) || (
$id ==
'ifone' && count($array) == 1)) && !$disabled) {
9649 $out .=
' selected';
9653 if (is_array($tmpvalue)) {
9654 foreach ($tmpvalue as $keyforvalue => $valueforvalue) {
9655 if ($keyforvalue ==
'labelhtml') {
9656 $keyforvalue =
'data-html';
9658 if (preg_match(
'/^data-/', $keyforvalue)) {
9659 $out .=
' '.dol_escape_htmltag($keyforvalue).
'="'.
dol_escape_htmltag($valueforvalue).
'"';
9662 } elseif (!empty($nohtmlescape)) {
9667 $out .= $selectOptionValue;
9668 $out .=
"</option>\n";
9671 $out .=
"</select>";
9674 if ($addjscombo && $jsbeautify) {
9676 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
9677 $out .=
ajax_combobox($idname, array(), 0, 0,
'resolve', (((
int) $show_empty) < 0 ? (
string) $show_empty :
'-1'), $morecss);
9701 public static function selectArrayAjax($htmlname, $url,
$id =
'', $moreparam =
'', $moreparamtourl =
'', $disabled = 0, $minimumInputLength = 1, $morecss =
'', $callurlonselect = 0, $placeholder =
'', $acceptdelayedhtml = 0)
9704 global $delayedhtmlcontent;
9707 if (!
getDolGlobalString(
'MAIN_USE_JQUERY_MULTISELECT') && !defined(
'REQUIRE_JQUERY_MULTISELECT')) {
9711 $out =
'<select type="text" class="' . $htmlname . ($morecss ?
' ' . $morecss :
'') .
'" ' . ($moreparam ? $moreparam .
' ' :
'') .
'name="' . $htmlname .
'"></select>';
9714 if (!empty($conf->use_javascript_ajax)) {
9715 $tmpplugin =
'select2';
9716 $outdelayed =
"\n" .
'<!-- JS CODE TO ENABLE ' . $tmpplugin .
' for id ' . $htmlname .
' -->
9717 <script nonce="' .
getNonce() .
'">
9718 $(document).ready(function () {
9720 ' . ($callurlonselect ?
'var saveRemoteData = [];' :
'') .
'
9722 $(".' . $htmlname .
'").select2({
9725 url: "' . $url .
'",
9728 data: function (params) {
9730 q: params.term, // search term
9734 processResults: function (data) {
9735 // parse the results into the format expected by Select2.
9736 // since we are using custom formatting functions we do not need to alter the remote JSON data
9737 //console.log(data);
9738 saveRemoteData = data;
9739 /* format json result for select2 */
9741 $.each( data, function( key, value ) {
9742 result.push({id: key, text: value.text});
9744 //return {results:[{id:\'none\', text:\'aa\'}, {id:\'rrr\', text:\'Red\'},{id:\'bbb\', text:\'Search a into projects\'}], more:false}
9745 //console.log(result);
9746 return {results: result, more: false}
9750 language: (typeof select2arrayoflanguage === \'undefined\') ? \'en\' : select2arrayoflanguage,
9751 containerCssClass: \':all:\', /* Line to add class from the original SELECT propagated to the new <span class="select2-selection...> tag */
9753 escapeMarkup:
function (markup) {
return markup; },
9754 minimumInputLength:
' . ((int) $minimumInputLength) . ',
9755 formatResult:
function (result, container, query, escapeMarkup) {
9756 return escapeMarkup(result.text);
9760 ' . ($callurlonselect ? '
9762 $(
".' . $htmlname . '").change(
function() {
9763 var selected = $(\
'.' .
dol_escape_js($htmlname) .
'\').val();
9764 console.log(
"We select in selectArrayAjax the entry "+selected)
9766 $.each( saveRemoteData,
function( key, value ) {
9767 if (key == selected)
9769 console.log(
"selectArrayAjax - Do a redirect to "+value.url)
9770 location.assign(value.url);
9779 if ($acceptdelayedhtml) {
9780 $delayedhtmlcontent .= $outdelayed;
9782 $out .= $outdelayed;
9806 public static function selectArrayFilter($htmlname, $array, $id = '
', $moreparam = '', $disableFiltering = 0, $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0, $textfortitle = '')
9809 global $delayedhtmlcontent; // Will be used later outside of this function
9811 // TODO Use an internal dolibarr component instead of select2
9812 if (!getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT
') && !defined('REQUIRE_JQUERY_MULTISELECT
')) {
9816 $out = '<select
type=
"text"'.($textfortitle ? ' title=
"'.dol_escape_htmltag($textfortitle).'"' : '').' id=
"'.$htmlname.'" class=
"'.$htmlname.($morecss ? ' ' . $morecss : '').'"'.($moreparam ? ' '.$moreparam : '').' name=
"'.$htmlname.'"><option></option></select>
';
9818 $formattedarrayresult = array();
9820 foreach ($array as $key => $value) {
9821 $o = new stdClass();
9823 $o->text = $value['text
'];
9824 $o->url = $value['url
'];
9825 $formattedarrayresult[] = $o;
9829 if (!empty($conf->use_javascript_ajax)) {
9830 $tmpplugin = 'select2
';
9831 $outdelayed = "\n" . '<!-- JS CODE TO ENABLE
' . $tmpplugin . ' for id ' . $htmlname . ' -->
9832 <script nonce=
"' . getNonce() . '">
9833 $(document).ready(
function () {
9834 var data =
' . json_encode($formattedarrayresult) . ';
9836 ' . ($callurlonselect ? 'var saveRemoteData =
' . json_encode($array) . ';
' : '') . '
9840 language: (typeof select2arrayoflanguage === \
'undefined\') ? \'en\' : select2arrayoflanguage,
9841 containerCssClass: \':all:\', /* Line to add class from the original SELECT propagated to the new <span class="select2-selection...> tag */
9843 escapeMarkup:
function (markup) {
return markup; },
9844 minimumInputLength:
' . ((int) $minimumInputLength) . ',
9845 formatResult:
function (result, container, query, escapeMarkup) {
9846 return escapeMarkup(result.text);
9848 matcher:
function (params, data) {
9850 if(! data.id)
return null;
';
9852 if ($callurlonselect) {
9853 // We forge the url with 'sall=
'
9856 var urlBase = data.url;
9857 var separ = urlBase.indexOf(
"?") >= 0 ?
"&" :
"?";
9860 saveRemoteData[data.id].url = urlBase + separ +
"search_all=" + encodeURIComponent(params.term.replace(/\
"/g, ""));';
9863 if (!$disableFiltering) {
9866 if(data.text.match(new RegExp(params.term))) {
9881 ' . ($callurlonselect ? '
9882 /* Code to execute a GET when we select a value */
9883 $(\'.' . dol_escape_js($htmlname) . '\').change(function() {
9884 var selected = $(\'.' . dol_escape_js($htmlname) . '\').val();
9885 console.log("We select
"+selected)
9887 $(\'.' . dol_escape_js($htmlname) . '\').val(""); /* reset visible combo value */
9888 $.each( saveRemoteData, function( key, value ) {
9889 if (key == selected)
9891 console.log("selectArrayFilter - Do a redirect to
"+value.url)
9892 location.assign(value.url);
9901 if ($acceptdelayedhtml) {
9902 $delayedhtmlcontent .= $outdelayed;
9904 $out .= $outdelayed;
9927 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)
9929 global $conf, $langs;
9932 if ($addjscombo < 0) {
9933 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
9940 $useenhancedmultiselect = 0;
9941 if (!empty($conf->use_javascript_ajax) && !defined('MAIN_DO_NOT_USE_JQUERY_MULTISELECT') && (getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') || defined('REQUIRE_JQUERY_MULTISELECT'))) {
9943 $useenhancedmultiselect = 1; // Use the js multiselect in one line. Possible only if $addjscombo not 0.
9947 $out .= '<span class="multiselectarray
'.$htmlname.'">';
9949 // We need a hidden field because when using the multiselect, if we unselect all, there is no
9950 // variable submitted at all, so no way to make a difference between variable not submitted and variable
9951 // submitted to nothing.
9952 $out .= '<input type="hidden
" name="'.$htmlname.'_multiselect
" value="1
">';
9953 // Output select component
9954 $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
";
9955 if (is_array($array) && !empty($array)) {
9956 if ($value_as_key) {
9957 $array = array_combine($array, $array);
9960 if (!empty($array)) {
9961 foreach ($array as $key => $value) {
9968 if (is_array($value) && array_key_exists('id', $value) && array_key_exists('label', $value)) {
9969 $tmpkey = $value['id'];
9970 $tmplabel = empty($value['label']) ? '' : $value['label'];
9971 $tmplabelhtml = empty($value['labelhtml']) ? (empty($value['data-html']) ? '' : $value['data-html']) : $value['labelhtml'];
9972 $tmpcolor = empty($value['color']) ? '' : $value['color'];
9973 $tmppicto = empty($value['picto']) ? '' : $value['picto'];
9974 $tmpdisabled = empty($value['disabled']) ? '' : $value['disabled'];
9976 $newval = ($translate ? $langs->trans($tmplabel) : $tmplabel);
9977 $newval = ($key_in_label ? $tmpkey . ' - ' . $newval : $newval);
9979 $tmplabelhtml = ($translate ? $langs->trans($tmplabelhtml) : $tmplabelhtml);
9980 $tmplabelhtml = ($key_in_label ? $tmpkey . ' - ' . $tmplabelhtml : $tmplabelhtml);
9982 $out .= '<option value="' . $tmpkey . '"';
9983 if (is_array($selected) && !empty($selected) && in_array((string) $tmpkey, $selected) && ((string) $tmpkey != '')) {
9984 $out .= ' selected';
9986 $out .= is_array($value) && array_key_exists('parent', $value) && !empty($value['parent']) ? ' parent="' . dolPrintHTMLForAttribute($value['parent
']) . '"' : '';
9990 if (!empty($tmplabelhtml)) {
9991 $out .= ' data-html="' . dolPrintHTMLForAttribute($tmplabelhtml) . '"';
9993 $tmplabelhtml = ($tmppicto ? img_picto('', $tmppicto, 'class="pictofixedwidth
" style="color: #
' . $tmpcolor . '"') : '') . $newval;
9994 $out .= ' data-html="' . dolPrintHTMLForAttribute($tmplabelhtml) . '"';
9997 $out .= dol_htmlentitiesbr($newval);
9998 $out .= '</option>' . "\n
";
10002 $out .= '</select>' . "\n
";
10006 // Add code for jquery to use multiselect
10007 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') || defined('REQUIRE_JQUERY_MULTISELECT')) {
10008 $out .= "\n
" . '<!-- JS CODE TO ENABLE select for id ' . $htmlname . ', addjscombo=' . $addjscombo . ' -->';
10009 $out .= "\n
" . '<script nonce="' . getNonce() . '">' . "\n
";
10010 if ($addjscombo == 1) {
10011 $tmpplugin = getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT', (defined('REQUIRE_JQUERY_MULTISELECT') ? constant('REQUIRE_JQUERY_MULTISELECT') : 'select2'));
10013 // If property data-html set, we decode html entities and use this.
10014 // Note that HTML content must have been sanitized from js with dol_escape_htmltag(xxx, 0, 0, '', 0, 1) when building the select option.
10015 // TODO Move this into common js ?
10016 $out .= 'function formatResult(record, container) {' . "\n
";
10017 $out .= ' if ($(record.element).attr("data-html
") != undefined && typeof htmlEntityDecodeJs === "function
") {';
10018 $out .= ' return htmlEntityDecodeJs($(record.element).attr("data-html
"));';
10020 $out .= ' return record.text;';
10021 $out .= '}' . "\n
";
10023 $out .= 'function formatSelection(record) {' . "\n
";
10024 $out .= ' return record.text;';
10025 $out .= '}' . "\n
";
10027 // Load the select2 enhancer
10028 //$out .= 'console.log(\'addjscombo=1 for htmlname=' . dol_escape_js($htmlname) . '\');';
10029 $out .= '$(document).ready(function () {
10030 $(\'#' . dol_escape_js($htmlname) . '\').' . $tmpplugin . '({';
10031 if ($placeholder) {
10035 text: \''.dol_escape_js($placeholder).'\'
10038 $out .= ' dir: \'ltr\',
10039 containerCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag (ko with multiselect) */
10040 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. */
10041 // Specify format function for dropdown item
10042 formatResult: formatResult,
10043 templateResult: formatResult, /* For 4.0 */
10044 escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
10045 // Specify format function for selected item
10046 formatSelection: formatSelection,
10047 templateSelection: formatSelection, /* For 4.0 */
10048 language: (typeof select2arrayoflanguage === \'undefined\') ? \'en\' : select2arrayoflanguage
10051 /* Add also morecss to the css .select2 that is after the #htmlname, for component that are shown dynamically after load, because select2 set
10052 the size only if component is not hidden by default on load */
10055 } elseif ($addjscombo == 2 && !defined(
'DISABLE_MULTISELECT')) {
10059 $out .=
'console.log(\'addjscombo=2 for htmlname=' .
dol_escape_js($htmlname) .
'\');
';
10060 $out .= '$(document).ready(
function () {
10062 containerHTML: \
'<div class="multi-select-container">\',
10063 menuHTML: \'<div class="multi-select-menu">\',
10064 buttonHTML: \'<span class="multi-select-button ' .
dol_escape_js($morecss) .
'">\',
10065 menuItemHTML: \'<label class="multi-select-menuitem">\',
10066 activeClass: \'multi-select-container--open\',
10071 $out .= '</script>
';
10089 public static function multiSelectArrayWithCheckbox($htmlname, &$array, $varpage, $pos = '
')
10091 global $conf, $langs, $user;
10093 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER
')) {
10096 if (empty($array)) {
10100 $tmpvar = "MAIN_SELECTEDFIELDS_" . $varpage; // To get list of saved selected fields to show
10102 if (!empty($user->conf->$tmpvar)) { // A list of fields was already customized for user
10103 $tmparray = explode(',
', $user->conf->$tmpvar);
10104 foreach ($array as $key => $val) {
10106 //var_dump($tmparray);
10107 if (in_array($key, $tmparray)) {
10108 $array[$key]['checked
'] = 1;
10110 $array[$key]['checked
'] = 0;
10113 } else { // There is no list of fields already customized for user
10114 foreach ($array as $key => $val) {
10115 if (!empty($array[$key]['checked
']) && $array[$key]['checked
'] < 0) {
10116 $array[$key]['checked
'] = 0;
10121 $listoffieldsforselection = '';
10122 $listcheckedstring = '';
10124 foreach ($array as $key => $val) {
10126 // var_dump(array_key_exists('enabled
', $val));
10127 // var_dump(!$val['enabled
']);
10128 if (array_key_exists('enabled
', $val) && isset($val['enabled
']) && !$val['enabled
']) {
10129 unset($array[$key]); // We don't want
this field
10132 if (!empty($val[
'type']) && $val[
'type'] ==
'separate') {
10137 if (!empty($val[
'label']) && $val[
'label']) {
10138 if (!empty($val[
'langfile']) && is_object($langs)) {
10139 $langs->load($val[
'langfile']);
10143 $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']).
'" />';
10144 $listoffieldsforselection .=
'<label for="checkbox' . $key .
'" class="paddingleft">';
10146 $listoffieldsforselection .=
'</label></li>';
10147 $listcheckedstring .= (empty($val[
'checked']) ?
'' : $key .
',');
10151 $out =
'<!-- Component multiSelectArrayWithCheckbox ' . $htmlname .
' -->
10153 <dl class="dropdown">
10155 <a href="#' . $htmlname .
'" class="multiselectpicto">
10158 <input type="hidden" class="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $listcheckedstring .
'">
10160 <dd class="dropdowndd">
10161 <div class="multiselectcheckbox'.$htmlname.
'">
10162 <ul class="'.$htmlname.(((string) $pos ==
'1' || (
string) $pos ==
'left') ?
'left' :
'').
'">
10163 <li class="liinputsearch">
10164 <input class="inputsearch_dropdownselectedfields width90p minwidth200imp" style="width:90%;" type="text" placeholder="'.$langs->trans(
'Search').
'">
10166 '.$listoffieldsforselection.
'
10172 <script nonce="' .
getNonce() .
'" type="text/javascript">
10173 jQuery(document).ready(function () {
10174 $(\'.multiselectcheckbox' . $htmlname .
' input[type="checkbox"]\').on("click", function () {
10175 console.log("A new field was added/removed, we edit field input[name=formfilteraction]");
10177 $("input:hidden[name=formfilteraction]").val(\'listafterchangingselectedfields\'); // Update field so we know we changed something on selected fields after POST
10179 var title = $(this).val() + ",";
10180 if ($(this).is(\':checked\')) {
10181 $(\'.' . $htmlname .
'\').val(title + $(\'.' . $htmlname .
'\').val());
10184 $(\'.' . $htmlname .
'\').val( $(\'.' . $htmlname .
'\').val().replace(title, \'\') )
10186 // Now, we submit page
10187 //$(this).parents(\'form:first\').submit();
10190 $("input.inputsearch_dropdownselectedfields").on("keyup", function() {
10191 console.log("keyup on inputsearch_dropdownselectedfields");
10192 var value = $(this).val().toLowerCase();
10193 $(\'.multiselectcheckbox'.$htmlname.
' li > label\').filter(function() {
10194 $(this).parent().toggle($(this).text().toLowerCase().indexOf(value) > -1)
10198 if (empty($conf->browser->layout) || $conf->browser->layout !=
'phone') {
10200 $(".dropdown dt a").on("click", function () {
10201 console.log("Click on dropdown, we set focus to search field");
10202 setTimeout(() => { $(\'.inputsearch_dropdownselectedfields\').focus(); }, 200);
10224 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
10227 $categories = $cat->containing(
$id, $type);
10229 if ($rendermode == 1) {
10230 $toprint = array();
10231 foreach ($categories as
$c) {
10232 $ways =
$c->print_all_ways(
'auto', ($nolink ?
'none' :
''), 0, 1);
10233 foreach ($ways as $way) {
10234 $color =
$c->color;
10235 $sfortag =
'<li class="select2-search-choice-dolibarr noborderoncategories'.(empty($toprint) ?
' nomarginleft' :
'').
'"' . ($color ?
' style="background: #' . $color .
';"' :
' style="background: #bbb"') .
'>';
10237 $sfortag .=
'</li>';
10238 $toprint[] = $sfortag;
10241 if (empty($toprint)) {
10244 return '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
10248 if ($rendermode == 0) {
10249 $arrayselected = array();
10250 $cate_arbo = $this->select_all_categories($type,
'',
'parent', 64, 0, 3);
10251 foreach ($categories as
$c) {
10252 $arrayselected[(string)
$c->id] = (
string)
$c->id;
10255 return $this->multiselectarray(
'categories', $cate_arbo, $arrayselected, 0, 0,
'', 0,
'100%',
'disabled',
'category');
10258 return 'ErrorBadValueForParameterRenderMode';
10272 global $conf, $langs, $hookmanager;
10276 $object->fetchObjectLinked();
10279 $hookmanager->initHooks(array(
'commonobject'));
10280 $parameters = array(
10281 'morehtmlright' => $morehtmlright,
10282 'compatibleImportElementsList' => &$compatibleImportElementsList,
10284 $reshook = $hookmanager->executeHooks(
'showLinkedObjectBlock', $parameters,
$object, $action);
10286 $nbofdifferenttypes = count(
$object->linkedObjects);
10288 if (empty($reshook)) {
10289 print
'<!-- showLinkedObjectBlock -->';
10290 print
load_fiche_titre($langs->trans($title), $morehtmlright,
'', 0,
'',
'showlinkedobjectblock');
10293 print
'<div class="div-table-responsive-no-min">';
10294 print
'<table class="noborder allwidth" data-block="showLinkedObject" data-element="' .
$object->element .
'" data-elementid="' .
$object->id .
'" >';
10296 print
'<tr class="liste_titre">';
10297 print
'<td>' . $langs->trans(
"Type") .
'</td>';
10298 print
'<td>' . $langs->trans(
"Ref") .
'</td>';
10299 print
'<td class="center"></td>';
10300 print
'<td class="center">' . $langs->trans(
"Date") .
'</td>';
10301 print
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
10302 print
'<td class="right">' . $langs->trans(
"Status") .
'</td>';
10306 $nboftypesoutput = 0;
10308 foreach (
$object->linkedObjects as $objecttype => $objects) {
10309 $tplpath = $element = $subelement = $objecttype;
10312 global $showImportButton;
10313 $showImportButton =
false;
10314 if (!empty($compatibleImportElementsList) && in_array($element, $compatibleImportElementsList)) {
10315 $showImportButton =
true;
10320 if ($objecttype !=
'supplier_proposal' && preg_match(
'/^([^_]+)_([^_]+)/i', $objecttype, $regs)) {
10321 $element = $regs[1];
10322 $subelement = $regs[2];
10323 $tplpath = $element .
'/' . $subelement;
10325 $tplname =
'linkedobjectblock';
10328 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $objecttype, $regs)) {
10329 $element = $regs[1];
10330 $module = $regs[2];
10331 $tplpath = $module.
'/' . $element;
10332 $tplname = $tplname.
'_'.$element;
10336 if ($objecttype ==
'facture') {
10337 $tplpath =
'compta/' . $element;
10341 } elseif ($objecttype ==
'facturerec') {
10342 $tplpath =
'compta/facture';
10343 $tplname =
'linkedobjectblockForRec';
10347 } elseif ($objecttype ==
'propal') {
10348 $tplpath =
'comm/' . $element;
10352 } elseif ($objecttype ==
'supplier_proposal') {
10356 } elseif ($objecttype ==
'shipping' || $objecttype ==
'shipment' || $objecttype ==
'expedition') {
10357 $tplpath =
'expedition';
10361 } elseif ($objecttype ==
'reception') {
10362 $tplpath =
'reception';
10366 } elseif ($objecttype ==
'delivery') {
10367 $tplpath =
'delivery';
10371 } elseif ($objecttype ==
'ficheinter') {
10372 $tplpath =
'fichinter';
10376 } elseif ($objecttype ==
'invoice_supplier') {
10377 $tplpath =
'fourn/facture';
10378 } elseif ($objecttype ==
'order_supplier') {
10379 $tplpath =
'fourn/commande';
10380 } elseif ($objecttype ==
'expensereport') {
10381 $tplpath =
'expensereport';
10382 } elseif ($objecttype ==
'subscription') {
10383 $tplpath =
'adherents';
10384 } elseif ($objecttype ==
'conferenceorbooth') {
10385 $tplpath =
'eventorganization';
10386 } elseif ($objecttype ==
'conferenceorboothattendee') {
10387 $tplpath =
'eventorganization';
10388 } elseif ($objecttype ==
'mo') {
10393 } elseif ($objecttype ==
'project_task') {
10394 $tplpath =
'projet/tasks';
10397 global $linkedObjectBlock;
10398 $linkedObjectBlock = $objects;
10401 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array(
'/' . $tplpath .
'/tpl'));
10403 foreach ($dirtpls as $reldir) {
10404 $reldir = rtrim($reldir,
'/');
10405 if ($nboftypesoutput == ($nbofdifferenttypes - 1)) {
10406 global $noMoreLinkedObjectBlockAfter;
10407 $noMoreLinkedObjectBlockAfter = 1;
10409 $file =
dol_buildpath($reldir .
'/' . $tplname .
'.tpl.php');
10410 if (file_exists($file)) {
10411 $res = @include $file;
10413 $nboftypesoutput++;
10420 if (!$nboftypesoutput) {
10421 print
'<tr><td colspan="7"><span class="opacitymedium">' . $langs->trans(
"None") .
'</span></td></tr>';
10426 if (!empty($compatibleImportElementsList)) {
10427 $res = @include
dol_buildpath(
'core/tpl/objectlinked_lineimport.tpl.php');
10433 return $nbofdifferenttypes;
10447 global $conf, $langs, $hookmanager, $form;
10450 if (empty($form)) {
10451 $form =
new Form($this->db);
10455 $linktoelemlist =
'';
10456 $listofidcompanytoscan =
'';
10458 if (!is_object(
$object->thirdparty)) {
10462 $possiblelinks = array();
10464 $dontIncludeCompletedItems =
getDolGlobalString(
'DONT_INCLUDE_COMPLETED_ELEMENTS_LINKS');
10466 if (is_object(
$object->thirdparty) && !empty(
$object->thirdparty->id) &&
$object->thirdparty->id > 0) {
10467 $listofidcompanytoscan = (int)
$object->thirdparty->id;
10469 $listofidcompanytoscan .=
',' . (int)
$object->thirdparty->parent;
10472 include_once DOL_DOCUMENT_ROOT .
'/projet/class/project.class.php';
10473 $tmpproject =
new Project($this->db);
10474 $tmpproject->fetch(
$object->fk_project);
10475 if ($tmpproject->socid > 0 && ($tmpproject->socid !=
$object->thirdparty->id)) {
10476 $listofidcompanytoscan .=
',' . (int) $tmpproject->socid;
10478 unset($tmpproject);
10481 $possiblelinks = array(
10485 'label' =>
'LinkToProposal',
10486 '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' :
''),
10488 'shipping' => array(
10491 'label' =>
'LinkToExpedition',
10492 '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' :
''),
10497 'label' =>
'LinkToOrder',
10498 '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' :
''),
10499 'linkname' =>
'commande',
10500 'subscription' => array(
10503 'label' =>
'LinkToMemberSubscription',
10504 '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') .
')',
10505 'linkname' =>
'subscription'),
10507 'invoice' => array(
10510 'label' =>
'LinkToInvoice',
10511 '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' :
''),
10512 'linkname' =>
'facture',
10514 'invoice_template' => array(
10517 'label' =>
'LinkToTemplateInvoice',
10518 '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') .
')',
10520 'contrat' => array(
10523 'label' =>
'LinkToContract',
10524 '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
10525 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',
10527 'fichinter' => array(
10530 'label' =>
'LinkToIntervention',
10531 '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') .
')',
10533 'supplier_proposal' => array(
10536 'label' =>
'LinkToSupplierProposal',
10537 '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' :
''),
10539 'order_supplier' => array(
10542 'label' =>
'LinkToSupplierOrder',
10543 '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' :
''),
10545 'invoice_supplier' => array(
10547 'perms' => 1,
'label' =>
'LinkToSupplierInvoice',
10548 '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' :
''),
10553 'label' =>
'LinkToTicket',
10554 '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' :
''),
10559 'label' =>
'LinkToMo',
10560 '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' :
''),
10565 if (
$object->table_element ==
'commande_fournisseur') {
10566 $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' :
'');
10567 } elseif (
$object->table_element ==
'mrp_mo') {
10568 $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' :
'');
10572 if (!empty($listofidcompanytoscan)) {
10574 $hookmanager->initHooks(array(
'commonobject'));
10575 $parameters = array(
'listofidcompanytoscan' => $listofidcompanytoscan,
'possiblelinks' => $possiblelinks);
10576 $reshook = $hookmanager->executeHooks(
'showLinkToObjectBlock', $parameters,
$object, $action);
10579 if (empty($reshook)) {
10580 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
10581 $possiblelinks = array_merge($possiblelinks, $hookmanager->resArray);
10583 } elseif ($reshook > 0) {
10584 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
10585 $possiblelinks = $hookmanager->resArray;
10589 if (!empty($possiblelinks)) {
10590 $object->fetchObjectLinked();
10594 $htmltoenteralink =
'';
10595 foreach ($possiblelinks as $key => $possiblelink) {
10597 if (empty($possiblelink[
'enabled'])) {
10604 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $key, $regs)) {
10606 $module = $regs[2];
10609 if (!empty($possiblelink[
'perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || !in_array($key, $excludelinksto))) {
10610 $htmltoenteralink .=
'<div id="' . $key .
'list"' . (empty($conf->use_javascript_ajax) ?
'' :
' style="display:none"') .
'>';
10614 $htmltoenteralink .=
'<br>'.
"\n";
10615 $htmltoenteralink .=
'<!-- form to add a link from anywhere -->'.
"\n";
10616 $htmltoenteralink .=
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinkedbyref' . $key .
'">';
10617 $htmltoenteralink .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
10618 $htmltoenteralink .=
'<input type="hidden" name="action" value="addlinkbyref">';
10619 $htmltoenteralink .=
'<input type="hidden" name="id" value="' .
$object->id .
'">';
10620 $htmltoenteralink .=
'<input type="hidden" name="addlink" value="' . $key .(!empty($module) ?
'@'.$module :
'').
'">';
10621 $htmltoenteralink .=
'<table class="noborder">';
10622 $htmltoenteralink .=
'<tr class="liste_titre">';
10624 $htmltoenteralink .=
'<td class="center"><input type="text" placeholder="'.dol_escape_htmltag($langs->trans(
"Ref")).
'" name="reftolinkto" value="' .
dol_escape_htmltag(
GETPOST(
'reftolinkto',
'alpha')) .
'"> ';
10625 $htmltoenteralink .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
'ToLink') .
'"> ';
10626 $htmltoenteralink .=
'<input type="submit" class="button smallpaddingimp" name="cancel" value="' . $langs->trans(
'Cancel') .
'"></td>';
10627 $htmltoenteralink .=
'</tr>';
10628 $htmltoenteralink .=
'</table>';
10629 $htmltoenteralink .=
'</form>';
10632 $sql = $possiblelink[
'sql'];
10634 $resqllist = $this->db->query($sql);
10636 $num = $this->db->num_rows($resqllist);
10642 $htmltoenteralink .=
'<br>';
10644 $htmltoenteralink .=
'<!-- form to add a link from object to same thirdparty -->'.
"\n";
10645 $htmltoenteralink .=
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinked' . $key .
'">';
10646 $htmltoenteralink .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
10647 $htmltoenteralink .=
'<input type="hidden" name="action" value="addlink">';
10648 $htmltoenteralink .=
'<input type="hidden" name="id" value="' .
$object->id .
'">';
10649 $htmltoenteralink .=
'<input type="hidden" name="addlink" value="' . $key . (!empty($module) ?
'@'.$module :
'').
'">';
10650 $htmltoenteralink .=
'<table class="noborder">';
10651 $htmltoenteralink .=
'<tr class="liste_titre">';
10652 $htmltoenteralink .=
'<td class="nowrap"></td>';
10653 $htmltoenteralink .=
'<td>' . $langs->trans(
"Ref") .
'</td>';
10654 $htmltoenteralink .=
'<td>' . $langs->trans(
"RefCustomer") .
'</td>';
10655 $htmltoenteralink .=
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
10656 $htmltoenteralink .=
'<td>' . $langs->trans(
"Company") .
'</td>';
10657 $htmltoenteralink .=
'</tr>';
10658 while ($i < $num) {
10659 $objp = $this->db->fetch_object($resqllist);
10660 $alreadylinked =
false;
10661 if (!empty(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key])) {
10662 if (in_array($objp->rowid, array_values(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key]))) {
10663 $alreadylinked =
true;
10666 $htmltoenteralink .=
'<tr class="oddeven">';
10667 $htmltoenteralink .=
'<td>';
10668 if ($alreadylinked) {
10669 $htmltoenteralink .=
img_picto(
'',
'link');
10671 $htmltoenteralink .=
'<input type="checkbox" name="idtolinkto[' . $key .
'_' . $objp->rowid .
']" id="' . $key .
'_' . $objp->rowid .
'" value="' . $objp->rowid .
'">';
10673 $htmltoenteralink .=
'</td>';
10674 $htmltoenteralink .=
'<td><label for="' . $key .
'_' . $objp->rowid .
'">' . $objp->ref .
'</label></td>';
10675 $htmltoenteralink .=
'<td>' . (!empty($objp->ref_client) ? $objp->ref_client : (!empty($objp->ref_supplier) ? $objp->ref_supplier :
'')) .
'</td>';
10676 $htmltoenteralink .=
'<td class="right">';
10677 if ($possiblelink[
'label'] ==
'LinkToContract') {
10678 $htmltoenteralink .= $form->textwithpicto(
'', $langs->trans(
"InformationOnLinkToContract")) .
' ';
10680 $htmltoenteralink .=
'<span class="amount">' . (isset($objp->total_ht) ?
price($objp->total_ht) :
'') .
'</span>';
10681 $htmltoenteralink .=
'</td>';
10682 $htmltoenteralink .=
'<td>' . $objp->name .
'</td>';
10683 $htmltoenteralink .=
'</tr>';
10686 $htmltoenteralink .=
'</table>';
10687 $htmltoenteralink .=
'<div class="center">';
10689 $htmltoenteralink .=
'<input type="submit" class="button valignmiddle marginleftonly marginrightonly smallpaddingimp" value="' . $langs->trans(
'ToLink') .
'">';
10691 if (empty($conf->use_javascript_ajax)) {
10692 $htmltoenteralink .=
'<input type="submit" class="button button-cancel marginleftonly marginrightonly smallpaddingimp" name="cancel" value="' . $langs->trans(
"Cancel") .
'"></div>';
10694 $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>';
10696 $htmltoenteralink .=
'</form>';
10699 $this->db->free($resqllist);
10703 $htmltoenteralink .=
'</div>';
10708 $linktoelemlist .=
'<li><a href="#linkto' . $key .
'" class="linkto dropdowncloseonclick" rel="' . $key .
'">' . $langs->trans($possiblelink[
'label']) .
' (' . $num .
')</a></li>';
10711 $linktoelemlist .=
'<li><span class="linktodisabled">' . $langs->trans($possiblelink[
'label']) .
' (0)</span></li>';
10716 if ($linktoelemlist) {
10718 <dl class="dropdown" id="linktoobjectname">
10720 if (!empty($conf->use_javascript_ajax)) {
10721 $linktoelem .=
'<dt><a href="#linktoobjectname"><span class="fas fa-link paddingrightonly"></span>' . $langs->trans(
"LinkTo") .
'...</a></dt>';
10723 $linktoelem .=
'<dd>
10724 <div class="multiselectlinkto">
10725 <ul class="ulselectedfields">' . $linktoelemlist .
'
10734 if (!empty($conf->use_javascript_ajax)) {
10735 print
'<!-- Add js to show linkto box -->
10736 <script nonce="' .
getNonce() .
'">
10737 jQuery(document).ready(function() {
10738 jQuery(".linkto").click(function() {
10739 console.log("We choose to show/hide links for rel="+jQuery(this).attr(\'rel\')+" so #"+jQuery(this).attr(\'rel\')+"list");
10740 jQuery("#"+jQuery(this).attr(\'rel\')+"list").toggle();
10748 return array(
'linktoelem' => $linktoelem,
'htmltoenteralink' => $htmltoenteralink);
10750 print $htmltoenteralink;
10753 return $linktoelem;
10770 public function selectyesno($htmlname, $value =
'', $option = 0, $disabled =
false, $useempty = 0, $addjscombo = 0, $morecss =
'yesno width75', $labelyes =
'Yes', $labelno =
'No')
10781 $disabled = ($disabled ?
' disabled' :
'');
10783 $resultyesno =
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'"' . $disabled .
'>' .
"\n";
10785 $resultyesno .=
'<option value="-1"' . (($value < 0) ?
' selected' :
'') .
'> </option>' .
"\n";
10787 if ((
"$value" ==
'yes') || ($value == 1)) {
10788 $resultyesno .=
'<option value="' . $yes .
'" selected>' . $langs->trans($labelyes) .
'</option>' .
"\n";
10789 $resultyesno .=
'<option value="' . $no .
'">' . $langs->trans($labelno) .
'</option>' .
"\n";
10791 $selected = (($useempty && $value !=
'0' && $value !=
'no') ?
'' :
' selected');
10792 $resultyesno .=
'<option value="' . $yes .
'">' . $langs->trans($labelyes) .
'</option>' .
"\n";
10793 $resultyesno .=
'<option value="' . $no .
'"' . $selected .
'>' . $langs->trans($labelno) .
'</option>' .
"\n";
10795 $resultyesno .=
'</select>' .
"\n";
10798 $resultyesno .=
ajax_combobox($htmlname, array(), 0, 0,
'resolve', ($useempty < 0 ? (
string) $useempty :
'-1'), $morecss);
10801 return $resultyesno;
10818 $sql =
"SELECT rowid, label";
10819 $sql .=
" FROM " . $this->db->prefix() .
"export_model";
10820 $sql .=
" WHERE type = '" . $this->db->escape($type) .
"'";
10821 $sql .=
" ORDER BY rowid";
10822 $result = $this->db->query($sql);
10824 print
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
10826 print
'<option value="-1"> </option>';
10829 $num = $this->db->num_rows($result);
10831 while ($i < $num) {
10832 $obj = $this->db->fetch_object($result);
10833 if ($selected == $obj->rowid) {
10834 print
'<option value="' . $obj->rowid .
'" selected>';
10836 print
'<option value="' . $obj->rowid .
'">';
10866 public function showrefnav(
$object, $paramid, $morehtml =
'', $shownav = 1, $fieldid =
'rowid', $fieldref =
'ref', $morehtmlref =
'', $moreparam =
'', $nodbprefix = 0, $morehtmlleft =
'', $morehtmlstatus =
'', $morehtmlright =
'')
10868 global $conf, $langs, $hookmanager, $extralanguages;
10871 if (empty($fieldid)) {
10872 $fieldid =
'rowid';
10874 if (empty($fieldref)) {
10879 $addgendertxt =
'';
10880 if (property_exists(
$object,
'gender') && !empty(
$object->gender)) {
10881 $addgendertxt =
' ';
10884 $addgendertxt .=
'<i class="fas fa-mars valignmiddle"></i>';
10887 $addgendertxt .=
'<i class="fas fa-venus valignmiddle"></i>';
10890 $addgendertxt .=
'<i class="fas fa-transgender valignmiddle"></i>';
10896 if (is_object($hookmanager)) {
10897 $parameters = array(
'showrefnav' =>
true);
10898 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters,
$object);
10899 if (!empty($hookmanager->resPrint)) {
10900 if (empty(
$object->next_prev_filter) && preg_match(
'/^\s*AND/i', $hookmanager->resPrint)) {
10901 $object->next_prev_filter = preg_replace(
'/^\s*AND\s*/i',
'', $hookmanager->resPrint);
10902 } elseif (!empty(
$object->next_prev_filter) && !preg_match(
'/^\s*AND/i', $hookmanager->resPrint)) {
10903 $object->next_prev_filter .=
' AND '.$hookmanager->resPrint;
10905 $object->next_prev_filter .= $hookmanager->resPrint;
10910 $previous_ref = $next_ref =
'';
10913 $object->load_previous_next_ref((isset(
$object->next_prev_filter) ?
$object->next_prev_filter :
''), $fieldid, $nodbprefix);
10915 $navurl = $_SERVER[
"PHP_SELF"];
10918 if ($paramid ==
'api_token_card') {
10919 if (preg_match(
'/\/user\/api_token/', $navurl)) {
10920 $navurl = preg_replace(
'/card/',
'list', $navurl);
10926 if ($paramid ==
'project_ref') {
10927 if (preg_match(
'/\/tasks\/(task|contact|note|document)\.php/', $navurl)) {
10928 $navurl = preg_replace(
'/\/tasks\/(task|contact|time|note|document)\.php/',
'/tasks.php', $navurl);
10933 $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>';
10934 $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>';
10938 $ret .=
'<!-- Start banner content --><div style="vertical-align: middle">';
10941 if ($morehtmlright) {
10942 $ret .=
'<div class="inline-block floatleft">' . $morehtmlright .
'</div>';
10945 if ($previous_ref || $next_ref || $morehtml) {
10946 $ret .=
'<div class="pagination paginationref"><ul class="right">';
10948 if ($morehtml &&
getDolGlobalInt(
'MAIN_OPTIMIZEFORTEXTBROWSER') < 2) {
10949 $ret .=
'<!-- morehtml --><li class="noborder litext' . (($shownav && $previous_ref && $next_ref) ?
' clearbothonsmartphone' :
'') .
'">' . $morehtml .
'</li>';
10951 if ($shownav && ($previous_ref || $next_ref)) {
10952 $ret .=
'<li class="pagination">' . $previous_ref .
'</li>';
10953 $ret .=
'<li class="pagination">' . $next_ref .
'</li>';
10955 if ($previous_ref || $next_ref || $morehtml) {
10956 $ret .=
'</ul></div>';
10960 $parameters = array(
'morehtmlstatus' => $morehtmlstatus);
10961 $reshook = $hookmanager->executeHooks(
'moreHtmlStatus', $parameters,
$object);
10962 if (empty($reshook)) {
10963 $morehtmlstatus .= $hookmanager->resPrint;
10965 $morehtmlstatus = $hookmanager->resPrint;
10967 if ($morehtmlstatus) {
10968 $ret .=
'<!-- status --><div class="statusref">' . $morehtmlstatus .
'</div>';
10971 $parameters = array();
10972 $reshook = $hookmanager->executeHooks(
'moreHtmlRef', $parameters,
$object);
10973 if (empty($reshook)) {
10974 $morehtmlref .= $hookmanager->resPrint;
10975 } elseif ($reshook > 0) {
10976 $morehtmlref = $hookmanager->resPrint;
10980 if ($morehtmlleft) {
10981 if ($conf->browser->layout ==
'phone') {
10982 $ret .=
'<!-- morehtmlleft --><div class="floatleft">' . $morehtmlleft .
'</div>';
10984 $ret .=
'<!-- morehtmlleft --><div class="inline-block floatleft">' . $morehtmlleft .
'</div>';
10989 $ret .=
'<!-- Ref or ID --><div class="inline-block floatleft valignmiddle maxwidth750 marginbottomonly refid' . (($shownav && ($previous_ref || $next_ref)) ?
' refidpadding' :
'') .
'">';
10992 if (
$object->element ==
'societe') {
10993 $ret .=
'<span class="valignmiddle">'.dol_htmlentities((
string)
$object->name).
'</span>';
10996 $arrayoflangcode = array();
11001 if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
11002 if (!is_object($extralanguages)) {
11003 include_once DOL_DOCUMENT_ROOT .
'/core/class/extralanguages.class.php';
11006 $extralanguages->fetch_name_extralanguages(
'societe');
11010 if (!empty($extralanguages->attributes[
'societe']) && !empty($extralanguages->attributes[
'societe'][
'name'])) {
11011 $object->fetchValuesForExtraLanguages();
11015 foreach ($arrayoflangcode as $extralangcode) {
11017 if (
$object->array_languages[
'name'][$extralangcode]) {
11018 $htmltext .=
$object->array_languages[
'name'][$extralangcode];
11020 $htmltext .=
'<span class="opacitymedium">' . $langs->trans(
"SwitchInEditModeToAddTranslation") .
'</span>';
11023 $ret .=
'<!-- Show translations of name -->' .
"\n";
11024 $ret .= $this->textwithpicto(
'', $htmltext, -1,
'language',
'opacitymedium paddingleft');
11027 } elseif (
$object->element ==
'member') {
11028 '@phan-var-force Adherent $object';
11029 $ret .=
$object->ref .
'<br>';
11030 $fullname =
$object->getFullName($langs);
11032 $ret .=
'<span class="valignmiddle">'.dol_htmlentities((
string)
$object->societe) . ((!empty($fullname) &&
$object->societe != $fullname) ?
' (' .
dol_htmlentities($fullname) . $addgendertxt .
')' :
'').
'</span>';
11034 $ret .=
'<span class="valignmiddle">'.dol_htmlentities($fullname) . $addgendertxt . ((!empty(
$object->societe) &&
$object->societe != $fullname) ?
' (' .
dol_htmlentities((
string)
$object->societe) .
')' :
'').
'</span>';
11036 } elseif (in_array(
$object->element, array(
'contact',
'user'))) {
11037 $ret .=
'<span class="valignmiddle">'.dol_htmlentities(
$object->getFullName($langs)).
'</span>'.$addgendertxt;
11038 } elseif (
$object->element ==
'usergroup') {
11040 } elseif (in_array(
$object->element, array(
'action',
'agenda'))) {
11041 '@phan-var-force ActionComm $object';
11043 } elseif (in_array(
$object->element, array(
'adherent_type'))) {
11045 } elseif (
$object->element ==
'ecm_directories') {
11047 } elseif (
$object->element ==
'accountingbookkeeping' && !empty(
$object->context[
'mode']) &&
$object->context[
'mode'] ==
'_tmp') {
11048 $ret .=
'<span class="valignmiddle">'.$langs->trans(
"Draft").
'</span>';
11049 } elseif ($fieldref !=
'none') {
11050 $ret .=
'<span class="valignmiddle">'.dol_htmlentities(!empty(
$object->$fieldref) ?
$object->$fieldref :
"").
'</span>';
11052 if ($morehtmlref) {
11054 if (substr($morehtmlref, 0, 4) !=
'<div') {
11058 $ret .=
'<!-- morehtmlref -->'.$morehtmlref;
11063 $ret .=
'</div><!-- End banner content -->';
11082 if (empty(
$object->barcode)) {
11087 if (empty(
$object->barcode_type_code) || empty(
$object->barcode_type_coder)) {
11089 $result =
$object->fetchBarCode();
11092 return '<!-- ErrorFetchBarcode -->';
11097 $url = DOL_URL_ROOT .
'/viewimage.php?modulepart=barcode&generator=' . urlencode(
$object->barcode_type_coder) .
'&code=' . urlencode(
$object->barcode) .
'&encoding=' . urlencode(
$object->barcode_type_code);
11098 $out =
'<!-- url barcode = ' . $url .
' -->';
11099 $out .=
'<img src="' . $url .
'"' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
'>';
11122 public static function showphoto($modulepart,
$object, $width = 100, $height = 0, $caneditfield = 0, $cssclass =
'photowithmargin', $imagesize =
'', $addlinktofullsize = 1, $cache = 0, $forcecapture =
'', $noexternsourceoverwrite = 0, $usesharelinkifavailable = 0)
11124 global $conf, $db, $langs;
11126 $entity = (empty(
$object->entity) ? $conf->entity :
$object->entity);
11131 $originalfile =
'';
11135 if ($modulepart ==
'societe') {
11136 $dir = $conf->societe->multidir_output[$entity];
11139 if ((
string) $imagesize ==
'mini') {
11141 } elseif ((
string) $imagesize ==
'small') {
11150 } elseif ($modulepart ==
'contact') {
11151 $dir = $conf->societe->multidir_output[$entity] .
'/contact';
11153 if (!empty($photo)) {
11155 if ((
string) $imagesize ==
'mini') {
11157 } elseif ((
string) $imagesize ==
'small') {
11162 $originalfile =
get_exdir(0, 0, 0, 0,
$object,
'contact') .
'photos/' . $photo;
11167 } elseif ($modulepart ==
'userphoto') {
11168 $dir = $conf->user->dir_output;
11170 if (!empty($photo)) {
11172 if ((
string) $imagesize ==
'mini') {
11174 } elseif ((
string) $imagesize ==
'small') {
11179 $originalfile =
get_exdir(0, 0, 0, 0,
$object,
'user') .
'photos/' . $photo;
11183 $altfile =
$object->id .
".jpg";
11187 } elseif ($modulepart ==
'memberphoto') {
11188 $dir = $conf->adherent->dir_output;
11190 if (!empty($photo)) {
11192 if ((
string) $imagesize ==
'mini') {
11194 } elseif ((
string) $imagesize ==
'small') {
11199 $originalfile =
get_exdir(0, 0, 0, 0,
$object,
'member') .
'photos/' . $photo;
11203 $altfile =
$object->id .
".jpg";
11210 if ($modulepart !=
"unknown" && method_exists(
$object,
'getDataToShowPhoto')) {
11211 $tmpdata =
$object->getDataToShowPhoto($modulepart, $imagesize);
11213 $dir = $tmpdata[
'dir'];
11214 $file = $tmpdata[
'file'];
11215 $originalfile = $tmpdata[
'originalfile'];
11216 $altfile = $tmpdata[
'altfile'];
11217 $email = $tmpdata[
'email'];
11218 $capture = $tmpdata[
'capture'];
11222 if ($forcecapture) {
11223 $capture = $forcecapture;
11229 if ($file && file_exists($dir .
"/" . $file)) {
11230 if ($addlinktofullsize) {
11232 if ($urladvanced) {
11233 $ret .=
'<a href="' . $urladvanced .
'">';
11235 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
11240 if ($usesharelinkifavailable) {
11242 $relativefileforecm = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT.
'/',
'/').
'/',
'', $dir.
'/'.$originalfile);
11244 require_once DOL_DOCUMENT_ROOT .
'/ecm/class/ecmfiles.class.php';
11246 $ecmfiles->fetch(0,
'', $relativefileforecm);
11248 $sharekey = (string) $ecmfiles->share;
11251 if (!empty($sharekey)) {
11252 $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) .
'">';
11254 $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 .
'">';
11256 if ($addlinktofullsize) {
11259 } elseif ($altfile && file_exists($dir .
"/" . $altfile)) {
11260 if ($addlinktofullsize) {
11262 if ($urladvanced) {
11263 $ret .=
'<a href="' . $urladvanced .
'">';
11265 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
11268 $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 .
'">';
11269 if ($addlinktofullsize) {
11273 $nophoto =
'/public/theme/common/nophoto.png';
11274 $defaultimg =
'identicon';
11275 if (in_array($modulepart, array(
'societe',
'userphoto',
'contact',
'memberphoto'))) {
11276 if ($modulepart ==
'societe' || ($modulepart ==
'memberphoto' && !empty(
$object->morphy) && strpos(
$object->morphy,
'mor') !==
false)) {
11277 $nophoto =
'company';
11279 $nophoto =
'/public/theme/common/user_anonymous.png';
11281 $nophoto =
'/public/theme/common/user_man.png';
11284 $nophoto =
'/public/theme/common/user_woman.png';
11289 if (
isModEnabled(
'gravatar') && $email && empty($noexternsourceoverwrite)) {
11291 $ret .=
'<!-- Put link to gravatar -->';
11292 $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 .
'">';
11294 if ($nophoto ==
'company') {
11295 $ret .=
'<div class="divforspanimg valignmiddle center photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
'>' .
img_picto(
'',
'company') .
'</div>';
11298 $ret .=
'<img class="photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="' . DOL_URL_ROOT . $nophoto .
'">';
11303 if ($caneditfield) {
11307 $ret .=
'<table class="nobordernopadding centpercent">';
11309 $ret .=
'<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> <label for="photodelete">' . $langs->trans(
"Delete") .
'</label><br><br></td></tr>';
11311 $ret .=
'<tr><td class="tdoverflow">';
11313 $maxmin = $maxfilesizearray[
'maxmin'];
11315 $ret .=
'<input type="hidden" name="MAX_FILE_SIZE" value="' . ($maxmin * 1024) .
'">';
11317 $ret .=
'<input type="file" class="flat maxwidth200onsmartphone" name="photo" id="photoinput" accept="image/*"' . ($capture ?
' capture="' .
dolPrintHTMLForAttribute($capture) .
'"' :
'') .
'>';
11318 $ret .=
'</td></tr>';
11319 $ret .=
'</table>';
11344 public function select_dolgroups($selected = 0, $htmlname =
'groupid', $show_empty = 0, $exclude =
'', $disabled = 0, $include =
'', $enableonly = array(), $force_entity =
'0', $multiple =
false, $morecss =
'minwidth200')
11347 global $conf, $user, $langs;
11350 $excludeGroups =
null;
11351 if (is_array($exclude)) {
11352 $excludeGroups = implode(
",", $exclude);
11355 $includeGroups =
null;
11356 if (is_array($include)) {
11357 $includeGroups = implode(
",", $include);
11360 if (!is_array($selected)) {
11361 $selected = array($selected);
11367 $sql =
"SELECT ug.rowid, ug.nom as name";
11368 if (
isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
11369 $sql .=
", e.label";
11371 $sql .=
" FROM " . $this->db->prefix() .
"usergroup as ug ";
11372 if (
isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
11373 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid=ug.entity";
11374 if ($force_entity) {
11375 $sql .=
" WHERE ug.entity IN (0, " . $force_entity .
")";
11377 $sql .=
" WHERE ug.entity IS NOT NULL";
11380 $sql .=
" WHERE ug.entity IN (0, " . $conf->entity .
")";
11382 if (is_array($exclude) && $excludeGroups) {
11383 $sql .=
" AND ug.rowid NOT IN (" . $this->db->sanitize($excludeGroups) .
")";
11385 if (is_array($include) && $includeGroups) {
11386 $sql .=
" AND ug.rowid IN (" . $this->db->sanitize($includeGroups) .
")";
11388 $sql .=
" ORDER BY ug.nom ASC";
11390 dol_syslog(get_class($this) .
"::select_dolgroups", LOG_DEBUG);
11391 $resql = $this->db->query($sql);
11394 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
11396 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
11398 $num = $this->db->num_rows($resql);
11401 if ($show_empty && !$multiple) {
11402 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'> </option>' .
"\n";
11405 while ($i < $num) {
11406 $obj = $this->db->fetch_object($resql);
11408 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
11412 $label = $obj->name;
11413 $labelhtml = $obj->name;
11415 $label .=
" (" . $obj->label .
")";
11416 $labelhtml .=
' <span class="opacitymedium">(' . $obj->label .
')</span>';
11419 $out .=
'<option value="' . $obj->rowid .
'"';
11420 if ($disableline) {
11421 $out .=
' disabled';
11423 if ((isset($selected[0]) && is_object($selected[0]) && $selected[0]->
id == $obj->rowid)
11424 || ((!isset($selected[0]) || !is_object($selected[0])) && !empty($selected) && in_array($obj->rowid, $selected))) {
11425 $out .=
' selected';
11427 $out .=
' data-html="'.dol_escape_htmltag($labelhtml).
'"';
11430 $out .=
'</option>';
11435 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'></option>' .
"\n";
11437 $out .=
'<option value="" disabled>' . $langs->trans(
"NoUserGroupDefined") .
'</option>';
11439 $out .=
'</select>';
11458 $out =
'<div class="nowraponall">';
11459 $out .=
'<button type="submit" class="liste_titre button_search reposition" name="button_search_x" value="x"><span class="fas fa-search"></span></button>';
11460 $out .=
'<button type="submit" class="liste_titre button_removefilter reposition" name="button_removefilter_x" value="x"><span class="fas fa-times"></span></button>';
11474 public function showCheckAddButtons($cssclass =
'checkforaction', $calljsfunction = 0, $massactionname =
"massaction")
11480 if (!empty($conf->use_javascript_ajax)) {
11481 $out .=
'<div class="inline-block checkallactions"><input type="checkbox" id="' . $cssclass .
's" name="' . $cssclass .
's" class="checkallactions"></div>';
11483 $out .=
'<script nonce="' .
getNonce() .
'">
11484 $(document).ready(function() {
11485 $("#' . $cssclass .
's").click(function() {
11486 if($(this).is(\':checked\')){
11487 console.log("We check all ' . $cssclass .
' and trigger the change method");
11488 $(".' . $cssclass .
'").prop(\'checked\', true).trigger(\'change\');
11492 console.log("We uncheck all");
11493 $(".' . $cssclass .
'").prop(\'checked\', false).trigger(\'change\');
11495 if ($calljsfunction) {
11496 $out .=
'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0, "' . $massactionname .
'", "' . $cssclass .
'"); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }';
11500 $(".' . $cssclass .
'").change(function() {
11501 console.log("We check and change the tr class highlight after a change on .'.$cssclass.
'");
11502 var $row = $(this).closest("tr");
11504 var anyChecked = $row.find(\'input[type="checkbox"].checkforselect:checked\').length > 0;
11505 console.log("anychecked="+anyChecked);
11507 $row.removeClass("highlight");
11509 $row.addClass("highlight");
11531 $out = $this->showFilterButtons();
11532 if ($addcheckuncheckall) {
11533 $out .= $this->showCheckAddButtons($cssclass, $calljsfunction, $massactionname);
11551 public function selectExpenseCategories($selected =
'', $htmlname =
'fk_c_exp_tax_cat', $useempty = 0, $excludeid = array(), $target =
'', $default_selected = 0, $params = array(), $info_admin = 1)
11553 global $langs, $user;
11556 $sql =
"SELECT rowid, label FROM " . $this->db->prefix() .
"c_exp_tax_cat WHERE active = 1";
11557 $sql .=
" AND entity IN (0," .
getEntity(
'exp_tax_cat') .
")";
11558 if (!empty($excludeid)) {
11559 $sql .=
" AND rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeid)) .
")";
11561 $sql .=
" ORDER BY label";
11563 $resql = $this->db->query($sql);
11565 $out =
'<select id="select_' . $htmlname .
'" name="' . $htmlname .
'" class="' . $htmlname .
' flat minwidth75imp maxwidth200">';
11567 $out .=
'<option value="0"> </option>';
11570 while ($obj = $this->db->fetch_object($resql)) {
11571 $out .=
'<option ' . ($selected == $obj->rowid ?
'selected="selected"' :
'') .
' value="' . $obj->rowid .
'">' . $langs->trans($obj->label) .
'</option>';
11573 $out .=
'</select>';
11576 if (!empty($htmlname) && $user->admin && $info_admin) {
11577 $out .=
' ' .
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
11580 if (!empty($target)) {
11581 $sql =
"SELECT c.id FROM " . $this->db->prefix() .
"c_type_fees as c WHERE c.code = 'EX_KME' AND c.active = 1";
11582 $resql = $this->db->query($sql);
11584 if ($this->db->num_rows($resql) > 0) {
11585 $obj = $this->db->fetch_object($resql);
11586 $out .=
'<script nonce="' .
getNonce() .
'">
11588 $("select[name=' . $target .
']").on("change", function() {
11589 var current_val = $(this).val();
11590 if (current_val == ' . $obj->id .
') {';
11591 if (!empty($default_selected) || !empty($selected)) {
11592 $out .=
'$("select[name=' . $htmlname .
']").val("' . ($default_selected > 0 ? $default_selected : $selected) .
'");';
11596 $("select[name=' . $htmlname .
']").change();
11600 $("select[name=' . $htmlname .
']").change(function() {
11602 if ($("select[name=' . $target .
']").val() == ' . $obj->id .
') {
11603 // get price of kilometer to fill the unit price
11607 data: { fk_c_exp_tax_cat: $(this).val(), token: \'' .
currentToken() .
'\' },
11608 url:
"' . (DOL_URL_ROOT . '/expensereport/ajax/ajaxik.php?' . implode('&', $params)) . '",
11609 }).done(
function( data, textStatus, jqXHR ) {
11611 if (typeof data.up !=
"undefined") {
11612 $(
"input[name=value_unit]").val(data.up);
11613 $(
"select[name=' . $htmlname . ']").attr(
"title", data.title);
11615 $(
"input[name=value_unit]").val(
"");
11616 $(
"select[name=' . $htmlname . ']").attr(
"title",
"");
11627 dol_print_error($this->db);
11641 public function selectExpenseRanges($selected = '
', $htmlname = 'fk_range
', $useempty = 0)
11643 global $conf, $langs;
11646 $sql = "SELECT rowid, range_ik FROM " . $this->db->prefix() . "c_exp_tax_range";
11647 $sql .= " WHERE entity = " . $conf->entity . " AND active = 1";
11649 $resql = $this->db->query($sql);
11651 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
11653 $out .= '<option value=
"0"></option>
';
11656 while ($obj = $this->db->fetch_object($resql)) {
11657 $out .= '<option
' . ($selected == $obj->rowid ? 'selected=
"selected"' : '') . ' value=
"' . $obj->rowid . '">
' . price($obj->range_ik, 0, $langs, 1, 0) . '</option>
';
11659 $out .= '</select>
';
11661 dol_print_error($this->db);
11677 public function selectExpenseFees($selected = '
', $htmlname = 'fk_c_type_fees
', $useempty = 0, $allchoice = 1, $useid = 0)
11682 $sql = "SELECT id, code, label";
11683 $sql .= " FROM ".$this->db->prefix()."c_type_fees";
11684 $sql .= " WHERE active = 1";
11686 $resql = $this->db->query($sql);
11688 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
11690 $out .= '<option value=
"0"></option>
';
11693 $out .= '<option value=
"-1">
' . $langs->trans('AllExpenseReport
') . '</option>
';
11701 while ($obj = $this->db->fetch_object($resql)) {
11702 $key = $langs->trans($obj->code);
11703 $out .= '<option
' . ($selected == $obj->{$field} ? 'selected=
"selected"' : '') . ' value=
"' . $obj->{$field} . '">
' . ($key != $obj->code ? $key : $obj->label) . '</option>
';
11705 $out .= '</select>
';
11707 $out .= ajax_combobox('select_
'.$htmlname);
11709 dol_print_error($this->db);
11733 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)
11735 global $user, $conf, $langs;
11737 require_once DOL_DOCUMENT_ROOT . '/projet/
class/project.class.php
';
11739 if (is_null($usertofilter)) {
11740 $usertofilter = $user;
11745 $hideunselectables = false;
11746 if (getDolGlobalString('INVOICE_HIDE_UNSELECTABLES
')) {
11747 $hideunselectables = true;
11750 if (empty($projectsListId)) {
11751 if (!$usertofilter->hasRight('projet
', 'all
', 'lire
')) {
11752 $projectstatic = new Project($this->db);
11753 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1);
11757 // Search all projects
11758 $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";
11759 $sql .= " FROM " . $this->db->prefix() . "facture as f";
11760 $sql .= " INNER JOIN " . $this->db->prefix() . "projet as p ON p.entity IN (" . getEntity('project
') . ") AND f.fk_projet = p.rowid";
11761 $sql .= " LEFT JOIN " . $this->db->prefix() . "societe as s ON s.rowid = p.fk_soc";
11762 $sql .= " WHERE f.fk_statut = 0"; // Draft invoices only
11763 //if ($projectsListId) $sql.= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")";
11764 //if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
11765 //if ($socid > 0) $sql.= " AND (p.fk_soc=".((int) $socid)." OR p.fk_soc IS NULL)";
11766 $sql .= " ORDER BY p.ref, f.ref ASC";
11768 $resql = $this->db->query($sql);
11770 // Use select2 selector
11771 if (!empty($conf->use_javascript_ajax)) {
11772 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
11773 $comboenhancement = ajax_combobox($htmlname, array(), 0, $forcefocus);
11774 $out .= $comboenhancement;
11775 $morecss = 'minwidth200imp maxwidth500
';
11778 if (empty($option_only)) {
11779 $out .= '<select
class=
"valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled=
"disabled"' : '') . ' id=
"' . $htmlname . '" name=
"' . $htmlname . '">
';
11781 if (!empty($show_empty)) {
11782 $out .= '<option value=
"0" class=
"optiongrey">
';
11783 if (!is_numeric($show_empty)) {
11784 $out .= $show_empty;
11788 $out .= '</option>
';
11790 $num = $this->db->num_rows($resql);
11793 while ($i < $num) {
11794 $obj = $this->db->fetch_object($resql);
11795 // 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.
11796 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$usertofilter->hasRight('societe
', 'lire
')) {
11799 if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) {
11806 if ($showproject == 'all
') {
11807 $labeltoshow .= dol_trunc($obj->ref, 18); // Invoice ref
11809 $labeltoshow .= ' -
' . $obj->name; // Soc name
11813 if ($obj->fk_statut == Project::STATUS_DRAFT) {
11815 $labeltoshow .= ' -
' . $langs->trans("Draft");
11816 } elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
11817 if ($discard_closed == 2) {
11820 $labeltoshow .= ' -
' . $langs->trans("Closed");
11821 } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
11823 $labeltoshow .= ' -
' . $langs->trans("LinkedToAnotherCompany");
11827 if (!empty($selected) && $selected == $obj->rowid) {
11828 $out .= '<option value=
"' . $obj->rowid . '" selected
';
11829 //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected
if disabled
11830 $out .=
'>' . $labeltoshow .
'</option>';
11832 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
11835 $resultat =
'<option value="' . $obj->rowid .
'"';
11837 $resultat .=
' disabled';
11842 $resultat .= $labeltoshow;
11843 $resultat .=
'</option>';
11851 if (empty($option_only)) {
11852 $out .=
'</select>';
11855 $this->db->free($resql);
11878 public function selectInvoiceRec($selected =
'', $htmlname =
'facrecid', $maxlength = 24, $option_only = 0, $show_empty =
'1', $forcefocus = 0, $disabled = 0, $morecss =
'maxwidth500')
11880 global $conf, $langs;
11886 $sql =
'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc';
11887 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'facture_rec as f';
11888 $sql .=
" WHERE f.entity IN (" .
getEntity(
'invoice') .
")";
11889 $sql .=
" ORDER BY f.titre ASC";
11891 $resql = $this->db->query($sql);
11894 if (!empty($conf->use_javascript_ajax)) {
11895 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
11896 $comboenhancement =
ajax_combobox($htmlname, array(), 0, $forcefocus);
11897 $out .= $comboenhancement;
11898 $morecss =
'minwidth200imp maxwidth500';
11901 if (empty($option_only)) {
11902 $out .=
'<select class="valignmiddle flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' id="' . $htmlname .
'" name="' . $htmlname .
'">';
11904 if (!empty($show_empty)) {
11905 $out .=
'<option value="0" class="optiongrey">';
11906 if (!is_numeric($show_empty)) {
11907 $out .= $show_empty;
11911 $out .=
'</option>';
11913 $num = $this->db->num_rows($resql);
11915 while ($obj = $this->db->fetch_object($resql)) {
11916 $labeltoshow =
dol_trunc($obj->title, 18);
11919 if (!empty($obj->suspended)) {
11921 $labeltoshow .=
' - ' . $langs->trans(
"Closed");
11925 if (!empty($selected) && $selected == $obj->rowid) {
11926 $out .=
'<option value="' . $obj->rowid .
'" selected';
11928 $out .=
'>' . $labeltoshow .
'</option>';
11930 if ($disabled && ($selected != $obj->rowid)) {
11933 $resultat =
'<option value="' . $obj->rowid .
'"';
11935 $resultat .=
' disabled';
11938 $resultat .= $labeltoshow;
11939 $resultat .=
'</option>';
11945 if (empty($option_only)) {
11946 $out .=
'</select>';
11951 $this->db->free($resql);
11954 $this->errors[] = $this->db->lasterror;
11970 public function searchComponent($arrayofcriterias, $search_component_params, $arrayofinputfieldsalreadyoutput = array(), $search_component_params_hidden =
'', $arrayoffiltercriterias = array())
11973 global $langs, $form;
11978 if ($search_component_params_hidden !=
'' && !preg_match(
'/^\(.*\)$/', $search_component_params_hidden)) {
11979 $search_component_params_hidden =
'(' . $search_component_params_hidden .
')';
11982 $ret =
'<!-- searchComponent -->';
11984 $ret .=
'<div class="divadvancedsearchfieldcomp centpercent inline-block">';
11985 $ret .=
'<a href="#" class="dropdownsearch-toggle unsetcolor">';
11986 $ret .=
'<span class="fas fa-filter linkobject boxfilter paddingright pictofixedwidth" title="' .
dol_escape_htmltag($langs->trans(
"Filters")) .
'" id="idsubimgproductdistribution"></span>';
11989 $ret .=
'<div class="divadvancedsearchfieldcompinput inline-block minwidth500 maxwidth300onsmartphone">';
11992 $ret .=
'<div id="divsearch_component_params" name="divsearch_component_params" class="noborderbottom search_component_params inline-block valignmiddle">';
11994 if ($search_component_params_hidden) {
12002 foreach ($arrayofandtags as $tmpkey => $tmpval) {
12003 $errormessage =
'';
12005 if ($errormessage) {
12006 $this->error =
'ERROR in parsing search string: '.$errormessage;
12009 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
12012 $ret .=
'<span class="marginleftonlyshort valignmiddle tagsearch" data-ufilterid="'.($tmpkey + 1).
'" data-ufilter="'.
dol_escape_htmltag($tmpval).
'">';
12013 $ret .=
'<span class="tagsearchdelete select2-selection__choice__remove" data-ufilterid="'.($tmpkey + 1).
'">x</span> ';
12025 $show_search_component_params_hidden = 1;
12026 if ($show_search_component_params_hidden) {
12027 $ret .=
'<input type="hidden" name="show_search_component_params_hidden" value="1">';
12029 $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%')) -->";
12030 $ret .=
'<input type="hidden" id="search_component_params_hidden" name="search_component_params_hidden" value="' .
dol_escape_htmltag($search_component_params_hidden) .
'">';
12035 foreach ($arrayofcriterias as $criteria) {
12036 foreach ($criteria as $criteriafamilykey => $criteriafamilyval) {
12037 if (in_array(
'search_' . $criteriafamilykey, $arrayofinputfieldsalreadyoutput)) {
12040 if (in_array($criteriafamilykey, array(
'rowid',
'ref_ext',
'entity',
'extraparams'))) {
12043 if (in_array($criteriafamilyval[
'type'], array(
'date',
'datetime',
'timestamp'))) {
12044 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_start">';
12045 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startyear">';
12046 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startmonth">';
12047 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startday">';
12048 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_end">';
12049 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endyear">';
12050 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endmonth">';
12051 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endday">';
12053 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'">';
12060 $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";
12061 $ret .=
'<input type="text" placeholder="' . $langs->trans(
"Filters") .
'" id="search_component_params_input" name="search_component_params_input" class="noborderall search_component_input" value="">';
12067 jQuery(".tagsearchdelete").click(function(e) {
12068 var filterid = $(this).parents().attr("data-ufilterid");
12069 console.log("We click to delete the criteria nb "+filterid);
12071 // Regenerate the search_component_params_hidden with all data-ufilter except the one to delete, and post the page
12072 var newparamstring = \'\';
12073 $(\'.tagsearch\').each(function(index, element) {
12074 tmpfilterid = $(this).attr("data-ufilterid");
12075 if (tmpfilterid != filterid) {
12076 // We keep this criteria
12077 if (newparamstring == \'\') {
12078 newparamstring = $(this).attr("data-ufilter");
12080 newparamstring = newparamstring + \' AND \' + $(this).attr("data-ufilter");
12084 console.log("newparamstring = "+newparamstring);
12086 jQuery("#search_component_params_hidden").val(newparamstring);
12088 // We repost the form
12089 $(this).closest(\'form\').submit();
12092 jQuery("#search_component_params_input").keydown(function(e) {
12093 console.log("We press a key on the filter field that is "+jQuery("#search_component_params_input").val());
12094 console.log(e.which);
12095 if (jQuery("#search_component_params_input").val() == "" && e.which == 8) {
12096 /* We click on back when the input field is already empty */
12097 event.preventDefault();
12098 jQuery("#divsearch_component_params .tagsearch").last().remove();
12099 /* Regenerate content of search_component_params_hidden from remaining .tagsearch */
12101 jQuery("#divsearch_component_params .tagsearch").each(function( index ) {
12105 s = s + $(this).attr("data-ufilter");
12107 console.log("New value for search_component_params_hidden = "+s);
12108 jQuery("#search_component_params_hidden").val(s);
12116 $arrayoffiltercriterias_json = json_encode($arrayoffiltercriterias);
12118 var arrayoffiltercriterias = ' . $arrayoffiltercriterias_json .
';
12122 $arrayoffilterfieldslabel = array();
12123 foreach ($arrayoffiltercriterias as $key => $val) {
12124 $arrayoffilterfieldslabel[$key][
'label'] = $val[
'label'];
12125 $arrayoffilterfieldslabel[$key][
'data-type'] = $val[
'type'];
12129 $ret .=
'<div class="search-component-assistance">';
12132 $ret .=
'<p class="assistance-title">' .
img_picto(
'',
'filter') .
' ' . $langs->trans(
'FilterAssistance') .
' </p>';
12134 $ret .=
'<p class="assistance-errors error" style="display:none">' . $langs->trans(
'AllFieldsRequired') .
' </p>';
12136 $ret .=
'<div class="operand">';
12137 $ret .= $form->selectarray(
'search_filter_field', $arrayoffilterfieldslabel,
'', $langs->trans(
"Fields"), 0, 0,
'', 0, 0, 0,
'',
'width200 combolargeelem', 1);
12140 $ret .=
'<span class="separator"></span>';
12143 $ret .=
'<div class="operator">';
12144 $ret .=
'<select class="operator-selector width150" id="operator-selector"">';
12145 $ret .=
'</select>';
12146 $ret .=
'<script>$(document).ready(function() {';
12147 $ret .=
' $(".operator-selector").select2({';
12148 $ret .=
' placeholder: \'' .
dol_escape_js($langs->transnoentitiesnoconv(
'Operator')) .
'\'';
12150 $ret .=
'});</script>';
12153 $ret .=
'<span class="separator"></span>';
12155 $ret .=
'<div class="value">';
12157 $ret .=
'<input type="text" class="flat width100 value-input" placeholder="' .
dolPrintHTML($langs->trans(
'Value')) .
'">';
12161 $ret .=
'<span class="date-one" style="display:none">';
12162 $ret .= $form->selectDate(($dateOne ? $dateOne : -1),
'dateone', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'');
12166 $ret .=
'<select class="value-selector width150" id="value-selector" style="display:none">';
12167 $ret .=
'</select>';
12169 $(document).ready(function() {
12170 $("#value-selector").select2({
12171 placeholder: "' .
dol_escape_js($langs->trans(
'Value')) .
'"
12173 $("#value-selector").hide();
12174 $("#value-selector").next(".select2-container").hide();
12180 $ret .=
'<div class="btn-div">';
12181 $ret .=
'<button class="button buttongen button-save add-filter-btn" type="button">' . $langs->trans(
"addToFilter") .
'</button>';
12192 $(document).ready(function() {
12193 $("#search_component_params_input").on("click", function() {
12194 const inputPosition = $(this).offset();
12195 const inputHeight = $(this).outerHeight();
12196 $(".search-component-assistance").css({
12197 top: inputPosition.top + inputHeight + 5 + "px",
12198 left: $("#divsearch_component_params").position().left
12199 }).slideToggle(200);
12201 $(document).on("click", function(e) {
12202 if (!$(e.target).closest("#search_component_params_input, .search-component-assistance, #ui-datepicker-div").length) {
12203 $(".search-component-assistance").hide();
12210 $(document).ready(function() {
12211 $(".search_filter_field").on("change", function() {
12212 console.log("We change search_filter_field");
12215 const selectedField = $(this).find(":selected");
12216 let fieldType = selectedField.data("type");
12217 const selectedFieldValue = selectedField.val();
12219 // If the selected field has an array of values then ask toshow the value selector instead of the value input
12220 if (arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"] !== undefined) {
12221 fieldType = "select";
12224 // If the selected field may be null then ask to append the "IsDefined" and "IsNotDefined" operators
12225 if (arrayoffiltercriterias[selectedFieldValue]["maybenull"] !== undefined) {
12228 const operators = getOperatorsForFieldType(fieldType, maybenull);
12229 const operatorSelector = $(".operator-selector");
12231 // Clear existing options
12232 operatorSelector.empty();
12234 // Populate operators
12235 Object.entries(operators).forEach(function([operator, label]) {
12236 operatorSelector.append("<option value=\'" + operator + "\'>" + label + "</option>");
12239 operatorSelector.trigger("change.select2");
12241 // Clear and hide all input elements initially
12242 $(".value-input, .dateone, .datemonth, .dateyear").val("").hide();
12243 $("#datemonth, #dateyear").val(null).trigger("change.select2");
12244 $("#dateone").datepicker("setDate", null);
12245 $(".date-one, .date-month, .date-year").hide();
12246 $("#value-selector").val("").hide();
12247 $("#value-selector").next(".select2-container").hide();
12248 $("#value-selector").val(null).trigger("change.select2");
12250 if (fieldType === "date" || fieldType === "datetime" || fieldType === "timestamp") {
12251 $(".date-one").show();
12252 } else if (arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"] !== undefined) {
12253 var arrayofkeyval = arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"];
12254 var valueSelector = $("#value-selector");
12255 valueSelector.empty();
12256 Object.entries(arrayofkeyval).forEach(function([key, val]) {
12257 valueSelector.append("<option value=\'" + key + "\'>" + val + "</option>");
12259 valueSelector.trigger("change.select2");
12261 $("#value-selector").show();
12262 $("#value-selector").next(".select2-container").show();
12264 $(".value-input").show();
12268 $("#operator-selector").on("change", function() {
12269 console.log("We change operator-selector");
12271 const selectedOperator = $(this).find(":selected").val();
12272 if (selectedOperator === "IsDefined" || selectedOperator === "IsNotDefined") {
12273 // Disable all value input elements
12274 $(".value-input, .dateone, .datemonth, .dateyear").val("").prop("disabled", true);
12275 $("#datemonth, #dateyear").val(null).trigger("change.select2");
12276 $("#dateone").datepicker("setDate", null).datepicker("option", "disabled", true);
12277 $(".date-one, .date-month, .date-year").prop("disabled", true);
12278 $("#value-selector").val("").prop("disabled", true);
12279 $("#value-selector").val(null).trigger("change.select2");
12281 // Enable all value input elements
12282 $(".value-input, .dateone, .datemonth, .dateyear").prop("disabled", false);
12283 $(".date-one, .date-month, .date-year").prop("disabled", false);
12284 $("#dateone").datepicker("option", "disabled", false);
12285 $("#value-selector").prop("disabled", false);
12289 $(".add-filter-btn").on("click", function(event) {
12290 console.log("We click on add-filter-btn");
12292 event.preventDefault();
12294 const field = $(".search_filter_field").val();
12295 const operator = $(".operator-selector").val();
12296 let value = $(".value-input").val();
12297 const fieldType = $(".search_filter_field").find(":selected").data("type");
12299 if (["date", "datetime", "timestamp"].includes(fieldType)) {
12300 const year = $("#dateoneyear").val().toString().padStart(4, "0");;
12301 const month = $("#dateonemonth").val().toString().padStart(2, "0");
12302 const day = $("#dateoneday").val().toString().padStart(2, "0");
12303 value = `${year}-${month}-${day}`;
12304 console.log("value="+value);
12307 // If the selected field has an array of values then take the selected value
12308 if (arrayoffiltercriterias[field]["arrayofkeyval"] !== undefined) {
12309 value = $("#value-selector").val();
12312 // If the operator is "IsDefined" or "IsNotDefined" then set the value to 1 (it will not be used)
12313 if (operator === "IsDefined" || operator === "IsNotDefined") {
12317 const filterString = generateFilterString(field, operator, value, fieldType);
12320 if (filterString !== "" && field !== "" && operator !== "" && value !== "") {
12321 $("#search_component_params_input").val($("#search_component_params_input").val() + " " + filterString);
12322 $("#search_component_params_input").closest("form").submit();
12324 $(".assistance-errors").show();
12344 public function selectModelMail($prefix, $modelType =
'', $default = 0, $addjscombo = 0, $selected = 0, $morecss =
'')
12346 global $langs, $user;
12350 $TModels = array();
12352 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
12353 $formmail =
new FormMail($this->db);
12354 $result = $formmail->fetchAllEMailTemplate($modelType, $user, $langs);
12357 $TModels[0] = $langs->trans(
'DefaultMailModel');
12360 foreach ($formmail->lines_model as $model) {
12361 $TModels[(int) $model->id] = $model->label;
12365 $retstring .=
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" id="select_' . $prefix .
'model_mail" name="' . $prefix .
'model_mail">';
12367 foreach ($TModels as $id_model => $label_model) {
12368 $retstring .=
'<option value="' . $id_model .
'"';
12369 if (!empty($selected) && ((int) $selected) == $id_model) {
12370 $retstring .=
"selected";
12372 $retstring .=
">" . $label_model .
"</option>";
12375 $retstring .=
"</select>";
12378 $retstring .=
ajax_combobox(
'select_' . $prefix .
'model_mail');
12395 public function buttonsSaveCancel($save_label =
'Save', $cancel_label =
'Cancel', $morebuttons = array(), $withoutdiv =
false, $morecss =
'', $dol_openinpopup =
'')
12399 $buttons = array();
12403 'label_key' => $save_label,
12406 if ($save_label ==
'Create' || $save_label ==
'Add') {
12407 $save[
'name'] =
'add';
12408 } elseif ($save_label ==
'Modify') {
12409 $save[
'name'] =
'edit';
12413 'name' =>
'cancel',
12414 'label_key' =>
'Cancel',
12419 !empty($save_label) ? $buttons[] = $save :
'';
12420 if (!empty($morebuttons)) {
12421 $buttons[] = $morebuttons;
12423 !empty($cancel_label) ? $buttons[] = $cancel :
'';
12425 if (!empty($morebuttons)) {
12426 $buttons[] = $morebuttons;
12428 !empty($cancel_label) ? $buttons[] = $cancel :
'';
12429 !empty($save_label) ? $buttons[] = $save :
'';
12432 $retstring = $withoutdiv ?
'' :
'<div class="center">';
12434 foreach ($buttons as $button) {
12435 $addclass = empty($button[
'addclass']) ?
'' : $button[
'addclass'];
12436 $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'])) .
'">';
12438 $retstring .= $withoutdiv ?
'' :
'</div>';
12440 if ($dol_openinpopup) {
12441 $retstring .=
'<!-- buttons are shown into a $dol_openinpopup=' .
dol_escape_htmltag($dol_openinpopup) .
' context, so we enable the close of dialog on cancel -->' .
"\n";
12442 $retstring .=
'<script nonce="' .
getNonce() .
'">';
12443 $retstring .=
'jQuery(".button-cancel").click(function(e) {
12444 e.preventDefault(); console.log(\'We click on cancel in iframe popup ' .
dol_escape_js($dol_openinpopup) .
'\');
12445 window.parent.jQuery(\
'#idfordialog' .
dol_escape_js($dol_openinpopup) .
'\').dialog(\
'close\');
12447 $retstring .=
'</script>';
12466 $num = count($this->cache_invoice_subtype);
12473 $sql =
"SELECT rowid, code, label as label";
12474 $sql .=
" FROM " . MAIN_DB_PREFIX .
'c_invoice_subtype';
12475 $sql .=
" WHERE active = 1";
12477 $resql = $this->db->query($sql);
12479 $num = $this->db->num_rows($resql);
12481 while ($i < $num) {
12482 $obj = $this->db->fetch_object($resql);
12485 $label = ($langs->trans(
"InvoiceSubtype" . $obj->rowid) !=
"InvoiceSubtype" . $obj->rowid) ? $langs->trans(
"InvoiceSubtype" . $obj->rowid) : (($obj->label !=
'-') ? $obj->label :
'');
12486 $this->cache_invoice_subtype[$obj->rowid][
'rowid'] = $obj->rowid;
12487 $this->cache_invoice_subtype[$obj->rowid][
'code'] = $obj->code;
12488 $this->cache_invoice_subtype[$obj->rowid][
'label'] = $label;
12492 $this->cache_invoice_subtype =
dol_sort_array($this->cache_invoice_subtype,
'code',
'asc', 0, 0, 1);
12514 global $langs, $user;
12517 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
12519 $this->load_cache_invoice_subtype();
12521 $out .=
'<select id="' . $htmlname .
'" class="flat selectsubtype' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
12523 $out .=
'<option value="0"> </option>';
12526 foreach ($this->cache_invoice_subtype as $rowid => $subtype) {
12527 $label = $subtype[
'label'];
12528 $out .=
'<option value="' . $subtype[
'rowid'] .
'"';
12529 if ($selected == $subtype[
'rowid']) {
12530 $out .=
' selected="selected"';
12534 $out .=
'</option>';
12537 $out .=
'</select>';
12538 if ($user->admin && empty($noinfoadmin)) {
12539 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
12560 'type' =>
'search',
12561 'name' => $htmlName,
12563 'class' =>
"search-tool-input",
12564 'placeholder' => $langs->trans(
'Search'),
12565 'autocomplete' =>
'off'
12573 if ($dataTarget !==
false) {
12574 $attr[
'data-search-tool-target'] = $dataTarget;
12578 if (!empty($params[
'attr']) && is_array($params[
'attr'])) {
12579 foreach ($params[
'attr'] as $key => $value) {
12580 if ($key ==
'class') {
12581 $attr[
'class'] .=
' '.$value;
12582 } elseif ($key ==
'classOverride') {
12583 $attr[
'class'] = $value;
12585 $attr[$key] = $value;
12591 if (!empty($attr[
'title']) && !empty($attr[
'class']) && strpos($attr[
'class'],
'classfortooltip') ===
false) {
12592 $attr[
'class'] .=
' classfortooltip';
12595 $TCompiledAttr = [];
12596 foreach ($attr as $key => $value) {
12597 if (in_array($key, [
'data-target'])
12598 || (!empty($params[
'use_unsecured_unescapedattr']) && is_array($params[
'use_unsecured_unescapedattr']) && in_array($key, $params[
'use_unsecured_unescapedattr']))) {
12604 $TCompiledAttr[] = $key .
'="' . $value .
'"';
12607 $compiledAttributes = implode(
' ', $TCompiledAttr);
12610 return '<div class="search-tool-container"><input '.$compiledAttributes.
'></div>';
12626 public function inputType($type, $name, $value =
'',
$id =
'', $morecss =
'', $moreparam =
'', $label =
'', $addInputLabel =
'')
12629 if ($label !=
'') {
12639 $out .= ($moreparam ?
' ' . $moreparam :
'');
12640 $out .=
' />' . $addInputLabel;
12641 if ($label !=
'') {
12642 $out .= $label .
'</label>';
12660 public function inputSelectAjax($htmlName, $array,
$id, $ajaxUrl, $ajaxData = [], $morecss =
'minwidth75', $moreparam =
'')
12664 $(document).ready(function () {
12665 $('#" . $htmlName .
"').select2({
12667 url: '" . $ajaxUrl .
"',
12669 delay: 250, // wait 250 milliseconds before triggering the request
12670 data: function (params) {
12672 search: params.term,
12673 page: params.page || 1";
12674 if (!empty($ajaxData) && is_array($ajaxData)) {
12675 foreach ($ajaxData as $key => $value) {
12676 $out .=
", " . $key .
": '" . $value .
"'";
12688 $out .= $this->selectarray($htmlName, $array,
$id, 0, 0, 0, $moreparam, 0, 0, 0,
'', $morecss);
12702 public function inputHtml($htmlName, $value, $morecss =
'', $moreparam =
'')
12704 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
12705 $doleditor =
new DolEditor($htmlName, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
isModEnabled(
'fckeditor') &&
getDolGlobalInt(
'FCKEDITOR_ENABLE_SOCIETE'), ROWS_5,
'90%');
12707 return (
string) $doleditor->Create(1,
'',
true,
'',
'', $moreparam, $morecss);
12720 public function inputText($htmlName, $value, $morecss =
'', $moreparam =
'', $options = array())
12725 if (!empty($options)) {
12727 $out .= $this->selectarray($htmlName .
"_multiinput", $options,
'', 1, 0, 0, $moreparam, 0, 0, 0,
'',
"flat maxwidthonphone" . $morecss);
12728 $out .=
'<input id="' . $htmlName .
'_multiinputadd" type="button" class="button" value="' . $langs->trans(
"Add") .
'">';
12729 $out .=
"<script>";
12731 function handlemultiinputdisabling(htmlname){
12732 console.log("We handle the disabling of used options for "+htmlname+"_multiinput");
12733 multiinput = $("#"+htmlname+"_multiinput");
12734 multiinput.find("option").each(function(){
12735 tmpval = $("#"+htmlname).val();
12736 tmpvalarray = tmpval.split("\n");
12737 valtotest = $(this).val();
12738 if(tmpvalarray.includes(valtotest)){
12739 $(this).prop("disabled",true);
12741 if($(this).prop("disabled") == true){
12742 console.log(valtotest)
12743 $(this).prop("disabled", false);
12749 $(document).ready(function () {
12750 $("#' . $htmlName .
'_multiinputadd").on("click",function() {
12751 tmpval = $("#' . $htmlName .
'").val();
12752 tmpvalarray = tmpval.split(",");
12753 valtotest = $("#' . $htmlName .
'_multiinput").val();
12754 if(valtotest != -1 && !tmpvalarray.includes(valtotest)){
12755 console.log("We add the selected value to the text area ' . $htmlName .
'");
12757 tmpval = valtotest;
12759 tmpval = tmpval + "\n" + valtotest;
12761 $("#' . $htmlName .
'").val(tmpval);
12762 handlemultiinputdisabling("' . $htmlName .
'");
12763 $("#' . $htmlName .
'_multiinput").val(-1);
12765 console.log("We add nothing the text area ' . $htmlName .
'");
12768 $("#' . $htmlName .
'").on("change",function(){
12769 handlemultiinputdisabling("' . $htmlName .
'");
12771 handlemultiinputdisabling("' . $htmlName .
'");
12773 $out .=
"</script>";
12774 $value = str_replace(
',',
"\n", $value);
12777 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
12778 $doleditor =
new DolEditor($htmlName, (
string) $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
12779 $out .= (string) $doleditor->Create(1,
'',
true,
'',
'', $moreparam, $morecss);
12794 public function inputRadio($htmlName, $options, $selectedValue, $morecss =
'', $moreparam =
'')
12797 foreach ($options as $optionKey => $optionLabel) {
12798 $selected = ((string) $selectedValue) === ((string) $optionKey) ?
' checked="checked"' :
'';
12799 $optionId = $htmlName .
'_' . $optionKey;
12800 $out .=
'<input class="flat' . $morecss .
'" type="radio" name="' . $htmlName .
'" id="' . $optionId .
'" value="' .
dolPrintHTMLForAttribute((
string) $optionKey) .
'"' . $selected . $moreparam .
'/><label for="' . $optionId .
'">' . $optionLabel .
'</label><br>';
12816 public function inputStars($htmlName, $size, $value, $morecss =
'', $moreparam =
'')
12818 $out =
'<input type="hidden" class="flat ' . $morecss .
'" name="' . $htmlName .
'" id="' . $htmlName .
'" value="' .
dolPrintHTMLForAttribute((
string) $value) .
'"' . $moreparam .
'>';
12819 $out .=
'<div class="star-selection" id="' . $htmlName .
'_selection">';
12820 for ($i = 1; $i <= $size; $i++) {
12821 $out .=
'<span class="star" data-value="' . $i .
'">' .
img_picto(
'',
'fontawesome_star_fas') .
'</span>';
12825 jQuery(function($) { /* commonobject.class.php 1 */
12826 let container = $("#' . $htmlName .
'_selection");
12827 let selectedStars = parseInt($("#' . $htmlName .
'").val()) || 0;
12828 container.find(".star").each(function() {
12829 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
12831 container.find(".star").on("mouseover", function() {
12832 let selectedStar = $(this).data("value");
12833 container.find(".star").each(function() {
12834 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
12837 container.on("mouseout", function() {
12838 container.find(".star").each(function() {
12839 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
12842 container.find(".star").off("click").on("click", function() {
12843 selectedStars = $(this).data("value");
12844 if (selectedStars === 1 && $("#' . $htmlName .
'").val() == 1) {
12847 $("#' . $htmlName .
'").val(selectedStars);
12848 container.find(".star").each(function() {
12849 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
12867 public function inputIcon($htmlName, $value, $morecss =
'', $moreparam =
'')
12876 $out =
'<input type="text" class="form-control icp icp-auto iconpicker-element iconpicker-input flat ' . $morecss .
' maxwidthonsmartphone"';
12877 $out .=
' name="' . $htmlName .
'" id="' . $htmlName .
'" value="' .
dolPrintHTMLForAttribute((
string) $value) .
'" ' . ((string) $moreparam) .
'>';
12879 $out .=
'<script>';
12880 $options =
"{ title: '<b>" . $langs->trans(
"IconFieldSelector") .
"</b>', placement: 'right', showFooter: false, templates: {";
12881 $options .=
"iconpicker: '<div class=\"iconpicker\"><div style=\"background-color:#EFEFEF;\" class=\"iconpicker-items\"></div></div>',";
12882 $options .=
"iconpickerItem: '<a role=\"button\" href=\"#\" class=\"iconpicker-item\" style=\"background-color:#DDDDDD;\"><i></i></a>',";
12885 $options .=
"footer: '<div class=\"popover-footer\" style=\"background-color:#EFEFEF;\"></div>',";
12886 $options .=
"search: '<input type=\"search\" class\"form-control iconpicker-search\" placeholder=\"" . $langs->trans(
"TypeToFilter") .
"\" />',";
12887 $options .=
"popover: '<div class=\"iconpicker-popover popover\">";
12888 $options .=
" <div class=\"arrow\" ></div>";
12889 $options .=
" <div class=\"popover-title\" style=\"text-align:center;background-color:#EFEFEF;\"></div>";
12890 $options .=
" <div class=\"popover-content \" ></div>";
12891 $options .=
"</div>'}}";
12892 $out .=
"$('#" . $htmlName .
"').iconpicker(" . $options .
");";
12893 $out .=
'</script>';
12909 require_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeophp.class.php';
12910 require_once DOL_DOCUMENT_ROOT .
'/core/class/geomapeditor.class.php';
12916 if (!empty($value)) {
12917 $tmparray = $dolgeophp->parseGeoString($value);
12918 $geojson = $tmparray[
'geojson'];
12919 $centroidjson = $tmparray[
'centroidjson'];
12922 return $geomapeditor->getHtml($htmlName, $geojson, $centroidjson, $type);
12934 $toPrint = array();
12935 $values = is_array($values) ? $values : array();
12937 foreach ($values as $value) {
12938 $toPrint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $value .
'</li>';
12940 if (!empty($toPrint)) {
12941 $out =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(
' ', $toPrint) .
'</ul></div>';
12957 for ($i = 1; $i <= $size; $i++) {
12958 $out .=
'<span class="star' . ($i <= $value ?
' active' :
'') .
'" data-value="' . $i .
'">' .
img_picto(
'',
'fontawesome_star_fas') .
'</span>';
12989 if (!empty($value)) {
12990 require_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeophp.class.php';
12992 if ($type ==
'point') {
12993 $out = $dolgeophp->getXYString($value);
12995 $out = $dolgeophp->getPointString($value);
13016 public function getNomUrl(&
$object, $withpicto = 0, $option =
'', $maxlength = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'', $add_label = 0, $sep =
' - ')
13018 if (is_object(
$object) && method_exists(
$object,
'getNomUrl')) {
13019 $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_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, ....
dol_print_email($email, $contactid=0, $socid=0, $addlink=0, $max=0, $showinvalid=1, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
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,...