68 public $errors = array();
75 public $cache_types_paiements = array();
76 public $cache_conditions_paiements = array();
77 public $cache_transport_mode = array();
78 public $cache_availability = array();
79 public $cache_demand_reason = array();
80 public $cache_types_fees = array();
81 public $cache_vatrates = array();
110 public function editfieldkey($text, $htmlname, $preselected, $object, $perm, $typeofdata =
'string', $moreparam =
'', $fieldrequired = 0, $notabletag = 0, $paramid =
'id', $help =
'')
112 global $conf, $langs;
117 if (!empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && !preg_match(
'/^select;/', $typeofdata)) {
119 $tmp = explode(
':', $typeofdata);
120 $ret .=
'<div class="editkey_' . $tmp[0] . (!empty($tmp[1]) ?
' ' . $tmp[1] :
'') .
'" id="' . $htmlname .
'">';
121 if ($fieldrequired) {
122 $ret .=
'<span class="fieldrequired">';
127 $ret .= $langs->trans($text);
129 if ($fieldrequired) {
132 $ret .=
'</div>' .
"\n";
134 if ($fieldrequired) {
135 $ret .=
'<span class="fieldrequired">';
140 $ret .= $langs->trans($text);
142 if ($fieldrequired) {
147 if (empty($notabletag) && $perm) {
148 $ret .=
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
150 if ($fieldrequired) {
151 $ret .=
'<span class="fieldrequired">';
156 $ret .= $langs->trans($text);
158 if ($fieldrequired) {
161 if (!empty($notabletag)) {
164 if (empty($notabletag) && $perm) {
167 if (empty($notabletag) && $perm) {
168 $ret .=
'<td class="right">';
170 if ($htmlname &&
GETPOST(
'action',
'aZ09') !=
'edit' . $htmlname && $perm) {
171 $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>';
173 if (!empty($notabletag) && $notabletag == 1) {
180 if (!empty($notabletag) && $notabletag == 3) {
183 if (empty($notabletag) && $perm) {
186 if (empty($notabletag) && $perm) {
187 $ret .=
'</tr></table>';
215 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 =
'')
217 global $conf, $langs;
222 if (empty($typeofdata)) {
223 return 'ErrorBadParameter typeofdata is empty';
226 if ($typeofdata ==
'datetime') {
227 $typeofdata =
'dayhour';
230 if (preg_match(
'/^(\w+)\((\d+)\)$/', $typeofdata, $reg)) {
231 if ($reg[1] ==
'varchar') {
232 $typeofdata =
'string';
233 } elseif ($reg[1] ==
'int') {
234 $typeofdata =
'numeric';
236 return 'ErrorBadParameter ' . $typeofdata;
241 if (!empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && !preg_match(
'/^select;|day|datepicker|dayhour|datehourpicker/', $typeofdata)) {
242 $ret .= $this->
editInPlace($object, $value, $htmlname, $perm, $typeofdata, $editvalue, $extObject, $custommsg);
244 if ($editaction ==
'') {
245 $editaction =
GETPOST(
'action',
'aZ09');
247 $editmode = ($editaction ==
'edit' . $htmlname);
250 $ret .=
'<form method="post" action="' . $_SERVER[
"PHP_SELF"] . ($moreparam ?
'?' . $moreparam :
'') .
'">';
251 $ret .=
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
252 $ret .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
253 $ret .=
'<input type="hidden" name="' . $paramid .
'" value="' . $object->id .
'">';
254 if (empty($notabletag)) {
255 $ret .=
'<table class="nobordernopadding centpercent">';
257 if (empty($notabletag)) {
260 if (preg_match(
'/^(string|safehtmlstring|email|phone|url)/', $typeofdata)) {
261 $tmp = explode(
':', $typeofdata);
262 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($editvalue ? $editvalue : $value) .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
263 } elseif (preg_match(
'/^(integer)/', $typeofdata)) {
264 $tmp = explode(
':', $typeofdata);
265 $valuetoshow =
price2num($editvalue ? $editvalue : $value, 0);
266 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $valuetoshow .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
267 } elseif (preg_match(
'/^(numeric|amount)/', $typeofdata)) {
268 $tmp = explode(
':', $typeofdata);
269 $valuetoshow =
price2num($editvalue ? $editvalue : $value);
270 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($valuetoshow !=
'' ?
price($valuetoshow) :
'') .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
271 } elseif (preg_match(
'/^(checkbox)/', $typeofdata)) {
272 $tmp = explode(
':', $typeofdata);
273 $ret .=
'<input type="checkbox" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($value ? $value :
'on') .
'"' . ($value ?
' checked' :
'') . (empty($tmp[1]) ?
'' : $tmp[1]) .
'/>';
274 } elseif (preg_match(
'/^text/', $typeofdata) || preg_match(
'/^note/', $typeofdata)) {
275 $tmp = explode(
':', $typeofdata);
276 $cols = (empty($tmp[2]) ?
'' : $tmp[2]);
278 if (preg_match(
'/%/', $cols)) {
279 $morealt =
' style="width: ' . $cols .
'"';
283 $valuetoshow = ($editvalue ? $editvalue : $value);
284 $ret .=
'<textarea id="' . $htmlname .
'" name="' . $htmlname .
'" wrap="soft" rows="' . (empty($tmp[1]) ?
'20' : $tmp[1]) .
'"' . ($cols ?
' cols="' . $cols .
'"' :
'class="quatrevingtpercent"') . $morealt .
'" autofocus>';
287 $valuetoshow = str_replace(
'&',
'&', $valuetoshow);
289 $ret .=
'</textarea>';
290 } elseif ($typeofdata ==
'day' || $typeofdata ==
'datepicker') {
291 $addnowlink = empty($moreoptions[
'addnowlink']) ? 0 : $moreoptions[
'addnowlink'];
292 $adddateof = empty($moreoptions[
'adddateof']) ?
'' : $moreoptions[
'adddateof'];
293 $labeladddateof = empty($moreoptions[
'labeladddateof']) ?
'' : $moreoptions[
'labeladddateof'];
294 $ret .= $this->
selectDate($value, $htmlname, 0, 0, 1,
'form' . $htmlname, 1, $addnowlink, 0,
'',
'', $adddateof,
'', 1, $labeladddateof,
'', $gm);
295 } elseif ($typeofdata ==
'dayhour' || $typeofdata ==
'datehourpicker') {
296 $addnowlink = empty($moreoptions[
'addnowlink']) ? 0 : $moreoptions[
'addnowlink'];
297 $adddateof = empty($moreoptions[
'adddateof']) ?
'' : $moreoptions[
'adddateof'];
298 $labeladddateof = empty($moreoptions[
'labeladddateof']) ?
'' : $moreoptions[
'labeladddateof'];
299 $ret .= $this->
selectDate($value, $htmlname, 1, 1, 1,
'form' . $htmlname, 1, $addnowlink, 0,
'',
'', $adddateof,
'', 1, $labeladddateof,
'', $gm);
300 } elseif (preg_match(
'/^select;/', $typeofdata)) {
301 $arraydata = explode(
',', preg_replace(
'/^select;/',
'', $typeofdata));
302 $arraylist = array();
303 foreach ($arraydata as $val) {
304 $tmp = explode(
':', $val);
305 $tmpkey = str_replace(
'|',
':', $tmp[0]);
306 $arraylist[$tmpkey] = $tmp[1];
308 $ret .= $this->
selectarray($htmlname, $arraylist, $value);
309 } elseif (preg_match(
'/^link/', $typeofdata)) {
311 } elseif (preg_match(
'/^ckeditor/', $typeofdata)) {
312 $tmp = explode(
':', $typeofdata);
313 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
314 $doleditor =
new DolEditor($htmlname, ($editvalue ? $editvalue : $value), (empty($tmp[2]) ?
'' : $tmp[2]), (empty($tmp[3]) ?
'100' : $tmp[3]), (empty($tmp[1]) ?
'dolibarr_notes' : $tmp[1]),
'In', (empty($tmp[5]) ? 0 : $tmp[5]), (isset($tmp[8]) ? ($tmp[8] ?
true :
false) :
true),
true, (empty($tmp[6]) ?
'20' : $tmp[6]), (empty($tmp[7]) ?
'100' : $tmp[7]));
315 $ret .= $doleditor->Create(1);
316 } elseif ($typeofdata ==
'asis') {
317 $ret .= ($editvalue ? $editvalue : $value);
319 if (empty($notabletag)) {
324 if (empty($notabletag)) {
328 $ret .=
'<input type="submit" class="smallpaddingimp button' . (empty($notabletag) ?
'' :
' ') .
'" name="modify" value="' . $langs->trans(
"Modify") .
'">';
329 if (preg_match(
'/ckeditor|textarea/', $typeofdata) && empty($notabletag)) {
330 $ret .=
'<br>' .
"\n";
332 $ret .=
'<input type="submit" class="smallpaddingimp button button-cancel' . (empty($notabletag) ?
'' :
' ') .
'" name="cancel" value="' . $langs->trans(
"Cancel") .
'">';
333 if (empty($notabletag)) {
337 if (empty($notabletag)) {
338 $ret .=
'</tr></table>' .
"\n";
340 $ret .=
'</form>' .
"\n";
342 if (preg_match(
'/^email/', $typeofdata)) {
344 } elseif (preg_match(
'/^phone/', $typeofdata)) {
346 } elseif (preg_match(
'/^url/', $typeofdata)) {
348 } elseif (preg_match(
'/^(amount|numeric)/', $typeofdata)) {
349 $ret .= ($value !=
'' ?
price($value,
'', $langs, 0, -1, -1, $conf->currency) :
'');
350 } elseif (preg_match(
'/^checkbox/', $typeofdata)) {
351 $tmp = explode(
':', $typeofdata);
352 $ret .=
'<input type="checkbox" disabled id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $value .
'"' . ($value ?
' checked' :
'') . ($tmp[1] ? $tmp[1] :
'') .
'/>';
353 } elseif (preg_match(
'/^text/', $typeofdata) || preg_match(
'/^note/', $typeofdata)) {
355 } elseif (preg_match(
'/^safehtmlstring/', $typeofdata)) {
357 } elseif (preg_match(
'/^restricthtml/', $typeofdata)) {
359 } elseif ($typeofdata ==
'day' || $typeofdata ==
'datepicker') {
360 $ret .=
'<span class="valuedate">' .
dol_print_date($value,
'day', $gm) .
'</span>';
361 } elseif ($typeofdata ==
'dayhour' || $typeofdata ==
'datehourpicker') {
362 $ret .=
'<span class="valuedate">' .
dol_print_date($value,
'dayhour', $gm) .
'</span>';
363 } elseif (preg_match(
'/^select;/', $typeofdata)) {
364 $arraydata = explode(
',', preg_replace(
'/^select;/',
'', $typeofdata));
365 $arraylist = array();
366 foreach ($arraydata as $val) {
367 $tmp = explode(
':', $val);
368 $arraylist[$tmp[0]] = $tmp[1];
370 $ret .= $arraylist[$value];
371 if ($htmlname ==
'fk_product_type') {
373 $ret =
img_picto($langs->trans(
"Product"),
'product',
'class="paddingleftonly paddingrightonly colorgrey"') . $ret;
375 $ret =
img_picto($langs->trans(
"Service"),
'service',
'class="paddingleftonly paddingrightonly colorgrey"') . $ret;
378 } elseif (preg_match(
'/^ckeditor/', $typeofdata)) {
380 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
381 $firstline = preg_replace(
'/<br>.*/',
'', $tmpcontent);
382 $firstline = preg_replace(
'/[\n\r].*/',
'', $firstline);
383 $tmpcontent = $firstline . ((strlen($firstline) != strlen($tmpcontent)) ?
'...' :
'');
389 if (empty($moreoptions[
'valuealreadyhtmlescaped'])) {
397 if ($formatfunc && method_exists($object, $formatfunc)) {
398 $ret = $object->$formatfunc($ret);
416 public function widgetForTranslation($fieldname, $object, $perm, $typeofdata =
'string', $check =
'', $morecss =
'')
418 global $conf, $langs, $extralanguages;
423 $arrayoflangcode = array();
424 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE)) {
425 $arrayoflangcode[] = $conf->global->PDF_USE_ALSO_LANGUAGE_CODE;
428 if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
429 if (!is_object($extralanguages)) {
430 include_once DOL_DOCUMENT_ROOT .
'/core/class/extralanguages.class.php';
433 $extralanguages->fetch_name_extralanguages(
'societe');
435 if (!is_array($extralanguages->attributes[$object->element]) || empty($extralanguages->attributes[$object->element][$fieldname])) {
439 $result .=
'<!-- Widget for translation -->' .
"\n";
440 $result .=
'<div class="inline-block paddingleft image-' . $object->element .
'-' . $fieldname .
'">';
441 $s =
img_picto($langs->trans(
"ShowOtherLanguages"),
'language',
'',
false, 0, 0,
'',
'fa-15 editfieldlang');
445 $result .=
'<div class="inline-block hidden field-' . $object->element .
'-' . $fieldname .
'">';
447 $resultforextrlang =
'';
448 foreach ($arrayoflangcode as $langcode) {
449 $valuetoshow =
GETPOSTISSET(
'field-' . $object->element .
"-" . $fieldname .
"-" . $langcode) ?
GETPOST(
'field-' . $object->element .
'-' . $fieldname .
"-" . $langcode, $check) :
'';
450 if (empty($valuetoshow)) {
451 $object->fetchValuesForExtraLanguages();
453 $valuetoshow = $object->array_languages[$fieldname][$langcode];
457 $resultforextrlang .= $s;
460 if ($typeofdata ==
'textarea') {
461 $resultforextrlang .=
'<textarea name="field-' . $object->element .
"-" . $fieldname .
"-" . $langcode .
'" id="' . $fieldname .
"-" . $langcode .
'" class="' . $morecss .
'" rows="' . ROWS_2 .
'" wrap="soft">';
462 $resultforextrlang .= $valuetoshow;
463 $resultforextrlang .=
'</textarea>';
465 $resultforextrlang .=
'<input type="text" class="inputfieldforlang ' . ($morecss ?
' ' . $morecss :
'') .
'" name="field-' . $object->element .
'-' . $fieldname .
'-' . $langcode .
'" value="' . $valuetoshow .
'">';
468 $result .= $resultforextrlang;
471 $result .=
'<script nonce="' .
getNonce() .
'">$(".image-' . $object->element .
'-' . $fieldname .
'").click(function() { console.log("Toggle lang widget"); jQuery(".field-' . $object->element .
'-' . $fieldname .
'").toggle(); });</script>';
490 protected function editInPlace($object, $value, $htmlname, $condition, $inputType =
'textarea', $editvalue =
null, $extObject =
null, $custommsg =
null)
497 if (preg_match(
'/^text/', $inputType)) {
499 } elseif (preg_match(
'/^numeric/', $inputType)) {
500 $value =
price($value);
501 } elseif ($inputType ==
'day' || $inputType ==
'datepicker') {
507 $table_element =
false;
511 $ext_element =
false;
512 $button_only =
false;
517 if (is_object($object)) {
518 $element = $object->element;
519 $table_element = $object->table_element;
520 $fk_element = $object->id;
523 if (is_object($extObject)) {
524 $ext_element = $extObject->element;
527 if (preg_match(
'/^(string|email|numeric)/', $inputType)) {
528 $tmp = explode(
':', $inputType);
529 $inputType = $tmp[0];
530 if (!empty($tmp[1])) {
531 $inputOption = $tmp[1];
533 if (!empty($tmp[2])) {
534 $savemethod = $tmp[2];
536 $out .=
'<input id="width_' . $htmlname .
'" value="' . $inputOption .
'" type="hidden"/>' .
"\n";
537 } elseif ((preg_match(
'/^day$/', $inputType)) || (preg_match(
'/^datepicker/', $inputType)) || (preg_match(
'/^datehourpicker/', $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];
547 $out .=
'<input id="timestamp" type="hidden"/>' .
"\n";
548 } elseif (preg_match(
'/^(select|autocomplete)/', $inputType)) {
549 $tmp = explode(
':', $inputType);
550 $inputType = $tmp[0];
551 $loadmethod = $tmp[1];
552 if (!empty($tmp[2])) {
553 $savemethod = $tmp[2];
555 if (!empty($tmp[3])) {
558 } elseif (preg_match(
'/^textarea/', $inputType)) {
559 $tmp = explode(
':', $inputType);
560 $inputType = $tmp[0];
561 $rows = (empty($tmp[1]) ?
'8' : $tmp[1]);
562 $cols = (empty($tmp[2]) ?
'80' : $tmp[2]);
563 } elseif (preg_match(
'/^ckeditor/', $inputType)) {
564 $tmp = explode(
':', $inputType);
565 $inputType = $tmp[0];
567 if (!empty($tmp[2])) {
570 if (!empty($tmp[3])) {
573 if (!empty($tmp[4])) {
574 $savemethod = $tmp[4];
578 $out .=
'<input id="ckeditor_toolbar" value="' . $toolbar .
'" type="hidden"/>' .
"\n";
580 $inputType =
'textarea';
584 $out .=
'<input id="element_' . $htmlname .
'" value="' . $element .
'" type="hidden"/>' .
"\n";
585 $out .=
'<input id="table_element_' . $htmlname .
'" value="' . $table_element .
'" type="hidden"/>' .
"\n";
586 $out .=
'<input id="fk_element_' . $htmlname .
'" value="' . $fk_element .
'" type="hidden"/>' .
"\n";
587 $out .=
'<input id="loadmethod_' . $htmlname .
'" value="' . $loadmethod .
'" type="hidden"/>' .
"\n";
588 if (!empty($savemethod)) {
589 $out .=
'<input id="savemethod_' . $htmlname .
'" value="' . $savemethod .
'" type="hidden"/>' .
"\n";
591 if (!empty($ext_element)) {
592 $out .=
'<input id="ext_element_' . $htmlname .
'" value="' . $ext_element .
'" type="hidden"/>' .
"\n";
594 if (!empty($custommsg)) {
595 if (is_array($custommsg)) {
596 if (!empty($custommsg[
'success'])) {
597 $out .=
'<input id="successmsg_' . $htmlname .
'" value="' . $custommsg[
'success'] .
'" type="hidden"/>' .
"\n";
599 if (!empty($custommsg[
'error'])) {
600 $out .=
'<input id="errormsg_' . $htmlname .
'" value="' . $custommsg[
'error'] .
'" type="hidden"/>' .
"\n";
603 $out .=
'<input id="successmsg_' . $htmlname .
'" value="' . $custommsg .
'" type="hidden"/>' .
"\n";
606 if ($inputType ==
'textarea') {
607 $out .=
'<input id="textarea_' . $htmlname .
'_rows" value="' . $rows .
'" type="hidden"/>' .
"\n";
608 $out .=
'<input id="textarea_' . $htmlname .
'_cols" value="' . $cols .
'" type="hidden"/>' .
"\n";
610 $out .=
'<span id="viewval_' . $htmlname .
'" class="viewval_' . $inputType . ($button_only ?
' inactive' :
' active') .
'">' . $value .
'</span>' .
"\n";
611 $out .=
'<span id="editval_' . $htmlname .
'" class="editval_' . $inputType . ($button_only ?
' inactive' :
' active') .
' hideobject">' . (!empty($editvalue) ? $editvalue : $value) .
'</span>' .
"\n";
637 public function textwithtooltip($text, $htmltext, $tooltipon = 1, $direction = 0, $img =
'', $extracss =
'', $notabs = 3, $incbefore =
'', $noencodehtmltext = 0, $tooltiptrigger =
'', $forcenowrap = 0)
640 $text = $incbefore . $text;
645 $direction = (int) $direction;
655 $htmltext = str_replace(array(
"\r",
"\n"),
'', $htmltext);
658 if ($direction < 0) {
659 $extracss = ($extracss ? $extracss .
' ' :
'') . ($notabs != 3 ?
'inline-block' :
'');
660 $extrastyle =
'padding: 0px; padding-left: 3px;';
662 if ($direction > 0) {
663 $extracss = ($extracss ? $extracss .
' ' :
'') . ($notabs != 3 ?
'inline-block' :
'');
664 $extrastyle =
'padding: 0px; padding-right: 3px;';
667 $classfortooltip =
'classfortooltip';
672 if ($tooltiptrigger ==
'') {
673 $htmltext = str_replace(
'"',
'"', $htmltext);
675 $classfortooltip =
'classfortooltiponclick';
676 $textfordialog .=
'<div style="display: none;" id="idfortooltiponclick_' . $tooltiptrigger .
'" class="classfortooltiponclicktext">' . $htmltext .
'</div>';
678 if ($tooltipon == 2 || $tooltipon == 3) {
679 $paramfortooltipimg =
' class="' . $classfortooltip . ($notabs != 3 ?
' inline-block' :
'') . ($extracss ?
' ' . $extracss :
'') .
'" style="padding: 0px;' . ($extrastyle ?
' ' . $extrastyle :
'') .
'"';
680 if ($tooltiptrigger ==
'') {
681 $paramfortooltipimg .=
' title="' . ($noencodehtmltext ? $htmltext :
dol_escape_htmltag($htmltext, 1)) .
'"';
683 $paramfortooltipimg .=
' dolid="' . $tooltiptrigger .
'"';
686 $paramfortooltipimg = ($extracss ?
' class="' . $extracss .
'"' :
'') . ($extrastyle ?
' style="' . $extrastyle .
'"' :
'');
688 if ($tooltipon == 1 || $tooltipon == 3) {
689 $paramfortooltiptd =
' class="' . ($tooltipon == 3 ?
'cursorpointer ' :
'') . $classfortooltip .
' inline-block' . ($extracss ?
' ' . $extracss :
'') .
'" style="padding: 0px;' . ($extrastyle ?
' ' . $extrastyle :
'') .
'" ';
690 if ($tooltiptrigger ==
'') {
691 $paramfortooltiptd .=
' title="' . ($noencodehtmltext ? $htmltext :
dol_escape_htmltag($htmltext, 1)) .
'"';
693 $paramfortooltiptd .=
' dolid="' . $tooltiptrigger .
'"';
696 $paramfortooltiptd = ($extracss ?
' class="' . $extracss .
'"' :
'') . ($extrastyle ?
' style="' . $extrastyle .
'"' :
'');
698 if (empty($notabs)) {
699 $s .=
'<table class="nobordernopadding"><tr style="height: auto;">';
700 } elseif ($notabs == 2) {
701 $s .=
'<div class="inline-block' . ($forcenowrap ?
' nowrap' :
'') .
'">';
704 if ($direction < 0) {
705 $s .=
'<' . $tag . $paramfortooltipimg;
707 $s .=
' class="valigntop" width="14"';
709 $s .=
'>' . $textfordialog . $img .
'</' . $tag .
'>';
713 if ((
string) $text !=
'') {
714 $s .=
'<' . $tag . $paramfortooltiptd .
'>' . $text .
'</' . $tag .
'>';
717 if ($direction > 0) {
718 $s .=
'<' . $tag . $paramfortooltipimg;
720 $s .=
' class="valignmiddle" width="14"';
722 $s .=
'>' . $textfordialog . $img .
'</' . $tag .
'>';
724 if (empty($notabs)) {
725 $s .=
'</tr></table>';
726 } elseif ($notabs == 2) {
747 public function textwithpicto($text, $htmltext, $direction = 1, $type =
'help', $extracss =
'', $noencodehtmltext = 0, $notabs = 3, $tooltiptrigger =
'', $forcenowrap = 0)
749 global $conf, $langs;
754 } elseif ($type ==
'1') {
758 if (preg_match(
'/onsmartphone$/', $tooltiptrigger) && empty($conf->dol_no_mouse_hover)) {
759 $tooltiptrigger = preg_replace(
'/^.*onsmartphone$/',
'', $tooltiptrigger);
763 if ($tooltiptrigger) {
764 $alt = $langs->transnoentitiesnoconv(
"ClickToShowHelp");
768 if (empty($conf->use_javascript_ajax)) {
769 if ($type ==
'info' || $type ==
'infoclickable' || $type ==
'help' || $type ==
'helpclickable') {
778 if (!empty($conf->dol_no_mouse_hover) && empty($tooltiptrigger)) {
779 if ($type ==
'info' || $type ==
'infoclickable' || $type ==
'help' || $type ==
'helpclickable') {
790 if ($type ==
'info') {
792 } elseif ($type ==
'help') {
793 $img =
img_help(($tooltiptrigger !=
'' ? 2 : 1), $alt);
794 } elseif ($type ==
'helpclickable') {
795 $img =
img_help(($tooltiptrigger !=
'' ? 2 : 1), $alt);
796 } elseif ($type ==
'superadmin') {
798 } elseif ($type ==
'admin') {
800 } elseif ($type ==
'warning') {
802 } elseif ($type !=
'none') {
806 return $this->
textwithtooltip($text, $htmltext, ((($tooltiptrigger && !$img) || strpos($type,
'clickable')) ? 3 : 2), $direction, $img, $extracss, $notabs,
'', $noencodehtmltext, $tooltiptrigger, $forcenowrap);
819 public function selectMassAction($selected, $arrayofaction, $alwaysvisible = 0, $name =
'massaction', $cssclass =
'checkforselect')
821 global $conf, $langs, $hookmanager;
824 $ret =
'<div class="centpercent center">';
825 $ret .=
'<select class="flat' . (empty($conf->use_javascript_ajax) ?
'' :
' hideobject') .
' ' . $name .
' ' . $name .
'select valignmiddle alignstart" id="' . $name .
'" name="' . $name .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
'>';
828 $parameters = array();
829 $reshook = $hookmanager->executeHooks(
'addMoreMassActions', $parameters);
831 if (count($arrayofaction) == 0 && empty($hookmanager->resPrint)) {
834 if (empty($reshook)) {
835 $ret .=
'<option value="0"' . ($disabled ?
' disabled="disabled"' :
'') .
'>-- ' . $langs->trans(
"SelectAction") .
' --</option>';
836 foreach ($arrayofaction as $code => $label) {
837 $ret .=
'<option value="' . $code .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' data-html="' .
dol_escape_htmltag($label) .
'">' . $label .
'</option>';
840 $ret .= $hookmanager->resPrint;
844 if (empty($conf->dol_optimize_smallscreen)) {
849 $ret .=
'<input type="submit" name="confirmmassactioninvisible" style="display: none" tabindex="-1">';
850 $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")) .
'">';
853 if (!empty($conf->use_javascript_ajax)) {
854 $ret .=
'<!-- JS CODE TO ENABLE mass action select -->
856 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 */
858 atleastoneselected=0;
859 jQuery("."+cssclass).each(function( index ) {
860 /* console.log( index + ": " + $( this ).text() ); */
861 if ($(this).is(\':checked\')) atleastoneselected++;
864 console.log("initCheckForSelect mode="+mode+" name="+name+" cssclass="+cssclass+" atleastoneselected="+atleastoneselected);
866 if (atleastoneselected || ' . $alwaysvisible .
')
868 jQuery("."+name).show();
869 ' . ($selected ?
'if (atleastoneselected) { jQuery("."+name+"select").val("' . $selected .
'").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', false); }' :
'') .
'
870 ' . ($selected ?
'if (! atleastoneselected) { jQuery("."+name+"select").val("0").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', true); } ' :
'') .
'
874 jQuery("."+name).hide();
875 jQuery("."+name+"other").hide();
879 jQuery(document).ready(function () {
880 initCheckForSelect(0, "' . $name .
'", "' . $cssclass .
'");
881 jQuery(".' . $cssclass .
'").click(function() {
882 initCheckForSelect(1, "' . $name .
'", "' . $cssclass .
'");
884 jQuery(".' . $name .
'select").change(function() {
885 var massaction = $( this ).val();
886 var urlform = $( this ).closest("form").attr("action").replace("#show_files","");
887 if (massaction == "builddoc")
889 urlform = urlform + "#show_files";
891 $( this ).closest("form").attr("action", urlform);
892 console.log("we select a mass action name=' . $name .
' massaction="+massaction+" - "+urlform);
893 /* Warning: if you set submit button to disabled, post using Enter will no more work if there is no other button */
894 if ($(this).val() != \'0\')
896 jQuery(".' . $name .
'confirmed").prop(\'disabled\', false);
897 jQuery(".' . $name .
'other").hide(); /* To disable if another div was open */
898 jQuery(".' . $name .
'"+massaction).show();
902 jQuery(".' . $name .
'confirmed").prop(\'disabled\', true);
903 jQuery(".' . $name .
'other").hide(); /* To disable any div open */
932 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)
935 global $conf, $langs, $mysoc;
937 $langs->load(
"dict");
940 $countryArray = array();
943 $atleastonefavorite = 0;
945 $sql =
"SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite, eec";
946 $sql .=
" FROM " . $this->db->prefix() .
"c_country";
947 $sql .=
" WHERE active > 0";
950 dol_syslog(get_class($this) .
"::select_country", LOG_DEBUG);
951 $resql = $this->db->query(
$sql);
953 $out .=
'<select id="select' . $htmlname .
'" class="flat maxwidth200onsmartphone selectcountry' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" ' . $htmloption .
'>';
954 $num = $this->db->num_rows($resql);
958 $obj = $this->db->fetch_object($resql);
960 $countryArray[$i][
'rowid'] = $obj->rowid;
961 $countryArray[$i][
'code_iso'] = $obj->code_iso;
962 $countryArray[$i][
'code_iso3'] = $obj->code_iso3;
963 $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 :
''));
964 $countryArray[$i][
'favorite'] = $obj->favorite;
965 $countryArray[$i][
'eec'] = $obj->eec;
966 $favorite[$i] = $obj->favorite;
971 if (empty($disablefavorites)) {
972 $array1_sort_order = SORT_DESC;
973 $array2_sort_order = SORT_ASC;
974 array_multisort($favorite, $array1_sort_order, $label, $array2_sort_order, $countryArray);
980 if (is_numeric($showempty)) {
981 $out .=
'<option value=""> </option>' .
"\n";
983 $out .=
'<option value="-1">' . $langs->trans($showempty) .
'</option>' .
"\n";
987 if ($addspecialentries) {
989 $out .=
'<option value="special_allnotme"' . ($selected ==
'special_allnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesExceptMe", $langs->transnoentitiesnoconv(
"Country" . $mysoc->country_code)) .
'</option>';
990 $out .=
'<option value="special_eec"' . ($selected ==
'special_eec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEEC") .
'</option>';
991 if ($mysoc->isInEEC()) {
992 $out .=
'<option value="special_eecnotme"' . ($selected ==
'special_eecnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEECExceptMe", $langs->transnoentitiesnoconv(
"Country" . $mysoc->country_code)) .
'</option>';
994 $out .=
'<option value="special_noteec"' . ($selected ==
'special_noteec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesNotInEEC") .
'</option>';
995 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
998 foreach ($countryArray as $row) {
1000 if (empty($row[
'rowid'])) {
1003 if (is_array($exclude_country_code) && count($exclude_country_code) && in_array($row[
'code_iso'], $exclude_country_code)) {
1007 if (empty($disablefavorites) && $row[
'favorite'] && $row[
'code_iso']) {
1008 $atleastonefavorite++;
1010 if (empty($row[
'favorite']) && $atleastonefavorite) {
1011 $atleastonefavorite = 0;
1012 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1016 if ($row[
'label']) {
1017 $labeltoshow .=
dol_trunc($row[
'label'], $maxlength,
'middle');
1019 $labeltoshow .=
' ';
1021 if ($row[
'code_iso']) {
1022 $labeltoshow .=
' <span class="opacitymedium">(' . $row[
'code_iso'] .
')</span>';
1023 if (empty($hideflags)) {
1024 $tmpflag =
picto_from_langcode($row[
'code_iso'],
'class="saturatemedium paddingrightonly"', 1);
1025 $labeltoshow = $tmpflag .
' ' . $labeltoshow;
1029 if ($selected && $selected !=
'-1' && ($selected == $row[
'rowid'] || $selected == $row[
'code_iso'] || $selected == $row[
'code_iso3'] || $selected == $row[
'label'])) {
1030 $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']) .
'">';
1032 $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']) .
'">';
1034 $out .= $labeltoshow;
1035 $out .=
'</option>' .
"\n";
1038 $out .=
'</select>';
1044 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1045 $out .=
ajax_combobox(
'select' . $htmlname, array(), 0, 0,
'resolve');
1065 public function select_incoterms($selected =
'', $location_incoterms =
'', $page =
'', $htmlname =
'incoterm_id', $htmloption =
'', $forcecombo = 1, $events = array(), $disableautocomplete = 0)
1068 global $conf, $langs;
1070 $langs->load(
"dict");
1074 $incotermArray = array();
1076 $sql =
"SELECT rowid, code";
1077 $sql .=
" FROM " . $this->db->prefix() .
"c_incoterms";
1078 $sql .=
" WHERE active > 0";
1079 $sql .=
" ORDER BY code ASC";
1081 dol_syslog(get_class($this) .
"::select_incoterm", LOG_DEBUG);
1082 $resql = $this->db->query(
$sql);
1084 if ($conf->use_javascript_ajax && !$forcecombo) {
1085 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1089 if (!empty($page)) {
1090 $out .=
'<form method="post" action="' . $page .
'">';
1091 $out .=
'<input type="hidden" name="action" value="set_incoterms">';
1092 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
1095 $out .=
'<select id="' . $htmlname .
'" class="flat selectincoterm width75" name="' . $htmlname .
'" ' . $htmloption .
'>';
1096 $out .=
'<option value="0"> </option>';
1097 $num = $this->db->num_rows($resql);
1101 $obj = $this->db->fetch_object($resql);
1102 $incotermArray[$i][
'rowid'] = $obj->rowid;
1103 $incotermArray[$i][
'code'] = $obj->code;
1107 foreach ($incotermArray as $row) {
1108 if ($selected && ($selected == $row[
'rowid'] || $selected == $row[
'code'])) {
1109 $out .=
'<option value="' . $row[
'rowid'] .
'" selected>';
1111 $out .=
'<option value="' . $row[
'rowid'] .
'">';
1115 $out .= $row[
'code'];
1118 $out .=
'</option>';
1121 $out .=
'</select>';
1123 if ($conf->use_javascript_ajax && empty($disableautocomplete)) {
1124 $out .=
ajax_multiautocompleter(
'location_incoterms', array(), DOL_URL_ROOT .
'/core/ajax/locationincoterms.php') .
"\n";
1125 $moreattrib .=
' autocomplete="off"';
1127 $out .=
'<input id="location_incoterms" class="maxwidthonsmartphone type="text" name="location_incoterms" value="' . $location_incoterms .
'">' .
"\n";
1129 if (!empty($page)) {
1130 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp nomargintop nomarginbottom" value="' . $langs->trans(
"Modify") .
'"></form>';
1152 public function select_type_of_lines($selected =
'', $htmlname =
'type', $showempty = 0, $hidetext = 0, $forceall = 0)
1155 global $langs, $conf;
1160 if (empty($hidetext)) {
1161 print $langs->trans(
"Type") .
': ';
1163 print
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
1165 print
'<option value="-1"';
1166 if ($selected == -1) {
1169 print
'> </option>';
1172 print
'<option value="0"';
1173 if (0 == $selected || ($selected == -1 &&
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') ==
'product')) {
1176 print
'>' . $langs->trans(
"Product");
1178 print
'<option value="1"';
1179 if (1 == $selected || ($selected == -1 &&
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') ==
'service')) {
1182 print
'>' . $langs->trans(
"Service");
1189 print $langs->trans(
"Service");
1190 print
'<input type="hidden" name="' . $htmlname .
'" value="1">';
1193 print $langs->trans(
"Product");
1194 print
'<input type="hidden" name="' . $htmlname .
'" value="0">';
1196 if ($forceall < 0) {
1197 print
'<input type="hidden" name="' . $htmlname .
'" value="1">';
1213 $num = count($this->cache_types_fees);
1220 $langs->load(
"trips");
1222 $sql =
"SELECT c.code, c.label";
1223 $sql .=
" FROM " . $this->db->prefix() .
"c_type_fees as c";
1224 $sql .=
" WHERE active > 0";
1226 $resql = $this->db->query(
$sql);
1228 $num = $this->db->num_rows($resql);
1232 $obj = $this->db->fetch_object($resql);
1235 $label = ($obj->code != $langs->trans($obj->code) ? $langs->trans($obj->code) : $langs->trans($obj->label));
1236 $this->cache_types_fees[$obj->code] = $label;
1240 asort($this->cache_types_fees);
1262 global $user, $langs;
1264 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
1268 print
'<select id="select_' . $htmlname .
'" class="flat" name="' . $htmlname .
'">';
1270 print
'<option value="-1"';
1271 if ($selected == -1) {
1274 print
'> </option>';
1277 foreach ($this->cache_types_fees as $key => $value) {
1278 print
'<option value="' . $key .
'"';
1279 if ($key == $selected) {
1289 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1317 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)
1320 global $conf, $user, $langs;
1324 if (!empty($conf->use_javascript_ajax) && !empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT) && !$forcecombo) {
1325 if (is_null($ajaxoptions)) {
1326 $ajaxoptions = array();
1329 require_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1333 if ($selected && empty($selected_input_value)) {
1334 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
1335 $societetmp =
new Societe($this->db);
1336 $societetmp->fetch($selected);
1337 $selected_input_value = $societetmp->name;
1342 $urloption =
'htmlname=' . urlencode(str_replace(
'.',
'_', $htmlname)) .
'&outjson=1&filter=' . urlencode($filter) . (empty($excludeids) ?
'' :
'&excludeids=' . join(
',', $excludeids)) . ($showtype ?
'&showtype=' . urlencode($showtype) :
'') . ($showcode ?
'&showcode=' . urlencode($showcode) :
'');
1344 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
1345 if (empty($hidelabel)) {
1346 print $langs->trans(
"RefOrLabel") .
' : ';
1347 } elseif ($hidelabel > 1) {
1348 $placeholder = $langs->trans(
"RefOrLabel");
1349 if ($hidelabel == 2) {
1350 $out .=
img_picto($langs->trans(
"Search"),
'search');
1353 $out .=
'<input type="text" class="' . $morecss .
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . ($placeholder ?
' placeholder="' .
dol_escape_htmltag($placeholder) .
'"' :
'') .
' ' . (!empty($conf->global->THIRDPARTY_SEARCH_AUTOFOCUS) ?
'autofocus' :
'') .
' />';
1354 if ($hidelabel == 3) {
1355 $out .=
img_picto($langs->trans(
"Search"),
'search');
1360 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT .
'/societe/ajax/company.php', $urloption, $conf->global->COMPANY_USE_SEARCH_TO_SELECT, 0, $ajaxoptions);
1363 $out .= $this->
select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events,
'', 0, $limit, $morecss, $moreparam, $multiple, $excludeids, $showcode);
1394 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)
1397 global $conf, $user, $langs;
1398 global $hookmanager;
1402 $outarray = array();
1404 if ($selected ===
'') {
1405 $selected = array();
1406 } elseif (!is_array($selected)) {
1407 $selected = array($selected);
1411 if (function_exists(
'testSqlAndScriptInject')) {
1414 return 'SQLInjectionTryDetected';
1418 if (preg_match(
'/[\(\)]/', $filter)) {
1424 if (function_exists(
'testSqlAndScriptInject')) {
1427 return 'SQLInjectionTryDetected';
1433 dol_syslog(
"Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Syntax.", LOG_WARNING);
1437 $sql =
"SELECT s.rowid, s.nom as name, s.name_alias, s.tva_intra, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
1438 if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) {
1439 $sql .=
", s.address, s.zip, s.town";
1440 $sql .=
", dictp.code as country_code";
1442 $sql .=
" FROM " . $this->db->prefix() .
"societe as s";
1443 if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) {
1444 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_country as dictp ON dictp.rowid = s.fk_pays";
1446 if (empty($user->rights->societe->client->voir) && !$user->socid) {
1447 $sql .=
", " . $this->db->prefix() .
"societe_commerciaux as sc";
1449 $sql .=
" WHERE s.entity IN (" .
getEntity(
'societe') .
")";
1450 if (!empty($user->socid)) {
1451 $sql .=
" AND s.rowid = " . ((int) $user->socid);
1456 $sql .=
" AND (" . $filter .
")";
1458 if (empty($user->rights->societe->client->voir) && !$user->socid) {
1459 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = " . ((int) $user->id);
1461 if (!empty($conf->global->COMPANY_HIDE_INACTIVE_IN_COMBOBOX)) {
1462 $sql .=
" AND s.status <> 0";
1464 if (!empty($excludeids)) {
1465 $sql .=
" AND s.rowid NOT IN (" . $this->db->sanitize(join(
',', $excludeids)) .
")";
1468 $parameters = array();
1469 $reshook = $hookmanager->executeHooks(
'selectThirdpartyListWhere', $parameters);
1470 $sql .= $hookmanager->resPrint;
1472 if ($filterkey && $filterkey !=
'') {
1474 $prefix = empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE) ?
'%' :
'';
1476 $scrit = explode(
' ', $filterkey);
1478 if (count($scrit) > 1) {
1481 foreach ($scrit as $crit) {
1485 $sql .=
"(s.nom LIKE '" . $this->db->escape($prefix . $crit) .
"%')";
1488 if (count($scrit) > 1) {
1492 $sql .=
" OR s.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1494 $sql .=
" OR s.code_client LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.code_fournisseur LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1495 $sql .=
" OR s.name_alias LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.tva_intra LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1498 $sql .= $this->db->order(
"nom",
"ASC");
1499 $sql .= $this->db->plimit($limit, 0);
1502 dol_syslog(get_class($this).
"::select_thirdparty_list", LOG_DEBUG);
1503 $resql = $this->db->query(
$sql);
1506 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1511 $out .=
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
' name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
'>' .
"\n";
1513 $textifempty = (($showempty && !is_numeric($showempty)) ? $langs->trans($showempty) :
'');
1514 if (!empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT)) {
1517 if ($showempty && !is_numeric($showempty)) {
1518 $textifempty = $langs->trans($showempty);
1520 $textifempty .= $langs->trans(
"All");
1524 $out .=
'<option value="-1" data-html="' .
dol_escape_htmltag(
'<span class="opacitymedium">' . ($textifempty ? $textifempty :
' ') .
'</span>') .
'">' . $textifempty .
'</option>' .
"\n";
1527 $companytemp =
new Societe($this->db);
1529 $num = $this->db->num_rows($resql);
1533 $obj = $this->db->fetch_object($resql);
1535 if ($showcode || !empty($conf->global->SOCIETE_ADD_REF_IN_LIST)) {
1536 if (($obj->client) && (!empty($obj->code_client))) {
1537 $label = $obj->code_client .
' - ';
1539 if (($obj->fournisseur) && (!empty($obj->code_fournisseur))) {
1540 $label .= $obj->code_fournisseur .
' - ';
1542 $label .=
' ' . $obj->name;
1544 $label = $obj->name;
1547 if (!empty($obj->name_alias)) {
1548 $label .=
' (' . $obj->name_alias .
')';
1551 if (!empty($conf->global->SOCIETE_SHOW_VAT_IN_LIST) && !empty($obj->tva_intra)) {
1552 $label .=
' - '.$obj->tva_intra;
1555 $labelhtml = $label;
1558 $companytemp->id = $obj->rowid;
1559 $companytemp->client = $obj->client;
1560 $companytemp->fournisseur = $obj->fournisseur;
1561 $tmptype = $companytemp->getTypeUrl(1,
'', 0,
'span');
1563 $labelhtml .=
' ' . $tmptype;
1566 if ($obj->client || $obj->fournisseur) {
1569 if ($obj->client == 1 || $obj->client == 3) {
1570 $label .= $langs->trans(
"Customer");
1572 if ($obj->client == 2 || $obj->client == 3) {
1573 $label .= ($obj->client == 3 ?
', ' :
'') . $langs->trans(
"Prospect");
1575 if ($obj->fournisseur) {
1576 $label .= ($obj->client ?
', ' :
'') . $langs->trans(
"Supplier");
1578 if ($obj->client || $obj->fournisseur) {
1583 if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) {
1584 $s = ($obj->address ?
' - ' . $obj->address :
'') . ($obj->zip ?
' - ' . $obj->zip :
'') . ($obj->town ?
' ' . $obj->town :
'');
1585 if (!empty($obj->country_code)) {
1586 $s .=
', ' . $langs->trans(
'Country' . $obj->country_code);
1592 if (empty($outputmode)) {
1593 if (in_array($obj->rowid, $selected)) {
1594 $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>';
1596 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
1599 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label,
'labelhtml' => $labelhtml));
1603 if (($i % 10) == 0) {
1608 $out .=
'</select>' .
"\n";
1613 $this->result = array(
'nbofthirdparties' => $num);
1637 global $langs, $conf;
1640 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
1641 $sql .=
" re.description, re.fk_facture_source";
1642 $sql .=
" FROM " . $this->db->prefix() .
"societe_remise_except as re";
1643 $sql .=
" WHERE re.fk_soc = " . (int) $socid;
1644 $sql .=
" AND re.entity = " . $conf->entity;
1646 $sql .=
" AND " . $filter;
1648 $sql .=
" ORDER BY re.description ASC";
1650 dol_syslog(get_class($this) .
"::select_remises", LOG_DEBUG);
1651 $resql = $this->db->query(
$sql);
1653 print
'<select id="select_' . $htmlname .
'" class="flat maxwidthonsmartphone" name="' . $htmlname .
'">';
1654 $num = $this->db->num_rows($resql);
1656 $qualifiedlines = $num;
1660 print
'<option value="0"> </option>';
1662 $obj = $this->db->fetch_object($resql);
1663 $desc =
dol_trunc($obj->description, 40);
1664 if (preg_match(
'/\(CREDIT_NOTE\)/', $desc)) {
1665 $desc = preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $desc);
1667 if (preg_match(
'/\(DEPOSIT\)/', $desc)) {
1668 $desc = preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"Deposit"), $desc);
1670 if (preg_match(
'/\(EXCESS RECEIVED\)/', $desc)) {
1671 $desc = preg_replace(
'/\(EXCESS RECEIVED\)/', $langs->trans(
"ExcessReceived"), $desc);
1673 if (preg_match(
'/\(EXCESS PAID\)/', $desc)) {
1674 $desc = preg_replace(
'/\(EXCESS PAID\)/', $langs->trans(
"ExcessPaid"), $desc);
1678 if ($selected > 0 && $selected == $obj->rowid) {
1679 $selectstring =
' selected';
1683 if ($maxvalue > 0 && $obj->amount_ttc > $maxvalue) {
1685 $disabled =
' disabled';
1688 if (!empty($conf->global->MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST) && !empty($obj->fk_facture_source)) {
1689 $tmpfac =
new Facture($this->db);
1690 if ($tmpfac->fetch($obj->fk_facture_source) > 0) {
1691 $desc = $desc .
' - ' . $tmpfac->ref;
1695 print
'<option value="' . $obj->rowid .
'"' . $selectstring . $disabled .
'>' . $desc .
' (' .
price($obj->amount_ht) .
' ' . $langs->trans(
"HT") .
' - ' .
price($obj->amount_ttc) .
' ' . $langs->trans(
"TTC") .
')</option>';
1702 return $qualifiedlines;
1731 public function select_contacts($socid, $selected =
'', $htmlname =
'contactid', $showempty = 0, $exclude =
'', $limitto =
'', $showfunction = 0, $morecss =
'', $showsoc = 0, $forcecombo = 0, $events = array(), $options_only =
false, $moreparam =
'', $htmlid =
'')
1734 print $this->
selectcontacts($socid, $selected, $htmlname, $showempty, $exclude, $limitto, $showfunction, $morecss, $options_only, $showsoc, $forcecombo, $events, $moreparam, $htmlid);
1762 public function selectcontacts($socid, $selected =
'', $htmlname =
'contactid', $showempty = 0, $exclude =
'', $limitto =
'', $showfunction = 0, $morecss =
'', $options_only =
false, $showsoc = 0, $forcecombo = 0, $events = array(), $moreparam =
'', $htmlid =
'', $multiple =
false, $disableifempty = 0)
1764 global $conf, $langs, $hookmanager, $action;
1766 $langs->load(
'companies');
1768 if (empty($htmlid)) {
1769 $htmlid = $htmlname;
1773 if ($selected ===
'') {
1774 $selected = array();
1775 } elseif (!is_array($selected)) {
1776 $selected = array($selected);
1780 if (!is_object($hookmanager)) {
1781 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
1786 $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";
1787 if ($showsoc > 0 || !empty($conf->global->CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST)) {
1788 $sql .=
", s.nom as company, s.town AS company_town";
1790 $sql .=
" FROM " . $this->db->prefix() .
"socpeople as sp";
1791 if ($showsoc > 0 || !empty($conf->global->CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST)) {
1792 $sql .=
" LEFT OUTER JOIN " . $this->db->prefix() .
"societe as s ON s.rowid=sp.fk_soc";
1794 $sql .=
" WHERE sp.entity IN (" .
getEntity(
'contact') .
")";
1795 if ($socid > 0 || $socid == -1) {
1796 $sql .=
" AND sp.fk_soc = " . ((int) $socid);
1798 if (!empty($conf->global->CONTACT_HIDE_INACTIVE_IN_COMBOBOX)) {
1799 $sql .=
" AND sp.statut <> 0";
1802 $parameters = array();
1803 $reshook = $hookmanager->executeHooks(
'selectContactListWhere', $parameters);
1804 $sql .= $hookmanager->resPrint;
1805 $sql .=
" ORDER BY sp.lastname ASC";
1807 dol_syslog(get_class($this) .
"::selectcontacts", LOG_DEBUG);
1808 $resql = $this->db->query(
$sql);
1810 $num = $this->db->num_rows($resql);
1812 if ($htmlname !=
'none' && !$options_only) {
1813 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlid .
'" name="' . $htmlname . (($num || empty($disableifempty)) ?
'' :
' disabled') . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . (!empty($moreparam) ? $moreparam :
'') .
'>';
1816 if ($showempty && !is_numeric($showempty)) {
1817 $textforempty = $showempty;
1818 $out .=
'<option class="optiongrey" value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'>' . $textforempty .
'</option>';
1820 if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) {
1821 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'> </option>';
1823 if ($showempty == 2) {
1824 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Internal") .
' --</option>';
1830 include_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
1831 $contactstatic =
new Contact($this->db);
1834 $obj = $this->db->fetch_object($resql);
1837 $extendedInfos =
'';
1838 if (!empty($conf->global->CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST)) {
1839 $extendedInfos = array();
1840 $email = trim($obj->email);
1841 if (!empty($email)) {
1842 $extendedInfos[] = $email;
1844 $phone = trim($obj->phone);
1845 $phone_perso = trim($obj->phone_perso);
1846 $phone_mobile = trim($obj->phone_mobile);
1847 if (!empty($phone)) {
1848 $extendedInfos[] = $phone;
1850 if (!empty($phone_perso)) {
1851 $extendedInfos[] = $phone_perso;
1853 if (!empty($phone_mobile)) {
1854 $extendedInfos[] = $phone_mobile;
1857 $contact_town = trim($obj->contact_town);
1858 $company_town = trim($obj->company_town);
1859 if (!empty($contact_town)) {
1860 $extendedInfos[] = $contact_town;
1861 } elseif (!empty($company_town)) {
1862 $extendedInfos[] = $company_town;
1864 $extendedInfos = implode(
' - ', $extendedInfos);
1865 if (!empty($extendedInfos)) {
1866 $extendedInfos =
' - ' . $extendedInfos;
1870 $contactstatic->id = $obj->rowid;
1871 $contactstatic->lastname = $obj->lastname;
1872 $contactstatic->firstname = $obj->firstname;
1873 if ($obj->statut == 1) {
1874 if ($htmlname !=
'none') {
1876 if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) {
1879 if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) {
1882 if (!empty($selected) && in_array($obj->rowid, $selected)) {
1883 $out .=
'<option value="' . $obj->rowid .
'"';
1885 $out .=
' disabled';
1887 $out .=
' selected>';
1888 $out .= $contactstatic->getFullName($langs) . $extendedInfos;
1889 if ($showfunction && $obj->poste) {
1890 $out .=
' (' . $obj->poste .
')';
1892 if (($showsoc > 0) && $obj->company) {
1893 $out .=
' - (' . $obj->company .
')';
1895 $out .=
'</option>';
1897 $out .=
'<option value="' . $obj->rowid .
'"';
1899 $out .=
' disabled';
1902 $out .= $contactstatic->getFullName($langs) . $extendedInfos;
1903 if ($showfunction && $obj->poste) {
1904 $out .=
' (' . $obj->poste .
')';
1906 if (($showsoc > 0) && $obj->company) {
1907 $out .=
' - (' . $obj->company .
')';
1909 $out .=
'</option>';
1912 if (in_array($obj->rowid, $selected)) {
1913 $out .= $contactstatic->getFullName($langs) . $extendedInfos;
1914 if ($showfunction && $obj->poste) {
1915 $out .=
' (' . $obj->poste .
')';
1917 if (($showsoc > 0) && $obj->company) {
1918 $out .=
' - (' . $obj->company .
')';
1926 $labeltoshow = ($socid != -1) ? ($langs->trans($socid ?
"NoContactDefinedForThirdParty" :
"NoContactDefined")) : $langs->trans(
'SelectAThirdPartyFirst');
1927 $out .=
'<option class="disabled" value="-1"' . (($showempty == 2 || $multiple) ?
'' :
' selected') .
' disabled="disabled">';
1928 $out .= $labeltoshow;
1929 $out .=
'</option>';
1932 $parameters = array(
1934 'htmlname' => $htmlname,
1937 'showfunction' => $showfunction,
1938 'showsoc' => $showsoc,
1941 $reshook = $hookmanager->executeHooks(
'afterSelectContactOptions', $parameters, $this, $action);
1943 if ($htmlname !=
'none' && !$options_only) {
1944 $out .=
'</select>';
1947 if ($conf->use_javascript_ajax && !$forcecombo && !$options_only) {
1948 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1977 public function select_users($selected =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include =
'', $enableonly =
'', $force_entity =
'0')
1980 print $this->
select_dolusers($selected, $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity);
2009 public function select_dolusers($selected =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include =
'', $enableonly =
'', $force_entity =
'0', $maxlength = 0, $showstatus = 0, $morefilter =
'', $show_every = 0, $enableonlytext =
'', $morecss =
'', $notdisabled = 0, $outputmode = 0, $multiple =
false, $forcecombo = 0)
2012 global $conf, $user, $langs, $hookmanager;
2016 if ((is_numeric($selected) && ($selected < -2 || empty($selected))) && empty($conf->global->SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE)) {
2017 $selected = $user->id;
2020 if ($selected ===
'') {
2021 $selected = array();
2022 } elseif (!is_array($selected)) {
2023 $selected = array($selected);
2026 $excludeUsers =
null;
2027 $includeUsers =
null;
2030 if (is_array($exclude)) {
2031 $excludeUsers = implode(
",", $exclude);
2034 if (is_array($include)) {
2035 $includeUsers = implode(
",", $include);
2036 } elseif ($include ==
'hierarchy') {
2038 $includeUsers = implode(
",", $user->getAllChildIds(0));
2039 } elseif ($include ==
'hierarchyme') {
2041 $includeUsers = implode(
",", $user->getAllChildIds(1));
2045 $outarray = array();
2046 $outarray2 = array();
2049 $sql =
"SELECT DISTINCT u.rowid, u.lastname as lastname, u.firstname, u.statut as status, u.login, u.admin, u.entity, u.photo";
2050 if (
isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
2051 $sql .=
", e.label";
2053 $sql .=
" FROM " . $this->db->prefix() .
"user as u";
2054 if (
isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
2055 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid = u.entity";
2056 if ($force_entity) {
2057 $sql .=
" WHERE u.entity IN (0, " . $this->db->sanitize($force_entity) .
")";
2059 $sql .=
" WHERE u.entity IS NOT NULL";
2062 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
2063 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"usergroup_user as ug";
2064 $sql .=
" ON ug.fk_user = u.rowid";
2065 $sql .=
" WHERE ug.entity = " . (int) $conf->entity;
2067 $sql .=
" WHERE u.entity IN (0, " . ((int) $conf->entity) .
")";
2070 if (!empty($user->socid)) {
2071 $sql .=
" AND u.fk_soc = " . ((int) $user->socid);
2073 if (is_array($exclude) && $excludeUsers) {
2074 $sql .=
" AND u.rowid NOT IN (" . $this->db->sanitize($excludeUsers) .
")";
2076 if ($includeUsers) {
2077 $sql .=
" AND u.rowid IN (" . $this->db->sanitize($includeUsers) .
")";
2079 if (!empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX) || $notdisabled) {
2080 $sql .=
" AND u.statut <> 0";
2082 if (!empty($morefilter)) {
2083 $sql .=
" " . $morefilter;
2087 $reshook = $hookmanager->executeHooks(
'addSQLWhereFilterOnSelectUsers', array(), $this, $action);
2088 if (!empty($reshook)) {
2089 $sql .= $hookmanager->resPrint;
2092 if (empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)) {
2093 $sql .=
" ORDER BY u.statut DESC, u.firstname ASC, u.lastname ASC";
2095 $sql .=
" ORDER BY u.statut DESC, u.lastname ASC, u.firstname ASC";
2098 dol_syslog(get_class($this) .
"::select_dolusers", LOG_DEBUG);
2100 $resql = $this->db->query(
$sql);
2102 $num = $this->db->num_rows($resql);
2106 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
' minwidth200') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
2107 if ($show_empty && !$multiple) {
2108 $textforempty =
' ';
2109 if (!empty($conf->use_javascript_ajax)) {
2110 $textforempty =
' ';
2112 if (!is_numeric($show_empty)) {
2113 $textforempty = $show_empty;
2115 $out .=
'<option class="optiongrey" value="' . ($show_empty < 0 ? $show_empty : -1) .
'"' . ((empty($selected) || in_array(-1, $selected)) ?
' selected' :
'') .
'>' . $textforempty .
'</option>' .
"\n";
2118 $out .=
'<option value="-2"' . ((in_array(-2, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Everybody") .
' --</option>' .
"\n";
2121 $userstatic =
new User($this->db);
2124 $obj = $this->db->fetch_object($resql);
2126 $userstatic->id = $obj->rowid;
2127 $userstatic->lastname = $obj->lastname;
2128 $userstatic->firstname = $obj->firstname;
2129 $userstatic->photo = $obj->photo;
2130 $userstatic->statut = $obj->status;
2131 $userstatic->entity = $obj->entity;
2132 $userstatic->admin = $obj->admin;
2135 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
2136 $disableline = ($enableonlytext ? $enableonlytext :
'1');
2140 $labeltoshowhtml =
'';
2144 if (empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)) {
2147 $labeltoshow .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2148 $labeltoshowhtml .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2149 if (empty($obj->firstname) && empty($obj->lastname)) {
2150 $labeltoshow .= $obj->login;
2151 $labeltoshowhtml .= $obj->login;
2157 if (!empty($conf->global->MAIN_SHOW_LOGIN)) {
2158 $moreinfo .= ($moreinfo ?
' - ' :
' (');
2159 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(');
2160 $moreinfo .= $obj->login;
2161 $moreinfohtml .= $obj->login;
2163 if ($showstatus >= 0) {
2164 if ($obj->status == 1 && $showstatus == 1) {
2165 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Enabled');
2166 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Enabled');
2168 if ($obj->status == 0 && $showstatus == 1) {
2169 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Disabled');
2170 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Disabled');
2173 if (
isModEnabled(
'multicompany') && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1 && $user->admin && !$user->entity) {
2174 if (!$obj->entity) {
2175 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
"AllEntities");
2176 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
"AllEntities");
2178 if ($obj->entity != $conf->entity) {
2179 $moreinfo .= ($moreinfo ?
' - ' :
' (') . ($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2180 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . ($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2184 $moreinfo .= ($moreinfo ?
')' :
'');
2185 $moreinfohtml .= ($moreinfohtml ?
')</span>' :
'');
2186 if ($disableline && $disableline !=
'1') {
2188 $moreinfo .=
' - ' . $disableline;
2189 $moreinfohtml .=
' - ' . $disableline;
2191 $labeltoshow .= $moreinfo;
2192 $labeltoshowhtml .= $moreinfohtml;
2194 $out .=
'<option value="' . $obj->rowid .
'"';
2196 $out .=
' disabled';
2198 if ((is_object($selected) && $selected->id == $obj->rowid) || (!is_object($selected) && in_array($obj->rowid, $selected))) {
2199 $out .=
' selected';
2201 $out .=
' data-html="';
2202 $outhtml = $userstatic->getNomUrl(-3,
'', 0, 1, 24, 1,
'login',
'', 1) .
' ';
2203 if ($showstatus >= 0 && $obj->status == 0) {
2204 $outhtml .=
'<strike class="opacitymediumxxx">';
2206 $outhtml .= $labeltoshowhtml;
2207 if ($showstatus >= 0 && $obj->status == 0) {
2208 $outhtml .=
'</strike>';
2212 $out .= $labeltoshow;
2213 $out .=
'</option>';
2215 $outarray[$userstatic->id] = $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength) . $moreinfo;
2216 $outarray2[$userstatic->id] = array(
2217 'id'=>$userstatic->id,
2218 'label'=>$labeltoshow,
2219 'labelhtml'=>$labeltoshowhtml,
2227 $out .=
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'" disabled>';
2228 $out .=
'<option value="">' . $langs->trans(
"None") .
'</option>';
2230 $out .=
'</select>';
2232 if ($num && !$forcecombo) {
2234 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2241 if ($outputmode == 2) {
2243 } elseif ($outputmode) {
2275 public function select_dolusers_forevent($action =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include =
'', $enableonly =
'', $force_entity =
'0', $maxlength = 0, $showstatus = 0, $morefilter =
'', $showproperties = 0, $listofuserid = array(), $listofcontactid = array(), $listofotherid = array())
2278 global $conf, $user, $langs;
2280 $userstatic =
new User($this->db);
2284 $assignedtouser = array();
2285 if (!empty($_SESSION[
'assignedtouser'])) {
2286 $assignedtouser = json_decode($_SESSION[
'assignedtouser'],
true);
2288 $nbassignetouser = count($assignedtouser);
2291 if ($nbassignetouser) {
2292 $out .=
'<ul class="attendees">';
2296 foreach ($assignedtouser as $key => $value) {
2297 if ($value[
'id'] == $ownerid) {
2302 $userstatic->fetch($value[
'id']);
2303 $out .= $userstatic->getNomUrl(-1);
2305 $ownerid = $value[
'id'];
2306 $out .=
' (' . $langs->trans(
"Owner") .
')';
2308 if ($nbassignetouser > 1 && $action !=
'view') {
2309 $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 .
'">';
2312 if ($showproperties) {
2313 if ($ownerid == $value[
'id'] && is_array($listofuserid) && count($listofuserid) && in_array($ownerid, array_keys($listofuserid))) {
2314 $out .=
'<div class="myavailability inline-block">';
2315 $out .=
'<span class="hideonsmartphone"> - <span class="opacitymedium">' . $langs->trans(
"Availability") .
':</span> </span><input id="transparency" class="paddingrightonly" ' . ($action ==
'view' ?
'disabled' :
'') .
' type="checkbox" name="transparency"' . ($listofuserid[$ownerid][
'transparency'] ?
' checked' :
'') .
'><label for="transparency">' . $langs->trans(
"Busy") .
'</label>';
2325 if ($nbassignetouser) {
2330 if ($action !=
'view') {
2331 $out .=
'<input type="hidden" class="removedassignedhidden" name="removedassigned" value="">';
2332 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
2333 $out .=
'jQuery(".removedassigned").click(function() { jQuery(".removedassignedhidden").val(jQuery(this).val()); });';
2334 $out .=
'jQuery(".assignedtouser").change(function() { console.log(jQuery(".assignedtouser option:selected").val());';
2335 $out .=
' if (jQuery(".assignedtouser option:selected").val() > 0) { jQuery("#' . $action .
'assignedtouser").attr("disabled", false); }';
2336 $out .=
' else { jQuery("#' . $action .
'assignedtouser").attr("disabled", true); }';
2338 $out .=
'})</script>';
2339 $out .= $this->
select_dolusers(
'', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter);
2340 $out .=
' <input type="submit" disabled class="button valignmiddle smallpaddingimp reposition" id="' . $action .
'assignedtouser" name="' . $action .
'assignedtouser" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
2377 public function select_produits($selected =
'', $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)
2380 global $langs, $conf;
2385 $price_level = (!empty($price_level) ? $price_level : 0);
2386 if (is_null($ajaxoptions)) {
2387 $ajaxoptions = array();
2398 if (!empty($conf->use_javascript_ajax) && !empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) {
2401 if ($selected && empty($selected_input_value)) {
2402 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
2403 $producttmpselect =
new Product($this->db);
2404 $producttmpselect->fetch($selected);
2405 $selected_input_value = $producttmpselect->ref;
2406 unset($producttmpselect);
2409 if ($filtertype ==
'') {
2417 $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;
2418 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT .
'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
2420 if (
isModEnabled(
'variants') && is_array($selected_combinations)) {
2424 <!-- script to auto show attributes select tags if a variant was selected -->
2425 <script nonce="' .
getNonce() .
'">
2426 // auto show attributes fields
2427 selected = ' . json_encode($selected_combinations) .
';
2430 jQuery(document).ready(function () {
2432 jQuery("input[name=\'prod_entry_mode\']").change(function () {
2433 if (jQuery(this).val() == \'free\') {
2434 jQuery(\'div#attributes_box\').empty();
2438 jQuery("input#' . $htmlname .
'").change(function () {
2440 if (!jQuery(this).val()) {
2441 jQuery(\'div#attributes_box\').empty();
2445 console.log("A change has started. We get variants fields to inject html select");
2447 jQuery.getJSON("' . DOL_URL_ROOT .
'/variants/ajax/getCombinations.php", {
2448 id: jQuery(this).val()
2449 }, function (data) {
2450 jQuery(\'div#attributes_box\').empty();
2452 jQuery.each(data, function (key, val) {
2454 combvalues[val.id] = val.values;
2456 var span = jQuery(document.createElement(\'div\')).css({
2457 \'display\': \'table-row\'
2461 jQuery(document.createElement(\'div\')).text(val.label).css({
2462 \'font-weight\': \'bold\',
2463 \'display\': \'table-cell\'
2467 var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({
2468 \'margin-left\': \'15px\',
2469 \'white-space\': \'pre\'
2471 jQuery(document.createElement(\'option\')).val(\'\')
2474 jQuery.each(combvalues[val.id], function (key, val) {
2475 var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value);
2477 if (selected[val.fk_product_attribute] == val.id) {
2478 tag.attr(\'selected\', \'selected\');
2485 jQuery(\'div#attributes_box\').append(span);
2490 ' . ($selected ?
'jQuery("input#' . $htmlname .
'").change();' :
'') .
'
2496 if (empty($hidelabel)) {
2497 $out .= $langs->trans(
"RefOrLabel") .
' : ';
2498 } elseif ($hidelabel > 1) {
2499 $placeholder =
' placeholder="' . $langs->trans(
"RefOrLabel") .
'"';
2500 if ($hidelabel == 2) {
2501 $out .=
img_picto($langs->trans(
"Search"),
'search');
2504 $out .=
'<input type="text" class="minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . $placeholder .
' ' . (!empty($conf->global->PRODUCT_SEARCH_AUTOFOCUS) ?
'autofocus' :
'') .
' />';
2505 if ($hidelabel == 3) {
2506 $out .=
img_picto($langs->trans(
"Search"),
'search');
2509 $out .= $this->
select_produits_list($selected, $htmlname, $filtertype, $limit, $price_level,
'', $status, $finished, 0, $socid, $showempty, $forcecombo, $morecss, $hidepriceinlabel, $warehouseStatus, $status_purchase);
2512 if (empty($nooutput)) {
2536 public function select_bom($selected =
'', $htmlname =
'bom_id', $limit = 0, $status = 1, $type = 0, $showempty =
'1', $morecss =
'', $nooutput =
'', $forcecombo = 0, $TProducts = [])
2539 global $conf, $user, $langs, $db;
2541 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
2547 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2552 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
2554 $sql =
'SELECT b.rowid, b.ref, b.label, b.fk_product';
2555 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'bom_bom as b';
2557 if (!empty($status))
$sql .=
' AND status = ' . (int) $status;
2558 if (!empty($type))
$sql .=
' AND bomtype = ' . (
int) $type;
2559 if (!empty($TProducts))
$sql .=
' AND fk_product IN (' . $this->db->sanitize(implode(
',', $TProducts)) .
')';
2560 if (!empty($limit))
$sql .=
' LIMIT ' . (
int) $limit;
2561 $resql = $db->query(
$sql);
2564 $out .=
'<option value="-1"';
2565 if (empty($selected)) $out .=
' selected';
2566 $out .=
'> </option>';
2568 while ($obj = $db->fetch_object($resql)) {
2570 $res = $product->fetch($obj->fk_product);
2571 $out .=
'<option value="' . $obj->rowid .
'"';
2572 if ($obj->rowid == $selected) $out .=
'selected';
2573 $out .=
'>' . $obj->ref .
' - ' . $product->label .
' - ' . $obj->label .
'</option>';
2579 $out .=
'</select>';
2580 if (empty($nooutput)) {
2614 public function select_produits_list($selected =
'', $htmlname =
'productid', $filtertype =
'', $limit = 20, $price_level = 0, $filterkey =
'', $status = 1, $finished = 2, $outputmode = 0, $socid = 0, $showempty =
'1', $forcecombo = 0, $morecss =
'', $hidepriceinlabel = 0, $warehouseStatus =
'', $status_purchase = -1)
2617 global $langs, $conf;
2618 global $hookmanager;
2621 $outarray = array();
2625 $langs->load(
'other');
2628 $warehouseStatusArray = array();
2629 if (!empty($warehouseStatus)) {
2630 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/entrepot.class.php';
2631 if (preg_match(
'/warehouseclosed/', $warehouseStatus)) {
2634 if (preg_match(
'/warehouseopen/', $warehouseStatus)) {
2637 if (preg_match(
'/warehouseinternal/', $warehouseStatus)) {
2642 $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";
2643 if (count($warehouseStatusArray)) {
2644 $selectFieldsGrouped =
", sum(" . $this->db->ifsql(
"e.statut IS NULL",
"0",
"ps.reel") .
") as stock";
2646 $selectFieldsGrouped =
", " . $this->db->ifsql(
"p.stock IS NULL", 0,
"p.stock") .
" AS stock";
2652 $parameters = array();
2653 $reshook = $hookmanager->executeHooks(
'selectProductsListSelect', $parameters);
2654 if (empty($reshook)) {
2655 $sql .= $selectFields.$selectFieldsGrouped.$hookmanager->resPrint;
2657 $sql .= $hookmanager->resPrint;
2660 if (!empty($conf->global->PRODUCT_SORT_BY_CATEGORY)) {
2662 $sql .=
", (SELECT " . $this->db->prefix() .
"categorie_product.fk_categorie
2663 FROM " . $this->db->prefix() .
"categorie_product
2664 WHERE " . $this->db->prefix() .
"categorie_product.fk_product=p.rowid
2666 ) AS categorie_product_id ";
2670 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) {
2671 $sql .=
', pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,';
2672 $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';
2673 $selectFields .=
", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custdefault_vat_code, custref";
2677 $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";
2678 $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';
2683 $sql .=
", pl.label as label_translated";
2684 $sql .=
", pl.description as description_translated";
2685 $selectFields .=
", label_translated";
2686 $selectFields .=
", description_translated";
2689 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
2690 $sql .=
", (SELECT pp.rowid FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
2691 if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
2692 $sql .=
" AND price_level = " . ((int) $price_level);
2694 $sql .=
" ORDER BY date_price";
2695 $sql .=
" DESC LIMIT 1) as price_rowid";
2696 $sql .=
", (SELECT pp.price_by_qty FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
2697 if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
2698 $sql .=
" AND price_level = " . ((int) $price_level);
2700 $sql .=
" ORDER BY date_price";
2701 $sql .=
" DESC LIMIT 1) as price_by_qty";
2702 $selectFields .=
", price_rowid, price_by_qty";
2705 $sql .=
" FROM ".$this->db->prefix().
"product as p";
2707 $parameters = array();
2708 $reshook = $hookmanager->executeHooks(
'selectProductsListFrom', $parameters);
2709 $sql .= $hookmanager->resPrint;
2711 if (count($warehouseStatusArray)) {
2712 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_stock as ps on ps.fk_product = p.rowid";
2713 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entrepot as e on ps.fk_entrepot = e.rowid AND e.entity IN (" .
getEntity(
'stock') .
")";
2714 $sql .=
' AND e.statut IN (' . $this->db->sanitize($this->db->escape(implode(
',', $warehouseStatusArray))) .
')';
2718 if (!empty($conf->global->MAIN_SEARCH_PRODUCT_BY_FOURN_REF)) {
2719 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
2723 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) {
2724 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_customer_price as pcp ON pcp.fk_soc=" . ((int) $socid) .
" AND pcp.fk_product=p.rowid";
2728 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
2732 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_lang as pl ON pl.fk_product = p.rowid ";
2733 if (!empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && !empty($socid)) {
2734 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
2735 $soc =
new Societe($this->db);
2736 $result = $soc->fetch($socid);
2737 if ($result > 0 && !empty($soc->default_lang)) {
2738 $sql .=
" AND pl.lang = '" . $this->db->escape($soc->default_lang) .
"'";
2740 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
2743 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
2747 if (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) {
2748 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_attribute_combination pac ON pac.fk_product_child = p.rowid";
2751 $sql .=
' WHERE p.entity IN (' .
getEntity(
'product') .
')';
2753 if (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) {
2754 $sql .=
" AND pac.rowid IS NULL";
2757 if ($finished == 0) {
2758 $sql .=
" AND p.finished = " . ((int) $finished);
2759 } elseif ($finished == 1) {
2760 $sql .=
" AND p.finished = " . ((int) $finished);
2762 $sql .=
" AND p.tosell = " . ((int) $status);
2764 } elseif ($status >= 0) {
2765 $sql .=
" AND p.tosell = " . ((int) $status);
2767 if ($status_purchase >= 0) {
2768 $sql .=
" AND p.tobuy = " . ((int) $status_purchase);
2771 if (strval($filtertype) !=
'') {
2772 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
2774 $sql .=
" AND p.fk_product_type = 1";
2776 $sql .=
" AND p.fk_product_type = 0";
2779 $parameters = array();
2780 $reshook = $hookmanager->executeHooks(
'selectProductsListWhere', $parameters);
2781 $sql .= $hookmanager->resPrint;
2783 if ($filterkey !=
'') {
2785 $prefix = empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE) ?
'%' :
'';
2787 $scrit = explode(
' ', $filterkey);
2789 if (count($scrit) > 1) {
2792 foreach ($scrit as $crit) {
2796 $sql .=
"(p.ref LIKE '" . $this->db->escape($prefix . $crit) .
"%' OR p.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
2798 $sql .=
" OR pl.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
2800 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) {
2801 $sql .=
" OR pcp.ref_customer LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
2803 if (!empty($conf->global->PRODUCT_AJAX_SEARCH_ON_DESCRIPTION)) {
2804 $sql .=
" OR p.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
2806 $sql .=
" OR pl.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
2809 if (!empty($conf->global->MAIN_SEARCH_PRODUCT_BY_FOURN_REF)) {
2810 $sql .=
" OR pfp.ref_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
2815 if (count($scrit) > 1) {
2819 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
2823 if (count($warehouseStatusArray)) {
2824 $sql .=
" GROUP BY " . $selectFields;
2828 if (!empty($conf->global->PRODUCT_SORT_BY_CATEGORY)) {
2829 $sql .=
" ORDER BY categorie_product_id ";
2831 ($conf->global->PRODUCT_SORT_BY_CATEGORY == 1) ?
$sql .=
"ASC" :
$sql .=
"DESC";
2833 $sql .= $this->db->order(
"p.ref");
2836 $sql .= $this->db->plimit($limit, 0);
2839 dol_syslog(get_class($this) .
"::select_produits_list search products", LOG_DEBUG);
2840 $result = $this->db->query(
$sql);
2842 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
2843 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
2844 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
2846 $num = $this->db->num_rows($result);
2851 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2855 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
2860 if (!empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) {
2861 if ($showempty && !is_numeric($showempty)) {
2862 $textifempty = $langs->trans($showempty);
2864 $textifempty .= $langs->trans(
"All");
2867 if ($showempty && !is_numeric($showempty)) {
2868 $textifempty = $langs->trans($showempty);
2872 $out .=
'<option value="-1" selected>' . ($textifempty ? $textifempty :
' ') .
'</option>';
2876 while ($num && $i < $num) {
2879 $objp = $this->db->fetch_object($result);
2881 if ((!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1) {
2882 $sql =
"SELECT rowid, quantity, price, unitprice, remise_percent, remise, price_base_type";
2883 $sql .=
" FROM " . $this->db->prefix() .
"product_price_by_qty";
2884 $sql .=
" WHERE fk_product_price = " . ((int) $objp->price_rowid);
2885 $sql .=
" ORDER BY quantity ASC";
2887 dol_syslog(get_class($this) .
"::select_produits_list search prices by qty", LOG_DEBUG);
2888 $result2 = $this->db->query(
$sql);
2890 $nb_prices = $this->db->num_rows($result2);
2892 while ($nb_prices && $j < $nb_prices) {
2893 $objp2 = $this->db->fetch_object($result2);
2895 $objp->price_by_qty_rowid = $objp2->rowid;
2896 $objp->price_by_qty_price_base_type = $objp2->price_base_type;
2897 $objp->price_by_qty_quantity = $objp2->quantity;
2898 $objp->price_by_qty_unitprice = $objp2->unitprice;
2899 $objp->price_by_qty_remise_percent = $objp2->remise_percent;
2901 $objp->quantity = $objp2->quantity;
2902 $objp->price = $objp2->price;
2903 $objp->unitprice = $objp2->unitprice;
2904 $objp->remise_percent = $objp2->remise_percent;
2917 array_push($outarray, $optJson);
2921 if (
isModEnabled(
'dynamicprices') && !empty($objp->fk_price_expression)) {
2922 $price_product =
new Product($this->db);
2923 $price_product->fetch($objp->rowid,
'',
'', 1);
2925 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
2927 $price_result = $priceparser->parseProduct($price_product);
2928 if ($price_result >= 0) {
2929 $objp->price = $price_result;
2930 $objp->unitprice = $price_result;
2932 $objp->price_ttc =
price2num($objp->price) * (1 + ($objp->tva_tx / 100));
2933 $objp->price_ttc =
price2num($objp->price_ttc,
'MU');
2942 array_push($outarray, $optJson);
2948 $out .=
'</select>';
2950 $this->db->free($result);
2952 if (empty($outputmode)) {
2979 protected function constructProductListOption(&$objp, &$opt, &$optJson, $price_level, $selected, $hidepriceinlabel = 0, $filterkey =
'', $novirtualstock = 0)
2981 global $langs, $conf, $user;
2982 global $hookmanager;
2988 $outlabel_translated =
'';
2990 $outdesc_translated =
'';
2996 $outpricebasetype =
'';
2998 $outdefault_vat_code =
'';
3002 $maxlengtharticle = (empty($conf->global->PRODUCT_MAX_LENGTH_COMBO) ? 48 : $conf->global->PRODUCT_MAX_LENGTH_COMBO);
3004 $label = $objp->label;
3005 if (!empty($objp->label_translated)) {
3006 $label = $objp->label_translated;
3008 if (!empty($filterkey) && $filterkey !=
'') {
3009 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
3012 $outkey = $objp->rowid;
3013 $outref = $objp->ref;
3014 $outrefcust = empty($objp->custref) ?
'' : $objp->custref;
3015 $outlabel = $objp->label;
3016 $outdesc = $objp->description;
3018 $outlabel_translated = $objp->label_translated;
3019 $outdesc_translated = $objp->description_translated;
3021 $outbarcode = $objp->barcode;
3022 $outorigin = $objp->fk_country;
3023 $outpbq = empty($objp->price_by_qty_rowid) ?
'' : $objp->price_by_qty_rowid;
3025 $outtype = $objp->fk_product_type;
3029 if ($outorigin && !empty($conf->global->PRODUCT_SHOW_ORIGIN_IN_COMBO)) {
3030 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
3036 if (!empty($objp->unit_short)) {
3037 $outvalUnits .=
' - ' . $objp->unit_short;
3040 if (!empty($conf->global->PRODUCT_SHOW_DIMENSIONS_IN_COMBO)) {
3041 if (!empty($objp->weight) && $objp->weight_units !==
null) {
3043 $outvalUnits .=
' - ' . $unitToShow;
3045 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
3046 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
3047 $outvalUnits .=
' - ' . $unitToShow;
3049 if (!empty($objp->surface) && $objp->surface_units !==
null) {
3051 $outvalUnits .=
' - ' . $unitToShow;
3053 if (!empty($objp->volume) && $objp->volume_units !==
null) {
3055 $outvalUnits .=
' - ' . $unitToShow;
3058 if ($outdurationvalue && $outdurationunit) {
3060 'h' => $langs->trans(
'Hour'),
3061 'd' => $langs->trans(
'Day'),
3062 'w' => $langs->trans(
'Week'),
3063 'm' => $langs->trans(
'Month'),
3064 'y' => $langs->trans(
'Year')
3066 if (isset($da[$outdurationunit])) {
3067 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
3071 $opt =
'<option value="' . $objp->rowid .
'"';
3072 $opt .= ($objp->rowid == $selected) ?
' selected' :
'';
3073 if (!empty($objp->price_by_qty_rowid) && $objp->price_by_qty_rowid > 0) {
3074 $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 .
'"';
3077 if (!empty($user->rights->stock->lire)) {
3078 if ($objp->stock > 0) {
3079 $opt .=
' class="product_line_stock_ok"';
3080 } elseif ($objp->stock <= 0) {
3081 $opt .=
' class="product_line_stock_too_low"';
3085 if (!empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
3086 $opt .=
' data-labeltrans="' . $outlabel_translated .
'"';
3091 if (!empty($objp->custref)) {
3092 $opt .=
' (' . $objp->custref .
')';
3095 $opt .=
' (' . $outbarcode .
')';
3097 $opt .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3098 if ($outorigin && !empty($conf->global->PRODUCT_SHOW_ORIGIN_IN_COMBO)) {
3099 $opt .=
' (' .
getCountry($outorigin, 1) .
')';
3102 $objRef = $objp->ref;
3103 if (!empty($objp->custref)) {
3104 $objRef .=
' (' . $objp->custref .
')';
3106 if (!empty($filterkey) && $filterkey !=
'') {
3107 $objRef = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRef, 1);
3111 $outval .=
' (' . $outbarcode .
')';
3113 $outval .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3114 if ($outorigin && !empty($conf->global->PRODUCT_SHOW_ORIGIN_IN_COMBO)) {
3115 $outval .=
' (' .
getCountry($outorigin, 1) .
')';
3119 $opt .= $outvalUnits;
3120 $outval .= $outvalUnits;
3126 if (empty($hidepriceinlabel) && $price_level >= 1 && (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))) {
3127 $sql =
"SELECT price, price_ttc, price_base_type, tva_tx, default_vat_code";
3128 $sql .=
" FROM " . $this->db->prefix() .
"product_price";
3129 $sql .=
" WHERE fk_product = " . ((int) $objp->rowid);
3130 $sql .=
" AND entity IN (" .
getEntity(
'productprice') .
")";
3131 $sql .=
" AND price_level = " . ((int) $price_level);
3132 $sql .=
" ORDER BY date_price DESC, rowid DESC";
3135 dol_syslog(get_class($this) .
'::constructProductListOption search price for product ' . $objp->rowid .
' AND level ' . $price_level, LOG_DEBUG);
3136 $result2 = $this->db->query(
$sql);
3138 $objp2 = $this->db->fetch_object($result2);
3141 if ($objp2->price_base_type ==
'HT') {
3142 $opt .=
' - ' .
price($objp2->price, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"HT");
3143 $outval .=
' - ' .
price($objp2->price, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"HT");
3145 $opt .=
' - ' .
price($objp2->price_ttc, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"TTC");
3146 $outval .=
' - ' .
price($objp2->price_ttc, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3148 $outprice_ht =
price($objp2->price);
3149 $outprice_ttc =
price($objp2->price_ttc);
3150 $outpricebasetype = $objp2->price_base_type;
3151 if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
3152 $outtva_tx = $objp2->tva_tx;
3153 $outdefault_vat_code = $objp2->default_vat_code;
3155 $outtva_tx = $objp->tva_tx;
3156 $outdefault_vat_code = $objp->default_vat_code;
3165 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1 && (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))) {
3167 $outqty = $objp->quantity;
3168 $outdiscount = $objp->remise_percent;
3169 if ($objp->quantity == 1) {
3170 $opt .=
' - ' .
price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency) .
"/";
3171 $outval .=
' - ' .
price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency) .
"/";
3172 $opt .= $langs->trans(
"Unit");
3173 $outval .= $langs->transnoentities(
"Unit");
3175 $opt .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1, $conf->currency) .
"/" . $objp->quantity;
3176 $outval .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1, $conf->currency) .
"/" . $objp->quantity;
3177 $opt .= $langs->trans(
"Units");
3178 $outval .= $langs->transnoentities(
"Units");
3181 $outprice_ht =
price($objp->unitprice);
3182 $outprice_ttc =
price($objp->unitprice * (1 + ($objp->tva_tx / 100)));
3183 $outpricebasetype = $objp->price_base_type;
3184 $outtva_tx = $objp->tva_tx;
3185 $outdefault_vat_code = $objp->default_vat_code;
3187 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1) {
3188 $opt .=
" (" .
price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency) .
"/" . $langs->trans(
"Unit") .
")";
3189 $outval .=
" (" .
price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency) .
"/" . $langs->transnoentities(
"Unit") .
")";
3191 if (empty($hidepriceinlabel) && !empty($objp->remise_percent) && $objp->remise_percent >= 1) {
3192 $opt .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3193 $outval .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3197 if (empty($hidepriceinlabel) && !empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
3198 if (!empty($objp->idprodcustprice)) {
3201 if ($objp->custprice_base_type ==
'HT') {
3202 $opt .=
' - ' .
price($objp->custprice, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"HT");
3203 $outval .=
' - ' .
price($objp->custprice, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"HT");
3205 $opt .=
' - ' .
price($objp->custprice_ttc, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"TTC");
3206 $outval .=
' - ' .
price($objp->custprice_ttc, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3209 $outprice_ht =
price($objp->custprice);
3210 $outprice_ttc =
price($objp->custprice_ttc);
3211 $outpricebasetype = $objp->custprice_base_type;
3212 $outtva_tx = $objp->custtva_tx;
3213 $outdefault_vat_code = $objp->custdefault_vat_code;
3218 if (empty($hidepriceinlabel) && !$found) {
3219 if ($objp->price_base_type ==
'HT') {
3220 $opt .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"HT");
3221 $outval .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"HT");
3223 $opt .=
' - ' .
price($objp->price_ttc, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"TTC");
3224 $outval .=
' - ' .
price($objp->price_ttc, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3226 $outprice_ht =
price($objp->price);
3227 $outprice_ttc =
price($objp->price_ttc);
3228 $outpricebasetype = $objp->price_base_type;
3229 $outtva_tx = $objp->tva_tx;
3230 $outdefault_vat_code = $objp->default_vat_code;
3234 if (!empty($user->rights->stock->lire)) {
3235 $opt .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'));
3237 if ($objp->stock > 0) {
3238 $outval .=
' - <span class="product_line_stock_ok">';
3239 } elseif ($objp->stock <= 0) {
3240 $outval .=
' - <span class="product_line_stock_too_low">';
3242 $outval .= $langs->transnoentities(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'));
3243 $outval .=
'</span>';
3244 if (empty($novirtualstock) && !empty($conf->global->STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO)) {
3245 $langs->load(
"stocks");
3247 $tmpproduct =
new Product($this->db);
3248 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
3249 $tmpproduct->load_virtual_stock();
3250 $virtualstock = $tmpproduct->stock_theorique;
3252 $opt .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
3254 $outval .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
3255 if ($virtualstock > 0) {
3256 $outval .=
'<span class="product_line_stock_ok">';
3257 } elseif ($virtualstock <= 0) {
3258 $outval .=
'<span class="product_line_stock_too_low">';
3260 $outval .= $virtualstock;
3261 $outval .=
'</span>';
3268 $parameters = array(
'objp'=>$objp);
3269 $reshook = $hookmanager->executeHooks(
'constructProductListOption', $parameters);
3270 if (empty($reshook)) {
3271 $opt .= $hookmanager->resPrint;
3273 $opt = $hookmanager->resPrint;
3276 $opt .=
"</option>\n";
3281 'label2' => $outlabel,
3285 'price_ttc' =>
price2num($outprice_ttc),
3288 'pricebasetype' => $outpricebasetype,
3289 'tva_tx' => $outtva_tx,
3290 'default_vat_code' => $outdefault_vat_code,
3292 'discount' => $outdiscount,
3293 'duration_value' => $outdurationvalue,
3294 'duration_unit' => $outdurationunit,
3296 'labeltrans' => $outlabel_translated,
3297 'desctrans' => $outdesc_translated,
3298 'ref_customer' => $outrefcust
3319 public function select_produits_fournisseurs($socid, $selected =
'', $htmlname =
'productid', $filtertype =
'', $filtre =
'', $ajaxoptions = array(), $hidelabel = 0, $alsoproductwithnosupplierprice = 0, $morecss =
'', $placeholder =
'')
3322 global $langs, $conf;
3323 global $price_level, $status, $finished;
3325 if (!isset($status)) {
3329 $selected_input_value =
'';
3330 if (!empty($conf->use_javascript_ajax) && !empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) {
3331 if ($selected > 0) {
3332 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3333 $producttmpselect =
new Product($this->db);
3334 $producttmpselect->fetch($selected);
3335 $selected_input_value = $producttmpselect->ref;
3336 unset($producttmpselect);
3340 $urloption = ($socid > 0 ?
'socid=' . $socid .
'&' :
'') .
'htmlname=' . $htmlname .
'&outjson=1&price_level=' . $price_level .
'&type=' . $filtertype .
'&mode=2&status=' . $status .
'&finished=' . $finished .
'&alsoproductwithnosupplierprice=' . $alsoproductwithnosupplierprice;
3341 print
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT .
'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 0, $ajaxoptions);
3343 print ($hidelabel ?
'' : $langs->trans(
"RefOrLabel") .
' : ') .
'<input type="text" class="minwidth300" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . ($placeholder ?
' placeholder="' . $placeholder .
'"' :
'') .
'>';
3345 print $this->
select_produits_fournisseurs_list($socid, $selected, $htmlname, $filtertype, $filtre,
'', $status, 0, 0, $alsoproductwithnosupplierprice, $morecss, 0, $placeholder);
3369 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 =
'')
3372 global $langs, $conf, $user;
3373 global $hookmanager;
3376 $outarray = array();
3378 $maxlengtharticle = (empty($conf->global->PRODUCT_MAX_LENGTH_COMBO) ? 48 : $conf->global->PRODUCT_MAX_LENGTH_COMBO);
3380 $langs->load(
'stocks');
3383 $langs->load(
'other');
3386 $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,";
3387 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice,";
3388 $sql .=
" pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.default_vat_code, pfp.fk_soc, s.nom as name,";
3389 $sql .=
" pfp.supplier_reputation";
3391 if (!empty($conf->global->PRODUIT_FOURN_TEXTS)) {
3392 $sql .=
", pfp.desc_fourn as description";
3394 $sql .=
", p.description";
3398 $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";
3401 $sql .=
", pfp.barcode";
3403 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
3404 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN (" .
getEntity(
'product') .
") )";
3406 $sql .=
" AND pfp.fk_soc = " . ((int) $socid);
3408 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
3411 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
3413 $sql .=
" WHERE p.entity IN (" .
getEntity(
'product') .
")";
3414 if ($statut != -1) {
3415 $sql .=
" AND p.tobuy = " . ((int) $statut);
3417 if (strval($filtertype) !=
'') {
3418 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
3420 if (!empty($filtre)) {
3421 $sql .=
" " . $filtre;
3424 $parameters = array();
3425 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListWhere', $parameters);
3426 $sql .= $hookmanager->resPrint;
3428 if ($filterkey !=
'') {
3430 $prefix = empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE) ?
'%' :
'';
3432 $scrit = explode(
' ', $filterkey);
3434 if (count($scrit) > 1) {
3437 foreach ($scrit as $crit) {
3441 $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) .
"%'";
3442 if (!empty($conf->global->PRODUIT_FOURN_TEXTS)) {
3443 $sql .=
" OR pfp.desc_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3448 if (count($scrit) > 1) {
3452 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3453 $sql .=
" OR pfp.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3457 $sql .=
" ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC";
3458 $sql .= $this->db->plimit($limit, 0);
3462 dol_syslog(get_class($this) .
"::select_produits_fournisseurs_list", LOG_DEBUG);
3463 $result = $this->db->query(
$sql);
3465 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3466 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
3468 $num = $this->db->num_rows($result);
3471 $out .=
'<select class="flat ' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'">';
3473 $out .=
'<option value="-1" selected>' . ($placeholder ? $placeholder :
' ') .
'</option>';
3475 $out .=
'<option value="-1">' . ($placeholder ? $placeholder :
' ') .
'</option>';
3480 $objp = $this->db->fetch_object($result);
3482 if (is_null($objp->idprodfournprice)) {
3484 $objp->tva_tx = $objp->tva_tx_sale;
3485 $objp->default_vat_code = $objp->default_vat_code_sale;
3488 $outkey = $objp->idprodfournprice;
3489 if (!$outkey && $alsoproductwithnosupplierprice) {
3490 $outkey =
'idprod_' . $objp->rowid;
3493 $outref = $objp->ref;
3494 $outbarcode = $objp->barcode;
3497 $outtype = $objp->fk_product_type;
3504 if (!empty($objp->unit_short)) {
3505 $outvalUnits .=
' - ' . $objp->unit_short;
3507 if (!empty($objp->weight) && $objp->weight_units !==
null) {
3509 $outvalUnits .=
' - ' . $unitToShow;
3511 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
3512 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
3513 $outvalUnits .=
' - ' . $unitToShow;
3515 if (!empty($objp->surface) && $objp->surface_units !==
null) {
3517 $outvalUnits .=
' - ' . $unitToShow;
3519 if (!empty($objp->volume) && $objp->volume_units !==
null) {
3521 $outvalUnits .=
' - ' . $unitToShow;
3523 if ($outdurationvalue && $outdurationunit) {
3525 'h' => $langs->trans(
'Hour'),
3526 'd' => $langs->trans(
'Day'),
3527 'w' => $langs->trans(
'Week'),
3528 'm' => $langs->trans(
'Month'),
3529 'y' => $langs->trans(
'Year')
3531 if (isset($da[$outdurationunit])) {
3532 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
3537 $objRef = $objp->ref;
3538 if ($filterkey && $filterkey !=
'') {
3539 $objRef = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRef, 1);
3541 $objRefFourn = $objp->ref_fourn;
3542 if ($filterkey && $filterkey !=
'') {
3543 $objRefFourn = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRefFourn, 1);
3545 $label = $objp->label;
3546 if ($filterkey && $filterkey !=
'') {
3547 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
3550 switch ($objp->fk_product_type) {
3562 if (empty($picto)) {
3565 $optlabel =
img_object(
'', $picto,
'class="paddingright classfortooltip"', 0, 0, 1);
3568 $optlabel .= $objp->ref;
3569 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
3570 $optlabel .=
' <span class="opacitymedium">(' . $objp->ref_fourn .
')</span>';
3572 if (
isModEnabled(
'barcode') && !empty($objp->barcode)) {
3573 $optlabel .=
' (' . $outbarcode .
')';
3575 $optlabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3577 $outvallabel = $objRef;
3578 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
3579 $outvallabel .=
' (' . $objRefFourn .
')';
3581 if (
isModEnabled(
'barcode') && !empty($objp->barcode)) {
3582 $outvallabel .=
' (' . $outbarcode .
')';
3584 $outvallabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3587 $optlabel .= $outvalUnits;
3588 $outvallabel .= $outvalUnits;
3590 if (!empty($objp->idprodfournprice)) {
3591 $outqty = $objp->quantity;
3592 $outdiscount = $objp->remise_percent;
3593 if (
isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
3595 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
3596 $prod_supplier->id = $objp->fk_product;
3597 $prod_supplier->fourn_qty = $objp->quantity;
3598 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
3599 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
3601 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3603 $price_result = $priceparser->parseProductSupplier($prod_supplier);
3604 if ($price_result >= 0) {
3605 $objp->fprice = $price_result;
3606 if ($objp->quantity >= 1) {
3607 $objp->unitprice = $objp->fprice / $objp->quantity;
3611 if ($objp->quantity == 1) {
3612 $optlabel .=
' - ' .
price($objp->fprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency) .
"/";
3613 $outvallabel .=
' - ' .
price($objp->fprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1, $conf->currency) .
"/";
3614 $optlabel .= $langs->trans(
"Unit");
3615 $outvallabel .= $langs->transnoentities(
"Unit");
3617 $optlabel .=
' - ' .
price($objp->fprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency) .
"/" . $objp->quantity;
3618 $outvallabel .=
' - ' .
price($objp->fprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1, $conf->currency) .
"/" . $objp->quantity;
3619 $optlabel .=
' ' . $langs->trans(
"Units");
3620 $outvallabel .=
' ' . $langs->transnoentities(
"Units");
3623 if ($objp->quantity > 1) {
3624 $optlabel .=
" (" .
price($objp->unitprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency) .
"/" . $langs->trans(
"Unit") .
")";
3625 $outvallabel .=
" (" .
price($objp->unitprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1, $conf->currency) .
"/" . $langs->transnoentities(
"Unit") .
")";
3627 if ($objp->remise_percent >= 1) {
3628 $optlabel .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3629 $outvallabel .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3631 if ($objp->duration) {
3632 $optlabel .=
" - " . $objp->duration;
3633 $outvallabel .=
" - " . $objp->duration;
3636 $optlabel .=
" - " .
dol_trunc($objp->name, 8);
3637 $outvallabel .=
" - " .
dol_trunc($objp->name, 8);
3639 if ($objp->supplier_reputation) {
3641 $reputations = array(
'' => $langs->trans(
'Standard'),
'FAVORITE' => $langs->trans(
'Favorite'),
'NOTTHGOOD' => $langs->trans(
'NotTheGoodQualitySupplier'),
'DONOTORDER' => $langs->trans(
'DoNotOrderThisProductToThisSupplier'));
3643 $optlabel .=
" - " . $reputations[$objp->supplier_reputation];
3644 $outvallabel .=
" - " . $reputations[$objp->supplier_reputation];
3647 if (empty($alsoproductwithnosupplierprice)) {
3648 $optlabel .=
" - <span class='opacitymedium'>" . $langs->trans(
"NoPriceDefinedForThisSupplier") .
'</span>';
3649 $outvallabel .=
' - ' . $langs->transnoentities(
"NoPriceDefinedForThisSupplier");
3652 $optlabel .=
" - <span class='opacitymedium'>" . $langs->trans(
"NoPriceDefinedForThisSupplier") .
'</span>';
3653 $outvallabel .=
' - ' . $langs->transnoentities(
"NoPriceDefinedForThisSupplier");
3657 if (
isModEnabled(
'stock') && $showstockinlist && isset($objp->stock) && ($objp->fk_product_type ==
Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES))) {
3658 $novirtualstock = ($showstockinlist == 2);
3660 if (!empty($user->rights->stock->lire)) {
3661 $outvallabel .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'));
3663 if ($objp->stock > 0) {
3664 $optlabel .=
' - <span class="product_line_stock_ok">';
3665 } elseif ($objp->stock <= 0) {
3666 $optlabel .=
' - <span class="product_line_stock_too_low">';
3668 $optlabel .= $langs->transnoentities(
"Stock") .
':' .
price(
price2num($objp->stock,
'MS'));
3669 $optlabel .=
'</span>';
3670 if (empty($novirtualstock) && !empty($conf->global->STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO)) {
3671 $langs->load(
"stocks");
3673 $tmpproduct =
new Product($this->db);
3674 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
3675 $tmpproduct->load_virtual_stock();
3676 $virtualstock = $tmpproduct->stock_theorique;
3678 $outvallabel .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
3680 $optlabel .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
3681 if ($virtualstock > 0) {
3682 $optlabel .=
'<span class="product_line_stock_ok">';
3683 } elseif ($virtualstock <= 0) {
3684 $optlabel .=
'<span class="product_line_stock_too_low">';
3686 $optlabel .= $virtualstock;
3687 $optlabel .=
'</span>';
3694 $optstart =
'<option value="' . $outkey .
'"';
3695 if ($selected && $selected == $objp->idprodfournprice) {
3696 $optstart .=
' selected';
3698 if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) {
3699 $optstart .=
' disabled';
3702 if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) {
3711 $optstart .=
' data-default-vat-code="' .
dol_escape_htmltag($objp->default_vat_code) .
'"';
3713 $optstart .=
' data-description="' .
dol_escape_htmltag($objp->description, 0, 1) .
'"';
3715 $outarrayentry = array(
3718 'label' => $outvallabel,
3720 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
3721 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
3722 'price_ht' =>
price2num($objp->unitprice,
'MU'),
3723 'tva_tx_formated' =>
price($objp->tva_tx, 0, $langs, 1, -1, 2),
3725 'default_vat_code' => $objp->default_vat_code,
3726 'discount' => $outdiscount,
3728 'duration_value' => $outdurationvalue,
3729 'duration_unit' => $outdurationunit,
3730 'disabled' => (empty($objp->idprodfournprice) ?
true :
false),
3731 'description' => $objp->description
3734 $parameters = array(
3736 'optstart' => &$optstart,
3737 'optlabel' => &$optlabel,
3738 'outvallabel' => &$outvallabel,
3739 'outarrayentry' => &$outarrayentry
3741 $reshook = $hookmanager->executeHooks(
'selectProduitsFournisseurListOption', $parameters, $this);
3747 $out .= $optstart .
' data-html="' .
dol_escape_htmltag($optlabel) .
'">' . $optlabel .
"</option>\n";
3750 array(
'key' => $outkey,
3752 'label' => $outvallabel,
3754 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
3755 'price_qty_ht_locale' =>
price($objp->fprice),
3756 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
3757 'price_unit_ht_locale' =>
price($objp->unitprice),
3758 'price_ht' =>
price2num($objp->unitprice,
'MU'),
3759 'tva_tx_formated' =>
price($objp->tva_tx),
3761 'default_vat_code' => $objp->default_vat_code,
3762 'discount' => $outdiscount,
3764 'duration_value' => $outdurationvalue,
3765 'duration_unit' => $outdurationunit,
3766 'disabled' => (empty($objp->idprodfournprice) ?
true :
false),
3767 'description' => $objp->description
3781 $out .=
'</select>';
3783 $this->db->free($result);
3785 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3791 if (empty($outputmode)) {
3810 global $langs, $conf;
3812 $langs->load(
'stocks');
3814 $sql =
"SELECT p.rowid, p.ref, p.label, p.price, p.duration, pfp.fk_soc,";
3815 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.remise_percent, pfp.quantity, pfp.unitprice,";
3816 $sql .=
" pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name";
3817 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
3818 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
3819 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
3820 $sql .=
" WHERE pfp.entity IN (" .
getEntity(
'productsupplierprice') .
")";
3821 $sql .=
" AND p.tobuy = 1";
3822 $sql .=
" AND s.fournisseur = 1";
3823 $sql .=
" AND p.rowid = " . ((int) $productid);
3824 if (empty($conf->global->PRODUCT_BEST_SUPPLIER_PRICE_PRESELECTED)) {
3825 $sql .=
" ORDER BY s.nom, pfp.ref_fourn DESC";
3827 $sql .=
" ORDER BY pfp.unitprice ASC";
3830 dol_syslog(get_class($this) .
"::select_product_fourn_price", LOG_DEBUG);
3831 $result = $this->db->query(
$sql);
3834 $num = $this->db->num_rows($result);
3836 $form =
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
3839 $form .=
'<option value="0">-- ' . $langs->trans(
"NoSupplierPriceDefinedForThisProduct") .
' --</option>';
3841 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3842 $form .=
'<option value="0"> </option>';
3846 $objp = $this->db->fetch_object($result);
3848 $opt =
'<option value="' . $objp->idprodfournprice .
'"';
3850 if ($num == 1 || ($selected_supplier > 0 && $objp->fk_soc == $selected_supplier) || ($i == 0 && !empty($conf->global->PRODUCT_BEST_SUPPLIER_PRICE_PRESELECTED))) {
3851 $opt .=
' selected';
3853 $opt .=
'>' . $objp->name .
' - ' . $objp->ref_fourn .
' - ';
3855 if (
isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
3857 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
3858 $prod_supplier->id = $productid;
3859 $prod_supplier->fourn_qty = $objp->quantity;
3860 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
3861 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
3863 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3865 $price_result = $priceparser->parseProductSupplier($prod_supplier);
3866 if ($price_result >= 0) {
3867 $objp->fprice = $price_result;
3868 if ($objp->quantity >= 1) {
3869 $objp->unitprice = $objp->fprice / $objp->quantity;
3873 if ($objp->quantity == 1) {
3874 $opt .=
price($objp->fprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency) .
"/";
3877 $opt .= $objp->quantity .
' ';
3879 if ($objp->quantity == 1) {
3880 $opt .= $langs->trans(
"Unit");
3882 $opt .= $langs->trans(
"Units");
3884 if ($objp->quantity > 1) {
3886 $opt .=
price($objp->unitprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency) .
"/" . $langs->trans(
"Unit");
3888 if ($objp->duration) {
3889 $opt .=
" - " . $objp->duration;
3891 $opt .=
"</option>\n";
3898 $form .=
'</select>';
3899 $this->db->free($result);
3918 public function select_address($selected, $socid, $htmlname =
'address_id', $showempty = 0)
3922 $sql =
"SELECT a.rowid, a.label";
3923 $sql .=
" FROM " . $this->db->prefix() .
"societe_address as a";
3924 $sql .=
" WHERE a.fk_soc = " . ((int) $socid);
3925 $sql .=
" ORDER BY a.label ASC";
3927 dol_syslog(get_class($this) .
"::select_address", LOG_DEBUG);
3928 $resql = $this->db->query(
$sql);
3930 print
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
3932 print
'<option value="0"> </option>';
3934 $num = $this->db->num_rows($resql);
3938 $obj = $this->db->fetch_object($resql);
3940 if ($selected && $selected == $obj->rowid) {
3941 print
'<option value="' . $obj->rowid .
'" selected>' . $obj->label .
'</option>';
3943 print
'<option value="' . $obj->rowid .
'">' . $obj->label .
'</option>';
3968 $num = count($this->cache_conditions_paiements);
3975 $sql =
"SELECT rowid, code, libelle as label, deposit_percent";
3976 $sql .=
" FROM " . $this->db->prefix() .
'c_payment_term';
3977 $sql .=
" WHERE entity IN (" .
getEntity(
'c_payment_term') .
")";
3978 $sql .=
" AND active > 0";
3979 $sql .=
" ORDER BY sortorder";
3981 $resql = $this->db->query(
$sql);
3983 $num = $this->db->num_rows($resql);
3986 $obj = $this->db->fetch_object($resql);
3989 $label = ($langs->trans(
"PaymentConditionShort" . $obj->code) != (
"PaymentConditionShort" . $obj->code) ? $langs->trans(
"PaymentConditionShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
3990 $this->cache_conditions_paiements[$obj->rowid][
'code'] = $obj->code;
3991 $this->cache_conditions_paiements[$obj->rowid][
'label'] = $label;
3992 $this->cache_conditions_paiements[$obj->rowid][
'deposit_percent'] = $obj->deposit_percent;
4017 $num = count($this->cache_availability);
4024 $langs->load(
'propal');
4026 $sql =
"SELECT rowid, code, label, position";
4027 $sql .=
" FROM " . $this->db->prefix() .
'c_availability';
4028 $sql .=
" WHERE active > 0";
4030 $resql = $this->db->query(
$sql);
4032 $num = $this->db->num_rows($resql);
4035 $obj = $this->db->fetch_object($resql);
4038 $label = ($langs->trans(
"AvailabilityType" . $obj->code) != (
"AvailabilityType" . $obj->code) ? $langs->trans(
"AvailabilityType" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4039 $this->cache_availability[$obj->rowid][
'code'] = $obj->code;
4040 $this->cache_availability[$obj->rowid][
'label'] = $label;
4041 $this->cache_availability[$obj->rowid][
'position'] = $obj->position;
4045 $this->cache_availability =
dol_sort_array($this->cache_availability,
'position',
'asc', 0, 0, 1);
4066 global $langs, $user;
4070 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
4072 print
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4074 print
'<option value="0"> </option>';
4076 foreach ($this->cache_availability as $id => $arrayavailability) {
4077 if ($selected == $id) {
4078 print
'<option value="' . $id .
'" selected>';
4080 print
'<option value="' . $id .
'">';
4087 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4101 $num = count($this->cache_demand_reason);
4106 $sql =
"SELECT rowid, code, label";
4107 $sql .=
" FROM " . $this->db->prefix() .
'c_input_reason';
4108 $sql .=
" WHERE active > 0";
4110 $resql = $this->db->query(
$sql);
4112 $num = $this->db->num_rows($resql);
4114 $tmparray = array();
4116 $obj = $this->db->fetch_object($resql);
4119 $label = ($obj->label !=
'-' ? $obj->label :
'');
4120 if ($langs->trans(
"DemandReasonType" . $obj->code) != (
"DemandReasonType" . $obj->code)) {
4121 $label = $langs->trans(
"DemandReasonType" . $obj->code);
4123 if ($langs->trans($obj->code) != $obj->code) {
4124 $label = $langs->trans($obj->code);
4127 $tmparray[$obj->rowid][
'id'] = $obj->rowid;
4128 $tmparray[$obj->rowid][
'code'] = $obj->code;
4129 $tmparray[$obj->rowid][
'label'] = $label;
4133 $this->cache_demand_reason =
dol_sort_array($tmparray,
'label',
'asc', 0, 0, 1);
4155 public function selectInputReason($selected =
'', $htmlname =
'demandreasonid', $exclude =
'', $addempty = 0, $morecss =
'', $notooltip = 0)
4157 global $langs, $user;
4161 print
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
4163 print
'<option value="0"' . (empty($selected) ?
' selected' :
'') .
'> </option>';
4165 foreach ($this->cache_demand_reason as $id => $arraydemandreason) {
4166 if ($arraydemandreason[
'code'] == $exclude) {
4170 if ($selected && ($selected == $arraydemandreason[
'id'] || $selected == $arraydemandreason[
'code'])) {
4171 print
'<option value="' . $arraydemandreason[
'id'] .
'" selected>';
4173 print
'<option value="' . $arraydemandreason[
'id'] .
'">';
4175 $label = $arraydemandreason[
'label'];
4176 print $langs->trans($label);
4180 if ($user->admin && empty($notooltip)) {
4181 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4198 $num = count($this->cache_types_paiements);
4205 $this->cache_types_paiements = array();
4207 $sql =
"SELECT id, code, libelle as label, type, active";
4208 $sql .=
" FROM " . $this->db->prefix() .
"c_paiement";
4209 $sql .=
" WHERE entity IN (" .
getEntity(
'c_paiement') .
")";
4211 $resql = $this->db->query(
$sql);
4213 $num = $this->db->num_rows($resql);
4216 $obj = $this->db->fetch_object($resql);
4219 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) != (
"PaymentTypeShort" . $obj->code) ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4220 $this->cache_types_paiements[$obj->id][
'id'] = $obj->id;
4221 $this->cache_types_paiements[$obj->id][
'code'] = $obj->code;
4222 $this->cache_types_paiements[$obj->id][
'label'] = $label;
4223 $this->cache_types_paiements[$obj->id][
'type'] = $obj->type;
4224 $this->cache_types_paiements[$obj->id][
'active'] = $obj->active;
4228 $this->cache_types_paiements =
dol_sort_array($this->cache_types_paiements,
'label',
'asc', 0, 0, 1);
4257 public function select_conditions_paiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1)
4280 public function getSelectConditionsPaiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1)
4282 global $langs, $user, $conf;
4285 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
4290 if (empty($selected) && !empty($conf->global->MAIN_DEFAULT_PAYMENT_TERM_ID)) {
4291 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TERM_ID", LOG_NOTICE);
4292 $selected = $conf->global->MAIN_DEFAULT_PAYMENT_TERM_ID;
4295 $out .=
'<select id="' . $htmlname .
'" class="flat selectpaymentterms' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4297 $out .=
'<option value="0"> </option>';
4300 $selectedDepositPercent =
null;
4302 foreach ($this->cache_conditions_paiements as $id => $arrayconditions) {
4303 if ($filtertype <= 0 && !empty($arrayconditions[
'deposit_percent'])) {
4307 if ($selected == $id) {
4308 $selectedDepositPercent = $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'];
4309 $out .=
'<option value="' . $id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'" selected>';
4311 $out .=
'<option value="' . $id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'">';
4313 $label = $arrayconditions[
'label'];
4315 if (!empty($arrayconditions[
'deposit_percent'])) {
4316 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'], $label);
4320 $out .=
'</option>';
4322 $out .=
'</select>';
4323 if ($user->admin && empty($noinfoadmin)) {
4324 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4328 if ($deposit_percent >= 0) {
4329 $out .=
' <span id="' . $htmlname .
'_deposit_percent_container"' . (empty($selectedDepositPercent) ?
' style="display: none"' :
'') .
'>';
4330 $out .= $langs->trans(
'DepositPercent') .
' : ';
4331 $out .=
'<input id="' . $htmlname .
'_deposit_percent" name="' . $htmlname .
'_deposit_percent" class="maxwidth50" value="' . $deposit_percent .
'" />';
4334 <script nonce="' .
getNonce() .
'">
4335 $(document).ready(function () {
4336 $("#' . $htmlname .
'").change(function () {
4337 let $selected = $(this).find("option:selected");
4338 let depositPercent = $selected.attr("data-deposit_percent");
4340 if (depositPercent.length > 0) {
4341 $("#' . $htmlname .
'_deposit_percent_container").show().find("#' . $htmlname .
'_deposit_percent").val(depositPercent);
4343 $("#' . $htmlname .
'_deposit_percent_container").hide();
4374 public function select_types_paiements($selected =
'', $htmlname =
'paiementtype', $filtertype =
'', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'', $nooutput = 0)
4377 global $langs, $user, $conf;
4381 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $filtertype .
", " . $format, LOG_DEBUG);
4383 $filterarray = array();
4384 if ($filtertype ==
'CRDT') {
4385 $filterarray = array(0, 2, 3);
4386 } elseif ($filtertype ==
'DBIT') {
4387 $filterarray = array(1, 2, 3);
4388 } elseif ($filtertype !=
'' && $filtertype !=
'-1') {
4389 $filterarray = explode(
',', $filtertype);
4395 if (empty($selected) && !empty($conf->global->MAIN_DEFAULT_PAYMENT_TYPE_ID)) {
4396 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TYPE_ID", LOG_NOTICE);
4397 $selected = $conf->global->MAIN_DEFAULT_PAYMENT_TYPE_ID;
4400 $out .=
'<select id="select' . $htmlname .
'" class="flat selectpaymenttypes' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4402 $out .=
'<option value=""> </option>';
4404 foreach ($this->cache_types_paiements as $id => $arraytypes) {
4406 if ($active >= 0 && $arraytypes[
'active'] != $active) {
4411 if (count($filterarray) && !in_array($arraytypes[
'type'], $filterarray)) {
4416 if ($empty && empty($arraytypes[
'code'])) {
4421 $out .=
'<option value="' . $id .
'"';
4422 } elseif ($format == 1) {
4423 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
4424 } elseif ($format == 2) {
4425 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
4426 } elseif ($format == 3) {
4427 $out .=
'<option value="' . $id .
'"';
4430 if ($format == 1 || $format == 2) {
4431 if ($selected == $arraytypes[
'code']) {
4432 $out .=
' selected';
4435 if ($selected == $id) {
4436 $out .=
' selected';
4442 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4443 } elseif ($format == 1) {
4444 $value = $arraytypes[
'code'];
4445 } elseif ($format == 2) {
4446 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4447 } elseif ($format == 3) {
4448 $value = $arraytypes[
'code'];
4450 $out .= $value ? $value :
' ';
4451 $out .=
'</option>';
4453 $out .=
'</select>';
4454 if ($user->admin && !$noadmininfo) {
4455 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4459 if (empty($nooutput)) {
4479 $return =
'<select class="flat maxwidth100" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
4481 'HT' => $langs->trans(
"HT"),
4482 'TTC' => $langs->trans(
"TTC")
4484 foreach ($options as $id => $value) {
4485 if ($selected == $id) {
4486 $return .=
'<option value="' . $id .
'" selected>' . $value;
4488 $return .=
'<option value="' . $id .
'">' . $value;
4490 $return .=
'</option>';
4492 $return .=
'</select>';
4512 $num = count($this->cache_transport_mode);
4519 $this->cache_transport_mode = array();
4521 $sql =
"SELECT rowid, code, label, active";
4522 $sql .=
" FROM " . $this->db->prefix() .
"c_transport_mode";
4523 $sql .=
" WHERE entity IN (" .
getEntity(
'c_transport_mode') .
")";
4525 $resql = $this->db->query(
$sql);
4527 $num = $this->db->num_rows($resql);
4530 $obj = $this->db->fetch_object($resql);
4533 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) != (
"PaymentTypeShort" . $obj->code) ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4534 $this->cache_transport_mode[$obj->rowid][
'rowid'] = $obj->rowid;
4535 $this->cache_transport_mode[$obj->rowid][
'code'] = $obj->code;
4536 $this->cache_transport_mode[$obj->rowid][
'label'] = $label;
4537 $this->cache_transport_mode[$obj->rowid][
'active'] = $obj->active;
4541 $this->cache_transport_mode =
dol_sort_array($this->cache_transport_mode,
'label',
'asc', 0, 0, 1);
4563 public function selectTransportMode($selected =
'', $htmlname =
'transportmode', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'')
4565 global $langs, $user;
4567 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $format, LOG_DEBUG);
4571 print
'<select id="select' . $htmlname .
'" class="flat selectmodetransport' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4573 print
'<option value=""> </option>';
4575 foreach ($this->cache_transport_mode as $id => $arraytypes) {
4577 if ($active >= 0 && $arraytypes[
'active'] != $active) {
4582 if ($empty && empty($arraytypes[
'code'])) {
4587 print
'<option value="' . $id .
'"';
4588 } elseif ($format == 1) {
4589 print
'<option value="' . $arraytypes[
'code'] .
'"';
4590 } elseif ($format == 2) {
4591 print
'<option value="' . $arraytypes[
'code'] .
'"';
4592 } elseif ($format == 3) {
4593 print
'<option value="' . $id .
'"';
4596 if (preg_match(
'/[a-z]/i', $selected) && $selected == $arraytypes[
'code']) {
4598 } elseif ($selected == $id) {
4604 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4605 } elseif ($format == 1) {
4606 $value = $arraytypes[
'code'];
4607 } elseif ($format == 2) {
4608 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4609 } elseif ($format == 3) {
4610 $value = $arraytypes[
'code'];
4612 print $value ? $value :
' ';
4616 if ($user->admin && !$noadmininfo) {
4617 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4633 public function selectShippingMethod($selected =
'', $htmlname =
'shipping_method_id', $filtre =
'', $useempty = 0, $moreattrib =
'', $noinfoadmin = 0, $morecss =
'')
4635 global $langs, $conf, $user;
4637 $langs->load(
"admin");
4638 $langs->load(
"deliveries");
4640 $sql =
"SELECT rowid, code, libelle as label";
4641 $sql .=
" FROM " . $this->db->prefix() .
"c_shipment_mode";
4642 $sql .=
" WHERE active > 0";
4644 $sql .=
" AND " . $filtre;
4646 $sql .=
" ORDER BY libelle ASC";
4648 dol_syslog(get_class($this) .
"::selectShippingMode", LOG_DEBUG);
4649 $result = $this->db->query(
$sql);
4651 $num = $this->db->num_rows($result);
4654 print
'<select id="select' . $htmlname .
'" class="flat selectshippingmethod' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
4655 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
4656 print
'<option value="-1"> </option>';
4659 $obj = $this->db->fetch_object($result);
4660 if ($selected == $obj->rowid) {
4661 print
'<option value="' . $obj->rowid .
'" selected>';
4663 print
'<option value="' . $obj->rowid .
'">';
4665 print ($langs->trans(
"SendingMethod" . strtoupper($obj->code)) !=
"SendingMethod" . strtoupper($obj->code)) ? $langs->trans(
"SendingMethod" . strtoupper($obj->code)) : $obj->label;
4670 if ($user->admin && empty($noinfoadmin)) {
4671 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4676 print $langs->trans(
"NoShippingMethodDefined");
4696 $langs->load(
"deliveries");
4698 if ($htmlname !=
"none") {
4699 print
'<form method="POST" action="' . $page .
'">';
4700 print
'<input type="hidden" name="action" value="setshippingmethod">';
4701 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
4703 print
'<input type="submit" class="button valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
4707 $code = $langs->getLabelFromKey($this->db, $selected,
'c_shipment_mode',
'rowid',
'code');
4708 print $langs->trans(
"SendingMethod" . strtoupper($code));
4727 $langs->load(
'bills');
4729 $opt =
'<option value="" selected></option>';
4730 $sql =
"SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc";
4731 $sql .=
' FROM ' . $this->db->prefix() .
'facture';
4733 $sql .=
' AND situation_counter >= 1';
4734 $sql .=
' AND fk_soc = ' . (int) $socid;
4735 $sql .=
' AND type <> 2';
4736 $sql .=
' ORDER by situation_cycle_ref, situation_counter desc';
4737 $resql = $this->db->query(
$sql);
4739 if ($resql && $this->db->num_rows($resql) > 0) {
4742 while ($obj = $this->db->fetch_object($resql)) {
4744 if ($obj->situation_cycle_ref != $ref) {
4746 $ref = $obj->situation_cycle_ref;
4748 if ($obj->situation_final != 1) {
4750 if (substr($obj->ref, 1, 4) !=
'PROV') {
4751 if ($selected == $obj->rowid) {
4752 $opt .=
'<option value="' . $obj->rowid .
'" selected>' . $obj->ref .
'</option>';
4754 $opt .=
'<option value="' . $obj->rowid .
'">' . $obj->ref .
'</option>';
4761 dol_syslog(
"Error sql=" .
$sql .
", error=" . $this->error, LOG_ERR);
4763 if ($opt ==
'<option value ="" selected></option>') {
4764 $opt =
'<option value ="0" selected>' . $langs->trans(
'NoSituations') .
'</option>';
4778 public function selectUnits($selected =
'', $htmlname =
'units', $showempty = 0, $unit_type =
'')
4782 $langs->load(
'products');
4784 $return =
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'">';
4786 $sql =
"SELECT rowid, label, code FROM " . $this->db->prefix() .
"c_units";
4787 $sql .=
' WHERE active > 0';
4788 if (!empty($unit_type)) {
4789 $sql .=
" AND unit_type = '" . $this->db->escape($unit_type) .
"'";
4791 $sql .=
" ORDER BY sortorder";
4793 $resql = $this->db->query(
$sql);
4794 if ($resql && $this->db->num_rows($resql) > 0) {
4796 $return .=
'<option value="none"></option>';
4799 while ($res = $this->db->fetch_object($resql)) {
4800 $unitLabel = $res->label;
4801 if (!empty($langs->tab_translate[
'unit' . $res->code])) {
4802 $unitLabel = $langs->trans(
'unit' . $res->code) != $res->label ? $langs->trans(
'unit' . $res->code) : $res->label;
4805 if ($selected == $res->rowid) {
4806 $return .=
'<option value="' . $res->rowid .
'" selected>' . $unitLabel .
'</option>';
4808 $return .=
'<option value="' . $res->rowid .
'">' . $unitLabel .
'</option>';
4811 $return .=
'</select>';
4832 public function select_comptes($selected =
'', $htmlname =
'accountid', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'', $showcurrency = 0, $morecss =
'', $nooutput = 0)
4835 global $langs, $conf;
4839 $langs->load(
"admin");
4842 $sql =
"SELECT rowid, label, bank, clos as status, currency_code";
4843 $sql .=
" FROM " . $this->db->prefix() .
"bank_account";
4844 $sql .=
" WHERE entity IN (" .
getEntity(
'bank_account') .
")";
4846 $sql .=
" AND clos = " . (int) $status;
4849 $sql .=
" AND " . $filtre;
4851 $sql .=
" ORDER BY label";
4853 dol_syslog(get_class($this) .
"::select_comptes", LOG_DEBUG);
4854 $result = $this->db->query(
$sql);
4856 $num = $this->db->num_rows($result);
4859 $out .=
'<select id="select' . $htmlname .
'" class="flat selectbankaccount' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
4860 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
4861 $out .=
'<option value="-1"> </option>';
4865 $obj = $this->db->fetch_object($result);
4866 if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
4867 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'" selected>';
4869 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'">';
4871 $out .= trim($obj->label);
4872 if ($showcurrency) {
4873 $out .=
' (' . $obj->currency_code .
')';
4875 if ($status == 2 && $obj->status == 1) {
4876 $out .=
' (' . $langs->trans(
"Closed") .
')';
4878 $out .=
'</option>';
4881 $out .=
"</select>";
4885 $out .=
'<span class="opacitymedium">' . $langs->trans(
"NoActiveBankAccountDefined") .
'</span>';
4887 $out .=
'<span class="opacitymedium">' . $langs->trans(
"NoBankAccountFound") .
'</span>';
4895 if (empty($nooutput)) {
4915 public function selectEstablishments($selected =
'', $htmlname =
'entity', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'')
4917 global $langs, $conf;
4919 $langs->load(
"admin");
4922 $sql =
"SELECT rowid, name, fk_country, status, entity";
4923 $sql .=
" FROM " . $this->db->prefix() .
"establishment";
4924 $sql .=
" WHERE 1=1";
4926 $sql .=
" AND status = " . (int) $status;
4929 $sql .=
" AND " . $filtre;
4931 $sql .=
" ORDER BY name";
4933 dol_syslog(get_class($this) .
"::select_establishment", LOG_DEBUG);
4934 $result = $this->db->query(
$sql);
4936 $num = $this->db->num_rows($result);
4939 print
'<select id="select' . $htmlname .
'" class="flat selectestablishment" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
4940 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
4941 print
'<option value="-1"> </option>';
4945 $obj = $this->db->fetch_object($result);
4946 if ($selected == $obj->rowid) {
4947 print
'<option value="' . $obj->rowid .
'" selected>';
4949 print
'<option value="' . $obj->rowid .
'">';
4951 print trim($obj->name);
4952 if ($status == 2 && $obj->status == 1) {
4953 print
' (' . $langs->trans(
"Closed") .
')';
4961 print
'<span class="opacitymedium">' . $langs->trans(
"NoActiveEstablishmentDefined") .
'</span>';
4963 print
'<span class="opacitymedium">' . $langs->trans(
"NoEstablishmentFound") .
'</span>';
4986 if ($htmlname !=
"none") {
4987 print
'<form method="POST" action="' . $page .
'">';
4988 print
'<input type="hidden" name="action" value="setbankaccount">';
4989 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
4990 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
4991 $nbaccountfound = $this->
select_comptes($selected, $htmlname, 0,
'', $addempty);
4992 if ($nbaccountfound > 0) {
4993 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
4997 $langs->load(
'banks');
5000 require_once DOL_DOCUMENT_ROOT .
'/compta/bank/class/account.class.php';
5001 $bankstatic =
new Account($this->db);
5002 $result = $bankstatic->fetch($selected);
5004 print $bankstatic->getNomUrl(1);
5032 public function select_all_categories($type, $selected =
'', $htmlname =
"parent", $maxlength = 64, $markafterid = 0, $outputmode = 0, $include = 0, $morecss =
'')
5035 global $conf, $langs;
5036 $langs->load(
"categories");
5038 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
5041 if (is_numeric($type)) {
5042 dol_syslog(__METHOD__ .
': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING);
5045 if ($type === Categorie::TYPE_BANK_LINE) {
5047 $cate_arbo = array();
5048 $sql =
"SELECT c.label, c.rowid";
5049 $sql .=
" FROM " . $this->db->prefix() .
"bank_categ as c";
5050 $sql .=
" WHERE entity = " . $conf->entity;
5051 $sql .=
" ORDER BY c.label";
5052 $result = $this->db->query(
$sql);
5054 $num = $this->db->num_rows($result);
5057 $objp = $this->db->fetch_object($result);
5059 $cate_arbo[$objp->rowid] = array(
'id' => $objp->rowid,
'fulllabel' => $objp->label,
'color' =>
'',
'picto' =>
'category');
5063 $this->db->free($result);
5069 $cate_arbo = $cat->get_full_arbo($type, $markafterid, $include);
5072 $outarray = array();
5074 $output =
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
5075 if (is_array($cate_arbo)) {
5076 if (!count($cate_arbo)) {
5077 $output .=
'<option value="-1" disabled>' . $langs->trans(
"NoCategoriesDefined") .
'</option>';
5079 $output .=
'<option value="-1"> </option>';
5080 foreach ($cate_arbo as $key => $value) {
5081 if ($cate_arbo[$key][
'id'] == $selected || ($selected ===
'auto' && count($cate_arbo) == 1)) {
5086 $output .=
'<option ' . $add .
'value="' . $cate_arbo[$key][
'id'] .
'"';
5087 $output .=
' data-html="' .
dol_escape_htmltag(
img_picto(
'',
'category',
'class="pictofixedwidth" style="color: #' . $cate_arbo[$key][
'color'] .
'"') .
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle')) .
'"';
5089 $output .=
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle');
5090 $output .=
'</option>';
5092 $outarray[$cate_arbo[$key][
'id']] = $cate_arbo[$key][
'fulllabel'];
5096 $output .=
'</select>';
5099 if ($outputmode == 2) {
5101 } elseif ($outputmode) {
5125 public function form_confirm($page, $title, $question, $action, $formquestion =
'', $selectedchoice =
"", $useajax = 0, $height = 170, $width = 500)
5128 dol_syslog(__METHOD__ .
': using form_confirm is deprecated. Use formconfim instead.', LOG_WARNING);
5129 print $this->
formconfirm($page, $title, $question, $action, $formquestion, $selectedchoice, $useajax, $height, $width);
5159 public function formconfirm($page, $title, $question, $action, $formquestion =
'', $selectedchoice =
'', $useajax = 0, $height = 0, $width = 500, $disableformtag = 0, $labelbuttonyes =
'Yes', $labelbuttonno =
'No')
5161 global $langs, $conf;
5163 $more =
'<!-- formconfirm - before call, page=' .
dol_escape_htmltag($page) .
' -->';
5169 $newselectedchoice = empty($selectedchoice) ?
"no" : $selectedchoice;
5170 if ($conf->browser->layout ==
'phone') {
5175 if (empty($height)) {
5177 if (is_array($formquestion) && count($formquestion) > 2) {
5178 $height += ((count($formquestion) - 2) * 24);
5182 if (is_array($formquestion) && !empty($formquestion)) {
5184 foreach ($formquestion as $key => $input) {
5185 if (is_array($input) && !empty($input)) {
5186 if ($input[
'type'] ==
'hidden') {
5187 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
5188 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
5196 $moreonecolumn =
'';
5197 $more .=
'<div class="tagtable paddingtopbottomonly centpercent noborderspacing">' .
"\n";
5198 foreach ($formquestion as $key => $input) {
5199 if (is_array($input) && !empty($input)) {
5200 $size = (!empty($input[
'size']) ?
' size="' . $input[
'size'] .
'"' :
'');
5201 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
5202 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
5204 if ($input[
'type'] ==
'text') {
5205 $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";
5206 } elseif ($input[
'type'] ==
'password') {
5207 $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";
5208 } elseif ($input[
'type'] ==
'textarea') {
5214 $moreonecolumn .=
'<div class="margintoponly">';
5215 $moreonecolumn .= $input[
'label'] .
'<br>';
5217 $moreonecolumn .= $input[
'value'];
5218 $moreonecolumn .=
'</textarea>';
5219 $moreonecolumn .=
'</div>';
5220 } elseif (in_array($input[
'type'], [
'select',
'multiselect'])) {
5221 if (empty($morecss)) {
5222 $morecss =
'minwidth100';
5225 $show_empty = isset($input[
'select_show_empty']) ? $input[
'select_show_empty'] : 1;
5226 $key_in_label = isset($input[
'select_key_in_label']) ? $input[
'select_key_in_label'] : 0;
5227 $value_as_key = isset($input[
'select_value_as_key']) ? $input[
'select_value_as_key'] : 0;
5228 $translate = isset($input[
'select_translate']) ? $input[
'select_translate'] : 0;
5229 $maxlen = isset($input[
'select_maxlen']) ? $input[
'select_maxlen'] : 0;
5230 $disabled = isset($input[
'select_disabled']) ? $input[
'select_disabled'] : 0;
5231 $sort = isset($input[
'select_sort']) ? $input[
'select_sort'] :
'';
5233 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">';
5234 if (!empty($input[
'label'])) {
5235 $more .= $input[
'label'] .
'</div><div class="tagtd left">';
5237 if ($input[
'type'] ==
'select') {
5238 $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);
5240 $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);
5242 $more .=
'</div></div>' .
"\n";
5243 } elseif ($input[
'type'] ==
'checkbox') {
5244 $more .=
'<div class="tagtr">';
5245 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'"><label for="' .
dol_escape_htmltag($input[
'name']) .
'">' . $input[
'label'] .
'</label></div><div class="tagtd">';
5246 $more .=
'<input type="checkbox" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' .
dol_escape_htmltag($input[
'name']) .
'" name="' .
dol_escape_htmltag($input[
'name']) .
'"' . $moreattr;
5247 if (!is_bool($input[
'value']) && $input[
'value'] !=
'false' && $input[
'value'] !=
'0' && $input[
'value'] !=
'') {
5248 $more .=
' checked';
5250 if (is_bool($input[
'value']) && $input[
'value']) {
5251 $more .=
' checked';
5253 if (isset($input[
'disabled'])) {
5254 $more .=
' disabled';
5256 $more .=
' /></div>';
5257 $more .=
'</div>' .
"\n";
5258 } elseif ($input[
'type'] ==
'radio') {
5260 foreach ($input[
'values'] as $selkey => $selval) {
5261 $more .=
'<div class="tagtr">';
5262 if (isset($input[
'label'])) {
5264 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
' tdtop' : (
' tdtop ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
5266 $more .=
'<div clas="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' "' . $input[
'tdclass'])) .
'"> </div>';
5269 $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;
5270 if (!empty($input[
'disabled'])) {
5271 $more .=
' disabled';
5273 if (isset($input[
'default']) && $input[
'default'] === $selkey) {
5274 $more .=
' checked="checked"';
5277 $more .=
'<label for="' .
dol_escape_htmltag($input[
'name'] . $selkey) .
'" class="valignmiddle">' . $selval .
'</label>';
5278 $more .=
'</div></div>' .
"\n";
5281 } elseif ($input[
'type'] ==
'date' || $input[
'type'] ==
'datetime') {
5282 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
5283 $more .=
'<div class="tagtd">';
5284 $addnowlink = (empty($input[
'datenow']) ? 0 : 1);
5286 if ($input[
'type'] ==
'datetime') {
5287 $h = isset($input[
'hours']) ? $input[
'hours'] : 1;
5288 $m = isset($input[
'minutes']) ? $input[
'minutes'] : 1;
5290 $more .= $this->
selectDate($input[
'value'], $input[
'name'], $h, $m, 0,
'', 1, $addnowlink);
5291 $more .=
'</div></div>'.
"\n";
5292 $formquestion[] = array(
'name'=>$input[
'name'].
'day');
5293 $formquestion[] = array(
'name'=>$input[
'name'].
'month');
5294 $formquestion[] = array(
'name'=>$input[
'name'].
'year');
5295 $formquestion[] = array(
'name'=>$input[
'name'].
'hour');
5296 $formquestion[] = array(
'name'=>$input[
'name'].
'min');
5297 } elseif ($input[
'type'] ==
'other') {
5298 $more .=
'<div class="tagtr"><div class="tagtd'.(empty($input[
'tdclass']) ?
'' : (
' '.$input[
'tdclass'])).
'">';
5299 if (!empty($input[
'label'])) {
5300 $more .= $input[
'label'] .
'</div><div class="tagtd">';
5302 $more .= $input[
'value'];
5303 $more .=
'</div></div>' .
"\n";
5304 } elseif ($input[
'type'] ==
'onecolumn') {
5305 $moreonecolumn .=
'<div class="margintoponly">';
5306 $moreonecolumn .= $input[
'value'];
5307 $moreonecolumn .=
'</div>' .
"\n";
5308 } elseif ($input[
'type'] ==
'hidden') {
5310 } elseif ($input[
'type'] ==
'separator') {
5313 $more .=
'Error type ' . $input[
'type'] .
' for the confirm box is not a supported type';
5317 $more .=
'</div>' .
"\n";
5318 $more .= $moreonecolumn;
5324 if (!empty($conf->dol_use_jmobile)) {
5327 if (empty($conf->use_javascript_ajax)) {
5333 $dialogconfirm =
'dialog-confirm';
5335 if (!is_numeric($useajax)) {
5339 $dialogconfirm .=
'-' . $button;
5341 $pageyes = $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=yes';
5342 $pageno = ($useajax == 2 ? $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=no' :
'');
5345 if (is_array($formquestion)) {
5346 foreach ($formquestion as $key => $input) {
5349 if (is_array($input) && isset($input[
'name'])) {
5350 if (strpos($input[
'name'],
',') > 0) {
5351 $inputok = array_merge($inputok, explode(
',', $input[
'name']));
5353 array_push($inputok, $input[
'name']);
5357 if (isset($input[
'inputko']) && $input[
'inputko'] == 1) {
5358 array_push($inputko, $input[
'name']);
5365 if (is_array($formquestion) && !empty($formquestion[
'text'])) {
5366 $formconfirm .=
'<div class="confirmtext">' . $formquestion[
'text'] .
'</div>' .
"\n";
5368 if (!empty($more)) {
5369 $formconfirm .=
'<div class="confirmquestions">' . $more .
'</div>' .
"\n";
5371 $formconfirm .= ($question ?
'<div class="confirmmessage">' .
img_help(
'',
'') .
' ' . $question .
'</div>' :
'');
5374 $formconfirm .=
"\n<!-- begin code of popup for formconfirm page=" . $page .
" -->\n";
5376 $formconfirm .=
"/* Code for the jQuery('#dialogforpopup').dialog() */\n";
5379 $( "#' . $dialogconfirm .
'" ).dialog(
5381 autoOpen: ' . ($autoOpen ?
"true" :
"false") .
',';
5382 if ($newselectedchoice ==
'no') {
5385 $(this).parent().find("button.ui-button:eq(2)").focus();
5390 if ($useajax == 1) {
5391 $jsforcursor =
'// The call to urljump can be slow, so we set the wait cursor' .
"\n";
5392 $jsforcursor .=
'jQuery("html,body,#id-container").addClass("cursorwait");' .
"\n";
5395 $postconfirmas =
'GET';
5399 height: "' . $height .
'",
5400 width: "' . $width .
'",
5402 closeOnEscape: false,
5404 "' .
dol_escape_js($langs->transnoentities($labelbuttonyes)) .
'": function() {
5405 var options = "token=' . urlencode(
newToken()) .
'";
5406 var inputok = ' . json_encode($inputok) .
'; /* List of fields into form */
5407 var page = "' .
dol_escape_js(!empty($page) ? $page :
'') .
'";
5408 var pageyes = "' .
dol_escape_js(!empty($pageyes) ? $pageyes :
'') .
'";
5410 if (inputok.length > 0) {
5411 $.each(inputok, function(i, inputname) {
5414 if ($("input[name=\'" + inputname + "\']").attr("type") == "radio") {
5415 inputvalue = $("input[name=\'" + inputname + "\']:checked").val();
5417 if ($("#" + inputname).attr("type") == "checkbox") { more = ":checked"; }
5418 inputvalue = $("#" + inputname + more).val();
5420 if (typeof inputvalue == "undefined") { inputvalue=""; }
5421 console.log("formconfirm check inputname="+inputname+" inputvalue="+inputvalue);
5422 options += "&" + inputname + "=" + encodeURIComponent(inputvalue);
5425 var urljump = pageyes + (pageyes.indexOf("?") < 0 ? "?" : "&") + options;
5426 if (pageyes.length > 0) {';
5427 if ($postconfirmas ==
'GET') {
5434 function(data) { $("body").html(data); jQuery("html,body,#id-container").removeClass("cursorwait"); }
5438 console.log("after post ok");
5440 $(this).dialog("close");
5442 "' .
dol_escape_js($langs->transnoentities($labelbuttonno)) .
'": function() {
5443 var options = "token=' . urlencode(
newToken()) .
'";
5444 var inputko = ' . json_encode($inputko) .
'; /* List of fields into form */
5445 var page = "' .
dol_escape_js(!empty($page) ? $page :
'') .
'";
5446 var pageno="' .
dol_escape_js(!empty($pageno) ? $pageno :
'') .
'";
5447 if (inputko.length > 0) {
5448 $.each(inputko, function(i, inputname) {
5450 if ($("#" + inputname).attr("type") == "checkbox") { more = ":checked"; }
5451 var inputvalue = $("#" + inputname + more).val();
5452 if (typeof inputvalue == "undefined") { inputvalue=""; }
5453 options += "&" + inputname + "=" + encodeURIComponent(inputvalue);
5456 var urljump=pageno + (pageno.indexOf("?") < 0 ? "?" : "&") + options;
5458 if (pageno.length > 0) {';
5459 if ($postconfirmas ==
'GET') {
5466 function(data) { $("body").html(data); jQuery("html,body,#id-container").removeClass("cursorwait"); }
5470 console.log("after post ko");
5472 $(this).dialog("close");
5478 var button = "' . $button .
'";
5479 if (button.length > 0) {
5480 $( "#" + button ).click(function() {
5481 $("#' . $dialogconfirm .
'").dialog("open");
5491 if (empty($disableformtag)) {
5492 $formconfirm .=
'<form method="POST" action="' . $page .
'" class="notoptoleftroright">' .
"\n";
5495 $formconfirm .=
'<input type="hidden" name="action" value="' . $action .
'">' .
"\n";
5498 $formconfirm .=
'<table class="valid centpercent">' .
"\n";
5501 $formconfirm .=
'<tr class="validtitre"><td class="validtitre" colspan="2">';
5506 if (is_array($formquestion) && !empty($formquestion[
'text'])) {
5507 $formconfirm .=
'<tr class="valid"><td class="valid" colspan="2">' . $formquestion[
'text'] .
'</td></tr>' .
"\n";
5512 $formconfirm .=
'<tr class="valid"><td class="valid" colspan="2">' .
"\n";
5519 $formconfirm .=
'<td class="valid">' . $question .
'</td>';
5521 $formconfirm .= $this->
selectyesno(
"confirm", $newselectedchoice, 0,
false, 0, 0,
'marginleftonly marginrightonly', $labelbuttonyes, $labelbuttonno);
5522 $formconfirm .=
'<input class="button valignmiddle confirmvalidatebutton small" type="submit" value="' . $langs->trans(
"Validate") .
'">';
5528 if (empty($disableformtag)) {
5533 if (!empty($conf->use_javascript_ajax)) {
5534 $formconfirm .=
'<!-- code to disable button to avoid double clic -->';
5537 $(document).ready(function () {
5538 $(".confirmvalidatebutton").on("click", function() {
5539 console.log("We click on button");
5540 $(this).attr("disabled", "disabled");
5541 setTimeout(\'$(".confirmvalidatebutton").removeAttr("disabled")\', 3000);
5542 //console.log($(this).closest("form"));
5543 $(this).closest("form").submit();
5574 public function form_project($page, $socid, $selected =
'', $htmlname =
'projectid', $discard_closed = 0, $maxlength = 20, $forcefocus = 0, $nooutput = 0, $textifnoproject =
'', $morecss =
'')
5579 require_once DOL_DOCUMENT_ROOT .
'/core/lib/project.lib.php';
5580 require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formprojet.class.php';
5586 $langs->load(
"project");
5587 if ($htmlname !=
"none") {
5588 $out .=
'<form method="post" action="' . $page .
'">';
5589 $out .=
'<input type="hidden" name="action" value="classin">';
5590 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5591 $out .= $formproject->select_projects($socid, $selected, $htmlname, $maxlength, 0, 1, $discard_closed, $forcefocus, 0, 0,
'', 1, 0, $morecss);
5592 $out .=
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
5595 $out .=
'<span class="project_head_block">';
5597 $projet =
new Project($this->db);
5598 $projet->fetch($selected);
5599 $out .= $projet->getNomUrl(0,
'', 1);
5601 $out .=
'<span class="opacitymedium">' . $textifnoproject .
'</span>';
5606 if (empty($nooutput)) {
5630 public function form_conditions_reglement($page, $selected =
'', $htmlname =
'cond_reglement_id', $addempty = 0, $type =
'', $filtertype = -1, $deposit_percent = -1, $nooutput = 0)
5637 if ($htmlname !=
"none") {
5638 $out .=
'<form method="POST" action="' . $page .
'">';
5639 $out .=
'<input type="hidden" name="action" value="setconditions">';
5640 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5642 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
5645 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
5650 if (isset($this->cache_conditions_paiements[$selected])) {
5651 $label = $this->cache_conditions_paiements[$selected][
'label'];
5653 if (!empty($this->cache_conditions_paiements[$selected][
'deposit_percent'])) {
5654 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $this->cache_conditions_paiements[$selected][
'deposit_percent'], $label);
5659 $langs->load(
'errors');
5660 $out .= $langs->trans(
'ErrorNotInDictionaryPaymentConditions');
5667 if (empty($nooutput)) {
5689 if ($htmlname !=
"none") {
5690 print
'<form method="post" action="' . $page .
'">';
5691 print
'<input type="hidden" name="action" value="setavailability">';
5692 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5694 print
'<input type="submit" name="modify" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
5695 print
'<input type="submit" name="cancel" class="button smallpaddingimp" value="' . $langs->trans(
"Cancel") .
'">';
5700 print $this->cache_availability[$selected][
'label'];
5717 public function formInputReason($page, $selected =
'', $htmlname =
'demandreason', $addempty = 0)
5720 if ($htmlname !=
"none") {
5721 print
'<form method="post" action="' . $page .
'">';
5722 print
'<input type="hidden" name="action" value="setdemandreason">';
5723 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5725 print
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
5730 foreach ($this->cache_demand_reason as $key => $val) {
5731 if ($val[
'id'] == $selected) {
5732 print $val[
'label'];
5757 public function form_date($page, $selected, $htmlname, $displayhour = 0, $displaymin = 0, $nooutput = 0, $type =
'')
5764 if ($htmlname !=
"none") {
5765 $ret .=
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
5766 $ret .=
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
5767 $ret .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5769 $ret .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
5771 $ret .=
'<table class="nobordernopadding">';
5773 $ret .= $this->
selectDate($selected, $htmlname, $displayhour, $displaymin, 1,
'form' . $htmlname, 1, 0);
5775 $ret .=
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
5776 $ret .=
'</tr></table></form>';
5785 if (empty($nooutput)) {
5804 public function form_users($page, $selected =
'', $htmlname =
'userid', $exclude =
'', $include =
'')
5809 if ($htmlname !=
"none") {
5810 print
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
5811 print
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
5812 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5813 print $this->
select_dolusers($selected, $htmlname, 1, $exclude, 0, $include);
5814 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5818 require_once DOL_DOCUMENT_ROOT .
'/user/class/user.class.php';
5819 $theuser =
new User($this->db);
5820 $theuser->fetch($selected);
5821 print $theuser->getNomUrl(1);
5844 public function form_modes_reglement($page, $selected =
'', $htmlname =
'mode_reglement_id', $filtertype =
'', $active = 1, $addempty = 0, $type =
'', $nooutput = 0)
5850 if ($htmlname !=
"none") {
5851 $out .=
'<form method="POST" action="' . $page .
'">';
5852 $out .=
'<input type="hidden" name="action" value="setmode">';
5853 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5855 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
5857 $out .= $this->
select_types_paiements($selected, $htmlname, $filtertype, 0, $addempty, 0, 0, $active,
'', 1);
5858 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5863 $out .= $this->cache_types_paiements[$selected][
'label'];
5890 if ($htmlname !=
"none") {
5891 print
'<form method="POST" action="' . $page .
'">';
5892 print
'<input type="hidden" name="action" value="settransportmode">';
5893 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5895 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5900 print $this->cache_transport_mode[$selected][
'label'];
5921 if ($htmlname !=
"none") {
5922 print
'<form method="POST" action="' . $page .
'">';
5923 print
'<input type="hidden" name="action" value="setmulticurrencycode">';
5924 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5926 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5930 print !empty($selected) ?
currency_name($selected, 1) :
' ';
5948 global $langs, $mysoc, $conf;
5950 if ($htmlname !=
"none") {
5951 print
'<form method="POST" action="' . $page .
'">';
5952 print
'<input type="hidden" name="action" value="setmulticurrencyrate">';
5953 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5954 print
'<input type="text" class="maxwidth100" name="' . $htmlname .
'" value="' . (!empty($rate) ?
price(
price2num($rate,
'CU')) : 1) .
'" /> ';
5955 print
'<select name="calculation_mode">';
5956 print
'<option value="1">Change ' . $langs->trans(
"PriceUHT") .
' of lines</option>';
5957 print
'<option value="2">Change ' . $langs->trans(
"PriceUHTCurrency") .
' of lines</option>';
5959 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5962 if (!empty($rate)) {
5963 print
price($rate, 1, $langs, 1, 0);
5964 if ($currency && $rate != 1) {
5965 print
' (' .
price($rate, 1, $langs, 1, 0) .
' ' . $currency .
' = 1 ' . $conf->currency .
')';
5991 public function form_remise_dispo($page, $selected, $htmlname, $socid, $amount, $filter =
'', $maxvalue = 0, $more =
'', $hidelist = 0, $discount_type = 0)
5994 global $conf, $langs;
5995 if ($htmlname !=
"none") {
5996 print
'<form method="post" action="' . $page .
'">';
5997 print
'<input type="hidden" name="action" value="setabsolutediscount">';
5998 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5999 print
'<div class="inline-block">';
6000 if (!empty($discount_type)) {
6001 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
6002 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL") {
6003 $translationKey =
'HasAbsoluteDiscountFromSupplier';
6005 $translationKey =
'HasCreditNoteFromSupplier';
6008 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
6009 $translationKey =
'HasAbsoluteDiscountFromSupplier';
6011 $translationKey =
'HasCreditNoteFromSupplier';
6015 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
6016 if (!$filter || $filter ==
"fk_facture_source IS NULL") {
6017 $translationKey =
'CompanyHasAbsoluteDiscount';
6019 $translationKey =
'CompanyHasCreditNote';
6022 if (!$filter || $filter ==
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
6023 $translationKey =
'CompanyHasAbsoluteDiscount';
6025 $translationKey =
'CompanyHasCreditNote';
6029 print $langs->trans($translationKey,
price($amount, 0, $langs, 0, 0, -1, $conf->currency));
6030 if (empty($hidelist)) {
6034 if (empty($hidelist)) {
6035 print
'<div class="inline-block" style="padding-right: 10px">';
6036 $newfilter =
'discount_type=' . intval($discount_type);
6037 if (!empty($discount_type)) {
6038 $newfilter .=
' AND fk_invoice_supplier IS NULL AND fk_invoice_supplier_line IS NULL';
6040 $newfilter .=
' AND fk_facture IS NULL AND fk_facture_line IS NULL';
6043 $newfilter .=
' AND (' . $filter .
')';
6046 $nbqualifiedlines = $this->
select_remises($selected, $htmlname, $newfilter, $socid, $maxvalue);
6047 if ($nbqualifiedlines > 0) {
6048 print
' <input type="submit" class="button smallpaddingimp" value="' .
dol_escape_htmltag($langs->trans(
"UseLine")) .
'"';
6049 if (!empty($discount_type) && $filter && $filter !=
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
6050 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
6052 if (empty($discount_type) && $filter && $filter !=
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
6053 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
6061 print
'<div class="inline-block">';
6087 public function form_contacts($page, $societe, $selected =
'', $htmlname =
'contactid')
6090 global $langs, $conf;
6092 if ($htmlname !=
"none") {
6093 print
'<form method="post" action="' . $page .
'">';
6094 print
'<input type="hidden" name="action" value="set_contact">';
6095 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6096 print
'<table class="nobordernopadding">';
6101 $addcontact = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans(
"AddContact") : $langs->trans(
"AddContactAddress"));
6102 print
'<a href="' . DOL_URL_ROOT .
'/contact/card.php?socid=' . $societe->id .
'&action=create&backtoreferer=1">' . $addcontact .
'</a>';
6105 print
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
6106 print
'</tr></table></form>';
6109 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
6110 $contact =
new Contact($this->db);
6111 $contact->fetch($selected);
6112 print $contact->getFullName($langs);
6137 public function form_thirdparty($page, $selected =
'', $htmlname =
'socid', $filter =
'', $showempty = 0, $showtype = 0, $forcecombo = 0, $events = array(), $nooutput = 0, $excludeids = array(), $textifnothirdparty =
'')
6143 if ($htmlname !=
"none") {
6144 $out .=
'<form method="post" action="' . $page .
'">';
6145 $out .=
'<input type="hidden" name="action" value="set_thirdparty">';
6146 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6147 $out .= $this->
select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, 0,
'minwidth100',
'',
'', 1, array(),
false, $excludeids);
6148 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6152 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
6153 $soc =
new Societe($this->db);
6154 $soc->fetch($selected);
6155 $out .= $soc->getNomUrl(0,
'');
6157 $out .=
'<span class="opacitymedium">' . $textifnothirdparty .
'</span>';
6195 public function selectCurrency($selected =
'', $htmlname =
'currency_id', $mode = 0, $useempty =
'')
6197 global $conf, $langs, $user;
6199 $langs->loadCacheCurrencies(
'');
6203 if ($selected ==
'euro' || $selected ==
'euros') {
6207 $out .=
'<select class="flat maxwidth200onsmartphone minwidth300" name="' . $htmlname .
'" id="' . $htmlname .
'">';
6209 $out .=
'<option value="-1" selected></option>';
6211 foreach ($langs->cache_currencies as $code_iso => $currency) {
6212 $labeltoshow = $currency[
'label'];
6214 $labeltoshow .=
' <span class="opacitymedium">(' . $code_iso .
')</span>';
6216 $labeltoshow .=
' <span class="opacitymedium">(' . $langs->getCurrencySymbol($code_iso) .
')</span>';
6219 if ($selected && $selected == $code_iso) {
6220 $out .=
'<option value="' . $code_iso .
'" selected data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
6222 $out .=
'<option value="' . $code_iso .
'" data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
6224 $out .= $labeltoshow;
6225 $out .=
'</option>';
6227 $out .=
'</select>';
6229 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
6233 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
6251 public function selectMultiCurrency($selected =
'', $htmlname =
'multicurrency_code', $useempty = 0, $filter =
'', $excludeConfCurrency =
false, $morecss =
'')
6253 global $conf, $langs;
6255 $langs->loadCacheCurrencies(
'');
6257 $TCurrency = array();
6259 $sql =
"SELECT code FROM " . $this->db->prefix() .
"multicurrency";
6260 $sql .=
" WHERE entity IN ('" .
getEntity(
'mutlicurrency') .
"')";
6262 $sql .=
" AND " . $filter;
6264 $resql = $this->db->query(
$sql);
6266 while ($obj = $this->db->fetch_object($resql)) {
6267 $TCurrency[$obj->code] = $obj->code;
6272 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
6274 $out .=
'<option value=""> </option>';
6277 if (!in_array($conf->currency, $TCurrency) && !$excludeConfCurrency) {
6278 $TCurrency[$conf->currency] = $conf->currency;
6280 if (count($TCurrency) > 0) {
6281 foreach ($langs->cache_currencies as $code_iso => $currency) {
6282 if (isset($TCurrency[$code_iso])) {
6283 if (!empty($selected) && $selected == $code_iso) {
6284 $out .=
'<option value="' . $code_iso .
'" selected="selected">';
6286 $out .=
'<option value="' . $code_iso .
'">';
6289 $out .= $currency[
'label'];
6290 $out .=
' (' . $langs->getCurrencySymbol($code_iso) .
')';
6291 $out .=
'</option>';
6296 $out .=
'</select>';
6299 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
6316 global $langs, $user;
6318 $num = count($this->cache_vatrates);
6325 $sql =
"SELECT DISTINCT t.rowid, t.code, t.taux, t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.recuperableonly";
6326 $sql .=
" FROM " . $this->db->prefix() .
"c_tva as t, " . $this->db->prefix() .
"c_country as c";
6327 $sql .=
" WHERE t.fk_pays = c.rowid";
6328 $sql .=
" AND t.active > 0";
6329 $sql .=
" AND c.code IN (" . $this->db->sanitize($country_code, 1) .
")";
6330 $sql .=
" ORDER BY t.code ASC, t.taux ASC, t.recuperableonly ASC";
6332 $resql = $this->db->query(
$sql);
6334 $num = $this->db->num_rows($resql);
6336 for ($i = 0; $i < $num; $i++) {
6337 $obj = $this->db->fetch_object($resql);
6338 $this->cache_vatrates[$i][
'rowid'] = $obj->rowid;
6339 $this->cache_vatrates[$i][
'code'] = $obj->code;
6340 $this->cache_vatrates[$i][
'txtva'] = $obj->taux;
6341 $this->cache_vatrates[$i][
'nprtva'] = $obj->recuperableonly;
6342 $this->cache_vatrates[$i][
'localtax1'] = $obj->localtax1;
6343 $this->cache_vatrates[$i][
'localtax1_type'] = $obj->localtax1_type;
6344 $this->cache_vatrates[$i][
'localtax2'] = $obj->localtax2;
6345 $this->cache_vatrates[$i][
'localtax2_type'] = $obj->localtax1_type;
6347 $this->cache_vatrates[$i][
'label'] = $obj->taux .
'%' . ($obj->code ?
' (' . $obj->code .
')' :
'');
6348 $this->cache_vatrates[$i][
'labelallrates'] = $obj->taux .
'/' . ($obj->localtax1 ? $obj->localtax1 :
'0') .
'/' . ($obj->localtax2 ? $obj->localtax2 :
'0') . ($obj->code ?
' (' . $obj->code .
')' :
'');
6349 $positiverates =
'';
6351 $positiverates .= ($positiverates ?
'/' :
'') . $obj->taux;
6353 if ($obj->localtax1) {
6354 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax1;
6356 if ($obj->localtax2) {
6357 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax2;
6359 if (empty($positiverates)) {
6360 $positiverates =
'0';
6362 $this->cache_vatrates[$i][
'labelpositiverates'] = $positiverates . ($obj->code ?
' (' . $obj->code .
')' :
'');
6367 $this->error =
'<span class="error">';
6368 $this->error .= $langs->trans(
"ErrorNoVATRateDefinedForSellerCountry", $country_code);
6370 if (!empty($user) && $user->admin && preg_match(
'/\'(..)\'/', $country_code, $reg)) {
6371 $langs->load(
"errors");
6372 $new_country_code = $reg[1];
6373 $country_id =
dol_getIdFromCode($this->db, $new_country_code,
'c_pays',
'code',
'rowid');
6374 $this->error .=
'<br>'.$langs->trans(
"ErrorFixThisHere", DOL_URL_ROOT.
'/admin/dict.php?id=10'.($country_id > 0 ?
'&countryidforinsert='.$country_id :
''));
6376 $this->error .=
'</span>';
6380 $this->error =
'<span class="error">' . $this->db->error() .
'</span>';
6408 public function load_tva($htmlname =
'tauxtva', $selectedrate =
'', $societe_vendeuse =
'', $societe_acheteuse =
'', $idprod = 0, $info_bits = 0, $type =
'', $options_only =
false, $mode = 0)
6411 global $langs, $conf, $mysoc;
6413 $langs->load(
'errors');
6418 $defaultnpr = ($info_bits & 0x01);
6419 $defaultnpr = (preg_match(
'/\*/', $selectedrate) ? 1 : $defaultnpr);
6420 $defaulttx = str_replace(
'*',
'', $selectedrate);
6423 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
6424 $defaultcode = $reg[1];
6425 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
6430 if (is_object($societe_vendeuse) && !$societe_vendeuse->country_code) {
6431 if ($societe_vendeuse->id == $mysoc->id) {
6432 $return .=
'<span class="error">' . $langs->trans(
"ErrorYourCountryIsNotDefined") .
'</span>';
6434 $return .=
'<span class="error">' . $langs->trans(
"ErrorSupplierCountryIsNotDefined") .
'</span>';
6445 if (is_object($societe_vendeuse)) {
6446 $code_country =
"'" . $societe_vendeuse->country_code .
"'";
6448 $code_country =
"'" . $mysoc->country_code .
"'";
6450 if (!empty($conf->global->SERVICE_ARE_ECOMMERCE_200238EC)) {
6451 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
6452 if (!
isInEEC($societe_vendeuse) && (!is_object($societe_acheteuse) || (
isInEEC($societe_acheteuse) && !$societe_acheteuse->isACompany()))) {
6454 if (is_numeric($type)) {
6456 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
6458 } elseif (!$idprod) {
6459 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
6461 $prodstatic =
new Product($this->db);
6462 $prodstatic->fetch($idprod);
6464 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
6475 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
6476 $tmpthirdparty =
new Societe($this->db);
6478 $defaulttx =
get_default_tva($societe_vendeuse, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
6479 $defaultnpr =
get_default_npr($societe_vendeuse, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
6481 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
6482 $defaultcode = $reg[1];
6483 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
6485 if (empty($defaulttx)) {
6492 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
6493 if (empty($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS)) {
6495 $defaulttx = $this->cache_vatrates[$num - 1][
'txtva'];
6499 if ($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS !=
'none') {
6500 $defaulttx = $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS;
6502 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
6503 $defaultcode = $reg[1];
6504 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
6512 if (is_object($societe_vendeuse) && $societe_vendeuse->id == $mysoc->id && $societe_vendeuse->tva_assuj ==
"0") {
6515 if (empty($conf->global->EXPENSEREPORT_OVERRIDE_VAT)) {
6521 if (!$options_only) {
6522 $return .=
'<select class="flat minwidth50imp maxwidth100" id="' . $htmlname .
'" name="' . $htmlname .
'"' . ($disabled ?
' disabled' :
'') . $title .
'>';
6525 $selectedfound =
false;
6526 foreach ($this->cache_vatrates as $rate) {
6528 if ($disabled && $rate[
'txtva'] != 0) {
6533 $key = $rate[
'txtva'];
6534 $key .= $rate[
'nprtva'] ?
'*' :
'';
6535 if ($mode > 0 && $rate[
'code']) {
6536 $key .=
' (' . $rate[
'code'] .
')';
6539 $key = $rate[
'rowid'];
6542 $return .=
'<option value="' . $key .
'"';
6543 if (!$selectedfound) {
6545 if ($defaultcode == $rate[
'code']) {
6546 $return .=
' selected';
6547 $selectedfound =
true;
6549 } elseif ($rate[
'txtva'] == $defaulttx && $rate[
'nprtva'] == $defaultnpr) {
6550 $return .=
' selected';
6551 $selectedfound =
true;
6557 if ($mysoc->country_code ==
'IN' || !empty($conf->global->MAIN_VAT_LABEL_IS_POSITIVE_RATES)) {
6559 $return .= $rate[
'labelpositiverates'];
6562 $return .=
vatrate($rate[
'label']);
6566 $return .= (empty($rate[
'code']) && $rate[
'nprtva']) ?
' *' :
'';
6568 $return .=
'</option>';
6571 if (!$options_only) {
6572 $return .=
'</select>';
6576 $return .= $this->error;
6610 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 =
'', $addplusone =
'', $adddateof =
'')
6613 $retstring = $this->
selectDate($set_time, $prefix, $h, $m, $empty, $form_name, $d, $addnowlink, $disabled, $fullday, $addplusone, $adddateof);
6614 if (!empty($nooutput)) {
6637 public function selectDateToDate($set_time =
'', $set_time_end =
'', $prefix =
're', $empty = 0, $forcenewline = 0)
6641 $ret = $this->
selectDate($set_time, $prefix .
'_start', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"from"),
'tzuserrel');
6642 if ($forcenewline) {
6645 $ret .= $this->
selectDate($set_time_end, $prefix .
'_end', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
6676 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')
6678 global $conf, $langs;
6680 if ($gm ===
'auto') {
6681 $gm = (empty($conf) ?
'tzserver' : $conf->tzuserinputkey);
6686 if ($prefix ==
'') {
6697 if ($stepminutes <= 0 || $stepminutes > 30) {
6708 $orig_set_time = $set_time;
6710 if ($set_time ===
'' && $emptydate == 0) {
6711 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
6712 if ($gm ==
'tzuser' || $gm ==
'tzuserrel') {
6724 if (preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/', $set_time, $reg)) {
6726 $syear = (!empty($reg[1]) ? $reg[1] :
'');
6727 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
6728 $sday = (!empty($reg[3]) ? $reg[3] :
'');
6729 $shour = (!empty($reg[4]) ? $reg[4] :
'');
6730 $smin = (!empty($reg[5]) ? $reg[5] :
'');
6731 } elseif (strval($set_time) !=
'' && $set_time != -1) {
6736 if ($orig_set_time !=
'') {
6746 $shour = !isset($conf->global->MAIN_DEFAULT_DATE_HOUR) ? ($h == -1 ?
'23' :
'') : $conf->global->MAIN_DEFAULT_DATE_HOUR;
6747 $smin = !isset($conf->global->MAIN_DEFAULT_DATE_MIN) ? ($h == -1 ?
'59' :
'') : $conf->global->MAIN_DEFAULT_DATE_MIN;
6748 $ssec = !isset($conf->global->MAIN_DEFAULT_DATE_SEC) ? ($h == -1 ?
'59' :
'') : $conf->global->MAIN_DEFAULT_DATE_SEC;
6761 $usecalendar =
'combo';
6762 if (!empty($conf->use_javascript_ajax) && (empty($conf->global->MAIN_POPUP_CALENDAR) || $conf->global->MAIN_POPUP_CALENDAR !=
"none")) {
6763 $usecalendar = ((empty($conf->global->MAIN_POPUP_CALENDAR) || $conf->global->MAIN_POPUP_CALENDAR ==
'eldy') ?
'jquery' : $conf->global->MAIN_POPUP_CALENDAR);
6768 if ($usecalendar !=
'combo') {
6769 $formated_date =
'';
6771 if (strval($set_time) !=
'' && $set_time != -1) {
6773 $formated_date =
dol_print_date($set_time, $langs->trans(
"FormatDateShortInput"), $gm);
6777 if ($usecalendar ==
"eldy") {
6779 $retstring .=
'<input id="' . $prefix .
'" name="' . $prefix .
'" type="text" class="maxwidthdate" maxlength="11" value="' . $formated_date .
'"';
6780 $retstring .= ($disabled ?
' disabled' :
'');
6781 $retstring .=
' onChange="dpChangeDay(\'' . $prefix .
'\',\
'' . $langs->trans(
"FormatDateShortJavaInput") .
'\');
"'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
6785 $retstringbuttom = '';
6787 $retstringbuttom = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
"';
6788 $base = DOL_URL_ROOT . '/core/';
6789 $retstringbuttom .= ' onClick="showDP(\
'' . $base .
'\',\
'' . $prefix .
'\',\
'' . $langs->trans(
"FormatDateShortJavaInput") .
'\',\
'' . $langs->defaultlang .
'\');
"';
6790 $retstringbuttom .= '>' . img_object($langs->trans("SelectDate
"), 'calendarday', 'class="datecallink
"') . '</button>';
6792 $retstringbuttom = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
">' . img_object($langs->trans("Disabled
"), 'calendarday', 'class="datecallink
"') . '</button>';
6794 $retstring = $retstringbuttom . $retstring;
6796 $retstring .= '<input type="hidden
" id="' . $prefix . 'day
" name="' . $prefix . 'day
" value="' . $sday . '">' . "\n
";
6797 $retstring .= '<input type="hidden
" id="' . $prefix . 'month
" name="' . $prefix . 'month
" value="' . $smonth . '">' . "\n
";
6798 $retstring .= '<input type="hidden
" id="' . $prefix . 'year
" name="' . $prefix . 'year
" value="' . $syear . '">' . "\n
";
6799 } elseif ($usecalendar == 'jquery') {
6801 // Output javascript for datepicker
6802 $minYear = getDolGlobalInt('MIN_YEAR_SELECT_DATE', (date('Y') - 100));
6803 $maxYear = getDolGlobalInt('MAX_YEAR_SELECT_DATE', (date('Y') + 100));
6805 $retstring .= '<script nonce="' . getNonce() . '" type="text/javascript
">';
6806 $retstring .= "$(
function(){ $(
'#" . $prefix . "').datepicker({
6807 dateFormat:
'" . $langs->trans("FormatDateShortJQueryInput") . "',
6809 todayHighlight:
true,
6810 yearRange:
'" . $minYear . ":" . $maxYear . "',
";
6811 if (!empty($conf->dol_use_jmobile)) {
6813 beforeShow:
function (input, datePicker) {
6814 input.disabled =
true;
6816 onClose:
function (dateText, datePicker) {
6817 this.disabled =
false;
6821 // Note: We don't need monthNames, monthNamesShort, dayNames, dayNamesShort, dayNamesMin, they are set globally on datepicker component in lib_head.js.php
6822 if (empty($conf->global->MAIN_POPUP_CALENDAR_ON_FOCUS)) {
6825 buttonImage:
'" . DOL_URL_ROOT . "/theme/" . dol_escape_js($conf->theme) . "/img/object_calendarday.png',
6826 buttonImageOnly:
true";
6830 $retstring .= "</script>
";
6833 // Zone de saisie manuelle de la date
6834 $retstring .= '<div class="nowraponall
inline-block divfordateinput
">';
6835 $retstring .= '<input id="'.$prefix.'" name="'.$prefix.'" type="text
" class="maxwidthdate
" maxlength="11
" value="'.$formated_date.'"';
6836 $retstring .= ($disabled ? ' disabled' : '');
6837 $retstring .= ($placeholder ? ' placeholder="' . dol_escape_htmltag($placeholder) . '"' : '');
6838 $retstring .= ' onChange="dpChangeDay(\
'' .
dol_escape_js($prefix) .
'\',\
'' .
dol_escape_js($langs->trans(
"FormatDateShortJavaInput")) .
'\');
"'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
6843 /* Not required. Managed by option buttonImage of jquery
6844 $retstring.=img_object($langs->trans("SelectDate
"),'calendarday','id="'.$prefix.'id" class="datecallink
"');
6845 $retstring.='<script nonce="'.getNonce().'" type="text/javascript
">';
6846 $retstring.="jQuery(document).ready(
function() {
";
6847 $retstring.=' jQuery("#
'.$prefix.'id").click(function() {';
6848 $retstring.=" jQuery(
'#".$prefix."').focus();
";
6851 $retstring.="</script>
";*/
6853 $retstringbutton = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
">' . img_object($langs->trans("Disabled
"), 'calendarday', 'class="datecallink
"') . '</button>';
6854 $retsring = $retstringbutton . $retstring;
6857 $retstring .= '</div>';
6858 $retstring .= '<input type="hidden
" id="' . $prefix . 'day
" name="' . $prefix . 'day
" value="' . $sday . '">' . "\n
";
6859 $retstring .= '<input type="hidden
" id="' . $prefix . 'month
" name="' . $prefix . 'month
" value="' . $smonth . '">' . "\n
";
6860 $retstring .= '<input type="hidden
" id="' . $prefix . 'year
" name="' . $prefix . 'year
" value="' . $syear . '">' . "\n
";
6862 $retstring .= "Bad value of MAIN_POPUP_CALENDAR
";
6865 // Show date with combo selects
6867 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50imp
" id="' . $prefix . 'day
" name="' . $prefix . 'day
">';
6869 if ($emptydate || $set_time == -1) {
6870 $retstring .= '<option value="0
" selected> </option>';
6873 for ($day = 1; $day <= 31; $day++) {
6874 $retstring .= '<option value="' . $day . '"' . ($day == $sday ? ' selected' : '') . '>' . $day . '</option>';
6877 $retstring .= "</select>
";
6879 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'month
" name="' . $prefix . 'month
">';
6880 if ($emptydate || $set_time == -1) {
6881 $retstring .= '<option value="0
" selected> </option>';
6885 for ($month = 1; $month <= 12; $month++) {
6886 $retstring .= '<option value="' . $month . '"' . ($month == $smonth ? ' selected' : '') . '>';
6887 $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b
");
6888 $retstring .= "</option>
";
6890 $retstring .= "</select>
";
6893 if ($emptydate || $set_time == -1) {
6894 $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 . '">';
6896 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'year
" name="' . $prefix . 'year
">';
6898 for ($year = $syear - 10; $year < $syear + 10; $year++) {
6899 $retstring .= '<option value="' . $year . '"' . ($year == $syear ? ' selected' : '') . '>' . $year . '</option>';
6901 $retstring .= "</select>\n
";
6907 $retstring .= ($h == 2 ? '<br>' : ' ');
6908 $retstring .= '<span class="nowraponall
">';
6914 if ($openinghours != '') {
6915 $openinghours = explode(',', $openinghours);
6916 $hourstart = $openinghours[0];
6917 $hourend = $openinghours[1];
6918 if ($hourend < $hourstart) {
6919 $hourend = $hourstart;
6923 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50
' . ($fullday ? $fullday . 'hour
' : '') . '" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
">';
6925 $retstring .= '<option value="-1
"> </option>';
6927 for ($hour = $hourstart; $hour < $hourend; $hour++) {
6928 if (strlen($hour) < 2) {
6929 $hour = "0
" . $hour;
6931 $retstring .= '<option value="' . $hour . '"' . (($hour == $shour) ? ' selected' : '') . '>' . $hour;
6932 //$retstring .= (empty($conf->dol_optimize_smallscreen) ? '' : 'H');
6933 $retstring .= '</option>';
6935 $retstring .= '</select>';
6936 //if ($m && empty($conf->dol_optimize_smallscreen)) $retstring .= ":
";
6944 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50
' . ($fullday ? $fullday . 'min
' : '') . '" id="' . $prefix . 'min
" name="' . $prefix . 'min
">';
6946 $retstring .= '<option value="-1
"> </option>';
6948 for ($min = 0; $min < 60; $min += $stepminutes) {
6949 if (strlen($min) < 2) {
6952 $retstring .= '<option value="' . $min . '"' . (($min == $smin) ? ' selected' : '') . '>' . $min . (empty($conf->dol_optimize_smallscreen) ? '' : '') . '</option>';
6954 $retstring .= '</select>';
6956 $retstring .= '<input type="hidden
" name="' . $prefix . 'sec
" value="' . $ssec . '">';
6960 $retstring .= '</span>';
6964 if (!empty($conf->use_javascript_ajax) && $addnowlink) {
6965 // Script which will be inserted in the onClick of the "Now
" link
6966 $reset_scripts = "";
6967 if ($addnowlink == 2) { // local computer time
6968 // pad add leading 0 on numbers
6969 $reset_scripts .= "Number.prototype.pad =
function(size) {
6970 var s = String(
this);
6971 while (s.length < (size || 2)) {s =
'0' + s;}
6974 var d =
new Date();
";
6977 // Generate the date part, depending on the use or not of the javascript calendar
6978 if ($addnowlink == 1) { // server time expressed in user time setup
6979 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
6980 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
6981 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
6982 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
6983 } elseif ($addnowlink == 2) {
6984 /* Disabled because the output does not use the string format defined by FormatDateShort key to forge the value into #prefix.
6985 * This break application for foreign languages.
6986 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(d.toLocaleDateString(\''.str_replace('_', '-', $langs->defaultlang).'\'));';
6987 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(d.getDate().pad());';
6988 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(parseInt(d.getMonth().pad()) + 1);';
6989 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(d.getFullYear());';
6991 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
6992 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
6993 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
6994 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
6996 /*if ($usecalendar == "eldy
")
6998 $base=DOL_URL_ROOT.'/core/';
6999 $reset_scripts .= 'resetDP(\''.$base.'\',\''.$prefix.'\',\''.$langs->trans("FormatDateShortJavaInput
").'\',\''.$langs->defaultlang.'\');';
7003 $reset_scripts .= 'this.form.elements[\''.$prefix.'day\'].value=formatDate(new Date(), \'d\'); ';
7004 $reset_scripts .= 'this.form.elements[\''.$prefix.'month\'].value=formatDate(new Date(), \'M\'); ';
7005 $reset_scripts .= 'this.form.elements[\''.$prefix.'year\'].value=formatDate(new Date(), \'yyyy\'); ';
7007 // Update the hour part
7010 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7012 //$reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); ';
7013 if ($addnowlink == 1) {
7014 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
7015 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
7016 } elseif ($addnowlink == 2) {
7017 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(d.getHours().pad());';
7018 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
7022 $reset_scripts .= ' } ';
7025 // Update the minute part
7028 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7030 //$reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); ';
7031 if ($addnowlink == 1) {
7032 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
7033 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
7034 } elseif ($addnowlink == 2) {
7035 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(d.getMinutes().pad());';
7036 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
7039 $reset_scripts .= ' } ';
7042 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
7043 if ($reset_scripts && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
7044 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonNow
" type="button" name="_useless
" value="now
" onClick="' . $reset_scripts . '">';
7045 $retstring .= $langs->trans("Now
");
7046 $retstring .= '</button> ';
7050 // Add a "Plus one hour
" link
7051 if ($conf->use_javascript_ajax && $addplusone) {
7052 // Script which will be inserted in the onClick of the "Add plusone
" link
7053 $reset_scripts = "";
7055 // Generate the date part, depending on the use or not of the javascript calendar
7056 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'dayinputnoreduce', 'tzuserrel') . '\');';
7057 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
7058 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
7059 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
7060 // Update the hour part
7063 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7065 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
7067 $reset_scripts .= ' } ';
7070 // Update the minute part
7073 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7075 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
7077 $reset_scripts .= ' } ';
7080 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
7081 if ($reset_scripts && empty($conf->dol_optimize_smallscreen)) {
7082 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonPlusOne
" type="button" name="_useless2
" value="plusone
" onClick="' . $reset_scripts . '">';
7083 $retstring .= $langs->trans("DateStartPlusOne
");
7084 $retstring .= '</button> ';
7088 // Add a link to set data
7089 if ($conf->use_javascript_ajax && !empty($adddateof)) {
7090 if (!is_array($adddateof)) {
7091 $arrayofdateof = array(array('adddateof'=>$adddateof, 'labeladddateof'=>$labeladddateof));
7093 $arrayofdateof = $adddateof;
7095 foreach ($arrayofdateof as $valuedateof) {
7096 $tmpadddateof = $valuedateof['adddateof'];
7097 $tmplabeladddateof = $valuedateof['labeladddateof'];
7098 $tmparray = dol_getdate($tmpadddateof);
7099 if (empty($tmplabeladddateof)) {
7100 $tmplabeladddateof = $langs->trans("DateInvoice
");
7102 $reset_scripts = 'console.log(\'Click on now link\'); ';
7103 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(\''.dol_print_date($tmpadddateof, 'dayinputnoreduce').'\');';
7104 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(\''.$tmparray['mday'].'\');';
7105 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(\''.$tmparray['mon'].'\');';
7106 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(\''.$tmparray['year'].'\');';
7107 $retstring .= ' - <button class="dpInvisibleButtons datenowlink
" id="dateofinvoice
" type="button" name="_dateofinvoice
" value="now
" onclick="'.$reset_scripts.'">'.$tmplabeladddateof.'</button>';
7122 public function selectTypeDuration($prefix, $selected = 'i', $excludetypes = array())
7126 $TDurationTypes = array(
7127 'y' => $langs->trans('Years'),
7128 'm' => $langs->trans('Month'),
7129 'w' => $langs->trans('Weeks'),
7130 'd' => $langs->trans('Days'),
7131 'h' => $langs->trans('Hours'),
7132 'i' => $langs->trans('Minutes')
7135 // Removed undesired duration types
7136 foreach ($excludetypes as $value) {
7137 unset($TDurationTypes[$value]);
7140 $retstring = '<select class="flat minwidth75 maxwidth100
" id="select_
' . $prefix . 'type_duration
" name="' . $prefix . 'type_duration
">';
7141 foreach ($TDurationTypes as $key => $typeduration) {
7142 $retstring .= '<option value="' . $key . '"';
7143 if ($key == $selected) {
7144 $retstring .= " selected
";
7146 $retstring .= ">
" . $typeduration . "</option>
";
7148 $retstring .= "</select>
";
7150 $retstring .= ajax_combobox('select_' . $prefix . 'type_duration');
7155 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
7170 public function select_duration($prefix, $iSecond = '', $disabled = 0, $typehour = 'select', $minunderhours = 0, $nooutput = 0)
7175 $retstring = '<span class="nowraponall
">';
7181 if ($iSecond != '') {
7182 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
7184 $hourSelected = convertSecondToTime($iSecond, 'allhour');
7185 $minSelected = convertSecondToTime($iSecond, 'min');
7188 if ($typehour == 'select') {
7189 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'hour
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . '>';
7190 for ($hour = 0; $hour < 25; $hour++) { // For a duration, we allow 24 hours
7191 $retstring .= '<option value="' . $hour . '"';
7192 if (is_numeric($hourSelected) && $hourSelected == $hour) {
7193 $retstring .= " selected
";
7195 $retstring .= ">
" . $hour . "</option>
";
7197 $retstring .= "</select>
";
7198 } elseif ($typehour == 'text' || $typehour == 'textselect') {
7199 $retstring .= '<input placeholder="' . $langs->trans('HourShort
') . '" type="number
" min="0
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputhour right
" value="' . (($hourSelected != '') ? ((int) $hourSelected) : '') . '">';
7201 return 'BadValueForParameterTypeHour';
7204 if ($typehour != 'text') {
7205 $retstring .= ' ' . $langs->trans('HourShort');
7207 $retstring .= '<span class="">:</span>';
7211 if ($minunderhours) {
7212 $retstring .= '<br>';
7214 if ($typehour != 'text') {
7215 $retstring .= '<span class="hideonsmartphone
"> </span>';
7219 if ($typehour == 'select' || $typehour == 'textselect') {
7220 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'min
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . '>';
7221 for ($min = 0; $min <= 55; $min = $min + 5) {
7222 $retstring .= '<option value="' . $min . '"';
7223 if (is_numeric($minSelected) && $minSelected == $min) {
7224 $retstring .= ' selected';
7226 $retstring .= '>' . $min . '</option>';
7228 $retstring .= "</select>
";
7229 } elseif ($typehour == 'text') {
7230 $retstring .= '<input placeholder="' . $langs->trans('MinuteShort
') . '" type="number
" min="0
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputminute right
" value="' . (($minSelected != '') ? ((int) $minSelected) : '') . '">';
7233 if ($typehour != 'text') {
7234 $retstring .= ' ' . $langs->trans('MinuteShort');
7237 $retstring .= "</span>
";
7239 if (!empty($nooutput)) {
7267 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)
7269 global $langs, $conf;
7274 if (is_null($ajaxoptions)) $ajaxoptions = array();
7276 if (!empty($conf->use_javascript_ajax) && !empty($conf->global->TICKET_USE_SEARCH_TO_SELECT)) {
7279 if ($selected && empty($selected_input_value)) {
7280 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
7281 $tickettmpselect = new Ticket($this->db);
7282 $tickettmpselect->fetch($selected);
7283 $selected_input_value = $tickettmpselect->ref;
7284 unset($tickettmpselect);
7288 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/ticket/ajax/tickets.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
7290 if (empty($hidelabel)) $out .= $langs->trans("RefOrLabel
") . ' : ';
7291 elseif ($hidelabel > 1) {
7292 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
7293 if ($hidelabel == 2) {
7294 $out .= img_picto($langs->trans("Search
"), 'search');
7297 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (!empty($conf->global->PRODUCT_SEARCH_AUTOFOCUS) ? 'autofocus' : '') . ' />';
7298 if ($hidelabel == 3) {
7299 $out .= img_picto($langs->trans("Search
"), 'search');
7302 $out .= $this->selectTicketsList($selected, $htmlname, $filtertype, $limit, $status, 0, $socid, $showempty, $forcecombo, $morecss);
7305 if (empty($nooutput)) {
7330 public function selectTicketsList($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
7332 global $langs, $conf;
7335 $outarray = array();
7337 $selectFields = " p.rowid, p.ref, p.message
";
7340 $sql .= $selectFields;
7341 $sql .= " FROM
" . $this->db->prefix() . "ticket as p
";
7342 $sql .= ' WHERE p.entity IN (' . getEntity('ticket') . ')';
7344 // Add criteria on ref/label
7345 if ($filterkey != '') {
7347 $prefix = empty($conf->global->TICKET_DONOTSEARCH_ANYWHERE) ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
7348 // For natural search
7349 $scrit = explode(' ', $filterkey);
7351 if (count($scrit) > 1) $sql .= "(
";
7352 foreach ($scrit as $crit) {
7353 if ($i > 0) $sql .= " AND
";
7354 $sql .= "(p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%' OR p.subject LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
7358 if (count($scrit) > 1) $sql .= ")
";
7362 $sql .= $this->db->plimit($limit, 0);
7364 // Build output string
7366 $result = $this->db->query($sql);
7368 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
7369 require_once DOL_DOCUMENT_ROOT . '/core/lib/ticket.lib.php';
7371 $num = $this->db->num_rows($result);
7376 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
7377 $out .= ajax_combobox($htmlname, $events, $conf->global->TICKET_USE_SEARCH_TO_SELECT);
7380 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
7383 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
7384 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
7385 if (!empty($conf->global->TICKET_USE_SEARCH_TO_SELECT)) {
7386 if ($showempty && !is_numeric($showempty)) $textifempty = $langs->trans($showempty);
7387 else $textifempty .= $langs->trans("All
");
7389 if ($showempty && !is_numeric($showempty)) $textifempty = $langs->trans($showempty);
7391 if ($showempty) $out .= '<option value="0
" selected>' . $textifempty . '</option>';
7394 while ($num && $i < $num) {
7397 $objp = $this->db->fetch_object($result);
7399 $this->constructTicketListOption($objp, $opt, $optJson, $selected, $filterkey);
7401 // "key
" value of json key array is used by jQuery automatically as selected value
7402 // "label
" value of json key array is used by jQuery automatically as text for combo box
7404 array_push($outarray, $optJson);
7409 $out .= '</select>';
7411 $this->db->free($result);
7413 if (empty($outputmode)) {
7418 dol_print_error($this->db);
7435 protected function constructTicketListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
7441 $outkey = $objp->rowid;
7442 $outref = $objp->ref;
7443 $outtype = $objp->fk_product_type;
7445 $opt = '<option value="' . $objp->rowid . '"';
7446 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
7449 $objRef = $objp->ref;
7450 if (!empty($filterkey) && $filterkey != '') $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1);
7452 $opt .= "</option>\n
";
7453 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
7475 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)
7477 global $langs, $conf;
7482 if (is_null($ajaxoptions)) $ajaxoptions = array();
7484 if (!empty($conf->use_javascript_ajax) && !empty($conf->global->TICKET_USE_SEARCH_TO_SELECT)) {
7487 if ($selected && empty($selected_input_value)) {
7488 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
7489 $projecttmpselect = new Project($this->db);
7490 $projecttmpselect->fetch($selected);
7491 $selected_input_value = $projecttmpselect->ref;
7492 unset($projecttmpselect);
7495 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/projet/ajax/projects.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
7497 if (empty($hidelabel)) $out .= $langs->trans("RefOrLabel
") . ' : ';
7498 elseif ($hidelabel > 1) {
7499 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
7500 if ($hidelabel == 2) {
7501 $out .= img_picto($langs->trans("Search
"), 'search');
7504 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (!empty($conf->global->PRODUCT_SEARCH_AUTOFOCUS) ? 'autofocus' : '') . ' />';
7505 if ($hidelabel == 3) {
7506 $out .= img_picto($langs->trans("Search
"), 'search');
7509 $out .= $this->selectProjectsList($selected, $htmlname, $filtertype, $limit, $status, 0, $socid, $showempty, $forcecombo, $morecss);
7512 if (empty($nooutput)) {
7536 public function selectProjectsList($selected = '', $htmlname = 'projectid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
7538 global $langs, $conf;
7541 $outarray = array();
7543 $selectFields = " p.rowid, p.ref
";
7546 $sql .= $selectFields;
7547 $sql .= " FROM
" . $this->db->prefix() . "projet as p
";
7548 $sql .= ' WHERE p.entity IN (' . getEntity('project') . ')';
7550 // Add criteria on ref/label
7551 if ($filterkey != '') {
7553 $prefix = empty($conf->global->TICKET_DONOTSEARCH_ANYWHERE) ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
7554 // For natural search
7555 $scrit = explode(' ', $filterkey);
7557 if (count($scrit) > 1) $sql .= "(
";
7558 foreach ($scrit as $crit) {
7559 if ($i > 0) $sql .= " AND
";
7560 $sql .= "p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
7564 if (count($scrit) > 1) $sql .= ")
";
7568 $sql .= $this->db->plimit($limit, 0);
7570 // Build output string
7572 $result = $this->db->query($sql);
7574 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
7575 require_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php';
7577 $num = $this->db->num_rows($result);
7582 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
7583 $out .= ajax_combobox($htmlname, $events, $conf->global->PROJECT_USE_SEARCH_TO_SELECT);
7586 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
7589 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
7590 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
7591 if (!empty($conf->global->PROJECT_USE_SEARCH_TO_SELECT)) {
7592 if ($showempty && !is_numeric($showempty)) $textifempty = $langs->trans($showempty);
7593 else $textifempty .= $langs->trans("All
");
7595 if ($showempty && !is_numeric($showempty)) $textifempty = $langs->trans($showempty);
7597 if ($showempty) $out .= '<option value="0
" selected>' . $textifempty . '</option>';
7600 while ($num && $i < $num) {
7603 $objp = $this->db->fetch_object($result);
7605 $this->constructProjectListOption($objp, $opt, $optJson, $selected, $filterkey);
7607 // "key
" value of json key array is used by jQuery automatically as selected value
7608 // "label
" value of json key array is used by jQuery automatically as text for combo box
7610 array_push($outarray, $optJson);
7615 $out .= '</select>';
7617 $this->db->free($result);
7619 if (empty($outputmode)) {
7624 dol_print_error($this->db);
7641 protected function constructProjectListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
7647 $label = $objp->label;
7649 $outkey = $objp->rowid;
7650 $outref = $objp->ref;
7651 $outlabel = $objp->label;
7652 $outtype = $objp->fk_product_type;
7654 $opt = '<option value="' . $objp->rowid . '"';
7655 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
7658 $objRef = $objp->ref;
7659 if (!empty($filterkey) && $filterkey != '') $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1);
7661 $opt .= "</option>\n
";
7662 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
7685 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)
7687 global $langs, $conf;
7692 if (is_null($ajaxoptions)) $ajaxoptions = array();
7694 if (!empty($conf->use_javascript_ajax) && !empty($conf->global->TICKET_USE_SEARCH_TO_SELECT)) {
7698 if ($selected && empty($selected_input_value)) {
7699 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
7700 $adherenttmpselect = new Adherent($this->db);
7701 $adherenttmpselect->fetch($selected);
7702 $selected_input_value = $adherenttmpselect->ref;
7703 unset($adherenttmpselect);
7708 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/adherents/ajax/adherents.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
7710 if (empty($hidelabel)) $out .= $langs->trans("RefOrLabel
") . ' : ';
7711 elseif ($hidelabel > 1) {
7712 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
7713 if ($hidelabel == 2) {
7714 $out .= img_picto($langs->trans("Search
"), 'search');
7717 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (!empty($conf->global->PRODUCT_SEARCH_AUTOFOCUS) ? 'autofocus' : '') . ' />';
7718 if ($hidelabel == 3) {
7719 $out .= img_picto($langs->trans("Search
"), 'search');
7724 $out .= $this->selectMembersList($selected, $htmlname, $filtertype, $limit, $filterkey, $status, 0, $showempty, $forcecombo, $morecss);
7727 if (empty($nooutput)) {
7751 public function selectMembersList($selected = '', $htmlname = 'adherentid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
7753 global $langs, $conf;
7756 $outarray = array();
7758 $selectFields = " p.rowid, p.ref, p.firstname, p.lastname, p.fk_adherent_type
";
7761 $sql .= $selectFields;
7762 $sql .= " FROM
" . $this->db->prefix() . "adherent as p
";
7763 $sql .= ' WHERE p.entity IN (' . getEntity('adherent') . ')';
7765 // Add criteria on ref/label
7766 if ($filterkey != '') {
7768 $prefix = empty($conf->global->MEMBER_DONOTSEARCH_ANYWHERE) ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
7769 // For natural search
7770 $scrit = explode(' ', $filterkey);
7772 if (count($scrit) > 1) $sql .= "(
";
7773 foreach ($scrit as $crit) {
7774 if ($i > 0) $sql .= " AND
";
7775 $sql .= "(p.firstname LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
7776 $sql .= " OR p.lastname LIKE
'" . $this->db->escape($prefix . $crit) . "%')
";
7779 if (count($scrit) > 1) $sql .= ")
";
7782 if ($status != -1) {
7783 $sql .= ' AND statut = ' . ((int) $status);
7785 $sql .= $this->db->plimit($limit, 0);
7787 // Build output string
7788 dol_syslog(get_class($this) . "::
selectMembersList search adherents
", LOG_DEBUG);
7789 $result = $this->db->query($sql);
7791 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
7792 require_once DOL_DOCUMENT_ROOT . '/core/lib/member.lib.php';
7794 $num = $this->db->num_rows($result);
7799 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
7800 $out .= ajax_combobox($htmlname, $events, !empty($conf->global->PROJECT_USE_SEARCH_TO_SELECT) ? $conf->global->PROJECT_USE_SEARCH_TO_SELECT : '');
7803 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
7806 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
7807 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
7808 if (!empty($conf->global->PROJECT_USE_SEARCH_TO_SELECT)) {
7809 if ($showempty && !is_numeric($showempty)) $textifempty = $langs->trans($showempty);
7810 else $textifempty .= $langs->trans("All
");
7812 if ($showempty && !is_numeric($showempty)) $textifempty = $langs->trans($showempty);
7815 $out .= '<option value="-1
" selected>' . $textifempty . '</option>';
7819 while ($num && $i < $num) {
7822 $objp = $this->db->fetch_object($result);
7824 $this->constructMemberListOption($objp, $opt, $optJson, $selected, $filterkey);
7827 // "key
" value of json key array is used by jQuery automatically as selected value
7828 // "label
" value of json key array is used by jQuery automatically as text for combo box
7830 array_push($outarray, $optJson);
7835 $out .= '</select>';
7837 $this->db->free($result);
7839 if (empty($outputmode)) {
7844 dol_print_error($this->db);
7861 protected function constructMemberListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
7867 $outkey = $objp->rowid;
7868 $outlabel = dolGetFirstLastname($objp->firstname, $objp->lastname);
7869 $outtype = $objp->fk_adherent_type;
7871 $opt = '<option value="' . $objp->rowid . '"';
7872 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
7874 if (!empty($filterkey) && $filterkey != '') {
7875 $outlabel = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $outlabel, 1);
7878 $opt .= "</option>\n
";
7880 $optJson = array('key' => $outkey, 'value' => $outlabel, 'type' => $outtype);
7902 public function selectForForms($objectdesc, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $disabled = 0, $selected_input_value = '')
7904 global $conf, $user;
7908 // Example of value for $objectdec:
7909 // Bom:bom/class/bom.class.php:0:t.status=1
7910 // Bom:bom/class/bom.class.php:0:t.status=1:ref
7911 // Bom:bom/class/bom.class.php:0:(t.status:=:1):ref
7912 $InfoFieldList = explode(":
", $objectdesc, 4);
7913 $vartmp = (empty($InfoFieldList[3]) ? '' : $InfoFieldList[3]);
7915 if (preg_match('/^.*:(\w*)$/', $vartmp, $reg)) {
7916 $InfoFieldList[4] = $reg[1]; // take the sort field
7918 $InfoFieldList[3] = preg_replace('/:\w*$/', '', $vartmp); // take the filter field
7920 $classname = $InfoFieldList[0];
7921 $classpath = $InfoFieldList[1];
7922 $addcreatebuttonornot = empty($InfoFieldList[2]) ? 0 : $InfoFieldList[2];
7923 $filter = empty($InfoFieldList[3]) ? '' : $InfoFieldList[3];
7924 $sortfield = empty($InfoFieldList[4]) ? '' : $InfoFieldList[4];
7926 if (!empty($classpath)) {
7927 dol_include_once($classpath);
7929 if ($classname && class_exists($classname)) {
7930 $objecttmp = new $classname($this->db);
7932 // Make some replacement
7933 $sharedentities = getEntity(strtolower($classname));
7934 $filter = str_replace(
7935 array('__ENTITY__', '__SHARED_ENTITIES__', '__USER_ID__'),
7936 array($conf->entity, $sharedentities, $user->id),
7941 if (!is_object($objecttmp)) {
7942 dol_syslog('Error bad setup of type for field ' . join(',', $InfoFieldList), LOG_WARNING);
7943 return 'Error bad setup of type for field ' . join(',', $InfoFieldList);
7946 //var_dump($filter);
7947 $prefixforautocompletemode = $objecttmp->element;
7948 if ($prefixforautocompletemode == 'societe') {
7949 $prefixforautocompletemode = 'company';
7951 if ($prefixforautocompletemode == 'product') {
7952 $prefixforautocompletemode = 'produit';
7954 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) . '_USE_SEARCH_TO_SELECT'; // For example COMPANY_USE_SEARCH_TO_SELECT
7956 dol_syslog(get_class($this) . "::
selectForForms filter=
" . $filter, LOG_DEBUG);
7958 if (!empty($conf->use_javascript_ajax) && getDolGlobalString($confkeyforautocompletemode) && !$forcecombo) {
7959 // No immediate load of all database
7961 if ($preselectedvalue && empty($selected_input_value)) {
7962 $objecttmp->fetch($preselectedvalue);
7963 $selected_input_value = ($prefixforautocompletemode == 'company' ? $objecttmp->name : $objecttmp->ref);
7964 //unset($objecttmp);
7967 $objectdesc = $classname . ':' . $classpath . ':' . $addcreatebuttonornot . ':' . $filter;
7968 $urlforajaxcall = DOL_URL_ROOT . '/core/ajax/selectobject.php';
7970 // No immediate load of all database
7971 $urloption = 'htmlname=' . urlencode($htmlname) . '&outjson=1&objectdesc=' . urlencode($objectdesc) . '&filter=' . urlencode($filter) . ($sortfield ? '&sortfield=' . urlencode($sortfield) : '');
7972 // Activate the auto complete using ajax call.
7973 $out .= ajax_autocompleter($preselectedvalue, $htmlname, $urlforajaxcall, $urloption, $conf->global->$confkeyforautocompletemode, 0, array());
7974 $out .= '<!-- force css to be higher than dialog popup --><style type="text/css
">.ui-autocomplete { z-index: 1010; }</style>';
7975 $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) . '"' : '') . ' />';
7977 // Immediate load of table record.
7978 $out .= $this->selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled, $sortfield, $filter);
8005 public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $outputmode = 0, $disabled = 0, $sortfield = '', $filter = '')
8007 global $conf, $langs, $user, $hookmanager;
8009 //print "$htmlname, $preselectedvalue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, $outputmode, $disabled
";
8011 $prefixforautocompletemode = $objecttmp->element;
8012 if ($prefixforautocompletemode == 'societe') {
8013 $prefixforautocompletemode = 'company';
8015 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) . '_USE_SEARCH_TO_SELECT'; // For example COMPANY_USE_SEARCH_TO_SELECT
8017 if (!empty($objecttmp->fields)) { // For object that declare it, it is better to use declared fields (like societe, contact, ...)
8018 $tmpfieldstoshow = '';
8019 foreach ($objecttmp->fields as $key => $val) {
8020 if (!dol_eval($val['enabled'], 1, 1, '1')) {
8023 if (!empty($val['showoncombobox'])) {
8024 $tmpfieldstoshow .= ($tmpfieldstoshow ? ',' : '') . 't.' . $key;
8027 if ($tmpfieldstoshow) {
8028 $fieldstoshow = $tmpfieldstoshow;
8031 // For backward compatibility
8032 $objecttmp->fields['ref'] = array('type' => 'varchar(30)', 'label' => 'Ref', 'showoncombobox' => 1);
8035 if (empty($fieldstoshow)) {
8036 if (isset($objecttmp->fields['ref'])) {
8037 $fieldstoshow = 't.ref';
8039 $langs->load("errors
");
8040 $this->error = $langs->trans("ErrorNoFieldWithAttributeShowoncombobox
");
8041 return $langs->trans('ErrorNoFieldWithAttributeShowoncombobox');
8046 $outarray = array();
8047 $tmparray = array();
8052 $sql = "SELECT t.rowid,
" . $fieldstoshow . " FROM
" . $this->db->prefix() . $objecttmp->table_element . " as t
";
8053 if (isset($objecttmp->ismultientitymanaged)) {
8054 if (!is_numeric($objecttmp->ismultientitymanaged)) {
8055 $tmparray = explode('@', $objecttmp->ismultientitymanaged);
8056 $sql .= " INNER JOIN
" . $this->db->prefix() . $tmparray[1] . " as parenttable ON parenttable.rowid = t.
" . $tmparray[0];
8058 if ($objecttmp->ismultientitymanaged === 'fk_soc@societe') {
8059 if (empty($user->rights->societe->client->voir) && !$user->socid) {
8060 $sql .= ",
" . $this->db->prefix() . "societe_commerciaux as sc
";
8065 // Add where from hooks
8066 $parameters = array(
8067 'object' => $objecttmp,
8068 'htmlname' => $htmlname,
8069 'filter' => $filter,
8070 'searchkey' => $searchkey
8073 $reshook = $hookmanager->executeHooks('selectForFormsListWhere', $parameters); // Note that $action and $object may have been modified by hook
8074 if (!empty($hookmanager->resPrint)) {
8075 $sql .= $hookmanager->resPrint;
8077 $sql .= " WHERE 1=1
";
8078 if (isset($objecttmp->ismultientitymanaged)) {
8079 if ($objecttmp->ismultientitymanaged == 1) {
8080 $sql .= " AND t.entity IN (
" . getEntity($objecttmp->table_element) . ")
";
8082 if (!is_numeric($objecttmp->ismultientitymanaged)) {
8083 $sql .= " AND parenttable.entity = t.
" . $tmparray[0];
8085 if ($objecttmp->ismultientitymanaged == 1 && !empty($user->socid)) {
8086 if ($objecttmp->element == 'societe') {
8087 $sql .= " AND t.rowid =
" . ((int) $user->socid);
8089 $sql .= " AND t.fk_soc =
" . ((int) $user->socid);
8092 if ($objecttmp->ismultientitymanaged === 'fk_soc@societe') {
8093 if (empty($user->rights->societe->client->voir) && !$user->socid) {
8094 $sql .= " AND t.rowid = sc.fk_soc AND sc.fk_user =
" . ((int) $user->id);
8098 if ($searchkey != '') {
8099 $sql .= natural_search(explode(',', $fieldstoshow), $searchkey);
8102 if ($filter) { // Syntax example "(t.ref:like:
'SO-%') and (t.date_creation:<:
'20160101')
"
8104 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
8105 if ($errormessage) {
8106 return 'Error forging a SQL request from an universal criteria: ' . $errormessage;
8110 $sql .= $this->db->order($sortfield ? $sortfield : $fieldstoshow, "ASC
");
8111 //$sql.=$this->db->plimit($limit, 0);
8114 // Build output string
8115 $resql = $this->db->query($sql);
8117 // Construct $out and $outarray
8118 $out .= '<select id="' . $htmlname . '" class="flat
' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled="disabled
"' : '') . ($moreparams ? ' ' . $moreparams : '') . ' name="' . $htmlname . '">' . "\n
";
8120 // Warning: Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'. Seems it is no more true with selec2 v4
8121 $textifempty = ' ';
8123 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
8124 if (!empty($conf->global->$confkeyforautocompletemode)) {
8125 if ($showempty && !is_numeric($showempty)) {
8126 $textifempty = $langs->trans($showempty);
8128 $textifempty .= $langs->trans("All
");
8132 $out .= '<option value="-1
">' . $textifempty . '</option>' . "\n
";
8135 $num = $this->db->num_rows($resql);
8139 $obj = $this->db->fetch_object($resql);
8142 $tmparray = explode(',', $fieldstoshow);
8143 $oldvalueforshowoncombobox = 0;
8144 foreach ($tmparray as $key => $val) {
8145 $val = preg_replace('/t\./', '', $val);
8146 $label .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val]['showoncombobox'] ? ' - ' : ' ') : '');
8147 $labelhtml .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val]['showoncombobox'] ? ' - ' : ' ') : '');
8148 $label .= $obj->$val;
8149 $labelhtml .= $obj->$val;
8151 $oldvalueforshowoncombobox = empty($objecttmp->fields[$val]['showoncombobox']) ? 0 : $objecttmp->fields[$val]['showoncombobox'];
8153 if (empty($outputmode)) {
8154 if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) {
8155 $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>';
8157 $out .= '<option value="' . $obj->rowid . '" data-html="' . dol_escape_htmltag($labelhtml, 0, 0, '', 0, 1) . '">' . dol_escape_htmltag($label, 0, 0, '', 0, 1) . '</option>';
8160 array_push($outarray, array('key' => $obj->rowid, 'value' => $label, 'label' => $label));
8164 if (($i % 10) == 0) {
8170 $out .= '</select>' . "\n
";
8173 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
8174 $out .= ajax_combobox($htmlname, null, (!empty($conf->global->$confkeyforautocompletemode) ? $conf->global->$confkeyforautocompletemode : 0));
8177 dol_print_error($this->db);
8180 $this->result = array('nbofelement' => $num);
8212 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)
8214 global $conf, $langs;
8216 // Do we want a multiselect ?
8218 //if (preg_match('/^multi/',$htmlname)) $jsbeautify = 1;
8221 if ($value_as_key) {
8222 $array = array_combine($array, $array);
8227 if ($addjscombo < 0) {
8228 if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
8235 $idname = str_replace(array('[', ']'), array('', ''), $htmlname);
8236 $out .= '<select id="' . preg_replace('/^\./
', '', $idname) . '" ' . ($disabled ? 'disabled="disabled
" ' : '') . 'class="flat
' . (preg_replace('/^\./
', '', $htmlname)) . ($morecss ? ' ' . $morecss : '') . '"';
8237 $out .= ' name="' . preg_replace('/^\./
', '', $htmlname) . '" ' . ($moreparam ? $moreparam : '');
8241 $textforempty = ' ';
8242 if (!empty($conf->use_javascript_ajax)) {
8243 $textforempty = ' '; // If we use ajaxcombo, we need here to avoid to have an empty element that is too small.
8245 if (!is_numeric($show_empty)) {
8246 $textforempty = $show_empty;
8248 $out .= '<option class="optiongrey
" ' . ($moreparamonempty ? $moreparamonempty . ' ' : '') . 'value="' . ($show_empty < 0 ? $show_empty : -1) . '"' . ($id == $show_empty ? ' selected' : '') . '>' . $textforempty . '</option>' . "\n
";
8251 if (is_array($array)) {
8254 foreach ($array as $key => $value) {
8255 if (!is_array($value)) {
8256 $array[$key] = $langs->trans($value);
8258 $array[$key]['label'] = $langs->trans($value['label']);
8264 if ($sort == 'ASC') {
8266 } elseif ($sort == 'DESC') {
8270 foreach ($array as $key => $tmpvalue) {
8271 if (is_array($tmpvalue)) {
8272 $value = $tmpvalue['label'];
8273 $disabled = empty($tmpvalue['disabled']) ? '' : ' disabled';
8274 $style = empty($tmpvalue['css']) ? '' : ' class="' . $tmpvalue['css
'] . '"';
8280 if (!empty($disablebademail)) {
8281 if (($disablebademail == 1 && !preg_match('/<.+@.+>/', $value))
8282 || ($disablebademail == 2 && preg_match('/---/', $value))) {
8283 $disabled = ' disabled';
8284 $style = ' class="warning
"';
8288 if ($key_in_label) {
8289 if (empty($nohtmlescape)) {
8290 $selectOptionValue = dol_escape_htmltag($key . ' - ' . ($maxlen ? dol_trunc($value, $maxlen) : $value));
8292 $selectOptionValue = $key . ' - ' . ($maxlen ? dol_trunc($value, $maxlen) : $value);
8295 if (empty($nohtmlescape)) {
8296 $selectOptionValue = dol_escape_htmltag($maxlen ? dol_trunc($value, $maxlen) : $value);
8298 $selectOptionValue = $maxlen ? dol_trunc($value, $maxlen) : $value;
8300 if ($value == '' || $value == '-') {
8301 $selectOptionValue = ' ';
8305 $out .= '<option value="' . $key . '"';
8306 $out .= $style . $disabled;
8307 if (is_array($id)) {
8308 if (in_array($key, $id) && !$disabled) {
8309 $out .= ' selected'; // To preselect a value
8312 $id = (string) $id; // if $id = 0, then $id = '0'
8313 if ($id != '' && ($id == $key || ($id == 'ifone' && count($array) == 1)) && !$disabled) {
8314 $out .= ' selected'; // To preselect a value
8317 if ($nohtmlescape) {
8318 $out .= ' data-html="' . dol_escape_htmltag($selectOptionValue) . '"';
8320 if (is_array($tmpvalue)) {
8321 foreach ($tmpvalue as $keyforvalue => $valueforvalue) {
8322 if (preg_match('/^data-/', $keyforvalue)) {
8323 $out .= ' '.$keyforvalue.'="'.dol_escape_htmltag($valueforvalue).'"';
8328 //var_dump($selectOptionValue);
8329 $out .= $selectOptionValue;
8330 $out .= "</option>\n
";
8334 $out .= "</select>
";
8336 // Add code for jquery to use multiselect
8337 if ($addjscombo && $jsbeautify) {
8338 // Enhance with select2
8339 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
8340 $out .= ajax_combobox($idname, array(), 0, 0, 'resolve', ($show_empty < 0 ? (string) $show_empty : '-1'), $morecss);
8365 public static function selectArrayAjax($htmlname, $url, $id = '', $moreparam = '', $moreparamtourl = '', $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0)
8367 global $conf, $langs;
8368 global $delayedhtmlcontent; // Will be used later outside of this function
8370 // TODO Use an internal dolibarr component instead of select2
8371 if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && !defined('REQUIRE_JQUERY_MULTISELECT')) {
8375 $out = '<select type="text
" class="' . $htmlname . ($morecss ? ' ' . $morecss : '') . '" ' . ($moreparam ? $moreparam . ' ' : '') . 'name="' . $htmlname . '"></select>';
8378 if (!empty($conf->use_javascript_ajax)) {
8379 $tmpplugin = 'select2';
8380 $outdelayed = "\n
" . '<!-- JS CODE TO ENABLE ' . $tmpplugin . ' for id ' . $htmlname . ' -->
8381 <script nonce="' . getNonce() . '">
8382 $(document).ready(function () {
8384 ' . ($callurlonselect ? 'var saveRemoteData = [];' : '') . '
8386 $(".
' . $htmlname . '").select2({
8389 url: "' . $url . '",
8392 data: function (params) {
8394 q: params.term, // search term
8398 processResults: function (data) {
8399 // parse the results into the format expected by Select2.
8400 // since we are using custom formatting functions we do not need to alter the remote JSON data
8401 //console.log(data);
8402 saveRemoteData = data;
8403 /* format json result for select2 */
8405 $.each( data, function( key, value ) {
8406 result.push({id: key, text: value.text});
8408 //return {results:[{id:\'none\', text:\'aa\'}, {id:\'rrr\', text:\'Red\'},{id:\'bbb\', text:\'Search a into projects\'}], more:false}
8409 //console.log(result);
8410 return {results: result, more: false}
8414 language: select2arrayoflanguage,
8415 containerCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag */
8416 placeholder:
"' . dol_escape_js($placeholder) . '",
8417 escapeMarkup:
function (markup) {
return markup; },
8418 minimumInputLength:
' . ((int) $minimumInputLength) . ',
8419 formatResult:
function (result, container, query, escapeMarkup) {
8420 return escapeMarkup(result.text);
8424 ' . ($callurlonselect ? '
8426 $(
".' . $htmlname . '").change(
function() {
8427 var selected = $(
".' . $htmlname . '").val();
8428 console.log(
"We select in selectArrayAjax the entry "+selected)
8429 $(
".' . $htmlname . '").val(
"");
8430 $.each( saveRemoteData,
function( key, value ) {
8431 if (key == selected)
8433 console.log(
"selectArrayAjax - Do a redirect to "+value.url)
8434 location.assign(value.url);
8443 if ($acceptdelayedhtml) {
8444 $delayedhtmlcontent .= $outdelayed;
8446 $out .= $outdelayed;
8470 public static function selectArrayFilter($htmlname, $array, $id = '', $moreparam = '', $disableFiltering = 0, $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0, $textfortitle = '')
8472 global $conf, $langs;
8473 global $delayedhtmlcontent; // Will be used later outside of this function
8475 // TODO Use an internal dolibarr component instead of select2
8476 if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && !defined('REQUIRE_JQUERY_MULTISELECT
')) {
8480 $out = '<select
type=
"text"'.($textfortitle? ' title=
"'.dol_escape_htmltag($textfortitle).'"' : '').' id=
"'.$htmlname.'" class=
"'.$htmlname.($morecss ? ' ' . $morecss : '').'"'.($moreparam ? ' '.$moreparam : '').' name=
"'.$htmlname.'"><option></option></select>
';
8482 $formattedarrayresult = array();
8484 foreach ($array as $key => $value) {
8485 $o = new stdClass();
8487 $o->text = $value['text
'];
8488 $o->url = $value['url
'];
8489 $formattedarrayresult[] = $o;
8493 if (!empty($conf->use_javascript_ajax)) {
8494 $tmpplugin = 'select2
';
8495 $outdelayed = "\n" . '<!-- JS CODE TO ENABLE
' . $tmpplugin . ' for id ' . $htmlname . ' -->
8496 <script nonce=
"' . getNonce() . '">
8497 $(document).ready(
function () {
8498 var data =
' . json_encode($formattedarrayresult) . ';
8500 ' . ($callurlonselect ? 'var saveRemoteData =
' . json_encode($array) . ';
' : '') . '
8502 $(
".' . $htmlname . '").select2({
8504 language: select2arrayoflanguage,
8505 containerCssClass: \
':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag */
8507 escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
8508 minimumInputLength: ' . $minimumInputLength .
',
8509 formatResult: function (result, container, query, escapeMarkup) {
8510 return escapeMarkup(result.text);
8512 matcher: function (params, data) {
8514 if(! data.id) return null;';
8516 if ($callurlonselect) {
8520 var urlBase = data.url;
8521 var separ = urlBase.indexOf("?") >= 0 ? "&" : "?";
8522 /* console.log("params.term="+params.term); */
8523 /* console.log("params.term encoded="+encodeURIComponent(params.term)); */
8524 saveRemoteData[data.id].url = urlBase + separ + "search_all=" + encodeURIComponent(params.term.replace(/\"/g, ""));';
8527 if (!$disableFiltering) {
8530 if(data.text.match(new RegExp(params.term))) {
8545 ' . ($callurlonselect ?
'
8546 /* Code to execute a GET when we select a value */
8547 $(".' . $htmlname .
'").change(function() {
8548 var selected = $(".' . $htmlname .
'").val();
8549 console.log("We select "+selected)
8551 $(".' . $htmlname .
'").val(""); /* reset visible combo value */
8552 $.each( saveRemoteData, function( key, value ) {
8553 if (key == selected)
8555 console.log("selectArrayFilter - Do a redirect to "+value.url)
8556 location.assign(value.url);
8565 if ($acceptdelayedhtml) {
8566 $delayedhtmlcontent .= $outdelayed;
8568 $out .= $outdelayed;
8591 public static function multiselectarray($htmlname, $array, $selected = array(), $key_in_label = 0, $value_as_key = 0, $morecss =
'', $translate = 0, $width = 0, $moreattrib =
'', $elemtype =
'', $placeholder =
'', $addjscombo = -1)
8593 global $conf, $langs;
8597 if ($addjscombo < 0) {
8598 if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
8605 $useenhancedmultiselect = 0;
8606 if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) || defined(
'REQUIRE_JQUERY_MULTISELECT')) {
8607 $useenhancedmultiselect = 1;
8611 $out .=
'<select id="' . $htmlname .
'" class="multiselect' . ($useenhancedmultiselect ?
' multiselectononeline' :
'') . ($morecss ?
' ' . $morecss :
'') .
'" multiple name="' . $htmlname .
'[]"' . ($moreattrib ?
' ' . $moreattrib :
'') . ($width ?
' style="width: ' . (preg_match(
'/%/', $width) ? $width : $width .
'px') .
'"' :
'') .
'>' .
"\n";
8612 if (is_array($array) && !empty($array)) {
8613 if ($value_as_key) {
8614 $array = array_combine($array, $array);
8617 if (!empty($array)) {
8618 foreach ($array as $key => $value) {
8624 if (is_array($value) && array_key_exists(
'id', $value) && array_key_exists(
'label', $value)) {
8625 $tmpkey = $value[
'id'];
8626 $tmpvalue = $value[
'label'];
8627 $tmpcolor = $value[
'color'];
8628 $tmppicto = $value[
'picto'];
8629 $tmplabelhtml = !empty($value[
'labelhtml']) ? $value[
'labelhtml'] :
'';
8631 $newval = ($translate ? $langs->trans($tmpvalue) : $tmpvalue);
8632 $newval = ($key_in_label ? $tmpkey .
' - ' . $newval : $newval);
8634 $out .=
'<option value="' . $tmpkey .
'"';
8635 if (is_array($selected) && !empty($selected) && in_array((
string) $tmpkey, $selected) && ((string) $tmpkey !=
'')) {
8636 $out .=
' selected';
8638 if (!empty($tmplabelhtml)) {
8641 $tmplabelhtml = ($tmppicto ?
img_picto(
'', $tmppicto,
'class="pictofixedwidth" style="color: #' . $tmpcolor .
'"') :
'') . $newval;
8646 $out .=
'</option>' .
"\n";
8650 $out .=
'</select>' .
"\n";
8653 if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) || defined(
'REQUIRE_JQUERY_MULTISELECT')) {
8654 $out .=
"\n" .
'<!-- JS CODE TO ENABLE select for id ' . $htmlname .
', addjscombo=' . $addjscombo .
' -->';
8655 $out .=
"\n" .
'<script nonce="' .
getNonce() .
'">' .
"\n";
8656 if ($addjscombo == 1) {
8657 $tmpplugin = empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) ? constant(
'REQUIRE_JQUERY_MULTISELECT') : $conf->global->MAIN_USE_JQUERY_MULTISELECT;
8658 $out .=
'function formatResult(record, container) {' .
"\n";
8661 $out .=
' if ($(record.element).attr("data-html") != undefined) { return htmlEntityDecodeJs($(record.element).attr("data-html")); }'.
"\n";
8662 $out .=
' return record.text;';
8664 $out .=
'function formatSelection(record) {' .
"\n";
8665 if ($elemtype ==
'category') {
8666 $out .=
'return \'<span><img src="' . DOL_URL_ROOT .
'/theme/eldy/img/object_category.png"> \'+record.text+\'</span>\';';
8668 $out .=
'return record.text;';
8671 $out .=
'$(document).ready(function () {
8672 $(\'#' . $htmlname .
'\').
' . $tmpplugin . '({
';
8680 $out .= ' dir: \
'ltr\',
8681 containerCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag (ko with multiselect) */
8682 dropdownCssClass: \'' . $morecss .
'\',
8684 formatResult: formatResult,
8685 templateResult: formatResult,
8686 escapeMarkup:
function (markup) {
return markup; },
8688 formatSelection: formatSelection,
8689 templateSelection: formatSelection
8694 $(\
'#' . $htmlname .
' + .select2\').addClass(\'' . $morecss .
'\');
8696 } elseif ($addjscombo == 2 && !defined('DISABLE_MULTISELECT
')) {
8698 // TODO external lib multiselect/jquery.multi-select.js must have been loaded to use this multiselect plugin
8700 $out .= 'console.log(\
'addjscombo=2 for htmlname=' . $htmlname .
'\');
';
8701 $out .= '$(document).ready(
function () {
8702 $(\
'#' . $htmlname .
'\').multiSelect({
8703 containerHTML: \
'<div class="multi-select-container">\',
8704 menuHTML: \'<div class="multi-select-menu">\',
8705 buttonHTML: \'<span class="multi-select-button ' . $morecss .
'">\',
8706 menuItemHTML: \'<label class="multi-select-menuitem">\',
8707 activeClass: \'multi-select-container--open\',
8708 noneText: \'' . $placeholder .
'\'
8712 $out .= '</script>
';
8729 public static function multiSelectArrayWithCheckbox($htmlname, &$array, $varpage, $pos = '')
8731 global $conf, $langs, $user, $extrafields;
8733 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
8736 if (empty($array)) {
8740 $tmpvar = "MAIN_SELECTEDFIELDS_" . $varpage; // To get list of saved selected fields to show
8742 if (!empty($user->conf->$tmpvar)) { // A list of fields was already customized for user
8743 $tmparray = explode(',
', $user->conf->$tmpvar);
8744 foreach ($array as $key => $val) {
8746 //var_dump($tmparray);
8747 if (in_array($key, $tmparray)) {
8748 $array[$key]['checked
'] = 1;
8750 $array[$key]['checked
'] = 0;
8753 } else { // There is no list of fields already customized for user
8754 foreach ($array as $key => $val) {
8755 if (!empty($array[$key]['checked
']) && $array[$key]['checked
'] < 0) {
8756 $array[$key]['checked
'] = 0;
8761 $listoffieldsforselection = '';
8762 $listcheckedstring = '';
8764 foreach ($array as $key => $val) {
8766 // var_dump(array_key_exists('enabled
', $val));
8767 // var_dump(!$val['enabled
']);
8768 if (array_key_exists('enabled
', $val) && isset($val['enabled
']) && !$val['enabled
']) {
8769 unset($array[$key]); // We don't want
this field
8772 if (!empty($val[
'type']) && $val[
'type'] ==
'separate') {
8777 if ($val[
'label']) {
8778 if (!empty($val[
'langfile']) && is_object($langs)) {
8779 $langs->load($val[
'langfile']);
8783 $listoffieldsforselection .=
'<li><input type="checkbox" id="checkbox' . $key .
'" value="' . $key .
'"' . ((empty($val[
'checked']) || $val[
'checked'] ==
'-1') ?
'' :
' checked="checked"') .
'/><label for="checkbox' . $key .
'">' .
dol_escape_htmltag($langs->trans($val[
'label'])) .
'</label></li>';
8784 $listcheckedstring .= (empty($val[
'checked']) ?
'' : $key .
',');
8788 $out =
'<!-- Component multiSelectArrayWithCheckbox ' . $htmlname .
' -->
8790 <dl class="dropdown">
8792 <a href="#' . $htmlname .
'">
8795 <input type="hidden" class="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $listcheckedstring .
'">
8797 <dd class="dropdowndd">
8798 <div class="multiselectcheckbox'.$htmlname.
'">
8799 <ul class="'.$htmlname.($pos ==
'1' ?
'left' :
'').
'">
8800 <li><input class="inputsearch_dropdownselectedfields width90p minwidth200imp" style="width:90%;" type="text" placeholder="'.$langs->trans(
'Search').
'"></li>
8801 '.$listoffieldsforselection.
'
8807 <script nonce="' .
getNonce() .
'" type="text/javascript">
8808 jQuery(document).ready(function () {
8809 $(\'.multiselectcheckbox' . $htmlname .
' input[type="checkbox"]\').on(\'click\', function () {
8810 console.log("A new field was added/removed, we edit field input[name=formfilteraction]");
8812 $("input:hidden[name=formfilteraction]").val(\'listafterchangingselectedfields\'); // Update field so we know we changed something on selected fields after POST
8814 var title = $(this).val() + ",";
8815 if ($(this).is(\':checked\')) {
8816 $(\'.' . $htmlname .
'\').val(title + $(\
'.' . $htmlname .
'\').val());
8819 $(\
'.' . $htmlname .
'\').val( $(\
'.' . $htmlname .
'\').val().replace(title, \
'\') )
8824 $(
"input.inputsearch_dropdownselectedfields").on(
"keyup",
function() {
8825 var value = $(
this).val().toLowerCase();
8826 $(\
'.multiselectcheckbox'.$htmlname.
' li > label\').filter(function() {
8827 $(this).parent().toggle($(this).text().toLowerCase().indexOf(value) > -1)
8850 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
8853 $categories = $cat->containing($id, $type);
8855 if ($rendermode == 1) {
8857 foreach ($categories as $c) {
8858 $ways = $c->print_all_ways(
' >> ', ($nolink ?
'none' :
''), 0, 1);
8859 foreach ($ways as $way) {
8860 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ?
' style="background: #' . $c->color .
';"' :
' style="background: #bbb"') .
'>' . $way .
'</li>';
8863 return '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
8866 if ($rendermode == 0) {
8867 $arrayselected = array();
8869 foreach ($categories as $c) {
8870 $arrayselected[] = $c->id;
8873 return $this->
multiselectarray(
'categories', $cate_arbo, $arrayselected,
'', 0,
'', 0,
'100%',
'disabled',
'category');
8876 return 'ErrorBadValueForParameterRenderMode';
8888 public function showLinkedObjectBlock($object, $morehtmlright =
'', $compatibleImportElementsList =
false, $title =
'RelatedObjects')
8890 global $conf, $langs, $hookmanager;
8891 global $bc, $action;
8893 $object->fetchObjectLinked();
8896 $hookmanager->initHooks(array(
'commonobject'));
8897 $parameters = array(
8898 'morehtmlright' => $morehtmlright,
8899 'compatibleImportElementsList' => &$compatibleImportElementsList,
8901 $reshook = $hookmanager->executeHooks(
'showLinkedObjectBlock', $parameters, $object, $action);
8903 $nbofdifferenttypes = count($object->linkedObjects);
8905 if (empty($reshook)) {
8906 print
'<!-- showLinkedObjectBlock -->';
8907 print
load_fiche_titre($langs->trans($title), $morehtmlright,
'', 0, 0,
'showlinkedobjectblock');
8910 print
'<div class="div-table-responsive-no-min">';
8911 print
'<table class="noborder allwidth" data-block="showLinkedObject" data-element="' . $object->element .
'" data-elementid="' . $object->id .
'" >';
8913 print
'<tr class="liste_titre">';
8914 print
'<td>' . $langs->trans(
"Type") .
'</td>';
8915 print
'<td>' . $langs->trans(
"Ref") .
'</td>';
8916 print
'<td class="center"></td>';
8917 print
'<td class="center">' . $langs->trans(
"Date") .
'</td>';
8918 print
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
8919 print
'<td class="right">' . $langs->trans(
"Status") .
'</td>';
8923 $nboftypesoutput = 0;
8925 foreach ($object->linkedObjects as $objecttype => $objects) {
8926 $tplpath = $element = $subelement = $objecttype;
8929 $showImportButton =
false;
8930 if (!empty($compatibleImportElementsList) && in_array($element, $compatibleImportElementsList)) {
8931 $showImportButton =
true;
8935 if ($objecttype !=
'supplier_proposal' && preg_match(
'/^([^_]+)_([^_]+)/i', $objecttype, $regs)) {
8936 $element = $regs[1];
8937 $subelement = $regs[2];
8938 $tplpath = $element .
'/' . $subelement;
8940 $tplname =
'linkedobjectblock';
8943 if ($objecttype ==
'facture') {
8944 $tplpath =
'compta/' . $element;
8948 } elseif ($objecttype ==
'facturerec') {
8949 $tplpath =
'compta/facture';
8950 $tplname =
'linkedobjectblockForRec';
8954 } elseif ($objecttype ==
'propal') {
8955 $tplpath =
'comm/' . $element;
8959 } elseif ($objecttype ==
'supplier_proposal') {
8963 } elseif ($objecttype ==
'shipping' || $objecttype ==
'shipment' || $objecttype ==
'expedition') {
8964 $tplpath =
'expedition';
8968 } elseif ($objecttype ==
'reception') {
8969 $tplpath =
'reception';
8973 } elseif ($objecttype ==
'delivery') {
8974 $tplpath =
'delivery';
8978 } elseif ($objecttype ==
'ficheinter') {
8979 $tplpath =
'fichinter';
8983 } elseif ($objecttype ==
'invoice_supplier') {
8984 $tplpath =
'fourn/facture';
8985 } elseif ($objecttype ==
'order_supplier') {
8986 $tplpath =
'fourn/commande';
8987 } elseif ($objecttype ==
'expensereport') {
8988 $tplpath =
'expensereport';
8989 } elseif ($objecttype ==
'subscription') {
8990 $tplpath =
'adherents';
8991 } elseif ($objecttype ==
'conferenceorbooth') {
8992 $tplpath =
'eventorganization';
8993 } elseif ($objecttype ==
'conferenceorboothattendee') {
8994 $tplpath =
'eventorganization';
8995 } elseif ($objecttype ==
'mo') {
9002 global $linkedObjectBlock;
9003 $linkedObjectBlock = $objects;
9006 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array(
'/' . $tplpath .
'/tpl'));
9007 foreach ($dirtpls as $reldir) {
9008 if ($nboftypesoutput == ($nbofdifferenttypes - 1)) {
9009 global $noMoreLinkedObjectBlockAfter;
9010 $noMoreLinkedObjectBlockAfter = 1;
9013 $res = @include
dol_buildpath($reldir .
'/' . $tplname .
'.tpl.php');
9021 if (!$nboftypesoutput) {
9022 print
'<tr><td class="impair" colspan="7"><span class="opacitymedium">' . $langs->trans(
"None") .
'</span></td></tr>';
9027 if (!empty($compatibleImportElementsList)) {
9028 $res = @include
dol_buildpath(
'core/tpl/objectlinked_lineimport.tpl.php');
9034 return $nbofdifferenttypes;
9047 global $conf, $langs, $hookmanager;
9051 $linktoelemlist =
'';
9052 $listofidcompanytoscan =
'';
9054 if (!is_object($object->thirdparty)) {
9055 $object->fetch_thirdparty();
9058 $possiblelinks = array();
9059 if (is_object($object->thirdparty) && !empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
9060 $listofidcompanytoscan = $object->thirdparty->id;
9061 if (($object->thirdparty->parent > 0) && !empty($conf->global->THIRDPARTY_INCLUDE_PARENT_IN_LINKTO)) {
9062 $listofidcompanytoscan .=
',' . $object->thirdparty->parent;
9064 if (($object->fk_project > 0) && !empty($conf->global->THIRDPARTY_INCLUDE_PROJECT_THIRDPARY_IN_LINKTO)) {
9065 include_once DOL_DOCUMENT_ROOT .
'/projet/class/project.class.php';
9066 $tmpproject =
new Project($this->db);
9067 $tmpproject->fetch($object->fk_project);
9068 if ($tmpproject->socid > 0 && ($tmpproject->socid != $object->thirdparty->id)) {
9069 $listofidcompanytoscan .=
',' . $tmpproject->socid;
9074 $possiblelinks = array(
9078 'label' =>
'LinkToProposal',
9079 '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') .
')'),
9080 'shipping' => array(
9083 'label' =>
'LinkToExpedition',
9084 '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') .
')'),
9088 'label' =>
'LinkToOrder',
9089 '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') .
')'),
9093 'label' =>
'LinkToInvoice',
9094 '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') .
')'),
9095 'invoice_template' => array(
9098 'label' =>
'LinkToTemplateInvoice',
9099 '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') .
')'),
9103 'label' =>
'LinkToContract',
9104 '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
9105 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'
9107 'fichinter' => array(
9110 'label' =>
'LinkToIntervention',
9111 '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') .
')'),
9112 'supplier_proposal' => array(
9113 'enabled' => (
isModEnabled(
'supplier_proposal') ? $conf->supplier_proposal->enabled : 0),
9115 'label' =>
'LinkToSupplierProposal',
9116 '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') .
')'),
9117 'order_supplier' => array(
9118 'enabled' => (
isModEnabled(
"supplier_order") ? $conf->supplier_order->enabled : 0),
9120 'label' =>
'LinkToSupplierOrder',
9121 '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') .
')'),
9122 'invoice_supplier' => array(
9123 'enabled' => (
isModEnabled(
"supplier_invoice") ? $conf->supplier_invoice->enabled : 0),
9124 'perms' => 1,
'label' =>
'LinkToSupplierInvoice',
9125 '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') .
')'),
9129 'label' =>
'LinkToTicket',
9130 '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') .
')'),
9134 'label' =>
'LinkToMo',
9135 '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') .
')')
9139 if ($object->table_element ==
'commande_fournisseur') {
9140 $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').
')';
9141 } elseif ($object->table_element ==
'mrp_mo') {
9142 $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').
')';
9145 if (!empty($listofidcompanytoscan)) {
9147 $hookmanager->initHooks(array(
'commonobject'));
9148 $parameters = array(
'listofidcompanytoscan' => $listofidcompanytoscan,
'possiblelinks' => $possiblelinks);
9149 $reshook = $hookmanager->executeHooks(
'showLinkToObjectBlock', $parameters, $object, $action);
9152 if (empty($reshook)) {
9153 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
9154 $possiblelinks = array_merge($possiblelinks, $hookmanager->resArray);
9156 } elseif ($reshook > 0) {
9157 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
9158 $possiblelinks = $hookmanager->resArray;
9162 foreach ($possiblelinks as $key => $possiblelink) {
9165 if (empty($possiblelink[
'enabled'])) {
9169 if (!empty($possiblelink[
'perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || !in_array($key, $excludelinksto))) {
9170 print
'<div id="' . $key .
'list"' . (empty($conf->use_javascript_ajax) ?
'' :
' style="display:none"') .
'>';
9172 if (!empty($conf->global->MAIN_LINK_BY_REF_IN_LINKTO)) {
9174 print
'<!-- form to add a link from anywhere -->'.
"\n";
9175 print
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinkedbyref' . $key .
'">';
9176 print
'<input type="hidden" name="id" value="' . $object->id .
'">';
9177 print
'<input type="hidden" name="action" value="addlinkbyref">';
9178 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
9179 print
'<input type="hidden" name="addlink" value="' . $key .
'">';
9180 print
'<table class="noborder">';
9183 print
'<td class="center"><input type="text" placeholder="'.dol_escape_htmltag($langs->trans(
"Ref")).
'" name="reftolinkto" value="' .
dol_escape_htmltag(
GETPOST(
'reftolinkto',
'alpha')) .
'"> ';
9184 print
'<input type="submit" class="button small valignmiddle" value="' . $langs->trans(
'ToLink') .
'"> ';
9185 print
'<input type="submit" class="button small" name="cancel" value="' . $langs->trans(
'Cancel') .
'"></td>';
9191 $sql = $possiblelink[
'sql'];
9193 $resqllist = $this->db->query(
$sql);
9195 $num = $this->db->num_rows($resqllist);
9199 print
'<!-- form to add a link from object to same thirdparty -->'.
"\n";
9200 print
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinked' . $key .
'">';
9201 print
'<input type="hidden" name="action" value="addlink">';
9202 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
9203 print
'<input type="hidden" name="id" value="' . $object->id .
'">';
9204 print
'<input type="hidden" name="addlink" value="' . $key .
'">';
9205 print
'<table class="noborder">';
9206 print
'<tr class="liste_titre">';
9207 print
'<td class="nowrap"></td>';
9208 print
'<td class="center">' . $langs->trans(
"Ref") .
'</td>';
9209 print
'<td class="left">' . $langs->trans(
"RefCustomer") .
'</td>';
9210 print
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
9211 print
'<td class="left">' . $langs->trans(
"Company") .
'</td>';
9214 $objp = $this->db->fetch_object($resqllist);
9216 print
'<tr class="oddeven">';
9217 print
'<td class="left">';
9218 print
'<input type="radio" name="idtolinkto" id="' . $key .
'_' . $objp->rowid .
'" value="' . $objp->rowid .
'">';
9220 print
'<td class="center"><label for="' . $key .
'_' . $objp->rowid .
'">' . $objp->ref .
'</label></td>';
9221 print
'<td>' . (!empty($objp->ref_client) ? $objp->ref_client : (!empty($objp->ref_supplier) ? $objp->ref_supplier :
'')) .
'</td>';
9222 print
'<td class="right">';
9223 if ($possiblelink[
'label'] ==
'LinkToContract') {
9225 print
$form->textwithpicto(
'', $langs->trans(
"InformationOnLinkToContract")) .
' ';
9227 print
'<span class="amount">' . (isset($objp->total_ht) ?
price($objp->total_ht) :
'') .
'</span>';
9229 print
'<td>' . $objp->name .
'</td>';
9234 print
'<div class="center">';
9236 print
'<input type="submit" class="button valignmiddle marginleftonly marginrightonly small" value="' . $langs->trans(
'ToLink') .
'">';
9238 if (empty($conf->use_javascript_ajax)) {
9239 print
'<input type="submit" class="button button-cancel marginleftonly marginrightonly small" name="cancel" value="' . $langs->trans(
"Cancel") .
'"></div>';
9241 print
'<input type="submit" onclick="jQuery(\'#' . $key .
'list\').toggle(); return false;" class="button button-cancel marginleftonly marginrightonly small" name="cancel" value="' . $langs->trans(
"Cancel") .
'"></div>';
9244 $this->db->free($resqllist);
9251 if ($num > 0 || !empty($conf->global->MAIN_LINK_BY_REF_IN_LINKTO)) {
9252 $linktoelemlist .=
'<li><a href="#linkto' . $key .
'" class="linkto dropdowncloseonclick" rel="' . $key .
'">' . $langs->trans($possiblelink[
'label']) .
' (' . $num .
')</a></li>';
9255 $linktoelemlist .=
'<li><span class="linktodisabled">' . $langs->trans($possiblelink[
'label']) .
' (0)</span></li>';
9260 if ($linktoelemlist) {
9262 <dl class="dropdown" id="linktoobjectname">
9264 if (!empty($conf->use_javascript_ajax)) {
9265 $linktoelem .=
'<dt><a href="#linktoobjectname"><span class="fas fa-link paddingrightonly"></span>' . $langs->trans(
"LinkTo") .
'...</a></dt>';
9267 $linktoelem .=
'<dd>
9268 <div class="multiselectlinkto">
9269 <ul class="ulselectedfields">' . $linktoelemlist .
'
9278 if (!empty($conf->use_javascript_ajax)) {
9279 print
'<!-- Add js to show linkto box -->
9280 <script nonce="' .
getNonce() .
'">
9281 jQuery(document).ready(function() {
9282 jQuery(".linkto").click(function() {
9283 console.log("We choose to show/hide links for rel="+jQuery(this).attr(\'rel\')+" so #"+jQuery(this).attr(\'rel\')+"list");
9284 jQuery("#"+jQuery(this).attr(\'rel\')+"list").toggle();
9308 public function selectyesno($htmlname, $value =
'', $option = 0, $disabled =
false, $useempty = 0, $addjscombo = 0, $morecss =
'', $labelyes =
'Yes', $labelno =
'No')
9319 $disabled = ($disabled ?
' disabled' :
'');
9321 $resultyesno =
'<select class="flat width75' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'"' . $disabled .
'>' .
"\n";
9323 $resultyesno .=
'<option value="-1"' . (($value < 0) ?
' selected' :
'') .
'> </option>' .
"\n";
9325 if ((
"$value" ==
'yes') || ($value == 1)) {
9326 $resultyesno .=
'<option value="' . $yes .
'" selected>' . $langs->trans($labelyes) .
'</option>' .
"\n";
9327 $resultyesno .=
'<option value="' . $no .
'">' . $langs->trans($labelno) .
'</option>' .
"\n";
9329 $selected = (($useempty && $value !=
'0' && $value !=
'no') ?
'' :
' selected');
9330 $resultyesno .=
'<option value="' . $yes .
'">' . $langs->trans($labelyes) .
'</option>' .
"\n";
9331 $resultyesno .=
'<option value="' . $no .
'"' . $selected .
'>' . $langs->trans($labelno) .
'</option>' .
"\n";
9333 $resultyesno .=
'</select>' .
"\n";
9336 $resultyesno .=
ajax_combobox($htmlname, array(), 0, 0,
'resolve', ($useempty < 0 ? (
string) $useempty :
'-1'), $morecss);
9339 return $resultyesno;
9356 $sql =
"SELECT rowid, label";
9357 $sql .=
" FROM " . $this->db->prefix() .
"export_model";
9358 $sql .=
" WHERE type = '" . $this->db->escape($type) .
"'";
9359 $sql .=
" ORDER BY rowid";
9360 $result = $this->db->query(
$sql);
9362 print
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
9364 print
'<option value="-1"> </option>';
9367 $num = $this->db->num_rows($result);
9370 $obj = $this->db->fetch_object($result);
9371 if ($selected == $obj->rowid) {
9372 print
'<option value="' . $obj->rowid .
'" selected>';
9374 print
'<option value="' . $obj->rowid .
'">';
9404 public function showrefnav($object, $paramid, $morehtml =
'', $shownav = 1, $fieldid =
'rowid', $fieldref =
'ref', $morehtmlref =
'', $moreparam =
'', $nodbprefix = 0, $morehtmlleft =
'', $morehtmlstatus =
'', $morehtmlright =
'')
9406 global $conf, $langs, $hookmanager, $extralanguages;
9409 if (empty($fieldid)) {
9412 if (empty($fieldref)) {
9418 if (property_exists($object,
'gender') && !empty($object->gender)) {
9419 $addgendertxt =
' ';
9420 switch ($object->gender) {
9422 $addgendertxt .=
'<i class="fas fa-mars"></i>';
9425 $addgendertxt .=
'<i class="fas fa-venus"></i>';
9428 $addgendertxt .=
'<i class="fas fa-transgender"></i>';
9444 if (is_object($hookmanager)) {
9445 $parameters = array(
'showrefnav' =>
true);
9446 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $object);
9447 $object->next_prev_filter .= $hookmanager->resPrint;
9449 $previous_ref = $next_ref =
'';
9452 $object->load_previous_next_ref((isset($object->next_prev_filter) ? $object->next_prev_filter :
''), $fieldid, $nodbprefix);
9454 $navurl = $_SERVER[
"PHP_SELF"];
9456 if ($paramid ==
'project_ref') {
9457 if (preg_match(
'/\/tasks\/(task|contact|note|document)\.php/', $navurl)) {
9458 $navurl = preg_replace(
'/\/tasks\/(task|contact|time|note|document)\.php/',
'/tasks.php', $navurl);
9465 $stringforfirstkey = $langs->trans(
"KeyboardShortcut");
9466 if ($conf->browser->name ==
'chrome') {
9467 $stringforfirstkey .=
' ALT +';
9468 } elseif ($conf->browser->name ==
'firefox') {
9469 $stringforfirstkey .=
' ALT + SHIFT +';
9471 $stringforfirstkey .=
' CTL +';
9474 $previous_ref = $object->ref_previous ?
'<a accesskey="p" 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>';
9475 $next_ref = $object->ref_next ?
'<a accesskey="n" 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>';
9479 $ret .=
'<!-- Start banner content --><div style="vertical-align: middle">';
9482 if ($morehtmlright) {
9483 $ret .=
'<div class="inline-block floatleft">' . $morehtmlright .
'</div>';
9486 if ($previous_ref || $next_ref || $morehtml) {
9487 $ret .=
'<div class="pagination paginationref"><ul class="right">';
9490 $ret .=
'<li class="noborder litext' . (($shownav && $previous_ref && $next_ref) ?
' clearbothonsmartphone' :
'') .
'">' . $morehtml .
'</li>';
9492 if ($shownav && ($previous_ref || $next_ref)) {
9493 $ret .=
'<li class="pagination">' . $previous_ref .
'</li>';
9494 $ret .=
'<li class="pagination">' . $next_ref .
'</li>';
9496 if ($previous_ref || $next_ref || $morehtml) {
9497 $ret .=
'</ul></div>';
9500 $parameters = array();
9501 $reshook = $hookmanager->executeHooks(
'moreHtmlStatus', $parameters, $object);
9502 if (empty($reshook)) {
9503 $morehtmlstatus .= $hookmanager->resPrint;
9505 $morehtmlstatus = $hookmanager->resPrint;
9507 if ($morehtmlstatus) {
9508 $ret .=
'<div class="statusref">' . $morehtmlstatus .
'</div>';
9511 $parameters = array();
9512 $reshook = $hookmanager->executeHooks(
'moreHtmlRef', $parameters, $object);
9513 if (empty($reshook)) {
9514 $morehtmlref .= $hookmanager->resPrint;
9515 } elseif ($reshook > 0) {
9516 $morehtmlref = $hookmanager->resPrint;
9520 if ($morehtmlleft) {
9521 if ($conf->browser->layout ==
'phone') {
9522 $ret .=
'<!-- morehtmlleft --><div class="floatleft">' . $morehtmlleft .
'</div>';
9524 $ret .=
'<!-- morehtmlleft --><div class="inline-block floatleft">' . $morehtmlleft .
'</div>';
9529 $ret .=
'<div class="inline-block floatleft valignmiddle maxwidth750 marginbottomonly refid' . (($shownav && ($previous_ref || $next_ref)) ?
' refidpadding' :
'') .
'">';
9532 if ($object->element ==
'societe') {
9536 $arrayoflangcode = array();
9537 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE)) {
9538 $arrayoflangcode[] = $conf->global->PDF_USE_ALSO_LANGUAGE_CODE;
9541 if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
9542 if (!is_object($extralanguages)) {
9543 include_once DOL_DOCUMENT_ROOT .
'/core/class/extralanguages.class.php';
9546 $extralanguages->fetch_name_extralanguages(
'societe');
9548 if (!empty($extralanguages->attributes[
'societe'][
'name'])) {
9549 $object->fetchValuesForExtraLanguages();
9553 foreach ($arrayoflangcode as $extralangcode) {
9555 if ($object->array_languages[
'name'][$extralangcode]) {
9556 $htmltext .= $object->array_languages[
'name'][$extralangcode];
9558 $htmltext .=
'<span class="opacitymedium">' . $langs->trans(
"SwitchInEditModeToAddTranslation") .
'</span>';
9561 $ret .=
'<!-- Show translations of name -->' .
"\n";
9562 $ret .= $this->
textwithpicto(
'', $htmltext, -1,
'language',
'opacitymedium paddingleft');
9565 } elseif ($object->element ==
'member') {
9566 $ret .= $object->ref .
'<br>';
9567 $fullname = $object->getFullName($langs);
9568 if ($object->morphy ==
'mor' && $object->societe) {
9569 $ret .=
dol_htmlentities($object->societe) . ((!empty($fullname) && $object->societe != $fullname) ?
' (' .
dol_htmlentities($fullname) . $addgendertxt .
')' :
'');
9571 $ret .=
dol_htmlentities($fullname) . $addgendertxt . ((!empty($object->societe) && $object->societe != $fullname) ?
' (' .
dol_htmlentities($object->societe) .
')' :
'');
9573 } elseif (in_array($object->element, array(
'contact',
'user'))) {
9575 } elseif ($object->element ==
'usergroup') {
9577 } elseif (in_array($object->element, array(
'action',
'agenda'))) {
9578 $ret .= $object->ref .
'<br>' . $object->label;
9579 } elseif (in_array($object->element, array(
'adherent_type'))) {
9580 $ret .= $object->label;
9581 } elseif ($object->element ==
'ecm_directories') {
9583 } elseif ($fieldref !=
'none') {
9584 $ret .=
dol_htmlentities(!empty($object->$fieldref) ? $object->$fieldref :
"");
9588 if (substr($morehtmlref, 0, 4) !=
'<div') {
9592 $ret .= $morehtmlref;
9597 $ret .=
'</div><!-- End banner content -->';
9616 if (empty($object->barcode)) {
9621 if (empty($object->barcode_type_code) || empty($object->barcode_type_coder)) {
9622 $result = $object->fetch_barcode();
9625 return '<!-- ErrorFetchBarcode -->';
9630 $url = DOL_URL_ROOT .
'/viewimage.php?modulepart=barcode&generator=' . urlencode($object->barcode_type_coder) .
'&code=' . urlencode($object->barcode) .
'&encoding=' . urlencode($object->barcode_type_code);
9631 $out =
'<!-- url barcode = ' . $url .
' -->';
9632 $out .=
'<img src="' . $url .
'"' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
'>';
9653 public static function showphoto($modulepart, $object, $width = 100, $height = 0, $caneditfield = 0, $cssclass =
'photowithmargin', $imagesize =
'', $addlinktofullsize = 1, $cache = 0, $forcecapture =
'', $noexternsourceoverwrite = 0)
9655 global $conf, $langs;
9657 $entity = (!empty($object->entity) ? $object->entity : $conf->entity);
9658 $id = (!empty($object->id) ? $object->id : $object->rowid);
9667 if ($modulepart ==
'societe') {
9668 $dir = $conf->societe->multidir_output[$entity];
9669 if (!empty($object->logo)) {
9671 if ((
string) $imagesize ==
'mini') {
9673 } elseif ((
string) $imagesize ==
'small') {
9676 $file =
get_exdir(0, 0, 0, 0, $object,
'thirdparty') .
'logos/' . $object->logo;
9678 $originalfile =
get_exdir(0, 0, 0, 0, $object,
'thirdparty') .
'logos/' . $object->logo;
9681 $email = $object->email;
9682 } elseif ($modulepart ==
'contact') {
9683 $dir = $conf->societe->multidir_output[$entity] .
'/contact';
9684 if (!empty($object->photo)) {
9686 if ((
string) $imagesize ==
'mini') {
9688 } elseif ((
string) $imagesize ==
'small') {
9691 $file =
get_exdir(0, 0, 0, 0, $object,
'contact') .
'photos/' . $object->photo;
9693 $originalfile =
get_exdir(0, 0, 0, 0, $object,
'contact') .
'photos/' . $object->photo;
9696 $email = $object->email;
9698 } elseif ($modulepart ==
'userphoto') {
9699 $dir = $conf->user->dir_output;
9700 if (!empty($object->photo)) {
9702 if ((
string) $imagesize ==
'mini') {
9704 } elseif ((
string) $imagesize ==
'small') {
9707 $file =
get_exdir(0, 0, 0, 0, $object,
'user') .
'photos/' . $object->photo;
9709 $originalfile =
get_exdir(0, 0, 0, 0, $object,
'user') .
'photos/' . $object->photo;
9712 if (!empty($conf->global->MAIN_OLD_IMAGE_LINKS)) {
9713 $altfile = $object->id .
".jpg";
9715 $email = $object->email;
9717 } elseif ($modulepart ==
'memberphoto') {
9718 $dir = $conf->adherent->dir_output;
9719 if (!empty($object->photo)) {
9721 if ((
string) $imagesize ==
'mini') {
9723 } elseif ((
string) $imagesize ==
'small') {
9726 $file =
get_exdir(0, 0, 0, 0, $object,
'member') .
'photos/' . $object->photo;
9728 $originalfile =
get_exdir(0, 0, 0, 0, $object,
'member') .
'photos/' . $object->photo;
9731 if (!empty($conf->global->MAIN_OLD_IMAGE_LINKS)) {
9732 $altfile = $object->id .
".jpg";
9734 $email = $object->email;
9738 $dir = $conf->$modulepart->dir_output;
9739 if (!empty($object->photo)) {
9741 if ((
string) $imagesize ==
'mini') {
9743 } elseif ((
string) $imagesize ==
'small') {
9746 $file =
get_exdir($id, 2, 0, 0, $object, $modulepart) .
'photos/' . $object->photo;
9748 $originalfile =
get_exdir($id, 2, 0, 0, $object, $modulepart) .
'photos/' . $object->photo;
9751 if (!empty($conf->global->MAIN_OLD_IMAGE_LINKS)) {
9752 $altfile = $object->id .
".jpg";
9754 $email = $object->email;
9757 if ($forcecapture) {
9758 $capture = $forcecapture;
9762 if ($file && file_exists($dir .
"/" . $file)) {
9763 if ($addlinktofullsize) {
9766 $ret .=
'<a href="' . $urladvanced .
'">';
9768 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
9771 $ret .=
'<img alt="Photo" 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 .
'">';
9772 if ($addlinktofullsize) {
9775 } elseif ($altfile && file_exists($dir .
"/" . $altfile)) {
9776 if ($addlinktofullsize) {
9779 $ret .=
'<a href="' . $urladvanced .
'">';
9781 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
9784 $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 .
'">';
9785 if ($addlinktofullsize) {
9789 $nophoto =
'/public/theme/common/nophoto.png';
9790 $defaultimg =
'identicon';
9791 if (in_array($modulepart, array(
'societe',
'userphoto',
'contact',
'memberphoto'))) {
9792 if ($modulepart ==
'societe' || ($modulepart ==
'memberphoto' && !empty($object->morphy) && strpos($object->morphy,
'mor')) !==
false) {
9793 $nophoto =
'company';
9795 $nophoto =
'/public/theme/common/user_anonymous.png';
9796 if (!empty($object->gender) && $object->gender ==
'man') {
9797 $nophoto =
'/public/theme/common/user_man.png';
9799 if (!empty($object->gender) && $object->gender ==
'woman') {
9800 $nophoto =
'/public/theme/common/user_woman.png';
9805 if (
isModEnabled(
'gravatar') && $email && empty($noexternsourceoverwrite)) {
9807 $ret .=
'<!-- Put link to gravatar -->';
9808 $ret .=
'<img class="photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" title="' . $email .
' Gravatar avatar" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="https://www.gravatar.com/avatar/' . md5(strtolower(trim($email))) .
'?s=' . $width .
'&d=' . $defaultimg .
'">';
9810 if ($nophoto ==
'company') {
9811 $ret .=
'<div class="divforspanimg photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
'>' .
img_picto(
'',
'company') .
'</div>';
9812 $ret .=
'<div class="difforspanimgright"></div>';
9814 $ret .=
'<img class="photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="' . DOL_URL_ROOT . $nophoto .
'">';
9819 if ($caneditfield) {
9820 if ($object->photo) {
9823 $ret .=
'<table class="nobordernopadding centpercent">';
9824 if ($object->photo) {
9825 $ret .=
'<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> <label for="photodelete">' . $langs->trans(
"Delete") .
'</label><br><br></td></tr>';
9827 $ret .=
'<tr><td class="tdoverflow">';
9829 $maxmin = $maxfilesizearray[
'maxmin'];
9831 $ret .=
'<input type="hidden" name="MAX_FILE_SIZE" value="' . ($maxmin * 1024) .
'">';
9833 $ret .=
'<input type="file" class="flat maxwidth200onsmartphone" name="photo" id="photoinput" accept="image/*"' . ($capture ?
' capture="' . $capture .
'"' :
'') .
'>';
9834 $ret .=
'</td></tr>';
9838 dol_print_error(
'',
'Call of showphoto with wrong parameters modulepart=' . $modulepart);
9862 public function select_dolgroups($selected =
'', $htmlname =
'groupid', $show_empty = 0, $exclude =
'', $disabled = 0, $include =
'', $enableonly =
'', $force_entity =
'0', $multiple =
false, $morecss =
'')
9865 global $conf, $user, $langs;
9868 $excludeGroups =
null;
9869 if (is_array($exclude)) {
9870 $excludeGroups = implode(
",", $exclude);
9873 $includeGroups =
null;
9874 if (is_array($include)) {
9875 $includeGroups = implode(
",", $include);
9878 if (!is_array($selected)) {
9879 $selected = array($selected);
9885 $sql =
"SELECT ug.rowid, ug.nom as name";
9886 if (
isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
9887 $sql .=
", e.label";
9889 $sql .=
" FROM " . $this->db->prefix() .
"usergroup as ug ";
9890 if (
isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
9891 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid=ug.entity";
9892 if ($force_entity) {
9893 $sql .=
" WHERE ug.entity IN (0, " . $force_entity .
")";
9895 $sql .=
" WHERE ug.entity IS NOT NULL";
9898 $sql .=
" WHERE ug.entity IN (0, " . $conf->entity .
")";
9900 if (is_array($exclude) && $excludeGroups) {
9901 $sql .=
" AND ug.rowid NOT IN (" . $this->db->sanitize($excludeGroups) .
")";
9903 if (is_array($include) && $includeGroups) {
9904 $sql .=
" AND ug.rowid IN (" . $this->db->sanitize($includeGroups) .
")";
9906 $sql .=
" ORDER BY ug.nom ASC";
9908 dol_syslog(get_class($this) .
"::select_dolgroups", LOG_DEBUG);
9909 $resql = $this->db->query(
$sql);
9912 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
9914 $out .=
'<select class="flat minwidth200' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
9916 $num = $this->db->num_rows($resql);
9919 if ($show_empty && !$multiple) {
9920 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'> </option>' .
"\n";
9924 $obj = $this->db->fetch_object($resql);
9926 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
9930 $out .=
'<option value="' . $obj->rowid .
'"';
9932 $out .=
' disabled';
9934 if ((isset($selected[0]) && is_object($selected[0]) && $selected[0]->
id == $obj->rowid) || ((!isset($selected[0]) || !is_object($selected[0])) && !empty($selected) && in_array($obj->rowid, $selected))) {
9935 $out .=
' selected';
9940 if (
isModEnabled(
'multicompany') && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1) {
9941 $out .=
" (" . $obj->label .
")";
9944 $out .=
'</option>';
9949 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'></option>' .
"\n";
9951 $out .=
'<option value="" disabled>' . $langs->trans(
"NoUserGroupDefined") .
'</option>';
9953 $out .=
'</select>';
9972 $out =
'<div class="nowraponall">';
9973 if ($pos ==
'left') {
9974 $out .=
'<button type="submit" class="liste_titre button_search reposition" name="button_search_x" value="x"><span class="fa fa-search"></span></button>';
9975 $out .=
'<button type="submit" class="liste_titre button_removefilter reposition" name="button_removefilter_x" value="x"><span class="fa fa-remove"></span></button>';
9977 $out .=
'<button type="submit" class="liste_titre button_search reposition" name="button_search_x" value="x"><span class="fa fa-search"></span></button>';
9978 $out .=
'<button type="submit" class="liste_titre button_removefilter reposition" name="button_removefilter_x" value="x"><span class="fa fa-remove"></span></button>';
9993 public function showCheckAddButtons($cssclass =
'checkforaction', $calljsfunction = 0, $massactionname =
"massaction")
9995 global $conf, $langs;
9999 if (!empty($conf->use_javascript_ajax)) {
10000 $out .=
'<div class="inline-block checkallactions"><input type="checkbox" id="' . $cssclass .
's" name="' . $cssclass .
's" class="checkallactions"></div>';
10002 $out .=
'<script nonce="' .
getNonce() .
'">
10003 $(document).ready(function() {
10004 $("#' . $cssclass .
's").click(function() {
10005 if($(this).is(\':checked\')){
10006 console.log("We check all ' . $cssclass .
' and trigger the change method");
10007 $(".' . $cssclass .
'").prop(\'checked\', true).trigger(\'change\');
10011 console.log("We uncheck all");
10012 $(".' . $cssclass .
'").prop(\'checked\', false).trigger(\'change\');
10014 if ($calljsfunction) {
10015 $out .=
'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0, "' . $massactionname .
'", "' . $cssclass .
'"); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }';
10018 $(".' . $cssclass .
'").change(function() {
10019 $(this).closest("tr").toggleClass("highlight", this.checked);
10039 if ($addcheckuncheckall) {
10058 public function selectExpenseCategories($selected =
'', $htmlname =
'fk_c_exp_tax_cat', $useempty = 0, $excludeid = array(), $target =
'', $default_selected = 0, $params = array(), $info_admin = 1)
10060 global $langs, $user;
10063 $sql =
"SELECT rowid, label FROM " . $this->db->prefix() .
"c_exp_tax_cat WHERE active = 1";
10064 $sql .=
" AND entity IN (0," .
getEntity(
'exp_tax_cat') .
")";
10065 if (!empty($excludeid)) {
10066 $sql .=
" AND rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeid)) .
")";
10068 $sql .=
" ORDER BY label";
10070 $resql = $this->db->query(
$sql);
10072 $out =
'<select id="select_' . $htmlname .
'" name="' . $htmlname .
'" class="' . $htmlname .
' flat minwidth75imp maxwidth200">';
10074 $out .=
'<option value="0"> </option>';
10077 while ($obj = $this->db->fetch_object($resql)) {
10078 $out .=
'<option ' . ($selected == $obj->rowid ?
'selected="selected"' :
'') .
' value="' . $obj->rowid .
'">' . $langs->trans($obj->label) .
'</option>';
10080 $out .=
'</select>';
10083 if (!empty($htmlname) && $user->admin && $info_admin) {
10084 $out .=
' ' .
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
10087 if (!empty($target)) {
10088 $sql =
"SELECT c.id FROM " . $this->db->prefix() .
"c_type_fees as c WHERE c.code = 'EX_KME' AND c.active = 1";
10089 $resql = $this->db->query(
$sql);
10091 if ($this->db->num_rows($resql) > 0) {
10092 $obj = $this->db->fetch_object($resql);
10093 $out .=
'<script nonce="' .
getNonce() .
'">
10095 $("select[name=' . $target .
']").on("change", function() {
10096 var current_val = $(this).val();
10097 if (current_val == ' . $obj->id .
') {';
10098 if (!empty($default_selected) || !empty($selected)) {
10099 $out .=
'$("select[name=' . $htmlname .
']").val("' . ($default_selected > 0 ? $default_selected : $selected) .
'");';
10103 $("select[name=' . $htmlname .
']").change();
10107 $("select[name=' . $htmlname .
']").change(function() {
10109 if ($("select[name=' . $target .
']").val() == ' . $obj->id .
') {
10110 // get price of kilometer to fill the unit price
10114 data: { fk_c_exp_tax_cat: $(this).val(), token: \'' .
currentToken() .
'\' },
10115 url:
"' . (DOL_URL_ROOT . '/expensereport/ajax/ajaxik.php?' . join('&', $params)) . '",
10116 }).done(
function( data, textStatus, jqXHR ) {
10118 if (typeof data.up !=
"undefined") {
10119 $(
"input[name=value_unit]").val(data.up);
10120 $(
"select[name=' . $htmlname . ']").attr(
"title", data.title);
10122 $(
"input[name=value_unit]").val(
"");
10123 $(
"select[name=' . $htmlname . ']").attr(
"title",
"");
10134 dol_print_error($this->db);
10148 public function selectExpenseRanges($selected = '', $htmlname = 'fk_range
', $useempty = 0)
10150 global $conf, $langs;
10153 $sql = "SELECT rowid, range_ik FROM " . $this->db->prefix() . "c_exp_tax_range";
10154 $sql .= " WHERE entity = " . $conf->entity . " AND active = 1";
10156 $resql = $this->db->query($sql);
10158 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
10160 $out .= '<option value=
"0"></option>
';
10163 while ($obj = $this->db->fetch_object($resql)) {
10164 $out .= '<option
' . ($selected == $obj->rowid ? 'selected=
"selected"' : '') . ' value=
"' . $obj->rowid . '">
' . price($obj->range_ik, 0, $langs, 1, 0) . '</option>
';
10166 $out .= '</select>
';
10168 dol_print_error($this->db);
10184 public function selectExpense($selected = '', $htmlname = 'fk_c_type_fees
', $useempty = 0, $allchoice = 1, $useid = 0)
10189 $sql = "SELECT id, code, label FROM " . $this->db->prefix() . "c_type_fees";
10190 $sql .= " WHERE active = 1";
10192 $resql = $this->db->query($sql);
10194 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
10196 $out .= '<option value=
"0"></option>
';
10199 $out .= '<option value=
"-1">
' . $langs->trans('AllExpenseReport
') . '</option>
';
10207 while ($obj = $this->db->fetch_object($resql)) {
10208 $key = $langs->trans($obj->code);
10209 $out .= '<option
' . ($selected == $obj->{$field} ? 'selected=
"selected"' : '') . ' value=
"' . $obj->{$field} . '">
' . ($key != $obj->code ? $key : $obj->label) . '</option>
';
10211 $out .= '</select>
';
10213 dol_print_error($this->db);
10237 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)
10239 global $user, $conf, $langs;
10241 require_once DOL_DOCUMENT_ROOT . '/projet/
class/project.class.php
';
10243 if (is_null($usertofilter)) {
10244 $usertofilter = $user;
10249 $hideunselectables = false;
10250 if (!empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) {
10251 $hideunselectables = true;
10254 if (empty($projectsListId)) {
10255 if (empty($usertofilter->rights->projet->all->lire)) {
10256 $projectstatic = new Project($this->db);
10257 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1);
10261 // Search all projects
10262 $sql = "SELECT f.rowid, f.ref as fref, 'nolabel
' as flabel, p.rowid as pid, f.ref,
10263 p.title, p.fk_soc, p.fk_statut, p.public,";
10264 $sql .= ' s.nom as
name';
10265 $sql .= ' FROM
' . $this->db->prefix() . 'projet as p
';
10266 $sql .= ' LEFT JOIN
' . $this->db->prefix() . 'societe as s ON s.rowid = p.fk_soc,
';
10267 $sql .= ' ' . $this->db->prefix() . 'facture as f
';
10268 $sql .= " WHERE p.entity IN (" . getEntity('project
') . ")";
10269 $sql .= " AND f.fk_projet = p.rowid AND f.fk_statut=0"; //Brouillons seulement
10270 //if ($projectsListId) $sql.= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")";
10271 //if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
10272 //if ($socid > 0) $sql.= " AND (p.fk_soc=".((int) $socid)." OR p.fk_soc IS NULL)";
10273 $sql .= " ORDER BY p.ref, f.ref ASC";
10275 $resql = $this->db->query($sql);
10277 // Use select2 selector
10278 if (!empty($conf->use_javascript_ajax)) {
10279 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
10280 $comboenhancement = ajax_combobox($htmlname, '', 0, $forcefocus);
10281 $out .= $comboenhancement;
10282 $morecss = 'minwidth200imp maxwidth500
';
10285 if (empty($option_only)) {
10286 $out .= '<select
class=
"valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled=
"disabled"' : '') . ' id=
"' . $htmlname . '" name=
"' . $htmlname . '">
';
10288 if (!empty($show_empty)) {
10289 $out .= '<option value=
"0" class=
"optiongrey">
';
10290 if (!is_numeric($show_empty)) {
10291 $out .= $show_empty;
10295 $out .= '</option>
';
10297 $num = $this->db->num_rows($resql);
10300 while ($i < $num) {
10301 $obj = $this->db->fetch_object($resql);
10302 // 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.
10303 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && empty($usertofilter->rights->societe->lire)) {
10306 if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) {
10313 if ($showproject == 'all
') {
10314 $labeltoshow .= dol_trunc($obj->ref, 18); // Invoice ref
10316 $labeltoshow .= ' -
' . $obj->name; // Soc name
10320 if ($obj->fk_statut == Project::STATUS_DRAFT) {
10322 $labeltoshow .= ' -
' . $langs->trans("Draft");
10323 } elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
10324 if ($discard_closed == 2) {
10327 $labeltoshow .= ' -
' . $langs->trans("Closed");
10328 } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
10330 $labeltoshow .= ' -
' . $langs->trans("LinkedToAnotherCompany");
10334 if (!empty($selected) && $selected == $obj->rowid) {
10335 $out .= '<option value=
"' . $obj->rowid . '" selected
';
10336 //if ($disabled) $out.=' disabled
'; // with select2, field can't be preselected
if disabled
10337 $out .=
'>' . $labeltoshow .
'</option>';
10339 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
10342 $resultat =
'<option value="' . $obj->rowid .
'"';
10344 $resultat .=
' disabled';
10349 $resultat .= $labeltoshow;
10350 $resultat .=
'</option>';
10358 if (empty($option_only)) {
10359 $out .=
'</select>';
10362 $this->db->free($resql);
10384 public function selectInvoiceRec($selected =
'', $htmlname =
'facrecid', $maxlength = 24, $option_only = 0, $show_empty =
'1', $forcefocus = 0, $disabled = 0, $morecss =
'maxwidth500')
10386 global $user, $conf, $langs;
10392 $sql =
'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc';
10394 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'facture_rec as f';
10395 $sql .=
" WHERE f.entity IN (" .
getEntity(
'invoice') .
")";
10396 $sql .=
" ORDER BY f.titre ASC";
10398 $resql = $this->db->query(
$sql);
10401 if (!empty($conf->use_javascript_ajax)) {
10402 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
10403 $comboenhancement =
ajax_combobox($htmlname,
'', 0, $forcefocus);
10404 $out .= $comboenhancement;
10405 $morecss =
'minwidth200imp maxwidth500';
10408 if (empty($option_only)) {
10409 $out .=
'<select class="valignmiddle flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' id="' . $htmlname .
'" name="' . $htmlname .
'">';
10411 if (!empty($show_empty)) {
10412 $out .=
'<option value="0" class="optiongrey">';
10413 if (!is_numeric($show_empty)) {
10414 $out .= $show_empty;
10418 $out .=
'</option>';
10420 $num = $this->db->num_rows($resql);
10422 while ($obj = $this->db->fetch_object($resql)) {
10423 $labeltoshow =
dol_trunc($obj->title, 18);
10426 if (!empty($obj->suspended)) {
10428 $labeltoshow .=
' - ' . $langs->trans(
"Closed");
10432 if (!empty($selected) && $selected == $obj->rowid) {
10433 $out .=
'<option value="' . $obj->rowid .
'" selected';
10435 $out .=
'>' . $labeltoshow .
'</option>';
10437 if ($disabled && ($selected != $obj->rowid)) {
10440 $resultat =
'<option value="' . $obj->rowid .
'"';
10442 $resultat .=
' disabled';
10445 $resultat .= $labeltoshow;
10446 $resultat .=
'</option>';
10452 if (empty($option_only)) {
10453 $out .=
'</select>';
10458 $this->db->free($resql);
10461 $this->errors[] = $this->db->lasterror;
10475 public function searchComponent($arrayofcriterias, $search_component_params, $arrayofinputfieldsalreadyoutput = array(), $search_component_params_hidden =
'')
10479 if ($search_component_params_hidden !=
'' && !preg_match(
'/^\(.*\)$/', $search_component_params_hidden)) {
10480 $search_component_params_hidden =
'(' . $search_component_params_hidden .
')';
10485 $ret .=
'<div class="divadvancedsearchfieldcomp inline-block">';
10486 $ret .=
'<a href="#" class="dropdownsearch-toggle unsetcolor">';
10487 $ret .=
'<span class="fas fa-filter linkobject boxfilter paddingright pictofixedwidth" title="' .
dol_escape_htmltag($langs->trans(
"Filters")) .
'" id="idsubimgproductdistribution"></span>';
10490 $ret .=
'<div class="divadvancedsearchfieldcompinput inline-block minwidth500 maxwidth300onsmartphone">';
10493 $ret .=
'<div name="divsearch_component_params" class="noborderbottom search_component_params inline-block valignmiddle">';
10495 if ($search_component_params_hidden) {
10499 $nbofchars =
dol_strlen($search_component_params_hidden);
10500 $arrayofandtags = array();
10502 $countparenthesis = 0;
10503 while ($i < $nbofchars) {
10504 $char =
dol_substr($search_component_params_hidden, $i, 1);
10506 if ($char ==
'(') {
10507 $countparenthesis++;
10508 } elseif ($char ==
')') {
10509 $countparenthesis--;
10512 if ($countparenthesis == 0) {
10513 $char2 =
dol_substr($search_component_params_hidden, $i+1, 1);
10514 $char3 =
dol_substr($search_component_params_hidden, $i+2, 1);
10515 if ($char ==
'A' && $char2 ==
'N' && $char3 ==
'D') {
10517 $arrayofandtags[] = trim($s);
10529 $arrayofandtags[] = trim($s);
10533 foreach ($arrayofandtags as $tmpkey => $tmpval) {
10534 $errormessage =
'';
10536 if ($errormessage) {
10537 $this->error =
'ERROR in parsing search string: '.$errormessage;
10540 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
10543 $ret .=
'<span class="marginleftonlyshort valignmiddle tagsearch" data-ufilterid="'.($tmpkey+1).
'" data-ufilter="'.
dol_escape_htmltag($tmpval).
'">';
10544 $ret .=
'<span class="tagsearchdelete select2-selection__choice__remove" data-ufilterid="'.($tmpkey+1).
'">x</span> ';
10556 $show_search_component_params_hidden = 1;
10557 if ($show_search_component_params_hidden) {
10558 $ret .=
'<input type="hidden" name="show_search_component_params_hidden" value="1">';
10560 $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%')) -->";
10561 $ret .=
'<input type="hidden" name="search_component_params_hidden" value="' .
dol_escape_htmltag($search_component_params_hidden) .
'">';
10565 foreach ($arrayofcriterias as $criterias) {
10566 foreach ($criterias as $criteriafamilykey => $criteriafamilyval) {
10567 if (in_array(
'search_' . $criteriafamilykey, $arrayofinputfieldsalreadyoutput)) {
10570 if (in_array($criteriafamilykey, array(
'rowid',
'ref_ext',
'entity',
'extraparams'))) {
10573 if (in_array($criteriafamilyval[
'type'], array(
'date',
'datetime',
'timestamp'))) {
10574 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_start">';
10575 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startyear">';
10576 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startmonth">';
10577 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startday">';
10578 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_end">';
10579 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endyear">';
10580 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endmonth">';
10581 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endday">';
10583 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'">';
10590 $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";
10591 $ret .=
'<input type="text" placeholder="' . $langs->trans(
"Search") .
'" name="search_component_params_input" class="noborderbottom search_component_input" value="">';
10597 jQuery(".tagsearchdelete").click(function() {
10598 var filterid = $(this).parents().data("ufilterid");
10599 console.log("We click to delete a criteria nb "+filterid);
10600 // TODO Update the search_component_params_hidden with all data-ufilter except the one delete and post page
10621 global $langs, $user;
10625 $TModels = array();
10627 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
10628 $formmail =
new FormMail($this->db);
10629 $result = $formmail->fetchAllEMailTemplate($modelType, $user, $langs);
10632 $TModels[0] = $langs->trans(
'DefaultMailModel');
10635 foreach ($formmail->lines_model as $model) {
10636 $TModels[$model->id] = $model->label;
10640 $retstring .=
'<select class="flat" id="select_' . $prefix .
'model_mail" name="' . $prefix .
'model_mail">';
10642 foreach ($TModels as $id_model => $label_model) {
10643 $retstring .=
'<option value="' . $id_model .
'"';
10644 $retstring .=
">" . $label_model .
"</option>";
10647 $retstring .=
"</select>";
10650 $retstring .=
ajax_combobox(
'select_' . $prefix .
'model_mail');
10667 public function buttonsSaveCancel($save_label =
'Save', $cancel_label =
'Cancel', $morebuttons = array(), $withoutdiv = 0, $morecss =
'', $dol_openinpopup =
'')
10671 $buttons = array();
10675 'label_key' => $save_label,
10678 if ($save_label ==
'Create' || $save_label ==
'Add') {
10679 $save[
'name'] =
'add';
10680 } elseif ($save_label ==
'Modify') {
10681 $save[
'name'] =
'edit';
10685 'name' =>
'cancel',
10686 'label_key' =>
'Cancel',
10689 !empty($save_label) ? $buttons[] = $save :
'';
10691 if (!empty($morebuttons)) {
10692 $buttons[] = $morebuttons;
10695 !empty($cancel_label) ? $buttons[] = $cancel :
'';
10697 $retstring = $withoutdiv ?
'' :
'<div class="center">';
10699 foreach ($buttons as $button) {
10700 $addclass = empty($button[
'addclass']) ?
'' : $button[
'addclass'];
10701 $retstring .=
'<input type="submit" class="button button-' . $button[
'name'] . ($morecss ?
' ' . $morecss :
'') .
' ' . $addclass .
'" name="' . $button[
'name'] .
'" value="' .
dol_escape_htmltag($langs->trans($button[
'label_key'])) .
'">';
10703 $retstring .= $withoutdiv ?
'' :
'</div>';
10705 if ($dol_openinpopup) {
10706 $retstring .=
'<!-- buttons are shown into a $dol_openinpopup=' . $dol_openinpopup .
' context, so we enable the close of dialog on cancel -->' .
"\n";
10707 $retstring .=
'<script nonce="' .
getNonce() .
'">';
10708 $retstring .=
'jQuery(".button-cancel").click(function(e) {
10709 e.preventDefault(); console.log(\'We click on cancel in iframe popup ' . $dol_openinpopup .
'\');
10710 window.parent.jQuery(\
'#idfordialog' . $dol_openinpopup .
'\').dialog(\
'close\');
10712 $retstring .=
'</script>';
ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLength=2, $autoselect=0, $ajaxoptions=array(), $moreparams='')
Generic function that return javascript to add to a page to transform a common input field into an au...
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 field into an au...
ajax_event($htmlname, $events)
Add event management script.
Class to manage bank accounts.
Class to manage categories.
Class to manage a WYSIWYG editor.
const STATUS_OPEN_INTERNAL
Warehouse open and only operations for stock transfers/corrections allowed (not for customer shipping...
const STATUS_OPEN_ALL
Warehouse open and any operations are allowed (customer shipping, supplier dispatch,...
const STATUS_CLOSED
Warehouse closed, inactive.
Class to manage invoices.
Class to parse product price expressions.
Class to manage predefined suppliers products.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
currency_name($code_iso, $withcode='', $outputlangs=null)
Return label of currency or code+label.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
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...
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated 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.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
currentToken()
Return the value of token currently saved into session with name 'token'.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0)
Show EMail link formatted for HTML output.
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0)
Format phone numbers according to country.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array(), $allowlink=0)
Clean a string to keep only desirable HTML tags.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
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.
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
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.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
dol_print_url($url, $target='_blank', $max=32, $withpicto=0, $morecss='float')
Show Url link.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier 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...
$formconfirm
if ($action == 'delbookkeepingyear') {
testSqlAndScriptInject($val, $type)
Security: WAF layer for SQL Injection and XSS Injection (scripts) protection (Filters on GET,...
table tableforfield button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
measuringUnitString($unit, $measuring_style='', $scale='', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
$conf db name
Only used if Module[ID]Name translation string is not found.
getMaxFileSizeArray()
Return the max allowed for file upload.
print *****$script_file(".$version.") pid code
! Closing after partial payment: discount_vat, badcustomer or badsupplier, bankcharge,...