71 public $errors = array();
80 public $cache_types_paiements = array();
81 public $cache_conditions_paiements = array();
82 public $cache_transport_mode = array();
83 public $cache_availability = array();
84 public $cache_demand_reason = array();
85 public $cache_types_fees = array();
86 public $cache_vatrates = array();
87 public $cache_invoice_subtype = array();
116 public function editfieldkey($text, $htmlname, $preselected,
$object, $perm, $typeofdata =
'string', $moreparam =
'', $fieldrequired = 0, $notabletag = 0, $paramid =
'id', $help =
'')
123 if (
getDolGlobalString(
'MAIN_USE_JQUERY_JEDITABLE') && !preg_match(
'/^select;/', $typeofdata)) {
125 $tmp = explode(
':', $typeofdata);
126 $ret .=
'<div class="editkey_' . $tmp[0] . (!empty($tmp[1]) ?
' ' . $tmp[1] :
'') .
'" id="' . $htmlname .
'">';
127 if ($fieldrequired) {
128 $ret .=
'<span class="fieldrequired">';
133 $ret .= $langs->trans($text);
135 if ($fieldrequired) {
138 $ret .=
'</div>' .
"\n";
140 if ($fieldrequired) {
141 $ret .=
'<span class="fieldrequired">';
146 $ret .= $langs->trans($text);
148 if ($fieldrequired) {
153 if (empty($notabletag) && $perm) {
154 $ret .=
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
156 if ($fieldrequired) {
157 $ret .=
'<span class="fieldrequired">';
162 $ret .= $langs->trans($text);
164 if ($fieldrequired) {
167 if (!empty($notabletag)) {
170 if (empty($notabletag) && $perm) {
173 if (empty($notabletag) && $perm) {
174 $ret .=
'<td class="right">';
176 if ($htmlname &&
GETPOST(
'action',
'aZ09') !=
'edit' . $htmlname && $perm) {
177 $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>';
179 if (!empty($notabletag) && $notabletag == 1) {
186 if (!empty($notabletag) && $notabletag == 3) {
189 if (empty($notabletag) && $perm) {
192 if (empty($notabletag) && $perm) {
193 $ret .=
'</tr></table>';
223 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 =
'')
225 global
$conf, $langs;
230 if (empty($typeofdata)) {
231 return 'ErrorBadParameter typeofdata is empty';
234 if ($typeofdata ==
'datetime') {
235 $typeofdata =
'dayhour';
238 if (preg_match(
'/^(\w+)\((\d+)\)$/', $typeofdata, $reg)) {
239 if ($reg[1] ==
'varchar') {
240 $typeofdata =
'string';
241 } elseif ($reg[1] ==
'int') {
242 $typeofdata =
'numeric';
244 return 'ErrorBadParameter ' . $typeofdata;
249 if (
getDolGlobalString(
'MAIN_USE_JQUERY_JEDITABLE') && !preg_match(
'/^select;|day|datepicker|dayhour|datehourpicker/', $typeofdata)) {
250 $ret .= $this->
editInPlace(
$object, $value, $htmlname, ($perm ? 1 : 0), $typeofdata, $editvalue, $extObject, $custommsg);
252 if ($editaction ==
'') {
253 $editaction =
GETPOST(
'action',
'aZ09');
255 $editmode = ($editaction ==
'edit' . $htmlname);
257 $ret .=
"<!-- formeditfieldval -->\n";
258 $ret .=
'<form method="post" action="' . $_SERVER[
"PHP_SELF"] . ($moreparam ?
'?' . $moreparam :
'') .
'">';
259 $ret .=
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
260 $ret .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
261 $ret .=
'<input type="hidden" name="' . $paramid .
'" value="' .
$object->id .
'">';
262 if (empty($notabletag)) {
263 $ret .=
'<table class="nobordernopadding centpercent">';
265 if (empty($notabletag)) {
268 if (preg_match(
'/^(string|safehtmlstring|email|phone|url)/', $typeofdata)) {
269 $tmp = explode(
':', $typeofdata);
270 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($editvalue ? $editvalue : $value) .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
271 } elseif (preg_match(
'/^(integer)/', $typeofdata)) {
272 $tmp = explode(
':', $typeofdata);
273 $valuetoshow =
price2num($editvalue ? $editvalue : $value, 0);
274 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $valuetoshow .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
275 } elseif (preg_match(
'/^(numeric|amount)/', $typeofdata)) {
276 $tmp = explode(
':', $typeofdata);
277 $valuetoshow =
price2num($editvalue ? $editvalue : $value);
278 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($valuetoshow !=
'' ?
price($valuetoshow) :
'') .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
279 } elseif (preg_match(
'/^(checkbox)/', $typeofdata)) {
280 $tmp = explode(
':', $typeofdata);
281 $ret .=
'<input type="checkbox" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($value ? $value :
'on') .
'"' . ($value ?
' checked' :
'') . (empty($tmp[1]) ?
'' : $tmp[1]) .
'/>';
282 } elseif (preg_match(
'/^text/', $typeofdata) || preg_match(
'/^note/', $typeofdata)) {
283 $tmp = explode(
':', $typeofdata);
284 $cols = (empty($tmp[2]) ?
'' : $tmp[2]);
286 if (preg_match(
'/%/', $cols)) {
287 $morealt =
' style="width: ' . $cols .
'"';
290 $valuetoshow = ($editvalue ? $editvalue : $value);
291 $ret .=
'<textarea id="' . $htmlname .
'" name="' . $htmlname .
'" wrap="soft" rows="' . (empty($tmp[1]) ?
'20' : $tmp[1]) .
'"' . ($cols ?
' cols="' . $cols .
'"' :
'class="quatrevingtpercent"') . $morealt .
'" autofocus>';
294 $valuetoshow = str_replace(
'&',
'&', $valuetoshow);
296 $ret .=
'</textarea><div class="clearboth"></div>';
297 } elseif ($typeofdata ==
'day' || $typeofdata ==
'datepicker') {
298 $addnowlink = empty($moreoptions[
'addnowlink']) ? 0 : $moreoptions[
'addnowlink'];
299 $adddateof = empty($moreoptions[
'adddateof']) ?
'' : $moreoptions[
'adddateof'];
300 $labeladddateof = empty($moreoptions[
'labeladddateof']) ?
'' : $moreoptions[
'labeladddateof'];
301 $ret .= $this->
selectDate($value, $htmlname, 0, 0, 1,
'form' . $htmlname, 1, $addnowlink, 0,
'',
'', $adddateof,
'', 1, $labeladddateof,
'', $gm);
302 } elseif ($typeofdata ==
'dayhour' || $typeofdata ==
'datehourpicker') {
303 $addnowlink = empty($moreoptions[
'addnowlink']) ? 0 : $moreoptions[
'addnowlink'];
304 $adddateof = empty($moreoptions[
'adddateof']) ?
'' : $moreoptions[
'adddateof'];
305 $labeladddateof = empty($moreoptions[
'labeladddateof']) ?
'' : $moreoptions[
'labeladddateof'];
306 $ret .= $this->
selectDate($value, $htmlname, 1, 1, 1,
'form' . $htmlname, 1, $addnowlink, 0,
'',
'', $adddateof,
'', 1, $labeladddateof,
'', $gm);
307 } elseif (preg_match(
'/^select;/', $typeofdata)) {
308 $arraydata = explode(
',', preg_replace(
'/^select;/',
'', $typeofdata));
309 $arraylist = array();
310 foreach ($arraydata as $val) {
311 $tmp = explode(
':', $val);
312 $tmpkey = str_replace(
'|',
':', $tmp[0]);
313 $arraylist[$tmpkey] = $tmp[1];
315 $ret .= $this->
selectarray($htmlname, $arraylist, $value);
316 } elseif (preg_match(
'/^link/', $typeofdata)) {
318 } elseif (preg_match(
'/^ckeditor/', $typeofdata)) {
319 $tmp = explode(
':', $typeofdata);
320 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
321 $doleditor =
new DolEditor($htmlname, ($editvalue ? $editvalue : $value), (empty($tmp[2]) ?
'' : $tmp[2]), (empty($tmp[3]) ? 100 : (int) $tmp[3]), (empty($tmp[1]) ?
'dolibarr_notes' : $tmp[1]),
'In', (empty($tmp[5]) ? false : (bool) $tmp[5]), (isset($tmp[8]) ? ($tmp[8] ? true :
false) :
true),
true, (empty($tmp[6]) ? 20 : (int) $tmp[6]), (empty($tmp[7]) ?
'100' : $tmp[7]));
322 $ret .= $doleditor->Create(1);
323 } elseif ($typeofdata ==
'asis') {
324 $ret .= ($editvalue ? $editvalue : $value);
326 if (empty($notabletag)) {
331 if (empty($notabletag)) {
335 $ret .=
'<input type="submit" class="smallpaddingimp nomargingtop nomarginbottom button' . (empty($notabletag) ?
'' :
' ') .
'" name="modify" value="' . $langs->trans(
"Modify") .
'">';
336 if (preg_match(
'/ckeditor|textarea/', $typeofdata) && empty($notabletag)) {
337 $ret .=
'<br>' .
"\n";
339 $ret .=
'<input type="submit" class="smallpaddingimp nomargingtop nomarginbottom button button-cancel' . (empty($notabletag) ?
'' :
' ') .
'" name="cancel" value="' . $langs->trans(
"Cancel") .
'">';
340 if (empty($notabletag)) {
344 if (empty($notabletag)) {
345 $ret .=
'</tr></table>' .
"\n";
347 $ret .=
'</form>' .
"\n";
349 if (preg_match(
'/^email/', $typeofdata)) {
351 } elseif (preg_match(
'/^phone/', $typeofdata)) {
353 } elseif (preg_match(
'/^url/', $typeofdata)) {
355 } elseif (preg_match(
'/^(amount|numeric)/', $typeofdata)) {
356 $ret .= ($value !=
'' ?
price($value, 0, $langs, 0, -1, -1,
$conf->currency) :
'');
357 } elseif (preg_match(
'/^checkbox/', $typeofdata)) {
358 $tmp = explode(
':', $typeofdata);
359 $ret .=
'<input type="checkbox" disabled id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $value .
'"' . ($value ?
' checked' :
'') . ($tmp[1] ? $tmp[1] :
'') .
'/>';
360 } elseif (preg_match(
'/^text/', $typeofdata) || preg_match(
'/^note/', $typeofdata)) {
362 } elseif (preg_match(
'/^(safehtmlstring|restricthtml)/', $typeofdata)) {
364 } elseif ($typeofdata ==
'day' || $typeofdata ==
'datepicker') {
365 $ret .=
'<span class="valuedate">' .
dol_print_date($value,
'day', $gm) .
'</span>';
366 } elseif ($typeofdata ==
'dayhour' || $typeofdata ==
'datehourpicker') {
367 $ret .=
'<span class="valuedate">' .
dol_print_date($value,
'dayhour', $gm) .
'</span>';
368 } elseif (preg_match(
'/^select;/', $typeofdata)) {
369 $arraydata = explode(
',', preg_replace(
'/^select;/',
'', $typeofdata));
370 $arraylist = array();
371 foreach ($arraydata as $val) {
372 $tmp = explode(
':', $val);
373 $arraylist[$tmp[0]] = $tmp[1];
375 $ret .= $arraylist[$value];
376 if ($htmlname ==
'fk_product_type') {
378 $ret =
img_picto($langs->trans(
"Product"),
'product',
'class="paddingleftonly paddingrightonly colorgrey"') . $ret;
380 $ret =
img_picto($langs->trans(
"Service"),
'service',
'class="paddingleftonly paddingrightonly colorgrey"') . $ret;
383 } elseif (preg_match(
'/^ckeditor/', $typeofdata)) {
386 $firstline = preg_replace(
'/<br>.*/',
'', $tmpcontent);
387 $firstline = preg_replace(
'/[\n\r].*/',
'', $firstline);
388 $tmpcontent = $firstline . ((strlen($firstline) != strlen($tmpcontent)) ?
'...' :
'');
394 if (empty($moreoptions[
'valuealreadyhtmlescaped'])) {
402 if ($formatfunc && method_exists(
$object, $formatfunc)) {
403 $ret =
$object->$formatfunc($ret);
423 global
$conf, $langs, $extralanguages;
428 $arrayoflangcode = array();
433 if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
434 if (!is_object($extralanguages)) {
435 include_once DOL_DOCUMENT_ROOT .
'/core/class/extralanguages.class.php';
438 $extralanguages->fetch_name_extralanguages(
'societe');
443 if (empty($extralanguages->attributes[
$object->element]) || !is_array($extralanguages->attributes[
$object->element]) || empty($extralanguages->attributes[
$object->element][$fieldname])) {
447 $result .=
'<!-- Widget for translation -->' .
"\n";
448 $result .=
'<div class="inline-block paddingleft image-' .
$object->element .
'-' . $fieldname .
'">';
449 $s =
img_picto($langs->trans(
"ShowOtherLanguages"),
'language',
'', 0, 0, 0,
'',
'fa-15 editfieldlang');
453 $result .=
'<div class="inline-block hidden field-' .
$object->element .
'-' . $fieldname .
'">';
455 $resultforextrlang =
'';
456 foreach ($arrayoflangcode as $langcode) {
457 $valuetoshow = GETPOSTISSET(
'field-' .
$object->element .
"-" . $fieldname .
"-" . $langcode) ?
GETPOST(
'field-' .
$object->element .
'-' . $fieldname .
"-" . $langcode, $check) :
'';
458 if (empty($valuetoshow)) {
459 $object->fetchValuesForExtraLanguages();
461 $valuetoshow =
$object->array_languages[$fieldname][$langcode];
465 $resultforextrlang .= $s;
468 if ($typeofdata ==
'textarea') {
469 $resultforextrlang .=
'<textarea name="field-' .
$object->element .
"-" . $fieldname .
"-" . $langcode .
'" id="' . $fieldname .
"-" . $langcode .
'" class="' . $morecss .
'" rows="' . ROWS_2 .
'" wrap="soft">';
470 $resultforextrlang .= $valuetoshow;
471 $resultforextrlang .=
'</textarea>';
473 $resultforextrlang .=
'<input type="text" class="inputfieldforlang ' . ($morecss ?
' ' . $morecss :
'') .
'" name="field-' .
$object->element .
'-' . $fieldname .
'-' . $langcode .
'" value="' . $valuetoshow .
'">';
476 $result .= $resultforextrlang;
479 $result .=
'<script nonce="' .
getNonce() .
'">$(".image-' .
$object->element .
'-' . $fieldname .
'").click(function() { console.log("Toggle lang widget"); jQuery(".field-' .
$object->element .
'-' . $fieldname .
'").toggle(); });</script>';
498 protected function editInPlace(
$object, $value, $htmlname, $condition, $inputType =
'textarea', $editvalue =
null, $extObject =
null, $custommsg =
null)
503 if (preg_match(
'/^text/', $inputType)) {
505 } elseif (preg_match(
'/^numeric/', $inputType)) {
506 $value =
price($value);
507 } elseif ($inputType ==
'day' || $inputType ==
'datepicker') {
513 $table_element =
false;
517 $ext_element =
false;
518 $button_only =
false;
525 $table_element =
$object->table_element;
529 if (is_object($extObject)) {
530 $ext_element = $extObject->element;
533 if (preg_match(
'/^(string|email|numeric)/', $inputType)) {
534 $tmp = explode(
':', $inputType);
535 $inputType = $tmp[0];
536 if (!empty($tmp[1])) {
537 $inputOption = $tmp[1];
539 if (!empty($tmp[2])) {
540 $savemethod = $tmp[2];
542 $out .=
'<input id="width_' . $htmlname .
'" value="' . $inputOption .
'" type="hidden"/>' .
"\n";
543 } elseif ((preg_match(
'/^day$/', $inputType)) || (preg_match(
'/^datepicker/', $inputType)) || (preg_match(
'/^datehourpicker/', $inputType))) {
544 $tmp = explode(
':', $inputType);
545 $inputType = $tmp[0];
546 if (!empty($tmp[1])) {
547 $inputOption = $tmp[1];
549 if (!empty($tmp[2])) {
550 $savemethod = $tmp[2];
553 $out .=
'<input id="timestamp" type="hidden"/>' .
"\n";
554 } elseif (preg_match(
'/^(select|autocomplete)/', $inputType)) {
555 $tmp = explode(
':', $inputType);
556 $inputType = $tmp[0];
557 $loadmethod = $tmp[1];
558 if (!empty($tmp[2])) {
559 $savemethod = $tmp[2];
561 if (!empty($tmp[3])) {
564 } elseif (preg_match(
'/^textarea/', $inputType)) {
565 $tmp = explode(
':', $inputType);
566 $inputType = $tmp[0];
567 $rows = (empty($tmp[1]) ?
'8' : $tmp[1]);
568 $cols = (empty($tmp[2]) ?
'80' : $tmp[2]);
569 } elseif (preg_match(
'/^ckeditor/', $inputType)) {
570 $tmp = explode(
':', $inputType);
571 $inputType = $tmp[0];
573 if (!empty($tmp[2])) {
576 if (!empty($tmp[3])) {
579 if (!empty($tmp[4])) {
580 $savemethod = $tmp[4];
583 if (isModEnabled(
'fckeditor')) {
584 $out .=
'<input id="ckeditor_toolbar" value="' . $toolbar .
'" type="hidden"/>' .
"\n";
586 $inputType =
'textarea';
590 $out .=
'<input id="element_' . $htmlname .
'" value="' . $element .
'" type="hidden"/>' .
"\n";
591 $out .=
'<input id="table_element_' . $htmlname .
'" value="' . $table_element .
'" type="hidden"/>' .
"\n";
592 $out .=
'<input id="fk_element_' . $htmlname .
'" value="' . $fk_element .
'" type="hidden"/>' .
"\n";
593 $out .=
'<input id="loadmethod_' . $htmlname .
'" value="' . $loadmethod .
'" type="hidden"/>' .
"\n";
594 if (!empty($savemethod)) {
595 $out .=
'<input id="savemethod_' . $htmlname .
'" value="' . $savemethod .
'" type="hidden"/>' .
"\n";
597 if (!empty($ext_element)) {
598 $out .=
'<input id="ext_element_' . $htmlname .
'" value="' . $ext_element .
'" type="hidden"/>' .
"\n";
600 if (!empty($custommsg)) {
601 if (is_array($custommsg)) {
602 if (!empty($custommsg[
'success'])) {
603 $out .=
'<input id="successmsg_' . $htmlname .
'" value="' . $custommsg[
'success'] .
'" type="hidden"/>' .
"\n";
605 if (!empty($custommsg[
'error'])) {
606 $out .=
'<input id="errormsg_' . $htmlname .
'" value="' . $custommsg[
'error'] .
'" type="hidden"/>' .
"\n";
609 $out .=
'<input id="successmsg_' . $htmlname .
'" value="' . $custommsg .
'" type="hidden"/>' .
"\n";
612 if ($inputType ==
'textarea') {
613 $out .=
'<input id="textarea_' . $htmlname .
'_rows" value="' . $rows .
'" type="hidden"/>' .
"\n";
614 $out .=
'<input id="textarea_' . $htmlname .
'_cols" value="' . $cols .
'" type="hidden"/>' .
"\n";
616 $out .=
'<span id="viewval_' . $htmlname .
'" class="viewval_' . $inputType . ($button_only ?
' inactive' :
' active') .
'">' . $value .
'</span>' .
"\n";
617 $out .=
'<span id="editval_' . $htmlname .
'" class="editval_' . $inputType . ($button_only ?
' inactive' :
' active') .
' hideobject">' . (!empty($editvalue) ? $editvalue : $value) .
'</span>' .
"\n";
643 public function textwithtooltip($text, $htmltext, $tooltipon = 1, $direction = 0, $img =
'', $extracss =
'', $notabs = 3, $incbefore =
'', $noencodehtmltext = 0, $tooltiptrigger =
'', $forcenowrap = 0)
646 $text = $incbefore . $text;
651 $direction = (int) $direction;
661 $htmltext = str_replace(array(
"\r",
"\n"),
'', $htmltext);
664 if ($direction < 0) {
665 $extracss = ($extracss ? $extracss :
'') . ($notabs != 3 ?
' inline-block' :
'');
666 $extrastyle =
'padding: 0px; padding-left: 2px;';
668 if ($direction > 0) {
669 $extracss = ($extracss ? $extracss :
'') . ($notabs != 3 ?
' inline-block' :
'');
670 $extrastyle =
'padding: 0px; padding-right: 2px;';
673 $classfortooltip =
'classfortooltip';
678 if ($tooltiptrigger ==
'') {
679 $htmltext = str_replace(
'"',
'"', $htmltext);
681 $classfortooltip =
'classfortooltiponclick';
682 $textfordialog .=
'<div style="display: none;" id="idfortooltiponclick_' . $tooltiptrigger .
'" class="classfortooltiponclicktext">' . $htmltext .
'</div>';
684 if ($tooltipon == 2 || $tooltipon == 3) {
685 $paramfortooltipimg =
' class="' . $classfortooltip . ($notabs != 3 ?
' inline-block' :
'') . ($extracss ?
' ' . $extracss :
'') .
'" style="padding: 0px;' . ($extrastyle ?
' ' . $extrastyle :
'') .
'"';
686 if ($tooltiptrigger ==
'') {
687 $paramfortooltipimg .=
' title="' . ($noencodehtmltext ? $htmltext :
dol_escape_htmltag($htmltext, 1)) .
'"';
689 $paramfortooltipimg .=
' dolid="' . $tooltiptrigger .
'"';
692 $paramfortooltipimg = ($extracss ?
' class="' . $extracss .
'"' :
'') . ($extrastyle ?
' style="' . $extrastyle .
'"' :
'');
694 if ($tooltipon == 1 || $tooltipon == 3) {
695 $paramfortooltiptd =
' class="' . ($tooltipon == 3 ?
'cursorpointer ' :
'') . $classfortooltip . ($tag !=
'td' ?
' inline-block' :
'') . ($extracss ?
' ' . $extracss :
'') .
'" style="padding: 0px;' . ($extrastyle ?
' ' . $extrastyle :
'') .
'" ';
696 if ($tooltiptrigger ==
'') {
697 $paramfortooltiptd .=
' title="' . ($noencodehtmltext ? $htmltext :
dol_escape_htmltag($htmltext, 1)) .
'"';
699 $paramfortooltiptd .=
' dolid="' . $tooltiptrigger .
'"';
702 $paramfortooltiptd = ($extracss ?
' class="' . $extracss .
'"' :
'') . ($extrastyle ?
' style="' . $extrastyle .
'"' :
'');
704 if (empty($notabs)) {
705 $s .=
'<table class="nobordernopadding"><tr style="height: auto;">';
706 } elseif ($notabs == 2) {
707 $s .=
'<div class="inline-block' . ($forcenowrap ?
' nowrap' :
'') .
'">';
710 if ($direction < 0) {
711 $s .=
'<' . $tag . $paramfortooltipimg;
713 $s .=
' class="valigntop" width="14"';
715 $s .=
'>' . $textfordialog . $img .
'</' . $tag .
'>';
719 if ((
string) $text !=
'') {
720 $s .=
'<' . $tag . $paramfortooltiptd .
'>' . $text .
'</' . $tag .
'>';
723 if ($direction > 0) {
724 $s .=
'<' . $tag . $paramfortooltipimg;
726 $s .=
' class="valignmiddle" width="14"';
728 $s .=
'>' . $textfordialog . $img .
'</' . $tag .
'>';
730 if (empty($notabs)) {
731 $s .=
'</tr></table>';
732 } elseif ($notabs == 2) {
753 public function textwithpicto($text, $htmltooltip, $direction = 1, $type =
'help', $extracss =
'valignmiddle', $noencodehtmltext = 0, $notabs = 3, $tooltiptrigger =
'', $forcenowrap = 0)
755 global
$conf, $langs;
760 } elseif ($type ==
'1') {
764 $tooltiptrigger = preg_replace(
'/[^a-z0-9]/i',
'', $tooltiptrigger);
766 if (preg_match(
'/onsmartphone$/', $tooltiptrigger) && empty(
$conf->dol_no_mouse_hover)) {
767 $tooltiptrigger = preg_replace(
'/^.*onsmartphone$/',
'', $tooltiptrigger);
770 if ($tooltiptrigger) {
771 $alt = $langs->transnoentitiesnoconv(
"ClickToShowHelp");
775 if (empty(
$conf->use_javascript_ajax)) {
776 if ($type ==
'info' || $type ==
'infoclickable' || $type ==
'help' || $type ==
'helpclickable') {
785 if (!empty(
$conf->dol_no_mouse_hover) && empty($tooltiptrigger)) {
786 if ($type ==
'info' || $type ==
'infoclickable' || $type ==
'help' || $type ==
'helpclickable') {
797 if ($type ==
'info') {
799 } elseif ($type ==
'help') {
800 $img =
img_help(($tooltiptrigger !=
'' ? 2 : 1), $alt);
801 } elseif ($type ==
'helpclickable') {
802 $img =
img_help(($tooltiptrigger !=
'' ? 2 : 1), $alt);
803 } elseif ($type ==
'superadmin') {
806 } elseif ($type ==
'admin') {
809 } elseif ($type ==
'warning') {
811 } elseif ($type !=
'none') {
816 return $this->
textwithtooltip($text, $htmltooltip, ((($tooltiptrigger && !$img) || strpos($type,
'clickable')) ? 3 : 2), $direction, $img, $extracss, $notabs,
'', $noencodehtmltext, $tooltiptrigger, $forcenowrap);
829 public function selectMassAction($selected, $arrayofaction, $alwaysvisible = 0, $name =
'massaction', $cssclass =
'checkforselect')
831 global
$conf, $langs, $hookmanager;
834 $ret =
'<div class="centpercent center">';
835 $ret .=
'<select class="flat' . (empty(
$conf->use_javascript_ajax) ?
'' :
' hideobject') .
' ' . $name .
' ' . $name .
'select valignmiddle alignstart" id="' . $name .
'" name="' . $name .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
'>';
838 $parameters = array();
839 $reshook = $hookmanager->executeHooks(
'addMoreMassActions', $parameters);
842 if (is_array($arrayofaction) && count($arrayofaction) == 0 && empty($hookmanager->resPrint)) {
845 if (empty($reshook)) {
846 $ret .=
'<option value="0"' . ($disabled ?
' disabled="disabled"' :
'') .
'>-- ' . $langs->trans(
"SelectAction") .
' --</option>';
847 if (is_array($arrayofaction)) {
848 foreach ($arrayofaction as $code => $label) {
849 $ret .=
'<option value="' . $code .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' data-html="' .
dol_escape_htmltag($label) .
'">' . $label .
'</option>';
853 $ret .= $hookmanager->resPrint;
857 if (empty(
$conf->dol_optimize_smallscreen)) {
862 $ret .=
'<input type="submit" name="confirmmassactioninvisible" style="display: none" tabindex="-1">';
863 $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")) .
'">';
866 if (!empty(
$conf->use_javascript_ajax)) {
867 $ret .=
'<!-- JS CODE TO ENABLE mass action select -->
869 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 */
871 atleastoneselected=0;
872 jQuery("."+cssclass).each(function( index ) {
873 /* console.log( index + ": " + $( this ).text() ); */
874 if ($(this).is(\':checked\')) atleastoneselected++;
877 console.log("initCheckForSelect mode="+mode+" name="+name+" cssclass="+cssclass+" atleastoneselected="+atleastoneselected);
879 if (atleastoneselected || ' . ((int) $alwaysvisible) .
')
881 jQuery("."+name).show();
882 ' . ($selected ?
'if (atleastoneselected) { jQuery("."+name+"select").val("' . $selected .
'").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', false); }' :
'') .
'
883 ' . ($selected ?
'if (! atleastoneselected) { jQuery("."+name+"select").val("0").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', true); } ' :
'') .
'
887 jQuery("."+name).hide();
888 jQuery("."+name+"other").hide();
892 jQuery(document).ready(function () {
893 initCheckForSelect(0, "' . $name .
'", "' . $cssclass .
'");
894 jQuery(".' . $cssclass .
'").click(function() {
895 initCheckForSelect(1, "' . $name .
'", "' . $cssclass .
'");
897 jQuery(".' . $name .
'select").change(function() {
898 var massaction = $( this ).val();
899 var urlform = $( this ).closest("form").attr("action").replace("#show_files","");
900 if (massaction == "builddoc") {
901 urlform = urlform + "#show_files";
903 $( this ).closest("form").attr("action", urlform);
904 console.log("we select a mass action name=' . $name .
' massaction="+massaction+" - "+urlform);
905 /* Warning: if you set submit button to disabled, post using Enter will no more work if there is no other button */
906 if ($(this).val() != \'0\') {
907 jQuery(".' . $name .
'confirmed").prop(\'disabled\', false);
908 jQuery(".' . $name .
'other").hide(); /* To disable if another div was open */
909 jQuery(".' . $name .
'"+massaction).show();
911 jQuery(".' . $name .
'confirmed").prop(\'disabled\', true);
912 jQuery(".' . $name .
'other").hide(); /* To disable any div open */
942 public function select_country($selected =
'', $htmlname =
'country_id', $htmloption =
'', $maxlength = 0, $morecss =
'minwidth300', $usecodeaskey =
'', $showempty = 1, $disablefavorites = 0, $addspecialentries = 0, $exclude_country_code = array(), $hideflags = 0, $forcecombo = 0)
945 global
$conf, $langs, $mysoc;
947 $langs->load(
"dict");
950 $countryArray = array();
953 $atleastonefavorite = 0;
955 $sql =
"SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite, eec";
956 $sql .=
" FROM " . $this->db->prefix() .
"c_country";
957 $sql .=
" WHERE active > 0";
960 dol_syslog(get_class($this) .
"::select_country", LOG_DEBUG);
961 $resql = $this->db->query($sql);
963 $out .=
'<select id="select' . $htmlname .
'" class="flat maxwidth200onsmartphone selectcountry' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" ' . $htmloption .
'>';
964 $num = $this->db->num_rows($resql);
968 $obj = $this->db->fetch_object($resql);
970 $countryArray[$i][
'rowid'] = $obj->rowid;
971 $countryArray[$i][
'code_iso'] = $obj->code_iso;
972 $countryArray[$i][
'code_iso3'] = $obj->code_iso3;
973 $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 :
''));
974 $countryArray[$i][
'favorite'] = $obj->favorite;
975 $countryArray[$i][
'eec'] = $obj->eec;
976 $favorite[$i] = $obj->favorite;
981 if (empty($disablefavorites)) {
982 $array1_sort_order = SORT_DESC;
983 $array2_sort_order = SORT_ASC;
984 array_multisort($favorite, $array1_sort_order, $label, $array2_sort_order, $countryArray);
990 if (is_numeric($showempty)) {
991 $out .=
'<option value=""> </option>' .
"\n";
993 $out .=
'<option value="-1">' . $langs->trans($showempty) .
'</option>' .
"\n";
997 if ($addspecialentries) {
999 $out .=
'<option value="special_allnotme"' . ($selected ==
'special_allnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesExceptMe", $langs->transnoentitiesnoconv(
"Country" . $mysoc->country_code)) .
'</option>';
1000 $out .=
'<option value="special_eec"' . ($selected ==
'special_eec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEEC") .
'</option>';
1001 if ($mysoc->isInEEC()) {
1002 $out .=
'<option value="special_eecnotme"' . ($selected ==
'special_eecnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEECExceptMe", $langs->transnoentitiesnoconv(
"Country" . $mysoc->country_code)) .
'</option>';
1004 $out .=
'<option value="special_noteec"' . ($selected ==
'special_noteec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesNotInEEC") .
'</option>';
1005 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1008 foreach ($countryArray as $row) {
1010 if (empty($row[
'rowid'])) {
1013 if (is_array($exclude_country_code) && count($exclude_country_code) && in_array($row[
'code_iso'], $exclude_country_code)) {
1017 if (empty($disablefavorites) && $row[
'favorite'] && $row[
'code_iso']) {
1018 $atleastonefavorite++;
1020 if (empty($row[
'favorite']) && $atleastonefavorite) {
1021 $atleastonefavorite = 0;
1022 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1026 if ($row[
'label']) {
1027 $labeltoshow .=
dol_trunc($row[
'label'], $maxlength,
'middle');
1029 $labeltoshow .=
' ';
1031 if ($row[
'code_iso']) {
1032 $labeltoshow .=
' <span class="opacitymedium">(' . $row[
'code_iso'] .
')</span>';
1033 if (empty($hideflags)) {
1034 $tmpflag =
picto_from_langcode($row[
'code_iso'],
'class="saturatemedium paddingrightonly"', 1);
1035 $labeltoshow = $tmpflag .
' ' . $labeltoshow;
1039 if ($selected && $selected !=
'-1' && ($selected == $row[
'rowid'] || $selected == $row[
'code_iso'] || $selected == $row[
'code_iso3'] || $selected == $row[
'label'])) {
1040 $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']) .
'">';
1042 $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']) .
'">';
1044 $out .= $labeltoshow;
1045 $out .=
'</option>' .
"\n";
1048 $out .=
'</select>';
1054 if (empty($forcecombo)) {
1055 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1056 $out .=
ajax_combobox(
'select' . $htmlname, array(), 0, 0,
'resolve');
1077 public function select_incoterms($selected =
'', $location_incoterms =
'', $page =
'', $htmlname =
'incoterm_id', $htmloption =
'', $forcecombo = 1, $events = array(), $disableautocomplete = 0)
1080 global
$conf, $langs;
1082 $langs->load(
"dict");
1086 $incotermArray = array();
1088 $sql =
"SELECT rowid, code";
1089 $sql .=
" FROM " . $this->db->prefix() .
"c_incoterms";
1090 $sql .=
" WHERE active > 0";
1091 $sql .=
" ORDER BY code ASC";
1093 dol_syslog(get_class($this) .
"::select_incoterm", LOG_DEBUG);
1094 $resql = $this->db->query($sql);
1096 if (
$conf->use_javascript_ajax && !$forcecombo) {
1097 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1101 if (!empty($page)) {
1102 $out .=
'<form method="post" action="' . $page .
'">';
1103 $out .=
'<input type="hidden" name="action" value="set_incoterms">';
1104 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
1107 $out .=
'<select id="' . $htmlname .
'" class="flat selectincoterm width75" name="' . $htmlname .
'" ' . $htmloption .
'>';
1108 $out .=
'<option value="0"> </option>';
1109 $num = $this->db->num_rows($resql);
1113 $obj = $this->db->fetch_object($resql);
1114 $incotermArray[$i][
'rowid'] = $obj->rowid;
1115 $incotermArray[$i][
'code'] = $obj->code;
1119 foreach ($incotermArray as $row) {
1120 if ($selected && ($selected == $row[
'rowid'] || $selected == $row[
'code'])) {
1121 $out .=
'<option value="' . $row[
'rowid'] .
'" selected>';
1123 $out .=
'<option value="' . $row[
'rowid'] .
'">';
1127 $out .= $row[
'code'];
1130 $out .=
'</option>';
1133 $out .=
'</select>';
1136 if (
$conf->use_javascript_ajax && empty($disableautocomplete)) {
1137 $out .=
ajax_multiautocompleter(
'location_incoterms', array(), DOL_URL_ROOT .
'/core/ajax/locationincoterms.php') .
"\n";
1140 $out .=
'<input id="location_incoterms" class="maxwidthonsmartphone type="text" name="location_incoterms" value="' . $location_incoterms .
'">' .
"\n";
1142 if (!empty($page)) {
1143 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp nomargintop nomarginbottom" value="' . $langs->trans(
"Modify") .
'"></form>';
1167 public function select_type_of_lines($selected =
'', $htmlname =
'type', $showempty = 0, $hidetext = 0, $forceall = 0, $morecss =
"", $useajaxcombo = 1)
1173 if ($forceall == 1 || (empty($forceall) && isModEnabled(
"product") && isModEnabled(
"service"))
1174 || (empty($forceall) && !isModEnabled(
'product') && !isModEnabled(
'service'))) {
1175 if (empty($hidetext)) {
1176 print $langs->trans(
"Type").
'...';
1178 print
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
1180 print
'<option value="-1" class="opacitymedium"'.($useajaxcombo ?
'' :
' disabled="disabled"');
1181 if ($selected == -1) {
1185 if (is_numeric($showempty)) {
1193 print
'<option value="0"';
1194 if (0 == $selected || ($selected == -1 &&
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') ==
'product')) {
1197 print
'>' . $langs->trans(
"Product");
1199 print
'<option value="1"';
1200 if (1 == $selected || ($selected == -1 &&
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') ==
'service')) {
1203 print
'>' . $langs->trans(
"Service");
1207 if ($useajaxcombo) {
1212 if ((empty($forceall) && !isModEnabled(
'product') && isModEnabled(
"service")) || $forceall == 3) {
1213 print $langs->trans(
"Service");
1214 print
'<input type="hidden" name="' . $htmlname .
'" value="1">';
1216 if ((empty($forceall) && isModEnabled(
"product") && !isModEnabled(
'service')) || $forceall == 2) {
1217 print $langs->trans(
"Product");
1218 print
'<input type="hidden" name="' . $htmlname .
'" value="0">';
1220 if ($forceall < 0) {
1221 print
'<input type="hidden" name="' . $htmlname .
'" value="1">';
1237 $num = count($this->cache_types_fees);
1244 $langs->load(
"trips");
1246 $sql =
"SELECT c.code, c.label";
1247 $sql .=
" FROM " . $this->db->prefix() .
"c_type_fees as c";
1248 $sql .=
" WHERE active > 0";
1250 $resql = $this->db->query($sql);
1252 $num = $this->db->num_rows($resql);
1256 $obj = $this->db->fetch_object($resql);
1259 $label = ($obj->code != $langs->trans($obj->code) ? $langs->trans($obj->code) : $langs->trans($obj->label));
1260 $this->cache_types_fees[$obj->code] = $label;
1264 asort($this->cache_types_fees);
1286 global $user, $langs;
1288 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
1292 print
'<select id="select_' . $htmlname .
'" class="flat" name="' . $htmlname .
'">';
1294 print
'<option value="-1"';
1295 if ($selected == -1) {
1298 print
'> </option>';
1301 foreach ($this->cache_types_fees as $key => $value) {
1302 print
'<option value="' . $key .
'"';
1303 if ($key == $selected) {
1313 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1342 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)
1345 global
$conf, $langs;
1349 if (!empty(
$conf->use_javascript_ajax) &&
getDolGlobalString(
'COMPANY_USE_SEARCH_TO_SELECT') && !$forcecombo) {
1350 if (is_null($ajaxoptions)) {
1351 $ajaxoptions = array();
1354 require_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1358 if ($selected && empty($selected_input_value)) {
1359 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
1360 $societetmp =
new Societe($this->db);
1361 $societetmp->fetch($selected);
1362 $selected_input_value = $societetmp->name;
1367 $urloption =
'htmlname=' . urlencode((
string) (str_replace(
'.',
'_', $htmlname))) .
'&outjson=1&filter=' . urlencode((
string) ($filter)) . (empty($excludeids) ?
'' :
'&excludeids=' . implode(
',', $excludeids)) . ($showtype ?
'&showtype=' . urlencode((
string) ($showtype)) :
'') . ($showcode ?
'&showcode=' . urlencode((
string) ($showcode)) :
'');
1369 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
1370 if (empty($hidelabel)) {
1371 $out .= $langs->trans(
"RefOrLabel") .
' : ';
1372 } elseif ($hidelabel == 1 && !is_numeric($showempty)) {
1373 $placeholder = $langs->trans($showempty);
1374 } elseif ($hidelabel > 1) {
1375 $placeholder = $langs->trans(
"RefOrLabel");
1376 if ($hidelabel == 2) {
1377 $out .=
img_picto($langs->trans(
"Search"),
'search');
1380 $out .=
'<input type="text" class="' . $morecss .
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . ($placeholder ?
' placeholder="' .
dol_escape_htmltag($placeholder) .
'"' :
'') .
' ' . (
getDolGlobalString(
'THIRDPARTY_SEARCH_AUTOFOCUS') ?
'autofocus' :
'') .
' />';
1381 if ($hidelabel == 3) {
1382 $out .=
img_picto($langs->trans(
"Search"),
'search');
1387 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.
'/societe/ajax/company.php', $urloption,
getDolGlobalInt(
'COMPANY_USE_SEARCH_TO_SELECT'), 0, $ajaxoptions);
1390 $out .= $this->
select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events,
'', 0, $limit, $morecss, $moreparam, $multiple, $excludeids, $showcode);
1424 public function select_contact($socid, $selected =
'', $htmlname =
'contactid', $showempty = 0, $exclude =
'', $limitto =
'', $showfunction = 0, $morecss =
'', $nokeyifsocid =
true, $showsoc = 0, $forcecombo = 0, $events = array(), $moreparam =
'', $htmlid =
'', $selected_input_value =
'', $filter =
'')
1428 global
$conf, $langs;
1433 if ($nokeyifsocid && $socid > 0) {
1434 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = 0;
1437 if (!empty(
$conf->use_javascript_ajax) &&
getDolGlobalString(
'CONTACT_USE_SEARCH_TO_SELECT') && !$forcecombo) {
1438 if (is_null($events)) {
1442 require_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1446 if ($selected && empty($selected_input_value)) {
1447 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
1448 $contacttmp =
new Contact($this->db);
1449 $contacttmp->fetch($selected);
1450 $selected_input_value = $contacttmp->getFullName($langs);
1453 if (!is_numeric($showempty)) {
1454 $placeholder = $showempty;
1458 $urloption =
'htmlname=' . urlencode((
string) (str_replace(
'.',
'_', $htmlname))) .
'&outjson=1&filter=' . urlencode((
string) ($filter)) . (empty($exclude) ?
'' :
'&exclude=' . urlencode($exclude)) . ($showsoc ?
'&showsoc=' . urlencode((
string) ($showsoc)) :
'');
1460 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
1462 $out .=
'<input type="text" class="' . $morecss .
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . ($placeholder ?
' placeholder="' .
dol_escape_htmltag($placeholder) .
'"' :
'') .
' ' . (
getDolGlobalString(
'CONTACT_SEARCH_AUTOFOCUS') ?
'autofocus' :
'') .
' />';
1466 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.
'/contact/ajax/contact.php', $urloption,
getDolGlobalInt(
'CONTACT_USE_SEARCH_TO_SELECT'), 0, $events);
1470 $disableifempty = 0;
1474 $out .= $this->
selectcontacts($socid, $selected, $htmlname, $showempty, $exclude, $limitto, $showfunction, $morecss, $options_only, $showsoc, $forcecombo, $events, $moreparam, $htmlid, $multiple, $disableifempty);
1477 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = $sav;
1509 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)
1512 global $user, $langs;
1513 global $hookmanager;
1515 $langs->loadLangs(array(
"companies",
"suppliers"));
1519 $outarray = array();
1521 if ($selected ===
'') {
1522 $selected = array();
1523 } elseif (!is_array($selected)) {
1524 $selected = array($selected);
1528 if (function_exists(
'testSqlAndScriptInject')) {
1531 return 'SQLInjectionTryDetected';
1535 if ($filter !=
'') {
1536 if (preg_match(
'/[\(\)]/', $filter)) {
1542 if (function_exists(
'testSqlAndScriptInject')) {
1545 return 'SQLInjectionTryDetected';
1551 dol_syslog(
"Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Syntax.", LOG_WARNING);
1556 $sql =
"SELECT s.rowid, s.nom as name, s.name_alias, s.tva_intra, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
1558 $sql .=
", s.address, s.zip, s.town";
1559 $sql .=
", dictp.code as country_code";
1561 $sql .=
" FROM " . $this->db->prefix() .
"societe as s";
1563 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_country as dictp ON dictp.rowid = s.fk_pays";
1565 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1566 $sql .=
", " . $this->db->prefix() .
"societe_commerciaux as sc";
1568 $sql .=
" WHERE s.entity IN (" .
getEntity(
'societe') .
")";
1569 if (!empty($user->socid)) {
1570 $sql .=
" AND s.rowid = " . ((int) $user->socid);
1575 $sql .=
" AND (" . $filter .
")";
1577 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1578 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = " . ((int) $user->id);
1581 $sql .=
" AND s.status <> 0";
1583 if (!empty($excludeids)) {
1584 $sql .=
" AND s.rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeids)) .
")";
1587 $parameters = array();
1588 $reshook = $hookmanager->executeHooks(
'selectThirdpartyListWhere', $parameters);
1589 $sql .= $hookmanager->resPrint;
1591 if ($filterkey && $filterkey !=
'') {
1595 $search_crit = explode(
' ', $filterkey);
1597 if (count($search_crit) > 1) {
1600 foreach ($search_crit as $crit) {
1604 $sql .=
"(s.nom LIKE '" . $this->db->escape($prefix . $crit) .
"%')";
1607 if (count($search_crit) > 1) {
1610 if (isModEnabled(
'barcode')) {
1611 $sql .=
" OR s.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1613 $sql .=
" OR s.code_client LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.code_fournisseur LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1614 $sql .=
" OR s.name_alias LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.tva_intra LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1617 $sql .= $this->db->order(
"nom",
"ASC");
1618 $sql .= $this->db->plimit($limit, 0);
1621 dol_syslog(get_class($this).
"::select_thirdparty_list", LOG_DEBUG);
1622 $resql = $this->db->query($sql);
1625 $out .=
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
' name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
'>' .
"\n";
1627 $textifempty = (($showempty && !is_numeric($showempty)) ? $langs->trans($showempty) :
'');
1631 if ($showempty && !is_numeric($showempty)) {
1632 $textifempty = $langs->trans($showempty);
1634 $textifempty .= $langs->trans(
"All");
1638 $out .=
'<option value="-1" data-html="' .
dol_escape_htmltag(
'<span class="opacitymedium">' . ($textifempty ? $textifempty :
' ') .
'</span>') .
'">' . $textifempty .
'</option>' .
"\n";
1641 $companytemp =
new Societe($this->db);
1643 $num = $this->db->num_rows($resql);
1647 $obj = $this->db->fetch_object($resql);
1650 if (($obj->client) && (!empty($obj->code_client))) {
1651 $label = $obj->code_client .
' - ';
1653 if (($obj->fournisseur) && (!empty($obj->code_fournisseur))) {
1654 $label .= $obj->code_fournisseur .
' - ';
1656 $label .=
' ' . $obj->name;
1658 $label = $obj->name;
1661 if (!empty($obj->name_alias)) {
1662 $label .=
' (' . $obj->name_alias .
')';
1666 $label .=
' - '.$obj->tva_intra;
1669 $labelhtml = $label;
1672 $companytemp->id = $obj->rowid;
1673 $companytemp->client = $obj->client;
1674 $companytemp->fournisseur = $obj->fournisseur;
1675 $tmptype = $companytemp->getTypeUrl(1,
'', 0,
'span');
1677 $labelhtml .=
' ' . $tmptype;
1680 if ($obj->client || $obj->fournisseur) {
1683 if ($obj->client == 1 || $obj->client == 3) {
1684 $label .= $langs->trans(
"Customer");
1686 if ($obj->client == 2 || $obj->client == 3) {
1687 $label .= ($obj->client == 3 ?
', ' :
'') . $langs->trans(
"Prospect");
1689 if ($obj->fournisseur) {
1690 $label .= ($obj->client ?
', ' :
'') . $langs->trans(
"Supplier");
1692 if ($obj->client || $obj->fournisseur) {
1698 $s = ($obj->address ?
' - ' . $obj->address :
'') . ($obj->zip ?
' - ' . $obj->zip :
'') . ($obj->town ?
' ' . $obj->town :
'');
1699 if (!empty($obj->country_code)) {
1700 $s .=
', ' . $langs->trans(
'Country' . $obj->country_code);
1706 if (empty($outputmode)) {
1707 if (in_array($obj->rowid, $selected)) {
1708 $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>';
1710 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
1713 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label,
'labelhtml' => $labelhtml));
1717 if (($i % 10) == 0) {
1722 $out .=
'</select>' .
"\n";
1724 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1731 $this->result = array(
'nbofthirdparties' => $num);
1765 public function selectcontacts($socid, $selected = array(), $htmlname =
'contactid', $showempty = 0, $exclude =
'', $limitto =
'', $showfunction = 0, $morecss =
'', $options_only = 0, $showsoc = 0, $forcecombo = 0, $events = array(), $moreparam =
'', $htmlid =
'', $multiple =
false, $disableifempty = 0, $filter =
'')
1767 global
$conf, $user, $langs, $hookmanager, $action;
1769 $langs->load(
'companies');
1771 if (empty($htmlid)) {
1772 $htmlid = $htmlname;
1776 $outarray = array();
1778 if ($selected ===
'') {
1779 $selected = array();
1780 } elseif (!is_array($selected)) {
1781 $selected = array((
int) $selected);
1785 if (function_exists(
'testSqlAndScriptInject')) {
1788 return 'SQLInjectionTryDetected';
1792 if ($filter !=
'') {
1793 if (preg_match(
'/[\(\)]/', $filter)) {
1799 if (function_exists(
'testSqlAndScriptInject')) {
1802 return 'SQLInjectionTryDetected';
1808 dol_syslog(
"Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Filter Syntax.", LOG_WARNING);
1812 if (!is_object($hookmanager)) {
1813 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
1818 $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";
1819 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
1820 $sql .=
", s.nom as company, s.town AS company_town";
1822 $sql .=
" FROM " . $this->db->prefix() .
"socpeople as sp";
1823 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
1824 $sql .=
" LEFT OUTER JOIN " . $this->db->prefix() .
"societe as s ON s.rowid=sp.fk_soc";
1826 $sql .=
" WHERE sp.entity IN (" .
getEntity(
'contact') .
")";
1827 $sql .=
" AND ((sp.fk_user_creat = ".((int) $user->id).
" AND sp.priv = 1) OR sp.priv = 0)";
1828 if ($socid > 0 || $socid == -1) {
1829 $sql .=
" AND sp.fk_soc = " . ((int) $socid);
1832 $sql .=
" AND sp.statut <> 0";
1837 $sql .=
" AND (" . $filter .
")";
1840 $parameters = array();
1841 $reshook = $hookmanager->executeHooks(
'selectContactListWhere', $parameters);
1842 $sql .= $hookmanager->resPrint;
1843 $sql .=
" ORDER BY sp.lastname ASC";
1845 dol_syslog(get_class($this) .
"::selectcontacts", LOG_DEBUG);
1846 $resql = $this->db->query($sql);
1848 $num = $this->db->num_rows($resql);
1850 if ($htmlname !=
'none' && !$options_only) {
1851 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlid .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . (($num || empty($disableifempty)) ?
'' :
' disabled') . ($multiple ?
'multiple' :
'') .
' ' . (!empty($moreparam) ? $moreparam :
'') .
'>';
1854 if ($showempty && !is_numeric($showempty)) {
1855 $textforempty = $showempty;
1856 $out .=
'<option class="optiongrey" value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'>' . $textforempty .
'</option>';
1858 if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) {
1859 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'> </option>';
1861 if ($showempty == 2) {
1862 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Internal") .
' --</option>';
1868 include_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
1869 $contactstatic =
new Contact($this->db);
1872 $obj = $this->db->fetch_object($resql);
1875 $extendedInfos =
'';
1877 $extendedInfos = array();
1878 $email = trim($obj->email);
1879 if (!empty($email)) {
1880 $extendedInfos[] = $email;
1882 $phone = trim($obj->phone);
1883 $phone_perso = trim($obj->phone_perso);
1884 $phone_mobile = trim($obj->phone_mobile);
1885 if (!empty($phone)) {
1886 $extendedInfos[] = $phone;
1888 if (!empty($phone_perso)) {
1889 $extendedInfos[] = $phone_perso;
1891 if (!empty($phone_mobile)) {
1892 $extendedInfos[] = $phone_mobile;
1895 $contact_town = trim($obj->contact_town);
1896 $company_town = trim($obj->company_town);
1897 if (!empty($contact_town)) {
1898 $extendedInfos[] = $contact_town;
1899 } elseif (!empty($company_town)) {
1900 $extendedInfos[] = $company_town;
1902 $extendedInfos = implode(
' - ', $extendedInfos);
1903 if (!empty($extendedInfos)) {
1904 $extendedInfos =
' - ' . $extendedInfos;
1908 $contactstatic->id = $obj->rowid;
1909 $contactstatic->lastname = $obj->lastname;
1910 $contactstatic->firstname = $obj->firstname;
1911 if ($obj->statut == 1) {
1913 if ($htmlname !=
'none') {
1915 if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) {
1918 if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) {
1921 if (!empty($selected) && in_array($obj->rowid, $selected)) {
1922 $out .=
'<option value="' . $obj->rowid .
'"';
1924 $out .=
' disabled';
1926 $out .=
' selected>';
1928 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1929 if ($showfunction && $obj->poste) {
1930 $tmplabel .=
' (' . $obj->poste .
')';
1932 if (($showsoc > 0) && $obj->company) {
1933 $tmplabel .=
' - (' . $obj->company .
')';
1937 $out .=
'</option>';
1939 $out .=
'<option value="' . $obj->rowid .
'"';
1941 $out .=
' disabled';
1945 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1946 if ($showfunction && $obj->poste) {
1947 $tmplabel .=
' (' . $obj->poste .
')';
1949 if (($showsoc > 0) && $obj->company) {
1950 $tmplabel .=
' - (' . $obj->company .
')';
1954 $out .=
'</option>';
1957 if (in_array($obj->rowid, $selected)) {
1958 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1959 if ($showfunction && $obj->poste) {
1960 $tmplabel .=
' (' . $obj->poste .
')';
1962 if (($showsoc > 0) && $obj->company) {
1963 $tmplabel .=
' - (' . $obj->company .
')';
1970 if ($tmplabel !=
'') {
1971 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $tmplabel,
'label' => $tmplabel,
'labelhtml' => $tmplabel));
1977 $labeltoshow = ($socid != -1) ? ($langs->trans($socid ?
"NoContactDefinedForThirdParty" :
"NoContactDefined")) : $langs->trans(
'SelectAThirdPartyFirst');
1978 $out .=
'<option class="disabled" value="-1"' . (($showempty == 2 || $multiple) ?
'' :
' selected') .
' disabled="disabled">';
1979 $out .= $labeltoshow;
1980 $out .=
'</option>';
1983 $parameters = array(
1985 'htmlname' => $htmlname,
1988 'showfunction' => $showfunction,
1989 'showsoc' => $showsoc,
1992 $reshook = $hookmanager->executeHooks(
'afterSelectContactOptions', $parameters, $this, $action);
1994 if ($htmlname !=
'none' && !$options_only) {
1995 $out .=
'</select>';
1998 if (
$conf->use_javascript_ajax && !$forcecombo && !$options_only) {
1999 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2005 if ($options_only === 2) {
2033 global $langs,
$conf;
2036 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
2037 $sql .=
" re.description, re.fk_facture_source";
2038 $sql .=
" FROM " . $this->db->prefix() .
"societe_remise_except as re";
2039 $sql .=
" WHERE re.fk_soc = " . (int) $socid;
2040 $sql .=
" AND re.entity = " .
$conf->entity;
2042 $sql .=
" AND " . $filter;
2044 $sql .=
" ORDER BY re.description ASC";
2046 dol_syslog(get_class($this) .
"::select_remises", LOG_DEBUG);
2047 $resql = $this->db->query($sql);
2049 print
'<select id="select_' . $htmlname .
'" class="flat maxwidthonsmartphone" name="' . $htmlname .
'">';
2050 $num = $this->db->num_rows($resql);
2052 $qualifiedlines = $num;
2056 print
'<option value="0"> </option>';
2058 $obj = $this->db->fetch_object($resql);
2059 $desc =
dol_trunc($obj->description, 40);
2060 if (preg_match(
'/\(CREDIT_NOTE\)/', $desc)) {
2061 $desc = preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $desc);
2063 if (preg_match(
'/\(DEPOSIT\)/', $desc)) {
2064 $desc = preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"Deposit"), $desc);
2066 if (preg_match(
'/\(EXCESS RECEIVED\)/', $desc)) {
2067 $desc = preg_replace(
'/\(EXCESS RECEIVED\)/', $langs->trans(
"ExcessReceived"), $desc);
2069 if (preg_match(
'/\(EXCESS PAID\)/', $desc)) {
2070 $desc = preg_replace(
'/\(EXCESS PAID\)/', $langs->trans(
"ExcessPaid"), $desc);
2074 if ($selected > 0 && $selected == $obj->rowid) {
2075 $selectstring =
' selected';
2079 if ($maxvalue > 0 && $obj->amount_ttc > $maxvalue) {
2081 $disabled =
' disabled';
2084 if (
getDolGlobalString(
'MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST') && !empty($obj->fk_facture_source)) {
2085 $tmpfac =
new Facture($this->db);
2086 if ($tmpfac->fetch($obj->fk_facture_source) > 0) {
2087 $desc = $desc .
' - ' . $tmpfac->ref;
2091 print
'<option value="' . $obj->rowid .
'"' . $selectstring . $disabled .
'>' . $desc .
' (' .
price($obj->amount_ht) .
' ' . $langs->trans(
"HT") .
' - ' .
price($obj->amount_ttc) .
' ' . $langs->trans(
"TTC") .
')</option>';
2098 return $qualifiedlines;
2123 public function select_users($selected =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include =
'', $enableonly = array(), $force_entity =
'0')
2126 print $this->
select_dolusers($selected, $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity);
2155 public function select_dolusers($selected =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include =
'', $enableonly =
'', $force_entity =
'', $maxlength = 0, $showstatus = 0, $morefilter =
'', $show_every = 0, $enableonlytext =
'', $morecss =
'', $notdisabled = 0, $outputmode = 0, $multiple =
false, $forcecombo = 0)
2158 global
$conf, $user, $langs, $hookmanager;
2162 if ((is_numeric($selected) && ($selected < -2 || empty($selected))) && !
getDolGlobalString(
'SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE')) {
2163 $selected = $user->id;
2166 if ($selected ===
'') {
2167 $selected = array();
2168 } elseif (!is_array($selected)) {
2169 $selected = array($selected);
2172 $excludeUsers =
null;
2173 $includeUsers =
null;
2176 if (is_array($exclude)) {
2177 $excludeUsers = implode(
",", $exclude);
2180 if (is_array($include)) {
2181 $includeUsers = implode(
",", $include);
2182 } elseif ($include ==
'hierarchy') {
2184 $includeUsers = implode(
",", $user->getAllChildIds(0));
2185 } elseif ($include ==
'hierarchyme') {
2187 $includeUsers = implode(
",", $user->getAllChildIds(1));
2193 $outarray = array();
2194 $outarray2 = array();
2197 $showlabelofentity = isModEnabled(
'multicompany') && !
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE') &&
$conf->entity == 1 && !empty($user->admin) && empty($user->entity);
2198 $userissuperadminentityone = isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && empty($user->entity);
2201 $sql =
"SELECT DISTINCT u.rowid, u.lastname as lastname, u.firstname, u.statut as status, u.login, u.admin, u.entity, u.gender, u.photo";
2202 if ($showlabelofentity) {
2203 $sql .=
", e.label";
2205 $sql .=
" FROM " . $this->db->prefix() .
"user as u";
2206 if ($showlabelofentity) {
2207 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid = u.entity";
2210 if ($userissuperadminentityone && $force_entity !==
'default') {
2211 if (!empty($force_entity)) {
2212 $sql .=
" WHERE u.entity IN (0, " . $this->db->sanitize($force_entity) .
")";
2214 $sql .=
" WHERE u.entity IS NOT NULL";
2217 if (isModEnabled(
'multicompany') &&
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE')) {
2218 $sql .=
" WHERE u.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
2220 $sql .=
" WHERE u.entity IN (" .
getEntity(
'user') .
")";
2224 if (!empty($user->socid)) {
2225 $sql .=
" AND u.fk_soc = " . ((int) $user->socid);
2227 if (is_array($exclude) && $excludeUsers) {
2228 $sql .=
" AND u.rowid NOT IN (" . $this->db->sanitize($excludeUsers) .
")";
2230 if ($includeUsers) {
2231 $sql .=
" AND u.rowid IN (" . $this->db->sanitize($includeUsers) .
")";
2234 $sql .=
" AND u.statut <> 0";
2237 $sql .=
" AND u.employee <> 0";
2240 $sql .=
" AND u.fk_soc IS NULL";
2242 if (!empty($morefilter)) {
2245 if ($errormessage) {
2246 $this->errors[] = $errormessage;
2247 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2248 if ($outputmode == 0) {
2249 return 'Error bad param $morefilter';
2257 $reshook = $hookmanager->executeHooks(
'addSQLWhereFilterOnSelectUsers', array(), $this, $action);
2258 if (!empty($reshook)) {
2259 $sql .= $hookmanager->resPrint;
2263 $sql .=
" ORDER BY u.statut DESC, u.firstname ASC, u.lastname ASC";
2265 $sql .=
" ORDER BY u.statut DESC, u.lastname ASC, u.firstname ASC";
2268 dol_syslog(get_class($this) .
"::select_dolusers", LOG_DEBUG);
2270 $resql = $this->db->query($sql);
2272 $num = $this->db->num_rows($resql);
2276 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
' minwidth200') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
2277 if ($show_empty && !$multiple) {
2278 $textforempty =
' ';
2279 if (!empty(
$conf->use_javascript_ajax)) {
2280 $textforempty =
' ';
2282 if (!is_numeric($show_empty)) {
2283 $textforempty = $show_empty;
2285 $out .=
'<option class="optiongrey" value="' . ($show_empty < 0 ? $show_empty : -1) .
'"' . ((empty($selected) || in_array(-1, $selected)) ?
' selected' :
'') .
'>' . $textforempty .
'</option>' .
"\n";
2287 $outarray[($show_empty < 0 ? $show_empty : -1)] = $textforempty;
2288 $outarray2[($show_empty < 0 ? $show_empty : -1)] = array(
2289 'id' => ($show_empty < 0 ? $show_empty : -1),
2290 'label' => $textforempty,
2291 'labelhtml' => $textforempty,
2297 $out .=
'<option value="-2"' . ((in_array(-2, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Everybody") .
' --</option>' .
"\n";
2299 $outarray[-2] =
'-- ' . $langs->trans(
"Everybody") .
' --';
2300 $outarray2[-2] = array(
2302 'label' =>
'-- ' . $langs->trans(
"Everybody") .
' --',
2303 'labelhtml' =>
'-- ' . $langs->trans(
"Everybody") .
' --',
2309 $userstatic =
new User($this->db);
2312 $obj = $this->db->fetch_object($resql);
2314 $userstatic->id = $obj->rowid;
2315 $userstatic->lastname = $obj->lastname;
2316 $userstatic->firstname = $obj->firstname;
2317 $userstatic->photo = $obj->photo;
2318 $userstatic->status = $obj->status;
2319 $userstatic->entity = $obj->entity;
2320 $userstatic->admin = $obj->admin;
2321 $userstatic->gender = $obj->gender;
2324 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
2325 $disableline = ($enableonlytext ? $enableonlytext :
'1');
2329 $labeltoshowhtml =
'';
2336 $labeltoshow .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2337 $labeltoshowhtml .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2338 if (empty($obj->firstname) && empty($obj->lastname)) {
2339 $labeltoshow .= $obj->login;
2340 $labeltoshowhtml .= $obj->login;
2347 $moreinfo .= ($moreinfo ?
' - ' :
' (');
2348 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(');
2349 $moreinfo .= $obj->login;
2350 $moreinfohtml .= $obj->login;
2352 if ($showstatus >= 0) {
2353 if ($obj->status == 1 && $showstatus == 1) {
2354 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Enabled');
2355 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Enabled');
2357 if ($obj->status == 0 && $showstatus == 1) {
2358 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Disabled');
2359 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Disabled');
2362 if ($showlabelofentity) {
2363 if (empty($obj->entity)) {
2364 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
"AllEntities");
2365 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
"AllEntities");
2367 if ($obj->entity !=
$conf->entity) {
2368 $moreinfo .= ($moreinfo ?
' - ' :
' (') . ($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2369 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(').($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2373 $moreinfo .= (!empty($moreinfo) ?
')' :
'');
2374 $moreinfohtml .= (!empty($moreinfohtml) ?
')</span>' :
'');
2375 if (!empty($disableline) && $disableline !=
'1') {
2377 $moreinfo .=
' - ' . $disableline;
2378 $moreinfohtml .=
' - ' . $disableline;
2380 $labeltoshow .= $moreinfo;
2381 $labeltoshowhtml .= $moreinfohtml;
2383 $out .=
'<option value="' . $obj->rowid .
'"';
2384 if (!empty($disableline)) {
2385 $out .=
' disabled';
2387 if ((!empty($selected[0]) && is_object($selected[0])) ? $selected[0]->id == $obj->rowid : in_array($obj->rowid, $selected)) {
2388 $out .=
' selected';
2390 $out .=
' data-html="';
2392 $outhtml = $userstatic->getNomUrl(-3,
'', 0, 1, 24, 1,
'login',
'', 1) .
' ';
2393 if ($showstatus >= 0 && $obj->status == 0) {
2394 $outhtml .=
'<strike class="opacitymediumxxx">';
2396 $outhtml .= $labeltoshowhtml;
2397 if ($showstatus >= 0 && $obj->status == 0) {
2398 $outhtml .=
'</strike>';
2400 $labeltoshowhtml = $outhtml;
2404 $out .= $labeltoshow;
2405 $out .=
'</option>';
2407 $outarray[$userstatic->id] = $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength) . $moreinfo;
2408 $outarray2[$userstatic->id] = array(
2409 'id' => $userstatic->id,
2410 'label' => $labeltoshow,
2411 'labelhtml' => $labeltoshowhtml,
2419 $out .=
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'" disabled>';
2420 $out .=
'<option value="">' . $langs->trans(
"None") .
'</option>';
2422 $out .=
'</select>';
2424 if ($num && !$forcecombo) {
2426 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2435 if ($outputmode == 2) {
2437 } elseif ($outputmode) {
2469 public function select_dolusers_forevent($action =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include = array(), $enableonly = array(), $force_entity =
'0', $maxlength = 0, $showstatus = 0, $morefilter =
'', $showproperties = 0, $listofuserid = array(), $listofcontactid = array(), $listofotherid = array(), $canremoveowner = 1)
2472 global $langs, $user;
2474 $userstatic =
new User($this->db);
2477 if (!empty($_SESSION[
'assignedtouser'])) {
2478 $assignedtouser = json_decode($_SESSION[
'assignedtouser'],
true);
2479 if (!is_array($assignedtouser)) {
2480 $assignedtouser = array();
2483 $assignedtouser = array();
2485 $nbassignetouser = count($assignedtouser);
2488 if ($nbassignetouser) {
2489 $out .=
'<ul class="attendees">';
2493 foreach ($assignedtouser as $key => $value) {
2494 if ($value[
'id'] == $ownerid) {
2499 $userstatic->fetch($value[
'id']);
2500 $out .= $userstatic->getNomUrl(-1);
2502 $ownerid = $value[
'id'];
2503 $out .=
' (' . $langs->trans(
"Owner") .
')';
2506 if ($nbassignetouser > 1 && $action !=
'view') {
2507 $canremoveassignee = 1;
2510 if (!$canremoveowner) {
2511 $canremoveassignee = 0;
2513 if (!$user->hasRight(
'agenda',
'allactions',
'create')) {
2514 $canremoveassignee = 0;
2519 if ($canremoveassignee) {
2522 $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 .
'">';
2526 if ($showproperties) {
2527 if ($ownerid == $value[
'id'] && is_array($listofuserid) && count($listofuserid) && in_array($ownerid, array_keys($listofuserid))) {
2528 $out .=
'<div class="myavailability inline-block">';
2529 $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>';
2539 if ($nbassignetouser) {
2544 if ($action !=
'view') {
2545 $out .=
'<input type="hidden" class="removedassignedhidden" name="removedassigned" value="">';
2546 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
2547 $out .=
'jQuery(".removedassigned").click(function() { jQuery(".removedassignedhidden").val(jQuery(this).val()); });';
2548 $out .=
'jQuery(".assignedtouser").change(function() { console.log(jQuery(".assignedtouser option:selected").val());';
2549 $out .=
' if (jQuery(".assignedtouser option:selected").val() > 0) { jQuery("#' . $action .
'assignedtouser").attr("disabled", false); }';
2550 $out .=
' else { jQuery("#' . $action .
'assignedtouser").attr("disabled", true); }';
2552 $out .=
'})</script>';
2553 $out .= $this->
select_dolusers(
'', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter);
2554 $out .=
' <input type="submit" disabled class="button valignmiddle smallpaddingimp reposition" id="' . $action .
'assignedtouser" name="' . $action .
'assignedtouser" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
2581 public function select_dolresources_forevent($action =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include = array(), $enableonly = array(), $force_entity =
'0', $maxlength = 0, $showstatus = 0, $morefilter =
'', $showproperties = 0, $listofresourceid = array())
2586 require_once DOL_DOCUMENT_ROOT.
'/resource/class/html.formresource.class.php';
2587 require_once DOL_DOCUMENT_ROOT.
'/resource/class/dolresource.class.php';
2592 if (!empty($_SESSION[
'assignedtoresource'])) {
2593 $assignedtoresource = json_decode($_SESSION[
'assignedtoresource'],
true);
2594 if (!is_array($assignedtoresource)) {
2595 $assignedtoresource = array();
2598 $assignedtoresource = array();
2600 $nbassignetoresource = count($assignedtoresource);
2603 if ($nbassignetoresource) {
2604 $out .=
'<ul class="attendees">';
2608 foreach ($assignedtoresource as $key => $value) {
2610 $resourcestatic->fetch($value[
'id']);
2611 $out .= $resourcestatic->getNomUrl(-1);
2612 if ($nbassignetoresource >= 1 && $action !=
'view') {
2613 $out .=
' <input type="image" style="border: 0px;" src="' .
img_picto($langs->trans(
"Remove"),
'delete',
'', 0, 1) .
'" value="' . $resourcestatic->id .
'" class="removedassignedresource reposition" id="removedassignedresource_' . $resourcestatic->id .
'" name="removedassignedresource_' . $resourcestatic->id .
'">';
2616 if ($showproperties) {
2617 if (is_array($listofresourceid) && count($listofresourceid)) {
2618 $out .=
'<div class="myavailability inline-block">';
2619 $out .=
'<span class="hideonsmartphone"> - <span class="opacitymedium">' . $langs->trans(
"Availability") .
':</span> </span><input id="transparencyresource'.$value[
'id'].
'" class="paddingrightonly" ' . ($action ==
'view' ?
'disabled' :
'') .
' type="checkbox" name="transparency"' . ($listofresourceid[$value[
'id']][
'transparency'] ?
' checked' :
'') .
'><label for="transparencyresource'.$value[
'id'].
'">' . $langs->trans(
"Busy") .
'</label>';
2629 if ($nbassignetoresource) {
2634 if ($action !=
'view') {
2635 $out .=
'<input type="hidden" class="removedassignedresourcehidden" name="removedassignedresource" value="">';
2636 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
2637 $out .=
'jQuery(".removedassignedresource").click(function() { jQuery(".removedassignedresourcehidden").val(jQuery(this).val()); });';
2638 $out .=
'jQuery(".assignedtoresource").change(function() { console.log(jQuery(".assignedtoresource option:selected").val());';
2639 $out .=
' if (jQuery(".assignedtoresource option:selected").val() > 0) { jQuery("#' . $action .
'assignedtoresource").attr("disabled", false); }';
2640 $out .=
' else { jQuery("#' . $action .
'assignedtoresource").attr("disabled", true); }';
2642 $out .=
'})</script>';
2645 $out .=
img_picto(
'',
'resource',
'class="pictofixedwidth"');
2646 $out .= $formresources->select_resource_list(0, $htmlname, [], 1, 1, 0, $events, array(), 2, 0);
2648 $out .=
' <input type="submit" disabled class="button valignmiddle smallpaddingimp reposition" id="' . $action .
'assignedtoresource" name="' . $action .
'assignedtoresource" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
2686 public function select_produits($selected = 0, $htmlname =
'productid', $filtertype =
'', $limit = 0, $price_level = 0, $status = 1, $finished = 2, $selected_input_value =
'', $hidelabel = 0, $ajaxoptions = array(), $socid = 0, $showempty =
'1', $forcecombo = 0, $morecss =
'', $hidepriceinlabel = 0, $warehouseStatus =
'', $selected_combinations =
null, $nooutput = 0, $status_purchase = -1, $warehouseId = 0)
2689 global $langs,
$conf;
2694 $price_level = (!empty($price_level) ? $price_level : 0);
2695 if (is_null($ajaxoptions)) {
2696 $ajaxoptions = array();
2699 if (strval($filtertype) ===
'' && (isModEnabled(
"product") || isModEnabled(
"service"))) {
2700 if (isModEnabled(
"product") && !isModEnabled(
'service')) {
2702 } elseif (!isModEnabled(
'product') && isModEnabled(
"service")) {
2708 $placeholder = (is_numeric($showempty) ?
'' :
'placeholder="'.dolPrintHTML($showempty).
'"');
2710 if ($selected && empty($selected_input_value)) {
2711 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
2712 $producttmpselect =
new Product($this->db);
2713 $producttmpselect->fetch($selected);
2714 $selected_input_value = $producttmpselect->ref;
2715 unset($producttmpselect);
2718 if ($filtertype ==
'') {
2719 if (!isModEnabled(
'product')) {
2721 } elseif (!isModEnabled(
'service')) {
2726 $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;
2727 if ((
int) $warehouseId > 0) {
2728 $urloption .=
'&warehouseid=' . (int) $warehouseId;
2731 $out .=
ajax_autocompleter((
string) $selected, $htmlname, DOL_URL_ROOT .
'/product/ajax/products.php', $urloption,
getDolGlobalInt(
'PRODUIT_USE_SEARCH_TO_SELECT'),
getDolGlobalInt(
'PRODUCT_SEARCH_AUTO_SELECT_IF_ONLY_ONE', 1), $ajaxoptions);
2733 if (isModEnabled(
'variants') && is_array($selected_combinations)) {
2737 <!-- script to auto show attributes select tags if a variant was selected -->
2738 <script nonce="' .
getNonce() .
'">
2739 // auto show attributes fields
2740 selected = ' . json_encode($selected_combinations) .
';
2743 jQuery(document).ready(function () {
2745 jQuery("input[name=\'prod_entry_mode\']").change(function () {
2746 if (jQuery(this).val() == \'free\') {
2747 jQuery(\'div#attributes_box\').empty();
2751 jQuery("input#' . $htmlname .
'").change(function () {
2753 if (!jQuery(this).val()) {
2754 jQuery(\'div#attributes_box\').empty();
2758 console.log("A change has started. We get variants fields to inject html select");
2760 jQuery.getJSON("' . DOL_URL_ROOT .
'/variants/ajax/getCombinations.php", {
2761 id: jQuery(this).val()
2762 }, function (data) {
2763 jQuery(\'div#attributes_box\').empty();
2765 jQuery.each(data, function (key, val) {
2767 combvalues[val.id] = val.values;
2769 var span = jQuery(document.createElement(\'div\')).css({
2770 \'display\': \'table-row\'
2774 jQuery(document.createElement(\'div\')).text(val.label).css({
2775 \'font-weight\': \'bold\',
2776 \'display\': \'table-cell\'
2780 var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({
2781 \'margin-left\': \'15px\',
2782 \'white-space\': \'pre\'
2784 jQuery(document.createElement(\'option\')).val(\'\')
2787 jQuery.each(combvalues[val.id], function (key, val) {
2788 var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value);
2790 if (selected[val.fk_product_attribute] == val.id) {
2791 tag.attr(\'selected\', \'selected\');
2798 jQuery(\'div#attributes_box\').append(span);
2803 ' . ($selected ?
'jQuery("input#' . $htmlname .
'").change();' :
'') .
'
2809 if (empty($hidelabel)) {
2811 } elseif ($hidelabel > 1) {
2813 if ($hidelabel == 2) {
2814 $out .=
img_picto($langs->trans(
"Search"),
'search');
2818 $out .=
'<input type="text" class="minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . $placeholder .
' ' . (
getDolGlobalString(
'PRODUCT_SEARCH_AUTOFOCUS') ?
'autofocus' :
'') .
' />';
2819 if ($hidelabel == 3) {
2820 $out .=
img_picto($langs->trans(
"Search"),
'search');
2823 $out .= $this->
select_produits_list($selected, $htmlname, $filtertype, $limit, $price_level,
'', $status, $finished, 0, $socid, $showempty, $forcecombo, $morecss, $hidepriceinlabel, $warehouseStatus, $status_purchase, $warehouseId);
2826 if (empty($nooutput)) {
2850 public function select_bom($selected =
'', $htmlname =
'bom_id', $limit = 0, $status = 1, $type = 0, $showempty =
'1', $morecss =
'', $nooutput =
'', $forcecombo = 0, $TProducts = [])
2855 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
2861 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2866 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
2868 $sql =
'SELECT b.rowid, b.ref, b.label, b.fk_product';
2869 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'bom_bom as b';
2870 $sql .=
' WHERE b.entity IN (' .
getEntity(
'bom') .
')';
2871 if (!empty($status)) {
2872 $sql .=
' AND status = ' . (int) $status;
2874 if (!empty($type)) {
2875 $sql .=
' AND bomtype = ' . (int) $type;
2877 if (!empty($TProducts)) {
2878 $sql .=
' AND fk_product IN (' . $this->db->sanitize(implode(
',', $TProducts)) .
')';
2880 if (!empty($limit)) {
2881 $sql .=
' LIMIT ' . (int) $limit;
2883 $resql = $db->query($sql);
2886 $out .=
'<option value="-1"';
2887 if (empty($selected)) {
2888 $out .=
' selected';
2890 $out .=
'> </option>';
2892 while ($obj = $db->fetch_object($resql)) {
2894 $res = $product->fetch($obj->fk_product);
2895 $out .=
'<option value="' . $obj->rowid .
'"';
2896 if ($obj->rowid == $selected) {
2899 $out .=
'>' . $obj->ref .
' - ' . $product->label .
' - ' . $obj->label .
'</option>';
2905 $out .=
'</select>';
2906 if (empty($nooutput)) {
2941 public function select_produits_list($selected = 0, $htmlname =
'productid', $filtertype =
'', $limit = 20, $price_level = 0, $filterkey =
'', $status = 1, $finished = 2, $outputmode = 0, $socid = 0, $showempty =
'1', $forcecombo = 0, $morecss =
'maxwidth500', $hidepriceinlabel = 0, $warehouseStatus =
'', $status_purchase = -1, $warehouseId = 0)
2945 global $hookmanager;
2948 $outarray = array();
2952 $langs->load(
'other');
2955 $warehouseStatusArray = array();
2956 if (!empty($warehouseStatus)) {
2957 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/entrepot.class.php';
2958 if (preg_match(
'/warehouseclosed/', $warehouseStatus)) {
2961 if (preg_match(
'/warehouseopen/', $warehouseStatus)) {
2964 if (preg_match(
'/warehouseinternal/', $warehouseStatus)) {
2969 $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";
2970 if (count($warehouseStatusArray)) {
2971 $selectFieldsGrouped =
", sum(" . $this->db->ifsql(
"e.statut IS NULL",
"0",
"ps.reel") .
") as stock";
2973 $selectFieldsGrouped =
", " . $this->db->ifsql(
"p.stock IS NULL", 0,
"p.stock") .
" AS stock";
2979 $parameters = array();
2980 $reshook = $hookmanager->executeHooks(
'selectProductsListSelect', $parameters);
2981 if (empty($reshook)) {
2982 $sql .= $selectFields.$selectFieldsGrouped.$hookmanager->resPrint;
2984 $sql .= $hookmanager->resPrint;
2989 $sql .=
", (SELECT " . $this->db->prefix() .
"categorie_product.fk_categorie
2990 FROM " . $this->db->prefix() .
"categorie_product
2991 WHERE " . $this->db->prefix() .
"categorie_product.fk_product=p.rowid
2993 ) AS categorie_product_id ";
2998 $sql .=
', pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,';
2999 $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';
3000 $selectFields .=
", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custdefault_vat_code, custref";
3004 $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";
3005 $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';
3010 $sql .=
", pl.label as label_translated";
3011 $sql .=
", pl.description as description_translated";
3012 $selectFields .=
", label_translated";
3013 $selectFields .=
", description_translated";
3017 $sql .=
", (SELECT pp.rowid FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
3018 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
3019 $sql .=
" AND price_level = " . ((int) $price_level);
3021 $sql .=
" ORDER BY date_price";
3022 $sql .=
" DESC LIMIT 1) as price_rowid";
3023 $sql .=
", (SELECT pp.price_by_qty FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
3024 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
3025 $sql .=
" AND price_level = " . ((int) $price_level);
3027 $sql .=
" ORDER BY date_price";
3028 $sql .=
" DESC LIMIT 1) as price_by_qty";
3029 $selectFields .=
", price_rowid, price_by_qty";
3032 $sql .=
" FROM ".$this->db->prefix().
"product as p";
3035 $sql .=
" USE INDEX (" . $this->db->sanitize(
getDolGlobalString(
'MAIN_PRODUCT_FORCE_INDEX')) .
")";
3039 $parameters = array();
3040 $reshook = $hookmanager->executeHooks(
'selectProductsListFrom', $parameters);
3041 $sql .= $hookmanager->resPrint;
3043 if (count($warehouseStatusArray)) {
3044 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_stock as ps on ps.fk_product = p.rowid";
3045 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entrepot as e on ps.fk_entrepot = e.rowid AND e.entity IN (" .
getEntity(
'stock') .
")";
3046 $sql .=
' AND e.statut IN (' . $this->db->sanitize($this->db->escape(implode(
',', $warehouseStatusArray))) .
')';
3051 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_customer_price as pcp ON pcp.fk_soc=" . ((int) $socid) .
" AND pcp.fk_product=p.rowid";
3055 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
3059 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_lang as pl ON pl.fk_product = p.rowid ";
3061 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
3062 $soc =
new Societe($this->db);
3063 $result = $soc->fetch($socid);
3064 if ($result > 0 && !empty($soc->default_lang)) {
3065 $sql .=
" AND pl.lang = '" . $this->db->escape($soc->default_lang) .
"'";
3067 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3070 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3075 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_attribute_combination pac ON pac.fk_product_child = p.rowid";
3078 $sql .=
' WHERE p.entity IN (' .
getEntity(
'product') .
')';
3081 $sql .=
" AND pac.rowid IS NULL";
3084 if ($finished == 0) {
3085 $sql .=
" AND p.finished = " . ((int) $finished);
3086 } elseif ($finished == 1) {
3087 $sql .=
" AND p.finished = ".((int) $finished);
3090 $sql .=
" AND p.tosell = ".((int) $status);
3092 if ($status_purchase >= 0) {
3093 $sql .=
" AND p.tobuy = " . ((int) $status_purchase);
3096 if (strval($filtertype) !=
'') {
3097 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
3098 } elseif (!isModEnabled(
'product')) {
3099 $sql .=
" AND p.fk_product_type = 1";
3100 } elseif (!isModEnabled(
'service')) {
3101 $sql .=
" AND p.fk_product_type = 0";
3104 if ((
int) $warehouseId > 0) {
3105 $sql .=
" AND EXISTS (SELECT psw.fk_product FROM " . $this->db->prefix() .
"product_stock as psw WHERE psw.reel>0 AND psw.fk_entrepot=".(int) $warehouseId.
" AND psw.fk_product = p.rowid)";
3109 $parameters = array();
3110 $reshook = $hookmanager->executeHooks(
'selectProductsListWhere', $parameters);
3111 $sql .= $hookmanager->resPrint;
3113 if ($filterkey !=
'') {
3114 $sqlSupplierSearch=
'';
3119 $search_crit = explode(
' ', $filterkey);
3121 if (count($search_crit) > 1) {
3124 foreach ($search_crit as $crit) {
3128 $sql .=
"(p.ref LIKE '" . $this->db->escape($prefix . $crit) .
"%' OR p.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3130 $sql .=
" OR pl.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3133 $sql .=
" OR pcp.ref_customer LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3136 $sql .=
" OR p.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3138 $sql .=
" OR pl.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3144 $sqlSupplierSearch .= !empty($sqlSupplierSearch) ?
' AND ':
'';
3145 $sqlSupplierSearch .=
" pfp.ref_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3150 if (count($search_crit) > 1) {
3153 if (isModEnabled(
'barcode')) {
3154 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3159 $sql .=
" OR EXISTS (SELECT pfp.fk_product FROM " . $this->db->prefix() .
"product_fournisseur_price as pfp WHERE p.rowid = pfp.fk_product";
3161 $sql .= $sqlSupplierSearch;
3167 if (count($warehouseStatusArray)) {
3168 $sql .=
" GROUP BY " . $selectFields;
3173 $sql .=
" ORDER BY categorie_product_id ";
3175 (
getDolGlobalInt(
'PRODUCT_SORT_BY_CATEGORY') == 1) ? $sql .=
"ASC" : $sql .=
"DESC";
3177 $sql .= $this->db->order(
"p.ref");
3180 $sql .= $this->db->plimit($limit, 0);
3183 dol_syslog(get_class($this) .
"::select_produits_list search products", LOG_DEBUG);
3184 $result = $this->db->query($sql);
3186 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3187 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3188 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
3190 $num = $this->db->num_rows($result);
3195 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3199 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
3205 if ($showempty && !is_numeric($showempty)) {
3206 $textifempty = $langs->trans($showempty);
3208 $textifempty .= $langs->trans(
"All");
3211 if ($showempty && !is_numeric($showempty)) {
3212 $textifempty = $langs->trans($showempty);
3216 $out .=
'<option value="-1" selected>' . ($textifempty ? $textifempty :
' ') .
'</option>';
3220 while ($num && $i < $num) {
3223 $objp = $this->db->fetch_object($result);
3225 if ((
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1) {
3226 $sql =
"SELECT rowid, quantity, price, unitprice, remise_percent, remise, price_base_type";
3227 $sql .=
" FROM " . $this->db->prefix() .
"product_price_by_qty";
3228 $sql .=
" WHERE fk_product_price = " . ((int) $objp->price_rowid);
3229 $sql .=
" ORDER BY quantity ASC";
3231 dol_syslog(get_class($this) .
"::select_produits_list search prices by qty", LOG_DEBUG);
3232 $result2 = $this->db->query($sql);
3234 $nb_prices = $this->db->num_rows($result2);
3236 while ($nb_prices && $j < $nb_prices) {
3237 $objp2 = $this->db->fetch_object($result2);
3239 $objp->price_by_qty_rowid = $objp2->rowid;
3240 $objp->price_by_qty_price_base_type = $objp2->price_base_type;
3241 $objp->price_by_qty_quantity = $objp2->quantity;
3242 $objp->price_by_qty_unitprice = $objp2->unitprice;
3243 $objp->price_by_qty_remise_percent = $objp2->remise_percent;
3245 $objp->quantity = $objp2->quantity;
3246 $objp->price = $objp2->price;
3247 $objp->unitprice = $objp2->unitprice;
3248 $objp->remise_percent = $objp2->remise_percent;
3254 '@phan-var-force array{key:string,value:string,label:string,label2:string,desc:string,type:string,price_ht:string,price_ttc:string,price_ht_locale:string,price_ttc_locale:string,pricebasetype:string,tva_tx:string,default_vat_code:string,qty:string,discount:string,duration_value:string,duration_unit:string,pbq:string,labeltrans:string,desctrans:string,ref_customer:string} $optJson';
3261 array_push($outarray, $optJson);
3265 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_price_expression)) {
3266 $price_product =
new Product($this->db);
3267 $price_product->fetch($objp->rowid,
'',
'', 1);
3269 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3271 $price_result = $priceparser->parseProduct($price_product);
3272 if ($price_result >= 0) {
3273 $objp->price = $price_result;
3274 $objp->unitprice = $price_result;
3276 $objp->price_ttc = (float)
price2num($objp->price) * (1 + ($objp->tva_tx / 100));
3277 $objp->price_ttc =
price2num($objp->price_ttc,
'MU');
3280 if (
getDolGlobalInt(
'PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES') && !empty($objp->custprice)) {
3288 array_push($outarray, $optJson);
3294 $out .=
'</select>';
3296 $this->db->free($result);
3298 if (empty($outputmode)) {
3325 protected function constructProductListOption(&$objp, &$opt, &$optJson, $price_level, $selected, $hidepriceinlabel = 0, $filterkey =
'', $novirtualstock = 0)
3327 global $langs,
$conf, $user;
3328 global $hookmanager;
3334 $outlabel_translated =
'';
3336 $outdesc_translated =
'';
3342 $outpricebasetype =
'';
3344 $outdefault_vat_code =
'';
3348 $maxlengtharticle = (!
getDolGlobalString(
'PRODUCT_MAX_LENGTH_COMBO') ? 48 :
$conf->global->PRODUCT_MAX_LENGTH_COMBO);
3350 $label = $objp->label;
3351 if (!empty($objp->label_translated)) {
3352 $label = $objp->label_translated;
3354 if (!empty($filterkey) && $filterkey !=
'') {
3355 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
3358 $outkey = $objp->rowid;
3359 $outref = $objp->ref;
3360 $outrefcust = empty($objp->custref) ?
'' : $objp->custref;
3361 $outlabel = $objp->label;
3362 $outdesc = $objp->description;
3364 $outlabel_translated = $objp->label_translated;
3365 $outdesc_translated = $objp->description_translated;
3367 $outbarcode = $objp->barcode;
3368 $outorigin = $objp->fk_country;
3369 $outpbq = empty($objp->price_by_qty_rowid) ?
'' : $objp->price_by_qty_rowid;
3371 $outtype = $objp->fk_product_type;
3376 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
3382 if (!empty($objp->unit_short)) {
3383 $outvalUnits .=
' - ' . $objp->unit_short;
3387 if (!empty($objp->weight) && $objp->weight_units !==
null) {
3389 $outvalUnits .=
' - ' . $unitToShow;
3391 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
3392 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
3393 $outvalUnits .=
' - ' . $unitToShow;
3395 if (!empty($objp->surface) && $objp->surface_units !==
null) {
3397 $outvalUnits .=
' - ' . $unitToShow;
3399 if (!empty($objp->volume) && $objp->volume_units !==
null) {
3401 $outvalUnits .=
' - ' . $unitToShow;
3404 if ($outdurationvalue && $outdurationunit) {
3406 'h' => $langs->trans(
'Hour'),
3407 'd' => $langs->trans(
'Day'),
3408 'w' => $langs->trans(
'Week'),
3409 'm' => $langs->trans(
'Month'),
3410 'y' => $langs->trans(
'Year')
3412 if (isset($da[$outdurationunit])) {
3413 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
3420 if ($user->hasRight(
'stock',
'lire')) {
3421 if ($objp->stock > 0) {
3423 } elseif ($objp->stock <= 0) {
3431 $labeltoshow .= $objp->ref;
3432 if (!empty($objp->custref)) {
3433 $labeltoshow .=
' (' . $objp->custref .
')';
3436 $labeltoshow .=
' (' . $outbarcode .
')';
3438 $labeltoshow .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3440 $labeltoshow .=
' (' .
getCountry($outorigin,
'1') .
')';
3444 $labeltoshowhtml =
'';
3445 $labeltoshowhtml .= $objp->ref;
3446 if (!empty($objp->custref)) {
3447 $labeltoshowhtml .=
' (' . $objp->custref .
')';
3449 if (!empty($filterkey) && $filterkey !=
'') {
3450 $labeltoshowhtml = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $labeltoshowhtml, 1);
3453 $labeltoshowhtml .=
' (' . $outbarcode .
')';
3455 $labeltoshowhtml .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3457 $labeltoshowhtml .=
' (' .
getCountry($outorigin,
'1') .
')';
3461 $labeltoshowstock =
'';
3462 $labeltoshowhtmlstock =
'';
3464 if ($user->hasRight(
'stock',
'lire')) {
3465 $labeltoshowstock .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
3467 if ($objp->stock > 0) {
3468 $labeltoshowhtmlstock .=
' - <span class="product_line_stock_ok">';
3469 } elseif ($objp->stock <= 0) {
3470 $labeltoshowhtmlstock .=
' - <span class="product_line_stock_too_low">';
3472 $labeltoshowhtmlstock .= $langs->transnoentities(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
3473 $labeltoshowhtmlstock .=
'</span>';
3475 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
3476 $langs->load(
"stocks");
3478 $tmpproduct =
new Product($this->db);
3479 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
3480 $tmpproduct->load_virtual_stock();
3481 $virtualstock = $tmpproduct->stock_theorique;
3483 $labeltoshowstock .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
3485 $labeltoshowhtmlstock .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
3486 if ($virtualstock > 0) {
3487 $labeltoshowhtmlstock .=
'<span class="product_line_stock_ok">';
3488 } elseif ($virtualstock <= 0) {
3489 $labeltoshowhtmlstock .=
'<span class="product_line_stock_too_low">';
3491 $labeltoshowhtmlstock .= $virtualstock;
3492 $labeltoshowhtmlstock .=
'</span>';
3501 $labeltoshowprice =
'';
3502 $labeltoshowhtmlprice =
'';
3505 $sql =
"SELECT price, price_ttc, price_base_type, tva_tx, default_vat_code";
3506 $sql .=
" FROM " . $this->db->prefix() .
"product_price";
3507 $sql .=
" WHERE fk_product = " . ((int) $objp->rowid);
3508 $sql .=
" AND entity IN (" .
getEntity(
'productprice') .
")";
3509 $sql .=
" AND price_level = " . ((int) $price_level);
3510 $sql .=
" ORDER BY date_price DESC, rowid DESC";
3513 dol_syslog(get_class($this) .
'::constructProductListOption search price for product ' . $objp->rowid .
' AND level ' . $price_level, LOG_DEBUG);
3514 $result2 = $this->db->query($sql);
3516 $objp2 = $this->db->fetch_object($result2);
3519 if ($objp2->price_base_type ==
'HT') {
3520 $labeltoshowprice .=
' - ' .
price($objp2->price, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
3521 $labeltoshowhtmlprice .=
' - ' .
price($objp2->price, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
3523 $labeltoshowprice .=
' - ' .
price($objp2->price_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
3524 $labeltoshowhtmlprice .=
' - ' .
price($objp2->price_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3526 $outprice_ht =
price($objp2->price);
3527 $outprice_ttc =
price($objp2->price_ttc);
3528 $outpricebasetype = $objp2->price_base_type;
3530 $outtva_tx = $objp2->tva_tx;
3531 $outdefault_vat_code = $objp2->default_vat_code;
3533 $outtva_tx = $objp->tva_tx;
3534 $outdefault_vat_code = $objp->default_vat_code;
3543 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1 && (
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
3545 $outqty = $objp->quantity;
3546 $outdiscount = $objp->remise_percent;
3547 if ($objp->quantity == 1) {
3548 $labeltoshowprice .=
' - ' .
price($objp->unitprice, 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
3549 $labeltoshowhtmlprice .=
' - ' .
price($objp->unitprice, 0, $langs, 0, 0, -1,
$conf->currency) .
"/";
3550 $labeltoshowprice .= $langs->trans(
"Unit");
3551 $labeltoshowhtmlprice .= $langs->transnoentities(
"Unit");
3553 $labeltoshowprice .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
3554 $labeltoshowhtmlprice .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
3555 $labeltoshowprice .= $langs->trans(
"Units");
3556 $labeltoshowhtmlprice .= $langs->transnoentities(
"Units");
3559 $outprice_ht =
price($objp->unitprice);
3560 $outprice_ttc =
price($objp->unitprice * (1 + ($objp->tva_tx / 100)));
3561 $outpricebasetype = $objp->price_base_type;
3562 $outtva_tx = $objp->tva_tx;
3563 $outdefault_vat_code = $objp->default_vat_code;
3565 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1) {
3566 $labeltoshowprice .=
" (" .
price($objp->unitprice, 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->trans(
"Unit") .
")";
3567 $labeltoshowhtmlprice .=
" (" .
price($objp->unitprice, 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->transnoentities(
"Unit") .
")";
3569 if (empty($hidepriceinlabel) && !empty($objp->remise_percent) && $objp->remise_percent >= 1) {
3570 $labeltoshowprice .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3571 $labeltoshowhtmlprice .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3576 if (!empty($objp->idprodcustprice)) {
3579 if ($objp->custprice_base_type ==
'HT') {
3580 $labeltoshowprice .=
' - ' .
price($objp->custprice, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
3581 $labeltoshowhtmlprice .=
' - ' .
price($objp->custprice, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
3583 $labeltoshowprice .=
' - ' .
price($objp->custprice_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
3584 $labeltoshowhtmlprice .=
' - ' .
price($objp->custprice_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3587 $outprice_ht =
price($objp->custprice);
3588 $outprice_ttc =
price($objp->custprice_ttc);
3589 $outpricebasetype = $objp->custprice_base_type;
3590 $outtva_tx = $objp->custtva_tx;
3591 $outdefault_vat_code = $objp->custdefault_vat_code;
3596 if (empty($hidepriceinlabel) && !$found) {
3597 if ($objp->price_base_type ==
'HT') {
3598 $labeltoshowprice .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
3599 $labeltoshowhtmlprice .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
3601 $labeltoshowprice .=
' - ' .
price($objp->price_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
3602 $labeltoshowhtmlprice .=
' - ' .
price($objp->price_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3604 $outprice_ht =
price($objp->price);
3605 $outprice_ttc =
price($objp->price_ttc);
3606 $outpricebasetype = $objp->price_base_type;
3607 $outtva_tx = $objp->tva_tx;
3608 $outdefault_vat_code = $objp->default_vat_code;
3612 $opt =
'<option value="' . $objp->rowid .
'"';
3613 $opt .= ($objp->rowid == $selected) ?
' selected' :
'';
3614 if (!empty($objp->price_by_qty_rowid) && $objp->price_by_qty_rowid > 0) {
3615 $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 .
'"';
3618 $opt .=
' data-labeltrans="' . $outlabel_translated .
'"';
3622 if ($stocktag == 1) {
3623 $opt .=
' class="product_line_stock_ok" data-html="'.$labeltoshowhtml.$outvalUnits.$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
3626 if ($stocktag == -1) {
3627 $opt .=
' class="product_line_stock_too_low" data-html="'.$labeltoshowhtml.$outvalUnits.$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
3634 $opt .= $labeltoshow;
3635 $outval .= $labeltoshowhtml;
3638 $opt .= $outvalUnits;
3639 $outval .= $outvalUnits;
3642 $opt .= $labeltoshowprice;
3643 $outval .= $labeltoshowhtmlprice;
3646 $opt .= $labeltoshowstock;
3647 $outval .= $labeltoshowhtmlstock;
3650 $parameters = array(
'objp' => $objp);
3651 $reshook = $hookmanager->executeHooks(
'constructProductListOption', $parameters);
3652 if (empty($reshook)) {
3653 $opt .= $hookmanager->resPrint;
3655 $opt = $hookmanager->resPrint;
3658 $opt .=
"</option>\n";
3663 'label2' => $outlabel,
3667 'price_ttc' =>
price2num($outprice_ttc),
3670 'pricebasetype' => $outpricebasetype,
3671 'tva_tx' => $outtva_tx,
3672 'default_vat_code' => $outdefault_vat_code,
3674 'discount' => $outdiscount,
3675 'duration_value' => $outdurationvalue,
3676 'duration_unit' => $outdurationunit,
3678 'labeltrans' => $outlabel_translated,
3679 'desctrans' => $outdesc_translated,
3680 'ref_customer' => $outrefcust
3701 public function select_produits_fournisseurs($socid, $selected =
'', $htmlname =
'productid', $filtertype =
'', $filtre =
'', $ajaxoptions = array(), $hidelabel = 0, $alsoproductwithnosupplierprice = 0, $morecss =
'', $placeholder =
'')
3704 global $langs,
$conf;
3705 global $price_level, $status, $finished;
3707 if (!isset($status)) {
3711 $selected_input_value =
'';
3713 if ($selected > 0) {
3714 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3715 $producttmpselect =
new Product($this->db);
3716 $producttmpselect->fetch($selected);
3717 $selected_input_value = $producttmpselect->ref;
3718 unset($producttmpselect);
3722 $urloption = ($socid > 0 ?
'socid=' . $socid .
'&' :
'') .
'htmlname=' . $htmlname .
'&outjson=1&price_level=' . $price_level .
'&type=' . $filtertype .
'&mode=2&status=' . $status .
'&finished=' . $finished .
'&alsoproductwithnosupplierprice=' . $alsoproductwithnosupplierprice;
3723 print
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT .
'/product/ajax/products.php', $urloption,
getDolGlobalInt(
'PRODUIT_USE_SEARCH_TO_SELECT'), 0, $ajaxoptions);
3725 print($hidelabel ?
'' : $langs->trans(
"RefOrLabel") .
' : ') .
'<input type="text" class="'.$morecss.
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . ($placeholder ?
' placeholder="' . $placeholder .
'"' :
'') .
'>';
3727 print $this->
select_produits_fournisseurs_list($socid, $selected, $htmlname, $filtertype, $filtre,
'', $status, 0, 0, $alsoproductwithnosupplierprice, $morecss, 0, $placeholder);
3751 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 =
'')
3754 global $langs,
$conf, $user;
3755 global $hookmanager;
3758 $outarray = array();
3760 $maxlengtharticle = (!
getDolGlobalString(
'PRODUCT_MAX_LENGTH_COMBO') ? 48 :
$conf->global->PRODUCT_MAX_LENGTH_COMBO);
3762 $langs->load(
'stocks');
3765 $langs->load(
'other');
3768 $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,";
3769 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice, pfp.barcode";
3770 $sql .=
", pfp.multicurrency_code, pfp.multicurrency_unitprice";
3771 $sql .=
", pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.default_vat_code, pfp.fk_soc, s.nom as name";
3772 $sql .=
", pfp.supplier_reputation";
3775 $sql .=
", pfp.desc_fourn as description";
3777 $sql .=
", p.description";
3781 $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";
3783 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
3784 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN (" .
getEntity(
'product') .
") )";
3786 $sql .=
" AND pfp.fk_soc = " . ((int) $socid);
3788 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
3791 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
3793 $sql .=
" WHERE p.entity IN (" .
getEntity(
'product') .
")";
3794 if ($statut != -1) {
3795 $sql .=
" AND p.tobuy = " . ((int) $statut);
3797 if (strval($filtertype) !=
'') {
3798 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
3800 if (!empty($filtre)) {
3801 $sql .=
" " . $filtre;
3804 $parameters = array();
3805 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListWhere', $parameters);
3806 $sql .= $hookmanager->resPrint;
3808 if ($filterkey !=
'') {
3812 $search_crit = explode(
' ', $filterkey);
3814 if (count($search_crit) > 1) {
3817 foreach ($search_crit as $crit) {
3821 $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) .
"%'";
3823 $sql .=
" OR pfp.desc_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3828 if (count($search_crit) > 1) {
3831 if (isModEnabled(
'barcode')) {
3832 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3833 $sql .=
" OR pfp.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3837 $sql .=
" ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC";
3838 $sql .= $this->db->plimit($limit, 0);
3842 dol_syslog(get_class($this) .
"::select_produits_fournisseurs_list", LOG_DEBUG);
3843 $result = $this->db->query($sql);
3845 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3846 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
3848 $num = $this->db->num_rows($result);
3851 $out .=
'<select class="flat ' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'">';
3853 $out .=
'<option value="-1" selected>' . ($placeholder ? $placeholder :
' ') .
'</option>';
3855 $out .=
'<option value="-1">' . ($placeholder ? $placeholder :
' ') .
'</option>';
3860 $objp = $this->db->fetch_object($result);
3862 if (is_null($objp->idprodfournprice)) {
3864 $objp->tva_tx = $objp->tva_tx_sale;
3865 $objp->default_vat_code = $objp->default_vat_code_sale;
3868 $outkey = $objp->idprodfournprice;
3869 if (!$outkey && $alsoproductwithnosupplierprice) {
3870 $outkey =
'idprod_' . $objp->rowid;
3873 $outref = $objp->ref;
3874 $outbarcode = $objp->barcode;
3877 $outtype = $objp->fk_product_type;
3884 if (!empty($objp->unit_short)) {
3885 $outvalUnits .=
' - ' . $objp->unit_short;
3887 if (!empty($objp->weight) && $objp->weight_units !==
null) {
3889 $outvalUnits .=
' - ' . $unitToShow;
3891 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
3892 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
3893 $outvalUnits .=
' - ' . $unitToShow;
3895 if (!empty($objp->surface) && $objp->surface_units !==
null) {
3897 $outvalUnits .=
' - ' . $unitToShow;
3899 if (!empty($objp->volume) && $objp->volume_units !==
null) {
3901 $outvalUnits .=
' - ' . $unitToShow;
3903 if ($outdurationvalue && $outdurationunit) {
3905 'h' => $langs->trans(
'Hour'),
3906 'd' => $langs->trans(
'Day'),
3907 'w' => $langs->trans(
'Week'),
3908 'm' => $langs->trans(
'Month'),
3909 'y' => $langs->trans(
'Year')
3911 if (isset($da[$outdurationunit])) {
3912 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
3917 $objRef = $objp->ref;
3918 if ($filterkey && $filterkey !=
'') {
3919 $objRef = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRef, 1);
3921 $objRefFourn = $objp->ref_fourn;
3922 if ($filterkey && $filterkey !=
'') {
3923 $objRefFourn = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRefFourn, 1);
3925 $label = $objp->label;
3926 if ($filterkey && $filterkey !=
'') {
3927 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
3930 switch ($objp->fk_product_type) {
3942 if (empty($picto)) {
3945 $optlabel =
img_object(
'', $picto,
'class="paddingright classfortooltip"', 0, 0, 1);
3948 $optlabel .= $objp->ref;
3949 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
3950 $optlabel .=
' <span class="opacitymedium">(' . $objp->ref_fourn .
')</span>';
3952 if (isModEnabled(
'barcode') && !empty($objp->barcode)) {
3953 $optlabel .=
' (' . $outbarcode .
')';
3955 $optlabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3957 $outvallabel = $objRef;
3958 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
3959 $outvallabel .=
' (' . $objRefFourn .
')';
3961 if (isModEnabled(
'barcode') && !empty($objp->barcode)) {
3962 $outvallabel .=
' (' . $outbarcode .
')';
3964 $outvallabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3967 $optlabel .= $outvalUnits;
3968 $outvallabel .= $outvalUnits;
3970 if (!empty($objp->idprodfournprice)) {
3971 $outqty = $objp->quantity;
3972 $outdiscount = $objp->remise_percent;
3973 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
3975 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
3976 $prod_supplier->id = $objp->fk_product;
3977 $prod_supplier->fourn_qty = $objp->quantity;
3978 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
3979 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
3981 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3983 $price_result = $priceparser->parseProductSupplier($prod_supplier);
3984 if ($price_result >= 0) {
3985 $objp->fprice = $price_result;
3986 if ($objp->quantity >= 1) {
3987 $objp->unitprice = $objp->fprice / $objp->quantity;
3991 if ($objp->quantity == 1) {
3992 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
3993 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1,
$conf->currency) .
"/";
3994 $optlabel .= $langs->trans(
"Unit");
3995 $outvallabel .= $langs->transnoentities(
"Unit");
3997 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
3998 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
3999 $optlabel .=
' ' . $langs->trans(
"Units");
4000 $outvallabel .=
' ' . $langs->transnoentities(
"Units");
4003 if ($objp->quantity > 1) {
4004 $optlabel .=
" (" .
price($objp->unitprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->trans(
"Unit") .
")";
4005 $outvallabel .=
" (" .
price($objp->unitprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->transnoentities(
"Unit") .
")";
4007 if ($objp->remise_percent >= 1) {
4008 $optlabel .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4009 $outvallabel .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4011 if ($objp->duration) {
4012 $optlabel .=
" - " . $objp->duration;
4013 $outvallabel .=
" - " . $objp->duration;
4016 $optlabel .=
" - " .
dol_trunc($objp->name, 8);
4017 $outvallabel .=
" - " .
dol_trunc($objp->name, 8);
4019 if ($objp->supplier_reputation) {
4021 $reputations = array(
'' => $langs->trans(
'Standard'),
'FAVORITE' => $langs->trans(
'Favorite'),
'NOTTHGOOD' => $langs->trans(
'NotTheGoodQualitySupplier'),
'DONOTORDER' => $langs->trans(
'DoNotOrderThisProductToThisSupplier'));
4023 $optlabel .=
" - " . $reputations[$objp->supplier_reputation];
4024 $outvallabel .=
" - " . $reputations[$objp->supplier_reputation];
4027 $optlabel .=
" - <span class='opacitymedium'>" . $langs->trans(
"NoPriceDefinedForThisSupplier") .
'</span>';
4028 $outvallabel .=
' - ' . $langs->transnoentities(
"NoPriceDefinedForThisSupplier");
4032 $novirtualstock = ($showstockinlist == 2);
4034 if ($user->hasRight(
'stock',
'lire')) {
4035 $outvallabel .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
4037 if ($objp->stock > 0) {
4038 $optlabel .=
' - <span class="product_line_stock_ok">';
4039 } elseif ($objp->stock <= 0) {
4040 $optlabel .=
' - <span class="product_line_stock_too_low">';
4042 $optlabel .= $langs->transnoentities(
"Stock") .
':' .
price(
price2num($objp->stock,
'MS'));
4043 $optlabel .=
'</span>';
4044 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
4045 $langs->load(
"stocks");
4047 $tmpproduct =
new Product($this->db);
4048 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
4049 $tmpproduct->load_virtual_stock();
4050 $virtualstock = $tmpproduct->stock_theorique;
4052 $outvallabel .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
4054 $optlabel .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
4055 if ($virtualstock > 0) {
4056 $optlabel .=
'<span class="product_line_stock_ok">';
4057 } elseif ($virtualstock <= 0) {
4058 $optlabel .=
'<span class="product_line_stock_too_low">';
4060 $optlabel .= $virtualstock;
4061 $optlabel .=
'</span>';
4068 $optstart =
'<option value="' . $outkey .
'"';
4069 if ($selected && $selected == $objp->idprodfournprice) {
4070 $optstart .=
' selected';
4072 if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) {
4073 $optstart .=
' disabled';
4076 if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) {
4085 $optstart .=
' data-default-vat-code="' .
dol_escape_htmltag($objp->default_vat_code) .
'"';
4087 if (isModEnabled(
'multicurrency')) {
4088 $optstart .=
' data-multicurrency-code="' .
dol_escape_htmltag($objp->multicurrency_code) .
'"';
4092 $optstart .=
' data-description="' .
dol_escape_htmltag($objp->description, 0, 1) .
'"';
4095 $outarrayentry = array(
4098 'label' => $outvallabel,
4099 'labelhtml' => $optlabel,
4101 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4102 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4103 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4104 'tva_tx_formated' =>
price($objp->tva_tx, 0, $langs, 1, -1, 2),
4106 'default_vat_code' => $objp->default_vat_code,
4107 'supplier_ref' => $objp->ref_fourn,
4108 'discount' => $outdiscount,
4110 'duration_value' => $outdurationvalue,
4111 'duration_unit' => $outdurationunit,
4112 'disabled' => empty($objp->idprodfournprice),
4113 'description' => $objp->description
4115 if (isModEnabled(
'multicurrency')) {
4116 $outarrayentry[
'multicurrency_code'] = $objp->multicurrency_code;
4117 $outarrayentry[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4119 $parameters = array(
4121 'optstart' => &$optstart,
4122 'optlabel' => &$optlabel,
4123 'outvallabel' => &$outvallabel,
4124 'outarrayentry' => &$outarrayentry,
4127 $reshook = $hookmanager->executeHooks(
'selectProduitsFournisseurListOption', $parameters, $this);
4133 $out .= $optstart .
' data-html="' .
dol_escape_htmltag($optlabel) .
'">' . $optlabel .
"</option>\n";
4134 $outarraypush = array(
4137 'label' => $outvallabel,
4138 'labelhtml' => $optlabel,
4140 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4141 'price_qty_ht_locale' =>
price($objp->fprice),
4142 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4143 'price_unit_ht_locale' =>
price($objp->unitprice),
4144 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4145 'tva_tx_formated' =>
price($objp->tva_tx),
4147 'default_vat_code' => $objp->default_vat_code,
4148 'supplier_ref' => $objp->ref_fourn,
4149 'discount' => $outdiscount,
4151 'duration_value' => $outdurationvalue,
4152 'duration_unit' => $outdurationunit,
4153 'disabled' => empty($objp->idprodfournprice),
4154 'description' => $objp->description
4156 if (isModEnabled(
'multicurrency')) {
4157 $outarraypush[
'multicurrency_code'] = $objp->multicurrency_code;
4158 $outarraypush[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4160 array_push($outarray, $outarraypush);
4173 $out .=
'</select>';
4175 $this->db->free($result);
4177 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
4183 if (empty($outputmode)) {
4202 global $langs,
$conf;
4204 $langs->load(
'stocks');
4206 $sql =
"SELECT p.rowid, p.ref, p.label, p.price, p.duration, pfp.fk_soc,";
4207 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.remise_percent, pfp.quantity, pfp.unitprice,";
4208 $sql .=
" pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name";
4209 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
4210 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
4211 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
4212 $sql .=
" WHERE pfp.entity IN (" .
getEntity(
'productsupplierprice') .
")";
4213 $sql .=
" AND p.tobuy = 1";
4214 $sql .=
" AND s.fournisseur = 1";
4215 $sql .=
" AND p.rowid = " . ((int) $productid);
4217 $sql .=
" ORDER BY s.nom, pfp.ref_fourn DESC";
4219 $sql .=
" ORDER BY pfp.unitprice ASC";
4222 dol_syslog(get_class($this) .
"::select_product_fourn_price", LOG_DEBUG);
4223 $result = $this->db->query($sql);
4226 $num = $this->db->num_rows($result);
4228 $form =
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
4231 $form .=
'<option value="0">-- ' . $langs->trans(
"NoSupplierPriceDefinedForThisProduct") .
' --</option>';
4233 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4234 $form .=
'<option value="0"> </option>';
4238 $objp = $this->db->fetch_object($result);
4240 $opt =
'<option value="' . $objp->idprodfournprice .
'"';
4242 if ($num == 1 || ($selected_supplier > 0 && $objp->fk_soc == $selected_supplier) || ($i == 0 &&
getDolGlobalString(
'PRODUCT_BEST_SUPPLIER_PRICE_PRESELECTED'))) {
4243 $opt .=
' selected';
4245 $opt .=
'>' . $objp->name .
' - ' . $objp->ref_fourn .
' - ';
4247 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
4249 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
4250 $prod_supplier->id = $productid;
4251 $prod_supplier->fourn_qty = $objp->quantity;
4252 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
4253 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
4255 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4257 $price_result = $priceparser->parseProductSupplier($prod_supplier);
4258 if ($price_result >= 0) {
4259 $objp->fprice = $price_result;
4260 if ($objp->quantity >= 1) {
4261 $objp->unitprice = $objp->fprice / $objp->quantity;
4265 if ($objp->quantity == 1) {
4266 $opt .=
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
4269 $opt .= $objp->quantity .
' ';
4271 if ($objp->quantity == 1) {
4272 $opt .= $langs->trans(
"Unit");
4274 $opt .= $langs->trans(
"Units");
4276 if ($objp->quantity > 1) {
4278 $opt .=
price($objp->unitprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->trans(
"Unit");
4280 if ($objp->duration) {
4281 $opt .=
" - " . $objp->duration;
4283 $opt .=
"</option>\n";
4290 $form .=
'</select>';
4291 $this->db->free($result);
4311 $num = count($this->cache_conditions_paiements);
4318 $sql =
"SELECT rowid, code, libelle as label, deposit_percent";
4319 $sql .=
" FROM " . $this->db->prefix() .
'c_payment_term';
4320 $sql .=
" WHERE entity IN (" .
getEntity(
'c_payment_term') .
")";
4321 $sql .=
" AND active > 0";
4322 $sql .=
" ORDER BY sortorder";
4324 $resql = $this->db->query($sql);
4326 $num = $this->db->num_rows($resql);
4329 $obj = $this->db->fetch_object($resql);
4332 $label = ($langs->trans(
"PaymentConditionShort" . $obj->code) !=
"PaymentConditionShort" . $obj->code ? $langs->trans(
"PaymentConditionShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4333 $this->cache_conditions_paiements[$obj->rowid][
'code'] = $obj->code;
4334 $this->cache_conditions_paiements[$obj->rowid][
'label'] = $label;
4335 $this->cache_conditions_paiements[$obj->rowid][
'deposit_percent'] = $obj->deposit_percent;
4360 $num = count($this->cache_availability);
4367 $langs->load(
'propal');
4369 $sql =
"SELECT rowid, code, label, position";
4370 $sql .=
" FROM " . $this->db->prefix() .
'c_availability';
4371 $sql .=
" WHERE active > 0";
4373 $resql = $this->db->query($sql);
4375 $num = $this->db->num_rows($resql);
4378 $obj = $this->db->fetch_object($resql);
4381 $label = ($langs->trans(
"AvailabilityType" . $obj->code) !=
"AvailabilityType" . $obj->code ? $langs->trans(
"AvailabilityType" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4382 $this->cache_availability[$obj->rowid][
'code'] = $obj->code;
4383 $this->cache_availability[$obj->rowid][
'label'] = $label;
4384 $this->cache_availability[$obj->rowid][
'position'] = $obj->position;
4388 $this->cache_availability =
dol_sort_array($this->cache_availability,
'position',
'asc', 0, 0, 1);
4409 global $langs, $user;
4413 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
4415 print
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4417 print
'<option value="0"> </option>';
4419 foreach ($this->cache_availability as
$id => $arrayavailability) {
4420 if ($selected ==
$id) {
4421 print
'<option value="' .
$id .
'" selected>';
4423 print
'<option value="' .
$id .
'">';
4430 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4444 $num = count($this->cache_demand_reason);
4449 $sql =
"SELECT rowid, code, label";
4450 $sql .=
" FROM " . $this->db->prefix() .
'c_input_reason';
4451 $sql .=
" WHERE active > 0";
4453 $resql = $this->db->query($sql);
4455 $num = $this->db->num_rows($resql);
4457 $tmparray = array();
4459 $obj = $this->db->fetch_object($resql);
4462 $label = ($obj->label !=
'-' ? $obj->label :
'');
4463 if ($langs->trans(
"DemandReasonType" . $obj->code) !=
"DemandReasonType" . $obj->code) {
4464 $label = $langs->trans(
"DemandReasonType" . $obj->code);
4466 if ($langs->trans($obj->code) != $obj->code) {
4467 $label = $langs->trans($obj->code);
4470 $tmparray[$obj->rowid][
'id'] = $obj->rowid;
4471 $tmparray[$obj->rowid][
'code'] = $obj->code;
4472 $tmparray[$obj->rowid][
'label'] = $label;
4476 $this->cache_demand_reason =
dol_sort_array($tmparray,
'label',
'asc', 0, 0, 1);
4498 public function selectInputReason($selected =
'', $htmlname =
'demandreasonid', $exclude =
'', $addempty = 0, $morecss =
'', $notooltip = 0)
4500 global $langs, $user;
4504 print
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
4506 print
'<option value="0"' . (empty($selected) ?
' selected' :
'') .
'> </option>';
4508 foreach ($this->cache_demand_reason as
$id => $arraydemandreason) {
4509 if ($arraydemandreason[
'code'] == $exclude) {
4513 if ($selected && ($selected == $arraydemandreason[
'id'] || $selected == $arraydemandreason[
'code'])) {
4514 print
'<option value="' . $arraydemandreason[
'id'] .
'" selected>';
4516 print
'<option value="' . $arraydemandreason[
'id'] .
'">';
4518 $label = $arraydemandreason[
'label'];
4519 print $langs->trans($label);
4523 if ($user->admin && empty($notooltip)) {
4524 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4541 $num = count($this->cache_types_paiements);
4548 $this->cache_types_paiements = array();
4550 $sql =
"SELECT id, code, libelle as label, type, active";
4551 $sql .=
" FROM " . $this->db->prefix() .
"c_paiement";
4552 $sql .=
" WHERE entity IN (" .
getEntity(
'c_paiement') .
")";
4554 $resql = $this->db->query($sql);
4556 $num = $this->db->num_rows($resql);
4559 $obj = $this->db->fetch_object($resql);
4562 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) !=
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4563 $this->cache_types_paiements[$obj->id][
'id'] = $obj->id;
4564 $this->cache_types_paiements[$obj->id][
'code'] = $obj->code;
4565 $this->cache_types_paiements[$obj->id][
'label'] = $label;
4566 $this->cache_types_paiements[$obj->id][
'type'] = $obj->type;
4567 $this->cache_types_paiements[$obj->id][
'active'] = $obj->active;
4571 $this->cache_types_paiements =
dol_sort_array($this->cache_types_paiements,
'label',
'asc', 0, 0, 1);
4601 public function select_conditions_paiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1, $noprint = 0)
4605 if (empty($noprint)) {
4629 public function getSelectConditionsPaiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1)
4631 global $langs, $user,
$conf;
4634 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
4640 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TERM_ID", LOG_NOTICE);
4644 $out .=
'<select id="' . $htmlname .
'" class="flat selectpaymentterms' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4646 $out .=
'<option value="0"> </option>';
4649 $selectedDepositPercent =
null;
4651 foreach ($this->cache_conditions_paiements as
$id => $arrayconditions) {
4652 if ($filtertype <= 0 && !empty($arrayconditions[
'deposit_percent'])) {
4656 if ($selected ==
$id) {
4657 $selectedDepositPercent = $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'];
4658 $out .=
'<option value="' .
$id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'" selected>';
4660 $out .=
'<option value="' .
$id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'">';
4662 $label = $arrayconditions[
'label'];
4664 if (!empty($arrayconditions[
'deposit_percent'])) {
4665 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'], $label);
4669 $out .=
'</option>';
4671 $out .=
'</select>';
4672 if ($user->admin && empty($noinfoadmin)) {
4673 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4677 if ($deposit_percent >= 0) {
4678 $out .=
' <span id="' . $htmlname .
'_deposit_percent_container"' . (empty($selectedDepositPercent) ?
' style="display: none"' :
'') .
'>';
4679 $out .= $langs->trans(
'DepositPercent') .
' : ';
4680 $out .=
'<input id="' . $htmlname .
'_deposit_percent" name="' . $htmlname .
'_deposit_percent" class="maxwidth50" value="' . $deposit_percent .
'" />';
4683 <script nonce="' .
getNonce() .
'">
4684 $(document).ready(function () {
4685 $("#' . $htmlname .
'").change(function () {
4686 let $selected = $(this).find("option:selected");
4687 let depositPercent = $selected.attr("data-deposit_percent");
4689 if (depositPercent.length > 0) {
4690 $("#' . $htmlname .
'_deposit_percent_container").show().find("#' . $htmlname .
'_deposit_percent").val(depositPercent);
4692 $("#' . $htmlname .
'_deposit_percent_container").hide();
4723 public function select_types_paiements($selected =
'', $htmlname =
'paiementtype', $filtertype =
'', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'', $nooutput = 0)
4726 global $langs, $user,
$conf;
4730 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $filtertype .
", " . $format, LOG_DEBUG);
4732 $filterarray = array();
4733 if ($filtertype ==
'CRDT') {
4734 $filterarray = array(0, 2, 3);
4735 } elseif ($filtertype ==
'DBIT') {
4736 $filterarray = array(1, 2, 3);
4737 } elseif ($filtertype !=
'' && $filtertype !=
'-1') {
4738 $filterarray = explode(
',', $filtertype);
4745 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TYPE_ID", LOG_NOTICE);
4749 $out .=
'<select id="select' . $htmlname .
'" class="flat selectpaymenttypes' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4751 $out .=
'<option value=""> </option>';
4753 foreach ($this->cache_types_paiements as
$id => $arraytypes) {
4755 if ($active >= 0 && $arraytypes[
'active'] != $active) {
4760 if (count($filterarray) && !in_array($arraytypes[
'type'], $filterarray)) {
4765 if ($empty && empty($arraytypes[
'code'])) {
4770 $out .=
'<option value="' .
$id .
'" data-code="'.$arraytypes[
'code'].
'"';
4771 } elseif ($format == 1) {
4772 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
4773 } elseif ($format == 2) {
4774 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
4775 } elseif ($format == 3) {
4776 $out .=
'<option value="' .
$id .
'"';
4779 if ($format == 1 || $format == 2) {
4780 if ($selected == $arraytypes[
'code']) {
4781 $out .=
' selected';
4784 if ($selected ==
$id) {
4785 $out .=
' selected';
4791 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4792 } elseif ($format == 1) {
4793 $value = $arraytypes[
'code'];
4794 } elseif ($format == 2) {
4795 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4796 } elseif ($format == 3) {
4797 $value = $arraytypes[
'code'];
4799 $out .= $value ? $value :
' ';
4800 $out .=
'</option>';
4802 $out .=
'</select>';
4803 if ($user->admin && !$noadmininfo) {
4804 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4808 if (empty($nooutput)) {
4828 $return =
'<select class="flat maxwidth100" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
4830 'HT' => $langs->trans(
"HT"),
4831 'TTC' => $langs->trans(
"TTC")
4833 foreach ($options as
$id => $value) {
4834 if ($selected ==
$id) {
4835 $return .=
'<option value="' .
$id .
'" selected>' . $value;
4837 $return .=
'<option value="' .
$id .
'">' . $value;
4839 $return .=
'</option>';
4841 $return .=
'</select>';
4861 $num = count($this->cache_transport_mode);
4868 $this->cache_transport_mode = array();
4870 $sql =
"SELECT rowid, code, label, active";
4871 $sql .=
" FROM " . $this->db->prefix() .
"c_transport_mode";
4872 $sql .=
" WHERE entity IN (" .
getEntity(
'c_transport_mode') .
")";
4874 $resql = $this->db->query($sql);
4876 $num = $this->db->num_rows($resql);
4879 $obj = $this->db->fetch_object($resql);
4882 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) !=
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4883 $this->cache_transport_mode[$obj->rowid][
'rowid'] = $obj->rowid;
4884 $this->cache_transport_mode[$obj->rowid][
'code'] = $obj->code;
4885 $this->cache_transport_mode[$obj->rowid][
'label'] = $label;
4886 $this->cache_transport_mode[$obj->rowid][
'active'] = $obj->active;
4890 $this->cache_transport_mode =
dol_sort_array($this->cache_transport_mode,
'label',
'asc', 0, 0, 1);
4912 public function selectTransportMode($selected =
'', $htmlname =
'transportmode', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'')
4914 global $langs, $user;
4916 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $format, LOG_DEBUG);
4920 print
'<select id="select' . $htmlname .
'" class="flat selectmodetransport' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4922 print
'<option value=""> </option>';
4924 foreach ($this->cache_transport_mode as
$id => $arraytypes) {
4926 if ($active >= 0 && $arraytypes[
'active'] != $active) {
4931 if ($empty && empty($arraytypes[
'code'])) {
4936 print
'<option value="' .
$id .
'"';
4937 } elseif ($format == 1) {
4938 print
'<option value="' . $arraytypes[
'code'] .
'"';
4939 } elseif ($format == 2) {
4940 print
'<option value="' . $arraytypes[
'code'] .
'"';
4941 } elseif ($format == 3) {
4942 print
'<option value="' .
$id .
'"';
4945 if (preg_match(
'/[a-z]/i', $selected) && $selected == $arraytypes[
'code']) {
4947 } elseif ($selected ==
$id) {
4953 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4954 } elseif ($format == 1) {
4955 $value = $arraytypes[
'code'];
4956 } elseif ($format == 2) {
4957 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4958 } elseif ($format == 3) {
4959 $value = $arraytypes[
'code'];
4961 print $value ? $value :
' ';
4968 if ($user->admin && !$noadmininfo) {
4969 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4985 public function selectShippingMethod($selected =
'', $htmlname =
'shipping_method_id', $filtre =
'', $useempty = 0, $moreattrib =
'', $noinfoadmin = 0, $morecss =
'')
4987 global $langs, $user;
4989 $langs->load(
"admin");
4990 $langs->load(
"deliveries");
4992 $sql =
"SELECT rowid, code, libelle as label";
4993 $sql .=
" FROM " . $this->db->prefix() .
"c_shipment_mode";
4994 $sql .=
" WHERE active > 0";
4996 $sql .=
" AND " . $filtre;
4998 $sql .=
" ORDER BY libelle ASC";
5000 dol_syslog(get_class($this) .
"::selectShippingMode", LOG_DEBUG);
5001 $result = $this->db->query($sql);
5003 $num = $this->db->num_rows($result);
5006 print
'<select id="select' . $htmlname .
'" class="flat selectshippingmethod' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5007 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5008 print
'<option value="-1"> </option>';
5011 $obj = $this->db->fetch_object($result);
5012 if ($selected == $obj->rowid) {
5013 print
'<option value="' . $obj->rowid .
'" selected>';
5015 print
'<option value="' . $obj->rowid .
'">';
5017 print ($langs->trans(
"SendingMethod" . strtoupper($obj->code)) !=
"SendingMethod" . strtoupper($obj->code)) ? $langs->trans(
"SendingMethod" . strtoupper($obj->code)) : $obj->label;
5022 if ($user->admin && empty($noinfoadmin)) {
5023 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5028 print $langs->trans(
"NoShippingMethodDefined");
5048 $langs->load(
"deliveries");
5050 if ($htmlname !=
"none") {
5051 print
'<form method="POST" action="' . $page .
'">';
5052 print
'<input type="hidden" name="action" value="setshippingmethod">';
5053 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5055 print
'<input type="submit" class="button valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5059 $code = $langs->getLabelFromKey($this->db, $selected,
'c_shipment_mode',
'rowid',
'code');
5060 print $langs->trans(
"SendingMethod" . strtoupper($code));
5079 $langs->load(
'bills');
5081 $opt =
'<option value="" selected></option>';
5082 $sql =
"SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc";
5083 $sql .=
' FROM ' . $this->db->prefix() .
'facture';
5084 $sql .=
' WHERE entity IN (' .
getEntity(
'invoice') .
')';
5085 $sql .=
' AND situation_counter >= 1';
5086 $sql .=
' AND fk_soc = ' . (int) $socid;
5087 $sql .=
' AND type <> 2';
5088 $sql .=
' ORDER by situation_cycle_ref, situation_counter desc';
5089 $resql = $this->db->query($sql);
5091 if ($resql && $this->db->num_rows($resql) > 0) {
5094 while ($obj = $this->db->fetch_object($resql)) {
5096 if ($obj->situation_cycle_ref != $ref) {
5098 $ref = $obj->situation_cycle_ref;
5100 if ($obj->situation_final != 1) {
5102 if (substr($obj->ref, 1, 4) !=
'PROV') {
5103 if ($selected == $obj->rowid) {
5104 $opt .=
'<option value="' . $obj->rowid .
'" selected>' . $obj->ref .
'</option>';
5106 $opt .=
'<option value="' . $obj->rowid .
'">' . $obj->ref .
'</option>';
5113 dol_syslog(
"Error sql=" . $sql .
", error=" . $this->error, LOG_ERR);
5115 if ($opt ==
'<option value ="" selected></option>') {
5116 $opt =
'<option value ="0" selected>' . $langs->trans(
'NoSituations') .
'</option>';
5130 public function selectUnits($selected =
'', $htmlname =
'units', $showempty = 0, $unit_type =
'')
5134 $langs->load(
'products');
5136 $return =
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'">';
5138 $sql =
"SELECT rowid, label, code FROM " . $this->db->prefix() .
"c_units";
5139 $sql .=
' WHERE active > 0';
5140 if (!empty($unit_type)) {
5141 $sql .=
" AND unit_type = '" . $this->db->escape($unit_type) .
"'";
5143 $sql .=
" ORDER BY sortorder";
5145 $resql = $this->db->query($sql);
5146 if ($resql && $this->db->num_rows($resql) > 0) {
5148 $return .=
'<option value="-1"></option>';
5151 while ($res = $this->db->fetch_object($resql)) {
5152 $unitLabel = $res->label;
5153 if (!empty($langs->tab_translate[
'unit' . $res->code])) {
5154 $unitLabel = $langs->trans(
'unit' . $res->code) != $res->label ? $langs->trans(
'unit' . $res->code) : $res->label;
5157 if ($selected == $res->rowid) {
5158 $return .=
'<option value="' . $res->rowid .
'" selected>' . $unitLabel .
'</option>';
5160 $return .=
'<option value="' . $res->rowid .
'">' . $unitLabel .
'</option>';
5163 $return .=
'</select>';
5186 public function select_comptes($selected =
'', $htmlname =
'accountid', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'', $showcurrency = 0, $morecss =
'', $nooutput = 0)
5193 $langs->loadLangs(array(
"admin",
"banks"));
5196 $sql =
"SELECT rowid, label, bank, clos as status, currency_code";
5197 $sql .=
" FROM " . $this->db->prefix() .
"bank_account";
5198 $sql .=
" WHERE entity IN (" .
getEntity(
'bank_account') .
")";
5200 $sql .=
" AND clos = " . (int) $status;
5203 $sql .=
" AND " . $filtre;
5205 $sql .=
" ORDER BY label";
5207 dol_syslog(get_class($this) .
"::select_comptes", LOG_DEBUG);
5208 $result = $this->db->query($sql);
5210 $num = $this->db->num_rows($result);
5213 $out .=
'<select id="select' . $htmlname .
'" class="flat selectbankaccount' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5217 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoActiveBankAccountDefined") .
'</span>';
5219 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoBankAccountDefined") .
'</span>';
5222 if (!empty($useempty) && !is_numeric($useempty)) {
5223 $out .=
'<option value="-1">'.$langs->trans($useempty).
'</option>';
5224 } elseif ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5225 $out .=
'<option value="-1"> </option>';
5230 $obj = $this->db->fetch_object($result);
5232 $labeltoshow = trim($obj->label);
5233 $labeltoshowhtml = trim($obj->label);
5234 if ($showcurrency) {
5235 $labeltoshow .=
' (' . $obj->currency_code .
')';
5236 $labeltoshowhtml .=
' <span class="opacitymedium">(' . $obj->currency_code .
')</span>';
5238 if ($status == 2 && $obj->status == 1) {
5239 $labeltoshow .=
' (' . $langs->trans(
"Closed") .
')';
5240 $labeltoshowhtml .=
' <span class="opacitymedium">(' . $langs->trans(
"Closed") .
')</span>';
5243 if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
5244 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml).
'" selected>';
5246 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml).
'">';
5248 $out .= $labeltoshow;
5249 $out .=
'</option>';
5252 $out .=
"</select>";
5259 if (empty($nooutput)) {
5281 public function selectRib($selected =
'', $htmlname =
'ribcompanyid', $filtre =
'', $useempty = 0, $moreattrib =
'', $showibanbic = 0, $morecss =
'', $nooutput = 0)
5288 $langs->loadLangs(array(
"admin",
"banks"));
5291 $sql =
"SELECT rowid, label, bank, status, iban_prefix, bic";
5292 $sql .=
" FROM " . $this->db->prefix() .
"societe_rib";
5293 $sql .=
" WHERE type = 'ban'";
5295 $sql .=
" AND " . $filtre;
5297 $sql .=
" ORDER BY label";
5298 dol_syslog(get_class($this) .
"::select_comptes", LOG_DEBUG);
5299 $result = $this->db->query($sql);
5301 $num = $this->db->num_rows($result);
5304 $out .=
'<select id="select' . $htmlname .
'" class="flat selectbankaccount' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5307 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoBankAccountDefined") .
'</span>';
5309 if (!empty($useempty) && !is_numeric($useempty)) {
5310 $out .=
'<option value="-1">'.$langs->trans($useempty).
'</option>';
5311 } elseif ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5312 $out .=
'<option value="-1"> </option>';
5317 $obj = $this->db->fetch_object($result);
5319 if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
5320 $out .=
'<option value="' . $obj->rowid .
'" data-iban-prefix="' . $iban .
' data-bic="' . $obj->bic .
'" selected>';
5322 $out .=
'<option value="' . $obj->rowid .
'" data-iban-prefix="' . $iban .
' data-bic="' . $obj->bic .
'">';
5324 $out .= trim($obj->label);
5326 $out .=
' (' . $iban .
'/' .$obj->bic.
')';
5328 $out .=
'</option>';
5331 $out .=
"</select>";
5338 if (empty($nooutput)) {
5358 public function selectEstablishments($selected =
'', $htmlname =
'entity', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'')
5362 $langs->load(
"admin");
5365 $sql =
"SELECT rowid, name, fk_country, status, entity";
5366 $sql .=
" FROM " . $this->db->prefix() .
"establishment";
5367 $sql .=
" WHERE 1=1";
5369 $sql .=
" AND status = " . (int) $status;
5372 $sql .=
" AND " . $filtre;
5374 $sql .=
" ORDER BY name";
5376 dol_syslog(get_class($this) .
"::select_establishment", LOG_DEBUG);
5377 $result = $this->db->query($sql);
5379 $num = $this->db->num_rows($result);
5382 print
'<select id="select' . $htmlname .
'" class="flat selectestablishment" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5383 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5384 print
'<option value="-1"> </option>';
5388 $obj = $this->db->fetch_object($result);
5389 if ($selected == $obj->rowid) {
5390 print
'<option value="' . $obj->rowid .
'" selected>';
5392 print
'<option value="' . $obj->rowid .
'">';
5394 print trim($obj->name);
5395 if ($status == 2 && $obj->status == 1) {
5396 print
' (' . $langs->trans(
"Closed") .
')';
5404 print
'<span class="opacitymedium">' . $langs->trans(
"NoActiveEstablishmentDefined") .
'</span>';
5406 print
'<span class="opacitymedium">' . $langs->trans(
"NoEstablishmentFound") .
'</span>';
5429 if ($htmlname !=
"none") {
5430 print
'<form method="POST" action="' . $page .
'">';
5431 print
'<input type="hidden" name="action" value="setbankaccount">';
5432 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5433 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
5434 $nbaccountfound = $this->
select_comptes($selected, $htmlname, 0,
'', $addempty);
5435 if ($nbaccountfound > 0) {
5436 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5440 $langs->load(
'banks');
5443 require_once DOL_DOCUMENT_ROOT .
'/compta/bank/class/account.class.php';
5444 $bankstatic =
new Account($this->db);
5445 $result = $bankstatic->fetch($selected);
5447 print $bankstatic->getNomUrl(1);
5466 public function formRib($page, $selected =
'', $htmlname =
'ribcompanyid', $filtre =
'', $addempty = 0, $showibanbic = 0)
5469 if ($htmlname !=
"none") {
5470 print
'<form method="POST" action="' . $page .
'">';
5471 print
'<input type="hidden" name="action" value="setbankaccountcustomer">';
5472 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5473 $nbaccountfound = $this->
selectRib($selected, $htmlname, $filtre, $addempty,
'', $showibanbic);
5474 if ($nbaccountfound > 0) {
5475 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5479 $langs->load(
'banks');
5482 require_once DOL_DOCUMENT_ROOT .
'/societe/class/companybankaccount.class.php';
5484 $result = $bankstatic->fetch($selected);
5486 print $bankstatic->label;
5488 print
' (' . $bankstatic->iban .
'/' .$bankstatic->bic.
')';
5518 public function select_all_categories($type, $selected =
'', $htmlname =
"parent", $maxlength = 64, $fromid = 0, $outputmode = 0, $include = 0, $morecss =
'', $useempty = 1)
5521 global
$conf, $langs;
5522 $langs->load(
"categories");
5524 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
5527 if (is_numeric($type)) {
5528 dol_syslog(__METHOD__ .
': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING);
5531 if ($type === Categorie::TYPE_BANK_LINE) {
5534 $cate_arbo = array();
5535 $sql =
"SELECT c.label, c.rowid";
5536 $sql .=
" FROM " . $this->db->prefix() .
"categorie as c";
5537 $sql .=
" WHERE entity = " .
$conf->entity .
" AND type = " . ((int) $cat->getMapId()[$type]);
5538 $sql .=
" ORDER BY c.label";
5539 $result = $this->db->query($sql);
5541 $num = $this->db->num_rows($result);
5544 $objp = $this->db->fetch_object($result);
5546 $cate_arbo[$objp->rowid] = array(
'id' => $objp->rowid,
'fulllabel' => $objp->label,
'color' =>
'',
'picto' =>
'category');
5550 $this->db->free($result);
5556 $cate_arbo = $cat->get_full_arbo($type, $fromid, $include);
5559 $outarray = array();
5560 $outarrayrichhtml = array();
5563 $output =
'<select class="flat minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
5564 if (is_array($cate_arbo)) {
5565 $num = count($cate_arbo);
5568 $output .=
'<option value="-1" disabled>' . $langs->trans(
"NoCategoriesDefined") .
'</option>';
5570 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5571 $output .=
'<option value="-1"> </option>';
5573 foreach ($cate_arbo as $key => $value) {
5574 if ($cate_arbo[$key][
'id'] == $selected || ($selected ===
'auto' && count($cate_arbo) == 1)) {
5580 $labeltoshow =
img_picto(
'',
'category',
'class="pictofixedwidth" style="color: #' . $cate_arbo[$key][
'color'] .
'"');
5581 $labeltoshow .=
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle');
5583 $outarray[$cate_arbo[$key][
'id']] = $cate_arbo[$key][
'fulllabel'];
5585 $outarrayrichhtml[$cate_arbo[$key][
'id']] = $labeltoshow;
5587 $output .=
'<option ' . $add .
'value="' . $cate_arbo[$key][
'id'] .
'"';
5590 $output .=
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle');
5591 $output .=
'</option>';
5593 $cate_arbo[$key][
'data-html'] = $labeltoshow;
5597 $output .=
'</select>';
5600 if ($outputmode == 2) {
5603 } elseif ($outputmode == 1) {
5605 } elseif ($outputmode == 3) {
5606 return $outarrayrichhtml;
5631 public function form_confirm($page, $title, $question, $action, $formquestion = array(), $selectedchoice =
"", $useajax = 0, $height = 170, $width = 500)
5634 dol_syslog(__METHOD__ .
': using form_confirm is deprecated. Use formconfim instead.', LOG_WARNING);
5635 print $this->
formconfirm($page, $title, $question, $action, $formquestion, $selectedchoice, $useajax, $height, $width);
5665 public function formconfirm($page, $title, $question, $action, $formquestion =
'', $selectedchoice =
'', $useajax = 0, $height = 0, $width = 500, $disableformtag = 0, $labelbuttonyes =
'Yes', $labelbuttonno =
'No')
5667 global $langs,
$conf;
5669 $more =
'<!-- formconfirm - before call, page=' .
dol_escape_htmltag($page) .
' -->';
5675 $newselectedchoice = empty($selectedchoice) ?
"no" : $selectedchoice;
5676 if (
$conf->browser->layout ==
'phone') {
5681 if (empty($height)) {
5683 if (is_array($formquestion) && count($formquestion) > 2) {
5684 $height += ((count($formquestion) - 2) * 24);
5688 if (is_array($formquestion) && !empty($formquestion)) {
5690 foreach ($formquestion as $key => $input) {
5691 if (is_array($input) && !empty($input)) {
5692 if ($input[
'type'] ==
'hidden') {
5693 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
5694 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
5702 $moreonecolumn =
'';
5703 $more .=
'<div class="tagtable paddingtopbottomonly centpercent noborderspacing">' .
"\n";
5704 foreach ($formquestion as $key => $input) {
5705 if (is_array($input) && !empty($input)) {
5706 $size = (!empty($input[
'size']) ?
' size="' . $input[
'size'] .
'"' :
'');
5707 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
5708 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
5710 if ($input[
'type'] ==
'text') {
5711 $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";
5712 } elseif ($input[
'type'] ==
'password') {
5713 $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";
5714 } elseif ($input[
'type'] ==
'textarea') {
5720 $moreonecolumn .=
'<div class="margintoponly">';
5721 $moreonecolumn .= $input[
'label'] .
'<br>';
5723 $moreonecolumn .= $input[
'value'];
5724 $moreonecolumn .=
'</textarea>';
5725 $moreonecolumn .=
'</div>';
5726 } elseif (in_array($input[
'type'], [
'select',
'multiselect'])) {
5727 if (empty($morecss)) {
5728 $morecss =
'minwidth100';
5731 $show_empty = isset($input[
'select_show_empty']) ? $input[
'select_show_empty'] : 1;
5732 $key_in_label = isset($input[
'select_key_in_label']) ? $input[
'select_key_in_label'] : 0;
5733 $value_as_key = isset($input[
'select_value_as_key']) ? $input[
'select_value_as_key'] : 0;
5734 $translate = isset($input[
'select_translate']) ? $input[
'select_translate'] : 0;
5735 $maxlen = isset($input[
'select_maxlen']) ? $input[
'select_maxlen'] : 0;
5736 $disabled = isset($input[
'select_disabled']) ? $input[
'select_disabled'] : 0;
5737 $sort = isset($input[
'select_sort']) ? $input[
'select_sort'] :
'';
5739 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">';
5740 if (!empty($input[
'label'])) {
5741 $more .= $input[
'label'] .
'</div><div class="tagtd left">';
5743 if ($input[
'type'] ==
'select') {
5744 $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);
5746 $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);
5748 $more .=
'</div></div>' .
"\n";
5749 } elseif ($input[
'type'] ==
'checkbox') {
5750 $more .=
'<div class="tagtr">';
5751 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'"><label for="' .
dol_escape_htmltag($input[
'name']) .
'">' . $input[
'label'] .
'</label></div><div class="tagtd">';
5752 $more .=
'<input type="checkbox" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' .
dol_escape_htmltag($input[
'name']) .
'" name="' .
dol_escape_htmltag($input[
'name']) .
'"' . $moreattr;
5753 if (!is_bool($input[
'value']) && $input[
'value'] !=
'false' && $input[
'value'] !=
'0' && $input[
'value'] !=
'') {
5754 $more .=
' checked';
5756 if (is_bool($input[
'value']) && $input[
'value']) {
5757 $more .=
' checked';
5759 if (isset($input[
'disabled'])) {
5760 $more .=
' disabled';
5762 $more .=
' /></div>';
5763 $more .=
'</div>' .
"\n";
5764 } elseif ($input[
'type'] ==
'radio') {
5766 foreach ($input[
'values'] as $selkey => $selval) {
5767 $more .=
'<div class="tagtr">';
5768 if (isset($input[
'label'])) {
5770 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
' tdtop' : (
' tdtop ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
5772 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' "' . $input[
'tdclass'])) .
'"> </div>';
5775 $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;
5776 if (!empty($input[
'disabled'])) {
5777 $more .=
' disabled';
5779 if (isset($input[
'default']) && $input[
'default'] === $selkey) {
5780 $more .=
' checked="checked"';
5783 $more .=
'<label for="' .
dol_escape_htmltag($input[
'name'] . $selkey) .
'" class="valignmiddle">' . $selval .
'</label>';
5784 $more .=
'</div></div>' .
"\n";
5787 } elseif ($input[
'type'] ==
'date' || $input[
'type'] ==
'datetime') {
5788 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
5789 $more .=
'<div class="tagtd">';
5790 $addnowlink = (empty($input[
'datenow']) ? 0 : 1);
5792 if ($input[
'type'] ==
'datetime') {
5793 $h = isset($input[
'hours']) ? $input[
'hours'] : 1;
5794 $m = isset($input[
'minutes']) ? $input[
'minutes'] : 1;
5796 $more .= $this->
selectDate(isset($input[
'value']) ? $input[
'value'] : -1, $input[
'name'], $h, $m, 0,
'', 1, $addnowlink);
5797 $more .=
'</div></div>'.
"\n";
5798 $formquestion[] = array(
'name' => $input[
'name'].
'day');
5799 $formquestion[] = array(
'name' => $input[
'name'].
'month');
5800 $formquestion[] = array(
'name' => $input[
'name'].
'year');
5801 $formquestion[] = array(
'name' => $input[
'name'].
'hour');
5802 $formquestion[] = array(
'name' => $input[
'name'].
'min');
5803 } elseif ($input[
'type'] ==
'other') {
5804 $more .=
'<div class="tagtr"><div class="tagtd'.(empty($input[
'tdclass']) ?
'' : (
' '.$input[
'tdclass'])).
'">';
5805 if (!empty($input[
'label'])) {
5806 $more .= $input[
'label'] .
'</div><div class="tagtd">';
5808 $more .= $input[
'value'];
5809 $more .=
'</div></div>' .
"\n";
5810 } elseif ($input[
'type'] ==
'onecolumn') {
5811 $moreonecolumn .=
'<div class="margintoponly">';
5812 $moreonecolumn .= $input[
'value'];
5813 $moreonecolumn .=
'</div>' .
"\n";
5814 } elseif ($input[
'type'] ==
'hidden') {
5816 } elseif ($input[
'type'] ==
'separator') {
5819 $more .=
'Error type ' . $input[
'type'] .
' for the confirm box is not a supported type';
5823 $more .=
'</div>' .
"\n";
5824 $more .= $moreonecolumn;
5830 if (!empty(
$conf->dol_use_jmobile)) {
5833 if (empty(
$conf->use_javascript_ajax)) {
5839 $dialogconfirm =
'dialog-confirm';
5841 if (!is_numeric($useajax)) {
5845 $dialogconfirm .=
'-' . $button;
5847 $pageyes = $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=yes';
5848 $pageno = ($useajax == 2 ? $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=no' :
'');
5851 if (is_array($formquestion)) {
5852 foreach ($formquestion as $key => $input) {
5855 if (is_array($input) && isset($input[
'name'])) {
5856 if (strpos($input[
'name'],
',') > 0) {
5857 $inputok = array_merge($inputok, explode(
',', $input[
'name']));
5859 array_push($inputok, $input[
'name']);
5864 if (is_array($input) && isset($input[
'inputko']) && $input[
'inputko'] == 1 && isset($input[
'name'])) {
5865 array_push($inputko, $input[
'name']);
5871 $formconfirm .=
'<div id="' . $dialogconfirm .
'" title="' .
dol_escape_htmltag($title) .
'" style="display: none;">';
5872 if (is_array($formquestion) && array_key_exists(
'text', $formquestion) && !empty($formquestion[
'text'])) {
5873 $formconfirm .=
'<div class="confirmtext">' . $formquestion[
'text'] .
'</div>' .
"\n";
5875 if (!empty($more)) {
5876 $formconfirm .=
'<div class="confirmquestions">' . $more .
'</div>' .
"\n";
5878 $formconfirm .= ($question ?
'<div class="confirmmessage">' .
img_help(0,
'') .
' ' . $question .
'</div>' :
'');
5879 $formconfirm .=
'</div>' .
"\n";
5881 $formconfirm .=
"\n<!-- begin code of popup for formconfirm page=" . $page .
" -->\n";
5882 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
5883 $formconfirm .=
"/* Code for the jQuery('#dialogforpopup').dialog() */\n";
5884 $formconfirm .=
'jQuery(document).ready(function() {
5886 $( "#' . $dialogconfirm .
'" ).dialog(
5888 autoOpen: ' . ($autoOpen ?
"true" :
"false") .
',';
5889 if ($newselectedchoice ==
'no') {
5892 $(this).parent().find("button.ui-button:eq(2)").focus();
5897 if ($useajax == 1) {
5898 $jsforcursor =
'// The call to urljump can be slow, so we set the wait cursor' .
"\n";
5899 $jsforcursor .=
'jQuery("html,body,#id-container").addClass("cursorwait");' .
"\n";
5902 $postconfirmas =
'GET';
5909 closeOnEscape:
false,
5911 "' . dol_escape_js($langs->transnoentities($labelbuttonyes)) . '":
function() {
5912 var options =
"token=' . urlencode(newToken()) . '";
5913 var inputok =
' . json_encode($inputok) . ';
5914 var page = \
'' .
dol_escape_js(!empty($page) ? $page :
'') .
'\';
5915 var pageyes = \
'' .
dol_escape_js(!empty($pageyes) ? $pageyes :
'') .
'\';
5917 if (inputok.length > 0) {
5918 $.each(inputok,
function(i, inputname) {
5921 if ($(
"input[name=\'" + inputname +
"\']").attr(
"type") ==
"radio") {
5922 inputvalue = $(
"input[name=\'" + inputname +
"\']:checked").val();
5924 if ($(
"#" + inputname).attr(
"type") ==
"checkbox") { more =
":checked"; }
5925 inputvalue = $(
"#" + inputname + more).val();
5927 if (typeof inputvalue ==
"undefined") { inputvalue=
""; }
5928 console.log(
"formconfirm check inputname="+inputname+
" inputvalue="+inputvalue);
5929 options +=
"&" + inputname +
"=" + encodeURIComponent(inputvalue);
5932 var urljump = pageyes + (pageyes.indexOf(
"?") < 0 ?
"?" :
"&") + options;
5933 if (pageyes.length > 0) {
';
5934 if ($postconfirmas == 'GET
') {
5935 $formconfirm .= 'location.href = urljump;
';
5937 $formconfirm .= $jsforcursor;
5938 $formconfirm .= 'var post = $.post(
5941 function(data) { $(
"body").html(data); jQuery(
"html,body,#id-container").removeClass(
"cursorwait"); }
5945 console.log(
"after post ok");
5947 $(
this).dialog(
"close");
5949 "' . dol_escape_js($langs->transnoentities($labelbuttonno)) . '":
function() {
5950 var options =
"token=' . urlencode(newToken()) . '";
5951 var inputko =
' . json_encode($inputko) . ';
5952 var page =
"' . dol_escape_js(!empty($page) ? $page : '') . '";
5953 var pageno=
"' . dol_escape_js(!empty($pageno) ? $pageno : '') . '";
5954 if (inputko.length > 0) {
5955 $.each(inputko,
function(i, inputname) {
5957 if ($(
"#" + inputname).attr(
"type") ==
"checkbox") { more =
":checked"; }
5958 var inputvalue = $(
"#" + inputname + more).val();
5959 if (typeof inputvalue ==
"undefined") { inputvalue=
""; }
5960 options +=
"&" + inputname +
"=" + encodeURIComponent(inputvalue);
5963 var urljump=pageno + (pageno.indexOf(
"?") < 0 ?
"?" :
"&") + options;
5965 if (pageno.length > 0) {
';
5966 if ($postconfirmas == 'GET
') {
5967 $formconfirm .= 'location.href = urljump;
';
5969 $formconfirm .= $jsforcursor;
5970 $formconfirm .= 'var post = $.post(
5973 function(data) { $(
"body").html(data); jQuery(
"html,body,#id-container").removeClass(
"cursorwait"); }
5977 console.log(
"after post ko");
5979 $(
this).dialog(
"close");
5985 var
button =
"' . $button . '";
5987 $(
"#" +
button ).click(
function() {
5988 $(
"#' . $dialogconfirm . '").dialog(
"open");
5994 $formconfirm .= "<!-- end ajax formconfirm -->\n";
5996 $formconfirm .= "\n<!-- begin formconfirm page=" . dol_escape_htmltag($page) . " -->\n";
5998 if (empty($disableformtag)) {
5999 $formconfirm .= '<form method=
"POST" action=
"' . $page . '" class=
"notoptoleftnoright">
' . "\n";
6002 $formconfirm .= '<input
type=
"hidden" name=
"action" value=
"' . $action . '">
' . "\n";
6003 $formconfirm .= '<input
type=
"hidden" name=
"token" value=
"' . newToken() . '">
' . "\n";
6005 $formconfirm .= '<
table class=
"valid centpercent">
' . "\n";
6008 $formconfirm .= '<tr
class=
"validtitre"><td
class=
"validtitre" colspan=
"2">
';
6009 $formconfirm .= img_picto('', 'pictoconfirm
') . ' ' . $title;
6010 $formconfirm .= '</td></tr>
' . "\n";
6013 if (is_array($formquestion) && array_key_exists('text
', $formquestion) && !empty($formquestion['text
'])) {
6014 $formconfirm .= '<tr
class=
"valid"><td
class=
"valid" colspan=
"2">
' . $formquestion['text
'] . '</td></tr>
' . "\n";
6019 $formconfirm .= '<tr
class=
"valid"><td
class=
"valid" colspan=
"2">
' . "\n";
6020 $formconfirm .= $more;
6021 $formconfirm .= '</td></tr>
' . "\n";
6024 // Line with question
6025 $formconfirm .= '<tr
class=
"valid">
';
6026 $formconfirm .= '<td
class=
"valid">
' . $question . '</td>
';
6027 $formconfirm .= '<td
class=
"valid center">
';
6028 $formconfirm .= $this->selectyesno("confirm", $newselectedchoice, 0, false, 0, 0, 'marginleftonly marginrightonly
', $labelbuttonyes, $labelbuttonno);
6029 $formconfirm .= '<input
class=
"button valignmiddle confirmvalidatebutton small" type=
"submit" value=
"' . $langs->trans("Validate") . '">
';
6030 $formconfirm .= '</td>
';
6031 $formconfirm .= '</tr>
' . "\n";
6033 $formconfirm .= '</
table>
' . "\n";
6035 if (empty($disableformtag)) {
6036 $formconfirm .= "</form>\n";
6038 $formconfirm .= '<br>
';
6040 if (!empty($conf->use_javascript_ajax)) {
6041 $formconfirm .= '<!-- code to disable
button to avoid
double clic -->
';
6042 $formconfirm .= '<script nonce=
"' . getNonce() . '" type=
"text/javascript">
' . "\n";
6044 $(document).ready(
function () {
6045 $(
".confirmvalidatebutton").on(
"click",
function() {
6046 console.log(
"We click on button confirmvalidatebutton");
6047 $(
this).attr(
"disabled",
"disabled");
6048 setTimeout(\
'$(".confirmvalidatebutton").removeAttr("disabled")\', 3000);
6049 //console.log($(this).closest("form"));
6050 $(this).closest("form").submit();
6054 $formconfirm .=
'</script>' .
"\n";
6057 $formconfirm .=
"<!-- end formconfirm -->\n";
6060 return $formconfirm;
6081 public function form_project($page, $socid, $selected =
'', $htmlname =
'projectid', $discard_closed = 0, $maxlength = 20, $forcefocus = 0, $nooutput = 0, $textifnoproject =
'', $morecss =
'')
6086 require_once DOL_DOCUMENT_ROOT .
'/core/lib/project.lib.php';
6087 require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formprojet.class.php';
6093 $langs->load(
"project");
6094 if ($htmlname !=
"none") {
6095 $out .=
'<form method="post" action="' . $page .
'">';
6096 $out .=
'<input type="hidden" name="action" value="classin">';
6097 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6098 $out .= $formproject->select_projects($socid, $selected, $htmlname, $maxlength, 0, 1, $discard_closed, $forcefocus, 0, 0,
'', 1, 0, $morecss);
6099 $out .=
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6102 $out .=
'<span class="project_head_block">';
6104 $projet =
new Project($this->db);
6105 $projet->fetch($selected);
6106 $out .= $projet->getNomUrl(0,
'', 1);
6108 $out .=
'<span class="opacitymedium">' . $textifnoproject .
'</span>';
6113 if (empty($nooutput)) {
6137 public function form_conditions_reglement($page, $selected =
'', $htmlname =
'cond_reglement_id', $addempty = 0, $type =
'', $filtertype = -1, $deposit_percent = -1, $nooutput = 0)
6144 if ($htmlname !=
"none") {
6145 $out .=
'<form method="POST" action="' . $page .
'">';
6146 $out .=
'<input type="hidden" name="action" value="setconditions">';
6147 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6149 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
6151 $out .= $this->getSelectConditionsPaiements($selected, $htmlname, $filtertype, $addempty, 0,
'', $deposit_percent);
6152 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6156 $this->load_cache_conditions_paiements();
6157 if (isset($this->cache_conditions_paiements[$selected])) {
6158 $label = $this->cache_conditions_paiements[$selected][
'label'];
6160 if (!empty($this->cache_conditions_paiements[$selected][
'deposit_percent'])) {
6161 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $this->cache_conditions_paiements[$selected][
'deposit_percent'], $label);
6166 $langs->load(
'errors');
6167 $out .= $langs->trans(
'ErrorNotInDictionaryPaymentConditions');
6174 if (empty($nooutput)) {
6196 if ($htmlname !=
"none") {
6197 print
'<form method="post" action="' . $page .
'">';
6198 print
'<input type="hidden" name="action" value="setavailability">';
6199 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6200 $this->selectAvailabilityDelay($selected, $htmlname,
'', $addempty);
6201 print
'<input type="submit" name="modify" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6202 print
'<input type="submit" name="cancel" class="button smallpaddingimp" value="' . $langs->trans(
"Cancel") .
'">';
6206 $this->load_cache_availability();
6207 print $this->cache_availability[$selected][
'label'];
6224 public function formInputReason($page, $selected =
'', $htmlname =
'demandreason', $addempty = 0)
6227 if ($htmlname !=
"none") {
6228 print
'<form method="post" action="' . $page .
'">';
6229 print
'<input type="hidden" name="action" value="setdemandreason">';
6230 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6231 $this->selectInputReason($selected, $htmlname,
'-1', $addempty);
6232 print
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6236 $this->loadCacheInputReason();
6237 foreach ($this->cache_demand_reason as $key => $val) {
6238 if ($val[
'id'] == $selected) {
6239 print $val[
'label'];
6264 public function form_date($page, $selected, $htmlname, $displayhour = 0, $displaymin = 0, $nooutput = 0, $type =
'')
6271 if ($htmlname !=
"none") {
6272 $ret .=
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
6273 $ret .=
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
6274 $ret .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6276 $ret .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
6278 $ret .=
'<table class="nobordernopadding">';
6280 $ret .= $this->selectDate($selected, $htmlname, $displayhour, $displaymin, 1,
'form' . $htmlname, 1, 0);
6282 $ret .=
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
6283 $ret .=
'</tr></table></form>';
6292 if (empty($nooutput)) {
6311 public function form_users($page, $selected =
'', $htmlname =
'userid', $exclude = array(), $include = array())
6316 if ($htmlname !=
"none") {
6317 print
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
6318 print
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
6319 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6320 print $this->select_dolusers($selected, $htmlname, 1, $exclude, 0, $include);
6321 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6325 require_once DOL_DOCUMENT_ROOT .
'/user/class/user.class.php';
6326 $theuser =
new User($this->db);
6327 $theuser->fetch($selected);
6328 print $theuser->getNomUrl(1);
6351 public function form_modes_reglement($page, $selected =
'', $htmlname =
'mode_reglement_id', $filtertype =
'', $active = 1, $addempty = 0, $type =
'', $nooutput = 0)
6357 if ($htmlname !=
"none") {
6358 $out .=
'<form method="POST" action="' . $page .
'">';
6359 $out .=
'<input type="hidden" name="action" value="setmode">';
6360 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6362 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
6364 $out .= $this->select_types_paiements($selected, $htmlname, $filtertype, 0, $addempty, 0, 0, $active,
'', 1);
6365 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6369 $this->load_cache_types_paiements();
6370 $out .= $this->cache_types_paiements[$selected][
'label'];
6397 if ($htmlname !=
"none") {
6398 print
'<form method="POST" action="' . $page .
'">';
6399 print
'<input type="hidden" name="action" value="settransportmode">';
6400 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6401 $this->selectTransportMode($selected, $htmlname, 0, $addempty, 0, 0, $active);
6402 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6406 $this->load_cache_transport_mode();
6407 print $this->cache_transport_mode[$selected][
'label'];
6428 if ($htmlname !=
"none") {
6429 print
'<form method="POST" action="' . $page .
'">';
6430 print
'<input type="hidden" name="action" value="setmulticurrencycode">';
6431 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6432 print $this->selectMultiCurrency($selected, $htmlname, 0);
6433 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6436 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
6437 print !empty($selected) ?
currency_name($selected, 1) :
' ';
6455 global $langs, $mysoc,
$conf;
6457 if ($htmlname !=
"none") {
6458 print
'<form method="POST" action="' . $page .
'">';
6459 print
'<input type="hidden" name="action" value="setmulticurrencyrate">';
6460 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6461 print
'<input type="text" class="maxwidth75" name="' . $htmlname .
'" value="' . (!empty($rate) ?
price(
price2num($rate,
'CU')) : 1) .
'" /> ';
6462 print
'<select name="calculation_mode" id="calculation_mode">';
6463 print
'<option value="1">Change ' . $langs->trans(
"PriceUHT") .
' of lines</option>';
6464 print
'<option value="2">Change ' . $langs->trans(
"PriceUHTCurrency") .
' of lines</option>';
6467 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6470 if (!empty($rate)) {
6471 print
price($rate, 1, $langs, 0, 0);
6472 if ($currency && $rate != 1) {
6473 print
' <span class="opacitymedium">(' .
price($rate, 1, $langs, 0, 0) .
' ' . $currency .
' = 1 ' .
$conf->currency .
')</span>';
6498 public function form_remise_dispo($page, $selected, $htmlname, $socid, $amount, $filter =
'', $maxvalue = 0, $more =
'', $hidelist = 0, $discount_type = 0)
6501 global
$conf, $langs;
6502 if ($htmlname !=
"none") {
6503 print
'<form method="post" action="' . $page .
'">';
6504 print
'<input type="hidden" name="action" value="setabsolutediscount">';
6505 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6506 print
'<div class="inline-block">';
6507 if (!empty($discount_type)) {
6509 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL") {
6510 $translationKey =
'HasAbsoluteDiscountFromSupplier';
6512 $translationKey =
'HasCreditNoteFromSupplier';
6515 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
6516 $translationKey =
'HasAbsoluteDiscountFromSupplier';
6518 $translationKey =
'HasCreditNoteFromSupplier';
6523 if (!$filter || $filter ==
"fk_facture_source IS NULL") {
6524 $translationKey =
'CompanyHasAbsoluteDiscount';
6526 $translationKey =
'CompanyHasCreditNote';
6529 if (!$filter || $filter ==
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
6530 $translationKey =
'CompanyHasAbsoluteDiscount';
6532 $translationKey =
'CompanyHasCreditNote';
6536 print $langs->trans($translationKey,
price($amount, 0, $langs, 0, 0, -1,
$conf->currency));
6537 if (empty($hidelist)) {
6541 if (empty($hidelist)) {
6542 print
'<div class="inline-block" style="padding-right: 10px">';
6543 $newfilter =
'discount_type=' . intval($discount_type);
6544 if (!empty($discount_type)) {
6545 $newfilter .=
' AND fk_invoice_supplier IS NULL AND fk_invoice_supplier_line IS NULL';
6547 $newfilter .=
' AND fk_facture IS NULL AND fk_facture_line IS NULL';
6550 $newfilter .=
' AND (' . $filter .
')';
6553 $nbqualifiedlines = $this->select_remises((
string) $selected, $htmlname, $newfilter, $socid, $maxvalue);
6554 if ($nbqualifiedlines > 0) {
6555 print
' <input type="submit" class="button smallpaddingimp" value="' .
dol_escape_htmltag($langs->trans(
"UseLine")) .
'"';
6556 if (!empty($discount_type) && $filter && $filter !=
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
6557 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
6559 if (empty($discount_type) && $filter && $filter !=
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
6560 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
6568 print
'<div class="inline-block">';
6594 public function form_contacts($page, $societe, $selected =
'', $htmlname =
'contactid')
6599 if ($htmlname !=
"none") {
6600 print
'<form method="post" action="' . $page .
'">';
6601 print
'<input type="hidden" name="action" value="set_contact">';
6602 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6603 print
'<table class="nobordernopadding">';
6605 print $this->selectcontacts($societe->id, $selected, $htmlname);
6608 $addcontact = (
getDolGlobalString(
'SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans(
"AddContact") : $langs->trans(
"AddContactAddress"));
6609 print
'<a href="' . DOL_URL_ROOT .
'/contact/card.php?socid=' . $societe->id .
'&action=create&backtoreferer=1">' . $addcontact .
'</a>';
6612 print
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
6613 print
'</tr></table></form>';
6616 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
6617 $contact =
new Contact($this->db);
6618 $contact->fetch($selected);
6619 print $contact->getFullName($langs);
6644 public function form_thirdparty($page, $selected =
'', $htmlname =
'socid', $filter =
'', $showempty = 0, $showtype = 0, $forcecombo = 0, $events = array(), $nooutput = 0, $excludeids = array(), $textifnothirdparty =
'')
6650 if ($htmlname !=
"none") {
6651 $out .=
'<form method="post" action="' . $page .
'">';
6652 $out .=
'<input type="hidden" name="action" value="set_thirdparty">';
6653 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6654 $out .= $this->select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, 0,
'minwidth100',
'',
'', 1, array(),
false, $excludeids);
6655 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6659 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
6660 $soc =
new Societe($this->db);
6661 $soc->fetch($selected);
6662 $out .= $soc->getNomUrl(0,
'');
6664 $out .=
'<span class="opacitymedium">' . $textifnothirdparty .
'</span>';
6690 print $this->selectCurrency($selected, $htmlname);
6702 public function selectCurrency($selected =
'', $htmlname =
'currency_id', $mode = 0, $useempty =
'')
6704 global $langs, $user;
6706 $langs->loadCacheCurrencies(
'');
6710 if ($selected ==
'euro' || $selected ==
'euros') {
6714 $out .=
'<select class="flat maxwidth200onsmartphone minwidth300" name="' . $htmlname .
'" id="' . $htmlname .
'">';
6716 $out .=
'<option value="-1" selected></option>';
6718 foreach ($langs->cache_currencies as $code_iso => $currency) {
6719 $labeltoshow = $currency[
'label'];
6721 $labeltoshow .=
' <span class="opacitymedium">(' . $code_iso .
')</span>';
6723 $labeltoshow .=
' <span class="opacitymedium">(' . $langs->getCurrencySymbol($code_iso) .
')</span>';
6726 if ($selected && $selected == $code_iso) {
6727 $out .=
'<option value="' . $code_iso .
'" selected data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
6729 $out .=
'<option value="' . $code_iso .
'" data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
6731 $out .= $labeltoshow;
6732 $out .=
'</option>';
6734 $out .=
'</select>';
6736 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
6740 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
6758 public function selectMultiCurrency($selected =
'', $htmlname =
'multicurrency_code', $useempty = 0, $filter =
'', $excludeConfCurrency =
false, $morecss =
'')
6760 global
$conf, $langs;
6762 $langs->loadCacheCurrencies(
'');
6764 $TCurrency = array();
6766 $sql =
"SELECT code FROM " . $this->db->prefix() .
"multicurrency";
6767 $sql .=
" WHERE entity IN ('" .
getEntity(
'multicurrency') .
"')";
6769 $sql .=
" AND " . $filter;
6771 $resql = $this->db->query($sql);
6773 while ($obj = $this->db->fetch_object($resql)) {
6774 $TCurrency[$obj->code] = $obj->code;
6779 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
6781 $out .=
'<option value=""> </option>';
6784 if (!in_array(
$conf->currency, $TCurrency) && !$excludeConfCurrency) {
6785 $TCurrency[
$conf->currency] =
$conf->currency;
6787 if (count($TCurrency) > 0) {
6788 foreach ($langs->cache_currencies as $code_iso => $currency) {
6789 if (isset($TCurrency[$code_iso])) {
6790 if (!empty($selected) && $selected == $code_iso) {
6791 $out .=
'<option value="' . $code_iso .
'" selected="selected">';
6793 $out .=
'<option value="' . $code_iso .
'">';
6796 $out .= $currency[
'label'];
6797 $out .=
' (' . $langs->getCurrencySymbol($code_iso) .
')';
6798 $out .=
'</option>';
6803 $out .=
'</select>';
6806 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
6823 global $langs, $user;
6825 $num = count($this->cache_vatrates);
6832 $sql =
"SELECT t.rowid, t.type_vat, t.code, t.taux, t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.recuperableonly";
6833 $sql .=
" FROM ".$this->db->prefix().
"c_tva as t, ".$this->db->prefix().
"c_country as c";
6834 $sql .=
" WHERE t.fk_pays = c.rowid";
6835 $sql .=
" AND t.active > 0";
6836 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
6837 $sql .=
" AND c.code IN (" . $this->db->sanitize($country_code, 1) .
")";
6838 $sql .=
" ORDER BY t.code ASC, t.taux ASC, t.recuperableonly ASC";
6840 $resql = $this->db->query($sql);
6842 $num = $this->db->num_rows($resql);
6844 for ($i = 0; $i < $num; $i++) {
6845 $obj = $this->db->fetch_object($resql);
6847 $tmparray = array();
6848 $tmparray[
'rowid'] = $obj->rowid;
6849 $tmparray[
'type_vat'] = ($obj->type_vat <= 0 ? 0 : $obj->type_vat);
6850 $tmparray[
'code'] = $obj->code;
6851 $tmparray[
'txtva'] = $obj->taux;
6852 $tmparray[
'nprtva'] = $obj->recuperableonly;
6853 $tmparray[
'localtax1'] = $obj->localtax1;
6854 $tmparray[
'localtax1_type'] = $obj->localtax1_type;
6855 $tmparray[
'localtax2'] = $obj->localtax2;
6856 $tmparray[
'localtax2_type'] = $obj->localtax1_type;
6857 $tmparray[
'label'] = $obj->taux .
'%' . ($obj->code ?
' (' . $obj->code .
')' :
'');
6858 $tmparray[
'labelallrates'] = $obj->taux .
'/' . ($obj->localtax1 ? $obj->localtax1 :
'0') .
'/' . ($obj->localtax2 ? $obj->localtax2 :
'0') . ($obj->code ?
' (' . $obj->code .
')' :
'');
6859 $positiverates =
'';
6861 $positiverates .= ($positiverates ?
'/' :
'') . $obj->taux;
6863 if ($obj->localtax1) {
6864 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax1;
6866 if ($obj->localtax2) {
6867 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax2;
6869 if (empty($positiverates)) {
6870 $positiverates =
'0';
6872 $tmparray[
'labelpositiverates'] = $positiverates . ($obj->code ?
' (' . $obj->code .
')' :
'');
6874 $this->cache_vatrates[$obj->rowid] = $tmparray;
6879 $this->error =
'<span class="error">';
6880 $this->error .= $langs->trans(
"ErrorNoVATRateDefinedForSellerCountry", $country_code);
6882 if (!empty($user) && $user->admin && preg_match(
'/\'(..)\'/', $country_code, $reg)) {
6883 $langs->load(
"errors");
6884 $new_country_code = $reg[1];
6885 $country_id =
dol_getIdFromCode($this->db, $new_country_code,
'c_country',
'code',
'rowid');
6886 $this->error .=
'<br>'.$langs->trans(
"ErrorFixThisHere", DOL_URL_ROOT.
'/admin/dict.php?id=10'.($country_id > 0 ?
'&countryidforinsert='.$country_id :
''));
6888 $this->error .=
'</span>';
6892 $this->error =
'<span class="error">' . $this->db->error() .
'</span>';
6921 public function load_tva($htmlname =
'tauxtva', $selectedrate =
'', $societe_vendeuse =
null, $societe_acheteuse =
null, $idprod = 0, $info_bits = 0, $type =
'', $options_only =
false, $mode = 0, $type_vat = 0)
6924 global $langs, $mysoc;
6926 $langs->load(
'errors');
6931 $defaultnpr = ($info_bits & 0x01);
6932 $defaultnpr = (preg_match(
'/\*/', $selectedrate) ? 1 : $defaultnpr);
6933 $defaulttx = str_replace(
'*',
'', $selectedrate);
6936 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
6937 $defaultcode = $reg[1];
6938 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
6943 if (is_object($societe_vendeuse) && !$societe_vendeuse->country_code) {
6944 if ($societe_vendeuse->id == $mysoc->id) {
6945 $return .=
'<span class="error">' . $langs->trans(
"ErrorYourCountryIsNotDefined") .
'</span>';
6947 $return .=
'<span class="error">' . $langs->trans(
"ErrorSupplierCountryIsNotDefined") .
'</span>';
6958 if (is_object($societe_vendeuse)) {
6959 $code_country =
"'" . $societe_vendeuse->country_code .
"'";
6961 $code_country =
"'" . $mysoc->country_code .
"'";
6964 if ($societe_vendeuse == $mysoc &&
getDolGlobalString(
'SERVICE_ARE_ECOMMERCE_200238EC')) {
6965 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
6969 if (is_object($societe_vendeuse) && is_object($societe_acheteuse) &&
isInEEC($societe_vendeuse) &&
isInEEC($societe_acheteuse) && !$societe_acheteuse->isACompany()) {
6971 if (is_numeric($type)) {
6973 switch ($selectVatComboMode) {
6975 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
6978 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
6982 } elseif (!$idprod) {
6983 switch ($selectVatComboMode) {
6985 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
6988 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
6992 $prodstatic =
new Product($this->db);
6993 $prodstatic->fetch($idprod);
6995 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
7002 $this->load_cache_vatrates($code_country);
7005 $arrayofvatrates = array();
7006 foreach ($this->cache_vatrates as $cachevalue) {
7007 if (empty($cachevalue[
'type_vat']) || $cachevalue[
'type_vat'] == $type_vat) {
7008 $arrayofvatrates[] = $cachevalue;
7012 $num = count($arrayofvatrates);
7015 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
7017 $tmpthirdparty =
new Societe($this->db);
7018 $tmpthirdparty->country_code = $mysoc->country_code;
7020 $defaulttx =
get_default_tva(is_object($societe_vendeuse) ? $societe_vendeuse : $tmpthirdparty, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
7021 $defaultnpr =
get_default_npr(is_object($societe_vendeuse) ? $societe_vendeuse : $tmpthirdparty, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
7023 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
7024 $defaultcode = $reg[1];
7025 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
7027 if (empty($defaulttx)) {
7034 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
7037 $defaulttx = $arrayofvatrates[$num - 1][
'txtva'];
7044 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
7045 $defaultcode = $reg[1];
7046 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
7054 if (is_object($societe_vendeuse) && $societe_vendeuse->id == $mysoc->id && $societe_vendeuse->tva_assuj ==
"0") {
7063 if (!$options_only) {
7064 $return .=
'<select class="flat minwidth75imp maxwidth100 right" id="' . $htmlname .
'" name="' . $htmlname .
'"' . ($disabled ?
' disabled' :
'') . $title .
'>';
7067 $selectedfound =
false;
7068 foreach ($arrayofvatrates as $rate) {
7070 if ($disabled && $rate[
'txtva'] != 0) {
7075 $key = $rate[
'txtva'];
7076 $key .= $rate[
'nprtva'] ?
'*' :
'';
7077 if ($mode > 0 && $rate[
'code']) {
7078 $key .=
' (' . $rate[
'code'] .
')';
7081 $key = $rate[
'rowid'];
7084 $return .=
'<option value="' . $key .
'"';
7085 if (!$selectedfound) {
7087 if ($defaultcode == $rate[
'code']) {
7088 $return .=
' selected';
7089 $selectedfound =
true;
7091 } elseif ($rate[
'txtva'] == $defaulttx && $rate[
'nprtva'] == $defaultnpr) {
7092 $return .=
' selected';
7093 $selectedfound =
true;
7099 if ($mysoc->country_code ==
'IN' ||
getDolGlobalString(
'MAIN_VAT_LABEL_IS_POSITIVE_RATES')) {
7101 $return .= $rate[
'labelpositiverates'];
7104 $return .=
vatrate($rate[
'label']);
7108 $return .= (empty($rate[
'code']) && $rate[
'nprtva']) ?
' *' :
'';
7110 $return .=
'</option>';
7113 if (!$options_only) {
7114 $return .=
'</select>';
7118 $return .= $this->error;
7152 public function select_date($set_time =
'', $prefix =
're', $h = 0, $m = 0, $empty = 0, $form_name =
"", $d = 1, $addnowlink = 0, $nooutput = 0, $disabled = 0, $fullday = 0, $addplusone =
'', $adddateof =
'')
7155 dol_syslog(__METHOD__ .
': using select_date is deprecated. Use selectDate instead.', LOG_WARNING);
7156 $retstring = $this->selectDate($set_time, $prefix, $h, $m, $empty, $form_name, $d, $addnowlink, $disabled, $fullday, $addplusone, $adddateof);
7157 if (!empty($nooutput)) {
7180 public function selectDateToDate($set_time =
'', $set_time_end =
'', $prefix =
're', $empty = 0, $forcenewline = 0)
7184 $ret = $this->selectDate($set_time, $prefix .
'_start', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"from"),
'tzuserrel');
7185 if ($forcenewline) {
7188 $ret .= $this->selectDate($set_time_end, $prefix .
'_end', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
7220 public function selectDate($set_time =
'', $prefix =
're', $h = 0, $m = 0, $empty = 0, $form_name =
"", $d = 1, $addnowlink = 0, $disabled = 0, $fullday =
'', $addplusone =
'', $adddateof =
'', $openinghours =
'', $stepminutes = 1, $labeladddateof =
'', $placeholder =
'', $gm =
'auto', $calendarpicto =
'')
7222 global
$conf, $langs;
7224 if ($gm ===
'auto') {
7225 $gm = (empty(
$conf) ?
'tzserver' :
$conf->tzuserinputkey);
7230 if ($prefix ==
'') {
7241 if ($stepminutes <= 0 || $stepminutes > 30) {
7252 $orig_set_time = $set_time;
7254 if ($set_time ===
'' && $emptydate == 0) {
7255 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
7256 if ($gm ==
'tzuser' || $gm ==
'tzuserrel') {
7268 if (!empty($set_time) && preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/', $set_time, $reg)) {
7270 $syear = (!empty($reg[1]) ? $reg[1] :
'');
7271 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
7272 $sday = (!empty($reg[3]) ? $reg[3] :
'');
7273 $shour = (!empty($reg[4]) ? $reg[4] :
'');
7274 $smin = (!empty($reg[5]) ? $reg[5] :
'');
7275 } elseif (strval($set_time) !=
'' && $set_time != -1) {
7280 if ($orig_set_time !=
'') {
7294 if ($h == 3 || $h == 4) {
7305 $usecalendar =
'combo';
7311 $usecalendar =
'html';
7316 if ($usecalendar !=
'combo') {
7317 $formatted_date =
'';
7319 if (strval($set_time) !=
'' && $set_time != -1) {
7321 $formatted_date =
dol_print_date($set_time, $langs->trans(
"FormatDateShortInput"), $gm);
7325 if ($usecalendar ==
"eldy") {
7327 $retstring .=
'<input id="' . $prefix .
'" name="' . $prefix .
'" type="text" class="maxwidthdate center" maxlength="11" value="' . $formatted_date .
'"';
7328 $retstring .= ($disabled ?
' disabled' :
'');
7329 $retstring .=
' onChange="dpChangeDay(\'' .
dol_escape_js($prefix) .
'\',\
'' .
dol_escape_js($langs->trans(
"FormatDateShortJavaInput")) .
'\');
"'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
7330 $retstring .= ' autocomplete="off
">';
7333 $retstringbuttom = '';
7335 $retstringbuttom = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
"';
7336 $base = DOL_URL_ROOT . '/core/';
7338 $retstringbuttom .= '>' . img_object($langs->trans("SelectDate
"), 'calendarday', 'class="datecallink
"') . '</button>';
7340 $retstringbuttom = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
">' . img_object($langs->trans("Disabled
"), 'calendarday', 'class="datecallink
"') . '</button>';
7342 $retstring = $retstringbuttom . $retstring;
7344 $retstring .= '<input type="hidden
" id="' . $prefix . 'day
" name="' . $prefix . 'day
" value="' . $sday . '">' . "\n
";
7345 $retstring .= '<input type="hidden
" id="' . $prefix . 'month
" name="' . $prefix . 'month
" value="' . $smonth . '">' . "\n
";
7346 $retstring .= '<input type="hidden
" id="' . $prefix . 'year
" name="' . $prefix . 'year
" value="' . $syear . '">' . "\n
";
7347 } elseif ($usecalendar == 'jquery' || $usecalendar == 'html') {
7348 if (!$disabled && $usecalendar != 'html') {
7349 // Output javascript for datepicker
7350 $minYear = getDolGlobalInt('MIN_YEAR_SELECT_DATE', (idate('Y') - 100));
7351 $maxYear = getDolGlobalInt('MAX_YEAR_SELECT_DATE', (idate('Y') + 100));
7353 $retstring .= '<script nonce="' . getNonce() . '" type="text/javascript
">';
7354 $retstring .= "$(
function(){ $(
'#" . $prefix . "').datepicker({
7355 dateFormat:
'" . $langs->trans("FormatDateShortJQueryInput") . "',
7357 todayHighlight:
true,
7358 yearRange:
'" . $minYear . ":" . $maxYear . "',
";
7359 if (!empty($conf->dol_use_jmobile)) {
7361 beforeShow:
function (input, datePicker) {
7362 input.disabled =
true;
7364 onClose:
function (dateText, datePicker) {
7369 // Note: We don't need monthNames, monthNamesShort, dayNames, dayNamesShort, dayNamesMin, they are set globally on datepicker component in lib_head.js.php
7370 if (!getDolGlobalString('MAIN_POPUP_CALENDAR_ON_FOCUS')) {
7371 $buttonImage = $calendarpicto ?: DOL_URL_ROOT . "/theme/
" . dol_escape_js($conf->theme) . "/img/object_calendarday.png
";
7374 buttonImage:
'" . $buttonImage . "',
7375 buttonImageOnly:
true";
7379 $retstring .= "</script>
";
7382 // Input area to enter date manually
7383 $retstring .= '<div class="nowraponall
inline-block divfordateinput
">';
7384 $retstring .= '<input id="'.$prefix.'" name="'.$prefix.'" type="'.($usecalendar == 'html
' ? "date" : "text").'" class="maxwidthdate center
" maxlength="11
" value="'.$formatted_date.'"';
7385 $retstring .= ($disabled ? ' disabled' : '');
7386 $retstring .= ($placeholder ? ' placeholder="' . dol_escape_htmltag($placeholder) . '"' : '');
7387 $retstring .= ' onChange="dpChangeDay(\
'' .
dol_escape_js($prefix) .
'\',\
'' .
dol_escape_js($langs->trans(
"FormatDateShortJavaInput")) .
'\');
"'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
7388 $retstring .= ' autocomplete="off
">';
7392 $retstringbutton = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
">' . img_object($langs->trans("Disabled
"), 'calendarday', 'class="datecallink
"') . '</button>';
7393 $retstring = $retstringbutton . $retstring;
7396 $retstring .= '</div>';
7397 $retstring .= '<input type="hidden
" id="' . $prefix . 'day
" name="' . $prefix . 'day
" value="' . $sday . '">' . "\n
";
7398 $retstring .= '<input type="hidden
" id="' . $prefix . 'month
" name="' . $prefix . 'month
" value="' . $smonth . '">' . "\n
";
7399 $retstring .= '<input type="hidden
" id="' . $prefix . 'year
" name="' . $prefix . 'year
" value="' . $syear . '">' . "\n
";
7401 $retstring .= "Bad value of MAIN_POPUP_CALENDAR
";
7404 // Show date with combo selects
7406 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50imp
" id="' . $prefix . 'day
" name="' . $prefix . 'day
">';
7408 if ($emptydate || $set_time == -1) {
7409 $retstring .= '<option value="0
" selected> </option>';
7412 for ($day = 1; $day <= 31; $day++) {
7413 $retstring .= '<option value="' . $day . '"' . ($day == $sday ? ' selected' : '') . '>' . $day . '</option>';
7416 $retstring .= "</select>
";
7418 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'month
" name="' . $prefix . 'month
">';
7419 if ($emptydate || $set_time == -1) {
7420 $retstring .= '<option value="0
" selected> </option>';
7424 for ($month = 1; $month <= 12; $month++) {
7425 $retstring .= '<option value="' . $month . '"' . ($month == $smonth ? ' selected' : '') . '>';
7426 $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b
");
7427 $retstring .= "</option>
";
7429 $retstring .= "</select>
";
7432 if ($emptydate || $set_time == -1) {
7433 $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 . '">';
7435 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'year
" name="' . $prefix . 'year
">';
7437 $syear = (int) $syear;
7438 for ($year = $syear - 10; $year < (int) $syear + 10; $year++) {
7439 $retstring .= '<option value="' . $year . '"' . ($year == $syear ? ' selected' : '') . '>' . $year . '</option>';
7441 $retstring .= "</select>\n
";
7447 $retstring .= (($h == 2 || $h == 4) ? '<br>' : ' ');
7448 $retstring .= '<span class="nowraponall
">';
7454 if ($openinghours != '') {
7455 $openinghours = explode(',', $openinghours);
7456 $hourstart = $openinghours[0];
7457 $hourend = $openinghours[1];
7458 if ($hourend < $hourstart) {
7459 $hourend = $hourstart;
7464 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50
' . ($fullday ? $fullday . 'hour
' : '') . '" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
">';
7466 $retstring .= '<option value="-1
"> </option>';
7468 for ($hour = $hourstart; $hour < $hourend; $hour++) {
7469 if (strlen($hour) < 2) {
7470 $hour = "0
" . $hour;
7472 $retstring .= '<option value="' . $hour . '"' . (($hour == $shour) ? ' selected' : '') . '>' . $hour;
7473 $retstring .= '</option>';
7475 $retstring .= '</select>';
7477 $retstring .= '<input type="hidden
" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
" value="' . $shour . '">' . "\n
";
7486 $retstring .= '<select ' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50
' . ($fullday ? $fullday . 'min
' : '') . '" id="' . $prefix . 'min
" name="' . $prefix . 'min
">';
7488 $retstring .= '<option value="-1
"> </option>';
7490 for ($min = 0; $min < 60; $min += $stepminutes) {
7491 $min_str = sprintf("%02d
", $min);
7492 $retstring .= '<option value="' . $min_str . '"' . (($min_str == $smin) ? ' selected' : '') . '>' . $min_str . '</option>';
7494 $retstring .= '</select>';
7496 $retstring .= '<input type="hidden
" id="' . $prefix . 'min
" name="' . $prefix . 'min
" value="' . $smin . '">' . "\n
";
7499 $retstring .= '<input type="hidden
" name="' . $prefix . 'sec
" value="' . $ssec . '">';
7503 $retstring .= '</span>';
7507 if (!empty($conf->use_javascript_ajax) && $addnowlink && !$disabled) {
7508 // Script which will be inserted in the onClick of the "Now
" link
7509 $reset_scripts = "";
7510 if ($addnowlink == 2) { // local computer time
7511 // pad add leading 0 on numbers
7512 $reset_scripts .= "Number.prototype.pad =
function(size) {
7513 var s = String(
this);
7514 while (s.length < (size || 2)) {s =
'0' + s;}
7517 var d =
new Date();
";
7520 // Generate the date part, depending on the use or not of the javascript calendar
7521 if ($addnowlink == 1) { // server time expressed in user time setup
7522 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
7523 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
7524 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
7525 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
7526 } elseif ($addnowlink == 2) {
7527 /* Disabled because the output does not use the string format defined by FormatDateShort key to forge the value into #prefix.
7528 * This break application for foreign languages.
7529 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(d.toLocaleDateString(\''.str_replace('_', '-', $langs->defaultlang).'\'));';
7530 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(d.getDate().pad());';
7531 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(parseInt(d.getMonth().pad()) + 1);';
7532 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(d.getFullYear());';
7534 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
7535 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
7536 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
7537 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
7539 /*if ($usecalendar == "eldy
")
7541 $base=DOL_URL_ROOT.'/core/';
7542 $reset_scripts .= 'resetDP(\''.$base.'\',\''.$prefix.'\',\''.$langs->trans("FormatDateShortJavaInput
").'\',\''.$langs->defaultlang.'\');';
7546 $reset_scripts .= 'this.form.elements[\''.$prefix.'day\'].value=formatDate(new Date(), \'d\'); ';
7547 $reset_scripts .= 'this.form.elements[\''.$prefix.'month\'].value=formatDate(new Date(), \'M\'); ';
7548 $reset_scripts .= 'this.form.elements[\''.$prefix.'year\'].value=formatDate(new Date(), \'yyyy\'); ';
7550 // Update the hour part
7553 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7555 //$reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); ';
7556 if ($addnowlink == 1) {
7557 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
7558 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
7559 } elseif ($addnowlink == 2) {
7560 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(d.getHours().pad());';
7561 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
7565 $reset_scripts .= ' } ';
7568 // Update the minute part
7571 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7573 //$reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); ';
7574 if ($addnowlink == 1) {
7575 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
7576 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
7577 } elseif ($addnowlink == 2) {
7578 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(d.getMinutes().pad());';
7579 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
7582 $reset_scripts .= ' } ';
7585 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
7586 if ($reset_scripts && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
7587 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonNow
" type="button" name="_useless
" value="now
" onClick="' . $reset_scripts . '">';
7588 $retstring .= $langs->trans("Now
");
7589 $retstring .= '</button> ';
7593 // Add a "Plus one hour
" link
7594 if ($conf->use_javascript_ajax && $addplusone && !$disabled) {
7595 // Script which will be inserted in the onClick of the "Add plusone
" link
7596 $reset_scripts = "";
7598 // Generate the date part, depending on the use or not of the javascript calendar
7599 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'dayinputnoreduce', 'tzuserrel') . '\');';
7600 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
7601 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
7602 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
7603 // Update the hour part
7606 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7608 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
7610 $reset_scripts .= ' } ';
7613 // Update the minute part
7616 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7618 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
7620 $reset_scripts .= ' } ';
7623 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
7624 if ($reset_scripts && empty($conf->dol_optimize_smallscreen)) {
7625 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonPlusOne
" type="button" name="_useless2
" value="plusone
" onClick="' . $reset_scripts . '">';
7626 $retstring .= $langs->trans("DateStartPlusOne
");
7627 $retstring .= '</button> ';
7631 // Add a link to set data
7632 if ($conf->use_javascript_ajax && !empty($adddateof) && !$disabled) {
7633 if (!is_array($adddateof)) {
7634 $arrayofdateof = array(array('adddateof' => $adddateof, 'labeladddateof' => $labeladddateof));
7636 $arrayofdateof = $adddateof;
7638 foreach ($arrayofdateof as $valuedateof) {
7639 $tmpadddateof = empty($valuedateof['adddateof']) ? 0 : $valuedateof['adddateof'];
7640 $tmplabeladddateof = empty($valuedateof['labeladddateof']) ? '' : $valuedateof['labeladddateof'];
7641 $tmparray = dol_getdate($tmpadddateof);
7642 if (empty($tmplabeladddateof)) {
7643 $tmplabeladddateof = $langs->trans("DateInvoice
");
7645 $reset_scripts = 'console.log(\'Click on now link\'); ';
7646 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(\''.dol_print_date($tmpadddateof, 'dayinputnoreduce').'\');';
7647 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(\''.$tmparray['mday'].'\');';
7648 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(\''.$tmparray['mon'].'\');';
7649 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(\''.$tmparray['year'].'\');';
7650 $retstring .= ' - <button class="dpInvisibleButtons datenowlink
" id="dateofinvoice
" type="button" name="_dateofinvoice
" value="now
" onclick="'.$reset_scripts.'">'.$tmplabeladddateof.'</button>';
7665 public function selectTypeDuration($prefix, $selected = 'i', $excludetypes = array())
7669 $TDurationTypes = array(
7670 'y' => $langs->trans('Years'),
7671 'm' => $langs->trans('Month'),
7672 'w' => $langs->trans('Weeks'),
7673 'd' => $langs->trans('Days'),
7674 'h' => $langs->trans('Hours'),
7675 'i' => $langs->trans('Minutes')
7678 // Removed undesired duration types
7679 foreach ($excludetypes as $value) {
7680 unset($TDurationTypes[$value]);
7683 $retstring = '<select class="flat minwidth75 maxwidth100
" id="select_
' . $prefix . 'type_duration
" name="' . $prefix . 'type_duration
">';
7684 foreach ($TDurationTypes as $key => $typeduration) {
7685 $retstring .= '<option value="' . $key . '"';
7686 if ($key == $selected) {
7687 $retstring .= " selected
";
7689 $retstring .= ">
" . $typeduration . "</option>
";
7691 $retstring .= "</select>
";
7693 $retstring .= ajax_combobox('select_' . $prefix . 'type_duration');
7698 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
7713 public function select_duration($prefix, $iSecond = '', $disabled = 0, $typehour = 'select', $minunderhours = 0, $nooutput = 0)
7718 $retstring = '<span class="nowraponall
">';
7724 if ($iSecond != '') {
7725 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
7727 $hourSelected = convertSecondToTime($iSecond, 'allhour');
7728 $minSelected = convertSecondToTime($iSecond, 'min');
7731 if ($typehour == 'select') {
7732 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'hour
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . '>';
7733 for ($hour = 0; $hour < 25; $hour++) { // For a duration, we allow 24 hours
7734 $retstring .= '<option value="' . $hour . '"';
7735 if (is_numeric($hourSelected) && $hourSelected == $hour) {
7736 $retstring .= " selected
";
7738 $retstring .= ">
" . $hour . "</option>
";
7740 $retstring .= "</select>
";
7741 } elseif ($typehour == 'text' || $typehour == 'textselect') {
7742 $retstring .= '<input placeholder="' . $langs->trans('HourShort
') . '" type="number
" min="0
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputhour right
" value="' . (($hourSelected != '') ? ((int) $hourSelected) : '') . '">';
7744 return 'BadValueForParameterTypeHour';
7747 if ($typehour != 'text') {
7748 $retstring .= ' ' . $langs->trans('HourShort');
7750 $retstring .= '<span class="">:</span>';
7754 if ($minunderhours) {
7755 $retstring .= '<br>';
7757 if ($typehour != 'text') {
7758 $retstring .= '<span class="hideonsmartphone
"> </span>';
7762 if ($typehour == 'select' || $typehour == 'textselect') {
7763 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'min
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . '>';
7764 for ($min = 0; $min <= 55; $min += 5) {
7765 $retstring .= '<option value="' . $min . '"';
7766 if (is_numeric($minSelected) && $minSelected == $min) {
7767 $retstring .= ' selected';
7769 $retstring .= '>' . $min . '</option>';
7771 $retstring .= "</select>
";
7772 } elseif ($typehour == 'text') {
7773 $retstring .= '<input placeholder="' . $langs->trans('MinuteShort
') . '" type="number
" min="0
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputminute right
" value="' . (($minSelected != '') ? ((int) $minSelected) : '') . '">';
7776 if ($typehour != 'text') {
7777 $retstring .= ' ' . $langs->trans('MinuteShort');
7780 $retstring .= "</span>
";
7782 if (!empty($nooutput)) {
7810 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)
7812 global $langs, $conf;
7817 if (is_null($ajaxoptions)) {
7818 $ajaxoptions = array();
7821 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
7824 if ($selected && empty($selected_input_value)) {
7825 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
7826 $tickettmpselect = new Ticket($this->db);
7827 $tickettmpselect->fetch($selected);
7828 $selected_input_value = $tickettmpselect->ref;
7829 unset($tickettmpselect);
7833 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/ticket/ajax/tickets.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
7835 if (empty($hidelabel)) {
7836 $out .= $langs->trans("RefOrLabel
") . ' : ';
7837 } elseif ($hidelabel > 1) {
7838 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
7839 if ($hidelabel == 2) {
7840 $out .= img_picto($langs->trans("Search
"), 'search');
7843 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
7844 if ($hidelabel == 3) {
7845 $out .= img_picto($langs->trans("Search
"), 'search');
7848 $out .= $this->selectTicketsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
7851 if (empty($nooutput)) {
7876 public function selectTicketsList($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
7878 global $langs, $conf;
7881 $outarray = array();
7883 $selectFields = " p.rowid, p.ref, p.message
";
7886 $sql .= $selectFields;
7887 $sql .= " FROM
" . $this->db->prefix() . "ticket as p
";
7888 $sql .= ' WHERE p.entity IN (' . getEntity('ticket') . ')';
7890 // Add criteria on ref/label
7891 if ($filterkey != '') {
7893 $prefix = !getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
7894 // For natural search
7895 $search_crit = explode(' ', $filterkey);
7897 if (count($search_crit) > 1) {
7900 foreach ($search_crit as $crit) {
7904 $sql .= "(p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%' OR p.subject LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
7908 if (count($search_crit) > 1) {
7914 $sql .= $this->db->plimit($limit, 0);
7916 // Build output string
7917 dol_syslog(get_class($this) . "::selectTicketsList search tickets
", LOG_DEBUG);
7918 $result = $this->db->query($sql);
7920 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
7921 require_once DOL_DOCUMENT_ROOT . '/core/lib/ticket.lib.php';
7923 $num = $this->db->num_rows($result);
7928 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
7929 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('TICKET_USE_SEARCH_TO_SELECT'));
7932 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
7935 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
7936 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
7937 if (getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
7938 if ($showempty && !is_numeric($showempty)) {
7939 $textifempty = $langs->trans($showempty);
7941 $textifempty .= $langs->trans("All
");
7944 if ($showempty && !is_numeric($showempty)) {
7945 $textifempty = $langs->trans($showempty);
7949 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
7953 while ($num && $i < $num) {
7956 $objp = $this->db->fetch_object($result);
7958 $this->constructTicketListOption($objp, $opt, $optJson, $selected, $filterkey);
7959 '@phan-var-force array{key:string,value:mixed,type:int} $optJson';
7961 // "key
" value of json key array is used by jQuery automatically as selected value
7962 // "label
" value of json key array is used by jQuery automatically as text for combo box
7964 array_push($outarray, $optJson);
7969 $out .= '</select>';
7971 $this->db->free($result);
7973 if (empty($outputmode)) {
7978 dol_print_error($this->db);
7995 protected function constructTicketListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
8001 $outkey = $objp->rowid;
8002 $outref = $objp->ref;
8004 $opt = '<option value="
' . $objp->rowid . '"';
8005 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
8008 $objRef = $objp->ref;
8009 if (!empty($filterkey) && $filterkey != '') {
8010 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1);
8013 $opt .= "</option>\n
";
8014 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
8036 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)
8038 global $langs, $conf;
8043 if (is_null($ajaxoptions)) {
8044 $ajaxoptions = array();
8047 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
8050 if ($selected && empty($selected_input_value)) {
8051 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
8052 $projecttmpselect = new Project($this->db);
8053 $projecttmpselect->fetch($selected);
8054 $selected_input_value = $projecttmpselect->ref;
8055 unset($projecttmpselect);
8059 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/projet/ajax/projects.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
8061 if (empty($hidelabel)) {
8062 $out .= $langs->trans("RefOrLabel
") . ' : ';
8063 } elseif ($hidelabel > 1) {
8064 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
8065 if ($hidelabel == 2) {
8066 $out .= img_picto($langs->trans("Search
"), 'search');
8069 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
8070 if ($hidelabel == 3) {
8071 $out .= img_picto($langs->trans("Search
"), 'search');
8074 $out .= $this->selectProjectsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
8077 if (empty($nooutput)) {
8101 public function selectProjectsList($selected = '', $htmlname = 'projectid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
8103 global $langs, $conf;
8106 $outarray = array();
8108 $selectFields = " p.rowid, p.ref
";
8111 $sql .= $selectFields;
8112 $sql .= " FROM
" . $this->db->prefix() . "projet as p
";
8113 $sql .= ' WHERE p.entity IN (' . getEntity('project') . ')';
8115 // Add criteria on ref/label
8116 if ($filterkey != '') {
8118 $prefix = !getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
8119 // For natural search
8120 $search_crit = explode(' ', $filterkey);
8122 if (count($search_crit) > 1) {
8125 foreach ($search_crit as $crit) {
8129 $sql .= "p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
8133 if (count($search_crit) > 1) {
8139 $sql .= $this->db->plimit($limit, 0);
8141 // Build output string
8142 dol_syslog(get_class($this) . "::selectProjectsList search projects
", LOG_DEBUG);
8143 $result = $this->db->query($sql);
8145 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
8146 require_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php';
8148 $num = $this->db->num_rows($result);
8153 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
8154 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('PROJECT_USE_SEARCH_TO_SELECT'));
8157 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
8160 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
8161 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
8162 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
8163 if ($showempty && !is_numeric($showempty)) {
8164 $textifempty = $langs->trans($showempty);
8166 $textifempty .= $langs->trans("All
");
8169 if ($showempty && !is_numeric($showempty)) {
8170 $textifempty = $langs->trans($showempty);
8174 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
8178 while ($num && $i < $num) {
8181 $objp = $this->db->fetch_object($result);
8183 $this->constructProjectListOption($objp, $opt, $optJson, $selected, $filterkey);
8185 // "key
" value of json key array is used by jQuery automatically as selected value
8186 // "label
" value of json key array is used by jQuery automatically as text for combo box
8188 array_push($outarray, $optJson);
8193 $out .= '</select>';
8195 $this->db->free($result);
8197 if (empty($outputmode)) {
8202 dol_print_error($this->db);
8219 protected function constructProjectListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
8225 $label = $objp->label;
8227 $outkey = $objp->rowid;
8228 $outref = $objp->ref;
8229 $outlabel = $objp->label;
8230 $outtype = $objp->fk_product_type;
8232 $opt = '<option value="
' . $objp->rowid . '"';
8233 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
8236 $objRef = $objp->ref;
8237 if (!empty($filterkey) && $filterkey != '') {
8238 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1);
8241 $opt .= "</option>\n
";
8242 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
8265 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)
8267 global $langs, $conf;
8272 if (is_null($ajaxoptions)) {
8273 $ajaxoptions = array();
8276 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
8279 if ($selected && empty($selected_input_value)) {
8280 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
8281 $adherenttmpselect = new Adherent($this->db);
8282 $adherenttmpselect->fetch($selected);
8283 $selected_input_value = $adherenttmpselect->ref;
8284 unset($adherenttmpselect);
8289 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/adherents/ajax/adherents.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
8291 if (empty($hidelabel)) {
8292 $out .= $langs->trans("RefOrLabel
") . ' : ';
8293 } elseif ($hidelabel > 1) {
8294 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
8295 if ($hidelabel == 2) {
8296 $out .= img_picto($langs->trans("Search
"), 'search');
8299 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
8300 if ($hidelabel == 3) {
8301 $out .= img_picto($langs->trans("Search
"), 'search');
8306 $out .= $this->selectMembersList($selected, $htmlname, $filtertype, $limit, $filterkey, $status, 0, $showempty, $forcecombo, $morecss);
8309 if (empty($nooutput)) {
8333 public function selectMembersList($selected = '', $htmlname = 'adherentid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
8335 global $langs, $conf;
8338 $outarray = array();
8340 $selectFields = " p.rowid, p.ref, p.firstname, p.lastname, p.fk_adherent_type
";
8343 $sql .= $selectFields;
8344 $sql .= " FROM
" . $this->db->prefix() . "adherent as p
";
8345 $sql .= ' WHERE p.entity IN (' . getEntity('adherent') . ')';
8347 // Add criteria on ref/label
8348 if ($filterkey != '') {
8350 $prefix = !getDolGlobalString('MEMBER_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
8351 // For natural search
8352 $search_crit = explode(' ', $filterkey);
8354 if (count($search_crit) > 1) {
8357 foreach ($search_crit as $crit) {
8361 $sql .= "(p.firstname LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
8362 $sql .= " OR p.lastname LIKE
'" . $this->db->escape($prefix . $crit) . "%')
";
8365 if (count($search_crit) > 1) {
8370 if ($status != -1) {
8371 $sql .= ' AND statut = ' . ((int) $status);
8373 $sql .= $this->db->plimit($limit, 0);
8375 // Build output string
8376 dol_syslog(get_class($this) . "::selectMembersList search adherents
", LOG_DEBUG);
8377 $result = $this->db->query($sql);
8379 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
8380 require_once DOL_DOCUMENT_ROOT . '/core/lib/member.lib.php';
8382 $num = $this->db->num_rows($result);
8387 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
8388 $out .= ajax_combobox($htmlname, $events, getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT') ? $conf->global->PROJECT_USE_SEARCH_TO_SELECT : '');
8391 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
8394 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
8395 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
8396 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
8397 if ($showempty && !is_numeric($showempty)) {
8398 $textifempty = $langs->trans($showempty);
8400 $textifempty .= $langs->trans("All
");
8403 if ($showempty && !is_numeric($showempty)) {
8404 $textifempty = $langs->trans($showempty);
8408 $out .= '<option value="-1
" selected>' . $textifempty . '</option>';
8412 while ($num && $i < $num) {
8415 $objp = $this->db->fetch_object($result);
8417 $this->constructMemberListOption($objp, $opt, $optJson, $selected, $filterkey);
8420 // "key
" value of json key array is used by jQuery automatically as selected value
8421 // "label
" value of json key array is used by jQuery automatically as text for combo box
8423 array_push($outarray, $optJson);
8428 $out .= '</select>';
8430 $this->db->free($result);
8432 if (empty($outputmode)) {
8437 dol_print_error($this->db);
8454 protected function constructMemberListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
8460 $outkey = $objp->rowid;
8461 $outlabel = dolGetFirstLastname($objp->firstname, $objp->lastname);
8462 $outtype = $objp->fk_adherent_type;
8464 $opt = '<option value="
' . $objp->rowid . '"';
8465 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
8467 if (!empty($filterkey) && $filterkey != '') {
8468 $outlabel = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $outlabel, 1);
8471 $opt .= "</option>\n
";
8473 $optJson = array('key' => $outkey, 'value' => $outlabel, 'type' => $outtype);
8496 public function selectForForms($objectdesc, $htmlname, $preSelectedValue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $disabled = 0, $selected_input_value = '', $objectfield = '')
8498 global $conf, $extrafields, $user;
8500 // Example of common usage for a link to a thirdparty
8502 // We got this in a modulebuilder form of "
MyObject" of module "mymodule
".
8503 // ->fields is array( ... "fk_soc
" => array("type"=>"integer:
Societe:societe/class/societe.class.php:1:((
status:=:1) AND (entity:IN:__SHARED_ENTITIES__))
" ...)
8504 // $objectdesc = 'Societe'
8505 // $objectfield = 'myobject@mymodule:fk_soc' ('fk_soc' is code to retrieve myobject->fields['fk_soc'])
8507 // We got this when showing an extrafields on resource that is a link to societe
8508 // extrafields 'link_to_societe' of Resource is 'link' to 'Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))" ...)
'
8510 // $objectfield = 'resource:options_link_to_societe
'
8513 // $objectdesc = 'Societe:societe/class/societe.class.php:1:((
status:=:1) AND (entity:IN:__SHARED_ENTITIES__))
'
8514 // $objectfield = ''
8516 //var_dump($objectdesc.' '.$objectfield);
8517 //debug_print_backtrace();
8519 $objectdescorig = $objectdesc;
8521 $InfoFieldList = array();
8523 $filter = ''; // Ensure filter has value (for static analysis)
8524 $sortfield = ''; // Ensure filter has value (for static analysis)
8526 if ($objectfield) { // We must retrieve the objectdesc from the field or extrafield
8527 // Example: $objectfield = 'product:options_package
' or 'myobject@mymodule:options_myfield
'
8528 $tmparray = explode(':
', $objectfield);
8530 // Get instance of object from $element
8531 $objectforfieldstmp = fetchObjectByElement(0, strtolower($tmparray[0]));
8533 if (is_object($objectforfieldstmp)) {
8537 if (preg_match('/^options_(.*)$/
', $tmparray[1], $reg)) {
8538 // For a property in extrafields
8540 // fetch optionals attributes and labels
8541 $extrafields->fetch_name_optionals_label($objectforfieldstmp->table_element);
8543 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element]['type'][$key]) && $extrafields->attributes[$objectforfieldstmp->table_element]['type'][$key] == 'link
') {
8544 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element]['param
'][$key]['options
'])) {
8545 $tmpextrafields = array_keys($extrafields->attributes[$objectforfieldstmp->table_element]['param
'][$key]['options
']);
8546 $objectdesc = $tmpextrafields[0];
8550 // For a property in ->fields
8551 if (array_key_exists($tmparray[1], $objectforfieldstmp->fields)) {
8552 $objectdesc = $objectforfieldstmp->fields[$tmparray[1]]['type'];
8553 $objectdesc = preg_replace('/^integer[^:]*:/
', '', $objectdesc);
8560 // Example of value for $objectdesc:
8561 // Bom:bom/class/bom.class.php:0:t.status=1
8562 // Bom:bom/class/bom.class.php:0:t.status=1:ref
8563 // Bom:bom/class/bom.class.php:0:(t.status:=:1) OR (t.field2:=:2):ref
8564 $InfoFieldList = explode(":", $objectdesc, 4);
8565 $vartmp = (empty($InfoFieldList[3]) ? '' : $InfoFieldList[3]);
8567 if (preg_match('/^.*:(\w*)$/
', $vartmp, $reg)) {
8568 $InfoFieldList[4] = $reg[1]; // take the sort field
8570 $InfoFieldList[3] = preg_replace('/:\w*$/
', '', $vartmp); // take the filter field
8572 $classname = $InfoFieldList[0];
8573 $classpath = empty($InfoFieldList[1]) ? '' : $InfoFieldList[1];
8574 //$addcreatebuttonornot = empty($InfoFieldList[2]) ? 0 : $InfoFieldList[2];
8575 $filter = empty($InfoFieldList[3]) ? '' : $InfoFieldList[3];
8576 $sortfield = empty($InfoFieldList[4]) ? '' : $InfoFieldList[4];
8578 // Load object according to $id and $element
8579 $objecttmp = fetchObjectByElement(0, strtolower($InfoFieldList[0]));
8581 // Fallback to another solution to get $objecttmp
8582 if (empty($objecttmp) && !empty($classpath)) {
8583 dol_include_once($classpath);
8585 if ($classname && class_exists($classname)) {
8586 $objecttmp = new $classname($this->db);
8591 // Make some replacement in $filter. May not be used if we used the ajax mode with $objectfield. In such a case
8592 // we propagate the $objectfield and not the filter and replacement is done by the ajax/selectobject.php component.
8593 $sharedentities = (is_object($objecttmp) && property_exists($objecttmp, 'element
')) ? getEntity($objecttmp->element) : strtolower($classname);
8594 $filter = str_replace(
8595 array('__ENTITY__
', '__SHARED_ENTITIES__
', '__USER_ID__
'),
8596 array($conf->entity, $sharedentities, $user->id),
8600 if (!is_object($objecttmp)) {
8601 dol_syslog('selectForForms: Error bad setup of field objectdescorig=
' . $objectdescorig.', objectfield=
'.$objectfield.', objectdesc=
'.$objectdesc, LOG_WARNING);
8602 return 'selectForForms: Error bad setup of field objectdescorig=
' . $objectdescorig.', objectfield=
'.$objectfield.', objectdesc=
'.$objectdesc;
8606 //var_dump($filter);
8607 $prefixforautocompletemode = $objecttmp->element;
8608 if ($prefixforautocompletemode == 'societe
') {
8609 $prefixforautocompletemode = 'company
';
8611 if ($prefixforautocompletemode == 'product
') {
8612 $prefixforautocompletemode = 'produit
';
8614 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) . '_USE_SEARCH_TO_SELECT
'; // For example COMPANY_USE_SEARCH_TO_SELECT
8616 dol_syslog(get_class($this) . "::selectForForms filter=" . $filter, LOG_DEBUG);
8618 // Generate the combo HTML component
8620 if (!empty($conf->use_javascript_ajax) && getDolGlobalString($confkeyforautocompletemode) && !$forcecombo) {
8621 // No immediate load of all database
8624 if ($preSelectedValue && empty($selected_input_value)) {
8625 $objecttmp->fetch($preSelectedValue);
8626 $selected_input_value = ($prefixforautocompletemode == 'company
' ? $objecttmp->name : $objecttmp->ref);
8628 $oldValueForShowOnCombobox = 0;
8629 foreach ($objecttmp->fields as $fieldK => $fielV) {
8630 if (!array_key_exists('showoncombobox
', $fielV) || !$fielV['showoncombobox
'] || empty($objecttmp->$fieldK)) {
8634 if (!$oldValueForShowOnCombobox) {
8635 $selected_input_value = '';
8638 $selected_input_value .= $oldValueForShowOnCombobox ? ' -
' : '';
8639 $selected_input_value .= $objecttmp->$fieldK;
8640 $oldValueForShowOnCombobox = empty($fielV['showoncombobox
']) ? 0 : $fielV['showoncombobox
'];
8644 // Set url and param to call to get json of the search results
8645 $urlforajaxcall = DOL_URL_ROOT . '/core/ajax/selectobject.php
';
8646 $urloption = 'htmlname=
' . urlencode($htmlname) . '&outjson=1&objectdesc=
' . urlencode($objectdescorig) . '&objectfield=
'.urlencode($objectfield) . ($sortfield ? '&sortfield=
' . urlencode($sortfield) : '');
8648 // Activate the auto complete using ajax call.
8649 $out .= ajax_autocompleter((string) $preSelectedValue, $htmlname, $urlforajaxcall, $urloption, getDolGlobalInt($confkeyforautocompletemode), 0);
8650 $out .= '<!-- force css to be higher than dialog popup --><style
type=
"text/css">.ui-autocomplete { z-index: 1010; }</style>
';
8651 $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) . '"' : '') . ' />
';
8653 // Immediate load of table record.
8654 $out .= $this->selectForFormsList($objecttmp, $htmlname, $preSelectedValue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled, $sortfield, $filter);
8681 public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty = '
', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $outputmode = 0, $disabled = 0, $sortfield = '', $filter = '')
8683 global $langs, $user, $hookmanager;
8685 //print "$htmlname, $preselectedvalue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, $outputmode, $disabled";
8687 $prefixforautocompletemode = $objecttmp->element;
8688 if ($prefixforautocompletemode == 'societe
') {
8689 $prefixforautocompletemode = 'company
';
8691 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) . '_USE_SEARCH_TO_SELECT
'; // For example COMPANY_USE_SEARCH_TO_SELECT
8693 if (!empty($objecttmp->fields)) { // For object that declare it, it is better to use declared fields (like societe, contact, ...)
8694 $tmpfieldstoshow = '';
8695 foreach ($objecttmp->fields as $key => $val) {
8696 if (! (int) dol_eval($val['enabled
'], 1, 1, '1
')) {
8699 if (!empty($val['showoncombobox
'])) {
8700 $tmpfieldstoshow .= ($tmpfieldstoshow ? ',
' : '') . 't.
' . $key;
8703 if ($tmpfieldstoshow) {
8704 $fieldstoshow = $tmpfieldstoshow;
8706 } elseif ($objecttmp->element === 'category
') {
8707 $fieldstoshow = 't.label
';
8709 // For backward compatibility
8710 $objecttmp->fields['ref'] = array('type' => 'varchar(30)
', 'label
' => 'Ref
', 'showoncombobox
' => 1);
8713 if (empty($fieldstoshow)) {
8714 if (!empty($objecttmp->parent_element)) {
8715 $fieldstoshow = 'o.ref
';
8716 if (empty($sortfield)) {
8717 $sortfield = 'o.ref
';
8719 if (in_array($objecttmp->element, ['commandedet
', 'propaldet
', 'facturedet
', 'expeditiondet
'])) {
8720 $fieldstoshow .= ',p.ref AS p_ref,p.label,t.description
';
8721 $sortfield .= ', p.ref
';
8723 } elseif (isset($objecttmp->fields['ref'])) {
8724 $fieldstoshow = 't.ref
';
8726 $langs->load("errors");
8727 $this->error = $langs->trans("ErrorNoFieldWithAttributeShowoncombobox");
8728 return $langs->trans('ErrorNoFieldWithAttributeShowoncombobox
');
8733 $outarray = array();
8734 $tmparray = array();
8739 $sql = "SELECT t.rowid, " . $fieldstoshow . " FROM " . $this->db->prefix() . $this->db->sanitize($objecttmp->table_element) . " as t";
8740 if (!empty($objecttmp->isextrafieldmanaged)) {
8741 $sql .= " LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($objecttmp->table_element) . "_extrafields as e ON t.rowid = e.fk_object";
8743 if (!empty($objecttmp->parent_element)) {
8744 $parent_properties = getElementProperties($objecttmp->parent_element);
8745 $sql .= " INNER JOIN " . $this->db->prefix() . $this->db->sanitize($parent_properties['table_element
']) . " as o ON o.rowid = t.".$objecttmp->fk_parent_attribute;
8747 if (in_array($objecttmp->parent_element, ['commande
', 'propal
', 'facture
', 'expedition
'])) {
8748 $sql .= " LEFT JOIN " . $this->db->prefix() . "product as p ON p.rowid = t.fk_product";
8750 if (isset($objecttmp->ismultientitymanaged)) {
8751 if (!is_numeric($objecttmp->ismultientitymanaged)) {
8752 $tmparray = explode('@
', $objecttmp->ismultientitymanaged);
8753 $sql .= " INNER JOIN " . $this->db->prefix() . $this->db->sanitize($tmparray[1]) . " as parenttable ON parenttable.rowid = t." . $this->db->sanitize($tmparray[0]);
8755 if ($objecttmp->ismultientitymanaged === 'fk_soc@societe
') {
8756 if (!$user->hasRight('societe
', 'client
', 'voir
')) {
8757 $sql .= ", " . $this->db->prefix() . "societe_commerciaux as sc";
8762 // Add where from hooks
8763 $parameters = array(
8764 'object' => $objecttmp,
8765 'htmlname
' => $htmlname,
8766 'filter
' => $filter,
8767 'searchkey
' => $searchkey
8770 $reshook = $hookmanager->executeHooks('selectForFormsListWhere
', $parameters); // Note that $action and $object may have been modified by hook
8771 if (!empty($hookmanager->resPrint)) {
8772 $sql .= $hookmanager->resPrint;
8774 $sql .= " WHERE 1=1";
8775 if (isset($objecttmp->ismultientitymanaged)) {
8776 if ($objecttmp->ismultientitymanaged == 1) {
8777 $sql .= " AND t.entity IN (" . getEntity($objecttmp->table_element) . ")";
8779 if (!is_numeric($objecttmp->ismultientitymanaged)) {
8780 $sql .= " AND parenttable.entity = t." . $this->db->sanitize($tmparray[0]);
8782 if ($objecttmp->ismultientitymanaged == 1 && !empty($user->socid)) {
8783 if ($objecttmp->element == 'societe
') {
8784 $sql .= " AND t.rowid = " . ((int) $user->socid);
8786 $sql .= " AND t.fk_soc = " . ((int) $user->socid);
8789 if ($objecttmp->ismultientitymanaged === 'fk_soc@societe
') {
8790 if (!$user->hasRight('societe
', 'client
', 'voir
')) {
8791 $sql .= " AND t.rowid = sc.fk_soc AND sc.fk_user = " . ((int) $user->id);
8795 $splittedfieldstoshow = explode(',
', $fieldstoshow);
8796 foreach ($splittedfieldstoshow as &$field2) {
8797 if (is_numeric($pos = strpos($field2, ' '))) {
8798 $field2 = substr($field2, 0, $pos);
8801 if ($searchkey != '') {
8802 $sql .= natural_search($splittedfieldstoshow, $searchkey);
8805 if ($filter) { // Syntax example "(t.ref:like:'SO-%
') and (t.date_creation:<:'20160101
')"
8807 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
8808 if ($errormessage) {
8809 return 'Error forging a SQL request from an universal criteria:
' . $errormessage;
8813 $sql .= $this->db->order($sortfield ? $sortfield : $fieldstoshow, "ASC");
8814 //$sql.=$this->db->plimit($limit, 0);
8817 // Build output string
8818 $resql = $this->db->query($sql);
8820 // Construct $out and $outarray
8821 $out .= '<select
id=
"' . $htmlname . '" class=
"flat minwidth100' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled=
"disabled"' : '') . ($moreparams ? ' ' . $moreparams : '') . ' name=
"' . $htmlname . '">
' . "\n";
8823 // Warning: Do not use textifempty = ' ' or '
' here, or search on key will search on ' key
'. Seems it is no more true with selec2 v4
8824 $textifempty = '
';
8826 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
8827 if (getDolGlobalInt($confkeyforautocompletemode)) {
8828 if ($showempty && !is_numeric($showempty)) {
8829 $textifempty = $langs->trans($showempty);
8831 $textifempty .= $langs->trans("All");
8835 $out .= '<option value=
"-1">
' . $textifempty . '</option>
' . "\n";
8838 $num = $this->db->num_rows($resql);
8842 $obj = $this->db->fetch_object($resql);
8845 $tmparray = explode(',
', $fieldstoshow);
8846 $oldvalueforshowoncombobox = 0;
8847 foreach ($tmparray as $key => $val) {
8848 $val = preg_replace('/(t|p|o)\./
', '', $val);
8849 $label .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val]['showoncombobox
'] ? ' -
' : ' ') : '');
8850 $labelhtml .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val]['showoncombobox
'] ? ' -
' : ' ') : '');
8851 $label .= $obj->$val;
8852 $labelhtml .= $obj->$val;
8854 $oldvalueforshowoncombobox = empty($objecttmp->fields[$val]['showoncombobox
']) ? 0 : $objecttmp->fields[$val]['showoncombobox
'];
8856 if (empty($outputmode)) {
8857 if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) {
8858 $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>
';
8860 $out .= '<option value=
"' . $obj->rowid . '" data-html=
"' . dol_escape_htmltag($labelhtml, 0, 0, '', 0, 1) . '">
' . dol_escape_htmltag($label, 0, 0, '', 0, 1) . '</option>
';
8863 array_push($outarray, array('key
' => $obj->rowid, 'value
' => $label, 'label
' => $label));
8867 if (($i % 10) == 0) {
8873 $out .= '</select>
' . "\n";
8876 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
8877 $out .= ajax_combobox($htmlname, array(), getDolGlobalInt($confkeyforautocompletemode, 0));
8880 dol_print_error($this->db);
8883 $this->result = array('nbofelement
' => $num);
8915 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)
8917 global $conf, $langs;
8919 // Do we want a multiselect ?
8921 //if (preg_match('/^multi/
',$htmlname)) $jsbeautify = 1;
8924 if ($value_as_key) {
8925 $array = array_combine($array, $array);
8928 '@phan-var-force array{label:string,data-html:string,disable?:int<0,1>,css?:string} $array
'; // Array combine breaks information
8932 if ($addjscombo < 0) {
8933 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER
')) {
8939 $idname = str_replace(array('[
', ']
'), array('', ''), $htmlname);
8940 $out .= '<select id=
"' . preg_replace('/^\./', '', $idname) . '" ' . ($disabled ? 'disabled=
"disabled" ' : '') . 'class=
"flat ' . (preg_replace('/^\./', '', $htmlname)) . ($morecss ? ' ' . $morecss : '') . ' selectformat"';
8941 $out .= ' name=
"' . preg_replace('/^\./', '', $htmlname) . '" ' . ($moreparam ? $moreparam : '');
8945 $textforempty = ' ';
8946 if (!empty($conf->use_javascript_ajax)) {
8947 $textforempty = '
'; // If we use ajaxcombo, we need here to avoid to have an empty element that is too small.
8949 if (!is_numeric($show_empty)) {
8950 $textforempty = $show_empty;
8952 $out .= '<option
class=
"optiongrey" ' . ($moreparamonempty ? $moreparamonempty . ' ' : '') . 'value=
"' . (((int) $show_empty) < 0 ? $show_empty : -1) . '"' . ($id == $show_empty ? ' selected
' : '') . '>
' . $textforempty . '</option>
' . "\n";
8954 if (is_array($array)) {
8957 foreach ($array as $key => $value) {
8958 if (!is_array($value)) {
8959 $array[$key] = $langs->trans($value);
8961 $array[$key]['label
'] = $langs->trans($value['label
']);
8966 if ($sort == 'ASC
') {
8968 } elseif ($sort == 'DESC
') {
8972 foreach ($array as $key => $tmpvalue) {
8973 if (is_array($tmpvalue)) {
8974 $value = $tmpvalue['label
'];
8975 //$valuehtml = empty($tmpvalue['data-html
']) ? $value : $tmpvalue['data-html
'];
8977 $style = empty($tmpvalue['css
']) ? '' : ' class=
"' . $tmpvalue['css'] . '"';
8980 //$valuehtml = $tmpvalue;
8984 if (!empty($disablebademail)) {
8985 if (($disablebademail == 1 && !preg_match('/<.+@.+>/
', $value))
8986 || ($disablebademail == 2 && preg_match('/---/
', $value))) {
8988 $style = ' class=
"warning"';
8991 if ($key_in_label) {
8992 if (empty($nohtmlescape)) {
8993 $selectOptionValue = dol_escape_htmltag($key . ' -
' . ($maxlen ? dol_trunc($value, $maxlen) : $value));
8995 $selectOptionValue = $key . ' -
' . ($maxlen ? dol_trunc($value, $maxlen) : $value);
8998 if (empty($nohtmlescape)) {
8999 $selectOptionValue = dol_escape_htmltag($maxlen ? dol_trunc($value, $maxlen) : $value);
9001 $selectOptionValue = $maxlen ? dol_trunc($value, $maxlen) : $value;
9003 if ($value == '' || $value == '-
') {
9004 $selectOptionValue = '
';
9007 $out .= '<option value=
"' . $key . '"';
9008 $out .= $style . $disabled;
9009 if (is_array($id)) {
9010 if (in_array($key, $id) && !$disabled) {
9011 $out .= ' selected
'; // To preselect a value
9014 $id = (string) $id; // if $id = 0, then $id = '0
'
9015 if ($id != '' && (($id == (string) $key) || ($id == 'ifone
' && count($array) == 1)) && !$disabled) {
9016 $out .= ' selected
'; // To preselect a value
9019 if (!empty($nohtmlescape)) { // deprecated. Use instead the key 'data-html
' into input $array, managed at next step to use HTML content.
9020 $out .= ' data-html=
"' . dol_escape_htmltag($selectOptionValue) . '"';
9023 if (is_array($tmpvalue)) {
9024 foreach ($tmpvalue as $keyforvalue => $valueforvalue) {
9025 if ($keyforvalue == 'labelhtml
') {
9026 $keyforvalue = 'data-html
';
9028 if (preg_match('/^data-/
', $keyforvalue)) { // The best solution if you want to use HTML values into the list is to use data-html.
9029 $out .= ' '.dol_escape_htmltag($keyforvalue).'=
"'.dol_escape_htmltag($valueforvalue).'"';
9034 $out .= $selectOptionValue;
9035 $out .= "</option>\n";
9038 $out .= "</select>";
9040 // Add code for jquery to use multiselect
9041 if ($addjscombo && $jsbeautify) {
9042 // Enhance with select2
9043 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
9044 $out .= ajax_combobox($idname, array(), 0, 0, 'resolve
', (((int) $show_empty) < 0 ? (string) $show_empty : '-1
'), $morecss);
9068 public static function selectArrayAjax($htmlname, $url, $id = '
', $moreparam = '', $moreparamtourl = '', $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0)
9071 global $delayedhtmlcontent; // Will be used later outside of this function
9073 // TODO Use an internal dolibarr component instead of select2
9074 if (!getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT
') && !defined('REQUIRE_JQUERY_MULTISELECT
')) {
9078 $out = '<select
type=
"text" class=
"' . $htmlname . ($morecss ? ' ' . $morecss : '') . '" ' . ($moreparam ? $moreparam . ' ' : '') . 'name=
"' . $htmlname . '"></select>
';
9081 if (!empty($conf->use_javascript_ajax)) {
9082 $tmpplugin = 'select2
';
9083 $outdelayed = "\n" . '<!-- JS CODE TO ENABLE
' . $tmpplugin . ' for id ' . $htmlname . ' -->
9084 <script nonce=
"' . getNonce() . '">
9085 $(document).ready(
function () {
9087 ' . ($callurlonselect ? 'var saveRemoteData = [];
' : '') . '
9089 $(
".' . $htmlname . '").select2({
9092 url:
"' . $url . '",
9095 data: function (params) {
9097 q: params.term, // search term
9101 processResults: function (data) {
9102 // parse the results into the format expected by Select2.
9103 // since we are using custom formatting functions we do not need to alter the remote JSON data
9104 //console.log(data);
9105 saveRemoteData = data;
9106 /* format json result for select2 */
9108 $.each( data, function( key, value ) {
9109 result.push({id: key, text: value.text});
9111 //return {results:[{id:\'none\', text:\'aa\'}, {id:\'rrr\', text:\'Red\'},{id:\'bbb\', text:\'Search a into projects\'}], more:false}
9112 //console.log(result);
9113 return {results: result, more: false}
9117 language: (typeof select2arrayoflanguage === \'undefined\') ? \'en\' : select2arrayoflanguage,
9118 containerCssClass: \':all:\', /* Line to add class from the original SELECT propagated to the new <span class="select2-selection...> tag */
9120 escapeMarkup:
function (markup) {
return markup; },
9121 minimumInputLength:
' . ((int) $minimumInputLength) . ',
9122 formatResult:
function (result, container, query, escapeMarkup) {
9123 return escapeMarkup(result.text);
9127 ' . ($callurlonselect ? '
9129 $(
".' . $htmlname . '").change(
function() {
9130 var selected = $(\
'.' .
dol_escape_js($htmlname) .
'\').val();
9131 console.log(
"We select in selectArrayAjax the entry "+selected)
9133 $.each( saveRemoteData,
function( key, value ) {
9134 if (key == selected)
9136 console.log(
"selectArrayAjax - Do a redirect to "+value.url)
9137 location.assign(value.url);
9146 if ($acceptdelayedhtml) {
9147 $delayedhtmlcontent .= $outdelayed;
9149 $out .= $outdelayed;
9173 public static function selectArrayFilter($htmlname, $array, $id = '
', $moreparam = '', $disableFiltering = 0, $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0, $textfortitle = '')
9176 global $delayedhtmlcontent; // Will be used later outside of this function
9178 // TODO Use an internal dolibarr component instead of select2
9179 if (!getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT
') && !defined('REQUIRE_JQUERY_MULTISELECT
')) {
9183 $out = '<select
type=
"text"'.($textfortitle ? ' title=
"'.dol_escape_htmltag($textfortitle).'"' : '').' id=
"'.$htmlname.'" class=
"'.$htmlname.($morecss ? ' ' . $morecss : '').'"'.($moreparam ? ' '.$moreparam : '').' name=
"'.$htmlname.'"><option></option></select>
';
9185 $formattedarrayresult = array();
9187 foreach ($array as $key => $value) {
9188 $o = new stdClass();
9190 $o->text = $value['text
'];
9191 $o->url = $value['url
'];
9192 $formattedarrayresult[] = $o;
9196 if (!empty($conf->use_javascript_ajax)) {
9197 $tmpplugin = 'select2
';
9198 $outdelayed = "\n" . '<!-- JS CODE TO ENABLE
' . $tmpplugin . ' for id ' . $htmlname . ' -->
9199 <script nonce=
"' . getNonce() . '">
9200 $(document).ready(
function () {
9201 var data =
' . json_encode($formattedarrayresult) . ';
9203 ' . ($callurlonselect ? 'var saveRemoteData =
' . json_encode($array) . ';
' : '') . '
9207 language: (typeof select2arrayoflanguage === \
'undefined\') ? \'en\' : select2arrayoflanguage,
9208 containerCssClass: \':all:\', /* Line to add class from the original SELECT propagated to the new <span class="select2-selection...> tag */
9210 escapeMarkup:
function (markup) {
return markup; },
9211 minimumInputLength:
' . ((int) $minimumInputLength) . ',
9212 formatResult:
function (result, container, query, escapeMarkup) {
9213 return escapeMarkup(result.text);
9215 matcher:
function (params, data) {
9217 if(! data.id)
return null;
';
9219 if ($callurlonselect) {
9220 // We forge the url with 'sall=
'
9223 var urlBase = data.url;
9224 var separ = urlBase.indexOf(
"?") >= 0 ?
"&" :
"?";
9227 saveRemoteData[data.id].url = urlBase + separ +
"search_all=" + encodeURIComponent(params.term.replace(/\
"/g, ""));';
9230 if (!$disableFiltering) {
9233 if(data.text.match(new RegExp(params.term))) {
9248 ' . ($callurlonselect ? '
9249 /* Code to execute a GET when we select a value */
9250 $(\'.' . dol_escape_js($htmlname) . '\').change(function() {
9251 var selected = $(\'.' . dol_escape_js($htmlname) . '\').val();
9252 console.log("We select
"+selected)
9254 $(\'.' . dol_escape_js($htmlname) . '\').val(""); /* reset visible combo value */
9255 $.each( saveRemoteData, function( key, value ) {
9256 if (key == selected)
9258 console.log("selectArrayFilter - Do a redirect to
"+value.url)
9259 location.assign(value.url);
9268 if ($acceptdelayedhtml) {
9269 $delayedhtmlcontent .= $outdelayed;
9271 $out .= $outdelayed;
9294 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)
9296 global $conf, $langs;
9299 if ($addjscombo < 0) {
9300 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
9307 $useenhancedmultiselect = 0;
9308 if (!empty($conf->use_javascript_ajax) && !defined('MAIN_DO_NOT_USE_JQUERY_MULTISELECT') && (getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') || defined('REQUIRE_JQUERY_MULTISELECT'))) {
9310 $useenhancedmultiselect = 1; // Use the js multiselect in one line. Possible only if $addjscombo not 0.
9314 // We need a hidden field because when using the multiselect, if we unselect all, there is no
9315 // variable submitted at all, so no way to make a difference between variable not submitted and variable
9316 // submitted to nothing.
9317 $out .= '<input type="hidden
" name="'.$htmlname.'_multiselect
" value="1
">';
9318 // Output select component
9319 $out .= '<select id="' . $htmlname . '" class="multiselect
' . ($useenhancedmultiselect ? ' multiselectononeline
' : '') . ($morecss ? ' ' . $morecss : '') . '" multiple name="' . $htmlname . '[]
"' . ($moreattrib ? ' ' . $moreattrib : '') . ($width ? ' style="width:
' . (preg_match('/%/
', (string) $width) ? $width : $width . 'px
') . '"' : '') . '>' . "\n
";
9320 if (is_array($array) && !empty($array)) {
9321 if ($value_as_key) {
9322 $array = array_combine($array, $array);
9325 if (!empty($array)) {
9326 foreach ($array as $key => $value) {
9332 if (is_array($value) && array_key_exists('id', $value) && array_key_exists('label', $value)) {
9333 $tmpkey = $value['id'];
9334 $tmpvalue = empty($value['label']) ? '' : $value['label'];
9335 $tmpcolor = empty($value['color']) ? '' : $value['color'];
9336 $tmppicto = empty($value['picto']) ? '' : $value['picto'];
9337 $tmplabelhtml = empty($value['labelhtml']) ? (empty($value['data-html']) ? '' : $value['data-html']) : $value['labelhtml'];
9339 $newval = ($translate ? $langs->trans($tmpvalue) : $tmpvalue);
9340 $newval = ($key_in_label ? $tmpkey . ' - ' . $newval : $newval);
9342 $out .= '<option value="' . $tmpkey . '"';
9343 if (is_array($selected) && !empty($selected) && in_array((string) $tmpkey, $selected) && ((string) $tmpkey != '')) {
9344 $out .= ' selected';
9346 if (!empty($tmplabelhtml)) {
9347 $out .= ' data-html="' . dol_escape_htmltag($tmplabelhtml, 0, 0, '', 0, 1) . '"';
9349 $tmplabelhtml = ($tmppicto ? img_picto('', $tmppicto, 'class="pictofixedwidth
" style="color: #
' . $tmpcolor . '"') : '') . $newval;
9350 $out .= ' data-html="' . dol_escape_htmltag($tmplabelhtml, 0, 0, '', 0, 1) . '"';
9353 $out .= dol_htmlentitiesbr($newval);
9354 $out .= '</option>' . "\n
";
9358 $out .= '</select>' . "\n
";
9360 // Add code for jquery to use multiselect
9361 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') || defined('REQUIRE_JQUERY_MULTISELECT')) {
9362 $out .= "\n
" . '<!-- JS CODE TO ENABLE select for id ' . $htmlname . ', addjscombo=' . $addjscombo . ' -->';
9363 $out .= "\n
" . '<script nonce="' . getNonce() . '">' . "\n
";
9364 if ($addjscombo == 1) {
9365 $tmpplugin = !getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') ? constant('REQUIRE_JQUERY_MULTISELECT') : $conf->global->MAIN_USE_JQUERY_MULTISELECT;
9366 $out .= 'function formatResult(record, container) {' . "\n
";
9367 // If property data-html set, we decode html entities and use this.
9368 // Note that HTML content must have been sanitized from js with dol_escape_htmltag(xxx, 0, 0, '', 0, 1) when building the select option.
9369 $out .= ' if ($(record.element).attr("data-html
") != undefined && typeof htmlEntityDecodeJs === "function
") {';
9370 //$out .= ' console.log("aaa
");';
9371 $out .= ' return htmlEntityDecodeJs($(record.element).attr("data-html
"));';
9373 $out .= ' return record.text;';
9375 $out .= 'function formatSelection(record) {' . "\n
";
9376 if ($elemtype == 'category') {
9377 $out .= 'return \'<span><img src="' . DOL_URL_ROOT . '/theme/eldy/img/object_category.png
"> \'+record.text+\'</span>\';';
9379 $out .= 'return record.text;';
9382 $out .= '$(document).ready(function () {
9383 $(\'#' . dol_escape_js($htmlname) . '\').' . $tmpplugin . '({';
9388 text: \'' . dol_escape_js($placeholder) . '\'
9391 $out .= ' dir: \'ltr\',
9392 containerCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag (ko with multiselect) */
9393 dropdownCssClass: \
'' .
dol_escape_js($morecss) .
'\', /* Line to add class on the new <span class="select2-selection...> tag (ok with multiselect). Need full version of select2. */
9394 // Specify format function for dropdown item
9395 formatResult: formatResult,
9396 templateResult: formatResult, /* For 4.0 */
9397 escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
9398 // Specify format function for selected item
9399 formatSelection: formatSelection,
9400 templateSelection: formatSelection, /* For 4.0 */
9401 language: (typeof select2arrayoflanguage === \'undefined\') ? \'en\' : select2arrayoflanguage
9404 /* Add also morecss to the css .select2 that is after the #htmlname, for component that are show dynamically after load, because select2 set
9405 the size only if component is not hidden by default on load */
9408 } elseif ($addjscombo == 2 && !defined(
'DISABLE_MULTISELECT')) {
9412 $out .=
'console.log(\'addjscombo=2 for htmlname=' .
dol_escape_js($htmlname) .
'\');
';
9413 $out .= '$(document).ready(
function () {
9415 containerHTML: \
'<div class="multi-select-container">\',
9416 menuHTML: \'<div class="multi-select-menu">\',
9417 buttonHTML: \'<span class="multi-select-button ' .
dol_escape_js($morecss) .
'">\',
9418 menuItemHTML: \'<label class="multi-select-menuitem">\',
9419 activeClass: \'multi-select-container--open\',
9424 $out .= '</script>
';
9442 public static function multiSelectArrayWithCheckbox($htmlname, &$array, $varpage, $pos = '
')
9444 global $langs, $user;
9446 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER
')) {
9449 if (empty($array)) {
9453 $tmpvar = "MAIN_SELECTEDFIELDS_" . $varpage; // To get list of saved selected fields to show
9455 if (!empty($user->conf->$tmpvar)) { // A list of fields was already customized for user
9456 $tmparray = explode(',
', $user->conf->$tmpvar);
9457 foreach ($array as $key => $val) {
9459 //var_dump($tmparray);
9460 if (in_array($key, $tmparray)) {
9461 $array[$key]['checked
'] = 1;
9463 $array[$key]['checked
'] = 0;
9466 } else { // There is no list of fields already customized for user
9467 foreach ($array as $key => $val) {
9468 if (!empty($array[$key]['checked
']) && $array[$key]['checked
'] < 0) {
9469 $array[$key]['checked
'] = 0;
9474 $listoffieldsforselection = '';
9475 $listcheckedstring = '';
9477 foreach ($array as $key => $val) {
9479 // var_dump(array_key_exists('enabled
', $val));
9480 // var_dump(!$val['enabled
']);
9481 if (array_key_exists('enabled
', $val) && isset($val['enabled
']) && !$val['enabled
']) {
9482 unset($array[$key]); // We don't want
this field
9485 if (!empty($val[
'type']) && $val[
'type'] ==
'separate') {
9490 if (!empty($val[
'label']) && $val[
'label']) {
9491 if (!empty($val[
'langfile']) && is_object($langs)) {
9492 $langs->load($val[
'langfile']);
9496 $listoffieldsforselection .=
'<li><input type="checkbox" id="checkbox' . $key .
'" value="' . $key .
'"' . ((!array_key_exists(
'checked', $val) || empty($val[
'checked']) || $val[
'checked'] ==
'-1') ?
'' :
' checked="checked"') .
'/>';
9497 $listoffieldsforselection .=
'<label for="checkbox' . $key .
'">'.dol_string_nohtmltag($langs->trans($val[
'label'])) .
'</label></li>';
9498 $listcheckedstring .= (empty($val[
'checked']) ?
'' : $key .
',');
9502 $out =
'<!-- Component multiSelectArrayWithCheckbox ' . $htmlname .
' -->
9504 <dl class="dropdown">
9506 <a href="#' . $htmlname .
'">
9509 <input type="hidden" class="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $listcheckedstring .
'">
9511 <dd class="dropdowndd">
9512 <div class="multiselectcheckbox'.$htmlname.
'">
9513 <ul class="'.$htmlname.(((string) $pos ==
'1' || (
string) $pos ==
'left') ?
'left' :
'').
'">
9514 <li class="liinputsearch"><input class="inputsearch_dropdownselectedfields width90p minwidth200imp" style="width:90%;" type="text" placeholder="'.$langs->trans(
'Search').
'"></li>
9515 '.$listoffieldsforselection.
'
9521 <script nonce="' .
getNonce() .
'" type="text/javascript">
9522 jQuery(document).ready(function () {
9523 $(\'.multiselectcheckbox' . $htmlname .
' input[type="checkbox"]\').on(\'click\', function () {
9524 console.log("A new field was added/removed, we edit field input[name=formfilteraction]");
9526 $("input:hidden[name=formfilteraction]").val(\'listafterchangingselectedfields\'); // Update field so we know we changed something on selected fields after POST
9528 var title = $(this).val() + ",";
9529 if ($(this).is(\':checked\')) {
9530 $(\'.' . $htmlname .
'\').val(title + $(\'.' . $htmlname .
'\').val());
9533 $(\'.' . $htmlname .
'\').val( $(\'.' . $htmlname .
'\').val().replace(title, \'\') )
9535 // Now, we submit page
9536 //$(this).parents(\'form:first\').submit();
9538 $("input.inputsearch_dropdownselectedfields").on("keyup", function() {
9539 var value = $(this).val().toLowerCase();
9540 $(\'.multiselectcheckbox'.$htmlname.
' li > label\').filter(function() {
9541 $(this).parent().toggle($(this).text().toLowerCase().indexOf(value) > -1)
9564 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
9567 $categories = $cat->containing(
$id, $type);
9569 if ($rendermode == 1) {
9571 foreach ($categories as
$c) {
9572 $ways =
$c->print_all_ways(
' >> ', ($nolink ?
'none' :
''), 0, 1);
9573 foreach ($ways as $way) {
9574 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . (
$c->color ?
' style="background: #' .
$c->color .
';"' :
' style="background: #bbb"') .
'>' . $way .
'</li>';
9577 if (empty($toprint)) {
9580 return '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
9584 if ($rendermode == 0) {
9585 $arrayselected = array();
9586 $cate_arbo = $this->select_all_categories($type,
'',
'parent', 64, 0, 3);
9587 foreach ($categories as
$c) {
9588 $arrayselected[] =
$c->id;
9591 return $this->multiselectarray(
'categories', $cate_arbo, $arrayselected, 0, 0,
'', 0,
'100%',
'disabled',
'category');
9594 return 'ErrorBadValueForParameterRenderMode';
9608 global
$conf, $langs, $hookmanager;
9614 $hookmanager->initHooks(array(
'commonobject'));
9615 $parameters = array(
9616 'morehtmlright' => $morehtmlright,
9617 'compatibleImportElementsList' => &$compatibleImportElementsList,
9619 $reshook = $hookmanager->executeHooks(
'showLinkedObjectBlock', $parameters,
$object, $action);
9621 $nbofdifferenttypes = count(
$object->linkedObjects);
9623 if (empty($reshook)) {
9624 print
'<!-- showLinkedObjectBlock -->';
9625 print
load_fiche_titre($langs->trans($title), $morehtmlright,
'', 0,
'',
'showlinkedobjectblock');
9628 print
'<div class="div-table-responsive-no-min">';
9629 print
'<table class="noborder allwidth" data-block="showLinkedObject" data-element="' .
$object->element .
'" data-elementid="' .
$object->id .
'" >';
9631 print
'<tr class="liste_titre">';
9632 print
'<td>' . $langs->trans(
"Type") .
'</td>';
9633 print
'<td>' . $langs->trans(
"Ref") .
'</td>';
9634 print
'<td class="center"></td>';
9635 print
'<td class="center">' . $langs->trans(
"Date") .
'</td>';
9636 print
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
9637 print
'<td class="right">' . $langs->trans(
"Status") .
'</td>';
9641 $nboftypesoutput = 0;
9643 foreach (
$object->linkedObjects as $objecttype => $objects) {
9644 $tplpath = $element = $subelement = $objecttype;
9647 $showImportButton =
false;
9648 if (!empty($compatibleImportElementsList) && in_array($element, $compatibleImportElementsList)) {
9649 $showImportButton =
true;
9653 if ($objecttype !=
'supplier_proposal' && preg_match(
'/^([^_]+)_([^_]+)/i', $objecttype, $regs)) {
9654 $element = $regs[1];
9655 $subelement = $regs[2];
9656 $tplpath = $element .
'/' . $subelement;
9658 $tplname =
'linkedobjectblock';
9661 if ($objecttype ==
'facture') {
9662 $tplpath =
'compta/' . $element;
9663 if (!isModEnabled(
'invoice')) {
9666 } elseif ($objecttype ==
'facturerec') {
9667 $tplpath =
'compta/facture';
9668 $tplname =
'linkedobjectblockForRec';
9669 if (!isModEnabled(
'invoice')) {
9672 } elseif ($objecttype ==
'propal') {
9673 $tplpath =
'comm/' . $element;
9674 if (!isModEnabled(
'propal')) {
9677 } elseif ($objecttype ==
'supplier_proposal') {
9678 if (!isModEnabled(
'supplier_proposal')) {
9681 } elseif ($objecttype ==
'shipping' || $objecttype ==
'shipment' || $objecttype ==
'expedition') {
9682 $tplpath =
'expedition';
9683 if (!isModEnabled(
'shipping')) {
9686 } elseif ($objecttype ==
'reception') {
9687 $tplpath =
'reception';
9688 if (!isModEnabled(
'reception')) {
9691 } elseif ($objecttype ==
'delivery') {
9692 $tplpath =
'delivery';
9696 } elseif ($objecttype ==
'ficheinter') {
9697 $tplpath =
'fichinter';
9698 if (!isModEnabled(
'intervention')) {
9701 } elseif ($objecttype ==
'invoice_supplier') {
9702 $tplpath =
'fourn/facture';
9703 } elseif ($objecttype ==
'order_supplier') {
9704 $tplpath =
'fourn/commande';
9705 } elseif ($objecttype ==
'expensereport') {
9706 $tplpath =
'expensereport';
9707 } elseif ($objecttype ==
'subscription') {
9708 $tplpath =
'adherents';
9709 } elseif ($objecttype ==
'conferenceorbooth') {
9710 $tplpath =
'eventorganization';
9711 } elseif ($objecttype ==
'conferenceorboothattendee') {
9712 $tplpath =
'eventorganization';
9713 } elseif ($objecttype ==
'mo') {
9715 if (!isModEnabled(
'mrp')) {
9718 } elseif ($objecttype ==
'project_task') {
9719 $tplpath =
'projet/tasks';
9722 global $linkedObjectBlock;
9723 $linkedObjectBlock = $objects;
9726 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array(
'/' . $tplpath .
'/tpl'));
9727 foreach ($dirtpls as $reldir) {
9728 $reldir = rtrim($reldir,
'/');
9729 if ($nboftypesoutput == ($nbofdifferenttypes - 1)) {
9730 global $noMoreLinkedObjectBlockAfter;
9731 $noMoreLinkedObjectBlockAfter = 1;
9734 $res = @include
dol_buildpath($reldir .
'/' . $tplname .
'.tpl.php');
9742 if (!$nboftypesoutput) {
9743 print
'<tr><td colspan="7"><span class="opacitymedium">' . $langs->trans(
"None") .
'</span></td></tr>';
9748 if (!empty($compatibleImportElementsList)) {
9749 $res = @include
dol_buildpath(
'core/tpl/objectlinked_lineimport.tpl.php');
9755 return $nbofdifferenttypes;
9769 global
$conf, $langs, $hookmanager, $form;
9773 $form =
new Form($this->db);
9777 $linktoelemlist =
'';
9778 $listofidcompanytoscan =
'';
9780 if (!is_object(
$object->thirdparty)) {
9784 $possiblelinks = array();
9786 $dontIncludeCompletedItems =
getDolGlobalString(
'DONT_INCLUDE_COMPLETED_ELEMENTS_LINKS');
9788 if (is_object(
$object->thirdparty) && !empty(
$object->thirdparty->id) &&
$object->thirdparty->id > 0) {
9789 $listofidcompanytoscan = (int)
$object->thirdparty->id;
9791 $listofidcompanytoscan .=
',' . (int)
$object->thirdparty->parent;
9794 include_once DOL_DOCUMENT_ROOT .
'/projet/class/project.class.php';
9795 $tmpproject =
new Project($this->db);
9796 $tmpproject->fetch(
$object->fk_project);
9797 if ($tmpproject->socid > 0 && ($tmpproject->socid !=
$object->thirdparty->id)) {
9798 $listofidcompanytoscan .=
',' . (int) $tmpproject->socid;
9803 $possiblelinks = array(
9805 'enabled' => isModEnabled(
'propal'),
9807 'label' =>
'LinkToProposal',
9808 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"propal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'propal') .
')'.($dontIncludeCompletedItems ?
' AND t.fk_statut < 4' :
''),
9810 'shipping' => array(
9811 'enabled' => isModEnabled(
'shipping'),
9813 'label' =>
'LinkToExpedition',
9814 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"expedition as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'shipping') .
')'.($dontIncludeCompletedItems ?
' AND t.fk_statut < 2' :
''),
9817 'enabled' => isModEnabled(
'order'),
9819 'label' =>
'LinkToOrder',
9820 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"commande as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'commande') .
')'.($dontIncludeCompletedItems ?
' AND t.facture < 1' :
''),
9821 'linkname' =>
'commande',
9824 'enabled' => isModEnabled(
'invoice'),
9826 'label' =>
'LinkToInvoice',
9827 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"facture as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'invoice') .
')'.($dontIncludeCompletedItems ?
' AND t.paye < 1' :
''),
9828 'linkname' =>
'facture',
9830 'invoice_template' => array(
9831 'enabled' => isModEnabled(
'invoice'),
9833 'label' =>
'LinkToTemplateInvoice',
9834 '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') .
')',
9837 'enabled' => isModEnabled(
'contract'),
9839 'label' =>
'LinkToContract',
9840 '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
9841 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',
9843 'fichinter' => array(
9844 'enabled' => isModEnabled(
'intervention'),
9846 'label' =>
'LinkToIntervention',
9847 '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') .
')',
9849 'supplier_proposal' => array(
9850 'enabled' => isModEnabled(
'supplier_proposal'),
9852 'label' =>
'LinkToSupplierProposal',
9853 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, '' as ref_supplier, t.total_ht FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"supplier_proposal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'supplier_proposal') .
')'.($dontIncludeCompletedItems ?
' AND t.fk_statut < 4' :
''),
9855 'order_supplier' => array(
9856 'enabled' => isModEnabled(
"supplier_order"),
9858 'label' =>
'LinkToSupplierOrder',
9859 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"commande_fournisseur as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'commande_fournisseur') .
')'.($dontIncludeCompletedItems ?
' AND t.billed < 1' :
''),
9861 'invoice_supplier' => array(
9862 'enabled' => isModEnabled(
"supplier_invoice"),
9863 'perms' => 1,
'label' =>
'LinkToSupplierInvoice',
9864 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"facture_fourn as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'facture_fourn') .
')'.($dontIncludeCompletedItems ?
' AND t.paye < 1' :
''),
9867 'enabled' => isModEnabled(
'ticket'),
9869 'label' =>
'LinkToTicket',
9870 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.track_id, '0' as total_ht FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"ticket as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'ticket') .
')'.($dontIncludeCompletedItems ?
' AND t.fk_statut < 8' :
''),
9873 'enabled' => isModEnabled(
'mrp'),
9875 'label' =>
'LinkToMo',
9876 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.rowid, '0' as total_ht FROM " . $this->db->prefix() .
"societe as s INNER JOIN " . $this->db->prefix() .
"mrp_mo as t ON t.fk_soc = s.rowid WHERE t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) .
') AND t.entity IN (' .
getEntity(
'mo') .
')'.($dontIncludeCompletedItems ?
' AND t.status < 3' :
''),
9881 if (
$object->table_element ==
'commande_fournisseur') {
9882 $possiblelinks[
'mo'][
'sql'] =
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.rowid, '0' as total_ht FROM ".$this->db->prefix().
"societe as s INNER JOIN ".$this->db->prefix().
'mrp_mo as t ON t.fk_soc = s.rowid WHERE t.entity IN ('.
getEntity(
'mo').
')'.($dontIncludeCompletedItems ?
' AND t.status < 3' :
'');
9883 } elseif (
$object->table_element ==
'mrp_mo') {
9884 $possiblelinks[
'order_supplier'][
'sql'] =
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".$this->db->prefix().
"societe as s, ".$this->db->prefix().
'commande_fournisseur as t WHERE t.fk_soc = s.rowid AND t.entity IN ('.
getEntity(
'commande_fournisseur').
')'.($dontIncludeCompletedItems ?
' AND t.billed < 1' :
'');
9888 if (!empty($listofidcompanytoscan)) {
9890 $hookmanager->initHooks(array(
'commonobject'));
9891 $parameters = array(
'listofidcompanytoscan' => $listofidcompanytoscan,
'possiblelinks' => $possiblelinks);
9892 $reshook = $hookmanager->executeHooks(
'showLinkToObjectBlock', $parameters,
$object, $action);
9895 if (empty($reshook)) {
9896 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
9897 $possiblelinks = array_merge($possiblelinks, $hookmanager->resArray);
9899 } elseif ($reshook > 0) {
9900 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
9901 $possiblelinks = $hookmanager->resArray;
9905 if (!empty($possiblelinks)) {
9910 $htmltoenteralink =
'';
9911 foreach ($possiblelinks as $key => $possiblelink) {
9913 if (empty($possiblelink[
'enabled'])) {
9917 if (!empty($possiblelink[
'perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || !in_array($key, $excludelinksto))) {
9918 $htmltoenteralink .=
'<div id="' . $key .
'list"' . (empty(
$conf->use_javascript_ajax) ?
'' :
' style="display:none"') .
'>';
9922 $htmltoenteralink .=
'<br>'.
"\n";
9923 $htmltoenteralink .=
'<!-- form to add a link from anywhere -->'.
"\n";
9924 $htmltoenteralink .=
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinkedbyref' . $key .
'">';
9925 $htmltoenteralink .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
9926 $htmltoenteralink .=
'<input type="hidden" name="action" value="addlinkbyref">';
9927 $htmltoenteralink .=
'<input type="hidden" name="id" value="' .
$object->id .
'">';
9928 $htmltoenteralink .=
'<input type="hidden" name="addlink" value="' . $key .
'">';
9929 $htmltoenteralink .=
'<table class="noborder">';
9930 $htmltoenteralink .=
'<tr class="liste_titre">';
9932 $htmltoenteralink .=
'<td class="center"><input type="text" placeholder="'.dol_escape_htmltag($langs->trans(
"Ref")).
'" name="reftolinkto" value="' .
dol_escape_htmltag(
GETPOST(
'reftolinkto',
'alpha')) .
'"> ';
9933 $htmltoenteralink .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
'ToLink') .
'"> ';
9934 $htmltoenteralink .=
'<input type="submit" class="button smallpaddingimp" name="cancel" value="' . $langs->trans(
'Cancel') .
'"></td>';
9935 $htmltoenteralink .=
'</tr>';
9936 $htmltoenteralink .=
'</table>';
9937 $htmltoenteralink .=
'</form>';
9940 $sql = $possiblelink[
'sql'];
9942 $resqllist = $this->db->query($sql);
9944 $num = $this->db->num_rows($resqllist);
9950 $htmltoenteralink .=
'<br>';
9952 $htmltoenteralink .=
'<!-- form to add a link from object to same thirdparty -->'.
"\n";
9953 $htmltoenteralink .=
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinked' . $key .
'">';
9954 $htmltoenteralink .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
9955 $htmltoenteralink .=
'<input type="hidden" name="action" value="addlink">';
9956 $htmltoenteralink .=
'<input type="hidden" name="id" value="' .
$object->id .
'">';
9957 $htmltoenteralink .=
'<input type="hidden" name="addlink" value="' . $key .
'">';
9958 $htmltoenteralink .=
'<table class="noborder">';
9959 $htmltoenteralink .=
'<tr class="liste_titre">';
9960 $htmltoenteralink .=
'<td class="nowrap"></td>';
9961 $htmltoenteralink .=
'<td>' . $langs->trans(
"Ref") .
'</td>';
9962 $htmltoenteralink .=
'<td>' . $langs->trans(
"RefCustomer") .
'</td>';
9963 $htmltoenteralink .=
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
9964 $htmltoenteralink .=
'<td>' . $langs->trans(
"Company") .
'</td>';
9965 $htmltoenteralink .=
'</tr>';
9967 $objp = $this->db->fetch_object($resqllist);
9968 $alreadylinked =
false;
9969 if (!empty(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key])) {
9970 if (in_array($objp->rowid, array_values(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key]))) {
9971 $alreadylinked =
true;
9974 $htmltoenteralink .=
'<tr class="oddeven">';
9975 $htmltoenteralink .=
'<td>';
9976 if ($alreadylinked) {
9977 $htmltoenteralink .=
img_picto(
'',
'link');
9979 $htmltoenteralink .=
'<input type="checkbox" name="idtolinkto[' . $key .
'_' . $objp->rowid .
']" id="' . $key .
'_' . $objp->rowid .
'" value="' . $objp->rowid .
'">';
9981 $htmltoenteralink .=
'</td>';
9982 $htmltoenteralink .=
'<td><label for="' . $key .
'_' . $objp->rowid .
'">' . $objp->ref .
'</label></td>';
9983 $htmltoenteralink .=
'<td>' . (!empty($objp->ref_client) ? $objp->ref_client : (!empty($objp->ref_supplier) ? $objp->ref_supplier :
'')) .
'</td>';
9984 $htmltoenteralink .=
'<td class="right">';
9985 if ($possiblelink[
'label'] ==
'LinkToContract') {
9986 $htmltoenteralink .= $form->textwithpicto(
'', $langs->trans(
"InformationOnLinkToContract")) .
' ';
9988 $htmltoenteralink .=
'<span class="amount">' . (isset($objp->total_ht) ?
price($objp->total_ht) :
'') .
'</span>';
9989 $htmltoenteralink .=
'</td>';
9990 $htmltoenteralink .=
'<td>' . $objp->name .
'</td>';
9991 $htmltoenteralink .=
'</tr>';
9994 $htmltoenteralink .=
'</table>';
9995 $htmltoenteralink .=
'<div class="center">';
9997 $htmltoenteralink .=
'<input type="submit" class="button valignmiddle marginleftonly marginrightonly smallpaddingimp" value="' . $langs->trans(
'ToLink') .
'">';
9999 if (empty(
$conf->use_javascript_ajax)) {
10000 $htmltoenteralink .=
'<input type="submit" class="button button-cancel marginleftonly marginrightonly smallpaddingimp" name="cancel" value="' . $langs->trans(
"Cancel") .
'"></div>';
10002 $htmltoenteralink .=
'<input type="submit" onclick="jQuery(\'#' . $key .
'list\').toggle(); return false;" class="button button-cancel marginleftonly marginrightonly smallpaddingimp" name="cancel" value="' . $langs->trans(
"Cancel") .
'"></div>';
10004 $htmltoenteralink .=
'</form>';
10007 $this->db->free($resqllist);
10011 $htmltoenteralink .=
'</div>';
10016 $linktoelemlist .=
'<li><a href="#linkto' . $key .
'" class="linkto dropdowncloseonclick" rel="' . $key .
'">' . $langs->trans($possiblelink[
'label']) .
' (' . $num .
')</a></li>';
10019 $linktoelemlist .=
'<li><span class="linktodisabled">' . $langs->trans($possiblelink[
'label']) .
' (0)</span></li>';
10024 if ($linktoelemlist) {
10026 <dl class="dropdown" id="linktoobjectname">
10028 if (!empty(
$conf->use_javascript_ajax)) {
10029 $linktoelem .=
'<dt><a href="#linktoobjectname"><span class="fas fa-link paddingrightonly"></span>' . $langs->trans(
"LinkTo") .
'...</a></dt>';
10031 $linktoelem .=
'<dd>
10032 <div class="multiselectlinkto">
10033 <ul class="ulselectedfields">' . $linktoelemlist .
'
10042 if (!empty(
$conf->use_javascript_ajax)) {
10043 print
'<!-- Add js to show linkto box -->
10044 <script nonce="' .
getNonce() .
'">
10045 jQuery(document).ready(function() {
10046 jQuery(".linkto").click(function() {
10047 console.log("We choose to show/hide links for rel="+jQuery(this).attr(\'rel\')+" so #"+jQuery(this).attr(\'rel\')+"list");
10048 jQuery("#"+jQuery(this).attr(\'rel\')+"list").toggle();
10056 return array(
'linktoelem' => $linktoelem,
'htmltoenteralink' => $htmltoenteralink);
10058 print $htmltoenteralink;
10061 return $linktoelem;
10078 public function selectyesno($htmlname, $value =
'', $option = 0, $disabled =
false, $useempty = 0, $addjscombo = 0, $morecss =
'width75', $labelyes =
'Yes', $labelno =
'No')
10089 $disabled = ($disabled ?
' disabled' :
'');
10091 $resultyesno =
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'"' . $disabled .
'>' .
"\n";
10093 $resultyesno .=
'<option value="-1"' . (($value < 0) ?
' selected' :
'') .
'> </option>' .
"\n";
10095 if ((
"$value" ==
'yes') || ($value == 1)) {
10096 $resultyesno .=
'<option value="' . $yes .
'" selected>' . $langs->trans($labelyes) .
'</option>' .
"\n";
10097 $resultyesno .=
'<option value="' . $no .
'">' . $langs->trans($labelno) .
'</option>' .
"\n";
10099 $selected = (($useempty && $value !=
'0' && $value !=
'no') ?
'' :
' selected');
10100 $resultyesno .=
'<option value="' . $yes .
'">' . $langs->trans($labelyes) .
'</option>' .
"\n";
10101 $resultyesno .=
'<option value="' . $no .
'"' . $selected .
'>' . $langs->trans($labelno) .
'</option>' .
"\n";
10103 $resultyesno .=
'</select>' .
"\n";
10106 $resultyesno .=
ajax_combobox($htmlname, array(), 0, 0,
'resolve', ($useempty < 0 ? (
string) $useempty :
'-1'), $morecss);
10109 return $resultyesno;
10126 $sql =
"SELECT rowid, label";
10127 $sql .=
" FROM " . $this->db->prefix() .
"export_model";
10128 $sql .=
" WHERE type = '" . $this->db->escape($type) .
"'";
10129 $sql .=
" ORDER BY rowid";
10130 $result = $this->db->query($sql);
10132 print
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
10134 print
'<option value="-1"> </option>';
10137 $num = $this->db->num_rows($result);
10139 while ($i < $num) {
10140 $obj = $this->db->fetch_object($result);
10141 if ($selected == $obj->rowid) {
10142 print
'<option value="' . $obj->rowid .
'" selected>';
10144 print
'<option value="' . $obj->rowid .
'">';
10174 public function showrefnav(
$object, $paramid, $morehtml =
'', $shownav = 1, $fieldid =
'rowid', $fieldref =
'ref', $morehtmlref =
'', $moreparam =
'', $nodbprefix = 0, $morehtmlleft =
'', $morehtmlstatus =
'', $morehtmlright =
'')
10176 global
$conf, $langs, $hookmanager, $extralanguages;
10179 if (empty($fieldid)) {
10180 $fieldid =
'rowid';
10182 if (empty($fieldref)) {
10187 $addgendertxt =
'';
10188 if (property_exists(
$object,
'gender') && !empty(
$object->gender)) {
10189 $addgendertxt =
' ';
10192 $addgendertxt .=
'<i class="fas fa-mars valignmiddle"></i>';
10195 $addgendertxt .=
'<i class="fas fa-venus valignmiddle"></i>';
10198 $addgendertxt .=
'<i class="fas fa-transgender valignmiddle"></i>';
10204 if (is_object($hookmanager)) {
10205 $parameters = array(
'showrefnav' =>
true);
10206 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters,
$object);
10207 if (!empty($hookmanager->resPrint)) {
10208 if (empty(
$object->next_prev_filter) && preg_match(
'/^\s*AND/i', $hookmanager->resPrint)) {
10209 $object->next_prev_filter = preg_replace(
'/^\s*AND\s*/i',
'', $hookmanager->resPrint);
10210 } elseif (!empty(
$object->next_prev_filter) && !preg_match(
'/^\s*AND/i', $hookmanager->resPrint)) {
10211 $object->next_prev_filter .=
' AND '.$hookmanager->resPrint;
10213 $object->next_prev_filter .= $hookmanager->resPrint;
10218 $previous_ref = $next_ref =
'';
10221 $object->load_previous_next_ref((isset(
$object->next_prev_filter) ?
$object->next_prev_filter :
''), $fieldid, $nodbprefix);
10223 $navurl = $_SERVER[
"PHP_SELF"];
10225 if ($paramid ==
'project_ref') {
10226 if (preg_match(
'/\/tasks\/(task|contact|note|document)\.php/', $navurl)) {
10227 $navurl = preg_replace(
'/\/tasks\/(task|contact|time|note|document)\.php/',
'/tasks.php', $navurl);
10234 $stringforfirstkey = $langs->trans(
"KeyboardShortcut");
10235 if (
$conf->browser->name ==
'chrome') {
10236 $stringforfirstkey .=
' ALT +';
10237 } elseif (
$conf->browser->name ==
'firefox') {
10238 $stringforfirstkey .=
' ALT + SHIFT +';
10240 $stringforfirstkey .=
' CTL +';
10243 $previous_ref =
$object->ref_previous ?
'<a accesskey="p" alt="'.dol_escape_htmltag($langs->trans(
"Previous")).
'" title="' . $stringforfirstkey .
' p" class="classfortooltip" href="' . $navurl .
'?' . $paramid .
'=' . urlencode(
$object->ref_previous) . $moreparam .
'"><i class="fa fa-chevron-left"></i></a>' :
'<span class="inactive"><i class="fa fa-chevron-left opacitymedium"></i></span>';
10244 $next_ref =
$object->ref_next ?
'<a accesskey="n" alt="'.dol_escape_htmltag($langs->trans(
"Next")).
'" title="' . $stringforfirstkey .
' n" class="classfortooltip" href="' . $navurl .
'?' . $paramid .
'=' . urlencode(
$object->ref_next) . $moreparam .
'"><i class="fa fa-chevron-right"></i></a>' :
'<span class="inactive"><i class="fa fa-chevron-right opacitymedium"></i></span>';
10248 $ret .=
'<!-- Start banner content --><div style="vertical-align: middle">';
10251 if ($morehtmlright) {
10252 $ret .=
'<div class="inline-block floatleft">' . $morehtmlright .
'</div>';
10255 if ($previous_ref || $next_ref || $morehtml) {
10256 $ret .=
'<div class="pagination paginationref"><ul class="right">';
10258 if ($morehtml &&
getDolGlobalInt(
'MAIN_OPTIMIZEFORTEXTBROWSER') < 2) {
10259 $ret .=
'<!-- morehtml --><li class="noborder litext' . (($shownav && $previous_ref && $next_ref) ?
' clearbothonsmartphone' :
'') .
'">' . $morehtml .
'</li>';
10261 if ($shownav && ($previous_ref || $next_ref)) {
10262 $ret .=
'<li class="pagination">' . $previous_ref .
'</li>';
10263 $ret .=
'<li class="pagination">' . $next_ref .
'</li>';
10265 if ($previous_ref || $next_ref || $morehtml) {
10266 $ret .=
'</ul></div>';
10270 $parameters = array(
'morehtmlstatus' => $morehtmlstatus);
10271 $reshook = $hookmanager->executeHooks(
'moreHtmlStatus', $parameters,
$object);
10272 if (empty($reshook)) {
10273 $morehtmlstatus .= $hookmanager->resPrint;
10275 $morehtmlstatus = $hookmanager->resPrint;
10277 if ($morehtmlstatus) {
10278 $ret .=
'<div class="statusref">' . $morehtmlstatus .
'</div>';
10281 $parameters = array();
10282 $reshook = $hookmanager->executeHooks(
'moreHtmlRef', $parameters,
$object);
10283 if (empty($reshook)) {
10284 $morehtmlref .= $hookmanager->resPrint;
10285 } elseif ($reshook > 0) {
10286 $morehtmlref = $hookmanager->resPrint;
10290 if ($morehtmlleft) {
10291 if (
$conf->browser->layout ==
'phone') {
10292 $ret .=
'<!-- morehtmlleft --><div class="floatleft">' . $morehtmlleft .
'</div>';
10294 $ret .=
'<!-- morehtmlleft --><div class="inline-block floatleft">' . $morehtmlleft .
'</div>';
10299 $ret .=
'<div class="inline-block floatleft valignmiddle maxwidth750 marginbottomonly refid' . (($shownav && ($previous_ref || $next_ref)) ?
' refidpadding' :
'') .
'">';
10302 if (
$object->element ==
'societe') {
10306 $arrayoflangcode = array();
10311 if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
10312 if (!is_object($extralanguages)) {
10313 include_once DOL_DOCUMENT_ROOT .
'/core/class/extralanguages.class.php';
10316 $extralanguages->fetch_name_extralanguages(
'societe');
10320 if (!empty($extralanguages->attributes[
'societe']) && !empty($extralanguages->attributes[
'societe'][
'name'])) {
10321 $object->fetchValuesForExtraLanguages();
10325 foreach ($arrayoflangcode as $extralangcode) {
10327 if (
$object->array_languages[
'name'][$extralangcode]) {
10328 $htmltext .=
$object->array_languages[
'name'][$extralangcode];
10330 $htmltext .=
'<span class="opacitymedium">' . $langs->trans(
"SwitchInEditModeToAddTranslation") .
'</span>';
10333 $ret .=
'<!-- Show translations of name -->' .
"\n";
10334 $ret .= $this->textwithpicto(
'', $htmltext, -1,
'language',
'opacitymedium paddingleft');
10337 } elseif (
$object->element ==
'member') {
10338 '@phan-var-force Adherent $object';
10339 $ret .=
$object->ref .
'<br>';
10340 $fullname =
$object->getFullName($langs);
10346 } elseif (in_array(
$object->element, array(
'contact',
'user'))) {
10347 $ret .=
'<span class="valignmiddle">'.dol_htmlentities(
$object->getFullName($langs)).
'</span>'.$addgendertxt;
10348 } elseif (
$object->element ==
'usergroup') {
10350 } elseif (in_array(
$object->element, array(
'action',
'agenda'))) {
10351 '@phan-var-force ActionComm $object';
10353 } elseif (in_array(
$object->element, array(
'adherent_type'))) {
10355 } elseif (
$object->element ==
'ecm_directories') {
10357 } elseif ($fieldref !=
'none') {
10360 if ($morehtmlref) {
10362 if (substr($morehtmlref, 0, 4) !=
'<div') {
10366 $ret .=
'<!-- morehtmlref -->'.$morehtmlref;
10371 $ret .=
'</div><!-- End banner content -->';
10390 if (empty(
$object->barcode)) {
10395 if (empty(
$object->barcode_type_code) || empty(
$object->barcode_type_coder)) {
10397 $result =
$object->fetchBarCode();
10400 return '<!-- ErrorFetchBarcode -->';
10405 $url = DOL_URL_ROOT .
'/viewimage.php?modulepart=barcode&generator=' . urlencode(
$object->barcode_type_coder) .
'&code=' . urlencode(
$object->barcode) .
'&encoding=' . urlencode(
$object->barcode_type_code);
10406 $out =
'<!-- url barcode = ' . $url .
' -->';
10407 $out .=
'<img src="' . $url .
'"' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
'>';
10429 public static function showphoto($modulepart,
$object, $width = 100, $height = 0, $caneditfield = 0, $cssclass =
'photowithmargin', $imagesize =
'', $addlinktofullsize = 1, $cache = 0, $forcecapture =
'', $noexternsourceoverwrite = 0)
10431 global
$conf, $langs;
10438 $originalfile =
'';
10442 if ($modulepart ==
'societe') {
10443 $dir =
$conf->societe->multidir_output[$entity];
10446 if ((
string) $imagesize ==
'mini') {
10448 } elseif ((
string) $imagesize ==
'small') {
10457 } elseif ($modulepart ==
'contact') {
10458 $dir =
$conf->societe->multidir_output[$entity] .
'/contact';
10459 if (!empty(
$object->photo)) {
10461 if ((
string) $imagesize ==
'mini') {
10463 } elseif ((
string) $imagesize ==
'small') {
10473 } elseif ($modulepart ==
'userphoto') {
10474 $dir =
$conf->user->dir_output;
10475 if (!empty(
$object->photo)) {
10477 if ((
string) $imagesize ==
'mini') {
10479 } elseif ((
string) $imagesize ==
'small') {
10488 $altfile =
$object->id .
".jpg";
10492 } elseif ($modulepart ==
'memberphoto') {
10493 $dir =
$conf->adherent->dir_output;
10494 if (!empty(
$object->photo)) {
10496 if ((
string) $imagesize ==
'mini') {
10498 } elseif ((
string) $imagesize ==
'small') {
10507 $altfile =
$object->id .
".jpg";
10514 if ($modulepart !=
"unknown" && method_exists(
$object,
'getDataToShowPhoto')) {
10515 $tmpdata =
$object->getDataToShowPhoto($modulepart, $imagesize);
10517 $dir = $tmpdata[
'dir'];
10518 $file = $tmpdata[
'file'];
10519 $originalfile = $tmpdata[
'originalfile'];
10520 $altfile = $tmpdata[
'altfile'];
10521 $email = $tmpdata[
'email'];
10522 $capture = $tmpdata[
'capture'];
10526 if ($forcecapture) {
10527 $capture = $forcecapture;
10533 if ($file && file_exists($dir .
"/" . $file)) {
10534 if ($addlinktofullsize) {
10536 if ($urladvanced) {
10537 $ret .=
'<a href="' . $urladvanced .
'">';
10539 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
10542 $ret .=
'<img alt="" class="photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
' photologo' . (preg_replace(
'/[^a-z]/i',
'_', $file)) .
'" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($file) .
'&cache=' . $cache .
'">';
10543 if ($addlinktofullsize) {
10546 } elseif ($altfile && file_exists($dir .
"/" . $altfile)) {
10547 if ($addlinktofullsize) {
10549 if ($urladvanced) {
10550 $ret .=
'<a href="' . $urladvanced .
'">';
10552 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
10555 $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 .
'">';
10556 if ($addlinktofullsize) {
10560 $nophoto =
'/public/theme/common/nophoto.png';
10561 $defaultimg =
'identicon';
10562 if (in_array($modulepart, array(
'societe',
'userphoto',
'contact',
'memberphoto'))) {
10563 if ($modulepart ==
'societe' || ($modulepart ==
'memberphoto' && !empty(
$object->morphy) && strpos(
$object->morphy,
'mor') !==
false)) {
10564 $nophoto =
'company';
10566 $nophoto =
'/public/theme/common/user_anonymous.png';
10568 $nophoto =
'/public/theme/common/user_man.png';
10571 $nophoto =
'/public/theme/common/user_woman.png';
10576 if (isModEnabled(
'gravatar') && $email && empty($noexternsourceoverwrite)) {
10578 $ret .=
'<!-- Put link to gravatar -->';
10579 $ret .=
'<img class="photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" title="' . $email .
' Gravatar avatar" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="https://www.gravatar.com/avatar/' .
dol_hash(strtolower(trim($email)),
'sha256', 1) .
'?s=' . $width .
'&d=' . $defaultimg .
'">';
10581 if ($nophoto ==
'company') {
10582 $ret .=
'<div class="divforspanimg valignmiddle center photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
'>' .
img_picto(
'',
'company') .
'</div>';
10585 $ret .=
'<img class="photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="' . DOL_URL_ROOT . $nophoto .
'">';
10590 if ($caneditfield) {
10594 $ret .=
'<table class="nobordernopadding centpercent">';
10596 $ret .=
'<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> <label for="photodelete">' . $langs->trans(
"Delete") .
'</label><br><br></td></tr>';
10598 $ret .=
'<tr><td class="tdoverflow">';
10600 $maxmin = $maxfilesizearray[
'maxmin'];
10602 $ret .=
'<input type="hidden" name="MAX_FILE_SIZE" value="' . ($maxmin * 1024) .
'">';
10604 $ret .=
'<input type="file" class="flat maxwidth200onsmartphone" name="photo" id="photoinput" accept="image/*"' . ($capture ?
' capture="' . $capture .
'"' :
'') .
'>';
10605 $ret .=
'</td></tr>';
10606 $ret .=
'</table>';
10631 public function select_dolgroups($selected = 0, $htmlname =
'groupid', $show_empty = 0, $exclude =
'', $disabled = 0, $include =
'', $enableonly = array(), $force_entity =
'0', $multiple =
false, $morecss =
'minwidth200')
10634 global
$conf, $user, $langs;
10637 $excludeGroups =
null;
10638 if (is_array($exclude)) {
10639 $excludeGroups = implode(
",", $exclude);
10642 $includeGroups =
null;
10643 if (is_array($include)) {
10644 $includeGroups = implode(
",", $include);
10647 if (!is_array($selected)) {
10648 $selected = array($selected);
10654 $sql =
"SELECT ug.rowid, ug.nom as name";
10655 if (isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && !$user->entity) {
10656 $sql .=
", e.label";
10658 $sql .=
" FROM " . $this->db->prefix() .
"usergroup as ug ";
10659 if (isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && !$user->entity) {
10660 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid=ug.entity";
10661 if ($force_entity) {
10662 $sql .=
" WHERE ug.entity IN (0, " . $force_entity .
")";
10664 $sql .=
" WHERE ug.entity IS NOT NULL";
10667 $sql .=
" WHERE ug.entity IN (0, " .
$conf->entity .
")";
10669 if (is_array($exclude) && $excludeGroups) {
10670 $sql .=
" AND ug.rowid NOT IN (" . $this->db->sanitize($excludeGroups) .
")";
10672 if (is_array($include) && $includeGroups) {
10673 $sql .=
" AND ug.rowid IN (" . $this->db->sanitize($includeGroups) .
")";
10675 $sql .=
" ORDER BY ug.nom ASC";
10677 dol_syslog(get_class($this) .
"::select_dolgroups", LOG_DEBUG);
10678 $resql = $this->db->query($sql);
10681 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
10683 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
10685 $num = $this->db->num_rows($resql);
10688 if ($show_empty && !$multiple) {
10689 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'> </option>' .
"\n";
10692 while ($i < $num) {
10693 $obj = $this->db->fetch_object($resql);
10695 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
10699 $label = $obj->name;
10700 $labelhtml = $obj->name;
10701 if (isModEnabled(
'multicompany') && !
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE') &&
$conf->entity == 1) {
10702 $label .=
" (" . $obj->label .
")";
10703 $labelhtml .=
' <span class="opacitymedium">(' . $obj->label .
')</span>';
10706 $out .=
'<option value="' . $obj->rowid .
'"';
10707 if ($disableline) {
10708 $out .=
' disabled';
10710 if ((isset($selected[0]) && is_object($selected[0]) && $selected[0]->
id == $obj->rowid)
10711 || ((!isset($selected[0]) || !is_object($selected[0])) && !empty($selected) && in_array($obj->rowid, $selected))) {
10712 $out .=
' selected';
10714 $out .=
' data-html="'.dol_escape_htmltag($labelhtml).
'"';
10717 $out .=
'</option>';
10722 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'></option>' .
"\n";
10724 $out .=
'<option value="" disabled>' . $langs->trans(
"NoUserGroupDefined") .
'</option>';
10726 $out .=
'</select>';
10745 $out =
'<div class="nowraponall">';
10746 $out .=
'<button type="submit" class="liste_titre button_search reposition" name="button_search_x" value="x"><span class="fas fa-search"></span></button>';
10747 $out .=
'<button type="submit" class="liste_titre button_removefilter reposition" name="button_removefilter_x" value="x"><span class="fas fa-times"></span></button>';
10761 public function showCheckAddButtons($cssclass =
'checkforaction', $calljsfunction = 0, $massactionname =
"massaction")
10767 if (!empty(
$conf->use_javascript_ajax)) {
10768 $out .=
'<div class="inline-block checkallactions"><input type="checkbox" id="' . $cssclass .
's" name="' . $cssclass .
's" class="checkallactions"></div>';
10770 $out .=
'<script nonce="' .
getNonce() .
'">
10771 $(document).ready(function() {
10772 $("#' . $cssclass .
's").click(function() {
10773 if($(this).is(\':checked\')){
10774 console.log("We check all ' . $cssclass .
' and trigger the change method");
10775 $(".' . $cssclass .
'").prop(\'checked\', true).trigger(\'change\');
10779 console.log("We uncheck all");
10780 $(".' . $cssclass .
'").prop(\'checked\', false).trigger(\'change\');
10782 if ($calljsfunction) {
10783 $out .=
'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0, "' . $massactionname .
'", "' . $cssclass .
'"); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }';
10786 $(".' . $cssclass .
'").change(function() {
10787 $(this).closest("tr").toggleClass("highlight", this.checked);
10806 $out = $this->showFilterButtons();
10807 if ($addcheckuncheckall) {
10808 $out .= $this->showCheckAddButtons($cssclass, $calljsfunction, $massactionname);
10826 public function selectExpenseCategories($selected =
'', $htmlname =
'fk_c_exp_tax_cat', $useempty = 0, $excludeid = array(), $target =
'', $default_selected = 0, $params = array(), $info_admin = 1)
10828 global $langs, $user;
10831 $sql =
"SELECT rowid, label FROM " . $this->db->prefix() .
"c_exp_tax_cat WHERE active = 1";
10832 $sql .=
" AND entity IN (0," .
getEntity(
'exp_tax_cat') .
")";
10833 if (!empty($excludeid)) {
10834 $sql .=
" AND rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeid)) .
")";
10836 $sql .=
" ORDER BY label";
10838 $resql = $this->db->query($sql);
10840 $out =
'<select id="select_' . $htmlname .
'" name="' . $htmlname .
'" class="' . $htmlname .
' flat minwidth75imp maxwidth200">';
10842 $out .=
'<option value="0"> </option>';
10845 while ($obj = $this->db->fetch_object($resql)) {
10846 $out .=
'<option ' . ($selected == $obj->rowid ?
'selected="selected"' :
'') .
' value="' . $obj->rowid .
'">' . $langs->trans($obj->label) .
'</option>';
10848 $out .=
'</select>';
10851 if (!empty($htmlname) && $user->admin && $info_admin) {
10852 $out .=
' ' .
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
10855 if (!empty($target)) {
10856 $sql =
"SELECT c.id FROM " . $this->db->prefix() .
"c_type_fees as c WHERE c.code = 'EX_KME' AND c.active = 1";
10857 $resql = $this->db->query($sql);
10859 if ($this->db->num_rows($resql) > 0) {
10860 $obj = $this->db->fetch_object($resql);
10861 $out .=
'<script nonce="' .
getNonce() .
'">
10863 $("select[name=' . $target .
']").on("change", function() {
10864 var current_val = $(this).val();
10865 if (current_val == ' . $obj->id .
') {';
10866 if (!empty($default_selected) || !empty($selected)) {
10867 $out .=
'$("select[name=' . $htmlname .
']").val("' . ($default_selected > 0 ? $default_selected : $selected) .
'");';
10871 $("select[name=' . $htmlname .
']").change();
10875 $("select[name=' . $htmlname .
']").change(function() {
10877 if ($("select[name=' . $target .
']").val() == ' . $obj->id .
') {
10878 // get price of kilometer to fill the unit price
10882 data: { fk_c_exp_tax_cat: $(this).val(), token: \'' .
currentToken() .
'\' },
10883 url:
"' . (DOL_URL_ROOT . '/expensereport/ajax/ajaxik.php?' . implode('&', $params)) . '",
10884 }).done(
function( data, textStatus, jqXHR ) {
10886 if (typeof data.up !=
"undefined") {
10887 $(
"input[name=value_unit]").val(data.up);
10888 $(
"select[name=' . $htmlname . ']").attr(
"title", data.title);
10890 $(
"input[name=value_unit]").val(
"");
10891 $(
"select[name=' . $htmlname . ']").attr(
"title",
"");
10902 dol_print_error($this->db);
10916 public function selectExpenseRanges($selected = '
', $htmlname = 'fk_range
', $useempty = 0)
10918 global $conf, $langs;
10921 $sql = "SELECT rowid, range_ik FROM " . $this->db->prefix() . "c_exp_tax_range";
10922 $sql .= " WHERE entity = " . $conf->entity . " AND active = 1";
10924 $resql = $this->db->query($sql);
10926 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
10928 $out .= '<option value=
"0"></option>
';
10931 while ($obj = $this->db->fetch_object($resql)) {
10932 $out .= '<option
' . ($selected == $obj->rowid ? 'selected=
"selected"' : '') . ' value=
"' . $obj->rowid . '">
' . price($obj->range_ik, 0, $langs, 1, 0) . '</option>
';
10934 $out .= '</select>
';
10936 dol_print_error($this->db);
10952 public function selectExpense($selected = '
', $htmlname = 'fk_c_type_fees
', $useempty = 0, $allchoice = 1, $useid = 0)
10957 $sql = "SELECT id, code, label";
10958 $sql .= " FROM ".$this->db->prefix()."c_type_fees";
10959 $sql .= " WHERE active = 1";
10961 $resql = $this->db->query($sql);
10963 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
10965 $out .= '<option value=
"0"></option>
';
10968 $out .= '<option value=
"-1">
' . $langs->trans('AllExpenseReport
') . '</option>
';
10976 while ($obj = $this->db->fetch_object($resql)) {
10977 $key = $langs->trans($obj->code);
10978 $out .= '<option
' . ($selected == $obj->{$field} ? 'selected=
"selected"' : '') . ' value=
"' . $obj->{$field} . '">
' . ($key != $obj->code ? $key : $obj->label) . '</option>
';
10980 $out .= '</select>
';
10982 $out .= ajax_combobox('select_
'.$htmlname);
10984 dol_print_error($this->db);
11008 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)
11010 global $user, $conf, $langs;
11012 require_once DOL_DOCUMENT_ROOT . '/projet/
class/project.class.php
';
11014 if (is_null($usertofilter)) {
11015 $usertofilter = $user;
11020 $hideunselectables = false;
11021 if (getDolGlobalString('PROJECT_HIDE_UNSELECTABLES
')) {
11022 $hideunselectables = true;
11025 if (empty($projectsListId)) {
11026 if (!$usertofilter->hasRight('projet
', 'all
', 'lire
')) {
11027 $projectstatic = new Project($this->db);
11028 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1);
11032 // Search all projects
11033 $sql = "SELECT f.rowid, f.ref as fref, 'nolabel
' as flabel, p.rowid as pid, f.ref,
11034 p.title, p.fk_soc, p.fk_statut, p.public,";
11035 $sql .= ' s.nom as
name';
11036 $sql .= ' FROM
' . $this->db->prefix() . 'projet as p
';
11037 $sql .= ' LEFT JOIN
' . $this->db->prefix() . 'societe as s ON s.rowid = p.fk_soc,
';
11038 $sql .= ' ' . $this->db->prefix() . 'facture as f
';
11039 $sql .= " WHERE p.entity IN (" . getEntity('project
') . ")";
11040 $sql .= " AND f.fk_projet = p.rowid AND f.fk_statut=0"; //Brouillons seulement
11041 //if ($projectsListId) $sql.= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")";
11042 //if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
11043 //if ($socid > 0) $sql.= " AND (p.fk_soc=".((int) $socid)." OR p.fk_soc IS NULL)";
11044 $sql .= " ORDER BY p.ref, f.ref ASC";
11046 $resql = $this->db->query($sql);
11048 // Use select2 selector
11049 if (!empty($conf->use_javascript_ajax)) {
11050 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
11051 $comboenhancement = ajax_combobox($htmlname, array(), 0, $forcefocus);
11052 $out .= $comboenhancement;
11053 $morecss = 'minwidth200imp maxwidth500
';
11056 if (empty($option_only)) {
11057 $out .= '<select
class=
"valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled=
"disabled"' : '') . ' id=
"' . $htmlname . '" name=
"' . $htmlname . '">
';
11059 if (!empty($show_empty)) {
11060 $out .= '<option value=
"0" class=
"optiongrey">
';
11061 if (!is_numeric($show_empty)) {
11062 $out .= $show_empty;
11066 $out .= '</option>
';
11068 $num = $this->db->num_rows($resql);
11071 while ($i < $num) {
11072 $obj = $this->db->fetch_object($resql);
11073 // 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.
11074 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$usertofilter->hasRight('societe
', 'lire
')) {
11077 if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) {
11084 if ($showproject == 'all
') {
11085 $labeltoshow .= dol_trunc($obj->ref, 18); // Invoice ref
11087 $labeltoshow .= ' -
' . $obj->name; // Soc name
11091 if ($obj->fk_statut == Project::STATUS_DRAFT) {
11093 $labeltoshow .= ' -
' . $langs->trans("Draft");
11094 } elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
11095 if ($discard_closed == 2) {
11098 $labeltoshow .= ' -
' . $langs->trans("Closed");
11099 } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
11101 $labeltoshow .= ' -
' . $langs->trans("LinkedToAnotherCompany");
11105 if (!empty($selected) && $selected == $obj->rowid) {
11106 $out .= '<option value=
"' . $obj->rowid . '" selected
';
11107 //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected
if disabled
11108 $out .=
'>' . $labeltoshow .
'</option>';
11110 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
11113 $resultat =
'<option value="' . $obj->rowid .
'"';
11115 $resultat .=
' disabled';
11120 $resultat .= $labeltoshow;
11121 $resultat .=
'</option>';
11129 if (empty($option_only)) {
11130 $out .=
'</select>';
11133 $this->db->free($resql);
11155 public function selectInvoiceRec($selected =
'', $htmlname =
'facrecid', $maxlength = 24, $option_only = 0, $show_empty =
'1', $forcefocus = 0, $disabled = 0, $morecss =
'maxwidth500')
11157 global
$conf, $langs;
11163 $sql =
'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc';
11165 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'facture_rec as f';
11166 $sql .=
" WHERE f.entity IN (" .
getEntity(
'invoice') .
")";
11167 $sql .=
" ORDER BY f.titre ASC";
11169 $resql = $this->db->query($sql);
11172 if (!empty(
$conf->use_javascript_ajax)) {
11173 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
11174 $comboenhancement =
ajax_combobox($htmlname, array(), 0, $forcefocus);
11175 $out .= $comboenhancement;
11176 $morecss =
'minwidth200imp maxwidth500';
11179 if (empty($option_only)) {
11180 $out .=
'<select class="valignmiddle flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' id="' . $htmlname .
'" name="' . $htmlname .
'">';
11182 if (!empty($show_empty)) {
11183 $out .=
'<option value="0" class="optiongrey">';
11184 if (!is_numeric($show_empty)) {
11185 $out .= $show_empty;
11189 $out .=
'</option>';
11191 $num = $this->db->num_rows($resql);
11193 while ($obj = $this->db->fetch_object($resql)) {
11194 $labeltoshow =
dol_trunc($obj->title, 18);
11197 if (!empty($obj->suspended)) {
11199 $labeltoshow .=
' - ' . $langs->trans(
"Closed");
11203 if (!empty($selected) && $selected == $obj->rowid) {
11204 $out .=
'<option value="' . $obj->rowid .
'" selected';
11206 $out .=
'>' . $labeltoshow .
'</option>';
11208 if ($disabled && ($selected != $obj->rowid)) {
11211 $resultat =
'<option value="' . $obj->rowid .
'"';
11213 $resultat .=
' disabled';
11216 $resultat .= $labeltoshow;
11217 $resultat .=
'</option>';
11223 if (empty($option_only)) {
11224 $out .=
'</select>';
11229 $this->db->free($resql);
11232 $this->errors[] = $this->db->lasterror;
11247 public function searchComponent($arrayofcriterias, $search_component_params, $arrayofinputfieldsalreadyoutput = array(), $search_component_params_hidden =
'', $arrayoffiltercriterias = array())
11250 global $langs, $form;
11252 require_once DOL_DOCUMENT_ROOT.
"/core/class/html.formother.class.php";
11255 if ($search_component_params_hidden !=
'' && !preg_match(
'/^\(.*\)$/', $search_component_params_hidden)) {
11256 $search_component_params_hidden =
'(' . $search_component_params_hidden .
')';
11259 $ret =
'<!-- searchComponent -->';
11261 $ret .=
'<div class="divadvancedsearchfieldcomp centpercent inline-block">';
11262 $ret .=
'<a href="#" class="dropdownsearch-toggle unsetcolor">';
11263 $ret .=
'<span class="fas fa-filter linkobject boxfilter paddingright pictofixedwidth" title="' .
dol_escape_htmltag($langs->trans(
"Filters")) .
'" id="idsubimgproductdistribution"></span>';
11266 $ret .=
'<div class="divadvancedsearchfieldcompinput inline-block minwidth500 maxwidth300onsmartphone">';
11269 $ret .=
'<div id="divsearch_component_params" name="divsearch_component_params" class="noborderbottom search_component_params inline-block valignmiddle">';
11271 if ($search_component_params_hidden) {
11279 foreach ($arrayofandtags as $tmpkey => $tmpval) {
11280 $errormessage =
'';
11282 if ($errormessage) {
11283 $this->error =
'ERROR in parsing search string: '.$errormessage;
11286 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
11289 $ret .=
'<span class="marginleftonlyshort valignmiddle tagsearch" data-ufilterid="'.($tmpkey + 1).
'" data-ufilter="'.
dol_escape_htmltag($tmpval).
'">';
11290 $ret .=
'<span class="tagsearchdelete select2-selection__choice__remove" data-ufilterid="'.($tmpkey + 1).
'">x</span> ';
11302 $show_search_component_params_hidden = 1;
11303 if ($show_search_component_params_hidden) {
11304 $ret .=
'<input type="hidden" name="show_search_component_params_hidden" value="1">';
11306 $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%')) -->";
11307 $ret .=
'<input type="hidden" id="search_component_params_hidden" name="search_component_params_hidden" value="' .
dol_escape_htmltag($search_component_params_hidden) .
'">';
11312 foreach ($arrayofcriterias as $criteria) {
11313 foreach ($criteria as $criteriafamilykey => $criteriafamilyval) {
11314 if (in_array(
'search_' . $criteriafamilykey, $arrayofinputfieldsalreadyoutput)) {
11317 if (in_array($criteriafamilykey, array(
'rowid',
'ref_ext',
'entity',
'extraparams'))) {
11320 if (in_array($criteriafamilyval[
'type'], array(
'date',
'datetime',
'timestamp'))) {
11321 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_start">';
11322 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startyear">';
11323 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startmonth">';
11324 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startday">';
11325 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_end">';
11326 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endyear">';
11327 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endmonth">';
11328 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endday">';
11330 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'">';
11337 $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";
11338 $ret .=
'<input type="text" placeholder="' . $langs->trans(
"Filters") .
'" id="search_component_params_input" name="search_component_params_input" class="noborderbottom search_component_input" value="">';
11344 jQuery(".tagsearchdelete").click(function(e) {
11345 var filterid = $(this).parents().attr("data-ufilterid");
11346 console.log("We click to delete the criteria nb "+filterid);
11348 // Regenerate the search_component_params_hidden with all data-ufilter except the one to delete, and post the page
11349 var newparamstring = \'\';
11350 $(\'.tagsearch\').each(function(index, element) {
11351 tmpfilterid = $(this).attr("data-ufilterid");
11352 if (tmpfilterid != filterid) {
11353 // We keep this criteria
11354 if (newparamstring == \'\') {
11355 newparamstring = $(this).attr("data-ufilter");
11357 newparamstring = newparamstring + \' AND \' + $(this).attr("data-ufilter");
11361 console.log("newparamstring = "+newparamstring);
11363 jQuery("#search_component_params_hidden").val(newparamstring);
11365 // We repost the form
11366 $(this).closest(\'form\').submit();
11369 jQuery("#search_component_params_input").keydown(function(e) {
11370 console.log("We press a key on the filter field that is "+jQuery("#search_component_params_input").val());
11371 console.log(e.which);
11372 if (jQuery("#search_component_params_input").val() == "" && e.which == 8) {
11373 /* We click on back when the input field is already empty */
11374 event.preventDefault();
11375 jQuery("#divsearch_component_params .tagsearch").last().remove();
11376 /* Regenerate content of search_component_params_hidden from remaining .tagsearch */
11378 jQuery("#divsearch_component_params .tagsearch").each(function( index ) {
11382 s = s + $(this).attr("data-ufilter");
11384 console.log("New value for search_component_params_hidden = "+s);
11385 jQuery("#search_component_params_hidden").val(s);
11393 $arrayoffiltercriterias_json = json_encode($arrayoffiltercriterias);
11395 var arrayoffiltercriterias = ' . $arrayoffiltercriterias_json .
';
11399 $arrayoffilterfieldslabel = array();
11400 foreach ($arrayoffiltercriterias as $key => $val) {
11401 $arrayoffilterfieldslabel[$key][
'label'] = $val[
'label'];
11402 $arrayoffilterfieldslabel[$key][
'data-type'] = $val[
'type'];
11406 $ret .=
'<div class="search-component-assistance">';
11409 $ret .=
'<p class="assistance-title">' .
img_picto(
'',
'filter') .
' ' . $langs->trans(
'FilterAssistance') .
' </p>';
11411 $ret .=
'<p class="assistance-errors error" style="display:none">' . $langs->trans(
'AllFieldsRequired') .
' </p>';
11413 $ret .=
'<div class="operand">';
11414 $ret .= $form->selectarray(
'search_filter_field', $arrayoffilterfieldslabel,
'', $langs->trans(
"Fields"), 0, 0,
'', 0, 0, 0,
'',
'width200 combolargeelem', 1);
11417 $ret .=
'<span class="separator"></span>';
11420 $ret .=
'<div class="operator">';
11421 $ret .=
'<select class="operator-selector width150" id="operator-selector"">';
11422 $ret .=
'</select>';
11423 $ret .=
'<script>$(document).ready(function() {';
11424 $ret .=
' $(".operator-selector").select2({';
11425 $ret .=
' placeholder: \'' .
dol_escape_js($langs->trans(
'Operator')) .
'\'';
11427 $ret .=
'});</script>';
11430 $ret .=
'<span class="separator"></span>';
11432 $ret .=
'<div class="value">';
11434 $ret .=
'<input type="text" class="flat width100 value-input" placeholder="' .
dolPrintHTML($langs->trans(
'Value')) .
'">';
11438 $ret .=
'<span class="date-one" style="display:none">';
11439 $ret .= $form->selectDate(($dateOne ? $dateOne : -1),
'dateone', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'');
11443 $ret .=
'<select class="value-selector width150" id="value-selector" style="display:none">';
11444 $ret .=
'</select>';
11446 $(document).ready(function() {
11447 $("#value-selector").select2({
11448 placeholder: "' .
dol_escape_js($langs->trans(
'Value')) .
'"
11450 $("#value-selector").hide();
11451 $("#value-selector").next(".select2-container").hide();
11457 $ret .=
'<div class="btn-div">';
11458 $ret .=
'<button class="button buttongen button-save add-filter-btn" type="button">' . $langs->trans(
"addToFilter") .
'</button>';
11469 $(document).ready(function() {
11470 $("#search_component_params_input").on("click", function() {
11471 const inputPosition = $(this).offset();
11472 const inputHeight = $(this).outerHeight();
11473 $(".search-component-assistance").css({
11474 top: inputPosition.top + inputHeight + 5 + "px",
11475 left: $("#divsearch_component_params").position().left
11476 }).slideToggle(200);
11478 $(document).on("click", function(e) {
11479 if (!$(e.target).closest("#search_component_params_input, .search-component-assistance, #ui-datepicker-div").length) {
11480 $(".search-component-assistance").hide();
11487 $(document).ready(function() {
11488 $(".search_filter_field").on("change", function() {
11490 const selectedField = $(this).find(":selected");
11491 let fieldType = selectedField.data("type");
11492 const selectedFieldValue = selectedField.val();
11494 // If the selected field has an array of values then ask toshow the value selector instead of the value input
11495 if (arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"] !== undefined) {
11496 fieldType = "select";
11499 // If the selected field may be null then ask to append the "IsDefined" and "IsNotDefined" operators
11500 if (arrayoffiltercriterias[selectedFieldValue]["maybenull"] !== undefined) {
11503 const operators = getOperatorsForFieldType(fieldType, maybenull);
11504 const operatorSelector = $(".operator-selector");
11506 // Clear existing options
11507 operatorSelector.empty();
11509 // Populate operators
11510 Object.entries(operators).forEach(function([operator, label]) {
11511 operatorSelector.append("<option value=\'" + operator + "\'>" + label + "</option>");
11514 operatorSelector.trigger("change.select2");
11516 // Clear and hide all input elements initially
11517 $(".value-input, .dateone, .datemonth, .dateyear").val("").hide();
11518 $("#datemonth, #dateyear").val(null).trigger("change.select2");
11519 $("#dateone").datepicker("setDate", null);
11520 $(".date-one, .date-month, .date-year").hide();
11521 $("#value-selector").val("").hide();
11522 $("#value-selector").next(".select2-container").hide();
11523 $("#value-selector").val(null).trigger("change.select2");
11525 if (fieldType === "date" || fieldType === "datetime" || fieldType === "timestamp") {
11526 $(".date-one").show();
11527 } else if (arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"] !== undefined) {
11528 var arrayofkeyval = arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"];
11529 var valueSelector = $("#value-selector");
11530 valueSelector.empty();
11531 Object.entries(arrayofkeyval).forEach(function([key, val]) {
11532 valueSelector.append("<option value=\'" + key + "\'>" + val + "</option>");
11534 valueSelector.trigger("change.select2");
11536 $("#value-selector").show();
11537 $("#value-selector").next(".select2-container").show();
11539 $(".value-input").show();
11543 $("#operator-selector").on("change", function() {
11544 const selectedOperator = $(this).find(":selected").val();
11545 if (selectedOperator === "IsDefined" || selectedOperator === "IsNotDefined") {
11546 // Disable all value input elements
11547 $(".value-input, .dateone, .datemonth, .dateyear").val("").prop("disabled", true);
11548 $("#datemonth, #dateyear").val(null).trigger("change.select2");
11549 $("#dateone").datepicker("setDate", null).datepicker("option", "disabled", true);
11550 $(".date-one, .date-month, .date-year").prop("disabled", true);
11551 $("#value-selector").val("").prop("disabled", true);
11552 $("#value-selector").val(null).trigger("change.select2");
11554 // Enable all value input elements
11555 $(".value-input, .dateone, .datemonth, .dateyear").prop("disabled", false);
11556 $(".date-one, .date-month, .date-year").prop("disabled", false);
11557 $("#dateone").datepicker("option", "disabled", false);
11558 $("#value-selector").prop("disabled", false);
11562 $(".add-filter-btn").on("click", function(event) {
11563 event.preventDefault();
11565 const field = $(".search_filter_field").val();
11566 const operator = $(".operator-selector").val();
11567 let value = $(".value-input").val();
11568 const fieldType = $(".search_filter_field").find(":selected").data("type");
11570 if (["date", "datetime", "timestamp"].includes(fieldType)) {
11571 const parsedDate = new Date($("#dateone").val());
11572 if (!isNaN(parsedDate)) {
11573 const year = parsedDate.getFullYear();
11574 const month = String(parsedDate.getMonth() + 1).padStart(2, "0");
11575 const day = String(parsedDate.getDate()).padStart(2, "0");
11576 value = `${year}-${month}-${day}`;
11580 // If the selected field has an array of values then take the selected value
11581 if (arrayoffiltercriterias[field]["arrayofkeyval"] !== undefined) {
11582 value = $("#value-selector").val();
11585 // If the operator is "IsDefined" or "IsNotDefined" then set the value to 1 (it will not be used)
11586 if (operator === "IsDefined" || operator === "IsNotDefined") {
11590 const filterString = generateFilterString(field, operator, value, fieldType);
11593 if (filterString !== "" && field !== "" && operator !== "" && value !== "") {
11594 $("#search_component_params_input").val($("#search_component_params_input").val() + " " + filterString);
11595 $("#search_component_params_input").closest("form").submit();
11597 $(".assistance-errors").show();
11616 public function selectModelMail($prefix, $modelType =
'', $default = 0, $addjscombo = 0, $selected =
'')
11618 global $langs, $user;
11622 $TModels = array();
11624 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
11625 $formmail =
new FormMail($this->db);
11626 $result = $formmail->fetchAllEMailTemplate($modelType, $user, $langs);
11629 $TModels[0] = $langs->trans(
'DefaultMailModel');
11632 foreach ($formmail->lines_model as $model) {
11633 $TModels[$model->id] = $model->label;
11637 $retstring .=
'<select class="flat" id="select_' . $prefix .
'model_mail" name="' . $prefix .
'model_mail">';
11639 foreach ($TModels as $id_model => $label_model) {
11640 $retstring .=
'<option value="' . $id_model .
'"';
11641 if (!empty($selected) && $selected == $id_model) {
11642 $retstring .=
"selected";
11644 $retstring .=
">" . $label_model .
"</option>";
11647 $retstring .=
"</select>";
11650 $retstring .=
ajax_combobox(
'select_' . $prefix .
'model_mail');
11667 public function buttonsSaveCancel($save_label =
'Save', $cancel_label =
'Cancel', $morebuttons = array(), $withoutdiv =
false, $morecss =
'', $dol_openinpopup =
'')
11671 $buttons = array();
11675 'label_key' => $save_label,
11678 if ($save_label ==
'Create' || $save_label ==
'Add') {
11679 $save[
'name'] =
'add';
11680 } elseif ($save_label ==
'Modify') {
11681 $save[
'name'] =
'edit';
11685 'name' =>
'cancel',
11686 'label_key' =>
'Cancel',
11689 !empty($save_label) ? $buttons[] = $save :
'';
11691 if (!empty($morebuttons)) {
11692 $buttons[] = $morebuttons;
11695 !empty($cancel_label) ? $buttons[] = $cancel :
'';
11697 $retstring = $withoutdiv ?
'' :
'<div class="center">';
11699 foreach ($buttons as $button) {
11700 $addclass = empty($button[
'addclass']) ?
'' : $button[
'addclass'];
11701 $retstring .=
'<input type="submit" class="button button-' . $button[
'name'] . ($morecss ?
' ' . $morecss :
'') .
' ' . $addclass .
'" name="' . $button[
'name'] .
'" value="' .
dol_escape_htmltag($langs->trans($button[
'label_key'])) .
'">';
11703 $retstring .= $withoutdiv ?
'' :
'</div>';
11705 if ($dol_openinpopup) {
11706 $retstring .=
'<!-- buttons are shown into a $dol_openinpopup=' .
dol_escape_htmltag($dol_openinpopup) .
' context, so we enable the close of dialog on cancel -->' .
"\n";
11707 $retstring .=
'<script nonce="' .
getNonce() .
'">';
11708 $retstring .=
'jQuery(".button-cancel").click(function(e) {
11709 e.preventDefault(); console.log(\'We click on cancel in iframe popup ' .
dol_escape_js($dol_openinpopup) .
'\');
11710 window.parent.jQuery(\
'#idfordialog' .
dol_escape_js($dol_openinpopup) .
'\').dialog(\
'close\');
11712 $retstring .=
'</script>';
11731 $num = count($this->cache_invoice_subtype);
11738 $sql =
"SELECT rowid, code, label as label";
11739 $sql .=
" FROM " . MAIN_DB_PREFIX .
'c_invoice_subtype';
11740 $sql .=
" WHERE active = 1";
11742 $resql = $this->db->query($sql);
11744 $num = $this->db->num_rows($resql);
11746 while ($i < $num) {
11747 $obj = $this->db->fetch_object($resql);
11750 $label = ($langs->trans(
"InvoiceSubtype" . $obj->rowid) !=
"InvoiceSubtype" . $obj->rowid) ? $langs->trans(
"InvoiceSubtype" . $obj->rowid) : (($obj->label !=
'-') ? $obj->label :
'');
11751 $this->cache_invoice_subtype[$obj->rowid][
'rowid'] = $obj->rowid;
11752 $this->cache_invoice_subtype[$obj->rowid][
'code'] = $obj->code;
11753 $this->cache_invoice_subtype[$obj->rowid][
'label'] = $label;
11757 $this->cache_invoice_subtype =
dol_sort_array($this->cache_invoice_subtype,
'code',
'asc', 0, 0, 1);
11779 global $langs, $user;
11782 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
11784 $this->load_cache_invoice_subtype();
11786 $out .=
'<select id="' . $htmlname .
'" class="flat selectsubtype' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
11788 $out .=
'<option value="0"> </option>';
11791 foreach ($this->cache_invoice_subtype as $rowid => $subtype) {
11792 $label = $subtype[
'label'];
11793 $out .=
'<option value="' . $subtype[
'rowid'] .
'"';
11794 if ($selected == $subtype[
'rowid']) {
11795 $out .=
' selected="selected"';
11799 $out .=
'</option>';
11802 $out .=
'</select>';
11803 if ($user->admin && empty($noinfoadmin)) {
11804 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLength=2, $autoselect=0, $ajaxoptions=array(), $moreparams='')
Generic function that return javascript to add to transform a common input text or select field into ...
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
ajax_multiautocompleter($htmlname, $fields, $url, $option='', $minLength=2, $autoselect=0)
Generic function that return javascript to add to a page to transform a common input text field into ...
ajax_event($htmlname, $events)
Add event management script.
Class to manage bank accounts.
Class to manage categories.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Class to manage bank accounts description of third parties.
Class to manage a WYSIWYG editor.
const STATUS_OPEN_INTERNAL
Warehouse open and only operations for stock transfers/corrections allowed (not for customer shipping...
const STATUS_OPEN_ALL
Warehouse open and any operations are allowed (customer shipping, supplier dispatch,...
const STATUS_CLOSED
Warehouse closed, inactive.
Class to manage invoices.
Class to 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.
Class toolbox to validate values.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
currency_name($code_iso, $withcode=0, $outputlangs=null)
Return label of currency or code+label.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
getServerTimeZoneInt($refgmtdate='now')
Return server timezone int.
removeGlobalParenthesis($string)
Remove first and last parenthesis but only if first is the opening and last the closing of the same g...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dolForgeExplodeAnd($sqlfilters)
Explode an universal search string with AND parts.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
dolPrintHTML($s, $allowiframe=0)
Return a string (that can be on several lines) ready to be output on a HTML page.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
currentToken()
Return the value of token currently saved into session with name 'token'.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_print_url($url, $target='_blank', $max=32, $withpicto=0, $morecss='')
Show Url link.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
dol_string_neverthesehtmltags($stringtoclean, $disallowed_tags=array('textarea'), $cleanalsosomestyles=0)
Clean a string from some undesirable HTML tags.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
dolPrintHTMLForAttribute($s, $escapeonlyhtmltags=0, $allowothertags=array())
Return a string ready to be output into an HTML attribute (alt, title, data-html, ....
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
getAdvancedPreviewUrl($modulepart, $relativepath, $alldata=0, $param='')
Return URL we can use for advanced preview links.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dolIsAllowedForPreview($file)
Return if a file is qualified for preview.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getNonce()
Return a random string to be used as a nonce value for js.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox=0, $check='restricthtml')
Sanitize a HTML to remove js, dangerous content and external link.
dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array(), $allowlink=0, $allowscript=0, $allowstyle=0, $allowphp=0)
Clean a string to keep only desirable HTML tags.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
treeview li table
No Email.
ui state ui widget content ui state ui widget header ui state a ui button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
testSqlAndScriptInject($val, $type)
Security: WAF layer for SQL Injection and XSS Injection (scripts) protection (Filters on GET,...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
measuringUnitString($unitid, $measuring_style='', $unitscale='', $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.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.
getMaxFileSizeArray()
Return the max allowed for file upload.
dolDecrypt($chain, $key='')
Decode a string with a symmetric encryption.