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 . ($tag !=
'td' ?
' 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, $htmltooltip, $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, $htmltooltip, ((($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 || ' . ((int) $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 */
939 public function select_country($selected =
'', $htmlname =
'country_id', $htmloption =
'', $maxlength = 0, $morecss =
'minwidth300', $usecodeaskey =
'', $showempty = 1, $disablefavorites = 0, $addspecialentries = 0, $exclude_country_code = array(), $hideflags = 0, $forcecombo = 0)
942 global
$conf, $langs, $mysoc;
944 $langs->load(
"dict");
947 $countryArray = array();
950 $atleastonefavorite = 0;
952 $sql =
"SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite, eec";
953 $sql .=
" FROM " . $this->db->prefix() .
"c_country";
954 $sql .=
" WHERE active > 0";
957 dol_syslog(get_class($this) .
"::select_country", LOG_DEBUG);
958 $resql = $this->db->query($sql);
960 $out .=
'<select id="select' . $htmlname .
'" class="flat maxwidth200onsmartphone selectcountry' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" ' . $htmloption .
'>';
961 $num = $this->db->num_rows($resql);
965 $obj = $this->db->fetch_object($resql);
967 $countryArray[$i][
'rowid'] = $obj->rowid;
968 $countryArray[$i][
'code_iso'] = $obj->code_iso;
969 $countryArray[$i][
'code_iso3'] = $obj->code_iso3;
970 $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 :
''));
971 $countryArray[$i][
'favorite'] = $obj->favorite;
972 $countryArray[$i][
'eec'] = $obj->eec;
973 $favorite[$i] = $obj->favorite;
978 if (empty($disablefavorites)) {
979 $array1_sort_order = SORT_DESC;
980 $array2_sort_order = SORT_ASC;
981 array_multisort($favorite, $array1_sort_order, $label, $array2_sort_order, $countryArray);
987 if (is_numeric($showempty)) {
988 $out .=
'<option value=""> </option>' .
"\n";
990 $out .=
'<option value="-1">' . $langs->trans($showempty) .
'</option>' .
"\n";
994 if ($addspecialentries) {
996 $out .=
'<option value="special_allnotme"' . ($selected ==
'special_allnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesExceptMe", $langs->transnoentitiesnoconv(
"Country" . $mysoc->country_code)) .
'</option>';
997 $out .=
'<option value="special_eec"' . ($selected ==
'special_eec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEEC") .
'</option>';
998 if ($mysoc->isInEEC()) {
999 $out .=
'<option value="special_eecnotme"' . ($selected ==
'special_eecnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEECExceptMe", $langs->transnoentitiesnoconv(
"Country" . $mysoc->country_code)) .
'</option>';
1001 $out .=
'<option value="special_noteec"' . ($selected ==
'special_noteec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesNotInEEC") .
'</option>';
1002 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1005 foreach ($countryArray as $row) {
1007 if (empty($row[
'rowid'])) {
1010 if (is_array($exclude_country_code) && count($exclude_country_code) && in_array($row[
'code_iso'], $exclude_country_code)) {
1014 if (empty($disablefavorites) && $row[
'favorite'] && $row[
'code_iso']) {
1015 $atleastonefavorite++;
1017 if (empty($row[
'favorite']) && $atleastonefavorite) {
1018 $atleastonefavorite = 0;
1019 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1023 if ($row[
'label']) {
1024 $labeltoshow .=
dol_trunc($row[
'label'], $maxlength,
'middle');
1026 $labeltoshow .=
' ';
1028 if ($row[
'code_iso']) {
1029 $labeltoshow .=
' <span class="opacitymedium">(' . $row[
'code_iso'] .
')</span>';
1030 if (empty($hideflags)) {
1031 $tmpflag =
picto_from_langcode($row[
'code_iso'],
'class="saturatemedium paddingrightonly"', 1);
1032 $labeltoshow = $tmpflag .
' ' . $labeltoshow;
1036 if ($selected && $selected !=
'-1' && ($selected == $row[
'rowid'] || $selected == $row[
'code_iso'] || $selected == $row[
'code_iso3'] || $selected == $row[
'label'])) {
1037 $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']) .
'">';
1039 $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']) .
'">';
1041 $out .= $labeltoshow;
1042 $out .=
'</option>' .
"\n";
1045 $out .=
'</select>';
1051 if (empty($forcecombo)) {
1052 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1053 $out .=
ajax_combobox(
'select' . $htmlname, array(), 0, 0,
'resolve');
1074 public function select_incoterms($selected =
'', $location_incoterms =
'', $page =
'', $htmlname =
'incoterm_id', $htmloption =
'', $forcecombo = 1, $events = array(), $disableautocomplete = 0)
1077 global
$conf, $langs;
1079 $langs->load(
"dict");
1083 $incotermArray = array();
1085 $sql =
"SELECT rowid, code";
1086 $sql .=
" FROM " . $this->db->prefix() .
"c_incoterms";
1087 $sql .=
" WHERE active > 0";
1088 $sql .=
" ORDER BY code ASC";
1090 dol_syslog(get_class($this) .
"::select_incoterm", LOG_DEBUG);
1091 $resql = $this->db->query($sql);
1093 if (
$conf->use_javascript_ajax && !$forcecombo) {
1094 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1098 if (!empty($page)) {
1099 $out .=
'<form method="post" action="' . $page .
'">';
1100 $out .=
'<input type="hidden" name="action" value="set_incoterms">';
1101 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
1104 $out .=
'<select id="' . $htmlname .
'" class="flat selectincoterm width75" name="' . $htmlname .
'" ' . $htmloption .
'>';
1105 $out .=
'<option value="0"> </option>';
1106 $num = $this->db->num_rows($resql);
1110 $obj = $this->db->fetch_object($resql);
1111 $incotermArray[$i][
'rowid'] = $obj->rowid;
1112 $incotermArray[$i][
'code'] = $obj->code;
1116 foreach ($incotermArray as $row) {
1117 if ($selected && ($selected == $row[
'rowid'] || $selected == $row[
'code'])) {
1118 $out .=
'<option value="' . $row[
'rowid'] .
'" selected>';
1120 $out .=
'<option value="' . $row[
'rowid'] .
'">';
1124 $out .= $row[
'code'];
1127 $out .=
'</option>';
1130 $out .=
'</select>';
1133 if (
$conf->use_javascript_ajax && empty($disableautocomplete)) {
1134 $out .=
ajax_multiautocompleter(
'location_incoterms', array(), DOL_URL_ROOT .
'/core/ajax/locationincoterms.php') .
"\n";
1137 $out .=
'<input id="location_incoterms" class="maxwidthonsmartphone type="text" name="location_incoterms" value="' . $location_incoterms .
'">' .
"\n";
1139 if (!empty($page)) {
1140 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp nomargintop nomarginbottom" value="' . $langs->trans(
"Modify") .
'"></form>';
1164 public function select_type_of_lines($selected =
'', $htmlname =
'type', $showempty = 0, $hidetext = 0, $forceall = 0, $morecss =
"", $useajaxcombo = 1)
1170 if ($forceall == 1 || (empty($forceall) && isModEnabled(
"product") && isModEnabled(
"service"))
1171 || (empty($forceall) && !isModEnabled(
'product') && !isModEnabled(
'service'))) {
1172 if (empty($hidetext)) {
1173 print $langs->trans(
"Type").
'...';
1175 print
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
1177 print
'<option value="-1" class="opacitymedium"'.($useajaxcombo ?
'' :
' disabled="disabled"');
1178 if ($selected == -1) {
1182 if (is_numeric($showempty)) {
1190 print
'<option value="0"';
1191 if (0 == $selected || ($selected == -1 &&
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') ==
'product')) {
1194 print
'>' . $langs->trans(
"Product");
1196 print
'<option value="1"';
1197 if (1 == $selected || ($selected == -1 &&
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') ==
'service')) {
1200 print
'>' . $langs->trans(
"Service");
1204 if ($useajaxcombo) {
1209 if ((empty($forceall) && !isModEnabled(
'product') && isModEnabled(
"service")) || $forceall == 3) {
1210 print $langs->trans(
"Service");
1211 print
'<input type="hidden" name="' . $htmlname .
'" value="1">';
1213 if ((empty($forceall) && isModEnabled(
"product") && !isModEnabled(
'service')) || $forceall == 2) {
1214 print $langs->trans(
"Product");
1215 print
'<input type="hidden" name="' . $htmlname .
'" value="0">';
1217 if ($forceall < 0) {
1218 print
'<input type="hidden" name="' . $htmlname .
'" value="1">';
1234 $num = count($this->cache_types_fees);
1241 $langs->load(
"trips");
1243 $sql =
"SELECT c.code, c.label";
1244 $sql .=
" FROM " . $this->db->prefix() .
"c_type_fees as c";
1245 $sql .=
" WHERE active > 0";
1247 $resql = $this->db->query($sql);
1249 $num = $this->db->num_rows($resql);
1253 $obj = $this->db->fetch_object($resql);
1256 $label = ($obj->code != $langs->trans($obj->code) ? $langs->trans($obj->code) : $langs->trans($obj->label));
1257 $this->cache_types_fees[$obj->code] = $label;
1261 asort($this->cache_types_fees);
1283 global $user, $langs;
1285 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
1289 print
'<select id="select_' . $htmlname .
'" class="flat" name="' . $htmlname .
'">';
1291 print
'<option value="-1"';
1292 if ($selected == -1) {
1295 print
'> </option>';
1298 foreach ($this->cache_types_fees as $key => $value) {
1299 print
'<option value="' . $key .
'"';
1300 if ($key == $selected) {
1310 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1339 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)
1342 global
$conf, $langs;
1346 if (!empty(
$conf->use_javascript_ajax) &&
getDolGlobalString(
'COMPANY_USE_SEARCH_TO_SELECT') && !$forcecombo) {
1347 if (is_null($ajaxoptions)) {
1348 $ajaxoptions = array();
1351 require_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1355 if ($selected && empty($selected_input_value)) {
1356 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
1357 $societetmp =
new Societe($this->db);
1358 $societetmp->fetch($selected);
1359 $selected_input_value = $societetmp->name;
1364 $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)) :
'');
1366 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
1367 if (empty($hidelabel)) {
1368 $out .= $langs->trans(
"RefOrLabel") .
' : ';
1369 } elseif ($hidelabel == 1 && !is_numeric($showempty)) {
1370 $placeholder = $langs->trans($showempty);
1371 } elseif ($hidelabel > 1) {
1372 $placeholder = $langs->trans(
"RefOrLabel");
1373 if ($hidelabel == 2) {
1374 $out .=
img_picto($langs->trans(
"Search"),
'search');
1377 $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' :
'') .
' />';
1378 if ($hidelabel == 3) {
1379 $out .=
img_picto($langs->trans(
"Search"),
'search');
1384 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.
'/societe/ajax/company.php', $urloption,
getDolGlobalInt(
'COMPANY_USE_SEARCH_TO_SELECT'), 0, $ajaxoptions);
1387 $out .= $this->
select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events,
'', 0, $limit, $morecss, $moreparam, $multiple, $excludeids, $showcode);
1421 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 =
'')
1425 global
$conf, $langs;
1430 if ($nokeyifsocid && $socid > 0) {
1431 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = 0;
1434 if (!empty(
$conf->use_javascript_ajax) &&
getDolGlobalString(
'CONTACT_USE_SEARCH_TO_SELECT') && !$forcecombo) {
1435 if (is_null($events)) {
1439 require_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1443 if ($selected && empty($selected_input_value)) {
1444 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
1445 $contacttmp =
new Contact($this->db);
1446 $contacttmp->fetch($selected);
1447 $selected_input_value = $contacttmp->getFullName($langs);
1450 if (!is_numeric($showempty)) {
1451 $placeholder = $showempty;
1455 $urloption =
'htmlname=' . urlencode((
string) (str_replace(
'.',
'_', $htmlname))) .
'&outjson=1&filter=' . urlencode((
string) ($filter)) . (empty($exclude) ?
'' :
'&exclude=' . urlencode($exclude)) . ($showsoc ?
'&showsoc=' . urlencode((
string) ($showsoc)) :
'');
1457 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
1459 $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' :
'') .
' />';
1463 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.
'/contact/ajax/contact.php', $urloption,
getDolGlobalInt(
'CONTACT_USE_SEARCH_TO_SELECT'), 0, $events);
1467 $disableifempty = 0;
1471 $out .= $this->
selectcontacts($socid, $selected, $htmlname, $showempty, $exclude, $limitto, $showfunction, $morecss, $options_only, $showsoc, $forcecombo, $events, $moreparam, $htmlid, $multiple, $disableifempty);
1474 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = $sav;
1506 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)
1509 global $user, $langs;
1510 global $hookmanager;
1512 $langs->loadLangs(array(
"companies",
"suppliers"));
1516 $outarray = array();
1518 if ($selected ===
'') {
1519 $selected = array();
1520 } elseif (!is_array($selected)) {
1521 $selected = array($selected);
1525 if (function_exists(
'testSqlAndScriptInject')) {
1528 return 'SQLInjectionTryDetected';
1532 if ($filter !=
'') {
1533 if (preg_match(
'/[\(\)]/', $filter)) {
1539 if (function_exists(
'testSqlAndScriptInject')) {
1542 return 'SQLInjectionTryDetected';
1548 dol_syslog(
"Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Syntax.", LOG_WARNING);
1553 $sql =
"SELECT s.rowid, s.nom as name, s.name_alias, s.tva_intra, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
1555 $sql .=
", s.address, s.zip, s.town";
1556 $sql .=
", dictp.code as country_code";
1558 $sql .=
" FROM " . $this->db->prefix() .
"societe as s";
1560 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_country as dictp ON dictp.rowid = s.fk_pays";
1562 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1563 $sql .=
", " . $this->db->prefix() .
"societe_commerciaux as sc";
1565 $sql .=
" WHERE s.entity IN (" .
getEntity(
'societe') .
")";
1566 if (!empty($user->socid)) {
1567 $sql .=
" AND s.rowid = " . ((int) $user->socid);
1572 $sql .=
" AND (" . $filter .
")";
1574 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1575 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = " . ((int) $user->id);
1578 $sql .=
" AND s.status <> 0";
1580 if (!empty($excludeids)) {
1581 $sql .=
" AND s.rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeids)) .
")";
1584 $parameters = array();
1585 $reshook = $hookmanager->executeHooks(
'selectThirdpartyListWhere', $parameters);
1586 $sql .= $hookmanager->resPrint;
1588 if ($filterkey && $filterkey !=
'') {
1592 $search_crit = explode(
' ', $filterkey);
1594 if (count($search_crit) > 1) {
1597 foreach ($search_crit as $crit) {
1601 $sql .=
"(s.nom LIKE '" . $this->db->escape($prefix . $crit) .
"%')";
1604 if (count($search_crit) > 1) {
1607 if (isModEnabled(
'barcode')) {
1608 $sql .=
" OR s.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1610 $sql .=
" OR s.code_client LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.code_fournisseur LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1611 $sql .=
" OR s.name_alias LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.tva_intra LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1614 $sql .= $this->db->order(
"nom",
"ASC");
1615 $sql .= $this->db->plimit($limit, 0);
1618 dol_syslog(get_class($this).
"::select_thirdparty_list", LOG_DEBUG);
1619 $resql = $this->db->query($sql);
1622 $out .=
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
' name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
'>' .
"\n";
1624 $textifempty = (($showempty && !is_numeric($showempty)) ? $langs->trans($showempty) :
'');
1628 if ($showempty && !is_numeric($showempty)) {
1629 $textifempty = $langs->trans($showempty);
1631 $textifempty .= $langs->trans(
"All");
1635 $out .=
'<option value="-1" data-html="' .
dol_escape_htmltag(
'<span class="opacitymedium">' . ($textifempty ? $textifempty :
' ') .
'</span>') .
'">' . $textifempty .
'</option>' .
"\n";
1638 $companytemp =
new Societe($this->db);
1640 $num = $this->db->num_rows($resql);
1644 $obj = $this->db->fetch_object($resql);
1647 if (($obj->client) && (!empty($obj->code_client))) {
1648 $label = $obj->code_client .
' - ';
1650 if (($obj->fournisseur) && (!empty($obj->code_fournisseur))) {
1651 $label .= $obj->code_fournisseur .
' - ';
1653 $label .=
' ' . $obj->name;
1655 $label = $obj->name;
1658 if (!empty($obj->name_alias)) {
1659 $label .=
' (' . $obj->name_alias .
')';
1663 $label .=
' - '.$obj->tva_intra;
1666 $labelhtml = $label;
1669 $companytemp->id = $obj->rowid;
1670 $companytemp->client = $obj->client;
1671 $companytemp->fournisseur = $obj->fournisseur;
1672 $tmptype = $companytemp->getTypeUrl(1,
'', 0,
'span');
1674 $labelhtml .=
' ' . $tmptype;
1677 if ($obj->client || $obj->fournisseur) {
1680 if ($obj->client == 1 || $obj->client == 3) {
1681 $label .= $langs->trans(
"Customer");
1683 if ($obj->client == 2 || $obj->client == 3) {
1684 $label .= ($obj->client == 3 ?
', ' :
'') . $langs->trans(
"Prospect");
1686 if ($obj->fournisseur) {
1687 $label .= ($obj->client ?
', ' :
'') . $langs->trans(
"Supplier");
1689 if ($obj->client || $obj->fournisseur) {
1695 $s = ($obj->address ?
' - ' . $obj->address :
'') . ($obj->zip ?
' - ' . $obj->zip :
'') . ($obj->town ?
' ' . $obj->town :
'');
1696 if (!empty($obj->country_code)) {
1697 $s .=
', ' . $langs->trans(
'Country' . $obj->country_code);
1703 if (empty($outputmode)) {
1704 if (in_array($obj->rowid, $selected)) {
1705 $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>';
1707 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
1710 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label,
'labelhtml' => $labelhtml));
1714 if (($i % 10) == 0) {
1719 $out .=
'</select>' .
"\n";
1721 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1728 $this->result = array(
'nbofthirdparties' => $num);
1762 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 =
'')
1764 global
$conf, $user, $langs, $hookmanager, $action;
1766 $langs->load(
'companies');
1768 if (empty($htmlid)) {
1769 $htmlid = $htmlname;
1773 $outarray = array();
1775 if ($selected ===
'') {
1776 $selected = array();
1777 } elseif (!is_array($selected)) {
1778 $selected = array((
int) $selected);
1782 if (function_exists(
'testSqlAndScriptInject')) {
1785 return 'SQLInjectionTryDetected';
1789 if ($filter !=
'') {
1790 if (preg_match(
'/[\(\)]/', $filter)) {
1796 if (function_exists(
'testSqlAndScriptInject')) {
1799 return 'SQLInjectionTryDetected';
1805 dol_syslog(
"Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Filter Syntax.", LOG_WARNING);
1809 if (!is_object($hookmanager)) {
1810 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
1815 $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";
1816 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
1817 $sql .=
", s.nom as company, s.town AS company_town";
1819 $sql .=
" FROM " . $this->db->prefix() .
"socpeople as sp";
1820 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
1821 $sql .=
" LEFT OUTER JOIN " . $this->db->prefix() .
"societe as s ON s.rowid=sp.fk_soc";
1823 $sql .=
" WHERE sp.entity IN (" .
getEntity(
'contact') .
")";
1824 $sql .=
" AND ((sp.fk_user_creat = ".((int) $user->id).
" AND sp.priv = 1) OR sp.priv = 0)";
1825 if ($socid > 0 || $socid == -1) {
1826 $sql .=
" AND sp.fk_soc = " . ((int) $socid);
1829 $sql .=
" AND sp.statut <> 0";
1834 $sql .=
" AND (" . $filter .
")";
1837 $parameters = array();
1838 $reshook = $hookmanager->executeHooks(
'selectContactListWhere', $parameters);
1839 $sql .= $hookmanager->resPrint;
1840 $sql .=
" ORDER BY sp.lastname ASC";
1842 dol_syslog(get_class($this) .
"::selectcontacts", LOG_DEBUG);
1843 $resql = $this->db->query($sql);
1845 $num = $this->db->num_rows($resql);
1847 if ($htmlname !=
'none' && !$options_only) {
1848 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlid .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . (($num || empty($disableifempty)) ?
'' :
' disabled') . ($multiple ?
'multiple' :
'') .
' ' . (!empty($moreparam) ? $moreparam :
'') .
'>';
1851 if ($showempty && !is_numeric($showempty)) {
1852 $textforempty = $showempty;
1853 $out .=
'<option class="optiongrey" value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'>' . $textforempty .
'</option>';
1855 if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) {
1856 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'> </option>';
1858 if ($showempty == 2) {
1859 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Internal") .
' --</option>';
1865 include_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
1866 $contactstatic =
new Contact($this->db);
1869 $obj = $this->db->fetch_object($resql);
1872 $extendedInfos =
'';
1874 $extendedInfos = array();
1875 $email = trim($obj->email);
1876 if (!empty($email)) {
1877 $extendedInfos[] = $email;
1879 $phone = trim($obj->phone);
1880 $phone_perso = trim($obj->phone_perso);
1881 $phone_mobile = trim($obj->phone_mobile);
1882 if (!empty($phone)) {
1883 $extendedInfos[] = $phone;
1885 if (!empty($phone_perso)) {
1886 $extendedInfos[] = $phone_perso;
1888 if (!empty($phone_mobile)) {
1889 $extendedInfos[] = $phone_mobile;
1892 $contact_town = trim($obj->contact_town);
1893 $company_town = trim($obj->company_town);
1894 if (!empty($contact_town)) {
1895 $extendedInfos[] = $contact_town;
1896 } elseif (!empty($company_town)) {
1897 $extendedInfos[] = $company_town;
1899 $extendedInfos = implode(
' - ', $extendedInfos);
1900 if (!empty($extendedInfos)) {
1901 $extendedInfos =
' - ' . $extendedInfos;
1905 $contactstatic->id = $obj->rowid;
1906 $contactstatic->lastname = $obj->lastname;
1907 $contactstatic->firstname = $obj->firstname;
1908 if ($obj->statut == 1) {
1910 if ($htmlname !=
'none') {
1912 if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) {
1915 if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) {
1918 if (!empty($selected) && in_array($obj->rowid, $selected)) {
1919 $out .=
'<option value="' . $obj->rowid .
'"';
1921 $out .=
' disabled';
1923 $out .=
' selected>';
1925 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1926 if ($showfunction && $obj->poste) {
1927 $tmplabel .=
' (' . $obj->poste .
')';
1929 if (($showsoc > 0) && $obj->company) {
1930 $tmplabel .=
' - (' . $obj->company .
')';
1934 $out .=
'</option>';
1936 $out .=
'<option value="' . $obj->rowid .
'"';
1938 $out .=
' disabled';
1942 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1943 if ($showfunction && $obj->poste) {
1944 $tmplabel .=
' (' . $obj->poste .
')';
1946 if (($showsoc > 0) && $obj->company) {
1947 $tmplabel .=
' - (' . $obj->company .
')';
1951 $out .=
'</option>';
1954 if (in_array($obj->rowid, $selected)) {
1955 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1956 if ($showfunction && $obj->poste) {
1957 $tmplabel .=
' (' . $obj->poste .
')';
1959 if (($showsoc > 0) && $obj->company) {
1960 $tmplabel .=
' - (' . $obj->company .
')';
1967 if ($tmplabel !=
'') {
1968 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $tmplabel,
'label' => $tmplabel,
'labelhtml' => $tmplabel));
1974 $labeltoshow = ($socid != -1) ? ($langs->trans($socid ?
"NoContactDefinedForThirdParty" :
"NoContactDefined")) : $langs->trans(
'SelectAThirdPartyFirst');
1975 $out .=
'<option class="disabled" value="-1"' . (($showempty == 2 || $multiple) ?
'' :
' selected') .
' disabled="disabled">';
1976 $out .= $labeltoshow;
1977 $out .=
'</option>';
1980 $parameters = array(
1982 'htmlname' => $htmlname,
1985 'showfunction' => $showfunction,
1986 'showsoc' => $showsoc,
1989 $reshook = $hookmanager->executeHooks(
'afterSelectContactOptions', $parameters, $this, $action);
1991 if ($htmlname !=
'none' && !$options_only) {
1992 $out .=
'</select>';
1995 if (
$conf->use_javascript_ajax && !$forcecombo && !$options_only) {
1996 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2002 if ($options_only === 2) {
2030 global $langs,
$conf;
2033 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
2034 $sql .=
" re.description, re.fk_facture_source";
2035 $sql .=
" FROM " . $this->db->prefix() .
"societe_remise_except as re";
2036 $sql .=
" WHERE re.fk_soc = " . (int) $socid;
2037 $sql .=
" AND re.entity = " .
$conf->entity;
2039 $sql .=
" AND " . $filter;
2041 $sql .=
" ORDER BY re.description ASC";
2043 dol_syslog(get_class($this) .
"::select_remises", LOG_DEBUG);
2044 $resql = $this->db->query($sql);
2046 print
'<select id="select_' . $htmlname .
'" class="flat maxwidthonsmartphone" name="' . $htmlname .
'">';
2047 $num = $this->db->num_rows($resql);
2049 $qualifiedlines = $num;
2053 print
'<option value="0"> </option>';
2055 $obj = $this->db->fetch_object($resql);
2056 $desc =
dol_trunc($obj->description, 40);
2057 if (preg_match(
'/\(CREDIT_NOTE\)/', $desc)) {
2058 $desc = preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $desc);
2060 if (preg_match(
'/\(DEPOSIT\)/', $desc)) {
2061 $desc = preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"Deposit"), $desc);
2063 if (preg_match(
'/\(EXCESS RECEIVED\)/', $desc)) {
2064 $desc = preg_replace(
'/\(EXCESS RECEIVED\)/', $langs->trans(
"ExcessReceived"), $desc);
2066 if (preg_match(
'/\(EXCESS PAID\)/', $desc)) {
2067 $desc = preg_replace(
'/\(EXCESS PAID\)/', $langs->trans(
"ExcessPaid"), $desc);
2071 if ($selected > 0 && $selected == $obj->rowid) {
2072 $selectstring =
' selected';
2076 if ($maxvalue > 0 && $obj->amount_ttc > $maxvalue) {
2078 $disabled =
' disabled';
2081 if (
getDolGlobalString(
'MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST') && !empty($obj->fk_facture_source)) {
2082 $tmpfac =
new Facture($this->db);
2083 if ($tmpfac->fetch($obj->fk_facture_source) > 0) {
2084 $desc = $desc .
' - ' . $tmpfac->ref;
2088 print
'<option value="' . $obj->rowid .
'"' . $selectstring . $disabled .
'>' . $desc .
' (' .
price($obj->amount_ht) .
' ' . $langs->trans(
"HT") .
' - ' .
price($obj->amount_ttc) .
' ' . $langs->trans(
"TTC") .
')</option>';
2095 return $qualifiedlines;
2120 public function select_users($selected =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include =
'', $enableonly = array(), $force_entity =
'0')
2123 print $this->
select_dolusers($selected, $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity);
2152 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)
2155 global
$conf, $user, $langs, $hookmanager;
2159 if ((is_numeric($selected) && ($selected < -2 || empty($selected))) && !
getDolGlobalString(
'SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE')) {
2160 $selected = $user->id;
2163 if ($selected ===
'') {
2164 $selected = array();
2165 } elseif (!is_array($selected)) {
2166 $selected = array($selected);
2169 $excludeUsers =
null;
2170 $includeUsers =
null;
2173 if (is_array($exclude)) {
2174 $excludeUsers = implode(
",", $exclude);
2177 if (is_array($include)) {
2178 $includeUsers = implode(
",", $include);
2179 } elseif ($include ==
'hierarchy') {
2181 $includeUsers = implode(
",", $user->getAllChildIds(0));
2182 } elseif ($include ==
'hierarchyme') {
2184 $includeUsers = implode(
",", $user->getAllChildIds(1));
2190 $outarray = array();
2191 $outarray2 = array();
2194 $showlabelofentity = isModEnabled(
'multicompany') && !
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE') &&
$conf->entity == 1 && !empty($user->admin) && empty($user->entity);
2195 $userissuperadminentityone = isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && empty($user->entity);
2198 $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";
2199 if ($showlabelofentity) {
2200 $sql .=
", e.label";
2202 $sql .=
" FROM " . $this->db->prefix() .
"user as u";
2203 if ($showlabelofentity) {
2204 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid = u.entity";
2207 if ($userissuperadminentityone && $force_entity !==
'default') {
2208 if (!empty($force_entity)) {
2209 $sql .=
" WHERE u.entity IN (0, " . $this->db->sanitize($force_entity) .
")";
2211 $sql .=
" WHERE u.entity IS NOT NULL";
2214 if (isModEnabled(
'multicompany') &&
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE')) {
2215 $sql .=
" WHERE u.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
2217 $sql .=
" WHERE u.entity IN (" .
getEntity(
'user') .
")";
2221 if (!empty($user->socid)) {
2222 $sql .=
" AND u.fk_soc = " . ((int) $user->socid);
2224 if (is_array($exclude) && $excludeUsers) {
2225 $sql .=
" AND u.rowid NOT IN (" . $this->db->sanitize($excludeUsers) .
")";
2227 if ($includeUsers) {
2228 $sql .=
" AND u.rowid IN (" . $this->db->sanitize($includeUsers) .
")";
2231 $sql .=
" AND u.statut <> 0";
2234 $sql .=
" AND u.employee <> 0";
2237 $sql .=
" AND u.fk_soc IS NULL";
2239 if (!empty($morefilter)) {
2242 if ($errormessage) {
2243 $this->errors[] = $errormessage;
2244 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2245 if ($outputmode == 0) {
2246 return 'Error bad param $morefilter';
2254 $reshook = $hookmanager->executeHooks(
'addSQLWhereFilterOnSelectUsers', array(), $this, $action);
2255 if (!empty($reshook)) {
2256 $sql .= $hookmanager->resPrint;
2260 $sql .=
" ORDER BY u.statut DESC, u.firstname ASC, u.lastname ASC";
2262 $sql .=
" ORDER BY u.statut DESC, u.lastname ASC, u.firstname ASC";
2265 dol_syslog(get_class($this) .
"::select_dolusers", LOG_DEBUG);
2267 $resql = $this->db->query($sql);
2269 $num = $this->db->num_rows($resql);
2273 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
' minwidth200') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
2274 if ($show_empty && !$multiple) {
2275 $textforempty =
' ';
2276 if (!empty(
$conf->use_javascript_ajax)) {
2277 $textforempty =
' ';
2279 if (!is_numeric($show_empty)) {
2280 $textforempty = $show_empty;
2282 $out .=
'<option class="optiongrey" value="' . ($show_empty < 0 ? $show_empty : -1) .
'"' . ((empty($selected) || in_array(-1, $selected)) ?
' selected' :
'') .
'>' . $textforempty .
'</option>' .
"\n";
2284 $outarray[($show_empty < 0 ? $show_empty : -1)] = $textforempty;
2285 $outarray2[($show_empty < 0 ? $show_empty : -1)] = array(
2286 'id' => ($show_empty < 0 ? $show_empty : -1),
2287 'label' => $textforempty,
2288 'labelhtml' => $textforempty,
2294 $out .=
'<option value="-2"' . ((in_array(-2, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Everybody") .
' --</option>' .
"\n";
2296 $outarray[-2] =
'-- ' . $langs->trans(
"Everybody") .
' --';
2297 $outarray2[-2] = array(
2299 'label' =>
'-- ' . $langs->trans(
"Everybody") .
' --',
2300 'labelhtml' =>
'-- ' . $langs->trans(
"Everybody") .
' --',
2306 $userstatic =
new User($this->db);
2309 $obj = $this->db->fetch_object($resql);
2311 $userstatic->id = $obj->rowid;
2312 $userstatic->lastname = $obj->lastname;
2313 $userstatic->firstname = $obj->firstname;
2314 $userstatic->photo = $obj->photo;
2315 $userstatic->status = $obj->status;
2316 $userstatic->entity = $obj->entity;
2317 $userstatic->admin = $obj->admin;
2318 $userstatic->gender = $obj->gender;
2321 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
2322 $disableline = ($enableonlytext ? $enableonlytext :
'1');
2326 $labeltoshowhtml =
'';
2333 $labeltoshow .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2334 $labeltoshowhtml .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2335 if (empty($obj->firstname) && empty($obj->lastname)) {
2336 $labeltoshow .= $obj->login;
2337 $labeltoshowhtml .= $obj->login;
2344 $moreinfo .= ($moreinfo ?
' - ' :
' (');
2345 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(');
2346 $moreinfo .= $obj->login;
2347 $moreinfohtml .= $obj->login;
2349 if ($showstatus >= 0) {
2350 if ($obj->status == 1 && $showstatus == 1) {
2351 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Enabled');
2352 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Enabled');
2354 if ($obj->status == 0 && $showstatus == 1) {
2355 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Disabled');
2356 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Disabled');
2359 if ($showlabelofentity) {
2360 if (empty($obj->entity)) {
2361 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
"AllEntities");
2362 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
"AllEntities");
2364 if ($obj->entity !=
$conf->entity) {
2365 $moreinfo .= ($moreinfo ?
' - ' :
' (') . ($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2366 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(').($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2370 $moreinfo .= (!empty($moreinfo) ?
')' :
'');
2371 $moreinfohtml .= (!empty($moreinfohtml) ?
')</span>' :
'');
2372 if (!empty($disableline) && $disableline !=
'1') {
2374 $moreinfo .=
' - ' . $disableline;
2375 $moreinfohtml .=
' - ' . $disableline;
2377 $labeltoshow .= $moreinfo;
2378 $labeltoshowhtml .= $moreinfohtml;
2380 $out .=
'<option value="' . $obj->rowid .
'"';
2381 if (!empty($disableline)) {
2382 $out .=
' disabled';
2384 if ((!empty($selected[0]) && is_object($selected[0])) ? $selected[0]->id == $obj->rowid : in_array($obj->rowid, $selected)) {
2385 $out .=
' selected';
2387 $out .=
' data-html="';
2389 $outhtml = $userstatic->getNomUrl(-3,
'', 0, 1, 24, 1,
'login',
'', 1) .
' ';
2390 if ($showstatus >= 0 && $obj->status == 0) {
2391 $outhtml .=
'<strike class="opacitymediumxxx">';
2393 $outhtml .= $labeltoshowhtml;
2394 if ($showstatus >= 0 && $obj->status == 0) {
2395 $outhtml .=
'</strike>';
2397 $labeltoshowhtml = $outhtml;
2401 $out .= $labeltoshow;
2402 $out .=
'</option>';
2404 $outarray[$userstatic->id] = $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength) . $moreinfo;
2405 $outarray2[$userstatic->id] = array(
2406 'id' => $userstatic->id,
2407 'label' => $labeltoshow,
2408 'labelhtml' => $labeltoshowhtml,
2416 $out .=
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'" disabled>';
2417 $out .=
'<option value="">' . $langs->trans(
"None") .
'</option>';
2419 $out .=
'</select>';
2421 if ($num && !$forcecombo) {
2423 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2432 if ($outputmode == 2) {
2434 } elseif ($outputmode) {
2466 public function select_dolusers_forevent($action =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include = array(), $enableonly = array(), $force_entity =
'0', $maxlength = 0, $showstatus = 0, $morefilter =
'', $showproperties = 0, $listofuserid = array(), $listofcontactid = array(), $listofotherid = array(), $canremoveowner = 1)
2469 global $langs, $user;
2471 $userstatic =
new User($this->db);
2474 if (!empty($_SESSION[
'assignedtouser'])) {
2475 $assignedtouser = json_decode($_SESSION[
'assignedtouser'],
true);
2476 if (!is_array($assignedtouser)) {
2477 $assignedtouser = array();
2480 $assignedtouser = array();
2482 $nbassignetouser = count($assignedtouser);
2485 if ($nbassignetouser) {
2486 $out .=
'<ul class="attendees">';
2490 foreach ($assignedtouser as $key => $value) {
2491 if ($value[
'id'] == $ownerid) {
2496 $userstatic->fetch($value[
'id']);
2497 $out .= $userstatic->getNomUrl(-1);
2499 $ownerid = $value[
'id'];
2500 $out .=
' (' . $langs->trans(
"Owner") .
')';
2503 if ($nbassignetouser > 1 && $action !=
'view') {
2504 $canremoveassignee = 1;
2507 if (!$canremoveowner) {
2508 $canremoveassignee = 0;
2510 if (!$user->hasRight(
'agenda',
'allactions',
'create')) {
2511 $canremoveassignee = 0;
2516 if ($canremoveassignee) {
2519 $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 .
'">';
2523 if ($showproperties) {
2524 if ($ownerid == $value[
'id'] && is_array($listofuserid) && count($listofuserid) && in_array($ownerid, array_keys($listofuserid))) {
2525 $out .=
'<div class="myavailability inline-block">';
2526 $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>';
2536 if ($nbassignetouser) {
2541 if ($action !=
'view') {
2542 $out .=
'<input type="hidden" class="removedassignedhidden" name="removedassigned" value="">';
2543 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
2544 $out .=
'jQuery(".removedassigned").click(function() { jQuery(".removedassignedhidden").val(jQuery(this).val()); });';
2545 $out .=
'jQuery(".assignedtouser").change(function() { console.log(jQuery(".assignedtouser option:selected").val());';
2546 $out .=
' if (jQuery(".assignedtouser option:selected").val() > 0) { jQuery("#' . $action .
'assignedtouser").attr("disabled", false); }';
2547 $out .=
' else { jQuery("#' . $action .
'assignedtouser").attr("disabled", true); }';
2549 $out .=
'})</script>';
2550 $out .= $this->
select_dolusers(
'', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter);
2551 $out .=
' <input type="submit" disabled class="button valignmiddle smallpaddingimp reposition" id="' . $action .
'assignedtouser" name="' . $action .
'assignedtouser" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
2578 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())
2583 require_once DOL_DOCUMENT_ROOT.
'/resource/class/html.formresource.class.php';
2584 require_once DOL_DOCUMENT_ROOT.
'/resource/class/dolresource.class.php';
2589 if (!empty($_SESSION[
'assignedtoresource'])) {
2590 $assignedtoresource = json_decode($_SESSION[
'assignedtoresource'],
true);
2591 if (!is_array($assignedtoresource)) {
2592 $assignedtoresource = array();
2595 $assignedtoresource = array();
2597 $nbassignetoresource = count($assignedtoresource);
2600 if ($nbassignetoresource) {
2601 $out .=
'<ul class="attendees">';
2605 foreach ($assignedtoresource as $key => $value) {
2607 $resourcestatic->fetch($value[
'id']);
2608 $out .= $resourcestatic->getNomUrl(-1);
2609 if ($nbassignetoresource >= 1 && $action !=
'view') {
2610 $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 .
'">';
2613 if ($showproperties) {
2614 if (is_array($listofresourceid) && count($listofresourceid)) {
2615 $out .=
'<div class="myavailability inline-block">';
2616 $out .=
'<span class="hideonsmartphone"> - <span class="opacitymedium">' . $langs->trans(
"Availability") .
':</span> </span><input id="transparencyresource'.$value[
'id'].
'" class="paddingrightonly" ' . ($action ==
'view' ?
'disabled' :
'') .
' type="checkbox" name="transparency"' . ($listofresourceid[$value[
'id']][
'transparency'] ?
' checked' :
'') .
'><label for="transparencyresource'.$value[
'id'].
'">' . $langs->trans(
"Busy") .
'</label>';
2626 if ($nbassignetoresource) {
2631 if ($action !=
'view') {
2632 $out .=
'<input type="hidden" class="removedassignedresourcehidden" name="removedassignedresource" value="">';
2633 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">jQuery(document).ready(function () {';
2634 $out .=
'jQuery(".removedassignedresource").click(function() { jQuery(".removedassignedresourcehidden").val(jQuery(this).val()); });';
2635 $out .=
'jQuery(".assignedtoresource").change(function() { console.log(jQuery(".assignedtoresource option:selected").val());';
2636 $out .=
' if (jQuery(".assignedtoresource option:selected").val() > 0) { jQuery("#' . $action .
'assignedtoresource").attr("disabled", false); }';
2637 $out .=
' else { jQuery("#' . $action .
'assignedtoresource").attr("disabled", true); }';
2639 $out .=
'})</script>';
2642 $out .=
img_picto(
'',
'resource',
'class="pictofixedwidth"');
2643 $out .= $formresources->select_resource_list(0, $htmlname, [], 1, 1, 0, $events, array(), 2, 0);
2645 $out .=
' <input type="submit" disabled class="button valignmiddle smallpaddingimp reposition" id="' . $action .
'assignedtoresource" name="' . $action .
'assignedtoresource" value="' .
dol_escape_htmltag($langs->trans(
"Add")) .
'">';
2683 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)
2686 global $langs,
$conf;
2691 $price_level = (!empty($price_level) ? $price_level : 0);
2692 if (is_null($ajaxoptions)) {
2693 $ajaxoptions = array();
2696 if (strval($filtertype) ===
'' && (isModEnabled(
"product") || isModEnabled(
"service"))) {
2697 if (isModEnabled(
"product") && !isModEnabled(
'service')) {
2699 } elseif (!isModEnabled(
'product') && isModEnabled(
"service")) {
2705 $placeholder = (is_numeric($showempty) ?
'' :
'placeholder="'.dolPrintHTML($showempty).
'"');
2707 if ($selected && empty($selected_input_value)) {
2708 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
2709 $producttmpselect =
new Product($this->db);
2710 $producttmpselect->fetch($selected);
2711 $selected_input_value = $producttmpselect->ref;
2712 unset($producttmpselect);
2715 if ($filtertype ==
'') {
2716 if (!isModEnabled(
'product')) {
2718 } elseif (!isModEnabled(
'service')) {
2723 $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;
2724 if ((
int) $warehouseId > 0) {
2725 $urloption .=
'&warehouseid=' . (int) $warehouseId;
2728 $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);
2730 if (isModEnabled(
'variants') && is_array($selected_combinations)) {
2734 <!-- script to auto show attributes select tags if a variant was selected -->
2735 <script nonce="' .
getNonce() .
'">
2736 // auto show attributes fields
2737 selected = ' . json_encode($selected_combinations) .
';
2740 jQuery(document).ready(function () {
2742 jQuery("input[name=\'prod_entry_mode\']").change(function () {
2743 if (jQuery(this).val() == \'free\') {
2744 jQuery(\'div#attributes_box\').empty();
2748 jQuery("input#' . $htmlname .
'").change(function () {
2750 if (!jQuery(this).val()) {
2751 jQuery(\'div#attributes_box\').empty();
2755 console.log("A change has started. We get variants fields to inject html select");
2757 jQuery.getJSON("' . DOL_URL_ROOT .
'/variants/ajax/getCombinations.php", {
2758 id: jQuery(this).val()
2759 }, function (data) {
2760 jQuery(\'div#attributes_box\').empty();
2762 jQuery.each(data, function (key, val) {
2764 combvalues[val.id] = val.values;
2766 var span = jQuery(document.createElement(\'div\')).css({
2767 \'display\': \'table-row\'
2771 jQuery(document.createElement(\'div\')).text(val.label).css({
2772 \'font-weight\': \'bold\',
2773 \'display\': \'table-cell\'
2777 var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({
2778 \'margin-left\': \'15px\',
2779 \'white-space\': \'pre\'
2781 jQuery(document.createElement(\'option\')).val(\'\')
2784 jQuery.each(combvalues[val.id], function (key, val) {
2785 var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value);
2787 if (selected[val.fk_product_attribute] == val.id) {
2788 tag.attr(\'selected\', \'selected\');
2795 jQuery(\'div#attributes_box\').append(span);
2800 ' . ($selected ?
'jQuery("input#' . $htmlname .
'").change();' :
'') .
'
2806 if (empty($hidelabel)) {
2808 } elseif ($hidelabel > 1) {
2810 if ($hidelabel == 2) {
2811 $out .=
img_picto($langs->trans(
"Search"),
'search');
2815 $out .=
'<input type="text" class="minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . $placeholder .
' ' . (
getDolGlobalString(
'PRODUCT_SEARCH_AUTOFOCUS') ?
'autofocus' :
'') .
' />';
2816 if ($hidelabel == 3) {
2817 $out .=
img_picto($langs->trans(
"Search"),
'search');
2820 $out .= $this->
select_produits_list($selected, $htmlname, $filtertype, $limit, $price_level,
'', $status, $finished, 0, $socid, $showempty, $forcecombo, $morecss, $hidepriceinlabel, $warehouseStatus, $status_purchase, $warehouseId);
2823 if (empty($nooutput)) {
2847 public function select_bom($selected =
'', $htmlname =
'bom_id', $limit = 0, $status = 1, $type = 0, $showempty =
'1', $morecss =
'', $nooutput =
'', $forcecombo = 0, $TProducts = [])
2852 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
2858 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2863 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
2865 $sql =
'SELECT b.rowid, b.ref, b.label, b.fk_product';
2866 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'bom_bom as b';
2867 $sql .=
' WHERE b.entity IN (' .
getEntity(
'bom') .
')';
2868 if (!empty($status)) {
2869 $sql .=
' AND status = ' . (int) $status;
2871 if (!empty($type)) {
2872 $sql .=
' AND bomtype = ' . (int) $type;
2874 if (!empty($TProducts)) {
2875 $sql .=
' AND fk_product IN (' . $this->db->sanitize(implode(
',', $TProducts)) .
')';
2877 if (!empty($limit)) {
2878 $sql .=
' LIMIT ' . (int) $limit;
2880 $resql = $db->query($sql);
2883 $out .=
'<option value="-1"';
2884 if (empty($selected)) {
2885 $out .=
' selected';
2887 $out .=
'> </option>';
2889 while ($obj = $db->fetch_object($resql)) {
2891 $res = $product->fetch($obj->fk_product);
2892 $out .=
'<option value="' . $obj->rowid .
'"';
2893 if ($obj->rowid == $selected) {
2896 $out .=
'>' . $obj->ref .
' - ' . $product->label .
' - ' . $obj->label .
'</option>';
2902 $out .=
'</select>';
2903 if (empty($nooutput)) {
2938 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)
2942 global $hookmanager;
2945 $outarray = array();
2949 $langs->load(
'other');
2952 $warehouseStatusArray = array();
2953 if (!empty($warehouseStatus)) {
2954 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/entrepot.class.php';
2955 if (preg_match(
'/warehouseclosed/', $warehouseStatus)) {
2958 if (preg_match(
'/warehouseopen/', $warehouseStatus)) {
2961 if (preg_match(
'/warehouseinternal/', $warehouseStatus)) {
2966 $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";
2967 if (count($warehouseStatusArray)) {
2968 $selectFieldsGrouped =
", sum(" . $this->db->ifsql(
"e.statut IS NULL",
"0",
"ps.reel") .
") as stock";
2970 $selectFieldsGrouped =
", " . $this->db->ifsql(
"p.stock IS NULL", 0,
"p.stock") .
" AS stock";
2976 $parameters = array();
2977 $reshook = $hookmanager->executeHooks(
'selectProductsListSelect', $parameters);
2978 if (empty($reshook)) {
2979 $sql .= $selectFields.$selectFieldsGrouped.$hookmanager->resPrint;
2981 $sql .= $hookmanager->resPrint;
2986 $sql .=
", (SELECT " . $this->db->prefix() .
"categorie_product.fk_categorie
2987 FROM " . $this->db->prefix() .
"categorie_product
2988 WHERE " . $this->db->prefix() .
"categorie_product.fk_product=p.rowid
2990 ) AS categorie_product_id ";
2995 $sql .=
', pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,';
2996 $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';
2997 $selectFields .=
", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custdefault_vat_code, custref";
3001 $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";
3002 $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';
3007 $sql .=
", pl.label as label_translated";
3008 $sql .=
", pl.description as description_translated";
3009 $selectFields .=
", label_translated";
3010 $selectFields .=
", description_translated";
3014 $sql .=
", (SELECT pp.rowid FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
3015 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
3016 $sql .=
" AND price_level = " . ((int) $price_level);
3018 $sql .=
" ORDER BY date_price";
3019 $sql .=
" DESC LIMIT 1) as price_rowid";
3020 $sql .=
", (SELECT pp.price_by_qty FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
3021 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
3022 $sql .=
" AND price_level = " . ((int) $price_level);
3024 $sql .=
" ORDER BY date_price";
3025 $sql .=
" DESC LIMIT 1) as price_by_qty";
3026 $selectFields .=
", price_rowid, price_by_qty";
3029 $sql .=
" FROM ".$this->db->prefix().
"product as p";
3032 $sql .=
" USE INDEX (" . $this->db->sanitize(
getDolGlobalString(
'MAIN_PRODUCT_FORCE_INDEX')) .
")";
3036 $parameters = array();
3037 $reshook = $hookmanager->executeHooks(
'selectProductsListFrom', $parameters);
3038 $sql .= $hookmanager->resPrint;
3040 if (count($warehouseStatusArray)) {
3041 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_stock as ps on ps.fk_product = p.rowid";
3042 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entrepot as e on ps.fk_entrepot = e.rowid AND e.entity IN (" .
getEntity(
'stock') .
")";
3043 $sql .=
' AND e.statut IN (' . $this->db->sanitize($this->db->escape(implode(
',', $warehouseStatusArray))) .
')';
3048 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_customer_price as pcp ON pcp.fk_soc=" . ((int) $socid) .
" AND pcp.fk_product=p.rowid";
3052 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
3056 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_lang as pl ON pl.fk_product = p.rowid ";
3058 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
3059 $soc =
new Societe($this->db);
3060 $result = $soc->fetch($socid);
3061 if ($result > 0 && !empty($soc->default_lang)) {
3062 $sql .=
" AND pl.lang = '" . $this->db->escape($soc->default_lang) .
"'";
3064 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3067 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3072 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_attribute_combination pac ON pac.fk_product_child = p.rowid";
3075 $sql .=
' WHERE p.entity IN (' .
getEntity(
'product') .
')';
3078 $sql .=
" AND pac.rowid IS NULL";
3081 if ($finished == 0) {
3082 $sql .=
" AND p.finished = " . ((int) $finished);
3083 } elseif ($finished == 1) {
3084 $sql .=
" AND p.finished = ".((int) $finished);
3087 $sql .=
" AND p.tosell = ".((int) $status);
3089 if ($status_purchase >= 0) {
3090 $sql .=
" AND p.tobuy = " . ((int) $status_purchase);
3093 if (strval($filtertype) !=
'') {
3094 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
3095 } elseif (!isModEnabled(
'product')) {
3096 $sql .=
" AND p.fk_product_type = 1";
3097 } elseif (!isModEnabled(
'service')) {
3098 $sql .=
" AND p.fk_product_type = 0";
3101 if ((
int) $warehouseId > 0) {
3102 $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)";
3106 $parameters = array();
3107 $reshook = $hookmanager->executeHooks(
'selectProductsListWhere', $parameters);
3108 $sql .= $hookmanager->resPrint;
3110 if ($filterkey !=
'') {
3111 $sqlSupplierSearch=
'';
3116 $search_crit = explode(
' ', $filterkey);
3118 if (count($search_crit) > 1) {
3121 foreach ($search_crit as $crit) {
3125 $sql .=
"(p.ref LIKE '" . $this->db->escape($prefix . $crit) .
"%' OR p.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3127 $sql .=
" OR pl.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3130 $sql .=
" OR pcp.ref_customer LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3133 $sql .=
" OR p.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3135 $sql .=
" OR pl.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3141 $sqlSupplierSearch .= !empty($sqlSupplierSearch) ?
' AND ':
'';
3142 $sqlSupplierSearch .=
" pfp.ref_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3147 if (count($search_crit) > 1) {
3150 if (isModEnabled(
'barcode')) {
3151 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3156 $sql .=
" OR EXISTS (SELECT pfp.fk_product FROM " . $this->db->prefix() .
"product_fournisseur_price as pfp WHERE p.rowid = pfp.fk_product";
3158 $sql .= $sqlSupplierSearch;
3164 if (count($warehouseStatusArray)) {
3165 $sql .=
" GROUP BY " . $selectFields;
3170 $sql .=
" ORDER BY categorie_product_id ";
3172 (
getDolGlobalInt(
'PRODUCT_SORT_BY_CATEGORY') == 1) ? $sql .=
"ASC" : $sql .=
"DESC";
3174 $sql .= $this->db->order(
"p.ref");
3177 $sql .= $this->db->plimit($limit, 0);
3180 dol_syslog(get_class($this) .
"::select_produits_list search products", LOG_DEBUG);
3181 $result = $this->db->query($sql);
3183 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3184 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3185 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
3187 $num = $this->db->num_rows($result);
3192 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3196 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
3202 if ($showempty && !is_numeric($showempty)) {
3203 $textifempty = $langs->trans($showempty);
3205 $textifempty .= $langs->trans(
"All");
3208 if ($showempty && !is_numeric($showempty)) {
3209 $textifempty = $langs->trans($showempty);
3213 $out .=
'<option value="-1" selected>' . ($textifempty ? $textifempty :
' ') .
'</option>';
3217 while ($num && $i < $num) {
3220 $objp = $this->db->fetch_object($result);
3222 if ((
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1) {
3223 $sql =
"SELECT rowid, quantity, price, unitprice, remise_percent, remise, price_base_type";
3224 $sql .=
" FROM " . $this->db->prefix() .
"product_price_by_qty";
3225 $sql .=
" WHERE fk_product_price = " . ((int) $objp->price_rowid);
3226 $sql .=
" ORDER BY quantity ASC";
3228 dol_syslog(get_class($this) .
"::select_produits_list search prices by qty", LOG_DEBUG);
3229 $result2 = $this->db->query($sql);
3231 $nb_prices = $this->db->num_rows($result2);
3233 while ($nb_prices && $j < $nb_prices) {
3234 $objp2 = $this->db->fetch_object($result2);
3236 $objp->price_by_qty_rowid = $objp2->rowid;
3237 $objp->price_by_qty_price_base_type = $objp2->price_base_type;
3238 $objp->price_by_qty_quantity = $objp2->quantity;
3239 $objp->price_by_qty_unitprice = $objp2->unitprice;
3240 $objp->price_by_qty_remise_percent = $objp2->remise_percent;
3242 $objp->quantity = $objp2->quantity;
3243 $objp->price = $objp2->price;
3244 $objp->unitprice = $objp2->unitprice;
3245 $objp->remise_percent = $objp2->remise_percent;
3251 '@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';
3258 array_push($outarray, $optJson);
3262 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_price_expression)) {
3263 $price_product =
new Product($this->db);
3264 $price_product->fetch($objp->rowid,
'',
'', 1);
3266 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3268 $price_result = $priceparser->parseProduct($price_product);
3269 if ($price_result >= 0) {
3270 $objp->price = $price_result;
3271 $objp->unitprice = $price_result;
3273 $objp->price_ttc = (float)
price2num($objp->price) * (1 + ($objp->tva_tx / 100));
3274 $objp->price_ttc =
price2num($objp->price_ttc,
'MU');
3277 if (
getDolGlobalInt(
'PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES') && !empty($objp->custprice)) {
3285 array_push($outarray, $optJson);
3291 $out .=
'</select>';
3293 $this->db->free($result);
3295 if (empty($outputmode)) {
3322 protected function constructProductListOption(&$objp, &$opt, &$optJson, $price_level, $selected, $hidepriceinlabel = 0, $filterkey =
'', $novirtualstock = 0)
3324 global $langs,
$conf, $user;
3325 global $hookmanager;
3331 $outlabel_translated =
'';
3333 $outdesc_translated =
'';
3339 $outpricebasetype =
'';
3341 $outdefault_vat_code =
'';
3345 $maxlengtharticle = (!
getDolGlobalString(
'PRODUCT_MAX_LENGTH_COMBO') ? 48 :
$conf->global->PRODUCT_MAX_LENGTH_COMBO);
3347 $label = $objp->label;
3348 if (!empty($objp->label_translated)) {
3349 $label = $objp->label_translated;
3351 if (!empty($filterkey) && $filterkey !=
'') {
3352 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
3355 $outkey = $objp->rowid;
3356 $outref = $objp->ref;
3357 $outrefcust = empty($objp->custref) ?
'' : $objp->custref;
3358 $outlabel = $objp->label;
3359 $outdesc = $objp->description;
3361 $outlabel_translated = $objp->label_translated;
3362 $outdesc_translated = $objp->description_translated;
3364 $outbarcode = $objp->barcode;
3365 $outorigin = $objp->fk_country;
3366 $outpbq = empty($objp->price_by_qty_rowid) ?
'' : $objp->price_by_qty_rowid;
3368 $outtype = $objp->fk_product_type;
3373 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
3379 if (!empty($objp->unit_short)) {
3380 $outvalUnits .=
' - ' . $objp->unit_short;
3384 if (!empty($objp->weight) && $objp->weight_units !==
null) {
3386 $outvalUnits .=
' - ' . $unitToShow;
3388 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
3389 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
3390 $outvalUnits .=
' - ' . $unitToShow;
3392 if (!empty($objp->surface) && $objp->surface_units !==
null) {
3394 $outvalUnits .=
' - ' . $unitToShow;
3396 if (!empty($objp->volume) && $objp->volume_units !==
null) {
3398 $outvalUnits .=
' - ' . $unitToShow;
3401 if ($outdurationvalue && $outdurationunit) {
3403 'h' => $langs->trans(
'Hour'),
3404 'd' => $langs->trans(
'Day'),
3405 'w' => $langs->trans(
'Week'),
3406 'm' => $langs->trans(
'Month'),
3407 'y' => $langs->trans(
'Year')
3409 if (isset($da[$outdurationunit])) {
3410 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
3417 if ($user->hasRight(
'stock',
'lire')) {
3418 if ($objp->stock > 0) {
3420 } elseif ($objp->stock <= 0) {
3428 $labeltoshow .= $objp->ref;
3429 if (!empty($objp->custref)) {
3430 $labeltoshow .=
' (' . $objp->custref .
')';
3433 $labeltoshow .=
' (' . $outbarcode .
')';
3435 $labeltoshow .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3437 $labeltoshow .=
' (' .
getCountry($outorigin,
'1') .
')';
3441 $labeltoshowhtml =
'';
3442 $labeltoshowhtml .= $objp->ref;
3443 if (!empty($objp->custref)) {
3444 $labeltoshowhtml .=
' (' . $objp->custref .
')';
3446 if (!empty($filterkey) && $filterkey !=
'') {
3447 $labeltoshowhtml = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $labeltoshowhtml, 1);
3450 $labeltoshowhtml .=
' (' . $outbarcode .
')';
3452 $labeltoshowhtml .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3454 $labeltoshowhtml .=
' (' .
getCountry($outorigin,
'1') .
')';
3458 $labeltoshowstock =
'';
3459 $labeltoshowhtmlstock =
'';
3461 if ($user->hasRight(
'stock',
'lire')) {
3462 $labeltoshowstock .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
3464 if ($objp->stock > 0) {
3465 $labeltoshowhtmlstock .=
' - <span class="product_line_stock_ok">';
3466 } elseif ($objp->stock <= 0) {
3467 $labeltoshowhtmlstock .=
' - <span class="product_line_stock_too_low">';
3469 $labeltoshowhtmlstock .= $langs->transnoentities(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
3470 $labeltoshowhtmlstock .=
'</span>';
3472 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
3473 $langs->load(
"stocks");
3475 $tmpproduct =
new Product($this->db);
3476 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
3477 $tmpproduct->load_virtual_stock();
3478 $virtualstock = $tmpproduct->stock_theorique;
3480 $labeltoshowstock .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
3482 $labeltoshowhtmlstock .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
3483 if ($virtualstock > 0) {
3484 $labeltoshowhtmlstock .=
'<span class="product_line_stock_ok">';
3485 } elseif ($virtualstock <= 0) {
3486 $labeltoshowhtmlstock .=
'<span class="product_line_stock_too_low">';
3488 $labeltoshowhtmlstock .= $virtualstock;
3489 $labeltoshowhtmlstock .=
'</span>';
3498 $labeltoshowprice =
'';
3499 $labeltoshowhtmlprice =
'';
3502 $sql =
"SELECT price, price_ttc, price_base_type, tva_tx, default_vat_code";
3503 $sql .=
" FROM " . $this->db->prefix() .
"product_price";
3504 $sql .=
" WHERE fk_product = " . ((int) $objp->rowid);
3505 $sql .=
" AND entity IN (" .
getEntity(
'productprice') .
")";
3506 $sql .=
" AND price_level = " . ((int) $price_level);
3507 $sql .=
" ORDER BY date_price DESC, rowid DESC";
3510 dol_syslog(get_class($this) .
'::constructProductListOption search price for product ' . $objp->rowid .
' AND level ' . $price_level, LOG_DEBUG);
3511 $result2 = $this->db->query($sql);
3513 $objp2 = $this->db->fetch_object($result2);
3516 if ($objp2->price_base_type ==
'HT') {
3517 $labeltoshowprice .=
' - ' .
price($objp2->price, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
3518 $labeltoshowhtmlprice .=
' - ' .
price($objp2->price, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
3520 $labeltoshowprice .=
' - ' .
price($objp2->price_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
3521 $labeltoshowhtmlprice .=
' - ' .
price($objp2->price_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3523 $outprice_ht =
price($objp2->price);
3524 $outprice_ttc =
price($objp2->price_ttc);
3525 $outpricebasetype = $objp2->price_base_type;
3527 $outtva_tx = $objp2->tva_tx;
3528 $outdefault_vat_code = $objp2->default_vat_code;
3530 $outtva_tx = $objp->tva_tx;
3531 $outdefault_vat_code = $objp->default_vat_code;
3540 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1 && (
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
3542 $outqty = $objp->quantity;
3543 $outdiscount = $objp->remise_percent;
3544 if ($objp->quantity == 1) {
3545 $labeltoshowprice .=
' - ' .
price($objp->unitprice, 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
3546 $labeltoshowhtmlprice .=
' - ' .
price($objp->unitprice, 0, $langs, 0, 0, -1,
$conf->currency) .
"/";
3547 $labeltoshowprice .= $langs->trans(
"Unit");
3548 $labeltoshowhtmlprice .= $langs->transnoentities(
"Unit");
3550 $labeltoshowprice .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
3551 $labeltoshowhtmlprice .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
3552 $labeltoshowprice .= $langs->trans(
"Units");
3553 $labeltoshowhtmlprice .= $langs->transnoentities(
"Units");
3556 $outprice_ht =
price($objp->unitprice);
3557 $outprice_ttc =
price($objp->unitprice * (1 + ($objp->tva_tx / 100)));
3558 $outpricebasetype = $objp->price_base_type;
3559 $outtva_tx = $objp->tva_tx;
3560 $outdefault_vat_code = $objp->default_vat_code;
3562 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1) {
3563 $labeltoshowprice .=
" (" .
price($objp->unitprice, 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->trans(
"Unit") .
")";
3564 $labeltoshowhtmlprice .=
" (" .
price($objp->unitprice, 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->transnoentities(
"Unit") .
")";
3566 if (empty($hidepriceinlabel) && !empty($objp->remise_percent) && $objp->remise_percent >= 1) {
3567 $labeltoshowprice .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3568 $labeltoshowhtmlprice .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3573 if (!empty($objp->idprodcustprice)) {
3576 if ($objp->custprice_base_type ==
'HT') {
3577 $labeltoshowprice .=
' - ' .
price($objp->custprice, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
3578 $labeltoshowhtmlprice .=
' - ' .
price($objp->custprice, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
3580 $labeltoshowprice .=
' - ' .
price($objp->custprice_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
3581 $labeltoshowhtmlprice .=
' - ' .
price($objp->custprice_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3584 $outprice_ht =
price($objp->custprice);
3585 $outprice_ttc =
price($objp->custprice_ttc);
3586 $outpricebasetype = $objp->custprice_base_type;
3587 $outtva_tx = $objp->custtva_tx;
3588 $outdefault_vat_code = $objp->custdefault_vat_code;
3593 if (empty($hidepriceinlabel) && !$found) {
3594 if ($objp->price_base_type ==
'HT') {
3595 $labeltoshowprice .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
3596 $labeltoshowhtmlprice .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
3598 $labeltoshowprice .=
' - ' .
price($objp->price_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
3599 $labeltoshowhtmlprice .=
' - ' .
price($objp->price_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3601 $outprice_ht =
price($objp->price);
3602 $outprice_ttc =
price($objp->price_ttc);
3603 $outpricebasetype = $objp->price_base_type;
3604 $outtva_tx = $objp->tva_tx;
3605 $outdefault_vat_code = $objp->default_vat_code;
3609 $opt =
'<option value="' . $objp->rowid .
'"';
3610 $opt .= ($objp->rowid == $selected) ?
' selected' :
'';
3611 if (!empty($objp->price_by_qty_rowid) && $objp->price_by_qty_rowid > 0) {
3612 $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 .
'"';
3615 $opt .=
' data-labeltrans="' . $outlabel_translated .
'"';
3619 if ($stocktag == 1) {
3620 $opt .=
' class="product_line_stock_ok" data-html="'.$labeltoshowhtml.$outvalUnits.$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
3623 if ($stocktag == -1) {
3624 $opt .=
' class="product_line_stock_too_low" data-html="'.$labeltoshowhtml.$outvalUnits.$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
3631 $opt .= $labeltoshow;
3632 $outval .= $labeltoshowhtml;
3635 $opt .= $outvalUnits;
3636 $outval .= $outvalUnits;
3639 $opt .= $labeltoshowprice;
3640 $outval .= $labeltoshowhtmlprice;
3643 $opt .= $labeltoshowstock;
3644 $outval .= $labeltoshowhtmlstock;
3647 $parameters = array(
'objp' => $objp);
3648 $reshook = $hookmanager->executeHooks(
'constructProductListOption', $parameters);
3649 if (empty($reshook)) {
3650 $opt .= $hookmanager->resPrint;
3652 $opt = $hookmanager->resPrint;
3655 $opt .=
"</option>\n";
3660 'label2' => $outlabel,
3664 'price_ttc' =>
price2num($outprice_ttc),
3667 'pricebasetype' => $outpricebasetype,
3668 'tva_tx' => $outtva_tx,
3669 'default_vat_code' => $outdefault_vat_code,
3671 'discount' => $outdiscount,
3672 'duration_value' => $outdurationvalue,
3673 'duration_unit' => $outdurationunit,
3675 'labeltrans' => $outlabel_translated,
3676 'desctrans' => $outdesc_translated,
3677 'ref_customer' => $outrefcust
3698 public function select_produits_fournisseurs($socid, $selected =
'', $htmlname =
'productid', $filtertype =
'', $filtre =
'', $ajaxoptions = array(), $hidelabel = 0, $alsoproductwithnosupplierprice = 0, $morecss =
'', $placeholder =
'')
3701 global $langs,
$conf;
3702 global $price_level, $status, $finished;
3704 if (!isset($status)) {
3708 $selected_input_value =
'';
3710 if ($selected > 0) {
3711 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3712 $producttmpselect =
new Product($this->db);
3713 $producttmpselect->fetch($selected);
3714 $selected_input_value = $producttmpselect->ref;
3715 unset($producttmpselect);
3719 $urloption = ($socid > 0 ?
'socid=' . $socid .
'&' :
'') .
'htmlname=' . $htmlname .
'&outjson=1&price_level=' . $price_level .
'&type=' . $filtertype .
'&mode=2&status=' . $status .
'&finished=' . $finished .
'&alsoproductwithnosupplierprice=' . $alsoproductwithnosupplierprice;
3720 print
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT .
'/product/ajax/products.php', $urloption,
getDolGlobalInt(
'PRODUIT_USE_SEARCH_TO_SELECT'), 0, $ajaxoptions);
3722 print($hidelabel ?
'' : $langs->trans(
"RefOrLabel") .
' : ') .
'<input type="text" class="'.$morecss.
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . ($placeholder ?
' placeholder="' . $placeholder .
'"' :
'') .
'>';
3724 print $this->
select_produits_fournisseurs_list($socid, $selected, $htmlname, $filtertype, $filtre,
'', $status, 0, 0, $alsoproductwithnosupplierprice, $morecss, 0, $placeholder);
3748 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 =
'')
3751 global $langs,
$conf, $user;
3752 global $hookmanager;
3755 $outarray = array();
3757 $maxlengtharticle = (!
getDolGlobalString(
'PRODUCT_MAX_LENGTH_COMBO') ? 48 :
$conf->global->PRODUCT_MAX_LENGTH_COMBO);
3759 $langs->load(
'stocks');
3762 $langs->load(
'other');
3765 $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,";
3766 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice, pfp.barcode";
3767 $sql .=
", pfp.multicurrency_code, pfp.multicurrency_unitprice";
3768 $sql .=
", pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.default_vat_code, pfp.fk_soc, s.nom as name";
3769 $sql .=
", pfp.supplier_reputation";
3772 $sql .=
", pfp.desc_fourn as description";
3774 $sql .=
", p.description";
3778 $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";
3780 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
3781 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN (" .
getEntity(
'product') .
") )";
3783 $sql .=
" AND pfp.fk_soc = " . ((int) $socid);
3785 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
3788 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
3790 $sql .=
" WHERE p.entity IN (" .
getEntity(
'product') .
")";
3791 if ($statut != -1) {
3792 $sql .=
" AND p.tobuy = " . ((int) $statut);
3794 if (strval($filtertype) !=
'') {
3795 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
3797 if (!empty($filtre)) {
3798 $sql .=
" " . $filtre;
3801 $parameters = array();
3802 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListWhere', $parameters);
3803 $sql .= $hookmanager->resPrint;
3805 if ($filterkey !=
'') {
3809 $search_crit = explode(
' ', $filterkey);
3811 if (count($search_crit) > 1) {
3814 foreach ($search_crit as $crit) {
3818 $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) .
"%'";
3820 $sql .=
" OR pfp.desc_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3825 if (count($search_crit) > 1) {
3828 if (isModEnabled(
'barcode')) {
3829 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3830 $sql .=
" OR pfp.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3834 $sql .=
" ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC";
3835 $sql .= $this->db->plimit($limit, 0);
3839 dol_syslog(get_class($this) .
"::select_produits_fournisseurs_list", LOG_DEBUG);
3840 $result = $this->db->query($sql);
3842 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3843 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
3845 $num = $this->db->num_rows($result);
3848 $out .=
'<select class="flat ' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'">';
3850 $out .=
'<option value="-1" selected>' . ($placeholder ? $placeholder :
' ') .
'</option>';
3852 $out .=
'<option value="-1">' . ($placeholder ? $placeholder :
' ') .
'</option>';
3857 $objp = $this->db->fetch_object($result);
3859 if (is_null($objp->idprodfournprice)) {
3861 $objp->tva_tx = $objp->tva_tx_sale;
3862 $objp->default_vat_code = $objp->default_vat_code_sale;
3865 $outkey = $objp->idprodfournprice;
3866 if (!$outkey && $alsoproductwithnosupplierprice) {
3867 $outkey =
'idprod_' . $objp->rowid;
3870 $outref = $objp->ref;
3871 $outbarcode = $objp->barcode;
3874 $outtype = $objp->fk_product_type;
3881 if (!empty($objp->unit_short)) {
3882 $outvalUnits .=
' - ' . $objp->unit_short;
3884 if (!empty($objp->weight) && $objp->weight_units !==
null) {
3886 $outvalUnits .=
' - ' . $unitToShow;
3888 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
3889 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
3890 $outvalUnits .=
' - ' . $unitToShow;
3892 if (!empty($objp->surface) && $objp->surface_units !==
null) {
3894 $outvalUnits .=
' - ' . $unitToShow;
3896 if (!empty($objp->volume) && $objp->volume_units !==
null) {
3898 $outvalUnits .=
' - ' . $unitToShow;
3900 if ($outdurationvalue && $outdurationunit) {
3902 'h' => $langs->trans(
'Hour'),
3903 'd' => $langs->trans(
'Day'),
3904 'w' => $langs->trans(
'Week'),
3905 'm' => $langs->trans(
'Month'),
3906 'y' => $langs->trans(
'Year')
3908 if (isset($da[$outdurationunit])) {
3909 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
3914 $objRef = $objp->ref;
3915 if ($filterkey && $filterkey !=
'') {
3916 $objRef = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRef, 1);
3918 $objRefFourn = $objp->ref_fourn;
3919 if ($filterkey && $filterkey !=
'') {
3920 $objRefFourn = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRefFourn, 1);
3922 $label = $objp->label;
3923 if ($filterkey && $filterkey !=
'') {
3924 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
3927 switch ($objp->fk_product_type) {
3939 if (empty($picto)) {
3942 $optlabel =
img_object(
'', $picto,
'class="paddingright classfortooltip"', 0, 0, 1);
3945 $optlabel .= $objp->ref;
3946 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
3947 $optlabel .=
' <span class="opacitymedium">(' . $objp->ref_fourn .
')</span>';
3949 if (isModEnabled(
'barcode') && !empty($objp->barcode)) {
3950 $optlabel .=
' (' . $outbarcode .
')';
3952 $optlabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3954 $outvallabel = $objRef;
3955 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
3956 $outvallabel .=
' (' . $objRefFourn .
')';
3958 if (isModEnabled(
'barcode') && !empty($objp->barcode)) {
3959 $outvallabel .=
' (' . $outbarcode .
')';
3961 $outvallabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3964 $optlabel .= $outvalUnits;
3965 $outvallabel .= $outvalUnits;
3967 if (!empty($objp->idprodfournprice)) {
3968 $outqty = $objp->quantity;
3969 $outdiscount = $objp->remise_percent;
3970 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
3972 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
3973 $prod_supplier->id = $objp->fk_product;
3974 $prod_supplier->fourn_qty = $objp->quantity;
3975 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
3976 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
3978 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3980 $price_result = $priceparser->parseProductSupplier($prod_supplier);
3981 if ($price_result >= 0) {
3982 $objp->fprice = $price_result;
3983 if ($objp->quantity >= 1) {
3984 $objp->unitprice = $objp->fprice / $objp->quantity;
3988 if ($objp->quantity == 1) {
3989 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
3990 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1,
$conf->currency) .
"/";
3991 $optlabel .= $langs->trans(
"Unit");
3992 $outvallabel .= $langs->transnoentities(
"Unit");
3994 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
3995 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
3996 $optlabel .=
' ' . $langs->trans(
"Units");
3997 $outvallabel .=
' ' . $langs->transnoentities(
"Units");
4000 if ($objp->quantity > 1) {
4001 $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") .
")";
4002 $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") .
")";
4004 if ($objp->remise_percent >= 1) {
4005 $optlabel .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4006 $outvallabel .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
4008 if ($objp->duration) {
4009 $optlabel .=
" - " . $objp->duration;
4010 $outvallabel .=
" - " . $objp->duration;
4013 $optlabel .=
" - " .
dol_trunc($objp->name, 8);
4014 $outvallabel .=
" - " .
dol_trunc($objp->name, 8);
4016 if ($objp->supplier_reputation) {
4018 $reputations = array(
'' => $langs->trans(
'Standard'),
'FAVORITE' => $langs->trans(
'Favorite'),
'NOTTHGOOD' => $langs->trans(
'NotTheGoodQualitySupplier'),
'DONOTORDER' => $langs->trans(
'DoNotOrderThisProductToThisSupplier'));
4020 $optlabel .=
" - " . $reputations[$objp->supplier_reputation];
4021 $outvallabel .=
" - " . $reputations[$objp->supplier_reputation];
4024 $optlabel .=
" - <span class='opacitymedium'>" . $langs->trans(
"NoPriceDefinedForThisSupplier") .
'</span>';
4025 $outvallabel .=
' - ' . $langs->transnoentities(
"NoPriceDefinedForThisSupplier");
4029 $novirtualstock = ($showstockinlist == 2);
4031 if ($user->hasRight(
'stock',
'lire')) {
4032 $outvallabel .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
4034 if ($objp->stock > 0) {
4035 $optlabel .=
' - <span class="product_line_stock_ok">';
4036 } elseif ($objp->stock <= 0) {
4037 $optlabel .=
' - <span class="product_line_stock_too_low">';
4039 $optlabel .= $langs->transnoentities(
"Stock") .
':' .
price(
price2num($objp->stock,
'MS'));
4040 $optlabel .=
'</span>';
4041 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
4042 $langs->load(
"stocks");
4044 $tmpproduct =
new Product($this->db);
4045 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
4046 $tmpproduct->load_virtual_stock();
4047 $virtualstock = $tmpproduct->stock_theorique;
4049 $outvallabel .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
4051 $optlabel .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
4052 if ($virtualstock > 0) {
4053 $optlabel .=
'<span class="product_line_stock_ok">';
4054 } elseif ($virtualstock <= 0) {
4055 $optlabel .=
'<span class="product_line_stock_too_low">';
4057 $optlabel .= $virtualstock;
4058 $optlabel .=
'</span>';
4065 $optstart =
'<option value="' . $outkey .
'"';
4066 if ($selected && $selected == $objp->idprodfournprice) {
4067 $optstart .=
' selected';
4069 if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) {
4070 $optstart .=
' disabled';
4073 if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) {
4082 $optstart .=
' data-default-vat-code="' .
dol_escape_htmltag($objp->default_vat_code) .
'"';
4084 if (isModEnabled(
'multicurrency')) {
4085 $optstart .=
' data-multicurrency-code="' .
dol_escape_htmltag($objp->multicurrency_code) .
'"';
4089 $optstart .=
' data-description="' .
dol_escape_htmltag($objp->description, 0, 1) .
'"';
4092 $outarrayentry = array(
4095 'label' => $outvallabel,
4096 'labelhtml' => $optlabel,
4098 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4099 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4100 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4101 'tva_tx_formated' =>
price($objp->tva_tx, 0, $langs, 1, -1, 2),
4103 'default_vat_code' => $objp->default_vat_code,
4104 'supplier_ref' => $objp->ref_fourn,
4105 'discount' => $outdiscount,
4107 'duration_value' => $outdurationvalue,
4108 'duration_unit' => $outdurationunit,
4109 'disabled' => empty($objp->idprodfournprice),
4110 'description' => $objp->description
4112 if (isModEnabled(
'multicurrency')) {
4113 $outarrayentry[
'multicurrency_code'] = $objp->multicurrency_code;
4114 $outarrayentry[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4116 $parameters = array(
4118 'optstart' => &$optstart,
4119 'optlabel' => &$optlabel,
4120 'outvallabel' => &$outvallabel,
4121 'outarrayentry' => &$outarrayentry,
4124 $reshook = $hookmanager->executeHooks(
'selectProduitsFournisseurListOption', $parameters, $this);
4130 $out .= $optstart .
' data-html="' .
dol_escape_htmltag($optlabel) .
'">' . $optlabel .
"</option>\n";
4131 $outarraypush = array(
4134 'label' => $outvallabel,
4135 'labelhtml' => $optlabel,
4137 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4138 'price_qty_ht_locale' =>
price($objp->fprice),
4139 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4140 'price_unit_ht_locale' =>
price($objp->unitprice),
4141 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4142 'tva_tx_formated' =>
price($objp->tva_tx),
4144 'default_vat_code' => $objp->default_vat_code,
4145 'supplier_ref' => $objp->ref_fourn,
4146 'discount' => $outdiscount,
4148 'duration_value' => $outdurationvalue,
4149 'duration_unit' => $outdurationunit,
4150 'disabled' => empty($objp->idprodfournprice),
4151 'description' => $objp->description
4153 if (isModEnabled(
'multicurrency')) {
4154 $outarraypush[
'multicurrency_code'] = $objp->multicurrency_code;
4155 $outarraypush[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4157 array_push($outarray, $outarraypush);
4170 $out .=
'</select>';
4172 $this->db->free($result);
4174 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
4180 if (empty($outputmode)) {
4199 global $langs,
$conf;
4201 $langs->load(
'stocks');
4203 $sql =
"SELECT p.rowid, p.ref, p.label, p.price, p.duration, pfp.fk_soc,";
4204 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.remise_percent, pfp.quantity, pfp.unitprice,";
4205 $sql .=
" pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name";
4206 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
4207 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
4208 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
4209 $sql .=
" WHERE pfp.entity IN (" .
getEntity(
'productsupplierprice') .
")";
4210 $sql .=
" AND p.tobuy = 1";
4211 $sql .=
" AND s.fournisseur = 1";
4212 $sql .=
" AND p.rowid = " . ((int) $productid);
4214 $sql .=
" ORDER BY s.nom, pfp.ref_fourn DESC";
4216 $sql .=
" ORDER BY pfp.unitprice ASC";
4219 dol_syslog(get_class($this) .
"::select_product_fourn_price", LOG_DEBUG);
4220 $result = $this->db->query($sql);
4223 $num = $this->db->num_rows($result);
4225 $form =
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
4228 $form .=
'<option value="0">-- ' . $langs->trans(
"NoSupplierPriceDefinedForThisProduct") .
' --</option>';
4230 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4231 $form .=
'<option value="0"> </option>';
4235 $objp = $this->db->fetch_object($result);
4237 $opt =
'<option value="' . $objp->idprodfournprice .
'"';
4239 if ($num == 1 || ($selected_supplier > 0 && $objp->fk_soc == $selected_supplier) || ($i == 0 &&
getDolGlobalString(
'PRODUCT_BEST_SUPPLIER_PRICE_PRESELECTED'))) {
4240 $opt .=
' selected';
4242 $opt .=
'>' . $objp->name .
' - ' . $objp->ref_fourn .
' - ';
4244 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
4246 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
4247 $prod_supplier->id = $productid;
4248 $prod_supplier->fourn_qty = $objp->quantity;
4249 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
4250 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
4252 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
4254 $price_result = $priceparser->parseProductSupplier($prod_supplier);
4255 if ($price_result >= 0) {
4256 $objp->fprice = $price_result;
4257 if ($objp->quantity >= 1) {
4258 $objp->unitprice = $objp->fprice / $objp->quantity;
4262 if ($objp->quantity == 1) {
4263 $opt .=
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
4266 $opt .= $objp->quantity .
' ';
4268 if ($objp->quantity == 1) {
4269 $opt .= $langs->trans(
"Unit");
4271 $opt .= $langs->trans(
"Units");
4273 if ($objp->quantity > 1) {
4275 $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");
4277 if ($objp->duration) {
4278 $opt .=
" - " . $objp->duration;
4280 $opt .=
"</option>\n";
4287 $form .=
'</select>';
4288 $this->db->free($result);
4308 $num = count($this->cache_conditions_paiements);
4315 $sql =
"SELECT rowid, code, libelle as label, deposit_percent";
4316 $sql .=
" FROM " . $this->db->prefix() .
'c_payment_term';
4317 $sql .=
" WHERE entity IN (" .
getEntity(
'c_payment_term') .
")";
4318 $sql .=
" AND active > 0";
4319 $sql .=
" ORDER BY sortorder";
4321 $resql = $this->db->query($sql);
4323 $num = $this->db->num_rows($resql);
4326 $obj = $this->db->fetch_object($resql);
4329 $label = ($langs->trans(
"PaymentConditionShort" . $obj->code) !=
"PaymentConditionShort" . $obj->code ? $langs->trans(
"PaymentConditionShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4330 $this->cache_conditions_paiements[$obj->rowid][
'code'] = $obj->code;
4331 $this->cache_conditions_paiements[$obj->rowid][
'label'] = $label;
4332 $this->cache_conditions_paiements[$obj->rowid][
'deposit_percent'] = $obj->deposit_percent;
4357 $num = count($this->cache_availability);
4364 $langs->load(
'propal');
4366 $sql =
"SELECT rowid, code, label, position";
4367 $sql .=
" FROM " . $this->db->prefix() .
'c_availability';
4368 $sql .=
" WHERE active > 0";
4370 $resql = $this->db->query($sql);
4372 $num = $this->db->num_rows($resql);
4375 $obj = $this->db->fetch_object($resql);
4378 $label = ($langs->trans(
"AvailabilityType" . $obj->code) !=
"AvailabilityType" . $obj->code ? $langs->trans(
"AvailabilityType" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4379 $this->cache_availability[$obj->rowid][
'code'] = $obj->code;
4380 $this->cache_availability[$obj->rowid][
'label'] = $label;
4381 $this->cache_availability[$obj->rowid][
'position'] = $obj->position;
4385 $this->cache_availability =
dol_sort_array($this->cache_availability,
'position',
'asc', 0, 0, 1);
4406 global $langs, $user;
4410 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
4412 print
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4414 print
'<option value="0"> </option>';
4416 foreach ($this->cache_availability as
$id => $arrayavailability) {
4417 if ($selected ==
$id) {
4418 print
'<option value="' .
$id .
'" selected>';
4420 print
'<option value="' .
$id .
'">';
4427 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4441 $num = count($this->cache_demand_reason);
4446 $sql =
"SELECT rowid, code, label";
4447 $sql .=
" FROM " . $this->db->prefix() .
'c_input_reason';
4448 $sql .=
" WHERE active > 0";
4450 $resql = $this->db->query($sql);
4452 $num = $this->db->num_rows($resql);
4454 $tmparray = array();
4456 $obj = $this->db->fetch_object($resql);
4459 $label = ($obj->label !=
'-' ? $obj->label :
'');
4460 if ($langs->trans(
"DemandReasonType" . $obj->code) !=
"DemandReasonType" . $obj->code) {
4461 $label = $langs->trans(
"DemandReasonType" . $obj->code);
4463 if ($langs->trans($obj->code) != $obj->code) {
4464 $label = $langs->trans($obj->code);
4467 $tmparray[$obj->rowid][
'id'] = $obj->rowid;
4468 $tmparray[$obj->rowid][
'code'] = $obj->code;
4469 $tmparray[$obj->rowid][
'label'] = $label;
4473 $this->cache_demand_reason =
dol_sort_array($tmparray,
'label',
'asc', 0, 0, 1);
4495 public function selectInputReason($selected =
'', $htmlname =
'demandreasonid', $exclude =
'', $addempty = 0, $morecss =
'', $notooltip = 0)
4497 global $langs, $user;
4501 print
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
4503 print
'<option value="0"' . (empty($selected) ?
' selected' :
'') .
'> </option>';
4505 foreach ($this->cache_demand_reason as
$id => $arraydemandreason) {
4506 if ($arraydemandreason[
'code'] == $exclude) {
4510 if ($selected && ($selected == $arraydemandreason[
'id'] || $selected == $arraydemandreason[
'code'])) {
4511 print
'<option value="' . $arraydemandreason[
'id'] .
'" selected>';
4513 print
'<option value="' . $arraydemandreason[
'id'] .
'">';
4515 $label = $arraydemandreason[
'label'];
4516 print $langs->trans($label);
4520 if ($user->admin && empty($notooltip)) {
4521 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4538 $num = count($this->cache_types_paiements);
4545 $this->cache_types_paiements = array();
4547 $sql =
"SELECT id, code, libelle as label, type, active";
4548 $sql .=
" FROM " . $this->db->prefix() .
"c_paiement";
4549 $sql .=
" WHERE entity IN (" .
getEntity(
'c_paiement') .
")";
4551 $resql = $this->db->query($sql);
4553 $num = $this->db->num_rows($resql);
4556 $obj = $this->db->fetch_object($resql);
4559 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) !=
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4560 $this->cache_types_paiements[$obj->id][
'id'] = $obj->id;
4561 $this->cache_types_paiements[$obj->id][
'code'] = $obj->code;
4562 $this->cache_types_paiements[$obj->id][
'label'] = $label;
4563 $this->cache_types_paiements[$obj->id][
'type'] = $obj->type;
4564 $this->cache_types_paiements[$obj->id][
'active'] = $obj->active;
4568 $this->cache_types_paiements =
dol_sort_array($this->cache_types_paiements,
'label',
'asc', 0, 0, 1);
4598 public function select_conditions_paiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1, $noprint = 0)
4602 if (empty($noprint)) {
4626 public function getSelectConditionsPaiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1)
4628 global $langs, $user,
$conf;
4631 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
4637 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TERM_ID", LOG_NOTICE);
4641 $out .=
'<select id="' . $htmlname .
'" class="flat selectpaymentterms' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4643 $out .=
'<option value="0"> </option>';
4646 $selectedDepositPercent =
null;
4648 foreach ($this->cache_conditions_paiements as
$id => $arrayconditions) {
4649 if ($filtertype <= 0 && !empty($arrayconditions[
'deposit_percent'])) {
4653 if ($selected ==
$id) {
4654 $selectedDepositPercent = $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'];
4655 $out .=
'<option value="' .
$id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'" selected>';
4657 $out .=
'<option value="' .
$id .
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'">';
4659 $label = $arrayconditions[
'label'];
4661 if (!empty($arrayconditions[
'deposit_percent'])) {
4662 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'], $label);
4666 $out .=
'</option>';
4668 $out .=
'</select>';
4669 if ($user->admin && empty($noinfoadmin)) {
4670 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4674 if ($deposit_percent >= 0) {
4675 $out .=
' <span id="' . $htmlname .
'_deposit_percent_container"' . (empty($selectedDepositPercent) ?
' style="display: none"' :
'') .
'>';
4676 $out .= $langs->trans(
'DepositPercent') .
' : ';
4677 $out .=
'<input id="' . $htmlname .
'_deposit_percent" name="' . $htmlname .
'_deposit_percent" class="maxwidth50" value="' . $deposit_percent .
'" />';
4680 <script nonce="' .
getNonce() .
'">
4681 $(document).ready(function () {
4682 $("#' . $htmlname .
'").change(function () {
4683 let $selected = $(this).find("option:selected");
4684 let depositPercent = $selected.attr("data-deposit_percent");
4686 if (depositPercent.length > 0) {
4687 $("#' . $htmlname .
'_deposit_percent_container").show().find("#' . $htmlname .
'_deposit_percent").val(depositPercent);
4689 $("#' . $htmlname .
'_deposit_percent_container").hide();
4720 public function select_types_paiements($selected =
'', $htmlname =
'paiementtype', $filtertype =
'', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'', $nooutput = 0)
4723 global $langs, $user,
$conf;
4727 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $filtertype .
", " . $format, LOG_DEBUG);
4729 $filterarray = array();
4730 if ($filtertype ==
'CRDT') {
4731 $filterarray = array(0, 2, 3);
4732 } elseif ($filtertype ==
'DBIT') {
4733 $filterarray = array(1, 2, 3);
4734 } elseif ($filtertype !=
'' && $filtertype !=
'-1') {
4735 $filterarray = explode(
',', $filtertype);
4742 dol_syslog(__METHOD__ .
"Using deprecated option MAIN_DEFAULT_PAYMENT_TYPE_ID", LOG_NOTICE);
4746 $out .=
'<select id="select' . $htmlname .
'" class="flat selectpaymenttypes' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4748 $out .=
'<option value=""> </option>';
4750 foreach ($this->cache_types_paiements as
$id => $arraytypes) {
4752 if ($active >= 0 && $arraytypes[
'active'] != $active) {
4757 if (count($filterarray) && !in_array($arraytypes[
'type'], $filterarray)) {
4762 if ($empty && empty($arraytypes[
'code'])) {
4767 $out .=
'<option value="' .
$id .
'" data-code="'.$arraytypes[
'code'].
'"';
4768 } elseif ($format == 1) {
4769 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
4770 } elseif ($format == 2) {
4771 $out .=
'<option value="' . $arraytypes[
'code'] .
'"';
4772 } elseif ($format == 3) {
4773 $out .=
'<option value="' .
$id .
'"';
4776 if ($format == 1 || $format == 2) {
4777 if ($selected == $arraytypes[
'code']) {
4778 $out .=
' selected';
4781 if ($selected ==
$id) {
4782 $out .=
' selected';
4788 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4789 } elseif ($format == 1) {
4790 $value = $arraytypes[
'code'];
4791 } elseif ($format == 2) {
4792 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4793 } elseif ($format == 3) {
4794 $value = $arraytypes[
'code'];
4796 $out .= $value ? $value :
' ';
4797 $out .=
'</option>';
4799 $out .=
'</select>';
4800 if ($user->admin && !$noadmininfo) {
4801 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4805 if (empty($nooutput)) {
4825 $return =
'<select class="flat maxwidth100" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
4827 'HT' => $langs->trans(
"HT"),
4828 'TTC' => $langs->trans(
"TTC")
4830 foreach ($options as
$id => $value) {
4831 if ($selected ==
$id) {
4832 $return .=
'<option value="' .
$id .
'" selected>' . $value;
4834 $return .=
'<option value="' .
$id .
'">' . $value;
4836 $return .=
'</option>';
4838 $return .=
'</select>';
4858 $num = count($this->cache_transport_mode);
4865 $this->cache_transport_mode = array();
4867 $sql =
"SELECT rowid, code, label, active";
4868 $sql .=
" FROM " . $this->db->prefix() .
"c_transport_mode";
4869 $sql .=
" WHERE entity IN (" .
getEntity(
'c_transport_mode') .
")";
4871 $resql = $this->db->query($sql);
4873 $num = $this->db->num_rows($resql);
4876 $obj = $this->db->fetch_object($resql);
4879 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) !=
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4880 $this->cache_transport_mode[$obj->rowid][
'rowid'] = $obj->rowid;
4881 $this->cache_transport_mode[$obj->rowid][
'code'] = $obj->code;
4882 $this->cache_transport_mode[$obj->rowid][
'label'] = $label;
4883 $this->cache_transport_mode[$obj->rowid][
'active'] = $obj->active;
4887 $this->cache_transport_mode =
dol_sort_array($this->cache_transport_mode,
'label',
'asc', 0, 0, 1);
4909 public function selectTransportMode($selected =
'', $htmlname =
'transportmode', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'')
4911 global $langs, $user;
4913 dol_syslog(__METHOD__ .
" " . $selected .
", " . $htmlname .
", " . $format, LOG_DEBUG);
4917 print
'<select id="select' . $htmlname .
'" class="flat selectmodetransport' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
4919 print
'<option value=""> </option>';
4921 foreach ($this->cache_transport_mode as
$id => $arraytypes) {
4923 if ($active >= 0 && $arraytypes[
'active'] != $active) {
4928 if ($empty && empty($arraytypes[
'code'])) {
4933 print
'<option value="' .
$id .
'"';
4934 } elseif ($format == 1) {
4935 print
'<option value="' . $arraytypes[
'code'] .
'"';
4936 } elseif ($format == 2) {
4937 print
'<option value="' . $arraytypes[
'code'] .
'"';
4938 } elseif ($format == 3) {
4939 print
'<option value="' .
$id .
'"';
4942 if (preg_match(
'/[a-z]/i', $selected) && $selected == $arraytypes[
'code']) {
4944 } elseif ($selected ==
$id) {
4950 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4951 } elseif ($format == 1) {
4952 $value = $arraytypes[
'code'];
4953 } elseif ($format == 2) {
4954 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4955 } elseif ($format == 3) {
4956 $value = $arraytypes[
'code'];
4958 print $value ? $value :
' ';
4965 if ($user->admin && !$noadmininfo) {
4966 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4982 public function selectShippingMethod($selected =
'', $htmlname =
'shipping_method_id', $filtre =
'', $useempty = 0, $moreattrib =
'', $noinfoadmin = 0, $morecss =
'')
4984 global $langs, $user;
4986 $langs->load(
"admin");
4987 $langs->load(
"deliveries");
4989 $sql =
"SELECT rowid, code, libelle as label";
4990 $sql .=
" FROM " . $this->db->prefix() .
"c_shipment_mode";
4991 $sql .=
" WHERE active > 0";
4993 $sql .=
" AND " . $filtre;
4995 $sql .=
" ORDER BY libelle ASC";
4997 dol_syslog(get_class($this) .
"::selectShippingMode", LOG_DEBUG);
4998 $result = $this->db->query($sql);
5000 $num = $this->db->num_rows($result);
5003 print
'<select id="select' . $htmlname .
'" class="flat selectshippingmethod' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5004 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5005 print
'<option value="-1"> </option>';
5008 $obj = $this->db->fetch_object($result);
5009 if ($selected == $obj->rowid) {
5010 print
'<option value="' . $obj->rowid .
'" selected>';
5012 print
'<option value="' . $obj->rowid .
'">';
5014 print ($langs->trans(
"SendingMethod" . strtoupper($obj->code)) !=
"SendingMethod" . strtoupper($obj->code)) ? $langs->trans(
"SendingMethod" . strtoupper($obj->code)) : $obj->label;
5019 if ($user->admin && empty($noinfoadmin)) {
5020 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5025 print $langs->trans(
"NoShippingMethodDefined");
5045 $langs->load(
"deliveries");
5047 if ($htmlname !=
"none") {
5048 print
'<form method="POST" action="' . $page .
'">';
5049 print
'<input type="hidden" name="action" value="setshippingmethod">';
5050 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5052 print
'<input type="submit" class="button valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5056 $code = $langs->getLabelFromKey($this->db, $selected,
'c_shipment_mode',
'rowid',
'code');
5057 print $langs->trans(
"SendingMethod" . strtoupper($code));
5076 $langs->load(
'bills');
5078 $opt =
'<option value="" selected></option>';
5079 $sql =
"SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc";
5080 $sql .=
' FROM ' . $this->db->prefix() .
'facture';
5081 $sql .=
' WHERE entity IN (' .
getEntity(
'invoice') .
')';
5082 $sql .=
' AND situation_counter >= 1';
5083 $sql .=
' AND fk_soc = ' . (int) $socid;
5084 $sql .=
' AND type <> 2';
5085 $sql .=
' ORDER by situation_cycle_ref, situation_counter desc';
5086 $resql = $this->db->query($sql);
5088 if ($resql && $this->db->num_rows($resql) > 0) {
5091 while ($obj = $this->db->fetch_object($resql)) {
5093 if ($obj->situation_cycle_ref != $ref) {
5095 $ref = $obj->situation_cycle_ref;
5097 if ($obj->situation_final != 1) {
5099 if (substr($obj->ref, 1, 4) !=
'PROV') {
5100 if ($selected == $obj->rowid) {
5101 $opt .=
'<option value="' . $obj->rowid .
'" selected>' . $obj->ref .
'</option>';
5103 $opt .=
'<option value="' . $obj->rowid .
'">' . $obj->ref .
'</option>';
5110 dol_syslog(
"Error sql=" . $sql .
", error=" . $this->error, LOG_ERR);
5112 if ($opt ==
'<option value ="" selected></option>') {
5113 $opt =
'<option value ="0" selected>' . $langs->trans(
'NoSituations') .
'</option>';
5127 public function selectUnits($selected =
'', $htmlname =
'units', $showempty = 0, $unit_type =
'')
5131 $langs->load(
'products');
5133 $return =
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'">';
5135 $sql =
"SELECT rowid, label, code FROM " . $this->db->prefix() .
"c_units";
5136 $sql .=
' WHERE active > 0';
5137 if (!empty($unit_type)) {
5138 $sql .=
" AND unit_type = '" . $this->db->escape($unit_type) .
"'";
5140 $sql .=
" ORDER BY sortorder";
5142 $resql = $this->db->query($sql);
5143 if ($resql && $this->db->num_rows($resql) > 0) {
5145 $return .=
'<option value="-1"></option>';
5148 while ($res = $this->db->fetch_object($resql)) {
5149 $unitLabel = $res->label;
5150 if (!empty($langs->tab_translate[
'unit' . $res->code])) {
5151 $unitLabel = $langs->trans(
'unit' . $res->code) != $res->label ? $langs->trans(
'unit' . $res->code) : $res->label;
5154 if ($selected == $res->rowid) {
5155 $return .=
'<option value="' . $res->rowid .
'" selected>' . $unitLabel .
'</option>';
5157 $return .=
'<option value="' . $res->rowid .
'">' . $unitLabel .
'</option>';
5160 $return .=
'</select>';
5183 public function select_comptes($selected =
'', $htmlname =
'accountid', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'', $showcurrency = 0, $morecss =
'', $nooutput = 0)
5190 $langs->loadLangs(array(
"admin",
"banks"));
5193 $sql =
"SELECT rowid, label, bank, clos as status, currency_code";
5194 $sql .=
" FROM " . $this->db->prefix() .
"bank_account";
5195 $sql .=
" WHERE entity IN (" .
getEntity(
'bank_account') .
")";
5197 $sql .=
" AND clos = " . (int) $status;
5200 $sql .=
" AND " . $filtre;
5202 $sql .=
" ORDER BY label";
5204 dol_syslog(get_class($this) .
"::select_comptes", LOG_DEBUG);
5205 $result = $this->db->query($sql);
5207 $num = $this->db->num_rows($result);
5210 $out .=
'<select id="select' . $htmlname .
'" class="flat selectbankaccount' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5214 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoActiveBankAccountDefined") .
'</span>';
5216 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoBankAccountDefined") .
'</span>';
5219 if (!empty($useempty) && !is_numeric($useempty)) {
5220 $out .=
'<option value="-1">'.$langs->trans($useempty).
'</option>';
5221 } elseif ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5222 $out .=
'<option value="-1"> </option>';
5227 $obj = $this->db->fetch_object($result);
5229 $labeltoshow = trim($obj->label);
5230 $labeltoshowhtml = trim($obj->label);
5231 if ($showcurrency) {
5232 $labeltoshow .=
' (' . $obj->currency_code .
')';
5233 $labeltoshowhtml .=
' <span class="opacitymedium">(' . $obj->currency_code .
')</span>';
5235 if ($status == 2 && $obj->status == 1) {
5236 $labeltoshow .=
' (' . $langs->trans(
"Closed") .
')';
5237 $labeltoshowhtml .=
' <span class="opacitymedium">(' . $langs->trans(
"Closed") .
')</span>';
5240 if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
5241 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml).
'" selected>';
5243 $out .=
'<option value="' . $obj->rowid .
'" data-currency-code="' . $obj->currency_code .
'" data-html="'.dolPrintHTMLForAttribute($labeltoshowhtml).
'">';
5245 $out .= $labeltoshow;
5246 $out .=
'</option>';
5249 $out .=
"</select>";
5256 if (empty($nooutput)) {
5278 public function selectRib($selected =
'', $htmlname =
'ribcompanyid', $filtre =
'', $useempty = 0, $moreattrib =
'', $showibanbic = 0, $morecss =
'', $nooutput = 0)
5285 $langs->loadLangs(array(
"admin",
"banks"));
5288 $sql =
"SELECT rowid, label, bank, status, iban_prefix, bic";
5289 $sql .=
" FROM " . $this->db->prefix() .
"societe_rib";
5290 $sql .=
" WHERE type = 'ban'";
5292 $sql .=
" AND " . $filtre;
5294 $sql .=
" ORDER BY label";
5295 dol_syslog(get_class($this) .
"::select_comptes", LOG_DEBUG);
5296 $result = $this->db->query($sql);
5298 $num = $this->db->num_rows($result);
5301 $out .=
'<select id="select' . $htmlname .
'" class="flat selectbankaccount' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5304 $out .=
'<option class="opacitymedium" value="-1">' . $langs->trans(
"NoBankAccountDefined") .
'</span>';
5306 if (!empty($useempty) && !is_numeric($useempty)) {
5307 $out .=
'<option value="-1">'.$langs->trans($useempty).
'</option>';
5308 } elseif ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5309 $out .=
'<option value="-1"> </option>';
5314 $obj = $this->db->fetch_object($result);
5316 if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
5317 $out .=
'<option value="' . $obj->rowid .
'" data-iban-prefix="' . $iban .
' data-bic="' . $obj->bic .
'" selected>';
5319 $out .=
'<option value="' . $obj->rowid .
'" data-iban-prefix="' . $iban .
' data-bic="' . $obj->bic .
'">';
5321 $out .= trim($obj->label);
5323 $out .=
' (' . $iban .
'/' .$obj->bic.
')';
5325 $out .=
'</option>';
5328 $out .=
"</select>";
5335 if (empty($nooutput)) {
5355 public function selectEstablishments($selected =
'', $htmlname =
'entity', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'')
5359 $langs->load(
"admin");
5362 $sql =
"SELECT rowid, name, fk_country, status, entity";
5363 $sql .=
" FROM " . $this->db->prefix() .
"establishment";
5364 $sql .=
" WHERE 1=1";
5366 $sql .=
" AND status = " . (int) $status;
5369 $sql .=
" AND " . $filtre;
5371 $sql .=
" ORDER BY name";
5373 dol_syslog(get_class($this) .
"::select_establishment", LOG_DEBUG);
5374 $result = $this->db->query($sql);
5376 $num = $this->db->num_rows($result);
5379 print
'<select id="select' . $htmlname .
'" class="flat selectestablishment" name="' . $htmlname .
'"' . ($moreattrib ?
' ' . $moreattrib :
'') .
'>';
5380 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5381 print
'<option value="-1"> </option>';
5385 $obj = $this->db->fetch_object($result);
5386 if ($selected == $obj->rowid) {
5387 print
'<option value="' . $obj->rowid .
'" selected>';
5389 print
'<option value="' . $obj->rowid .
'">';
5391 print trim($obj->name);
5392 if ($status == 2 && $obj->status == 1) {
5393 print
' (' . $langs->trans(
"Closed") .
')';
5401 print
'<span class="opacitymedium">' . $langs->trans(
"NoActiveEstablishmentDefined") .
'</span>';
5403 print
'<span class="opacitymedium">' . $langs->trans(
"NoEstablishmentFound") .
'</span>';
5426 if ($htmlname !=
"none") {
5427 print
'<form method="POST" action="' . $page .
'">';
5428 print
'<input type="hidden" name="action" value="setbankaccount">';
5429 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5430 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
5431 $nbaccountfound = $this->
select_comptes($selected, $htmlname, 0,
'', $addempty);
5432 if ($nbaccountfound > 0) {
5433 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5437 $langs->load(
'banks');
5440 require_once DOL_DOCUMENT_ROOT .
'/compta/bank/class/account.class.php';
5441 $bankstatic =
new Account($this->db);
5442 $result = $bankstatic->fetch($selected);
5444 print $bankstatic->getNomUrl(1);
5463 public function formRib($page, $selected =
'', $htmlname =
'ribcompanyid', $filtre =
'', $addempty = 0, $showibanbic = 0)
5466 if ($htmlname !=
"none") {
5467 print
'<form method="POST" action="' . $page .
'">';
5468 print
'<input type="hidden" name="action" value="setbankaccountcustomer">';
5469 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5470 $nbaccountfound = $this->
selectRib($selected, $htmlname, $filtre, $addempty,
'', $showibanbic);
5471 if ($nbaccountfound > 0) {
5472 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
5476 $langs->load(
'banks');
5479 require_once DOL_DOCUMENT_ROOT .
'/societe/class/companybankaccount.class.php';
5481 $result = $bankstatic->fetch($selected);
5483 print $bankstatic->label;
5485 print
' (' . $bankstatic->iban .
'/' .$bankstatic->bic.
')';
5515 public function select_all_categories($type, $selected =
'', $htmlname =
"parent", $maxlength = 64, $fromid = 0, $outputmode = 0, $include = 0, $morecss =
'', $useempty = 1)
5518 global
$conf, $langs;
5519 $langs->load(
"categories");
5521 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
5524 if (is_numeric($type)) {
5525 dol_syslog(__METHOD__ .
': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING);
5528 if ($type === Categorie::TYPE_BANK_LINE) {
5531 $cate_arbo = array();
5532 $sql =
"SELECT c.label, c.rowid";
5533 $sql .=
" FROM " . $this->db->prefix() .
"categorie as c";
5534 $sql .=
" WHERE entity = " .
$conf->entity .
" AND type = " . ((int) $cat->getMapId()[$type]);
5535 $sql .=
" ORDER BY c.label";
5536 $result = $this->db->query($sql);
5538 $num = $this->db->num_rows($result);
5541 $objp = $this->db->fetch_object($result);
5543 $cate_arbo[$objp->rowid] = array(
'id' => $objp->rowid,
'fulllabel' => $objp->label,
'color' =>
'',
'picto' =>
'category');
5547 $this->db->free($result);
5553 $cate_arbo = $cat->get_full_arbo($type, $fromid, $include);
5556 $outarray = array();
5557 $outarrayrichhtml = array();
5560 $output =
'<select class="flat minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
5561 if (is_array($cate_arbo)) {
5562 $num = count($cate_arbo);
5565 $output .=
'<option value="-1" disabled>' . $langs->trans(
"NoCategoriesDefined") .
'</option>';
5567 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
5568 $output .=
'<option value="-1"> </option>';
5570 foreach ($cate_arbo as $key => $value) {
5571 if ($cate_arbo[$key][
'id'] == $selected || ($selected ===
'auto' && count($cate_arbo) == 1)) {
5577 $labeltoshow =
img_picto(
'',
'category',
'class="pictofixedwidth" style="color: #' . $cate_arbo[$key][
'color'] .
'"');
5578 $labeltoshow .=
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle');
5580 $outarray[$cate_arbo[$key][
'id']] = $cate_arbo[$key][
'fulllabel'];
5582 $outarrayrichhtml[$cate_arbo[$key][
'id']] = $labeltoshow;
5584 $output .=
'<option ' . $add .
'value="' . $cate_arbo[$key][
'id'] .
'"';
5587 $output .=
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle');
5588 $output .=
'</option>';
5590 $cate_arbo[$key][
'data-html'] = $labeltoshow;
5594 $output .=
'</select>';
5597 if ($outputmode == 2) {
5600 } elseif ($outputmode == 1) {
5602 } elseif ($outputmode == 3) {
5603 return $outarrayrichhtml;
5628 public function form_confirm($page, $title, $question, $action, $formquestion = array(), $selectedchoice =
"", $useajax = 0, $height = 170, $width = 500)
5631 dol_syslog(__METHOD__ .
': using form_confirm is deprecated. Use formconfim instead.', LOG_WARNING);
5632 print $this->
formconfirm($page, $title, $question, $action, $formquestion, $selectedchoice, $useajax, $height, $width);
5662 public function formconfirm($page, $title, $question, $action, $formquestion =
'', $selectedchoice =
'', $useajax = 0, $height = 0, $width = 500, $disableformtag = 0, $labelbuttonyes =
'Yes', $labelbuttonno =
'No')
5664 global $langs,
$conf;
5666 $more =
'<!-- formconfirm - before call, page=' .
dol_escape_htmltag($page) .
' -->';
5672 $newselectedchoice = empty($selectedchoice) ?
"no" : $selectedchoice;
5673 if (
$conf->browser->layout ==
'phone') {
5678 if (empty($height)) {
5680 if (is_array($formquestion) && count($formquestion) > 2) {
5681 $height += ((count($formquestion) - 2) * 24);
5685 if (is_array($formquestion) && !empty($formquestion)) {
5687 foreach ($formquestion as $key => $input) {
5688 if (is_array($input) && !empty($input)) {
5689 if ($input[
'type'] ==
'hidden') {
5690 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
5691 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
5699 $moreonecolumn =
'';
5700 $more .=
'<div class="tagtable paddingtopbottomonly centpercent noborderspacing">' .
"\n";
5701 foreach ($formquestion as $key => $input) {
5702 if (is_array($input) && !empty($input)) {
5703 $size = (!empty($input[
'size']) ?
' size="' . $input[
'size'] .
'"' :
'');
5704 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
5705 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
5707 if ($input[
'type'] ==
'text') {
5708 $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";
5709 } elseif ($input[
'type'] ==
'password') {
5710 $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";
5711 } elseif ($input[
'type'] ==
'textarea') {
5717 $moreonecolumn .=
'<div class="margintoponly">';
5718 $moreonecolumn .= $input[
'label'] .
'<br>';
5720 $moreonecolumn .= $input[
'value'];
5721 $moreonecolumn .=
'</textarea>';
5722 $moreonecolumn .=
'</div>';
5723 } elseif (in_array($input[
'type'], [
'select',
'multiselect'])) {
5724 if (empty($morecss)) {
5725 $morecss =
'minwidth100';
5728 $show_empty = isset($input[
'select_show_empty']) ? $input[
'select_show_empty'] : 1;
5729 $key_in_label = isset($input[
'select_key_in_label']) ? $input[
'select_key_in_label'] : 0;
5730 $value_as_key = isset($input[
'select_value_as_key']) ? $input[
'select_value_as_key'] : 0;
5731 $translate = isset($input[
'select_translate']) ? $input[
'select_translate'] : 0;
5732 $maxlen = isset($input[
'select_maxlen']) ? $input[
'select_maxlen'] : 0;
5733 $disabled = isset($input[
'select_disabled']) ? $input[
'select_disabled'] : 0;
5734 $sort = isset($input[
'select_sort']) ? $input[
'select_sort'] :
'';
5736 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">';
5737 if (!empty($input[
'label'])) {
5738 $more .= $input[
'label'] .
'</div><div class="tagtd left">';
5740 if ($input[
'type'] ==
'select') {
5741 $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);
5743 $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);
5745 $more .=
'</div></div>' .
"\n";
5746 } elseif ($input[
'type'] ==
'checkbox') {
5747 $more .=
'<div class="tagtr">';
5748 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'"><label for="' .
dol_escape_htmltag($input[
'name']) .
'">' . $input[
'label'] .
'</label></div><div class="tagtd">';
5749 $more .=
'<input type="checkbox" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' .
dol_escape_htmltag($input[
'name']) .
'" name="' .
dol_escape_htmltag($input[
'name']) .
'"' . $moreattr;
5750 if (!is_bool($input[
'value']) && $input[
'value'] !=
'false' && $input[
'value'] !=
'0' && $input[
'value'] !=
'') {
5751 $more .=
' checked';
5753 if (is_bool($input[
'value']) && $input[
'value']) {
5754 $more .=
' checked';
5756 if (isset($input[
'disabled'])) {
5757 $more .=
' disabled';
5759 $more .=
' /></div>';
5760 $more .=
'</div>' .
"\n";
5761 } elseif ($input[
'type'] ==
'radio') {
5763 foreach ($input[
'values'] as $selkey => $selval) {
5764 $more .=
'<div class="tagtr">';
5765 if (isset($input[
'label'])) {
5767 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
' tdtop' : (
' tdtop ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
5769 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' "' . $input[
'tdclass'])) .
'"> </div>';
5772 $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;
5773 if (!empty($input[
'disabled'])) {
5774 $more .=
' disabled';
5776 if (isset($input[
'default']) && $input[
'default'] === $selkey) {
5777 $more .=
' checked="checked"';
5780 $more .=
'<label for="' .
dol_escape_htmltag($input[
'name'] . $selkey) .
'" class="valignmiddle">' . $selval .
'</label>';
5781 $more .=
'</div></div>' .
"\n";
5784 } elseif ($input[
'type'] ==
'date' || $input[
'type'] ==
'datetime') {
5785 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
5786 $more .=
'<div class="tagtd">';
5787 $addnowlink = (empty($input[
'datenow']) ? 0 : 1);
5789 if ($input[
'type'] ==
'datetime') {
5790 $h = isset($input[
'hours']) ? $input[
'hours'] : 1;
5791 $m = isset($input[
'minutes']) ? $input[
'minutes'] : 1;
5793 $more .= $this->
selectDate(isset($input[
'value']) ? $input[
'value'] : -1, $input[
'name'], $h, $m, 0,
'', 1, $addnowlink);
5794 $more .=
'</div></div>'.
"\n";
5795 $formquestion[] = array(
'name' => $input[
'name'].
'day');
5796 $formquestion[] = array(
'name' => $input[
'name'].
'month');
5797 $formquestion[] = array(
'name' => $input[
'name'].
'year');
5798 $formquestion[] = array(
'name' => $input[
'name'].
'hour');
5799 $formquestion[] = array(
'name' => $input[
'name'].
'min');
5800 } elseif ($input[
'type'] ==
'other') {
5801 $more .=
'<div class="tagtr"><div class="tagtd'.(empty($input[
'tdclass']) ?
'' : (
' '.$input[
'tdclass'])).
'">';
5802 if (!empty($input[
'label'])) {
5803 $more .= $input[
'label'] .
'</div><div class="tagtd">';
5805 $more .= $input[
'value'];
5806 $more .=
'</div></div>' .
"\n";
5807 } elseif ($input[
'type'] ==
'onecolumn') {
5808 $moreonecolumn .=
'<div class="margintoponly">';
5809 $moreonecolumn .= $input[
'value'];
5810 $moreonecolumn .=
'</div>' .
"\n";
5811 } elseif ($input[
'type'] ==
'hidden') {
5813 } elseif ($input[
'type'] ==
'separator') {
5816 $more .=
'Error type ' . $input[
'type'] .
' for the confirm box is not a supported type';
5820 $more .=
'</div>' .
"\n";
5821 $more .= $moreonecolumn;
5827 if (!empty(
$conf->dol_use_jmobile)) {
5830 if (empty(
$conf->use_javascript_ajax)) {
5836 $dialogconfirm =
'dialog-confirm';
5838 if (!is_numeric($useajax)) {
5842 $dialogconfirm .=
'-' . $button;
5844 $pageyes = $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=yes';
5845 $pageno = ($useajax == 2 ? $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=no' :
'');
5848 if (is_array($formquestion)) {
5849 foreach ($formquestion as $key => $input) {
5852 if (is_array($input) && isset($input[
'name'])) {
5853 if (strpos($input[
'name'],
',') > 0) {
5854 $inputok = array_merge($inputok, explode(
',', $input[
'name']));
5856 array_push($inputok, $input[
'name']);
5861 if (is_array($input) && isset($input[
'inputko']) && $input[
'inputko'] == 1 && isset($input[
'name'])) {
5862 array_push($inputko, $input[
'name']);
5868 $formconfirm .=
'<div id="' . $dialogconfirm .
'" title="' .
dol_escape_htmltag($title) .
'" style="display: none;">';
5869 if (is_array($formquestion) && array_key_exists(
'text', $formquestion) && !empty($formquestion[
'text'])) {
5870 $formconfirm .=
'<div class="confirmtext">' . $formquestion[
'text'] .
'</div>' .
"\n";
5872 if (!empty($more)) {
5873 $formconfirm .=
'<div class="confirmquestions">' . $more .
'</div>' .
"\n";
5875 $formconfirm .= ($question ?
'<div class="confirmmessage">' .
img_help(0,
'') .
' ' . $question .
'</div>' :
'');
5876 $formconfirm .=
'</div>' .
"\n";
5878 $formconfirm .=
"\n<!-- begin code of popup for formconfirm page=" . $page .
" -->\n";
5879 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
5880 $formconfirm .=
"/* Code for the jQuery('#dialogforpopup').dialog() */\n";
5881 $formconfirm .=
'jQuery(document).ready(function() {
5883 $( "#' . $dialogconfirm .
'" ).dialog(
5885 autoOpen: ' . ($autoOpen ?
"true" :
"false") .
',';
5886 if ($newselectedchoice ==
'no') {
5889 $(this).parent().find("button.ui-button:eq(2)").focus();
5894 if ($useajax == 1) {
5895 $jsforcursor =
'// The call to urljump can be slow, so we set the wait cursor' .
"\n";
5896 $jsforcursor .=
'jQuery("html,body,#id-container").addClass("cursorwait");' .
"\n";
5899 $postconfirmas =
'GET';
5906 closeOnEscape:
false,
5908 "' . dol_escape_js($langs->transnoentities($labelbuttonyes)) . '":
function() {
5909 var options =
"token=' . urlencode(newToken()) . '";
5910 var inputok =
' . json_encode($inputok) . ';
5911 var page = \
'' .
dol_escape_js(!empty($page) ? $page :
'') .
'\';
5912 var pageyes = \
'' .
dol_escape_js(!empty($pageyes) ? $pageyes :
'') .
'\';
5914 if (inputok.length > 0) {
5915 $.each(inputok,
function(i, inputname) {
5918 if ($(
"input[name=\'" + inputname +
"\']").attr(
"type") ==
"radio") {
5919 inputvalue = $(
"input[name=\'" + inputname +
"\']:checked").val();
5921 if ($(
"#" + inputname).attr(
"type") ==
"checkbox") { more =
":checked"; }
5922 inputvalue = $(
"#" + inputname + more).val();
5924 if (typeof inputvalue ==
"undefined") { inputvalue=
""; }
5925 console.log(
"formconfirm check inputname="+inputname+
" inputvalue="+inputvalue);
5926 options +=
"&" + inputname +
"=" + encodeURIComponent(inputvalue);
5929 var urljump = pageyes + (pageyes.indexOf(
"?") < 0 ?
"?" :
"&") + options;
5930 if (pageyes.length > 0) {
';
5931 if ($postconfirmas == 'GET
') {
5932 $formconfirm .= 'location.href = urljump;
';
5934 $formconfirm .= $jsforcursor;
5935 $formconfirm .= 'var post = $.post(
5938 function(data) { $(
"body").html(data); jQuery(
"html,body,#id-container").removeClass(
"cursorwait"); }
5942 console.log(
"after post ok");
5944 $(
this).dialog(
"close");
5946 "' . dol_escape_js($langs->transnoentities($labelbuttonno)) . '":
function() {
5947 var options =
"token=' . urlencode(newToken()) . '";
5948 var inputko =
' . json_encode($inputko) . ';
5949 var page =
"' . dol_escape_js(!empty($page) ? $page : '') . '";
5950 var pageno=
"' . dol_escape_js(!empty($pageno) ? $pageno : '') . '";
5951 if (inputko.length > 0) {
5952 $.each(inputko,
function(i, inputname) {
5954 if ($(
"#" + inputname).attr(
"type") ==
"checkbox") { more =
":checked"; }
5955 var inputvalue = $(
"#" + inputname + more).val();
5956 if (typeof inputvalue ==
"undefined") { inputvalue=
""; }
5957 options +=
"&" + inputname +
"=" + encodeURIComponent(inputvalue);
5960 var urljump=pageno + (pageno.indexOf(
"?") < 0 ?
"?" :
"&") + options;
5962 if (pageno.length > 0) {
';
5963 if ($postconfirmas == 'GET
') {
5964 $formconfirm .= 'location.href = urljump;
';
5966 $formconfirm .= $jsforcursor;
5967 $formconfirm .= 'var post = $.post(
5970 function(data) { $(
"body").html(data); jQuery(
"html,body,#id-container").removeClass(
"cursorwait"); }
5974 console.log(
"after post ko");
5976 $(
this).dialog(
"close");
5982 var
button =
"' . $button . '";
5984 $(
"#" +
button ).click(
function() {
5985 $(
"#' . $dialogconfirm . '").dialog(
"open");
5991 $formconfirm .= "<!-- end ajax formconfirm -->\n";
5993 $formconfirm .= "\n<!-- begin formconfirm page=" . dol_escape_htmltag($page) . " -->\n";
5995 if (empty($disableformtag)) {
5996 $formconfirm .= '<form method=
"POST" action=
"' . $page . '" class=
"notoptoleftnoright">
' . "\n";
5999 $formconfirm .= '<input
type=
"hidden" name=
"action" value=
"' . $action . '">
' . "\n";
6000 $formconfirm .= '<input
type=
"hidden" name=
"token" value=
"' . newToken() . '">
' . "\n";
6002 $formconfirm .= '<
table class=
"valid centpercent">
' . "\n";
6005 $formconfirm .= '<tr
class=
"validtitre"><td
class=
"validtitre" colspan=
"2">
';
6006 $formconfirm .= img_picto('', 'pictoconfirm
') . ' ' . $title;
6007 $formconfirm .= '</td></tr>
' . "\n";
6010 if (is_array($formquestion) && array_key_exists('text
', $formquestion) && !empty($formquestion['text
'])) {
6011 $formconfirm .= '<tr
class=
"valid"><td
class=
"valid" colspan=
"2">
' . $formquestion['text
'] . '</td></tr>
' . "\n";
6016 $formconfirm .= '<tr
class=
"valid"><td
class=
"valid" colspan=
"2">
' . "\n";
6017 $formconfirm .= $more;
6018 $formconfirm .= '</td></tr>
' . "\n";
6021 // Line with question
6022 $formconfirm .= '<tr
class=
"valid">
';
6023 $formconfirm .= '<td
class=
"valid">
' . $question . '</td>
';
6024 $formconfirm .= '<td
class=
"valid center">
';
6025 $formconfirm .= $this->selectyesno("confirm", $newselectedchoice, 0, false, 0, 0, 'marginleftonly marginrightonly
', $labelbuttonyes, $labelbuttonno);
6026 $formconfirm .= '<input
class=
"button valignmiddle confirmvalidatebutton small" type=
"submit" value=
"' . $langs->trans("Validate") . '">
';
6027 $formconfirm .= '</td>
';
6028 $formconfirm .= '</tr>
' . "\n";
6030 $formconfirm .= '</
table>
' . "\n";
6032 if (empty($disableformtag)) {
6033 $formconfirm .= "</form>\n";
6035 $formconfirm .= '<br>
';
6037 if (!empty($conf->use_javascript_ajax)) {
6038 $formconfirm .= '<!-- code to disable
button to avoid
double clic -->
';
6039 $formconfirm .= '<script nonce=
"' . getNonce() . '" type=
"text/javascript">
' . "\n";
6041 $(document).ready(
function () {
6042 $(
".confirmvalidatebutton").on(
"click",
function() {
6043 console.log(
"We click on button confirmvalidatebutton");
6044 $(
this).attr(
"disabled",
"disabled");
6045 setTimeout(\
'$(".confirmvalidatebutton").removeAttr("disabled")\', 3000);
6046 //console.log($(this).closest("form"));
6047 $(this).closest("form").submit();
6051 $formconfirm .=
'</script>' .
"\n";
6054 $formconfirm .=
"<!-- end formconfirm -->\n";
6057 return $formconfirm;
6078 public function form_project($page, $socid, $selected =
'', $htmlname =
'projectid', $discard_closed = 0, $maxlength = 20, $forcefocus = 0, $nooutput = 0, $textifnoproject =
'', $morecss =
'')
6083 require_once DOL_DOCUMENT_ROOT .
'/core/lib/project.lib.php';
6084 require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formprojet.class.php';
6090 $langs->load(
"project");
6091 if ($htmlname !=
"none") {
6092 $out .=
'<form method="post" action="' . $page .
'">';
6093 $out .=
'<input type="hidden" name="action" value="classin">';
6094 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6095 $out .= $formproject->select_projects($socid, $selected, $htmlname, $maxlength, 0, 1, $discard_closed, $forcefocus, 0, 0,
'', 1, 0, $morecss);
6096 $out .=
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6099 $out .=
'<span class="project_head_block">';
6101 $projet =
new Project($this->db);
6102 $projet->fetch($selected);
6103 $out .= $projet->getNomUrl(0,
'', 1);
6105 $out .=
'<span class="opacitymedium">' . $textifnoproject .
'</span>';
6110 if (empty($nooutput)) {
6134 public function form_conditions_reglement($page, $selected =
'', $htmlname =
'cond_reglement_id', $addempty = 0, $type =
'', $filtertype = -1, $deposit_percent = -1, $nooutput = 0)
6141 if ($htmlname !=
"none") {
6142 $out .=
'<form method="POST" action="' . $page .
'">';
6143 $out .=
'<input type="hidden" name="action" value="setconditions">';
6144 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6146 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
6148 $out .= $this->getSelectConditionsPaiements($selected, $htmlname, $filtertype, $addempty, 0,
'', $deposit_percent);
6149 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6153 $this->load_cache_conditions_paiements();
6154 if (isset($this->cache_conditions_paiements[$selected])) {
6155 $label = $this->cache_conditions_paiements[$selected][
'label'];
6157 if (!empty($this->cache_conditions_paiements[$selected][
'deposit_percent'])) {
6158 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $this->cache_conditions_paiements[$selected][
'deposit_percent'], $label);
6163 $langs->load(
'errors');
6164 $out .= $langs->trans(
'ErrorNotInDictionaryPaymentConditions');
6171 if (empty($nooutput)) {
6193 if ($htmlname !=
"none") {
6194 print
'<form method="post" action="' . $page .
'">';
6195 print
'<input type="hidden" name="action" value="setavailability">';
6196 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6197 $this->selectAvailabilityDelay($selected, $htmlname,
'', $addempty);
6198 print
'<input type="submit" name="modify" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6199 print
'<input type="submit" name="cancel" class="button smallpaddingimp" value="' . $langs->trans(
"Cancel") .
'">';
6203 $this->load_cache_availability();
6204 print $this->cache_availability[$selected][
'label'];
6221 public function formInputReason($page, $selected =
'', $htmlname =
'demandreason', $addempty = 0)
6224 if ($htmlname !=
"none") {
6225 print
'<form method="post" action="' . $page .
'">';
6226 print
'<input type="hidden" name="action" value="setdemandreason">';
6227 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6228 $this->selectInputReason($selected, $htmlname,
'-1', $addempty);
6229 print
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'">';
6233 $this->loadCacheInputReason();
6234 foreach ($this->cache_demand_reason as $key => $val) {
6235 if ($val[
'id'] == $selected) {
6236 print $val[
'label'];
6261 public function form_date($page, $selected, $htmlname, $displayhour = 0, $displaymin = 0, $nooutput = 0, $type =
'')
6268 if ($htmlname !=
"none") {
6269 $ret .=
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
6270 $ret .=
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
6271 $ret .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6273 $ret .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
6275 $ret .=
'<table class="nobordernopadding">';
6277 $ret .= $this->selectDate($selected, $htmlname, $displayhour, $displaymin, 1,
'form' . $htmlname, 1, 0);
6279 $ret .=
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
6280 $ret .=
'</tr></table></form>';
6289 if (empty($nooutput)) {
6308 public function form_users($page, $selected =
'', $htmlname =
'userid', $exclude = array(), $include = array())
6313 if ($htmlname !=
"none") {
6314 print
'<form method="POST" action="' . $page .
'" name="form' . $htmlname .
'">';
6315 print
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
6316 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6317 print $this->select_dolusers($selected, $htmlname, 1, $exclude, 0, $include);
6318 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6322 require_once DOL_DOCUMENT_ROOT .
'/user/class/user.class.php';
6323 $theuser =
new User($this->db);
6324 $theuser->fetch($selected);
6325 print $theuser->getNomUrl(1);
6348 public function form_modes_reglement($page, $selected =
'', $htmlname =
'mode_reglement_id', $filtertype =
'', $active = 1, $addempty = 0, $type =
'', $nooutput = 0)
6354 if ($htmlname !=
"none") {
6355 $out .=
'<form method="POST" action="' . $page .
'">';
6356 $out .=
'<input type="hidden" name="action" value="setmode">';
6357 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6359 $out .=
'<input type="hidden" name="type" value="' .
dol_escape_htmltag($type) .
'">';
6361 $out .= $this->select_types_paiements($selected, $htmlname, $filtertype, 0, $addempty, 0, 0, $active,
'', 1);
6362 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6366 $this->load_cache_types_paiements();
6367 $out .= $this->cache_types_paiements[$selected][
'label'];
6394 if ($htmlname !=
"none") {
6395 print
'<form method="POST" action="' . $page .
'">';
6396 print
'<input type="hidden" name="action" value="settransportmode">';
6397 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6398 $this->selectTransportMode($selected, $htmlname, 0, $addempty, 0, 0, $active);
6399 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6403 $this->load_cache_transport_mode();
6404 print $this->cache_transport_mode[$selected][
'label'];
6425 if ($htmlname !=
"none") {
6426 print
'<form method="POST" action="' . $page .
'">';
6427 print
'<input type="hidden" name="action" value="setmulticurrencycode">';
6428 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6429 print $this->selectMultiCurrency($selected, $htmlname, 0);
6430 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6433 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
6434 print !empty($selected) ?
currency_name($selected, 1) :
' ';
6452 global $langs, $mysoc,
$conf;
6454 if ($htmlname !=
"none") {
6455 print
'<form method="POST" action="' . $page .
'">';
6456 print
'<input type="hidden" name="action" value="setmulticurrencyrate">';
6457 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6458 print
'<input type="text" class="maxwidth75" name="' . $htmlname .
'" value="' . (!empty($rate) ?
price(
price2num($rate,
'CU')) : 1) .
'" /> ';
6459 print
'<select name="calculation_mode" id="calculation_mode">';
6460 print
'<option value="1">Change ' . $langs->trans(
"PriceUHT") .
' of lines</option>';
6461 print
'<option value="2">Change ' . $langs->trans(
"PriceUHTCurrency") .
' of lines</option>';
6464 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6467 if (!empty($rate)) {
6468 print
price($rate, 1, $langs, 0, 0);
6469 if ($currency && $rate != 1) {
6470 print
' <span class="opacitymedium">(' .
price($rate, 1, $langs, 0, 0) .
' ' . $currency .
' = 1 ' .
$conf->currency .
')</span>';
6495 public function form_remise_dispo($page, $selected, $htmlname, $socid, $amount, $filter =
'', $maxvalue = 0, $more =
'', $hidelist = 0, $discount_type = 0)
6498 global
$conf, $langs;
6499 if ($htmlname !=
"none") {
6500 print
'<form method="post" action="' . $page .
'">';
6501 print
'<input type="hidden" name="action" value="setabsolutediscount">';
6502 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6503 print
'<div class="inline-block">';
6504 if (!empty($discount_type)) {
6506 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL") {
6507 $translationKey =
'HasAbsoluteDiscountFromSupplier';
6509 $translationKey =
'HasCreditNoteFromSupplier';
6512 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
6513 $translationKey =
'HasAbsoluteDiscountFromSupplier';
6515 $translationKey =
'HasCreditNoteFromSupplier';
6520 if (!$filter || $filter ==
"fk_facture_source IS NULL") {
6521 $translationKey =
'CompanyHasAbsoluteDiscount';
6523 $translationKey =
'CompanyHasCreditNote';
6526 if (!$filter || $filter ==
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
6527 $translationKey =
'CompanyHasAbsoluteDiscount';
6529 $translationKey =
'CompanyHasCreditNote';
6533 print $langs->trans($translationKey,
price($amount, 0, $langs, 0, 0, -1,
$conf->currency));
6534 if (empty($hidelist)) {
6538 if (empty($hidelist)) {
6539 print
'<div class="inline-block" style="padding-right: 10px">';
6540 $newfilter =
'discount_type=' . intval($discount_type);
6541 if (!empty($discount_type)) {
6542 $newfilter .=
' AND fk_invoice_supplier IS NULL AND fk_invoice_supplier_line IS NULL';
6544 $newfilter .=
' AND fk_facture IS NULL AND fk_facture_line IS NULL';
6547 $newfilter .=
' AND (' . $filter .
')';
6550 $nbqualifiedlines = $this->select_remises((
string) $selected, $htmlname, $newfilter, $socid, $maxvalue);
6551 if ($nbqualifiedlines > 0) {
6552 print
' <input type="submit" class="button smallpaddingimp" value="' .
dol_escape_htmltag($langs->trans(
"UseLine")) .
'"';
6553 if (!empty($discount_type) && $filter && $filter !=
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
6554 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
6556 if (empty($discount_type) && $filter && $filter !=
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
6557 print
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") .
'"';
6565 print
'<div class="inline-block">';
6591 public function form_contacts($page, $societe, $selected =
'', $htmlname =
'contactid')
6596 if ($htmlname !=
"none") {
6597 print
'<form method="post" action="' . $page .
'">';
6598 print
'<input type="hidden" name="action" value="set_contact">';
6599 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6600 print
'<table class="nobordernopadding">';
6602 print $this->selectcontacts($societe->id, $selected, $htmlname);
6605 $addcontact = (
getDolGlobalString(
'SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans(
"AddContact") : $langs->trans(
"AddContactAddress"));
6606 print
'<a href="' . DOL_URL_ROOT .
'/contact/card.php?socid=' . $societe->id .
'&action=create&backtoreferer=1">' . $addcontact .
'</a>';
6609 print
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") .
'"></td>';
6610 print
'</tr></table></form>';
6613 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
6614 $contact =
new Contact($this->db);
6615 $contact->fetch($selected);
6616 print $contact->getFullName($langs);
6641 public function form_thirdparty($page, $selected =
'', $htmlname =
'socid', $filter =
'', $showempty = 0, $showtype = 0, $forcecombo = 0, $events = array(), $nooutput = 0, $excludeids = array(), $textifnothirdparty =
'')
6647 if ($htmlname !=
"none") {
6648 $out .=
'<form method="post" action="' . $page .
'">';
6649 $out .=
'<input type="hidden" name="action" value="set_thirdparty">';
6650 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
6651 $out .= $this->select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, 0,
'minwidth100',
'',
'', 1, array(),
false, $excludeids);
6652 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") .
'">';
6656 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
6657 $soc =
new Societe($this->db);
6658 $soc->fetch($selected);
6659 $out .= $soc->getNomUrl(0,
'');
6661 $out .=
'<span class="opacitymedium">' . $textifnothirdparty .
'</span>';
6687 print $this->selectCurrency($selected, $htmlname);
6699 public function selectCurrency($selected =
'', $htmlname =
'currency_id', $mode = 0, $useempty =
'')
6701 global $langs, $user;
6703 $langs->loadCacheCurrencies(
'');
6707 if ($selected ==
'euro' || $selected ==
'euros') {
6711 $out .=
'<select class="flat maxwidth200onsmartphone minwidth300" name="' . $htmlname .
'" id="' . $htmlname .
'">';
6713 $out .=
'<option value="-1" selected></option>';
6715 foreach ($langs->cache_currencies as $code_iso => $currency) {
6716 $labeltoshow = $currency[
'label'];
6718 $labeltoshow .=
' <span class="opacitymedium">(' . $code_iso .
')</span>';
6720 $labeltoshow .=
' <span class="opacitymedium">(' . $langs->getCurrencySymbol($code_iso) .
')</span>';
6723 if ($selected && $selected == $code_iso) {
6724 $out .=
'<option value="' . $code_iso .
'" selected data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
6726 $out .=
'<option value="' . $code_iso .
'" data-html="' .
dol_escape_htmltag($labeltoshow) .
'">';
6728 $out .= $labeltoshow;
6729 $out .=
'</option>';
6731 $out .=
'</select>';
6733 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
6737 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
6755 public function selectMultiCurrency($selected =
'', $htmlname =
'multicurrency_code', $useempty = 0, $filter =
'', $excludeConfCurrency =
false, $morecss =
'')
6757 global
$conf, $langs;
6759 $langs->loadCacheCurrencies(
'');
6761 $TCurrency = array();
6763 $sql =
"SELECT code FROM " . $this->db->prefix() .
"multicurrency";
6764 $sql .=
" WHERE entity IN ('" .
getEntity(
'multicurrency') .
"')";
6766 $sql .=
" AND " . $filter;
6768 $resql = $this->db->query($sql);
6770 while ($obj = $this->db->fetch_object($resql)) {
6771 $TCurrency[$obj->code] = $obj->code;
6776 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
6778 $out .=
'<option value=""> </option>';
6781 if (!in_array(
$conf->currency, $TCurrency) && !$excludeConfCurrency) {
6782 $TCurrency[
$conf->currency] =
$conf->currency;
6784 if (count($TCurrency) > 0) {
6785 foreach ($langs->cache_currencies as $code_iso => $currency) {
6786 if (isset($TCurrency[$code_iso])) {
6787 if (!empty($selected) && $selected == $code_iso) {
6788 $out .=
'<option value="' . $code_iso .
'" selected="selected">';
6790 $out .=
'<option value="' . $code_iso .
'">';
6793 $out .= $currency[
'label'];
6794 $out .=
' (' . $langs->getCurrencySymbol($code_iso) .
')';
6795 $out .=
'</option>';
6800 $out .=
'</select>';
6803 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
6820 global $langs, $user;
6822 $num = count($this->cache_vatrates);
6829 $sql =
"SELECT t.rowid, t.type_vat, t.code, t.taux, t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.recuperableonly";
6830 $sql .=
" FROM ".$this->db->prefix().
"c_tva as t, ".$this->db->prefix().
"c_country as c";
6831 $sql .=
" WHERE t.fk_pays = c.rowid";
6832 $sql .=
" AND t.active > 0";
6833 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
6834 $sql .=
" AND c.code IN (" . $this->db->sanitize($country_code, 1) .
")";
6835 $sql .=
" ORDER BY t.code ASC, t.taux ASC, t.recuperableonly ASC";
6837 $resql = $this->db->query($sql);
6839 $num = $this->db->num_rows($resql);
6841 for ($i = 0; $i < $num; $i++) {
6842 $obj = $this->db->fetch_object($resql);
6844 $tmparray = array();
6845 $tmparray[
'rowid'] = $obj->rowid;
6846 $tmparray[
'type_vat'] = $obj->type_vat;
6847 $tmparray[
'code'] = $obj->code;
6848 $tmparray[
'txtva'] = $obj->taux;
6849 $tmparray[
'nprtva'] = $obj->recuperableonly;
6850 $tmparray[
'localtax1'] = $obj->localtax1;
6851 $tmparray[
'localtax1_type'] = $obj->localtax1_type;
6852 $tmparray[
'localtax2'] = $obj->localtax2;
6853 $tmparray[
'localtax2_type'] = $obj->localtax1_type;
6854 $tmparray[
'label'] = $obj->taux .
'%' . ($obj->code ?
' (' . $obj->code .
')' :
'');
6855 $tmparray[
'labelallrates'] = $obj->taux .
'/' . ($obj->localtax1 ? $obj->localtax1 :
'0') .
'/' . ($obj->localtax2 ? $obj->localtax2 :
'0') . ($obj->code ?
' (' . $obj->code .
')' :
'');
6856 $positiverates =
'';
6858 $positiverates .= ($positiverates ?
'/' :
'') . $obj->taux;
6860 if ($obj->localtax1) {
6861 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax1;
6863 if ($obj->localtax2) {
6864 $positiverates .= ($positiverates ?
'/' :
'') . $obj->localtax2;
6866 if (empty($positiverates)) {
6867 $positiverates =
'0';
6869 $tmparray[
'labelpositiverates'] = $positiverates . ($obj->code ?
' (' . $obj->code .
')' :
'');
6871 $this->cache_vatrates[$obj->rowid] = $tmparray;
6876 $this->error =
'<span class="error">';
6877 $this->error .= $langs->trans(
"ErrorNoVATRateDefinedForSellerCountry", $country_code);
6879 if (!empty($user) && $user->admin && preg_match(
'/\'(..)\'/', $country_code, $reg)) {
6880 $langs->load(
"errors");
6881 $new_country_code = $reg[1];
6882 $country_id =
dol_getIdFromCode($this->db, $new_country_code,
'c_pays',
'code',
'rowid');
6883 $this->error .=
'<br>'.$langs->trans(
"ErrorFixThisHere", DOL_URL_ROOT.
'/admin/dict.php?id=10'.($country_id > 0 ?
'&countryidforinsert='.$country_id :
''));
6885 $this->error .=
'</span>';
6889 $this->error =
'<span class="error">' . $this->db->error() .
'</span>';
6918 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)
6921 global $langs, $mysoc;
6923 $langs->load(
'errors');
6928 $defaultnpr = ($info_bits & 0x01);
6929 $defaultnpr = (preg_match(
'/\*/', $selectedrate) ? 1 : $defaultnpr);
6930 $defaulttx = str_replace(
'*',
'', $selectedrate);
6933 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
6934 $defaultcode = $reg[1];
6935 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
6940 if (is_object($societe_vendeuse) && !$societe_vendeuse->country_code) {
6941 if ($societe_vendeuse->id == $mysoc->id) {
6942 $return .=
'<span class="error">' . $langs->trans(
"ErrorYourCountryIsNotDefined") .
'</span>';
6944 $return .=
'<span class="error">' . $langs->trans(
"ErrorSupplierCountryIsNotDefined") .
'</span>';
6955 if (is_object($societe_vendeuse)) {
6956 $code_country =
"'" . $societe_vendeuse->country_code .
"'";
6958 $code_country =
"'" . $mysoc->country_code .
"'";
6961 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
6965 if (
isInEEC($societe_vendeuse) &&
isInEEC($societe_acheteuse) && !$societe_acheteuse->isACompany()) {
6967 if (is_numeric($type)) {
6969 switch ($selectVatComboMode) {
6971 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
6974 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
6978 } elseif (!$idprod) {
6979 switch ($selectVatComboMode) {
6981 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
6984 $code_country =
"'" . $societe_acheteuse->country_code .
"'";
6988 $prodstatic =
new Product($this->db);
6989 $prodstatic->fetch($idprod);
6991 $code_country .=
",'" . $societe_acheteuse->country_code .
"'";
6998 $this->load_cache_vatrates($code_country);
7001 $arrayofvatrates = array();
7002 foreach ($this->cache_vatrates as $cachevalue) {
7003 if (empty($cachevalue[
'type_vat']) || $cachevalue[
'type_vat'] == $type_vat) {
7004 $arrayofvatrates[] = $cachevalue;
7008 $num = count($arrayofvatrates);
7012 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
7014 $tmpthirdparty =
new Societe($this->db);
7015 $tmpthirdparty->country_code = $mysoc->country_code;
7017 $defaulttx =
get_default_tva(is_object($societe_vendeuse) ? $societe_vendeuse : $tmpthirdparty, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
7018 $defaultnpr =
get_default_npr(is_object($societe_vendeuse) ? $societe_vendeuse : $tmpthirdparty, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
7020 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
7021 $defaultcode = $reg[1];
7022 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
7024 if (empty($defaulttx)) {
7031 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
7034 $defaulttx = $arrayofvatrates[$num - 1][
'txtva'];
7041 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
7042 $defaultcode = $reg[1];
7043 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
7051 if (is_object($societe_vendeuse) && $societe_vendeuse->id == $mysoc->id && $societe_vendeuse->tva_assuj ==
"0") {
7060 if (!$options_only) {
7061 $return .=
'<select class="flat minwidth75imp maxwidth100 right" id="' . $htmlname .
'" name="' . $htmlname .
'"' . ($disabled ?
' disabled' :
'') . $title .
'>';
7064 $selectedfound =
false;
7065 foreach ($arrayofvatrates as $rate) {
7067 if ($disabled && $rate[
'txtva'] != 0) {
7072 $key = $rate[
'txtva'];
7073 $key .= $rate[
'nprtva'] ?
'*' :
'';
7074 if ($mode > 0 && $rate[
'code']) {
7075 $key .=
' (' . $rate[
'code'] .
')';
7078 $key = $rate[
'rowid'];
7081 $return .=
'<option value="' . $key .
'"';
7082 if (!$selectedfound) {
7084 if ($defaultcode == $rate[
'code']) {
7085 $return .=
' selected';
7086 $selectedfound =
true;
7088 } elseif ($rate[
'txtva'] == $defaulttx && $rate[
'nprtva'] == $defaultnpr) {
7089 $return .=
' selected';
7090 $selectedfound =
true;
7096 if ($mysoc->country_code ==
'IN' ||
getDolGlobalString(
'MAIN_VAT_LABEL_IS_POSITIVE_RATES')) {
7098 $return .= $rate[
'labelpositiverates'];
7101 $return .=
vatrate($rate[
'label']);
7105 $return .= (empty($rate[
'code']) && $rate[
'nprtva']) ?
' *' :
'';
7107 $return .=
'</option>';
7110 if (!$options_only) {
7111 $return .=
'</select>';
7115 $return .= $this->error;
7149 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 =
'')
7152 dol_syslog(__METHOD__ .
': using select_date is deprecated. Use selectDate instead.', LOG_WARNING);
7153 $retstring = $this->selectDate($set_time, $prefix, $h, $m, $empty, $form_name, $d, $addnowlink, $disabled, $fullday, $addplusone, $adddateof);
7154 if (!empty($nooutput)) {
7177 public function selectDateToDate($set_time =
'', $set_time_end =
'', $prefix =
're', $empty = 0, $forcenewline = 0)
7181 $ret = $this->selectDate($set_time, $prefix .
'_start', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"from"),
'tzuserrel');
7182 if ($forcenewline) {
7185 $ret .= $this->selectDate($set_time_end, $prefix .
'_end', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
7217 public function selectDate($set_time =
'', $prefix =
're', $h = 0, $m = 0, $empty = 0, $form_name =
"", $d = 1, $addnowlink = 0, $disabled = 0, $fullday =
'', $addplusone =
'', $adddateof =
'', $openinghours =
'', $stepminutes = 1, $labeladddateof =
'', $placeholder =
'', $gm =
'auto', $calendarpicto =
'')
7219 global
$conf, $langs;
7221 if ($gm ===
'auto') {
7222 $gm = (empty(
$conf) ?
'tzserver' :
$conf->tzuserinputkey);
7227 if ($prefix ==
'') {
7238 if ($stepminutes <= 0 || $stepminutes > 30) {
7249 $orig_set_time = $set_time;
7251 if ($set_time ===
'' && $emptydate == 0) {
7252 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
7253 if ($gm ==
'tzuser' || $gm ==
'tzuserrel') {
7265 if (!empty($set_time) && preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/', $set_time, $reg)) {
7267 $syear = (!empty($reg[1]) ? $reg[1] :
'');
7268 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
7269 $sday = (!empty($reg[3]) ? $reg[3] :
'');
7270 $shour = (!empty($reg[4]) ? $reg[4] :
'');
7271 $smin = (!empty($reg[5]) ? $reg[5] :
'');
7272 } elseif (strval($set_time) !=
'' && $set_time != -1) {
7277 if ($orig_set_time !=
'') {
7291 if ($h == 3 || $h == 4) {
7302 $usecalendar =
'combo';
7308 $usecalendar =
'html';
7313 if ($usecalendar !=
'combo') {
7314 $formatted_date =
'';
7316 if (strval($set_time) !=
'' && $set_time != -1) {
7318 $formatted_date =
dol_print_date($set_time, $langs->trans(
"FormatDateShortInput"), $gm);
7322 if ($usecalendar ==
"eldy") {
7324 $retstring .=
'<input id="' . $prefix .
'" name="' . $prefix .
'" type="text" class="maxwidthdate center" maxlength="11" value="' . $formatted_date .
'"';
7325 $retstring .= ($disabled ?
' disabled' :
'');
7326 $retstring .=
' onChange="dpChangeDay(\'' .
dol_escape_js($prefix) .
'\',\
'' .
dol_escape_js($langs->trans(
"FormatDateShortJavaInput")) .
'\');
"'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
7327 $retstring .= ' autocomplete="off
">';
7330 $retstringbuttom = '';
7332 $retstringbuttom = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
"';
7333 $base = DOL_URL_ROOT . '/core/';
7335 $retstringbuttom .= '>' . img_object($langs->trans("SelectDate
"), 'calendarday', 'class="datecallink
"') . '</button>';
7337 $retstringbuttom = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
">' . img_object($langs->trans("Disabled
"), 'calendarday', 'class="datecallink
"') . '</button>';
7339 $retstring = $retstringbuttom . $retstring;
7341 $retstring .= '<input type="hidden
" id="' . $prefix . 'day
" name="' . $prefix . 'day
" value="' . $sday . '">' . "\n
";
7342 $retstring .= '<input type="hidden
" id="' . $prefix . 'month
" name="' . $prefix . 'month
" value="' . $smonth . '">' . "\n
";
7343 $retstring .= '<input type="hidden
" id="' . $prefix . 'year
" name="' . $prefix . 'year
" value="' . $syear . '">' . "\n
";
7344 } elseif ($usecalendar == 'jquery' || $usecalendar == 'html') {
7345 if (!$disabled && $usecalendar != 'html') {
7346 // Output javascript for datepicker
7347 $minYear = getDolGlobalInt('MIN_YEAR_SELECT_DATE', (idate('Y') - 100));
7348 $maxYear = getDolGlobalInt('MAX_YEAR_SELECT_DATE', (idate('Y') + 100));
7350 $retstring .= '<script nonce="' . getNonce() . '" type="text/javascript
">';
7351 $retstring .= "$(
function(){ $(
'#" . $prefix . "').datepicker({
7352 dateFormat:
'" . $langs->trans("FormatDateShortJQueryInput") . "',
7354 todayHighlight:
true,
7355 yearRange:
'" . $minYear . ":" . $maxYear . "',
";
7356 if (!empty($conf->dol_use_jmobile)) {
7358 beforeShow:
function (input, datePicker) {
7359 input.disabled =
true;
7361 onClose:
function (dateText, datePicker) {
7366 // Note: We don't need monthNames, monthNamesShort, dayNames, dayNamesShort, dayNamesMin, they are set globally on datepicker component in lib_head.js.php
7367 if (!getDolGlobalString('MAIN_POPUP_CALENDAR_ON_FOCUS')) {
7368 $buttonImage = $calendarpicto ?: DOL_URL_ROOT . "/theme/
" . dol_escape_js($conf->theme) . "/img/object_calendarday.png
";
7371 buttonImage:
'" . $buttonImage . "',
7372 buttonImageOnly:
true";
7376 $retstring .= "</script>
";
7379 // Input area to enter date manually
7380 $retstring .= '<div class="nowraponall
inline-block divfordateinput
">';
7381 $retstring .= '<input id="'.$prefix.'" name="'.$prefix.'" type="'.($usecalendar == 'html
' ? "date" : "text").'" class="maxwidthdate center
" maxlength="11
" value="'.$formatted_date.'"';
7382 $retstring .= ($disabled ? ' disabled' : '');
7383 $retstring .= ($placeholder ? ' placeholder="' . dol_escape_htmltag($placeholder) . '"' : '');
7384 $retstring .= ' onChange="dpChangeDay(\
'' .
dol_escape_js($prefix) .
'\',\
'' .
dol_escape_js($langs->trans(
"FormatDateShortJavaInput")) .
'\');
"'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
7385 $retstring .= ' autocomplete="off
">';
7389 $retstringbutton = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
">' . img_object($langs->trans("Disabled
"), 'calendarday', 'class="datecallink
"') . '</button>';
7390 $retstring = $retstringbutton . $retstring;
7393 $retstring .= '</div>';
7394 $retstring .= '<input type="hidden
" id="' . $prefix . 'day
" name="' . $prefix . 'day
" value="' . $sday . '">' . "\n
";
7395 $retstring .= '<input type="hidden
" id="' . $prefix . 'month
" name="' . $prefix . 'month
" value="' . $smonth . '">' . "\n
";
7396 $retstring .= '<input type="hidden
" id="' . $prefix . 'year
" name="' . $prefix . 'year
" value="' . $syear . '">' . "\n
";
7398 $retstring .= "Bad value of MAIN_POPUP_CALENDAR
";
7401 // Show date with combo selects
7403 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50imp
" id="' . $prefix . 'day
" name="' . $prefix . 'day
">';
7405 if ($emptydate || $set_time == -1) {
7406 $retstring .= '<option value="0
" selected> </option>';
7409 for ($day = 1; $day <= 31; $day++) {
7410 $retstring .= '<option value="' . $day . '"' . ($day == $sday ? ' selected' : '') . '>' . $day . '</option>';
7413 $retstring .= "</select>
";
7415 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'month
" name="' . $prefix . 'month
">';
7416 if ($emptydate || $set_time == -1) {
7417 $retstring .= '<option value="0
" selected> </option>';
7421 for ($month = 1; $month <= 12; $month++) {
7422 $retstring .= '<option value="' . $month . '"' . ($month == $smonth ? ' selected' : '') . '>';
7423 $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b
");
7424 $retstring .= "</option>
";
7426 $retstring .= "</select>
";
7429 if ($emptydate || $set_time == -1) {
7430 $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 . '">';
7432 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'year
" name="' . $prefix . 'year
">';
7434 $syear = (int) $syear;
7435 for ($year = $syear - 10; $year < (int) $syear + 10; $year++) {
7436 $retstring .= '<option value="' . $year . '"' . ($year == $syear ? ' selected' : '') . '>' . $year . '</option>';
7438 $retstring .= "</select>\n
";
7444 $retstring .= (($h == 2 || $h == 4) ? '<br>' : ' ');
7445 $retstring .= '<span class="nowraponall
">';
7451 if ($openinghours != '') {
7452 $openinghours = explode(',', $openinghours);
7453 $hourstart = $openinghours[0];
7454 $hourend = $openinghours[1];
7455 if ($hourend < $hourstart) {
7456 $hourend = $hourstart;
7461 $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50
' . ($fullday ? $fullday . 'hour
' : '') . '" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
">';
7463 $retstring .= '<option value="-1
"> </option>';
7465 for ($hour = $hourstart; $hour < $hourend; $hour++) {
7466 if (strlen($hour) < 2) {
7467 $hour = "0
" . $hour;
7469 $retstring .= '<option value="' . $hour . '"' . (($hour == $shour) ? ' selected' : '') . '>' . $hour;
7470 $retstring .= '</option>';
7472 $retstring .= '</select>';
7474 $retstring .= '<input type="hidden
" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
" value="' . $shour . '">' . "\n
";
7483 $retstring .= '<select ' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50
' . ($fullday ? $fullday . 'min
' : '') . '" id="' . $prefix . 'min
" name="' . $prefix . 'min
">';
7485 $retstring .= '<option value="-1
"> </option>';
7487 for ($min = 0; $min < 60; $min += $stepminutes) {
7488 $min_str = sprintf("%02d
", $min);
7489 $retstring .= '<option value="' . $min_str . '"' . (($min_str == $smin) ? ' selected' : '') . '>' . $min_str . '</option>';
7491 $retstring .= '</select>';
7493 $retstring .= '<input type="hidden
" id="' . $prefix . 'min
" name="' . $prefix . 'min
" value="' . $smin . '">' . "\n
";
7496 $retstring .= '<input type="hidden
" name="' . $prefix . 'sec
" value="' . $ssec . '">';
7500 $retstring .= '</span>';
7504 if (!empty($conf->use_javascript_ajax) && $addnowlink && !$disabled) {
7505 // Script which will be inserted in the onClick of the "Now
" link
7506 $reset_scripts = "";
7507 if ($addnowlink == 2) { // local computer time
7508 // pad add leading 0 on numbers
7509 $reset_scripts .= "Number.prototype.pad =
function(size) {
7510 var s = String(
this);
7511 while (s.length < (size || 2)) {s =
'0' + s;}
7514 var d =
new Date();
";
7517 // Generate the date part, depending on the use or not of the javascript calendar
7518 if ($addnowlink == 1) { // server time expressed in user time setup
7519 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
7520 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
7521 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
7522 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
7523 } elseif ($addnowlink == 2) {
7524 /* Disabled because the output does not use the string format defined by FormatDateShort key to forge the value into #prefix.
7525 * This break application for foreign languages.
7526 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(d.toLocaleDateString(\''.str_replace('_', '-', $langs->defaultlang).'\'));';
7527 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(d.getDate().pad());';
7528 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(parseInt(d.getMonth().pad()) + 1);';
7529 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(d.getFullYear());';
7531 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');';
7532 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
7533 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
7534 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
7536 /*if ($usecalendar == "eldy
")
7538 $base=DOL_URL_ROOT.'/core/';
7539 $reset_scripts .= 'resetDP(\''.$base.'\',\''.$prefix.'\',\''.$langs->trans("FormatDateShortJavaInput
").'\',\''.$langs->defaultlang.'\');';
7543 $reset_scripts .= 'this.form.elements[\''.$prefix.'day\'].value=formatDate(new Date(), \'d\'); ';
7544 $reset_scripts .= 'this.form.elements[\''.$prefix.'month\'].value=formatDate(new Date(), \'M\'); ';
7545 $reset_scripts .= 'this.form.elements[\''.$prefix.'year\'].value=formatDate(new Date(), \'yyyy\'); ';
7547 // Update the hour part
7550 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7552 //$reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); ';
7553 if ($addnowlink == 1) {
7554 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
7555 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
7556 } elseif ($addnowlink == 2) {
7557 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(d.getHours().pad());';
7558 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();';
7562 $reset_scripts .= ' } ';
7565 // Update the minute part
7568 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7570 //$reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); ';
7571 if ($addnowlink == 1) {
7572 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
7573 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
7574 } elseif ($addnowlink == 2) {
7575 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(d.getMinutes().pad());';
7576 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();';
7579 $reset_scripts .= ' } ';
7582 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
7583 if ($reset_scripts && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
7584 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonNow
" type="button" name="_useless
" value="now
" onClick="' . $reset_scripts . '">';
7585 $retstring .= $langs->trans("Now
");
7586 $retstring .= '</button> ';
7590 // Add a "Plus one hour
" link
7591 if ($conf->use_javascript_ajax && $addplusone && !$disabled) {
7592 // Script which will be inserted in the onClick of the "Add plusone
" link
7593 $reset_scripts = "";
7595 // Generate the date part, depending on the use or not of the javascript calendar
7596 $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'dayinputnoreduce', 'tzuserrel') . '\');';
7597 $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');';
7598 $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');';
7599 $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');';
7600 // Update the hour part
7603 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7605 $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');';
7607 $reset_scripts .= ' } ';
7610 // Update the minute part
7613 $reset_scripts .= " if (jQuery(
'#fullday:checked').val() ==
null) {
";
7615 $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');';
7617 $reset_scripts .= ' } ';
7620 // If reset_scripts is not empty, print the link with the reset_scripts in the onClick
7621 if ($reset_scripts && empty($conf->dol_optimize_smallscreen)) {
7622 $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonPlusOne
" type="button" name="_useless2
" value="plusone
" onClick="' . $reset_scripts . '">';
7623 $retstring .= $langs->trans("DateStartPlusOne
");
7624 $retstring .= '</button> ';
7628 // Add a link to set data
7629 if ($conf->use_javascript_ajax && !empty($adddateof) && !$disabled) {
7630 if (!is_array($adddateof)) {
7631 $arrayofdateof = array(array('adddateof' => $adddateof, 'labeladddateof' => $labeladddateof));
7633 $arrayofdateof = $adddateof;
7635 foreach ($arrayofdateof as $valuedateof) {
7636 $tmpadddateof = empty($valuedateof['adddateof']) ? 0 : $valuedateof['adddateof'];
7637 $tmplabeladddateof = empty($valuedateof['labeladddateof']) ? '' : $valuedateof['labeladddateof'];
7638 $tmparray = dol_getdate($tmpadddateof);
7639 if (empty($tmplabeladddateof)) {
7640 $tmplabeladddateof = $langs->trans("DateInvoice
");
7642 $reset_scripts = 'console.log(\'Click on now link\'); ';
7643 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(\''.dol_print_date($tmpadddateof, 'dayinputnoreduce').'\');';
7644 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(\''.$tmparray['mday'].'\');';
7645 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(\''.$tmparray['mon'].'\');';
7646 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(\''.$tmparray['year'].'\');';
7647 $retstring .= ' - <button class="dpInvisibleButtons datenowlink
" id="dateofinvoice
" type="button" name="_dateofinvoice
" value="now
" onclick="'.$reset_scripts.'">'.$tmplabeladddateof.'</button>';
7662 public function selectTypeDuration($prefix, $selected = 'i', $excludetypes = array())
7666 $TDurationTypes = array(
7667 'y' => $langs->trans('Years'),
7668 'm' => $langs->trans('Month'),
7669 'w' => $langs->trans('Weeks'),
7670 'd' => $langs->trans('Days'),
7671 'h' => $langs->trans('Hours'),
7672 'i' => $langs->trans('Minutes')
7675 // Removed undesired duration types
7676 foreach ($excludetypes as $value) {
7677 unset($TDurationTypes[$value]);
7680 $retstring = '<select class="flat minwidth75 maxwidth100
" id="select_
' . $prefix . 'type_duration
" name="' . $prefix . 'type_duration
">';
7681 foreach ($TDurationTypes as $key => $typeduration) {
7682 $retstring .= '<option value="' . $key . '"';
7683 if ($key == $selected) {
7684 $retstring .= " selected
";
7686 $retstring .= ">
" . $typeduration . "</option>
";
7688 $retstring .= "</select>
";
7690 $retstring .= ajax_combobox('select_' . $prefix . 'type_duration');
7695 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
7710 public function select_duration($prefix, $iSecond = '', $disabled = 0, $typehour = 'select', $minunderhours = 0, $nooutput = 0)
7715 $retstring = '<span class="nowraponall
">';
7721 if ($iSecond != '') {
7722 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
7724 $hourSelected = convertSecondToTime($iSecond, 'allhour');
7725 $minSelected = convertSecondToTime($iSecond, 'min');
7728 if ($typehour == 'select') {
7729 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'hour
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . '>';
7730 for ($hour = 0; $hour < 25; $hour++) { // For a duration, we allow 24 hours
7731 $retstring .= '<option value="' . $hour . '"';
7732 if (is_numeric($hourSelected) && $hourSelected == $hour) {
7733 $retstring .= " selected
";
7735 $retstring .= ">
" . $hour . "</option>
";
7737 $retstring .= "</select>
";
7738 } elseif ($typehour == 'text' || $typehour == 'textselect') {
7739 $retstring .= '<input placeholder="' . $langs->trans('HourShort
') . '" type="number
" min="0
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputhour right
" value="' . (($hourSelected != '') ? ((int) $hourSelected) : '') . '">';
7741 return 'BadValueForParameterTypeHour';
7744 if ($typehour != 'text') {
7745 $retstring .= ' ' . $langs->trans('HourShort');
7747 $retstring .= '<span class="">:</span>';
7751 if ($minunderhours) {
7752 $retstring .= '<br>';
7754 if ($typehour != 'text') {
7755 $retstring .= '<span class="hideonsmartphone
"> </span>';
7759 if ($typehour == 'select' || $typehour == 'textselect') {
7760 $retstring .= '<select class="flat
" id="select_
' . $prefix . 'min
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . '>';
7761 for ($min = 0; $min <= 55; $min += 5) {
7762 $retstring .= '<option value="' . $min . '"';
7763 if (is_numeric($minSelected) && $minSelected == $min) {
7764 $retstring .= ' selected';
7766 $retstring .= '>' . $min . '</option>';
7768 $retstring .= "</select>
";
7769 } elseif ($typehour == 'text') {
7770 $retstring .= '<input placeholder="' . $langs->trans('MinuteShort
') . '" type="number
" min="0
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputminute right
" value="' . (($minSelected != '') ? ((int) $minSelected) : '') . '">';
7773 if ($typehour != 'text') {
7774 $retstring .= ' ' . $langs->trans('MinuteShort');
7777 $retstring .= "</span>
";
7779 if (!empty($nooutput)) {
7807 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)
7809 global $langs, $conf;
7814 if (is_null($ajaxoptions)) {
7815 $ajaxoptions = array();
7818 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
7821 if ($selected && empty($selected_input_value)) {
7822 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
7823 $tickettmpselect = new Ticket($this->db);
7824 $tickettmpselect->fetch($selected);
7825 $selected_input_value = $tickettmpselect->ref;
7826 unset($tickettmpselect);
7830 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/ticket/ajax/tickets.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
7832 if (empty($hidelabel)) {
7833 $out .= $langs->trans("RefOrLabel
") . ' : ';
7834 } elseif ($hidelabel > 1) {
7835 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
7836 if ($hidelabel == 2) {
7837 $out .= img_picto($langs->trans("Search
"), 'search');
7840 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
7841 if ($hidelabel == 3) {
7842 $out .= img_picto($langs->trans("Search
"), 'search');
7845 $out .= $this->selectTicketsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
7848 if (empty($nooutput)) {
7873 public function selectTicketsList($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
7875 global $langs, $conf;
7878 $outarray = array();
7880 $selectFields = " p.rowid, p.ref, p.message
";
7883 $sql .= $selectFields;
7884 $sql .= " FROM
" . $this->db->prefix() . "ticket as p
";
7885 $sql .= ' WHERE p.entity IN (' . getEntity('ticket') . ')';
7887 // Add criteria on ref/label
7888 if ($filterkey != '') {
7890 $prefix = !getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
7891 // For natural search
7892 $search_crit = explode(' ', $filterkey);
7894 if (count($search_crit) > 1) {
7897 foreach ($search_crit as $crit) {
7901 $sql .= "(p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%' OR p.subject LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
7905 if (count($search_crit) > 1) {
7911 $sql .= $this->db->plimit($limit, 0);
7913 // Build output string
7914 dol_syslog(get_class($this) . "::selectTicketsList search tickets
", LOG_DEBUG);
7915 $result = $this->db->query($sql);
7917 require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
7918 require_once DOL_DOCUMENT_ROOT . '/core/lib/ticket.lib.php';
7920 $num = $this->db->num_rows($result);
7925 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
7926 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('TICKET_USE_SEARCH_TO_SELECT'));
7929 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
7932 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
7933 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
7934 if (getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
7935 if ($showempty && !is_numeric($showempty)) {
7936 $textifempty = $langs->trans($showempty);
7938 $textifempty .= $langs->trans("All
");
7941 if ($showempty && !is_numeric($showempty)) {
7942 $textifempty = $langs->trans($showempty);
7946 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
7950 while ($num && $i < $num) {
7953 $objp = $this->db->fetch_object($result);
7955 $this->constructTicketListOption($objp, $opt, $optJson, $selected, $filterkey);
7956 '@phan-var-force array{key:string,value:mixed,type:int} $optJson';
7958 // "key
" value of json key array is used by jQuery automatically as selected value
7959 // "label
" value of json key array is used by jQuery automatically as text for combo box
7961 array_push($outarray, $optJson);
7966 $out .= '</select>';
7968 $this->db->free($result);
7970 if (empty($outputmode)) {
7975 dol_print_error($this->db);
7992 protected function constructTicketListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
7998 $outkey = $objp->rowid;
7999 $outref = $objp->ref;
8001 $opt = '<option value="
' . $objp->rowid . '"';
8002 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
8005 $objRef = $objp->ref;
8006 if (!empty($filterkey) && $filterkey != '') {
8007 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1);
8010 $opt .= "</option>\n
";
8011 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
8033 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)
8035 global $langs, $conf;
8040 if (is_null($ajaxoptions)) {
8041 $ajaxoptions = array();
8044 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
8047 if ($selected && empty($selected_input_value)) {
8048 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
8049 $projecttmpselect = new Project($this->db);
8050 $projecttmpselect->fetch($selected);
8051 $selected_input_value = $projecttmpselect->ref;
8052 unset($projecttmpselect);
8056 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/projet/ajax/projects.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
8058 if (empty($hidelabel)) {
8059 $out .= $langs->trans("RefOrLabel
") . ' : ';
8060 } elseif ($hidelabel > 1) {
8061 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
8062 if ($hidelabel == 2) {
8063 $out .= img_picto($langs->trans("Search
"), 'search');
8066 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
8067 if ($hidelabel == 3) {
8068 $out .= img_picto($langs->trans("Search
"), 'search');
8071 $out .= $this->selectProjectsList($selected, $htmlname, $filtertype, $limit, '', $status, 0, $showempty, $forcecombo, $morecss);
8074 if (empty($nooutput)) {
8098 public function selectProjectsList($selected = '', $htmlname = 'projectid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
8100 global $langs, $conf;
8103 $outarray = array();
8105 $selectFields = " p.rowid, p.ref
";
8108 $sql .= $selectFields;
8109 $sql .= " FROM
" . $this->db->prefix() . "projet as p
";
8110 $sql .= ' WHERE p.entity IN (' . getEntity('project') . ')';
8112 // Add criteria on ref/label
8113 if ($filterkey != '') {
8115 $prefix = !getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
8116 // For natural search
8117 $search_crit = explode(' ', $filterkey);
8119 if (count($search_crit) > 1) {
8122 foreach ($search_crit as $crit) {
8126 $sql .= "p.ref LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
8130 if (count($search_crit) > 1) {
8136 $sql .= $this->db->plimit($limit, 0);
8138 // Build output string
8139 dol_syslog(get_class($this) . "::selectProjectsList search projects
", LOG_DEBUG);
8140 $result = $this->db->query($sql);
8142 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
8143 require_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php';
8145 $num = $this->db->num_rows($result);
8150 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
8151 $out .= ajax_combobox($htmlname, $events, getDolGlobalInt('PROJECT_USE_SEARCH_TO_SELECT'));
8154 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
8157 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
8158 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
8159 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
8160 if ($showempty && !is_numeric($showempty)) {
8161 $textifempty = $langs->trans($showempty);
8163 $textifempty .= $langs->trans("All
");
8166 if ($showempty && !is_numeric($showempty)) {
8167 $textifempty = $langs->trans($showempty);
8171 $out .= '<option value="0
" selected>' . $textifempty . '</option>';
8175 while ($num && $i < $num) {
8178 $objp = $this->db->fetch_object($result);
8180 $this->constructProjectListOption($objp, $opt, $optJson, $selected, $filterkey);
8182 // "key
" value of json key array is used by jQuery automatically as selected value
8183 // "label
" value of json key array is used by jQuery automatically as text for combo box
8185 array_push($outarray, $optJson);
8190 $out .= '</select>';
8192 $this->db->free($result);
8194 if (empty($outputmode)) {
8199 dol_print_error($this->db);
8216 protected function constructProjectListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
8222 $label = $objp->label;
8224 $outkey = $objp->rowid;
8225 $outref = $objp->ref;
8226 $outlabel = $objp->label;
8227 $outtype = $objp->fk_product_type;
8229 $opt = '<option value="
' . $objp->rowid . '"';
8230 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
8233 $objRef = $objp->ref;
8234 if (!empty($filterkey) && $filterkey != '') {
8235 $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1);
8238 $opt .= "</option>\n
";
8239 $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype);
8262 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)
8264 global $langs, $conf;
8269 if (is_null($ajaxoptions)) {
8270 $ajaxoptions = array();
8273 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
8276 if ($selected && empty($selected_input_value)) {
8277 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
8278 $adherenttmpselect = new Adherent($this->db);
8279 $adherenttmpselect->fetch($selected);
8280 $selected_input_value = $adherenttmpselect->ref;
8281 unset($adherenttmpselect);
8286 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/adherents/ajax/adherents.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
8288 if (empty($hidelabel)) {
8289 $out .= $langs->trans("RefOrLabel
") . ' : ';
8290 } elseif ($hidelabel > 1) {
8291 $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
8292 if ($hidelabel == 2) {
8293 $out .= img_picto($langs->trans("Search
"), 'search');
8296 $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />';
8297 if ($hidelabel == 3) {
8298 $out .= img_picto($langs->trans("Search
"), 'search');
8303 $out .= $this->selectMembersList($selected, $htmlname, $filtertype, $limit, $filterkey, $status, 0, $showempty, $forcecombo, $morecss);
8306 if (empty($nooutput)) {
8330 public function selectMembersList($selected = '', $htmlname = 'adherentid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
8332 global $langs, $conf;
8335 $outarray = array();
8337 $selectFields = " p.rowid, p.ref, p.firstname, p.lastname, p.fk_adherent_type
";
8340 $sql .= $selectFields;
8341 $sql .= " FROM
" . $this->db->prefix() . "adherent as p
";
8342 $sql .= ' WHERE p.entity IN (' . getEntity('adherent') . ')';
8344 // Add criteria on ref/label
8345 if ($filterkey != '') {
8347 $prefix = !getDolGlobalString('MEMBER_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
8348 // For natural search
8349 $search_crit = explode(' ', $filterkey);
8351 if (count($search_crit) > 1) {
8354 foreach ($search_crit as $crit) {
8358 $sql .= "(p.firstname LIKE
'" . $this->db->escape($prefix . $crit) . "%'";
8359 $sql .= " OR p.lastname LIKE
'" . $this->db->escape($prefix . $crit) . "%')
";
8362 if (count($search_crit) > 1) {
8367 if ($status != -1) {
8368 $sql .= ' AND statut = ' . ((int) $status);
8370 $sql .= $this->db->plimit($limit, 0);
8372 // Build output string
8373 dol_syslog(get_class($this) . "::selectMembersList search adherents
", LOG_DEBUG);
8374 $result = $this->db->query($sql);
8376 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
8377 require_once DOL_DOCUMENT_ROOT . '/core/lib/member.lib.php';
8379 $num = $this->db->num_rows($result);
8384 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
8385 $out .= ajax_combobox($htmlname, $events, getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT') ? $conf->global->PROJECT_USE_SEARCH_TO_SELECT : '');
8388 $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">';
8391 // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
8392 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
8393 if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
8394 if ($showempty && !is_numeric($showempty)) {
8395 $textifempty = $langs->trans($showempty);
8397 $textifempty .= $langs->trans("All
");
8400 if ($showempty && !is_numeric($showempty)) {
8401 $textifempty = $langs->trans($showempty);
8405 $out .= '<option value="-1
" selected>' . $textifempty . '</option>';
8409 while ($num && $i < $num) {
8412 $objp = $this->db->fetch_object($result);
8414 $this->constructMemberListOption($objp, $opt, $optJson, $selected, $filterkey);
8417 // "key
" value of json key array is used by jQuery automatically as selected value
8418 // "label
" value of json key array is used by jQuery automatically as text for combo box
8420 array_push($outarray, $optJson);
8425 $out .= '</select>';
8427 $this->db->free($result);
8429 if (empty($outputmode)) {
8434 dol_print_error($this->db);
8451 protected function constructMemberListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
8457 $outkey = $objp->rowid;
8458 $outlabel = dolGetFirstLastname($objp->firstname, $objp->lastname);
8459 $outtype = $objp->fk_adherent_type;
8461 $opt = '<option value="
' . $objp->rowid . '"';
8462 $opt .= ($objp->rowid == $selected) ? ' selected' : '';
8464 if (!empty($filterkey) && $filterkey != '') {
8465 $outlabel = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $outlabel, 1);
8468 $opt .= "</option>\n
";
8470 $optJson = array('key' => $outkey, 'value' => $outlabel, 'type' => $outtype);
8493 public function selectForForms($objectdesc, $htmlname, $preSelectedValue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $disabled = 0, $selected_input_value = '', $objectfield = '')
8495 global $conf, $extrafields, $user;
8497 // Example of common usage for a link to a thirdparty
8499 // We got this in a modulebuilder form of "
MyObject" of module "mymodule
".
8500 // ->fields is array( ... "fk_soc
" => array("type"=>"integer:
Societe:societe/class/societe.class.php:1:((
status:=:1) AND (entity:IN:__SHARED_ENTITIES__))
" ...)
8501 // $objectdesc = 'Societe'
8502 // $objectfield = 'myobject@mymodule:fk_soc' ('fk_soc' is code to retrieve myobject->fields['fk_soc'])
8504 // We got this when showing an extrafields on resource that is a link to societe
8505 // extrafields 'link_to_societe' of Resource is 'link' to 'Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))" ...)
'
8507 // $objectfield = 'resource:options_link_to_societe
'
8510 // $objectdesc = 'Societe:societe/class/societe.class.php:1:((
status:=:1) AND (entity:IN:__SHARED_ENTITIES__))
'
8511 // $objectfield = ''
8513 //var_dump($objectdesc.' '.$objectfield);
8514 //debug_print_backtrace();
8516 $objectdescorig = $objectdesc;
8518 $InfoFieldList = array();
8520 $filter = ''; // Ensure filter has value (for static analysis)
8521 $sortfield = ''; // Ensure filter has value (for static analysis)
8523 if ($objectfield) { // We must retrieve the objectdesc from the field or extrafield
8524 // Example: $objectfield = 'product:options_package
' or 'myobject@mymodule:options_myfield
'
8525 $tmparray = explode(':
', $objectfield);
8527 // Get instance of object from $element
8528 $objectforfieldstmp = fetchObjectByElement(0, strtolower($tmparray[0]));
8530 if (is_object($objectforfieldstmp)) {
8534 if (preg_match('/^options_(.*)$/
', $tmparray[1], $reg)) {
8535 // For a property in extrafields
8537 // fetch optionals attributes and labels
8538 $extrafields->fetch_name_optionals_label($objectforfieldstmp->table_element);
8540 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element]['type'][$key]) && $extrafields->attributes[$objectforfieldstmp->table_element]['type'][$key] == 'link
') {
8541 if (!empty($extrafields->attributes[$objectforfieldstmp->table_element]['param
'][$key]['options
'])) {
8542 $tmpextrafields = array_keys($extrafields->attributes[$objectforfieldstmp->table_element]['param
'][$key]['options
']);
8543 $objectdesc = $tmpextrafields[0];
8547 // For a property in ->fields
8548 if (array_key_exists($tmparray[1], $objectforfieldstmp->fields)) {
8549 $objectdesc = $objectforfieldstmp->fields[$tmparray[1]]['type'];
8550 $objectdesc = preg_replace('/^integer[^:]*:/
', '', $objectdesc);
8557 // Example of value for $objectdesc:
8558 // Bom:bom/class/bom.class.php:0:t.status=1
8559 // Bom:bom/class/bom.class.php:0:t.status=1:ref
8560 // Bom:bom/class/bom.class.php:0:(t.status:=:1) OR (t.field2:=:2):ref
8561 $InfoFieldList = explode(":", $objectdesc, 4);
8562 $vartmp = (empty($InfoFieldList[3]) ? '' : $InfoFieldList[3]);
8564 if (preg_match('/^.*:(\w*)$/
', $vartmp, $reg)) {
8565 $InfoFieldList[4] = $reg[1]; // take the sort field
8567 $InfoFieldList[3] = preg_replace('/:\w*$/
', '', $vartmp); // take the filter field
8569 $classname = $InfoFieldList[0];
8570 $classpath = empty($InfoFieldList[1]) ? '' : $InfoFieldList[1];
8571 //$addcreatebuttonornot = empty($InfoFieldList[2]) ? 0 : $InfoFieldList[2];
8572 $filter = empty($InfoFieldList[3]) ? '' : $InfoFieldList[3];
8573 $sortfield = empty($InfoFieldList[4]) ? '' : $InfoFieldList[4];
8575 // Load object according to $id and $element
8576 $objecttmp = fetchObjectByElement(0, strtolower($InfoFieldList[0]));
8578 // Fallback to another solution to get $objecttmp
8579 if (empty($objecttmp) && !empty($classpath)) {
8580 dol_include_once($classpath);
8582 if ($classname && class_exists($classname)) {
8583 $objecttmp = new $classname($this->db);
8588 // Make some replacement in $filter. May not be used if we used the ajax mode with $objectfield. In such a case
8589 // we propagate the $objectfield and not the filter and replacement is done by the ajax/selectobject.php component.
8590 $sharedentities = (is_object($objecttmp) && property_exists($objecttmp, 'element
')) ? getEntity($objecttmp->element) : strtolower($classname);
8591 $filter = str_replace(
8592 array('__ENTITY__
', '__SHARED_ENTITIES__
', '__USER_ID__
'),
8593 array($conf->entity, $sharedentities, $user->id),
8597 if (!is_object($objecttmp)) {
8598 dol_syslog('selectForForms: Error bad setup of field objectdescorig=
' . $objectdescorig.', objectfield=
'.$objectfield.', objectdesc=
'.$objectdesc, LOG_WARNING);
8599 return 'selectForForms: Error bad setup of field objectdescorig=
' . $objectdescorig.', objectfield=
'.$objectfield.', objectdesc=
'.$objectdesc;
8603 //var_dump($filter);
8604 $prefixforautocompletemode = $objecttmp->element;
8605 if ($prefixforautocompletemode == 'societe
') {
8606 $prefixforautocompletemode = 'company
';
8608 if ($prefixforautocompletemode == 'product
') {
8609 $prefixforautocompletemode = 'produit
';
8611 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) . '_USE_SEARCH_TO_SELECT
'; // For example COMPANY_USE_SEARCH_TO_SELECT
8613 dol_syslog(get_class($this) . "::selectForForms filter=" . $filter, LOG_DEBUG);
8615 // Generate the combo HTML component
8617 if (!empty($conf->use_javascript_ajax) && getDolGlobalString($confkeyforautocompletemode) && !$forcecombo) {
8618 // No immediate load of all database
8621 if ($preSelectedValue && empty($selected_input_value)) {
8622 $objecttmp->fetch($preSelectedValue);
8623 $selected_input_value = ($prefixforautocompletemode == 'company
' ? $objecttmp->name : $objecttmp->ref);
8625 $oldValueForShowOnCombobox = 0;
8626 foreach ($objecttmp->fields as $fieldK => $fielV) {
8627 if (!array_key_exists('showoncombobox
', $fielV) || !$fielV['showoncombobox
'] || empty($objecttmp->$fieldK)) {
8631 if (!$oldValueForShowOnCombobox) {
8632 $selected_input_value = '';
8635 $selected_input_value .= $oldValueForShowOnCombobox ? ' -
' : '';
8636 $selected_input_value .= $objecttmp->$fieldK;
8637 $oldValueForShowOnCombobox = empty($fielV['showoncombobox
']) ? 0 : $fielV['showoncombobox
'];
8641 // Set url and param to call to get json of the search results
8642 $urlforajaxcall = DOL_URL_ROOT . '/core/ajax/selectobject.php
';
8643 $urloption = 'htmlname=
' . urlencode($htmlname) . '&outjson=1&objectdesc=
' . urlencode($objectdescorig) . '&objectfield=
'.urlencode($objectfield) . ($sortfield ? '&sortfield=
' . urlencode($sortfield) : '');
8645 // Activate the auto complete using ajax call.
8646 $out .= ajax_autocompleter((string) $preSelectedValue, $htmlname, $urlforajaxcall, $urloption, getDolGlobalInt($confkeyforautocompletemode), 0);
8647 $out .= '<!-- force css to be higher than dialog popup --><style
type=
"text/css">.ui-autocomplete { z-index: 1010; }</style>
';
8648 $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) . '"' : '') . ' />
';
8650 // Immediate load of table record.
8651 $out .= $this->selectForFormsList($objecttmp, $htmlname, $preSelectedValue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled, $sortfield, $filter);
8678 public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty = '
', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $outputmode = 0, $disabled = 0, $sortfield = '', $filter = '')
8680 global $langs, $user, $hookmanager;
8682 //print "$htmlname, $preselectedvalue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, $outputmode, $disabled";
8684 $prefixforautocompletemode = $objecttmp->element;
8685 if ($prefixforautocompletemode == 'societe
') {
8686 $prefixforautocompletemode = 'company
';
8688 $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) . '_USE_SEARCH_TO_SELECT
'; // For example COMPANY_USE_SEARCH_TO_SELECT
8690 if (!empty($objecttmp->fields)) { // For object that declare it, it is better to use declared fields (like societe, contact, ...)
8691 $tmpfieldstoshow = '';
8692 foreach ($objecttmp->fields as $key => $val) {
8693 if (! (int) dol_eval($val['enabled
'], 1, 1, '1
')) {
8696 if (!empty($val['showoncombobox
'])) {
8697 $tmpfieldstoshow .= ($tmpfieldstoshow ? ',
' : '') . 't.
' . $key;
8700 if ($tmpfieldstoshow) {
8701 $fieldstoshow = $tmpfieldstoshow;
8704 // For backward compatibility
8705 $objecttmp->fields['ref
'] = array('type' => 'varchar(30)
', 'label
' => 'Ref
', 'showoncombobox
' => 1);
8708 if (empty($fieldstoshow)) {
8709 if (!empty($objecttmp->parent_element)) {
8710 $fieldstoshow = 'o.ref
';
8711 if (empty($sortfield)) {
8712 $sortfield = 'o.ref
';
8714 if (in_array($objecttmp->element, ['commandedet
', 'propaldet
', 'facturedet
', 'expeditiondet
'])) {
8715 $fieldstoshow .= ',p.ref AS p_ref,p.label,t.description
';
8716 $sortfield .= ', p.ref
';
8718 } elseif (isset($objecttmp->fields['ref'])) {
8719 $fieldstoshow = 't.ref
';
8721 $langs->load("errors");
8722 $this->error = $langs->trans("ErrorNoFieldWithAttributeShowoncombobox");
8723 return $langs->trans('ErrorNoFieldWithAttributeShowoncombobox
');
8728 $outarray = array();
8729 $tmparray = array();
8734 $sql = "SELECT t.rowid, " . $fieldstoshow . " FROM " . $this->db->prefix() . $this->db->sanitize($objecttmp->table_element) . " as t";
8735 if (!empty($objecttmp->isextrafieldmanaged)) {
8736 $sql .= " LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($objecttmp->table_element) . "_extrafields as e ON t.rowid = e.fk_object";
8738 if (!empty($objecttmp->parent_element)) {
8739 $parent_properties = getElementProperties($objecttmp->parent_element);
8740 $sql .= " INNER JOIN " . $this->db->prefix() . $this->db->sanitize($parent_properties['table_element
']) . " as o ON o.rowid = t.".$objecttmp->fk_parent_attribute;
8742 if (in_array($objecttmp->parent_element, ['commande
', 'propal
', 'facture
', 'expedition
'])) {
8743 $sql .= " LEFT JOIN " . $this->db->prefix() . "product as p ON p.rowid = t.fk_product";
8745 if (isset($objecttmp->ismultientitymanaged)) {
8746 if (!is_numeric($objecttmp->ismultientitymanaged)) {
8747 $tmparray = explode('@
', $objecttmp->ismultientitymanaged);
8748 $sql .= " INNER JOIN " . $this->db->prefix() . $this->db->sanitize($tmparray[1]) . " as parenttable ON parenttable.rowid = t." . $this->db->sanitize($tmparray[0]);
8750 if ($objecttmp->ismultientitymanaged === 'fk_soc@societe
') {
8751 if (!$user->hasRight('societe
', 'client
', 'voir
')) {
8752 $sql .= ", " . $this->db->prefix() . "societe_commerciaux as sc";
8757 // Add where from hooks
8758 $parameters = array(
8759 'object' => $objecttmp,
8760 'htmlname
' => $htmlname,
8761 'filter
' => $filter,
8762 'searchkey
' => $searchkey
8765 $reshook = $hookmanager->executeHooks('selectForFormsListWhere
', $parameters); // Note that $action and $object may have been modified by hook
8766 if (!empty($hookmanager->resPrint)) {
8767 $sql .= $hookmanager->resPrint;
8769 $sql .= " WHERE 1=1";
8770 if (isset($objecttmp->ismultientitymanaged)) {
8771 if ($objecttmp->ismultientitymanaged == 1) {
8772 $sql .= " AND t.entity IN (" . getEntity($objecttmp->table_element) . ")";
8774 if (!is_numeric($objecttmp->ismultientitymanaged)) {
8775 $sql .= " AND parenttable.entity = t." . $this->db->sanitize($tmparray[0]);
8777 if ($objecttmp->ismultientitymanaged == 1 && !empty($user->socid)) {
8778 if ($objecttmp->element == 'societe
') {
8779 $sql .= " AND t.rowid = " . ((int) $user->socid);
8781 $sql .= " AND t.fk_soc = " . ((int) $user->socid);
8784 if ($objecttmp->ismultientitymanaged === 'fk_soc@societe
') {
8785 if (!$user->hasRight('societe
', 'client
', 'voir
')) {
8786 $sql .= " AND t.rowid = sc.fk_soc AND sc.fk_user = " . ((int) $user->id);
8790 $splittedfieldstoshow = explode(',
', $fieldstoshow);
8791 foreach ($splittedfieldstoshow as &$field2) {
8792 if (is_numeric($pos = strpos($field2, ' '))) {
8793 $field2 = substr($field2, 0, $pos);
8796 if ($searchkey != '') {
8797 $sql .= natural_search($splittedfieldstoshow, $searchkey);
8800 if ($filter) { // Syntax example "(t.ref:like:'SO-%
') and (t.date_creation:<:'20160101
')"
8802 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
8803 if ($errormessage) {
8804 return 'Error forging a SQL request from an universal criteria:
' . $errormessage;
8808 $sql .= $this->db->order($sortfield ? $sortfield : $fieldstoshow, "ASC");
8809 //$sql.=$this->db->plimit($limit, 0);
8812 // Build output string
8813 $resql = $this->db->query($sql);
8815 // Construct $out and $outarray
8816 $out .= '<select
id=
"' . $htmlname . '" class=
"flat minwidth100' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled=
"disabled"' : '') . ($moreparams ? ' ' . $moreparams : '') . ' name=
"' . $htmlname . '">
' . "\n";
8818 // Warning: Do not use textifempty = ' ' or '
' here, or search on key will search on ' key
'. Seems it is no more true with selec2 v4
8819 $textifempty = '
';
8821 //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
8822 if (getDolGlobalInt($confkeyforautocompletemode)) {
8823 if ($showempty && !is_numeric($showempty)) {
8824 $textifempty = $langs->trans($showempty);
8826 $textifempty .= $langs->trans("All");
8830 $out .= '<option value=
"-1">
' . $textifempty . '</option>
' . "\n";
8833 $num = $this->db->num_rows($resql);
8837 $obj = $this->db->fetch_object($resql);
8840 $tmparray = explode(',
', $fieldstoshow);
8841 $oldvalueforshowoncombobox = 0;
8842 foreach ($tmparray as $key => $val) {
8843 $val = preg_replace('/(t|p|o)\./
', '', $val);
8844 $label .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val]['showoncombobox
'] ? ' -
' : ' ') : '');
8845 $labelhtml .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val]['showoncombobox
'] ? ' -
' : ' ') : '');
8846 $label .= $obj->$val;
8847 $labelhtml .= $obj->$val;
8849 $oldvalueforshowoncombobox = empty($objecttmp->fields[$val]['showoncombobox
']) ? 0 : $objecttmp->fields[$val]['showoncombobox
'];
8851 if (empty($outputmode)) {
8852 if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) {
8853 $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>
';
8855 $out .= '<option value=
"' . $obj->rowid . '" data-html=
"' . dol_escape_htmltag($labelhtml, 0, 0, '', 0, 1) . '">
' . dol_escape_htmltag($label, 0, 0, '', 0, 1) . '</option>
';
8858 array_push($outarray, array('key
' => $obj->rowid, 'value
' => $label, 'label
' => $label));
8862 if (($i % 10) == 0) {
8868 $out .= '</select>
' . "\n";
8871 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
8872 $out .= ajax_combobox($htmlname, array(), getDolGlobalInt($confkeyforautocompletemode, 0));
8875 dol_print_error($this->db);
8878 $this->result = array('nbofelement
' => $num);
8910 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)
8912 global $conf, $langs;
8914 // Do we want a multiselect ?
8916 //if (preg_match('/^multi/
',$htmlname)) $jsbeautify = 1;
8919 if ($value_as_key) {
8920 $array = array_combine($array, $array);
8923 '@phan-var-force array{label:string,data-html:string,disable?:int<0,1>,css?:string} $array
'; // Array combine breaks information
8927 if ($addjscombo < 0) {
8928 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER
')) {
8934 $idname = str_replace(array('[
', ']
'), array('', ''), $htmlname);
8935 $out .= '<select id=
"' . preg_replace('/^\./', '', $idname) . '" ' . ($disabled ? 'disabled=
"disabled" ' : '') . 'class=
"flat ' . (preg_replace('/^\./', '', $htmlname)) . ($morecss ? ' ' . $morecss : '') . ' selectformat"';
8936 $out .= ' name=
"' . preg_replace('/^\./', '', $htmlname) . '" ' . ($moreparam ? $moreparam : '');
8940 $textforempty = ' ';
8941 if (!empty($conf->use_javascript_ajax)) {
8942 $textforempty = '
'; // If we use ajaxcombo, we need here to avoid to have an empty element that is too small.
8944 if (!is_numeric($show_empty)) {
8945 $textforempty = $show_empty;
8947 $out .= '<option
class=
"optiongrey" ' . ($moreparamonempty ? $moreparamonempty . ' ' : '') . 'value=
"' . (((int) $show_empty) < 0 ? $show_empty : -1) . '"' . ($id == $show_empty ? ' selected
' : '') . '>
' . $textforempty . '</option>
' . "\n";
8949 if (is_array($array)) {
8952 foreach ($array as $key => $value) {
8953 if (!is_array($value)) {
8954 $array[$key] = $langs->trans($value);
8956 $array[$key]['label
'] = $langs->trans($value['label
']);
8961 if ($sort == 'ASC
') {
8963 } elseif ($sort == 'DESC
') {
8967 foreach ($array as $key => $tmpvalue) {
8968 if (is_array($tmpvalue)) {
8969 $value = $tmpvalue['label
'];
8970 //$valuehtml = empty($tmpvalue['data-html
']) ? $value : $tmpvalue['data-html
'];
8972 $style = empty($tmpvalue['css
']) ? '' : ' class=
"' . $tmpvalue['css'] . '"';
8975 //$valuehtml = $tmpvalue;
8979 if (!empty($disablebademail)) {
8980 if (($disablebademail == 1 && !preg_match('/<.+@.+>/
', $value))
8981 || ($disablebademail == 2 && preg_match('/---/
', $value))) {
8983 $style = ' class=
"warning"';
8986 if ($key_in_label) {
8987 if (empty($nohtmlescape)) {
8988 $selectOptionValue = dol_escape_htmltag($key . ' -
' . ($maxlen ? dol_trunc($value, $maxlen) : $value));
8990 $selectOptionValue = $key . ' -
' . ($maxlen ? dol_trunc($value, $maxlen) : $value);
8993 if (empty($nohtmlescape)) {
8994 $selectOptionValue = dol_escape_htmltag($maxlen ? dol_trunc($value, $maxlen) : $value);
8996 $selectOptionValue = $maxlen ? dol_trunc($value, $maxlen) : $value;
8998 if ($value == '' || $value == '-
') {
8999 $selectOptionValue = '
';
9002 $out .= '<option value=
"' . $key . '"';
9003 $out .= $style . $disabled;
9004 if (is_array($id)) {
9005 if (in_array($key, $id) && !$disabled) {
9006 $out .= ' selected
'; // To preselect a value
9009 $id = (string) $id; // if $id = 0, then $id = '0
'
9010 if ($id != '' && (($id == (string) $key) || ($id == 'ifone
' && count($array) == 1)) && !$disabled) {
9011 $out .= ' selected
'; // To preselect a value
9014 if (!empty($nohtmlescape)) { // deprecated. Use instead the key 'data-html
' into input $array, managed at next step to use HTML content.
9015 $out .= ' data-html=
"' . dol_escape_htmltag($selectOptionValue) . '"';
9018 if (is_array($tmpvalue)) {
9019 foreach ($tmpvalue as $keyforvalue => $valueforvalue) {
9020 if ($keyforvalue == 'labelhtml
') {
9021 $keyforvalue = 'data-html
';
9023 if (preg_match('/^data-/
', $keyforvalue)) { // The best solution if you want to use HTML values into the list is to use data-html.
9024 $out .= ' '.dol_escape_htmltag($keyforvalue).'=
"'.dol_escape_htmltag($valueforvalue).'"';
9029 $out .= $selectOptionValue;
9030 $out .= "</option>\n";
9033 $out .= "</select>";
9035 // Add code for jquery to use multiselect
9036 if ($addjscombo && $jsbeautify) {
9037 // Enhance with select2
9038 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
9039 $out .= ajax_combobox($idname, array(), 0, 0, 'resolve
', (((int) $show_empty) < 0 ? (string) $show_empty : '-1
'), $morecss);
9063 public static function selectArrayAjax($htmlname, $url, $id = '
', $moreparam = '', $moreparamtourl = '', $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0)
9066 global $delayedhtmlcontent; // Will be used later outside of this function
9068 // TODO Use an internal dolibarr component instead of select2
9069 if (!getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT
') && !defined('REQUIRE_JQUERY_MULTISELECT
')) {
9073 $out = '<select
type=
"text" class=
"' . $htmlname . ($morecss ? ' ' . $morecss : '') . '" ' . ($moreparam ? $moreparam . ' ' : '') . 'name=
"' . $htmlname . '"></select>
';
9076 if (!empty($conf->use_javascript_ajax)) {
9077 $tmpplugin = 'select2
';
9078 $outdelayed = "\n" . '<!-- JS CODE TO ENABLE
' . $tmpplugin . ' for id ' . $htmlname . ' -->
9079 <script nonce=
"' . getNonce() . '">
9080 $(document).ready(
function () {
9082 ' . ($callurlonselect ? 'var saveRemoteData = [];
' : '') . '
9084 $(
".' . $htmlname . '").select2({
9087 url:
"' . $url . '",
9090 data: function (params) {
9092 q: params.term, // search term
9096 processResults: function (data) {
9097 // parse the results into the format expected by Select2.
9098 // since we are using custom formatting functions we do not need to alter the remote JSON data
9099 //console.log(data);
9100 saveRemoteData = data;
9101 /* format json result for select2 */
9103 $.each( data, function( key, value ) {
9104 result.push({id: key, text: value.text});
9106 //return {results:[{id:\'none\', text:\'aa\'}, {id:\'rrr\', text:\'Red\'},{id:\'bbb\', text:\'Search a into projects\'}], more:false}
9107 //console.log(result);
9108 return {results: result, more: false}
9112 language: (typeof select2arrayoflanguage === \'undefined\') ? \'en\' : select2arrayoflanguage,
9113 containerCssClass: \':all:\', /* Line to add class from the original SELECT propagated to the new <span class="select2-selection...> tag */
9115 escapeMarkup:
function (markup) {
return markup; },
9116 minimumInputLength:
' . ((int) $minimumInputLength) . ',
9117 formatResult:
function (result, container, query, escapeMarkup) {
9118 return escapeMarkup(result.text);
9122 ' . ($callurlonselect ? '
9124 $(
".' . $htmlname . '").change(
function() {
9125 var selected = $(\
'.' .
dol_escape_js($htmlname) .
'\').val();
9126 console.log(
"We select in selectArrayAjax the entry "+selected)
9128 $.each( saveRemoteData,
function( key, value ) {
9129 if (key == selected)
9131 console.log(
"selectArrayAjax - Do a redirect to "+value.url)
9132 location.assign(value.url);
9141 if ($acceptdelayedhtml) {
9142 $delayedhtmlcontent .= $outdelayed;
9144 $out .= $outdelayed;
9168 public static function selectArrayFilter($htmlname, $array, $id = '
', $moreparam = '', $disableFiltering = 0, $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0, $textfortitle = '')
9171 global $delayedhtmlcontent; // Will be used later outside of this function
9173 // TODO Use an internal dolibarr component instead of select2
9174 if (!getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT
') && !defined('REQUIRE_JQUERY_MULTISELECT
')) {
9178 $out = '<select
type=
"text"'.($textfortitle ? ' title=
"'.dol_escape_htmltag($textfortitle).'"' : '').' id=
"'.$htmlname.'" class=
"'.$htmlname.($morecss ? ' ' . $morecss : '').'"'.($moreparam ? ' '.$moreparam : '').' name=
"'.$htmlname.'"><option></option></select>
';
9180 $formattedarrayresult = array();
9182 foreach ($array as $key => $value) {
9183 $o = new stdClass();
9185 $o->text = $value['text
'];
9186 $o->url = $value['url
'];
9187 $formattedarrayresult[] = $o;
9191 if (!empty($conf->use_javascript_ajax)) {
9192 $tmpplugin = 'select2
';
9193 $outdelayed = "\n" . '<!-- JS CODE TO ENABLE
' . $tmpplugin . ' for id ' . $htmlname . ' -->
9194 <script nonce=
"' . getNonce() . '">
9195 $(document).ready(
function () {
9196 var data =
' . json_encode($formattedarrayresult) . ';
9198 ' . ($callurlonselect ? 'var saveRemoteData =
' . json_encode($array) . ';
' : '') . '
9202 language: (typeof select2arrayoflanguage === \
'undefined\') ? \'en\' : select2arrayoflanguage,
9203 containerCssClass: \':all:\', /* Line to add class from the original SELECT propagated to the new <span class="select2-selection...> tag */
9205 escapeMarkup:
function (markup) {
return markup; },
9206 minimumInputLength:
' . ((int) $minimumInputLength) . ',
9207 formatResult:
function (result, container, query, escapeMarkup) {
9208 return escapeMarkup(result.text);
9210 matcher:
function (params, data) {
9212 if(! data.id)
return null;
';
9214 if ($callurlonselect) {
9215 // We forge the url with 'sall=
'
9218 var urlBase = data.url;
9219 var separ = urlBase.indexOf(
"?") >= 0 ?
"&" :
"?";
9222 saveRemoteData[data.id].url = urlBase + separ +
"search_all=" + encodeURIComponent(params.term.replace(/\
"/g, ""));';
9225 if (!$disableFiltering) {
9228 if(data.text.match(new RegExp(params.term))) {
9243 ' . ($callurlonselect ? '
9244 /* Code to execute a GET when we select a value */
9245 $(\'.' . dol_escape_js($htmlname) . '\').change(function() {
9246 var selected = $(\'.' . dol_escape_js($htmlname) . '\').val();
9247 console.log("We select
"+selected)
9249 $(\'.' . dol_escape_js($htmlname) . '\').val(""); /* reset visible combo value */
9250 $.each( saveRemoteData, function( key, value ) {
9251 if (key == selected)
9253 console.log("selectArrayFilter - Do a redirect to
"+value.url)
9254 location.assign(value.url);
9263 if ($acceptdelayedhtml) {
9264 $delayedhtmlcontent .= $outdelayed;
9266 $out .= $outdelayed;
9289 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)
9291 global $conf, $langs;
9294 if ($addjscombo < 0) {
9295 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
9302 $useenhancedmultiselect = 0;
9303 if (!empty($conf->use_javascript_ajax) && !defined('MAIN_DO_NOT_USE_JQUERY_MULTISELECT') && (getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') || defined('REQUIRE_JQUERY_MULTISELECT'))) {
9305 $useenhancedmultiselect = 1; // Use the js multiselect in one line. Possible only if $addjscombo not 0.
9309 // We need a hidden field because when using the multiselect, if we unselect all, there is no
9310 // variable submitted at all, so no way to make a difference between variable not submitted and variable
9311 // submitted to nothing.
9312 $out .= '<input type="hidden
" name="'.$htmlname.'_multiselect
" value="1
">';
9313 // Output select component
9314 $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
";
9315 if (is_array($array) && !empty($array)) {
9316 if ($value_as_key) {
9317 $array = array_combine($array, $array);
9320 if (!empty($array)) {
9321 foreach ($array as $key => $value) {
9327 if (is_array($value) && array_key_exists('id', $value) && array_key_exists('label', $value)) {
9328 $tmpkey = $value['id'];
9329 $tmpvalue = empty($value['label']) ? '' : $value['label'];
9330 $tmpcolor = empty($value['color']) ? '' : $value['color'];
9331 $tmppicto = empty($value['picto']) ? '' : $value['picto'];
9332 $tmplabelhtml = empty($value['labelhtml']) ? (empty($value['data-html']) ? '' : $value['data-html']) : $value['labelhtml'];
9334 $newval = ($translate ? $langs->trans($tmpvalue) : $tmpvalue);
9335 $newval = ($key_in_label ? $tmpkey . ' - ' . $newval : $newval);
9337 $out .= '<option value="' . $tmpkey . '"';
9338 if (is_array($selected) && !empty($selected) && in_array((string) $tmpkey, $selected) && ((string) $tmpkey != '')) {
9339 $out .= ' selected';
9341 if (!empty($tmplabelhtml)) {
9342 $out .= ' data-html="' . dol_escape_htmltag($tmplabelhtml, 0, 0, '', 0, 1) . '"';
9344 $tmplabelhtml = ($tmppicto ? img_picto('', $tmppicto, 'class="pictofixedwidth
" style="color: #
' . $tmpcolor . '"') : '') . $newval;
9345 $out .= ' data-html="' . dol_escape_htmltag($tmplabelhtml, 0, 0, '', 0, 1) . '"';
9348 $out .= dol_htmlentitiesbr($newval);
9349 $out .= '</option>' . "\n
";
9353 $out .= '</select>' . "\n
";
9355 // Add code for jquery to use multiselect
9356 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') || defined('REQUIRE_JQUERY_MULTISELECT')) {
9357 $out .= "\n
" . '<!-- JS CODE TO ENABLE select for id ' . $htmlname . ', addjscombo=' . $addjscombo . ' -->';
9358 $out .= "\n
" . '<script nonce="' . getNonce() . '">' . "\n
";
9359 if ($addjscombo == 1) {
9360 $tmpplugin = !getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') ? constant('REQUIRE_JQUERY_MULTISELECT') : $conf->global->MAIN_USE_JQUERY_MULTISELECT;
9361 $out .= 'function formatResult(record, container) {' . "\n
";
9362 // If property data-html set, we decode html entities and use this.
9363 // Note that HTML content must have been sanitized from js with dol_escape_htmltag(xxx, 0, 0, '', 0, 1) when building the select option.
9364 $out .= ' if ($(record.element).attr("data-html
") != undefined && typeof htmlEntityDecodeJs === "function
") {';
9365 //$out .= ' console.log("aaa
");';
9366 $out .= ' return htmlEntityDecodeJs($(record.element).attr("data-html
"));';
9368 $out .= ' return record.text;';
9370 $out .= 'function formatSelection(record) {' . "\n
";
9371 if ($elemtype == 'category') {
9372 $out .= 'return \'<span><img src="' . DOL_URL_ROOT . '/theme/eldy/img/object_category.png
"> \'+record.text+\'</span>\';';
9374 $out .= 'return record.text;';
9377 $out .= '$(document).ready(function () {
9378 $(\'#' . dol_escape_js($htmlname) . '\').' . $tmpplugin . '({';
9383 text: \'' . dol_escape_js($placeholder) . '\'
9386 $out .= ' dir: \'ltr\',
9387 containerCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag (ko with multiselect) */
9388 dropdownCssClass: \
'' .
dol_escape_js($morecss) .
'\', /* Line to add class on the new <span class="select2-selection...> tag (ok with multiselect). Need full version of select2. */
9389 // Specify format function for dropdown item
9390 formatResult: formatResult,
9391 templateResult: formatResult, /* For 4.0 */
9392 escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
9393 // Specify format function for selected item
9394 formatSelection: formatSelection,
9395 templateSelection: formatSelection, /* For 4.0 */
9396 language: (typeof select2arrayoflanguage === \'undefined\') ? \'en\' : select2arrayoflanguage
9399 /* Add also morecss to the css .select2 that is after the #htmlname, for component that are show dynamically after load, because select2 set
9400 the size only if component is not hidden by default on load */
9403 } elseif ($addjscombo == 2 && !defined(
'DISABLE_MULTISELECT')) {
9407 $out .=
'console.log(\'addjscombo=2 for htmlname=' .
dol_escape_js($htmlname) .
'\');
';
9408 $out .= '$(document).ready(
function () {
9410 containerHTML: \
'<div class="multi-select-container">\',
9411 menuHTML: \'<div class="multi-select-menu">\',
9412 buttonHTML: \'<span class="multi-select-button ' .
dol_escape_js($morecss) .
'">\',
9413 menuItemHTML: \'<label class="multi-select-menuitem">\',
9414 activeClass: \'multi-select-container--open\',
9419 $out .= '</script>
';
9437 public static function multiSelectArrayWithCheckbox($htmlname, &$array, $varpage, $pos = '
')
9439 global $langs, $user;
9441 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER
')) {
9444 if (empty($array)) {
9448 $tmpvar = "MAIN_SELECTEDFIELDS_" . $varpage; // To get list of saved selected fields to show
9450 if (!empty($user->conf->$tmpvar)) { // A list of fields was already customized for user
9451 $tmparray = explode(',
', $user->conf->$tmpvar);
9452 foreach ($array as $key => $val) {
9454 //var_dump($tmparray);
9455 if (in_array($key, $tmparray)) {
9456 $array[$key]['checked
'] = 1;
9458 $array[$key]['checked
'] = 0;
9461 } else { // There is no list of fields already customized for user
9462 foreach ($array as $key => $val) {
9463 if (!empty($array[$key]['checked
']) && $array[$key]['checked
'] < 0) {
9464 $array[$key]['checked
'] = 0;
9469 $listoffieldsforselection = '';
9470 $listcheckedstring = '';
9472 foreach ($array as $key => $val) {
9474 // var_dump(array_key_exists('enabled
', $val));
9475 // var_dump(!$val['enabled
']);
9476 if (array_key_exists('enabled
', $val) && isset($val['enabled
']) && !$val['enabled
']) {
9477 unset($array[$key]); // We don't want
this field
9480 if (!empty($val[
'type']) && $val[
'type'] ==
'separate') {
9485 if (!empty($val[
'label']) && $val[
'label']) {
9486 if (!empty($val[
'langfile']) && is_object($langs)) {
9487 $langs->load($val[
'langfile']);
9491 $listoffieldsforselection .=
'<li><input type="checkbox" id="checkbox' . $key .
'" value="' . $key .
'"' . ((!array_key_exists(
'checked', $val) || empty($val[
'checked']) || $val[
'checked'] ==
'-1') ?
'' :
' checked="checked"') .
'/>';
9492 $listoffieldsforselection .=
'<label for="checkbox' . $key .
'">'.dol_string_nohtmltag($langs->trans($val[
'label'])) .
'</label></li>';
9493 $listcheckedstring .= (empty($val[
'checked']) ?
'' : $key .
',');
9497 $out =
'<!-- Component multiSelectArrayWithCheckbox ' . $htmlname .
' -->
9499 <dl class="dropdown">
9501 <a href="#' . $htmlname .
'">
9504 <input type="hidden" class="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $listcheckedstring .
'">
9506 <dd class="dropdowndd">
9507 <div class="multiselectcheckbox'.$htmlname.
'">
9508 <ul class="'.$htmlname.(((string) $pos ==
'1' || (
string) $pos ==
'left') ?
'left' :
'').
'">
9509 <li class="liinputsearch"><input class="inputsearch_dropdownselectedfields width90p minwidth200imp" style="width:90%;" type="text" placeholder="'.$langs->trans(
'Search').
'"></li>
9510 '.$listoffieldsforselection.
'
9516 <script nonce="' .
getNonce() .
'" type="text/javascript">
9517 jQuery(document).ready(function () {
9518 $(\'.multiselectcheckbox' . $htmlname .
' input[type="checkbox"]\').on(\'click\', function () {
9519 console.log("A new field was added/removed, we edit field input[name=formfilteraction]");
9521 $("input:hidden[name=formfilteraction]").val(\'listafterchangingselectedfields\'); // Update field so we know we changed something on selected fields after POST
9523 var title = $(this).val() + ",";
9524 if ($(this).is(\':checked\')) {
9525 $(\'.' . $htmlname .
'\').val(title + $(\'.' . $htmlname .
'\').val());
9528 $(\'.' . $htmlname .
'\').val( $(\'.' . $htmlname .
'\').val().replace(title, \'\') )
9530 // Now, we submit page
9531 //$(this).parents(\'form:first\').submit();
9533 $("input.inputsearch_dropdownselectedfields").on("keyup", function() {
9534 var value = $(this).val().toLowerCase();
9535 $(\'.multiselectcheckbox'.$htmlname.
' li > label\').filter(function() {
9536 $(this).parent().toggle($(this).text().toLowerCase().indexOf(value) > -1)
9559 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
9562 $categories = $cat->containing(
$id, $type);
9564 if ($rendermode == 1) {
9566 foreach ($categories as
$c) {
9567 $ways =
$c->print_all_ways(
' >> ', ($nolink ?
'none' :
''), 0, 1);
9568 foreach ($ways as $way) {
9569 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . (
$c->color ?
' style="background: #' .
$c->color .
';"' :
' style="background: #bbb"') .
'>' . $way .
'</li>';
9572 if (empty($toprint)) {
9575 return '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
9579 if ($rendermode == 0) {
9580 $arrayselected = array();
9581 $cate_arbo = $this->select_all_categories($type,
'',
'parent', 64, 0, 3);
9582 foreach ($categories as
$c) {
9583 $arrayselected[] =
$c->id;
9586 return $this->multiselectarray(
'categories', $cate_arbo, $arrayselected, 0, 0,
'', 0,
'100%',
'disabled',
'category');
9589 return 'ErrorBadValueForParameterRenderMode';
9603 global
$conf, $langs, $hookmanager;
9609 $hookmanager->initHooks(array(
'commonobject'));
9610 $parameters = array(
9611 'morehtmlright' => $morehtmlright,
9612 'compatibleImportElementsList' => &$compatibleImportElementsList,
9614 $reshook = $hookmanager->executeHooks(
'showLinkedObjectBlock', $parameters,
$object, $action);
9616 $nbofdifferenttypes = count(
$object->linkedObjects);
9618 if (empty($reshook)) {
9619 print
'<!-- showLinkedObjectBlock -->';
9620 print
load_fiche_titre($langs->trans($title), $morehtmlright,
'', 0,
'',
'showlinkedobjectblock');
9623 print
'<div class="div-table-responsive-no-min">';
9624 print
'<table class="noborder allwidth" data-block="showLinkedObject" data-element="' .
$object->element .
'" data-elementid="' .
$object->id .
'" >';
9626 print
'<tr class="liste_titre">';
9627 print
'<td>' . $langs->trans(
"Type") .
'</td>';
9628 print
'<td>' . $langs->trans(
"Ref") .
'</td>';
9629 print
'<td class="center"></td>';
9630 print
'<td class="center">' . $langs->trans(
"Date") .
'</td>';
9631 print
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
9632 print
'<td class="right">' . $langs->trans(
"Status") .
'</td>';
9636 $nboftypesoutput = 0;
9638 foreach (
$object->linkedObjects as $objecttype => $objects) {
9639 $tplpath = $element = $subelement = $objecttype;
9642 $showImportButton =
false;
9643 if (!empty($compatibleImportElementsList) && in_array($element, $compatibleImportElementsList)) {
9644 $showImportButton =
true;
9648 if ($objecttype !=
'supplier_proposal' && preg_match(
'/^([^_]+)_([^_]+)/i', $objecttype, $regs)) {
9649 $element = $regs[1];
9650 $subelement = $regs[2];
9651 $tplpath = $element .
'/' . $subelement;
9653 $tplname =
'linkedobjectblock';
9656 if ($objecttype ==
'facture') {
9657 $tplpath =
'compta/' . $element;
9658 if (!isModEnabled(
'invoice')) {
9661 } elseif ($objecttype ==
'facturerec') {
9662 $tplpath =
'compta/facture';
9663 $tplname =
'linkedobjectblockForRec';
9664 if (!isModEnabled(
'invoice')) {
9667 } elseif ($objecttype ==
'propal') {
9668 $tplpath =
'comm/' . $element;
9669 if (!isModEnabled(
'propal')) {
9672 } elseif ($objecttype ==
'supplier_proposal') {
9673 if (!isModEnabled(
'supplier_proposal')) {
9676 } elseif ($objecttype ==
'shipping' || $objecttype ==
'shipment' || $objecttype ==
'expedition') {
9677 $tplpath =
'expedition';
9678 if (!isModEnabled(
'shipping')) {
9681 } elseif ($objecttype ==
'reception') {
9682 $tplpath =
'reception';
9683 if (!isModEnabled(
'reception')) {
9686 } elseif ($objecttype ==
'delivery') {
9687 $tplpath =
'delivery';
9691 } elseif ($objecttype ==
'ficheinter') {
9692 $tplpath =
'fichinter';
9693 if (!isModEnabled(
'intervention')) {
9696 } elseif ($objecttype ==
'invoice_supplier') {
9697 $tplpath =
'fourn/facture';
9698 } elseif ($objecttype ==
'order_supplier') {
9699 $tplpath =
'fourn/commande';
9700 } elseif ($objecttype ==
'expensereport') {
9701 $tplpath =
'expensereport';
9702 } elseif ($objecttype ==
'subscription') {
9703 $tplpath =
'adherents';
9704 } elseif ($objecttype ==
'conferenceorbooth') {
9705 $tplpath =
'eventorganization';
9706 } elseif ($objecttype ==
'conferenceorboothattendee') {
9707 $tplpath =
'eventorganization';
9708 } elseif ($objecttype ==
'mo') {
9710 if (!isModEnabled(
'mrp')) {
9713 } elseif ($objecttype ==
'project_task') {
9714 $tplpath =
'projet/tasks';
9717 global $linkedObjectBlock;
9718 $linkedObjectBlock = $objects;
9721 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array(
'/' . $tplpath .
'/tpl'));
9722 foreach ($dirtpls as $reldir) {
9723 $reldir = rtrim($reldir,
'/');
9724 if ($nboftypesoutput == ($nbofdifferenttypes - 1)) {
9725 global $noMoreLinkedObjectBlockAfter;
9726 $noMoreLinkedObjectBlockAfter = 1;
9729 $res = @include
dol_buildpath($reldir .
'/' . $tplname .
'.tpl.php');
9737 if (!$nboftypesoutput) {
9738 print
'<tr><td colspan="7"><span class="opacitymedium">' . $langs->trans(
"None") .
'</span></td></tr>';
9743 if (!empty($compatibleImportElementsList)) {
9744 $res = @include
dol_buildpath(
'core/tpl/objectlinked_lineimport.tpl.php');
9750 return $nbofdifferenttypes;
9764 global
$conf, $langs, $hookmanager, $form;
9768 $form =
new Form($this->db);
9772 $linktoelemlist =
'';
9773 $listofidcompanytoscan =
'';
9775 if (!is_object(
$object->thirdparty)) {
9779 $possiblelinks = array();
9781 $dontIncludeCompletedItems =
getDolGlobalString(
'DONT_INCLUDE_COMPLETED_ELEMENTS_LINKS');
9783 if (is_object(
$object->thirdparty) && !empty(
$object->thirdparty->id) &&
$object->thirdparty->id > 0) {
9784 $listofidcompanytoscan = (int)
$object->thirdparty->id;
9786 $listofidcompanytoscan .=
',' . (int)
$object->thirdparty->parent;
9789 include_once DOL_DOCUMENT_ROOT .
'/projet/class/project.class.php';
9790 $tmpproject =
new Project($this->db);
9791 $tmpproject->fetch(
$object->fk_project);
9792 if ($tmpproject->socid > 0 && ($tmpproject->socid !=
$object->thirdparty->id)) {
9793 $listofidcompanytoscan .=
',' . (int) $tmpproject->socid;
9798 $possiblelinks = array(
9800 'enabled' => isModEnabled(
'propal'),
9802 'label' =>
'LinkToProposal',
9803 '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' :
''),
9805 'shipping' => array(
9806 'enabled' => isModEnabled(
'shipping'),
9808 'label' =>
'LinkToExpedition',
9809 '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' :
''),
9812 'enabled' => isModEnabled(
'order'),
9814 'label' =>
'LinkToOrder',
9815 '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' :
''),
9816 'linkname' =>
'commande',
9819 'enabled' => isModEnabled(
'invoice'),
9821 'label' =>
'LinkToInvoice',
9822 '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' :
''),
9823 'linkname' =>
'facture',
9825 'invoice_template' => array(
9826 'enabled' => isModEnabled(
'invoice'),
9828 'label' =>
'LinkToTemplateInvoice',
9829 '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') .
')',
9832 'enabled' => isModEnabled(
'contract'),
9834 'label' =>
'LinkToContract',
9835 '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
9836 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',
9838 'fichinter' => array(
9839 'enabled' => isModEnabled(
'intervention'),
9841 'label' =>
'LinkToIntervention',
9842 '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') .
')',
9844 'supplier_proposal' => array(
9845 'enabled' => isModEnabled(
'supplier_proposal'),
9847 'label' =>
'LinkToSupplierProposal',
9848 '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' :
''),
9850 'order_supplier' => array(
9851 'enabled' => isModEnabled(
"supplier_order"),
9853 'label' =>
'LinkToSupplierOrder',
9854 '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' :
''),
9856 'invoice_supplier' => array(
9857 'enabled' => isModEnabled(
"supplier_invoice"),
9858 'perms' => 1,
'label' =>
'LinkToSupplierInvoice',
9859 'sql' =>
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM " . $this->db->prefix() .
"societe as s, " . $this->db->prefix() .
"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' :
''),
9862 'enabled' => isModEnabled(
'ticket'),
9864 'label' =>
'LinkToTicket',
9865 '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' :
''),
9868 'enabled' => isModEnabled(
'mrp'),
9870 'label' =>
'LinkToMo',
9871 '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' :
''),
9876 if (
$object->table_element ==
'commande_fournisseur') {
9877 $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' :
'');
9878 } elseif (
$object->table_element ==
'mrp_mo') {
9879 $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' :
'');
9883 if (!empty($listofidcompanytoscan)) {
9885 $hookmanager->initHooks(array(
'commonobject'));
9886 $parameters = array(
'listofidcompanytoscan' => $listofidcompanytoscan,
'possiblelinks' => $possiblelinks);
9887 $reshook = $hookmanager->executeHooks(
'showLinkToObjectBlock', $parameters,
$object, $action);
9890 if (empty($reshook)) {
9891 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
9892 $possiblelinks = array_merge($possiblelinks, $hookmanager->resArray);
9894 } elseif ($reshook > 0) {
9895 if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
9896 $possiblelinks = $hookmanager->resArray;
9900 if (!empty($possiblelinks)) {
9905 $htmltoenteralink =
'';
9906 foreach ($possiblelinks as $key => $possiblelink) {
9908 if (empty($possiblelink[
'enabled'])) {
9912 if (!empty($possiblelink[
'perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || !in_array($key, $excludelinksto))) {
9913 $htmltoenteralink .=
'<div id="' . $key .
'list"' . (empty(
$conf->use_javascript_ajax) ?
'' :
' style="display:none"') .
'>';
9917 $htmltoenteralink .=
'<br>'.
"\n";
9918 $htmltoenteralink .=
'<!-- form to add a link from anywhere -->'.
"\n";
9919 $htmltoenteralink .=
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinkedbyref' . $key .
'">';
9920 $htmltoenteralink .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
9921 $htmltoenteralink .=
'<input type="hidden" name="action" value="addlinkbyref">';
9922 $htmltoenteralink .=
'<input type="hidden" name="id" value="' .
$object->id .
'">';
9923 $htmltoenteralink .=
'<input type="hidden" name="addlink" value="' . $key .
'">';
9924 $htmltoenteralink .=
'<table class="noborder">';
9925 $htmltoenteralink .=
'<tr class="liste_titre">';
9927 $htmltoenteralink .=
'<td class="center"><input type="text" placeholder="'.dol_escape_htmltag($langs->trans(
"Ref")).
'" name="reftolinkto" value="' .
dol_escape_htmltag(
GETPOST(
'reftolinkto',
'alpha')) .
'"> ';
9928 $htmltoenteralink .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
'ToLink') .
'"> ';
9929 $htmltoenteralink .=
'<input type="submit" class="button smallpaddingimp" name="cancel" value="' . $langs->trans(
'Cancel') .
'"></td>';
9930 $htmltoenteralink .=
'</tr>';
9931 $htmltoenteralink .=
'</table>';
9932 $htmltoenteralink .=
'</form>';
9935 $sql = $possiblelink[
'sql'];
9937 $resqllist = $this->db->query($sql);
9939 $num = $this->db->num_rows($resqllist);
9945 $htmltoenteralink .=
'<br>';
9947 $htmltoenteralink .=
'<!-- form to add a link from object to same thirdparty -->'.
"\n";
9948 $htmltoenteralink .=
'<form action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST" name="formlinked' . $key .
'">';
9949 $htmltoenteralink .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
9950 $htmltoenteralink .=
'<input type="hidden" name="action" value="addlink">';
9951 $htmltoenteralink .=
'<input type="hidden" name="id" value="' .
$object->id .
'">';
9952 $htmltoenteralink .=
'<input type="hidden" name="addlink" value="' . $key .
'">';
9953 $htmltoenteralink .=
'<table class="noborder">';
9954 $htmltoenteralink .=
'<tr class="liste_titre">';
9955 $htmltoenteralink .=
'<td class="nowrap"></td>';
9956 $htmltoenteralink .=
'<td>' . $langs->trans(
"Ref") .
'</td>';
9957 $htmltoenteralink .=
'<td>' . $langs->trans(
"RefCustomer") .
'</td>';
9958 $htmltoenteralink .=
'<td class="right">' . $langs->trans(
"AmountHTShort") .
'</td>';
9959 $htmltoenteralink .=
'<td>' . $langs->trans(
"Company") .
'</td>';
9960 $htmltoenteralink .=
'</tr>';
9962 $objp = $this->db->fetch_object($resqllist);
9963 $alreadylinked =
false;
9964 if (!empty(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key])) {
9965 if (in_array($objp->rowid, array_values(
$object->linkedObjectsIds[$possiblelink[
'linkname'] ?? $key]))) {
9966 $alreadylinked =
true;
9969 $htmltoenteralink .=
'<tr class="oddeven">';
9970 $htmltoenteralink .=
'<td>';
9971 if ($alreadylinked) {
9972 $htmltoenteralink .=
img_picto(
'',
'link');
9974 $htmltoenteralink .=
'<input type="checkbox" name="idtolinkto[' . $key .
'_' . $objp->rowid .
']" id="' . $key .
'_' . $objp->rowid .
'" value="' . $objp->rowid .
'">';
9976 $htmltoenteralink .=
'</td>';
9977 $htmltoenteralink .=
'<td><label for="' . $key .
'_' . $objp->rowid .
'">' . $objp->ref .
'</label></td>';
9978 $htmltoenteralink .=
'<td>' . (!empty($objp->ref_client) ? $objp->ref_client : (!empty($objp->ref_supplier) ? $objp->ref_supplier :
'')) .
'</td>';
9979 $htmltoenteralink .=
'<td class="right">';
9980 if ($possiblelink[
'label'] ==
'LinkToContract') {
9981 $htmltoenteralink .= $form->textwithpicto(
'', $langs->trans(
"InformationOnLinkToContract")) .
' ';
9983 $htmltoenteralink .=
'<span class="amount">' . (isset($objp->total_ht) ?
price($objp->total_ht) :
'') .
'</span>';
9984 $htmltoenteralink .=
'</td>';
9985 $htmltoenteralink .=
'<td>' . $objp->name .
'</td>';
9986 $htmltoenteralink .=
'</tr>';
9989 $htmltoenteralink .=
'</table>';
9990 $htmltoenteralink .=
'<div class="center">';
9992 $htmltoenteralink .=
'<input type="submit" class="button valignmiddle marginleftonly marginrightonly smallpaddingimp" value="' . $langs->trans(
'ToLink') .
'">';
9994 if (empty(
$conf->use_javascript_ajax)) {
9995 $htmltoenteralink .=
'<input type="submit" class="button button-cancel marginleftonly marginrightonly smallpaddingimp" name="cancel" value="' . $langs->trans(
"Cancel") .
'"></div>';
9997 $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>';
9999 $htmltoenteralink .=
'</form>';
10002 $this->db->free($resqllist);
10006 $htmltoenteralink .=
'</div>';
10011 $linktoelemlist .=
'<li><a href="#linkto' . $key .
'" class="linkto dropdowncloseonclick" rel="' . $key .
'">' . $langs->trans($possiblelink[
'label']) .
' (' . $num .
')</a></li>';
10014 $linktoelemlist .=
'<li><span class="linktodisabled">' . $langs->trans($possiblelink[
'label']) .
' (0)</span></li>';
10019 if ($linktoelemlist) {
10021 <dl class="dropdown" id="linktoobjectname">
10023 if (!empty(
$conf->use_javascript_ajax)) {
10024 $linktoelem .=
'<dt><a href="#linktoobjectname"><span class="fas fa-link paddingrightonly"></span>' . $langs->trans(
"LinkTo") .
'...</a></dt>';
10026 $linktoelem .=
'<dd>
10027 <div class="multiselectlinkto">
10028 <ul class="ulselectedfields">' . $linktoelemlist .
'
10037 if (!empty(
$conf->use_javascript_ajax)) {
10038 print
'<!-- Add js to show linkto box -->
10039 <script nonce="' .
getNonce() .
'">
10040 jQuery(document).ready(function() {
10041 jQuery(".linkto").click(function() {
10042 console.log("We choose to show/hide links for rel="+jQuery(this).attr(\'rel\')+" so #"+jQuery(this).attr(\'rel\')+"list");
10043 jQuery("#"+jQuery(this).attr(\'rel\')+"list").toggle();
10051 return array(
'linktoelem' => $linktoelem,
'htmltoenteralink' => $htmltoenteralink);
10053 print $htmltoenteralink;
10056 return $linktoelem;
10073 public function selectyesno($htmlname, $value =
'', $option = 0, $disabled =
false, $useempty = 0, $addjscombo = 0, $morecss =
'width75', $labelyes =
'Yes', $labelno =
'No')
10084 $disabled = ($disabled ?
' disabled' :
'');
10086 $resultyesno =
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'"' . $disabled .
'>' .
"\n";
10088 $resultyesno .=
'<option value="-1"' . (($value < 0) ?
' selected' :
'') .
'> </option>' .
"\n";
10090 if ((
"$value" ==
'yes') || ($value == 1)) {
10091 $resultyesno .=
'<option value="' . $yes .
'" selected>' . $langs->trans($labelyes) .
'</option>' .
"\n";
10092 $resultyesno .=
'<option value="' . $no .
'">' . $langs->trans($labelno) .
'</option>' .
"\n";
10094 $selected = (($useempty && $value !=
'0' && $value !=
'no') ?
'' :
' selected');
10095 $resultyesno .=
'<option value="' . $yes .
'">' . $langs->trans($labelyes) .
'</option>' .
"\n";
10096 $resultyesno .=
'<option value="' . $no .
'"' . $selected .
'>' . $langs->trans($labelno) .
'</option>' .
"\n";
10098 $resultyesno .=
'</select>' .
"\n";
10101 $resultyesno .=
ajax_combobox($htmlname, array(), 0, 0,
'resolve', ($useempty < 0 ? (
string) $useempty :
'-1'), $morecss);
10104 return $resultyesno;
10121 $sql =
"SELECT rowid, label";
10122 $sql .=
" FROM " . $this->db->prefix() .
"export_model";
10123 $sql .=
" WHERE type = '" . $this->db->escape($type) .
"'";
10124 $sql .=
" ORDER BY rowid";
10125 $result = $this->db->query($sql);
10127 print
'<select class="flat" id="select_' . $htmlname .
'" name="' . $htmlname .
'">';
10129 print
'<option value="-1"> </option>';
10132 $num = $this->db->num_rows($result);
10134 while ($i < $num) {
10135 $obj = $this->db->fetch_object($result);
10136 if ($selected == $obj->rowid) {
10137 print
'<option value="' . $obj->rowid .
'" selected>';
10139 print
'<option value="' . $obj->rowid .
'">';
10169 public function showrefnav(
$object, $paramid, $morehtml =
'', $shownav = 1, $fieldid =
'rowid', $fieldref =
'ref', $morehtmlref =
'', $moreparam =
'', $nodbprefix = 0, $morehtmlleft =
'', $morehtmlstatus =
'', $morehtmlright =
'')
10171 global
$conf, $langs, $hookmanager, $extralanguages;
10174 if (empty($fieldid)) {
10175 $fieldid =
'rowid';
10177 if (empty($fieldref)) {
10182 $addgendertxt =
'';
10183 if (property_exists(
$object,
'gender') && !empty(
$object->gender)) {
10184 $addgendertxt =
' ';
10187 $addgendertxt .=
'<i class="fas fa-mars valignmiddle"></i>';
10190 $addgendertxt .=
'<i class="fas fa-venus valignmiddle"></i>';
10193 $addgendertxt .=
'<i class="fas fa-transgender valignmiddle"></i>';
10199 if (is_object($hookmanager)) {
10200 $parameters = array(
'showrefnav' =>
true);
10201 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters,
$object);
10202 if (!empty($hookmanager->resPrint)) {
10203 if (empty(
$object->next_prev_filter) && preg_match(
'/^\s*AND/i', $hookmanager->resPrint)) {
10204 $object->next_prev_filter = preg_replace(
'/^\s*AND\s*/i',
'', $hookmanager->resPrint);
10205 } elseif (!empty(
$object->next_prev_filter) && !preg_match(
'/^\s*AND/i', $hookmanager->resPrint)) {
10206 $object->next_prev_filter .=
' AND '.$hookmanager->resPrint;
10208 $object->next_prev_filter .= $hookmanager->resPrint;
10213 $previous_ref = $next_ref =
'';
10216 $object->load_previous_next_ref((isset(
$object->next_prev_filter) ?
$object->next_prev_filter :
''), $fieldid, $nodbprefix);
10218 $navurl = $_SERVER[
"PHP_SELF"];
10220 if ($paramid ==
'project_ref') {
10221 if (preg_match(
'/\/tasks\/(task|contact|note|document)\.php/', $navurl)) {
10222 $navurl = preg_replace(
'/\/tasks\/(task|contact|time|note|document)\.php/',
'/tasks.php', $navurl);
10229 $stringforfirstkey = $langs->trans(
"KeyboardShortcut");
10230 if (
$conf->browser->name ==
'chrome') {
10231 $stringforfirstkey .=
' ALT +';
10232 } elseif (
$conf->browser->name ==
'firefox') {
10233 $stringforfirstkey .=
' ALT + SHIFT +';
10235 $stringforfirstkey .=
' CTL +';
10238 $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>';
10239 $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>';
10243 $ret .=
'<!-- Start banner content --><div style="vertical-align: middle">';
10246 if ($morehtmlright) {
10247 $ret .=
'<div class="inline-block floatleft">' . $morehtmlright .
'</div>';
10250 if ($previous_ref || $next_ref || $morehtml) {
10251 $ret .=
'<div class="pagination paginationref"><ul class="right">';
10253 if ($morehtml &&
getDolGlobalInt(
'MAIN_OPTIMIZEFORTEXTBROWSER') < 2) {
10254 $ret .=
'<!-- morehtml --><li class="noborder litext' . (($shownav && $previous_ref && $next_ref) ?
' clearbothonsmartphone' :
'') .
'">' . $morehtml .
'</li>';
10256 if ($shownav && ($previous_ref || $next_ref)) {
10257 $ret .=
'<li class="pagination">' . $previous_ref .
'</li>';
10258 $ret .=
'<li class="pagination">' . $next_ref .
'</li>';
10260 if ($previous_ref || $next_ref || $morehtml) {
10261 $ret .=
'</ul></div>';
10265 $parameters = array(
'morehtmlstatus' => $morehtmlstatus);
10266 $reshook = $hookmanager->executeHooks(
'moreHtmlStatus', $parameters,
$object);
10267 if (empty($reshook)) {
10268 $morehtmlstatus .= $hookmanager->resPrint;
10270 $morehtmlstatus = $hookmanager->resPrint;
10272 if ($morehtmlstatus) {
10273 $ret .=
'<div class="statusref">' . $morehtmlstatus .
'</div>';
10276 $parameters = array();
10277 $reshook = $hookmanager->executeHooks(
'moreHtmlRef', $parameters,
$object);
10278 if (empty($reshook)) {
10279 $morehtmlref .= $hookmanager->resPrint;
10280 } elseif ($reshook > 0) {
10281 $morehtmlref = $hookmanager->resPrint;
10285 if ($morehtmlleft) {
10286 if (
$conf->browser->layout ==
'phone') {
10287 $ret .=
'<!-- morehtmlleft --><div class="floatleft">' . $morehtmlleft .
'</div>';
10289 $ret .=
'<!-- morehtmlleft --><div class="inline-block floatleft">' . $morehtmlleft .
'</div>';
10294 $ret .=
'<div class="inline-block floatleft valignmiddle maxwidth750 marginbottomonly refid' . (($shownav && ($previous_ref || $next_ref)) ?
' refidpadding' :
'') .
'">';
10297 if (
$object->element ==
'societe') {
10301 $arrayoflangcode = array();
10306 if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
10307 if (!is_object($extralanguages)) {
10308 include_once DOL_DOCUMENT_ROOT .
'/core/class/extralanguages.class.php';
10311 $extralanguages->fetch_name_extralanguages(
'societe');
10313 if (!empty($extralanguages->attributes[
'societe'][
'name'])) {
10314 $object->fetchValuesForExtraLanguages();
10318 foreach ($arrayoflangcode as $extralangcode) {
10320 if (
$object->array_languages[
'name'][$extralangcode]) {
10321 $htmltext .=
$object->array_languages[
'name'][$extralangcode];
10323 $htmltext .=
'<span class="opacitymedium">' . $langs->trans(
"SwitchInEditModeToAddTranslation") .
'</span>';
10326 $ret .=
'<!-- Show translations of name -->' .
"\n";
10327 $ret .= $this->textwithpicto(
'', $htmltext, -1,
'language',
'opacitymedium paddingleft');
10330 } elseif (
$object->element ==
'member') {
10331 '@phan-var-force Adherent $object';
10332 $ret .=
$object->ref .
'<br>';
10333 $fullname =
$object->getFullName($langs);
10339 } elseif (in_array(
$object->element, array(
'contact',
'user'))) {
10340 $ret .=
'<span class="valignmiddle">'.dol_htmlentities(
$object->getFullName($langs)).
'</span>'.$addgendertxt;
10341 } elseif (
$object->element ==
'usergroup') {
10343 } elseif (in_array(
$object->element, array(
'action',
'agenda'))) {
10344 '@phan-var-force ActionComm $object';
10346 } elseif (in_array(
$object->element, array(
'adherent_type'))) {
10348 } elseif (
$object->element ==
'ecm_directories') {
10350 } elseif ($fieldref !=
'none') {
10353 if ($morehtmlref) {
10355 if (substr($morehtmlref, 0, 4) !=
'<div') {
10359 $ret .=
'<!-- morehtmlref -->'.$morehtmlref;
10364 $ret .=
'</div><!-- End banner content -->';
10383 if (empty(
$object->barcode)) {
10388 if (empty(
$object->barcode_type_code) || empty(
$object->barcode_type_coder)) {
10390 $result =
$object->fetchBarCode();
10393 return '<!-- ErrorFetchBarcode -->';
10398 $url = DOL_URL_ROOT .
'/viewimage.php?modulepart=barcode&generator=' . urlencode(
$object->barcode_type_coder) .
'&code=' . urlencode(
$object->barcode) .
'&encoding=' . urlencode(
$object->barcode_type_code);
10399 $out =
'<!-- url barcode = ' . $url .
' -->';
10400 $out .=
'<img src="' . $url .
'"' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
'>';
10422 public static function showphoto($modulepart,
$object, $width = 100, $height = 0, $caneditfield = 0, $cssclass =
'photowithmargin', $imagesize =
'', $addlinktofullsize = 1, $cache = 0, $forcecapture =
'', $noexternsourceoverwrite = 0)
10424 global
$conf, $langs;
10431 $originalfile =
'';
10435 if ($modulepart ==
'societe') {
10436 $dir =
$conf->societe->multidir_output[$entity];
10439 if ((
string) $imagesize ==
'mini') {
10441 } elseif ((
string) $imagesize ==
'small') {
10450 } elseif ($modulepart ==
'contact') {
10451 $dir =
$conf->societe->multidir_output[$entity] .
'/contact';
10452 if (!empty(
$object->photo)) {
10454 if ((
string) $imagesize ==
'mini') {
10456 } elseif ((
string) $imagesize ==
'small') {
10466 } elseif ($modulepart ==
'userphoto') {
10467 $dir =
$conf->user->dir_output;
10468 if (!empty(
$object->photo)) {
10470 if ((
string) $imagesize ==
'mini') {
10472 } elseif ((
string) $imagesize ==
'small') {
10481 $altfile =
$object->id .
".jpg";
10485 } elseif ($modulepart ==
'memberphoto') {
10486 $dir =
$conf->adherent->dir_output;
10487 if (!empty(
$object->photo)) {
10489 if ((
string) $imagesize ==
'mini') {
10491 } elseif ((
string) $imagesize ==
'small') {
10500 $altfile =
$object->id .
".jpg";
10507 if ($modulepart !=
"unknown" && method_exists(
$object,
'getDataToShowPhoto')) {
10508 $tmpdata =
$object->getDataToShowPhoto($modulepart, $imagesize);
10510 $dir = $tmpdata[
'dir'];
10511 $file = $tmpdata[
'file'];
10512 $originalfile = $tmpdata[
'originalfile'];
10513 $altfile = $tmpdata[
'altfile'];
10514 $email = $tmpdata[
'email'];
10515 $capture = $tmpdata[
'capture'];
10519 if ($forcecapture) {
10520 $capture = $forcecapture;
10526 if ($file && file_exists($dir .
"/" . $file)) {
10527 if ($addlinktofullsize) {
10529 if ($urladvanced) {
10530 $ret .=
'<a href="' . $urladvanced .
'">';
10532 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
10535 $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 .
'">';
10536 if ($addlinktofullsize) {
10539 } elseif ($altfile && file_exists($dir .
"/" . $altfile)) {
10540 if ($addlinktofullsize) {
10542 if ($urladvanced) {
10543 $ret .=
'<a href="' . $urladvanced .
'">';
10545 $ret .=
'<a href="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=' . $modulepart .
'&entity=' . $entity .
'&file=' . urlencode($originalfile) .
'&cache=' . $cache .
'">';
10548 $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 .
'">';
10549 if ($addlinktofullsize) {
10553 $nophoto =
'/public/theme/common/nophoto.png';
10554 $defaultimg =
'identicon';
10555 if (in_array($modulepart, array(
'societe',
'userphoto',
'contact',
'memberphoto'))) {
10556 if ($modulepart ==
'societe' || ($modulepart ==
'memberphoto' && !empty(
$object->morphy) && strpos(
$object->morphy,
'mor') !==
false)) {
10557 $nophoto =
'company';
10559 $nophoto =
'/public/theme/common/user_anonymous.png';
10561 $nophoto =
'/public/theme/common/user_man.png';
10564 $nophoto =
'/public/theme/common/user_woman.png';
10569 if (isModEnabled(
'gravatar') && $email && empty($noexternsourceoverwrite)) {
10571 $ret .=
'<!-- Put link to gravatar -->';
10572 $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 .
'">';
10574 if ($nophoto ==
'company') {
10575 $ret .=
'<div class="divforspanimg valignmiddle center photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
'>' .
img_picto(
'',
'company') .
'</div>';
10578 $ret .=
'<img class="photo' . $modulepart . ($cssclass ?
' ' . $cssclass :
'') .
'" alt="" ' . ($width ?
' width="' . $width .
'"' :
'') . ($height ?
' height="' . $height .
'"' :
'') .
' src="' . DOL_URL_ROOT . $nophoto .
'">';
10583 if ($caneditfield) {
10587 $ret .=
'<table class="nobordernopadding centpercent">';
10589 $ret .=
'<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> <label for="photodelete">' . $langs->trans(
"Delete") .
'</label><br><br></td></tr>';
10591 $ret .=
'<tr><td class="tdoverflow">';
10593 $maxmin = $maxfilesizearray[
'maxmin'];
10595 $ret .=
'<input type="hidden" name="MAX_FILE_SIZE" value="' . ($maxmin * 1024) .
'">';
10597 $ret .=
'<input type="file" class="flat maxwidth200onsmartphone" name="photo" id="photoinput" accept="image/*"' . ($capture ?
' capture="' . $capture .
'"' :
'') .
'>';
10598 $ret .=
'</td></tr>';
10599 $ret .=
'</table>';
10624 public function select_dolgroups($selected = 0, $htmlname =
'groupid', $show_empty = 0, $exclude =
'', $disabled = 0, $include =
'', $enableonly = array(), $force_entity =
'0', $multiple =
false, $morecss =
'minwidth200')
10627 global
$conf, $user, $langs;
10630 $excludeGroups =
null;
10631 if (is_array($exclude)) {
10632 $excludeGroups = implode(
",", $exclude);
10635 $includeGroups =
null;
10636 if (is_array($include)) {
10637 $includeGroups = implode(
",", $include);
10640 if (!is_array($selected)) {
10641 $selected = array($selected);
10647 $sql =
"SELECT ug.rowid, ug.nom as name";
10648 if (isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && !$user->entity) {
10649 $sql .=
", e.label";
10651 $sql .=
" FROM " . $this->db->prefix() .
"usergroup as ug ";
10652 if (isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && !$user->entity) {
10653 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid=ug.entity";
10654 if ($force_entity) {
10655 $sql .=
" WHERE ug.entity IN (0, " . $force_entity .
")";
10657 $sql .=
" WHERE ug.entity IS NOT NULL";
10660 $sql .=
" WHERE ug.entity IN (0, " .
$conf->entity .
")";
10662 if (is_array($exclude) && $excludeGroups) {
10663 $sql .=
" AND ug.rowid NOT IN (" . $this->db->sanitize($excludeGroups) .
")";
10665 if (is_array($include) && $includeGroups) {
10666 $sql .=
" AND ug.rowid IN (" . $this->db->sanitize($includeGroups) .
")";
10668 $sql .=
" ORDER BY ug.nom ASC";
10670 dol_syslog(get_class($this) .
"::select_dolgroups", LOG_DEBUG);
10671 $resql = $this->db->query($sql);
10674 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
10676 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
10678 $num = $this->db->num_rows($resql);
10681 if ($show_empty && !$multiple) {
10682 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'> </option>' .
"\n";
10685 while ($i < $num) {
10686 $obj = $this->db->fetch_object($resql);
10688 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
10692 $label = $obj->name;
10693 $labelhtml = $obj->name;
10694 if (isModEnabled(
'multicompany') && !
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE') &&
$conf->entity == 1) {
10695 $label .=
" (" . $obj->label .
")";
10696 $labelhtml .=
' <span class="opacitymedium">(' . $obj->label .
')</span>';
10699 $out .=
'<option value="' . $obj->rowid .
'"';
10700 if ($disableline) {
10701 $out .=
' disabled';
10703 if ((isset($selected[0]) && is_object($selected[0]) && $selected[0]->
id == $obj->rowid)
10704 || ((!isset($selected[0]) || !is_object($selected[0])) && !empty($selected) && in_array($obj->rowid, $selected))) {
10705 $out .=
' selected';
10707 $out .=
' data-html="'.dol_escape_htmltag($labelhtml).
'"';
10710 $out .=
'</option>';
10715 $out .=
'<option value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'></option>' .
"\n";
10717 $out .=
'<option value="" disabled>' . $langs->trans(
"NoUserGroupDefined") .
'</option>';
10719 $out .=
'</select>';
10738 $out =
'<div class="nowraponall">';
10739 $out .=
'<button type="submit" class="liste_titre button_search reposition" name="button_search_x" value="x"><span class="fas fa-search"></span></button>';
10740 $out .=
'<button type="submit" class="liste_titre button_removefilter reposition" name="button_removefilter_x" value="x"><span class="fas fa-times"></span></button>';
10754 public function showCheckAddButtons($cssclass =
'checkforaction', $calljsfunction = 0, $massactionname =
"massaction")
10760 if (!empty(
$conf->use_javascript_ajax)) {
10761 $out .=
'<div class="inline-block checkallactions"><input type="checkbox" id="' . $cssclass .
's" name="' . $cssclass .
's" class="checkallactions"></div>';
10763 $out .=
'<script nonce="' .
getNonce() .
'">
10764 $(document).ready(function() {
10765 $("#' . $cssclass .
's").click(function() {
10766 if($(this).is(\':checked\')){
10767 console.log("We check all ' . $cssclass .
' and trigger the change method");
10768 $(".' . $cssclass .
'").prop(\'checked\', true).trigger(\'change\');
10772 console.log("We uncheck all");
10773 $(".' . $cssclass .
'").prop(\'checked\', false).trigger(\'change\');
10775 if ($calljsfunction) {
10776 $out .=
'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0, "' . $massactionname .
'", "' . $cssclass .
'"); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }';
10779 $(".' . $cssclass .
'").change(function() {
10780 $(this).closest("tr").toggleClass("highlight", this.checked);
10799 $out = $this->showFilterButtons();
10800 if ($addcheckuncheckall) {
10801 $out .= $this->showCheckAddButtons($cssclass, $calljsfunction, $massactionname);
10819 public function selectExpenseCategories($selected =
'', $htmlname =
'fk_c_exp_tax_cat', $useempty = 0, $excludeid = array(), $target =
'', $default_selected = 0, $params = array(), $info_admin = 1)
10821 global $langs, $user;
10824 $sql =
"SELECT rowid, label FROM " . $this->db->prefix() .
"c_exp_tax_cat WHERE active = 1";
10825 $sql .=
" AND entity IN (0," .
getEntity(
'exp_tax_cat') .
")";
10826 if (!empty($excludeid)) {
10827 $sql .=
" AND rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeid)) .
")";
10829 $sql .=
" ORDER BY label";
10831 $resql = $this->db->query($sql);
10833 $out =
'<select id="select_' . $htmlname .
'" name="' . $htmlname .
'" class="' . $htmlname .
' flat minwidth75imp maxwidth200">';
10835 $out .=
'<option value="0"> </option>';
10838 while ($obj = $this->db->fetch_object($resql)) {
10839 $out .=
'<option ' . ($selected == $obj->rowid ?
'selected="selected"' :
'') .
' value="' . $obj->rowid .
'">' . $langs->trans($obj->label) .
'</option>';
10841 $out .=
'</select>';
10844 if (!empty($htmlname) && $user->admin && $info_admin) {
10845 $out .=
' ' .
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
10848 if (!empty($target)) {
10849 $sql =
"SELECT c.id FROM " . $this->db->prefix() .
"c_type_fees as c WHERE c.code = 'EX_KME' AND c.active = 1";
10850 $resql = $this->db->query($sql);
10852 if ($this->db->num_rows($resql) > 0) {
10853 $obj = $this->db->fetch_object($resql);
10854 $out .=
'<script nonce="' .
getNonce() .
'">
10856 $("select[name=' . $target .
']").on("change", function() {
10857 var current_val = $(this).val();
10858 if (current_val == ' . $obj->id .
') {';
10859 if (!empty($default_selected) || !empty($selected)) {
10860 $out .=
'$("select[name=' . $htmlname .
']").val("' . ($default_selected > 0 ? $default_selected : $selected) .
'");';
10864 $("select[name=' . $htmlname .
']").change();
10868 $("select[name=' . $htmlname .
']").change(function() {
10870 if ($("select[name=' . $target .
']").val() == ' . $obj->id .
') {
10871 // get price of kilometer to fill the unit price
10875 data: { fk_c_exp_tax_cat: $(this).val(), token: \'' .
currentToken() .
'\' },
10876 url:
"' . (DOL_URL_ROOT . '/expensereport/ajax/ajaxik.php?' . implode('&', $params)) . '",
10877 }).done(
function( data, textStatus, jqXHR ) {
10879 if (typeof data.up !=
"undefined") {
10880 $(
"input[name=value_unit]").val(data.up);
10881 $(
"select[name=' . $htmlname . ']").attr(
"title", data.title);
10883 $(
"input[name=value_unit]").val(
"");
10884 $(
"select[name=' . $htmlname . ']").attr(
"title",
"");
10895 dol_print_error($this->db);
10909 public function selectExpenseRanges($selected = '
', $htmlname = 'fk_range
', $useempty = 0)
10911 global $conf, $langs;
10914 $sql = "SELECT rowid, range_ik FROM " . $this->db->prefix() . "c_exp_tax_range";
10915 $sql .= " WHERE entity = " . $conf->entity . " AND active = 1";
10917 $resql = $this->db->query($sql);
10919 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
10921 $out .= '<option value=
"0"></option>
';
10924 while ($obj = $this->db->fetch_object($resql)) {
10925 $out .= '<option
' . ($selected == $obj->rowid ? 'selected=
"selected"' : '') . ' value=
"' . $obj->rowid . '">
' . price($obj->range_ik, 0, $langs, 1, 0) . '</option>
';
10927 $out .= '</select>
';
10929 dol_print_error($this->db);
10945 public function selectExpense($selected = '
', $htmlname = 'fk_c_type_fees
', $useempty = 0, $allchoice = 1, $useid = 0)
10950 $sql = "SELECT id, code, label";
10951 $sql .= " FROM ".$this->db->prefix()."c_type_fees";
10952 $sql .= " WHERE active = 1";
10954 $resql = $this->db->query($sql);
10956 $out = '<select
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
';
10958 $out .= '<option value=
"0"></option>
';
10961 $out .= '<option value=
"-1">
' . $langs->trans('AllExpenseReport
') . '</option>
';
10969 while ($obj = $this->db->fetch_object($resql)) {
10970 $key = $langs->trans($obj->code);
10971 $out .= '<option
' . ($selected == $obj->{$field} ? 'selected=
"selected"' : '') . ' value=
"' . $obj->{$field} . '">
' . ($key != $obj->code ? $key : $obj->label) . '</option>
';
10973 $out .= '</select>
';
10975 $out .= ajax_combobox('select_
'.$htmlname);
10977 dol_print_error($this->db);
11001 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)
11003 global $user, $conf, $langs;
11005 require_once DOL_DOCUMENT_ROOT . '/projet/
class/project.class.php
';
11007 if (is_null($usertofilter)) {
11008 $usertofilter = $user;
11013 $hideunselectables = false;
11014 if (getDolGlobalString('PROJECT_HIDE_UNSELECTABLES
')) {
11015 $hideunselectables = true;
11018 if (empty($projectsListId)) {
11019 if (!$usertofilter->hasRight('projet
', 'all
', 'lire
')) {
11020 $projectstatic = new Project($this->db);
11021 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1);
11025 // Search all projects
11026 $sql = "SELECT f.rowid, f.ref as fref, 'nolabel
' as flabel, p.rowid as pid, f.ref,
11027 p.title, p.fk_soc, p.fk_statut, p.public,";
11028 $sql .= ' s.nom as
name';
11029 $sql .= ' FROM
' . $this->db->prefix() . 'projet as p
';
11030 $sql .= ' LEFT JOIN
' . $this->db->prefix() . 'societe as s ON s.rowid = p.fk_soc,
';
11031 $sql .= ' ' . $this->db->prefix() . 'facture as f
';
11032 $sql .= " WHERE p.entity IN (" . getEntity('project
') . ")";
11033 $sql .= " AND f.fk_projet = p.rowid AND f.fk_statut=0"; //Brouillons seulement
11034 //if ($projectsListId) $sql.= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")";
11035 //if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
11036 //if ($socid > 0) $sql.= " AND (p.fk_soc=".((int) $socid)." OR p.fk_soc IS NULL)";
11037 $sql .= " ORDER BY p.ref, f.ref ASC";
11039 $resql = $this->db->query($sql);
11041 // Use select2 selector
11042 if (!empty($conf->use_javascript_ajax)) {
11043 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
';
11044 $comboenhancement = ajax_combobox($htmlname, array(), 0, $forcefocus);
11045 $out .= $comboenhancement;
11046 $morecss = 'minwidth200imp maxwidth500
';
11049 if (empty($option_only)) {
11050 $out .= '<select
class=
"valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled=
"disabled"' : '') . ' id=
"' . $htmlname . '" name=
"' . $htmlname . '">
';
11052 if (!empty($show_empty)) {
11053 $out .= '<option value=
"0" class=
"optiongrey">
';
11054 if (!is_numeric($show_empty)) {
11055 $out .= $show_empty;
11059 $out .= '</option>
';
11061 $num = $this->db->num_rows($resql);
11064 while ($i < $num) {
11065 $obj = $this->db->fetch_object($resql);
11066 // 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.
11067 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$usertofilter->hasRight('societe
', 'lire
')) {
11070 if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) {
11077 if ($showproject == 'all
') {
11078 $labeltoshow .= dol_trunc($obj->ref, 18); // Invoice ref
11080 $labeltoshow .= ' -
' . $obj->name; // Soc name
11084 if ($obj->fk_statut == Project::STATUS_DRAFT) {
11086 $labeltoshow .= ' -
' . $langs->trans("Draft");
11087 } elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
11088 if ($discard_closed == 2) {
11091 $labeltoshow .= ' -
' . $langs->trans("Closed");
11092 } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
11094 $labeltoshow .= ' -
' . $langs->trans("LinkedToAnotherCompany");
11098 if (!empty($selected) && $selected == $obj->rowid) {
11099 $out .= '<option value=
"' . $obj->rowid . '" selected
';
11100 //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected
if disabled
11101 $out .=
'>' . $labeltoshow .
'</option>';
11103 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
11106 $resultat =
'<option value="' . $obj->rowid .
'"';
11108 $resultat .=
' disabled';
11113 $resultat .= $labeltoshow;
11114 $resultat .=
'</option>';
11122 if (empty($option_only)) {
11123 $out .=
'</select>';
11126 $this->db->free($resql);
11148 public function selectInvoiceRec($selected =
'', $htmlname =
'facrecid', $maxlength = 24, $option_only = 0, $show_empty =
'1', $forcefocus = 0, $disabled = 0, $morecss =
'maxwidth500')
11150 global
$conf, $langs;
11156 $sql =
'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc';
11158 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'facture_rec as f';
11159 $sql .=
" WHERE f.entity IN (" .
getEntity(
'invoice') .
")";
11160 $sql .=
" ORDER BY f.titre ASC";
11162 $resql = $this->db->query($sql);
11165 if (!empty(
$conf->use_javascript_ajax)) {
11166 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
11167 $comboenhancement =
ajax_combobox($htmlname, array(), 0, $forcefocus);
11168 $out .= $comboenhancement;
11169 $morecss =
'minwidth200imp maxwidth500';
11172 if (empty($option_only)) {
11173 $out .=
'<select class="valignmiddle flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($disabled ?
' disabled="disabled"' :
'') .
' id="' . $htmlname .
'" name="' . $htmlname .
'">';
11175 if (!empty($show_empty)) {
11176 $out .=
'<option value="0" class="optiongrey">';
11177 if (!is_numeric($show_empty)) {
11178 $out .= $show_empty;
11182 $out .=
'</option>';
11184 $num = $this->db->num_rows($resql);
11186 while ($obj = $this->db->fetch_object($resql)) {
11187 $labeltoshow =
dol_trunc($obj->title, 18);
11190 if (!empty($obj->suspended)) {
11192 $labeltoshow .=
' - ' . $langs->trans(
"Closed");
11196 if (!empty($selected) && $selected == $obj->rowid) {
11197 $out .=
'<option value="' . $obj->rowid .
'" selected';
11199 $out .=
'>' . $labeltoshow .
'</option>';
11201 if ($disabled && ($selected != $obj->rowid)) {
11204 $resultat =
'<option value="' . $obj->rowid .
'"';
11206 $resultat .=
' disabled';
11209 $resultat .= $labeltoshow;
11210 $resultat .=
'</option>';
11216 if (empty($option_only)) {
11217 $out .=
'</select>';
11222 $this->db->free($resql);
11225 $this->errors[] = $this->db->lasterror;
11240 public function searchComponent($arrayofcriterias, $search_component_params, $arrayofinputfieldsalreadyoutput = array(), $search_component_params_hidden =
'', $arrayoffiltercriterias = array())
11243 global $langs, $form;
11245 require_once DOL_DOCUMENT_ROOT.
"/core/class/html.formother.class.php";
11248 if ($search_component_params_hidden !=
'' && !preg_match(
'/^\(.*\)$/', $search_component_params_hidden)) {
11249 $search_component_params_hidden =
'(' . $search_component_params_hidden .
')';
11252 $ret =
'<!-- searchComponent -->';
11254 $ret .=
'<div class="divadvancedsearchfieldcomp centpercent inline-block">';
11255 $ret .=
'<a href="#" class="dropdownsearch-toggle unsetcolor">';
11256 $ret .=
'<span class="fas fa-filter linkobject boxfilter paddingright pictofixedwidth" title="' .
dol_escape_htmltag($langs->trans(
"Filters")) .
'" id="idsubimgproductdistribution"></span>';
11259 $ret .=
'<div class="divadvancedsearchfieldcompinput inline-block minwidth500 maxwidth300onsmartphone">';
11262 $ret .=
'<div id="divsearch_component_params" name="divsearch_component_params" class="noborderbottom search_component_params inline-block valignmiddle">';
11264 if ($search_component_params_hidden) {
11272 foreach ($arrayofandtags as $tmpkey => $tmpval) {
11273 $errormessage =
'';
11275 if ($errormessage) {
11276 $this->error =
'ERROR in parsing search string: '.$errormessage;
11279 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
11282 $ret .=
'<span class="marginleftonlyshort valignmiddle tagsearch" data-ufilterid="'.($tmpkey + 1).
'" data-ufilter="'.
dol_escape_htmltag($tmpval).
'">';
11283 $ret .=
'<span class="tagsearchdelete select2-selection__choice__remove" data-ufilterid="'.($tmpkey + 1).
'">x</span> ';
11295 $show_search_component_params_hidden = 1;
11296 if ($show_search_component_params_hidden) {
11297 $ret .=
'<input type="hidden" name="show_search_component_params_hidden" value="1">';
11299 $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%')) -->";
11300 $ret .=
'<input type="hidden" id="search_component_params_hidden" name="search_component_params_hidden" value="' .
dol_escape_htmltag($search_component_params_hidden) .
'">';
11305 foreach ($arrayofcriterias as $criteria) {
11306 foreach ($criteria as $criteriafamilykey => $criteriafamilyval) {
11307 if (in_array(
'search_' . $criteriafamilykey, $arrayofinputfieldsalreadyoutput)) {
11310 if (in_array($criteriafamilykey, array(
'rowid',
'ref_ext',
'entity',
'extraparams'))) {
11313 if (in_array($criteriafamilyval[
'type'], array(
'date',
'datetime',
'timestamp'))) {
11314 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_start">';
11315 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startyear">';
11316 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startmonth">';
11317 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_startday">';
11318 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_end">';
11319 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endyear">';
11320 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endmonth">';
11321 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'_endday">';
11323 $ret .=
'<input type="hidden" name="search_' . $criteriafamilykey .
'">';
11330 $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";
11331 $ret .=
'<input type="text" placeholder="' . $langs->trans(
"Filters") .
'" id="search_component_params_input" name="search_component_params_input" class="noborderbottom search_component_input" value="">';
11337 jQuery(".tagsearchdelete").click(function(e) {
11338 var filterid = $(this).parents().attr("data-ufilterid");
11339 console.log("We click to delete the criteria nb "+filterid);
11341 // Regenerate the search_component_params_hidden with all data-ufilter except the one to delete, and post the page
11342 var newparamstring = \'\';
11343 $(\'.tagsearch\').each(function(index, element) {
11344 tmpfilterid = $(this).attr("data-ufilterid");
11345 if (tmpfilterid != filterid) {
11346 // We keep this criteria
11347 if (newparamstring == \'\') {
11348 newparamstring = $(this).attr("data-ufilter");
11350 newparamstring = newparamstring + \' AND \' + $(this).attr("data-ufilter");
11354 console.log("newparamstring = "+newparamstring);
11356 jQuery("#search_component_params_hidden").val(newparamstring);
11358 // We repost the form
11359 $(this).closest(\'form\').submit();
11362 jQuery("#search_component_params_input").keydown(function(e) {
11363 console.log("We press a key on the filter field that is "+jQuery("#search_component_params_input").val());
11364 console.log(e.which);
11365 if (jQuery("#search_component_params_input").val() == "" && e.which == 8) {
11366 /* We click on back when the input field is already empty */
11367 event.preventDefault();
11368 jQuery("#divsearch_component_params .tagsearch").last().remove();
11369 /* Regenerate content of search_component_params_hidden from remaining .tagsearch */
11371 jQuery("#divsearch_component_params .tagsearch").each(function( index ) {
11375 s = s + $(this).attr("data-ufilter");
11377 console.log("New value for search_component_params_hidden = "+s);
11378 jQuery("#search_component_params_hidden").val(s);
11386 $arrayoffiltercriterias_json = json_encode($arrayoffiltercriterias);
11388 var arrayoffiltercriterias = ' . $arrayoffiltercriterias_json .
';
11392 $arrayoffilterfieldslabel = array();
11393 foreach ($arrayoffiltercriterias as $key => $val) {
11394 $arrayoffilterfieldslabel[$key][
'label'] = $val[
'label'];
11395 $arrayoffilterfieldslabel[$key][
'data-type'] = $val[
'type'];
11399 $ret .=
'<div class="search-component-assistance">';
11402 $ret .=
'<p class="assistance-title">' .
img_picto(
'',
'filter') .
' ' . $langs->trans(
'FilterAssistance') .
' </p>';
11404 $ret .=
'<p class="assistance-errors error" style="display:none">' . $langs->trans(
'AllFieldsRequired') .
' </p>';
11406 $ret .=
'<div class="operand">';
11407 $ret .= $form->selectarray(
'search_filter_field', $arrayoffilterfieldslabel,
'', $langs->trans(
"Fields"), 0, 0,
'', 0, 0, 0,
'',
'width200 combolargeelem', 1);
11410 $ret .=
'<span class="separator"></span>';
11413 $ret .=
'<div class="operator">';
11414 $ret .=
'<select class="operator-selector width150" id="operator-selector"">';
11415 $ret .=
'</select>';
11416 $ret .=
'<script>$(document).ready(function() {';
11417 $ret .=
' $(".operator-selector").select2({';
11418 $ret .=
' placeholder: \'' .
dol_escape_js($langs->trans(
'Operator')) .
'\'';
11420 $ret .=
'});</script>';
11423 $ret .=
'<span class="separator"></span>';
11425 $ret .=
'<div class="value">';
11427 $ret .=
'<input type="text" class="flat width100 value-input" placeholder="' .
dolPrintHTML($langs->trans(
'Value')) .
'">';
11431 $ret .=
'<span class="date-one" style="display:none">';
11432 $ret .= $form->selectDate(($dateOne ? $dateOne : -1),
'dateone', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'');
11436 $ret .=
'<select class="value-selector width150" id="value-selector" style="display:none">';
11437 $ret .=
'</select>';
11439 $(document).ready(function() {
11440 $("#value-selector").select2({
11441 placeholder: "' .
dol_escape_js($langs->trans(
'Value')) .
'"
11443 $("#value-selector").hide();
11444 $("#value-selector").next(".select2-container").hide();
11450 $ret .=
'<div class="btn-div">';
11451 $ret .=
'<button class="button buttongen button-save add-filter-btn" type="button">' . $langs->trans(
"addToFilter") .
'</button>';
11462 $(document).ready(function() {
11463 $("#search_component_params_input").on("click", function() {
11464 const inputPosition = $(this).offset();
11465 const inputHeight = $(this).outerHeight();
11466 $(".search-component-assistance").css({
11467 top: inputPosition.top + inputHeight + 5 + "px",
11468 left: $("#divsearch_component_params").position().left
11469 }).slideToggle(200);
11471 $(document).on("click", function(e) {
11472 if (!$(e.target).closest("#search_component_params_input, .search-component-assistance, #ui-datepicker-div").length) {
11473 $(".search-component-assistance").hide();
11480 $(document).ready(function() {
11481 $(".search_filter_field").on("change", function() {
11483 const selectedField = $(this).find(":selected");
11484 let fieldType = selectedField.data("type");
11485 const selectedFieldValue = selectedField.val();
11487 // If the selected field has an array of values then ask toshow the value selector instead of the value input
11488 if (arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"] !== undefined) {
11489 fieldType = "select";
11492 // If the selected field may be null then ask to append the "IsDefined" and "IsNotDefined" operators
11493 if (arrayoffiltercriterias[selectedFieldValue]["maybenull"] !== undefined) {
11496 const operators = getOperatorsForFieldType(fieldType, maybenull);
11497 const operatorSelector = $(".operator-selector");
11499 // Clear existing options
11500 operatorSelector.empty();
11502 // Populate operators
11503 Object.entries(operators).forEach(function([operator, label]) {
11504 operatorSelector.append("<option value=\'" + operator + "\'>" + label + "</option>");
11507 operatorSelector.trigger("change.select2");
11509 // Clear and hide all input elements initially
11510 $(".value-input, .dateone, .datemonth, .dateyear").val("").hide();
11511 $("#datemonth, #dateyear").val(null).trigger("change.select2");
11512 $("#dateone").datepicker("setDate", null);
11513 $(".date-one, .date-month, .date-year").hide();
11514 $("#value-selector").val("").hide();
11515 $("#value-selector").next(".select2-container").hide();
11516 $("#value-selector").val(null).trigger("change.select2");
11518 if (fieldType === "date" || fieldType === "datetime" || fieldType === "timestamp") {
11519 $(".date-one").show();
11520 } else if (arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"] !== undefined) {
11521 var arrayofkeyval = arrayoffiltercriterias[selectedFieldValue]["arrayofkeyval"];
11522 var valueSelector = $("#value-selector");
11523 valueSelector.empty();
11524 Object.entries(arrayofkeyval).forEach(function([key, val]) {
11525 valueSelector.append("<option value=\'" + key + "\'>" + val + "</option>");
11527 valueSelector.trigger("change.select2");
11529 $("#value-selector").show();
11530 $("#value-selector").next(".select2-container").show();
11532 $(".value-input").show();
11536 $("#operator-selector").on("change", function() {
11537 const selectedOperator = $(this).find(":selected").val();
11538 if (selectedOperator === "IsDefined" || selectedOperator === "IsNotDefined") {
11539 // Disable all value input elements
11540 $(".value-input, .dateone, .datemonth, .dateyear").val("").prop("disabled", true);
11541 $("#datemonth, #dateyear").val(null).trigger("change.select2");
11542 $("#dateone").datepicker("setDate", null).datepicker("option", "disabled", true);
11543 $(".date-one, .date-month, .date-year").prop("disabled", true);
11544 $("#value-selector").val("").prop("disabled", true);
11545 $("#value-selector").val(null).trigger("change.select2");
11547 // Enable all value input elements
11548 $(".value-input, .dateone, .datemonth, .dateyear").prop("disabled", false);
11549 $(".date-one, .date-month, .date-year").prop("disabled", false);
11550 $("#dateone").datepicker("option", "disabled", false);
11551 $("#value-selector").prop("disabled", false);
11555 $(".add-filter-btn").on("click", function(event) {
11556 event.preventDefault();
11558 const field = $(".search_filter_field").val();
11559 const operator = $(".operator-selector").val();
11560 let value = $(".value-input").val();
11561 const fieldType = $(".search_filter_field").find(":selected").data("type");
11563 if (["date", "datetime", "timestamp"].includes(fieldType)) {
11564 const parsedDate = new Date($("#dateone").val());
11565 if (!isNaN(parsedDate)) {
11566 const year = parsedDate.getFullYear();
11567 const month = String(parsedDate.getMonth() + 1).padStart(2, "0");
11568 const day = String(parsedDate.getDate()).padStart(2, "0");
11569 value = `${year}-${month}-${day}`;
11573 // If the selected field has an array of values then take the selected value
11574 if (arrayoffiltercriterias[field]["arrayofkeyval"] !== undefined) {
11575 value = $("#value-selector").val();
11578 // If the operator is "IsDefined" or "IsNotDefined" then set the value to 1 (it will not be used)
11579 if (operator === "IsDefined" || operator === "IsNotDefined") {
11583 const filterString = generateFilterString(field, operator, value, fieldType);
11586 if (filterString !== "" && field !== "" && operator !== "" && value !== "") {
11587 $("#search_component_params_input").val($("#search_component_params_input").val() + " " + filterString);
11588 $("#search_component_params_input").closest("form").submit();
11590 $(".assistance-errors").show();
11609 public function selectModelMail($prefix, $modelType =
'', $default = 0, $addjscombo = 0, $selected =
'')
11611 global $langs, $user;
11615 $TModels = array();
11617 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
11618 $formmail =
new FormMail($this->db);
11619 $result = $formmail->fetchAllEMailTemplate($modelType, $user, $langs);
11622 $TModels[0] = $langs->trans(
'DefaultMailModel');
11625 foreach ($formmail->lines_model as $model) {
11626 $TModels[$model->id] = $model->label;
11630 $retstring .=
'<select class="flat" id="select_' . $prefix .
'model_mail" name="' . $prefix .
'model_mail">';
11632 foreach ($TModels as $id_model => $label_model) {
11633 $retstring .=
'<option value="' . $id_model .
'"';
11634 if (!empty($selected) && $selected == $id_model) {
11635 $retstring .=
"selected";
11637 $retstring .=
">" . $label_model .
"</option>";
11640 $retstring .=
"</select>";
11643 $retstring .=
ajax_combobox(
'select_' . $prefix .
'model_mail');
11660 public function buttonsSaveCancel($save_label =
'Save', $cancel_label =
'Cancel', $morebuttons = array(), $withoutdiv =
false, $morecss =
'', $dol_openinpopup =
'')
11664 $buttons = array();
11668 'label_key' => $save_label,
11671 if ($save_label ==
'Create' || $save_label ==
'Add') {
11672 $save[
'name'] =
'add';
11673 } elseif ($save_label ==
'Modify') {
11674 $save[
'name'] =
'edit';
11678 'name' =>
'cancel',
11679 'label_key' =>
'Cancel',
11682 !empty($save_label) ? $buttons[] = $save :
'';
11684 if (!empty($morebuttons)) {
11685 $buttons[] = $morebuttons;
11688 !empty($cancel_label) ? $buttons[] = $cancel :
'';
11690 $retstring = $withoutdiv ?
'' :
'<div class="center">';
11692 foreach ($buttons as $button) {
11693 $addclass = empty($button[
'addclass']) ?
'' : $button[
'addclass'];
11694 $retstring .=
'<input type="submit" class="button button-' . $button[
'name'] . ($morecss ?
' ' . $morecss :
'') .
' ' . $addclass .
'" name="' . $button[
'name'] .
'" value="' .
dol_escape_htmltag($langs->trans($button[
'label_key'])) .
'">';
11696 $retstring .= $withoutdiv ?
'' :
'</div>';
11698 if ($dol_openinpopup) {
11699 $retstring .=
'<!-- buttons are shown into a $dol_openinpopup=' .
dol_escape_htmltag($dol_openinpopup) .
' context, so we enable the close of dialog on cancel -->' .
"\n";
11700 $retstring .=
'<script nonce="' .
getNonce() .
'">';
11701 $retstring .=
'jQuery(".button-cancel").click(function(e) {
11702 e.preventDefault(); console.log(\'We click on cancel in iframe popup ' .
dol_escape_js($dol_openinpopup) .
'\');
11703 window.parent.jQuery(\
'#idfordialog' .
dol_escape_js($dol_openinpopup) .
'\').dialog(\
'close\');
11705 $retstring .=
'</script>';
11724 $num = count($this->cache_invoice_subtype);
11731 $sql =
"SELECT rowid, code, label as label";
11732 $sql .=
" FROM " . MAIN_DB_PREFIX .
'c_invoice_subtype';
11733 $sql .=
" WHERE active = 1";
11735 $resql = $this->db->query($sql);
11737 $num = $this->db->num_rows($resql);
11739 while ($i < $num) {
11740 $obj = $this->db->fetch_object($resql);
11743 $label = ($langs->trans(
"InvoiceSubtype" . $obj->rowid) !=
"InvoiceSubtype" . $obj->rowid) ? $langs->trans(
"InvoiceSubtype" . $obj->rowid) : (($obj->label !=
'-') ? $obj->label :
'');
11744 $this->cache_invoice_subtype[$obj->rowid][
'rowid'] = $obj->rowid;
11745 $this->cache_invoice_subtype[$obj->rowid][
'code'] = $obj->code;
11746 $this->cache_invoice_subtype[$obj->rowid][
'label'] = $label;
11750 $this->cache_invoice_subtype =
dol_sort_array($this->cache_invoice_subtype,
'code',
'asc', 0, 0, 1);
11772 global $langs, $user;
11775 dol_syslog(__METHOD__ .
" selected=" . $selected .
", htmlname=" . $htmlname, LOG_DEBUG);
11777 $this->load_cache_invoice_subtype();
11779 $out .=
'<select id="' . $htmlname .
'" class="flat selectsubtype' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'">';
11781 $out .=
'<option value="0"> </option>';
11784 foreach ($this->cache_invoice_subtype as $rowid => $subtype) {
11785 $label = $subtype[
'label'];
11786 $out .=
'<option value="' . $subtype[
'rowid'] .
'"';
11787 if ($selected == $subtype[
'rowid']) {
11788 $out .=
' selected="selected"';
11792 $out .=
'</option>';
11795 $out .=
'</select>';
11796 if ($user->admin && empty($noinfoadmin)) {
11797 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLength=2, $autoselect=0, $ajaxoptions=array(), $moreparams='')
Generic function that return javascript to add to transform a common input text or select field into ...
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
ajax_multiautocompleter($htmlname, $fields, $url, $option='', $minLength=2, $autoselect=0)
Generic function that return javascript to add to a page to transform a common input text field into ...
ajax_event($htmlname, $events)
Add event management script.
Class to manage bank accounts.
Class to manage categories.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Class to manage bank accounts description of third parties.
Class to manage a WYSIWYG editor.
const STATUS_OPEN_INTERNAL
Warehouse open and only operations for stock transfers/corrections allowed (not for customer shipping...
const STATUS_OPEN_ALL
Warehouse open and any operations are allowed (customer shipping, supplier dispatch,...
const STATUS_CLOSED
Warehouse closed, inactive.
Class to manage invoices.
Class to parse product price expressions.
Class to manage predefined suppliers products.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
Class toolbox to validate values.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
currency_name($code_iso, $withcode=0, $outputlangs=null)
Return label of currency or code+label.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
getServerTimeZoneInt($refgmtdate='now')
Return server timezone int.
removeGlobalParenthesis($string)
Remove first and last parenthesis but only if first is the opening and last the closing of the same g...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dolForgeExplodeAnd($sqlfilters)
Explode an universal search string with AND parts.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
dolPrintHTML($s, $allowiframe=0)
Return a string (that can be on several lines) ready to be output on a HTML page.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
currentToken()
Return the value of token currently saved into session with name 'token'.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_print_url($url, $target='_blank', $max=32, $withpicto=0, $morecss='')
Show Url link.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
dol_string_neverthesehtmltags($stringtoclean, $disallowed_tags=array('textarea'), $cleanalsosomestyles=0)
Clean a string from some undesirable HTML tags.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
dolPrintHTMLForAttribute($s, $escapeonlyhtmltags=0, $allowothertags=array())
Return a string ready to be output into an HTML attribute (alt, title, data-html, ....
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
getAdvancedPreviewUrl($modulepart, $relativepath, $alldata=0, $param='')
Return URL we can use for advanced preview links.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dolIsAllowedForPreview($file)
Return if a file is qualified for preview.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getNonce()
Return a random string to be used as a nonce value for js.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox=0, $check='restricthtml')
Sanitize a HTML to remove js, dangerous content and external link.
dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array(), $allowlink=0, $allowscript=0, $allowstyle=0, $allowphp=0)
Clean a string to keep only desirable HTML tags.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
treeview li table
No Email.
ui state ui widget content ui state ui widget header ui state a ui button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
testSqlAndScriptInject($val, $type)
Security: WAF layer for SQL Injection and XSS Injection (scripts) protection (Filters on GET,...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
measuringUnitString($unitid, $measuring_style='', $unitscale='', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
$conf db name
Only used if Module[ID]Name translation string is not found.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.
getMaxFileSizeArray()
Return the max allowed for file upload.
dolDecrypt($chain, $key='')
Decode a string with a symmetric encryption.