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');
440 if (!is_array($extralanguages->attributes[
$object->element]) || empty($extralanguages->attributes[
$object->element][$fieldname])) {
444 $result .=
'<!-- Widget for translation -->' .
"\n";
445 $result .=
'<div class="inline-block paddingleft image-' .
$object->element .
'-' . $fieldname .
'">';
446 $s =
img_picto($langs->trans(
"ShowOtherLanguages"),
'language',
'', 0, 0, 0,
'',
'fa-15 editfieldlang');
450 $result .=
'<div class="inline-block hidden field-' .
$object->element .
'-' . $fieldname .
'">';
452 $resultforextrlang =
'';
453 foreach ($arrayoflangcode as $langcode) {
454 $valuetoshow = GETPOSTISSET(
'field-' .
$object->element .
"-" . $fieldname .
"-" . $langcode) ?
GETPOST(
'field-' .
$object->element .
'-' . $fieldname .
"-" . $langcode, $check) :
'';
455 if (empty($valuetoshow)) {
456 $object->fetchValuesForExtraLanguages();
458 $valuetoshow =
$object->array_languages[$fieldname][$langcode];
462 $resultforextrlang .= $s;
465 if ($typeofdata ==
'textarea') {
466 $resultforextrlang .=
'<textarea name="field-' .
$object->element .
"-" . $fieldname .
"-" . $langcode .
'" id="' . $fieldname .
"-" . $langcode .
'" class="' . $morecss .
'" rows="' . ROWS_2 .
'" wrap="soft">';
467 $resultforextrlang .= $valuetoshow;
468 $resultforextrlang .=
'</textarea>';
470 $resultforextrlang .=
'<input type="text" class="inputfieldforlang ' . ($morecss ?
' ' . $morecss :
'') .
'" name="field-' .
$object->element .
'-' . $fieldname .
'-' . $langcode .
'" value="' . $valuetoshow .
'">';
473 $result .= $resultforextrlang;
476 $result .=
'<script nonce="' .
getNonce() .
'">$(".image-' .
$object->element .
'-' . $fieldname .
'").click(function() { console.log("Toggle lang widget"); jQuery(".field-' .
$object->element .
'-' . $fieldname .
'").toggle(); });</script>';
495 protected function editInPlace(
$object, $value, $htmlname, $condition, $inputType =
'textarea', $editvalue =
null, $extObject =
null, $custommsg =
null)
500 if (preg_match(
'/^text/', $inputType)) {
502 } elseif (preg_match(
'/^numeric/', $inputType)) {
503 $value =
price($value);
504 } elseif ($inputType ==
'day' || $inputType ==
'datepicker') {
510 $table_element =
false;
514 $ext_element =
false;
515 $button_only =
false;
522 $table_element =
$object->table_element;
526 if (is_object($extObject)) {
527 $ext_element = $extObject->element;
530 if (preg_match(
'/^(string|email|numeric)/', $inputType)) {
531 $tmp = explode(
':', $inputType);
532 $inputType = $tmp[0];
533 if (!empty($tmp[1])) {
534 $inputOption = $tmp[1];
536 if (!empty($tmp[2])) {
537 $savemethod = $tmp[2];
539 $out .=
'<input id="width_' . $htmlname .
'" value="' . $inputOption .
'" type="hidden"/>' .
"\n";
540 } elseif ((preg_match(
'/^day$/', $inputType)) || (preg_match(
'/^datepicker/', $inputType)) || (preg_match(
'/^datehourpicker/', $inputType))) {
541 $tmp = explode(
':', $inputType);
542 $inputType = $tmp[0];
543 if (!empty($tmp[1])) {
544 $inputOption = $tmp[1];
546 if (!empty($tmp[2])) {
547 $savemethod = $tmp[2];
550 $out .=
'<input id="timestamp" type="hidden"/>' .
"\n";
551 } elseif (preg_match(
'/^(select|autocomplete)/', $inputType)) {
552 $tmp = explode(
':', $inputType);
553 $inputType = $tmp[0];
554 $loadmethod = $tmp[1];
555 if (!empty($tmp[2])) {
556 $savemethod = $tmp[2];
558 if (!empty($tmp[3])) {
561 } elseif (preg_match(
'/^textarea/', $inputType)) {
562 $tmp = explode(
':', $inputType);
563 $inputType = $tmp[0];
564 $rows = (empty($tmp[1]) ?
'8' : $tmp[1]);
565 $cols = (empty($tmp[2]) ?
'80' : $tmp[2]);
566 } elseif (preg_match(
'/^ckeditor/', $inputType)) {
567 $tmp = explode(
':', $inputType);
568 $inputType = $tmp[0];
570 if (!empty($tmp[2])) {
573 if (!empty($tmp[3])) {
576 if (!empty($tmp[4])) {
577 $savemethod = $tmp[4];
580 if (isModEnabled(
'fckeditor')) {
581 $out .=
'<input id="ckeditor_toolbar" value="' . $toolbar .
'" type="hidden"/>' .
"\n";
583 $inputType =
'textarea';
587 $out .=
'<input id="element_' . $htmlname .
'" value="' . $element .
'" type="hidden"/>' .
"\n";
588 $out .=
'<input id="table_element_' . $htmlname .
'" value="' . $table_element .
'" type="hidden"/>' .
"\n";
589 $out .=
'<input id="fk_element_' . $htmlname .
'" value="' . $fk_element .
'" type="hidden"/>' .
"\n";
590 $out .=
'<input id="loadmethod_' . $htmlname .
'" value="' . $loadmethod .
'" type="hidden"/>' .
"\n";
591 if (!empty($savemethod)) {
592 $out .=
'<input id="savemethod_' . $htmlname .
'" value="' . $savemethod .
'" type="hidden"/>' .
"\n";
594 if (!empty($ext_element)) {
595 $out .=
'<input id="ext_element_' . $htmlname .
'" value="' . $ext_element .
'" type="hidden"/>' .
"\n";
597 if (!empty($custommsg)) {
598 if (is_array($custommsg)) {
599 if (!empty($custommsg[
'success'])) {
600 $out .=
'<input id="successmsg_' . $htmlname .
'" value="' . $custommsg[
'success'] .
'" type="hidden"/>' .
"\n";
602 if (!empty($custommsg[
'error'])) {
603 $out .=
'<input id="errormsg_' . $htmlname .
'" value="' . $custommsg[
'error'] .
'" type="hidden"/>' .
"\n";
606 $out .=
'<input id="successmsg_' . $htmlname .
'" value="' . $custommsg .
'" type="hidden"/>' .
"\n";
609 if ($inputType ==
'textarea') {
610 $out .=
'<input id="textarea_' . $htmlname .
'_rows" value="' . $rows .
'" type="hidden"/>' .
"\n";
611 $out .=
'<input id="textarea_' . $htmlname .
'_cols" value="' . $cols .
'" type="hidden"/>' .
"\n";
613 $out .=
'<span id="viewval_' . $htmlname .
'" class="viewval_' . $inputType . ($button_only ?
' inactive' :
' active') .
'">' . $value .
'</span>' .
"\n";
614 $out .=
'<span id="editval_' . $htmlname .
'" class="editval_' . $inputType . ($button_only ?
' inactive' :
' active') .
' hideobject">' . (!empty($editvalue) ? $editvalue : $value) .
'</span>' .
"\n";
640 public function textwithtooltip($text, $htmltext, $tooltipon = 1, $direction = 0, $img =
'', $extracss =
'', $notabs = 3, $incbefore =
'', $noencodehtmltext = 0, $tooltiptrigger =
'', $forcenowrap = 0)
643 $text = $incbefore . $text;
648 $direction = (int) $direction;
658 $htmltext = str_replace(array(
"\r",
"\n"),
'', $htmltext);
661 if ($direction < 0) {
662 $extracss = ($extracss ? $extracss :
'') . ($notabs != 3 ?
' inline-block' :
'');
663 $extrastyle =
'padding: 0px; padding-left: 2px;';
665 if ($direction > 0) {
666 $extracss = ($extracss ? $extracss :
'') . ($notabs != 3 ?
' inline-block' :
'');
667 $extrastyle =
'padding: 0px; padding-right: 2px;';
670 $classfortooltip =
'classfortooltip';
675 if ($tooltiptrigger ==
'') {
676 $htmltext = str_replace(
'"',
'"', $htmltext);
678 $classfortooltip =
'classfortooltiponclick';
679 $textfordialog .=
'<div style="display: none;" id="idfortooltiponclick_' . $tooltiptrigger .
'" class="classfortooltiponclicktext">' . $htmltext .
'</div>';
681 if ($tooltipon == 2 || $tooltipon == 3) {
682 $paramfortooltipimg =
' class="' . $classfortooltip . ($notabs != 3 ?
' inline-block' :
'') . ($extracss ?
' ' . $extracss :
'') .
'" style="padding: 0px;' . ($extrastyle ?
' ' . $extrastyle :
'') .
'"';
683 if ($tooltiptrigger ==
'') {
684 $paramfortooltipimg .=
' title="' . ($noencodehtmltext ? $htmltext :
dol_escape_htmltag($htmltext, 1)) .
'"';
686 $paramfortooltipimg .=
' dolid="' . $tooltiptrigger .
'"';
689 $paramfortooltipimg = ($extracss ?
' class="' . $extracss .
'"' :
'') . ($extrastyle ?
' style="' . $extrastyle .
'"' :
'');
691 if ($tooltipon == 1 || $tooltipon == 3) {
692 $paramfortooltiptd =
' class="' . ($tooltipon == 3 ?
'cursorpointer ' :
'') . $classfortooltip .
' inline-block' . ($extracss ?
' ' . $extracss :
'') .
'" style="padding: 0px;' . ($extrastyle ?
' ' . $extrastyle :
'') .
'" ';
693 if ($tooltiptrigger ==
'') {
694 $paramfortooltiptd .=
' title="' . ($noencodehtmltext ? $htmltext :
dol_escape_htmltag($htmltext, 1)) .
'"';
696 $paramfortooltiptd .=
' dolid="' . $tooltiptrigger .
'"';
699 $paramfortooltiptd = ($extracss ?
' class="' . $extracss .
'"' :
'') . ($extrastyle ?
' style="' . $extrastyle .
'"' :
'');
701 if (empty($notabs)) {
702 $s .=
'<table class="nobordernopadding"><tr style="height: auto;">';
703 } elseif ($notabs == 2) {
704 $s .=
'<div class="inline-block' . ($forcenowrap ?
' nowrap' :
'') .
'">';
707 if ($direction < 0) {
708 $s .=
'<' . $tag . $paramfortooltipimg;
710 $s .=
' class="valigntop" width="14"';
712 $s .=
'>' . $textfordialog . $img .
'</' . $tag .
'>';
716 if ((
string) $text !=
'') {
717 $s .=
'<' . $tag . $paramfortooltiptd .
'>' . $text .
'</' . $tag .
'>';
720 if ($direction > 0) {
721 $s .=
'<' . $tag . $paramfortooltipimg;
723 $s .=
' class="valignmiddle" width="14"';
725 $s .=
'>' . $textfordialog . $img .
'</' . $tag .
'>';
727 if (empty($notabs)) {
728 $s .=
'</tr></table>';
729 } elseif ($notabs == 2) {
750 public function textwithpicto($text, $htmltext, $direction = 1, $type =
'help', $extracss =
'valignmiddle', $noencodehtmltext = 0, $notabs = 3, $tooltiptrigger =
'', $forcenowrap = 0)
752 global
$conf, $langs;
757 } elseif ($type ==
'1') {
761 $tooltiptrigger = preg_replace(
'/[^a-z0-9]/i',
'', $tooltiptrigger);
763 if (preg_match(
'/onsmartphone$/', $tooltiptrigger) && empty(
$conf->dol_no_mouse_hover)) {
764 $tooltiptrigger = preg_replace(
'/^.*onsmartphone$/',
'', $tooltiptrigger);
767 if ($tooltiptrigger) {
768 $alt = $langs->transnoentitiesnoconv(
"ClickToShowHelp");
772 if (empty(
$conf->use_javascript_ajax)) {
773 if ($type ==
'info' || $type ==
'infoclickable' || $type ==
'help' || $type ==
'helpclickable') {
782 if (!empty(
$conf->dol_no_mouse_hover) && empty($tooltiptrigger)) {
783 if ($type ==
'info' || $type ==
'infoclickable' || $type ==
'help' || $type ==
'helpclickable') {
794 if ($type ==
'info') {
796 } elseif ($type ==
'help') {
797 $img =
img_help(($tooltiptrigger !=
'' ? 2 : 1), $alt);
798 } elseif ($type ==
'helpclickable') {
799 $img =
img_help(($tooltiptrigger !=
'' ? 2 : 1), $alt);
800 } elseif ($type ==
'superadmin') {
803 } elseif ($type ==
'admin') {
806 } elseif ($type ==
'warning') {
808 } elseif ($type !=
'none') {
813 return $this->
textwithtooltip($text, $htmltext, ((($tooltiptrigger && !$img) || strpos($type,
'clickable')) ? 3 : 2), $direction, $img, $extracss, $notabs,
'', $noencodehtmltext, $tooltiptrigger, $forcenowrap);
826 public function selectMassAction($selected, $arrayofaction, $alwaysvisible = 0, $name =
'massaction', $cssclass =
'checkforselect')
828 global
$conf, $langs, $hookmanager;
831 $ret =
'<div class="centpercent center">';
832 $ret .=
'<select class="flat' . (empty(
$conf->use_javascript_ajax) ?
'' :
' hideobject') .
' ' . $name .
' ' . $name .
'select valignmiddle alignstart" id="' . $name .
'" name="' . $name .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
'>';
835 $parameters = array();
836 $reshook = $hookmanager->executeHooks(
'addMoreMassActions', $parameters);
839 if (is_array($arrayofaction) && count($arrayofaction) == 0 && empty($hookmanager->resPrint)) {
842 if (empty($reshook)) {
843 $ret .=
'<option value="0"' . ($disabled ?
' disabled="disabled"' :
'') .
'>-- ' . $langs->trans(
"SelectAction") .
' --</option>';
844 if (is_array($arrayofaction)) {
845 foreach ($arrayofaction as $code => $label) {
846 $ret .=
'<option value="' . $code .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' data-html="' .
dol_escape_htmltag($label) .
'">' . $label .
'</option>';
850 $ret .= $hookmanager->resPrint;
854 if (empty(
$conf->dol_optimize_smallscreen)) {
859 $ret .=
'<input type="submit" name="confirmmassactioninvisible" style="display: none" tabindex="-1">';
860 $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")) .
'">';
863 if (!empty(
$conf->use_javascript_ajax)) {
864 $ret .=
'<!-- JS CODE TO ENABLE mass action select -->
866 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 */
868 atleastoneselected=0;
869 jQuery("."+cssclass).each(function( index ) {
870 /* console.log( index + ": " + $( this ).text() ); */
871 if ($(this).is(\':checked\')) atleastoneselected++;
874 console.log("initCheckForSelect mode="+mode+" name="+name+" cssclass="+cssclass+" atleastoneselected="+atleastoneselected);
876 if (atleastoneselected || ' . $alwaysvisible .
')
878 jQuery("."+name).show();
879 ' . ($selected ?
'if (atleastoneselected) { jQuery("."+name+"select").val("' . $selected .
'").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', false); }' :
'') .
'
880 ' . ($selected ?
'if (! atleastoneselected) { jQuery("."+name+"select").val("0").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', true); } ' :
'') .
'
884 jQuery("."+name).hide();
885 jQuery("."+name+"other").hide();
889 jQuery(document).ready(function () {
890 initCheckForSelect(0, "' . $name .
'", "' . $cssclass .
'");
891 jQuery(".' . $cssclass .
'").click(function() {
892 initCheckForSelect(1, "' . $name .
'", "' . $cssclass .
'");
894 jQuery(".' . $name .
'select").change(function() {
895 var massaction = $( this ).val();
896 var urlform = $( this ).closest("form").attr("action").replace("#show_files","");
897 if (massaction == "builddoc") {
898 urlform = urlform + "#show_files";
900 $( this ).closest("form").attr("action", urlform);
901 console.log("we select a mass action name=' . $name .
' massaction="+massaction+" - "+urlform);
902 /* Warning: if you set submit button to disabled, post using Enter will no more work if there is no other button */
903 if ($(this).val() != \'0\') {
904 jQuery(".' . $name .
'confirmed").prop(\'disabled\', false);
905 jQuery(".' . $name .
'other").hide(); /* To disable if another div was open */
906 jQuery(".' . $name .
'"+massaction).show();
908 jQuery(".' . $name .
'confirmed").prop(\'disabled\', true);
909 jQuery(".' . $name .
'other").hide(); /* To disable any div open */
938 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)
941 global
$conf, $langs, $mysoc;
943 $langs->load(
"dict");
946 $countryArray = array();
949 $atleastonefavorite = 0;
951 $sql =
"SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite, eec";
952 $sql .=
" FROM " . $this->db->prefix() .
"c_country";
953 $sql .=
" WHERE active > 0";
956 dol_syslog(get_class($this) .
"::select_country", LOG_DEBUG);
957 $resql = $this->db->query($sql);
959 $out .=
'<select id="select' . $htmlname .
'" class="flat maxwidth200onsmartphone selectcountry' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" ' . $htmloption .
'>';
960 $num = $this->db->num_rows($resql);
964 $obj = $this->db->fetch_object($resql);
966 $countryArray[$i][
'rowid'] = $obj->rowid;
967 $countryArray[$i][
'code_iso'] = $obj->code_iso;
968 $countryArray[$i][
'code_iso3'] = $obj->code_iso3;
969 $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 :
''));
970 $countryArray[$i][
'favorite'] = $obj->favorite;
971 $countryArray[$i][
'eec'] = $obj->eec;
972 $favorite[$i] = $obj->favorite;
977 if (empty($disablefavorites)) {
978 $array1_sort_order = SORT_DESC;
979 $array2_sort_order = SORT_ASC;
980 array_multisort($favorite, $array1_sort_order, $label, $array2_sort_order, $countryArray);
986 if (is_numeric($showempty)) {
987 $out .=
'<option value=""> </option>' .
"\n";
989 $out .=
'<option value="-1">' . $langs->trans($showempty) .
'</option>' .
"\n";
993 if ($addspecialentries) {
995 $out .=
'<option value="special_allnotme"' . ($selected ==
'special_allnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesExceptMe", $langs->transnoentitiesnoconv(
"Country" . $mysoc->country_code)) .
'</option>';
996 $out .=
'<option value="special_eec"' . ($selected ==
'special_eec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEEC") .
'</option>';
997 if ($mysoc->isInEEC()) {
998 $out .=
'<option value="special_eecnotme"' . ($selected ==
'special_eecnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEECExceptMe", $langs->transnoentitiesnoconv(
"Country" . $mysoc->country_code)) .
'</option>';
1000 $out .=
'<option value="special_noteec"' . ($selected ==
'special_noteec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesNotInEEC") .
'</option>';
1001 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1004 foreach ($countryArray as $row) {
1006 if (empty($row[
'rowid'])) {
1009 if (is_array($exclude_country_code) && count($exclude_country_code) && in_array($row[
'code_iso'], $exclude_country_code)) {
1013 if (empty($disablefavorites) && $row[
'favorite'] && $row[
'code_iso']) {
1014 $atleastonefavorite++;
1016 if (empty($row[
'favorite']) && $atleastonefavorite) {
1017 $atleastonefavorite = 0;
1018 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1022 if ($row[
'label']) {
1023 $labeltoshow .=
dol_trunc($row[
'label'], $maxlength,
'middle');
1025 $labeltoshow .=
' ';
1027 if ($row[
'code_iso']) {
1028 $labeltoshow .=
' <span class="opacitymedium">(' . $row[
'code_iso'] .
')</span>';
1029 if (empty($hideflags)) {
1030 $tmpflag =
picto_from_langcode($row[
'code_iso'],
'class="saturatemedium paddingrightonly"', 1);
1031 $labeltoshow = $tmpflag .
' ' . $labeltoshow;
1035 if ($selected && $selected !=
'-1' && ($selected == $row[
'rowid'] || $selected == $row[
'code_iso'] || $selected == $row[
'code_iso3'] || $selected == $row[
'label'])) {
1036 $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']) .
'">';
1038 $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']) .
'">';
1040 $out .= $labeltoshow;
1041 $out .=
'</option>' .
"\n";
1044 $out .=
'</select>';
1050 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1051 $out .=
ajax_combobox(
'select' . $htmlname, array(), 0, 0,
'resolve');
1071 public function select_incoterms($selected =
'', $location_incoterms =
'', $page =
'', $htmlname =
'incoterm_id', $htmloption =
'', $forcecombo = 1, $events = array(), $disableautocomplete = 0)
1074 global
$conf, $langs;
1076 $langs->load(
"dict");
1080 $incotermArray = array();
1082 $sql =
"SELECT rowid, code";
1083 $sql .=
" FROM " . $this->db->prefix() .
"c_incoterms";
1084 $sql .=
" WHERE active > 0";
1085 $sql .=
" ORDER BY code ASC";
1087 dol_syslog(get_class($this) .
"::select_incoterm", LOG_DEBUG);
1088 $resql = $this->db->query($sql);
1090 if (
$conf->use_javascript_ajax && !$forcecombo) {
1091 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1095 if (!empty($page)) {
1096 $out .=
'<form method="post" action="' . $page .
'">';
1097 $out .=
'<input type="hidden" name="action" value="set_incoterms">';
1098 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
1101 $out .=
'<select id="' . $htmlname .
'" class="flat selectincoterm width75" name="' . $htmlname .
'" ' . $htmloption .
'>';
1102 $out .=
'<option value="0"> </option>';
1103 $num = $this->db->num_rows($resql);
1107 $obj = $this->db->fetch_object($resql);
1108 $incotermArray[$i][
'rowid'] = $obj->rowid;
1109 $incotermArray[$i][
'code'] = $obj->code;
1113 foreach ($incotermArray as $row) {
1114 if ($selected && ($selected == $row[
'rowid'] || $selected == $row[
'code'])) {
1115 $out .=
'<option value="' . $row[
'rowid'] .
'" selected>';
1117 $out .=
'<option value="' . $row[
'rowid'] .
'">';
1121 $out .= $row[
'code'];
1124 $out .=
'</option>';
1127 $out .=
'</select>';
1130 if (
$conf->use_javascript_ajax && empty($disableautocomplete)) {
1131 $out .=
ajax_multiautocompleter(
'location_incoterms', array(), DOL_URL_ROOT .
'/core/ajax/locationincoterms.php') .
"\n";
1132 $moreattrib .=
' autocomplete="off"';
1134 $out .=
'<input id="location_incoterms" class="maxwidthonsmartphone type="text" name="location_incoterms" value="' . $location_incoterms .
'">' .
"\n";
1136 if (!empty($page)) {
1137 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp nomargintop nomarginbottom" value="' . $langs->trans(
"Modify") .
'"></form>';
1160 public function select_type_of_lines($selected =
'', $htmlname =
'type', $showempty = 0, $hidetext = 0, $forceall = 0, $morecss =
"")
1166 if ($forceall == 1 || (empty($forceall) && isModEnabled(
"product") && isModEnabled(
"service"))
1167 || (empty($forceall) && !isModEnabled(
'product') && !isModEnabled(
'service'))) {
1168 if (empty($hidetext)) {
1169 print $langs->trans(
"Type") .
': ';
1171 print
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
1173 print
'<option value="-1"';
1174 if ($selected == -1) {
1178 if (is_numeric($showempty)) {
1186 print
'<option value="0"';
1187 if (0 == $selected || ($selected == -1 &&
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') ==
'product')) {
1190 print
'>' . $langs->trans(
"Product");
1192 print
'<option value="1"';
1193 if (1 == $selected || ($selected == -1 &&
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') ==
'service')) {
1196 print
'>' . $langs->trans(
"Service");
1202 if ((empty($forceall) && !isModEnabled(
'product') && isModEnabled(
"service")) || $forceall == 3) {
1203 print $langs->trans(
"Service");
1204 print
'<input type="hidden" name="' . $htmlname .
'" value="1">';
1206 if ((empty($forceall) && isModEnabled(
"product") && !isModEnabled(
'service')) || $forceall == 2) {
1207 print $langs->trans(
"Product");
1208 print
'<input type="hidden" name="' . $htmlname .
'" value="0">';
1210 if ($forceall < 0) {
1211 print
'<input type="hidden" name="' . $htmlname .
'" value="1">';
1227 $num = count($this->cache_types_fees);
1234 $langs->load(
"trips");
1236 $sql =
"SELECT c.code, c.label";
1237 $sql .=
" FROM " . $this->db->prefix() .
"c_type_fees as c";
1238 $sql .=
" WHERE active > 0";
1240 $resql = $this->db->query($sql);
1242 $num = $this->db->num_rows($resql);
1246 $obj = $this->db->fetch_object($resql);
1249 $label = ($obj->code != $langs->trans($obj->code) ? $langs->trans($obj->code) : $langs->trans($obj->label));
1250 $this->cache_types_fees[$obj->code] = $label;
1254 asort($this->cache_types_fees);
1276 global $user, $langs;
1278 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
1282 print
'<select id="select_' . $htmlname .
'" class="flat" name="' . $htmlname .
'">';
1284 print
'<option value="-1"';
1285 if ($selected == -1) {
1288 print
'> </option>';
1291 foreach ($this->cache_types_fees as $key => $value) {
1292 print
'<option value="' . $key .
'"';
1293 if ($key == $selected) {
1303 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1332 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)
1335 global
$conf, $langs;
1339 if (!empty(
$conf->use_javascript_ajax) &&
getDolGlobalString(
'COMPANY_USE_SEARCH_TO_SELECT') && !$forcecombo) {
1340 if (is_null($ajaxoptions)) {
1341 $ajaxoptions = array();
1344 require_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1348 if ($selected && empty($selected_input_value)) {
1349 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
1350 $societetmp =
new Societe($this->db);
1351 $societetmp->fetch($selected);
1352 $selected_input_value = $societetmp->name;
1357 $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)) :
'');
1359 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
1360 if (empty($hidelabel)) {
1361 $out .= $langs->trans(
"RefOrLabel") .
' : ';
1362 } elseif ($hidelabel == 1 && !is_numeric($showempty)) {
1363 $placeholder = $langs->trans($showempty);
1364 } elseif ($hidelabel > 1) {
1365 $placeholder = $langs->trans(
"RefOrLabel");
1366 if ($hidelabel == 2) {
1367 $out .=
img_picto($langs->trans(
"Search"),
'search');
1370 $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' :
'') .
' />';
1371 if ($hidelabel == 3) {
1372 $out .=
img_picto($langs->trans(
"Search"),
'search');
1377 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.
'/societe/ajax/company.php', $urloption,
getDolGlobalInt(
'COMPANY_USE_SEARCH_TO_SELECT'), 0, $ajaxoptions);
1380 $out .= $this->
select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events,
'', 0, $limit, $morecss, $moreparam, $multiple, $excludeids, $showcode);
1414 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 =
'')
1418 global
$conf, $langs;
1423 if ($nokeyifsocid && $socid > 0) {
1424 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = 0;
1427 if (!empty(
$conf->use_javascript_ajax) &&
getDolGlobalString(
'CONTACT_USE_SEARCH_TO_SELECT') && !$forcecombo) {
1428 if (is_null($events)) {
1432 require_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1436 if ($selected && empty($selected_input_value)) {
1437 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
1438 $contacttmp =
new Contact($this->db);
1439 $contacttmp->fetch($selected);
1440 $selected_input_value = $contacttmp->getFullName($langs);
1443 if (!is_numeric($showempty)) {
1444 $placeholder = $showempty;
1448 $urloption =
'htmlname=' . urlencode((
string) (str_replace(
'.',
'_', $htmlname))) .
'&outjson=1&filter=' . urlencode((
string) ($filter)) . (empty($exclude) ?
'' :
'&exclude=' . urlencode($exclude)) . ($showsoc ?
'&showsoc=' . urlencode((
string) ($showsoc)) :
'');
1450 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
1452 $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' :
'') .
' />';
1456 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.
'/contact/ajax/contact.php', $urloption,
getDolGlobalInt(
'CONTACT_USE_SEARCH_TO_SELECT'), 0, $events);
1460 $disableifempty = 0;
1464 $out .= $this->
selectcontacts($socid, $selected, $htmlname, $showempty, $exclude, $limitto, $showfunction, $morecss, $options_only, $showsoc, $forcecombo, $events, $moreparam, $htmlid, $multiple, $disableifempty);
1467 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = $sav;
1499 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)
1502 global $user, $langs;
1503 global $hookmanager;
1507 $outarray = array();
1509 if ($selected ===
'') {
1510 $selected = array();
1511 } elseif (!is_array($selected)) {
1512 $selected = array($selected);
1516 if (function_exists(
'testSqlAndScriptInject')) {
1519 return 'SQLInjectionTryDetected';
1523 if ($filter !=
'') {
1524 if (preg_match(
'/[\(\)]/', $filter)) {
1530 if (function_exists(
'testSqlAndScriptInject')) {
1533 return 'SQLInjectionTryDetected';
1539 dol_syslog(
"Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Syntax.", LOG_WARNING);
1544 $sql =
"SELECT s.rowid, s.nom as name, s.name_alias, s.tva_intra, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
1546 $sql .=
", s.address, s.zip, s.town";
1547 $sql .=
", dictp.code as country_code";
1549 $sql .=
" FROM " . $this->db->prefix() .
"societe as s";
1551 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_country as dictp ON dictp.rowid = s.fk_pays";
1553 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1554 $sql .=
", " . $this->db->prefix() .
"societe_commerciaux as sc";
1556 $sql .=
" WHERE s.entity IN (" .
getEntity(
'societe') .
")";
1557 if (!empty($user->socid)) {
1558 $sql .=
" AND s.rowid = " . ((int) $user->socid);
1563 $sql .=
" AND (" . $filter .
")";
1565 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1566 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = " . ((int) $user->id);
1569 $sql .=
" AND s.status <> 0";
1571 if (!empty($excludeids)) {
1572 $sql .=
" AND s.rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeids)) .
")";
1575 $parameters = array();
1576 $reshook = $hookmanager->executeHooks(
'selectThirdpartyListWhere', $parameters);
1577 $sql .= $hookmanager->resPrint;
1579 if ($filterkey && $filterkey !=
'') {
1583 $search_crit = explode(
' ', $filterkey);
1585 if (count($search_crit) > 1) {
1588 foreach ($search_crit as $crit) {
1592 $sql .=
"(s.nom LIKE '" . $this->db->escape($prefix . $crit) .
"%')";
1595 if (count($search_crit) > 1) {
1598 if (isModEnabled(
'barcode')) {
1599 $sql .=
" OR s.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1601 $sql .=
" OR s.code_client LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.code_fournisseur LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1602 $sql .=
" OR s.name_alias LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.tva_intra LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1605 $sql .= $this->db->order(
"nom",
"ASC");
1606 $sql .= $this->db->plimit($limit, 0);
1609 dol_syslog(get_class($this).
"::select_thirdparty_list", LOG_DEBUG);
1610 $resql = $this->db->query($sql);
1613 $out .=
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
' name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
'>' .
"\n";
1615 $textifempty = (($showempty && !is_numeric($showempty)) ? $langs->trans($showempty) :
'');
1619 if ($showempty && !is_numeric($showempty)) {
1620 $textifempty = $langs->trans($showempty);
1622 $textifempty .= $langs->trans(
"All");
1626 $out .=
'<option value="-1" data-html="' .
dol_escape_htmltag(
'<span class="opacitymedium">' . ($textifempty ? $textifempty :
' ') .
'</span>') .
'">' . $textifempty .
'</option>' .
"\n";
1629 $companytemp =
new Societe($this->db);
1631 $num = $this->db->num_rows($resql);
1635 $obj = $this->db->fetch_object($resql);
1638 if (($obj->client) && (!empty($obj->code_client))) {
1639 $label = $obj->code_client .
' - ';
1641 if (($obj->fournisseur) && (!empty($obj->code_fournisseur))) {
1642 $label .= $obj->code_fournisseur .
' - ';
1644 $label .=
' ' . $obj->name;
1646 $label = $obj->name;
1649 if (!empty($obj->name_alias)) {
1650 $label .=
' (' . $obj->name_alias .
')';
1654 $label .=
' - '.$obj->tva_intra;
1657 $labelhtml = $label;
1660 $companytemp->id = $obj->rowid;
1661 $companytemp->client = $obj->client;
1662 $companytemp->fournisseur = $obj->fournisseur;
1663 $tmptype = $companytemp->getTypeUrl(1,
'', 0,
'span');
1665 $labelhtml .=
' ' . $tmptype;
1668 if ($obj->client || $obj->fournisseur) {
1671 if ($obj->client == 1 || $obj->client == 3) {
1672 $label .= $langs->trans(
"Customer");
1674 if ($obj->client == 2 || $obj->client == 3) {
1675 $label .= ($obj->client == 3 ?
', ' :
'') . $langs->trans(
"Prospect");
1677 if ($obj->fournisseur) {
1678 $label .= ($obj->client ?
', ' :
'') . $langs->trans(
"Supplier");
1680 if ($obj->client || $obj->fournisseur) {
1686 $s = ($obj->address ?
' - ' . $obj->address :
'') . ($obj->zip ?
' - ' . $obj->zip :
'') . ($obj->town ?
' ' . $obj->town :
'');
1687 if (!empty($obj->country_code)) {
1688 $s .=
', ' . $langs->trans(
'Country' . $obj->country_code);
1694 if (empty($outputmode)) {
1695 if (in_array($obj->rowid, $selected)) {
1696 $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>';
1698 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
1701 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label,
'labelhtml' => $labelhtml));
1705 if (($i % 10) == 0) {
1710 $out .=
'</select>' .
"\n";
1712 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1719 $this->result = array(
'nbofthirdparties' => $num);
1753 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 =
'')
1755 global
$conf, $user, $langs, $hookmanager, $action;
1757 $langs->load(
'companies');
1759 if (empty($htmlid)) {
1760 $htmlid = $htmlname;
1764 $outarray = array();
1766 if ($selected ===
'') {
1767 $selected = array();
1768 } elseif (!is_array($selected)) {
1769 $selected = array((
int) $selected);
1773 if (function_exists(
'testSqlAndScriptInject')) {
1776 return 'SQLInjectionTryDetected';
1780 if ($filter !=
'') {
1781 if (preg_match(
'/[\(\)]/', $filter)) {
1787 if (function_exists(
'testSqlAndScriptInject')) {
1790 return 'SQLInjectionTryDetected';
1796 dol_syslog(
"Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Filter Syntax.", LOG_WARNING);
1800 if (!is_object($hookmanager)) {
1801 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
1806 $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";
1807 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
1808 $sql .=
", s.nom as company, s.town AS company_town";
1810 $sql .=
" FROM " . $this->db->prefix() .
"socpeople as sp";
1811 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
1812 $sql .=
" LEFT OUTER JOIN " . $this->db->prefix() .
"societe as s ON s.rowid=sp.fk_soc";
1814 $sql .=
" WHERE sp.entity IN (" .
getEntity(
'contact') .
")";
1815 $sql .=
" AND ((sp.fk_user_creat = ".((int) $user->id).
" AND sp.priv = 1) OR sp.priv = 0)";
1816 if ($socid > 0 || $socid == -1) {
1817 $sql .=
" AND sp.fk_soc = " . ((int) $socid);
1820 $sql .=
" AND sp.statut <> 0";
1825 $sql .=
" AND (" . $filter .
")";
1828 $parameters = array();
1829 $reshook = $hookmanager->executeHooks(
'selectContactListWhere', $parameters);
1830 $sql .= $hookmanager->resPrint;
1831 $sql .=
" ORDER BY sp.lastname ASC";
1833 dol_syslog(get_class($this) .
"::selectcontacts", LOG_DEBUG);
1834 $resql = $this->db->query($sql);
1836 $num = $this->db->num_rows($resql);
1838 if ($htmlname !=
'none' && !$options_only) {
1839 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlid .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . (($num || empty($disableifempty)) ?
'' :
' disabled') . ($multiple ?
'multiple' :
'') .
' ' . (!empty($moreparam) ? $moreparam :
'') .
'>';
1842 if ($showempty && !is_numeric($showempty)) {
1843 $textforempty = $showempty;
1844 $out .=
'<option class="optiongrey" value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'>' . $textforempty .
'</option>';
1846 if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) {
1847 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'> </option>';
1849 if ($showempty == 2) {
1850 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Internal") .
' --</option>';
1856 include_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
1857 $contactstatic =
new Contact($this->db);
1860 $obj = $this->db->fetch_object($resql);
1863 $extendedInfos =
'';
1865 $extendedInfos = array();
1866 $email = trim($obj->email);
1867 if (!empty($email)) {
1868 $extendedInfos[] = $email;
1870 $phone = trim($obj->phone);
1871 $phone_perso = trim($obj->phone_perso);
1872 $phone_mobile = trim($obj->phone_mobile);
1873 if (!empty($phone)) {
1874 $extendedInfos[] = $phone;
1876 if (!empty($phone_perso)) {
1877 $extendedInfos[] = $phone_perso;
1879 if (!empty($phone_mobile)) {
1880 $extendedInfos[] = $phone_mobile;
1883 $contact_town = trim($obj->contact_town);
1884 $company_town = trim($obj->company_town);
1885 if (!empty($contact_town)) {
1886 $extendedInfos[] = $contact_town;
1887 } elseif (!empty($company_town)) {
1888 $extendedInfos[] = $company_town;
1890 $extendedInfos = implode(
' - ', $extendedInfos);
1891 if (!empty($extendedInfos)) {
1892 $extendedInfos =
' - ' . $extendedInfos;
1896 $contactstatic->id = $obj->rowid;
1897 $contactstatic->lastname = $obj->lastname;
1898 $contactstatic->firstname = $obj->firstname;
1899 if ($obj->statut == 1) {
1901 if ($htmlname !=
'none') {
1903 if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) {
1906 if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) {
1909 if (!empty($selected) && in_array($obj->rowid, $selected)) {
1910 $out .=
'<option value="' . $obj->rowid .
'"';
1912 $out .=
' disabled';
1914 $out .=
' selected>';
1916 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1917 if ($showfunction && $obj->poste) {
1918 $tmplabel .=
' (' . $obj->poste .
')';
1920 if (($showsoc > 0) && $obj->company) {
1921 $tmplabel .=
' - (' . $obj->company .
')';
1925 $out .=
'</option>';
1927 $out .=
'<option value="' . $obj->rowid .
'"';
1929 $out .=
' disabled';
1933 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1934 if ($showfunction && $obj->poste) {
1935 $tmplabel .=
' (' . $obj->poste .
')';
1937 if (($showsoc > 0) && $obj->company) {
1938 $tmplabel .=
' - (' . $obj->company .
')';
1942 $out .=
'</option>';
1945 if (in_array($obj->rowid, $selected)) {
1946 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1947 if ($showfunction && $obj->poste) {
1948 $tmplabel .=
' (' . $obj->poste .
')';
1950 if (($showsoc > 0) && $obj->company) {
1951 $tmplabel .=
' - (' . $obj->company .
')';
1958 if ($tmplabel !=
'') {
1959 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $tmplabel,
'label' => $tmplabel,
'labelhtml' => $tmplabel));
1965 $labeltoshow = ($socid != -1) ? ($langs->trans($socid ?
"NoContactDefinedForThirdParty" :
"NoContactDefined")) : $langs->trans(
'SelectAThirdPartyFirst');
1966 $out .=
'<option class="disabled" value="-1"' . (($showempty == 2 || $multiple) ?
'' :
' selected') .
' disabled="disabled">';
1967 $out .= $labeltoshow;
1968 $out .=
'</option>';
1971 $parameters = array(
1973 'htmlname' => $htmlname,
1976 'showfunction' => $showfunction,
1977 'showsoc' => $showsoc,
1980 $reshook = $hookmanager->executeHooks(
'afterSelectContactOptions', $parameters, $this, $action);
1982 if ($htmlname !=
'none' && !$options_only) {
1983 $out .=
'</select>';
1986 if (
$conf->use_javascript_ajax && !$forcecombo && !$options_only) {
1987 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1993 if ($options_only === 2) {
2021 global $langs,
$conf;
2024 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
2025 $sql .=
" re.description, re.fk_facture_source";
2026 $sql .=
" FROM " . $this->db->prefix() .
"societe_remise_except as re";
2027 $sql .=
" WHERE re.fk_soc = " . (int) $socid;
2028 $sql .=
" AND re.entity = " .
$conf->entity;
2030 $sql .=
" AND " . $filter;
2032 $sql .=
" ORDER BY re.description ASC";
2034 dol_syslog(get_class($this) .
"::select_remises", LOG_DEBUG);
2035 $resql = $this->db->query($sql);
2037 print
'<select id="select_' . $htmlname .
'" class="flat maxwidthonsmartphone" name="' . $htmlname .
'">';
2038 $num = $this->db->num_rows($resql);
2040 $qualifiedlines = $num;
2044 print
'<option value="0"> </option>';
2046 $obj = $this->db->fetch_object($resql);
2047 $desc =
dol_trunc($obj->description, 40);
2048 if (preg_match(
'/\(CREDIT_NOTE\)/', $desc)) {
2049 $desc = preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $desc);
2051 if (preg_match(
'/\(DEPOSIT\)/', $desc)) {
2052 $desc = preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"Deposit"), $desc);
2054 if (preg_match(
'/\(EXCESS RECEIVED\)/', $desc)) {
2055 $desc = preg_replace(
'/\(EXCESS RECEIVED\)/', $langs->trans(
"ExcessReceived"), $desc);
2057 if (preg_match(
'/\(EXCESS PAID\)/', $desc)) {
2058 $desc = preg_replace(
'/\(EXCESS PAID\)/', $langs->trans(
"ExcessPaid"), $desc);
2062 if ($selected > 0 && $selected == $obj->rowid) {
2063 $selectstring =
' selected';
2067 if ($maxvalue > 0 && $obj->amount_ttc > $maxvalue) {
2069 $disabled =
' disabled';
2072 if (
getDolGlobalString(
'MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST') && !empty($obj->fk_facture_source)) {
2073 $tmpfac =
new Facture($this->db);
2074 if ($tmpfac->fetch($obj->fk_facture_source) > 0) {
2075 $desc = $desc .
' - ' . $tmpfac->ref;
2079 print
'<option value="' . $obj->rowid .
'"' . $selectstring . $disabled .
'>' . $desc .
' (' .
price($obj->amount_ht) .
' ' . $langs->trans(
"HT") .
' - ' .
price($obj->amount_ttc) .
' ' . $langs->trans(
"TTC") .
')</option>';
2086 return $qualifiedlines;
2111 public function select_users($selected =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include =
'', $enableonly = array(), $force_entity =
'0')
2114 print $this->
select_dolusers($selected, $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity);
2143 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)
2146 global
$conf, $user, $langs, $hookmanager;
2150 if ((is_numeric($selected) && ($selected < -2 || empty($selected))) && !
getDolGlobalString(
'SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE')) {
2151 $selected = $user->id;
2154 if ($selected ===
'') {
2155 $selected = array();
2156 } elseif (!is_array($selected)) {
2157 $selected = array($selected);
2160 $excludeUsers =
null;
2161 $includeUsers =
null;
2164 if (is_array($exclude)) {
2165 $excludeUsers = implode(
",", $exclude);
2168 if (is_array($include)) {
2169 $includeUsers = implode(
",", $include);
2170 } elseif ($include ==
'hierarchy') {
2172 $includeUsers = implode(
",", $user->getAllChildIds(0));
2173 } elseif ($include ==
'hierarchyme') {
2175 $includeUsers = implode(
",", $user->getAllChildIds(1));
2181 $outarray = array();
2182 $outarray2 = array();
2185 $showlabelofentity = isModEnabled(
'multicompany') && !
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE') &&
$conf->entity == 1 && !empty($user->admin) && empty($user->entity);
2186 $userissuperadminentityone = isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && empty($user->entity);
2189 $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";
2190 if ($showlabelofentity) {
2191 $sql .=
", e.label";
2193 $sql .=
" FROM " . $this->db->prefix() .
"user as u";
2194 if ($showlabelofentity) {
2195 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid = u.entity";
2198 if ($userissuperadminentityone && $force_entity !=
'default') {
2199 if (!empty($force_entity)) {
2200 $sql .=
" WHERE u.entity IN (0, " . $this->db->sanitize($force_entity) .
")";
2202 $sql .=
" WHERE u.entity IS NOT NULL";
2205 if (isModEnabled(
'multicompany') &&
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE')) {
2206 $sql .=
" WHERE u.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
2208 $sql .=
" WHERE u.entity IN (" .
getEntity(
'user') .
")";
2212 if (!empty($user->socid)) {
2213 $sql .=
" AND u.fk_soc = " . ((int) $user->socid);
2215 if (is_array($exclude) && $excludeUsers) {
2216 $sql .=
" AND u.rowid NOT IN (" . $this->db->sanitize($excludeUsers) .
")";
2218 if ($includeUsers) {
2219 $sql .=
" AND u.rowid IN (" . $this->db->sanitize($includeUsers) .
")";
2222 $sql .=
" AND u.statut <> 0";
2225 $sql .=
" AND u.employee <> 0";
2228 $sql .=
" AND u.fk_soc IS NULL";
2230 if (!empty($morefilter)) {
2231 $sql .=
" " . $morefilter;
2235 $reshook = $hookmanager->executeHooks(
'addSQLWhereFilterOnSelectUsers', array(), $this, $action);
2236 if (!empty($reshook)) {
2237 $sql .= $hookmanager->resPrint;
2241 $sql .=
" ORDER BY u.statut DESC, u.firstname ASC, u.lastname ASC";
2243 $sql .=
" ORDER BY u.statut DESC, u.lastname ASC, u.firstname ASC";
2246 dol_syslog(get_class($this) .
"::select_dolusers", LOG_DEBUG);
2248 $resql = $this->db->query($sql);
2250 $num = $this->db->num_rows($resql);
2254 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
' minwidth200') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
2255 if ($show_empty && !$multiple) {
2256 $textforempty =
' ';
2257 if (!empty(
$conf->use_javascript_ajax)) {
2258 $textforempty =
' ';
2260 if (!is_numeric($show_empty)) {
2261 $textforempty = $show_empty;
2263 $out .=
'<option class="optiongrey" value="' . ($show_empty < 0 ? $show_empty : -1) .
'"' . ((empty($selected) || in_array(-1, $selected)) ?
' selected' :
'') .
'>' . $textforempty .
'</option>' .
"\n";
2265 $outarray[($show_empty < 0 ? $show_empty : -1)] = $textforempty;
2266 $outarray2[($show_empty < 0 ? $show_empty : -1)] = array(
2267 'id' => ($show_empty < 0 ? $show_empty : -1),
2268 'label' => $textforempty,
2269 'labelhtml' => $textforempty,
2275 $out .=
'<option value="-2"' . ((in_array(-2, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Everybody") .
' --</option>' .
"\n";
2277 $outarray[-2] =
'-- ' . $langs->trans(
"Everybody") .
' --';
2278 $outarray2[-2] = array(
2280 'label' =>
'-- ' . $langs->trans(
"Everybody") .
' --',
2281 'labelhtml' =>
'-- ' . $langs->trans(
"Everybody") .
' --',
2287 $userstatic =
new User($this->db);
2290 $obj = $this->db->fetch_object($resql);
2292 $userstatic->id = $obj->rowid;
2293 $userstatic->lastname = $obj->lastname;
2294 $userstatic->firstname = $obj->firstname;
2295 $userstatic->photo = $obj->photo;
2296 $userstatic->status = $obj->status;
2297 $userstatic->entity = $obj->entity;
2298 $userstatic->admin = $obj->admin;
2299 $userstatic->gender = $obj->gender;
2302 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
2303 $disableline = ($enableonlytext ? $enableonlytext :
'1');
2307 $labeltoshowhtml =
'';
2314 $labeltoshow .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2315 $labeltoshowhtml .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2316 if (empty($obj->firstname) && empty($obj->lastname)) {
2317 $labeltoshow .= $obj->login;
2318 $labeltoshowhtml .= $obj->login;
2325 $moreinfo .= ($moreinfo ?
' - ' :
' (');
2326 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(');
2327 $moreinfo .= $obj->login;
2328 $moreinfohtml .= $obj->login;
2330 if ($showstatus >= 0) {
2331 if ($obj->status == 1 && $showstatus == 1) {
2332 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Enabled');
2333 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Enabled');
2335 if ($obj->status == 0 && $showstatus == 1) {
2336 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Disabled');
2337 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Disabled');
2340 if ($showlabelofentity) {
2341 if (empty($obj->entity)) {
2342 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
"AllEntities");
2343 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
"AllEntities");
2345 if ($obj->entity !=
$conf->entity) {
2346 $moreinfo .= ($moreinfo ?
' - ' :
' (') . ($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2347 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(').($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2351 $moreinfo .= (!empty($moreinfo) ?
')' :
'');
2352 $moreinfohtml .= (!empty($moreinfohtml) ?
')</span>' :
'');
2353 if (!empty($disableline) && $disableline !=
'1') {
2355 $moreinfo .=
' - ' . $disableline;
2356 $moreinfohtml .=
' - ' . $disableline;
2358 $labeltoshow .= $moreinfo;
2359 $labeltoshowhtml .= $moreinfohtml;
2361 $out .=
'<option value="' . $obj->rowid .
'"';
2362 if (!empty($disableline)) {
2363 $out .=
' disabled';
2365 if ((!empty($selected[0]) && is_object($selected[0])) ? $selected[0]->id == $obj->rowid : in_array($obj->rowid, $selected)) {
2366 $out .=
' selected';
2368 $out .=
' data-html="';
2370 $outhtml = $userstatic->getNomUrl(-3,
'', 0, 1, 24, 1,
'login',
'', 1) .
' ';
2371 if ($showstatus >= 0 && $obj->status == 0) {
2372 $outhtml .=
'<strike class="opacitymediumxxx">';
2374 $outhtml .= $labeltoshowhtml;
2375 if ($showstatus >= 0 && $obj->status == 0) {
2376 $outhtml .=
'</strike>';
2378 $labeltoshowhtml = $outhtml;
2382 $out .= $labeltoshow;
2383 $out .=
'</option>';
2385 $outarray[$userstatic->id] = $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength) . $moreinfo;
2386 $outarray2[$userstatic->id] = array(
2387 'id' => $userstatic->id,
2388 'label' => $labeltoshow,
2389 'labelhtml' => $labeltoshowhtml,
2397 $out .=
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'" disabled>';
2398 $out .=
'<option value="">' . $langs->trans(
"None") .
'</option>';
2400 $out .=
'</select>';
2402 if ($num && !$forcecombo) {
2404 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2413 if ($outputmode == 2) {
2415 } elseif ($outputmode) {
2446 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())
2451 $userstatic =
new User($this->db);
2454 if (!empty($_SESSION[
'assignedtouser'])) {
2455 $assignedtouser = json_decode($_SESSION[
'assignedtouser'],
true);
2456 if (!is_array($assignedtouser)) {
2457 $assignedtouser = array();
2460 $assignedtouser = array();
2462 $nbassignetouser = count($assignedtouser);
2465 if ($nbassignetouser) {
2466 $out .=
'<ul class="attendees">';
2470 foreach ($assignedtouser as $key => $value) {
2471 if ($value[
'id'] == $ownerid) {
2476 $userstatic->fetch($value[
'id']);
2477 $out .= $userstatic->getNomUrl(-1);
2479 $ownerid = $value[
'id'];
2480 $out .=
' (' . $langs->trans(
"Owner") .
')';
2482 if ($nbassignetouser > 1 && $action !=
'view') {
2483 $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 .
'">';
2486 if ($showproperties) {
2487 if ($ownerid == $value[
'id'] && is_array($listofuserid) && count($listofuserid) && in_array($ownerid, array_keys($listofuserid))) {
2488 $out .=
'<div class="myavailability inline-block">';
2489 $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>';
2499 if ($nbassignetouser) {
2504 if ($action !=
'view') {
2505 $out .=
'<input type="hidden" class="removedassignedhidden" name="removedassigned" value="">';
2506 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
2507 $out .=
'jQuery(".removedassigned").click(function() { jQuery(".removedassignedhidden").val(jQuery(this).val()); });';
2508 $out .=
'jQuery(".assignedtouser").change(function() { console.log(jQuery(".assignedtouser option:selected").val());';
2509 $out .=
' if (jQuery(".assignedtouser option:selected").val() > 0) { jQuery("#' . $action .
'assignedtouser").attr("disabled", false); }';
2510 $out .=
' else { jQuery("#' . $action .
'assignedtouser").attr("disabled", true); }';
2512 $out .=
'})</script>';
2513 $out .= $this->
select_dolusers(
'', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter);
2514 $out .=
' <input type="submit" disabled class="button valignmiddle smallpaddingimp reposition" id="' . $action .
'assignedtouser" name="' . $action .
'assignedtouser" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
2541 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())
2546 require_once DOL_DOCUMENT_ROOT.
'/resource/class/html.formresource.class.php';
2547 require_once DOL_DOCUMENT_ROOT.
'/resource/class/dolresource.class.php';
2552 if (!empty($_SESSION[
'assignedtoresource'])) {
2553 $assignedtoresource = json_decode($_SESSION[
'assignedtoresource'],
true);
2554 if (!is_array($assignedtoresource)) {
2555 $assignedtoresource = array();
2558 $assignedtoresource = array();
2560 $nbassignetoresource = count($assignedtoresource);
2563 if ($nbassignetoresource) {
2564 $out .=
'<ul class="attendees">';
2568 foreach ($assignedtoresource as $key => $value) {
2570 $resourcestatic->fetch($value[
'id']);
2571 $out .= $resourcestatic->getNomUrl(-1);
2572 if ($nbassignetoresource >= 1 && $action !=
'view') {
2573 $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 .
'">';
2576 if ($showproperties) {
2577 if (is_array($listofresourceid) && count($listofresourceid)) {
2578 $out .=
'<div class="myavailability inline-block">';
2579 $out .=
'<span class="hideonsmartphone"> - <span class="opacitymedium">' . $langs->trans(
"Availability") .
':</span> </span><input id="transparencyresource" class="paddingrightonly" ' . ($action ==
'view' ?
'disabled' :
'') .
' type="checkbox" name="transparency"' . ($listofresourceid[$value[
'id']][
'transparency'] ?
' checked' :
'') .
'><label for="transparency">' . $langs->trans(
"Busy") .
'</label>';
2589 if ($nbassignetoresource) {
2594 if ($action !=
'view') {
2595 $out .=
'<input type="hidden" class="removedassignedresourcehidden" name="removedassignedresource" value="">';
2596 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
2597 $out .=
'jQuery(".removedassignedresource").click(function() { jQuery(".removedassignedresourcehidden").val(jQuery(this).val()); });';
2598 $out .=
'jQuery(".assignedtoresource").change(function() { console.log(jQuery(".assignedtoresource option:selected").val());';
2599 $out .=
' if (jQuery(".assignedtoresource option:selected").val() > 0) { jQuery("#' . $action .
'assignedtoresource").attr("disabled", false); }';
2600 $out .=
' else { jQuery("#' . $action .
'assignedtoresource").attr("disabled", true); }';
2602 $out .=
'})</script>';
2605 $out .=
img_picto(
'',
'resource',
'class="pictofixedwidth"');
2606 $out .= $formresources->select_resource_list(0, $htmlname, [], 1, 1, 0, $events, array(), 2, 0);
2608 $out .=
' <input type="submit" disabled class="button valignmiddle smallpaddingimp reposition" id="' . $action .
'assignedtoresource" name="' . $action .
'assignedtoresource" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
2646 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)
2649 global $langs,
$conf;
2654 $price_level = (!empty($price_level) ? $price_level : 0);
2655 if (is_null($ajaxoptions)) {
2656 $ajaxoptions = array();
2659 if (strval($filtertype) ===
'' && (isModEnabled(
"product") || isModEnabled(
"service"))) {
2660 if (isModEnabled(
"product") && !isModEnabled(
'service')) {
2662 } elseif (!isModEnabled(
'product') && isModEnabled(
"service")) {
2668 $placeholder = (is_numeric($showempty) ?
'' :
'placeholder="'.dolPrintHTML($showempty).
'"');
2670 if ($selected && empty($selected_input_value)) {
2671 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
2672 $producttmpselect =
new Product($this->db);
2673 $producttmpselect->fetch($selected);
2674 $selected_input_value = $producttmpselect->ref;
2675 unset($producttmpselect);
2678 if ($filtertype ==
'') {
2679 if (!isModEnabled(
'product')) {
2681 } elseif (!isModEnabled(
'service')) {
2686 $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;
2687 if ((
int) $warehouseId > 0) {
2688 $urloption .=
'&warehouseid=' . (int) $warehouseId;
2691 $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);
2693 if (isModEnabled(
'variants') && is_array($selected_combinations)) {
2697 <!-- script to auto show attributes select tags if a variant was selected -->
2698 <script nonce="' .
getNonce() .
'">
2699 // auto show attributes fields
2700 selected = ' . json_encode($selected_combinations) .
';
2703 jQuery(document).ready(function () {
2705 jQuery("input[name=\'prod_entry_mode\']").change(function () {
2706 if (jQuery(this).val() == \'free\') {
2707 jQuery(\'div#attributes_box\').empty();
2711 jQuery("input#' . $htmlname .
'").change(function () {
2713 if (!jQuery(this).val()) {
2714 jQuery(\'div#attributes_box\').empty();
2718 console.log("A change has started. We get variants fields to inject html select");
2720 jQuery.getJSON("' . DOL_URL_ROOT .
'/variants/ajax/getCombinations.php", {
2721 id: jQuery(this).val()
2722 }, function (data) {
2723 jQuery(\'div#attributes_box\').empty();
2725 jQuery.each(data, function (key, val) {
2727 combvalues[val.id] = val.values;
2729 var span = jQuery(document.createElement(\'div\')).css({
2730 \'display\': \'table-row\'
2734 jQuery(document.createElement(\'div\')).text(val.label).css({
2735 \'font-weight\': \'bold\',
2736 \'display\': \'table-cell\'
2740 var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({
2741 \'margin-left\': \'15px\',
2742 \'white-space\': \'pre\'
2744 jQuery(document.createElement(\'option\')).val(\'\')
2747 jQuery.each(combvalues[val.id], function (key, val) {
2748 var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value);
2750 if (selected[val.fk_product_attribute] == val.id) {
2751 tag.attr(\'selected\', \'selected\');
2758 jQuery(\'div#attributes_box\').append(span);
2763 ' . ($selected ?
'jQuery("input#' . $htmlname .
'").change();' :
'') .
'
2769 if (empty($hidelabel)) {
2771 } elseif ($hidelabel > 1) {
2773 if ($hidelabel == 2) {
2774 $out .=
img_picto($langs->trans(
"Search"),
'search');
2778 $out .=
'<input type="text" class="minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . $placeholder .
' ' . (
getDolGlobalString(
'PRODUCT_SEARCH_AUTOFOCUS') ?
'autofocus' :
'') .
' />';
2779 if ($hidelabel == 3) {
2780 $out .=
img_picto($langs->trans(
"Search"),
'search');
2783 $out .= $this->
select_produits_list($selected, $htmlname, $filtertype, $limit, $price_level,
'', $status, $finished, 0, $socid, $showempty, $forcecombo, $morecss, $hidepriceinlabel, $warehouseStatus, $status_purchase, $warehouseId);
2786 if (empty($nooutput)) {
2810 public function select_bom($selected =
'', $htmlname =
'bom_id', $limit = 0, $status = 1, $type = 0, $showempty =
'1', $morecss =
'', $nooutput =
'', $forcecombo = 0, $TProducts = [])
2815 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
2821 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2826 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
2828 $sql =
'SELECT b.rowid, b.ref, b.label, b.fk_product';
2829 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'bom_bom as b';
2830 $sql .=
' WHERE b.entity IN (' .
getEntity(
'bom') .
')';
2831 if (!empty($status)) {
2832 $sql .=
' AND status = ' . (int) $status;
2834 if (!empty($type)) {
2835 $sql .=
' AND bomtype = ' . (int) $type;
2837 if (!empty($TProducts)) {
2838 $sql .=
' AND fk_product IN (' . $this->db->sanitize(implode(
',', $TProducts)) .
')';
2840 if (!empty($limit)) {
2841 $sql .=
' LIMIT ' . (int) $limit;
2843 $resql = $db->query($sql);
2846 $out .=
'<option value="-1"';
2847 if (empty($selected)) {
2848 $out .=
' selected';
2850 $out .=
'> </option>';
2852 while ($obj = $db->fetch_object($resql)) {
2854 $res = $product->fetch($obj->fk_product);
2855 $out .=
'<option value="' . $obj->rowid .
'"';
2856 if ($obj->rowid == $selected) {
2859 $out .=
'>' . $obj->ref .
' - ' . $product->label .
' - ' . $obj->label .
'</option>';
2865 $out .=
'</select>';
2866 if (empty($nooutput)) {
2901 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)
2905 global $hookmanager;
2908 $outarray = array();
2912 $langs->load(
'other');
2915 $warehouseStatusArray = array();
2916 if (!empty($warehouseStatus)) {
2917 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/entrepot.class.php';
2918 if (preg_match(
'/warehouseclosed/', $warehouseStatus)) {
2921 if (preg_match(
'/warehouseopen/', $warehouseStatus)) {
2924 if (preg_match(
'/warehouseinternal/', $warehouseStatus)) {
2929 $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";
2930 if (count($warehouseStatusArray)) {
2931 $selectFieldsGrouped =
", sum(" . $this->db->ifsql(
"e.statut IS NULL",
"0",
"ps.reel") .
") as stock";
2933 $selectFieldsGrouped =
", " . $this->db->ifsql(
"p.stock IS NULL", 0,
"p.stock") .
" AS stock";
2939 $parameters = array();
2940 $reshook = $hookmanager->executeHooks(
'selectProductsListSelect', $parameters);
2941 if (empty($reshook)) {
2942 $sql .= $selectFields.$selectFieldsGrouped.$hookmanager->resPrint;
2944 $sql .= $hookmanager->resPrint;
2949 $sql .=
", (SELECT " . $this->db->prefix() .
"categorie_product.fk_categorie
2950 FROM " . $this->db->prefix() .
"categorie_product
2951 WHERE " . $this->db->prefix() .
"categorie_product.fk_product=p.rowid
2953 ) AS categorie_product_id ";
2958 $sql .=
', pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,';
2959 $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';
2960 $selectFields .=
", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custdefault_vat_code, custref";
2964 $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";
2965 $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';
2970 $sql .=
", pl.label as label_translated";
2971 $sql .=
", pl.description as description_translated";
2972 $selectFields .=
", label_translated";
2973 $selectFields .=
", description_translated";
2977 $sql .=
", (SELECT pp.rowid FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
2978 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
2979 $sql .=
" AND price_level = " . ((int) $price_level);
2981 $sql .=
" ORDER BY date_price";
2982 $sql .=
" DESC LIMIT 1) as price_rowid";
2983 $sql .=
", (SELECT pp.price_by_qty FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
2984 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
2985 $sql .=
" AND price_level = " . ((int) $price_level);
2987 $sql .=
" ORDER BY date_price";
2988 $sql .=
" DESC LIMIT 1) as price_by_qty";
2989 $selectFields .=
", price_rowid, price_by_qty";
2992 $sql .=
" FROM ".$this->db->prefix().
"product as p";
2995 $sql .=
" USE INDEX (" . $this->db->sanitize(
getDolGlobalString(
'MAIN_PRODUCT_FORCE_INDEX')) .
")";
2999 $parameters = array();
3000 $reshook = $hookmanager->executeHooks(
'selectProductsListFrom', $parameters);
3001 $sql .= $hookmanager->resPrint;
3003 if (count($warehouseStatusArray)) {
3004 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_stock as ps on ps.fk_product = p.rowid";
3005 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entrepot as e on ps.fk_entrepot = e.rowid AND e.entity IN (" .
getEntity(
'stock') .
")";
3006 $sql .=
' AND e.statut IN (' . $this->db->sanitize($this->db->escape(implode(
',', $warehouseStatusArray))) .
')';
3011 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
3016 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_customer_price as pcp ON pcp.fk_soc=" . ((int) $socid) .
" AND pcp.fk_product=p.rowid";
3020 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
3024 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_lang as pl ON pl.fk_product = p.rowid ";
3026 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
3027 $soc =
new Societe($this->db);
3028 $result = $soc->fetch($socid);
3029 if ($result > 0 && !empty($soc->default_lang)) {
3030 $sql .=
" AND pl.lang = '" . $this->db->escape($soc->default_lang) .
"'";
3032 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3035 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3040 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_attribute_combination pac ON pac.fk_product_child = p.rowid";
3043 $sql .=
' WHERE p.entity IN (' .
getEntity(
'product') .
')';
3046 $sql .=
" AND pac.rowid IS NULL";
3049 if ($finished == 0) {
3050 $sql .=
" AND p.finished = " . ((int) $finished);
3051 } elseif ($finished == 1) {
3052 $sql .=
" AND p.finished = ".((int) $finished);
3055 $sql .=
" AND p.tosell = ".((int) $status);
3057 if ($status_purchase >= 0) {
3058 $sql .=
" AND p.tobuy = " . ((int) $status_purchase);
3061 if (strval($filtertype) !=
'') {
3062 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
3063 } elseif (!isModEnabled(
'product')) {
3064 $sql .=
" AND p.fk_product_type = 1";
3065 } elseif (!isModEnabled(
'service')) {
3066 $sql .=
" AND p.fk_product_type = 0";
3069 if ((
int) $warehouseId > 0) {
3070 $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)";
3074 $parameters = array();
3075 $reshook = $hookmanager->executeHooks(
'selectProductsListWhere', $parameters);
3076 $sql .= $hookmanager->resPrint;
3078 if ($filterkey !=
'') {
3082 $search_crit = explode(
' ', $filterkey);
3084 if (count($search_crit) > 1) {
3087 foreach ($search_crit as $crit) {
3091 $sql .=
"(p.ref LIKE '" . $this->db->escape($prefix . $crit) .
"%' OR p.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3093 $sql .=
" OR pl.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3096 $sql .=
" OR pcp.ref_customer LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3099 $sql .=
" OR p.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3101 $sql .=
" OR pl.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3105 $sql .=
" OR pfp.ref_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3110 if (count($search_crit) > 1) {
3113 if (isModEnabled(
'barcode')) {
3114 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3118 if (count($warehouseStatusArray)) {
3119 $sql .=
" GROUP BY " . $selectFields;
3124 $sql .=
" ORDER BY categorie_product_id ";
3126 (
getDolGlobalInt(
'PRODUCT_SORT_BY_CATEGORY') == 1) ? $sql .=
"ASC" : $sql .=
"DESC";
3128 $sql .= $this->db->order(
"p.ref");
3131 $sql .= $this->db->plimit($limit, 0);
3134 dol_syslog(get_class($this) .
"::select_produits_list search products", LOG_DEBUG);
3135 $result = $this->db->query($sql);
3137 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3138 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3139 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
3141 $num = $this->db->num_rows($result);
3146 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3150 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
3156 if ($showempty && !is_numeric($showempty)) {
3157 $textifempty = $langs->trans($showempty);
3159 $textifempty .= $langs->trans(
"All");
3162 if ($showempty && !is_numeric($showempty)) {
3163 $textifempty = $langs->trans($showempty);
3167 $out .=
'<option value="-1" selected>' . ($textifempty ? $textifempty :
' ') .
'</option>';
3171 while ($num && $i < $num) {
3174 $objp = $this->db->fetch_object($result);
3176 if ((
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1) {
3177 $sql =
"SELECT rowid, quantity, price, unitprice, remise_percent, remise, price_base_type";
3178 $sql .=
" FROM " . $this->db->prefix() .
"product_price_by_qty";
3179 $sql .=
" WHERE fk_product_price = " . ((int) $objp->price_rowid);
3180 $sql .=
" ORDER BY quantity ASC";
3182 dol_syslog(get_class($this) .
"::select_produits_list search prices by qty", LOG_DEBUG);
3183 $result2 = $this->db->query($sql);
3185 $nb_prices = $this->db->num_rows($result2);
3187 while ($nb_prices && $j < $nb_prices) {
3188 $objp2 = $this->db->fetch_object($result2);
3190 $objp->price_by_qty_rowid = $objp2->rowid;
3191 $objp->price_by_qty_price_base_type = $objp2->price_base_type;
3192 $objp->price_by_qty_quantity = $objp2->quantity;
3193 $objp->price_by_qty_unitprice = $objp2->unitprice;
3194 $objp->price_by_qty_remise_percent = $objp2->remise_percent;
3196 $objp->quantity = $objp2->quantity;
3197 $objp->price = $objp2->price;
3198 $objp->unitprice = $objp2->unitprice;
3199 $objp->remise_percent = $objp2->remise_percent;
3205 '@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';
3212 array_push($outarray, $optJson);
3216 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_price_expression)) {
3217 $price_product =
new Product($this->db);
3218 $price_product->fetch($objp->rowid,
'',
'', 1);
3220 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3222 $price_result = $priceparser->parseProduct($price_product);
3223 if ($price_result >= 0) {
3224 $objp->price = $price_result;
3225 $objp->unitprice = $price_result;
3227 $objp->price_ttc = (float)
price2num($objp->price) * (1 + ($objp->tva_tx / 100));
3228 $objp->price_ttc =
price2num($objp->price_ttc,
'MU');
3231 if (
getDolGlobalInt(
'PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES') && !empty($objp->custprice)) {
3239 array_push($outarray, $optJson);
3245 $out .=
'</select>';
3247 $this->db->free($result);
3249 if (empty($outputmode)) {
3276 protected function constructProductListOption(&$objp, &$opt, &$optJson, $price_level, $selected, $hidepriceinlabel = 0, $filterkey =
'', $novirtualstock = 0)
3278 global $langs,
$conf, $user;
3279 global $hookmanager;
3285 $outlabel_translated =
'';
3287 $outdesc_translated =
'';
3293 $outpricebasetype =
'';
3295 $outdefault_vat_code =
'';
3299 $maxlengtharticle = (!
getDolGlobalString(
'PRODUCT_MAX_LENGTH_COMBO') ? 48 :
$conf->global->PRODUCT_MAX_LENGTH_COMBO);
3301 $label = $objp->label;
3302 if (!empty($objp->label_translated)) {
3303 $label = $objp->label_translated;
3305 if (!empty($filterkey) && $filterkey !=
'') {
3306 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
3309 $outkey = $objp->rowid;
3310 $outref = $objp->ref;
3311 $outrefcust = empty($objp->custref) ?
'' : $objp->custref;
3312 $outlabel = $objp->label;
3313 $outdesc = $objp->description;
3315 $outlabel_translated = $objp->label_translated;
3316 $outdesc_translated = $objp->description_translated;
3318 $outbarcode = $objp->barcode;
3319 $outorigin = $objp->fk_country;
3320 $outpbq = empty($objp->price_by_qty_rowid) ?
'' : $objp->price_by_qty_rowid;
3322 $outtype = $objp->fk_product_type;
3327 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
3333 if (!empty($objp->unit_short)) {
3334 $outvalUnits .=
' - ' . $objp->unit_short;
3338 if (!empty($objp->weight) && $objp->weight_units !==
null) {
3340 $outvalUnits .=
' - ' . $unitToShow;
3342 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
3343 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
3344 $outvalUnits .=
' - ' . $unitToShow;
3346 if (!empty($objp->surface) && $objp->surface_units !==
null) {
3348 $outvalUnits .=
' - ' . $unitToShow;
3350 if (!empty($objp->volume) && $objp->volume_units !==
null) {
3352 $outvalUnits .=
' - ' . $unitToShow;
3355 if ($outdurationvalue && $outdurationunit) {
3357 'h' => $langs->trans(
'Hour'),
3358 'd' => $langs->trans(
'Day'),
3359 'w' => $langs->trans(
'Week'),
3360 'm' => $langs->trans(
'Month'),
3361 'y' => $langs->trans(
'Year')
3363 if (isset($da[$outdurationunit])) {
3364 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
3371 if ($user->hasRight(
'stock',
'lire')) {
3372 if ($objp->stock > 0) {
3374 } elseif ($objp->stock <= 0) {
3382 $labeltoshow .= $objp->ref;
3383 if (!empty($objp->custref)) {
3384 $labeltoshow .=
' (' . $objp->custref .
')';
3387 $labeltoshow .=
' (' . $outbarcode .
')';
3389 $labeltoshow .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3391 $labeltoshow .=
' (' .
getCountry($outorigin,
'1') .
')';
3395 $labeltoshowhtml =
'';
3396 $labeltoshowhtml .= $objp->ref;
3397 if (!empty($objp->custref)) {
3398 $labeltoshowhtml .=
' (' . $objp->custref .
')';
3400 if (!empty($filterkey) && $filterkey !=
'') {
3401 $labeltoshowhtml = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $labeltoshowhtml, 1);
3404 $labeltoshowhtml .=
' (' . $outbarcode .
')';
3406 $labeltoshowhtml .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3408 $labeltoshowhtml .=
' (' .
getCountry($outorigin,
'1') .
')';
3412 $labeltoshowstock =
'';
3413 $labeltoshowhtmlstock =
'';
3415 if ($user->hasRight(
'stock',
'lire')) {
3416 $labeltoshowstock .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
3418 if ($objp->stock > 0) {
3419 $labeltoshowhtmlstock .=
' - <span class="product_line_stock_ok">';
3420 } elseif ($objp->stock <= 0) {
3421 $labeltoshowhtmlstock .=
' - <span class="product_line_stock_too_low">';
3423 $labeltoshowhtmlstock .= $langs->transnoentities(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
3424 $labeltoshowhtmlstock .=
'</span>';
3426 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
3427 $langs->load(
"stocks");
3429 $tmpproduct =
new Product($this->db);
3430 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
3431 $tmpproduct->load_virtual_stock();
3432 $virtualstock = $tmpproduct->stock_theorique;
3434 $labeltoshowstock .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
3436 $labeltoshowhtmlstock .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
3437 if ($virtualstock > 0) {
3438 $labeltoshowhtmlstock .=
'<span class="product_line_stock_ok">';
3439 } elseif ($virtualstock <= 0) {
3440 $labeltoshowhtmlstock .=
'<span class="product_line_stock_too_low">';
3442 $labeltoshowhtmlstock .= $virtualstock;
3443 $labeltoshowhtmlstock .=
'</span>';
3452 $labeltoshowprice =
'';
3453 $labeltoshowhtmlprice =
'';
3456 $sql =
"SELECT price, price_ttc, price_base_type, tva_tx, default_vat_code";
3457 $sql .=
" FROM " . $this->db->prefix() .
"product_price";
3458 $sql .=
" WHERE fk_product = " . ((int) $objp->rowid);
3459 $sql .=
" AND entity IN (" .
getEntity(
'productprice') .
")";
3460 $sql .=
" AND price_level = " . ((int) $price_level);
3461 $sql .=
" ORDER BY date_price DESC, rowid DESC";
3464 dol_syslog(get_class($this) .
'::constructProductListOption search price for product ' . $objp->rowid .
' AND level ' . $price_level, LOG_DEBUG);
3465 $result2 = $this->db->query($sql);
3467 $objp2 = $this->db->fetch_object($result2);
3470 if ($objp2->price_base_type ==
'HT') {
3471 $labeltoshowprice .=
' - ' .
price($objp2->price, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
3472 $labeltoshowhtmlprice .=
' - ' .
price($objp2->price, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
3474 $labeltoshowprice .=
' - ' .
price($objp2->price_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
3475 $labeltoshowhtmlprice .=
' - ' .
price($objp2->price_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3477 $outprice_ht =
price($objp2->price);
3478 $outprice_ttc =
price($objp2->price_ttc);
3479 $outpricebasetype = $objp2->price_base_type;
3481 $outtva_tx = $objp2->tva_tx;
3482 $outdefault_vat_code = $objp2->default_vat_code;
3484 $outtva_tx = $objp->tva_tx;
3485 $outdefault_vat_code = $objp->default_vat_code;
3494 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1 && (
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
3496 $outqty = $objp->quantity;
3497 $outdiscount = $objp->remise_percent;
3498 if ($objp->quantity == 1) {
3499 $labeltoshowprice .=
' - ' .
price($objp->unitprice, 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
3500 $labeltoshowhtmlprice .=
' - ' .
price($objp->unitprice, 0, $langs, 0, 0, -1,
$conf->currency) .
"/";
3501 $labeltoshowprice .= $langs->trans(
"Unit");
3502 $labeltoshowhtmlprice .= $langs->transnoentities(
"Unit");
3504 $labeltoshowprice .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
3505 $labeltoshowhtmlprice .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
3506 $labeltoshowprice .= $langs->trans(
"Units");
3507 $labeltoshowhtmlprice .= $langs->transnoentities(
"Units");
3510 $outprice_ht =
price($objp->unitprice);
3511 $outprice_ttc =
price($objp->unitprice * (1 + ($objp->tva_tx / 100)));
3512 $outpricebasetype = $objp->price_base_type;
3513 $outtva_tx = $objp->tva_tx;
3514 $outdefault_vat_code = $objp->default_vat_code;
3516 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1) {
3517 $labeltoshowprice .=
" (" .
price($objp->unitprice, 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->trans(
"Unit") .
")";
3518 $labeltoshowhtmlprice .=
" (" .
price($objp->unitprice, 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->transnoentities(
"Unit") .
")";
3520 if (empty($hidepriceinlabel) && !empty($objp->remise_percent) && $objp->remise_percent >= 1) {
3521 $labeltoshowprice .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3522 $labeltoshowhtmlprice .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3527 if (!empty($objp->idprodcustprice)) {
3530 if ($objp->custprice_base_type ==
'HT') {
3531 $labeltoshowprice .=
' - ' .
price($objp->custprice, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
3532 $labeltoshowhtmlprice .=
' - ' .
price($objp->custprice, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
3534 $labeltoshowprice .=
' - ' .
price($objp->custprice_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
3535 $labeltoshowhtmlprice .=
' - ' .
price($objp->custprice_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3538 $outprice_ht =
price($objp->custprice);
3539 $outprice_ttc =
price($objp->custprice_ttc);
3540 $outpricebasetype = $objp->custprice_base_type;
3541 $outtva_tx = $objp->custtva_tx;
3542 $outdefault_vat_code = $objp->custdefault_vat_code;
3547 if (empty($hidepriceinlabel) && !$found) {
3548 if ($objp->price_base_type ==
'HT') {
3549 $labeltoshowprice .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
3550 $labeltoshowhtmlprice .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
3552 $labeltoshowprice .=
' - ' .
price($objp->price_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
3553 $labeltoshowhtmlprice .=
' - ' .
price($objp->price_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3555 $outprice_ht =
price($objp->price);
3556 $outprice_ttc =
price($objp->price_ttc);
3557 $outpricebasetype = $objp->price_base_type;
3558 $outtva_tx = $objp->tva_tx;
3559 $outdefault_vat_code = $objp->default_vat_code;
3563 $opt =
'<option value="' . $objp->rowid .
'"';
3564 $opt .= ($objp->rowid == $selected) ?
' selected' :
'';
3565 if (!empty($objp->price_by_qty_rowid) && $objp->price_by_qty_rowid > 0) {
3566 $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 .
'"';
3569 $opt .=
' data-labeltrans="' . $outlabel_translated .
'"';
3573 if ($stocktag == 1) {
3574 $opt .=
' class="product_line_stock_ok" data-html="'.$labeltoshowhtml.$outvalUnits.$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
3577 if ($stocktag == -1) {
3578 $opt .=
' class="product_line_stock_too_low" data-html="'.$labeltoshowhtml.$outvalUnits.$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
3585 $opt .= $labeltoshow;
3586 $outval .= $labeltoshowhtml;
3589 $opt .= $outvalUnits;
3590 $outval .= $outvalUnits;
3593 $opt .= $labeltoshowprice;
3594 $outval .= $labeltoshowhtmlprice;
3597 $opt .= $labeltoshowstock;
3598 $outval .= $labeltoshowhtmlstock;
3601 $parameters = array(
'objp' => $objp);
3602 $reshook = $hookmanager->executeHooks(
'constructProductListOption', $parameters);
3603 if (empty($reshook)) {
3604 $opt .= $hookmanager->resPrint;
3606 $opt = $hookmanager->resPrint;
3609 $opt .=
"</option>\n";
3614 'label2' => $outlabel,
3618 'price_ttc' =>
price2num($outprice_ttc),
3621 'pricebasetype' => $outpricebasetype,
3622 'tva_tx' => $outtva_tx,
3623 'default_vat_code' => $outdefault_vat_code,
3625 'discount' => $outdiscount,
3626 'duration_value' => $outdurationvalue,
3627 'duration_unit' => $outdurationunit,
3629 'labeltrans' => $outlabel_translated,
3630 'desctrans' => $outdesc_translated,
3631 'ref_customer' => $outrefcust
3652 public function select_produits_fournisseurs($socid, $selected =
'', $htmlname =
'productid', $filtertype =
'', $filtre =
'', $ajaxoptions = array(), $hidelabel = 0, $alsoproductwithnosupplierprice = 0, $morecss =
'', $placeholder =
'')
3655 global $langs,
$conf;
3656 global $price_level, $status, $finished;
3658 if (!isset($status)) {
3662 $selected_input_value =
'';
3664 if ($selected > 0) {
3665 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3666 $producttmpselect =
new Product($this->db);
3667 $producttmpselect->fetch($selected);
3668 $selected_input_value = $producttmpselect->ref;
3669 unset($producttmpselect);
3673 $urloption = ($socid > 0 ?
'socid=' . $socid .
'&' :
'') .
'htmlname=' . $htmlname .
'&outjson=1&price_level=' . $price_level .
'&type=' . $filtertype .
'&mode=2&status=' . $status .
'&finished=' . $finished .
'&alsoproductwithnosupplierprice=' . $alsoproductwithnosupplierprice;
3674 print
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT .
'/product/ajax/products.php', $urloption,
getDolGlobalInt(
'PRODUIT_USE_SEARCH_TO_SELECT'), 0, $ajaxoptions);
3676 print($hidelabel ?
'' : $langs->trans(
"RefOrLabel") .
' : ') .
'<input type="text" class="'.$morecss.
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . ($placeholder ?
' placeholder="' . $placeholder .
'"' :
'') .
'>';
3678 print $this->
select_produits_fournisseurs_list($socid, $selected, $htmlname, $filtertype, $filtre,
'', $status, 0, 0, $alsoproductwithnosupplierprice, $morecss, 0, $placeholder);
3702 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 =
'')
3705 global $langs,
$conf, $user;
3706 global $hookmanager;
3709 $outarray = array();
3711 $maxlengtharticle = (!
getDolGlobalString(
'PRODUCT_MAX_LENGTH_COMBO') ? 48 :
$conf->global->PRODUCT_MAX_LENGTH_COMBO);
3713 $langs->load(
'stocks');
3716 $langs->load(
'other');
3719 $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,";
3720 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice, pfp.barcode";
3721 $sql .=
", pfp.multicurrency_code, pfp.multicurrency_unitprice";
3722 $sql .=
", pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.default_vat_code, pfp.fk_soc, s.nom as name";
3723 $sql .=
", pfp.supplier_reputation";
3726 $sql .=
", pfp.desc_fourn as description";
3728 $sql .=
", p.description";
3732 $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";
3734 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
3735 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN (" .
getEntity(
'product') .
") )";
3737 $sql .=
" AND pfp.fk_soc = " . ((int) $socid);
3739 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
3742 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
3744 $sql .=
" WHERE p.entity IN (" .
getEntity(
'product') .
")";
3745 if ($statut != -1) {
3746 $sql .=
" AND p.tobuy = " . ((int) $statut);
3748 if (strval($filtertype) !=
'') {
3749 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
3751 if (!empty($filtre)) {
3752 $sql .=
" " . $filtre;
3755 $parameters = array();
3756 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListWhere', $parameters);
3757 $sql .= $hookmanager->resPrint;
3759 if ($filterkey !=
'') {
3763 $search_crit = explode(
' ', $filterkey);
3765 if (count($search_crit) > 1) {
3768 foreach ($search_crit as $crit) {
3772 $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) .
"%'";
3774 $sql .=
" OR pfp.desc_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3779 if (count($search_crit) > 1) {
3782 if (isModEnabled(
'barcode')) {
3783 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3784 $sql .=
" OR pfp.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3788 $sql .=
" ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC";
3789 $sql .= $this->db->plimit($limit, 0);
3793 dol_syslog(get_class($this) .
"::select_produits_fournisseurs_list", LOG_DEBUG);
3794 $result = $this->db->query($sql);
3796 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3797 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
3799 $num = $this->db->num_rows($result);
3802 $out .=
'<select class="flat ' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'">';
3804 $out .=
'<option value="-1" selected>' . ($placeholder ? $placeholder :
' ') .
'</option>';
3806 $out .=
'<option value="-1">' . ($placeholder ? $placeholder :
' ') .
'</option>';
3811 $objp = $this->db->fetch_object($result);
3813 if (is_null($objp->idprodfournprice)) {
3815 $objp->tva_tx = $objp->tva_tx_sale;
3816 $objp->default_vat_code = $objp->default_vat_code_sale;
3819 $outkey = $objp->idprodfournprice;
3820 if (!$outkey && $alsoproductwithnosupplierprice) {
3821 $outkey =
'idprod_' . $objp->rowid;
3824 $outref = $objp->ref;
3825 $outbarcode = $objp->barcode;
3828 $outtype = $objp->fk_product_type;
3835 if (!empty($objp->unit_short)) {
3836 $outvalUnits .=
' - ' . $objp->unit_short;
3838 if (!empty($objp->weight) && $objp->weight_units !==
null) {
3840 $outvalUnits .=
' - ' . $unitToShow;
3842 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
3843 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
3844 $outvalUnits .=
' - ' . $unitToShow;
3846 if (!empty($objp->surface) && $objp->surface_units !==
null) {
3848 $outvalUnits .=
' - ' . $unitToShow;
3850 if (!empty($objp->volume) && $objp->volume_units !==
null) {
3852 $outvalUnits .=
' - ' . $unitToShow;
3854 if ($outdurationvalue && $outdurationunit) {
3856 'h' => $langs->trans(
'Hour'),
3857 'd' => $langs->trans(
'Day'),
3858 'w' => $langs->trans(
'Week'),
3859 'm' => $langs->trans(
'Month'),
3860 'y' => $langs->trans(
'Year')
3862 if (isset($da[$outdurationunit])) {
3863 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
3868 $objRef = $objp->ref;
3869 if ($filterkey && $filterkey !=
'') {
3870 $objRef = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRef, 1);
3872 $objRefFourn = $objp->ref_fourn;
3873 if ($filterkey && $filterkey !=
'') {
3874 $objRefFourn = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRefFourn, 1);
3876 $label = $objp->label;
3877 if ($filterkey && $filterkey !=
'') {
3878 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
3881 switch ($objp->fk_product_type) {
3893 if (empty($picto)) {
3896 $optlabel =
img_object(
'', $picto,
'class="paddingright classfortooltip"', 0, 0, 1);
3899 $optlabel .= $objp->ref;
3900 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
3901 $optlabel .=
' <span class="opacitymedium">(' . $objp->ref_fourn .
')</span>';
3903 if (isModEnabled(
'barcode') && !empty($objp->barcode)) {
3904 $optlabel .=
' (' . $outbarcode .
')';
3906 $optlabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3908 $outvallabel = $objRef;
3909 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
3910 $outvallabel .=
' (' . $objRefFourn .
')';
3912 if (isModEnabled(
'barcode') && !empty($objp->barcode)) {
3913 $outvallabel .=
' (' . $outbarcode .
')';
3915 $outvallabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3918 $optlabel .= $outvalUnits;
3919 $outvallabel .= $outvalUnits;
3921 if (!empty($objp->idprodfournprice)) {
3922 $outqty = $objp->quantity;
3923 $outdiscount = $objp->remise_percent;
3924 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
3926 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
3927 $prod_supplier->id = $objp->fk_product;
3928 $prod_supplier->fourn_qty = $objp->quantity;
3929 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
3930 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
3932 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3934 $price_result = $priceparser->parseProductSupplier($prod_supplier);
3935 if ($price_result >= 0) {
3936 $objp->fprice = $price_result;
3937 if ($objp->quantity >= 1) {
3938 $objp->unitprice = $objp->fprice / $objp->quantity;
3942 if ($objp->quantity == 1) {
3943 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
3944 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1,
$conf->currency) .
"/";
3945 $optlabel .= $langs->trans(
"Unit");
3946 $outvallabel .= $langs->transnoentities(
"Unit");
3948 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
3949 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
3950 $optlabel .=
' ' . $langs->trans(
"Units");
3951 $outvallabel .=
' ' . $langs->transnoentities(
"Units");
3954 if ($objp->quantity > 1) {
3955 $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") .
")";
3956 $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") .
")";
3958 if ($objp->remise_percent >= 1) {
3959 $optlabel .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3960 $outvallabel .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3962 if ($objp->duration) {
3963 $optlabel .=
" - " . $objp->duration;
3964 $outvallabel .=
" - " . $objp->duration;
3967 $optlabel .=
" - " .
dol_trunc($objp->name, 8);
3968 $outvallabel .=
" - " .
dol_trunc($objp->name, 8);
3970 if ($objp->supplier_reputation) {
3972 $reputations = array(
'' => $langs->trans(
'Standard'),
'FAVORITE' => $langs->trans(
'Favorite'),
'NOTTHGOOD' => $langs->trans(
'NotTheGoodQualitySupplier'),
'DONOTORDER' => $langs->trans(
'DoNotOrderThisProductToThisSupplier'));
3974 $optlabel .=
" - " . $reputations[$objp->supplier_reputation];
3975 $outvallabel .=
" - " . $reputations[$objp->supplier_reputation];
3978 $optlabel .=
" - <span class='opacitymedium'>" . $langs->trans(
"NoPriceDefinedForThisSupplier") .
'</span>';
3979 $outvallabel .=
' - ' . $langs->transnoentities(
"NoPriceDefinedForThisSupplier");
3983 $novirtualstock = ($showstockinlist == 2);
3985 if ($user->hasRight(
'stock',
'lire')) {
3986 $outvallabel .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
3988 if ($objp->stock > 0) {
3989 $optlabel .=
' - <span class="product_line_stock_ok">';
3990 } elseif ($objp->stock <= 0) {
3991 $optlabel .=
' - <span class="product_line_stock_too_low">';
3993 $optlabel .= $langs->transnoentities(
"Stock") .
':' .
price(
price2num($objp->stock,
'MS'));
3994 $optlabel .=
'</span>';
3995 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
3996 $langs->load(
"stocks");
3998 $tmpproduct =
new Product($this->db);
3999 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
4000 $tmpproduct->load_virtual_stock();
4001 $virtualstock = $tmpproduct->stock_theorique;
4003 $outvallabel .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
4005 $optlabel .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
4006 if ($virtualstock > 0) {
4007 $optlabel .=
'<span class="product_line_stock_ok">';
4008 } elseif ($virtualstock <= 0) {
4009 $optlabel .=
'<span class="product_line_stock_too_low">';
4011 $optlabel .= $virtualstock;
4012 $optlabel .=
'</span>';
4019 $optstart =
'<option value="' . $outkey .
'"';
4020 if ($selected && $selected == $objp->idprodfournprice) {
4021 $optstart .=
' selected';
4023 if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) {
4024 $optstart .=
' disabled';
4027 if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) {
4036 $optstart .=
' data-default-vat-code="' .
dol_escape_htmltag($objp->default_vat_code) .
'"';
4038 if (isModEnabled(
'multicurrency')) {
4039 $optstart .=
' data-multicurrency-code="' .
dol_escape_htmltag($objp->multicurrency_code) .
'"';
4040 $optstart .=
' data-multicurrency-unitprice="' .
dol_escape_htmltag($objp->multicurrency_unitprice) .
'"';
4043 $optstart .=
' data-description="' .
dol_escape_htmltag($objp->description, 0, 1) .
'"';
4046 $outarrayentry = array(
4049 'label' => $outvallabel,
4050 'labelhtml' => $optlabel,
4052 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4053 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4054 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4055 'tva_tx_formated' =>
price($objp->tva_tx, 0, $langs, 1, -1, 2),
4057 'default_vat_code' => $objp->default_vat_code,
4058 'supplier_ref' => $objp->ref_fourn,
4059 'discount' => $outdiscount,
4061 'duration_value' => $outdurationvalue,
4062 'duration_unit' => $outdurationunit,
4063 'disabled' => empty($objp->idprodfournprice),
4064 'description' => $objp->description
4066 if (isModEnabled(
'multicurrency')) {
4067 $outarrayentry[
'multicurrency_code'] = $objp->multicurrency_code;
4068 $outarrayentry[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4070 $parameters = array(
4072 'optstart' => &$optstart,
4073 'optlabel' => &$optlabel,
4074 'outvallabel' => &$outvallabel,
4075 'outarrayentry' => &$outarrayentry,
4078 $reshook = $hookmanager->executeHooks(
'selectProduitsFournisseurListOption', $parameters, $this);
4084 $out .= $optstart .
' data-html="' .
dol_escape_htmltag($optlabel) .
'">' . $optlabel .
"</option>\n";
4085 $outarraypush = array(
4088 'label' => $outvallabel,
4089 'labelhtml' => $optlabel,
4091 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4092 'price_qty_ht_locale' =>
price($objp->fprice),
4093 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4094 'price_unit_ht_locale' =>
price($objp->unitprice),
4095 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4096 'tva_tx_formated' =>
price($objp->tva_tx),
4098 'default_vat_code' => $objp->default_vat_code,
4099 'supplier_ref' => $objp->ref_fourn,
4100 'discount' => $outdiscount,
4102 'duration_value' => $outdurationvalue,
4103 'duration_unit' => $outdurationunit,
4104 'disabled' => empty($objp->idprodfournprice),
4105 'description' => $objp->description
4107 if (isModEnabled(
'multicurrency')) {
4108 $outarraypush[
'multicurrency_code'] = $objp->multicurrency_code;
4109 $outarraypush[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4111 array_push($outarray, $outarraypush);
4124 $out .=
'</select>';
4126 $this->db->free($result);
4128 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
4134 if (empty($outputmode)) {
4153 global $langs,
$conf;
4155 $langs->load(
'stocks');
4157 $sql =
"SELECT p.rowid, p.ref, p.label, p.price, p.duration, pfp.fk_soc,";
4158 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.remise_percent, pfp.quantity, pfp.unitprice,";
4159 $sql .=
" pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name";
4160 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
4161 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
4162 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
4163 $sql .=
" WHERE pfp.entity IN (" .
getEntity(
'productsupplierprice') .
")";
4164 $sql .=
" AND p.tobuy = 1";
4165 $sql .=
" AND s.fournisseur = 1";
4166 $sql .=
" AND p.rowid = " . ((int) $productid);
4168 $sql .=
" ORDER BY s.nom, pfp.ref_fourn DESC";
4170 $sql .=
" ORDER BY pfp.unitprice ASC";
4173 dol_syslog(get_class($this) .
"::select_product_fourn_price", LOG_DEBUG);
4174 $result = $this->db->query($sql);
4177 $num = $this->db->num_rows($result);
4179 $form =
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
4182 $form .=
'<option value="0">-- ' . $langs->trans(
"NoSupplierPriceDefinedForThisProduct") .
' --</option>';
4184 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4185 $form .=
'<option value="0"> </option>';
4189 $objp = $this->db->fetch_object($result);
4191 $opt =
'<option value="' . $objp->idprodfournprice .
'"';
4193 if ($num == 1 || ($selected_supplier > 0 && $objp->fk_soc == $selected_supplier) || ($i == 0 &&
getDolGlobalString(
'PRODUCT_BEST_SUPPLIER_PRICE_PRESELECTED'))) {
4194 $opt .=
' selected';
4196 $opt .=
'>' . $objp->name .
' - ' . $objp->ref_fourn .
' - ';
4198 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
4200 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
4201 $prod_supplier->id = $productid;
4202 $prod_supplier->fourn_qty = $objp->quantity;
4203 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
4204 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
4206 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4208 $price_result = $priceparser->parseProductSupplier($prod_supplier);
4209 if ($price_result >= 0) {
4210 $objp->fprice = $price_result;
4211 if ($objp->quantity >= 1) {
4212 $objp->unitprice = $objp->fprice / $objp->quantity;
4216 if ($objp->quantity == 1) {
4217 $opt .=
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
4220 $opt .= $objp->quantity .
' ';
4222 if ($objp->quantity == 1) {
4223 $opt .= $langs->trans(
"Unit");
4225 $opt .= $langs->trans(
"Units");
4227 if ($objp->quantity > 1) {
4229 $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");
4231 if ($objp->duration) {
4232 $opt .=
" - " . $objp->duration;
4234 $opt .=
"</option>\n";
4241 $form .=
'</select>';
4242 $this->db->free($result);
4262 $num = count($this->cache_conditions_paiements);
4269 $sql =
"SELECT rowid, code, libelle as label, deposit_percent";
4270 $sql .=
" FROM " . $this->db->prefix() .
'c_payment_term';
4271 $sql .=
" WHERE entity IN (" .
getEntity(
'c_payment_term') .
")";
4272 $sql .=
" AND active > 0";
4273 $sql .=
" ORDER BY sortorder";
4275 $resql = $this->db->query($sql);
4277 $num = $this->db->num_rows($resql);
4280 $obj = $this->db->fetch_object($resql);
4283 $label = ($langs->trans(
"PaymentConditionShort" . $obj->code) !=
"PaymentConditionShort" . $obj->code ? $langs->trans(
"PaymentConditionShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4284 $this->cache_conditions_paiements[$obj->rowid][
'code'] = $obj->code;
4285 $this->cache_conditions_paiements[$obj->rowid][
'label'] = $label;
4286 $this->cache_conditions_paiements[$obj->rowid][
'deposit_percent'] = $obj->deposit_percent;
4311 $num = count($this->cache_availability);
4318 $langs->load(
'propal');
4320 $sql =
"SELECT rowid, code, label, position";
4321 $sql .=
" FROM " . $this->db->prefix() .
'c_availability';
4322 $sql .=
" WHERE active > 0";
4324 $resql = $this->db->query($sql);
4326 $num = $this->db->num_rows($resql);
4329 $obj = $this->db->fetch_object($resql);
4332 $label = ($langs->trans(
"AvailabilityType" . $obj->code) !=
"AvailabilityType" . $obj->code ? $langs->trans(
"AvailabilityType" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4333 $this->cache_availability[$obj->rowid][
'code'] = $obj->code;
4334 $this->cache_availability[$obj->rowid][
'label'] = $label;
4335 $this->cache_availability[$obj->rowid][
'position'] = $obj->position;
4339 $this->cache_availability =
dol_sort_array($this->cache_availability,
'position',
'asc', 0, 0, 1);
4360 global $langs, $user;
4364 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
4366 print
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4368 print
'<option value="0"> </option>';
4370 foreach ($this->cache_availability as
$id => $arrayavailability) {
4371 if ($selected ==
$id) {
4372 print
'<option value="' .
$id .
'" selected>';
4374 print
'<option value="' .
$id .
'">';
4381 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4395 $num = count($this->cache_demand_reason);
4400 $sql =
"SELECT rowid, code, label";
4401 $sql .=
" FROM " . $this->db->prefix() .
'c_input_reason';
4402 $sql .=
" WHERE active > 0";
4404 $resql = $this->db->query($sql);
4406 $num = $this->db->num_rows($resql);
4408 $tmparray = array();
4410 $obj = $this->db->fetch_object($resql);
4413 $label = ($obj->label !=
'-' ? $obj->label :
'');
4414 if ($langs->trans(
"DemandReasonType" . $obj->code) !=
"DemandReasonType" . $obj->code) {
4415 $label = $langs->trans(
"DemandReasonType" . $obj->code);
4417 if ($langs->trans($obj->code) != $obj->code) {
4418 $label = $langs->trans($obj->code);
4421 $tmparray[$obj->rowid][
'id'] = $obj->rowid;
4422 $tmparray[$obj->rowid][
'code'] = $obj->code;
4423 $tmparray[$obj->rowid][
'label'] = $label;
4427 $this->cache_demand_reason =
dol_sort_array($tmparray,
'label',
'asc', 0, 0, 1);
4449 public function selectInputReason($selected =
'', $htmlname =
'demandreasonid', $exclude =
'', $addempty = 0, $morecss =
'', $notooltip = 0)
4451 global $langs, $user;
4455 print
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
4457 print
'<option value="0"' . (empty($selected) ?
' selected' :
'') .
'> </option>';
4459 foreach ($this->cache_demand_reason as
$id => $arraydemandreason) {
4460 if ($arraydemandreason[
'code'] == $exclude) {
4464 if ($selected && ($selected == $arraydemandreason[
'id'] || $selected == $arraydemandreason[
'code'])) {
4465 print
'<option value="' . $arraydemandreason[
'id'] .
'" selected>';
4467 print
'<option value="' . $arraydemandreason[
'id'] .
'">';
4469 $label = $arraydemandreason[
'label'];
4470 print $langs->trans($label);
4474 if ($user->admin && empty($notooltip)) {
4475 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4492 $num = count($this->cache_types_paiements);
4499 $this->cache_types_paiements = array();
4501 $sql =
"SELECT id, code, libelle as label, type, active";
4502 $sql .=
" FROM " . $this->db->prefix() .
"c_paiement";
4503 $sql .=
" WHERE entity IN (" .
getEntity(
'c_paiement') .
")";
4505 $resql = $this->db->query($sql);
4507 $num = $this->db->num_rows($resql);
4510 $obj = $this->db->fetch_object($resql);
4513 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) !=
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4514 $this->cache_types_paiements[$obj->id][
'id'] = $obj->id;
4515 $this->cache_types_paiements[$obj->id][
'code'] = $obj->code;
4516 $this->cache_types_paiements[$obj->id][
'label'] = $label;
4517 $this->cache_types_paiements[$obj->id][
'type'] = $obj->type;
4518 $this->cache_types_paiements[$obj->id][
'active'] = $obj->active;
4522 $this->cache_types_paiements =
dol_sort_array($this->cache_types_paiements,
'label',
'asc', 0, 0, 1);
4552 public function select_conditions_paiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1, $noprint = 0)
4556 if (empty($noprint)) {
4580 public function getSelectConditionsPaiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1)
4582 global $langs, $user,
$conf;
4585 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
4591 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TERM_ID", LOG_NOTICE);
4595 $out .=
'<select id="' . $htmlname .
'" class="flat selectpaymentterms' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4597 $out .=
'<option value="0"> </option>';
4600 $selectedDepositPercent =
null;
4602 foreach ($this->cache_conditions_paiements as
$id => $arrayconditions) {
4603 if ($filtertype <= 0 && !empty($arrayconditions[
'deposit_percent'])) {
4607 if ($selected ==
$id) {
4608 $selectedDepositPercent = $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'];
4609 $out .=
'<option value="' .
$id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'" selected>';
4611 $out .=
'<option value="' .
$id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'">';
4613 $label = $arrayconditions[
'label'];
4615 if (!empty($arrayconditions[
'deposit_percent'])) {
4616 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'], $label);
4620 $out .=
'</option>';
4622 $out .=
'</select>';
4623 if ($user->admin && empty($noinfoadmin)) {
4624 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4628 if ($deposit_percent >= 0) {
4629 $out .=
' <span id="' . $htmlname .
'_deposit_percent_container"' . (empty($selectedDepositPercent) ?
' style="display: none"' :
'') .
'>';
4630 $out .= $langs->trans(
'DepositPercent') .
' : ';
4631 $out .=
'<input id="' . $htmlname .
'_deposit_percent" name="' . $htmlname .
'_deposit_percent" class="maxwidth50" value="' . $deposit_percent .
'" />';
4634 <script nonce="' .
getNonce() .
'">
4635 $(document).ready(function () {
4636 $("#' . $htmlname .
'").change(function () {
4637 let $selected = $(this).find("option:selected");
4638 let depositPercent = $selected.attr("data-deposit_percent");
4640 if (depositPercent.length > 0) {
4641 $("#' . $htmlname .
'_deposit_percent_container").show().find("#' . $htmlname .
'_deposit_percent").val(depositPercent);
4643 $("#' . $htmlname .
'_deposit_percent_container").hide();
4674 public function select_types_paiements($selected =
'', $htmlname =
'paiementtype', $filtertype =
'', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'', $nooutput = 0)
4677 global $langs, $user,
$conf;
4681 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $filtertype .
", " . $format, LOG_DEBUG);
4683 $filterarray = array();
4684 if ($filtertype ==
'CRDT') {
4685 $filterarray = array(0, 2, 3);
4686 } elseif ($filtertype ==
'DBIT') {
4687 $filterarray = array(1, 2, 3);
4688 } elseif ($filtertype !=
'' && $filtertype !=
'-1') {
4689 $filterarray = explode(
',', $filtertype);
4696 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TYPE_ID", LOG_NOTICE);
4700 $out .=
'<select id="select' . $htmlname .
'" class="flat selectpaymenttypes' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4702 $out .=
'<option value=""> </option>';
4704 foreach ($this->cache_types_paiements as
$id => $arraytypes) {
4706 if ($active >= 0 && $arraytypes[
'active'] != $active) {
4711 if (count($filterarray) && !in_array($arraytypes[
'type'], $filterarray)) {
4716 if ($empty && empty($arraytypes[
'code'])) {
4721 $out .=
'<option value="' .
$id .
'" data-code="'.$arraytypes[
'code'].
'"';
4722 } elseif ($format == 1) {
4723 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
4724 } elseif ($format == 2) {
4725 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
4726 } elseif ($format == 3) {
4727 $out .=
'<option value="' .
$id .
'"';
4730 if ($format == 1 || $format == 2) {
4731 if ($selected == $arraytypes[
'code']) {
4732 $out .=
' selected';
4735 if ($selected ==
$id) {
4736 $out .=
' selected';
4742 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4743 } elseif ($format == 1) {
4744 $value = $arraytypes[
'code'];
4745 } elseif ($format == 2) {
4746 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4747 } elseif ($format == 3) {
4748 $value = $arraytypes[
'code'];
4750 $out .= $value ? $value :
' ';
4751 $out .=
'</option>';
4753 $out .=
'</select>';
4754 if ($user->admin && !$noadmininfo) {
4755 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4759 if (empty($nooutput)) {
4779 $return =
'<select class="flat maxwidth100" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
4781 'HT' => $langs->trans(
"HT"),
4782 'TTC' => $langs->trans(
"TTC")
4784 foreach ($options as
$id => $value) {
4785 if ($selected ==
$id) {
4786 $return .=
'<option value="' .
$id .
'" selected>' . $value;
4788 $return .=
'<option value="' .
$id .
'">' . $value;
4790 $return .=
'</option>';
4792 $return .=
'</select>';
4812 $num = count($this->cache_transport_mode);
4819 $this->cache_transport_mode = array();
4821 $sql =
"SELECT rowid, code, label, active";
4822 $sql .=
" FROM " . $this->db->prefix() .
"c_transport_mode";
4823 $sql .=
" WHERE entity IN (" .
getEntity(
'c_transport_mode') .
")";
4825 $resql = $this->db->query($sql);
4827 $num = $this->db->num_rows($resql);
4830 $obj = $this->db->fetch_object($resql);
4833 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) !=
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4834 $this->cache_transport_mode[$obj->rowid][
'rowid'] = $obj->rowid;
4835 $this->cache_transport_mode[$obj->rowid][
'code'] = $obj->code;
4836 $this->cache_transport_mode[$obj->rowid][
'label'] = $label;
4837 $this->cache_transport_mode[$obj->rowid][
'active'] = $obj->active;
4841 $this->cache_transport_mode =
dol_sort_array($this->cache_transport_mode,
'label',
'asc', 0, 0, 1);
4863 public function selectTransportMode($selected =
'', $htmlname =
'transportmode', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'')
4865 global $langs, $user;
4867 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $format, LOG_DEBUG);
4871 print
'<select id="select' . $htmlname .
'" class="flat selectmodetransport' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4873 print
'<option value=""> </option>';
4875 foreach ($this->cache_transport_mode as
$id => $arraytypes) {
4877 if ($active >= 0 && $arraytypes[
'active'] != $active) {
4882 if ($empty && empty($arraytypes[
'code'])) {
4887 print
'<option value="' .
$id .
'"';
4888 } elseif ($format == 1) {
4889 print
'<option value="' . $arraytypes[
'code'] .
'"';
4890 } elseif ($format == 2) {
4891 print
'<option value="' . $arraytypes[
'code'] .
'"';
4892 } elseif ($format == 3) {
4893 print
'<option value="' .
$id .
'"';
4896 if (preg_match(
'/[a-z]/i', $selected) && $selected == $arraytypes[
'code']) {
4898 } elseif ($selected ==
$id) {
4904 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4905 } elseif ($format == 1) {
4906 $value = $arraytypes[
'code'];
4907 } elseif ($format == 2) {
4908 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4909 } elseif ($format == 3) {
4910 $value = $arraytypes[
'code'];
4912 print $value ? $value :
' ';
4919 if ($user->admin && !$noadmininfo) {
4920 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4936 public function selectShippingMethod($selected =
'', $htmlname =
'shipping_method_id', $filtre =
'', $useempty = 0, $moreattrib =
'', $noinfoadmin = 0, $morecss =
'')
4938 global $langs, $user;
4940 $langs->load(
"admin");
4941 $langs->load(
"deliveries");
4943 $sql =
"SELECT rowid, code, libelle as label";
4944 $sql .=
" FROM " . $this->db->prefix() .
"c_shipment_mode";
4945 $sql .=
" WHERE active > 0";
4947 $sql .=
" AND " . $filtre;
4949 $sql .=
" ORDER BY libelle ASC";
4951 dol_syslog(get_class($this) .
"::selectShippingMode", LOG_DEBUG);
4952 $result = $this->db->query($sql);
4954 $num = $this->db->num_rows($result);
4957 print
'<select id="select' . $htmlname .
'" class="flat selectshippingmethod' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
4958 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
4959 print
'<option value="-1"> </option>';
4962 $obj = $this->db->fetch_object($result);
4963 if ($selected == $obj->rowid) {
4964 print
'<option value="' . $obj->rowid .
'" selected>';
4966 print
'<option value="' . $obj->rowid .
'">';
4968 print ($langs->trans(
"SendingMethod" . strtoupper($obj->code)) !=
"SendingMethod" . strtoupper($obj->code)) ? $langs->trans(
"SendingMethod" . strtoupper($obj->code)) : $obj->label;
4973 if ($user->admin && empty($noinfoadmin)) {
4974 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4979 print $langs->trans(
"NoShippingMethodDefined");
4999 $langs->load(
"deliveries");
5001 if ($htmlname !=
"none") {
5002 print
'<form method="POST" action="' . $page .
'">';
5003 print
'<input type="hidden" name="action" value="setshippingmethod">';
5004 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5006 print
'<input type="submit" class="button valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5010 $code = $langs->getLabelFromKey($this->db, $selected,
'c_shipment_mode',
'rowid',
'code');
5011 print $langs->trans(
"SendingMethod" . strtoupper($code));
5030 $langs->load(
'bills');
5032 $opt =
'<option value="" selected></option>';
5033 $sql =
"SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc";
5034 $sql .=
' FROM ' . $this->db->prefix() .
'facture';
5035 $sql .=
' WHERE entity IN (' .
getEntity(
'invoice') .
')';
5036 $sql .=
' AND situation_counter >= 1';
5037 $sql .=
' AND fk_soc = ' . (int) $socid;
5038 $sql .=
' AND type <> 2';
5039 $sql .=
' ORDER by situation_cycle_ref, situation_counter desc';
5040 $resql = $this->db->query($sql);
5042 if ($resql && $this->db->num_rows($resql) > 0) {
5045 while ($obj = $this->db->fetch_object($resql)) {
5047 if ($obj->situation_cycle_ref != $ref) {
5049 $ref = $obj->situation_cycle_ref;
5051 if ($obj->situation_final != 1) {
5053 if (substr($obj->ref, 1, 4) !=
'PROV') {
5054 if ($selected == $obj->rowid) {
5055 $opt .=
'<option value="' . $obj->rowid .
'" selected>' . $obj->ref .
'</option>';
5057 $opt .=
'<option value="' . $obj->rowid .
'">' . $obj->ref .
'</option>';
5064 dol_syslog(
"Error sql=" . $sql .
", error=" . $this->error, LOG_ERR);
5066 if ($opt ==
'<option value ="" selected></option>') {
5067 $opt =
'<option value ="0" selected>' . $langs->trans(
'NoSituations') .
'</option>';
5081 public function selectUnits($selected =
'', $htmlname =
'units', $showempty = 0, $unit_type =
'')
5085 $langs->load(
'products');
5087 $return =
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'">';
5089 $sql =
"SELECT rowid, label, code FROM " . $this->db->prefix() .
"c_units";
5090 $sql .=
' WHERE active > 0';
5091 if (!empty($unit_type)) {
5092 $sql .=
" AND unit_type = '" . $this->db->escape($unit_type) .
"'";
5094 $sql .=
" ORDER BY sortorder";
5096 $resql = $this->db->query($sql);
5097 if ($resql && $this->db->num_rows($resql) > 0) {
5099 $return .=
'<option value="none"></option>';
5102 while ($res = $this->db->fetch_object($resql)) {
5103 $unitLabel = $res->label;
5104 if (!empty($langs->tab_translate[
'unit' . $res->code])) {
5105 $unitLabel = $langs->trans(
'unit' . $res->code) != $res->label ? $langs->trans(
'unit' . $res->code) : $res->label;
5108 if ($selected == $res->rowid) {
5109 $return .=
'<option value="' . $res->rowid .
'" selected>' . $unitLabel .
'</option>';
5111 $return .=
'<option value="' . $res->rowid .
'">' . $unitLabel .
'</option>';
5114 $return .=
'</select>';
5135 public function select_comptes($selected =
'', $htmlname =
'accountid', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'', $showcurrency = 0, $morecss =
'', $nooutput = 0)
5142 $langs->loadLangs(array(
"admin",
"banks"));
5145 $sql =
"SELECT rowid, label, bank, clos as status, currency_code";
5146 $sql .=
" FROM " . $this->db->prefix() .
"bank_account";
5147 $sql .=
" WHERE entity IN (" .
getEntity(
'bank_account') .
")";
5149 $sql .=
" AND clos = " . (int) $status;
5152 $sql .=
" AND " . $filtre;
5154 $sql .=
" ORDER BY label";
5156 dol_syslog(get_class($this) .
"::select_comptes", LOG_DEBUG);
5157 $result = $this->db->query($sql);
5159 $num = $this->db->num_rows($result);
5162 $out .=
'<select id="select' . $htmlname .
'" class="flat selectbankaccount' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5166 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoActiveBankAccountDefined") .
'</span>';
5168 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoBankAccountDefined") .
'</span>';
5171 if (!empty($useempty) && !is_numeric($useempty)) {
5172 $out .=
'<option value="-1">'.$langs->trans($useempty).
'</option>';
5173 } elseif ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5174 $out .=
'<option value="-1"> </option>';
5179 $obj = $this->db->fetch_object($result);
5181 $labeltoshow = trim($obj->label);
5182 $labeltoshowhtml = trim($obj->label);
5183 if ($showcurrency) {
5184 $labeltoshow .=
' (' . $obj->currency_code .
')';
5185 $labeltoshowhtml .=
' <span class="opacitymedium">(' . $obj->currency_code .
')</span>';
5187 if ($status == 2 && $obj->status == 1) {
5188 $labeltoshow .=
' (' . $langs->trans(
"Closed") .
')';
5189 $labeltoshowhtml .=
' <span class="opacitymedium">(' . $langs->trans(
"Closed") .
')</span>';
5192 if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
5193 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml).
'" selected>';
5195 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml).
'">';
5197 $out .= $labeltoshow;
5198 $out .=
'</option>';
5201 $out .=
"</select>";
5208 if (empty($nooutput)) {
5230 public function selectRib($selected =
'', $htmlname =
'ribcompanyid', $filtre =
'', $useempty = 0, $moreattrib =
'', $showibanbic = 0, $morecss =
'', $nooutput = 0)
5237 $langs->loadLangs(array(
"admin",
"banks"));
5240 $sql =
"SELECT rowid, label, bank, status, iban_prefix, bic";
5241 $sql .=
" FROM " . $this->db->prefix() .
"societe_rib";
5242 $sql.=
" WHERE type = 'ban'";
5244 $sql .=
" AND " . $filtre;
5246 $sql .=
" ORDER BY label";
5247 dol_syslog(get_class($this) .
"::select_comptes", LOG_DEBUG);
5248 $result = $this->db->query($sql);
5250 $num = $this->db->num_rows($result);
5253 $out .=
'<select id="select' . $htmlname .
'" class="flat selectbankaccount' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5256 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoBankAccountDefined") .
'</span>';
5258 if (!empty($useempty) && !is_numeric($useempty)) {
5259 $out .=
'<option value="-1">'.$langs->trans($useempty).
'</option>';
5260 } elseif ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5261 $out .=
'<option value="-1"> </option>';
5266 $obj = $this->db->fetch_object($result);
5268 if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
5269 $out .=
'<option value="' . $obj->rowid .
'" data-iban-prefix="' . $iban .
' data-bic="' . $obj->bic .
'" selected>';
5271 $out .=
'<option value="' . $obj->rowid .
'" data-iban-prefix="' . $iban .
' data-bic="' . $obj->bic .
'">';
5273 $out .= trim($obj->label);
5275 $out .=
' (' . $iban .
'/' .$obj->bic.
')';
5277 $out .=
'</option>';
5280 $out .=
"</select>";
5287 if (empty($nooutput)) {
5307 public function selectEstablishments($selected =
'', $htmlname =
'entity', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'')
5311 $langs->load(
"admin");
5314 $sql =
"SELECT rowid, name, fk_country, status, entity";
5315 $sql .=
" FROM " . $this->db->prefix() .
"establishment";
5316 $sql .=
" WHERE 1=1";
5318 $sql .=
" AND status = " . (int) $status;
5321 $sql .=
" AND " . $filtre;
5323 $sql .=
" ORDER BY name";
5325 dol_syslog(get_class($this) .
"::select_establishment", LOG_DEBUG);
5326 $result = $this->db->query($sql);
5328 $num = $this->db->num_rows($result);
5331 print
'<select id="select' . $htmlname .
'" class="flat selectestablishment" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5332 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5333 print
'<option value="-1"> </option>';
5337 $obj = $this->db->fetch_object($result);
5338 if ($selected == $obj->rowid) {
5339 print
'<option value="' . $obj->rowid .
'" selected>';
5341 print
'<option value="' . $obj->rowid .
'">';
5343 print trim($obj->name);
5344 if ($status == 2 && $obj->status == 1) {
5345 print
' (' . $langs->trans(
"Closed") .
')';
5353 print
'<span class="opacitymedium">' . $langs->trans(
"NoActiveEstablishmentDefined") .
'</span>';
5355 print
'<span class="opacitymedium">' . $langs->trans(
"NoEstablishmentFound") .
'</span>';
5378 if ($htmlname !=
"none") {
5379 print
'<form method="POST" action="' . $page .
'">';
5380 print
'<input type="hidden" name="action" value="setbankaccount">';
5381 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5382 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
5383 $nbaccountfound = $this->
select_comptes($selected, $htmlname, 0,
'', $addempty);
5384 if ($nbaccountfound > 0) {
5385 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5389 $langs->load(
'banks');
5392 require_once DOL_DOCUMENT_ROOT .
'/compta/bank/class/account.class.php';
5393 $bankstatic =
new Account($this->db);
5394 $result = $bankstatic->fetch($selected);
5396 print $bankstatic->getNomUrl(1);
5415 public function formRib($page, $selected =
'', $htmlname =
'ribcompanyid', $filtre =
'', $addempty = 0, $showibanbic = 0)
5418 if ($htmlname !=
"none") {
5419 print
'<form method="POST" action="' . $page .
'">';
5420 print
'<input type="hidden" name="action" value="setbankaccountcustomer">';
5421 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5422 $nbaccountfound = $this->
selectRib($selected, $htmlname, $filtre, $addempty,
'', $showibanbic);
5423 if ($nbaccountfound > 0) {
5424 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5428 $langs->load(
'banks');
5431 require_once DOL_DOCUMENT_ROOT .
'/societe/class/companybankaccount.class.php';
5433 $result = $bankstatic->fetch($selected);
5435 print $bankstatic->label;
5436 if ($showibanbic) print
' (' . $bankstatic->iban .
'/' .$bankstatic->bic.
')';
5465 public function select_all_categories($type, $selected =
'', $htmlname =
"parent", $maxlength = 64, $fromid = 0, $outputmode = 0, $include = 0, $morecss =
'', $useempty = 1)
5468 global
$conf, $langs;
5469 $langs->load(
"categories");
5471 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
5474 if (is_numeric($type)) {
5475 dol_syslog(__METHOD__ .
': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING);
5478 if ($type === Categorie::TYPE_BANK_LINE) {
5481 $cate_arbo = array();
5482 $sql =
"SELECT c.label, c.rowid";
5483 $sql .=
" FROM " . $this->db->prefix() .
"categorie as c";
5484 $sql .=
" WHERE entity = " .
$conf->entity .
" AND type = " . ((int) $cat->getMapId()[$type]);
5485 $sql .=
" ORDER BY c.label";
5486 $result = $this->db->query($sql);
5488 $num = $this->db->num_rows($result);
5491 $objp = $this->db->fetch_object($result);
5493 $cate_arbo[$objp->rowid] = array(
'id' => $objp->rowid,
'fulllabel' => $objp->label,
'color' =>
'',
'picto' =>
'category');
5497 $this->db->free($result);
5503 $cate_arbo = $cat->get_full_arbo($type, $fromid, $include);
5506 $outarray = array();
5507 $outarrayrichhtml = array();
5510 $output =
'<select class="flat minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
5511 if (is_array($cate_arbo)) {
5512 $num = count($cate_arbo);
5515 $output .=
'<option value="-1" disabled>' . $langs->trans(
"NoCategoriesDefined") .
'</option>';
5517 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5518 $output .=
'<option value="-1"> </option>';
5520 foreach ($cate_arbo as $key => $value) {
5521 if ($cate_arbo[$key][
'id'] == $selected || ($selected ===
'auto' && count($cate_arbo) == 1)) {
5527 $labeltoshow =
img_picto(
'',
'category',
'class="pictofixedwidth" style="color: #' . $cate_arbo[$key][
'color'] .
'"');
5528 $labeltoshow .=
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle');
5530 $outarray[$cate_arbo[$key][
'id']] = $cate_arbo[$key][
'fulllabel'];
5532 $outarrayrichhtml[$cate_arbo[$key][
'id']] = $labeltoshow;
5534 $output .=
'<option ' . $add .
'value="' . $cate_arbo[$key][
'id'] .
'"';
5537 $output .=
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle');
5538 $output .=
'</option>';
5540 $cate_arbo[$key][
'data-html'] = $labeltoshow;
5544 $output .=
'</select>';
5547 if ($outputmode == 2) {
5550 } elseif ($outputmode == 1) {
5552 } elseif ($outputmode == 3) {
5553 return $outarrayrichhtml;
5578 public function form_confirm($page, $title, $question, $action, $formquestion = array(), $selectedchoice =
"", $useajax = 0, $height = 170, $width = 500)
5581 dol_syslog(__METHOD__ .
': using form_confirm is deprecated. Use formconfim instead.', LOG_WARNING);
5582 print $this->
formconfirm($page, $title, $question, $action, $formquestion, $selectedchoice, $useajax, $height, $width);
5612 public function formconfirm($page, $title, $question, $action, $formquestion =
'', $selectedchoice =
'', $useajax = 0, $height = 0, $width = 500, $disableformtag = 0, $labelbuttonyes =
'Yes', $labelbuttonno =
'No')
5614 global $langs,
$conf;
5616 $more =
'<!-- formconfirm - before call, page=' .
dol_escape_htmltag($page) .
' -->';
5622 $newselectedchoice = empty($selectedchoice) ?
"no" : $selectedchoice;
5623 if (
$conf->browser->layout ==
'phone') {
5628 if (empty($height)) {
5630 if (is_array($formquestion) && count($formquestion) > 2) {
5631 $height += ((count($formquestion) - 2) * 24);
5635 if (is_array($formquestion) && !empty($formquestion)) {
5637 foreach ($formquestion as $key => $input) {
5638 if (is_array($input) && !empty($input)) {
5639 if ($input[
'type'] ==
'hidden') {
5640 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
5641 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
5649 $moreonecolumn =
'';
5650 $more .=
'<div class="tagtable paddingtopbottomonly centpercent noborderspacing">' .
"\n";
5651 foreach ($formquestion as $key => $input) {
5652 if (is_array($input) && !empty($input)) {
5653 $size = (!empty($input[
'size']) ?
' size="' . $input[
'size'] .
'"' :
'');
5654 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
5655 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
5657 if ($input[
'type'] ==
'text') {
5658 $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";
5659 } elseif ($input[
'type'] ==
'password') {
5660 $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";
5661 } elseif ($input[
'type'] ==
'textarea') {
5667 $moreonecolumn .=
'<div class="margintoponly">';
5668 $moreonecolumn .= $input[
'label'] .
'<br>';
5670 $moreonecolumn .= $input[
'value'];
5671 $moreonecolumn .=
'</textarea>';
5672 $moreonecolumn .=
'</div>';
5673 } elseif (in_array($input[
'type'], [
'select',
'multiselect'])) {
5674 if (empty($morecss)) {
5675 $morecss =
'minwidth100';
5678 $show_empty = isset($input[
'select_show_empty']) ? $input[
'select_show_empty'] : 1;
5679 $key_in_label = isset($input[
'select_key_in_label']) ? $input[
'select_key_in_label'] : 0;
5680 $value_as_key = isset($input[
'select_value_as_key']) ? $input[
'select_value_as_key'] : 0;
5681 $translate = isset($input[
'select_translate']) ? $input[
'select_translate'] : 0;
5682 $maxlen = isset($input[
'select_maxlen']) ? $input[
'select_maxlen'] : 0;
5683 $disabled = isset($input[
'select_disabled']) ? $input[
'select_disabled'] : 0;
5684 $sort = isset($input[
'select_sort']) ? $input[
'select_sort'] :
'';
5686 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">';
5687 if (!empty($input[
'label'])) {
5688 $more .= $input[
'label'] .
'</div><div class="tagtd left">';
5690 if ($input[
'type'] ==
'select') {
5691 $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);
5693 $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);
5695 $more .=
'</div></div>' .
"\n";
5696 } elseif ($input[
'type'] ==
'checkbox') {
5697 $more .=
'<div class="tagtr">';
5698 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'"><label for="' .
dol_escape_htmltag($input[
'name']) .
'">' . $input[
'label'] .
'</label></div><div class="tagtd">';
5699 $more .=
'<input type="checkbox" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' .
dol_escape_htmltag($input[
'name']) .
'" name="' .
dol_escape_htmltag($input[
'name']) .
'"' . $moreattr;
5700 if (!is_bool($input[
'value']) && $input[
'value'] !=
'false' && $input[
'value'] !=
'0' && $input[
'value'] !=
'') {
5701 $more .=
' checked';
5703 if (is_bool($input[
'value']) && $input[
'value']) {
5704 $more .=
' checked';
5706 if (isset($input[
'disabled'])) {
5707 $more .=
' disabled';
5709 $more .=
' /></div>';
5710 $more .=
'</div>' .
"\n";
5711 } elseif ($input[
'type'] ==
'radio') {
5713 foreach ($input[
'values'] as $selkey => $selval) {
5714 $more .=
'<div class="tagtr">';
5715 if (isset($input[
'label'])) {
5717 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
' tdtop' : (
' tdtop ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
5719 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' "' . $input[
'tdclass'])) .
'"> </div>';
5722 $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;
5723 if (!empty($input[
'disabled'])) {
5724 $more .=
' disabled';
5726 if (isset($input[
'default']) && $input[
'default'] === $selkey) {
5727 $more .=
' checked="checked"';
5730 $more .=
'<label for="' .
dol_escape_htmltag($input[
'name'] . $selkey) .
'" class="valignmiddle">' . $selval .
'</label>';
5731 $more .=
'</div></div>' .
"\n";
5734 } elseif ($input[
'type'] ==
'date' || $input[
'type'] ==
'datetime') {
5735 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
5736 $more .=
'<div class="tagtd">';
5737 $addnowlink = (empty($input[
'datenow']) ? 0 : 1);
5739 if ($input[
'type'] ==
'datetime') {
5740 $h = isset($input[
'hours']) ? $input[
'hours'] : 1;
5741 $m = isset($input[
'minutes']) ? $input[
'minutes'] : 1;
5743 $more .= $this->
selectDate(isset($input[
'value']) ? $input[
'value'] : -1, $input[
'name'], $h, $m, 0,
'', 1, $addnowlink);
5744 $more .=
'</div></div>'.
"\n";
5745 $formquestion[] = array(
'name' => $input[
'name'].
'day');
5746 $formquestion[] = array(
'name' => $input[
'name'].
'month');
5747 $formquestion[] = array(
'name' => $input[
'name'].
'year');
5748 $formquestion[] = array(
'name' => $input[
'name'].
'hour');
5749 $formquestion[] = array(
'name' => $input[
'name'].
'min');
5750 } elseif ($input[
'type'] ==
'other') {
5751 $more .=
'<div class="tagtr"><div class="tagtd'.(empty($input[
'tdclass']) ?
'' : (
' '.$input[
'tdclass'])).
'">';
5752 if (!empty($input[
'label'])) {
5753 $more .= $input[
'label'] .
'</div><div class="tagtd">';
5755 $more .= $input[
'value'];
5756 $more .=
'</div></div>' .
"\n";
5757 } elseif ($input[
'type'] ==
'onecolumn') {
5758 $moreonecolumn .=
'<div class="margintoponly">';
5759 $moreonecolumn .= $input[
'value'];
5760 $moreonecolumn .=
'</div>' .
"\n";
5761 } elseif ($input[
'type'] ==
'hidden') {
5763 } elseif ($input[
'type'] ==
'separator') {
5766 $more .=
'Error type ' . $input[
'type'] .
' for the confirm box is not a supported type';
5770 $more .=
'</div>' .
"\n";
5771 $more .= $moreonecolumn;
5777 if (!empty(
$conf->dol_use_jmobile)) {
5780 if (empty(
$conf->use_javascript_ajax)) {
5786 $dialogconfirm =
'dialog-confirm';
5788 if (!is_numeric($useajax)) {
5792 $dialogconfirm .=
'-' . $button;
5794 $pageyes = $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=yes';
5795 $pageno = ($useajax == 2 ? $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=no' :
'');
5798 if (is_array($formquestion)) {
5799 foreach ($formquestion as $key => $input) {
5802 if (is_array($input) && isset($input[
'name'])) {
5803 if (strpos($input[
'name'],
',') > 0) {
5804 $inputok = array_merge($inputok, explode(
',', $input[
'name']));
5806 array_push($inputok, $input[
'name']);
5811 if (is_array($input) && isset($input[
'inputko']) && $input[
'inputko'] == 1 && isset($input[
'name'])) {
5812 array_push($inputko, $input[
'name']);
5818 $formconfirm .=
'<div id="' . $dialogconfirm .
'" title="' .
dol_escape_htmltag($title) .
'" style="display: none;">';
5819 if (is_array($formquestion) && array_key_exists(
'text', $formquestion) && !empty($formquestion[
'text'])) {
5820 $formconfirm .=
'<div class="confirmtext">' . $formquestion[
'text'] .
'</div>' .
"\n";
5822 if (!empty($more)) {
5823 $formconfirm .=
'<div class="confirmquestions">' . $more .
'</div>' .
"\n";
5825 $formconfirm .= ($question ?
'<div class="confirmmessage">' .
img_help(0,
'') .
' ' . $question .
'</div>' :
'');
5826 $formconfirm .=
'</div>' .
"\n";
5828 $formconfirm .=
"\n<!-- begin code of popup for formconfirm page=" . $page .
" -->\n";
5829 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
5830 $formconfirm .=
"/* Code for the jQuery('#dialogforpopup').dialog() */\n";
5831 $formconfirm .=
'jQuery(document).ready(function() {
5833 $( "#' . $dialogconfirm .
'" ).dialog(
5835 autoOpen: ' . ($autoOpen ?
"true" :
"false") .
',';
5836 if ($newselectedchoice ==
'no') {
5839 $(this).parent().find("button.ui-button:eq(2)").focus();
5844 if ($useajax == 1) {
5845 $jsforcursor =
'// The call to urljump can be slow, so we set the wait cursor' .
"\n";
5846 $jsforcursor .=
'jQuery("html,body,#id-container").addClass("cursorwait");' .
"\n";
5849 $postconfirmas =
'GET';
5853 height: "' . $height .
'",
5854 width: "' . $width .
'",
5856 closeOnEscape: false,
5858 "' .
dol_escape_js($langs->transnoentities($labelbuttonyes)) .
'": function() {
5859 var options = "token=' . urlencode(
newToken()) .
'";
5860 var inputok = ' . json_encode($inputok) .
'; /* List of fields into form */
5861 var page = "' .
dol_escape_js(!empty($page) ? $page :
'') .
'";
5862 var pageyes = "' .
dol_escape_js(!empty($pageyes) ? $pageyes :
'') .
'";
5864 if (inputok.length > 0) {
5865 $.each(inputok, function(i, inputname) {
5868 if ($("input[name=\'" + inputname + "\']").attr("type") == "radio") {
5869 inputvalue = $("input[name=\'" + inputname + "\']:checked").val();
5871 if ($("#" + inputname).attr("type") == "checkbox") { more = ":checked"; }
5872 inputvalue = $("#" + inputname + more).val();
5874 if (typeof inputvalue == "undefined") { inputvalue=""; }
5875 console.log("formconfirm check inputname="+inputname+" inputvalue="+inputvalue);
5876 options += "&" + inputname + "=" + encodeURIComponent(inputvalue);
5879 var urljump = pageyes + (pageyes.indexOf("?") < 0 ? "?" : "&") + options;
5880 if (pageyes.length > 0) {';
5881 if ($postconfirmas ==
'GET') {
5882 $formconfirm .=
'location.href = urljump;';
5884 $formconfirm .= $jsforcursor;
5885 $formconfirm .=
'var post = $.post(
5888 function(data) { $("body").html(data); jQuery("html,body,#id-container").removeClass("cursorwait"); }
5892 console.log("after post ok");
5894 $(this).dialog("close");
5896 "' .
dol_escape_js($langs->transnoentities($labelbuttonno)) .
'": function() {
5897 var options = "token=' . urlencode(
newToken()) .
'";
5898 var inputko = ' . json_encode($inputko) .
'; /* List of fields into form */
5899 var page = "' .
dol_escape_js(!empty($page) ? $page :
'') .
'";
5900 var pageno="' .
dol_escape_js(!empty($pageno) ? $pageno :
'') .
'";
5901 if (inputko.length > 0) {
5902 $.each(inputko, function(i, inputname) {
5904 if ($("#" + inputname).attr("type") == "checkbox") { more = ":checked"; }
5905 var inputvalue = $("#" + inputname + more).val();
5906 if (typeof inputvalue == "undefined") { inputvalue=""; }
5907 options += "&" + inputname + "=" + encodeURIComponent(inputvalue);
5910 var urljump=pageno + (pageno.indexOf("?") < 0 ? "?" : "&") + options;
5912 if (pageno.length > 0) {';
5913 if ($postconfirmas ==
'GET') {
5914 $formconfirm .=
'location.href = urljump;';
5916 $formconfirm .= $jsforcursor;
5917 $formconfirm .=
'var post = $.post(
5920 function(data) { $("body").html(data); jQuery("html,body,#id-container").removeClass("cursorwait"); }
5924 console.log("after post ko");
5926 $(this).dialog("close");
5932 var button = "' . $button .
'";
5933 if (button.length > 0) {
5934 $( "#" + button ).click(function() {
5935 $("#' . $dialogconfirm .
'").dialog("open");
5941 $formconfirm .=
"<!-- end ajax formconfirm -->\n";
5943 $formconfirm .=
"\n<!-- begin formconfirm page=" .
dol_escape_htmltag($page) .
" -->\n";
5945 if (empty($disableformtag)) {
5946 $formconfirm .=
'<form method="POST" action="' . $page .
'" class="notoptoleftnoright">' .
"\n";
5949 $formconfirm .=
'<input type="hidden" name="action" value="' . $action .
'">' .
"\n";
5950 $formconfirm .=
'<input type="hidden" name="token" value="' .
newToken() .
'">' .
"\n";
5952 $formconfirm .=
'<table class="valid centpercent">' .
"\n";
5955 $formconfirm .=
'<tr class="validtitre"><td class="validtitre" colspan="2">';
5956 $formconfirm .=
img_picto(
'',
'pictoconfirm') .
' ' . $title;
5957 $formconfirm .=
'</td></tr>' .
"\n";
5960 if (is_array($formquestion) && array_key_exists(
'text', $formquestion) && !empty($formquestion[
'text'])) {
5961 $formconfirm .=
'<tr class="valid"><td class="valid" colspan="2">' . $formquestion[
'text'] .
'</td></tr>' .
"\n";
5966 $formconfirm .=
'<tr class="valid"><td class="valid" colspan="2">' .
"\n";
5967 $formconfirm .= $more;
5968 $formconfirm .=
'</td></tr>' .
"\n";
5972 $formconfirm .=
'<tr class="valid">';
5973 $formconfirm .=
'<td class="valid">' . $question .
'</td>';
5974 $formconfirm .=
'<td class="valid center">';
5975 $formconfirm .= $this->
selectyesno(
"confirm", $newselectedchoice, 0,
false, 0, 0,
'marginleftonly marginrightonly', $labelbuttonyes, $labelbuttonno);
5976 $formconfirm .=
'<input class="button valignmiddle confirmvalidatebutton small" type="submit" value="' . $langs->trans(
"Validate") .
'">';
5977 $formconfirm .=
'</td>';
5978 $formconfirm .=
'</tr>' .
"\n";
5980 $formconfirm .=
'</table>' .
"\n";
5982 if (empty($disableformtag)) {
5983 $formconfirm .=
"</form>\n";
5985 $formconfirm .=
'<br>';
5987 if (!empty(
$conf->use_javascript_ajax)) {
5988 $formconfirm .=
'<!-- code to disable button to avoid double clic -->';
5989 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
5991 $(document).ready(function () {
5992 $(".confirmvalidatebutton").on("click", function() {
5993 console.log("We click on button confirmvalidatebutton");
5994 $(this).attr("disabled", "disabled");
5995 setTimeout(\'$(".confirmvalidatebutton").removeAttr("disabled")\', 3000);
5996 //console.log($(this).closest("form"));
5997 $(this).closest("form").submit();
6001 $formconfirm .=
'</script>' .
"\n";
6004 $formconfirm .=
"<!-- end formconfirm -->\n";
6007 return $formconfirm;
6028 public function form_project($page, $socid, $selected =
'', $htmlname =
'projectid', $discard_closed = 0, $maxlength = 20, $forcefocus = 0, $nooutput = 0, $textifnoproject =
'', $morecss =
'')
6033 require_once DOL_DOCUMENT_ROOT .
'/core/lib/project.lib.php';
6034 require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formprojet.class.php';
6040 $langs->load(
"project");
6041 if ($htmlname !=
"none") {
6042 $out .=
'<form method="post" action="' . $page .
'">';
6043 $out .=
'<input type="hidden" name="action" value="classin">';
6044 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6045 $out .= $formproject->select_projects($socid, $selected, $htmlname, $maxlength, 0, 1, $discard_closed, $forcefocus, 0, 0,
'', 1, 0, $morecss);
6046 $out .=
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6049 $out .=
'<span class="project_head_block">';
6051 $projet =
new Project($this->db);
6052 $projet->fetch($selected);
6053 $out .= $projet->getNomUrl(0,
'', 1);
6055 $out .=
'<span class="opacitymedium">' . $textifnoproject .
'</span>';
6060 if (empty($nooutput)) {
6084 public function form_conditions_reglement($page, $selected =
'', $htmlname =
'cond_reglement_id', $addempty = 0, $type =
'', $filtertype = -1, $deposit_percent = -1, $nooutput = 0)
6091 if ($htmlname !=
"none") {
6092 $out .=
'<form method="POST" action="' . $page .
'">';
6093 $out .=
'<input type="hidden" name="action" value="setconditions">';
6094 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6096 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
6099 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6104 if (isset($this->cache_conditions_paiements[$selected])) {
6105 $label = $this->cache_conditions_paiements[$selected][
'label'];
6107 if (!empty($this->cache_conditions_paiements[$selected][
'deposit_percent'])) {
6108 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $this->cache_conditions_paiements[$selected][
'deposit_percent'], $label);
6113 $langs->load(
'errors');
6114 $out .= $langs->trans(
'ErrorNotInDictionaryPaymentConditions');
6121 if (empty($nooutput)) {
6143 if ($htmlname !=
"none") {
6144 print
'<form method="post" action="' . $page .
'">';
6145 print
'<input type="hidden" name="action" value="setavailability">';
6146 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6148 print
'<input type="submit" name="modify" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6149 print
'<input type="submit" name="cancel" class="button smallpaddingimp" value="' . $langs->trans(
"Cancel") .
'">';
6154 print $this->cache_availability[$selected][
'label'];
6171 public function formInputReason($page, $selected =
'', $htmlname =
'demandreason', $addempty = 0)
6174 if ($htmlname !=
"none") {
6175 print
'<form method="post" action="' . $page .
'">';
6176 print
'<input type="hidden" name="action" value="setdemandreason">';
6177 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6179 print
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6184 foreach ($this->cache_demand_reason as $key => $val) {
6185 if ($val[
'id'] == $selected) {
6186 print $val[
'label'];
6211 public function form_date($page, $selected, $htmlname, $displayhour = 0, $displaymin = 0, $nooutput = 0, $type =
'')
6218 if ($htmlname !=
"none") {
6219 $ret .=
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
6220 $ret .=
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
6221 $ret .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6223 $ret .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
6225 $ret .=
'<table class="nobordernopadding">';
6227 $ret .= $this->
selectDate($selected, $htmlname, $displayhour, $displaymin, 1,
'form' . $htmlname, 1, 0);
6229 $ret .=
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
6230 $ret .=
'</tr></table></form>';
6239 if (empty($nooutput)) {
6258 public function form_users($page, $selected =
'', $htmlname =
'userid', $exclude = array(), $include = array())
6263 if ($htmlname !=
"none") {
6264 print
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
6265 print
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
6266 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6267 print $this->
select_dolusers($selected, $htmlname, 1, $exclude, 0, $include);
6268 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6272 require_once DOL_DOCUMENT_ROOT .
'/user/class/user.class.php';
6273 $theuser =
new User($this->db);
6274 $theuser->fetch($selected);
6275 print $theuser->getNomUrl(1);
6298 public function form_modes_reglement($page, $selected =
'', $htmlname =
'mode_reglement_id', $filtertype =
'', $active = 1, $addempty = 0, $type =
'', $nooutput = 0)
6304 if ($htmlname !=
"none") {
6305 $out .=
'<form method="POST" action="' . $page .
'">';
6306 $out .=
'<input type="hidden" name="action" value="setmode">';
6307 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6309 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
6311 $out .= $this->
select_types_paiements($selected, $htmlname, $filtertype, 0, $addempty, 0, 0, $active,
'', 1);
6312 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6317 $out .= $this->cache_types_paiements[$selected][
'label'];
6344 if ($htmlname !=
"none") {
6345 print
'<form method="POST" action="' . $page .
'">';
6346 print
'<input type="hidden" name="action" value="settransportmode">';
6347 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6349 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6354 print $this->cache_transport_mode[$selected][
'label'];
6375 if ($htmlname !=
"none") {
6376 print
'<form method="POST" action="' . $page .
'">';
6377 print
'<input type="hidden" name="action" value="setmulticurrencycode">';
6378 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6380 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6383 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
6384 print !empty($selected) ?
currency_name($selected, 1) :
' ';
6402 global $langs, $mysoc,
$conf;
6404 if ($htmlname !=
"none") {
6405 print
'<form method="POST" action="' . $page .
'">';
6406 print
'<input type="hidden" name="action" value="setmulticurrencyrate">';
6407 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6408 print
'<input type="text" class="maxwidth75" name="' . $htmlname .
'" value="' . (!empty($rate) ?
price(
price2num($rate,
'CU')) : 1) .
'" /> ';
6409 print
'<select name="calculation_mode" id="calculation_mode">';
6410 print
'<option value="1">Change ' . $langs->trans(
"PriceUHT") .
' of lines</option>';
6411 print
'<option value="2">Change ' . $langs->trans(
"PriceUHTCurrency") .
' of lines</option>';
6414 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6417 if (!empty($rate)) {
6418 print
price($rate, 1, $langs, 0, 0);
6419 if ($currency && $rate != 1) {
6420 print
' <span class="opacitymedium">(' .
price($rate, 1, $langs, 0, 0) .
' ' . $currency .
' = 1 ' .
$conf->currency .
')</span>';
6445 public function form_remise_dispo($page, $selected, $htmlname, $socid, $amount, $filter =
'', $maxvalue = 0, $more =
'', $hidelist = 0, $discount_type = 0)
6448 global
$conf, $langs;
6449 if ($htmlname !=
"none") {
6450 print
'<form method="post" action="' . $page .
'">';
6451 print
'<input type="hidden" name="action" value="setabsolutediscount">';
6452 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6453 print
'<div class="inline-block">';
6454 if (!empty($discount_type)) {
6456 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL") {
6457 $translationKey =
'HasAbsoluteDiscountFromSupplier';
6459 $translationKey =
'HasCreditNoteFromSupplier';
6462 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
6463 $translationKey =
'HasAbsoluteDiscountFromSupplier';
6465 $translationKey =
'HasCreditNoteFromSupplier';
6470 if (!$filter || $filter ==
"fk_facture_source IS NULL") {
6471 $translationKey =
'CompanyHasAbsoluteDiscount';
6473 $translationKey =
'CompanyHasCreditNote';
6476 if (!$filter || $filter ==
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
6477 $translationKey =
'CompanyHasAbsoluteDiscount';
6479 $translationKey =
'CompanyHasCreditNote';
6483 print $langs->trans($translationKey,
price($amount, 0, $langs, 0, 0, -1,
$conf->currency));
6484 if (empty($hidelist)) {
6488 if (empty($hidelist)) {
6489 print
'<div class="inline-block" style="padding-right: 10px">';
6490 $newfilter =
'discount_type=' . intval($discount_type);
6491 if (!empty($discount_type)) {
6492 $newfilter .=
' AND fk_invoice_supplier IS NULL AND fk_invoice_supplier_line IS NULL';
6494 $newfilter .=
' AND fk_facture IS NULL AND fk_facture_line IS NULL';
6497 $newfilter .=
' AND (' . $filter .
')';
6500 $nbqualifiedlines = $this->
select_remises((
string) $selected, $htmlname, $newfilter, $socid, $maxvalue);
6501 if ($nbqualifiedlines > 0) {
6502 print
' <input type="submit" class="button smallpaddingimp" value="' .
dol_escape_htmltag($langs->trans(
"UseLine")) .
'"';
6503 if (!empty($discount_type) && $filter && $filter !=
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
6504 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
6506 if (empty($discount_type) && $filter && $filter !=
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
6507 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
6515 print
'<div class="inline-block">';
6541 public function form_contacts($page, $societe, $selected =
'', $htmlname =
'contactid')
6546 if ($htmlname !=
"none") {
6547 print
'<form method="post" action="' . $page .
'">';
6548 print
'<input type="hidden" name="action" value="set_contact">';
6549 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6550 print
'<table class="nobordernopadding">';
6555 $addcontact = (
getDolGlobalString(
'SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans(
"AddContact") : $langs->trans(
"AddContactAddress"));
6556 print
'<a href="' . DOL_URL_ROOT .
'/contact/card.php?socid=' . $societe->id .
'&action=create&backtoreferer=1">' . $addcontact .
'</a>';
6559 print
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
6560 print
'</tr></table></form>';
6563 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
6564 $contact =
new Contact($this->db);
6565 $contact->fetch($selected);
6566 print $contact->getFullName($langs);
6591 public function form_thirdparty($page, $selected =
'', $htmlname =
'socid', $filter =
'', $showempty = 0, $showtype = 0, $forcecombo = 0, $events = array(), $nooutput = 0, $excludeids = array(), $textifnothirdparty =
'')
6597 if ($htmlname !=
"none") {
6598 $out .=
'<form method="post" action="' . $page .
'">';
6599 $out .=
'<input type="hidden" name="action" value="set_thirdparty">';
6600 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6601 $out .= $this->
select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, 0,
'minwidth100',
'',
'', 1, array(),
false, $excludeids);
6602 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6606 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
6607 $soc =
new Societe($this->db);
6608 $soc->fetch($selected);
6609 $out .= $soc->getNomUrl(0,
'');
6611 $out .=
'<span class="opacitymedium">' . $textifnothirdparty .
'</span>';
6649 public function selectCurrency($selected =
'', $htmlname =
'currency_id', $mode = 0, $useempty =
'')
6651 global $langs, $user;
6653 $langs->loadCacheCurrencies(
'');
6657 if ($selected ==
'euro' || $selected ==
'euros') {
6661 $out .=
'<select class="flat maxwidth200onsmartphone minwidth300" name="' . $htmlname .
'" id="' . $htmlname .
'">';
6663 $out .=
'<option value="-1" selected></option>';
6665 foreach ($langs->cache_currencies as $code_iso => $currency) {
6666 $labeltoshow = $currency[
'label'];
6668 $labeltoshow .=
' <span class="opacitymedium">(' . $code_iso .
')</span>';
6670 $labeltoshow .=
' <span class="opacitymedium">(' . $langs->getCurrencySymbol($code_iso) .
')</span>';
6673 if ($selected && $selected == $code_iso) {
6674 $out .=
'<option value="' . $code_iso .
'" selected data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
6676 $out .=
'<option value="' . $code_iso .
'" data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
6678 $out .= $labeltoshow;
6679 $out .=
'</option>';
6681 $out .=
'</select>';
6683 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
6687 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
6705 public function selectMultiCurrency($selected =
'', $htmlname =
'multicurrency_code', $useempty = 0, $filter =
'', $excludeConfCurrency =
false, $morecss =
'')
6707 global
$conf, $langs;
6709 $langs->loadCacheCurrencies(
'');
6711 $TCurrency = array();
6713 $sql =
"SELECT code FROM " . $this->db->prefix() .
"multicurrency";
6714 $sql .=
" WHERE entity IN ('" .
getEntity(
'mutlicurrency') .
"')";
6716 $sql .=
" AND " . $filter;
6718 $resql = $this->db->query($sql);
6720 while ($obj = $this->db->fetch_object($resql)) {
6721 $TCurrency[$obj->code] = $obj->code;
6726 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
6728 $out .=
'<option value=""> </option>';
6731 if (!in_array(
$conf->currency, $TCurrency) && !$excludeConfCurrency) {
6732 $TCurrency[
$conf->currency] =
$conf->currency;
6734 if (count($TCurrency) > 0) {
6735 foreach ($langs->cache_currencies as $code_iso => $currency) {
6736 if (isset($TCurrency[$code_iso])) {
6737 if (!empty($selected) && $selected == $code_iso) {
6738 $out .=
'<option value="' . $code_iso .
'" selected="selected">';
6740 $out .=
'<option value="' . $code_iso .
'">';
6743 $out .= $currency[
'label'];
6744 $out .=
' (' . $langs->getCurrencySymbol($code_iso) .
')';
6745 $out .=
'</option>';
6750 $out .=
'</select>';
6753 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
6770 global $langs, $user;
6772 $num = count($this->cache_vatrates);
6779 $sql =
"SELECT t.rowid, t.type_vat, t.code, t.taux, t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.recuperableonly";
6780 $sql .=
" FROM ".$this->db->prefix().
"c_tva as t, ".$this->db->prefix().
"c_country as c";
6781 $sql .=
" WHERE t.fk_pays = c.rowid";
6782 $sql .=
" AND t.active > 0";
6783 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
6784 $sql .=
" AND c.code IN (" . $this->db->sanitize($country_code, 1) .
")";
6785 $sql .=
" ORDER BY t.code ASC, t.taux ASC, t.recuperableonly ASC";
6787 $resql = $this->db->query($sql);
6789 $num = $this->db->num_rows($resql);
6791 for ($i = 0; $i < $num; $i++) {
6792 $obj = $this->db->fetch_object($resql);
6794 $tmparray = array();
6795 $tmparray[
'rowid'] = $obj->rowid;
6796 $tmparray[
'type_vat'] = $obj->type_vat;
6797 $tmparray[
'code'] = $obj->code;
6798 $tmparray[
'txtva'] = $obj->taux;
6799 $tmparray[
'nprtva'] = $obj->recuperableonly;
6800 $tmparray[
'localtax1'] = $obj->localtax1;
6801 $tmparray[
'localtax1_type'] = $obj->localtax1_type;
6802 $tmparray[
'localtax2'] = $obj->localtax2;
6803 $tmparray[
'localtax2_type'] = $obj->localtax1_type;
6804 $tmparray[
'label'] = $obj->taux .
'%' . ($obj->code ?
' (' . $obj->code .
')' :
'');
6805 $tmparray[
'labelallrates'] = $obj->taux .
'/' . ($obj->localtax1 ? $obj->localtax1 :
'0') .
'/' . ($obj->localtax2 ? $obj->localtax2 :
'0') . ($obj->code ?
' (' . $obj->code .
')' :
'');
6806 $positiverates =
'';
6808 $positiverates .= ($positiverates ?
'/' :
'') . $obj->taux;
6810 if ($obj->localtax1) {
6811 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax1;
6813 if ($obj->localtax2) {
6814 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax2;
6816 if (empty($positiverates)) {
6817 $positiverates =
'0';
6819 $tmparray[
'labelpositiverates'] = $positiverates . ($obj->code ?
' (' . $obj->code .
')' :
'');
6821 $this->cache_vatrates[$obj->rowid] = $tmparray;
6826 $this->error =
'<span class="error">';
6827 $this->error .= $langs->trans(
"ErrorNoVATRateDefinedForSellerCountry", $country_code);
6829 if (!empty($user) && $user->admin && preg_match(
'/\'(..)\'/', $country_code, $reg)) {
6830 $langs->load(
"errors");
6831 $new_country_code = $reg[1];
6832 $country_id =
dol_getIdFromCode($this->db, $new_country_code,
'c_pays',
'code',
'rowid');
6833 $this->error .=
'<br>'.$langs->trans(
"ErrorFixThisHere", DOL_URL_ROOT.
'/admin/dict.php?id=10'.($country_id > 0 ?
'&countryidforinsert='.$country_id :
''));
6835 $this->error .=
'</span>';
6839 $this->error =
'<span class="error">' . $this->db->error() .
'</span>';
6868 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)
6871 global $langs, $mysoc;
6873 $langs->load(
'errors');
6878 $defaultnpr = ($info_bits & 0x01);
6879 $defaultnpr = (preg_match(
'/\*/', $selectedrate) ? 1 : $defaultnpr);
6880 $defaulttx = str_replace(
'*',
'', $selectedrate);
6883 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
6884 $defaultcode = $reg[1];
6885 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
6890 if (is_object($societe_vendeuse) && !$societe_vendeuse->country_code) {
6891 if ($societe_vendeuse->id == $mysoc->id) {
6892 $return .=
'<span class="error">' . $langs->trans(
"ErrorYourCountryIsNotDefined") .
'</span>';
6894 $return .=
'<span class="error">' . $langs->trans(
"ErrorSupplierCountryIsNotDefined") .
'</span>';
6905 if (is_object($societe_vendeuse)) {
6906 $code_country =
"'" . $societe_vendeuse->country_code .
"'";
6908 $code_country =
"'" . $mysoc->country_code .
"'";
6911 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
6915 if (
isInEEC($societe_vendeuse) &&
isInEEC($societe_acheteuse) && !$societe_acheteuse->isACompany()) {
6917 if (is_numeric($type)) {
6919 switch ($selectVatComboMode) {
6921 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
6924 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
6928 } elseif (!$idprod) {
6929 switch ($selectVatComboMode) {
6931 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
6934 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
6938 $prodstatic =
new Product($this->db);
6939 $prodstatic->fetch($idprod);
6941 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
6951 $arrayofvatrates = array();
6952 foreach ($this->cache_vatrates as $cachevalue) {
6953 if (empty($cachevalue[
'type_vat']) || $cachevalue[
'type_vat'] != $type_vat) {
6954 $arrayofvatrates[] = $cachevalue;
6958 $num = count($arrayofvatrates);
6962 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
6963 $tmpthirdparty =
new Societe($this->db);
6965 $defaulttx =
get_default_tva($societe_vendeuse, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
6966 $defaultnpr =
get_default_npr($societe_vendeuse, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
6968 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
6969 $defaultcode = $reg[1];
6970 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
6972 if (empty($defaulttx)) {
6979 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
6982 $defaulttx = $arrayofvatrates[$num - 1][
'txtva'];
6989 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
6990 $defaultcode = $reg[1];
6991 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
6999 if (is_object($societe_vendeuse) && $societe_vendeuse->id == $mysoc->id && $societe_vendeuse->tva_assuj ==
"0") {
7008 if (!$options_only) {
7009 $return .=
'<select class="flat minwidth75imp maxwidth100 right" id="' . $htmlname .
'" name="' . $htmlname .
'"' . ($disabled ?
' disabled' :
'') . $title .
'>';
7012 $selectedfound =
false;
7013 foreach ($arrayofvatrates as $rate) {
7015 if ($disabled && $rate[
'txtva'] != 0) {
7020 $key = $rate[
'txtva'];
7021 $key .= $rate[
'nprtva'] ?
'*' :
'';
7022 if ($mode > 0 && $rate[
'code']) {
7023 $key .=
' (' . $rate[
'code'] .
')';
7026 $key = $rate[
'rowid'];
7029 $return .=
'<option value="' . $key .
'"';
7030 if (!$selectedfound) {
7032 if ($defaultcode == $rate[
'code']) {
7033 $return .=
' selected';
7034 $selectedfound =
true;
7036 } elseif ($rate[
'txtva'] == $defaulttx && $rate[
'nprtva'] == $defaultnpr) {
7037 $return .=
' selected';
7038 $selectedfound =
true;
7044 if ($mysoc->country_code ==
'IN' ||
getDolGlobalString(
'MAIN_VAT_LABEL_IS_POSITIVE_RATES')) {
7046 $return .= $rate[
'labelpositiverates'];
7049 $return .=
vatrate($rate[
'label']);
7053 $return .= (empty($rate[
'code']) && $rate[
'nprtva']) ?
' *' :
'';
7055 $return .=
'</option>';
7058 if (!$options_only) {
7059 $return .=
'</select>';
7063 $return .= $this->error;
7097 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 =
'')
7100 dol_syslog(__METHOD__ .
': using select_date is deprecated. Use selectDate instead.', LOG_WARNING);
7101 $retstring = $this->
selectDate($set_time, $prefix, $h, $m, $empty, $form_name, $d, $addnowlink, $disabled, $fullday, $addplusone, $adddateof);
7102 if (!empty($nooutput)) {
7125 public function selectDateToDate($set_time =
'', $set_time_end =
'', $prefix =
're', $empty = 0, $forcenewline = 0)
7129 $ret = $this->
selectDate($set_time, $prefix .
'_start', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"from"),
'tzuserrel');
7130 if ($forcenewline) {
7133 $ret .= $this->
selectDate($set_time_end, $prefix .
'_end', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
7164 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')
7166 global
$conf, $langs;
7168 if ($gm ===
'auto') {
7169 $gm = (empty(
$conf) ?
'tzserver' :
$conf->tzuserinputkey);
7174 if ($prefix ==
'') {
7185 if ($stepminutes <= 0 || $stepminutes > 30) {
7196 $orig_set_time = $set_time;
7198 if ($set_time ===
'' && $emptydate == 0) {
7199 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
7200 if ($gm ==
'tzuser' || $gm ==
'tzuserrel') {
7212 if (!empty($set_time) && preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/', $set_time, $reg)) {
7214 $syear = (!empty($reg[1]) ? $reg[1] :
'');
7215 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
7216 $sday = (!empty($reg[3]) ? $reg[3] :
'');
7217 $shour = (!empty($reg[4]) ? $reg[4] :
'');
7218 $smin = (!empty($reg[5]) ? $reg[5] :
'');
7219 } elseif (strval($set_time) !=
'' && $set_time != -1) {
7224 if ($orig_set_time !=
'') {
7238 if ($h == 3 || $h == 4) {
7249 $usecalendar =
'combo';
7255 $usecalendar =
'html';
7260 if ($usecalendar !=
'combo') {
7261 $formated_date =
'';
7263 if (strval($set_time) !=
'' && $set_time != -1) {
7265 $formated_date =
dol_print_date($set_time, $langs->trans(
"FormatDateShortInput"), $gm);
7269 if ($usecalendar ==
"eldy") {
7271 $retstring .=
'<input id="' . $prefix .
'" name="' . $prefix .
'" type="text" class="maxwidthdate center" maxlength="11" value="' . $formated_date .
'"';
7272 $retstring .= ($disabled ?
' disabled' :
'');
7273 $retstring .=
' onChange="dpChangeDay(\'' . $prefix .
'\',\
'' . $langs->trans(
"FormatDateShortJavaInput") .
'\');
"'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
7274 $retstring .= ' autocomplete="off
">';
7277 $retstringbuttom = '';
7279 $retstringbuttom = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
"';
7280 $base = DOL_URL_ROOT . '/core/';
7281 $retstringbuttom .= ' onClick="showDP(\
'' . $base .
'\',\
'' . $prefix .
'\',\
'' . $langs->trans(
"FormatDateShortJavaInput") .
'\',\
'' . $langs->defaultlang .
'\');
"';
7282 $retstringbuttom .= '>' . img_object($langs->trans("SelectDate
"), 'calendarday', 'class="datecallink
"') . '</button>';
7284 $retstringbuttom = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
">' . img_object($langs->trans("Disabled
"), 'calendarday', 'class="datecallink
"') . '</button>';
7286 $retstring = $retstringbuttom . $retstring;
7288 $retstring .= '<input type="hidden
" id="' . $prefix . 'day
" name="' . $prefix . 'day
" value="' . $sday . '">' . "\n
";
7289 $retstring .= '<input type="hidden
" id="' . $prefix . 'month
" name="' . $prefix . 'month
" value="' . $smonth . '">' . "\n
";
7290 $retstring .= '<input type="hidden
" id="' . $prefix . 'year
" name="' . $prefix . 'year
" value="' . $syear . '">' . "\n
";
7291 } elseif ($usecalendar == 'jquery' || $usecalendar == 'html') {
7292 if (!$disabled && $usecalendar != 'html') {
7293 // Output javascript for datepicker
7294 $minYear = getDolGlobalInt('MIN_YEAR_SELECT_DATE', (idate('Y') - 100));
7295 $maxYear = getDolGlobalInt('MAX_YEAR_SELECT_DATE', (idate('Y') + 100));
7297 $retstring .= '<script nonce="' . getNonce() . '" type="text/javascript
">';
7298 $retstring .= "$(
function(){ $(
'#" . $prefix . "').datepicker({
7299 dateFormat:
'" . $langs->trans("FormatDateShortJQueryInput") . "',
7301 todayHighlight:
true,
7302 yearRange:
'" . $minYear . ":" . $maxYear . "',
";
7303 if (!empty($conf->dol_use_jmobile)) {
7305 beforeShow:
function (input, datePicker) {
7306 input.disabled =
true;
7308 onClose:
function (dateText, datePicker) {
7313 // Note: We don't need monthNames, monthNamesShort, dayNames, dayNamesShort, dayNamesMin, they are set globally on datepicker component in lib_head.js.php
7314 if (!getDolGlobalString('MAIN_POPUP_CALENDAR_ON_FOCUS')) {
7317 buttonImage:
'" . DOL_URL_ROOT . "/theme/" . dol_escape_js($conf->theme) . "/img/object_calendarday.png',
7318 buttonImageOnly:
true";
7322 $retstring .= "</script>
";
7325 // Input area to enter date manually
7326 $retstring .= '<div class="nowraponall
inline-block divfordateinput
">';
7327 $retstring .= '<input id="'.$prefix.'" name="'.$prefix.'" type="text
" class="maxwidthdate center
" maxlength="11
" value="'.$formated_date.'"';
7328 $retstring .= ($disabled ? ' disabled' : '');
7329 $retstring .= ($placeholder ? ' placeholder="' . dol_escape_htmltag($placeholder) . '"' : '');
7330 $retstring .= ' onChange="dpChangeDay(\
'' .
dol_escape_js($prefix) .
'\',\
'' .
dol_escape_js($langs->trans(
"FormatDateShortJavaInput")) .
'\');
"'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
7331 $retstring .= ' autocomplete="off
">';
7335 $retstringbutton = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
">' . img_object($langs->trans("Disabled
"), 'calendarday', 'class="datecallink
"') . '</button>';
7336 $retstring = $retstringbutton . $retstring;
7339 $retstring .= '</div>';
7340 $retstring .= '<input type="hidden
" id="' . $prefix . 'day
" name="' . $prefix . 'day
" value="' . $sday . '">' . "\n
";
7341 $retstring .= '<input type="hidden
" id="' . $prefix . 'month
" name="' . $prefix . 'month
" value="' . $smonth . '">' . "\n
";
7342 $retstring .= '<input type="hidden
" id="' . $prefix . 'year
" name="' . $prefix . 'year
" value="' . $syear . '">' . "\n
";
7344 $retstring .= "Bad value of MAIN_POPUP_CALENDAR
";
7347 // Show date with combo selects
7349 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50imp
" id="' . $prefix . 'day
" name="' . $prefix . 'day
">';
7351 if ($emptydate || $set_time == -1) {
7352 $retstring .= '<option value="0
" selected> </option>';
7355 for ($day = 1; $day <= 31; $day++) {
7356 $retstring .= '<option value="' . $day . '"' . ($day == $sday ? ' selected' : '') . '>' . $day . '</option>';
7359 $retstring .= "</select>
";
7361 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'month
" name="' . $prefix . 'month
">';
7362 if ($emptydate || $set_time == -1) {
7363 $retstring .= '<option value="0
" selected> </option>';
7367 for ($month = 1; $month <= 12; $month++) {
7368 $retstring .= '<option value="' . $month . '"' . ($month == $smonth ? ' selected' : '') . '>';
7369 $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b
");
7370 $retstring .= "</option>
";
7372 $retstring .= "</select>
";
7375 if ($emptydate || $set_time == -1) {
7376 $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 . '">';
7378 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'year
" name="' . $prefix . 'year
">';
7380 $syear = (int) $syear;
7381 for ($year = $syear - 10; $year < (int) $syear + 10; $year++) {
7382 $retstring .= '<option value="' . $year . '"' . ($year == $syear ? ' selected' : '') . '>' . $year . '</option>';
7384 $retstring .= "</select>\n
";
7390 $retstring .= (($h == 2 || $h == 4) ? '<br>' : ' ');
7391 $retstring .= '<span class="nowraponall
">';
7397 if ($openinghours != '') {
7398 $openinghours = explode(',', $openinghours);
7399 $hourstart = $openinghours[0];
7400 $hourend = $openinghours[1];
7401 if ($hourend < $hourstart) {
7402 $hourend = $hourstart;
7406 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50
' . ($fullday ? $fullday . 'hour
' : '') . '" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
">';
7408 $retstring .= '<option value="-1
"> </option>';
7410 for ($hour = $hourstart; $hour < $hourend; $hour++) {
7411 if (strlen($hour) < 2) {
7412 $hour = "0
" . $hour;
7414 $retstring .= '<option value="' . $hour . '"' . (($hour == $shour) ? ' selected' : '') . '>' . $hour;
7415 //$retstring .= (empty($conf->dol_optimize_smallscreen) ? '' : 'H');
7416 $retstring .= '</option>';
7418 $retstring .= '</select>';
7419 //if ($m && empty($conf->dol_optimize_smallscreen)) $retstring .= ":
";
7427 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50
' . ($fullday ? $fullday . 'min
' : '') . '" id="' . $prefix . 'min
" name="' . $prefix . 'min
">';
7429 $retstring .= '<option value="-1
"> </option>';
7431 for ($min = 0; $min < 60; $min += $stepminutes) {
7432 $min_str = sprintf("%02d
", $min);
7433 $retstring .= '<option value="' . $min_str . '"' . (($min_str == $smin) ? ' selected' : '') . '>' . $min_str . '</option>';
7435 $retstring .= '</select>';
7437 $retstring .= '<input type="hidden
" name="' . $prefix . 'sec
" value="' . $ssec . '">';
7441 $retstring .= '</span>';
7445 if (!empty($conf->use_javascript_ajax) && $addnowlink) {
7446 // Script which will be inserted in the onClick of the "Now
" link
7447 $reset_scripts = "";
7448 if ($addnowlink == 2) { // local computer time
7449 // pad add leading 0 on numbers
7450 $reset_scripts .= "Number.prototype.pad =
function(size) {
7451 var s = String(
this);
7452 while (s.length < (size || 2)) {s =
'0' + s;}
7455 var d =
new Date();
";
7458 // Generate the date part, depending on the use or not of the javascript calendar
7459 if ($addnowlink == 1) { // server time expressed in user time setup
7460 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
7461 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
7462 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
7463 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
7464 } elseif ($addnowlink == 2) {
7465 /* Disabled because the output does not use the string format defined by FormatDateShort key to forge the value into #prefix.
7466 * This break application for foreign languages.
7467 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(d.toLocaleDateString(\''.str_replace('_', '-', $langs->defaultlang).'\'));';
7468 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(d.getDate().pad());';
7469 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(parseInt(d.getMonth().pad()) + 1);';
7470 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(d.getFullYear());';
7472 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
7473 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
7474 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
7475 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
7477 /*if ($usecalendar == "eldy
")
7479 $base=DOL_URL_ROOT.'/core/';
7480 $reset_scripts .= 'resetDP(\''.$base.'\',\''.$prefix.'\',\''.$langs->trans("FormatDateShortJavaInput
").'\',\''.$langs->defaultlang.'\');';
7484 $reset_scripts .= 'this.form.elements[\''.$prefix.'day\'].value=formatDate(new Date(), \'d\'); ';
7485 $reset_scripts .= 'this.form.elements[\''.$prefix.'month\'].value=formatDate(new Date(), \'M\'); ';
7486 $reset_scripts .= 'this.form.elements[\''.$prefix.'year\'].value=formatDate(new Date(), \'yyyy\'); ';
7488 // Update the hour part
7491 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7493 //$reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); ';
7494 if ($addnowlink == 1) {
7495 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
7496 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
7497 } elseif ($addnowlink == 2) {
7498 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(d.getHours().pad());';
7499 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
7503 $reset_scripts .= ' } ';
7506 // Update the minute part
7509 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7511 //$reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); ';
7512 if ($addnowlink == 1) {
7513 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
7514 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
7515 } elseif ($addnowlink == 2) {
7516 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(d.getMinutes().pad());';
7517 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
7520 $reset_scripts .= ' } ';
7523 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
7524 if ($reset_scripts && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
7525 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonNow
" type="button" name="_useless
" value="now
" onClick="' . $reset_scripts . '">';
7526 $retstring .= $langs->trans("Now
");
7527 $retstring .= '</button> ';
7531 // Add a "Plus one hour
" link
7532 if ($conf->use_javascript_ajax && $addplusone) {
7533 // Script which will be inserted in the onClick of the "Add plusone
" link
7534 $reset_scripts = "";
7536 // Generate the date part, depending on the use or not of the javascript calendar
7537 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'dayinputnoreduce', 'tzuserrel') . '\');';
7538 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
7539 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
7540 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
7541 // Update the hour part
7544 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7546 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
7548 $reset_scripts .= ' } ';
7551 // Update the minute part
7554 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7556 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
7558 $reset_scripts .= ' } ';
7561 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
7562 if ($reset_scripts && empty($conf->dol_optimize_smallscreen)) {
7563 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonPlusOne
" type="button" name="_useless2
" value="plusone
" onClick="' . $reset_scripts . '">';
7564 $retstring .= $langs->trans("DateStartPlusOne
");
7565 $retstring .= '</button> ';
7569 // Add a link to set data
7570 if ($conf->use_javascript_ajax && !empty($adddateof)) {
7571 if (!is_array($adddateof)) {
7572 $arrayofdateof = array(array('adddateof' => $adddateof, 'labeladddateof' => $labeladddateof));
7574 $arrayofdateof = $adddateof;
7576 foreach ($arrayofdateof as $valuedateof) {
7577 $tmpadddateof = empty($valuedateof['adddateof']) ? 0 : $valuedateof['adddateof'];
7578 $tmplabeladddateof = empty($valuedateof['labeladddateof']) ? '' : $valuedateof['labeladddateof'];
7579 $tmparray = dol_getdate($tmpadddateof);
7580 if (empty($tmplabeladddateof)) {
7581 $tmplabeladddateof = $langs->trans("DateInvoice
");
7583 $reset_scripts = 'console.log(\'Click on now link\'); ';
7584 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(\''.dol_print_date($tmpadddateof, 'dayinputnoreduce').'\');';
7585 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(\''.$tmparray['mday'].'\');';
7586 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(\''.$tmparray['mon'].'\');';
7587 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(\''.$tmparray['year'].'\');';
7588 $retstring .= ' - <button class="dpInvisibleButtons datenowlink
" id="dateofinvoice
" type="button" name="_dateofinvoice
" value="now
" onclick="'.$reset_scripts.'">'.$tmplabeladddateof.'</button>';
7603 public function selectTypeDuration($prefix, $selected = 'i', $excludetypes = array())
7607 $TDurationTypes = array(
7608 'y' => $langs->trans('Years'),
7609 'm' => $langs->trans('Month'),
7610 'w' => $langs->trans('Weeks'),
7611 'd' => $langs->trans('Days'),
7612 'h' => $langs->trans('Hours'),
7613 'i' => $langs->trans('Minutes')
7616 // Removed undesired duration types
7617 foreach ($excludetypes as $value) {
7618 unset($TDurationTypes[$value]);
7621 $retstring = '<select class="flat minwidth75 maxwidth100
" id="select_
' . $prefix . 'type_duration
" name="' . $prefix . 'type_duration
">';
7622 foreach ($TDurationTypes as $key => $typeduration) {
7623 $retstring .= '<option value="' . $key . '"';
7624 if ($key == $selected) {
7625 $retstring .= " selected
";
7627 $retstring .= ">
" . $typeduration . "</option>
";
7629 $retstring .= "</select>
";
7631 $retstring .= ajax_combobox('select_' . $prefix . 'type_duration');
7636 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
7651 public function select_duration($prefix, $iSecond = '', $disabled = 0, $typehour = 'select', $minunderhours = 0, $nooutput = 0)
7656 $retstring = '<span class="nowraponall
">';
7662 if ($iSecond != '') {
7663 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
7665 $hourSelected = convertSecondToTime($iSecond, 'allhour');
7666 $minSelected = convertSecondToTime($iSecond, 'min');
7669 if ($typehour == 'select') {
7670 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'hour
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . '>';
7671 for ($hour = 0; $hour < 25; $hour++) { // For a duration, we allow 24 hours
7672 $retstring .= '<option value="' . $hour . '"';
7673 if (is_numeric($hourSelected) && $hourSelected == $hour) {
7674 $retstring .= " selected
";
7676 $retstring .= ">
" . $hour . "</option>
";
7678 $retstring .= "</select>
";
7679 } elseif ($typehour == 'text' || $typehour == 'textselect') {
7680 $retstring .= '<input placeholder="' . $langs->trans('HourShort
') . '" type="number
" min="0
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputhour right
" value="' . (($hourSelected != '') ? ((int) $hourSelected) : '') . '">';
7682 return 'BadValueForParameterTypeHour';
7685 if ($typehour != 'text') {
7686 $retstring .= ' ' . $langs->trans('HourShort');
7688 $retstring .= '<span class="">:</span>';
7692 if ($minunderhours) {
7693 $retstring .= '<br>';
7695 if ($typehour != 'text') {
7696 $retstring .= '<span class="hideonsmartphone
"> </span>';
7700 if ($typehour == 'select' || $typehour == 'textselect') {
7701 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'min
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . '>';
7702 for ($min = 0; $min <= 55; $min += 5) {
7703 $retstring .= '<option value="' . $min . '"';
7704 if (is_numeric($minSelected) && $minSelected == $min) {
7705 $retstring .= ' selected';
7707 $retstring .= '>' . $min . '</option>';
7709 $retstring .= "</select>
";
7710 } elseif ($typehour == 'text') {
7711 $retstring .= '<input placeholder="' . $langs->trans('MinuteShort
') . '" type="number
" min="0
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputminute right
" value="' . (($minSelected != '') ? ((int) $minSelected) : '') . '">';
7714 if ($typehour != 'text') {
7715 $retstring .= ' ' . $langs->trans('MinuteShort');
7718 $retstring .= "</span>
";
7720 if (!empty($nooutput)) {
7748 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)
7750 global $langs, $conf;
7755 if (is_null($ajaxoptions)) {
7756 $ajaxoptions = array();
7759 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
7762 if ($selected && empty($selected_input_value)) {
7763 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
7764 $tickettmpselect = new Ticket($this->db);
7765 $tickettmpselect->fetch($selected);
7766 $selected_input_value = $tickettmpselect->ref;
7767 unset($tickettmpselect);
7771 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/ticket/ajax/tickets.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
7773 if (empty($hidelabel)) {
7774 $out .= $langs->trans("RefOrLabel
") . ' : ';
7775 } elseif ($hidelabel > 1) {
7776 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
7777 if ($hidelabel == 2) {
7778 $out .= img_picto($langs->trans("Search
"), 'search');
7781 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
7782 if ($hidelabel == 3) {
7783 $out .= img_picto($langs->trans("Search
"), 'search');
7786 $out .= $this->selectTicketsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
7789 if (empty($nooutput)) {
7814 public function selectTicketsList($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
7816 global $langs, $conf;
7819 $outarray = array();
7821 $selectFields = " p.rowid, p.ref, p.message
";
7824 $sql .= $selectFields;
7825 $sql .= " FROM
" . $this->db->prefix() . "ticket as p
";
7826 $sql .= ' WHERE p.entity IN (' . getEntity('ticket') . ')';
7828 // Add criteria on ref/label
7829 if ($filterkey != '') {
7831 $prefix = !getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
7832 // For natural search
7833 $search_crit = explode(' ', $filterkey);
7835 if (count($search_crit) > 1) {
7838 foreach ($search_crit as $crit) {
7842 $sql .= "(p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%' OR p.subject LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
7846 if (count($search_crit) > 1) {
7852 $sql .= $this->db->plimit($limit, 0);
7854 // Build output string
7856 $result = $this->db->query($sql);
7858 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
7859 require_once DOL_DOCUMENT_ROOT . '/core/lib/ticket.lib.php';
7861 $num = $this->db->num_rows($result);
7866 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
7867 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('TICKET_USE_SEARCH_TO_SELECT'));
7870 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
7873 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
7874 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
7875 if (getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
7876 if ($showempty && !is_numeric($showempty)) {
7877 $textifempty = $langs->trans($showempty);
7879 $textifempty .= $langs->trans("All
");
7882 if ($showempty && !is_numeric($showempty)) {
7883 $textifempty = $langs->trans($showempty);
7887 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
7891 while ($num && $i < $num) {
7894 $objp = $this->db->fetch_object($result);
7896 $this->constructTicketListOption($objp, $opt, $optJson, $selected, $filterkey);
7897 '@phan-var-force array{key:string,value:mixed,type:int} $optJson';
7899 // "key
" value of json key array is used by jQuery automatically as selected value
7900 // "label
" value of json key array is used by jQuery automatically as text for combo box
7902 array_push($outarray, $optJson);
7907 $out .= '</select>';
7909 $this->db->free($result);
7911 if (empty($outputmode)) {
7916 dol_print_error($this->db);
7933 protected function constructTicketListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
7939 $outkey = $objp->rowid;
7940 $outref = $objp->ref;
7942 $opt = '<option value="
' . $objp->rowid . '"';
7943 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
7946 $objRef = $objp->ref;
7947 if (!empty($filterkey) && $filterkey != '') {
7948 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1);
7951 $opt .= "</option>\n
";
7952 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
7974 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)
7976 global $langs, $conf;
7981 if (is_null($ajaxoptions)) {
7982 $ajaxoptions = array();
7985 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
7988 if ($selected && empty($selected_input_value)) {
7989 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
7990 $projecttmpselect = new Project($this->db);
7991 $projecttmpselect->fetch($selected);
7992 $selected_input_value = $projecttmpselect->ref;
7993 unset($projecttmpselect);
7997 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/projet/ajax/projects.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
7999 if (empty($hidelabel)) {
8000 $out .= $langs->trans("RefOrLabel
") . ' : ';
8001 } elseif ($hidelabel > 1) {
8002 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
8003 if ($hidelabel == 2) {
8004 $out .= img_picto($langs->trans("Search
"), 'search');
8007 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
8008 if ($hidelabel == 3) {
8009 $out .= img_picto($langs->trans("Search
"), 'search');
8012 $out .= $this->selectProjectsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
8015 if (empty($nooutput)) {
8039 public function selectProjectsList($selected = '', $htmlname = 'projectid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
8041 global $langs, $conf;
8044 $outarray = array();
8046 $selectFields = " p.rowid, p.ref
";
8049 $sql .= $selectFields;
8050 $sql .= " FROM
" . $this->db->prefix() . "projet as p
";
8051 $sql .= ' WHERE p.entity IN (' . getEntity('project') . ')';
8053 // Add criteria on ref/label
8054 if ($filterkey != '') {
8056 $prefix = !getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
8057 // For natural search
8058 $search_crit = explode(' ', $filterkey);
8060 if (count($search_crit) > 1) {
8063 foreach ($search_crit as $crit) {
8067 $sql .= "p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
8071 if (count($search_crit) > 1) {
8077 $sql .= $this->db->plimit($limit, 0);
8079 // Build output string
8081 $result = $this->db->query($sql);
8083 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
8084 require_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php';
8086 $num = $this->db->num_rows($result);
8091 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
8092 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('PROJECT_USE_SEARCH_TO_SELECT'));
8095 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
8098 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
8099 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
8100 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
8101 if ($showempty && !is_numeric($showempty)) {
8102 $textifempty = $langs->trans($showempty);
8104 $textifempty .= $langs->trans("All
");
8107 if ($showempty && !is_numeric($showempty)) {
8108 $textifempty = $langs->trans($showempty);
8112 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
8116 while ($num && $i < $num) {
8119 $objp = $this->db->fetch_object($result);
8121 $this->constructProjectListOption($objp, $opt, $optJson, $selected, $filterkey);
8123 // "key
" value of json key array is used by jQuery automatically as selected value
8124 // "label
" value of json key array is used by jQuery automatically as text for combo box
8126 array_push($outarray, $optJson);
8131 $out .= '</select>';
8133 $this->db->free($result);
8135 if (empty($outputmode)) {
8140 dol_print_error($this->db);
8157 protected function constructProjectListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
8163 $label = $objp->label;
8165 $outkey = $objp->rowid;
8166 $outref = $objp->ref;
8167 $outlabel = $objp->label;
8168 $outtype = $objp->fk_product_type;
8170 $opt = '<option value="
' . $objp->rowid . '"';
8171 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
8174 $objRef = $objp->ref;
8175 if (!empty($filterkey) && $filterkey != '') {
8176 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1);
8179 $opt .= "</option>\n
";
8180 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
8203 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)
8205 global $langs, $conf;
8210 if (is_null($ajaxoptions)) {
8211 $ajaxoptions = array();
8214 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
8217 if ($selected && empty($selected_input_value)) {
8218 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
8219 $adherenttmpselect = new Adherent($this->db);
8220 $adherenttmpselect->fetch($selected);
8221 $selected_input_value = $adherenttmpselect->ref;
8222 unset($adherenttmpselect);
8227 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/adherents/ajax/adherents.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
8229 if (empty($hidelabel)) {
8230 $out .= $langs->trans("RefOrLabel
") . ' : ';
8231 } elseif ($hidelabel > 1) {
8232 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
8233 if ($hidelabel == 2) {
8234 $out .= img_picto($langs->trans("Search
"), 'search');
8237 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
8238 if ($hidelabel == 3) {
8239 $out .= img_picto($langs->trans("Search
"), 'search');
8244 $out .= $this->selectMembersList($selected, $htmlname, $filtertype, $limit, $filterkey, $status, 0, $showempty, $forcecombo, $morecss);
8247 if (empty($nooutput)) {
8271 public function selectMembersList($selected = '', $htmlname = 'adherentid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
8273 global $langs, $conf;
8276 $outarray = array();
8278 $selectFields = " p.rowid, p.ref, p.firstname, p.lastname, p.fk_adherent_type
";
8281 $sql .= $selectFields;
8282 $sql .= " FROM
" . $this->db->prefix() . "adherent as p
";
8283 $sql .= ' WHERE p.entity IN (' . getEntity('adherent') . ')';
8285 // Add criteria on ref/label
8286 if ($filterkey != '') {
8288 $prefix = !getDolGlobalString('MEMBER_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
8289 // For natural search
8290 $search_crit = explode(' ', $filterkey);
8292 if (count($search_crit) > 1) {
8295 foreach ($search_crit as $crit) {
8299 $sql .= "(p.firstname LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
8300 $sql .= " OR p.lastname LIKE
'" . $this->db->escape($prefix . $crit) . "%')
";
8303 if (count($search_crit) > 1) {
8308 if ($status != -1) {
8309 $sql .= ' AND statut = ' . ((int) $status);
8311 $sql .= $this->db->plimit($limit, 0);
8313 // Build output string
8315 $result = $this->db->query($sql);
8317 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
8318 require_once DOL_DOCUMENT_ROOT . '/core/lib/member.lib.php';
8320 $num = $this->db->num_rows($result);
8325 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
8326 $out .= ajax_combobox($htmlname, $events, getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT') ? $conf->global->PROJECT_USE_SEARCH_TO_SELECT : '');
8329 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
8332 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
8333 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
8334 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
8335 if ($showempty && !is_numeric($showempty)) {
8336 $textifempty = $langs->trans($showempty);
8338 $textifempty .= $langs->trans("All
");
8341 if ($showempty && !is_numeric($showempty)) {
8342 $textifempty = $langs->trans($showempty);
8346 $out .= '<option value="-1
" selected>' . $textifempty . '</option>';
8350 while ($num && $i < $num) {
8353 $objp = $this->db->fetch_object($result);
8355 $this->constructMemberListOption($objp, $opt, $optJson, $selected, $filterkey);
8358 // "key
" value of json key array is used by jQuery automatically as selected value
8359 // "label
" value of json key array is used by jQuery automatically as text for combo box
8361 array_push($outarray, $optJson);
8366 $out .= '</select>';
8368 $this->db->free($result);
8370 if (empty($outputmode)) {
8375 dol_print_error($this->db);
8392 protected function constructMemberListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
8398 $outkey = $objp->rowid;
8399 $outlabel = dolGetFirstLastname($objp->firstname, $objp->lastname);
8400 $outtype = $objp->fk_adherent_type;
8402 $opt = '<option value="
' . $objp->rowid . '"';
8403 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
8405 if (!empty($filterkey) && $filterkey != '') {
8406 $outlabel = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $outlabel, 1);
8409 $opt .= "</option>\n
";
8411 $optJson = array('key' => $outkey, 'value' => $outlabel, 'type' => $outtype);
8434 public function selectForForms($objectdesc, $htmlname, $preSelectedValue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $disabled = 0, $selected_input_value = '', $objectfield = '')
8436 global $conf, $extrafields, $user;
8438 // Example of common usage for a link to a thirdparty
8440 // We got this in a modulebuilder form of "
MyObject" of module "mymodule
".
8441 // ->fields is array( ... "fk_soc
" => array("type"=>"integer:
Societe:societe/class/societe.class.php:1:((
status:=:1) AND (entity:IN:__SHARED_ENTITIES__))
" ...)
8442 // $objectdesc = 'Societe'
8443 // $objectfield = 'myobject@mymodule:fk_soc' ('fk_soc' is code to retrieve myobject->fields['fk_soc'])
8445 // We got this when showing an extrafields on resource that is a link to societe
8446 // extrafields 'link_to_societe' of Resource is 'link' to 'Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))" ...)
'
8448 // $objectfield = 'resource:options_link_to_societe
'
8451 // $objectdesc = 'Societe:societe/class/societe.class.php:1:((
status:=:1) AND (entity:IN:__SHARED_ENTITIES__))
'
8452 // $objectfield = ''
8454 //var_dump($objectdesc.' '.$objectfield);
8455 //debug_print_backtrace();
8457 $objectdescorig = $objectdesc;
8459 $InfoFieldList = array();
8461 $filter = ''; // Ensure filter has value (for static analysis)
8462 $sortfield = ''; // Ensure filter has value (for static analysis)
8464 if ($objectfield) { // We must retrieve the objectdesc from the field or extrafield
8465 // Example: $objectfield = 'product:options_package
' or 'myobject@mymodule:options_myfield
'
8466 $tmparray = explode(':
', $objectfield);
8468 // Get instance of object from $element
8469 $objectforfieldstmp = fetchObjectByElement(0, strtolower($tmparray[0]));
8471 if (is_object($objectforfieldstmp)) {
8475 if (preg_match('/^options_(.*)$/
', $tmparray[1], $reg)) {
8476 // For a property in extrafields
8478 // fetch optionals attributes and labels
8479 $extrafields->fetch_name_optionals_label($objectforfieldstmp->table_element);
8481 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element]['type'][$key]) && $extrafields->attributes[$objectforfieldstmp->table_element]['type'][$key] == 'link
') {
8482 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element]['param
'][$key]['options
'])) {
8483 $tmpextrafields = array_keys($extrafields->attributes[$objectforfieldstmp->table_element]['param
'][$key]['options
']);
8484 $objectdesc = $tmpextrafields[0];
8488 // For a property in ->fields
8489 if (array_key_exists($tmparray[1], $objectforfieldstmp->fields)) {
8490 $objectdesc = $objectforfieldstmp->fields[$tmparray[1]]['type'];
8491 $objectdesc = preg_replace('/^integer[^:]*:/
', '', $objectdesc);
8498 // Example of value for $objectdesc:
8499 // Bom:bom/class/bom.class.php:0:t.status=1
8500 // Bom:bom/class/bom.class.php:0:t.status=1:ref
8501 // Bom:bom/class/bom.class.php:0:(t.status:=:1) OR (t.field2:=:2):ref
8502 $InfoFieldList = explode(":", $objectdesc, 4);
8503 $vartmp = (empty($InfoFieldList[3]) ? '' : $InfoFieldList[3]);
8505 if (preg_match('/^.*:(\w*)$/
', $vartmp, $reg)) {
8506 $InfoFieldList[4] = $reg[1]; // take the sort field
8508 $InfoFieldList[3] = preg_replace('/:\w*$/
', '', $vartmp); // take the filter field
8510 $classname = $InfoFieldList[0];
8511 $classpath = empty($InfoFieldList[1]) ? '' : $InfoFieldList[1];
8512 //$addcreatebuttonornot = empty($InfoFieldList[2]) ? 0 : $InfoFieldList[2];
8513 $filter = empty($InfoFieldList[3]) ? '' : $InfoFieldList[3];
8514 $sortfield = empty($InfoFieldList[4]) ? '' : $InfoFieldList[4];
8516 // Load object according to $id and $element
8517 $objecttmp = fetchObjectByElement(0, strtolower($InfoFieldList[0]));
8519 // Fallback to another solution to get $objecttmp
8520 if (empty($objecttmp) && !empty($classpath)) {
8521 dol_include_once($classpath);
8523 if ($classname && class_exists($classname)) {
8524 $objecttmp = new $classname($this->db);
8529 // Make some replacement in $filter. May not be used if we used the ajax mode with $objectfield. In such a case
8530 // we propagate the $objectfield and not the filter and replacement is done by the ajax/selectobject.php component.
8531 $sharedentities = (is_object($objecttmp) && property_exists($objecttmp, 'element
')) ? getEntity($objecttmp->element) : strtolower($classname);
8532 $filter = str_replace(
8533 array('__ENTITY__
', '__SHARED_ENTITIES__
', '__USER_ID__
'),
8534 array($conf->entity, $sharedentities, $user->id),
8538 if (!is_object($objecttmp)) {
8539 dol_syslog('selectForForms: Error bad setup of field objectdescorig=
' . $objectdescorig.', objectfield=
'.$objectfield.', objectdesc=
'.$objectdesc, LOG_WARNING);
8540 return 'selectForForms: Error bad setup of field objectdescorig=
' . $objectdescorig.', objectfield=
'.$objectfield.', objectdesc=
'.$objectdesc;
8544 //var_dump($filter);
8545 $prefixforautocompletemode = $objecttmp->element;
8546 if ($prefixforautocompletemode == 'societe
') {
8547 $prefixforautocompletemode = 'company
';
8549 if ($prefixforautocompletemode == 'product
') {
8550 $prefixforautocompletemode = 'produit
';
8552 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) . '_USE_SEARCH_TO_SELECT
'; // For example COMPANY_USE_SEARCH_TO_SELECT
8554 dol_syslog(get_class($this) . "::selectForForms filter=" . $filter, LOG_DEBUG);
8556 // Generate the combo HTML component
8558 if (!empty($conf->use_javascript_ajax) && getDolGlobalString($confkeyforautocompletemode) && !$forcecombo) {
8559 // No immediate load of all database
8562 if ($preSelectedValue && empty($selected_input_value)) {
8563 $objecttmp->fetch($preSelectedValue);
8564 $selected_input_value = ($prefixforautocompletemode == 'company
' ? $objecttmp->name : $objecttmp->ref);
8566 $oldValueForShowOnCombobox = 0;
8567 foreach ($objecttmp->fields as $fieldK => $fielV) {
8568 if (!array_key_exists('showoncombobox
', $fielV) || !$fielV['showoncombobox
'] || empty($objecttmp->$fieldK)) {
8572 if (!$oldValueForShowOnCombobox) {
8573 $selected_input_value = '';
8576 $selected_input_value .= $oldValueForShowOnCombobox ? ' -
' : '';
8577 $selected_input_value .= $objecttmp->$fieldK;
8578 $oldValueForShowOnCombobox = empty($fielV['showoncombobox
']) ? 0 : $fielV['showoncombobox
'];
8582 // Set url and param to call to get json of the search results
8583 $urlforajaxcall = DOL_URL_ROOT . '/core/ajax/selectobject.php
';
8584 $urloption = 'htmlname=
' . urlencode($htmlname) . '&outjson=1&objectdesc=
' . urlencode($objectdescorig) . '&objectfield=
'.urlencode($objectfield) . ($sortfield ? '&sortfield=
' . urlencode($sortfield) : '');
8586 // Activate the auto complete using ajax call.
8587 $out .= ajax_autocompleter((string) $preSelectedValue, $htmlname, $urlforajaxcall, $urloption, getDolGlobalInt($confkeyforautocompletemode), 0);
8588 $out .= '<!-- force css to be higher than dialog popup --><style
type=
"text/css">.ui-autocomplete { z-index: 1010; }</style>
';
8589 $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) . '"' : '') . ' />
';
8591 // Immediate load of table record.
8592 $out .= $this->selectForFormsList($objecttmp, $htmlname, $preSelectedValue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled, $sortfield, $filter);
8619 public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty = '
', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $outputmode = 0, $disabled = 0, $sortfield = '', $filter = '')
8621 global $langs, $user, $hookmanager;
8623 //print "$htmlname, $preselectedvalue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, $outputmode, $disabled";
8625 $prefixforautocompletemode = $objecttmp->element;
8626 if ($prefixforautocompletemode == 'societe
') {
8627 $prefixforautocompletemode = 'company
';
8629 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) . '_USE_SEARCH_TO_SELECT
'; // For example COMPANY_USE_SEARCH_TO_SELECT
8631 if (!empty($objecttmp->fields)) { // For object that declare it, it is better to use declared fields (like societe, contact, ...)
8632 $tmpfieldstoshow = '';
8633 foreach ($objecttmp->fields as $key => $val) {
8634 if (! (int) dol_eval($val['enabled
'], 1, 1, '1
')) {
8637 if (!empty($val['showoncombobox
'])) {
8638 $tmpfieldstoshow .= ($tmpfieldstoshow ? ',
' : '') . 't.
' . $key;
8641 if ($tmpfieldstoshow) {
8642 $fieldstoshow = $tmpfieldstoshow;
8645 // For backward compatibility
8646 $objecttmp->fields['ref
'] = array('type' => 'varchar(30)
', 'label
' => 'Ref
', 'showoncombobox
' => 1);
8649 if (empty($fieldstoshow)) {
8650 if (!empty($objecttmp->parent_element)) {
8651 $fieldstoshow = 'o.ref
';
8652 if (empty($sortfield)) {
8653 $sortfield = 'o.ref
';
8655 if (in_array($objecttmp->element, ['commandedet
', 'propaldet
', 'facturedet
', 'expeditiondet
'])) {
8656 $fieldstoshow .= ',p.ref AS p_ref,p.label,t.description
';
8657 $sortfield .= ', p.ref
';
8659 } elseif (isset($objecttmp->fields['ref'])) {
8660 $fieldstoshow = 't.ref
';
8662 $langs->load("errors");
8663 $this->error = $langs->trans("ErrorNoFieldWithAttributeShowoncombobox");
8664 return $langs->trans('ErrorNoFieldWithAttributeShowoncombobox
');
8669 $outarray = array();
8670 $tmparray = array();
8675 $sql = "SELECT t.rowid, " . $fieldstoshow . " FROM " . $this->db->prefix() . $this->db->sanitize($objecttmp->table_element) . " as t";
8676 if (!empty($objecttmp->isextrafieldmanaged)) {
8677 $sql .= " LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($objecttmp->table_element) . "_extrafields as e ON t.rowid = e.fk_object";
8679 if (!empty($objecttmp->parent_element)) {
8680 $parent_properties = getElementProperties($objecttmp->parent_element);
8681 $sql .= " INNER JOIN " . $this->db->prefix() . $this->db->sanitize($parent_properties['table_element
']) . " as o ON o.rowid = t.".$objecttmp->fk_parent_attribute;
8683 if (in_array($objecttmp->parent_element, ['commande
', 'propal
', 'facture
', 'expedition
'])) {
8684 $sql .= " LEFT JOIN " . $this->db->prefix() . "product as p ON p.rowid = t.fk_product";
8686 if (isset($objecttmp->ismultientitymanaged)) {
8687 if (!is_numeric($objecttmp->ismultientitymanaged)) {
8688 $tmparray = explode('@
', $objecttmp->ismultientitymanaged);
8689 $sql .= " INNER JOIN " . $this->db->prefix() . $this->db->sanitize($tmparray[1]) . " as parenttable ON parenttable.rowid = t." . $this->db->sanitize($tmparray[0]);
8691 if ($objecttmp->ismultientitymanaged === 'fk_soc@societe
') {
8692 if (!$user->hasRight('societe
', 'client
', 'voir
')) {
8693 $sql .= ", " . $this->db->prefix() . "societe_commerciaux as sc";
8698 // Add where from hooks
8699 $parameters = array(
8700 'object' => $objecttmp,
8701 'htmlname
' => $htmlname,
8702 'filter
' => $filter,
8703 'searchkey
' => $searchkey
8706 $reshook = $hookmanager->executeHooks('selectForFormsListWhere
', $parameters); // Note that $action and $object may have been modified by hook
8707 if (!empty($hookmanager->resPrint)) {
8708 $sql .= $hookmanager->resPrint;
8710 $sql .= " WHERE 1=1";
8711 if (isset($objecttmp->ismultientitymanaged)) {
8712 if ($objecttmp->ismultientitymanaged == 1) {
8713 $sql .= " AND t.entity IN (" . getEntity($objecttmp->table_element) . ")";
8715 if (!is_numeric($objecttmp->ismultientitymanaged)) {
8716 $sql .= " AND parenttable.entity = t." . $this->db->sanitize($tmparray[0]);
8718 if ($objecttmp->ismultientitymanaged == 1 && !empty($user->socid)) {
8719 if ($objecttmp->element == 'societe
') {
8720 $sql .= " AND t.rowid = " . ((int) $user->socid);
8722 $sql .= " AND t.fk_soc = " . ((int) $user->socid);
8725 if ($objecttmp->ismultientitymanaged === 'fk_soc@societe
') {
8726 if (!$user->hasRight('societe
', 'client
', 'voir
')) {
8727 $sql .= " AND t.rowid = sc.fk_soc AND sc.fk_user = " . ((int) $user->id);
8731 $splittedfieldstoshow = explode(',
', $fieldstoshow);
8732 foreach ($splittedfieldstoshow as &$field2) {
8733 if (is_numeric($pos=strpos($field2, ' '))) {
8734 $field2 = substr($field2, 0, $pos);
8737 if ($searchkey != '') {
8738 $sql .= natural_search($splittedfieldstoshow, $searchkey);
8741 if ($filter) { // Syntax example "(t.ref:like:'SO-%
') and (t.date_creation:<:'20160101
')"
8743 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
8744 if ($errormessage) {
8745 return 'Error forging a SQL request from an universal criteria:
' . $errormessage;
8749 $sql .= $this->db->order($sortfield ? $sortfield : $fieldstoshow, "ASC");
8750 //$sql.=$this->db->plimit($limit, 0);
8753 // Build output string
8754 $resql = $this->db->query($sql);
8756 // Construct $out and $outarray
8757 $out .= '<select
id=
"' . $htmlname . '" class=
"flat minwidth100' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled=
"disabled"' : '') . ($moreparams ? ' ' . $moreparams : '') . ' name=
"' . $htmlname . '">
' . "\n";
8759 // Warning: Do not use textifempty = ' ' or '
' here, or search on key will search on ' key
'. Seems it is no more true with selec2 v4
8760 $textifempty = '
';
8762 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
8763 if (getDolGlobalInt($confkeyforautocompletemode)) {
8764 if ($showempty && !is_numeric($showempty)) {
8765 $textifempty = $langs->trans($showempty);
8767 $textifempty .= $langs->trans("All");
8771 $out .= '<option value=
"-1">
' . $textifempty . '</option>
' . "\n";
8774 $num = $this->db->num_rows($resql);
8778 $obj = $this->db->fetch_object($resql);
8781 $tmparray = explode(',
', $fieldstoshow);
8782 $oldvalueforshowoncombobox = 0;
8783 foreach ($tmparray as $key => $val) {
8784 $val = preg_replace('/(t|p|o)\./
', '', $val);
8785 $label .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val]['showoncombobox
'] ? ' -
' : ' ') : '');
8786 $labelhtml .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val]['showoncombobox
'] ? ' -
' : ' ') : '');
8787 $label .= $obj->$val;
8788 $labelhtml .= $obj->$val;
8790 $oldvalueforshowoncombobox = empty($objecttmp->fields[$val]['showoncombobox
']) ? 0 : $objecttmp->fields[$val]['showoncombobox
'];
8792 if (empty($outputmode)) {
8793 if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) {
8794 $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>
';
8796 $out .= '<option value=
"' . $obj->rowid . '" data-html=
"' . dol_escape_htmltag($labelhtml, 0, 0, '', 0, 1) . '">
' . dol_escape_htmltag($label, 0, 0, '', 0, 1) . '</option>
';
8799 array_push($outarray, array('key
' => $obj->rowid, 'value
' => $label, 'label
' => $label));
8803 if (($i % 10) == 0) {
8809 $out .= '</select>
' . "\n";
8812 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
8813 $out .= ajax_combobox($htmlname, array(), getDolGlobalInt($confkeyforautocompletemode, 0));
8816 dol_print_error($this->db);
8819 $this->result = array('nbofelement
' => $num);
8851 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)
8853 global $conf, $langs;
8855 // Do we want a multiselect ?
8857 //if (preg_match('/^multi/
',$htmlname)) $jsbeautify = 1;
8860 if ($value_as_key) {
8861 $array = array_combine($array, $array);
8864 '@phan-var-force array{label:string,data-html:string,disable?:int<0,1>,css?:string} $array
'; // Array combine breaks information
8868 if ($addjscombo < 0) {
8869 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER
')) {
8875 $idname = str_replace(array('[
', ']
'), array('', ''), $htmlname);
8876 $out .= '<select id=
"' . preg_replace('/^\./', '', $idname) . '" ' . ($disabled ? 'disabled=
"disabled" ' : '') . 'class=
"flat ' . (preg_replace('/^\./', '', $htmlname)) . ($morecss ? ' ' . $morecss : '') . ' selectformat"';
8877 $out .= ' name=
"' . preg_replace('/^\./', '', $htmlname) . '" ' . ($moreparam ? $moreparam : '');
8881 $textforempty = ' ';
8882 if (!empty($conf->use_javascript_ajax)) {
8883 $textforempty = '
'; // If we use ajaxcombo, we need here to avoid to have an empty element that is too small.
8885 if (!is_numeric($show_empty)) {
8886 $textforempty = $show_empty;
8888 $out .= '<option
class=
"optiongrey" ' . ($moreparamonempty ? $moreparamonempty . ' ' : '') . 'value=
"' . (((int) $show_empty) < 0 ? $show_empty : -1) . '"' . ($id == $show_empty ? ' selected
' : '') . '>
' . $textforempty . '</option>
' . "\n";
8890 if (is_array($array)) {
8893 foreach ($array as $key => $value) {
8894 if (!is_array($value)) {
8895 $array[$key] = $langs->trans($value);
8897 $array[$key]['label
'] = $langs->trans($value['label
']);
8902 if ($sort == 'ASC
') {
8904 } elseif ($sort == 'DESC
') {
8908 foreach ($array as $key => $tmpvalue) {
8909 if (is_array($tmpvalue)) {
8910 $value = $tmpvalue['label
'];
8911 //$valuehtml = empty($tmpvalue['data-html
']) ? $value : $tmpvalue['data-html
'];
8913 $style = empty($tmpvalue['css
']) ? '' : ' class=
"' . $tmpvalue['css'] . '"';
8916 //$valuehtml = $tmpvalue;
8920 if (!empty($disablebademail)) {
8921 if (($disablebademail == 1 && !preg_match('/<.+@.+>/
', $value))
8922 || ($disablebademail == 2 && preg_match('/---/
', $value))) {
8924 $style = ' class=
"warning"';
8927 if ($key_in_label) {
8928 if (empty($nohtmlescape)) {
8929 $selectOptionValue = dol_escape_htmltag($key . ' -
' . ($maxlen ? dol_trunc($value, $maxlen) : $value));
8931 $selectOptionValue = $key . ' -
' . ($maxlen ? dol_trunc($value, $maxlen) : $value);
8934 if (empty($nohtmlescape)) {
8935 $selectOptionValue = dol_escape_htmltag($maxlen ? dol_trunc($value, $maxlen) : $value);
8937 $selectOptionValue = $maxlen ? dol_trunc($value, $maxlen) : $value;
8939 if ($value == '' || $value == '-
') {
8940 $selectOptionValue = '
';
8943 $out .= '<option value=
"' . $key . '"';
8944 $out .= $style . $disabled;
8945 if (is_array($id)) {
8946 if (in_array($key, $id) && !$disabled) {
8947 $out .= ' selected
'; // To preselect a value
8950 $id = (string) $id; // if $id = 0, then $id = '0
'
8951 if ($id != '' && (($id == (string) $key) || ($id == 'ifone
' && count($array) == 1)) && !$disabled) {
8952 $out .= ' selected
'; // To preselect a value
8955 if (!empty($nohtmlescape)) { // deprecated. Use instead the key 'data-html
' into input $array, managed at next step to use HTML content.
8956 $out .= ' data-html=
"' . dol_escape_htmltag($selectOptionValue) . '"';
8959 if (is_array($tmpvalue)) {
8960 foreach ($tmpvalue as $keyforvalue => $valueforvalue) {
8961 if ($keyforvalue == 'labelhtml
') {
8962 $keyforvalue = 'data-html
';
8964 if (preg_match('/^data-/
', $keyforvalue)) { // The best solution if you want to use HTML values into the list is to use data-html.
8965 $out .= ' '.dol_escape_htmltag($keyforvalue).'=
"'.dol_escape_htmltag($valueforvalue).'"';
8970 $out .= $selectOptionValue;
8971 $out .= "</option>\n";
8974 $out .= "</select>";
8976 // Add code for jquery to use multiselect
8977 if ($addjscombo && $jsbeautify) {
8978 // Enhance with select2
8979 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
8980 $out .= ajax_combobox($idname, array(), 0, 0, 'resolve
', (((int) $show_empty) < 0 ? (string) $show_empty : '-1
'), $morecss);
9004 public static function selectArrayAjax($htmlname, $url, $id = '
', $moreparam = '', $moreparamtourl = '', $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0)
9006 global $conf, $langs;
9007 global $delayedhtmlcontent; // Will be used later outside of this function
9009 // TODO Use an internal dolibarr component instead of select2
9010 if (!getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT
') && !defined('REQUIRE_JQUERY_MULTISELECT
')) {
9014 $out = '<select
type=
"text" class=
"' . $htmlname . ($morecss ? ' ' . $morecss : '') . '" ' . ($moreparam ? $moreparam . ' ' : '') . 'name=
"' . $htmlname . '"></select>
';
9017 if (!empty($conf->use_javascript_ajax)) {
9018 $tmpplugin = 'select2
';
9019 $outdelayed = "\n" . '<!-- JS CODE TO ENABLE
' . $tmpplugin . ' for id ' . $htmlname . ' -->
9020 <script nonce=
"' . getNonce() . '">
9021 $(document).ready(
function () {
9023 ' . ($callurlonselect ? 'var saveRemoteData = [];
' : '') . '
9025 $(
".' . $htmlname . '").select2({
9028 url:
"' . $url . '",
9031 data: function (params) {
9033 q: params.term, // search term
9037 processResults: function (data) {
9038 // parse the results into the format expected by Select2.
9039 // since we are using custom formatting functions we do not need to alter the remote JSON data
9040 //console.log(data);
9041 saveRemoteData = data;
9042 /* format json result for select2 */
9044 $.each( data, function( key, value ) {
9045 result.push({id: key, text: value.text});
9047 //return {results:[{id:\'none\', text:\'aa\'}, {id:\'rrr\', text:\'Red\'},{id:\'bbb\', text:\'Search a into projects\'}], more:false}
9048 //console.log(result);
9049 return {results: result, more: false}
9053 language: select2arrayoflanguage,
9054 containerCssClass: \':all:\', /* Line to add class from the original SELECT propagated to the new <span class="select2-selection...> tag */
9056 escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
9057 minimumInputLength: ' . ((int) $minimumInputLength) .
',
9058 formatResult: function (result, container, query, escapeMarkup) {
9059 return escapeMarkup(result.text);
9063 ' . ($callurlonselect ?
'
9064 /* Code to execute a GET when we select a value */
9065 $(".' . $htmlname .
'").change(function() {
9066 var selected = $(".' . $htmlname .
'").val();
9067 console.log("We select in selectArrayAjax the entry "+selected)
9068 $(".' . $htmlname .
'").val(""); /* reset visible combo value */
9069 $.each( saveRemoteData, function( key, value ) {
9070 if (key == selected)
9072 console.log("selectArrayAjax - Do a redirect to "+value.url)
9073 location.assign(value.url);
9082 if ($acceptdelayedhtml) {
9083 $delayedhtmlcontent .= $outdelayed;
9085 $out .= $outdelayed;
9109 public static function selectArrayFilter($htmlname, $array,
$id =
'', $moreparam =
'', $disableFiltering = 0, $disabled = 0, $minimumInputLength = 1, $morecss =
'', $callurlonselect = 0, $placeholder =
'', $acceptdelayedhtml = 0, $textfortitle =
'')
9111 global
$conf, $langs;
9112 global $delayedhtmlcontent;
9115 if (!
getDolGlobalString(
'MAIN_USE_JQUERY_MULTISELECT') && !defined(
'REQUIRE_JQUERY_MULTISELECT')) {
9119 $out =
'<select type="text"'.($textfortitle ?
' title="'.dol_escape_htmltag($textfortitle).
'"' :
'').
' id="'.$htmlname.
'" class="'.$htmlname.($morecss ?
' ' . $morecss :
'').
'"'.($moreparam ?
' '.$moreparam :
'').
' name="'.$htmlname.
'"><option></option></select>';
9121 $formattedarrayresult = array();
9123 foreach ($array as $key => $value) {
9126 $o->text = $value[
'text'];
9127 $o->url = $value[
'url'];
9128 $formattedarrayresult[] = $o;
9132 if (!empty(
$conf->use_javascript_ajax)) {
9133 $tmpplugin =
'select2';
9134 $outdelayed =
"\n" .
'<!-- JS CODE TO ENABLE ' . $tmpplugin .
' for id ' . $htmlname .
' -->
9135 <script nonce="' .
getNonce() .
'">
9136 $(document).ready(function () {
9137 var data = ' . json_encode($formattedarrayresult) .
';
9139 ' . ($callurlonselect ?
'var saveRemoteData = ' . json_encode($array) .
';' :
'') .
'
9141 $(".' . $htmlname .
'").select2({
9143 language: select2arrayoflanguage,
9144 containerCssClass: \':all:\', /* Line to add class from the original SELECT propagated to the new <span class="select2-selection...> tag */
9146 escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
9147 minimumInputLength: ' . $minimumInputLength .
',
9148 formatResult: function (result, container, query, escapeMarkup) {
9149 return escapeMarkup(result.text);
9151 matcher: function (params, data) {
9153 if(! data.id) return null;';
9155 if ($callurlonselect) {
9159 var urlBase = data.url;
9160 var separ = urlBase.indexOf("?") >= 0 ? "&" : "?";
9161 /* console.log("params.term="+params.term); */
9162 /* console.log("params.term encoded="+encodeURIComponent(params.term)); */
9163 saveRemoteData[data.id].url = urlBase + separ + "search_all=" + encodeURIComponent(params.term.replace(/\"/g, ""));';
9166 if (!$disableFiltering) {
9169 if(data.text.match(new RegExp(params.term))) {
9184 ' . ($callurlonselect ?
'
9185 /* Code to execute a GET when we select a value */
9186 $(".' . $htmlname .
'").change(function() {
9187 var selected = $(".' . $htmlname .
'").val();
9188 console.log("We select "+selected)
9190 $(".' . $htmlname .
'").val(""); /* reset visible combo value */
9191 $.each( saveRemoteData, function( key, value ) {
9192 if (key == selected)
9194 console.log("selectArrayFilter - Do a redirect to "+value.url)
9195 location.assign(value.url);
9204 if ($acceptdelayedhtml) {
9205 $delayedhtmlcontent .= $outdelayed;
9207 $out .= $outdelayed;
9230 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)
9232 global
$conf, $langs;
9235 if ($addjscombo < 0) {
9243 $useenhancedmultiselect = 0;
9244 if (!empty(
$conf->use_javascript_ajax) && !defined(
'MAIN_DO_NOT_USE_JQUERY_MULTISELECT') && (
getDolGlobalString(
'MAIN_USE_JQUERY_MULTISELECT') || defined(
'REQUIRE_JQUERY_MULTISELECT'))) {
9246 $useenhancedmultiselect = 1;
9253 $out .=
'<input type="hidden" name="'.$htmlname.
'_multiselect" value="1">';
9255 $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";
9256 if (is_array($array) && !empty($array)) {
9257 if ($value_as_key) {
9258 $array = array_combine($array, $array);
9261 if (!empty($array)) {
9262 foreach ($array as $key => $value) {
9268 if (is_array($value) && array_key_exists(
'id', $value) && array_key_exists(
'label', $value)) {
9269 $tmpkey = $value[
'id'];
9270 $tmpvalue = empty($value[
'label']) ?
'' : $value[
'label'];
9271 $tmpcolor = empty($value[
'color']) ?
'' : $value[
'color'];
9272 $tmppicto = empty($value[
'picto']) ?
'' : $value[
'picto'];
9273 $tmplabelhtml = empty($value[
'labelhtml']) ? (empty($value[
'data-html']) ?
'' : $value[
'data-html']) : $value[
'labelhtml'];
9275 $newval = ($translate ? $langs->trans($tmpvalue) : $tmpvalue);
9276 $newval = ($key_in_label ? $tmpkey .
' - ' . $newval : $newval);
9278 $out .=
'<option value="' . $tmpkey .
'"';
9279 if (is_array($selected) && !empty($selected) && in_array((
string) $tmpkey, $selected) && ((string) $tmpkey !=
'')) {
9280 $out .=
' selected';
9282 if (!empty($tmplabelhtml)) {
9285 $tmplabelhtml = ($tmppicto ?
img_picto(
'', $tmppicto,
'class="pictofixedwidth" style="color: #' . $tmpcolor .
'"') :
'') . $newval;
9290 $out .=
'</option>' .
"\n";
9294 $out .=
'</select>' .
"\n";
9297 if (!empty(
$conf->use_javascript_ajax) &&
getDolGlobalString(
'MAIN_USE_JQUERY_MULTISELECT') || defined(
'REQUIRE_JQUERY_MULTISELECT')) {
9298 $out .=
"\n" .
'<!-- JS CODE TO ENABLE select for id ' . $htmlname .
', addjscombo=' . $addjscombo .
' -->';
9299 $out .=
"\n" .
'<script nonce="' .
getNonce() .
'">' .
"\n";
9300 if ($addjscombo == 1) {
9301 $tmpplugin = !
getDolGlobalString(
'MAIN_USE_JQUERY_MULTISELECT') ? constant(
'REQUIRE_JQUERY_MULTISELECT') :
$conf->global->MAIN_USE_JQUERY_MULTISELECT;
9302 $out .=
'function formatResult(record, container) {' .
"\n";
9305 $out .=
' if ($(record.element).attr("data-html") != undefined && typeof htmlEntityDecodeJs === "function") {';
9307 $out .=
' return htmlEntityDecodeJs($(record.element).attr("data-html"));';
9309 $out .=
' return record.text;';
9311 $out .=
'function formatSelection(record) {' .
"\n";
9312 if ($elemtype ==
'category') {
9313 $out .=
'return \'<span><img src="' . DOL_URL_ROOT .
'/theme/eldy/img/object_category.png"> \'+record.text+\'</span>\';';
9315 $out .=
'return record.text;';
9318 $out .=
'$(document).ready(function () {
9319 $(\'#' . $htmlname .
'\').
' . $tmpplugin . '({
';
9327 $out .= ' dir: \
'ltr\',
9328 containerCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag (ko with multiselect) */
9329 dropdownCssClass: \'' . $morecss .
'\',
9331 formatResult: formatResult,
9332 templateResult: formatResult,
9333 escapeMarkup:
function (markup) {
return markup; },
9335 formatSelection: formatSelection,
9336 templateSelection: formatSelection
9341 $(\
'#' . $htmlname .
' + .select2\').addClass(\'' . $morecss .
'\');
9343 } elseif ($addjscombo == 2 && !defined('DISABLE_MULTISELECT
')) {
9345 // TODO external lib multiselect/jquery.multi-select.js must have been loaded to use this multiselect plugin
9347 $out .= 'console.log(\
'addjscombo=2 for htmlname=' . $htmlname .
'\');
';
9348 $out .= '$(document).ready(
function () {
9349 $(\
'#' . $htmlname .
'\').multiSelect({
9350 containerHTML: \
'<div class="multi-select-container">\',
9351 menuHTML: \'<div class="multi-select-menu">\',
9352 buttonHTML: \'<span class="multi-select-button ' . $morecss .
'">\',
9353 menuItemHTML: \'<label class="multi-select-menuitem">\',
9354 activeClass: \'multi-select-container--open\',
9355 noneText: \'' . $placeholder .
'\'
9359 $out .= '</script>
';
9377 public static function multiSelectArrayWithCheckbox($htmlname, &$array, $varpage, $pos = '
')
9379 global $langs, $user;
9381 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER
')) {
9384 if (empty($array)) {
9388 $tmpvar = "MAIN_SELECTEDFIELDS_" . $varpage; // To get list of saved selected fields to show
9390 if (!empty($user->conf->$tmpvar)) { // A list of fields was already customized for user
9391 $tmparray = explode(',
', $user->conf->$tmpvar);
9392 foreach ($array as $key => $val) {
9394 //var_dump($tmparray);
9395 if (in_array($key, $tmparray)) {
9396 $array[$key]['checked
'] = 1;
9398 $array[$key]['checked
'] = 0;
9401 } else { // There is no list of fields already customized for user
9402 foreach ($array as $key => $val) {
9403 if (!empty($array[$key]['checked
']) && $array[$key]['checked
'] < 0) {
9404 $array[$key]['checked
'] = 0;
9409 $listoffieldsforselection = '';
9410 $listcheckedstring = '';
9412 foreach ($array as $key => $val) {
9414 // var_dump(array_key_exists('enabled
', $val));
9415 // var_dump(!$val['enabled
']);
9416 if (array_key_exists('enabled
', $val) && isset($val['enabled
']) && !$val['enabled
']) {
9417 unset($array[$key]); // We don't want
this field
9420 if (!empty($val[
'type']) && $val[
'type'] ==
'separate') {
9425 if (!empty($val[
'label']) && $val[
'label']) {
9426 if (!empty($val[
'langfile']) && is_object($langs)) {
9427 $langs->load($val[
'langfile']);
9431 $listoffieldsforselection .=
'<li><input type="checkbox" id="checkbox' . $key .
'" value="' . $key .
'"' . ((!array_key_exists(
'checked', $val) || empty($val[
'checked']) || $val[
'checked'] ==
'-1') ?
'' :
' checked="checked"') .
'/><label for="checkbox' . $key .
'">' .
dol_escape_htmltag($langs->trans($val[
'label'])) .
'</label></li>';
9432 $listcheckedstring .= (empty($val[
'checked']) ?
'' : $key .
',');
9436 $out =
'<!-- Component multiSelectArrayWithCheckbox ' . $htmlname .
' -->
9438 <dl class="dropdown">
9440 <a href="#' . $htmlname .
'">
9443 <input type="hidden" class="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $listcheckedstring .
'">
9445 <dd class="dropdowndd">
9446 <div class="multiselectcheckbox'.$htmlname.
'">
9447 <ul class="'.$htmlname.($pos ==
'1' ?
'left' :
'').
'">
9448 <li class="liinputsearch"><input class="inputsearch_dropdownselectedfields width90p minwidth200imp" style="width:90%;" type="text" placeholder="'.$langs->trans(
'Search').
'"></li>
9449 '.$listoffieldsforselection.
'
9455 <script nonce="' .
getNonce() .
'" type="text/javascript">
9456 jQuery(document).ready(function () {
9457 $(\'.multiselectcheckbox' . $htmlname .
' input[type="checkbox"]\').on(\'click\', function () {
9458 console.log("A new field was added/removed, we edit field input[name=formfilteraction]");
9460 $("input:hidden[name=formfilteraction]").val(\'listafterchangingselectedfields\'); // Update field so we know we changed something on selected fields after POST
9462 var title = $(this).val() + ",";
9463 if ($(this).is(\':checked\')) {
9464 $(\'.' . $htmlname .
'\').val(title + $(\
'.' . $htmlname .
'\').val());
9467 $(\
'.' . $htmlname .
'\').val( $(\
'.' . $htmlname .
'\').val().replace(title, \
'\') )
9472 $(
"input.inputsearch_dropdownselectedfields").on(
"keyup",
function() {
9473 var value = $(
this).val().toLowerCase();
9474 $(\
'.multiselectcheckbox'.$htmlname.
' li > label\').filter(function() {
9475 $(this).parent().toggle($(this).text().toLowerCase().indexOf(value) > -1)
9498 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
9501 $categories = $cat->containing(
$id, $type);
9503 if ($rendermode == 1) {
9505 foreach ($categories as $c) {
9506 $ways = $c->print_all_ways(
' >> ', ($nolink ?
'none' :
''), 0, 1);
9507 foreach ($ways as $way) {
9508 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ?
' style="background: #' . $c->color .
';"' :
' style="background: #bbb"') .
'>' . $way .
'</li>';
9511 if (empty($toprint)) {
9514 return '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
9518 if ($rendermode == 0) {
9519 $arrayselected = array();
9521 foreach ($categories as $c) {
9522 $arrayselected[] = $c->id;
9525 return $this->
multiselectarray(
'categories', $cate_arbo, $arrayselected, 0, 0,
'', 0,
'100%',
'disabled',
'category');
9528 return 'ErrorBadValueForParameterRenderMode';
9542 global
$conf, $langs, $hookmanager;
9548 $hookmanager->initHooks(array(
'commonobject'));
9549 $parameters = array(
9550 'morehtmlright' => $morehtmlright,
9551 'compatibleImportElementsList' => &$compatibleImportElementsList,
9553 $reshook = $hookmanager->executeHooks(
'showLinkedObjectBlock', $parameters,
$object, $action);
9555 $nbofdifferenttypes = count(
$object->linkedObjects);
9557 if (empty($reshook)) {
9558 print
'<!-- showLinkedObjectBlock -->';
9559 print
load_fiche_titre($langs->trans($title), $morehtmlright,
'', 0,
'',
'showlinkedobjectblock');
9562 print
'<div class="div-table-responsive-no-min">';
9563 print
'<table class="noborder allwidth" data-block="showLinkedObject" data-element="' .
$object->element .
'" data-elementid="' .
$object->id .
'" >';
9565 print
'<tr class="liste_titre">';
9566 print
'<td>' . $langs->trans(
"Type") .
'</td>';
9567 print
'<td>' . $langs->trans(
"Ref") .
'</td>';
9568 print
'<td class="center"></td>';
9569 print
'<td class="center">' . $langs->trans(
"Date") .
'</td>';
9570 print
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
9571 print
'<td class="right">' . $langs->trans(
"Status") .
'</td>';
9575 $nboftypesoutput = 0;
9577 foreach (
$object->linkedObjects as $objecttype => $objects) {
9578 $tplpath = $element = $subelement = $objecttype;
9581 $showImportButton =
false;
9582 if (!empty($compatibleImportElementsList) && in_array($element, $compatibleImportElementsList)) {
9583 $showImportButton =
true;
9587 if ($objecttype !=
'supplier_proposal' && preg_match(
'/^([^_]+)_([^_]+)/i', $objecttype, $regs)) {
9588 $element = $regs[1];
9589 $subelement = $regs[2];
9590 $tplpath = $element .
'/' . $subelement;
9592 $tplname =
'linkedobjectblock';
9595 if ($objecttype ==
'facture') {
9596 $tplpath =
'compta/' . $element;
9597 if (!isModEnabled(
'invoice')) {
9600 } elseif ($objecttype ==
'facturerec') {
9601 $tplpath =
'compta/facture';
9602 $tplname =
'linkedobjectblockForRec';
9603 if (!isModEnabled(
'invoice')) {
9606 } elseif ($objecttype ==
'propal') {
9607 $tplpath =
'comm/' . $element;
9608 if (!isModEnabled(
'propal')) {
9611 } elseif ($objecttype ==
'supplier_proposal') {
9612 if (!isModEnabled(
'supplier_proposal')) {
9615 } elseif ($objecttype ==
'shipping' || $objecttype ==
'shipment' || $objecttype ==
'expedition') {
9616 $tplpath =
'expedition';
9617 if (!isModEnabled(
'shipping')) {
9620 } elseif ($objecttype ==
'reception') {
9621 $tplpath =
'reception';
9622 if (!isModEnabled(
'reception')) {
9625 } elseif ($objecttype ==
'delivery') {
9626 $tplpath =
'delivery';
9630 } elseif ($objecttype ==
'ficheinter') {
9631 $tplpath =
'fichinter';
9632 if (!isModEnabled(
'intervention')) {
9635 } elseif ($objecttype ==
'invoice_supplier') {
9636 $tplpath =
'fourn/facture';
9637 } elseif ($objecttype ==
'order_supplier') {
9638 $tplpath =
'fourn/commande';
9639 } elseif ($objecttype ==
'expensereport') {
9640 $tplpath =
'expensereport';
9641 } elseif ($objecttype ==
'subscription') {
9642 $tplpath =
'adherents';
9643 } elseif ($objecttype ==
'conferenceorbooth') {
9644 $tplpath =
'eventorganization';
9645 } elseif ($objecttype ==
'conferenceorboothattendee') {
9646 $tplpath =
'eventorganization';
9647 } elseif ($objecttype ==
'mo') {
9649 if (!isModEnabled(
'mrp')) {
9652 } elseif ($objecttype ==
'project_task') {
9653 $tplpath =
'projet/tasks';
9656 global $linkedObjectBlock;
9657 $linkedObjectBlock = $objects;
9660 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array(
'/' . $tplpath .
'/tpl'));
9661 foreach ($dirtpls as $reldir) {
9662 $reldir = rtrim($reldir,
'/');
9663 if ($nboftypesoutput == ($nbofdifferenttypes - 1)) {
9664 global $noMoreLinkedObjectBlockAfter;
9665 $noMoreLinkedObjectBlockAfter = 1;
9668 $res = @include
dol_buildpath($reldir .
'/' . $tplname .
'.tpl.php');
9676 if (!$nboftypesoutput) {
9677 print
'<tr><td colspan="7"><span class="opacitymedium">' . $langs->trans(
"None") .
'</span></td></tr>';
9682 if (!empty($compatibleImportElementsList)) {
9683 $res = @include
dol_buildpath(
'core/tpl/objectlinked_lineimport.tpl.php');
9689 return $nbofdifferenttypes;
9703 global
$conf, $langs, $hookmanager, $form;
9707 $form =
new Form($this->db);
9711 $linktoelemlist =
'';
9712 $listofidcompanytoscan =
'';
9714 if (!is_object(
$object->thirdparty)) {
9718 $possiblelinks = array();
9720 $dontIncludeCompletedItems =
getDolGlobalString(
'DONT_INCLUDE_COMPLETED_ELEMENTS_LINKS');
9722 if (is_object(
$object->thirdparty) && !empty(
$object->thirdparty->id) &&
$object->thirdparty->id > 0) {
9723 $listofidcompanytoscan = (int)
$object->thirdparty->id;
9725 $listofidcompanytoscan .=
',' . (int)
$object->thirdparty->parent;
9728 include_once DOL_DOCUMENT_ROOT .
'/projet/class/project.class.php';
9729 $tmpproject =
new Project($this->db);
9730 $tmpproject->fetch(
$object->fk_project);
9731 if ($tmpproject->socid > 0 && ($tmpproject->socid !=
$object->thirdparty->id)) {
9732 $listofidcompanytoscan .=
',' . (int) $tmpproject->socid;
9737 $possiblelinks = array(
9739 'enabled' => isModEnabled(
'propal'),
9741 'label' =>
'LinkToProposal',
9742 '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' :
''),
9744 'shipping' => array(
9745 'enabled' => isModEnabled(
'shipping'),
9747 'label' =>
'LinkToExpedition',
9748 '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' :
''),
9751 'enabled' => isModEnabled(
'order'),
9753 'label' =>
'LinkToOrder',
9754 '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' :
''),
9755 'linkname' =>
'commande',
9758 'enabled' => isModEnabled(
'invoice'),
9760 'label' =>
'LinkToInvoice',
9761 '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' :
''),
9762 'linkname' =>
'facture',
9764 'invoice_template' => array(
9765 'enabled' => isModEnabled(
'invoice'),
9767 'label' =>
'LinkToTemplateInvoice',
9768 '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') .
')'.($dontIncludeCompletedItems ?
' AND t.paye < 1' :
''),
9771 'enabled' => isModEnabled(
'contract'),
9773 'label' =>
'LinkToContract',
9774 '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
9775 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',
9777 'fichinter' => array(
9778 'enabled' => isModEnabled(
'intervention'),
9780 'label' =>
'LinkToIntervention',
9781 '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') .
')',
9783 'supplier_proposal' => array(
9784 'enabled' => isModEnabled(
'supplier_proposal'),
9786 'label' =>
'LinkToSupplierProposal',
9787 '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' :
''),
9789 'order_supplier' => array(
9790 'enabled' => isModEnabled(
"supplier_order"),
9792 'label' =>
'LinkToSupplierOrder',
9793 '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' :
''),
9795 'invoice_supplier' => array(
9796 'enabled' => isModEnabled(
"supplier_invoice"),
9797 'perms' => 1,
'label' =>
'LinkToSupplierInvoice',
9798 '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' :
''),
9801 'enabled' => isModEnabled(
'ticket'),
9803 'label' =>
'LinkToTicket',
9804 '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' :
''),
9807 'enabled' => isModEnabled(
'mrp'),
9809 'label' =>
'LinkToMo',
9810 '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' :
''),
9815 if (
$object->table_element ==
'commande_fournisseur') {
9816 $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' :
'');
9817 } elseif (
$object->table_element ==
'mrp_mo') {
9818 $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' :
'');
9822 if (!empty($listofidcompanytoscan)) {
9824 $hookmanager->initHooks(array(
'commonobject'));
9825 $parameters = array(
'listofidcompanytoscan' => $listofidcompanytoscan,
'possiblelinks' => $possiblelinks);
9826 $reshook = $hookmanager->executeHooks(
'showLinkToObjectBlock', $parameters,
$object, $action);
9829 if (empty($reshook)) {
9830 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
9831 $possiblelinks = array_merge($possiblelinks, $hookmanager->resArray);
9833 } elseif ($reshook > 0) {
9834 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
9835 $possiblelinks = $hookmanager->resArray;
9839 if (!empty($possiblelinks)) {
9844 $htmltoenteralink =
'';
9845 foreach ($possiblelinks as $key => $possiblelink) {
9847 if (empty($possiblelink[
'enabled'])) {
9851 if (!empty($possiblelink[
'perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || !in_array($key, $excludelinksto))) {
9852 $htmltoenteralink .=
'<div id="' . $key .
'list"' . (empty(
$conf->use_javascript_ajax) ?
'' :
' style="display:none"') .
'>';
9856 $htmltoenteralink .=
'<br>'.
"\n";
9857 $htmltoenteralink .=
'<!-- form to add a link from anywhere -->'.
"\n";
9858 $htmltoenteralink .=
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinkedbyref' . $key .
'">';
9859 $htmltoenteralink .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
9860 $htmltoenteralink .=
'<input type="hidden" name="action" value="addlinkbyref">';
9861 $htmltoenteralink .=
'<input type="hidden" name="id" value="' .
$object->id .
'">';
9862 $htmltoenteralink .=
'<input type="hidden" name="addlink" value="' . $key .
'">';
9863 $htmltoenteralink .=
'<table class="noborder">';
9864 $htmltoenteralink .=
'<tr class="liste_titre">';
9866 $htmltoenteralink .=
'<td class="center"><input type="text" placeholder="'.dol_escape_htmltag($langs->trans(
"Ref")).
'" name="reftolinkto" value="' .
dol_escape_htmltag(
GETPOST(
'reftolinkto',
'alpha')) .
'"> ';
9867 $htmltoenteralink .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
'ToLink') .
'"> ';
9868 $htmltoenteralink .=
'<input type="submit" class="button smallpaddingimp" name="cancel" value="' . $langs->trans(
'Cancel') .
'"></td>';
9869 $htmltoenteralink .=
'</tr>';
9870 $htmltoenteralink .=
'</table>';
9871 $htmltoenteralink .=
'</form>';
9874 $sql = $possiblelink[
'sql'];
9876 $resqllist = $this->db->query($sql);
9878 $num = $this->db->num_rows($resqllist);
9884 $htmltoenteralink .=
'<br>';
9886 $htmltoenteralink .=
'<!-- form to add a link from object to same thirdparty -->'.
"\n";
9887 $htmltoenteralink .=
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinked' . $key .
'">';
9888 $htmltoenteralink .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
9889 $htmltoenteralink .=
'<input type="hidden" name="action" value="addlink">';
9890 $htmltoenteralink .=
'<input type="hidden" name="id" value="' .
$object->id .
'">';
9891 $htmltoenteralink .=
'<input type="hidden" name="addlink" value="' . $key .
'">';
9892 $htmltoenteralink .=
'<table class="noborder">';
9893 $htmltoenteralink .=
'<tr class="liste_titre">';
9894 $htmltoenteralink .=
'<td class="nowrap"></td>';
9895 $htmltoenteralink .=
'<td>' . $langs->trans(
"Ref") .
'</td>';
9896 $htmltoenteralink .=
'<td>' . $langs->trans(
"RefCustomer") .
'</td>';
9897 $htmltoenteralink .=
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
9898 $htmltoenteralink .=
'<td>' . $langs->trans(
"Company") .
'</td>';
9899 $htmltoenteralink .=
'</tr>';
9901 $objp = $this->db->fetch_object($resqllist);
9902 $alreadylinked =
false;
9903 if (!empty(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key])) {
9904 if (in_array($objp->rowid, array_values(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key]))) {
9905 $alreadylinked =
true;
9908 $htmltoenteralink .=
'<tr class="oddeven">';
9909 $htmltoenteralink .=
'<td>';
9910 if ($alreadylinked) {
9911 $htmltoenteralink .=
img_picto(
'',
'link');
9913 $htmltoenteralink .=
'<input type="checkbox" name="idtolinkto[' . $key .
'_' . $objp->rowid .
']" id="' . $key .
'_' . $objp->rowid .
'" value="' . $objp->rowid .
'">';
9915 $htmltoenteralink .=
'</td>';
9916 $htmltoenteralink .=
'<td><label for="' . $key .
'_' . $objp->rowid .
'">' . $objp->ref .
'</label></td>';
9917 $htmltoenteralink .=
'<td>' . (!empty($objp->ref_client) ? $objp->ref_client : (!empty($objp->ref_supplier) ? $objp->ref_supplier :
'')) .
'</td>';
9918 $htmltoenteralink .=
'<td class="right">';
9919 if ($possiblelink[
'label'] ==
'LinkToContract') {
9920 $htmltoenteralink .= $form->textwithpicto(
'', $langs->trans(
"InformationOnLinkToContract")) .
' ';
9922 $htmltoenteralink .=
'<span class="amount">' . (isset($objp->total_ht) ?
price($objp->total_ht) :
'') .
'</span>';
9923 $htmltoenteralink .=
'</td>';
9924 $htmltoenteralink .=
'<td>' . $objp->name .
'</td>';
9925 $htmltoenteralink .=
'</tr>';
9928 $htmltoenteralink .=
'</table>';
9929 $htmltoenteralink .=
'<div class="center">';
9931 $htmltoenteralink .=
'<input type="submit" class="button valignmiddle marginleftonly marginrightonly smallpaddingimp" value="' . $langs->trans(
'ToLink') .
'">';
9933 if (empty(
$conf->use_javascript_ajax)) {
9934 $htmltoenteralink .=
'<input type="submit" class="button button-cancel marginleftonly marginrightonly smallpaddingimp" name="cancel" value="' . $langs->trans(
"Cancel") .
'"></div>';
9936 $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>';
9938 $htmltoenteralink .=
'</form>';
9941 $this->db->free($resqllist);
9945 $htmltoenteralink .=
'</div>';
9950 $linktoelemlist .=
'<li><a href="#linkto' . $key .
'" class="linkto dropdowncloseonclick" rel="' . $key .
'">' . $langs->trans($possiblelink[
'label']) .
' (' . $num .
')</a></li>';
9953 $linktoelemlist .=
'<li><span class="linktodisabled">' . $langs->trans($possiblelink[
'label']) .
' (0)</span></li>';
9958 if ($linktoelemlist) {
9960 <dl class="dropdown" id="linktoobjectname">
9962 if (!empty(
$conf->use_javascript_ajax)) {
9963 $linktoelem .=
'<dt><a href="#linktoobjectname"><span class="fas fa-link paddingrightonly"></span>' . $langs->trans(
"LinkTo") .
'...</a></dt>';
9965 $linktoelem .=
'<dd>
9966 <div class="multiselectlinkto">
9967 <ul class="ulselectedfields">' . $linktoelemlist .
'
9976 if (!empty(
$conf->use_javascript_ajax)) {
9977 print
'<!-- Add js to show linkto box -->
9978 <script nonce="' .
getNonce() .
'">
9979 jQuery(document).ready(function() {
9980 jQuery(".linkto").click(function() {
9981 console.log("We choose to show/hide links for rel="+jQuery(this).attr(\'rel\')+" so #"+jQuery(this).attr(\'rel\')+"list");
9982 jQuery("#"+jQuery(this).attr(\'rel\')+"list").toggle();
9990 return array(
'linktoelem' => $linktoelem,
'htmltoenteralink' => $htmltoenteralink);
9992 print $htmltoenteralink;
10012 public function selectyesno($htmlname, $value =
'', $option = 0, $disabled =
false, $useempty = 0, $addjscombo = 0, $morecss =
'width75', $labelyes =
'Yes', $labelno =
'No')
10023 $disabled = ($disabled ?
' disabled' :
'');
10025 $resultyesno =
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'"' . $disabled .
'>' .
"\n";
10027 $resultyesno .=
'<option value="-1"' . (($value < 0) ?
' selected' :
'') .
'> </option>' .
"\n";
10029 if ((
"$value" ==
'yes') || ($value == 1)) {
10030 $resultyesno .=
'<option value="' . $yes .
'" selected>' . $langs->trans($labelyes) .
'</option>' .
"\n";
10031 $resultyesno .=
'<option value="' . $no .
'">' . $langs->trans($labelno) .
'</option>' .
"\n";
10033 $selected = (($useempty && $value !=
'0' && $value !=
'no') ?
'' :
' selected');
10034 $resultyesno .=
'<option value="' . $yes .
'">' . $langs->trans($labelyes) .
'</option>' .
"\n";
10035 $resultyesno .=
'<option value="' . $no .
'"' . $selected .
'>' . $langs->trans($labelno) .
'</option>' .
"\n";
10037 $resultyesno .=
'</select>' .
"\n";
10040 $resultyesno .=
ajax_combobox($htmlname, array(), 0, 0,
'resolve', ($useempty < 0 ? (
string) $useempty :
'-1'), $morecss);
10043 return $resultyesno;
10060 $sql =
"SELECT rowid, label";
10061 $sql .=
" FROM " . $this->db->prefix() .
"export_model";
10062 $sql .=
" WHERE type = '" . $this->db->escape($type) .
"'";
10063 $sql .=
" ORDER BY rowid";
10064 $result = $this->db->query($sql);
10066 print
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
10068 print
'<option value="-1"> </option>';
10071 $num = $this->db->num_rows($result);
10073 while ($i < $num) {
10074 $obj = $this->db->fetch_object($result);
10075 if ($selected == $obj->rowid) {
10076 print
'<option value="' . $obj->rowid .
'" selected>';
10078 print
'<option value="' . $obj->rowid .
'">';
10108 public function showrefnav(
$object, $paramid, $morehtml =
'', $shownav = 1, $fieldid =
'rowid', $fieldref =
'ref', $morehtmlref =
'', $moreparam =
'', $nodbprefix = 0, $morehtmlleft =
'', $morehtmlstatus =
'', $morehtmlright =
'')
10110 global
$conf, $langs, $hookmanager, $extralanguages;
10113 if (empty($fieldid)) {
10114 $fieldid =
'rowid';
10116 if (empty($fieldref)) {
10121 $addgendertxt =
'';
10122 if (property_exists(
$object,
'gender') && !empty(
$object->gender)) {
10123 $addgendertxt =
' ';
10126 $addgendertxt .=
'<i class="fas fa-mars valignmiddle"></i>';
10129 $addgendertxt .=
'<i class="fas fa-venus valignmiddle"></i>';
10132 $addgendertxt .=
'<i class="fas fa-transgender valignmiddle"></i>';
10138 if (is_object($hookmanager)) {
10139 $parameters = array(
'showrefnav' =>
true);
10140 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters,
$object);
10141 $object->next_prev_filter .= $hookmanager->resPrint;
10144 $previous_ref = $next_ref =
'';
10147 $object->load_previous_next_ref((isset(
$object->next_prev_filter) ?
$object->next_prev_filter :
''), $fieldid, $nodbprefix);
10149 $navurl = $_SERVER[
"PHP_SELF"];
10151 if ($paramid ==
'project_ref') {
10152 if (preg_match(
'/\/tasks\/(task|contact|note|document)\.php/', $navurl)) {
10153 $navurl = preg_replace(
'/\/tasks\/(task|contact|time|note|document)\.php/',
'/tasks.php', $navurl);
10160 $stringforfirstkey = $langs->trans(
"KeyboardShortcut");
10161 if (
$conf->browser->name ==
'chrome') {
10162 $stringforfirstkey .=
' ALT +';
10163 } elseif (
$conf->browser->name ==
'firefox') {
10164 $stringforfirstkey .=
' ALT + SHIFT +';
10166 $stringforfirstkey .=
' CTL +';
10169 $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>';
10170 $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>';
10174 $ret .=
'<!-- Start banner content --><div style="vertical-align: middle">';
10177 if ($morehtmlright) {
10178 $ret .=
'<div class="inline-block floatleft">' . $morehtmlright .
'</div>';
10181 if ($previous_ref || $next_ref || $morehtml) {
10182 $ret .=
'<div class="pagination paginationref"><ul class="right">';
10184 if ($morehtml &&
getDolGlobalInt(
'MAIN_OPTIMIZEFORTEXTBROWSER') < 2) {
10185 $ret .=
'<!-- morehtml --><li class="noborder litext' . (($shownav && $previous_ref && $next_ref) ?
' clearbothonsmartphone' :
'') .
'">' . $morehtml .
'</li>';
10187 if ($shownav && ($previous_ref || $next_ref)) {
10188 $ret .=
'<li class="pagination">' . $previous_ref .
'</li>';
10189 $ret .=
'<li class="pagination">' . $next_ref .
'</li>';
10191 if ($previous_ref || $next_ref || $morehtml) {
10192 $ret .=
'</ul></div>';
10196 $parameters = array(
'morehtmlstatus' => $morehtmlstatus);
10197 $reshook = $hookmanager->executeHooks(
'moreHtmlStatus', $parameters,
$object);
10198 if (empty($reshook)) {
10199 $morehtmlstatus .= $hookmanager->resPrint;
10201 $morehtmlstatus = $hookmanager->resPrint;
10203 if ($morehtmlstatus) {
10204 $ret .=
'<div class="statusref">' . $morehtmlstatus .
'</div>';
10207 $parameters = array();
10208 $reshook = $hookmanager->executeHooks(
'moreHtmlRef', $parameters,
$object);
10209 if (empty($reshook)) {
10210 $morehtmlref .= $hookmanager->resPrint;
10211 } elseif ($reshook > 0) {
10212 $morehtmlref = $hookmanager->resPrint;
10216 if ($morehtmlleft) {
10217 if (
$conf->browser->layout ==
'phone') {
10218 $ret .=
'<!-- morehtmlleft --><div class="floatleft">' . $morehtmlleft .
'</div>';
10220 $ret .=
'<!-- morehtmlleft --><div class="inline-block floatleft">' . $morehtmlleft .
'</div>';
10225 $ret .=
'<div class="inline-block floatleft valignmiddle maxwidth750 marginbottomonly refid' . (($shownav && ($previous_ref || $next_ref)) ?
' refidpadding' :
'') .
'">';
10228 if (
$object->element ==
'societe') {
10232 $arrayoflangcode = array();
10237 if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
10238 if (!is_object($extralanguages)) {
10239 include_once DOL_DOCUMENT_ROOT .
'/core/class/extralanguages.class.php';
10242 $extralanguages->fetch_name_extralanguages(
'societe');
10244 if (!empty($extralanguages->attributes[
'societe'][
'name'])) {
10245 $object->fetchValuesForExtraLanguages();
10249 foreach ($arrayoflangcode as $extralangcode) {
10251 if (
$object->array_languages[
'name'][$extralangcode]) {
10252 $htmltext .=
$object->array_languages[
'name'][$extralangcode];
10254 $htmltext .=
'<span class="opacitymedium">' . $langs->trans(
"SwitchInEditModeToAddTranslation") .
'</span>';
10257 $ret .=
'<!-- Show translations of name -->' .
"\n";
10258 $ret .= $this->
textwithpicto(
'', $htmltext, -1,
'language',
'opacitymedium paddingleft');
10261 } elseif (
$object->element ==
'member') {
10262 '@phan-var-force Adherent $object';
10263 $ret .=
$object->ref .
'<br>';
10264 $fullname =
$object->getFullName($langs);
10270 } elseif (in_array(
$object->element, array(
'contact',
'user'))) {
10271 $ret .=
'<span class="valignmiddle">'.dol_htmlentities(
$object->getFullName($langs)).
'</span>'.$addgendertxt;
10272 } elseif (
$object->element ==
'usergroup') {
10274 } elseif (in_array(
$object->element, array(
'action',
'agenda'))) {
10275 '@phan-var-force ActionComm $object';
10277 } elseif (in_array(
$object->element, array(
'adherent_type'))) {
10279 } elseif (
$object->element ==
'ecm_directories') {
10281 } elseif ($fieldref !=
'none') {
10284 if ($morehtmlref) {
10286 if (substr($morehtmlref, 0, 4) !=
'<div') {
10290 $ret .=
'<!-- morehtmlref -->'.$morehtmlref;
10295 $ret .=
'</div><!-- End banner content -->';
10314 if (empty(
$object->barcode)) {
10319 if (empty(
$object->barcode_type_code) || empty(
$object->barcode_type_coder)) {
10321 $result =
$object->fetchBarCode();
10324 return '<!-- ErrorFetchBarcode -->';
10329 $url = DOL_URL_ROOT .
'/viewimage.php?modulepart=barcode&generator=' . urlencode(
$object->barcode_type_coder) .
'&code=' . urlencode(
$object->barcode) .
'&encoding=' . urlencode(
$object->barcode_type_code);
10330 $out =
'<!-- url barcode = ' . $url .
' -->';
10331 $out .=
'<img src="' . $url .
'"' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
'>';
10353 public static function showphoto($modulepart,
$object, $width = 100, $height = 0, $caneditfield = 0, $cssclass =
'photowithmargin', $imagesize =
'', $addlinktofullsize = 1, $cache = 0, $forcecapture =
'', $noexternsourceoverwrite = 0)
10355 global
$conf, $langs;
10362 $originalfile =
'';
10366 if ($modulepart ==
'societe') {
10367 $dir =
$conf->societe->multidir_output[$entity];
10370 if ((
string) $imagesize ==
'mini') {
10372 } elseif ((
string) $imagesize ==
'small') {
10381 } elseif ($modulepart ==
'contact') {
10382 $dir =
$conf->societe->multidir_output[$entity] .
'/contact';
10383 if (!empty(
$object->photo)) {
10385 if ((
string) $imagesize ==
'mini') {
10387 } elseif ((
string) $imagesize ==
'small') {
10397 } elseif ($modulepart ==
'userphoto') {
10398 $dir =
$conf->user->dir_output;
10399 if (!empty(
$object->photo)) {
10401 if ((
string) $imagesize ==
'mini') {
10403 } elseif ((
string) $imagesize ==
'small') {
10412 $altfile =
$object->id .
".jpg";
10416 } elseif ($modulepart ==
'memberphoto') {
10417 $dir =
$conf->adherent->dir_output;
10418 if (!empty(
$object->photo)) {
10420 if ((
string) $imagesize ==
'mini') {
10422 } elseif ((
string) $imagesize ==
'small') {
10431 $altfile =
$object->id .
".jpg";
10438 if ($modulepart !=
"unknown" && method_exists(
$object,
'getDataToShowPhoto')) {
10439 $tmpdata =
$object->getDataToShowPhoto($modulepart, $imagesize);
10441 $dir = $tmpdata[
'dir'];
10442 $file = $tmpdata[
'file'];
10443 $originalfile = $tmpdata[
'originalfile'];
10444 $altfile = $tmpdata[
'altfile'];
10445 $email = $tmpdata[
'email'];
10446 $capture = $tmpdata[
'capture'];
10450 if ($forcecapture) {
10451 $capture = $forcecapture;
10457 if ($file && file_exists($dir .
"/" . $file)) {
10458 if ($addlinktofullsize) {
10460 if ($urladvanced) {
10461 $ret .=
'<a href="' . $urladvanced .
'">';
10463 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
10466 $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 .
'">';
10467 if ($addlinktofullsize) {
10470 } elseif ($altfile && file_exists($dir .
"/" . $altfile)) {
10471 if ($addlinktofullsize) {
10473 if ($urladvanced) {
10474 $ret .=
'<a href="' . $urladvanced .
'">';
10476 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
10479 $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 .
'">';
10480 if ($addlinktofullsize) {
10484 $nophoto =
'/public/theme/common/nophoto.png';
10485 $defaultimg =
'identicon';
10486 if (in_array($modulepart, array(
'societe',
'userphoto',
'contact',
'memberphoto'))) {
10487 if ($modulepart ==
'societe' || ($modulepart ==
'memberphoto' && !empty(
$object->morphy) && strpos(
$object->morphy,
'mor') !==
false)) {
10488 $nophoto =
'company';
10490 $nophoto =
'/public/theme/common/user_anonymous.png';
10492 $nophoto =
'/public/theme/common/user_man.png';
10495 $nophoto =
'/public/theme/common/user_woman.png';
10500 if (isModEnabled(
'gravatar') && $email && empty($noexternsourceoverwrite)) {
10502 $ret .=
'<!-- Put link to gravatar -->';
10503 $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 .
'">';
10505 if ($nophoto ==
'company') {
10506 $ret .=
'<div class="divforspanimg valignmiddle center photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
'>' .
img_picto(
'',
'company') .
'</div>';
10509 $ret .=
'<img class="photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="' . DOL_URL_ROOT . $nophoto .
'">';
10514 if ($caneditfield) {
10518 $ret .=
'<table class="nobordernopadding centpercent">';
10520 $ret .=
'<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> <label for="photodelete">' . $langs->trans(
"Delete") .
'</label><br><br></td></tr>';
10522 $ret .=
'<tr><td class="tdoverflow">';
10524 $maxmin = $maxfilesizearray[
'maxmin'];
10526 $ret .=
'<input type="hidden" name="MAX_FILE_SIZE" value="' . ($maxmin * 1024) .
'">';
10528 $ret .=
'<input type="file" class="flat maxwidth200onsmartphone" name="photo" id="photoinput" accept="image/*"' . ($capture ?
' capture="' . $capture .
'"' :
'') .
'>';
10529 $ret .=
'</td></tr>';
10530 $ret .=
'</table>';
10555 public function select_dolgroups($selected = 0, $htmlname =
'groupid', $show_empty = 0, $exclude =
'', $disabled = 0, $include =
'', $enableonly = array(), $force_entity =
'0', $multiple =
false, $morecss =
'minwidth200')
10558 global
$conf, $user, $langs;
10561 $excludeGroups =
null;
10562 if (is_array($exclude)) {
10563 $excludeGroups = implode(
",", $exclude);
10566 $includeGroups =
null;
10567 if (is_array($include)) {
10568 $includeGroups = implode(
",", $include);
10571 if (!is_array($selected)) {
10572 $selected = array($selected);
10578 $sql =
"SELECT ug.rowid, ug.nom as name";
10579 if (isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && !$user->entity) {
10580 $sql .=
", e.label";
10582 $sql .=
" FROM " . $this->db->prefix() .
"usergroup as ug ";
10583 if (isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && !$user->entity) {
10584 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid=ug.entity";
10585 if ($force_entity) {
10586 $sql .=
" WHERE ug.entity IN (0, " . $force_entity .
")";
10588 $sql .=
" WHERE ug.entity IS NOT NULL";
10591 $sql .=
" WHERE ug.entity IN (0, " .
$conf->entity .
")";
10593 if (is_array($exclude) && $excludeGroups) {
10594 $sql .=
" AND ug.rowid NOT IN (" . $this->db->sanitize($excludeGroups) .
")";
10596 if (is_array($include) && $includeGroups) {
10597 $sql .=
" AND ug.rowid IN (" . $this->db->sanitize($includeGroups) .
")";
10599 $sql .=
" ORDER BY ug.nom ASC";
10601 dol_syslog(get_class($this) .
"::select_dolgroups", LOG_DEBUG);
10602 $resql = $this->db->query($sql);
10605 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
10607 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
10609 $num = $this->db->num_rows($resql);
10612 if ($show_empty && !$multiple) {
10613 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'> </option>' .
"\n";
10616 while ($i < $num) {
10617 $obj = $this->db->fetch_object($resql);
10619 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
10623 $label = $obj->name;
10624 $labelhtml = $obj->name;
10625 if (isModEnabled(
'multicompany') && !
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE') &&
$conf->entity == 1) {
10626 $label .=
" (" . $obj->label .
")";
10627 $labelhtml .=
' <span class="opacitymedium">(' . $obj->label .
')</span>';
10630 $out .=
'<option value="' . $obj->rowid .
'"';
10631 if ($disableline) {
10632 $out .=
' disabled';
10634 if ((isset($selected[0]) && is_object($selected[0]) && $selected[0]->
id == $obj->rowid)
10635 || ((!isset($selected[0]) || !is_object($selected[0])) && !empty($selected) && in_array($obj->rowid, $selected))) {
10636 $out .=
' selected';
10638 $out .=
' data-html="'.dol_escape_htmltag($labelhtml).
'"';
10641 $out .=
'</option>';
10646 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'></option>' .
"\n";
10648 $out .=
'<option value="" disabled>' . $langs->trans(
"NoUserGroupDefined") .
'</option>';
10650 $out .=
'</select>';
10669 $out =
'<div class="nowraponall">';
10670 $out .=
'<button type="submit" class="liste_titre button_search reposition" name="button_search_x" value="x"><span class="fas fa-search"></span></button>';
10671 $out .=
'<button type="submit" class="liste_titre button_removefilter reposition" name="button_removefilter_x" value="x"><span class="fas fa-times"></span></button>';
10685 public function showCheckAddButtons($cssclass =
'checkforaction', $calljsfunction = 0, $massactionname =
"massaction")
10691 if (!empty(
$conf->use_javascript_ajax)) {
10692 $out .=
'<div class="inline-block checkallactions"><input type="checkbox" id="' . $cssclass .
's" name="' . $cssclass .
's" class="checkallactions"></div>';
10694 $out .=
'<script nonce="' .
getNonce() .
'">
10695 $(document).ready(function() {
10696 $("#' . $cssclass .
's").click(function() {
10697 if($(this).is(\':checked\')){
10698 console.log("We check all ' . $cssclass .
' and trigger the change method");
10699 $(".' . $cssclass .
'").prop(\'checked\', true).trigger(\'change\');
10703 console.log("We uncheck all");
10704 $(".' . $cssclass .
'").prop(\'checked\', false).trigger(\'change\');
10706 if ($calljsfunction) {
10707 $out .=
'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0, "' . $massactionname .
'", "' . $cssclass .
'"); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }';
10710 $(".' . $cssclass .
'").change(function() {
10711 $(this).closest("tr").toggleClass("highlight", this.checked);
10731 if ($addcheckuncheckall) {
10750 public function selectExpenseCategories($selected =
'', $htmlname =
'fk_c_exp_tax_cat', $useempty = 0, $excludeid = array(), $target =
'', $default_selected = 0, $params = array(), $info_admin = 1)
10752 global $langs, $user;
10755 $sql =
"SELECT rowid, label FROM " . $this->db->prefix() .
"c_exp_tax_cat WHERE active = 1";
10756 $sql .=
" AND entity IN (0," .
getEntity(
'exp_tax_cat') .
")";
10757 if (!empty($excludeid)) {
10758 $sql .=
" AND rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeid)) .
")";
10760 $sql .=
" ORDER BY label";
10762 $resql = $this->db->query($sql);
10764 $out =
'<select id="select_' . $htmlname .
'" name="' . $htmlname .
'" class="' . $htmlname .
' flat minwidth75imp maxwidth200">';
10766 $out .=
'<option value="0"> </option>';
10769 while ($obj = $this->db->fetch_object($resql)) {
10770 $out .=
'<option ' . ($selected == $obj->rowid ?
'selected="selected"' :
'') .
' value="' . $obj->rowid .
'">' . $langs->trans($obj->label) .
'</option>';
10772 $out .=
'</select>';
10775 if (!empty($htmlname) && $user->admin && $info_admin) {
10776 $out .=
' ' .
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
10779 if (!empty($target)) {
10780 $sql =
"SELECT c.id FROM " . $this->db->prefix() .
"c_type_fees as c WHERE c.code = 'EX_KME' AND c.active = 1";
10781 $resql = $this->db->query($sql);
10783 if ($this->db->num_rows($resql) > 0) {
10784 $obj = $this->db->fetch_object($resql);
10785 $out .=
'<script nonce="' .
getNonce() .
'">
10787 $("select[name=' . $target .
']").on("change", function() {
10788 var current_val = $(this).val();
10789 if (current_val == ' . $obj->id .
') {';
10790 if (!empty($default_selected) || !empty($selected)) {
10791 $out .=
'$("select[name=' . $htmlname .
']").val("' . ($default_selected > 0 ? $default_selected : $selected) .
'");';
10795 $("select[name=' . $htmlname .
']").change();
10799 $("select[name=' . $htmlname .
']").change(function() {
10801 if ($("select[name=' . $target .
']").val() == ' . $obj->id .
') {
10802 // get price of kilometer to fill the unit price
10806 data: { fk_c_exp_tax_cat: $(this).val(), token: \'' .
currentToken() .
'\' },
10807 url:
"' . (DOL_URL_ROOT . '/expensereport/ajax/ajaxik.php?' . implode('&', $params)) . '",
10808 }).done(
function( data, textStatus, jqXHR ) {
10810 if (typeof data.up !=
"undefined") {
10811 $(
"input[name=value_unit]").val(data.up);
10812 $(
"select[name=' . $htmlname . ']").attr(
"title", data.title);
10814 $(
"input[name=value_unit]").val(
"");
10815 $(
"select[name=' . $htmlname . ']").attr(
"title",
"");
10826 dol_print_error($this->db);
10840 public function selectExpenseRanges($selected = '
', $htmlname = 'fk_range
', $useempty = 0)
10842 global $conf, $langs;
10845 $sql = "SELECT rowid, range_ik FROM " . $this->db->prefix() . "c_exp_tax_range";
10846 $sql .= " WHERE entity = " . $conf->entity . " AND active = 1";
10848 $resql = $this->db->query($sql);
10850 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
10852 $out .= '<option value=
"0"></option>
';
10855 while ($obj = $this->db->fetch_object($resql)) {
10856 $out .= '<option
' . ($selected == $obj->rowid ? 'selected=
"selected"' : '') . ' value=
"' . $obj->rowid . '">
' . price($obj->range_ik, 0, $langs, 1, 0) . '</option>
';
10858 $out .= '</select>
';
10860 dol_print_error($this->db);
10876 public function selectExpense($selected = '
', $htmlname = 'fk_c_type_fees
', $useempty = 0, $allchoice = 1, $useid = 0)
10881 $sql = "SELECT id, code, label";
10882 $sql .= " FROM ".$this->db->prefix()."c_type_fees";
10883 $sql .= " WHERE active = 1";
10885 $resql = $this->db->query($sql);
10887 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
10889 $out .= '<option value=
"0"></option>
';
10892 $out .= '<option value=
"-1">
' . $langs->trans('AllExpenseReport
') . '</option>
';
10900 while ($obj = $this->db->fetch_object($resql)) {
10901 $key = $langs->trans($obj->code);
10902 $out .= '<option
' . ($selected == $obj->{$field} ? 'selected=
"selected"' : '') . ' value=
"' . $obj->{$field} . '">
' . ($key != $obj->code ? $key : $obj->label) . '</option>
';
10904 $out .= '</select>
';
10906 $out .= ajax_combobox('select_
'.$htmlname);
10908 dol_print_error($this->db);
10932 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)
10934 global $user, $conf, $langs;
10936 require_once DOL_DOCUMENT_ROOT . '/projet/
class/project.class.php
';
10938 if (is_null($usertofilter)) {
10939 $usertofilter = $user;
10944 $hideunselectables = false;
10945 if (getDolGlobalString('PROJECT_HIDE_UNSELECTABLES
')) {
10946 $hideunselectables = true;
10949 if (empty($projectsListId)) {
10950 if (!$usertofilter->hasRight('projet
', 'all
', 'lire
')) {
10951 $projectstatic = new Project($this->db);
10952 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1);
10956 // Search all projects
10957 $sql = "SELECT f.rowid, f.ref as fref, 'nolabel
' as flabel, p.rowid as pid, f.ref,
10958 p.title, p.fk_soc, p.fk_statut, p.public,";
10959 $sql .= ' s.nom as
name';
10960 $sql .= ' FROM
' . $this->db->prefix() . 'projet as p
';
10961 $sql .= ' LEFT JOIN
' . $this->db->prefix() . 'societe as s ON s.rowid = p.fk_soc,
';
10962 $sql .= ' ' . $this->db->prefix() . 'facture as f
';
10963 $sql .= " WHERE p.entity IN (" . getEntity('project
') . ")";
10964 $sql .= " AND f.fk_projet = p.rowid AND f.fk_statut=0"; //Brouillons seulement
10965 //if ($projectsListId) $sql.= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")";
10966 //if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
10967 //if ($socid > 0) $sql.= " AND (p.fk_soc=".((int) $socid)." OR p.fk_soc IS NULL)";
10968 $sql .= " ORDER BY p.ref, f.ref ASC";
10970 $resql = $this->db->query($sql);
10972 // Use select2 selector
10973 if (!empty($conf->use_javascript_ajax)) {
10974 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
10975 $comboenhancement = ajax_combobox($htmlname, array(), 0, $forcefocus);
10976 $out .= $comboenhancement;
10977 $morecss = 'minwidth200imp maxwidth500
';
10980 if (empty($option_only)) {
10981 $out .= '<select
class=
"valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled=
"disabled"' : '') . ' id=
"' . $htmlname . '" name=
"' . $htmlname . '">
';
10983 if (!empty($show_empty)) {
10984 $out .= '<option value=
"0" class=
"optiongrey">
';
10985 if (!is_numeric($show_empty)) {
10986 $out .= $show_empty;
10990 $out .= '</option>
';
10992 $num = $this->db->num_rows($resql);
10995 while ($i < $num) {
10996 $obj = $this->db->fetch_object($resql);
10997 // 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.
10998 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$usertofilter->hasRight('societe
', 'lire
')) {
11001 if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) {
11008 if ($showproject == 'all
') {
11009 $labeltoshow .= dol_trunc($obj->ref, 18); // Invoice ref
11011 $labeltoshow .= ' -
' . $obj->name; // Soc name
11015 if ($obj->fk_statut == Project::STATUS_DRAFT) {
11017 $labeltoshow .= ' -
' . $langs->trans("Draft");
11018 } elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
11019 if ($discard_closed == 2) {
11022 $labeltoshow .= ' -
' . $langs->trans("Closed");
11023 } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
11025 $labeltoshow .= ' -
' . $langs->trans("LinkedToAnotherCompany");
11029 if (!empty($selected) && $selected == $obj->rowid) {
11030 $out .= '<option value=
"' . $obj->rowid . '" selected
';
11031 //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected
if disabled
11032 $out .=
'>' . $labeltoshow .
'</option>';
11034 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
11037 $resultat =
'<option value="' . $obj->rowid .
'"';
11039 $resultat .=
' disabled';
11044 $resultat .= $labeltoshow;
11045 $resultat .=
'</option>';
11053 if (empty($option_only)) {
11054 $out .=
'</select>';
11057 $this->db->free($resql);
11079 public function selectInvoiceRec($selected =
'', $htmlname =
'facrecid', $maxlength = 24, $option_only = 0, $show_empty =
'1', $forcefocus = 0, $disabled = 0, $morecss =
'maxwidth500')
11081 global
$conf, $langs;
11087 $sql =
'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc';
11089 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'facture_rec as f';
11090 $sql .=
" WHERE f.entity IN (" .
getEntity(
'invoice') .
")";
11091 $sql .=
" ORDER BY f.titre ASC";
11093 $resql = $this->db->query($sql);
11096 if (!empty(
$conf->use_javascript_ajax)) {
11097 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
11098 $comboenhancement =
ajax_combobox($htmlname, array(), 0, $forcefocus);
11099 $out .= $comboenhancement;
11100 $morecss =
'minwidth200imp maxwidth500';
11103 if (empty($option_only)) {
11104 $out .=
'<select class="valignmiddle flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' id="' . $htmlname .
'" name="' . $htmlname .
'">';
11106 if (!empty($show_empty)) {
11107 $out .=
'<option value="0" class="optiongrey">';
11108 if (!is_numeric($show_empty)) {
11109 $out .= $show_empty;
11113 $out .=
'</option>';
11115 $num = $this->db->num_rows($resql);
11117 while ($obj = $this->db->fetch_object($resql)) {
11118 $labeltoshow =
dol_trunc($obj->title, 18);
11121 if (!empty($obj->suspended)) {
11123 $labeltoshow .=
' - ' . $langs->trans(
"Closed");
11127 if (!empty($selected) && $selected == $obj->rowid) {
11128 $out .=
'<option value="' . $obj->rowid .
'" selected';
11130 $out .=
'>' . $labeltoshow .
'</option>';
11132 if ($disabled && ($selected != $obj->rowid)) {
11135 $resultat =
'<option value="' . $obj->rowid .
'"';
11137 $resultat .=
' disabled';
11140 $resultat .= $labeltoshow;
11141 $resultat .=
'</option>';
11147 if (empty($option_only)) {
11148 $out .=
'</select>';
11153 $this->db->free($resql);
11156 $this->errors[] = $this->db->lasterror;
11171 public function searchComponent($arrayofcriterias, $search_component_params, $arrayofinputfieldsalreadyoutput = array(), $search_component_params_hidden =
'', $arrayoffiltercriterias = array())
11174 global $langs, $form;
11176 require_once DOL_DOCUMENT_ROOT.
"/core/class/html.formother.class.php";
11179 if ($search_component_params_hidden !=
'' && !preg_match(
'/^\(.*\)$/', $search_component_params_hidden)) {
11180 $search_component_params_hidden =
'(' . $search_component_params_hidden .
')';
11185 $ret .=
'<div class="divadvancedsearchfieldcomp centpercent inline-block">';
11186 $ret .=
'<a href="#" class="dropdownsearch-toggle unsetcolor">';
11187 $ret .=
'<span class="fas fa-filter linkobject boxfilter paddingright pictofixedwidth" title="' .
dol_escape_htmltag($langs->trans(
"Filters")) .
'" id="idsubimgproductdistribution"></span>';
11190 $ret .=
'<div class="divadvancedsearchfieldcompinput inline-block minwidth500 maxwidth300onsmartphone">';
11193 $ret .=
'<div id="divsearch_component_params" name="divsearch_component_params" class="noborderbottom search_component_params inline-block valignmiddle">';
11195 if ($search_component_params_hidden) {
11203 foreach ($arrayofandtags as $tmpkey => $tmpval) {
11204 $errormessage =
'';
11206 if ($errormessage) {
11207 $this->error =
'ERROR in parsing search string: '.$errormessage;
11210 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
11213 $ret .=
'<span class="marginleftonlyshort valignmiddle tagsearch" data-ufilterid="'.($tmpkey + 1).
'" data-ufilter="'.
dol_escape_htmltag($tmpval).
'">';
11214 $ret .=
'<span class="tagsearchdelete select2-selection__choice__remove" data-ufilterid="'.($tmpkey + 1).
'">x</span> ';
11226 $show_search_component_params_hidden = 1;
11227 if ($show_search_component_params_hidden) {
11228 $ret .=
'<input type="hidden" name="show_search_component_params_hidden" value="1">';
11230 $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%')) -->";
11231 $ret .=
'<input type="hidden" id="search_component_params_hidden" name="search_component_params_hidden" value="' .
dol_escape_htmltag($search_component_params_hidden) .
'">';
11236 foreach ($arrayofcriterias as $criteria) {
11237 foreach ($criteria as $criteriafamilykey => $criteriafamilyval) {
11238 if (in_array(
'search_' . $criteriafamilykey, $arrayofinputfieldsalreadyoutput)) {
11241 if (in_array($criteriafamilykey, array(
'rowid',
'ref_ext',
'entity',
'extraparams'))) {
11244 if (in_array($criteriafamilyval[
'type'], array(
'date',
'datetime',
'timestamp'))) {
11245 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_start">';
11246 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startyear">';
11247 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startmonth">';
11248 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startday">';
11249 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_end">';
11250 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endyear">';
11251 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endmonth">';
11252 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endday">';
11254 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'">';
11261 $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";
11262 $ret .=
'<input type="text" placeholder="' . $langs->trans(
"Filters") .
'" id="search_component_params_input" name="search_component_params_input" class="noborderbottom search_component_input" value="">';
11268 jQuery(".tagsearchdelete").click(function(e) {
11269 var filterid = $(this).parents().attr("data-ufilterid");
11270 console.log("We click to delete the criteria nb "+filterid);
11272 // Regenerate the search_component_params_hidden with all data-ufilter except the one to delete, and post the page
11273 var newparamstring = \'\';
11274 $(\'.tagsearch\').each(function(index, element) {
11275 tmpfilterid = $(this).attr("data-ufilterid");
11276 if (tmpfilterid != filterid) {
11277 // We keep this criteria
11278 if (newparamstring == \'\') {
11279 newparamstring = $(this).attr("data-ufilter");
11281 newparamstring = newparamstring + \' AND \' + $(this).attr("data-ufilter");
11285 console.log("newparamstring = "+newparamstring);
11287 jQuery("#search_component_params_hidden").val(newparamstring);
11289 // We repost the form
11290 $(this).closest(\'form\').submit();
11293 jQuery("#search_component_params_input").keydown(function(e) {
11294 console.log("We press a key on the filter field that is "+jQuery("#search_component_params_input").val());
11295 console.log(e.which);
11296 if (jQuery("#search_component_params_input").val() == "" && e.which == 8) {
11297 /* We click on back when the input field is already empty */
11298 event.preventDefault();
11299 jQuery("#divsearch_component_params .tagsearch").last().remove();
11300 /* Regenerate content of search_component_params_hidden from remaining .tagsearch */
11302 jQuery("#divsearch_component_params .tagsearch").each(function( index ) {
11306 s = s + $(this).attr("data-ufilter");
11308 console.log("New value for search_component_params_hidden = "+s);
11309 jQuery("#search_component_params_hidden").val(s);
11316 $arrayoffilterfieldslabel = array();
11317 foreach ($arrayoffiltercriterias as $key => $val) {
11318 $arrayoffilterfieldslabel[$key][
'label'] = $val[
'label'];
11319 $arrayoffilterfieldslabel[$key][
'data-type'] = $val[
'type'];
11323 $ret .=
'<div class="search-component-assistance">';
11326 $ret .=
'<p class="assistance-title">' .
img_picto(
'',
'filter') .
' ' . $langs->trans(
'FilterAssistance') .
' </p>';
11328 $ret .=
'<p class="assistance-errors error" style="display:none">' . $langs->trans(
'AllFieldsRequired') .
' </p>';
11330 $ret .=
'<div class="operand">';
11331 $ret .= $form->selectarray(
'search_filter_field', $arrayoffilterfieldslabel,
'', $langs->trans(
"Fields"), 0, 0,
'', 0, 0, 0,
'',
'width250', 1);
11334 $ret .=
'<span class="separator"></span>';
11337 $ret .=
'<div class="operator">';
11338 $ret .=
'<select class="operator-selector width150" id="operator-selector"">';
11339 $ret .=
'</select>';
11340 $ret .=
'<script>$(document).ready(function() {';
11341 $ret .=
' $(".operator-selector").select2({';
11342 $ret .=
' placeholder: \'' .
dol_escape_js($langs->trans(
'Operator')) .
'\'';
11344 $ret .=
'});</script>';
11347 $ret .=
'<span class="separator"></span>';
11349 $ret .=
'<div class="value">';
11351 $ret .=
'<input type="text" class="flat width100 value-input" placeholder="' .
dolPrintHTML($langs->trans(
'Value')) .
'">';
11355 $ret .=
'<span class="date-one" style="display:none">';
11356 $ret .= $form->selectDate(($dateOne ? $dateOne : -1),
'dateone', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'');
11361 $ret .=
'<div class="btn-div">';
11362 $ret .=
'<button class="button buttongen button-save add-filter-btn" type="button">' . $langs->trans(
"addToFilter") .
'</button>';
11373 $(document).ready(function() {
11374 $("#search_component_params_input").on("click", function() {
11375 const inputPosition = $(this).offset();
11376 const inputHeight = $(this).outerHeight();
11377 $(".search-component-assistance").css({
11378 top: inputPosition.top + inputHeight + 5 + "px",
11379 left: $("#divsearch_component_params").position().left
11380 }).slideToggle(200);
11382 $(document).on("click", function(e) {
11383 if (!$(e.target).closest("#search_component_params_input, .search-component-assistance, #ui-datepicker-div").length) {
11384 $(".search-component-assistance").hide();
11391 $(document).ready(function() {
11392 $(".search_filter_field").on("change", function() {
11393 const selectedField = $(this).find(":selected");
11394 const fieldType = selectedField.data("type");
11395 const selectedFieldValue = selectedField.val();
11396 const operators = getOperatorsForFieldType(fieldType);
11397 const operatorSelector = $(".operator-selector");
11399 // Clear existing options
11400 operatorSelector.empty();
11402 // Populate operators
11403 Object.entries(operators).forEach(function([operator, label]) {
11404 operatorSelector.append("<option value=\'" + operator + "\'>" + label + "</option>");
11407 operatorSelector.trigger("change.select2");
11409 // Clear and hide all input elements initially
11410 $(".value-input, .dateone, .datemonth, .dateyear").val("").hide();
11411 $("#datemonth, #dateyear").val(null).trigger("change.select2");
11412 $("#dateone").datepicker("setDate", null);
11413 $(".date-one, .date-month, .date-year").hide();
11415 if (fieldType === "date" || fieldType === "datetime" || fieldType === "timestamp") {
11416 $(".date-one").show();
11418 $(".value-input").show();
11422 $(".add-filter-btn").on("click", function(event) {
11423 event.preventDefault();
11425 const field = $(".search_filter_field").val();
11426 const operator = $(".operator-selector").val();
11427 let value = $(".value-input").val();
11428 const fieldType = $(".search_filter_field").find(":selected").data("type");
11430 if (["date", "datetime", "timestamp"].includes(fieldType)) {
11431 const parsedDate = new Date($("#dateone").val());
11432 if (!isNaN(parsedDate)) {
11433 const year = parsedDate.getFullYear();
11434 const month = String(parsedDate.getMonth() + 1).padStart(2, "0");
11435 const day = String(parsedDate.getDate()).padStart(2, "0");
11436 value = `${year}-${month}-${day}`;
11439 const filterString = generateFilterString(field, operator, value, fieldType);
11442 if (filterString !== "" && field !== "" && operator !== "" && value !== "") {
11443 $("#search_component_params_input").val($("#search_component_params_input").val() + " " + filterString);
11444 $("#search_component_params_input").closest("form").submit();
11446 $(".assistance-errors").show();
11465 public function selectModelMail($prefix, $modelType =
'', $default = 0, $addjscombo = 0, $selected =
'')
11467 global $langs, $user;
11471 $TModels = array();
11473 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
11474 $formmail =
new FormMail($this->db);
11475 $result = $formmail->fetchAllEMailTemplate($modelType, $user, $langs);
11478 $TModels[0] = $langs->trans(
'DefaultMailModel');
11481 foreach ($formmail->lines_model as $model) {
11482 $TModels[$model->id] = $model->label;
11486 $retstring .=
'<select class="flat" id="select_' . $prefix .
'model_mail" name="' . $prefix .
'model_mail">';
11488 foreach ($TModels as $id_model => $label_model) {
11489 $retstring .=
'<option value="' . $id_model .
'"';
11490 if (!empty($selected) && $selected == $id_model) {
11491 $retstring .=
"selected";
11493 $retstring .=
">" . $label_model .
"</option>";
11496 $retstring .=
"</select>";
11499 $retstring .=
ajax_combobox(
'select_' . $prefix .
'model_mail');
11516 public function buttonsSaveCancel($save_label =
'Save', $cancel_label =
'Cancel', $morebuttons = array(), $withoutdiv =
false, $morecss =
'', $dol_openinpopup =
'')
11520 $buttons = array();
11524 'label_key' => $save_label,
11527 if ($save_label ==
'Create' || $save_label ==
'Add') {
11528 $save[
'name'] =
'add';
11529 } elseif ($save_label ==
'Modify') {
11530 $save[
'name'] =
'edit';
11534 'name' =>
'cancel',
11535 'label_key' =>
'Cancel',
11538 !empty($save_label) ? $buttons[] = $save :
'';
11540 if (!empty($morebuttons)) {
11541 $buttons[] = $morebuttons;
11544 !empty($cancel_label) ? $buttons[] = $cancel :
'';
11546 $retstring = $withoutdiv ?
'' :
'<div class="center">';
11548 foreach ($buttons as $button) {
11549 $addclass = empty($button[
'addclass']) ?
'' : $button[
'addclass'];
11550 $retstring .=
'<input type="submit" class="button button-' . $button[
'name'] . ($morecss ?
' ' . $morecss :
'') .
' ' . $addclass .
'" name="' . $button[
'name'] .
'" value="' .
dol_escape_htmltag($langs->trans($button[
'label_key'])) .
'">';
11552 $retstring .= $withoutdiv ?
'' :
'</div>';
11554 if ($dol_openinpopup) {
11555 $retstring .=
'<!-- buttons are shown into a $dol_openinpopup=' .
dol_escape_htmltag($dol_openinpopup) .
' context, so we enable the close of dialog on cancel -->' .
"\n";
11556 $retstring .=
'<script nonce="' .
getNonce() .
'">';
11557 $retstring .=
'jQuery(".button-cancel").click(function(e) {
11558 e.preventDefault(); console.log(\'We click on cancel in iframe popup ' .
dol_escape_js($dol_openinpopup) .
'\');
11559 window.parent.jQuery(\
'#idfordialog' .
dol_escape_js($dol_openinpopup) .
'\').dialog(\
'close\');
11561 $retstring .=
'</script>';
11580 $num = count($this->cache_invoice_subtype);
11587 $sql =
"SELECT rowid, code, label as label";
11588 $sql .=
" FROM " . MAIN_DB_PREFIX .
'c_invoice_subtype';
11589 $sql .=
" WHERE active = 1";
11591 $resql = $this->db->query($sql);
11593 $num = $this->db->num_rows($resql);
11595 while ($i < $num) {
11596 $obj = $this->db->fetch_object($resql);
11599 $label = ($langs->trans(
"InvoiceSubtype" . $obj->rowid) !=
"InvoiceSubtype" . $obj->rowid) ? $langs->trans(
"InvoiceSubtype" . $obj->rowid) : (($obj->label !=
'-') ? $obj->label :
'');
11600 $this->cache_invoice_subtype[$obj->rowid][
'rowid'] = $obj->rowid;
11601 $this->cache_invoice_subtype[$obj->rowid][
'code'] = $obj->code;
11602 $this->cache_invoice_subtype[$obj->rowid][
'label'] = $label;
11606 $this->cache_invoice_subtype =
dol_sort_array($this->cache_invoice_subtype,
'code',
'asc', 0, 0, 1);
11628 global $langs, $user;
11631 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
11635 $out .=
'<select id="' . $htmlname .
'" class="flat selectsubtype' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
11637 $out .=
'<option value="0"> </option>';
11640 foreach ($this->cache_invoice_subtype as $rowid => $subtype) {
11641 $label = $subtype[
'label'];
11642 $out .=
'<option value="' . $subtype[
'rowid'] .
'"';
11643 if ($selected == $subtype[
'rowid']) {
11644 $out .=
' selected="selected"';
11648 $out .=
'</option>';
11651 $out .=
'</select>';
11652 if ($user->admin && empty($noinfoadmin)) {
11653 $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.
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array(), $allowlink=0, $allowscript=0, $allowstyle=0)
Clean a string to keep only desirable HTML tags.
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'.
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_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
dolPrintHTMLForAttribute($s)
Return a string ready to be output on an HTML attribute (alt, title, data-html, .....
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.
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.
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...
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.
getMaxFileSizeArray()
Return the max allowed for file upload.
dolDecrypt($chain, $key='')
Decode a string with a symmetric encryption.
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.