71 public $errors = array();
81 public $cache_types_paiements = array();
82 public $cache_conditions_paiements = array();
83 public $cache_transport_mode = array();
85 public $cache_availability = array();
86 public $cache_demand_reason = array();
87 public $cache_types_fees = array();
88 public $cache_vatrates = array();
89 public $cache_invoice_subtype = array();
91 public $cache_rule_for_lines_dates = array();
120 public function editfieldkey($text, $htmlname, $preselected,
$object, $perm, $typeofdata =
'string', $moreparam =
'', $fieldrequired = 0, $notabletag = 0, $paramid =
'id', $help =
'')
127 if (
getDolGlobalString(
'MAIN_USE_JQUERY_JEDITABLE') && !preg_match(
'/^select;/', $typeofdata)) {
129 $tmp = explode(
':', $typeofdata);
130 $ret .=
'<div class="editkey_' . $tmp[0] . (!empty($tmp[1]) ?
' ' . $tmp[1] :
'') .
'" id="' . $htmlname .
'">';
131 if ($fieldrequired) {
132 $ret .=
'<span class="fieldrequired">';
137 $ret .= $langs->trans($text);
139 if ($fieldrequired) {
142 $ret .=
'</div>' .
"\n";
144 if ($fieldrequired) {
145 $ret .=
'<span class="fieldrequired">';
150 $ret .= $langs->trans($text);
152 if ($fieldrequired) {
157 if (empty($notabletag) && $perm) {
158 $ret .=
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
160 if ($fieldrequired) {
161 $ret .=
'<span class="fieldrequired">';
166 $ret .= $langs->trans($text);
168 if ($fieldrequired) {
171 if (!empty($notabletag)) {
174 if (empty($notabletag) && $perm) {
177 if (empty($notabletag) && $perm) {
178 $ret .=
'<td class="right">';
180 if ($htmlname &&
GETPOST(
'action',
'aZ09') !=
'edit' . $htmlname && $perm) {
181 $ret .=
'<a class="editfielda reposition" href="' . $_SERVER[
"PHP_SELF"] .
'?action=edit' . $htmlname .
'&token=' .
newToken() .
'&' . $paramid .
'=' .
$object->id . $moreparam .
'">' .
img_edit($langs->trans(
'Edit'), ($notabletag ? 0 : 1)) .
'</a>';
183 if (!empty($notabletag) && $notabletag == 1) {
190 if (!empty($notabletag) && $notabletag == 3) {
193 if (empty($notabletag) && $perm) {
196 if (empty($notabletag) && $perm) {
197 $ret .=
'</tr></table>';
227 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 =
'')
229 global
$conf, $langs;
234 if (empty($typeofdata)) {
235 return 'ErrorBadParameter typeofdata is empty';
238 if ($typeofdata ==
'datetime') {
239 $typeofdata =
'dayhour';
242 if (preg_match(
'/^(\w+)\((\d+)\)$/', $typeofdata, $reg)) {
243 if ($reg[1] ==
'varchar') {
244 $typeofdata =
'string';
245 } elseif ($reg[1] ==
'int') {
246 $typeofdata =
'numeric';
248 return 'ErrorBadParameter ' . $typeofdata;
253 if (
getDolGlobalString(
'MAIN_USE_JQUERY_JEDITABLE') && !preg_match(
'/^select;|day|datepicker|dayhour|datehourpicker/', $typeofdata)) {
254 $ret .= $this->
editInPlace(
$object, $value, $htmlname, ($perm ? 1 : 0), $typeofdata, $editvalue, $extObject, $custommsg);
256 if ($editaction ==
'') {
257 $editaction =
GETPOST(
'action',
'aZ09');
259 $editmode = ($editaction ==
'edit' . $htmlname);
261 $ret .=
"<!-- formeditfieldval -->\n";
262 $ret .=
'<form method="post" action="' . $_SERVER[
"PHP_SELF"] . ($moreparam ?
'?' . $moreparam :
'') .
'">';
263 $ret .=
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
264 $ret .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
265 $ret .=
'<input type="hidden" name="' . $paramid .
'" value="' .
$object->id .
'">';
266 if (empty($notabletag)) {
267 $ret .=
'<table class="nobordernopadding centpercent">';
269 if (empty($notabletag)) {
272 if (preg_match(
'/^(string|safehtmlstring|email|phone|url)/', $typeofdata)) {
273 $tmp = explode(
':', $typeofdata);
274 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($editvalue ? $editvalue : $value) .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
275 } elseif (preg_match(
'/^(integer)/', $typeofdata)) {
276 $tmp = explode(
':', $typeofdata);
277 $valuetoshow =
price2num($editvalue ? $editvalue : $value, 0);
278 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $valuetoshow .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
279 } elseif (preg_match(
'/^(numeric|amount)/', $typeofdata)) {
280 $tmp = explode(
':', $typeofdata);
281 $valuetoshow =
price2num($editvalue ? $editvalue : $value);
282 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($valuetoshow !=
'' ?
price($valuetoshow) :
'') .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
283 } elseif (preg_match(
'/^(checkbox)/', $typeofdata)) {
284 $tmp = explode(
':', $typeofdata);
285 $ret .=
'<input type="checkbox" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($value ? $value :
'on') .
'"' . ($value ?
' checked' :
'') . (empty($tmp[1]) ?
'' : $tmp[1]) .
'/>';
286 } elseif (preg_match(
'/^text/', $typeofdata) || preg_match(
'/^note/', $typeofdata)) {
287 $tmp = explode(
':', $typeofdata);
288 $cols = (empty($tmp[2]) ?
'' : $tmp[2]);
290 if (preg_match(
'/%/', $cols)) {
291 $morealt =
' style="width: ' . $cols .
'"';
294 $valuetoshow = ($editvalue ? $editvalue : $value);
295 $ret .=
'<textarea id="' . $htmlname .
'" name="' . $htmlname .
'" wrap="soft" rows="' . (empty($tmp[1]) ?
'20' : $tmp[1]) .
'"' . ($cols ?
' cols="' . $cols .
'"' :
'class="quatrevingtpercent"') . $morealt .
'" autofocus>';
298 $valuetoshow = str_replace(
'&',
'&', $valuetoshow);
300 $ret .=
'</textarea><div class="clearboth"></div>';
301 } elseif ($typeofdata ==
'day' || $typeofdata ==
'datepicker') {
302 $addnowlink = empty($moreoptions[
'addnowlink']) ? 0 : $moreoptions[
'addnowlink'];
303 $adddateof = empty($moreoptions[
'adddateof']) ?
'' : $moreoptions[
'adddateof'];
304 $labeladddateof = empty($moreoptions[
'labeladddateof']) ?
'' : $moreoptions[
'labeladddateof'];
305 $ret .= $this->
selectDate($value, $htmlname, 0, 0, 1,
'form' . $htmlname, 1, $addnowlink, 0,
'',
'', $adddateof,
'', 1, $labeladddateof,
'', $gm);
306 } elseif ($typeofdata ==
'dayhour' || $typeofdata ==
'datehourpicker') {
307 $addnowlink = empty($moreoptions[
'addnowlink']) ? 0 : $moreoptions[
'addnowlink'];
308 $adddateof = empty($moreoptions[
'adddateof']) ?
'' : $moreoptions[
'adddateof'];
309 $labeladddateof = empty($moreoptions[
'labeladddateof']) ?
'' : $moreoptions[
'labeladddateof'];
310 $ret .= $this->
selectDate($value, $htmlname, 1, 1, 1,
'form' . $htmlname, 1, $addnowlink, 0,
'',
'', $adddateof,
'', 1, $labeladddateof,
'', $gm);
311 } elseif (preg_match(
'/^select;/', $typeofdata)) {
312 $arraydata = explode(
',', preg_replace(
'/^select;/',
'', $typeofdata));
313 $arraylist = array();
314 foreach ($arraydata as $val) {
315 $tmp = explode(
':', $val);
316 $tmpkey = str_replace(
'|',
':', $tmp[0]);
317 $arraylist[$tmpkey] = $tmp[1];
319 $ret .= $this->
selectarray($htmlname, $arraylist, $value);
320 } elseif (preg_match(
'/^link/', $typeofdata)) {
322 } elseif (preg_match(
'/^ckeditor/', $typeofdata)) {
323 $tmp = explode(
':', $typeofdata);
324 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
325 $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]));
326 $ret .= $doleditor->Create(1);
327 } elseif ($typeofdata ==
'asis') {
328 $ret .= ($editvalue ? $editvalue : $value);
330 if (empty($notabletag)) {
335 if (empty($notabletag)) {
339 $ret .=
'<input type="submit" class="smallpaddingimp nomargingtop nomarginbottom button' . (empty($notabletag) ?
'' :
' ') .
'" name="modify" value="' . $langs->trans(
"Save") .
'">';
340 if (preg_match(
'/ckeditor|textarea/', $typeofdata) && empty($notabletag)) {
341 $ret .=
'<br>' .
"\n";
343 $ret .=
'<input type="submit" class="smallpaddingimp nomargingtop nomarginbottom button button-cancel' . (empty($notabletag) ?
'' :
' ') .
'" name="cancel" value="' . $langs->trans(
"Cancel") .
'">';
344 if (empty($notabletag)) {
348 if (empty($notabletag)) {
349 $ret .=
'</tr></table>' .
"\n";
351 $ret .=
'</form>' .
"\n";
353 if (preg_match(
'/^email/', $typeofdata)) {
355 } elseif (preg_match(
'/^phone/', $typeofdata)) {
357 } elseif (preg_match(
'/^url/', $typeofdata)) {
359 } elseif (preg_match(
'/^(amount|numeric)/', $typeofdata)) {
360 $ret .= ($value !=
'' ?
price($value, 0, $langs, 0, -1, -1,
$conf->currency) :
'');
361 } elseif (preg_match(
'/^checkbox/', $typeofdata)) {
362 $tmp = explode(
':', $typeofdata);
363 $ret .=
'<input type="checkbox" disabled id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $value .
'"' . ($value ?
' checked' :
'') . ($tmp[1] ? $tmp[1] :
'') .
'/>';
364 } elseif (preg_match(
'/^text/', $typeofdata) || preg_match(
'/^note/', $typeofdata)) {
366 } elseif (preg_match(
'/^(safehtmlstring|restricthtml)/', $typeofdata)) {
368 } elseif ($typeofdata ==
'day' || $typeofdata ==
'datepicker') {
369 $ret .=
'<span class="valuedate">' .
dol_print_date($value,
'day', $gm) .
'</span>';
370 } elseif ($typeofdata ==
'dayhour' || $typeofdata ==
'datehourpicker') {
371 $ret .=
'<span class="valuedate">' .
dol_print_date($value,
'dayhour', $gm) .
'</span>';
372 } elseif (preg_match(
'/^select;/', $typeofdata)) {
373 $arraydata = explode(
',', preg_replace(
'/^select;/',
'', $typeofdata));
374 $arraylist = array();
375 foreach ($arraydata as $val) {
376 $tmp = explode(
':', $val);
377 $arraylist[$tmp[0]] = $tmp[1];
379 $ret .= $arraylist[$value];
380 if ($htmlname ==
'fk_product_type') {
382 $ret =
img_picto($langs->trans(
"Product"),
'product',
'class="paddingleftonly paddingrightonly colorgrey"') . $ret;
384 $ret =
img_picto($langs->trans(
"Service"),
'service',
'class="paddingleftonly paddingrightonly colorgrey"') . $ret;
387 } elseif (preg_match(
'/^ckeditor/', $typeofdata)) {
390 $firstline = preg_replace(
'/<br>.*/',
'', $tmpcontent);
391 $firstline = preg_replace(
'/[\n\r].*/',
'', $firstline);
392 $tmpcontent = $firstline . ((strlen($firstline) != strlen($tmpcontent)) ?
'...' :
'');
398 if (empty($moreoptions[
'valuealreadyhtmlescaped'])) {
406 if ($formatfunc && method_exists(
$object, $formatfunc)) {
407 $ret =
$object->$formatfunc($ret);
427 global
$conf, $langs, $extralanguages;
432 $arrayoflangcode = array();
437 if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
438 if (!is_object($extralanguages)) {
439 include_once DOL_DOCUMENT_ROOT .
'/core/class/extralanguages.class.php';
442 $extralanguages->fetch_name_extralanguages(
'societe');
447 if (empty($extralanguages->attributes[
$object->element]) || !is_array($extralanguages->attributes[
$object->element]) || empty($extralanguages->attributes[
$object->element][$fieldname])) {
451 $result .=
'<!-- Widget for translation -->' .
"\n";
452 $result .=
'<div class="inline-block paddingleft image-' .
$object->element .
'-' . $fieldname .
'">';
453 $s =
img_picto($langs->trans(
"ShowOtherLanguages"),
'language',
'', 0, 0, 0,
'',
'fa-15 editfieldlang');
457 $result .=
'<div class="inline-block hidden field-' .
$object->element .
'-' . $fieldname .
'">';
459 $resultforextrlang =
'';
460 foreach ($arrayoflangcode as $langcode) {
461 $valuetoshow = GETPOSTISSET(
'field-' .
$object->element .
"-" . $fieldname .
"-" . $langcode) ?
GETPOST(
'field-' .
$object->element .
'-' . $fieldname .
"-" . $langcode, $check) :
'';
462 if (empty($valuetoshow)) {
463 $object->fetchValuesForExtraLanguages();
465 $valuetoshow =
$object->array_languages[$fieldname][$langcode];
469 $resultforextrlang .= $s;
472 if ($typeofdata ==
'textarea') {
473 $resultforextrlang .=
'<textarea name="field-' .
$object->element .
"-" . $fieldname .
"-" . $langcode .
'" id="' . $fieldname .
"-" . $langcode .
'" class="' . $morecss .
'" rows="' . ROWS_2 .
'" wrap="soft">';
474 $resultforextrlang .= $valuetoshow;
475 $resultforextrlang .=
'</textarea>';
477 $resultforextrlang .=
'<input type="text" class="inputfieldforlang ' . ($morecss ?
' ' . $morecss :
'') .
'" name="field-' .
$object->element .
'-' . $fieldname .
'-' . $langcode .
'" value="' . $valuetoshow .
'">';
480 $result .= $resultforextrlang;
483 $result .=
'<script nonce="' .
getNonce() .
'">$(".image-' .
$object->element .
'-' . $fieldname .
'").click(function() { console.log("Toggle lang widget"); jQuery(".field-' .
$object->element .
'-' . $fieldname .
'").toggle(); });</script>';
502 protected function editInPlace(
$object, $value, $htmlname, $condition, $inputType =
'textarea', $editvalue =
null, $extObject =
null, $custommsg =
null)
507 if (preg_match(
'/^text/', $inputType)) {
509 } elseif (preg_match(
'/^numeric/', $inputType)) {
510 $value =
price($value);
511 } elseif ($inputType ==
'day' || $inputType ==
'datepicker') {
517 $table_element =
false;
521 $ext_element =
false;
522 $button_only =
false;
529 $table_element =
$object->table_element;
533 if (is_object($extObject)) {
534 $ext_element = $extObject->element;
537 if (preg_match(
'/^(string|email|numeric)/', $inputType)) {
538 $tmp = explode(
':', $inputType);
539 $inputType = $tmp[0];
540 if (!empty($tmp[1])) {
541 $inputOption = $tmp[1];
543 if (!empty($tmp[2])) {
544 $savemethod = $tmp[2];
546 $out .=
'<input id="width_' . $htmlname .
'" value="' . $inputOption .
'" type="hidden"/>' .
"\n";
547 } elseif ((preg_match(
'/^day$/', $inputType)) || (preg_match(
'/^datepicker/', $inputType)) || (preg_match(
'/^datehourpicker/', $inputType))) {
548 $tmp = explode(
':', $inputType);
549 $inputType = $tmp[0];
550 if (!empty($tmp[1])) {
551 $inputOption = $tmp[1];
553 if (!empty($tmp[2])) {
554 $savemethod = $tmp[2];
557 $out .=
'<input id="timestamp" type="hidden"/>' .
"\n";
558 } elseif (preg_match(
'/^(select|autocomplete)/', $inputType)) {
559 $tmp = explode(
':', $inputType);
560 $inputType = $tmp[0];
561 $loadmethod = $tmp[1];
562 if (!empty($tmp[2])) {
563 $savemethod = $tmp[2];
565 if (!empty($tmp[3])) {
568 } elseif (preg_match(
'/^textarea/', $inputType)) {
569 $tmp = explode(
':', $inputType);
570 $inputType = $tmp[0];
571 $rows = (empty($tmp[1]) ?
'8' : $tmp[1]);
572 $cols = (empty($tmp[2]) ?
'80' : $tmp[2]);
573 } elseif (preg_match(
'/^ckeditor/', $inputType)) {
574 $tmp = explode(
':', $inputType);
575 $inputType = $tmp[0];
577 if (!empty($tmp[2])) {
580 if (!empty($tmp[3])) {
583 if (!empty($tmp[4])) {
584 $savemethod = $tmp[4];
587 if (isModEnabled(
'fckeditor')) {
588 $out .=
'<input id="ckeditor_toolbar" value="' . $toolbar .
'" type="hidden"/>' .
"\n";
590 $inputType =
'textarea';
594 $out .=
'<input id="element_' . $htmlname .
'" value="' . $element .
'" type="hidden"/>' .
"\n";
595 $out .=
'<input id="table_element_' . $htmlname .
'" value="' . $table_element .
'" type="hidden"/>' .
"\n";
596 $out .=
'<input id="fk_element_' . $htmlname .
'" value="' . $fk_element .
'" type="hidden"/>' .
"\n";
597 $out .=
'<input id="loadmethod_' . $htmlname .
'" value="' . $loadmethod .
'" type="hidden"/>' .
"\n";
598 if (!empty($savemethod)) {
599 $out .=
'<input id="savemethod_' . $htmlname .
'" value="' . $savemethod .
'" type="hidden"/>' .
"\n";
601 if (!empty($ext_element)) {
602 $out .=
'<input id="ext_element_' . $htmlname .
'" value="' . $ext_element .
'" type="hidden"/>' .
"\n";
604 if (!empty($custommsg)) {
605 if (is_array($custommsg)) {
606 if (!empty($custommsg[
'success'])) {
607 $out .=
'<input id="successmsg_' . $htmlname .
'" value="' . $custommsg[
'success'] .
'" type="hidden"/>' .
"\n";
609 if (!empty($custommsg[
'error'])) {
610 $out .=
'<input id="errormsg_' . $htmlname .
'" value="' . $custommsg[
'error'] .
'" type="hidden"/>' .
"\n";
613 $out .=
'<input id="successmsg_' . $htmlname .
'" value="' . $custommsg .
'" type="hidden"/>' .
"\n";
616 if ($inputType ==
'textarea') {
617 $out .=
'<input id="textarea_' . $htmlname .
'_rows" value="' . $rows .
'" type="hidden"/>' .
"\n";
618 $out .=
'<input id="textarea_' . $htmlname .
'_cols" value="' . $cols .
'" type="hidden"/>' .
"\n";
620 $out .=
'<span id="viewval_' . $htmlname .
'" class="viewval_' . $inputType . ($button_only ?
' inactive' :
' active') .
'">' . $value .
'</span>' .
"\n";
621 $out .=
'<span id="editval_' . $htmlname .
'" class="editval_' . $inputType . ($button_only ?
' inactive' :
' active') .
' hideobject">' . (!empty($editvalue) ? $editvalue : $value) .
'</span>' .
"\n";
647 public function textwithtooltip($text, $htmltext, $tooltipon = 1, $direction = 0, $img =
'', $extracss =
'', $notabs = 3, $incbefore =
'', $noencodehtmltext = 0, $tooltiptrigger =
'', $forcenowrap = 0)
650 $text = $incbefore . $text;
655 $direction = (int) $direction;
665 $htmltext = str_replace(array(
"\r",
"\n"),
'', $htmltext);
668 if ($direction < 0) {
669 $extracss = ($extracss ? $extracss :
'') . ($notabs != 3 ?
' inline-block' :
'');
670 $extrastyle =
'padding: 0px; padding-left: 2px;';
672 if ($direction > 0) {
673 $extracss = ($extracss ? $extracss :
'') . ($notabs != 3 ?
' inline-block' :
'');
674 $extrastyle =
'padding: 0px; padding-right: 2px;';
677 $classfortooltip =
'classfortooltip';
682 if ($tooltiptrigger ==
'') {
683 $htmltext = str_replace(
'"',
'"', $htmltext);
685 $classfortooltip =
'classfortooltiponclick';
686 $textfordialog .=
'<div style="display: none;" id="idfortooltiponclick_' . $tooltiptrigger .
'" class="classfortooltiponclicktext"';
690 $textfordialog .=
' title="'.$langs->trans(
"Note").
'"';
692 $textfordialog .=
'>' . $htmltext .
'</div>';
694 if ($tooltipon == 2 || $tooltipon == 3) {
695 $paramfortooltipimg =
' class="' . $classfortooltip . ($notabs != 3 ?
' inline-block' :
'') . ($extracss ?
' ' . $extracss :
'') .
'" style="padding: 0px;' . ($extrastyle ?
' ' . $extrastyle :
'') .
'"';
696 if ($tooltiptrigger ==
'') {
697 $paramfortooltipimg .=
' title="' . ($noencodehtmltext ? $htmltext :
dol_escape_htmltag($htmltext, 1)) .
'"';
699 $paramfortooltipimg .=
' dolid="' . $tooltiptrigger .
'"';
702 $paramfortooltipimg = ($extracss ?
' class="' . $extracss .
'"' :
'') . ($extrastyle ?
' style="' . $extrastyle .
'"' :
'');
704 if ($tooltipon == 1 || $tooltipon == 3) {
705 $paramfortooltiptd =
' class="' . ($tooltipon == 3 ?
'cursorpointer ' :
'') . $classfortooltip . ($tag !=
'td' ?
' inline-block' :
'') . ($extracss ?
' ' . $extracss :
'') .
'" style="padding: 0px;' . ($extrastyle ?
' ' . $extrastyle :
'') .
'" ';
706 if ($tooltiptrigger ==
'') {
707 $paramfortooltiptd .=
' title="' . ($noencodehtmltext ? $htmltext :
dol_escape_htmltag($htmltext, 1)) .
'"';
709 $paramfortooltiptd .=
' dolid="' . $tooltiptrigger .
'"';
712 $paramfortooltiptd = ($extracss ?
' class="' . $extracss .
'"' :
'') . ($extrastyle ?
' style="' . $extrastyle .
'"' :
'');
714 if (empty($notabs)) {
715 $s .=
'<table class="nobordernopadding"><tr style="height: auto;">';
716 } elseif ($notabs == 2) {
717 $s .=
'<div class="inline-block' . ($forcenowrap ?
' nowrap' :
'') .
'">';
720 if ($direction < 0) {
721 $s .=
'<' . $tag . $paramfortooltipimg;
723 $s .=
' class="valigntop" width="14"';
725 $s .=
'>' . $textfordialog . $img .
'</' . $tag .
'>';
729 if ((
string) $text !=
'') {
730 $s .=
'<' . $tag . $paramfortooltiptd .
'>' . $text .
'</' . $tag .
'>';
733 if ($direction > 0) {
734 $s .=
'<' . $tag . $paramfortooltipimg;
736 $s .=
' class="valignmiddle" width="14"';
738 $s .=
'>' . $textfordialog . $img .
'</' . $tag .
'>';
740 if (empty($notabs)) {
741 $s .=
'</tr></table>';
742 } elseif ($notabs == 2) {
763 public function textwithpicto($text, $htmltooltip, $direction = 1, $type =
'help', $extracss =
'valignmiddle', $noencodehtmltext = 0, $notabs = 3, $tooltiptrigger =
'', $forcenowrap = 0)
765 global
$conf, $langs;
770 } elseif ($type ==
'1') {
774 $tooltiptrigger = preg_replace(
'/[^a-z0-9]/i',
'', $tooltiptrigger);
776 if (preg_match(
'/onsmartphone$/', $tooltiptrigger) && empty(
$conf->dol_no_mouse_hover)) {
777 $tooltiptrigger = preg_replace(
'/^.*onsmartphone$/',
'', $tooltiptrigger);
780 if ($tooltiptrigger) {
781 $alt = $langs->transnoentitiesnoconv(
"ClickToShowHelp");
785 if (empty(
$conf->use_javascript_ajax)) {
786 if ($type ==
'info' || $type ==
'infoclickable' || $type ==
'help' || $type ==
'helpclickable') {
795 if (!empty(
$conf->dol_no_mouse_hover) && empty($tooltiptrigger)) {
796 if ($type ==
'info' || $type ==
'infoclickable' || $type ==
'help' || $type ==
'helpclickable') {
807 if ($type ==
'info') {
808 $img =
img_help(($tooltiptrigger !=
'' ? 2 : 0), $alt);
809 } elseif ($type ==
'help') {
810 $img =
img_help(($tooltiptrigger !=
'' ? 2 : 1), $alt);
811 } elseif ($type ==
'helpclickable') {
812 $img =
img_help(($tooltiptrigger !=
'' ? 2 : 1), $alt);
813 } elseif ($type ==
'superadmin') {
816 } elseif ($type ==
'admin') {
819 } elseif ($type ==
'warning') {
821 } elseif ($type !=
'none') {
826 $tooltipon = ((($tooltiptrigger && !$img) || strpos($type,
'clickable')) ? 3 : 2);
828 return $this->
textwithtooltip($text, $htmltooltip, $tooltipon, $direction, $img, $extracss, $notabs,
'', $noencodehtmltext, $tooltiptrigger, $forcenowrap);
841 public function selectMassAction($selected, $arrayofaction, $alwaysvisible = 0, $name =
'massaction', $cssclass =
'checkforselect')
843 global
$conf, $langs, $hookmanager;
846 $ret =
'<div class="centpercent center">';
847 $ret .=
'<select class="flat' . (empty(
$conf->use_javascript_ajax) ?
'' :
' hideobject') .
' ' . $name .
' ' . $name .
'select valignmiddle alignstart" id="' . $name .
'" name="' . $name .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
'>';
850 $parameters = array();
851 $reshook = $hookmanager->executeHooks(
'addMoreMassActions', $parameters);
854 if (is_array($arrayofaction) && count($arrayofaction) == 0 && empty($hookmanager->resPrint)) {
857 if (empty($reshook)) {
858 $ret .=
'<option value="0"' . ($disabled ?
' disabled="disabled"' :
'') .
'>-- ' . $langs->trans(
"SelectAction") .
' --</option>';
859 if (is_array($arrayofaction)) {
860 foreach ($arrayofaction as $code => $label) {
861 $ret .=
'<option value="' . $code .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' data-html="' .
dol_escape_htmltag($label) .
'">' . $label .
'</option>';
865 $ret .= $hookmanager->resPrint;
869 if (empty(
$conf->dol_optimize_smallscreen)) {
874 $ret .=
'<input type="submit" name="confirmmassactioninvisible" style="display: none" tabindex="-1">';
875 $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")) .
'">';
878 if (!empty(
$conf->use_javascript_ajax)) {
879 $ret .=
'<!-- JS CODE TO ENABLE mass action select -->
881 function initCheckForSelect(mode, name, cssclass) { /* mode is 0 during init of page or click all, 1 when we click on 1 checkboxi, "name" refers to the class of the massaction button, "cssclass" to the class of the checkfor select boxes */
882 atleastoneselected=0;
883 jQuery("."+cssclass).each(function( index ) {
884 /* console.log( index + ": " + $( this ).text() ); */
885 if ($(this).is(\':checked\')) atleastoneselected++;
888 console.log("initCheckForSelect mode="+mode+" name="+name+" cssclass="+cssclass+" atleastoneselected="+atleastoneselected);
890 if (atleastoneselected || ' . ((int) $alwaysvisible) .
') {
891 jQuery("."+name).show();
892 ' . ($selected ?
'if (atleastoneselected) { jQuery("."+name+"select").val("' . $selected .
'").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', false); }' :
'') .
'
893 ' . ($selected ?
'if (! atleastoneselected) { jQuery("."+name+"select").val("0").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', true); } ' :
'') .
'
895 jQuery("."+name).hide();
896 jQuery("."+name+"other").hide();
900 jQuery(document).ready(function () {
901 initCheckForSelect(0, "' . $name .
'", "' . $cssclass .
'");
902 jQuery(".' . $cssclass .
'").click(function() {
903 initCheckForSelect(1, "' . $name .
'", "' . $cssclass .
'");
905 jQuery(".' . $name .
'select").change(function() {
906 var massaction = $( this ).val();
907 var urlform = $( this ).closest("form").attr("action").replace("#show_files","");
908 if (massaction == "builddoc") {
909 urlform = urlform + "#show_files";
911 $( this ).closest("form").attr("action", urlform);
912 console.log("we select a mass action name=' . $name .
' massaction="+massaction+" - "+urlform);
913 /* Warning: if you set submit button to disabled, post using Enter will no more work if there is no other button */
914 if ($(this).val() != \'0\') {
915 jQuery(".' . $name .
'confirmed").prop(\'disabled\', false);
916 jQuery(".' . $name .
'other").hide(); /* To disable if another div was open */
917 jQuery(".' . $name .
'"+massaction).show();
919 jQuery(".' . $name .
'confirmed").prop(\'disabled\', true);
920 jQuery(".' . $name .
'other").hide(); /* To disable any div open */
950 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)
953 global $langs, $mysoc;
955 $langs->load(
"dict");
958 $countryArray = array();
961 $atleastonefavorite = 0;
963 $sql =
"SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite, eec";
964 $sql .=
" FROM " . $this->db->prefix() .
"c_country";
965 $sql .=
" WHERE active > 0";
968 dol_syslog(get_class($this) .
"::select_country", LOG_DEBUG);
969 $resql = $this->db->query($sql);
971 $out .=
'<select id="select' . $htmlname .
'" class="flat maxwidth200onsmartphone selectcountry' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" ' . $htmloption .
'>';
972 $num = $this->db->num_rows($resql);
976 $obj = $this->db->fetch_object($resql);
978 $countryArray[$i][
'rowid'] = $obj->rowid;
979 $countryArray[$i][
'code_iso'] = $obj->code_iso;
980 $countryArray[$i][
'code_iso3'] = $obj->code_iso3;
981 $countryArray[$i][
'label'] = ($obj->code_iso && $langs->transnoentitiesnoconv(
"Country" . $obj->code_iso) !=
"Country" . $obj->code_iso ? $langs->transnoentitiesnoconv(
"Country" . $obj->code_iso) : ($obj->label !=
'-' ? $obj->label :
''));
982 $countryArray[$i][
'favorite'] = $obj->favorite;
983 $countryArray[$i][
'eec'] = $obj->eec;
984 $favorite[$i] = $obj->favorite;
989 if (empty($disablefavorites)) {
990 $array1_sort_order = SORT_DESC;
991 $array2_sort_order = SORT_ASC;
992 array_multisort($favorite, $array1_sort_order, $label, $array2_sort_order, $countryArray);
998 if (is_numeric($showempty)) {
999 $out .=
'<option value=""> </option>' .
"\n";
1001 $out .=
'<option value="-1">' . $langs->trans($showempty) .
'</option>' .
"\n";
1005 if ($addspecialentries) {
1007 $out .=
'<option value="special_allnotme"' . ($selected ==
'special_allnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesExceptMe", $langs->transnoentitiesnoconv(
"Country" . $mysoc->country_code)) .
'</option>';
1008 $out .=
'<option value="special_eec"' . ($selected ==
'special_eec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEEC") .
'</option>';
1009 if ($mysoc->isInEEC()) {
1010 $out .=
'<option value="special_eecnotme"' . ($selected ==
'special_eecnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEECExceptMe", $langs->transnoentitiesnoconv(
"Country" . $mysoc->country_code)) .
'</option>';
1012 $out .=
'<option value="special_noteec"' . ($selected ==
'special_noteec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesNotInEEC") .
'</option>';
1013 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1016 foreach ($countryArray as $row) {
1018 if (empty($row[
'rowid'])) {
1021 if (is_array($exclude_country_code) && count($exclude_country_code) && in_array($row[
'code_iso'], $exclude_country_code)) {
1025 if (empty($disablefavorites) && $row[
'favorite'] && $row[
'code_iso']) {
1026 $atleastonefavorite++;
1028 if (empty($row[
'favorite']) && $atleastonefavorite) {
1029 $atleastonefavorite = 0;
1030 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1034 if ($row[
'label']) {
1035 $labeltoshow .=
dol_trunc($row[
'label'], $maxlength,
'middle');
1037 $labeltoshow .=
' ';
1039 if ($row[
'code_iso']) {
1040 $labeltoshow .=
' <span class="opacitymedium">(' . $row[
'code_iso'] .
')</span>';
1041 if (empty($hideflags)) {
1042 $tmpflag =
picto_from_langcode($row[
'code_iso'],
'class="saturatemedium paddingrightonly"', 1);
1043 $labeltoshow = $tmpflag .
' ' . $labeltoshow;
1047 if ($selected && $selected !=
'-1' && ($selected == $row[
'rowid'] || $selected == $row[
'code_iso'] || $selected == $row[
'code_iso3'] || $selected == $row[
'label'])) {
1048 $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']) .
'">';
1050 $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']) .
'">';
1053 $out .=
'</option>' .
"\n";
1056 $out .=
'</select>';
1062 if (empty($forcecombo)) {
1063 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1064 $out .=
ajax_combobox(
'select' . $htmlname, array(), 0, 0,
'resolve');
1085 public function select_incoterms($selected =
'', $location_incoterms =
'', $page =
'', $htmlname =
'incoterm_id', $htmloption =
'', $forcecombo = 1, $events = array(), $disableautocomplete = 0)
1088 global
$conf, $langs;
1090 $langs->load(
"dict");
1094 $incotermArray = array();
1096 $sql =
"SELECT rowid, code";
1097 $sql .=
" FROM " . $this->db->prefix() .
"c_incoterms";
1098 $sql .=
" WHERE active > 0";
1099 $sql .=
" ORDER BY code ASC";
1101 dol_syslog(get_class($this) .
"::select_incoterm", LOG_DEBUG);
1102 $resql = $this->db->query($sql);
1104 if (
$conf->use_javascript_ajax && !$forcecombo) {
1105 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1109 if (!empty($page)) {
1110 $out .=
'<form method="post" action="' . $page .
'">';
1111 $out .=
'<input type="hidden" name="action" value="set_incoterms">';
1112 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
1115 $out .=
'<select id="' . $htmlname .
'" class="flat selectincoterm width75" name="' . $htmlname .
'" ' . $htmloption .
'>';
1116 $out .=
'<option value="0"> </option>';
1117 $num = $this->db->num_rows($resql);
1121 $obj = $this->db->fetch_object($resql);
1122 $incotermArray[$i][
'rowid'] = $obj->rowid;
1123 $incotermArray[$i][
'code'] = $obj->code;
1127 foreach ($incotermArray as $row) {
1128 if ($selected && ($selected == $row[
'rowid'] || $selected == $row[
'code'])) {
1129 $out .=
'<option value="' . $row[
'rowid'] .
'" selected>';
1131 $out .=
'<option value="' . $row[
'rowid'] .
'">';
1135 $out .= $row[
'code'];
1138 $out .=
'</option>';
1141 $out .=
'</select>';
1144 if (
$conf->use_javascript_ajax && empty($disableautocomplete)) {
1145 $out .=
ajax_multiautocompleter(
'location_incoterms', array(), DOL_URL_ROOT .
'/core/ajax/locationincoterms.php') .
"\n";
1148 $out .=
'<input id="location_incoterms" class="maxwidthonsmartphone heightofcombo" type="text" name="location_incoterms" value="' . $location_incoterms .
'">' .
"\n";
1150 if (!empty($page)) {
1151 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp nomargintop nomarginbottom" value="' . $langs->trans(
"Modify") .
'"></form>';
1175 public function select_type_of_lines($selected =
'', $htmlname =
'type', $showempty = 0, $hidetext = 0, $forceall = 0, $morecss =
"", $useajaxcombo = 1)
1181 if ($forceall == 1 || (empty($forceall) && isModEnabled(
"product") && isModEnabled(
"service"))
1182 || (empty($forceall) && !isModEnabled(
'product') && !isModEnabled(
'service'))) {
1183 if (empty($hidetext)) {
1184 print $langs->trans(
"Type").
'...';
1186 print
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
1188 print
'<option value="-1" class="opacitymedium"'.($useajaxcombo ?
'' :
' disabled="disabled"');
1189 if ($selected == -1) {
1193 if (is_numeric($showempty)) {
1201 print
'<option value="0"';
1202 if (0 == $selected || ($selected == -1 &&
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') ==
'product')) {
1205 print
'>' . $langs->trans(
"Product");
1207 print
'<option value="1"';
1208 if (1 == $selected || ($selected == -1 &&
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') ==
'service')) {
1211 print
'>' . $langs->trans(
"Service");
1215 if ($useajaxcombo) {
1220 if ((empty($forceall) && !isModEnabled(
'product') && isModEnabled(
"service")) || $forceall == 3) {
1221 print $langs->trans(
"Service");
1222 print
'<input type="hidden" name="' . $htmlname .
'" value="1">';
1224 if ((empty($forceall) && isModEnabled(
"product") && !isModEnabled(
'service')) || $forceall == 2) {
1225 print $langs->trans(
"Product");
1226 print
'<input type="hidden" name="' . $htmlname .
'" value="0">';
1228 if ($forceall < 0) {
1229 print
'<input type="hidden" name="' . $htmlname .
'" value="1">';
1245 $num = count($this->cache_types_fees);
1252 $langs->load(
"trips");
1254 $sql =
"SELECT c.code, c.label";
1255 $sql .=
" FROM " . $this->db->prefix() .
"c_type_fees as c";
1256 $sql .=
" WHERE active > 0";
1258 $resql = $this->db->query($sql);
1260 $num = $this->db->num_rows($resql);
1264 $obj = $this->db->fetch_object($resql);
1267 $label = ($obj->code != $langs->trans($obj->code) ? $langs->trans($obj->code) : $langs->trans($obj->label));
1268 $this->cache_types_fees[$obj->code] = $label;
1272 asort($this->cache_types_fees);
1294 global $user, $langs;
1296 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
1300 print
'<select id="select_' . $htmlname .
'" class="flat" name="' . $htmlname .
'">';
1302 print
'<option value="-1"';
1303 if ($selected == -1) {
1306 print
'> </option>';
1309 foreach ($this->cache_types_fees as $key => $value) {
1310 print
'<option value="' . $key .
'"';
1311 if ($key == $selected) {
1321 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1350 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)
1353 global
$conf, $langs;
1357 if (!empty(
$conf->use_javascript_ajax) &&
getDolGlobalString(
'COMPANY_USE_SEARCH_TO_SELECT') && !$forcecombo) {
1358 if (is_null($ajaxoptions)) {
1359 $ajaxoptions = array();
1362 require_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1366 if ($selected && empty($selected_input_value)) {
1367 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
1368 $societetmp =
new Societe($this->db);
1369 $societetmp->fetch($selected);
1370 $selected_input_value = $societetmp->name;
1375 $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)) :
'');
1377 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
1378 if (empty($hidelabel)) {
1379 $out .= $langs->trans(
"RefOrLabel") .
' : ';
1380 } elseif ($hidelabel == 1 && !is_numeric($showempty)) {
1381 $placeholder = $langs->trans($showempty);
1382 } elseif ($hidelabel > 1) {
1383 $placeholder = $langs->trans(
"RefOrLabel");
1384 if ($hidelabel == 2) {
1385 $out .=
img_picto($langs->trans(
"Search"),
'search');
1388 $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' :
'') .
' />';
1389 if ($hidelabel == 3) {
1390 $out .=
img_picto($langs->trans(
"Search"),
'search');
1395 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.
'/societe/ajax/company.php', $urloption,
getDolGlobalInt(
'COMPANY_USE_SEARCH_TO_SELECT'), 0, $ajaxoptions);
1398 $out .= $this->
select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events,
'', 0, $limit, $morecss, $moreparam, $multiple, $excludeids, $showcode);
1432 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 =
'')
1436 global
$conf, $langs;
1441 if ($nokeyifsocid && $socid > 0) {
1442 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = 0;
1445 if (!empty(
$conf->use_javascript_ajax) &&
getDolGlobalString(
'CONTACT_USE_SEARCH_TO_SELECT') && !$forcecombo) {
1446 if (is_null($events)) {
1450 require_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1454 if ($selected && empty($selected_input_value)) {
1455 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
1456 $contacttmp =
new Contact($this->db);
1457 $contacttmp->fetch($selected);
1458 $selected_input_value = $contacttmp->getFullName($langs);
1461 if (!is_numeric($showempty)) {
1462 $placeholder = $showempty;
1466 $urloption =
'htmlname=' . urlencode((
string) (str_replace(
'.',
'_', $htmlname))) .
'&outjson=1&filter=' . urlencode((
string) ($filter)) . (empty($exclude) ?
'' :
'&exclude=' . urlencode($exclude)) . ($showsoc ?
'&showsoc=' . urlencode((
string) ($showsoc)) :
'');
1468 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
1470 $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' :
'') .
' />';
1474 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.
'/contact/ajax/contact.php', $urloption,
getDolGlobalInt(
'CONTACT_USE_SEARCH_TO_SELECT'), 0, $events);
1478 $disableifempty = 0;
1482 $out .= $this->
selectcontacts($socid, $selected, $htmlname, $showempty, $exclude, $limitto, $showfunction, $morecss, $options_only, $showsoc, $forcecombo, $events, $moreparam, $htmlid, $multiple, $disableifempty);
1485 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = $sav;
1517 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)
1520 global $user, $langs;
1521 global $hookmanager;
1523 $langs->loadLangs(array(
"companies",
"suppliers"));
1527 $outarray = array();
1529 if ($selected ===
'') {
1530 $selected = array();
1531 } elseif (!is_array($selected)) {
1532 $selected = array($selected);
1536 if (function_exists(
'testSqlAndScriptInject')) {
1539 return 'SQLInjectionTryDetected';
1543 if ($filter !=
'') {
1544 if (preg_match(
'/[\(\)]/', $filter)) {
1550 if (function_exists(
'testSqlAndScriptInject')) {
1553 return 'SQLInjectionTryDetected';
1559 dol_syslog(
"Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Syntax.", LOG_WARNING);
1564 $sql =
"SELECT s.rowid, s.nom as name, s.name_alias, s.tva_intra, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
1566 $sql .=
", s.address, s.zip, s.town";
1567 $sql .=
", dictp.code as country_code";
1569 $sql .=
" FROM " . $this->db->prefix() .
"societe as s";
1571 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_country as dictp ON dictp.rowid = s.fk_pays";
1573 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1574 $sql .=
", " . $this->db->prefix() .
"societe_commerciaux as sc";
1576 $sql .=
" WHERE s.entity IN (" .
getEntity(
'societe') .
")";
1577 if (!empty($user->socid)) {
1578 $sql .=
" AND s.rowid = " . ((int) $user->socid);
1583 $sql .=
" AND (" . $filter .
")";
1585 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1586 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = " . ((int) $user->id);
1589 $sql .=
" AND s.status <> 0";
1591 if (!empty($excludeids)) {
1592 $sql .=
" AND s.rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeids)) .
")";
1595 $parameters = array();
1596 $reshook = $hookmanager->executeHooks(
'selectThirdpartyListWhere', $parameters);
1597 $sql .= $hookmanager->resPrint;
1599 if ($filterkey && $filterkey !=
'') {
1603 $search_crit = explode(
' ', $filterkey);
1605 if (count($search_crit) > 1) {
1608 foreach ($search_crit as $crit) {
1612 $sql .=
"(s.nom LIKE '" . $this->db->escape($prefix . $crit) .
"%')";
1615 if (count($search_crit) > 1) {
1618 if (isModEnabled(
'barcode')) {
1619 $sql .=
" OR s.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1621 $sql .=
" OR s.code_client LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.code_fournisseur LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1622 $sql .=
" OR s.name_alias LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.tva_intra LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1625 $sql .= $this->db->order(
"nom",
"ASC");
1626 $sql .= $this->db->plimit($limit, 0);
1629 dol_syslog(get_class($this).
"::select_thirdparty_list", LOG_DEBUG);
1630 $resql = $this->db->query($sql);
1633 $out .=
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
' name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
'>' .
"\n";
1635 $textifempty = (($showempty && !is_numeric($showempty)) ? $langs->trans($showempty) :
'');
1639 if ($showempty && !is_numeric($showempty)) {
1640 $textifempty = $langs->trans($showempty);
1642 $textifempty .= $langs->trans(
"All");
1646 $out .=
'<option value="-1" data-html="' .
dol_escape_htmltag(
'<span class="opacitymedium">' . ($textifempty ? $textifempty :
' ') .
'</span>') .
'">' . $textifempty .
'</option>' .
"\n";
1649 $companytemp =
new Societe($this->db);
1651 $num = $this->db->num_rows($resql);
1655 $obj = $this->db->fetch_object($resql);
1658 if (($obj->client) && (!empty($obj->code_client))) {
1659 $label = $obj->code_client .
' - ';
1661 if (($obj->fournisseur) && (!empty($obj->code_fournisseur))) {
1662 $label .= $obj->code_fournisseur .
' - ';
1664 $label .=
' ' . $obj->name;
1666 $label = $obj->name;
1669 if (!empty($obj->name_alias)) {
1670 $label .=
' (' . $obj->name_alias .
')';
1674 $label .=
' - '.$obj->tva_intra;
1677 $labelhtml = $label;
1680 $companytemp->id = $obj->rowid;
1681 $companytemp->client = $obj->client;
1682 $companytemp->fournisseur = $obj->fournisseur;
1683 $tmptype = $companytemp->getTypeUrl(1,
'', 0,
'span');
1685 $labelhtml .=
' ' . $tmptype;
1688 if ($obj->client || $obj->fournisseur) {
1691 if ($obj->client == 1 || $obj->client == 3) {
1692 $label .= $langs->trans(
"Customer");
1694 if ($obj->client == 2 || $obj->client == 3) {
1695 $label .= ($obj->client == 3 ?
', ' :
'') . $langs->trans(
"Prospect");
1697 if ($obj->fournisseur) {
1698 $label .= ($obj->client ?
', ' :
'') . $langs->trans(
"Supplier");
1700 if ($obj->client || $obj->fournisseur) {
1706 $s = ($obj->address ?
' - ' . $obj->address :
'') . ($obj->zip ?
' - ' . $obj->zip :
'') . ($obj->town ?
' ' . $obj->town :
'');
1707 if (!empty($obj->country_code)) {
1708 $s .=
', ' . $langs->trans(
'Country' . $obj->country_code);
1714 if (empty($outputmode)) {
1715 if (in_array($obj->rowid, $selected)) {
1716 $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>';
1718 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
1721 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label,
'labelhtml' => $labelhtml));
1725 if (($i % 10) == 0) {
1730 $out .=
'</select>' .
"\n";
1732 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1739 $this->result = array(
'nbofthirdparties' => $num);
1773 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 =
'')
1775 global
$conf, $user, $langs, $hookmanager, $action;
1777 $langs->load(
'companies');
1779 if (empty($htmlid)) {
1780 $htmlid = $htmlname;
1784 $outarray = array();
1786 if ($selected ===
'') {
1787 $selected = array();
1788 } elseif (!is_array($selected)) {
1789 $selected = array((
int) $selected);
1793 if (function_exists(
'testSqlAndScriptInject')) {
1796 return 'SQLInjectionTryDetected';
1800 if ($filter !=
'') {
1801 if (preg_match(
'/[\(\)]/', $filter)) {
1807 if (function_exists(
'testSqlAndScriptInject')) {
1810 return 'SQLInjectionTryDetected';
1816 dol_syslog(
"Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Filter Syntax.", LOG_WARNING);
1820 if (!is_object($hookmanager)) {
1821 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
1826 $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";
1827 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
1828 $sql .=
", s.nom as company, s.town AS company_town";
1830 $sql .=
" FROM " . $this->db->prefix() .
"socpeople as sp";
1831 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
1832 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON s.rowid = sp.fk_soc";
1834 $sql .=
" WHERE sp.entity IN (" .
getEntity(
'contact') .
")";
1835 $sql .=
" AND ((sp.fk_user_creat = ".((int) $user->id).
" AND sp.priv = 1) OR sp.priv = 0)";
1836 if ($socid > 0 || $socid == -1) {
1837 $sql .=
" AND sp.fk_soc = " . ((int) $socid);
1840 $sql .=
" AND sp.statut <> 0";
1843 if (!$user->hasRight(
'societe',
'client',
'voir') && !$user->socid) {
1844 $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 .
")";
1846 if ($user->socid > 0) {
1847 $sql .=
" AND sp.fk_soc = ".((int) $user->socid);
1852 $sql .=
" AND (" . $filter .
")";
1855 $parameters = array();
1856 $reshook = $hookmanager->executeHooks(
'selectContactListWhere', $parameters);
1857 $sql .= $hookmanager->resPrint;
1858 $sql .=
" ORDER BY sp.lastname ASC";
1860 dol_syslog(get_class($this) .
"::selectcontacts", LOG_DEBUG);
1861 $resql = $this->db->query($sql);
1863 $num = $this->db->num_rows($resql);
1865 if ($htmlname !=
'none' && !$options_only) {
1866 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlid .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . (($num || empty($disableifempty)) ?
'' :
' disabled') . ($multiple ?
'multiple' :
'') .
' ' . (!empty($moreparam) ? $moreparam :
'') .
'>';
1869 if ($showempty && !is_numeric($showempty)) {
1870 $textforempty = $showempty;
1871 $out .=
'<option class="optiongrey" value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'>' . $textforempty .
'</option>';
1873 if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) {
1874 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'> </option>';
1876 if ($showempty == 2) {
1877 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Internal") .
' --</option>';
1883 include_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
1884 $contactstatic =
new Contact($this->db);
1887 $obj = $this->db->fetch_object($resql);
1890 $extendedInfos =
'';
1892 $extendedInfos = array();
1893 $email = trim($obj->email);
1894 if (!empty($email)) {
1895 $extendedInfos[] = $email;
1897 $phone = trim($obj->phone);
1898 $phone_perso = trim($obj->phone_perso);
1899 $phone_mobile = trim($obj->phone_mobile);
1900 if (!empty($phone)) {
1901 $extendedInfos[] = $phone;
1903 if (!empty($phone_perso)) {
1904 $extendedInfos[] = $phone_perso;
1906 if (!empty($phone_mobile)) {
1907 $extendedInfos[] = $phone_mobile;
1910 $contact_town = trim($obj->contact_town);
1911 $company_town = trim($obj->company_town);
1912 if (!empty($contact_town)) {
1913 $extendedInfos[] = $contact_town;
1914 } elseif (!empty($company_town)) {
1915 $extendedInfos[] = $company_town;
1917 $extendedInfos = implode(
' - ', $extendedInfos);
1918 if (!empty($extendedInfos)) {
1919 $extendedInfos =
' - ' . $extendedInfos;
1923 $contactstatic->id = $obj->rowid;
1924 $contactstatic->lastname = $obj->lastname;
1925 $contactstatic->firstname = $obj->firstname;
1926 if ($obj->statut == 1) {
1928 if ($htmlname !=
'none') {
1930 if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) {
1933 if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) {
1936 if (!empty($selected) && in_array($obj->rowid, $selected)) {
1937 $out .=
'<option value="' . $obj->rowid .
'"';
1939 $out .=
' disabled';
1941 $out .=
' selected>';
1943 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1944 if ($showfunction && $obj->poste) {
1945 $tmplabel .=
' (' . $obj->poste .
')';
1947 if (($showsoc > 0) && $obj->company) {
1948 $tmplabel .=
' - (' . $obj->company .
')';
1952 $out .=
'</option>';
1954 $out .=
'<option value="' . $obj->rowid .
'"';
1956 $out .=
' disabled';
1960 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1961 if ($showfunction && $obj->poste) {
1962 $tmplabel .=
' (' . $obj->poste .
')';
1964 if (($showsoc > 0) && $obj->company) {
1965 $tmplabel .=
' - (' . $obj->company .
')';
1969 $out .=
'</option>';
1972 if (in_array($obj->rowid, $selected)) {
1973 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1974 if ($showfunction && $obj->poste) {
1975 $tmplabel .=
' (' . $obj->poste .
')';
1977 if (($showsoc > 0) && $obj->company) {
1978 $tmplabel .=
' - (' . $obj->company .
')';
1985 if ($tmplabel !=
'') {
1986 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $tmplabel,
'label' => $tmplabel,
'labelhtml' => $tmplabel));
1992 $labeltoshow = ($socid != -1) ? ($langs->trans($socid ?
"NoContactDefinedForThirdParty" :
"NoContactDefined")) : $langs->trans(
'SelectAThirdPartyFirst');
1993 $out .=
'<option class="disabled" value="-1"' . (($showempty == 2 || $multiple) ?
'' :
' selected') .
' disabled="disabled">';
1994 $out .= $labeltoshow;
1995 $out .=
'</option>';
1998 $parameters = array(
2000 'htmlname' => $htmlname,
2003 'showfunction' => $showfunction,
2004 'showsoc' => $showsoc,
2007 $reshook = $hookmanager->executeHooks(
'afterSelectContactOptions', $parameters, $this, $action);
2009 if ($htmlname !=
'none' && !$options_only) {
2010 $out .=
'</select>';
2013 if (
$conf->use_javascript_ajax && !$forcecombo && !$options_only) {
2014 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2020 if ($options_only === 2) {
2048 global $langs,
$conf;
2051 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
2052 $sql .=
" re.description, re.fk_facture_source";
2053 $sql .=
" FROM " . $this->db->prefix() .
"societe_remise_except as re";
2054 $sql .=
" WHERE re.fk_soc = " . (int) $socid;
2055 $sql .=
" AND re.entity = " .
$conf->entity;
2057 $sql .=
" AND " . $filter;
2059 $sql .=
" ORDER BY re.description ASC";
2061 dol_syslog(get_class($this) .
"::select_remises", LOG_DEBUG);
2062 $resql = $this->db->query($sql);
2064 print
'<select id="select_' . $htmlname .
'" class="flat maxwidthonsmartphone" name="' . $htmlname .
'">';
2065 $num = $this->db->num_rows($resql);
2067 $qualifiedlines = $num;
2071 print
'<option value="0"> </option>';
2073 $obj = $this->db->fetch_object($resql);
2074 $desc =
dol_trunc($obj->description, 40);
2075 if (preg_match(
'/\(CREDIT_NOTE\)/', $desc)) {
2076 $desc = preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $desc);
2078 if (preg_match(
'/\(DEPOSIT\)/', $desc)) {
2079 $desc = preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"Deposit"), $desc);
2081 if (preg_match(
'/\(EXCESS RECEIVED\)/', $desc)) {
2082 $desc = preg_replace(
'/\(EXCESS RECEIVED\)/', $langs->trans(
"ExcessReceived"), $desc);
2084 if (preg_match(
'/\(EXCESS PAID\)/', $desc)) {
2085 $desc = preg_replace(
'/\(EXCESS PAID\)/', $langs->trans(
"ExcessPaid"), $desc);
2089 if ($selected > 0 && $selected == $obj->rowid) {
2090 $selectstring =
' selected';
2094 if ($maxvalue > 0 && $obj->amount_ttc > $maxvalue) {
2096 $disabled =
' disabled';
2099 if (
getDolGlobalString(
'MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST') && !empty($obj->fk_facture_source)) {
2100 $tmpfac =
new Facture($this->db);
2101 if ($tmpfac->fetch($obj->fk_facture_source) > 0) {
2102 $desc = $desc .
' - ' . $tmpfac->ref;
2106 print
'<option value="' . $obj->rowid .
'"' . $selectstring . $disabled .
'>' . $desc .
' (' .
price($obj->amount_ht) .
' ' . $langs->trans(
"HT") .
' - ' .
price($obj->amount_ttc) .
' ' . $langs->trans(
"TTC") .
')</option>';
2113 return $qualifiedlines;
2138 public function select_users($selected =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include =
'', $enableonly = array(), $force_entity =
'0')
2141 print $this->
select_dolusers($selected, $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity);
2170 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)
2173 global
$conf, $user, $langs, $hookmanager;
2177 if ((is_numeric($selected) && ($selected < -3 || empty($selected))) && !
getDolGlobalString(
'SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE')) {
2178 $selected = $user->id;
2181 if ($selected ===
'') {
2182 $selected = array();
2183 } elseif (!is_array($selected)) {
2184 $selected = array($selected);
2188 $excludeUsers =
null;
2189 if (is_array($exclude)) {
2190 $excludeUsers = implode(
",", $exclude);
2194 $includeUsers =
null;
2195 $includeUsersArray = array();
2196 if (is_array($include)) {
2197 $includeUsersArray = $include;
2198 } elseif ($include ==
'hierarchy') {
2200 $includeUsersArray = $user->getAllChildIds(0);
2201 } elseif ($include ==
'hierarchyme') {
2203 $includeUsersArray = $user->getAllChildIds(1);
2218 $includeUsers = implode(
",", $includeUsersArray);
2223 $outarray = array();
2224 $outarray2 = array();
2227 $showlabelofentity = isModEnabled(
'multicompany') && !
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE') &&
$conf->entity == 1 && !empty($user->admin) && empty($user->entity) && !preg_match(
'/^search_/', $htmlname);
2228 $userissuperadminentityone = isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && empty($user->entity);
2231 $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";
2232 if ($showlabelofentity) {
2233 $sql .=
", e.label";
2235 $sql .=
" FROM " . $this->db->prefix() .
"user as u";
2236 if ($showlabelofentity) {
2237 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid = u.entity";
2240 if ($userissuperadminentityone && $force_entity !==
'default') {
2241 if (!empty($force_entity)) {
2242 $sql .=
" WHERE u.entity IN (0, " . $this->db->sanitize($force_entity) .
")";
2244 $sql .=
" WHERE u.entity IS NOT NULL";
2247 if (isModEnabled(
'multicompany') &&
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE')) {
2248 $sql .=
" WHERE u.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
2250 $sql .=
" WHERE u.entity IN (" .
getEntity(
'user') .
")";
2254 if (!empty($user->socid)) {
2255 $sql .=
" AND u.fk_soc = " . ((int) $user->socid);
2257 if (is_array($exclude) && $excludeUsers) {
2258 $sql .=
" AND u.rowid NOT IN (" . $this->db->sanitize($excludeUsers) .
")";
2260 if ($includeUsers) {
2261 $sql .=
" AND u.rowid IN (" . $this->db->sanitize($includeUsers) .
")";
2264 $sql .=
" AND u.statut <> 0";
2267 $sql .=
" AND u.employee <> 0";
2270 $sql .=
" AND u.fk_soc IS NULL";
2272 if (!empty($morefilter)) {
2275 if ($errormessage) {
2276 $this->errors[] = $errormessage;
2277 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2278 if ($outputmode == 0) {
2279 return 'Error bad param $morefilter';
2287 $reshook = $hookmanager->executeHooks(
'addSQLWhereFilterOnSelectUsers', array(), $this, $action);
2288 if (!empty($reshook)) {
2289 $sql .= $hookmanager->resPrint;
2293 $sql .=
" ORDER BY u.statut DESC, u.firstname ASC, u.lastname ASC";
2295 $sql .=
" ORDER BY u.statut DESC, u.lastname ASC, u.firstname ASC";
2298 dol_syslog(get_class($this) .
"::select_dolusers", LOG_DEBUG);
2300 $resql = $this->db->query($sql);
2302 $num = $this->db->num_rows($resql);
2306 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
' minwidth200') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
2307 if ($show_empty && !$multiple) {
2308 $textforempty =
' ';
2309 if (!empty(
$conf->use_javascript_ajax)) {
2310 $textforempty =
' ';
2312 if (!is_numeric($show_empty)) {
2313 $textforempty = $show_empty;
2315 $out .=
'<option class="optiongrey" value="' . ($show_empty < 0 ? $show_empty : -1) .
'"' . ((empty($selected) || in_array(-1, $selected)) ?
' selected' :
'') .
'>' . $textforempty .
'</option>' .
"\n";
2317 $outarray[($show_empty < 0 ? $show_empty : -1)] = $textforempty;
2318 $outarray2[($show_empty < 0 ? $show_empty : -1)] = array(
2319 'id' => ($show_empty < 0 ? $show_empty : -1),
2320 'label' => $textforempty,
2321 'labelhtml' => $textforempty,
2326 if ($showalso == 2 || $showalso == 3) {
2327 $out .=
'<option value="-3"' . ((in_array(-3, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"MyTeam") .
' --</option>' .
"\n";
2329 $hasAtLeastOneSubordinate = (count($user->getAllChildIds(1)) > 1);
2330 if ($hasAtLeastOneSubordinate) {
2332 $outarray[-3] =
'-- ' . $langs->trans(
"MyTeam") .
' --';
2333 $outarray2[-3] = array(
2335 'label' =>
'-- ' . $langs->trans(
"MyTeam") .
' --',
2336 'labelhtml' =>
'-- ' . $langs->trans(
"MyTeam") .
' --',
2342 if ($showalso == 1 || $showalso == 3) {
2343 $out .=
'<option value="-2"' . ((in_array(-2, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Everybody") .
' --</option>' .
"\n";
2345 $outarray[-2] =
'-- ' . $langs->trans(
"Everybody") .
' --';
2346 $outarray2[-2] = array(
2348 'label' =>
'-- ' . $langs->trans(
"Everybody") .
' --',
2349 'labelhtml' =>
'-- ' . $langs->trans(
"Everybody") .
' --',
2355 $userstatic =
new User($this->db);
2358 $obj = $this->db->fetch_object($resql);
2360 $userstatic->id = $obj->rowid;
2361 $userstatic->lastname = $obj->lastname;
2362 $userstatic->firstname = $obj->firstname;
2363 $userstatic->photo = $obj->photo;
2364 $userstatic->status = $obj->status;
2365 $userstatic->entity = $obj->entity;
2366 $userstatic->admin = $obj->admin;
2367 $userstatic->gender = $obj->gender;
2370 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
2371 $disableline = ($enableonlytext ? $enableonlytext :
'1');
2375 $labeltoshowhtml =
'';
2382 $labeltoshow .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2383 $labeltoshowhtml .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2384 if (empty($obj->firstname) && empty($obj->lastname)) {
2385 $labeltoshow .= $obj->login;
2386 $labeltoshowhtml .= $obj->login;
2393 $moreinfo .= ($moreinfo ?
' - ' :
' (');
2394 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(');
2395 $moreinfo .= $obj->login;
2396 $moreinfohtml .= $obj->login;
2398 if ($showstatus >= 0) {
2399 if ($obj->status == 1 && $showstatus == 1) {
2400 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Enabled');
2401 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Enabled');
2403 if ($obj->status == 0 && $showstatus == 1) {
2404 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Disabled');
2405 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Disabled');
2408 if ($showlabelofentity) {
2409 if (empty($obj->entity)) {
2410 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
"AllEntities");
2411 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
"AllEntities");
2413 if ($obj->entity !=
$conf->entity) {
2414 $moreinfo .= ($moreinfo ?
' - ' :
' (') . ($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2415 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(').($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2419 $moreinfo .= (!empty($moreinfo) ?
')' :
'');
2420 $moreinfohtml .= (!empty($moreinfohtml) ?
')</span>' :
'');
2421 if (!empty($disableline) && $disableline !=
'1') {
2423 $moreinfo .=
' - ' . $disableline;
2424 $moreinfohtml .=
' - ' . $disableline;
2426 $labeltoshow .= $moreinfo;
2427 $labeltoshowhtml .= $moreinfohtml;
2429 $out .=
'<option value="' . $obj->rowid .
'"';
2430 if (!empty($disableline)) {
2431 $out .=
' disabled';
2433 if ((!empty($selected[0]) && is_object($selected[0])) ? $selected[0]->id == $obj->rowid : in_array($obj->rowid, $selected)) {
2434 $out .=
' selected';
2436 $out .=
' data-html="';
2438 $outhtml = $userstatic->getNomUrl(-3,
'', 0, 1, 24, 1,
'login',
'', 1) .
' ';
2439 if ($showstatus >= 0 && $obj->status == 0) {
2440 $outhtml .=
'<strike class="opacitymediumxxx">';
2442 $outhtml .= $labeltoshowhtml;
2443 if ($showstatus >= 0 && $obj->status == 0) {
2444 $outhtml .=
'</strike>';
2446 $labeltoshowhtml = $outhtml;
2450 $out .= $labeltoshow;
2451 $out .=
'</option>';
2453 $outarray[$userstatic->id] = $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength) . $moreinfo;
2454 $outarray2[$userstatic->id] = array(
2455 'id' => $userstatic->id,
2456 'label' => $labeltoshow,
2457 'labelhtml' => $labeltoshowhtml,
2465 $out .=
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'" disabled>';
2466 $out .=
'<option value="">' . $langs->trans(
"None") .
'</option>';
2468 $out .=
'</select>';
2470 if ($num && !$forcecombo) {
2472 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2481 if ($outputmode == 2) {
2483 } elseif ($outputmode) {
2515 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)
2518 global $langs, $user;
2520 $userstatic =
new User($this->db);
2523 if (!empty($_SESSION[
'assignedtouser'])) {
2524 $assignedtouser = json_decode($_SESSION[
'assignedtouser'],
true);
2525 if (!is_array($assignedtouser)) {
2526 $assignedtouser = array();
2529 $assignedtouser = array();
2531 $nbassignetouser = count($assignedtouser);
2534 if ($nbassignetouser) {
2535 $out .=
'<ul class="attendees">';
2539 foreach ($assignedtouser as $key => $value) {
2540 if ($value[
'id'] == $ownerid) {
2545 $userstatic->fetch($value[
'id']);
2546 $out .= $userstatic->getNomUrl(-1);
2548 $ownerid = $value[
'id'];
2549 $out .=
' (' . $langs->trans(
"Owner") .
')';
2552 if ($nbassignetouser > 1 && $action !=
'view') {
2553 $canremoveassignee = 1;
2556 if (!$canremoveowner) {
2557 $canremoveassignee = 0;
2559 if (!$user->hasRight(
'agenda',
'allactions',
'create')) {
2560 $canremoveassignee = 0;
2565 if ($canremoveassignee) {
2568 $out .=
' <input type="image" style="border: 0px;" src="' .
img_picto($langs->trans(
"Remove"),
'delete',
'', 0, 1) .
'" value="' . $userstatic->id .
'" class="removedassigned reposition" id="removedassigned_' . $userstatic->id .
'" name="removedassigned_' . $userstatic->id .
'">';
2572 if ($showproperties) {
2573 if ($ownerid == $value[
'id'] && is_array($listofuserid) && count($listofuserid) && in_array($ownerid, array_keys($listofuserid))) {
2574 $out .=
'<div class="myavailability inline-block">';
2575 $out .=
'<span class="hideonsmartphone"> - ';
2578 $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>';
2588 if ($nbassignetouser) {
2593 if ($action !=
'view') {
2594 $out .=
'<input type="hidden" class="removedassignedhidden" name="removedassigned" value="">';
2595 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
2596 $out .=
'jQuery(".removedassigned").click(function() { jQuery(".removedassignedhidden").val(jQuery(this).val()); });';
2597 $out .=
'jQuery(".assignedtouser").change(function() { console.log(jQuery(".assignedtouser option:selected").val());';
2598 $out .=
' if (jQuery(".assignedtouser option:selected").val() > 0) { jQuery("#' . $action .
'assignedtouser").attr("disabled", false); }';
2599 $out .=
' else { jQuery("#' . $action .
'assignedtouser").attr("disabled", true); }';
2601 $out .=
'})</script>';
2602 $out .= $this->
select_dolusers(
'', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter);
2603 $out .=
' <input type="submit" disabled class="button valignmiddle smallpaddingimp reposition" id="' . $action .
'assignedtouser" name="' . $action .
'assignedtouser" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
2630 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())
2635 require_once DOL_DOCUMENT_ROOT.
'/resource/class/html.formresource.class.php';
2636 require_once DOL_DOCUMENT_ROOT.
'/resource/class/dolresource.class.php';
2641 if (!empty($_SESSION[
'assignedtoresource'])) {
2642 $assignedtoresource = json_decode($_SESSION[
'assignedtoresource'],
true);
2643 if (!is_array($assignedtoresource)) {
2644 $assignedtoresource = array();
2647 $assignedtoresource = array();
2649 $nbassignetoresource = count($assignedtoresource);
2652 if ($nbassignetoresource) {
2653 $out .=
'<ul class="attendees">';
2657 foreach ($assignedtoresource as $key => $value) {
2659 $resourcestatic->fetch($value[
'id']);
2660 $out .= $resourcestatic->getNomUrl(-1);
2661 if ($nbassignetoresource >= 1 && $action !=
'view') {
2662 $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 .
'">';
2665 if ($showproperties) {
2666 if (is_array($listofresourceid) && count($listofresourceid)) {
2667 $out .=
'<div class="myavailability inline-block">';
2668 $out .=
'<span class="hideonsmartphone"> - ';
2671 $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>';
2681 if ($nbassignetoresource) {
2686 if ($action !=
'view') {
2687 $out .=
'<input type="hidden" class="removedassignedresourcehidden" name="removedassignedresource" value="">';
2688 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
2689 $out .=
'jQuery(".removedassignedresource").click(function() { jQuery(".removedassignedresourcehidden").val(jQuery(this).val()); });';
2690 $out .=
'jQuery(".assignedtoresource").change(function() { console.log(jQuery(".assignedtoresource option:selected").val());';
2691 $out .=
' if (jQuery(".assignedtoresource option:selected").val() > 0) { jQuery("#' . $action .
'assignedtoresource").attr("disabled", false); }';
2692 $out .=
' else { jQuery("#' . $action .
'assignedtoresource").attr("disabled", true); }';
2694 $out .=
'})</script>';
2697 $out .=
img_picto(
'',
'resource',
'class="pictofixedwidth"');
2698 $out .= $formresources->select_resource_list(0, $htmlname,
'', 1, 1, 0, $events,
'', 2, 0);
2700 $out .=
' <input type="submit" disabled class="button valignmiddle smallpaddingimp reposition" id="' . $action .
'assignedtoresource" name="' . $action .
'assignedtoresource" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
2738 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)
2741 global $langs,
$conf;
2746 $price_level = (!empty($price_level) ? $price_level : 0);
2747 if (is_null($ajaxoptions)) {
2748 $ajaxoptions = array();
2751 if (strval($filtertype) ===
'' && (isModEnabled(
"product") || isModEnabled(
"service"))) {
2752 if (isModEnabled(
"product") && !isModEnabled(
'service')) {
2754 } elseif (!isModEnabled(
'product') && isModEnabled(
"service")) {
2760 $placeholder = (is_numeric($showempty) ?
'' :
'placeholder="'.dolPrintHTML($showempty).
'"');
2762 if ($selected && empty($selected_input_value)) {
2763 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
2764 $producttmpselect =
new Product($this->db);
2765 $producttmpselect->fetch($selected);
2766 $selected_input_value = $producttmpselect->ref;
2767 unset($producttmpselect);
2770 if ($filtertype ==
'') {
2771 if (!isModEnabled(
'product')) {
2773 } elseif (!isModEnabled(
'service')) {
2778 $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;
2779 if ((
int) $warehouseId > 0) {
2780 $urloption .=
'&warehouseid=' . (int) $warehouseId;
2783 if (isModEnabled(
'variants') && is_array($selected_combinations)) {
2789 <!-- script to auto show attributes select tags if a variant was selected -->
2790 <script nonce="' .
getNonce() .
'">
2791 // auto show attributes fields
2792 selected = ' . json_encode($selected_combinations) .
';
2795 jQuery(document).ready(function () {
2797 jQuery("input[name=\'prod_entry_mode\']").change(function () {
2798 if (jQuery(this).val() == \'free\') {
2799 jQuery(\'div#attributes_box\').empty();
2803 jQuery("'.$htmltag.
'#' . $htmlname .
'").change(function () {
2805 if (!jQuery(this).val()) {
2806 jQuery(\'div#attributes_box\').empty();
2810 console.log("A change has started. We get variants fields to inject html select");
2812 jQuery.getJSON("' . DOL_URL_ROOT .
'/variants/ajax/getCombinations.php", {
2813 id: jQuery(this).val()
2814 }, function (data) {
2815 jQuery(\'div#attributes_box\').empty();
2817 jQuery.each(data, function (key, val) {
2819 combvalues[val.id] = val.values;
2821 var span = jQuery(document.createElement(\'div\')).css({
2822 \'display\': \'table-row\'
2826 jQuery(document.createElement(\'div\')).text(val.label).css({
2827 \'font-weight\': \'bold\',
2828 \'display\': \'table-cell\'
2832 var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({
2833 \'margin-left\': \'15px\',
2834 \'white-space\': \'pre\'
2836 jQuery(document.createElement(\'option\')).val(\'\')
2839 jQuery.each(combvalues[val.id], function (key, val) {
2840 var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value);
2842 if (selected[val.fk_product_attribute] == val.id) {
2843 tag.attr(\'selected\', \'selected\');
2850 jQuery(\'div#attributes_box\').append(span);
2855 ' . ($selected ?
'jQuery("'.$htmltag.
'#' . $htmlname .
'").change();' :
'') .
'
2861 if (empty($hidelabel)) {
2863 } elseif ($hidelabel > 1) {
2865 if ($hidelabel == 2) {
2866 $out .=
img_picto($langs->trans(
"Search"),
'search');
2870 $out .=
'<input type="text" class="minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . $placeholder .
' ' . (
getDolGlobalString(
'PRODUCT_SEARCH_AUTOFOCUS') ?
'autofocus' :
'') .
' />';
2871 if ($hidelabel == 3) {
2872 $out .=
img_picto($langs->trans(
"Search"),
'search');
2875 $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);
2877 $out .= $this->
select_produits_list($selected, $htmlname, $filtertype, $limit, $price_level,
'', $status, $finished, 0, $socid, $showempty, $forcecombo, $morecss, $hidepriceinlabel, $warehouseStatus, $status_purchase, $warehouseId);
2879 if (isModEnabled(
'variants') && is_array($selected_combinations)) {
2883 $htmltag =
'select';
2885 <!-- script to auto show attributes select tags if a variant was selected -->
2886 <script nonce="' .
getNonce() .
'">
2887 // auto show attributes fields
2888 selected = ' . json_encode($selected_combinations) .
';
2891 jQuery(document).ready(function () {
2893 jQuery("input[name=\'prod_entry_mode\']").change(function () {
2894 if (jQuery(this).val() == \'free\') {
2895 jQuery(\'div#attributes_box\').empty();
2899 jQuery("'.$htmltag.
'#' . $htmlname .
'").change(function () {
2901 if (!jQuery(this).val()) {
2902 jQuery(\'div#attributes_box\').empty();
2906 console.log("A change has started. We get variants fields to inject html select");
2908 jQuery.getJSON("' . DOL_URL_ROOT .
'/variants/ajax/getCombinations.php", {
2909 id: jQuery(this).val()
2910 }, function (data) {
2911 jQuery(\'div#attributes_box\').empty();
2913 jQuery.each(data, function (key, val) {
2915 combvalues[val.id] = val.values;
2917 var span = jQuery(document.createElement(\'div\')).css({
2918 \'display\': \'table-row\'
2922 jQuery(document.createElement(\'div\')).text(val.label).css({
2923 \'font-weight\': \'bold\',
2924 \'display\': \'table-cell\'
2928 var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({
2929 \'margin-left\': \'15px\',
2930 \'white-space\': \'pre\'
2932 jQuery(document.createElement(\'option\')).val(\'\')
2935 jQuery.each(combvalues[val.id], function (key, val) {
2936 var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value);
2938 if (selected[val.fk_product_attribute] == val.id) {
2939 tag.attr(\'selected\', \'selected\');
2946 jQuery(\'div#attributes_box\').append(span);
2951 ' . ($selected ?
'jQuery("'.$htmltag.
'#' . $htmlname .
'").change();' :
'') .
'
2958 if (empty($nooutput)) {
2982 public function select_bom($selected =
'', $htmlname =
'bom_id', $limit = 0, $status = 1, $type = 0, $showempty =
'1', $morecss =
'', $nooutput =
'', $forcecombo = 0, $TProducts = [])
2987 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
2993 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2998 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
3000 $sql =
'SELECT b.rowid, b.ref, b.label as bomLabel, p.label as productLabel';
3001 $sql .=
' FROM ' . $this->db->prefix() .
'bom_bom as b';
3002 $sql .=
' INNER JOIN ' . $this->db->prefix() .
'product as p ON b.fk_product = p.rowid';
3003 $sql .=
' WHERE b.entity IN (' .
getEntity(
'bom') .
')';
3004 if (!empty($status)) {
3005 $sql .=
' AND status = ' . (int) $status;
3007 if (!empty($type)) {
3008 $sql .=
' AND bomtype = ' . (int) $type;
3010 if (!empty($TProducts)) {
3011 $sql .=
' AND fk_product IN (' . $this->db->sanitize(implode(
',', $TProducts)) .
')';
3013 if (!empty($limit)) {
3014 $sql .=
' LIMIT ' . (int) $limit;
3016 $resql = $db->query($sql);
3019 $out .=
'<option value="-1"';
3020 if (empty($selected)) {
3021 $out .=
' selected';
3023 $out .=
'> </option>';
3025 while ($obj = $db->fetch_object($resql)) {
3026 $out .=
'<option value="' . $obj->rowid .
'"';
3027 if ($obj->rowid == $selected) {
3030 $out .=
'>' . $obj->ref .
' - ' . $obj->productLabel .
' - ' . $obj->bomLabel .
'</option>';
3036 $out .=
'</select>';
3037 if (empty($nooutput)) {
3072 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)
3076 global $hookmanager;
3079 $outarray = array();
3083 $langs->load(
'other');
3086 $warehouseStatusArray = array();
3087 if (!empty($warehouseStatus)) {
3088 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/entrepot.class.php';
3089 if (preg_match(
'/warehouseclosed/', $warehouseStatus)) {
3092 if (preg_match(
'/warehouseopen/', $warehouseStatus)) {
3095 if (preg_match(
'/warehouseinternal/', $warehouseStatus)) {
3100 $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";
3101 if (count($warehouseStatusArray)) {
3102 $selectFieldsGrouped =
", sum(" . $this->db->ifsql(
"e.statut IS NULL",
"0",
"ps.reel") .
") as stock";
3104 $selectFieldsGrouped =
", " . $this->db->ifsql(
"p.stock IS NULL",
'0',
"p.stock") .
" AS stock";
3110 $parameters = array();
3111 $reshook = $hookmanager->executeHooks(
'selectProductsListSelect', $parameters);
3112 if (empty($reshook)) {
3113 $sql .= $selectFields.$selectFieldsGrouped.$hookmanager->resPrint;
3115 $sql .= $hookmanager->resPrint;
3120 $sql .=
", (SELECT " . $this->db->prefix() .
"categorie_product.fk_categorie
3121 FROM " . $this->db->prefix() .
"categorie_product
3122 WHERE " . $this->db->prefix() .
"categorie_product.fk_product=p.rowid
3124 ) AS categorie_product_id ";
3129 $sql .=
', pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,';
3130 $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';
3131 $selectFields .=
", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custdefault_vat_code, custref, custdiscount_percent";
3135 $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";
3136 $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';
3141 $sql .=
", pl.label as label_translated";
3142 $sql .=
", pl.description as description_translated";
3143 $selectFields .=
", label_translated";
3144 $selectFields .=
", description_translated";
3148 $sql .=
", (SELECT pp.rowid FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
3149 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
3150 $sql .=
" AND price_level = " . ((int) $price_level);
3152 $sql .=
" ORDER BY date_price";
3153 $sql .=
" DESC LIMIT 1) as price_rowid";
3154 $sql .=
", (SELECT pp.price_by_qty FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
3155 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
3156 $sql .=
" AND price_level = " . ((int) $price_level);
3158 $sql .=
" ORDER BY date_price";
3159 $sql .=
" DESC LIMIT 1) as price_by_qty";
3160 $selectFields .=
", price_rowid, price_by_qty";
3163 $sql .=
" FROM ".$this->db->prefix().
"product as p";
3166 $sql .=
" USE INDEX (" . $this->db->sanitize(
getDolGlobalString(
'MAIN_PRODUCT_FORCE_INDEX')) .
")";
3170 $parameters = array(
3173 $reshook = $hookmanager->executeHooks(
'selectProductsListFrom', $parameters);
3174 $sql .= $hookmanager->resPrint;
3176 if (count($warehouseStatusArray)) {
3177 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_stock as ps on ps.fk_product = p.rowid";
3178 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entrepot as e on ps.fk_entrepot = e.rowid AND e.entity IN (" .
getEntity(
'stock') .
")";
3179 $sql .=
' AND e.statut IN (' . $this->db->sanitize($this->db->escape(implode(
',', $warehouseStatusArray))) .
')';
3185 $sql .=
" LEFT JOIN (";
3186 $sql .=
" SELECT pcp1.*";
3187 $sql .=
" FROM " . $this->db->prefix() .
"product_customer_price AS pcp1";
3188 $sql .=
" LEFT JOIN (";
3189 $sql .=
" SELECT fk_soc, fk_product, MIN(date_begin) AS date_begin";
3190 $sql .=
" FROM " . $this->db->prefix() .
"product_customer_price";
3191 $sql .=
" WHERE fk_soc = " . ((int) $socid);
3192 $sql .=
" AND date_begin <= '" . $this->db->idate($now) .
"'";
3193 $sql .=
" AND (date_end IS NULL OR '" . $this->db->idate($now) .
"' <= date_end)";
3194 $sql .=
" GROUP BY fk_soc, fk_product";
3195 $sql .=
" ) AS pcp2 ON pcp1.fk_soc = pcp2.fk_soc AND pcp1.fk_product = pcp2.fk_product AND pcp1.date_begin = pcp2.date_begin";
3196 $sql .=
" WHERE pcp2.fk_soc IS NOT NULL";
3197 $sql .=
" ) AS pcp ON pcp.fk_soc = " . ((int) $socid) .
" AND pcp.fk_product = p.rowid";
3201 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
3205 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_lang as pl ON pl.fk_product = p.rowid ";
3207 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
3208 $soc =
new Societe($this->db);
3209 $result = $soc->fetch($socid);
3210 if ($result > 0 && !empty($soc->default_lang)) {
3211 $sql .=
" AND pl.lang = '" . $this->db->escape($soc->default_lang) .
"'";
3213 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3216 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3221 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_attribute_combination pac ON pac.fk_product_child = p.rowid";
3224 $sql .=
' WHERE p.entity IN (' .
getEntity(
'product') .
')';
3227 $sql .=
" AND pac.rowid IS NULL";
3230 if ($finished == 0) {
3231 $sql .=
" AND p.finished = " . ((int) $finished);
3232 } elseif ($finished == 1) {
3233 $sql .=
" AND p.finished = ".((int) $finished);
3236 $sql .=
" AND p.tosell = ".((int) $status);
3238 if ($status_purchase >= 0) {
3239 $sql .=
" AND p.tobuy = " . ((int) $status_purchase);
3242 if (strval($filtertype) !=
'') {
3243 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
3244 } elseif (!isModEnabled(
'product')) {
3245 $sql .=
" AND p.fk_product_type = 1";
3246 } elseif (!isModEnabled(
'service')) {
3247 $sql .=
" AND p.fk_product_type = 0";
3250 if ((
int) $warehouseId > 0) {
3251 $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)";
3255 $parameters = array(
3256 'filterkey' => &$filterkey,
3259 $reshook = $hookmanager->executeHooks(
'selectProductsListWhere', $parameters);
3260 $sql .= $hookmanager->resPrint;
3262 if ($filterkey !=
'') {
3263 $sqlSupplierSearch =
'';
3268 $search_crit = explode(
' ', $filterkey);
3270 if (count($search_crit) > 1) {
3273 foreach ($search_crit as $crit) {
3277 $sql .=
"(p.ref LIKE '" . $this->db->escape($prefix . $crit) .
"%' OR p.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3279 $sql .=
" OR pl.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3282 $sql .=
" OR pcp.ref_customer LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3285 $sql .=
" OR p.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3287 $sql .=
" OR pl.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3293 $sqlSupplierSearch .= !empty($sqlSupplierSearch) ?
' AND ':
'';
3294 $sqlSupplierSearch .=
" pfp.ref_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3299 if (count($search_crit) > 1) {
3302 if (isModEnabled(
'barcode')) {
3303 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3308 $sql .=
" OR EXISTS (SELECT pfp.fk_product FROM " . $this->db->prefix() .
"product_fournisseur_price as pfp WHERE p.rowid = pfp.fk_product";
3310 $sql .= $sqlSupplierSearch;
3316 if (count($warehouseStatusArray)) {
3317 $sql .=
" GROUP BY " . $selectFields;
3322 $sql .=
" ORDER BY categorie_product_id ";
3324 (
getDolGlobalInt(
'PRODUCT_SORT_BY_CATEGORY') == 1) ? $sql .=
"ASC" : $sql .=
"DESC";
3326 $sql .= $this->db->order(
"p.ref");
3330 $sql .= $this->db->plimit($limit, 0);
3333 dol_syslog(get_class($this) .
"::select_produits_list search products", LOG_DEBUG);
3334 $result = $this->db->query($sql);
3336 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3337 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3338 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
3340 $num = $this->db->num_rows($result);
3345 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3349 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
3355 if ($showempty && !is_numeric($showempty)) {
3356 $textifempty = $langs->trans($showempty);
3358 $textifempty .= $langs->trans(
"All");
3361 if ($showempty && !is_numeric($showempty)) {
3362 $textifempty = $langs->trans($showempty);
3366 $out .=
'<option value="-1" selected>' . ($textifempty ? $textifempty :
' ') .
'</option>';
3370 while ($num && $i < $num) {
3373 $objp = $this->db->fetch_object($result);
3375 if ((
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1) {
3376 $sql =
"SELECT rowid, quantity, price, unitprice, remise_percent, remise, price_base_type";
3377 $sql .=
" FROM " . $this->db->prefix() .
"product_price_by_qty";
3378 $sql .=
" WHERE fk_product_price = " . ((int) $objp->price_rowid);
3379 $sql .=
" ORDER BY quantity ASC";
3381 dol_syslog(get_class($this) .
"::select_produits_list search prices by qty", LOG_DEBUG);
3382 $result2 = $this->db->query($sql);
3384 $nb_prices = $this->db->num_rows($result2);
3386 while ($nb_prices && $j < $nb_prices) {
3387 $objp2 = $this->db->fetch_object($result2);
3389 $objp->price_by_qty_rowid = $objp2->rowid;
3390 $objp->price_by_qty_price_base_type = $objp2->price_base_type;
3391 $objp->price_by_qty_quantity = $objp2->quantity;
3392 $objp->price_by_qty_unitprice = $objp2->unitprice;
3393 $objp->price_by_qty_remise_percent = $objp2->remise_percent;
3395 $objp->quantity = $objp2->quantity;
3396 $objp->price = $objp2->price;
3397 $objp->unitprice = $objp2->unitprice;
3398 $objp->remise_percent = $objp2->remise_percent;
3404 '@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';
3411 array_push($outarray, $optJson);
3415 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_price_expression)) {
3416 $price_product =
new Product($this->db);
3417 $price_product->fetch($objp->rowid,
'',
'',
'1');
3419 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3421 $price_result = $priceparser->parseProduct($price_product);
3422 if ($price_result >= 0) {
3423 $objp->price = $price_result;
3424 $objp->unitprice = $price_result;
3426 $objp->price_ttc = (float)
price2num($objp->price) * (1 + ($objp->tva_tx / 100));
3427 $objp->price_ttc =
price2num($objp->price_ttc,
'MU');
3430 if (
getDolGlobalInt(
'PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES') && !empty($objp->custprice)) {
3438 array_push($outarray, $optJson);
3444 $out .=
'</select>';
3446 $this->db->free($result);
3448 if (empty($outputmode)) {
3475 protected function constructProductListOption(&$objp, &$opt, &$optJson, $price_level, $selected, $hidepriceinlabel = 0, $filterkey =
'', $novirtualstock = 0)
3477 global $langs,
$conf, $user;
3478 global $hookmanager;
3484 $outlabel_translated =
'';
3486 $outdesc_translated =
'';
3492 $outpricebasetype =
'';
3494 $outdefault_vat_code =
'';
3498 $maxlengtharticle = (!
getDolGlobalString(
'PRODUCT_MAX_LENGTH_COMBO') ? 48 :
$conf->global->PRODUCT_MAX_LENGTH_COMBO);
3500 $label = $objp->label;
3501 if (!empty($objp->label_translated)) {
3502 $label = $objp->label_translated;
3504 if (!empty($filterkey) && $filterkey !=
'') {
3505 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
3508 $outkey = $objp->rowid;
3509 $outref = $objp->ref;
3510 $outrefcust = empty($objp->custref) ?
'' : $objp->custref;
3511 $outlabel = $objp->label;
3512 $outdesc = $objp->description;
3514 $outlabel_translated = $objp->label_translated;
3515 $outdesc_translated = $objp->description_translated;
3517 $outbarcode = $objp->barcode;
3518 $outorigin = $objp->fk_country;
3519 $outpbq = empty($objp->price_by_qty_rowid) ?
'' : $objp->price_by_qty_rowid;
3521 $outtype = $objp->fk_product_type;
3526 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
3532 if (!empty($objp->unit_short)) {
3533 $outvalUnits .=
' - ' . $objp->unit_short;
3537 if (!empty($objp->weight) && $objp->weight_units !==
null) {
3539 $outvalUnits .=
' - ' . $unitToShow;
3541 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
3542 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
3543 $outvalUnits .=
' - ' . $unitToShow;
3545 if (!empty($objp->surface) && $objp->surface_units !==
null) {
3547 $outvalUnits .=
' - ' . $unitToShow;
3549 if (!empty($objp->volume) && $objp->volume_units !==
null) {
3551 $outvalUnits .=
' - ' . $unitToShow;
3554 if ($outdurationvalue && $outdurationunit) {
3556 'h' => $langs->trans(
'Hour'),
3557 'd' => $langs->trans(
'Day'),
3558 'w' => $langs->trans(
'Week'),
3559 'm' => $langs->trans(
'Month'),
3560 'y' => $langs->trans(
'Year')
3562 if (isset($da[$outdurationunit])) {
3563 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
3570 if ($user->hasRight(
'stock',
'lire')) {
3571 if ($objp->stock > 0) {
3573 } elseif ($objp->stock <= 0) {
3581 $labeltoshow .= $objp->ref;
3582 if (!empty($objp->custref)) {
3583 $labeltoshow .=
' (' . $objp->custref .
')';
3586 $labeltoshow .=
' (' . $outbarcode .
')';
3588 $labeltoshow .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3590 $labeltoshow .=
' (' .
getCountry($outorigin,
'1') .
')';
3594 $labeltoshowhtml =
'';
3595 $labeltoshowhtml .= $objp->ref;
3596 if (!empty($objp->custref)) {
3597 $labeltoshowhtml .=
' (' . $objp->custref .
')';
3599 if (!empty($filterkey) && $filterkey !=
'') {
3600 $labeltoshowhtml = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $labeltoshowhtml, 1);
3603 $labeltoshowhtml .=
' (' . $outbarcode .
')';
3605 $labeltoshowhtml .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3607 $labeltoshowhtml .=
' (' .
getCountry($outorigin,
'1') .
')';
3611 $labeltoshowstock =
'';
3612 $labeltoshowhtmlstock =
'';
3614 if ($user->hasRight(
'stock',
'lire')) {
3615 $labeltoshowstock .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
3617 if ($objp->stock > 0) {
3618 $labeltoshowhtmlstock .=
' - <span class="product_line_stock_ok">';
3619 } elseif ($objp->stock <= 0) {
3620 $labeltoshowhtmlstock .=
' - <span class="product_line_stock_too_low">';
3622 $labeltoshowhtmlstock .= $langs->transnoentities(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
3623 $labeltoshowhtmlstock .=
'</span>';
3625 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
3626 $langs->load(
"stocks");
3628 $tmpproduct =
new Product($this->db);
3629 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
3630 $tmpproduct->load_virtual_stock();
3631 $virtualstock = $tmpproduct->stock_theorique;
3633 $labeltoshowstock .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
3635 $labeltoshowhtmlstock .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
3636 if ($virtualstock > 0) {
3637 $labeltoshowhtmlstock .=
'<span class="product_line_stock_ok">';
3638 } elseif ($virtualstock <= 0) {
3639 $labeltoshowhtmlstock .=
'<span class="product_line_stock_too_low">';
3641 $labeltoshowhtmlstock .= $virtualstock;
3642 $labeltoshowhtmlstock .=
'</span>';
3651 $labeltoshowprice =
'';
3652 $labeltoshowhtmlprice =
'';
3655 $sql =
"SELECT price, price_ttc, price_base_type, tva_tx, default_vat_code";
3656 $sql .=
" FROM " . $this->db->prefix() .
"product_price";
3657 $sql .=
" WHERE fk_product = " . ((int) $objp->rowid);
3658 $sql .=
" AND entity IN (" .
getEntity(
'productprice') .
")";
3659 $sql .=
" AND price_level = " . ((int) $price_level);
3660 $sql .=
" ORDER BY date_price DESC, rowid DESC";
3663 dol_syslog(get_class($this) .
'::constructProductListOption search price for product ' . $objp->rowid .
' AND level ' . $price_level, LOG_DEBUG);
3664 $result2 = $this->db->query($sql);
3666 $objp2 = $this->db->fetch_object($result2);
3669 if ($objp2->price_base_type ==
'HT') {
3670 $labeltoshowprice .=
' - ' .
price($objp2->price, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
3671 $labeltoshowhtmlprice .=
' - ' .
price($objp2->price, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
3673 $labeltoshowprice .=
' - ' .
price($objp2->price_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
3674 $labeltoshowhtmlprice .=
' - ' .
price($objp2->price_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3676 $outprice_ht =
price($objp2->price);
3677 $outprice_ttc =
price($objp2->price_ttc);
3678 $outpricebasetype = $objp2->price_base_type;
3680 $outtva_tx = $objp2->tva_tx;
3681 $outdefault_vat_code = $objp2->default_vat_code;
3683 $outtva_tx = $objp->tva_tx;
3684 $outdefault_vat_code = $objp->default_vat_code;
3693 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1 && (
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
3695 $outqty = $objp->quantity;
3696 $outdiscount = $objp->remise_percent;
3697 if ($objp->quantity == 1) {
3698 $labeltoshowprice .=
' - ' .
price($objp->unitprice, 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
3699 $labeltoshowhtmlprice .=
' - ' .
price($objp->unitprice, 0, $langs, 0, 0, -1,
$conf->currency) .
"/";
3700 $labeltoshowprice .= $langs->trans(
"Unit");
3701 $labeltoshowhtmlprice .= $langs->transnoentities(
"Unit");
3703 $labeltoshowprice .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
3704 $labeltoshowhtmlprice .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
3705 $labeltoshowprice .= $langs->trans(
"Units");
3706 $labeltoshowhtmlprice .= $langs->transnoentities(
"Units");
3709 $outprice_ht =
price($objp->unitprice);
3710 $outprice_ttc =
price($objp->unitprice * (1 + ($objp->tva_tx / 100)));
3711 $outpricebasetype = $objp->price_base_type;
3712 $outtva_tx = $objp->tva_tx;
3713 $outdefault_vat_code = $objp->default_vat_code;
3715 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1) {
3716 $labeltoshowprice .=
" (" .
price($objp->unitprice, 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->trans(
"Unit") .
")";
3717 $labeltoshowhtmlprice .=
" (" .
price($objp->unitprice, 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->transnoentities(
"Unit") .
")";
3719 if (empty($hidepriceinlabel) && !empty($objp->remise_percent) && $objp->remise_percent >= 1) {
3720 $labeltoshowprice .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3721 $labeltoshowhtmlprice .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3726 if (!empty($objp->idprodcustprice)) {
3729 if ($objp->custprice_base_type ==
'HT') {
3730 $labeltoshowprice .=
' - ' .
price($objp->custprice, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
3731 $labeltoshowhtmlprice .=
' - ' .
price($objp->custprice, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
3733 $labeltoshowprice .=
' - ' .
price($objp->custprice_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
3734 $labeltoshowhtmlprice .=
' - ' .
price($objp->custprice_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3737 $outprice_ht =
price($objp->custprice);
3738 $outprice_ttc =
price($objp->custprice_ttc);
3739 $outpricebasetype = $objp->custprice_base_type;
3740 $outtva_tx = $objp->custtva_tx;
3741 $outdefault_vat_code = $objp->custdefault_vat_code;
3742 $outdiscount = $objp->custdiscount_percent;
3747 if (empty($hidepriceinlabel) && !$found) {
3748 if ($objp->price_base_type ==
'HT') {
3749 $labeltoshowprice .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
3750 $labeltoshowhtmlprice .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
3752 $labeltoshowprice .=
' - ' .
price($objp->price_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
3753 $labeltoshowhtmlprice .=
' - ' .
price($objp->price_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3755 $outprice_ht =
price($objp->price);
3756 $outprice_ttc =
price($objp->price_ttc);
3757 $outpricebasetype = $objp->price_base_type;
3758 $outtva_tx = $objp->tva_tx;
3759 $outdefault_vat_code = $objp->default_vat_code;
3763 $opt =
'<option value="' . $objp->rowid .
'"';
3764 $opt .= ($objp->rowid == $selected) ?
' selected' :
'';
3765 if (!empty($objp->price_by_qty_rowid) && $objp->price_by_qty_rowid > 0) {
3766 $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 .
'"';
3769 $opt .=
' data-labeltrans="' . $outlabel_translated .
'"';
3773 if ($stocktag == 1) {
3774 $opt .=
' class="product_line_stock_ok" data-html="'.$labeltoshowhtml.$outvalUnits.$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
3777 if ($stocktag == -1) {
3778 $opt .=
' class="product_line_stock_too_low" data-html="'.$labeltoshowhtml.$outvalUnits.$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
3785 $opt .= $labeltoshow;
3786 $outval .= $labeltoshowhtml;
3789 $opt .= $outvalUnits;
3790 $outval .= $outvalUnits;
3793 $opt .= $labeltoshowprice;
3794 $outval .= $labeltoshowhtmlprice;
3797 $opt .= $labeltoshowstock;
3798 $outval .= $labeltoshowhtmlstock;
3801 $parameters = array(
'objp' => $objp);
3802 $reshook = $hookmanager->executeHooks(
'constructProductListOption', $parameters);
3803 if (empty($reshook)) {
3804 $opt .= $hookmanager->resPrint;
3806 $opt = $hookmanager->resPrint;
3809 $opt .=
"</option>\n";
3814 'label2' => $outlabel,
3818 'price_ttc' =>
price2num($outprice_ttc),
3821 'pricebasetype' => $outpricebasetype,
3822 'tva_tx' => $outtva_tx,
3823 'default_vat_code' => $outdefault_vat_code,
3825 'discount' => $outdiscount,
3826 'duration_value' => $outdurationvalue,
3827 'duration_unit' => $outdurationunit,
3829 'labeltrans' => $outlabel_translated,
3830 'desctrans' => $outdesc_translated,
3831 'ref_customer' => $outrefcust
3853 public function select_produits_fournisseurs($socid, $selected =
'', $htmlname =
'productid', $filtertype =
'', $filtre =
'', $ajaxoptions = array(), $hidelabel = 0, $alsoproductwithnosupplierprice = 0, $morecss =
'', $placeholder =
'', $nooutput = 0)
3856 global $langs,
$conf;
3857 global $price_level, $status, $finished;
3859 if (!isset($status)) {
3863 $selected_input_value =
'';
3865 if ((
int) $selected > 0) {
3866 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3867 $producttmpselect =
new Product($this->db);
3868 $producttmpselect->fetch((
int) $selected);
3869 $selected_input_value = $producttmpselect->ref;
3870 unset($producttmpselect);
3874 $urloption = ($socid > 0 ?
'socid=' . $socid .
'&' :
'') .
'htmlname=' . $htmlname .
'&outjson=1&price_level=' . $price_level .
'&type=' . $filtertype .
'&mode=2&status=' . $status .
'&finished=' . $finished .
'&alsoproductwithnosupplierprice=' . $alsoproductwithnosupplierprice;
3876 $s =
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT .
'/product/ajax/products.php', $urloption,
getDolGlobalInt(
'PRODUIT_USE_SEARCH_TO_SELECT'), 0, $ajaxoptions);
3878 $s .= ($hidelabel ?
'' : $langs->trans(
"RefOrLabel") .
' : ') .
'<input type="text" class="'.$morecss.
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . ($placeholder ?
' placeholder="' . $placeholder .
'"' :
'') .
'>';
3880 $s = $this->
select_produits_fournisseurs_list($socid, $selected, $htmlname, $filtertype, $filtre,
'', $status, 0, 0, $alsoproductwithnosupplierprice, $morecss,
getDolGlobalInt(
'SUPPLIER_SHOW_STOCK_IN_PRODUCTS_COMBO'), $placeholder);
3910 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 =
'')
3913 global $langs,
$conf, $user;
3914 global $hookmanager;
3917 $outarray = array();
3919 $maxlengtharticle = (!
getDolGlobalString(
'PRODUCT_MAX_LENGTH_COMBO') ? 48 :
$conf->global->PRODUCT_MAX_LENGTH_COMBO);
3921 $langs->load(
'stocks');
3924 $langs->load(
'other');
3927 $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,";
3928 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice, pfp.barcode";
3929 $sql .=
", pfp.multicurrency_code, pfp.multicurrency_unitprice";
3930 $sql .=
", pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.default_vat_code, pfp.fk_soc, s.nom as name";
3931 $sql .=
", pfp.supplier_reputation";
3934 $sql .=
", pfp.desc_fourn as description";
3936 $sql .=
", p.description";
3940 $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";
3945 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListSelect', $parameters);
3946 $sql .= $hookmanager->resPrint;
3948 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
3952 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListFrom', $parameters);
3953 $sql .= $hookmanager->resPrint;
3955 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN (" .
getEntity(
'product') .
") )";
3957 $sql .=
" AND pfp.fk_soc = " . ((int) $socid);
3959 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
3962 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
3964 $sql .=
" WHERE p.entity IN (" .
getEntity(
'product') .
")";
3965 if ($statut != -1) {
3966 $sql .=
" AND p.tobuy = " . ((int) $statut);
3968 if (strval($filtertype) !=
'') {
3969 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
3971 if (!empty($filtre)) {
3972 $sql .=
" " . $filtre;
3975 $parameters = array();
3976 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListWhere', $parameters);
3977 $sql .= $hookmanager->resPrint;
3979 if ($filterkey !=
'') {
3983 $search_crit = explode(
' ', $filterkey);
3985 if (count($search_crit) > 1) {
3988 foreach ($search_crit as $crit) {
3992 $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) .
"%'";
3994 $sql .=
" OR pfp.desc_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3999 if (count($search_crit) > 1) {
4002 if (isModEnabled(
'barcode')) {
4003 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
4004 $sql .=
" OR pfp.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
4008 $sql .=
" ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC";
4009 $sql .= $this->db->plimit($limit, 0);
4013 dol_syslog(get_class($this) .
"::select_produits_fournisseurs_list", LOG_DEBUG);
4014 $result = $this->db->query($sql);
4016 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4017 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
4019 $num = $this->db->num_rows($result);
4022 $out .=
'<select class="flat ' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'">';
4024 $out .=
'<option value="-1" selected>' . ($placeholder ? $placeholder :
' ') .
'</option>';
4026 $out .=
'<option value="-1">' . ($placeholder ? $placeholder :
' ') .
'</option>';
4031 $objp = $this->db->fetch_object($result);
4033 if (is_null($objp->idprodfournprice)) {
4035 $objp->tva_tx = $objp->tva_tx_sale;
4036 $objp->default_vat_code = $objp->default_vat_code_sale;
4039 $outkey = $objp->idprodfournprice;
4040 if (!$outkey && $alsoproductwithnosupplierprice) {
4041 $outkey =
'idprod_' . $objp->rowid;
4044 $outref = $objp->ref;
4045 $outbarcode = $objp->barcode;
4048 $outtype = $objp->fk_product_type;
4055 if (!empty($objp->unit_short)) {
4056 $outvalUnits .=
' - ' . $objp->unit_short;
4058 if (!empty($objp->weight) && $objp->weight_units !==
null) {
4060 $outvalUnits .=
' - ' . $unitToShow;
4062 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
4063 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
4064 $outvalUnits .=
' - ' . $unitToShow;
4066 if (!empty($objp->surface) && $objp->surface_units !==
null) {
4068 $outvalUnits .=
' - ' . $unitToShow;
4070 if (!empty($objp->volume) && $objp->volume_units !==
null) {
4072 $outvalUnits .=
' - ' . $unitToShow;
4074 if ($outdurationvalue && $outdurationunit) {
4076 'h' => $langs->trans(
'Hour'),
4077 'd' => $langs->trans(
'Day'),
4078 'w' => $langs->trans(
'Week'),
4079 'm' => $langs->trans(
'Month'),
4080 'y' => $langs->trans(
'Year')
4082 if (isset($da[$outdurationunit])) {
4083 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
4088 $objRef = $objp->ref;
4089 if ($filterkey && $filterkey !=
'') {
4090 $objRef = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRef, 1);
4092 $objRefFourn = $objp->ref_fourn;
4093 if ($filterkey && $filterkey !=
'') {
4094 $objRefFourn = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRefFourn, 1);
4096 $label = $objp->label;
4097 if ($filterkey && $filterkey !=
'') {
4098 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
4101 switch ($objp->fk_product_type) {
4113 if (empty($picto)) {
4116 $optlabel =
img_object(
'', $picto,
'class="paddingright classfortooltip"', 0, 0, 1);
4119 $optlabel .= $objp->ref;
4120 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
4121 $optlabel .=
' <span class="opacitymedium">(' . $objp->ref_fourn .
')</span>';
4123 if (isModEnabled(
'barcode') && !empty($objp->barcode)) {
4124 $optlabel .=
' (' . $outbarcode .
')';
4126 $optlabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
4128 $outvallabel = $objRef;
4129 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
4130 $outvallabel .=
' (' . $objRefFourn .
')';
4132 if (isModEnabled(
'barcode') && !empty($objp->barcode)) {
4133 $outvallabel .=
' (' . $outbarcode .
')';
4135 $outvallabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
4138 $optlabel .= $outvalUnits;
4139 $outvallabel .= $outvalUnits;
4141 if (!empty($objp->idprodfournprice)) {
4142 $outqty = $objp->quantity;
4143 $outdiscount = $objp->remise_percent;
4144 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
4146 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
4147 $prod_supplier->id = $objp->fk_product;
4148 $prod_supplier->fourn_qty = $objp->quantity;
4149 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
4150 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
4152 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4154 $price_result = $priceparser->parseProductSupplier($prod_supplier);
4155 if ($price_result >= 0) {
4156 $objp->fprice = $price_result;
4157 if ($objp->quantity >= 1) {
4158 $objp->unitprice = $objp->fprice / $objp->quantity;
4162 if ($objp->quantity == 1) {
4163 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
4164 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1,
$conf->currency) .
"/";
4165 $optlabel .= $langs->trans(
"Unit");
4166 $outvallabel .= $langs->transnoentities(
"Unit");
4168 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
4169 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
4170 $optlabel .=
' ' . $langs->trans(
"Units");
4171 $outvallabel .=
' ' . $langs->transnoentities(
"Units");
4174 if ($objp->quantity != 1) {
4175 $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") .
")";
4176 $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") .
")";
4178 if ($objp->remise_percent >= 1) {
4179 $optlabel .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4180 $outvallabel .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4182 if ($objp->duration) {
4183 $optlabel .=
" - " . $objp->duration;
4184 $outvallabel .=
" - " . $objp->duration;
4187 $optlabel .=
" - " .
dol_trunc($objp->name, 8);
4188 $outvallabel .=
" - " .
dol_trunc($objp->name, 8);
4190 if ($objp->supplier_reputation) {
4192 $reputations = array(
'' => $langs->trans(
'Standard'),
'FAVORITE' => $langs->trans(
'Favorite'),
'NOTTHGOOD' => $langs->trans(
'NotTheGoodQualitySupplier'),
'DONOTORDER' => $langs->trans(
'DoNotOrderThisProductToThisSupplier'));
4194 $optlabel .=
" - " . $reputations[$objp->supplier_reputation];
4195 $outvallabel .=
" - " . $reputations[$objp->supplier_reputation];
4198 $optlabel .=
" - <span class='opacitymedium'>" . $langs->trans(
"NoPriceDefinedForThisSupplier") .
'</span>';
4199 $outvallabel .=
' - ' . $langs->transnoentities(
"NoPriceDefinedForThisSupplier");
4203 $novirtualstock = ($showstockinlist == 2);
4205 if ($user->hasRight(
'stock',
'lire')) {
4206 $outvallabel .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
4208 if ($objp->stock > 0) {
4209 $optlabel .=
' - <span class="product_line_stock_ok">';
4210 } elseif ($objp->stock <= 0) {
4211 $optlabel .=
' - <span class="product_line_stock_too_low">';
4213 $optlabel .= $langs->transnoentities(
"Stock") .
':' .
price(
price2num($objp->stock,
'MS'));
4214 $optlabel .=
'</span>';
4215 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
4216 $langs->load(
"stocks");
4218 $tmpproduct =
new Product($this->db);
4219 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
4220 $tmpproduct->load_virtual_stock();
4221 $virtualstock = $tmpproduct->stock_theorique;
4223 $outvallabel .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
4225 $optlabel .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
4226 if ($virtualstock > 0) {
4227 $optlabel .=
'<span class="product_line_stock_ok">';
4228 } elseif ($virtualstock <= 0) {
4229 $optlabel .=
'<span class="product_line_stock_too_low">';
4231 $optlabel .= $virtualstock;
4232 $optlabel .=
'</span>';
4239 $optstart =
'<option value="' . $outkey .
'"';
4240 if ($selected && preg_match(
'/^idprod_/', (
string) $selected) && (
string) $selected ==
'idprod_'.$objp->rowid) {
4241 $optstart .=
' selected';
4242 } elseif ($selected && (
string) $selected == (
string) $objp->idprodfournprice) {
4243 $optstart .=
' selected';
4246 if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) {
4247 $optstart .=
' disabled';
4250 if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) {
4259 $optstart .=
' data-default-vat-code="' .
dol_escape_htmltag($objp->default_vat_code) .
'"';
4261 if (isModEnabled(
'multicurrency')) {
4262 $optstart .=
' data-multicurrency-code="' .
dol_escape_htmltag($objp->multicurrency_code) .
'"';
4266 $optstart .=
' data-description="' .
dol_escape_htmltag($objp->description, 0, 1) .
'"';
4269 $outarrayentry = array(
4272 'label' => $outvallabel,
4273 'labelhtml' => $optlabel,
4275 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4276 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4277 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4278 'tva_tx_formated' =>
price($objp->tva_tx, 0, $langs, 1, -1, 2),
4280 'default_vat_code' => $objp->default_vat_code,
4281 'supplier_ref' => $objp->ref_fourn,
4282 'discount' => $outdiscount,
4284 'duration_value' => $outdurationvalue,
4285 'duration_unit' => $outdurationunit,
4286 'disabled' => empty($objp->idprodfournprice),
4287 'description' => $objp->description
4289 if (isModEnabled(
'multicurrency')) {
4290 $outarrayentry[
'multicurrency_code'] = $objp->multicurrency_code;
4291 $outarrayentry[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4293 $parameters = array(
4295 'optstart' => &$optstart,
4296 'optlabel' => &$optlabel,
4297 'outvallabel' => &$outvallabel,
4298 'outarrayentry' => &$outarrayentry,
4301 $reshook = $hookmanager->executeHooks(
'selectProduitsFournisseurListOption', $parameters, $this);
4307 $out .= $optstart .
' data-html="' .
dol_escape_htmltag($optlabel) .
'">' . $optlabel .
"</option>\n";
4308 $outarraypush = array(
4311 'label' => $outvallabel,
4312 'labelhtml' => $optlabel,
4314 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4315 'price_qty_ht_locale' =>
price($objp->fprice),
4316 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4317 'price_unit_ht_locale' =>
price($objp->unitprice),
4318 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4319 'tva_tx_formated' =>
price($objp->tva_tx),
4321 'default_vat_code' => $objp->default_vat_code,
4322 'supplier_ref' => $objp->ref_fourn,
4323 'discount' => $outdiscount,
4325 'duration_value' => $outdurationvalue,
4326 'duration_unit' => $outdurationunit,
4327 'disabled' => empty($objp->idprodfournprice),
4328 'description' => $objp->description
4330 if (isModEnabled(
'multicurrency')) {
4331 $outarraypush[
'multicurrency_code'] = $objp->multicurrency_code;
4332 $outarraypush[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4334 array_push($outarray, $outarraypush);
4347 $out .=
'</select>';
4349 $this->db->free($result);
4351 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
4357 if (empty($outputmode)) {
4376 global $langs,
$conf;
4378 $langs->load(
'stocks');
4380 $sql =
"SELECT p.rowid, p.ref, p.label, p.price, p.duration, pfp.fk_soc,";
4381 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.remise_percent, pfp.quantity, pfp.unitprice,";
4382 $sql .=
" pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name";
4383 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
4384 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
4385 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
4386 $sql .=
" WHERE pfp.entity IN (" .
getEntity(
'productsupplierprice') .
")";
4387 $sql .=
" AND p.tobuy = 1";
4388 $sql .=
" AND s.fournisseur = 1";
4389 $sql .=
" AND p.rowid = " . ((int) $productid);
4391 $sql .=
" ORDER BY s.nom, pfp.ref_fourn DESC";
4393 $sql .=
" ORDER BY pfp.unitprice ASC";
4396 dol_syslog(get_class($this) .
"::select_product_fourn_price", LOG_DEBUG);
4397 $result = $this->db->query($sql);
4400 $num = $this->db->num_rows($result);
4402 $form =
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
4405 $form .=
'<option value="0">-- ' . $langs->trans(
"NoSupplierPriceDefinedForThisProduct") .
' --</option>';
4407 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4408 $form .=
'<option value="0"> </option>';
4412 $objp = $this->db->fetch_object($result);
4414 $opt =
'<option value="' . $objp->idprodfournprice .
'"';
4416 if ($num == 1 || ($selected_supplier > 0 && $objp->fk_soc == $selected_supplier) || ($i == 0 &&
getDolGlobalString(
'PRODUCT_BEST_SUPPLIER_PRICE_PRESELECTED'))) {
4417 $opt .=
' selected';
4419 $opt .=
'>' . $objp->name .
' - ' . $objp->ref_fourn .
' - ';
4421 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
4423 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
4424 $prod_supplier->id = $productid;
4425 $prod_supplier->fourn_qty = $objp->quantity;
4426 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
4427 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
4429 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4431 $price_result = $priceparser->parseProductSupplier($prod_supplier);
4432 if ($price_result >= 0) {
4433 $objp->fprice = $price_result;
4434 if ($objp->quantity >= 1) {
4435 $objp->unitprice = $objp->fprice / $objp->quantity;
4439 if ($objp->quantity == 1) {
4440 $opt .=
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
4443 $opt .= $objp->quantity .
' ';
4445 if ($objp->quantity == 1) {
4446 $opt .= $langs->trans(
"Unit");
4448 $opt .= $langs->trans(
"Units");
4450 if ($objp->quantity > 1) {
4452 $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");
4454 if ($objp->duration) {
4455 $opt .=
" - " . $objp->duration;
4457 $opt .=
"</option>\n";
4464 $form .=
'</select>';
4465 $this->db->free($result);
4483 global $langs, $hookmanager;
4485 $num = count($this->cache_conditions_paiements);
4492 $this->cache_conditions_paiements = array();
4494 $sql =
"SELECT rowid, code, libelle as label, deposit_percent, entity";
4495 $sql .=
" FROM " . $this->db->prefix() .
'c_payment_term';
4496 $sql .=
" WHERE entity IN (" .
getEntity(
'c_payment_term') .
")";
4497 $sql .=
" AND active > 0";
4498 $sql .=
" ORDER BY sortorder";
4500 $resql = $this->db->query($sql);
4502 $num = $this->db->num_rows($resql);
4505 $obj = $this->db->fetch_object($resql);
4508 $label = ($langs->trans(
"PaymentConditionShort" . $obj->code) !=
"PaymentConditionShort" . $obj->code ? $langs->trans(
"PaymentConditionShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4509 $this->cache_conditions_paiements[$obj->rowid][
'code'] = (string) $obj->code;
4510 $this->cache_conditions_paiements[$obj->rowid][
'label'] = (string) $label;
4511 $this->cache_conditions_paiements[$obj->rowid][
'deposit_percent'] = (string) $obj->deposit_percent;
4512 $this->cache_conditions_paiements[$obj->rowid][
'entity'] = (int) $obj->entity;
4516 $parameters = array(
'context' =>
'paymentterm');
4517 $reshook = $hookmanager->executeHooks(
'loadDictionaryCache', $parameters, $this);
4518 if (empty($reshook)) {
4519 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
4520 $this->cache_conditions_paiements = array_merge($this->cache_conditions_paiements, $hookmanager->resArray);
4523 $this->cache_conditions_paiements = $hookmanager->resArray;
4547 $this->cache_rule_for_lines_dates = $factureRec->fields[
'rule_for_lines_dates'][
'arrayofkeyval'];
4549 if (empty($this->cache_rule_for_lines_dates)) {
4568 $num = count($this->cache_availability);
4575 $this->cache_availability = array();
4577 $langs->load(
'propal');
4579 $sql =
"SELECT rowid, code, label, position";
4580 $sql .=
" FROM " . $this->db->prefix() .
'c_availability';
4581 $sql .=
" WHERE active > 0";
4583 $resql = $this->db->query($sql);
4585 $num = $this->db->num_rows($resql);
4588 $obj = $this->db->fetch_object($resql);
4591 $label = ($langs->trans(
"AvailabilityType" . $obj->code) !=
"AvailabilityType" . $obj->code ? $langs->trans(
"AvailabilityType" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4592 $this->cache_availability[$obj->rowid][
'code'] = (string) $obj->code;
4593 $this->cache_availability[$obj->rowid][
'label'] = (string) $label;
4594 $this->cache_availability[$obj->rowid][
'position'] = (int) $obj->position;
4598 $this->cache_availability =
dol_sort_array($this->cache_availability,
'position',
'asc', 0, 0, 1);
4619 global $langs, $user;
4623 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
4625 print
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4627 print
'<option value="0"> </option>';
4629 foreach ($this->cache_availability as
$id => $arrayavailability) {
4630 if ($selected ==
$id) {
4631 print
'<option value="' .
$id .
'" selected>';
4633 print
'<option value="' .
$id .
'">';
4640 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4654 $num = count($this->cache_demand_reason);
4659 $sql =
"SELECT rowid, code, label";
4660 $sql .=
" FROM " . $this->db->prefix() .
'c_input_reason';
4661 $sql .=
" WHERE active > 0";
4663 $resql = $this->db->query($sql);
4665 $num = $this->db->num_rows($resql);
4667 $tmparray = array();
4669 $obj = $this->db->fetch_object($resql);
4672 $label = ($obj->label !=
'-' ? $obj->label :
'');
4673 if ($langs->trans(
"DemandReasonType" . $obj->code) !=
"DemandReasonType" . $obj->code) {
4674 $label = $langs->trans(
"DemandReasonType" . $obj->code);
4676 if ($langs->trans($obj->code) != $obj->code) {
4677 $label = $langs->trans($obj->code);
4680 $tmparray[$obj->rowid][
'id'] = $obj->rowid;
4681 $tmparray[$obj->rowid][
'code'] = $obj->code;
4682 $tmparray[$obj->rowid][
'label'] = $label;
4686 $this->cache_demand_reason =
dol_sort_array($tmparray,
'label',
'asc', 0, 0, 1);
4708 public function selectInputReason($selected =
'', $htmlname =
'demandreasonid', $exclude =
'', $addempty = 0, $morecss =
'', $notooltip = 0)
4710 global $langs, $user;
4714 print
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
4716 print
'<option value="0"' . (empty($selected) ?
' selected' :
'') .
'> </option>';
4718 foreach ($this->cache_demand_reason as
$id => $arraydemandreason) {
4719 if ($arraydemandreason[
'code'] == $exclude) {
4723 if ($selected && ($selected == $arraydemandreason[
'id'] || $selected == $arraydemandreason[
'code'])) {
4724 print
'<option value="' . $arraydemandreason[
'id'] .
'" selected>';
4726 print
'<option value="' . $arraydemandreason[
'id'] .
'">';
4728 $label = $arraydemandreason[
'label'];
4729 print $langs->trans($label);
4733 if ($user->admin && empty($notooltip)) {
4734 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4749 global $langs, $hookmanager;
4751 $num = count($this->cache_types_paiements);
4758 $this->cache_types_paiements = array();
4760 $sql =
"SELECT id, code, libelle as label, type, entity, active";
4761 $sql .=
" FROM " . $this->db->prefix() .
"c_paiement";
4762 $sql .=
" WHERE entity IN (" .
getEntity(
'c_paiement') .
")";
4764 $resql = $this->db->query($sql);
4766 $num = $this->db->num_rows($resql);
4769 $obj = $this->db->fetch_object($resql);
4772 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) !=
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4773 $this->cache_types_paiements[$obj->id][
'id'] = (int) $obj->id;
4774 $this->cache_types_paiements[$obj->id][
'code'] = (string) $obj->code;
4775 $this->cache_types_paiements[$obj->id][
'label'] = (string) $label;
4776 $this->cache_types_paiements[$obj->id][
'type'] = (int) $obj->type;
4777 $this->cache_types_paiements[$obj->id][
'entity'] = (int) $obj->entity;
4778 $this->cache_types_paiements[$obj->id][
'active'] = (int) $obj->active;
4782 $parameters = array(
'context' =>
'paymenttype');
4783 $reshook = $hookmanager->executeHooks(
'loadDictionaryCache', $parameters, $this);
4784 if (empty($reshook)) {
4785 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
4786 $this->cache_types_paiements = array_merge($this->cache_types_paiements, $hookmanager->resArray);
4789 $this->cache_types_paiements = $hookmanager->resArray;
4792 $this->cache_types_paiements =
dol_sort_array($this->cache_types_paiements,
'label',
'asc', 0, 0, 1);
4822 public function select_conditions_paiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1, $noprint = 0)
4826 if (empty($noprint)) {
4850 public function getSelectConditionsPaiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1)
4852 global $langs, $user,
$conf;
4855 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
4860 if (empty($selected) && strpos($htmlname,
'search_') !== 0 &&
getDolGlobalString(
'MAIN_DEFAULT_PAYMENT_TERM_ID')) {
4861 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TERM_ID", LOG_NOTICE);
4865 $out .=
'<select id="' . $htmlname .
'" class="flat selectpaymentterms' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4867 $out .=
'<option value="0"> </option>';
4870 $selectedDepositPercent =
null;
4872 foreach ($this->cache_conditions_paiements as
$id => $arrayconditions) {
4873 if ($filtertype <= 0 && !empty($arrayconditions[
'deposit_percent'])) {
4877 if ($selected ==
$id) {
4878 $selectedDepositPercent = $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'];
4879 $out .=
'<option value="' .
$id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'" selected>';
4881 $out .=
'<option value="' .
$id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'">';
4883 $label = $arrayconditions[
'label'];
4885 if (!empty($arrayconditions[
'deposit_percent'])) {
4886 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'], $label);
4890 $out .=
'</option>';
4892 $out .=
'</select>';
4893 if ($user->admin && empty($noinfoadmin)) {
4894 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4898 if ($deposit_percent >= 0) {
4899 $out .=
' <span id="' . $htmlname .
'_deposit_percent_container"' . (empty($selectedDepositPercent) ?
' style="display: none"' :
'') .
'>';
4900 $out .= $langs->trans(
'DepositPercent') .
' : ';
4901 $out .=
'<input id="' . $htmlname .
'_deposit_percent" name="' . $htmlname .
'_deposit_percent" class="maxwidth50" value="' . $deposit_percent .
'" />';
4904 <script nonce="' .
getNonce() .
'">
4905 $(document).ready(function () {
4906 $("#' . $htmlname .
'").change(function () {
4907 let $selected = $(this).find("option:selected");
4908 let depositPercent = $selected.attr("data-deposit_percent");
4910 if (depositPercent.length > 0) {
4911 $("#' . $htmlname .
'_deposit_percent_container").show().find("#' . $htmlname .
'_deposit_percent").val(depositPercent);
4913 $("#' . $htmlname .
'_deposit_percent_container").hide();
4942 $out .=
'<select id="' . $htmlname .
'" class="flat selectbillingterm" name="' . $htmlname .
'">';
4944 $out .=
'<option value="-1"> </option>';
4948 foreach ($this->cache_rule_for_lines_dates as $rule_for_lines_dates_key => $rule_for_lines_dates_name) {
4949 if ($selected == $rule_for_lines_dates_key) {
4950 $out .=
'<option value="' . $rule_for_lines_dates_key .
'" selected>';
4952 $out .=
'<option value="' . $rule_for_lines_dates_key .
'">';
4955 $out .= $langs->trans($rule_for_lines_dates_name);
4956 $out .=
'</option>';
4958 $out .=
'</select>';
4984 public function select_types_paiements($selected =
'', $htmlname =
'paiementtype', $filtertype =
'', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'', $nooutput = 0)
4987 global $langs, $user,
$conf;
4991 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $filtertype .
", " . $format, LOG_DEBUG);
4993 $filterarray = array();
4994 if ($filtertype ==
'CRDT') {
4995 $filterarray = array(0, 2, 3);
4996 } elseif ($filtertype ==
'DBIT') {
4997 $filterarray = array(1, 2, 3);
4998 } elseif ($filtertype !=
'' && $filtertype !=
'-1') {
4999 $filterarray = explode(
',', $filtertype);
5005 if (empty($selected) && strpos($htmlname,
'search_') !== 0 &&
getDolGlobalString(
'MAIN_DEFAULT_PAYMENT_TYPE_ID')) {
5006 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TYPE_ID", LOG_NOTICE);
5010 $out .=
'<select id="select' . $htmlname .
'" class="flat selectpaymenttypes' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
5012 $out .=
'<option value=""> </option>';
5014 foreach ($this->cache_types_paiements as
$id => $arraytypes) {
5016 if ($active >= 0 && $arraytypes[
'active'] != $active) {
5021 if (count($filterarray) && !in_array($arraytypes[
'type'], $filterarray)) {
5026 if ($empty && empty($arraytypes[
'code'])) {
5031 $out .=
'<option value="' .
$id .
'" data-code="'.$arraytypes[
'code'].
'"';
5032 } elseif ($format == 1) {
5033 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
5034 } elseif ($format == 2) {
5035 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
5036 } elseif ($format == 3) {
5037 $out .=
'<option value="' .
$id .
'"';
5040 if ($format == 1 || $format == 2) {
5041 if ($selected == $arraytypes[
'code']) {
5042 $out .=
' selected';
5045 if ($selected ==
$id) {
5046 $out .=
' selected';
5052 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
5053 } elseif ($format == 1) {
5054 $value = $arraytypes[
'code'];
5055 } elseif ($format == 2) {
5056 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
5057 } elseif ($format == 3) {
5058 $value = $arraytypes[
'code'];
5060 $out .= $value ? $value :
' ';
5061 $out .=
'</option>';
5063 $out .=
'</select>';
5064 if ($user->admin && !$noadmininfo) {
5065 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5069 if (empty($nooutput)) {
5089 $return =
'<select class="flat maxwidth100" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
5091 'HT' => $langs->trans(
"HT"),
5092 'TTC' => $langs->trans(
"TTC")
5094 foreach ($options as
$id => $value) {
5095 if ($selected ==
$id) {
5096 $return .=
'<option value="' .
$id .
'" selected>' . $value;
5098 $return .=
'<option value="' .
$id .
'">' . $value;
5100 $return .=
'</option>';
5102 $return .=
'</select>';
5122 $num = count($this->cache_transport_mode);
5129 $this->cache_transport_mode = array();
5131 $sql =
"SELECT rowid, code, label, active";
5132 $sql .=
" FROM " . $this->db->prefix() .
"c_transport_mode";
5133 $sql .=
" WHERE entity IN (" .
getEntity(
'c_transport_mode') .
")";
5135 $resql = $this->db->query($sql);
5137 $num = $this->db->num_rows($resql);
5140 $obj = $this->db->fetch_object($resql);
5143 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) !=
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
5144 $this->cache_transport_mode[$obj->rowid][
'rowid'] = $obj->rowid;
5145 $this->cache_transport_mode[$obj->rowid][
'code'] = $obj->code;
5146 $this->cache_transport_mode[$obj->rowid][
'label'] = $label;
5147 $this->cache_transport_mode[$obj->rowid][
'active'] = $obj->active;
5151 $this->cache_transport_mode =
dol_sort_array($this->cache_transport_mode,
'label',
'asc', 0, 0, 1);
5173 public function selectTransportMode($selected =
'', $htmlname =
'transportmode', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'')
5175 global $langs, $user;
5177 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $format, LOG_DEBUG);
5181 print
'<select id="select' . $htmlname .
'" class="flat selectmodetransport' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
5183 print
'<option value=""> </option>';
5185 foreach ($this->cache_transport_mode as
$id => $arraytypes) {
5187 if ($active >= 0 && $arraytypes[
'active'] != $active) {
5192 if ($empty && empty($arraytypes[
'code'])) {
5197 print
'<option value="' .
$id .
'"';
5198 } elseif ($format == 1) {
5199 print
'<option value="' . $arraytypes[
'code'] .
'"';
5200 } elseif ($format == 2) {
5201 print
'<option value="' . $arraytypes[
'code'] .
'"';
5202 } elseif ($format == 3) {
5203 print
'<option value="' .
$id .
'"';
5206 if (preg_match(
'/[a-z]/i', $selected) && $selected == $arraytypes[
'code']) {
5208 } elseif ($selected ==
$id) {
5214 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
5215 } elseif ($format == 1) {
5216 $value = $arraytypes[
'code'];
5217 } elseif ($format == 2) {
5218 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
5219 } elseif ($format == 3) {
5220 $value = $arraytypes[
'code'];
5222 print $value ? $value :
' ';
5229 if ($user->admin && !$noadmininfo) {
5230 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5246 public function selectShippingMethod($selected =
'', $htmlname =
'shipping_method_id', $filtre =
'', $useempty = 0, $moreattrib =
'', $noinfoadmin = 0, $morecss =
'')
5248 global $langs, $user;
5250 $langs->load(
"admin");
5251 $langs->load(
"deliveries");
5253 $sql =
"SELECT rowid, code, libelle as label";
5254 $sql .=
" FROM " . $this->db->prefix() .
"c_shipment_mode";
5255 $sql .=
" WHERE active > 0";
5257 $sql .=
" AND " . $filtre;
5259 $sql .=
" ORDER BY libelle ASC";
5261 dol_syslog(get_class($this) .
"::selectShippingMode", LOG_DEBUG);
5262 $result = $this->db->query($sql);
5264 $num = $this->db->num_rows($result);
5267 print
'<select id="select' . $htmlname .
'" class="flat selectshippingmethod' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5268 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5269 print
'<option value="-1"> </option>';
5272 $obj = $this->db->fetch_object($result);
5273 if ($selected == $obj->rowid) {
5274 print
'<option value="' . $obj->rowid .
'" selected>';
5276 print
'<option value="' . $obj->rowid .
'">';
5278 print ($langs->trans(
"SendingMethod" . strtoupper($obj->code)) !=
"SendingMethod" . strtoupper($obj->code)) ? $langs->trans(
"SendingMethod" . strtoupper($obj->code)) : $obj->label;
5283 if ($user->admin && empty($noinfoadmin)) {
5284 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5289 print $langs->trans(
"NoShippingMethodDefined");
5309 $langs->load(
"deliveries");
5311 if ($htmlname !=
"none") {
5312 print
'<form method="POST" action="' . $page .
'">';
5313 print
'<input type="hidden" name="action" value="setshippingmethod">';
5314 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5316 print
'<input type="submit" class="button valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5320 $code = $langs->getLabelFromKey($this->db, $selected,
'c_shipment_mode',
'rowid',
'code');
5321 print $langs->trans(
"SendingMethod" . strtoupper($code));
5340 $langs->load(
'bills');
5344 $sql =
"SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc";
5345 $sql .=
' FROM ' . $this->db->prefix() .
'facture';
5346 $sql .=
' WHERE entity IN (' .
getEntity(
'invoice') .
')';
5347 $sql .=
' AND situation_counter >= 1';
5348 $sql .=
' AND fk_soc = ' . (int) $socid;
5349 $sql .=
' AND type <> 2';
5350 $sql .=
' ORDER by situation_cycle_ref, situation_counter desc';
5351 $resql = $this->db->query($sql);
5353 $nbSituationInvoiceForThirdparty = 0;
5355 if ($resql && $this->db->num_rows($resql) > 0) {
5358 while ($obj = $this->db->fetch_object($resql)) {
5360 if ($obj->situation_cycle_ref != $ref) {
5362 $ref = $obj->situation_cycle_ref;
5364 if ($obj->situation_final != 1) {
5366 if (substr($obj->ref, 1, 4) !=
'PROV') {
5367 $nbSituationInvoiceForThirdparty++;
5369 if ($selected == $obj->rowid) {
5370 $opt .=
'<option value="' . $obj->rowid .
'" selected>' . $obj->ref .
'</option>';
5372 $opt .=
'<option value="' . $obj->rowid .
'">' . $obj->ref .
'</option>';
5379 dol_syslog(
"Error sql=" . $sql .
", error=" . $this->error, LOG_ERR);
5382 if ($nbSituationInvoiceForThirdparty > 0) {
5383 $opt =
'<option class="minwidth100" value="" selected> </option>'.$opt;
5385 $opt =
'<option class="minwidth100" value="-1" selected>'.$langs->trans(
'NoSituations').
'</option>';
5400 public function selectUnits($selected =
'', $htmlname =
'units', $showempty = 0, $unit_type =
'')
5404 $langs->load(
'products');
5406 $return =
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'">';
5408 $sql =
"SELECT rowid, label, code FROM " . $this->db->prefix() .
"c_units";
5409 $sql .=
' WHERE active > 0';
5410 if (!empty($unit_type)) {
5411 $sql .=
" AND unit_type = '" . $this->db->escape($unit_type) .
"'";
5413 $sql .=
" ORDER BY sortorder";
5415 $resql = $this->db->query($sql);
5416 if ($resql && $this->db->num_rows($resql) > 0) {
5418 $return .=
'<option value="-1"></option>';
5421 while ($res = $this->db->fetch_object($resql)) {
5422 $unitLabel = $res->label;
5423 if (!empty($langs->tab_translate[
'unit' . $res->code])) {
5424 $unitLabel = $langs->trans(
'unit' . $res->code) != $res->label ? $langs->trans(
'unit' . $res->code) : $res->label;
5427 if ($selected == $res->rowid) {
5428 $return .=
'<option value="' . $res->rowid .
'" selected>' . $unitLabel .
'</option>';
5430 $return .=
'<option value="' . $res->rowid .
'">' . $unitLabel .
'</option>';
5433 $return .=
'</select>';
5456 public function select_comptes($selected =
'', $htmlname =
'accountid', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'', $showcurrency = 0, $morecss =
'', $nooutput = 0)
5463 $langs->loadLangs(array(
"admin",
"banks"));
5466 $sql =
"SELECT rowid, label, bank, clos as status, currency_code";
5467 $sql .=
" FROM " . $this->db->prefix() .
"bank_account";
5468 $sql .=
" WHERE entity IN (" .
getEntity(
'bank_account') .
")";
5470 $sql .=
" AND clos = " . (int) $status;
5473 $sql .=
" AND " . $filtre;
5475 $sql .=
" ORDER BY label";
5477 dol_syslog(get_class($this) .
"::select_comptes", LOG_DEBUG);
5478 $result = $this->db->query($sql);
5480 $num = $this->db->num_rows($result);
5483 $out .=
'<select id="select' . $htmlname .
'" class="flat selectbankaccount' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5487 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoActiveBankAccountDefined") .
'</span>';
5489 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoBankAccountDefined") .
'</span>';
5492 if (!empty($useempty) && !is_numeric($useempty)) {
5493 $out .=
'<option value="-1">'.$langs->trans($useempty).
'</option>';
5494 } elseif ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5495 $out .=
'<option value="-1"> </option>';
5500 $obj = $this->db->fetch_object($result);
5502 $labeltoshow = trim($obj->label);
5503 $labeltoshowhtml = trim($obj->label);
5504 if ($showcurrency) {
5505 $labeltoshow .=
' (' . $obj->currency_code .
')';
5506 $labeltoshowhtml .=
' <span class="opacitymedium">(' . $obj->currency_code .
')</span>';
5508 if ($status == 2 && $obj->status == 1) {
5509 $labeltoshow .=
' (' . $langs->trans(
"Closed") .
')';
5510 $labeltoshowhtml .=
' <span class="opacitymedium">(' . $langs->trans(
"Closed") .
')</span>';
5513 if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
5514 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml).
'" selected>';
5516 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml).
'">';
5518 $out .= $labeltoshow;
5519 $out .=
'</option>';
5522 $out .=
"</select>";
5529 if (empty($nooutput)) {
5551 public function selectRib($selected =
'', $htmlname =
'ribcompanyid', $filtre =
'', $useempty = 0, $moreattrib =
'', $showibanbic = 0, $morecss =
'', $nooutput = 0)
5558 $langs->loadLangs(array(
"admin",
"banks"));
5561 $sql =
"SELECT rowid, label, bank, status, iban_prefix, bic";
5562 $sql .=
" FROM " . $this->db->prefix() .
"societe_rib";
5563 $sql .=
" WHERE type = 'ban'";
5565 $sql .=
" AND " . $filtre;
5567 $sql .=
" ORDER BY label";
5568 dol_syslog(get_class($this) .
"::select_comptes", LOG_DEBUG);
5569 $result = $this->db->query($sql);
5571 $num = $this->db->num_rows($result);
5574 $out .=
'<select id="select' . $htmlname .
'" class="flat selectbankaccount' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5577 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoBankAccountDefined") .
'</span>';
5579 if (!empty($useempty) && !is_numeric($useempty)) {
5580 $out .=
'<option value="-1">'.$langs->trans($useempty).
'</option>';
5581 } elseif ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5582 $out .=
'<option value="-1"> </option>';
5587 $obj = $this->db->fetch_object($result);
5589 if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
5590 $out .=
'<option value="' . $obj->rowid .
'" data-iban-prefix="' . $iban .
' data-bic="' . $obj->bic .
'" selected>';
5592 $out .=
'<option value="' . $obj->rowid .
'" data-iban-prefix="' . $iban .
' data-bic="' . $obj->bic .
'">';
5594 $out .= trim($obj->label);
5596 $out .=
' (' . $iban .
'/' .$obj->bic.
')';
5598 $out .=
'</option>';
5601 $out .=
"</select>";
5608 if (empty($nooutput)) {
5628 public function selectEstablishments($selected =
'', $htmlname =
'entity', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'')
5632 $langs->load(
"admin");
5635 $sql =
"SELECT rowid, name, fk_country, status, entity";
5636 $sql .=
" FROM " . $this->db->prefix() .
"establishment";
5637 $sql .=
" WHERE 1=1";
5639 $sql .=
" AND status = " . (int) $status;
5642 $sql .=
" AND " . $filtre;
5644 $sql .=
" ORDER BY name";
5646 dol_syslog(get_class($this) .
"::select_establishment", LOG_DEBUG);
5647 $result = $this->db->query($sql);
5649 $num = $this->db->num_rows($result);
5652 print
'<select id="select' . $htmlname .
'" class="flat selectestablishment" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5653 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5654 print
'<option value="-1"> </option>';
5658 $obj = $this->db->fetch_object($result);
5659 if ($selected == $obj->rowid) {
5660 print
'<option value="' . $obj->rowid .
'" selected>';
5662 print
'<option value="' . $obj->rowid .
'">';
5664 print trim($obj->name);
5665 if ($status == 2 && $obj->status == 1) {
5666 print
' (' . $langs->trans(
"Closed") .
')';
5674 print
'<span class="opacitymedium">' . $langs->trans(
"NoActiveEstablishmentDefined") .
'</span>';
5676 print
'<span class="opacitymedium">' . $langs->trans(
"NoEstablishmentFound") .
'</span>';
5699 if ($htmlname !=
"none") {
5700 print
'<form method="POST" action="' . $page .
'">';
5701 print
'<input type="hidden" name="action" value="setbankaccount">';
5702 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5703 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
5704 $nbaccountfound = $this->
select_comptes($selected, $htmlname, 0,
'', $addempty);
5705 if ($nbaccountfound > 0) {
5706 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5710 $langs->load(
'banks');
5713 require_once DOL_DOCUMENT_ROOT .
'/compta/bank/class/account.class.php';
5714 $bankstatic =
new Account($this->db);
5715 $result = $bankstatic->fetch((
int) $selected);
5717 print $bankstatic->getNomUrl(1);
5736 public function formRib($page, $selected =
'', $htmlname =
'ribcompanyid', $filtre =
'', $addempty = 0, $showibanbic = 0)
5739 if ($htmlname !=
"none") {
5740 print
'<form method="POST" action="' . $page .
'">';
5741 print
'<input type="hidden" name="action" value="setbankaccountcustomer">';
5742 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5743 $nbaccountfound = $this->
selectRib($selected, $htmlname, $filtre, $addempty,
'', $showibanbic);
5744 if ($nbaccountfound > 0) {
5745 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5749 $langs->load(
'banks');
5752 require_once DOL_DOCUMENT_ROOT .
'/societe/class/companybankaccount.class.php';
5754 $result = $bankstatic->fetch((
int) $selected);
5756 print $bankstatic->label;
5758 print
' (' . $bankstatic->iban .
'/' .$bankstatic->bic.
')';
5786 $arrayselected = array();
5788 $arrayselected =
GETPOST($htmlname,
'array:int');
5791 $cats =
$c->containing(
$object->id, $categtype);
5792 $arrayselected = array();
5793 foreach ($cats as $cat) {
5794 $arrayselected[] = $cat->id;
5798 $out .=
img_picto(
'',
'category',
'class="pictofixedwidth"');
5799 $out .= $this->
multiselectarray($htmlname, $cate_arbo, $arrayselected, 0, 0,
'minwidth100 widthcentpercentminusxx', 0, 0);
5803 $jsonclose =
'doJsCodeAfterPopupClose'.$htmlname.
'()';
5804 $urltoopen =
'/categories/categorie_list.php?type='.urlencode($categtype).
'&nosearch=1';
5809 $out .=
'<!-- Add js code to open the popup for category/edit/add -->'.
"\n";
5810 $out .=
'<script>function doJsCodeAfterPopupClose'.$htmlname.
'() {
5811 console.log("doJsCodeAfterPopupClose'.$htmlname.
' has been called, we refresh the combo content + refresh select2...");
5813 // Call an ajax to reload values and update the select
5814 // $("#'.
dol_escape_js($htmlname).
'").append(new Option("Option 4", "4"));
5816 // Refresh select2 to take account of new values (enough for small change)
5819 url: \''.DOL_URL_ROOT.
'/core/ajax/fetchCategories.php\',
5821 action: \'getCategories\',
5826 success: function (data) {
5827 var $select = $(\'#'.dol_escape_js($htmlname).
'\');
5828 var selectedValues = $select.val();
5829 console.log(selectedValues);
5831 $.each(data,
function (index, item) {
5832 $select.append(\
'<option value="\' + item.id + \'" data-html="\' + item.htmlforattribute + \'">\' + item.htmlforoption + \'</option>\');
5834 $select.val(selectedValues);
5836 error: function (xhr, status, error) {
5837 console.log("Error when loading ajax page : " + error);
5842 // Alternative if change in select is complex
5873 public function select_all_categories($type, $selected =
'', $htmlname =
"parent", $maxlength = 64, $fromid = 0, $outputmode = 0, $include = 0, $morecss =
'', $useempty = 1)
5878 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
5882 if (is_numeric($type)) {
5883 $type = array_search($type, $cat->MAP_ID);
5886 $cate_arbo = $cat->get_full_arbo($type, $fromid, $include);
5888 $outarray = array();
5889 $outarrayrichhtml = array();
5892 $output =
'<select class="flat minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
5893 if (is_array($cate_arbo)) {
5894 $num = count($cate_arbo);
5897 $langs->load(
"categories");
5898 $output .=
'<option value="-1" disabled>' . $langs->trans(
"NoCategoriesDefined") .
'</option>';
5900 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5901 $output .=
'<option value="-1"> </option>';
5903 foreach ($cate_arbo as $key => $value) {
5904 if ($cate_arbo[$key][
'id'] == $selected || ($selected ===
'auto' && count($cate_arbo) == 1)) {
5910 $labeltoshow =
img_picto(
'',
'category',
'class="pictofixedwidth"'.(empty($cate_arbo[$key][
'color']) ?
'' :
' style="color: #' . $cate_arbo[$key][
'color'] .
'"'));
5911 $labeltoshow .=
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle');
5913 $outarray[$cate_arbo[$key][
'id']] = $cate_arbo[$key][
'fulllabel'];
5915 $outarrayrichhtml[$cate_arbo[$key][
'id']] = $labeltoshow;
5917 $output .=
'<option ' . $add .
'value="' . $cate_arbo[$key][
'id'] .
'"';
5920 $output .=
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle');
5921 $output .=
'</option>';
5923 $cate_arbo[$key][
'data-html'] = $labeltoshow;
5927 $output .=
'</select>';
5930 $this->num = count($cate_arbo);
5932 if ($outputmode == 2) {
5935 } elseif ($outputmode == 1) {
5937 } elseif ($outputmode == 3) {
5938 return $outarrayrichhtml;
5963 public function form_confirm($page, $title, $question, $action, $formquestion = array(), $selectedchoice =
"", $useajax = 0, $height = 170, $width = 500)
5966 dol_syslog(__METHOD__ .
': using form_confirm is deprecated. Use formconfim instead.', LOG_WARNING);
5967 print $this->
formconfirm($page, $title, $question, $action, $formquestion, $selectedchoice, $useajax, $height, $width);
5996 public function formconfirm($page, $title, $question, $action, $formquestion =
'', $selectedchoice =
'', $useajax = 0, $height = 0, $width = 500, $disableformtag = 0, $labelbuttonyes =
'Yes', $labelbuttonno =
'No')
5998 global $langs,
$conf;
6001 $formconfirm =
'<!-- formconfirm - before call, page=' .
dol_escape_htmltag($page) .
' -->';
6007 $newselectedchoice = empty($selectedchoice) ?
"no" : $selectedchoice;
6008 if (
$conf->browser->layout ==
'phone') {
6013 if (empty($height)) {
6015 if (is_array($formquestion) && count($formquestion) > 2) {
6016 $height += ((count($formquestion) - 2) * 24);
6020 if (is_array($formquestion) && !empty($formquestion)) {
6022 foreach ($formquestion as $key => $input) {
6023 if (is_array($input) && !empty($input)) {
6024 if ($input[
'type'] ==
'hidden') {
6025 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
6026 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
6034 $moreonecolumn =
'';
6035 $more .=
'<div class="tagtable paddingtopbottomonly centpercent noborderspacing">' .
"\n";
6036 foreach ($formquestion as $key => $input) {
6037 if (is_array($input) && !empty($input)) {
6038 $size = (!empty($input[
'size']) ?
' size="' . $input[
'size'] .
'"' :
'');
6039 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
6040 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
6042 if ($input[
'type'] ==
'text' || $input[
'type'] ==
'input') {
6043 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">' . ($input[
'label'] ??
'') .
'</div><div class="tagtd"><input type="text" class="flat' . $morecss .
'" id="' .
dol_escape_htmltag($input[
'name']) .
'" name="' .
dol_escape_htmltag($input[
'name']) .
'"' . $size .
' value="' . (empty($input[
'value']) ?
'' : $input[
'value']) .
'"' . $moreattr .
' /></div></div>' .
"\n";
6044 } elseif ($input[
'type'] ==
'password') {
6045 $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";
6046 } elseif ($input[
'type'] ==
'textarea') {
6047 $moreonecolumn .=
'<div class="margintoponly">';
6048 $moreonecolumn .= $input[
'label'] .
'<br>';
6050 $moreonecolumn .= $input[
'value'];
6051 $moreonecolumn .=
'</textarea>';
6052 $moreonecolumn .=
'</div>';
6053 } elseif (in_array($input[
'type'], [
'select',
'multiselect'])) {
6054 if (empty($morecss)) {
6055 $morecss =
'minwidth100';
6058 $show_empty = isset($input[
'select_show_empty']) ? $input[
'select_show_empty'] : 1;
6059 $key_in_label = isset($input[
'select_key_in_label']) ? $input[
'select_key_in_label'] : 0;
6060 $value_as_key = isset($input[
'select_value_as_key']) ? $input[
'select_value_as_key'] : 0;
6061 $translate = isset($input[
'select_translate']) ? $input[
'select_translate'] : 0;
6062 $maxlen = isset($input[
'select_maxlen']) ? $input[
'select_maxlen'] : 0;
6063 $disabled = isset($input[
'select_disabled']) ? $input[
'select_disabled'] : 0;
6064 $sort = isset($input[
'select_sort']) ? $input[
'select_sort'] :
'';
6066 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">';
6067 if (!empty($input[
'label'])) {
6068 $more .= $input[
'label'] .
'</div><div class="tagtd left">';
6070 if ($input[
'type'] ==
'select') {
6071 $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);
6073 $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);
6075 $more .=
'</div></div>' .
"\n";
6076 } elseif ($input[
'type'] ==
'checkbox') {
6077 $more .=
'<div class="tagtr">';
6078 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'"><label for="' .
dol_escape_htmltag($input[
'name']) .
'">' . $input[
'label'] .
'</label></div><div class="tagtd">';
6079 $more .=
'<input type="checkbox" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' .
dol_escape_htmltag($input[
'name']) .
'" name="' .
dol_escape_htmltag($input[
'name']) .
'"' . $moreattr;
6080 if (!is_bool($input[
'value']) && $input[
'value'] !=
'false' && $input[
'value'] !=
'0' && $input[
'value'] !=
'') {
6081 $more .=
' checked';
6083 if (is_bool($input[
'value']) && $input[
'value']) {
6084 $more .=
' checked';
6086 if (isset($input[
'disabled'])) {
6087 $more .=
' disabled';
6089 $more .=
' /></div>';
6090 $more .=
'</div>' .
"\n";
6091 } elseif ($input[
'type'] ==
'radio') {
6093 foreach ($input[
'values'] as $selkey => $selval) {
6094 $more .=
'<div class="tagtr">';
6095 if (isset($input[
'label'])) {
6097 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
' tdtop' : (
' tdtop ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
6099 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' "' . $input[
'tdclass'])) .
'"> </div>';
6102 $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;
6103 if (!empty($input[
'disabled'])) {
6104 $more .=
' disabled';
6106 if (isset($input[
'default']) && $input[
'default'] === $selkey) {
6107 $more .=
' checked="checked"';
6110 $more .=
'<label for="' .
dol_escape_htmltag($input[
'name'] . $selkey) .
'" class="valignmiddle">' . $selval .
'</label>';
6111 $more .=
'</div></div>' .
"\n";
6114 } elseif ($input[
'type'] ==
'date' || $input[
'type'] ==
'datetime') {
6115 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
6116 $more .=
'<div class="tagtd">';
6117 $addnowlink = (empty($input[
'datenow']) ? 0 : 1);
6119 if ($input[
'type'] ==
'datetime') {
6120 $h = isset($input[
'hours']) ? $input[
'hours'] : 1;
6121 $m = isset($input[
'minutes']) ? $input[
'minutes'] : 1;
6123 $more .= $this->
selectDate(isset($input[
'value']) ? $input[
'value'] : -1, $input[
'name'], $h, $m, 0,
'', 1, $addnowlink);
6124 $more .=
'</div></div>'.
"\n";
6125 $formquestion[] = array(
'name' => $input[
'name'].
'day');
6126 $formquestion[] = array(
'name' => $input[
'name'].
'month');
6127 $formquestion[] = array(
'name' => $input[
'name'].
'year');
6128 $formquestion[] = array(
'name' => $input[
'name'].
'hour');
6129 $formquestion[] = array(
'name' => $input[
'name'].
'min');
6130 } elseif ($input[
'type'] ==
'other') {
6131 $more .=
'<div class="tagtr"><div class="tagtd'.(empty($input[
'tdclass']) ?
'' : (
' '.$input[
'tdclass'])).
'">';
6132 if (!empty($input[
'label'])) {
6133 $more .= $input[
'label'] .
'</div><div class="tagtd">';
6135 if (!empty($input[
'value'])) {
6136 $more .= $input[
'value'];
6138 $more .=
'</div></div>' .
"\n";
6139 } elseif ($input[
'type'] ==
'onecolumn') {
6140 $moreonecolumn .=
'<div class="margintoponly">';
6141 $moreonecolumn .= $input[
'value'];
6142 $moreonecolumn .=
'</div>' .
"\n";
6143 } elseif ($input[
'type'] ==
'hidden') {
6145 } elseif ($input[
'type'] ==
'separator') {
6148 $more .=
'Error type ' . $input[
'type'] .
' for the confirm box is not a supported type';
6152 $more .=
'</div>' .
"\n";
6153 $more .= $moreonecolumn;
6159 if (!empty(
$conf->dol_use_jmobile)) {
6162 if (empty(
$conf->use_javascript_ajax)) {
6168 $dialogconfirm =
'dialog-confirm';
6170 if (!is_numeric($useajax)) {
6174 $dialogconfirm .=
'-' . $button;
6176 $pageyes = $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=yes';
6177 $pageno = ($useajax == 2 ? $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=no' :
'');
6180 if (is_array($formquestion)) {
6181 foreach ($formquestion as $key => $input) {
6184 if (is_array($input) && isset($input[
'name'])) {
6185 if (strpos($input[
'name'],
',') > 0) {
6186 $inputok = array_merge($inputok, explode(
',', $input[
'name']));
6188 array_push($inputok, $input[
'name']);
6193 if (is_array($input) && isset($input[
'inputko']) && $input[
'inputko'] == 1 && isset($input[
'name'])) {
6194 array_push($inputko, $input[
'name']);
6200 $formconfirm .=
'<div id="' . $dialogconfirm .
'" title="' .
dol_escape_htmltag($title) .
'" style="display: none;">';
6201 if (is_array($formquestion) && array_key_exists(
'text', $formquestion) && !empty($formquestion[
'text'])) {
6202 $formconfirm .=
'<div class="confirmtext">' . $formquestion[
'text'] .
'</div>' .
"\n";
6204 if (!empty($more)) {
6205 $formconfirm .=
'<div class="confirmquestions">' . $more .
'</div>' .
"\n";
6207 $formconfirm .= ($question ?
'<div class="confirmmessage">' .
img_help(0,
'') .
' ' . $question .
'</div>' :
'');
6208 $formconfirm .=
'</div>' .
"\n";
6210 $formconfirm .=
"\n<!-- begin code of popup for formconfirm page=" . $page .
" -->\n";
6211 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
6212 $formconfirm .=
"/* Code for the jQuery('#dialogforpopup').dialog() */\n";
6213 $formconfirm .=
'jQuery(document).ready(function() {
6215 $( "#' . $dialogconfirm .
'" ).dialog(
6217 autoOpen: ' . ($autoOpen ?
"true" :
"false") .
',';
6218 if ($newselectedchoice ==
'no') {
6221 $(this).parent().find("button.ui-button:eq(2)").focus();
6226 if ($useajax == 1) {
6227 $jsforcursor =
'// The call to urljump can be slow, so we set the wait cursor' .
"\n";
6228 $jsforcursor .=
'jQuery("html,body,#id-container").addClass("cursorwait");' .
"\n";
6231 $postconfirmas =
'GET';
6238 closeOnEscape:
false,
6240 "' . dol_escape_js($langs->transnoentities($labelbuttonyes)) . '":
function() {
6241 var options =
"token=' . urlencode(newToken()) . '";
6242 var inputok =
' . json_encode($inputok) . ';
6243 var page = \
'' .
dol_escape_js(!empty($page) ? $page :
'') .
'\';
6244 var pageyes = \
'' .
dol_escape_js(!empty($pageyes) ? $pageyes :
'') .
'\';
6246 if (inputok.length > 0) {
6247 $.each(inputok,
function(i, inputname) {
6250 if ($(
"input[name=\'" + inputname +
"\']").attr(
"type") ==
"radio") {
6251 inputvalue = $(
"input[name=\'" + inputname +
"\']:checked").val();
6253 if ($(
"#" + inputname).attr(
"type") ==
"checkbox") { more =
":checked"; }
6254 inputvalue = $(
"#" + inputname + more).val();
6256 if (typeof inputvalue ==
"undefined") { inputvalue=
""; }
6257 console.log(
"formconfirm check inputname="+inputname+
" inputvalue="+inputvalue);
6258 options +=
"&" + inputname +
"=" + encodeURIComponent(inputvalue);
6261 var urljump = pageyes + (pageyes.indexOf(
"?") < 0 ?
"?" :
"&") + options;
6262 if (pageyes.length > 0) {
';
6263 if ($postconfirmas == 'GET
') {
6264 $formconfirm .= 'location.href = urljump;
';
6266 $formconfirm .= $jsforcursor;
6267 $formconfirm .= 'var post = $.post(
6270 function(data) { $(
"body").html(data); jQuery(
"html,body,#id-container").removeClass(
"cursorwait"); }
6274 console.log(
"after post ok");
6276 $(
this).dialog(
"close");
6278 "' . dol_escape_js($langs->transnoentities($labelbuttonno)) . '":
function() {
6279 var options =
"token=' . urlencode(newToken()) . '";
6280 var inputko =
' . json_encode($inputko) . ';
6281 var page =
"' . dol_escape_js(!empty($page) ? $page : '') . '";
6282 var pageno=
"' . dol_escape_js(!empty($pageno) ? $pageno : '') . '";
6283 if (inputko.length > 0) {
6284 $.each(inputko,
function(i, inputname) {
6286 if ($(
"#" + inputname).attr(
"type") ==
"checkbox") { more =
":checked"; }
6287 var inputvalue = $(
"#" + inputname + more).val();
6288 if (typeof inputvalue ==
"undefined") { inputvalue=
""; }
6289 options +=
"&" + inputname +
"=" + encodeURIComponent(inputvalue);
6292 var urljump=pageno + (pageno.indexOf(
"?") < 0 ?
"?" :
"&") + options;
6294 if (pageno.length > 0) {
';
6295 if ($postconfirmas == 'GET
') {
6296 $formconfirm .= 'location.href = urljump;
';
6298 $formconfirm .= $jsforcursor;
6299 $formconfirm .= 'var post = $.post(
6302 function(data) { $(
"body").html(data); jQuery(
"html,body,#id-container").removeClass(
"cursorwait"); }
6306 console.log(
"after post ko");
6308 $(
this).dialog(
"close");
6314 var
button =
"' . $button . '";
6316 $(
"#" +
button ).click(
function() {
6317 $(
"#' . $dialogconfirm . '").dialog(
"open");
6323 $formconfirm .= "<!-- end ajax formconfirm -->\n";
6325 $formconfirm .= "\n<!-- begin formconfirm page=" . dol_escape_htmltag($page) . " -->\n";
6327 if (empty($disableformtag)) {
6328 $formconfirm .= '<form method=
"POST" action=
"' . $page . '" class=
"notoptoleftnoright">
' . "\n";
6331 $formconfirm .= '<input
type=
"hidden" name=
"action" value=
"' . $action . '">
' . "\n";
6332 $formconfirm .= '<input
type=
"hidden" name=
"token" value=
"' . newToken() . '">
' . "\n";
6334 $formconfirm .= '<
table class=
"valid centpercent">
' . "\n";
6337 $formconfirm .= '<tr
class=
"validtitre"><td
class=
"validtitre" colspan=
"2">
';
6338 $formconfirm .= img_picto('', 'pictoconfirm
') . ' ' . $title;
6339 $formconfirm .= '</td></tr>
' . "\n";
6342 if (is_array($formquestion) && array_key_exists('text
', $formquestion) && !empty($formquestion['text
'])) {
6343 $formconfirm .= '<tr
class=
"valid"><td
class=
"valid" colspan=
"2">
' . $formquestion['text
'] . '</td></tr>
' . "\n";
6348 $formconfirm .= '<tr
class=
"valid"><td
class=
"valid" colspan=
"2">
' . "\n";
6349 $formconfirm .= $more;
6350 $formconfirm .= '</td></tr>
' . "\n";
6353 // Line with question
6354 $formconfirm .= '<tr
class=
"valid">
';
6355 $formconfirm .= '<td
class=
"valid">
' . $question . '</td>
';
6356 $formconfirm .= '<td
class=
"valid center">
';
6357 $formconfirm .= $this->selectyesno("confirm", $newselectedchoice, 0, false, 0, 0, 'marginleftonly marginrightonly
', $labelbuttonyes, $labelbuttonno);
6358 $formconfirm .= '<input
class=
"button valignmiddle confirmvalidatebutton small" type=
"submit" value=
"' . $langs->trans("Validate") . '">
';
6359 $formconfirm .= '</td>
';
6360 $formconfirm .= '</tr>
' . "\n";
6362 $formconfirm .= '</
table>
' . "\n";
6364 if (empty($disableformtag)) {
6365 $formconfirm .= "</form>\n";
6367 $formconfirm .= '<br>
';
6369 if (!empty($conf->use_javascript_ajax)) {
6370 $formconfirm .= '<!-- code to disable
button to avoid
double clic -->
';
6371 $formconfirm .= '<script nonce=
"' . getNonce() . '" type=
"text/javascript">
' . "\n";
6373 $(document).ready(
function () {
6374 $(
".confirmvalidatebutton").on(
"click",
function() {
6375 console.log(
"We click on button confirmvalidatebutton");
6376 $(
this).attr(
"disabled",
"disabled");
6377 setTimeout(\
'$(".confirmvalidatebutton").removeAttr("disabled")\', 3000);
6378 //console.log($(this).closest("form"));
6379 $(this).closest("form").submit();
6383 $formconfirm .=
'</script>' .
"\n";
6386 $formconfirm .=
"<!-- end formconfirm -->\n";
6389 return $formconfirm;
6410 public function form_project($page, $socid, $selected =
'', $htmlname =
'projectid', $discard_closed = 0, $maxlength = 20, $forcefocus = 0, $nooutput = 0, $textifnoproject =
'', $morecss =
'')
6415 require_once DOL_DOCUMENT_ROOT .
'/core/lib/project.lib.php';
6416 require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formprojet.class.php';
6422 $langs->load(
"project");
6423 if ($htmlname !=
"none") {
6424 $out .=
'<form method="post" action="' . $page .
'">';
6425 $out .=
'<input type="hidden" name="action" value="classin">';
6426 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6427 $out .= $formproject->select_projects($socid, $selected, $htmlname, $maxlength, 0, 1, $discard_closed, $forcefocus, 0, 0,
'', 1, 0, $morecss);
6428 $out .=
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6431 $out .=
'<span class="project_head_block">';
6433 $projet =
new Project($this->db);
6434 $projet->fetch((
int) $selected);
6435 $out .= $projet->getNomUrl(0,
'', 1);
6437 $out .=
'<span class="opacitymedium">' . $textifnoproject .
'</span>';
6442 if (empty($nooutput)) {
6466 public function form_conditions_reglement($page, $selected =
'', $htmlname =
'cond_reglement_id', $addempty = 0, $type =
'', $filtertype = -1, $deposit_percent = -1, $nooutput = 0)
6473 if ($htmlname !=
"none") {
6474 $out .=
'<form method="POST" action="' . $page .
'">';
6475 $out .=
'<input type="hidden" name="action" value="setconditions">';
6476 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6478 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
6480 $out .= $this->getSelectConditionsPaiements((
int) $selected, $htmlname, $filtertype, $addempty, 0,
'', $deposit_percent);
6481 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6485 $this->load_cache_conditions_paiements();
6486 if (isset($this->cache_conditions_paiements[$selected])) {
6487 $label = $this->cache_conditions_paiements[$selected][
'label'];
6489 if (!empty($this->cache_conditions_paiements[$selected][
'deposit_percent'])) {
6490 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $this->cache_conditions_paiements[$selected][
'deposit_percent'], $label);
6495 $langs->load(
'errors');
6496 $out .= $langs->trans(
'ErrorNotInDictionaryPaymentConditions');
6503 if (empty($nooutput)) {
6528 if ($htmlname !=
'none') {
6529 $out .=
'<form method="POST" action="' . $page .
'">';
6530 $out .=
'<input type="hidden" name="action" value="setruleforlinesdates">';
6531 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6532 $out .= $this->getSelectRuleForLinesDates($selected, $htmlname, $addempty);
6533 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6536 if (isset($selected)) {
6537 $this->load_cache_rule_for_lines_dates();
6538 if (isset($this->cache_rule_for_lines_dates[$selected])) {
6539 $label = $this->cache_rule_for_lines_dates[$selected];
6540 $out .= $langs->trans($label);
6547 if (empty($nooutput)) {
6570 if ($htmlname !=
"none") {
6571 print
'<form method="post" action="' . $page .
'">';
6572 print
'<input type="hidden" name="action" value="setavailability">';
6573 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6574 $this->selectAvailabilityDelay($selected, $htmlname,
'', $addempty);
6575 print
'<input type="submit" name="modify" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6576 print
'<input type="submit" name="cancel" class="button smallpaddingimp" value="' . $langs->trans(
"Cancel") .
'">';
6580 $this->load_cache_availability();
6581 print $this->cache_availability[$selected][
'label'];
6598 public function formInputReason($page, $selected =
'', $htmlname =
'demandreason', $addempty = 0)
6601 if ($htmlname !=
"none") {
6602 print
'<form method="post" action="' . $page .
'">';
6603 print
'<input type="hidden" name="action" value="setdemandreason">';
6604 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6605 $this->selectInputReason($selected, $htmlname,
'-1', $addempty);
6606 print
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6610 $this->loadCacheInputReason();
6611 foreach ($this->cache_demand_reason as $key => $val) {
6612 if ($val[
'id'] == $selected) {
6613 print $val[
'label'];
6638 public function form_date($page, $selected, $htmlname, $displayhour = 0, $displaymin = 0, $nooutput = 0, $type =
'')
6645 if ($htmlname !=
"none") {
6646 $ret .=
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
6647 $ret .=
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
6648 $ret .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6650 $ret .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
6652 $ret .=
'<table class="nobordernopadding">';
6654 $ret .= $this->selectDate($selected, $htmlname, $displayhour, $displaymin, 1,
'form' . $htmlname, 1, 0);
6656 $ret .=
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
6657 $ret .=
'</tr></table></form>';
6666 if (empty($nooutput)) {
6685 public function form_users($page, $selected =
'', $htmlname =
'userid', $exclude = array(), $include = array())
6690 if ($htmlname !=
"none") {
6691 print
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
6692 print
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
6693 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6694 print $this->select_dolusers($selected, $htmlname, 1, $exclude, 0, $include);
6695 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6699 require_once DOL_DOCUMENT_ROOT .
'/user/class/user.class.php';
6700 $theuser =
new User($this->db);
6701 $theuser->fetch((
int) $selected);
6702 print $theuser->getNomUrl(1);
6725 public function form_modes_reglement($page, $selected =
'', $htmlname =
'mode_reglement_id', $filtertype =
'', $active = 1, $addempty = 0, $type =
'', $nooutput = 0)
6731 if ($htmlname !=
"none") {
6732 $out .=
'<form method="POST" action="' . $page .
'">';
6733 $out .=
'<input type="hidden" name="action" value="setmode">';
6734 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6736 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
6738 $out .= $this->select_types_paiements($selected, $htmlname, $filtertype, 0, $addempty, 0, 0, $active,
'', 1);
6739 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6743 $this->load_cache_types_paiements();
6744 $out .= $this->cache_types_paiements[$selected][
'label'];
6771 if ($htmlname !=
"none") {
6772 print
'<form method="POST" action="' . $page .
'">';
6773 print
'<input type="hidden" name="action" value="settransportmode">';
6774 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6775 $this->selectTransportMode($selected, $htmlname, 0, $addempty, 0, 0, $active);
6776 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6780 $this->load_cache_transport_mode();
6781 print $this->cache_transport_mode[$selected][
'label'];
6802 if ($htmlname !=
"none") {
6803 print
'<form method="POST" action="' . $page .
'">';
6804 print
'<input type="hidden" name="action" value="setmulticurrencycode">';
6805 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6806 print $this->selectMultiCurrency($selected, $htmlname, 0);
6807 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6810 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
6811 print !empty($selected) ?
currency_name($selected, 1) :
' ';
6829 global $langs,
$conf;
6831 if ($htmlname !=
"none") {
6832 print
'<form method="POST" action="' . $page .
'">';
6833 print
'<input type="hidden" name="action" value="setmulticurrencyrate">';
6834 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6835 print
'<input type="text" class="maxwidth75" name="' . $htmlname .
'" value="' . (!empty($rate) ?
price(
price2num($rate,
'CU')) : 1) .
'" /> ';
6836 print
'<select name="calculation_mode" id="calculation_mode">';
6837 print
'<option value="1">Change ' . $langs->trans(
"PriceUHT") .
' of lines</option>';
6838 print
'<option value="2">Change ' . $langs->trans(
"PriceUHTCurrency") .
' of lines</option>';
6841 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6844 if (!empty($rate)) {
6845 print
price($rate, 1, $langs, 0, 0);
6846 if ($currency && $rate != 1) {
6847 print
' <span class="opacitymedium">(' .
price($rate, 1, $langs, 0, 0) .
' ' . $currency .
' = 1 ' .
$conf->currency .
')</span>';
6872 public function form_remise_dispo($page, $selected, $htmlname, $socid, $amount, $filter =
'', $maxvalue = 0, $more =
'', $hidelist = 0, $discount_type = 0)
6875 global
$conf, $langs;
6877 if ($htmlname !=
"none") {
6878 print
'<form method="post" action="' . $page .
'">';
6879 print
'<input type="hidden" name="action" value="setabsolutediscount">';
6880 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6881 print
'<div class="inline-block">';
6882 if (!empty($discount_type)) {
6884 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL") {
6885 $translationKey =
'HasAbsoluteDiscountFromSupplier';
6887 $translationKey =
'HasCreditNoteFromSupplier';
6890 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
6891 $translationKey =
'HasAbsoluteDiscountFromSupplier';
6893 $translationKey =
'HasCreditNoteFromSupplier';
6898 if (!$filter || $filter ==
"fk_facture_source IS NULL") {
6899 $translationKey =
'CompanyHasAbsoluteDiscount';
6901 $translationKey =
'CompanyHasCreditNote';
6904 if (!$filter || $filter ==
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
6905 $translationKey =
'CompanyHasAbsoluteDiscount';
6907 $translationKey =
'CompanyHasCreditNote';
6911 print $langs->trans($translationKey,
price($amount, 0, $langs, 0, 0, -1,
$conf->currency));
6912 if (empty($hidelist)) {
6916 if (empty($hidelist)) {
6917 print
'<div class="inline-block" style="padding-right: 10px">';
6918 $newfilter =
'discount_type=' . intval($discount_type);
6919 if (!empty($discount_type)) {
6920 $newfilter .=
' AND fk_invoice_supplier IS NULL AND fk_invoice_supplier_line IS NULL';
6922 $newfilter .=
' AND fk_facture IS NULL AND fk_facture_line IS NULL';
6925 $newfilter .=
' AND (' . $filter .
')';
6928 $nbqualifiedlines = $this->select_remises((
string) $selected, $htmlname, $newfilter, $socid, $maxvalue);
6929 if ($nbqualifiedlines > 0) {
6930 print
' <input type="submit" class="button smallpaddingimp" value="' .
dol_escape_htmltag($langs->trans(
"UseLine")) .
'"';
6931 if (!empty($discount_type) && $filter && $filter !=
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
6932 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
6934 if (empty($discount_type) && $filter && $filter !=
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
6935 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
6943 print
'<div class="inline-block">';
6969 public function form_contacts($page, $societe, $selected =
'', $htmlname =
'contactid')
6974 if ($htmlname !=
"none") {
6975 print
'<form method="post" action="' . $page .
'">';
6976 print
'<input type="hidden" name="action" value="set_contact">';
6977 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6978 print
'<table class="nobordernopadding">';
6980 print $this->selectcontacts($societe->id, $selected, $htmlname);
6983 $addcontact = (
getDolGlobalString(
'SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans(
"AddContact") : $langs->trans(
"AddContactAddress"));
6984 print
'<a href="' . DOL_URL_ROOT .
'/contact/card.php?socid=' . $societe->id .
'&action=create&backtoreferer=1">' . $addcontact .
'</a>';
6987 print
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
6988 print
'</tr></table></form>';
6991 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
6992 $contact =
new Contact($this->db);
6993 $contact->fetch((
int) $selected);
6994 print $contact->getFullName($langs);
7019 public function form_thirdparty($page, $selected =
'', $htmlname =
'socid', $filter =
'', $showempty = 0, $showtype = 0, $forcecombo = 0, $events = array(), $nooutput = 0, $excludeids = array(), $textifnothirdparty =
'')
7025 if ($htmlname !=
"none") {
7026 $out .=
'<form method="post" action="' . $page .
'">';
7027 $out .=
'<input type="hidden" name="action" value="set_thirdparty">';
7028 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
7029 $out .= $this->select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, 0,
'minwidth100',
'',
'', 1, array(),
false, $excludeids);
7030 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
7034 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
7035 $soc =
new Societe($this->db);
7036 $soc->fetch((
int) $selected);
7037 $out .= $soc->getNomUrl(0,
'');
7039 $out .=
'<span class="opacitymedium">' . $textifnothirdparty .
'</span>';
7065 print $this->selectCurrency($selected, $htmlname);
7077 public function selectCurrency($selected =
'', $htmlname =
'currency_id', $mode = 0, $useempty =
'')
7079 global $langs, $user;
7081 $langs->loadCacheCurrencies(
'');
7085 if ($selected ==
'euro' || $selected ==
'euros') {
7089 $out .=
'<select class="flat maxwidth200onsmartphone minwidth300" name="' . $htmlname .
'" id="' . $htmlname .
'">';
7091 $out .=
'<option value="-1" selected></option>';
7093 foreach ($langs->cache_currencies as $code_iso => $currency) {
7094 $labeltoshow = $currency[
'label'];
7096 $labeltoshow .=
' <span class="opacitymedium">(' . $code_iso .
')</span>';
7098 $labeltoshow .=
' <span class="opacitymedium">(' . $langs->getCurrencySymbol($code_iso) .
')</span>';
7101 if ($selected && $selected == $code_iso) {
7102 $out .=
'<option value="' . $code_iso .
'" selected data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
7104 $out .=
'<option value="' . $code_iso .
'" data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
7107 $out .=
'</option>';
7109 $out .=
'</select>';
7111 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
7115 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
7133 public function selectMultiCurrency($selected =
'', $htmlname =
'multicurrency_code', $useempty = 0, $filter =
'', $excludeConfCurrency =
false, $morecss =
'maxwidth200 widthcentpercentminusx')
7135 global
$conf, $langs;
7137 $langs->loadCacheCurrencies(
'');
7139 $TCurrency = array();
7141 $sql =
"SELECT code FROM " . $this->db->prefix() .
"multicurrency";
7142 $sql .=
" WHERE entity IN ('" .
getEntity(
'multicurrency') .
"')";
7144 $sql .=
" AND " . $filter;
7146 $resql = $this->db->query($sql);
7148 while ($obj = $this->db->fetch_object($resql)) {
7149 $TCurrency[$obj->code] = $obj->code;
7154 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
7156 $out .=
'<option value=""> </option>';
7159 if (!in_array(
$conf->currency, $TCurrency) && !$excludeConfCurrency) {
7160 $TCurrency[
$conf->currency] =
$conf->currency;
7162 if (count($TCurrency) > 0) {
7163 foreach ($langs->cache_currencies as $code_iso => $currency) {
7164 if (isset($TCurrency[$code_iso])) {
7165 if (!empty($selected) && $selected == $code_iso) {
7166 $out .=
'<option value="' . $code_iso .
'" selected="selected">';
7168 $out .=
'<option value="' . $code_iso .
'">';
7171 $out .= $currency[
'label'];
7172 $out .=
' (' . $langs->getCurrencySymbol($code_iso) .
')';
7173 $out .=
'</option>';
7178 $out .=
'</select>';
7181 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
7198 global $langs, $user;
7200 $num = count($this->cache_vatrates);
7207 $sql =
"SELECT t.rowid, t.type_vat, t.code, t.taux, t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.recuperableonly";
7208 $sql .=
" FROM ".$this->db->prefix().
"c_tva as t, ".$this->db->prefix().
"c_country as c";
7209 $sql .=
" WHERE t.fk_pays = c.rowid";
7210 $sql .=
" AND t.active > 0";
7211 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
7212 $sql .=
" AND c.code IN (" . $this->db->sanitize($country_code, 1) .
")";
7213 $sql .=
" ORDER BY t.code ASC, t.taux ASC, t.recuperableonly ASC";
7215 $resql = $this->db->query($sql);
7217 $num = $this->db->num_rows($resql);
7219 for ($i = 0; $i < $num; $i++) {
7220 $obj = $this->db->fetch_object($resql);
7222 $tmparray = array();
7223 $tmparray[
'rowid'] = $obj->rowid;
7224 $tmparray[
'type_vat'] = ($obj->type_vat <= 0 ? 0 : $obj->type_vat);
7225 $tmparray[
'code'] = $obj->code;
7226 $tmparray[
'txtva'] = $obj->taux;
7227 $tmparray[
'nprtva'] = $obj->recuperableonly;
7228 $tmparray[
'localtax1'] = $obj->localtax1;
7229 $tmparray[
'localtax1_type'] = $obj->localtax1_type;
7230 $tmparray[
'localtax2'] = $obj->localtax2;
7231 $tmparray[
'localtax2_type'] = $obj->localtax1_type;
7232 $tmparray[
'label'] = $obj->taux .
'%' . ($obj->code ?
' (' . $obj->code .
')' :
'');
7233 $tmparray[
'labelallrates'] = $obj->taux .
'/' . ($obj->localtax1 ? $obj->localtax1 :
'0') .
'/' . ($obj->localtax2 ? $obj->localtax2 :
'0') . ($obj->code ?
' (' . $obj->code .
')' :
'');
7234 $positiverates =
'';
7236 $positiverates .= ($positiverates ?
'/' :
'') . $obj->taux;
7238 if ($obj->localtax1) {
7239 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax1;
7241 if ($obj->localtax2) {
7242 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax2;
7244 if (empty($positiverates)) {
7245 $positiverates =
'0';
7247 $tmparray[
'labelpositiverates'] = $positiverates . ($obj->code ?
' (' . $obj->code .
')' :
'');
7249 $this->cache_vatrates[$obj->rowid] = $tmparray;
7254 $this->error =
'<span class="error">';
7255 $this->error .= $langs->trans(
"ErrorNoVATRateDefinedForSellerCountry", $country_code);
7257 if (!empty($user) && $user->admin && preg_match(
'/\'(..)\'/', $country_code, $reg)) {
7258 $langs->load(
"errors");
7259 $new_country_code = $reg[1];
7260 $country_id =
dol_getIdFromCode($this->db, $new_country_code,
'c_country',
'code',
'rowid');
7261 $this->error .=
'<br>'.$langs->trans(
"ErrorFixThisHere", DOL_URL_ROOT.
'/admin/dict.php?id=10'.($country_id > 0 ?
'&countryidforinsert='.$country_id :
''));
7263 $this->error .=
'</span>';
7267 $this->error =
'<span class="error">' . $this->db->error() .
'</span>';
7296 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)
7299 global $langs, $mysoc, $hookmanager;
7301 $langs->load(
'errors');
7305 $hookmanager->initHooks(array(
'commonobject'));
7306 $info_bits == 1 ? $is_npr = 1 : $is_npr = 0;
7307 $parameters = array(
7308 'seller' => $societe_vendeuse,
7309 'buyer' => $societe_acheteuse,
7310 'idprod' => $idprod,
7311 'is_npr' => $is_npr,
7313 'options_only' => $options_only,
7315 'type_vat' => $type_vat
7317 $reshook = $hookmanager->executeHooks(
'load_tva', $parameters);
7319 return $hookmanager->resPrint;
7320 } elseif ($reshook === 0) {
7321 $return .= $hookmanager->resPrint;
7325 $defaultnpr = ($info_bits & 0x01);
7326 $defaultnpr = (preg_match(
'/\*/', $selectedrate) ? 1 : $defaultnpr);
7327 $defaulttx = str_replace(
'*',
'', $selectedrate);
7330 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
7331 $defaultcode = $reg[1];
7332 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
7337 if (is_object($societe_vendeuse) && !$societe_vendeuse->country_code) {
7338 if ($societe_vendeuse->id == $mysoc->id) {
7339 $return .=
'<span class="error">' . $langs->trans(
"ErrorYourCountryIsNotDefined") .
'</span>';
7341 $return .=
'<span class="error">' . $langs->trans(
"ErrorSupplierCountryIsNotDefined") .
'</span>';
7352 if (is_object($societe_vendeuse)) {
7353 $code_country =
"'" . $societe_vendeuse->country_code .
"'";
7355 $code_country =
"'" . $mysoc->country_code .
"'";
7358 if ($societe_vendeuse == $mysoc &&
getDolGlobalString(
'SERVICE_ARE_ECOMMERCE_200238EC')) {
7359 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
7363 if (is_object($societe_vendeuse) && is_object($societe_acheteuse) &&
isInEEC($societe_vendeuse) &&
isInEEC($societe_acheteuse) && !$societe_acheteuse->isACompany()) {
7365 if (is_numeric($type)) {
7367 switch ($selectVatComboMode) {
7369 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
7372 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
7376 } elseif (!$idprod) {
7377 switch ($selectVatComboMode) {
7379 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
7382 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
7386 $prodstatic =
new Product($this->db);
7387 $prodstatic->fetch($idprod);
7389 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
7396 $this->load_cache_vatrates($code_country);
7399 $arrayofvatrates = array();
7400 foreach ($this->cache_vatrates as $cachevalue) {
7401 if (empty($cachevalue[
'type_vat']) || $cachevalue[
'type_vat'] == $type_vat) {
7402 $arrayofvatrates[] = $cachevalue;
7406 $num = count($arrayofvatrates);
7409 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
7411 $tmpthirdparty =
new Societe($this->db);
7412 $tmpthirdparty->country_code = $mysoc->country_code;
7414 $defaulttx =
get_default_tva(is_object($societe_vendeuse) ? $societe_vendeuse : $tmpthirdparty, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
7415 $defaultnpr =
get_default_npr(is_object($societe_vendeuse) ? $societe_vendeuse : $tmpthirdparty, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
7417 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
7418 $defaultcode = $reg[1];
7419 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
7421 if (empty($defaulttx)) {
7428 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
7431 $defaulttx = $arrayofvatrates[$num - 1][
'txtva'];
7438 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
7439 $defaultcode = $reg[1];
7440 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
7448 if (is_object($societe_vendeuse) && $societe_vendeuse->id == $mysoc->id && empty($societe_vendeuse->tva_assuj)) {
7458 if (!$options_only) {
7459 $return .=
'<select class="flat minwidth75imp maxwidth100 right" id="' . $htmlname .
'" name="' . $htmlname .
'"' . ($disabled ?
' disabled' :
'') . $title .
'>';
7462 $selectedfound =
false;
7463 foreach ($arrayofvatrates as $rate) {
7465 if ($disabled && $rate[
'txtva'] != 0) {
7470 $key = $rate[
'txtva'];
7471 $key .= $rate[
'nprtva'] ?
'*' :
'';
7472 if ($mode > 0 && $rate[
'code']) {
7473 $key .=
' (' . $rate[
'code'] .
')';
7476 $key = $rate[
'rowid'];
7479 $return .=
'<option value="' . $key .
'"';
7480 if (!$selectedfound) {
7482 if ($defaultcode == $rate[
'code']) {
7483 $return .=
' selected';
7484 $selectedfound =
true;
7486 } elseif ($rate[
'txtva'] == $defaulttx && $rate[
'nprtva'] == $defaultnpr) {
7487 $return .=
' selected';
7488 $selectedfound =
true;
7494 if ($mysoc->country_code ==
'IN' ||
getDolGlobalString(
'MAIN_VAT_LABEL_IS_POSITIVE_RATES')) {
7496 $return .= $rate[
'labelpositiverates'];
7499 $return .=
vatrate($rate[
'label']);
7503 $return .= (empty($rate[
'code']) && $rate[
'nprtva']) ?
' *' :
'';
7505 $return .=
'</option>';
7508 if (!$options_only) {
7509 $return .=
'</select>';
7513 $return .= $this->error;
7547 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 =
'')
7550 dol_syslog(__METHOD__ .
': using select_date is deprecated. Use selectDate instead.', LOG_WARNING);
7551 $retstring = $this->selectDate($set_time, $prefix, $h, $m, $empty, $form_name, $d, $addnowlink, $disabled, $fullday, $addplusone, $adddateof);
7552 if (!empty($nooutput)) {
7575 public function selectDateToDate($set_time =
'', $set_time_end =
'', $prefix =
're', $empty = 0, $forcenewline = 0)
7579 $ret = $this->selectDate($set_time, $prefix .
'_start', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"from"),
'tzuserrel');
7580 if ($forcenewline) {
7583 $ret .= $this->selectDate($set_time_end, $prefix .
'_end', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
7615 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 =
'')
7617 global
$conf, $langs;
7619 if ($gm ===
'auto') {
7620 $gm = (empty(
$conf) ?
'tzserver' :
$conf->tzuserinputkey);
7625 if ($prefix ==
'') {
7636 if ($stepminutes <= 0 || $stepminutes > 30) {
7647 $orig_set_time = $set_time;
7649 if ($set_time ===
'' && $emptydate == 0) {
7650 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
7651 if ($gm ==
'tzuser' || $gm ==
'tzuserrel') {
7663 if (!empty($set_time) && preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/', (
string) $set_time, $reg)) {
7665 $syear = (!empty($reg[1]) ? $reg[1] :
'');
7666 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
7667 $sday = (!empty($reg[3]) ? $reg[3] :
'');
7668 $shour = (!empty($reg[4]) ? $reg[4] :
'');
7669 $smin = (!empty($reg[5]) ? $reg[5] :
'');
7670 } elseif (strval($set_time) !=
'' && $set_time != -1) {
7675 if ($orig_set_time !=
'') {
7689 if ($h == 3 || $h == 4) {
7700 $usecalendar =
'combo';
7706 $usecalendar =
'html';
7711 if ($usecalendar !=
'combo') {
7712 $formatted_date =
'';
7714 if (strval($set_time) !=
'' && $set_time != -1) {
7716 $formatted_date =
dol_print_date($set_time, $langs->trans(
"FormatDateShortInput"), $gm);
7720 if ($usecalendar ==
"eldy") {
7747 } elseif ($usecalendar ==
'jquery' || $usecalendar ==
'html') {
7748 if (!$disabled && $usecalendar !=
'html') {
7750 $minYear =
getDolGlobalInt(
'MIN_YEAR_SELECT_DATE', (idate(
'Y') - 100));
7751 $maxYear =
getDolGlobalInt(
'MAX_YEAR_SELECT_DATE', (idate(
'Y') + 100));
7753 $retstring .=
'<!-- datepicker usecalendar='.$usecalendar.
' --><script nonce="' .
getNonce() .
'" type="text/javascript">';
7754 $retstring .=
"$(function(){ $('#" . $prefix .
"').datepicker({
7755 dateFormat: '" . $langs->trans(
"FormatDateShortJQueryInput") .
"',
7757 todayHighlight: true,
7758 yearRange: '" . $minYear .
":" . $maxYear .
"',";
7759 if (!empty(
$conf->dol_use_jmobile)) {
7761 beforeShow: function (input, datePicker) {
7762 input.disabled = true;
7764 onClose: function (dateText, datePicker) {
7765 this.disabled = false;
7771 $buttonImage = $calendarpicto ?: DOL_URL_ROOT .
"/theme/" .
dol_escape_js(
$conf->theme) .
"/img/object_calendarday.png";
7773 showOn: 'button', /* both has problem with autocompletion */
7774 buttonImage: '" . $buttonImage .
"',
7775 buttonImageOnly: true";
7779 $retstring .=
"</script>";
7783 $retstring .=
'<div class="nowraponall inline-block divfordateinput">';
7784 $retstring .=
'<input id="'.$prefix.
'" name="'.$prefix.
'" type="'.($usecalendar ==
'html' ?
"date" :
"text").
'" class="maxwidthdate center" maxlength="11" value="'.$formatted_date.
'"';
7785 $retstring .= ($disabled ?
' disabled' :
'');
7786 $retstring .= ($placeholder ?
' placeholder="' .
dol_escape_htmltag($placeholder) .
'"' :
'');
7787 $retstring .=
' onChange="dpChangeDay(\'' .
dol_escape_js($prefix) .
'\',\
'' .
dol_escape_js($usecalendar ==
'html' ?
'yyyy-MM-dd' : $langs->trans(
"FormatDateShortJavaInput")) .
'\');
"'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
7788 $retstring .= ' autocomplete="off
">';
7792 $retstringbutton = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
">' . img_object($langs->trans("Disabled
"), 'calendarday', 'class="datecallink
"') . '</button>';
7793 $retstring = $retstringbutton . $retstring;
7796 $retstring .= '</div>';
7797 $retstring .= '<input type="hidden
" id="' . $prefix . 'day
" name="' . $prefix . 'day
" value="' . $sday . '">' . "\n
";
7798 $retstring .= '<input type="hidden
" id="' . $prefix . 'month
" name="' . $prefix . 'month
" value="' . $smonth . '">' . "\n
";
7799 $retstring .= '<input type="hidden
" id="' . $prefix . 'year
" name="' . $prefix . 'year
" value="' . $syear . '">' . "\n
";
7801 $retstring .= "Bad value of MAIN_POPUP_CALENDAR
";
7804 // Show date with combo selects
7806 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50imp
" id="' . $prefix . 'day
" name="' . $prefix . 'day
">';
7808 if ($emptydate || $set_time == -1) {
7809 $retstring .= '<option value="0
" selected> </option>';
7812 for ($day = 1; $day <= 31; $day++) {
7813 $retstring .= '<option value="' . $day . '"' . ($day == $sday ? ' selected' : '') . '>' . $day . '</option>';
7816 $retstring .= "</select>
";
7818 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'month
" name="' . $prefix . 'month
">';
7819 if ($emptydate || $set_time == -1) {
7820 $retstring .= '<option value="0
" selected> </option>';
7824 for ($month = 1; $month <= 12; $month++) {
7825 $retstring .= '<option value="' . $month . '"' . ($month == $smonth ? ' selected' : '') . '>';
7826 $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b
");
7827 $retstring .= "</option>
";
7829 $retstring .= "</select>
";
7832 if ($emptydate || $set_time == -1) {
7833 $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 . '">';
7835 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'year
" name="' . $prefix . 'year
">';
7837 $syear = (int) $syear;
7838 for ($year = $syear - 10; $year < (int) $syear + 10; $year++) {
7839 $retstring .= '<option value="' . $year . '"' . ($year == $syear ? ' selected' : '') . '>' . $year . '</option>';
7841 $retstring .= "</select>\n
";
7847 $retstring .= (($h == 2 || $h == 4) ? '<br>' : ' ');
7848 $retstring .= '<span class="nowraponall
">';
7854 if ($openinghours != '') {
7855 $openinghours = explode(',', $openinghours);
7856 $hourstart = $openinghours[0];
7857 $hourend = $openinghours[1];
7858 if ($hourend < $hourstart) {
7859 $hourend = $hourstart;
7864 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50
' . ($fullday ? $fullday . 'hour
' : '') . '" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
">';
7866 $retstring .= '<option value="-1
"> </option>';
7868 for ($hour = $hourstart; $hour < $hourend; $hour++) {
7869 if (strlen($hour) < 2) {
7870 $hour = "0
" . $hour;
7872 $retstring .= '<option value="' . $hour . '"' . (($hour == $shour) ? ' selected' : '') . '>' . $hour;
7873 $retstring .= '</option>';
7875 $retstring .= '</select>';
7878 $retstring .= '<input type="hidden
" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
" value="' . $shour . '">' . "\n
";
7887 $retstring .= '<select ' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50
' . ($fullday ? $fullday . 'min
' : '') . '" id="' . $prefix . 'min
" name="' . $prefix . 'min
">';
7889 $retstring .= '<option value="-1
"> </option>';
7891 for ($min = 0; $min < 60; $min += $stepminutes) {
7892 $min_str = sprintf("%02d
", $min);
7893 $retstring .= '<option value="' . $min_str . '"' . (($min_str == $smin) ? ' selected' : '') . '>' . $min_str . '</option>';
7895 $retstring .= '</select>';
7897 $retstring .= '<input type="hidden
" id="' . $prefix . 'min
" name="' . $prefix . 'min
" value="' . $smin . '">' . "\n
";
7900 $retstring .= '<input type="hidden
" name="' . $prefix . 'sec
" value="' . $ssec . '">';
7904 $retstring .= '</span>';
7908 if (!empty($conf->use_javascript_ajax) && $addnowlink && !$disabled) {
7909 // Script which will be inserted in the onClick of the "Now
" link
7910 $reset_scripts = "";
7911 if ($addnowlink == 2) { // local computer time
7912 // pad add leading 0 on numbers
7913 $reset_scripts .= "Number.prototype.pad =
function(size) {
7914 var s = String(
this);
7915 while (s.length < (size || 2)) {s =
'0' + s;}
7918 var d =
new Date();
";
7921 // Generate the date part, depending on the use or not of the javascript calendar
7922 if ($addnowlink == 1) { // server time expressed in user time setup
7923 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
7924 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
7925 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
7926 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
7927 } elseif ($addnowlink == 2) {
7928 /* Disabled because the output does not use the string format defined by FormatDateShort key to forge the value into #prefix.
7929 * This break application for foreign languages.
7930 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(d.toLocaleDateString(\''.str_replace('_', '-', $langs->defaultlang).'\'));';
7931 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(d.getDate().pad());';
7932 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(parseInt(d.getMonth().pad()) + 1);';
7933 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(d.getFullYear());';
7935 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
7936 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
7937 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
7938 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
7940 /*if ($usecalendar == "eldy
")
7942 $base=DOL_URL_ROOT.'/core/';
7943 $reset_scripts .= 'resetDP(\''.$base.'\',\''.$prefix.'\',\''.$langs->trans("FormatDateShortJavaInput
").'\',\''.$langs->defaultlang.'\');';
7947 $reset_scripts .= 'this.form.elements[\''.$prefix.'day\'].value=formatDate(new Date(), \'d\'); ';
7948 $reset_scripts .= 'this.form.elements[\''.$prefix.'month\'].value=formatDate(new Date(), \'M\'); ';
7949 $reset_scripts .= 'this.form.elements[\''.$prefix.'year\'].value=formatDate(new Date(), \'yyyy\'); ';
7951 // Update the hour part
7954 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7956 //$reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); ';
7957 if ($addnowlink == 1) {
7958 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
7959 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
7960 } elseif ($addnowlink == 2) {
7961 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(d.getHours().pad());';
7962 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
7966 $reset_scripts .= ' } ';
7969 // Update the minute part
7972 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7974 //$reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); ';
7975 if ($addnowlink == 1) {
7976 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
7977 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
7978 } elseif ($addnowlink == 2) {
7979 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(d.getMinutes().pad());';
7980 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
7983 $reset_scripts .= ' } ';
7986 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
7987 if ($reset_scripts && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
7988 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonNow
" type="button" name="_useless
" value="now
" onClick="' . $reset_scripts . '">';
7989 $retstring .= $langs->trans("Now
");
7990 $retstring .= '</button> ';
7994 // Add a "Plus one hour
" link
7995 if ($conf->use_javascript_ajax && $addplusone && !$disabled) {
7996 // Script which will be inserted in the onClick of the "Add plusone
" link
7997 $reset_scripts = "";
7999 // Generate the date part, depending on the use or not of the javascript calendar
8000 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'dayinputnoreduce', 'tzuserrel') . '\');';
8001 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
8002 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
8003 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
8004 // Update the hour part
8007 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8009 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
8011 $reset_scripts .= ' } ';
8014 // Update the minute part
8017 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
8019 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
8021 $reset_scripts .= ' } ';
8024 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
8025 if ($reset_scripts && empty($conf->dol_optimize_smallscreen)) {
8026 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonPlusOne
" type="button" name="_useless2
" value="plusone
" onClick="' . $reset_scripts . '">';
8027 $retstring .= $langs->trans("DateStartPlusOne
");
8028 $retstring .= '</button> ';
8032 // Add a link to set data
8033 if ($conf->use_javascript_ajax && !empty($adddateof) && !$disabled) {
8034 if (!is_array($adddateof)) {
8035 $arrayofdateof = array(array('adddateof' => $adddateof, 'labeladddateof' => $labeladddateof));
8037 $arrayofdateof = $adddateof;
8039 foreach ($arrayofdateof as $valuedateof) {
8040 $tmpadddateof = empty($valuedateof['adddateof']) ? 0 : $valuedateof['adddateof'];
8041 $tmplabeladddateof = empty($valuedateof['labeladddateof']) ? '' : $valuedateof['labeladddateof'];
8042 $tmparray = dol_getdate($tmpadddateof);
8043 if (empty($tmplabeladddateof)) {
8044 $tmplabeladddateof = $langs->trans("DateInvoice
");
8046 $reset_scripts = 'console.log(\'Click on now link\'); ';
8047 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(\''.dol_print_date($tmpadddateof, 'dayinputnoreduce').'\');';
8048 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(\''.$tmparray['mday'].'\');';
8049 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(\''.$tmparray['mon'].'\');';
8050 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(\''.$tmparray['year'].'\');';
8051 $retstring .= ' - <button class="dpInvisibleButtons datenowlink
" id="dateofinvoice
" type="button" name="_dateofinvoice
" value="now
" onclick="'.$reset_scripts.'">'.$tmplabeladddateof.'</button>';
8066 public function selectTypeDuration($prefix, $selected = 'i', $excludetypes = array())
8070 $TDurationTypes = array(
8071 'y' => $langs->trans('Years'),
8072 'm' => $langs->trans('Month'),
8073 'w' => $langs->trans('Weeks'),
8074 'd' => $langs->trans('Days'),
8075 'h' => $langs->trans('Hours'),
8076 'i' => $langs->trans('Minutes')
8079 // Removed undesired duration types
8080 foreach ($excludetypes as $value) {
8081 unset($TDurationTypes[$value]);
8084 $retstring = '<select class="flat minwidth75 maxwidth100
" id="select_
' . $prefix . 'type_duration
" name="' . $prefix . 'type_duration
">';
8085 foreach ($TDurationTypes as $key => $typeduration) {
8086 $retstring .= '<option value="' . $key . '"';
8087 if ($key == $selected) {
8088 $retstring .= " selected
";
8090 $retstring .= ">
" . $typeduration . "</option>
";
8092 $retstring .= "</select>
";
8094 $retstring .= ajax_combobox('select_' . $prefix . 'type_duration');
8099 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
8114 public function select_duration($prefix, $iSecond = '', $disabled = 0, $typehour = 'select', $minunderhours = 0, $nooutput = 0)
8119 $retstring = '<span class="nowraponall
">';
8125 if ($iSecond != '') {
8126 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
8128 $hourSelected = convertSecondToTime($iSecond, 'allhour');
8129 $minSelected = convertSecondToTime($iSecond, 'min');
8132 if ($typehour == 'select') {
8133 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'hour
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . '>';
8134 for ($hour = 0; $hour < 25; $hour++) { // For a duration, we allow 24 hours
8135 $retstring .= '<option value="' . $hour . '"';
8136 if (is_numeric($hourSelected) && $hourSelected == $hour) {
8137 $retstring .= " selected
";
8139 $retstring .= ">
" . $hour . "</option>
";
8141 $retstring .= "</select>
";
8142 } elseif ($typehour == 'text' || $typehour == 'textselect') {
8143 $retstring .= '<input placeholder="' . $langs->trans('HourShort
') . '" type="number
" min="0
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputhour right
" value="' . (($hourSelected != '') ? ((int) $hourSelected) : '') . '">';
8145 return 'BadValueForParameterTypeHour';
8148 if ($typehour != 'text') {
8149 $retstring .= ' ' . $langs->trans('HourShort');
8151 $retstring .= '<span class="">:</span>';
8155 if ($minunderhours) {
8156 $retstring .= '<br>';
8158 if ($typehour != 'text') {
8159 $retstring .= '<span class="hideonsmartphone
"> </span>';
8163 if ($typehour == 'select' || $typehour == 'textselect') {
8164 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'min
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . '>';
8165 for ($min = 0; $min <= 55; $min += 5) {
8166 $retstring .= '<option value="' . $min . '"';
8167 if (is_numeric($minSelected) && $minSelected == $min) {
8168 $retstring .= ' selected';
8170 $retstring .= '>' . $min . '</option>';
8172 $retstring .= "</select>
";
8173 } elseif ($typehour == 'text') {
8174 $retstring .= '<input placeholder="' . $langs->trans('MinuteShort
') . '" type="number
" min="0
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputminute right
" value="' . (($minSelected != '') ? ((int) $minSelected) : '') . '">';
8177 if ($typehour != 'text') {
8178 $retstring .= ' ' . $langs->trans('MinuteShort');
8181 $retstring .= "</span>
";
8183 if (!empty($nooutput)) {
8211 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)
8213 global $langs, $conf;
8218 if (is_null($ajaxoptions)) {
8219 $ajaxoptions = array();
8222 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
8225 if ($selected && empty($selected_input_value)) {
8226 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
8227 $tickettmpselect = new Ticket($this->db);
8228 $tickettmpselect->fetch((int) $selected);
8229 $selected_input_value = $tickettmpselect->ref;
8230 unset($tickettmpselect);
8234 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/ticket/ajax/tickets.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
8236 if (empty($hidelabel)) {
8237 $out .= $langs->trans("RefOrLabel
") . ' : ';
8238 } elseif ($hidelabel > 1) {
8239 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
8240 if ($hidelabel == 2) {
8241 $out .= img_picto($langs->trans("Search
"), 'search');
8244 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
8245 if ($hidelabel == 3) {
8246 $out .= img_picto($langs->trans("Search
"), 'search');
8249 $out .= $this->selectTicketsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
8252 if (empty($nooutput)) {
8277 public function selectTicketsList($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
8279 global $langs, $conf;
8282 $outarray = array();
8284 $selectFields = " p.rowid, p.ref, p.message
";
8287 $sql .= $selectFields;
8288 $sql .= " FROM
" . $this->db->prefix() . "ticket as p
";
8289 $sql .= ' WHERE p.entity IN (' . getEntity('ticket') . ')';
8291 // Add criteria on ref/label
8292 if ($filterkey != '') {
8294 $prefix = !getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
8295 // For natural search
8296 $search_crit = explode(' ', $filterkey);
8298 if (count($search_crit) > 1) {
8301 foreach ($search_crit as $crit) {
8305 $sql .= "(p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%' OR p.subject LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
8309 if (count($search_crit) > 1) {
8315 $sql .= $this->db->plimit($limit, 0);
8317 // Build output string
8318 dol_syslog(get_class($this) . "::selectTicketsList search tickets
", LOG_DEBUG);
8319 $result = $this->db->query($sql);
8321 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
8322 require_once DOL_DOCUMENT_ROOT . '/core/lib/ticket.lib.php';
8324 $num = $this->db->num_rows($result);
8329 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
8330 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('TICKET_USE_SEARCH_TO_SELECT'));
8333 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
8336 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
8337 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
8338 if (getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
8339 if ($showempty && !is_numeric($showempty)) {
8340 $textifempty = $langs->trans($showempty);
8342 $textifempty .= $langs->trans("All
");
8345 if ($showempty && !is_numeric($showempty)) {
8346 $textifempty = $langs->trans($showempty);
8350 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
8354 while ($num && $i < $num) {
8357 $objp = $this->db->fetch_object($result);
8359 $this->constructTicketListOption($objp, $opt, $optJson, $selected, $filterkey);
8360 '@phan-var-force array{key:string,value:mixed,type:int} $optJson';
8362 // "key
" value of json key array is used by jQuery automatically as selected value
8363 // "label
" value of json key array is used by jQuery automatically as text for combo box
8365 array_push($outarray, $optJson);
8370 $out .= '</select>';
8372 $this->db->free($result);
8374 if (empty($outputmode)) {
8379 dol_print_error($this->db);
8396 protected function constructTicketListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
8402 $outkey = $objp->rowid;
8403 $outref = $objp->ref;
8405 $opt = '<option value="
' . $objp->rowid . '"';
8406 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
8409 $objRef = $objp->ref;
8410 if (!empty($filterkey) && $filterkey != '') {
8411 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1);
8414 $opt .= "</option>\n
";
8415 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
8437 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)
8439 global $langs, $conf;
8444 if (is_null($ajaxoptions)) {
8445 $ajaxoptions = array();
8448 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
8451 if ($selected && empty($selected_input_value)) {
8452 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
8453 $projecttmpselect = new Project($this->db);
8454 $projecttmpselect->fetch((int) $selected);
8455 $selected_input_value = $projecttmpselect->ref;
8456 unset($projecttmpselect);
8460 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/projet/ajax/projects.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
8462 if (empty($hidelabel)) {
8463 $out .= $langs->trans("RefOrLabel
") . ' : ';
8464 } elseif ($hidelabel > 1) {
8465 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
8466 if ($hidelabel == 2) {
8467 $out .= img_picto($langs->trans("Search
"), 'search');
8470 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
8471 if ($hidelabel == 3) {
8472 $out .= img_picto($langs->trans("Search
"), 'search');
8475 $out .= $this->selectProjectsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
8478 if (empty($nooutput)) {
8502 public function selectProjectsList($selected = '', $htmlname = 'projectid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
8504 global $langs, $conf;
8507 $outarray = array();
8509 $selectFields = " p.rowid, p.ref
";
8512 $sql .= $selectFields;
8513 $sql .= " FROM
" . $this->db->prefix() . "projet as p
";
8514 $sql .= ' WHERE p.entity IN (' . getEntity('project') . ')';
8516 // Add criteria on ref/label
8517 if ($filterkey != '') {
8519 $prefix = !getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
8520 // For natural search
8521 $search_crit = explode(' ', $filterkey);
8523 if (count($search_crit) > 1) {
8526 foreach ($search_crit as $crit) {
8530 $sql .= "p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
8534 if (count($search_crit) > 1) {
8540 $sql .= $this->db->plimit($limit, 0);
8542 // Build output string
8543 dol_syslog(get_class($this) . "::selectProjectsList search projects
", LOG_DEBUG);
8544 $result = $this->db->query($sql);
8546 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
8547 require_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php';
8549 $num = $this->db->num_rows($result);
8554 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
8555 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('PROJECT_USE_SEARCH_TO_SELECT'));
8558 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
8561 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
8562 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
8563 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
8564 if ($showempty && !is_numeric($showempty)) {
8565 $textifempty = $langs->trans($showempty);
8567 $textifempty .= $langs->trans("All
");
8570 if ($showempty && !is_numeric($showempty)) {
8571 $textifempty = $langs->trans($showempty);
8575 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
8579 while ($num && $i < $num) {
8582 $objp = $this->db->fetch_object($result);
8584 $this->constructProjectListOption($objp, $opt, $optJson, $selected, $filterkey);
8586 // "key
" value of json key array is used by jQuery automatically as selected value
8587 // "label
" value of json key array is used by jQuery automatically as text for combo box
8589 array_push($outarray, $optJson);
8594 $out .= '</select>';
8596 $this->db->free($result);
8598 if (empty($outputmode)) {
8603 dol_print_error($this->db);
8622 protected function constructProjectListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
8628 $label = $objp->label;
8630 $outkey = $objp->rowid;
8631 $outref = $objp->ref;
8632 $outlabel = $objp->label;
8633 $outtype = $objp->fk_product_type;
8635 $opt = '<option value="
' . $objp->rowid . '"';
8636 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
8639 $objRef = $objp->ref;
8640 if (!empty($filterkey) && $filterkey != '') {
8641 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1);
8644 $opt .= "</option>\n
";
8645 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
8668 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)
8670 global $langs, $conf;
8675 if (is_null($ajaxoptions)) {
8676 $ajaxoptions = array();
8679 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
8682 if ($selected && empty($selected_input_value)) {
8683 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
8684 $adherenttmpselect = new Adherent($this->db);
8685 $adherenttmpselect->fetch((int) $selected);
8686 $selected_input_value = $adherenttmpselect->ref;
8687 unset($adherenttmpselect);
8692 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/adherents/ajax/adherents.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
8694 if (empty($hidelabel)) {
8695 $out .= $langs->trans("RefOrLabel
") . ' : ';
8696 } elseif ($hidelabel > 1) {
8697 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
8698 if ($hidelabel == 2) {
8699 $out .= img_picto($langs->trans("Search
"), 'search');
8702 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
8703 if ($hidelabel == 3) {
8704 $out .= img_picto($langs->trans("Search
"), 'search');
8709 $out .= $this->selectMembersList($selected, $htmlname, $filtertype, $limit, $filterkey, $status, 0, $showempty, $forcecombo, $morecss);
8712 if (empty($nooutput)) {
8736 public function selectMembersList($selected = '', $htmlname = 'adherentid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
8738 global $langs, $conf;
8741 $outarray = array();
8743 $selectFields = " p.rowid, p.ref, p.firstname, p.lastname, p.fk_adherent_type
";
8746 $sql .= $selectFields;
8747 $sql .= " FROM
" . $this->db->prefix() . "adherent as p
";
8748 $sql .= ' WHERE p.entity IN (' . getEntity('adherent') . ')';
8750 // Add criteria on ref/label
8751 if ($filterkey != '') {
8753 $prefix = !getDolGlobalString('MEMBER_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
8754 // For natural search
8755 $search_crit = explode(' ', $filterkey);
8757 if (count($search_crit) > 1) {
8760 foreach ($search_crit as $crit) {
8764 $sql .= "(p.firstname LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
8765 $sql .= " OR p.lastname LIKE
'" . $this->db->escape($prefix . $crit) . "%')
";
8768 if (count($search_crit) > 1) {
8773 if ($status != -1) {
8774 $sql .= ' AND statut = ' . ((int) $status);
8776 $sql .= $this->db->plimit($limit, 0);
8778 // Build output string
8779 dol_syslog(get_class($this) . "::selectMembersList search adherents
", LOG_DEBUG);
8780 $result = $this->db->query($sql);
8782 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
8783 require_once DOL_DOCUMENT_ROOT . '/core/lib/member.lib.php';
8785 $num = $this->db->num_rows($result);
8790 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
8791 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('PROJECT_USE_SEARCH_TO_SELECT'));
8794 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
8797 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
8798 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
8799 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
8800 if ($showempty && !is_numeric($showempty)) {
8801 $textifempty = $langs->trans($showempty);
8803 $textifempty .= $langs->trans("All
");
8806 if ($showempty && !is_numeric($showempty)) {
8807 $textifempty = $langs->trans($showempty);
8811 $out .= '<option value="-1
" selected>' . $textifempty . '</option>';
8815 while ($num && $i < $num) {
8818 $objp = $this->db->fetch_object($result);
8820 $this->constructMemberListOption($objp, $opt, $optJson, $selected, $filterkey);
8823 // "key
" value of json key array is used by jQuery automatically as selected value
8824 // "label
" value of json key array is used by jQuery automatically as text for combo box
8826 array_push($outarray, $optJson);
8831 $out .= '</select>';
8833 $this->db->free($result);
8835 if (empty($outputmode)) {
8840 dol_print_error($this->db);
8857 protected function constructMemberListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
8863 $outkey = $objp->rowid;
8864 $outlabel = dolGetFirstLastname($objp->firstname, $objp->lastname);
8865 $outtype = $objp->fk_adherent_type;
8867 $opt = '<option value="
' . $objp->rowid . '"';
8868 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
8870 if (!empty($filterkey) && $filterkey != '') {
8871 $outlabel = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $outlabel, 1);
8874 $opt .= "</option>\n
";
8876 $optJson = array('key' => $outkey, 'value' => $outlabel, 'type' => $outtype);
8899 public function selectForForms($objectdesc, $htmlname, $preSelectedValue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $disabled = 0, $selected_input_value = '', $objectfield = '')
8901 global $conf, $extrafields, $user;
8903 // Example of common usage for a link to a thirdparty
8905 // We got this in a modulebuilder form of "
MyObject" of module "mymodule
".
8906 // 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
8907 // $objectdesc = 'Societe'
8908 // $objectfield = 'myobject@mymodule:fk_soc' ('fk_soc' is code to retrieve myobject->fields['fk_soc']) or it can be an array that is directly
8909 // array("type"=>"integer:
Societe:societe/class/societe.class.php:1:((
status:=:1) AND (entity:IN:__SHARED_ENTITIES__))
" ...)
8911 // We got this when showing an extrafields on resource that is a link to societe
8912 // When extrafields 'link_to_societe' of Resource is 'link' to 'Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))" ...)
', we have
8914 // $objectfield = 'resource:options_link_to_societe
' or it can be an array that is directly
8915 // array("type"=>'Societe:societe/class/societe.class.php:1:((
status:=:1) AND (entity:IN:__SHARED_ENTITIES__))
" ...)
8918 // $objectdesc = 'Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))'
8919 // $objectfield = ''
8921 //var_dump($objectdesc.' '.$objectfield);
8922 //debug_print_backtrace();
8924 $objectdescorig = $objectdesc;
8926 $InfoFieldList = array();
8928 $filter = ''; // Ensure filter has value (for static analysis)
8929 $sortfield = ''; // Ensure filter has value (for static analysis)
8931 if (is_array($objectfield)) { // objectfield is an array
8932 $objectdesc = $objectfield['type'];
8933 $objectdesc = preg_replace('/^integer[^:]*:/', '', $objectdesc);
8934 } elseif ($objectfield) { // objectfield is a string. We must retrieve the objectdesc from the field or extrafield. Deprecated, it is better to provide the array record directly.
8935 // Example: $objectfield = 'product:options_package' or 'myobject@mymodule:options_myfield'
8936 $tmparray = explode(':', $objectfield);
8938 // Get instance of object from $element
8939 $objectforfieldstmp = fetchObjectByElement(0, strtolower($tmparray[0]));
8941 if (is_object($objectforfieldstmp)) {
8945 if (preg_match('/^options_(.*)$/', $tmparray[1], $reg)) {
8946 // For a property in extrafields
8948 // fetch optionals attributes and labels
8949 $extrafields->fetch_name_optionals_label($objectforfieldstmp->table_element);
8951 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element]['type'][$key]) && $extrafields->attributes[$objectforfieldstmp->table_element]['type'][$key] == 'link') {
8952 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element]['param'][$key]['options'])) {
8953 $tmpextrafields = array_keys($extrafields->attributes[$objectforfieldstmp->table_element]['param'][$key]['options']);
8954 $objectdesc = $tmpextrafields[0];
8958 // For a property in ->fields
8959 if (array_key_exists($tmparray[1], $objectforfieldstmp->fields)) {
8960 $objectdesc = $objectforfieldstmp->fields[$tmparray[1]]['type'];
8961 $objectdesc = preg_replace('/^integer[^:]*:/', '', $objectdesc);
8968 // Example of value for $objectdesc:
8969 // Bom:bom/class/bom.class.php:0:t.status=1
8970 // Bom:bom/class/bom.class.php:0:t.status=1:ref
8971 // Bom:bom/class/bom.class.php:0:(t.status:=:1) OR (t.field2:=:2):ref
8972 $InfoFieldList = explode(":
", $objectdesc, 4);
8973 $vartmp = (empty($InfoFieldList[3]) ? '' : $InfoFieldList[3]);
8975 if (preg_match('/^.*:(\w*)$/', $vartmp, $reg)) {
8976 $InfoFieldList[4] = $reg[1]; // take the sort field
8978 $InfoFieldList[3] = preg_replace('/:\w*$/', '', $vartmp); // take the filter field
8980 $classname = $InfoFieldList[0];
8981 $classpath = empty($InfoFieldList[1]) ? '' : $InfoFieldList[1];
8982 //$addcreatebuttonornot = empty($InfoFieldList[2]) ? 0 : $InfoFieldList[2];
8983 $filter = empty($InfoFieldList[3]) ? '' : $InfoFieldList[3];
8984 $sortfield = empty($InfoFieldList[4]) ? '' : $InfoFieldList[4];
8986 // Load object according to $id and $element
8987 $objecttmp = fetchObjectByElement(0, strtolower($InfoFieldList[0]));
8989 // Fallback to another solution to get $objecttmp
8990 if (empty($objecttmp) && !empty($classpath)) {
8991 dol_include_once($classpath);
8993 if ($classname && class_exists($classname)) {
8994 $objecttmp = new $classname($this->db);
8999 // Make some replacement in $filter. May not be used if we used the ajax mode with $objectfield. In such a case
9000 // we propagate the $objectfield and not the filter and replacement is done by the ajax/selectobject.php component.
9001 $sharedentities = (is_object($objecttmp) && property_exists($objecttmp, 'element')) ? getEntity($objecttmp->element) : strtolower($classname);
9002 $filter = str_replace(
9003 array('__ENTITY__', '__SHARED_ENTITIES__', '__USER_ID__'),
9004 array($conf->entity, $sharedentities, $user->id),
9008 if (!is_object($objecttmp)) {
9009 dol_syslog('selectForForms: Error bad setup of field objectdescorig=' . $objectdescorig.', objectfield='.(is_array($objectfield) ? 'array' : $objectfield).', objectdesc='.$objectdesc, LOG_WARNING);
9010 return 'selectForForms: Error bad setup of field objectdescorig=' . $objectdescorig.', objectfield='.(is_array($objectfield) ? 'array' : $objectfield).', objectdesc='.$objectdesc;
9012 '@phan-var-force CommonObject $objecttmp';
9014 //var_dump($filter);
9015 $prefixforautocompletemode = $objecttmp->element;
9016 if ($prefixforautocompletemode == 'societe') {
9017 $prefixforautocompletemode = 'company';
9019 if ($prefixforautocompletemode == 'product') {
9020 $prefixforautocompletemode = 'produit';
9023 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) . '_USE_SEARCH_TO_SELECT'; // For example COMPANY_USE_SEARCH_TO_SELECT
9025 dol_syslog(get_class($this) . "::selectForForms filter=
" . $filter, LOG_DEBUG);
9027 // Generate the combo HTML component
9029 if (!empty($conf->use_javascript_ajax) && getDolGlobalString($confkeyforautocompletemode) && !$forcecombo) {
9030 // No immediate load of all database
9033 if ($preSelectedValue && empty($selected_input_value)) {
9034 $objecttmp->fetch($preSelectedValue);
9035 $selected_input_value = ($prefixforautocompletemode == 'company' ? $objecttmp->name : $objecttmp->ref);
9037 $oldValueForShowOnCombobox = 0;
9038 foreach ($objecttmp->fields as $fieldK => $fielV) {
9039 if (!array_key_exists('showoncombobox', $fielV) || !$fielV['showoncombobox'] || empty($objecttmp->$fieldK)) {
9043 if (!$oldValueForShowOnCombobox) {
9044 $selected_input_value = '';
9047 $selected_input_value .= $oldValueForShowOnCombobox ? ' - ' : '';
9048 $selected_input_value .= $objecttmp->$fieldK;
9049 $oldValueForShowOnCombobox = empty($fielV['showoncombobox']) ? 0 : $fielV['showoncombobox'];
9053 // Set url and param to call to get json of the search results
9054 $urlforajaxcall = DOL_URL_ROOT . '/core/ajax/selectobject.php';
9055 $urloption = 'htmlname=' . urlencode($htmlname) . '&outjson=1&objectdesc=' . urlencode($objectdescorig) . (is_scalar($objectfield) ? '&objectfield='.urlencode($objectfield) : '') . ($sortfield ? '&sortfield=' . urlencode($sortfield) : '');
9057 // Activate the auto complete using ajax call.
9058 $out .= ajax_autocompleter((string) $preSelectedValue, $htmlname, $urlforajaxcall, $urloption, getDolGlobalInt($confkeyforautocompletemode), 0);
9059 $out .= '<!-- force css to be higher than dialog popup --><style type="text/css
">.ui-autocomplete { z-index: 1010; }</style>';
9060 $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) . '"' : '') . ' />';
9062 // Immediate load of table record.
9063 $out .= $this->selectForFormsList($objecttmp, $htmlname, $preSelectedValue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled, $sortfield, $filter);
9090 public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $outputmode = 0, $disabled = 0, $sortfield = '', $filter = '')
9092 global $langs, $user, $hookmanager;
9094 //print "$htmlname, $preselectedvalue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, $outputmode, $disabled
";
9096 $prefixforautocompletemode = $objecttmp->element;
9097 if ($prefixforautocompletemode == 'societe') {
9098 $prefixforautocompletemode = 'company';
9100 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) . '_USE_SEARCH_TO_SELECT'; // For example COMPANY_USE_SEARCH_TO_SELECT
9102 if (!empty($objecttmp->fields)) { // For object that declare it, it is better to use declared fields (like societe, contact, ...)
9103 $tmpfieldstoshow = '';
9104 foreach ($objecttmp->fields as $key => $val) {
9105 if (! (int) dol_eval((string) $val['enabled'], 1, 1, '1')) {
9108 if (!empty($val['showoncombobox'])) {
9109 $tmpfieldstoshow .= ($tmpfieldstoshow ? ',' : '') . 't.' . $key;
9112 if ($tmpfieldstoshow) {
9113 $fieldstoshow = $tmpfieldstoshow;
9115 } elseif ($objecttmp->element === 'category') {
9116 $fieldstoshow = 't.label';
9118 // For backward compatibility
9119 $objecttmp->fields['ref'] = array('type' => 'varchar(30)', 'label' => 'Ref', 'showoncombobox' => 1);
9122 if (empty($fieldstoshow)) {
9123 if (!empty($objecttmp->parent_element)) {
9124 $fieldstoshow = 'o.ref';
9125 if (empty($sortfield)) {
9126 $sortfield = 'o.ref';
9128 if (in_array($objecttmp->element, ['commandedet', 'propaldet', 'facturedet', 'expeditiondet'])) {
9129 $fieldstoshow .= ',p.ref AS p_ref,p.label,t.description';
9130 $sortfield .= ', p.ref';
9132 } elseif (isset($objecttmp->fields['ref'])) {
9133 $fieldstoshow = 't.ref';
9135 $langs->load("errors
");
9136 $this->error = $langs->trans("ErrorNoFieldWithAttributeShowoncombobox
");
9137 return $langs->trans('ErrorNoFieldWithAttributeShowoncombobox');
9142 $outarray = array();
9143 $tmparray = array();
9148 $sql = "SELECT t.rowid,
" . $fieldstoshow . " FROM
" . $this->db->prefix() . $this->db->sanitize($objecttmp->table_element) . " as t
";
9149 if (!empty($objecttmp->isextrafieldmanaged)) {
9150 $extrafieldTable = $objecttmp->table_element;
9151 if ($extrafieldTable == 'categorie') {
9152 $extrafieldTable = 'categories'; // For compatibility
9154 $sql .= " LEFT JOIN
" . $this->db->prefix() . $this->db->sanitize($extrafieldTable) . "_extrafields as e ON t.rowid = e.fk_object
";
9156 if (!empty($objecttmp->parent_element)) { // If parent_element is defined
9157 $parent_properties = getElementProperties($objecttmp->parent_element);
9158 $sql .= " INNER JOIN
" . $this->db->prefix() . $this->db->sanitize($parent_properties['table_element']) . " as o ON o.rowid = t.
".$objecttmp->fk_parent_attribute;
9160 if (isset($objecttmp->parent_element) && in_array($objecttmp->parent_element, ['commande', 'propal', 'facture', 'expedition'])) {
9161 $sql .= " LEFT JOIN
" . $this->db->prefix() . "product as p ON p.rowid = t.fk_product
";
9163 if (!empty($objecttmp->ismultientitymanaged)) {
9164 if ($objecttmp->ismultientitymanaged == 1) { // @phan-suppress-current-line PhanPluginEmptyStatementIf
9165 // No need to join/link another table
9167 if (!is_numeric($objecttmp->ismultientitymanaged)) {
9168 $tmparray = explode('@', $objecttmp->ismultientitymanaged);
9169 $sql .= " INNER JOIN
" . $this->db->prefix() . $this->db->sanitize($tmparray[1]) . " as parenttable ON parenttable.rowid = t.
" . $this->db->sanitize($tmparray[0]);
9173 // Add where from hooks
9174 $parameters = array(
9175 'object' => $objecttmp,
9176 'htmlname' => $htmlname,
9177 'filter' => $filter,
9178 'searchkey' => $searchkey
9181 $reshook = $hookmanager->executeHooks('selectForFormsListWhere', $parameters); // Note that $action and $object may have been modified by hook
9182 if (!empty($hookmanager->resPrint)) {
9183 $sql .= $hookmanager->resPrint;
9185 $sql .= " WHERE 1=1
";
9187 // If table need a multientity restriction
9188 if (!empty($objecttmp->ismultientitymanaged)) {
9189 if ($objecttmp->ismultientitymanaged == 1) {
9190 $sql .= " AND t.entity IN (
" . getEntity($objecttmp->element) . ")
";
9192 if (!is_numeric($objecttmp->ismultientitymanaged)) {
9193 $sql .= " AND parenttable.entity = t.
" . $this->db->sanitize($tmparray[0]);
9195 // If the parent table is llx_societe and user is not an external user (a more robust test done later for external users),
9196 // then we must also check that user has permissions
9197 if ($objecttmp->ismultientitymanaged === 'fk_soc@societe') {
9198 if (!$user->hasRight('societe', 'client', 'voir') && empty($user->socid)) {
9199 $sql .= " AND EXISTS (SELECT sc.rowid FROM
".$this->db->prefix() . "societe_commerciaux as sc
";
9200 $sql .= " WHERE sc.fk_soc = t.fk_soc AND sc.fk_user =
".((int) $user->id).")
";
9205 // If user is external user, we must also make a test on llx_societe_commerciaux
9206 if (!empty($user->socid)) {
9207 if ($objecttmp->element == 'societe') {
9208 $sql .= " AND t.rowid =
" . ((int) $user->socid);
9209 } elseif (!empty($objecttmp->fields['fk_soc']) || !empty($objecttmp->fields['t.fk_soc']) || property_exists($objecttmp, 'fk_soc') || property_exists($objecttmp, 'socid')) {
9210 $sql .= " AND t.fk_soc =
" . ((int) $user->socid);
9214 $splittedfieldstoshow = explode(',', $fieldstoshow);
9215 foreach ($splittedfieldstoshow as &$field2) {
9216 if (is_numeric($pos = strpos($field2, ' '))) {
9217 $field2 = substr($field2, 0, $pos);
9220 if ($searchkey != '') {
9221 $sql .= natural_search($splittedfieldstoshow, $searchkey);
9224 if ($filter) { // Syntax example "(t.
ref:like:
'SO-%') and (t.date_creation:<:
'20160101')
"
9226 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
9227 if ($errormessage) {
9228 return 'Error forging a SQL request from an universal criteria: ' . $errormessage;
9232 $sql .= $this->db->order($sortfield ? $sortfield : $fieldstoshow, "ASC
");
9233 //$sql.=$this->db->plimit($limit, 0);
9236 // Build output string
9237 $resql = $this->db->query($sql);
9239 // Construct $out and $outarray
9240 $out .= '<select id="' . $htmlname . '" class="flat minwidth100
' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled="disabled"' : '') . ($moreparams ? ' ' . $moreparams : '') . ' name="' . $htmlname . '">' . "\n
";
9242 // Warning: Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'. Seems it is no more true with selec2 v4
9243 $textifempty = ' ';
9245 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
9246 if (getDolGlobalInt($confkeyforautocompletemode)) {
9247 if ($showempty && !is_numeric($showempty)) {
9248 $textifempty = $langs->trans($showempty);
9250 $textifempty .= $langs->trans("All
");
9254 $out .= '<option value="-1
">' . $textifempty . '</option>' . "\n
";
9257 $num = $this->db->num_rows($resql);
9261 $obj = $this->db->fetch_object($resql);
9264 $tmparray = explode(',', $fieldstoshow);
9265 $oldvalueforshowoncombobox = 0;
9266 foreach ($tmparray as $key => $val) {
9267 $val = preg_replace('/(t|p|o)\./', '', $val);
9268 $label .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val]['showoncombobox'] ? ' - ' : ' ') : '');
9269 $labelhtml .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val]['showoncombobox'] ? ' - ' : ' ') : '');
9270 $label .= $obj->$val;
9271 $labelhtml .= $obj->$val;
9273 $oldvalueforshowoncombobox = empty($objecttmp->fields[$val]['showoncombobox']) ? 0 : $objecttmp->fields[$val]['showoncombobox'];
9275 if (empty($outputmode)) {
9276 if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) {
9277 $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>';
9279 $out .= '<option value="' . $obj->rowid . '" data-html="' . dol_escape_htmltag($labelhtml, 0, 0, '', 0, 1) . '">' . dol_escape_htmltag($label, 0, 0, '', 0, 1) . '</option>';
9282 array_push($outarray, array('key' => $obj->rowid, 'value' => $label, 'label' => $label));
9286 if (($i % 10) == 0) {
9292 $out .= '</select>' . "\n
";
9295 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
9296 $out .= ajax_combobox($htmlname, array(), getDolGlobalInt($confkeyforautocompletemode, 0));
9299 dol_print_error($this->db);
9302 $this->result = array('nbofelement' => $num);
9334 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)
9336 global $conf, $langs;
9338 // Do we want a multiselect ?
9340 //if (preg_match('/^multi/',$htmlname)) $jsbeautify = 1;
9343 if ($value_as_key) {
9344 $array = array_combine($array, $array);
9347 '@phan-var-force array{label:string,data-html:string,disable?:int<0,1>,css?:string} $array'; // Array combine breaks information
9351 if ($addjscombo < 0) {
9352 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
9358 $idname = str_replace(array('[', ']'), array('', ''), $htmlname);
9359 $out .= '<select id="
' . preg_replace('/^\./
', '', $idname) . '" ' . ($disabled ? 'disabled="disabled" ' : '') . 'class="flat
' . (preg_replace('/^\./
', '', $htmlname)) . ($morecss ? ' ' . $morecss : '') . ' selectformat
"';
9360 $out .= ' name="' . preg_replace('/^\./
', '', $htmlname) . '" ' . ($moreparam ? $moreparam : '');
9364 $textforempty = ' ';
9365 if (!empty($conf->use_javascript_ajax)) {
9366 $textforempty = ' '; // If we use ajaxcombo, we need here to avoid to have an empty element that is too small.
9368 if (!is_numeric($show_empty)) {
9369 $textforempty = $show_empty;
9371 $out .= '<option class="optiongrey
" ' . ($moreparamonempty ? $moreparamonempty . ' ' : '') . 'value="' . (((int) $show_empty) < 0 ? $show_empty : -1) . '"' . ($id == $show_empty ? ' selected' : '') . '>' . $textforempty . '</option>' . "\n
";
9373 if (is_array($array)) {
9376 foreach ($array as $key => $value) {
9377 if (!is_array($value)) {
9378 $array[$key] = $langs->trans($value);
9380 $array[$key]['label'] = $langs->trans($value['label']);
9385 if ($sort == 'ASC') {
9387 } elseif ($sort == 'DESC') {
9391 foreach ($array as $key => $tmpvalue) {
9392 if (is_array($tmpvalue)) {
9393 $value = $tmpvalue['label'];
9394 //$valuehtml = empty($tmpvalue['data-html']) ? $value : $tmpvalue['data-html'];
9395 $disabled = empty($tmpvalue['disabled']) ? '' : ' disabled';
9396 $style = empty($tmpvalue['css']) ? '' : ' class="' . $tmpvalue['css
'] . '"';
9399 //$valuehtml = $tmpvalue;
9403 if (!empty($disablebademail)) {
9404 if (($disablebademail == 1 && !preg_match('/<.+@.+>/', $value))
9405 || ($disablebademail == 2 && preg_match('/---/', $value))) {
9406 $disabled = ' disabled';
9407 $style = ' class="warning
"';
9410 if ($key_in_label) {
9411 if (empty($nohtmlescape)) {
9412 $selectOptionValue = dol_escape_htmltag($key . ' - ' . ($maxlen ? dol_trunc($value, $maxlen) : $value));
9414 $selectOptionValue = $key . ' - ' . ($maxlen ? dol_trunc($value, $maxlen) : $value);
9417 if (empty($nohtmlescape)) {
9418 $selectOptionValue = dol_escape_htmltag($maxlen ? dol_trunc($value, $maxlen) : $value);
9420 $selectOptionValue = $maxlen ? dol_trunc($value, $maxlen) : $value;
9422 if ($value == '' || $value == '-') {
9423 $selectOptionValue = ' ';
9426 $out .= '<option value="' . $key . '"';
9427 $out .= $style . $disabled;
9428 if (is_array($id)) {
9429 if (in_array($key, $id) && !$disabled) {
9430 $out .= ' selected'; // To preselect a value
9433 $id = (string) $id; // if $id = 0, then $id = '0'
9434 if ($id != '' && (($id == (string) $key) || ($id == 'ifone' && count($array) == 1)) && !$disabled) {
9435 $out .= ' selected'; // To preselect a value
9438 if (!empty($nohtmlescape)) { // deprecated. Use instead the key 'data-html' into input $array, managed at next step to use HTML content.
9439 $out .= ' data-html="' . dol_escape_htmltag($selectOptionValue) . '"';
9442 if (is_array($tmpvalue)) {
9443 foreach ($tmpvalue as $keyforvalue => $valueforvalue) {
9444 if ($keyforvalue == 'labelhtml') {
9445 $keyforvalue = 'data-html';
9447 if (preg_match('/^data-/', $keyforvalue)) { // The best solution if you want to use HTML values into the list is to use data-html.
9448 $out .= ' '.dol_escape_htmltag($keyforvalue).'="'.dol_escape_htmltag($valueforvalue).'"';
9453 $out .= $selectOptionValue;
9454 $out .= "</option>\n
";
9457 $out .= "</select>
";
9459 // Add code for jquery to use multiselect
9460 if ($addjscombo && $jsbeautify) {
9461 // Enhance with select2
9462 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
9463 $out .= ajax_combobox($idname, array(), 0, 0, 'resolve', (((int) $show_empty) < 0 ? (string) $show_empty : '-1'), $morecss);
9487 public static function selectArrayAjax($htmlname, $url, $id = '', $moreparam = '', $moreparamtourl = '', $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0)
9490 global $delayedhtmlcontent; // Will be used later outside of this function
9492 // TODO Use an internal dolibarr component instead of select2
9493 if (!getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') && !defined('REQUIRE_JQUERY_MULTISELECT')) {
9497 $out = '<select type="text
" class="' . $htmlname . ($morecss ? ' ' . $morecss : '') . '" ' . ($moreparam ? $moreparam . ' ' : '') . 'name="' . $htmlname . '"></select>';
9500 if (!empty($conf->use_javascript_ajax)) {
9501 $tmpplugin = 'select2';
9502 $outdelayed = "\n
" . '<!-- JS CODE TO ENABLE ' . $tmpplugin . ' for id ' . $htmlname . ' -->
9503 <script nonce="' . getNonce() . '">
9504 $(document).ready(function () {
9506 ' . ($callurlonselect ? 'var saveRemoteData = [];' : '') . '
9508 $(".
' . $htmlname . '").select2({
9511 url: "' . $url . '",
9514 data: function (params) {
9516 q: params.term, // search term
9520 processResults: function (data) {
9521 // parse the results into the format expected by Select2.
9522 // since we are using custom formatting functions we do not need to alter the remote JSON data
9523 //console.log(data);
9524 saveRemoteData = data;
9525 /* format json result for select2 */
9527 $.each( data, function( key, value ) {
9528 result.push({id: key, text: value.text});
9530 //return {results:[{id:\'none\', text:\'aa\'}, {id:\'rrr\', text:\'Red\'},{id:\'bbb\', text:\'Search a into projects\'}], more:false}
9531 //console.log(result);
9532 return {results: result, more: false}
9536 language: (typeof select2arrayoflanguage === \'undefined\') ? \'en\' : select2arrayoflanguage,
9537 containerCssClass: \':all:\', /* Line to add class from the original SELECT propagated to the new <span class="select2-selection...> tag */
9539 escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
9540 minimumInputLength: ' . ((int) $minimumInputLength) .
',
9541 formatResult: function (result, container, query, escapeMarkup) {
9542 return escapeMarkup(result.text);
9546 ' . ($callurlonselect ?
'
9547 /* Code to execute a GET when we select a value */
9548 $(".' . $htmlname .
'").change(function() {
9549 var selected = $(\'.' .
dol_escape_js($htmlname) .
'\').val();
9550 console.log("We select in selectArrayAjax the entry "+selected)
9551 $(\'.' .
dol_escape_js($htmlname) .
'\').val(""); /* reset visible combo value */
9552 $.each( saveRemoteData, function( key, value ) {
9553 if (key == selected)
9555 console.log("selectArrayAjax - Do a redirect to "+value.url)
9556 location.assign(value.url);
9565 if ($acceptdelayedhtml) {
9566 $delayedhtmlcontent .= $outdelayed;
9568 $out .= $outdelayed;
9592 public static function selectArrayFilter($htmlname, $array,
$id =
'', $moreparam =
'', $disableFiltering = 0, $disabled = 0, $minimumInputLength = 1, $morecss =
'', $callurlonselect = 0, $placeholder =
'', $acceptdelayedhtml = 0, $textfortitle =
'')
9595 global $delayedhtmlcontent;
9598 if (!
getDolGlobalString(
'MAIN_USE_JQUERY_MULTISELECT') && !defined(
'REQUIRE_JQUERY_MULTISELECT')) {
9602 $out =
'<select type="text"'.($textfortitle ?
' title="'.dol_escape_htmltag($textfortitle).
'"' :
'').
' id="'.$htmlname.
'" class="'.$htmlname.($morecss ?
' ' . $morecss :
'').
'"'.($moreparam ?
' '.$moreparam :
'').
' name="'.$htmlname.
'"><option></option></select>';
9604 $formattedarrayresult = array();
9606 foreach ($array as $key => $value) {
9609 $o->text = $value[
'text'];
9610 $o->url = $value[
'url'];
9611 $formattedarrayresult[] = $o;
9615 if (!empty(
$conf->use_javascript_ajax)) {
9616 $tmpplugin =
'select2';
9617 $outdelayed =
"\n" .
'<!-- JS CODE TO ENABLE ' . $tmpplugin .
' for id ' . $htmlname .
' -->
9618 <script nonce="' .
getNonce() .
'">
9619 $(document).ready(function () {
9620 var data = ' . json_encode($formattedarrayresult) .
';
9622 ' . ($callurlonselect ?
'var saveRemoteData = ' . json_encode($array) .
';' :
'') .
'
9626 language: (typeof select2arrayoflanguage === \
'undefined\') ? \'en\' : select2arrayoflanguage,
9627 containerCssClass: \':all:\', /* Line to add class from the original SELECT propagated to the new <span class="select2-selection...> tag */
9629 escapeMarkup:
function (markup) {
return markup; },
9630 minimumInputLength:
' . ((int) $minimumInputLength) . ',
9631 formatResult:
function (result, container, query, escapeMarkup) {
9632 return escapeMarkup(result.text);
9634 matcher:
function (params, data) {
9636 if(! data.id)
return null;
';
9638 if ($callurlonselect) {
9639 // We forge the url with 'sall=
'
9642 var urlBase = data.url;
9643 var separ = urlBase.indexOf(
"?") >= 0 ?
"&" :
"?";
9646 saveRemoteData[data.id].url = urlBase + separ +
"search_all=" + encodeURIComponent(params.term.replace(/\
"/g, ""));';
9649 if (!$disableFiltering) {
9652 if(data.text.match(new RegExp(params.term))) {
9667 ' . ($callurlonselect ? '
9668 /* Code to execute a GET when we select a value */
9669 $(\'.' . dol_escape_js($htmlname) . '\').change(function() {
9670 var selected = $(\'.' . dol_escape_js($htmlname) . '\').val();
9671 console.log("We select
"+selected)
9673 $(\'.' . dol_escape_js($htmlname) . '\').val(""); /* reset visible combo value */
9674 $.each( saveRemoteData, function( key, value ) {
9675 if (key == selected)
9677 console.log("selectArrayFilter - Do a redirect to
"+value.url)
9678 location.assign(value.url);
9687 if ($acceptdelayedhtml) {
9688 $delayedhtmlcontent .= $outdelayed;
9690 $out .= $outdelayed;
9713 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)
9715 global $conf, $langs;
9718 if ($addjscombo < 0) {
9719 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
9726 $useenhancedmultiselect = 0;
9727 if (!empty($conf->use_javascript_ajax) && !defined('MAIN_DO_NOT_USE_JQUERY_MULTISELECT') && (getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') || defined('REQUIRE_JQUERY_MULTISELECT'))) {
9729 $useenhancedmultiselect = 1; // Use the js multiselect in one line. Possible only if $addjscombo not 0.
9733 $out .= '<span class="multiselectarray
'.$htmlname.'">';
9735 // We need a hidden field because when using the multiselect, if we unselect all, there is no
9736 // variable submitted at all, so no way to make a difference between variable not submitted and variable
9737 // submitted to nothing.
9738 $out .= '<input type="hidden
" name="'.$htmlname.'_multiselect
" value="1
">';
9739 // Output select component
9740 $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
";
9741 if (is_array($array) && !empty($array)) {
9742 if ($value_as_key) {
9743 $array = array_combine($array, $array);
9746 if (!empty($array)) {
9747 foreach ($array as $key => $value) {
9753 if (is_array($value) && array_key_exists('id', $value) && array_key_exists('label', $value)) {
9754 $tmpkey = $value['id'];
9755 $tmpvalue = empty($value['label']) ? '' : $value['label'];
9756 $tmpcolor = empty($value['color']) ? '' : $value['color'];
9757 $tmppicto = empty($value['picto']) ? '' : $value['picto'];
9758 $tmplabelhtml = empty($value['labelhtml']) ? (empty($value['data-html']) ? '' : $value['data-html']) : $value['labelhtml'];
9760 $newval = ($translate ? $langs->trans($tmpvalue) : $tmpvalue);
9761 $newval = ($key_in_label ? $tmpkey . ' - ' . $newval : $newval);
9763 $out .= '<option value="' . $tmpkey . '"';
9764 if (is_array($selected) && !empty($selected) && in_array((string) $tmpkey, $selected) && ((string) $tmpkey != '')) {
9765 $out .= ' selected';
9767 if (!empty($tmplabelhtml)) {
9768 $out .= ' data-html="' . dol_escape_htmltag($tmplabelhtml, 0, 0, '', 0, 1) . '"';
9770 $tmplabelhtml = ($tmppicto ? img_picto('', $tmppicto, 'class="pictofixedwidth
" style="color: #
' . $tmpcolor . '"') : '') . $newval;
9771 $out .= ' data-html="' . dol_escape_htmltag($tmplabelhtml, 0, 0, '', 0, 1) . '"';
9774 $out .= dol_htmlentitiesbr($newval);
9775 $out .= '</option>' . "\n
";
9779 $out .= '</select>' . "\n
";
9783 // Add code for jquery to use multiselect
9784 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') || defined('REQUIRE_JQUERY_MULTISELECT')) {
9785 $out .= "\n
" . '<!-- JS CODE TO ENABLE select for id ' . $htmlname . ', addjscombo=' . $addjscombo . ' -->';
9786 $out .= "\n
" . '<script nonce="' . getNonce() . '">' . "\n
";
9787 if ($addjscombo == 1) {
9788 $tmpplugin = getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT', (defined('REQUIRE_JQUERY_MULTISELECT') ? constant('REQUIRE_JQUERY_MULTISELECT') : 'select2'));
9790 // If property data-html set, we decode html entities and use this.
9791 // Note that HTML content must have been sanitized from js with dol_escape_htmltag(xxx, 0, 0, '', 0, 1) when building the select option.
9792 // TODO Move this into common js ?
9793 $out .= 'function formatResult(record, container) {' . "\n
";
9794 $out .= ' if ($(record.element).attr("data-html
") != undefined && typeof htmlEntityDecodeJs === "function
") {';
9795 $out .= ' return htmlEntityDecodeJs($(record.element).attr("data-html
"));';
9797 $out .= ' return record.text;';
9800 $out .= 'function formatSelection(record) {' . "\n
";
9801 $out .= ' return record.text;';
9804 // Load the select2 enhancer
9805 //$out .= 'console.log(\'addjscombo=1 for htmlname=' . dol_escape_js($htmlname) . '\');';
9806 $out .= '$(document).ready(function () {
9807 $(\'#' . dol_escape_js($htmlname) . '\').' . $tmpplugin . '({';
9812 text: \''.dol_escape_js($placeholder).'\'
9815 $out .= ' dir: \'ltr\',
9816 containerCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag (ko with multiselect) */
9817 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. */
9818 // Specify format function for dropdown item
9819 formatResult: formatResult,
9820 templateResult: formatResult, /* For 4.0 */
9821 escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
9822 // Specify format function for selected item
9823 formatSelection: formatSelection,
9824 templateSelection: formatSelection, /* For 4.0 */
9825 language: (typeof select2arrayoflanguage === \'undefined\') ? \'en\' : select2arrayoflanguage
9828 /* Add also morecss to the css .select2 that is after the #htmlname, for component that are shown dynamically after load, because select2 set
9829 the size only if component is not hidden by default on load */
9832 } elseif ($addjscombo == 2 && !defined(
'DISABLE_MULTISELECT')) {
9836 $out .=
'console.log(\'addjscombo=2 for htmlname=' .
dol_escape_js($htmlname) .
'\');
';
9837 $out .= '$(document).ready(
function () {
9839 containerHTML: \
'<div class="multi-select-container">\',
9840 menuHTML: \'<div class="multi-select-menu">\',
9841 buttonHTML: \'<span class="multi-select-button ' .
dol_escape_js($morecss) .
'">\',
9842 menuItemHTML: \'<label class="multi-select-menuitem">\',
9843 activeClass: \'multi-select-container--open\',
9848 $out .= '</script>
';
9866 public static function multiSelectArrayWithCheckbox($htmlname, &$array, $varpage, $pos = '
')
9868 global $conf, $langs, $user;
9870 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER
')) {
9873 if (empty($array)) {
9877 $tmpvar = "MAIN_SELECTEDFIELDS_" . $varpage; // To get list of saved selected fields to show
9879 if (!empty($user->conf->$tmpvar)) { // A list of fields was already customized for user
9880 $tmparray = explode(',
', $user->conf->$tmpvar);
9881 foreach ($array as $key => $val) {
9883 //var_dump($tmparray);
9884 if (in_array($key, $tmparray)) {
9885 $array[$key]['checked
'] = 1;
9887 $array[$key]['checked
'] = 0;
9890 } else { // There is no list of fields already customized for user
9891 foreach ($array as $key => $val) {
9892 if (!empty($array[$key]['checked
']) && $array[$key]['checked
'] < 0) {
9893 $array[$key]['checked
'] = 0;
9898 $listoffieldsforselection = '';
9899 $listcheckedstring = '';
9901 foreach ($array as $key => $val) {
9903 // var_dump(array_key_exists('enabled
', $val));
9904 // var_dump(!$val['enabled
']);
9905 if (array_key_exists('enabled
', $val) && isset($val['enabled
']) && !$val['enabled
']) {
9906 unset($array[$key]); // We don't want
this field
9909 if (!empty($val[
'type']) && $val[
'type'] ==
'separate') {
9914 if (!empty($val[
'label']) && $val[
'label']) {
9915 if (!empty($val[
'langfile']) && is_object($langs)) {
9916 $langs->load($val[
'langfile']);
9920 $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']).
'" />';
9921 $listoffieldsforselection .=
'<label for="checkbox' . $key .
'" class="paddingleft">';
9923 $listoffieldsforselection .=
'</label></li>';
9924 $listcheckedstring .= (empty($val[
'checked']) ?
'' : $key .
',');
9928 $out =
'<!-- Component multiSelectArrayWithCheckbox ' . $htmlname .
' -->
9930 <dl class="dropdown">
9932 <a href="#' . $htmlname .
'">
9935 <input type="hidden" class="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $listcheckedstring .
'">
9937 <dd class="dropdowndd">
9938 <div class="multiselectcheckbox'.$htmlname.
'">
9939 <ul class="'.$htmlname.(((string) $pos ==
'1' || (
string) $pos ==
'left') ?
'left' :
'').
'">
9940 <li class="liinputsearch">
9941 <input class="inputsearch_dropdownselectedfields width90p minwidth200imp" style="width:90%;" type="text" placeholder="'.$langs->trans(
'Search').
'">
9943 '.$listoffieldsforselection.
'
9949 <script nonce="' .
getNonce() .
'" type="text/javascript">
9950 jQuery(document).ready(function () {
9951 $(\'.multiselectcheckbox' . $htmlname .
' input[type="checkbox"]\').on("click", function () {
9952 console.log("A new field was added/removed, we edit field input[name=formfilteraction]");
9954 $("input:hidden[name=formfilteraction]").val(\'listafterchangingselectedfields\'); // Update field so we know we changed something on selected fields after POST
9956 var title = $(this).val() + ",";
9957 if ($(this).is(\':checked\')) {
9958 $(\'.' . $htmlname .
'\').val(title + $(\'.' . $htmlname .
'\').val());
9961 $(\'.' . $htmlname .
'\').val( $(\'.' . $htmlname .
'\').val().replace(title, \'\') )
9963 // Now, we submit page
9964 //$(this).parents(\'form:first\').submit();
9967 $("input.inputsearch_dropdownselectedfields").on("keyup", function() {
9968 console.log("keyup on inputsearch_dropdownselectedfields");
9969 var value = $(this).val().toLowerCase();
9970 $(\'.multiselectcheckbox'.$htmlname.
' li > label\').filter(function() {
9971 $(this).parent().toggle($(this).text().toLowerCase().indexOf(value) > -1)
9975 if (empty(
$conf->browser->layout) ||
$conf->browser->layout !=
'phone') {
9977 $(".dropdown dt a").on("click", function () {
9978 console.log("Click on dropdown, we set focus to search field");
9979 setTimeout(() => { $(\'.inputsearch_dropdownselectedfields\').focus(); }, 200);
10001 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
10004 $categories = $cat->containing(
$id, $type);
10006 if ($rendermode == 1) {
10007 $toprint = array();
10008 foreach ($categories as
$c) {
10009 $ways =
$c->print_all_ways(
' >> ', ($nolink ?
'none' :
''), 0, 1);
10010 foreach ($ways as $way) {
10011 $color =
$c->color;
10012 $sfortag =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($color ?
' style="background: #' . $color .
';"' :
' style="background: #bbb"') .
'>';
10014 $sfortag .=
'</li>';
10015 $toprint[] = $sfortag;
10018 if (empty($toprint)) {
10021 return '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
10025 if ($rendermode == 0) {
10026 $arrayselected = array();
10027 $cate_arbo = $this->select_all_categories($type,
'',
'parent', 64, 0, 3);
10028 foreach ($categories as
$c) {
10029 $arrayselected[(string)
$c->id] = (
string)
$c->id;
10032 return $this->multiselectarray(
'categories', $cate_arbo, $arrayselected, 0, 0,
'', 0,
'100%',
'disabled',
'category');
10035 return 'ErrorBadValueForParameterRenderMode';
10049 global
$conf, $langs, $hookmanager;
10052 $object->fetchObjectLinked();
10055 $hookmanager->initHooks(array(
'commonobject'));
10056 $parameters = array(
10057 'morehtmlright' => $morehtmlright,
10058 'compatibleImportElementsList' => &$compatibleImportElementsList,
10060 $reshook = $hookmanager->executeHooks(
'showLinkedObjectBlock', $parameters,
$object, $action);
10062 $nbofdifferenttypes = count(
$object->linkedObjects);
10064 if (empty($reshook)) {
10065 print
'<!-- showLinkedObjectBlock -->';
10066 print
load_fiche_titre($langs->trans($title), $morehtmlright,
'', 0,
'',
'showlinkedobjectblock');
10069 print
'<div class="div-table-responsive-no-min">';
10070 print
'<table class="noborder allwidth" data-block="showLinkedObject" data-element="' .
$object->element .
'" data-elementid="' .
$object->id .
'" >';
10072 print
'<tr class="liste_titre">';
10073 print
'<td>' . $langs->trans(
"Type") .
'</td>';
10074 print
'<td>' . $langs->trans(
"Ref") .
'</td>';
10075 print
'<td class="center"></td>';
10076 print
'<td class="center">' . $langs->trans(
"Date") .
'</td>';
10077 print
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
10078 print
'<td class="right">' . $langs->trans(
"Status") .
'</td>';
10082 $nboftypesoutput = 0;
10084 foreach (
$object->linkedObjects as $objecttype => $objects) {
10085 $tplpath = $element = $subelement = $objecttype;
10088 $showImportButton =
false;
10089 if (!empty($compatibleImportElementsList) && in_array($element, $compatibleImportElementsList)) {
10090 $showImportButton =
true;
10095 if ($objecttype !=
'supplier_proposal' && preg_match(
'/^([^_]+)_([^_]+)/i', $objecttype, $regs)) {
10096 $element = $regs[1];
10097 $subelement = $regs[2];
10098 $tplpath = $element .
'/' . $subelement;
10100 $tplname =
'linkedobjectblock';
10103 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $objecttype, $regs)) {
10104 $element = $regs[1];
10105 $module = $regs[2];
10106 $tplpath = $module.
'/' . $element;
10107 $tplname = $tplname.
'_'.$element;
10111 if ($objecttype ==
'facture') {
10112 $tplpath =
'compta/' . $element;
10113 if (!isModEnabled(
'invoice')) {
10116 } elseif ($objecttype ==
'facturerec') {
10117 $tplpath =
'compta/facture';
10118 $tplname =
'linkedobjectblockForRec';
10119 if (!isModEnabled(
'invoice')) {
10122 } elseif ($objecttype ==
'propal') {
10123 $tplpath =
'comm/' . $element;
10124 if (!isModEnabled(
'propal')) {
10127 } elseif ($objecttype ==
'supplier_proposal') {
10128 if (!isModEnabled(
'supplier_proposal')) {
10131 } elseif ($objecttype ==
'shipping' || $objecttype ==
'shipment' || $objecttype ==
'expedition') {
10132 $tplpath =
'expedition';
10133 if (!isModEnabled(
'shipping')) {
10136 } elseif ($objecttype ==
'reception') {
10137 $tplpath =
'reception';
10138 if (!isModEnabled(
'reception')) {
10141 } elseif ($objecttype ==
'delivery') {
10142 $tplpath =
'delivery';
10146 } elseif ($objecttype ==
'ficheinter') {
10147 $tplpath =
'fichinter';
10148 if (!isModEnabled(
'intervention')) {
10151 } elseif ($objecttype ==
'invoice_supplier') {
10152 $tplpath =
'fourn/facture';
10153 } elseif ($objecttype ==
'order_supplier') {
10154 $tplpath =
'fourn/commande';
10155 } elseif ($objecttype ==
'expensereport') {
10156 $tplpath =
'expensereport';
10157 } elseif ($objecttype ==
'subscription') {
10158 $tplpath =
'adherents';
10159 } elseif ($objecttype ==
'conferenceorbooth') {
10160 $tplpath =
'eventorganization';
10161 } elseif ($objecttype ==
'conferenceorboothattendee') {
10162 $tplpath =
'eventorganization';
10163 } elseif ($objecttype ==
'mo') {
10165 if (!isModEnabled(
'mrp')) {
10168 } elseif ($objecttype ==
'project_task') {
10169 $tplpath =
'projet/tasks';
10172 global $linkedObjectBlock;
10173 $linkedObjectBlock = $objects;
10176 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array(
'/' . $tplpath .
'/tpl'));
10178 foreach ($dirtpls as $reldir) {
10179 $reldir = rtrim($reldir,
'/');
10180 if ($nboftypesoutput == ($nbofdifferenttypes - 1)) {
10181 global $noMoreLinkedObjectBlockAfter;
10182 $noMoreLinkedObjectBlockAfter = 1;
10185 $res = @include
dol_buildpath($reldir .
'/' . $tplname .
'.tpl.php');
10187 $nboftypesoutput++;
10193 if (!$nboftypesoutput) {
10194 print
'<tr><td colspan="7"><span class="opacitymedium">' . $langs->trans(
"None") .
'</span></td></tr>';
10199 if (!empty($compatibleImportElementsList)) {
10200 $res = @include
dol_buildpath(
'core/tpl/objectlinked_lineimport.tpl.php');
10206 return $nbofdifferenttypes;
10220 global
$conf, $langs, $hookmanager, $form;
10223 if (empty($form)) {
10224 $form =
new Form($this->db);
10228 $linktoelemlist =
'';
10229 $listofidcompanytoscan =
'';
10231 if (!is_object(
$object->thirdparty)) {
10235 $possiblelinks = array();
10237 $dontIncludeCompletedItems =
getDolGlobalString(
'DONT_INCLUDE_COMPLETED_ELEMENTS_LINKS');
10239 if (is_object(
$object->thirdparty) && !empty(
$object->thirdparty->id) &&
$object->thirdparty->id > 0) {
10240 $listofidcompanytoscan = (int)
$object->thirdparty->id;
10242 $listofidcompanytoscan .=
',' . (int)
$object->thirdparty->parent;
10245 include_once DOL_DOCUMENT_ROOT .
'/projet/class/project.class.php';
10246 $tmpproject =
new Project($this->db);
10247 $tmpproject->fetch(
$object->fk_project);
10248 if ($tmpproject->socid > 0 && ($tmpproject->socid !=
$object->thirdparty->id)) {
10249 $listofidcompanytoscan .=
',' . (int) $tmpproject->socid;
10251 unset($tmpproject);
10254 $possiblelinks = array(
10256 'enabled' => isModEnabled(
'propal'),
10258 'label' =>
'LinkToProposal',
10259 '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' :
''),
10261 'shipping' => array(
10262 'enabled' => isModEnabled(
'shipping'),
10264 'label' =>
'LinkToExpedition',
10265 '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' :
''),
10268 'enabled' => isModEnabled(
'order'),
10270 'label' =>
'LinkToOrder',
10271 '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' :
''),
10272 'linkname' =>
'commande',
10273 'subscription' => array(
10274 'enabled' => isModEnabled(
'member'),
10276 'label' =>
'LinkToMemberSubscription',
10277 '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') .
')',
10278 'linkname' =>
'subscription'),
10280 'invoice' => array(
10281 'enabled' => isModEnabled(
'invoice'),
10283 'label' =>
'LinkToInvoice',
10284 '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' :
''),
10285 'linkname' =>
'facture',
10287 'invoice_template' => array(
10288 'enabled' => isModEnabled(
'invoice'),
10290 'label' =>
'LinkToTemplateInvoice',
10291 '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') .
')',
10293 'contrat' => array(
10294 'enabled' => isModEnabled(
'contract'),
10296 'label' =>
'LinkToContract',
10297 '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
10298 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',
10300 'fichinter' => array(
10301 'enabled' => isModEnabled(
'intervention'),
10303 'label' =>
'LinkToIntervention',
10304 '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') .
')',
10306 'supplier_proposal' => array(
10307 'enabled' => isModEnabled(
'supplier_proposal'),
10309 'label' =>
'LinkToSupplierProposal',
10310 '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' :
''),
10312 'order_supplier' => array(
10313 'enabled' => isModEnabled(
"supplier_order"),
10315 'label' =>
'LinkToSupplierOrder',
10316 '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' :
''),
10318 'invoice_supplier' => array(
10319 'enabled' => isModEnabled(
"supplier_invoice"),
10320 'perms' => 1,
'label' =>
'LinkToSupplierInvoice',
10321 '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' :
''),
10324 'enabled' => isModEnabled(
'ticket'),
10326 'label' =>
'LinkToTicket',
10327 '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' :
''),
10330 'enabled' => isModEnabled(
'mrp'),
10332 'label' =>
'LinkToMo',
10333 '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' :
''),
10338 if (
$object->table_element ==
'commande_fournisseur') {
10339 $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' :
'');
10340 } elseif (
$object->table_element ==
'mrp_mo') {
10341 $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' :
'');
10345 if (!empty($listofidcompanytoscan)) {
10347 $hookmanager->initHooks(array(
'commonobject'));
10348 $parameters = array(
'listofidcompanytoscan' => $listofidcompanytoscan,
'possiblelinks' => $possiblelinks);
10349 $reshook = $hookmanager->executeHooks(
'showLinkToObjectBlock', $parameters,
$object, $action);
10352 if (empty($reshook)) {
10353 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
10354 $possiblelinks = array_merge($possiblelinks, $hookmanager->resArray);
10356 } elseif ($reshook > 0) {
10357 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
10358 $possiblelinks = $hookmanager->resArray;
10362 if (!empty($possiblelinks)) {
10363 $object->fetchObjectLinked();
10367 $htmltoenteralink =
'';
10368 foreach ($possiblelinks as $key => $possiblelink) {
10370 if (empty($possiblelink[
'enabled'])) {
10377 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $key, $regs)) {
10382 if (!empty($possiblelink[
'perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || !in_array($key, $excludelinksto))) {
10383 $htmltoenteralink .=
'<div id="' . $key .
'list"' . (empty(
$conf->use_javascript_ajax) ?
'' :
' style="display:none"') .
'>';
10387 $htmltoenteralink .=
'<br>'.
"\n";
10388 $htmltoenteralink .=
'<!-- form to add a link from anywhere -->'.
"\n";
10389 $htmltoenteralink .=
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinkedbyref' . $key .
'">';
10390 $htmltoenteralink .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
10391 $htmltoenteralink .=
'<input type="hidden" name="action" value="addlinkbyref">';
10392 $htmltoenteralink .=
'<input type="hidden" name="id" value="' .
$object->id .
'">';
10393 $htmltoenteralink .=
'<input type="hidden" name="addlink" value="' . $key .(!empty($module)?
'@'.$module:
'').
'">';
10394 $htmltoenteralink .=
'<table class="noborder">';
10395 $htmltoenteralink .=
'<tr class="liste_titre">';
10397 $htmltoenteralink .=
'<td class="center"><input type="text" placeholder="'.dol_escape_htmltag($langs->trans(
"Ref")).
'" name="reftolinkto" value="' .
dol_escape_htmltag(
GETPOST(
'reftolinkto',
'alpha')) .
'"> ';
10398 $htmltoenteralink .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
'ToLink') .
'"> ';
10399 $htmltoenteralink .=
'<input type="submit" class="button smallpaddingimp" name="cancel" value="' . $langs->trans(
'Cancel') .
'"></td>';
10400 $htmltoenteralink .=
'</tr>';
10401 $htmltoenteralink .=
'</table>';
10402 $htmltoenteralink .=
'</form>';
10405 $sql = $possiblelink[
'sql'];
10407 $resqllist = $this->db->query($sql);
10409 $num = $this->db->num_rows($resqllist);
10415 $htmltoenteralink .=
'<br>';
10417 $htmltoenteralink .=
'<!-- form to add a link from object to same thirdparty -->'.
"\n";
10418 $htmltoenteralink .=
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinked' . $key .
'">';
10419 $htmltoenteralink .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
10420 $htmltoenteralink .=
'<input type="hidden" name="action" value="addlink">';
10421 $htmltoenteralink .=
'<input type="hidden" name="id" value="' .
$object->id .
'">';
10422 $htmltoenteralink .=
'<input type="hidden" name="addlink" value="' . $key . (!empty($module)?
'@'.$module:
'').
'">';
10423 $htmltoenteralink .=
'<table class="noborder">';
10424 $htmltoenteralink .=
'<tr class="liste_titre">';
10425 $htmltoenteralink .=
'<td class="nowrap"></td>';
10426 $htmltoenteralink .=
'<td>' . $langs->trans(
"Ref") .
'</td>';
10427 $htmltoenteralink .=
'<td>' . $langs->trans(
"RefCustomer") .
'</td>';
10428 $htmltoenteralink .=
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
10429 $htmltoenteralink .=
'<td>' . $langs->trans(
"Company") .
'</td>';
10430 $htmltoenteralink .=
'</tr>';
10431 while ($i < $num) {
10432 $objp = $this->db->fetch_object($resqllist);
10433 $alreadylinked =
false;
10434 if (!empty(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key])) {
10435 if (in_array($objp->rowid, array_values(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key]))) {
10436 $alreadylinked =
true;
10439 $htmltoenteralink .=
'<tr class="oddeven">';
10440 $htmltoenteralink .=
'<td>';
10441 if ($alreadylinked) {
10442 $htmltoenteralink .=
img_picto(
'',
'link');
10444 $htmltoenteralink .=
'<input type="checkbox" name="idtolinkto[' . $key .
'_' . $objp->rowid .
']" id="' . $key .
'_' . $objp->rowid .
'" value="' . $objp->rowid .
'">';
10446 $htmltoenteralink .=
'</td>';
10447 $htmltoenteralink .=
'<td><label for="' . $key .
'_' . $objp->rowid .
'">' . $objp->ref .
'</label></td>';
10448 $htmltoenteralink .=
'<td>' . (!empty($objp->ref_client) ? $objp->ref_client : (!empty($objp->ref_supplier) ? $objp->ref_supplier :
'')) .
'</td>';
10449 $htmltoenteralink .=
'<td class="right">';
10450 if ($possiblelink[
'label'] ==
'LinkToContract') {
10451 $htmltoenteralink .= $form->textwithpicto(
'', $langs->trans(
"InformationOnLinkToContract")) .
' ';
10453 $htmltoenteralink .=
'<span class="amount">' . (isset($objp->total_ht) ?
price($objp->total_ht) :
'') .
'</span>';
10454 $htmltoenteralink .=
'</td>';
10455 $htmltoenteralink .=
'<td>' . $objp->name .
'</td>';
10456 $htmltoenteralink .=
'</tr>';
10459 $htmltoenteralink .=
'</table>';
10460 $htmltoenteralink .=
'<div class="center">';
10462 $htmltoenteralink .=
'<input type="submit" class="button valignmiddle marginleftonly marginrightonly smallpaddingimp" value="' . $langs->trans(
'ToLink') .
'">';
10464 if (empty(
$conf->use_javascript_ajax)) {
10465 $htmltoenteralink .=
'<input type="submit" class="button button-cancel marginleftonly marginrightonly smallpaddingimp" name="cancel" value="' . $langs->trans(
"Cancel") .
'"></div>';
10467 $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>';
10469 $htmltoenteralink .=
'</form>';
10472 $this->db->free($resqllist);
10476 $htmltoenteralink .=
'</div>';
10481 $linktoelemlist .=
'<li><a href="#linkto' . $key .
'" class="linkto dropdowncloseonclick" rel="' . $key .
'">' . $langs->trans($possiblelink[
'label']) .
' (' . $num .
')</a></li>';
10484 $linktoelemlist .=
'<li><span class="linktodisabled">' . $langs->trans($possiblelink[
'label']) .
' (0)</span></li>';
10489 if ($linktoelemlist) {
10491 <dl class="dropdown" id="linktoobjectname">
10493 if (!empty(
$conf->use_javascript_ajax)) {
10494 $linktoelem .=
'<dt><a href="#linktoobjectname"><span class="fas fa-link paddingrightonly"></span>' . $langs->trans(
"LinkTo") .
'...</a></dt>';
10496 $linktoelem .=
'<dd>
10497 <div class="multiselectlinkto">
10498 <ul class="ulselectedfields">' . $linktoelemlist .
'
10507 if (!empty(
$conf->use_javascript_ajax)) {
10508 print
'<!-- Add js to show linkto box -->
10509 <script nonce="' .
getNonce() .
'">
10510 jQuery(document).ready(function() {
10511 jQuery(".linkto").click(function() {
10512 console.log("We choose to show/hide links for rel="+jQuery(this).attr(\'rel\')+" so #"+jQuery(this).attr(\'rel\')+"list");
10513 jQuery("#"+jQuery(this).attr(\'rel\')+"list").toggle();
10521 return array(
'linktoelem' => $linktoelem,
'htmltoenteralink' => $htmltoenteralink);
10523 print $htmltoenteralink;
10526 return $linktoelem;
10543 public function selectyesno($htmlname, $value =
'', $option = 0, $disabled =
false, $useempty = 0, $addjscombo = 0, $morecss =
'width75', $labelyes =
'Yes', $labelno =
'No')
10554 $disabled = ($disabled ?
' disabled' :
'');
10556 $resultyesno =
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'"' . $disabled .
'>' .
"\n";
10558 $resultyesno .=
'<option value="-1"' . (($value < 0) ?
' selected' :
'') .
'> </option>' .
"\n";
10560 if ((
"$value" ==
'yes') || ($value == 1)) {
10561 $resultyesno .=
'<option value="' . $yes .
'" selected>' . $langs->trans($labelyes) .
'</option>' .
"\n";
10562 $resultyesno .=
'<option value="' . $no .
'">' . $langs->trans($labelno) .
'</option>' .
"\n";
10564 $selected = (($useempty && $value !=
'0' && $value !=
'no') ?
'' :
' selected');
10565 $resultyesno .=
'<option value="' . $yes .
'">' . $langs->trans($labelyes) .
'</option>' .
"\n";
10566 $resultyesno .=
'<option value="' . $no .
'"' . $selected .
'>' . $langs->trans($labelno) .
'</option>' .
"\n";
10568 $resultyesno .=
'</select>' .
"\n";
10571 $resultyesno .=
ajax_combobox($htmlname, array(), 0, 0,
'resolve', ($useempty < 0 ? (
string) $useempty :
'-1'), $morecss);
10574 return $resultyesno;
10591 $sql =
"SELECT rowid, label";
10592 $sql .=
" FROM " . $this->db->prefix() .
"export_model";
10593 $sql .=
" WHERE type = '" . $this->db->escape($type) .
"'";
10594 $sql .=
" ORDER BY rowid";
10595 $result = $this->db->query($sql);
10597 print
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
10599 print
'<option value="-1"> </option>';
10602 $num = $this->db->num_rows($result);
10604 while ($i < $num) {
10605 $obj = $this->db->fetch_object($result);
10606 if ($selected == $obj->rowid) {
10607 print
'<option value="' . $obj->rowid .
'" selected>';
10609 print
'<option value="' . $obj->rowid .
'">';
10639 public function showrefnav(
$object, $paramid, $morehtml =
'', $shownav = 1, $fieldid =
'rowid', $fieldref =
'ref', $morehtmlref =
'', $moreparam =
'', $nodbprefix = 0, $morehtmlleft =
'', $morehtmlstatus =
'', $morehtmlright =
'')
10641 global
$conf, $langs, $hookmanager, $extralanguages;
10644 if (empty($fieldid)) {
10645 $fieldid =
'rowid';
10647 if (empty($fieldref)) {
10652 $addgendertxt =
'';
10653 if (property_exists(
$object,
'gender') && !empty(
$object->gender)) {
10654 $addgendertxt =
' ';
10657 $addgendertxt .=
'<i class="fas fa-mars valignmiddle"></i>';
10660 $addgendertxt .=
'<i class="fas fa-venus valignmiddle"></i>';
10663 $addgendertxt .=
'<i class="fas fa-transgender valignmiddle"></i>';
10669 if (is_object($hookmanager)) {
10670 $parameters = array(
'showrefnav' =>
true);
10671 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters,
$object);
10672 if (!empty($hookmanager->resPrint)) {
10673 if (empty(
$object->next_prev_filter) && preg_match(
'/^\s*AND/i', $hookmanager->resPrint)) {
10674 $object->next_prev_filter = preg_replace(
'/^\s*AND\s*/i',
'', $hookmanager->resPrint);
10675 } elseif (!empty(
$object->next_prev_filter) && !preg_match(
'/^\s*AND/i', $hookmanager->resPrint)) {
10676 $object->next_prev_filter .=
' AND '.$hookmanager->resPrint;
10678 $object->next_prev_filter .= $hookmanager->resPrint;
10683 $previous_ref = $next_ref =
'';
10686 $object->load_previous_next_ref((isset(
$object->next_prev_filter) ?
$object->next_prev_filter :
''), $fieldid, $nodbprefix);
10688 $navurl = $_SERVER[
"PHP_SELF"];
10690 if ($paramid ==
'project_ref') {
10691 if (preg_match(
'/\/tasks\/(task|contact|note|document)\.php/', $navurl)) {
10692 $navurl = preg_replace(
'/\/tasks\/(task|contact|time|note|document)\.php/',
'/tasks.php', $navurl);
10699 $stringforfirstkey = $langs->trans(
"KeyboardShortcut");
10700 if (
$conf->browser->name ==
'chrome') {
10701 $stringforfirstkey .=
' ALT +';
10702 } elseif (
$conf->browser->name ==
'firefox') {
10703 $stringforfirstkey .=
' ALT + SHIFT +';
10705 $stringforfirstkey .=
' CTL +';
10708 $previous_ref =
$object->ref_previous ?
'<a accesskey="p" alt="'.dol_escape_htmltag($langs->trans(
"Previous")).
'" title="' . $stringforfirstkey .
' p" class="classfortooltip" href="' . $navurl .
'?' . $paramid .
'=' . urlencode(
$object->ref_previous) . $moreparam .
'"><i class="fa fa-chevron-left"></i></a>' :
'<span class="inactive"><i class="fa fa-chevron-left opacitymedium"></i></span>';
10709 $next_ref =
$object->ref_next ?
'<a accesskey="n" alt="'.dol_escape_htmltag($langs->trans(
"Next")).
'" title="' . $stringforfirstkey .
' n" class="classfortooltip" href="' . $navurl .
'?' . $paramid .
'=' . urlencode(
$object->ref_next) . $moreparam .
'"><i class="fa fa-chevron-right"></i></a>' :
'<span class="inactive"><i class="fa fa-chevron-right opacitymedium"></i></span>';
10713 $ret .=
'<!-- Start banner content --><div style="vertical-align: middle">';
10716 if ($morehtmlright) {
10717 $ret .=
'<div class="inline-block floatleft">' . $morehtmlright .
'</div>';
10720 if ($previous_ref || $next_ref || $morehtml) {
10721 $ret .=
'<div class="pagination paginationref"><ul class="right">';
10723 if ($morehtml &&
getDolGlobalInt(
'MAIN_OPTIMIZEFORTEXTBROWSER') < 2) {
10724 $ret .=
'<!-- morehtml --><li class="noborder litext' . (($shownav && $previous_ref && $next_ref) ?
' clearbothonsmartphone' :
'') .
'">' . $morehtml .
'</li>';
10726 if ($shownav && ($previous_ref || $next_ref)) {
10727 $ret .=
'<li class="pagination">' . $previous_ref .
'</li>';
10728 $ret .=
'<li class="pagination">' . $next_ref .
'</li>';
10730 if ($previous_ref || $next_ref || $morehtml) {
10731 $ret .=
'</ul></div>';
10735 $parameters = array(
'morehtmlstatus' => $morehtmlstatus);
10736 $reshook = $hookmanager->executeHooks(
'moreHtmlStatus', $parameters,
$object);
10737 if (empty($reshook)) {
10738 $morehtmlstatus .= $hookmanager->resPrint;
10740 $morehtmlstatus = $hookmanager->resPrint;
10742 if ($morehtmlstatus) {
10743 $ret .=
'<!-- status --><div class="statusref">' . $morehtmlstatus .
'</div>';
10746 $parameters = array();
10747 $reshook = $hookmanager->executeHooks(
'moreHtmlRef', $parameters,
$object);
10748 if (empty($reshook)) {
10749 $morehtmlref .= $hookmanager->resPrint;
10750 } elseif ($reshook > 0) {
10751 $morehtmlref = $hookmanager->resPrint;
10755 if ($morehtmlleft) {
10756 if (
$conf->browser->layout ==
'phone') {
10757 $ret .=
'<!-- morehtmlleft --><div class="floatleft">' . $morehtmlleft .
'</div>';
10759 $ret .=
'<!-- morehtmlleft --><div class="inline-block floatleft">' . $morehtmlleft .
'</div>';
10764 $ret .=
'<!-- Ref or ID --><div class="inline-block floatleft valignmiddle maxwidth750 marginbottomonly refid' . (($shownav && ($previous_ref || $next_ref)) ?
' refidpadding' :
'') .
'">';
10767 if (
$object->element ==
'societe') {
10771 $arrayoflangcode = array();
10776 if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
10777 if (!is_object($extralanguages)) {
10778 include_once DOL_DOCUMENT_ROOT .
'/core/class/extralanguages.class.php';
10781 $extralanguages->fetch_name_extralanguages(
'societe');
10785 if (!empty($extralanguages->attributes[
'societe']) && !empty($extralanguages->attributes[
'societe'][
'name'])) {
10786 $object->fetchValuesForExtraLanguages();
10790 foreach ($arrayoflangcode as $extralangcode) {
10792 if (
$object->array_languages[
'name'][$extralangcode]) {
10793 $htmltext .=
$object->array_languages[
'name'][$extralangcode];
10795 $htmltext .=
'<span class="opacitymedium">' . $langs->trans(
"SwitchInEditModeToAddTranslation") .
'</span>';
10798 $ret .=
'<!-- Show translations of name -->' .
"\n";
10799 $ret .= $this->textwithpicto(
'', $htmltext, -1,
'language',
'opacitymedium paddingleft');
10802 } elseif (
$object->element ==
'member') {
10803 '@phan-var-force Adherent $object';
10804 $ret .=
$object->ref .
'<br>';
10805 $fullname =
$object->getFullName($langs);
10811 } elseif (in_array(
$object->element, array(
'contact',
'user'))) {
10812 $ret .=
'<span class="valignmiddle">'.dol_htmlentities(
$object->getFullName($langs)).
'</span>'.$addgendertxt;
10813 } elseif (
$object->element ==
'usergroup') {
10815 } elseif (in_array(
$object->element, array(
'action',
'agenda'))) {
10816 '@phan-var-force ActionComm $object';
10818 } elseif (in_array(
$object->element, array(
'adherent_type'))) {
10820 } elseif (
$object->element ==
'ecm_directories') {
10822 } elseif (
$object->element ==
'accountingbookkeeping' && !empty(
$object->context[
'mode']) &&
$object->context[
'mode'] ==
'_tmp') {
10823 $ret .= $langs->trans(
"Draft");
10824 } elseif ($fieldref !=
'none') {
10827 if ($morehtmlref) {
10829 if (substr($morehtmlref, 0, 4) !=
'<div') {
10833 $ret .=
'<!-- morehtmlref -->'.$morehtmlref;
10838 $ret .=
'</div><!-- End banner content -->';
10857 if (empty(
$object->barcode)) {
10862 if (empty(
$object->barcode_type_code) || empty(
$object->barcode_type_coder)) {
10864 $result =
$object->fetchBarCode();
10867 return '<!-- ErrorFetchBarcode -->';
10872 $url = DOL_URL_ROOT .
'/viewimage.php?modulepart=barcode&generator=' . urlencode(
$object->barcode_type_coder) .
'&code=' . urlencode(
$object->barcode) .
'&encoding=' . urlencode(
$object->barcode_type_code);
10873 $out =
'<!-- url barcode = ' . $url .
' -->';
10874 $out .=
'<img src="' . $url .
'"' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
'>';
10896 public static function showphoto($modulepart,
$object, $width = 100, $height = 0, $caneditfield = 0, $cssclass =
'photowithmargin', $imagesize =
'', $addlinktofullsize = 1, $cache = 0, $forcecapture =
'', $noexternsourceoverwrite = 0)
10898 global
$conf, $langs;
10905 $originalfile =
'';
10909 if ($modulepart ==
'societe') {
10910 $dir =
$conf->societe->multidir_output[$entity];
10913 if ((
string) $imagesize ==
'mini') {
10915 } elseif ((
string) $imagesize ==
'small') {
10924 } elseif ($modulepart ==
'contact') {
10925 $dir =
$conf->societe->multidir_output[$entity] .
'/contact';
10926 if (!empty(
$object->photo)) {
10928 if ((
string) $imagesize ==
'mini') {
10930 } elseif ((
string) $imagesize ==
'small') {
10940 } elseif ($modulepart ==
'userphoto') {
10941 $dir =
$conf->user->dir_output;
10942 if (!empty(
$object->photo)) {
10944 if ((
string) $imagesize ==
'mini') {
10946 } elseif ((
string) $imagesize ==
'small') {
10955 $altfile =
$object->id .
".jpg";
10959 } elseif ($modulepart ==
'memberphoto') {
10960 $dir =
$conf->adherent->dir_output;
10961 if (!empty(
$object->photo)) {
10963 if ((
string) $imagesize ==
'mini') {
10965 } elseif ((
string) $imagesize ==
'small') {
10974 $altfile =
$object->id .
".jpg";
10981 if ($modulepart !=
"unknown" && method_exists(
$object,
'getDataToShowPhoto')) {
10982 $tmpdata =
$object->getDataToShowPhoto($modulepart, $imagesize);
10984 $dir = $tmpdata[
'dir'];
10985 $file = $tmpdata[
'file'];
10986 $originalfile = $tmpdata[
'originalfile'];
10987 $altfile = $tmpdata[
'altfile'];
10988 $email = $tmpdata[
'email'];
10989 $capture = $tmpdata[
'capture'];
10993 if ($forcecapture) {
10994 $capture = $forcecapture;
11000 if ($file && file_exists($dir .
"/" . $file)) {
11001 if ($addlinktofullsize) {
11003 if ($urladvanced) {
11004 $ret .=
'<a href="' . $urladvanced .
'">';
11006 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
11009 $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 .
'">';
11010 if ($addlinktofullsize) {
11013 } elseif ($altfile && file_exists($dir .
"/" . $altfile)) {
11014 if ($addlinktofullsize) {
11016 if ($urladvanced) {
11017 $ret .=
'<a href="' . $urladvanced .
'">';
11019 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
11022 $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 .
'">';
11023 if ($addlinktofullsize) {
11027 $nophoto =
'/public/theme/common/nophoto.png';
11028 $defaultimg =
'identicon';
11029 if (in_array($modulepart, array(
'societe',
'userphoto',
'contact',
'memberphoto'))) {
11030 if ($modulepart ==
'societe' || ($modulepart ==
'memberphoto' && !empty(
$object->morphy) && strpos(
$object->morphy,
'mor') !==
false)) {
11031 $nophoto =
'company';
11033 $nophoto =
'/public/theme/common/user_anonymous.png';
11035 $nophoto =
'/public/theme/common/user_man.png';
11038 $nophoto =
'/public/theme/common/user_woman.png';
11043 if (isModEnabled(
'gravatar') && $email && empty($noexternsourceoverwrite)) {
11045 $ret .=
'<!-- Put link to gravatar -->';
11046 $ret .=
'<img class="photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" title="' . $email .
' Gravatar avatar" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="https://www.gravatar.com/avatar/' .
dol_hash(strtolower(trim($email)),
'sha256', 1) .
'?s=' . $width .
'&d=' . $defaultimg .
'">';
11048 if ($nophoto ==
'company') {
11049 $ret .=
'<div class="divforspanimg valignmiddle center photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
'>' .
img_picto(
'',
'company') .
'</div>';
11052 $ret .=
'<img class="photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="' . DOL_URL_ROOT . $nophoto .
'">';
11057 if ($caneditfield) {
11061 $ret .=
'<table class="nobordernopadding centpercent">';
11063 $ret .=
'<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> <label for="photodelete">' . $langs->trans(
"Delete") .
'</label><br><br></td></tr>';
11065 $ret .=
'<tr><td class="tdoverflow">';
11067 $maxmin = $maxfilesizearray[
'maxmin'];
11069 $ret .=
'<input type="hidden" name="MAX_FILE_SIZE" value="' . ($maxmin * 1024) .
'">';
11071 $ret .=
'<input type="file" class="flat maxwidth200onsmartphone" name="photo" id="photoinput" accept="image/*"' . ($capture ?
' capture="' .
dolPrintHTMLForAttribute($capture) .
'"' :
'') .
'>';
11072 $ret .=
'</td></tr>';
11073 $ret .=
'</table>';
11098 public function select_dolgroups($selected = 0, $htmlname =
'groupid', $show_empty = 0, $exclude =
'', $disabled = 0, $include =
'', $enableonly = array(), $force_entity =
'0', $multiple =
false, $morecss =
'minwidth200')
11101 global
$conf, $user, $langs;
11104 $excludeGroups =
null;
11105 if (is_array($exclude)) {
11106 $excludeGroups = implode(
",", $exclude);
11109 $includeGroups =
null;
11110 if (is_array($include)) {
11111 $includeGroups = implode(
",", $include);
11114 if (!is_array($selected)) {
11115 $selected = array($selected);
11121 $sql =
"SELECT ug.rowid, ug.nom as name";
11122 if (isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && !$user->entity) {
11123 $sql .=
", e.label";
11125 $sql .=
" FROM " . $this->db->prefix() .
"usergroup as ug ";
11126 if (isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && !$user->entity) {
11127 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid=ug.entity";
11128 if ($force_entity) {
11129 $sql .=
" WHERE ug.entity IN (0, " . $force_entity .
")";
11131 $sql .=
" WHERE ug.entity IS NOT NULL";
11134 $sql .=
" WHERE ug.entity IN (0, " .
$conf->entity .
")";
11136 if (is_array($exclude) && $excludeGroups) {
11137 $sql .=
" AND ug.rowid NOT IN (" . $this->db->sanitize($excludeGroups) .
")";
11139 if (is_array($include) && $includeGroups) {
11140 $sql .=
" AND ug.rowid IN (" . $this->db->sanitize($includeGroups) .
")";
11142 $sql .=
" ORDER BY ug.nom ASC";
11144 dol_syslog(get_class($this) .
"::select_dolgroups", LOG_DEBUG);
11145 $resql = $this->db->query($sql);
11148 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
11150 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
11152 $num = $this->db->num_rows($resql);
11155 if ($show_empty && !$multiple) {
11156 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'> </option>' .
"\n";
11159 while ($i < $num) {
11160 $obj = $this->db->fetch_object($resql);
11162 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
11166 $label = $obj->name;
11167 $labelhtml = $obj->name;
11168 if (isModEnabled(
'multicompany') && !
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE') &&
$conf->entity == 1) {
11169 $label .=
" (" . $obj->label .
")";
11170 $labelhtml .=
' <span class="opacitymedium">(' . $obj->label .
')</span>';
11173 $out .=
'<option value="' . $obj->rowid .
'"';
11174 if ($disableline) {
11175 $out .=
' disabled';
11177 if ((isset($selected[0]) && is_object($selected[0]) && $selected[0]->
id == $obj->rowid)
11178 || ((!isset($selected[0]) || !is_object($selected[0])) && !empty($selected) && in_array($obj->rowid, $selected))) {
11179 $out .=
' selected';
11181 $out .=
' data-html="'.dol_escape_htmltag($labelhtml).
'"';
11184 $out .=
'</option>';
11189 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'></option>' .
"\n";
11191 $out .=
'<option value="" disabled>' . $langs->trans(
"NoUserGroupDefined") .
'</option>';
11193 $out .=
'</select>';
11212 $out =
'<div class="nowraponall">';
11213 $out .=
'<button type="submit" class="liste_titre button_search reposition" name="button_search_x" value="x"><span class="fas fa-search"></span></button>';
11214 $out .=
'<button type="submit" class="liste_titre button_removefilter reposition" name="button_removefilter_x" value="x"><span class="fas fa-times"></span></button>';
11228 public function showCheckAddButtons($cssclass =
'checkforaction', $calljsfunction = 0, $massactionname =
"massaction")
11234 if (!empty(
$conf->use_javascript_ajax)) {
11235 $out .=
'<div class="inline-block checkallactions"><input type="checkbox" id="' . $cssclass .
's" name="' . $cssclass .
's" class="checkallactions"></div>';
11237 $out .=
'<script nonce="' .
getNonce() .
'">
11238 $(document).ready(function() {
11239 $("#' . $cssclass .
's").click(function() {
11240 if($(this).is(\':checked\')){
11241 console.log("We check all ' . $cssclass .
' and trigger the change method");
11242 $(".' . $cssclass .
'").prop(\'checked\', true).trigger(\'change\');
11246 console.log("We uncheck all");
11247 $(".' . $cssclass .
'").prop(\'checked\', false).trigger(\'change\');
11249 if ($calljsfunction) {
11250 $out .=
'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0, "' . $massactionname .
'", "' . $cssclass .
'"); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }';
11253 $(".' . $cssclass .
'").change(function() {
11254 console.log("We check and change the tr class highlight after a change on .'.$cssclass.
'");
11255 var $row = $(this).closest("tr");
11257 var anyChecked = $row.find(\'input[type="checkbox"].checkforselect:checked\').length > 0;
11258 console.log(anyChecked);
11260 $row.removeClass("highlight");
11262 $row.addClass("highlight");
11283 $out = $this->showFilterButtons();
11284 if ($addcheckuncheckall) {
11285 $out .= $this->showCheckAddButtons($cssclass, $calljsfunction, $massactionname);
11303 public function selectExpenseCategories($selected =
'', $htmlname =
'fk_c_exp_tax_cat', $useempty = 0, $excludeid = array(), $target =
'', $default_selected = 0, $params = array(), $info_admin = 1)
11305 global $langs, $user;
11308 $sql =
"SELECT rowid, label FROM " . $this->db->prefix() .
"c_exp_tax_cat WHERE active = 1";
11309 $sql .=
" AND entity IN (0," .
getEntity(
'exp_tax_cat') .
")";
11310 if (!empty($excludeid)) {
11311 $sql .=
" AND rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeid)) .
")";
11313 $sql .=
" ORDER BY label";
11315 $resql = $this->db->query($sql);
11317 $out =
'<select id="select_' . $htmlname .
'" name="' . $htmlname .
'" class="' . $htmlname .
' flat minwidth75imp maxwidth200">';
11319 $out .=
'<option value="0"> </option>';
11322 while ($obj = $this->db->fetch_object($resql)) {
11323 $out .=
'<option ' . ($selected == $obj->rowid ?
'selected="selected"' :
'') .
' value="' . $obj->rowid .
'">' . $langs->trans($obj->label) .
'</option>';
11325 $out .=
'</select>';
11328 if (!empty($htmlname) && $user->admin && $info_admin) {
11329 $out .=
' ' .
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
11332 if (!empty($target)) {
11333 $sql =
"SELECT c.id FROM " . $this->db->prefix() .
"c_type_fees as c WHERE c.code = 'EX_KME' AND c.active = 1";
11334 $resql = $this->db->query($sql);
11336 if ($this->db->num_rows($resql) > 0) {
11337 $obj = $this->db->fetch_object($resql);
11338 $out .=
'<script nonce="' .
getNonce() .
'">
11340 $("select[name=' . $target .
']").on("change", function() {
11341 var current_val = $(this).val();
11342 if (current_val == ' . $obj->id .
') {';
11343 if (!empty($default_selected) || !empty($selected)) {
11344 $out .=
'$("select[name=' . $htmlname .
']").val("' . ($default_selected > 0 ? $default_selected : $selected) .
'");';
11348 $("select[name=' . $htmlname .
']").change();
11352 $("select[name=' . $htmlname .
']").change(function() {
11354 if ($("select[name=' . $target .
']").val() == ' . $obj->id .
') {
11355 // get price of kilometer to fill the unit price
11359 data: { fk_c_exp_tax_cat: $(this).val(), token: \'' .
currentToken() .
'\' },
11360 url:
"' . (DOL_URL_ROOT . '/expensereport/ajax/ajaxik.php?' . implode('&', $params)) . '",
11361 }).done(
function( data, textStatus, jqXHR ) {
11363 if (typeof data.up !=
"undefined") {
11364 $(
"input[name=value_unit]").val(data.up);
11365 $(
"select[name=' . $htmlname . ']").attr(
"title", data.title);
11367 $(
"input[name=value_unit]").val(
"");
11368 $(
"select[name=' . $htmlname . ']").attr(
"title",
"");
11379 dol_print_error($this->db);
11393 public function selectExpenseRanges($selected = '
', $htmlname = 'fk_range
', $useempty = 0)
11395 global $conf, $langs;
11398 $sql = "SELECT rowid, range_ik FROM " . $this->db->prefix() . "c_exp_tax_range";
11399 $sql .= " WHERE entity = " . $conf->entity . " AND active = 1";
11401 $resql = $this->db->query($sql);
11403 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
11405 $out .= '<option value=
"0"></option>
';
11408 while ($obj = $this->db->fetch_object($resql)) {
11409 $out .= '<option
' . ($selected == $obj->rowid ? 'selected=
"selected"' : '') . ' value=
"' . $obj->rowid . '">
' . price($obj->range_ik, 0, $langs, 1, 0) . '</option>
';
11411 $out .= '</select>
';
11413 dol_print_error($this->db);
11429 public function selectExpense($selected = '
', $htmlname = 'fk_c_type_fees
', $useempty = 0, $allchoice = 1, $useid = 0)
11434 $sql = "SELECT id, code, label";
11435 $sql .= " FROM ".$this->db->prefix()."c_type_fees";
11436 $sql .= " WHERE active = 1";
11438 $resql = $this->db->query($sql);
11440 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
11442 $out .= '<option value=
"0"></option>
';
11445 $out .= '<option value=
"-1">
' . $langs->trans('AllExpenseReport
') . '</option>
';
11453 while ($obj = $this->db->fetch_object($resql)) {
11454 $key = $langs->trans($obj->code);
11455 $out .= '<option
' . ($selected == $obj->{$field} ? 'selected=
"selected"' : '') . ' value=
"' . $obj->{$field} . '">
' . ($key != $obj->code ? $key : $obj->label) . '</option>
';
11457 $out .= '</select>
';
11459 $out .= ajax_combobox('select_
'.$htmlname);
11461 dol_print_error($this->db);
11485 public function selectInvoice($socid = -1, $selected = '
', $htmlname = 'invoiceid
', $maxlength = 24, $option_only = 0, $show_empty = '1
', $discard_closed = 0, $forcefocus = 0, $disabled = 0, $morecss = 'maxwidth500
', $projectsListId = '', $showproject = 'all
', $usertofilter = null)
11487 global $user, $conf, $langs;
11489 require_once DOL_DOCUMENT_ROOT . '/projet/
class/project.class.php
';
11491 if (is_null($usertofilter)) {
11492 $usertofilter = $user;
11497 $hideunselectables = false;
11498 if (getDolGlobalString('INVOICE_HIDE_UNSELECTABLES
')) {
11499 $hideunselectables = true;
11502 if (empty($projectsListId)) {
11503 if (!$usertofilter->hasRight('projet
', 'all
', 'lire
')) {
11504 $projectstatic = new Project($this->db);
11505 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1);
11509 // Search all projects
11510 $sql = "SELECT f.rowid, f.ref as fref, 'nolabel
' as flabel, p.rowid as pid, f.ref,
11511 p.title, p.fk_soc, p.fk_statut, p.public,";
11512 $sql .= ' s.nom as
name';
11513 $sql .= ' FROM
' . $this->db->prefix() . 'projet as p
';
11514 $sql .= ' LEFT JOIN
' . $this->db->prefix() . 'societe as s ON s.rowid = p.fk_soc,
';
11515 $sql .= ' ' . $this->db->prefix() . 'facture as f
';
11516 $sql .= " WHERE p.entity IN (" . getEntity('project
') . ")";
11517 $sql .= " AND f.fk_projet = p.rowid AND f.fk_statut=0"; //Brouillons seulement
11518 //if ($projectsListId) $sql.= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")";
11519 //if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
11520 //if ($socid > 0) $sql.= " AND (p.fk_soc=".((int) $socid)." OR p.fk_soc IS NULL)";
11521 $sql .= " ORDER BY p.ref, f.ref ASC";
11523 $resql = $this->db->query($sql);
11525 // Use select2 selector
11526 if (!empty($conf->use_javascript_ajax)) {
11527 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
11528 $comboenhancement = ajax_combobox($htmlname, array(), 0, $forcefocus);
11529 $out .= $comboenhancement;
11530 $morecss = 'minwidth200imp maxwidth500
';
11533 if (empty($option_only)) {
11534 $out .= '<select
class=
"valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled=
"disabled"' : '') . ' id=
"' . $htmlname . '" name=
"' . $htmlname . '">
';
11536 if (!empty($show_empty)) {
11537 $out .= '<option value=
"0" class=
"optiongrey">
';
11538 if (!is_numeric($show_empty)) {
11539 $out .= $show_empty;
11543 $out .= '</option>
';
11545 $num = $this->db->num_rows($resql);
11548 while ($i < $num) {
11549 $obj = $this->db->fetch_object($resql);
11550 // 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.
11551 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$usertofilter->hasRight('societe
', 'lire
')) {
11554 if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) {
11561 if ($showproject == 'all
') {
11562 $labeltoshow .= dol_trunc($obj->ref, 18); // Invoice ref
11564 $labeltoshow .= ' -
' . $obj->name; // Soc name
11568 if ($obj->fk_statut == Project::STATUS_DRAFT) {
11570 $labeltoshow .= ' -
' . $langs->trans("Draft");
11571 } elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
11572 if ($discard_closed == 2) {
11575 $labeltoshow .= ' -
' . $langs->trans("Closed");
11576 } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
11578 $labeltoshow .= ' -
' . $langs->trans("LinkedToAnotherCompany");
11582 if (!empty($selected) && $selected == $obj->rowid) {
11583 $out .= '<option value=
"' . $obj->rowid . '" selected
';
11584 //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected
if disabled
11585 $out .=
'>' . $labeltoshow .
'</option>';
11587 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
11590 $resultat =
'<option value="' . $obj->rowid .
'"';
11592 $resultat .=
' disabled';
11597 $resultat .= $labeltoshow;
11598 $resultat .=
'</option>';
11606 if (empty($option_only)) {
11607 $out .=
'</select>';
11610 $this->db->free($resql);
11632 public function selectInvoiceRec($selected =
'', $htmlname =
'facrecid', $maxlength = 24, $option_only = 0, $show_empty =
'1', $forcefocus = 0, $disabled = 0, $morecss =
'maxwidth500')
11634 global
$conf, $langs;
11640 $sql =
'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc';
11642 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'facture_rec as f';
11643 $sql .=
" WHERE f.entity IN (" .
getEntity(
'invoice') .
")";
11644 $sql .=
" ORDER BY f.titre ASC";
11646 $resql = $this->db->query($sql);
11649 if (!empty(
$conf->use_javascript_ajax)) {
11650 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
11651 $comboenhancement =
ajax_combobox($htmlname, array(), 0, $forcefocus);
11652 $out .= $comboenhancement;
11653 $morecss =
'minwidth200imp maxwidth500';
11656 if (empty($option_only)) {
11657 $out .=
'<select class="valignmiddle flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' id="' . $htmlname .
'" name="' . $htmlname .
'">';
11659 if (!empty($show_empty)) {
11660 $out .=
'<option value="0" class="optiongrey">';
11661 if (!is_numeric($show_empty)) {
11662 $out .= $show_empty;
11666 $out .=
'</option>';
11668 $num = $this->db->num_rows($resql);
11670 while ($obj = $this->db->fetch_object($resql)) {
11671 $labeltoshow =
dol_trunc($obj->title, 18);
11674 if (!empty($obj->suspended)) {
11676 $labeltoshow .=
' - ' . $langs->trans(
"Closed");
11680 if (!empty($selected) && $selected == $obj->rowid) {
11681 $out .=
'<option value="' . $obj->rowid .
'" selected';
11683 $out .=
'>' . $labeltoshow .
'</option>';
11685 if ($disabled && ($selected != $obj->rowid)) {
11688 $resultat =
'<option value="' . $obj->rowid .
'"';
11690 $resultat .=
' disabled';
11693 $resultat .= $labeltoshow;
11694 $resultat .=
'</option>';
11700 if (empty($option_only)) {
11701 $out .=
'</select>';
11706 $this->db->free($resql);
11709 $this->errors[] = $this->db->lasterror;
11730 public function selectOrder($selected =
'', $htmlname =
'orderid', $maxlength = 24, $option_only = 0, $show_empty =
'1', $discard_closed = 0, $forcefocus = 0, $disabled = 0, $morecss =
'maxwidth500')
11732 global $user,
$conf, $langs;
11736 $hideunselectables =
false;
11738 $hideunselectables =
true;
11742 $sql =
"SELECT c.rowid, c.ref";
11743 $sql .=
' FROM '.$this->db->prefix().
'commande as c';
11744 $sql .=
" ORDER BY c.ref ASC";
11746 $resql = $this->db->query($sql);
11749 if (!empty(
$conf->use_javascript_ajax)) {
11750 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
11751 $comboenhancement =
ajax_combobox($htmlname, array(), 0, $forcefocus);
11752 $out .= $comboenhancement;
11753 $morecss =
'minwidth200imp maxwidth500';
11756 if (empty($option_only)) {
11757 $out .=
'<select class="valignmiddle flat'.($morecss ?
' '.$morecss :
'').
'"'.($disabled ?
' disabled="disabled"' :
'').
' id="'.$htmlname.
'" name="'.$htmlname.
'">';
11759 if (!empty($show_empty)) {
11760 $out .=
'<option value="0" class="optiongrey">';
11761 if (!is_numeric($show_empty)) {
11762 $out .= $show_empty;
11766 $out .=
'</option>';
11768 $num = $this->db->num_rows($resql);
11771 while ($i < $num) {
11772 $obj = $this->db->fetch_object($resql);
11779 $labeltoshow =
dol_trunc($obj->ref, 18);
11781 if (!empty($selected) && $selected == $obj->rowid) {
11782 $out .=
'<option value="'.$obj->rowid.
'" selected';
11784 $out .=
'>'.$labeltoshow.
'</option>';
11786 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
11789 $resultat =
'<option value="'.$obj->rowid.
'"';
11791 $resultat .=
' disabled';
11796 $resultat .= $labeltoshow;
11797 $resultat .=
'</option>';
11804 if (empty($option_only)) {
11805 $out .=
'</select>';
11810 $this->db->free($resql);
11833 public function selectSupplierOrder($selected =
'', $htmlname =
'supplierorderid', $maxlength = 24, $option_only = 0, $show_empty =
'1', $discard_closed = 0, $forcefocus = 0, $disabled = 0, $morecss =
'maxwidth500')
11835 global $user,
$conf, $langs;
11839 $hideunselectables =
false;
11841 $hideunselectables =
true;
11845 $sql =
"SELECT cf.rowid, cf.ref";
11846 $sql .=
' FROM '.$this->db->prefix().
'commande_fournisseur as cf';
11847 $sql .=
" ORDER BY cf.ref ASC";
11849 $resql = $this->db->query($sql);
11852 if (!empty(
$conf->use_javascript_ajax)) {
11853 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
11854 $comboenhancement =
ajax_combobox($htmlname, array(), 0, $forcefocus);
11855 $out .= $comboenhancement;
11856 $morecss =
'minwidth200imp maxwidth500';
11859 if (empty($option_only)) {
11860 $out .=
'<select class="valignmiddle flat'.($morecss ?
' '.$morecss :
'').
'"'.($disabled ?
' disabled="disabled"' :
'').
' id="'.$htmlname.
'" name="'.$htmlname.
'">';
11862 if (!empty($show_empty)) {
11863 $out .=
'<option value="0" class="optiongrey">';
11864 if (!is_numeric($show_empty)) {
11865 $out .= $show_empty;
11869 $out .=
'</option>';
11871 $num = $this->db->num_rows($resql);
11874 while ($i < $num) {
11875 $obj = $this->db->fetch_object($resql);
11882 $labeltoshow =
dol_trunc($obj->ref, 18);
11884 if (!empty($selected) && $selected == $obj->rowid) {
11885 $out .=
'<option value="'.$obj->rowid.
'" selected';
11887 $out .=
'>'.$labeltoshow.
'</option>';
11889 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
11892 $resultat =
'<option value="'.$obj->rowid.
'"';
11894 $resultat .=
' disabled';
11899 $resultat .= $labeltoshow;
11900 $resultat .=
'</option>';
11907 if (empty($option_only)) {
11908 $out .=
'</select>';
11913 $this->db->free($resql);
11936 public function selectSupplierInvoice($selected =
'', $htmlname =
'supplierinvoiceid', $maxlength = 24, $option_only = 0, $show_empty =
'1', $discard_closed = 0, $forcefocus = 0, $disabled = 0, $morecss =
'maxwidth500')
11938 global $user,
$conf, $langs;
11942 $hideunselectables =
false;
11944 $hideunselectables =
true;
11948 $sql =
"SELECT ff.rowid, ff.ref";
11949 $sql .=
' FROM '.$this->db->prefix().
'facture_fourn as ff';
11950 $sql .=
" ORDER BY ff.ref ASC";
11952 $resql = $this->db->query($sql);
11955 if (!empty(
$conf->use_javascript_ajax)) {
11956 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
11957 $comboenhancement =
ajax_combobox($htmlname, array(), 0, $forcefocus);
11958 $out .= $comboenhancement;
11959 $morecss =
'minwidth200imp maxwidth500';
11962 if (empty($option_only)) {
11963 $out .=
'<select class="valignmiddle flat'.($morecss ?
' '.$morecss :
'').
'"'.($disabled ?
' disabled="disabled"' :
'').
' id="'.$htmlname.
'" name="'.$htmlname.
'">';
11965 if (!empty($show_empty)) {
11966 $out .=
'<option value="0" class="optiongrey">';
11967 if (!is_numeric($show_empty)) {
11968 $out .= $show_empty;
11972 $out .=
'</option>';
11974 $num = $this->db->num_rows($resql);
11977 while ($i < $num) {
11978 $obj = $this->db->fetch_object($resql);
11985 $labeltoshow =
dol_trunc($obj->ref, 18);
11987 if (!empty($selected) && $selected == $obj->rowid) {
11988 $out .=
'<option value="'.$obj->rowid.
'" selected';
11990 $out .=
'>'.$labeltoshow.
'</option>';
11992 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
11995 $resultat =
'<option value="'.$obj->rowid.
'"';
11997 $resultat .=
' disabled';
12002 $resultat .= $labeltoshow;
12003 $resultat .=
'</option>';
12010 if (empty($option_only)) {
12011 $out .=
'</select>';
12016 $this->db->free($resql);
12034 public function searchComponent($arrayofcriterias, $search_component_params, $arrayofinputfieldsalreadyoutput = array(), $search_component_params_hidden =
'', $arrayoffiltercriterias = array())
12037 global $langs, $form;
12042 if ($search_component_params_hidden !=
'' && !preg_match(
'/^\(.*\)$/', $search_component_params_hidden)) {
12043 $search_component_params_hidden =
'(' . $search_component_params_hidden .
')';
12046 $ret =
'<!-- searchComponent -->';
12048 $ret .=
'<div class="divadvancedsearchfieldcomp centpercent inline-block">';
12049 $ret .=
'<a href="#" class="dropdownsearch-toggle unsetcolor">';
12050 $ret .=
'<span class="fas fa-filter linkobject boxfilter paddingright pictofixedwidth" title="' .
dol_escape_htmltag($langs->trans(
"Filters")) .
'" id="idsubimgproductdistribution"></span>';
12053 $ret .=
'<div class="divadvancedsearchfieldcompinput inline-block minwidth500 maxwidth300onsmartphone">';
12056 $ret .=
'<div id="divsearch_component_params" name="divsearch_component_params" class="noborderbottom search_component_params inline-block valignmiddle">';
12058 if ($search_component_params_hidden) {
12066 foreach ($arrayofandtags as $tmpkey => $tmpval) {
12067 $errormessage =
'';
12069 if ($errormessage) {
12070 $this->error =
'ERROR in parsing search string: '.$errormessage;
12073 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
12076 $ret .=
'<span class="marginleftonlyshort valignmiddle tagsearch" data-ufilterid="'.($tmpkey + 1).
'" data-ufilter="'.
dol_escape_htmltag($tmpval).
'">';
12077 $ret .=
'<span class="tagsearchdelete select2-selection__choice__remove" data-ufilterid="'.($tmpkey + 1).
'">x</span> ';
12089 $show_search_component_params_hidden = 1;
12090 if ($show_search_component_params_hidden) {
12091 $ret .=
'<input type="hidden" name="show_search_component_params_hidden" value="1">';
12093 $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%')) -->";
12094 $ret .=
'<input type="hidden" id="search_component_params_hidden" name="search_component_params_hidden" value="' .
dol_escape_htmltag($search_component_params_hidden) .
'">';
12099 foreach ($arrayofcriterias as $criteria) {
12100 foreach ($criteria as $criteriafamilykey => $criteriafamilyval) {
12101 if (in_array(
'search_' . $criteriafamilykey, $arrayofinputfieldsalreadyoutput)) {
12104 if (in_array($criteriafamilykey, array(
'rowid',
'ref_ext',
'entity',
'extraparams'))) {
12107 if (in_array($criteriafamilyval[
'type'], array(
'date',
'datetime',
'timestamp'))) {
12108 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_start">';
12109 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startyear">';
12110 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startmonth">';
12111 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startday">';
12112 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_end">';
12113 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endyear">';
12114 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endmonth">';
12115 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endday">';
12117 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'">';
12124 $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";
12125 $ret .=
'<input type="text" placeholder="' . $langs->trans(
"Filters") .
'" id="search_component_params_input" name="search_component_params_input" class="noborderbottom search_component_input" value="">';
12131 jQuery(".tagsearchdelete").click(function(e) {
12132 var filterid = $(this).parents().attr("data-ufilterid");
12133 console.log("We click to delete the criteria nb "+filterid);
12135 // Regenerate the search_component_params_hidden with all data-ufilter except the one to delete, and post the page
12136 var newparamstring = \'\';
12137 $(\'.tagsearch\').each(function(index, element) {
12138 tmpfilterid = $(this).attr("data-ufilterid");
12139 if (tmpfilterid != filterid) {
12140 // We keep this criteria
12141 if (newparamstring == \'\') {
12142 newparamstring = $(this).attr("data-ufilter");
12144 newparamstring = newparamstring + \' AND \' + $(this).attr("data-ufilter");
12148 console.log("newparamstring = "+newparamstring);
12150 jQuery("#search_component_params_hidden").val(newparamstring);
12152 // We repost the form
12153 $(this).closest(\'form\').submit();
12156 jQuery("#search_component_params_input").keydown(function(e) {
12157 console.log("We press a key on the filter field that is "+jQuery("#search_component_params_input").val());
12158 console.log(e.which);
12159 if (jQuery("#search_component_params_input").val() == "" && e.which == 8) {
12160 /* We click on back when the input field is already empty */
12161 event.preventDefault();
12162 jQuery("#divsearch_component_params .tagsearch").last().remove();
12163 /* Regenerate content of search_component_params_hidden from remaining .tagsearch */
12165 jQuery("#divsearch_component_params .tagsearch").each(function( index ) {
12169 s = s + $(this).attr("data-ufilter");
12171 console.log("New value for search_component_params_hidden = "+s);
12172 jQuery("#search_component_params_hidden").val(s);
12180 $arrayoffiltercriterias_json = json_encode($arrayoffiltercriterias);
12182 var arrayoffiltercriterias = ' . $arrayoffiltercriterias_json .
';
12186 $arrayoffilterfieldslabel = array();
12187 foreach ($arrayoffiltercriterias as $key => $val) {
12188 $arrayoffilterfieldslabel[$key][
'label'] = $val[
'label'];
12189 $arrayoffilterfieldslabel[$key][
'data-type'] = $val[
'type'];
12193 $ret .=
'<div class="search-component-assistance">';
12196 $ret .=
'<p class="assistance-title">' .
img_picto(
'',
'filter') .
' ' . $langs->trans(
'FilterAssistance') .
' </p>';
12198 $ret .=
'<p class="assistance-errors error" style="display:none">' . $langs->trans(
'AllFieldsRequired') .
' </p>';
12200 $ret .=
'<div class="operand">';
12201 $ret .= $form->selectarray(
'search_filter_field', $arrayoffilterfieldslabel,
'', $langs->trans(
"Fields"), 0, 0,
'', 0, 0, 0,
'',
'width200 combolargeelem', 1);
12204 $ret .=
'<span class="separator"></span>';
12207 $ret .=
'<div class="operator">';
12208 $ret .=
'<select class="operator-selector width150" id="operator-selector"">';
12209 $ret .=
'</select>';
12210 $ret .=
'<script>$(document).ready(function() {';
12211 $ret .=
' $(".operator-selector").select2({';
12212 $ret .=
' placeholder: \'' .
dol_escape_js($langs->transnoentitiesnoconv(
'Operator')) .
'\'';
12214 $ret .=
'});</script>';
12217 $ret .=
'<span class="separator"></span>';
12219 $ret .=
'<div class="value">';
12221 $ret .=
'<input type="text" class="flat width100 value-input" placeholder="' .
dolPrintHTML($langs->trans(
'Value')) .
'">';
12225 $ret .=
'<span class="date-one" style="display:none">';
12226 $ret .= $form->selectDate(($dateOne ? $dateOne : -1),
'dateone', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'');
12230 $ret .=
'<select class="value-selector width150" id="value-selector" style="display:none">';
12231 $ret .=
'</select>';
12233 $(document).ready(function() {
12234 $("#value-selector").select2({
12235 placeholder: "' .
dol_escape_js($langs->trans(
'Value')) .
'"
12237 $("#value-selector").hide();
12238 $("#value-selector").next(".select2-container").hide();
12244 $ret .=
'<div class="btn-div">';
12245 $ret .=
'<button class="button buttongen button-save add-filter-btn" type="button">' . $langs->trans(
"addToFilter") .
'</button>';
12256 $(document).ready(function() {
12257 $("#search_component_params_input").on("click", function() {
12258 const inputPosition = $(this).offset();
12259 const inputHeight = $(this).outerHeight();
12260 $(".search-component-assistance").css({
12261 top: inputPosition.top + inputHeight + 5 + "px",
12262 left: $("#divsearch_component_params").position().left
12263 }).slideToggle(200);
12265 $(document).on("click", function(e) {
12266 if (!$(e.target).closest("#search_component_params_input, .search-component-assistance, #ui-datepicker-div").length) {
12267 $(".search-component-assistance").hide();
12274 $(document).ready(function() {
12275 $(".search_filter_field").on("change", function() {
12276 console.log("We change search_filter_field");
12279 const selectedField = $(this).find(":selected");
12280 let fieldType = selectedField.data("type");
12281 const selectedFieldValue = selectedField.val();
12283 // If the selected field has an array of values then ask toshow the value selector instead of the value input
12284 if (arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"] !== undefined) {
12285 fieldType = "select";
12288 // If the selected field may be null then ask to append the "IsDefined" and "IsNotDefined" operators
12289 if (arrayoffiltercriterias[selectedFieldValue]["maybenull"] !== undefined) {
12292 const operators = getOperatorsForFieldType(fieldType, maybenull);
12293 const operatorSelector = $(".operator-selector");
12295 // Clear existing options
12296 operatorSelector.empty();
12298 // Populate operators
12299 Object.entries(operators).forEach(function([operator, label]) {
12300 operatorSelector.append("<option value=\'" + operator + "\'>" + label + "</option>");
12303 operatorSelector.trigger("change.select2");
12305 // Clear and hide all input elements initially
12306 $(".value-input, .dateone, .datemonth, .dateyear").val("").hide();
12307 $("#datemonth, #dateyear").val(null).trigger("change.select2");
12308 $("#dateone").datepicker("setDate", null);
12309 $(".date-one, .date-month, .date-year").hide();
12310 $("#value-selector").val("").hide();
12311 $("#value-selector").next(".select2-container").hide();
12312 $("#value-selector").val(null).trigger("change.select2");
12314 if (fieldType === "date" || fieldType === "datetime" || fieldType === "timestamp") {
12315 $(".date-one").show();
12316 } else if (arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"] !== undefined) {
12317 var arrayofkeyval = arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"];
12318 var valueSelector = $("#value-selector");
12319 valueSelector.empty();
12320 Object.entries(arrayofkeyval).forEach(function([key, val]) {
12321 valueSelector.append("<option value=\'" + key + "\'>" + val + "</option>");
12323 valueSelector.trigger("change.select2");
12325 $("#value-selector").show();
12326 $("#value-selector").next(".select2-container").show();
12328 $(".value-input").show();
12332 $("#operator-selector").on("change", function() {
12333 console.log("We change operator-selector");
12335 const selectedOperator = $(this).find(":selected").val();
12336 if (selectedOperator === "IsDefined" || selectedOperator === "IsNotDefined") {
12337 // Disable all value input elements
12338 $(".value-input, .dateone, .datemonth, .dateyear").val("").prop("disabled", true);
12339 $("#datemonth, #dateyear").val(null).trigger("change.select2");
12340 $("#dateone").datepicker("setDate", null).datepicker("option", "disabled", true);
12341 $(".date-one, .date-month, .date-year").prop("disabled", true);
12342 $("#value-selector").val("").prop("disabled", true);
12343 $("#value-selector").val(null).trigger("change.select2");
12345 // Enable all value input elements
12346 $(".value-input, .dateone, .datemonth, .dateyear").prop("disabled", false);
12347 $(".date-one, .date-month, .date-year").prop("disabled", false);
12348 $("#dateone").datepicker("option", "disabled", false);
12349 $("#value-selector").prop("disabled", false);
12353 $(".add-filter-btn").on("click", function(event) {
12354 console.log("We click on add-filter-btn");
12356 event.preventDefault();
12358 const field = $(".search_filter_field").val();
12359 const operator = $(".operator-selector").val();
12360 let value = $(".value-input").val();
12361 const fieldType = $(".search_filter_field").find(":selected").data("type");
12363 if (["date", "datetime", "timestamp"].includes(fieldType)) {
12364 const year = $("#dateoneyear").val().toString().padStart(4, "0");;
12365 const month = $("#dateonemonth").val().toString().padStart(2, "0");
12366 const day = $("#dateoneday").val().toString().padStart(2, "0");
12367 value = `${year}-${month}-${day}`;
12368 console.log("value="+value);
12371 // If the selected field has an array of values then take the selected value
12372 if (arrayoffiltercriterias[field]["arrayofkeyval"] !== undefined) {
12373 value = $("#value-selector").val();
12376 // If the operator is "IsDefined" or "IsNotDefined" then set the value to 1 (it will not be used)
12377 if (operator === "IsDefined" || operator === "IsNotDefined") {
12381 const filterString = generateFilterString(field, operator, value, fieldType);
12384 if (filterString !== "" && field !== "" && operator !== "" && value !== "") {
12385 $("#search_component_params_input").val($("#search_component_params_input").val() + " " + filterString);
12386 $("#search_component_params_input").closest("form").submit();
12388 $(".assistance-errors").show();
12407 public function selectModelMail($prefix, $modelType =
'', $default = 0, $addjscombo = 0, $selected = 0)
12409 global $langs, $user;
12413 $TModels = array();
12415 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
12416 $formmail =
new FormMail($this->db);
12417 $result = $formmail->fetchAllEMailTemplate($modelType, $user, $langs);
12420 $TModels[0] = $langs->trans(
'DefaultMailModel');
12423 foreach ($formmail->lines_model as $model) {
12424 $TModels[(int) $model->id] = $model->label;
12428 $retstring .=
'<select class="flat" id="select_' . $prefix .
'model_mail" name="' . $prefix .
'model_mail">';
12430 foreach ($TModels as $id_model => $label_model) {
12431 $retstring .=
'<option value="' . $id_model .
'"';
12432 if (!empty($selected) && ((
int) $selected) == $id_model) {
12433 $retstring .=
"selected";
12435 $retstring .=
">" . $label_model .
"</option>";
12438 $retstring .=
"</select>";
12441 $retstring .=
ajax_combobox(
'select_' . $prefix .
'model_mail');
12458 public function buttonsSaveCancel($save_label =
'Save', $cancel_label =
'Cancel', $morebuttons = array(), $withoutdiv =
false, $morecss =
'', $dol_openinpopup =
'')
12462 $buttons = array();
12466 'label_key' => $save_label,
12469 if ($save_label ==
'Create' || $save_label ==
'Add') {
12470 $save[
'name'] =
'add';
12471 } elseif ($save_label ==
'Modify') {
12472 $save[
'name'] =
'edit';
12476 'name' =>
'cancel',
12477 'label_key' =>
'Cancel',
12482 !empty($save_label) ? $buttons[] = $save :
'';
12483 if (!empty($morebuttons)) {
12484 $buttons[] = $morebuttons;
12486 !empty($cancel_label) ? $buttons[] = $cancel :
'';
12488 if (!empty($morebuttons)) {
12489 $buttons[] = $morebuttons;
12491 !empty($cancel_label) ? $buttons[] = $cancel :
'';
12492 !empty($save_label) ? $buttons[] = $save :
'';
12495 $retstring = $withoutdiv ?
'' :
'<div class="center">';
12497 foreach ($buttons as $button) {
12498 $addclass = empty($button[
'addclass']) ?
'' : $button[
'addclass'];
12499 $retstring .=
'<input type="submit" class="button button-' . $button[
'name'] . ($morecss ?
' ' . $morecss :
'') .
' ' . $addclass .
'" name="' . $button[
'name'] .
'" value="' .
dol_escape_htmltag($langs->transnoentities($button[
'label_key'])) .
'">';
12501 $retstring .= $withoutdiv ?
'' :
'</div>';
12503 if ($dol_openinpopup) {
12504 $retstring .=
'<!-- buttons are shown into a $dol_openinpopup=' .
dol_escape_htmltag($dol_openinpopup) .
' context, so we enable the close of dialog on cancel -->' .
"\n";
12505 $retstring .=
'<script nonce="' .
getNonce() .
'">';
12506 $retstring .=
'jQuery(".button-cancel").click(function(e) {
12507 e.preventDefault(); console.log(\'We click on cancel in iframe popup ' .
dol_escape_js($dol_openinpopup) .
'\');
12508 window.parent.jQuery(\
'#idfordialog' .
dol_escape_js($dol_openinpopup) .
'\').dialog(\
'close\');
12510 $retstring .=
'</script>';
12529 $num = count($this->cache_invoice_subtype);
12536 $sql =
"SELECT rowid, code, label as label";
12537 $sql .=
" FROM " . MAIN_DB_PREFIX .
'c_invoice_subtype';
12538 $sql .=
" WHERE active = 1";
12540 $resql = $this->db->query($sql);
12542 $num = $this->db->num_rows($resql);
12544 while ($i < $num) {
12545 $obj = $this->db->fetch_object($resql);
12548 $label = ($langs->trans(
"InvoiceSubtype" . $obj->rowid) !=
"InvoiceSubtype" . $obj->rowid) ? $langs->trans(
"InvoiceSubtype" . $obj->rowid) : (($obj->label !=
'-') ? $obj->label :
'');
12549 $this->cache_invoice_subtype[$obj->rowid][
'rowid'] = $obj->rowid;
12550 $this->cache_invoice_subtype[$obj->rowid][
'code'] = $obj->code;
12551 $this->cache_invoice_subtype[$obj->rowid][
'label'] = $label;
12555 $this->cache_invoice_subtype =
dol_sort_array($this->cache_invoice_subtype,
'code',
'asc', 0, 0, 1);
12577 global $langs, $user;
12580 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
12582 $this->load_cache_invoice_subtype();
12584 $out .=
'<select id="' . $htmlname .
'" class="flat selectsubtype' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
12586 $out .=
'<option value="0"> </option>';
12589 foreach ($this->cache_invoice_subtype as $rowid => $subtype) {
12590 $label = $subtype[
'label'];
12591 $out .=
'<option value="' . $subtype[
'rowid'] .
'"';
12592 if ($selected == $subtype[
'rowid']) {
12593 $out .=
' selected="selected"';
12597 $out .=
'</option>';
12600 $out .=
'</select>';
12601 if ($user->admin && empty($noinfoadmin)) {
12602 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
12623 'type' =>
'search',
12624 'name' => $htmlName,
12626 'class' =>
"search-tool-input",
12627 'placeholder' => $langs->trans(
'Search'),
12628 'autocomplete' =>
'off'
12636 if ($dataTarget !==
false) {
12637 $attr[
'data-search-tool-target'] = $dataTarget;
12641 if (!empty($params[
'attr']) && is_array($params[
'attr'])) {
12642 foreach ($params[
'attr'] as $key => $value) {
12643 if ($key ==
'class') {
12644 $attr[
'class'] .=
' '.$value;
12645 } elseif ($key ==
'classOverride') {
12646 $attr[
'class'] = $value;
12648 $attr[$key] = $value;
12654 if (!empty($attr[
'title']) && !empty($attr[
'class']) && strpos($attr[
'class'],
'classfortooltip') ===
false) {
12655 $attr[
'class'] .=
' classfortooltip';
12658 $TCompiledAttr = [];
12659 foreach ($attr as $key => $value) {
12660 if (in_array($key, [
'data-target'])
12661 || (!empty($params[
'use_unsecured_unescapedattr']) && is_array($params[
'use_unsecured_unescapedattr']) && in_array($key, $params[
'use_unsecured_unescapedattr']))) {
12667 $TCompiledAttr[] = $key .
'="' . $value .
'"';
12670 $compiledAttributes = implode(
' ', $TCompiledAttr);
12673 return '<div class="search-tool-container"><input '.$compiledAttributes.
'></div>';
$id
Support class for third parties, contacts, members, users or resources.
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLength=2, $autoselect=0, $ajaxoptions=array(), $moreparams='')
Generic function that return javascript to add to transform a common input text or select field into ...
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
ajax_multiautocompleter($htmlname, $fields, $url, $option='', $minLength=2, $autoselect=0)
Generic function that return javascript to add to a page to transform a common input text field into ...
ajax_event($htmlname, $events)
Add event management script.
Class to manage bank accounts.
Class to manage categories.
Class to manage bank accounts description of third parties.
Class to manage a WYSIWYG editor.
const STATUS_OPEN_INTERNAL
Warehouse open and only operations for stock transfers/corrections allowed (not for customer shipping...
const STATUS_OPEN_ALL
Warehouse open and any operations are allowed (customer shipping, supplier dispatch,...
const STATUS_CLOSED
Warehouse closed, inactive.
Class to manage invoices.
Class to manage invoice templates.
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.
const STATUS_CLOSED
Closed status.
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_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
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.
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
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'.
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.
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.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
dol_string_neverthesehtmltags($stringtoclean, $disallowed_tags=array('textarea'), $cleanalsosomestyles=0)
Clean a string from some undesirable HTML tags.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
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, $cid=0, $socid=0, $addlink=0, $max=64, $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_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getNonce()
Return a random string to be used as a nonce value for js.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox=0, $check='restricthtml')
Sanitize a HTML to remove js, dangerous content and external 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.
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...
treeview li table
No Email.
ui state ui widget content ui state ui widget header ui state a ui button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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
$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,...