222 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 =
'')
224 global $conf, $langs;
229 if (empty($typeofdata)) {
230 return 'ErrorBadParameter typeofdata is empty';
233 if ($typeofdata ==
'datetime') {
234 $typeofdata =
'dayhour';
237 if (preg_match(
'/^(\w+)\((\d+)\)$/', $typeofdata, $reg)) {
238 if ($reg[1] ==
'varchar') {
239 $typeofdata =
'string';
240 } elseif ($reg[1] ==
'int') {
241 $typeofdata =
'numeric';
243 return 'ErrorBadParameter ' . $typeofdata;
248 if (
getDolGlobalString(
'MAIN_USE_JQUERY_JEDITABLE') && !preg_match(
'/^select;|day|datepicker|dayhour|datehourpicker/', $typeofdata)) {
249 $ret .= $this->
editInPlace(
$object, $value, $htmlname, $perm, $typeofdata, $editvalue, $extObject, $custommsg);
251 if ($editaction ==
'') {
252 $editaction =
GETPOST(
'action',
'aZ09');
254 $editmode = ($editaction ==
'edit' . $htmlname);
257 $ret .=
'<form method="post" action="' . $_SERVER[
"PHP_SELF"] . ($moreparam ?
'?' . $moreparam :
'') .
'">';
258 $ret .=
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
259 $ret .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
260 $ret .=
'<input type="hidden" name="' . $paramid .
'" value="' .
$object->id .
'">';
261 if (empty($notabletag)) {
262 $ret .=
'<table class="nobordernopadding centpercent">';
264 if (empty($notabletag)) {
267 if (preg_match(
'/^(string|safehtmlstring|email|phone|url)/', $typeofdata)) {
268 $tmp = explode(
':', $typeofdata);
269 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($editvalue ? $editvalue : $value) .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
270 } elseif (preg_match(
'/^(integer)/', $typeofdata)) {
271 $tmp = explode(
':', $typeofdata);
272 $valuetoshow =
price2num($editvalue ? $editvalue : $value, 0);
273 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $valuetoshow .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
274 } elseif (preg_match(
'/^(numeric|amount)/', $typeofdata)) {
275 $tmp = explode(
':', $typeofdata);
276 $valuetoshow =
price2num($editvalue ? $editvalue : $value);
277 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($valuetoshow !=
'' ?
price($valuetoshow) :
'') .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
278 } elseif (preg_match(
'/^(checkbox)/', $typeofdata)) {
279 $tmp = explode(
':', $typeofdata);
280 $ret .=
'<input type="checkbox" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($value ? $value :
'on') .
'"' . ($value ?
' checked' :
'') . (empty($tmp[1]) ?
'' : $tmp[1]) .
'/>';
281 } elseif (preg_match(
'/^text/', $typeofdata) || preg_match(
'/^note/', $typeofdata)) {
282 $tmp = explode(
':', $typeofdata);
283 $cols = (empty($tmp[2]) ?
'' : $tmp[2]);
285 if (preg_match(
'/%/', $cols)) {
286 $morealt =
' style="width: ' . $cols .
'"';
289 $valuetoshow = ($editvalue ? $editvalue : $value);
290 $ret .=
'<textarea id="' . $htmlname .
'" name="' . $htmlname .
'" wrap="soft" rows="' . (empty($tmp[1]) ?
'20' : $tmp[1]) .
'"' . ($cols ?
' cols="' . $cols .
'"' :
'class="quatrevingtpercent"') . $morealt .
'" autofocus>';
293 $valuetoshow = str_replace(
'&',
'&', $valuetoshow);
295 $ret .=
'</textarea><div class="clearboth"></div>';
296 } elseif ($typeofdata ==
'day' || $typeofdata ==
'datepicker') {
297 $addnowlink = empty($moreoptions[
'addnowlink']) ? 0 : $moreoptions[
'addnowlink'];
298 $adddateof = empty($moreoptions[
'adddateof']) ?
'' : $moreoptions[
'adddateof'];
299 $labeladddateof = empty($moreoptions[
'labeladddateof']) ?
'' : $moreoptions[
'labeladddateof'];
300 $ret .= $this->
selectDate($value, $htmlname, 0, 0, 1,
'form' . $htmlname, 1, $addnowlink, 0,
'',
'', $adddateof,
'', 1, $labeladddateof,
'', $gm);
301 } elseif ($typeofdata ==
'dayhour' || $typeofdata ==
'datehourpicker') {
302 $addnowlink = empty($moreoptions[
'addnowlink']) ? 0 : $moreoptions[
'addnowlink'];
303 $adddateof = empty($moreoptions[
'adddateof']) ?
'' : $moreoptions[
'adddateof'];
304 $labeladddateof = empty($moreoptions[
'labeladddateof']) ?
'' : $moreoptions[
'labeladddateof'];
305 $ret .= $this->
selectDate($value, $htmlname, 1, 1, 1,
'form' . $htmlname, 1, $addnowlink, 0,
'',
'', $adddateof,
'', 1, $labeladddateof,
'', $gm);
306 } elseif (preg_match(
'/^select;/', $typeofdata)) {
307 $arraydata = explode(
',', preg_replace(
'/^select;/',
'', $typeofdata));
308 $arraylist = array();
309 foreach ($arraydata as $val) {
310 $tmp = explode(
':', $val);
311 $tmpkey = str_replace(
'|',
':', $tmp[0]);
312 $arraylist[$tmpkey] = $tmp[1];
314 $ret .= $this->
selectarray($htmlname, $arraylist, $value);
315 } elseif (preg_match(
'/^link/', $typeofdata)) {
317 } elseif (preg_match(
'/^ckeditor/', $typeofdata)) {
318 $tmp = explode(
':', $typeofdata);
319 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
320 $doleditor =
new DolEditor($htmlname, ($editvalue ? $editvalue : $value), (empty($tmp[2]) ?
'' : $tmp[2]), (empty($tmp[3]) ?
'100' : $tmp[3]), (empty($tmp[1]) ?
'dolibarr_notes' : $tmp[1]),
'In', (empty($tmp[5]) ? 0 : $tmp[5]), (isset($tmp[8]) ? ($tmp[8] ? true :
false) :
true),
true, (empty($tmp[6]) ?
'20' : $tmp[6]), (empty($tmp[7]) ?
'100' : $tmp[7]));
321 $ret .= $doleditor->Create(1);
322 } elseif ($typeofdata ==
'asis') {
323 $ret .= ($editvalue ? $editvalue : $value);
325 if (empty($notabletag)) {
330 if (empty($notabletag)) {
334 $ret .=
'<input type="submit" class="smallpaddingimp button' . (empty($notabletag) ?
'' :
' ') .
'" name="modify" value="' . $langs->trans(
"Modify") .
'">';
335 if (preg_match(
'/ckeditor|textarea/', $typeofdata) && empty($notabletag)) {
336 $ret .=
'<br>' .
"\n";
338 $ret .=
'<input type="submit" class="smallpaddingimp button button-cancel' . (empty($notabletag) ?
'' :
' ') .
'" name="cancel" value="' . $langs->trans(
"Cancel") .
'">';
339 if (empty($notabletag)) {
343 if (empty($notabletag)) {
344 $ret .=
'</tr></table>' .
"\n";
346 $ret .=
'</form>' .
"\n";
348 if (preg_match(
'/^email/', $typeofdata)) {
350 } elseif (preg_match(
'/^phone/', $typeofdata)) {
352 } elseif (preg_match(
'/^url/', $typeofdata)) {
354 } elseif (preg_match(
'/^(amount|numeric)/', $typeofdata)) {
355 $ret .= ($value !=
'' ?
price($value, 0, $langs, 0, -1, -1, $conf->currency) :
'');
356 } elseif (preg_match(
'/^checkbox/', $typeofdata)) {
357 $tmp = explode(
':', $typeofdata);
358 $ret .=
'<input type="checkbox" disabled id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $value .
'"' . ($value ?
' checked' :
'') . ($tmp[1] ? $tmp[1] :
'') .
'/>';
359 } elseif (preg_match(
'/^text/', $typeofdata) || preg_match(
'/^note/', $typeofdata)) {
361 } elseif (preg_match(
'/^(safehtmlstring|restricthtml)/', $typeofdata)) {
363 } elseif ($typeofdata ==
'day' || $typeofdata ==
'datepicker') {
364 $ret .=
'<span class="valuedate">' .
dol_print_date($value,
'day', $gm) .
'</span>';
365 } elseif ($typeofdata ==
'dayhour' || $typeofdata ==
'datehourpicker') {
366 $ret .=
'<span class="valuedate">' .
dol_print_date($value,
'dayhour', $gm) .
'</span>';
367 } elseif (preg_match(
'/^select;/', $typeofdata)) {
368 $arraydata = explode(
',', preg_replace(
'/^select;/',
'', $typeofdata));
369 $arraylist = array();
370 foreach ($arraydata as $val) {
371 $tmp = explode(
':', $val);
372 $arraylist[$tmp[0]] = $tmp[1];
374 $ret .= $arraylist[$value];
375 if ($htmlname ==
'fk_product_type') {
377 $ret =
img_picto($langs->trans(
"Product"),
'product',
'class="paddingleftonly paddingrightonly colorgrey"') . $ret;
379 $ret =
img_picto($langs->trans(
"Service"),
'service',
'class="paddingleftonly paddingrightonly colorgrey"') . $ret;
382 } elseif (preg_match(
'/^ckeditor/', $typeofdata)) {
385 $firstline = preg_replace(
'/<br>.*/',
'', $tmpcontent);
386 $firstline = preg_replace(
'/[\n\r].*/',
'', $firstline);
387 $tmpcontent = $firstline . ((strlen($firstline) != strlen($tmpcontent)) ?
'...' :
'');
393 if (empty($moreoptions[
'valuealreadyhtmlescaped'])) {
401 if ($formatfunc && method_exists(
$object, $formatfunc)) {
402 $ret =
$object->$formatfunc($ret);
941 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)
944 global $conf, $langs, $mysoc;
946 $langs->load(
"dict");
949 $countryArray = array();
952 $atleastonefavorite = 0;
954 $sql =
"SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite, eec";
955 $sql .=
" FROM " . $this->db->prefix() .
"c_country";
956 $sql .=
" WHERE active > 0";
959 dol_syslog(get_class($this) .
"::select_country", LOG_DEBUG);
960 $resql = $this->db->query($sql);
962 $out .=
'<select id="select' . $htmlname .
'" class="flat maxwidth200onsmartphone selectcountry' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" ' . $htmloption .
'>';
963 $num = $this->db->num_rows($resql);
967 $obj = $this->db->fetch_object($resql);
969 $countryArray[$i][
'rowid'] = $obj->rowid;
970 $countryArray[$i][
'code_iso'] = $obj->code_iso;
971 $countryArray[$i][
'code_iso3'] = $obj->code_iso3;
972 $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 :
''));
973 $countryArray[$i][
'favorite'] = $obj->favorite;
974 $countryArray[$i][
'eec'] = $obj->eec;
975 $favorite[$i] = $obj->favorite;
980 if (empty($disablefavorites)) {
981 $array1_sort_order = SORT_DESC;
982 $array2_sort_order = SORT_ASC;
983 array_multisort($favorite, $array1_sort_order, $label, $array2_sort_order, $countryArray);
989 if (is_numeric($showempty)) {
990 $out .=
'<option value=""> </option>' .
"\n";
992 $out .=
'<option value="-1">' . $langs->trans($showempty) .
'</option>' .
"\n";
996 if ($addspecialentries) {
998 $out .=
'<option value="special_allnotme"' . ($selected ==
'special_allnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesExceptMe", $langs->transnoentitiesnoconv(
"Country" . $mysoc->country_code)) .
'</option>';
999 $out .=
'<option value="special_eec"' . ($selected ==
'special_eec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEEC") .
'</option>';
1000 if ($mysoc->isInEEC()) {
1001 $out .=
'<option value="special_eecnotme"' . ($selected ==
'special_eecnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEECExceptMe", $langs->transnoentitiesnoconv(
"Country" . $mysoc->country_code)) .
'</option>';
1003 $out .=
'<option value="special_noteec"' . ($selected ==
'special_noteec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesNotInEEC") .
'</option>';
1004 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1007 foreach ($countryArray as $row) {
1009 if (empty($row[
'rowid'])) {
1012 if (is_array($exclude_country_code) && count($exclude_country_code) && in_array($row[
'code_iso'], $exclude_country_code)) {
1016 if (empty($disablefavorites) && $row[
'favorite'] && $row[
'code_iso']) {
1017 $atleastonefavorite++;
1019 if (empty($row[
'favorite']) && $atleastonefavorite) {
1020 $atleastonefavorite = 0;
1021 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1025 if ($row[
'label']) {
1026 $labeltoshow .=
dol_trunc($row[
'label'], $maxlength,
'middle');
1028 $labeltoshow .=
' ';
1030 if ($row[
'code_iso']) {
1031 $labeltoshow .=
' <span class="opacitymedium">(' . $row[
'code_iso'] .
')</span>';
1032 if (empty($hideflags)) {
1033 $tmpflag =
picto_from_langcode($row[
'code_iso'],
'class="saturatemedium paddingrightonly"', 1);
1034 $labeltoshow = $tmpflag .
' ' . $labeltoshow;
1038 if ($selected && $selected !=
'-1' && ($selected == $row[
'rowid'] || $selected == $row[
'code_iso'] || $selected == $row[
'code_iso3'] || $selected == $row[
'label'])) {
1039 $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']) .
'">';
1041 $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']) .
'">';
1043 $out .= $labeltoshow;
1044 $out .=
'</option>' .
"\n";
1047 $out .=
'</select>';
1053 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1054 $out .=
ajax_combobox(
'select' . $htmlname, array(), 0, 0,
'resolve');
1499 public function select_thirdparty_list($selected =
'', $htmlname =
'socid', $filter =
'', $showempty =
'', $showtype = 0, $forcecombo = 0, $events = array(), $filterkey =
'', $outputmode = 0, $limit = 0, $morecss =
'minwidth100', $moreparam =
'', $multiple =
false, $excludeids = array(), $showcode = 0)
1502 global $user, $langs;
1503 global $hookmanager;
1507 $outarray = array();
1509 if ($selected ===
'') {
1510 $selected = array();
1511 } elseif (!is_array($selected)) {
1512 $selected = array($selected);
1516 if (function_exists(
'testSqlAndScriptInject')) {
1519 return 'SQLInjectionTryDetected';
1523 if ($filter !=
'') {
1524 if (preg_match(
'/[\(\)]/', $filter)) {
1530 if (function_exists(
'testSqlAndScriptInject')) {
1533 return 'SQLInjectionTryDetected';
1539 dol_syslog(
"Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Syntax.", LOG_WARNING);
1544 $sql =
"SELECT s.rowid, s.nom as name, s.name_alias, s.tva_intra, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
1546 $sql .=
", s.address, s.zip, s.town";
1547 $sql .=
", dictp.code as country_code";
1549 $sql .=
" FROM " . $this->db->prefix() .
"societe as s";
1551 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_country as dictp ON dictp.rowid = s.fk_pays";
1553 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1554 $sql .=
", " . $this->db->prefix() .
"societe_commerciaux as sc";
1556 $sql .=
" WHERE s.entity IN (" .
getEntity(
'societe') .
")";
1557 if (!empty($user->socid)) {
1558 $sql .=
" AND s.rowid = " . ((int) $user->socid);
1563 $sql .=
" AND (" . $filter .
")";
1565 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1566 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = " . ((int) $user->id);
1569 $sql .=
" AND s.status <> 0";
1571 if (!empty($excludeids)) {
1572 $sql .=
" AND s.rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeids)) .
")";
1575 $parameters = array();
1576 $reshook = $hookmanager->executeHooks(
'selectThirdpartyListWhere', $parameters);
1577 $sql .= $hookmanager->resPrint;
1579 if ($filterkey && $filterkey !=
'') {
1583 $search_crit = explode(
' ', $filterkey);
1585 if (count($search_crit) > 1) {
1588 foreach ($search_crit as $crit) {
1592 $sql .=
"(s.nom LIKE '" . $this->db->escape($prefix . $crit) .
"%')";
1595 if (count($search_crit) > 1) {
1598 if (isModEnabled(
'barcode')) {
1599 $sql .=
" OR s.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1601 $sql .=
" OR s.code_client LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.code_fournisseur LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1602 $sql .=
" OR s.name_alias LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.tva_intra LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1605 $sql .= $this->db->order(
"nom",
"ASC");
1606 $sql .= $this->db->plimit($limit, 0);
1609 dol_syslog(get_class($this).
"::select_thirdparty_list", LOG_DEBUG);
1610 $resql = $this->db->query($sql);
1613 $out .=
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
' name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
'>' .
"\n";
1615 $textifempty = (($showempty && !is_numeric($showempty)) ? $langs->trans($showempty) :
'');
1619 if ($showempty && !is_numeric($showempty)) {
1620 $textifempty = $langs->trans($showempty);
1622 $textifempty .= $langs->trans(
"All");
1626 $out .=
'<option value="-1" data-html="' .
dol_escape_htmltag(
'<span class="opacitymedium">' . ($textifempty ? $textifempty :
' ') .
'</span>') .
'">' . $textifempty .
'</option>' .
"\n";
1629 $companytemp =
new Societe($this->db);
1631 $num = $this->db->num_rows($resql);
1635 $obj = $this->db->fetch_object($resql);
1638 if (($obj->client) && (!empty($obj->code_client))) {
1639 $label = $obj->code_client .
' - ';
1641 if (($obj->fournisseur) && (!empty($obj->code_fournisseur))) {
1642 $label .= $obj->code_fournisseur .
' - ';
1644 $label .=
' ' . $obj->name;
1646 $label = $obj->name;
1649 if (!empty($obj->name_alias)) {
1650 $label .=
' (' . $obj->name_alias .
')';
1654 $label .=
' - '.$obj->tva_intra;
1657 $labelhtml = $label;
1660 $companytemp->id = $obj->rowid;
1661 $companytemp->client = $obj->client;
1662 $companytemp->fournisseur = $obj->fournisseur;
1663 $tmptype = $companytemp->getTypeUrl(1,
'', 0,
'span');
1665 $labelhtml .=
' ' . $tmptype;
1668 if ($obj->client || $obj->fournisseur) {
1671 if ($obj->client == 1 || $obj->client == 3) {
1672 $label .= $langs->trans(
"Customer");
1674 if ($obj->client == 2 || $obj->client == 3) {
1675 $label .= ($obj->client == 3 ?
', ' :
'') . $langs->trans(
"Prospect");
1677 if ($obj->fournisseur) {
1678 $label .= ($obj->client ?
', ' :
'') . $langs->trans(
"Supplier");
1680 if ($obj->client || $obj->fournisseur) {
1686 $s = ($obj->address ?
' - ' . $obj->address :
'') . ($obj->zip ?
' - ' . $obj->zip :
'') . ($obj->town ?
' ' . $obj->town :
'');
1687 if (!empty($obj->country_code)) {
1688 $s .=
', ' . $langs->trans(
'Country' . $obj->country_code);
1694 if (empty($outputmode)) {
1695 if (in_array($obj->rowid, $selected)) {
1696 $out .=
'<option value="' . $obj->rowid .
'" selected data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
1698 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
1701 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label,
'labelhtml' => $labelhtml));
1705 if (($i % 10) == 0) {
1710 $out .=
'</select>' .
"\n";
1712 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1719 $this->result = array(
'nbofthirdparties' => $num);
1753 public function selectcontacts($socid, $selected = array(), $htmlname =
'contactid', $showempty = 0, $exclude =
'', $limitto =
'', $showfunction = 0, $morecss =
'', $options_only = 0, $showsoc = 0, $forcecombo = 0, $events = array(), $moreparam =
'', $htmlid =
'', $multiple =
false, $disableifempty = 0, $filter =
'')
1755 global $conf, $langs, $hookmanager, $action;
1757 $langs->load(
'companies');
1759 if (empty($htmlid)) {
1760 $htmlid = $htmlname;
1764 $outarray = array();
1766 if ($selected ===
'') {
1767 $selected = array();
1768 } elseif (!is_array($selected)) {
1769 $selected = array((
int) $selected);
1773 if (function_exists(
'testSqlAndScriptInject')) {
1776 return 'SQLInjectionTryDetected';
1780 if ($filter !=
'') {
1781 if (preg_match(
'/[\(\)]/', $filter)) {
1787 if (function_exists(
'testSqlAndScriptInject')) {
1790 return 'SQLInjectionTryDetected';
1796 dol_syslog(
"Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Filter Syntax.", LOG_WARNING);
1800 if (!is_object($hookmanager)) {
1801 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
1806 $sql =
"SELECT sp.rowid, sp.lastname, sp.statut, sp.firstname, sp.poste, sp.email, sp.phone, sp.phone_perso, sp.phone_mobile, sp.town AS contact_town";
1807 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
1808 $sql .=
", s.nom as company, s.town AS company_town";
1810 $sql .=
" FROM " . $this->db->prefix() .
"socpeople as sp";
1811 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
1812 $sql .=
" LEFT OUTER JOIN " . $this->db->prefix() .
"societe as s ON s.rowid=sp.fk_soc";
1814 $sql .=
" WHERE sp.entity IN (" .
getEntity(
'contact') .
")";
1815 if ($socid > 0 || $socid == -1) {
1816 $sql .=
" AND sp.fk_soc = " . ((int) $socid);
1819 $sql .=
" AND sp.statut <> 0";
1824 $sql .=
" AND (" . $filter .
")";
1827 $parameters = array();
1828 $reshook = $hookmanager->executeHooks(
'selectContactListWhere', $parameters);
1829 $sql .= $hookmanager->resPrint;
1830 $sql .=
" ORDER BY sp.lastname ASC";
1832 dol_syslog(get_class($this) .
"::selectcontacts", LOG_DEBUG);
1833 $resql = $this->db->query($sql);
1835 $num = $this->db->num_rows($resql);
1837 if ($htmlname !=
'none' && !$options_only) {
1838 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlid .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . (($num || empty($disableifempty)) ?
'' :
' disabled') . ($multiple ?
'multiple' :
'') .
' ' . (!empty($moreparam) ? $moreparam :
'') .
'>';
1841 if ($showempty && !is_numeric($showempty)) {
1842 $textforempty = $showempty;
1843 $out .=
'<option class="optiongrey" value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'>' . $textforempty .
'</option>';
1845 if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) {
1846 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'> </option>';
1848 if ($showempty == 2) {
1849 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Internal") .
' --</option>';
1855 include_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
1856 $contactstatic =
new Contact($this->db);
1859 $obj = $this->db->fetch_object($resql);
1862 $extendedInfos =
'';
1864 $extendedInfos = array();
1865 $email = trim($obj->email);
1866 if (!empty($email)) {
1867 $extendedInfos[] = $email;
1869 $phone = trim($obj->phone);
1870 $phone_perso = trim($obj->phone_perso);
1871 $phone_mobile = trim($obj->phone_mobile);
1872 if (!empty($phone)) {
1873 $extendedInfos[] = $phone;
1875 if (!empty($phone_perso)) {
1876 $extendedInfos[] = $phone_perso;
1878 if (!empty($phone_mobile)) {
1879 $extendedInfos[] = $phone_mobile;
1882 $contact_town = trim($obj->contact_town);
1883 $company_town = trim($obj->company_town);
1884 if (!empty($contact_town)) {
1885 $extendedInfos[] = $contact_town;
1886 } elseif (!empty($company_town)) {
1887 $extendedInfos[] = $company_town;
1889 $extendedInfos = implode(
' - ', $extendedInfos);
1890 if (!empty($extendedInfos)) {
1891 $extendedInfos =
' - ' . $extendedInfos;
1895 $contactstatic->id = $obj->rowid;
1896 $contactstatic->lastname = $obj->lastname;
1897 $contactstatic->firstname = $obj->firstname;
1898 if ($obj->statut == 1) {
1900 if ($htmlname !=
'none') {
1902 if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) {
1905 if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) {
1908 if (!empty($selected) && in_array($obj->rowid, $selected)) {
1909 $out .=
'<option value="' . $obj->rowid .
'"';
1911 $out .=
' disabled';
1913 $out .=
' selected>';
1915 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1916 if ($showfunction && $obj->poste) {
1917 $tmplabel .=
' (' . $obj->poste .
')';
1919 if (($showsoc > 0) && $obj->company) {
1920 $tmplabel .=
' - (' . $obj->company .
')';
1924 $out .=
'</option>';
1926 $out .=
'<option value="' . $obj->rowid .
'"';
1928 $out .=
' disabled';
1932 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1933 if ($showfunction && $obj->poste) {
1934 $tmplabel .=
' (' . $obj->poste .
')';
1936 if (($showsoc > 0) && $obj->company) {
1937 $tmplabel .=
' - (' . $obj->company .
')';
1941 $out .=
'</option>';
1944 if (in_array($obj->rowid, $selected)) {
1945 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1946 if ($showfunction && $obj->poste) {
1947 $tmplabel .=
' (' . $obj->poste .
')';
1949 if (($showsoc > 0) && $obj->company) {
1950 $tmplabel .=
' - (' . $obj->company .
')';
1957 if ($tmplabel !=
'') {
1958 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $tmplabel,
'label' => $tmplabel,
'labelhtml' => $tmplabel));
1964 $labeltoshow = ($socid != -1) ? ($langs->trans($socid ?
"NoContactDefinedForThirdParty" :
"NoContactDefined")) : $langs->trans(
'SelectAThirdPartyFirst');
1965 $out .=
'<option class="disabled" value="-1"' . (($showempty == 2 || $multiple) ?
'' :
' selected') .
' disabled="disabled">';
1966 $out .= $labeltoshow;
1967 $out .=
'</option>';
1970 $parameters = array(
1972 'htmlname' => $htmlname,
1975 'showfunction' => $showfunction,
1976 'showsoc' => $showsoc,
1979 $reshook = $hookmanager->executeHooks(
'afterSelectContactOptions', $parameters, $this, $action);
1981 if ($htmlname !=
'none' && !$options_only) {
1982 $out .=
'</select>';
1985 if ($conf->use_javascript_ajax && !$forcecombo && !$options_only) {
1986 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1992 if ($options_only === 2) {
2142 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)
2145 global $conf, $user, $langs, $hookmanager;
2149 if ((is_numeric($selected) && ($selected < -2 || empty($selected))) && !
getDolGlobalString(
'SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE')) {
2150 $selected = $user->id;
2153 if ($selected ===
'') {
2154 $selected = array();
2155 } elseif (!is_array($selected)) {
2156 $selected = array($selected);
2159 $excludeUsers =
null;
2160 $includeUsers =
null;
2163 if (is_array($exclude)) {
2164 $excludeUsers = implode(
",", $exclude);
2167 if (is_array($include)) {
2168 $includeUsers = implode(
",", $include);
2169 } elseif ($include ==
'hierarchy') {
2171 $includeUsers = implode(
",", $user->getAllChildIds(0));
2172 } elseif ($include ==
'hierarchyme') {
2174 $includeUsers = implode(
",", $user->getAllChildIds(1));
2180 $outarray = array();
2181 $outarray2 = array();
2184 $showlabelofentity = isModEnabled(
'multicompany') && !
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE') && $conf->entity == 1 && !empty($user->admin) && empty($user->entity);
2185 $userissuperadminentityone = isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && empty($user->entity);
2188 $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";
2189 if ($showlabelofentity) {
2190 $sql .=
", e.label";
2192 $sql .=
" FROM " . $this->db->prefix() .
"user as u";
2193 if ($showlabelofentity) {
2194 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid = u.entity";
2197 if ($userissuperadminentityone && $force_entity !=
'default') {
2198 if (!empty($force_entity)) {
2199 $sql .=
" WHERE u.entity IN (0, " . $this->db->sanitize($force_entity) .
")";
2201 $sql .=
" WHERE u.entity IS NOT NULL";
2204 if (isModEnabled(
'multicompany') &&
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE')) {
2205 $sql .=
" WHERE u.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
2207 $sql .=
" WHERE u.entity IN (" .
getEntity(
'user') .
")";
2211 if (!empty($user->socid)) {
2212 $sql .=
" AND u.fk_soc = " . ((int) $user->socid);
2214 if (is_array($exclude) && $excludeUsers) {
2215 $sql .=
" AND u.rowid NOT IN (" . $this->db->sanitize($excludeUsers) .
")";
2217 if ($includeUsers) {
2218 $sql .=
" AND u.rowid IN (" . $this->db->sanitize($includeUsers) .
")";
2221 $sql .=
" AND u.statut <> 0";
2224 $sql .=
" AND u.employee <> 0";
2227 $sql .=
" AND u.fk_soc IS NULL";
2229 if (!empty($morefilter)) {
2230 $sql .=
" " . $morefilter;
2234 $reshook = $hookmanager->executeHooks(
'addSQLWhereFilterOnSelectUsers', array(), $this, $action);
2235 if (!empty($reshook)) {
2236 $sql .= $hookmanager->resPrint;
2240 $sql .=
" ORDER BY u.statut DESC, u.firstname ASC, u.lastname ASC";
2242 $sql .=
" ORDER BY u.statut DESC, u.lastname ASC, u.firstname ASC";
2245 dol_syslog(get_class($this) .
"::select_dolusers", LOG_DEBUG);
2247 $resql = $this->db->query($sql);
2249 $num = $this->db->num_rows($resql);
2253 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
' minwidth200') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
2254 if ($show_empty && !$multiple) {
2255 $textforempty =
' ';
2256 if (!empty($conf->use_javascript_ajax)) {
2257 $textforempty =
' ';
2259 if (!is_numeric($show_empty)) {
2260 $textforempty = $show_empty;
2262 $out .=
'<option class="optiongrey" value="' . ($show_empty < 0 ? $show_empty : -1) .
'"' . ((empty($selected) || in_array(-1, $selected)) ?
' selected' :
'') .
'>' . $textforempty .
'</option>' .
"\n";
2264 $outarray[($show_empty < 0 ? $show_empty : -1)] = $textforempty;
2265 $outarray2[($show_empty < 0 ? $show_empty : -1)] = array(
2266 'id' => ($show_empty < 0 ? $show_empty : -1),
2267 'label' => $textforempty,
2268 'labelhtml' => $textforempty,
2274 $out .=
'<option value="-2"' . ((in_array(-2, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Everybody") .
' --</option>' .
"\n";
2276 $outarray[-2] =
'-- ' . $langs->trans(
"Everybody") .
' --';
2277 $outarray2[-2] = array(
2279 'label' =>
'-- ' . $langs->trans(
"Everybody") .
' --',
2280 'labelhtml' =>
'-- ' . $langs->trans(
"Everybody") .
' --',
2286 $userstatic =
new User($this->db);
2289 $obj = $this->db->fetch_object($resql);
2291 $userstatic->id = $obj->rowid;
2292 $userstatic->lastname = $obj->lastname;
2293 $userstatic->firstname = $obj->firstname;
2294 $userstatic->photo = $obj->photo;
2295 $userstatic->status = $obj->status;
2296 $userstatic->entity = $obj->entity;
2297 $userstatic->admin = $obj->admin;
2298 $userstatic->gender = $obj->gender;
2301 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
2302 $disableline = ($enableonlytext ? $enableonlytext :
'1');
2306 $labeltoshowhtml =
'';
2313 $labeltoshow .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2314 $labeltoshowhtml .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2315 if (empty($obj->firstname) && empty($obj->lastname)) {
2316 $labeltoshow .= $obj->login;
2317 $labeltoshowhtml .= $obj->login;
2324 $moreinfo .= ($moreinfo ?
' - ' :
' (');
2325 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(');
2326 $moreinfo .= $obj->login;
2327 $moreinfohtml .= $obj->login;
2329 if ($showstatus >= 0) {
2330 if ($obj->status == 1 && $showstatus == 1) {
2331 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Enabled');
2332 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Enabled');
2334 if ($obj->status == 0 && $showstatus == 1) {
2335 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Disabled');
2336 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Disabled');
2339 if ($showlabelofentity) {
2340 if (empty($obj->entity)) {
2341 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
"AllEntities");
2342 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
"AllEntities");
2344 if ($obj->entity != $conf->entity) {
2345 $moreinfo .= ($moreinfo ?
' - ' :
' (') . ($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2346 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(').($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2350 $moreinfo .= (!empty($moreinfo) ?
')' :
'');
2351 $moreinfohtml .= (!empty($moreinfohtml) ?
')</span>' :
'');
2352 if (!empty($disableline) && $disableline !=
'1') {
2354 $moreinfo .=
' - ' . $disableline;
2355 $moreinfohtml .=
' - ' . $disableline;
2357 $labeltoshow .= $moreinfo;
2358 $labeltoshowhtml .= $moreinfohtml;
2360 $out .=
'<option value="' . $obj->rowid .
'"';
2361 if (!empty($disableline)) {
2362 $out .=
' disabled';
2364 if ((!empty($selected[0]) && is_object($selected[0])) ? $selected[0]->id == $obj->rowid : in_array($obj->rowid, $selected)) {
2365 $out .=
' selected';
2367 $out .=
' data-html="';
2369 $outhtml = $userstatic->getNomUrl(-3,
'', 0, 1, 24, 1,
'login',
'', 1) .
' ';
2370 if ($showstatus >= 0 && $obj->status == 0) {
2371 $outhtml .=
'<strike class="opacitymediumxxx">';
2373 $outhtml .= $labeltoshowhtml;
2374 if ($showstatus >= 0 && $obj->status == 0) {
2375 $outhtml .=
'</strike>';
2377 $labeltoshowhtml = $outhtml;
2381 $out .= $labeltoshow;
2382 $out .=
'</option>';
2384 $outarray[$userstatic->id] = $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength) . $moreinfo;
2385 $outarray2[$userstatic->id] = array(
2386 'id' => $userstatic->id,
2387 'label' => $labeltoshow,
2388 'labelhtml' => $labeltoshowhtml,
2396 $out .=
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'" disabled>';
2397 $out .=
'<option value="">' . $langs->trans(
"None") .
'</option>';
2399 $out .=
'</select>';
2401 if ($num && !$forcecombo) {
2403 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2412 if ($outputmode == 2) {
2414 } elseif ($outputmode) {
2644 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)
2647 global $langs, $conf;
2652 $price_level = (!empty($price_level) ? $price_level : 0);
2653 if (is_null($ajaxoptions)) {
2654 $ajaxoptions = array();
2657 if (strval($filtertype) ===
'' && (isModEnabled(
"product") || isModEnabled(
"service"))) {
2658 if (isModEnabled(
"product") && !isModEnabled(
'service')) {
2660 } elseif (!isModEnabled(
'product') && isModEnabled(
"service")) {
2665 if (!empty($conf->use_javascript_ajax) &&
getDolGlobalString(
'PRODUIT_USE_SEARCH_TO_SELECT')) {
2668 if ($selected && empty($selected_input_value)) {
2669 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
2670 $producttmpselect =
new Product($this->db);
2671 $producttmpselect->fetch($selected);
2672 $selected_input_value = $producttmpselect->ref;
2673 unset($producttmpselect);
2676 if ($filtertype ==
'') {
2677 if (!isModEnabled(
'product')) {
2679 } elseif (!isModEnabled(
'service')) {
2684 $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;
2685 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT .
'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
2687 if (isModEnabled(
'variants') && is_array($selected_combinations)) {
2691 <!-- script to auto show attributes select tags if a variant was selected -->
2692 <script nonce="' .
getNonce() .
'">
2693 // auto show attributes fields
2694 selected = ' . json_encode($selected_combinations) .
';
2697 jQuery(document).ready(function () {
2699 jQuery("input[name=\'prod_entry_mode\']").change(function () {
2700 if (jQuery(this).val() == \'free\') {
2701 jQuery(\'div#attributes_box\').empty();
2705 jQuery("input#' . $htmlname .
'").change(function () {
2707 if (!jQuery(this).val()) {
2708 jQuery(\'div#attributes_box\').empty();
2712 console.log("A change has started. We get variants fields to inject html select");
2714 jQuery.getJSON("' . DOL_URL_ROOT .
'/variants/ajax/getCombinations.php", {
2715 id: jQuery(this).val()
2716 }, function (data) {
2717 jQuery(\'div#attributes_box\').empty();
2719 jQuery.each(data, function (key, val) {
2721 combvalues[val.id] = val.values;
2723 var span = jQuery(document.createElement(\'div\')).css({
2724 \'display\': \'table-row\'
2728 jQuery(document.createElement(\'div\')).text(val.label).css({
2729 \'font-weight\': \'bold\',
2730 \'display\': \'table-cell\'
2734 var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({
2735 \'margin-left\': \'15px\',
2736 \'white-space\': \'pre\'
2738 jQuery(document.createElement(\'option\')).val(\'\')
2741 jQuery.each(combvalues[val.id], function (key, val) {
2742 var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value);
2744 if (selected[val.fk_product_attribute] == val.id) {
2745 tag.attr(\'selected\', \'selected\');
2752 jQuery(\'div#attributes_box\').append(span);
2757 ' . ($selected ?
'jQuery("input#' . $htmlname .
'").change();' :
'') .
'
2763 if (empty($hidelabel)) {
2764 $out .= $langs->trans(
"RefOrLabel") .
' : ';
2765 } elseif ($hidelabel > 1) {
2766 $placeholder =
' placeholder="' . $langs->trans(
"RefOrLabel") .
'"';
2767 if ($hidelabel == 2) {
2768 $out .=
img_picto($langs->trans(
"Search"),
'search');
2771 $out .=
'<input type="text" class="minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . $placeholder .
' ' . (
getDolGlobalString(
'PRODUCT_SEARCH_AUTOFOCUS') ?
'autofocus' :
'') .
' />';
2772 if ($hidelabel == 3) {
2773 $out .=
img_picto($langs->trans(
"Search"),
'search');
2776 $out .= $this->
select_produits_list($selected, $htmlname, $filtertype, $limit, $price_level,
'', $status, $finished, 0, $socid, $showempty, $forcecombo, $morecss, $hidepriceinlabel, $warehouseStatus, $status_purchase);
2779 if (empty($nooutput)) {
2893 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)
2897 global $hookmanager;
2900 $outarray = array();
2904 $langs->load(
'other');
2907 $warehouseStatusArray = array();
2908 if (!empty($warehouseStatus)) {
2909 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/entrepot.class.php';
2910 if (preg_match(
'/warehouseclosed/', $warehouseStatus)) {
2913 if (preg_match(
'/warehouseopen/', $warehouseStatus)) {
2916 if (preg_match(
'/warehouseinternal/', $warehouseStatus)) {
2921 $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";
2922 if (count($warehouseStatusArray)) {
2923 $selectFieldsGrouped =
", sum(" . $this->db->ifsql(
"e.statut IS NULL",
"0",
"ps.reel") .
") as stock";
2925 $selectFieldsGrouped =
", " . $this->db->ifsql(
"p.stock IS NULL", 0,
"p.stock") .
" AS stock";
2931 $parameters = array();
2932 $reshook = $hookmanager->executeHooks(
'selectProductsListSelect', $parameters);
2933 if (empty($reshook)) {
2934 $sql .= $selectFields.$selectFieldsGrouped.$hookmanager->resPrint;
2936 $sql .= $hookmanager->resPrint;
2941 $sql .=
", (SELECT " . $this->db->prefix() .
"categorie_product.fk_categorie
2942 FROM " . $this->db->prefix() .
"categorie_product
2943 WHERE " . $this->db->prefix() .
"categorie_product.fk_product=p.rowid
2945 ) AS categorie_product_id ";
2950 $sql .=
', pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,';
2951 $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';
2952 $selectFields .=
", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custdefault_vat_code, custref";
2956 $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";
2957 $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';
2962 $sql .=
", pl.label as label_translated";
2963 $sql .=
", pl.description as description_translated";
2964 $selectFields .=
", label_translated";
2965 $selectFields .=
", description_translated";
2969 $sql .=
", (SELECT pp.rowid FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
2970 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
2971 $sql .=
" AND price_level = " . ((int) $price_level);
2973 $sql .=
" ORDER BY date_price";
2974 $sql .=
" DESC LIMIT 1) as price_rowid";
2975 $sql .=
", (SELECT pp.price_by_qty FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
2976 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
2977 $sql .=
" AND price_level = " . ((int) $price_level);
2979 $sql .=
" ORDER BY date_price";
2980 $sql .=
" DESC LIMIT 1) as price_by_qty";
2981 $selectFields .=
", price_rowid, price_by_qty";
2984 $sql .=
" FROM ".$this->db->prefix().
"product as p";
2987 $sql .=
" USE INDEX (" . $this->db->sanitize(
getDolGlobalString(
'MAIN_PRODUCT_FORCE_INDEX')) .
")";
2991 $parameters = array();
2992 $reshook = $hookmanager->executeHooks(
'selectProductsListFrom', $parameters);
2993 $sql .= $hookmanager->resPrint;
2995 if (count($warehouseStatusArray)) {
2996 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_stock as ps on ps.fk_product = p.rowid";
2997 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entrepot as e on ps.fk_entrepot = e.rowid AND e.entity IN (" .
getEntity(
'stock') .
")";
2998 $sql .=
' AND e.statut IN (' . $this->db->sanitize($this->db->escape(implode(
',', $warehouseStatusArray))) .
')';
3003 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
3008 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_customer_price as pcp ON pcp.fk_soc=" . ((int) $socid) .
" AND pcp.fk_product=p.rowid";
3012 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
3016 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_lang as pl ON pl.fk_product = p.rowid ";
3018 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
3019 $soc =
new Societe($this->db);
3020 $result = $soc->fetch($socid);
3021 if ($result > 0 && !empty($soc->default_lang)) {
3022 $sql .=
" AND pl.lang = '" . $this->db->escape($soc->default_lang) .
"'";
3024 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3027 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3032 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_attribute_combination pac ON pac.fk_product_child = p.rowid";
3035 $sql .=
' WHERE p.entity IN (' .
getEntity(
'product') .
')';
3038 $sql .=
" AND pac.rowid IS NULL";
3041 if ($finished == 0) {
3042 $sql .=
" AND p.finished = " . ((int) $finished);
3043 } elseif ($finished == 1) {
3044 $sql .=
" AND p.finished = ".((int) $finished);
3047 $sql .=
" AND p.tosell = ".((int) $status);
3049 if ($status_purchase >= 0) {
3050 $sql .=
" AND p.tobuy = " . ((int) $status_purchase);
3053 if (strval($filtertype) !=
'') {
3054 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
3055 } elseif (!isModEnabled(
'product')) {
3056 $sql .=
" AND p.fk_product_type = 1";
3057 } elseif (!isModEnabled(
'service')) {
3058 $sql .=
" AND p.fk_product_type = 0";
3061 $parameters = array();
3062 $reshook = $hookmanager->executeHooks(
'selectProductsListWhere', $parameters);
3063 $sql .= $hookmanager->resPrint;
3065 if ($filterkey !=
'') {
3069 $search_crit = explode(
' ', $filterkey);
3071 if (count($search_crit) > 1) {
3074 foreach ($search_crit as $crit) {
3078 $sql .=
"(p.ref LIKE '" . $this->db->escape($prefix . $crit) .
"%' OR p.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3080 $sql .=
" OR pl.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3083 $sql .=
" OR pcp.ref_customer LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3086 $sql .=
" OR p.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3088 $sql .=
" OR pl.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3092 $sql .=
" OR pfp.ref_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3097 if (count($search_crit) > 1) {
3100 if (isModEnabled(
'barcode')) {
3101 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3105 if (count($warehouseStatusArray)) {
3106 $sql .=
" GROUP BY " . $selectFields;
3111 $sql .=
" ORDER BY categorie_product_id ";
3113 (
getDolGlobalInt(
'PRODUCT_SORT_BY_CATEGORY') == 1) ? $sql .=
"ASC" : $sql .=
"DESC";
3115 $sql .= $this->db->order(
"p.ref");
3118 $sql .= $this->db->plimit($limit, 0);
3121 dol_syslog(get_class($this) .
"::select_produits_list search products", LOG_DEBUG);
3122 $result = $this->db->query($sql);
3124 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3125 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3126 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
3128 $num = $this->db->num_rows($result);
3133 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3137 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
3143 if ($showempty && !is_numeric($showempty)) {
3144 $textifempty = $langs->trans($showempty);
3146 $textifempty .= $langs->trans(
"All");
3149 if ($showempty && !is_numeric($showempty)) {
3150 $textifempty = $langs->trans($showempty);
3154 $out .=
'<option value="-1" selected>' . ($textifempty ? $textifempty :
' ') .
'</option>';
3158 while ($num && $i < $num) {
3161 $objp = $this->db->fetch_object($result);
3163 if ((
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1) {
3164 $sql =
"SELECT rowid, quantity, price, unitprice, remise_percent, remise, price_base_type";
3165 $sql .=
" FROM " . $this->db->prefix() .
"product_price_by_qty";
3166 $sql .=
" WHERE fk_product_price = " . ((int) $objp->price_rowid);
3167 $sql .=
" ORDER BY quantity ASC";
3169 dol_syslog(get_class($this) .
"::select_produits_list search prices by qty", LOG_DEBUG);
3170 $result2 = $this->db->query($sql);
3172 $nb_prices = $this->db->num_rows($result2);
3174 while ($nb_prices && $j < $nb_prices) {
3175 $objp2 = $this->db->fetch_object($result2);
3177 $objp->price_by_qty_rowid = $objp2->rowid;
3178 $objp->price_by_qty_price_base_type = $objp2->price_base_type;
3179 $objp->price_by_qty_quantity = $objp2->quantity;
3180 $objp->price_by_qty_unitprice = $objp2->unitprice;
3181 $objp->price_by_qty_remise_percent = $objp2->remise_percent;
3183 $objp->quantity = $objp2->quantity;
3184 $objp->price = $objp2->price;
3185 $objp->unitprice = $objp2->unitprice;
3186 $objp->remise_percent = $objp2->remise_percent;
3199 array_push($outarray, $optJson);
3203 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_price_expression)) {
3204 $price_product =
new Product($this->db);
3205 $price_product->fetch($objp->rowid,
'',
'', 1);
3207 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3209 $price_result = $priceparser->parseProduct($price_product);
3210 if ($price_result >= 0) {
3211 $objp->price = $price_result;
3212 $objp->unitprice = $price_result;
3214 $objp->price_ttc = (float)
price2num($objp->price) * (1 + ($objp->tva_tx / 100));
3215 $objp->price_ttc =
price2num($objp->price_ttc,
'MU');
3224 array_push($outarray, $optJson);
3230 $out .=
'</select>';
3232 $this->db->free($result);
3234 if (empty($outputmode)) {
3261 protected function constructProductListOption(&$objp, &$opt, &$optJson, $price_level, $selected, $hidepriceinlabel = 0, $filterkey =
'', $novirtualstock = 0)
3263 global $langs, $conf, $user;
3264 global $hookmanager;
3270 $outlabel_translated =
'';
3272 $outdesc_translated =
'';
3278 $outpricebasetype =
'';
3280 $outdefault_vat_code =
'';
3284 $maxlengtharticle = (!
getDolGlobalString(
'PRODUCT_MAX_LENGTH_COMBO') ? 48 : $conf->global->PRODUCT_MAX_LENGTH_COMBO);
3286 $label = $objp->label;
3287 if (!empty($objp->label_translated)) {
3288 $label = $objp->label_translated;
3290 if (!empty($filterkey) && $filterkey !=
'') {
3291 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
3294 $outkey = $objp->rowid;
3295 $outref = $objp->ref;
3296 $outrefcust = empty($objp->custref) ?
'' : $objp->custref;
3297 $outlabel = $objp->label;
3298 $outdesc = $objp->description;
3300 $outlabel_translated = $objp->label_translated;
3301 $outdesc_translated = $objp->description_translated;
3303 $outbarcode = $objp->barcode;
3304 $outorigin = $objp->fk_country;
3305 $outpbq = empty($objp->price_by_qty_rowid) ?
'' : $objp->price_by_qty_rowid;
3307 $outtype = $objp->fk_product_type;
3312 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
3318 if (!empty($objp->unit_short)) {
3319 $outvalUnits .=
' - ' . $objp->unit_short;
3323 if (!empty($objp->weight) && $objp->weight_units !==
null) {
3325 $outvalUnits .=
' - ' . $unitToShow;
3327 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
3328 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
3329 $outvalUnits .=
' - ' . $unitToShow;
3331 if (!empty($objp->surface) && $objp->surface_units !==
null) {
3333 $outvalUnits .=
' - ' . $unitToShow;
3335 if (!empty($objp->volume) && $objp->volume_units !==
null) {
3337 $outvalUnits .=
' - ' . $unitToShow;
3340 if ($outdurationvalue && $outdurationunit) {
3342 'h' => $langs->trans(
'Hour'),
3343 'd' => $langs->trans(
'Day'),
3344 'w' => $langs->trans(
'Week'),
3345 'm' => $langs->trans(
'Month'),
3346 'y' => $langs->trans(
'Year')
3348 if (isset($da[$outdurationunit])) {
3349 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
3353 $opt =
'<option value="' . $objp->rowid .
'"';
3354 $opt .= ($objp->rowid == $selected) ?
' selected' :
'';
3355 if (!empty($objp->price_by_qty_rowid) && $objp->price_by_qty_rowid > 0) {
3356 $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 .
'"';
3359 if ($user->hasRight(
'stock',
'lire')) {
3360 if ($objp->stock > 0) {
3361 $opt .=
' class="product_line_stock_ok"';
3362 } elseif ($objp->stock <= 0) {
3363 $opt .=
' class="product_line_stock_too_low"';
3368 $opt .=
' data-labeltrans="' . $outlabel_translated .
'"';
3373 if (!empty($objp->custref)) {
3374 $opt .=
' (' . $objp->custref .
')';
3377 $opt .=
' (' . $outbarcode .
')';
3379 $opt .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3381 $opt .=
' (' .
getCountry($outorigin, 1) .
')';
3384 $objRef = $objp->ref;
3385 if (!empty($objp->custref)) {
3386 $objRef .=
' (' . $objp->custref .
')';
3388 if (!empty($filterkey) && $filterkey !=
'') {
3389 $objRef = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRef, 1);
3393 $outval .=
' (' . $outbarcode .
')';
3395 $outval .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3397 $outval .=
' (' .
getCountry($outorigin, 1) .
')';
3401 $opt .= $outvalUnits;
3402 $outval .= $outvalUnits;
3409 $sql =
"SELECT price, price_ttc, price_base_type, tva_tx, default_vat_code";
3410 $sql .=
" FROM " . $this->db->prefix() .
"product_price";
3411 $sql .=
" WHERE fk_product = " . ((int) $objp->rowid);
3412 $sql .=
" AND entity IN (" .
getEntity(
'productprice') .
")";
3413 $sql .=
" AND price_level = " . ((int) $price_level);
3414 $sql .=
" ORDER BY date_price DESC, rowid DESC";
3417 dol_syslog(get_class($this) .
'::constructProductListOption search price for product ' . $objp->rowid .
' AND level ' . $price_level, LOG_DEBUG);
3418 $result2 = $this->db->query($sql);
3420 $objp2 = $this->db->fetch_object($result2);
3423 if ($objp2->price_base_type ==
'HT') {
3424 $opt .=
' - ' .
price($objp2->price, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"HT");
3425 $outval .=
' - ' .
price($objp2->price, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"HT");
3427 $opt .=
' - ' .
price($objp2->price_ttc, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"TTC");
3428 $outval .=
' - ' .
price($objp2->price_ttc, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3430 $outprice_ht =
price($objp2->price);
3431 $outprice_ttc =
price($objp2->price_ttc);
3432 $outpricebasetype = $objp2->price_base_type;
3434 $outtva_tx = $objp2->tva_tx;
3435 $outdefault_vat_code = $objp2->default_vat_code;
3437 $outtva_tx = $objp->tva_tx;
3438 $outdefault_vat_code = $objp->default_vat_code;
3447 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1 && (
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
3449 $outqty = $objp->quantity;
3450 $outdiscount = $objp->remise_percent;
3451 if ($objp->quantity == 1) {
3452 $opt .=
' - ' .
price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency) .
"/";
3453 $outval .=
' - ' .
price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency) .
"/";
3454 $opt .= $langs->trans(
"Unit");
3455 $outval .= $langs->transnoentities(
"Unit");
3457 $opt .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1, $conf->currency) .
"/" . $objp->quantity;
3458 $outval .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1, $conf->currency) .
"/" . $objp->quantity;
3459 $opt .= $langs->trans(
"Units");
3460 $outval .= $langs->transnoentities(
"Units");
3463 $outprice_ht =
price($objp->unitprice);
3464 $outprice_ttc =
price($objp->unitprice * (1 + ($objp->tva_tx / 100)));
3465 $outpricebasetype = $objp->price_base_type;
3466 $outtva_tx = $objp->tva_tx;
3467 $outdefault_vat_code = $objp->default_vat_code;
3469 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1) {
3470 $opt .=
" (" .
price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency) .
"/" . $langs->trans(
"Unit") .
")";
3471 $outval .=
" (" .
price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency) .
"/" . $langs->transnoentities(
"Unit") .
")";
3473 if (empty($hidepriceinlabel) && !empty($objp->remise_percent) && $objp->remise_percent >= 1) {
3474 $opt .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3475 $outval .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3480 if (!empty($objp->idprodcustprice)) {
3483 if ($objp->custprice_base_type ==
'HT') {
3484 $opt .=
' - ' .
price($objp->custprice, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"HT");
3485 $outval .=
' - ' .
price($objp->custprice, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"HT");
3487 $opt .=
' - ' .
price($objp->custprice_ttc, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"TTC");
3488 $outval .=
' - ' .
price($objp->custprice_ttc, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3491 $outprice_ht =
price($objp->custprice);
3492 $outprice_ttc =
price($objp->custprice_ttc);
3493 $outpricebasetype = $objp->custprice_base_type;
3494 $outtva_tx = $objp->custtva_tx;
3495 $outdefault_vat_code = $objp->custdefault_vat_code;
3500 if (empty($hidepriceinlabel) && !$found) {
3501 if ($objp->price_base_type ==
'HT') {
3502 $opt .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"HT");
3503 $outval .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"HT");
3505 $opt .=
' - ' .
price($objp->price_ttc, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"TTC");
3506 $outval .=
' - ' .
price($objp->price_ttc, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3508 $outprice_ht =
price($objp->price);
3509 $outprice_ttc =
price($objp->price_ttc);
3510 $outpricebasetype = $objp->price_base_type;
3511 $outtva_tx = $objp->tva_tx;
3512 $outdefault_vat_code = $objp->default_vat_code;
3516 if ($user->hasRight(
'stock',
'lire')) {
3517 $opt .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'));
3519 if ($objp->stock > 0) {
3520 $outval .=
' - <span class="product_line_stock_ok">';
3521 } elseif ($objp->stock <= 0) {
3522 $outval .=
' - <span class="product_line_stock_too_low">';
3524 $outval .= $langs->transnoentities(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'));
3525 $outval .=
'</span>';
3526 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
3527 $langs->load(
"stocks");
3529 $tmpproduct =
new Product($this->db);
3530 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
3531 $tmpproduct->load_virtual_stock();
3532 $virtualstock = $tmpproduct->stock_theorique;
3534 $opt .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
3536 $outval .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
3537 if ($virtualstock > 0) {
3538 $outval .=
'<span class="product_line_stock_ok">';
3539 } elseif ($virtualstock <= 0) {
3540 $outval .=
'<span class="product_line_stock_too_low">';
3542 $outval .= $virtualstock;
3543 $outval .=
'</span>';
3550 $parameters = array(
'objp' => $objp);
3551 $reshook = $hookmanager->executeHooks(
'constructProductListOption', $parameters);
3552 if (empty($reshook)) {
3553 $opt .= $hookmanager->resPrint;
3555 $opt = $hookmanager->resPrint;
3558 $opt .=
"</option>\n";
3563 'label2' => $outlabel,
3567 'price_ttc' =>
price2num($outprice_ttc),
3570 'pricebasetype' => $outpricebasetype,
3571 'tva_tx' => $outtva_tx,
3572 'default_vat_code' => $outdefault_vat_code,
3574 'discount' => $outdiscount,
3575 'duration_value' => $outdurationvalue,
3576 'duration_unit' => $outdurationunit,
3578 'labeltrans' => $outlabel_translated,
3579 'desctrans' => $outdesc_translated,
3580 'ref_customer' => $outrefcust
3651 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 =
'')
3654 global $langs, $conf, $user;
3655 global $hookmanager;
3658 $outarray = array();
3660 $maxlengtharticle = (!
getDolGlobalString(
'PRODUCT_MAX_LENGTH_COMBO') ? 48 : $conf->global->PRODUCT_MAX_LENGTH_COMBO);
3662 $langs->load(
'stocks');
3665 $langs->load(
'other');
3668 $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,";
3669 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice, pfp.barcode";
3670 $sql .=
", pfp.multicurrency_code, pfp.multicurrency_unitprice";
3671 $sql .=
", pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.default_vat_code, pfp.fk_soc, s.nom as name";
3672 $sql .=
", pfp.supplier_reputation";
3675 $sql .=
", pfp.desc_fourn as description";
3677 $sql .=
", p.description";
3681 $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";
3683 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
3684 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN (" .
getEntity(
'product') .
") )";
3686 $sql .=
" AND pfp.fk_soc = " . ((int) $socid);
3688 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
3691 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
3693 $sql .=
" WHERE p.entity IN (" .
getEntity(
'product') .
")";
3694 if ($statut != -1) {
3695 $sql .=
" AND p.tobuy = " . ((int) $statut);
3697 if (strval($filtertype) !=
'') {
3698 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
3700 if (!empty($filtre)) {
3701 $sql .=
" " . $filtre;
3704 $parameters = array();
3705 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListWhere', $parameters);
3706 $sql .= $hookmanager->resPrint;
3708 if ($filterkey !=
'') {
3712 $search_crit = explode(
' ', $filterkey);
3714 if (count($search_crit) > 1) {
3717 foreach ($search_crit as $crit) {
3721 $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) .
"%'";
3723 $sql .=
" OR pfp.desc_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3728 if (count($search_crit) > 1) {
3731 if (isModEnabled(
'barcode')) {
3732 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3733 $sql .=
" OR pfp.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3737 $sql .=
" ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC";
3738 $sql .= $this->db->plimit($limit, 0);
3742 dol_syslog(get_class($this) .
"::select_produits_fournisseurs_list", LOG_DEBUG);
3743 $result = $this->db->query($sql);
3745 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3746 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
3748 $num = $this->db->num_rows($result);
3751 $out .=
'<select class="flat ' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'">';
3753 $out .=
'<option value="-1" selected>' . ($placeholder ? $placeholder :
' ') .
'</option>';
3755 $out .=
'<option value="-1">' . ($placeholder ? $placeholder :
' ') .
'</option>';
3760 $objp = $this->db->fetch_object($result);
3762 if (is_null($objp->idprodfournprice)) {
3764 $objp->tva_tx = $objp->tva_tx_sale;
3765 $objp->default_vat_code = $objp->default_vat_code_sale;
3768 $outkey = $objp->idprodfournprice;
3769 if (!$outkey && $alsoproductwithnosupplierprice) {
3770 $outkey =
'idprod_' . $objp->rowid;
3773 $outref = $objp->ref;
3774 $outbarcode = $objp->barcode;
3777 $outtype = $objp->fk_product_type;
3784 if (!empty($objp->unit_short)) {
3785 $outvalUnits .=
' - ' . $objp->unit_short;
3787 if (!empty($objp->weight) && $objp->weight_units !==
null) {
3789 $outvalUnits .=
' - ' . $unitToShow;
3791 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
3792 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
3793 $outvalUnits .=
' - ' . $unitToShow;
3795 if (!empty($objp->surface) && $objp->surface_units !==
null) {
3797 $outvalUnits .=
' - ' . $unitToShow;
3799 if (!empty($objp->volume) && $objp->volume_units !==
null) {
3801 $outvalUnits .=
' - ' . $unitToShow;
3803 if ($outdurationvalue && $outdurationunit) {
3805 'h' => $langs->trans(
'Hour'),
3806 'd' => $langs->trans(
'Day'),
3807 'w' => $langs->trans(
'Week'),
3808 'm' => $langs->trans(
'Month'),
3809 'y' => $langs->trans(
'Year')
3811 if (isset($da[$outdurationunit])) {
3812 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
3817 $objRef = $objp->ref;
3818 if ($filterkey && $filterkey !=
'') {
3819 $objRef = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRef, 1);
3821 $objRefFourn = $objp->ref_fourn;
3822 if ($filterkey && $filterkey !=
'') {
3823 $objRefFourn = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRefFourn, 1);
3825 $label = $objp->label;
3826 if ($filterkey && $filterkey !=
'') {
3827 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
3830 switch ($objp->fk_product_type) {
3842 if (empty($picto)) {
3845 $optlabel =
img_object(
'', $picto,
'class="paddingright classfortooltip"', 0, 0, 1);
3848 $optlabel .= $objp->ref;
3849 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
3850 $optlabel .=
' <span class="opacitymedium">(' . $objp->ref_fourn .
')</span>';
3852 if (isModEnabled(
'barcode') && !empty($objp->barcode)) {
3853 $optlabel .=
' (' . $outbarcode .
')';
3855 $optlabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3857 $outvallabel = $objRef;
3858 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
3859 $outvallabel .=
' (' . $objRefFourn .
')';
3861 if (isModEnabled(
'barcode') && !empty($objp->barcode)) {
3862 $outvallabel .=
' (' . $outbarcode .
')';
3864 $outvallabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3867 $optlabel .= $outvalUnits;
3868 $outvallabel .= $outvalUnits;
3870 if (!empty($objp->idprodfournprice)) {
3871 $outqty = $objp->quantity;
3872 $outdiscount = $objp->remise_percent;
3873 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
3875 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
3876 $prod_supplier->id = $objp->fk_product;
3877 $prod_supplier->fourn_qty = $objp->quantity;
3878 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
3879 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
3881 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3883 $price_result = $priceparser->parseProductSupplier($prod_supplier);
3884 if ($price_result >= 0) {
3885 $objp->fprice = $price_result;
3886 if ($objp->quantity >= 1) {
3887 $objp->unitprice = $objp->fprice / $objp->quantity;
3891 if ($objp->quantity == 1) {
3892 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency) .
"/";
3893 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1, $conf->currency) .
"/";
3894 $optlabel .= $langs->trans(
"Unit");
3895 $outvallabel .= $langs->transnoentities(
"Unit");
3897 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency) .
"/" . $objp->quantity;
3898 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1, $conf->currency) .
"/" . $objp->quantity;
3899 $optlabel .=
' ' . $langs->trans(
"Units");
3900 $outvallabel .=
' ' . $langs->transnoentities(
"Units");
3903 if ($objp->quantity > 1) {
3904 $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") .
")";
3905 $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") .
")";
3907 if ($objp->remise_percent >= 1) {
3908 $optlabel .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3909 $outvallabel .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3911 if ($objp->duration) {
3912 $optlabel .=
" - " . $objp->duration;
3913 $outvallabel .=
" - " . $objp->duration;
3916 $optlabel .=
" - " .
dol_trunc($objp->name, 8);
3917 $outvallabel .=
" - " .
dol_trunc($objp->name, 8);
3919 if ($objp->supplier_reputation) {
3921 $reputations = array(
'' => $langs->trans(
'Standard'),
'FAVORITE' => $langs->trans(
'Favorite'),
'NOTTHGOOD' => $langs->trans(
'NotTheGoodQualitySupplier'),
'DONOTORDER' => $langs->trans(
'DoNotOrderThisProductToThisSupplier'));
3923 $optlabel .=
" - " . $reputations[$objp->supplier_reputation];
3924 $outvallabel .=
" - " . $reputations[$objp->supplier_reputation];
3927 $optlabel .=
" - <span class='opacitymedium'>" . $langs->trans(
"NoPriceDefinedForThisSupplier") .
'</span>';
3928 $outvallabel .=
' - ' . $langs->transnoentities(
"NoPriceDefinedForThisSupplier");
3932 $novirtualstock = ($showstockinlist == 2);
3934 if ($user->hasRight(
'stock',
'lire')) {
3935 $outvallabel .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'));
3937 if ($objp->stock > 0) {
3938 $optlabel .=
' - <span class="product_line_stock_ok">';
3939 } elseif ($objp->stock <= 0) {
3940 $optlabel .=
' - <span class="product_line_stock_too_low">';
3942 $optlabel .= $langs->transnoentities(
"Stock") .
':' .
price(
price2num($objp->stock,
'MS'));
3943 $optlabel .=
'</span>';
3944 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
3945 $langs->load(
"stocks");
3947 $tmpproduct =
new Product($this->db);
3948 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
3949 $tmpproduct->load_virtual_stock();
3950 $virtualstock = $tmpproduct->stock_theorique;
3952 $outvallabel .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
3954 $optlabel .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
3955 if ($virtualstock > 0) {
3956 $optlabel .=
'<span class="product_line_stock_ok">';
3957 } elseif ($virtualstock <= 0) {
3958 $optlabel .=
'<span class="product_line_stock_too_low">';
3960 $optlabel .= $virtualstock;
3961 $optlabel .=
'</span>';
3968 $optstart =
'<option value="' . $outkey .
'"';
3969 if ($selected && $selected == $objp->idprodfournprice) {
3970 $optstart .=
' selected';
3972 if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) {
3973 $optstart .=
' disabled';
3976 if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) {
3985 $optstart .=
' data-default-vat-code="' .
dol_escape_htmltag($objp->default_vat_code) .
'"';
3987 if (isModEnabled(
'multicurrency')) {
3988 $optstart .=
' data-multicurrency-code="' .
dol_escape_htmltag($objp->multicurrency_code) .
'"';
3989 $optstart .=
' data-multicurrency-up="' .
dol_escape_htmltag($objp->multicurrency_unitprice) .
'"';
3992 $optstart .=
' data-description="' .
dol_escape_htmltag($objp->description, 0, 1) .
'"';
3994 $outarrayentry = array(
3997 'label' => $outvallabel,
3999 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4000 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4001 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4002 'tva_tx_formated' =>
price($objp->tva_tx, 0, $langs, 1, -1, 2),
4004 'default_vat_code' => $objp->default_vat_code,
4005 'supplier_ref' => $objp->ref_fourn,
4006 'discount' => $outdiscount,
4008 'duration_value' => $outdurationvalue,
4009 'duration_unit' => $outdurationunit,
4010 'disabled' => empty($objp->idprodfournprice),
4011 'description' => $objp->description
4013 if (isModEnabled(
'multicurrency')) {
4014 $outarrayentry[
'multicurrency_code'] = $objp->multicurrency_code;
4015 $outarrayentry[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4018 $parameters = array(
4020 'optstart' => &$optstart,
4021 'optlabel' => &$optlabel,
4022 'outvallabel' => &$outvallabel,
4023 'outarrayentry' => &$outarrayentry
4025 $reshook = $hookmanager->executeHooks(
'selectProduitsFournisseurListOption', $parameters, $this);
4031 $out .= $optstart .
' data-html="' .
dol_escape_htmltag($optlabel) .
'">' . $optlabel .
"</option>\n";
4032 $outarraypush = array(
4035 'label' => $outvallabel,
4037 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4038 'price_qty_ht_locale' =>
price($objp->fprice),
4039 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4040 'price_unit_ht_locale' =>
price($objp->unitprice),
4041 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4042 'tva_tx_formated' =>
price($objp->tva_tx),
4044 'default_vat_code' => $objp->default_vat_code,
4045 'supplier_ref' => $objp->ref_fourn,
4046 'discount' => $outdiscount,
4048 'duration_value' => $outdurationvalue,
4049 'duration_unit' => $outdurationunit,
4050 'disabled' => (empty($objp->idprodfournprice) ?
true :
false),
4051 'description' => $objp->description
4053 if (isModEnabled(
'multicurrency')) {
4054 $outarraypush[
'multicurrency_code'] = $objp->multicurrency_code;
4055 $outarraypush[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4057 array_push($outarray, $outarraypush);
4070 $out .=
'</select>';
4072 $this->db->free($result);
4074 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
4080 if (empty($outputmode)) {
5426 public function formconfirm($page, $title, $question, $action, $formquestion =
'', $selectedchoice =
'', $useajax = 0, $height = 0, $width = 500, $disableformtag = 0, $labelbuttonyes =
'Yes', $labelbuttonno =
'No')
5428 global $langs, $conf;
5430 $more =
'<!-- formconfirm - before call, page=' .
dol_escape_htmltag($page) .
' -->';
5436 $newselectedchoice = empty($selectedchoice) ?
"no" : $selectedchoice;
5437 if ($conf->browser->layout ==
'phone') {
5442 if (empty($height)) {
5444 if (is_array($formquestion) && count($formquestion) > 2) {
5445 $height += ((count($formquestion) - 2) * 24);
5449 if (is_array($formquestion) && !empty($formquestion)) {
5451 foreach ($formquestion as $key => $input) {
5452 if (is_array($input) && !empty($input)) {
5453 if ($input[
'type'] ==
'hidden') {
5454 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
5455 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
5463 $moreonecolumn =
'';
5464 $more .=
'<div class="tagtable paddingtopbottomonly centpercent noborderspacing">' .
"\n";
5465 foreach ($formquestion as $key => $input) {
5466 if (is_array($input) && !empty($input)) {
5467 $size = (!empty($input[
'size']) ?
' size="' . $input[
'size'] .
'"' :
'');
5468 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
5469 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
5471 if ($input[
'type'] ==
'text') {
5472 $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";
5473 } elseif ($input[
'type'] ==
'password') {
5474 $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";
5475 } elseif ($input[
'type'] ==
'textarea') {
5481 $moreonecolumn .=
'<div class="margintoponly">';
5482 $moreonecolumn .= $input[
'label'] .
'<br>';
5484 $moreonecolumn .= $input[
'value'];
5485 $moreonecolumn .=
'</textarea>';
5486 $moreonecolumn .=
'</div>';
5487 } elseif (in_array($input[
'type'], [
'select',
'multiselect'])) {
5488 if (empty($morecss)) {
5489 $morecss =
'minwidth100';
5492 $show_empty = isset($input[
'select_show_empty']) ? $input[
'select_show_empty'] : 1;
5493 $key_in_label = isset($input[
'select_key_in_label']) ? $input[
'select_key_in_label'] : 0;
5494 $value_as_key = isset($input[
'select_value_as_key']) ? $input[
'select_value_as_key'] : 0;
5495 $translate = isset($input[
'select_translate']) ? $input[
'select_translate'] : 0;
5496 $maxlen = isset($input[
'select_maxlen']) ? $input[
'select_maxlen'] : 0;
5497 $disabled = isset($input[
'select_disabled']) ? $input[
'select_disabled'] : 0;
5498 $sort = isset($input[
'select_sort']) ? $input[
'select_sort'] :
'';
5500 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">';
5501 if (!empty($input[
'label'])) {
5502 $more .= $input[
'label'] .
'</div><div class="tagtd left">';
5504 if ($input[
'type'] ==
'select') {
5505 $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);
5507 $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);
5509 $more .=
'</div></div>' .
"\n";
5510 } elseif ($input[
'type'] ==
'checkbox') {
5511 $more .=
'<div class="tagtr">';
5512 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'"><label for="' .
dol_escape_htmltag($input[
'name']) .
'">' . $input[
'label'] .
'</label></div><div class="tagtd">';
5513 $more .=
'<input type="checkbox" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' .
dol_escape_htmltag($input[
'name']) .
'" name="' .
dol_escape_htmltag($input[
'name']) .
'"' . $moreattr;
5514 if (!is_bool($input[
'value']) && $input[
'value'] !=
'false' && $input[
'value'] !=
'0' && $input[
'value'] !=
'') {
5515 $more .=
' checked';
5517 if (is_bool($input[
'value']) && $input[
'value']) {
5518 $more .=
' checked';
5520 if (isset($input[
'disabled'])) {
5521 $more .=
' disabled';
5523 $more .=
' /></div>';
5524 $more .=
'</div>' .
"\n";
5525 } elseif ($input[
'type'] ==
'radio') {
5527 foreach ($input[
'values'] as $selkey => $selval) {
5528 $more .=
'<div class="tagtr">';
5529 if (isset($input[
'label'])) {
5531 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
' tdtop' : (
' tdtop ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
5533 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' "' . $input[
'tdclass'])) .
'"> </div>';
5536 $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;
5537 if (!empty($input[
'disabled'])) {
5538 $more .=
' disabled';
5540 if (isset($input[
'default']) && $input[
'default'] === $selkey) {
5541 $more .=
' checked="checked"';
5544 $more .=
'<label for="' .
dol_escape_htmltag($input[
'name'] . $selkey) .
'" class="valignmiddle">' . $selval .
'</label>';
5545 $more .=
'</div></div>' .
"\n";
5548 } elseif ($input[
'type'] ==
'date' || $input[
'type'] ==
'datetime') {
5549 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
5550 $more .=
'<div class="tagtd">';
5551 $addnowlink = (empty($input[
'datenow']) ? 0 : 1);
5553 if ($input[
'type'] ==
'datetime') {
5554 $h = isset($input[
'hours']) ? $input[
'hours'] : 1;
5555 $m = isset($input[
'minutes']) ? $input[
'minutes'] : 1;
5557 $more .= $this->
selectDate(isset($input[
'value']) ? $input[
'value'] : -1, $input[
'name'], $h, $m, 0,
'', 1, $addnowlink);
5558 $more .=
'</div></div>'.
"\n";
5559 $formquestion[] = array(
'name' => $input[
'name'].
'day');
5560 $formquestion[] = array(
'name' => $input[
'name'].
'month');
5561 $formquestion[] = array(
'name' => $input[
'name'].
'year');
5562 $formquestion[] = array(
'name' => $input[
'name'].
'hour');
5563 $formquestion[] = array(
'name' => $input[
'name'].
'min');
5564 } elseif ($input[
'type'] ==
'other') {
5565 $more .=
'<div class="tagtr"><div class="tagtd'.(empty($input[
'tdclass']) ?
'' : (
' '.$input[
'tdclass'])).
'">';
5566 if (!empty($input[
'label'])) {
5567 $more .= $input[
'label'] .
'</div><div class="tagtd">';
5569 $more .= $input[
'value'];
5570 $more .=
'</div></div>' .
"\n";
5571 } elseif ($input[
'type'] ==
'onecolumn') {
5572 $moreonecolumn .=
'<div class="margintoponly">';
5573 $moreonecolumn .= $input[
'value'];
5574 $moreonecolumn .=
'</div>' .
"\n";
5575 } elseif ($input[
'type'] ==
'hidden') {
5577 } elseif ($input[
'type'] ==
'separator') {
5580 $more .=
'Error type ' . $input[
'type'] .
' for the confirm box is not a supported type';
5584 $more .=
'</div>' .
"\n";
5585 $more .= $moreonecolumn;
5591 if (!empty($conf->dol_use_jmobile)) {
5594 if (empty($conf->use_javascript_ajax)) {
5600 $dialogconfirm =
'dialog-confirm';
5602 if (!is_numeric($useajax)) {
5606 $dialogconfirm .=
'-' . $button;
5608 $pageyes = $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=yes';
5609 $pageno = ($useajax == 2 ? $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=no' :
'');
5612 if (is_array($formquestion)) {
5613 foreach ($formquestion as $key => $input) {
5616 if (is_array($input) && isset($input[
'name'])) {
5617 if (strpos($input[
'name'],
',') > 0) {
5618 $inputok = array_merge($inputok, explode(
',', $input[
'name']));
5620 array_push($inputok, $input[
'name']);
5625 if (is_array($input) && isset($input[
'inputko']) && $input[
'inputko'] == 1 && isset($input[
'name'])) {
5626 array_push($inputko, $input[
'name']);
5632 $formconfirm .=
'<div id="' . $dialogconfirm .
'" title="' .
dol_escape_htmltag($title) .
'" style="display: none;">';
5633 if (is_array($formquestion) && array_key_exists(
'text', $formquestion) && !empty($formquestion[
'text'])) {
5634 $formconfirm .=
'<div class="confirmtext">' . $formquestion[
'text'] .
'</div>' .
"\n";
5636 if (!empty($more)) {
5637 $formconfirm .=
'<div class="confirmquestions">' . $more .
'</div>' .
"\n";
5639 $formconfirm .= ($question ?
'<div class="confirmmessage">' .
img_help(0,
'') .
' ' . $question .
'</div>' :
'');
5640 $formconfirm .=
'</div>' .
"\n";
5642 $formconfirm .=
"\n<!-- begin code of popup for formconfirm page=" . $page .
" -->\n";
5643 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
5644 $formconfirm .=
"/* Code for the jQuery('#dialogforpopup').dialog() */\n";
5645 $formconfirm .=
'jQuery(document).ready(function() {
5647 $( "#' . $dialogconfirm .
'" ).dialog(
5649 autoOpen: ' . ($autoOpen ?
"true" :
"false") .
',';
5650 if ($newselectedchoice ==
'no') {
5653 $(this).parent().find("button.ui-button:eq(2)").focus();
5658 if ($useajax == 1) {
5659 $jsforcursor =
'// The call to urljump can be slow, so we set the wait cursor' .
"\n";
5660 $jsforcursor .=
'jQuery("html,body,#id-container").addClass("cursorwait");' .
"\n";
5663 $postconfirmas =
'GET';
5667 height: "' . $height .
'",
5668 width: "' . $width .
'",
5670 closeOnEscape: false,
5672 "' .
dol_escape_js($langs->transnoentities($labelbuttonyes)) .
'": function() {
5673 var options = "token=' . urlencode(
newToken()) .
'";
5674 var inputok = ' . json_encode($inputok) .
'; /* List of fields into form */
5675 var page = "' .
dol_escape_js(!empty($page) ? $page :
'') .
'";
5676 var pageyes = "' .
dol_escape_js(!empty($pageyes) ? $pageyes :
'') .
'";
5678 if (inputok.length > 0) {
5679 $.each(inputok, function(i, inputname) {
5682 if ($("input[name=\'" + inputname + "\']").attr("type") == "radio") {
5683 inputvalue = $("input[name=\'" + inputname + "\']:checked").val();
5685 if ($("#" + inputname).attr("type") == "checkbox") { more = ":checked"; }
5686 inputvalue = $("#" + inputname + more).val();
5688 if (typeof inputvalue == "undefined") { inputvalue=""; }
5689 console.log("formconfirm check inputname="+inputname+" inputvalue="+inputvalue);
5690 options += "&" + inputname + "=" + encodeURIComponent(inputvalue);
5693 var urljump = pageyes + (pageyes.indexOf("?") < 0 ? "?" : "&") + options;
5694 if (pageyes.length > 0) {';
5695 if ($postconfirmas ==
'GET') {
5696 $formconfirm .=
'location.href = urljump;';
5698 $formconfirm .= $jsforcursor;
5699 $formconfirm .=
'var post = $.post(
5702 function(data) { $("body").html(data); jQuery("html,body,#id-container").removeClass("cursorwait"); }
5706 console.log("after post ok");
5708 $(this).dialog("close");
5710 "' .
dol_escape_js($langs->transnoentities($labelbuttonno)) .
'": function() {
5711 var options = "token=' . urlencode(
newToken()) .
'";
5712 var inputko = ' . json_encode($inputko) .
'; /* List of fields into form */
5713 var page = "' .
dol_escape_js(!empty($page) ? $page :
'') .
'";
5714 var pageno="' .
dol_escape_js(!empty($pageno) ? $pageno :
'') .
'";
5715 if (inputko.length > 0) {
5716 $.each(inputko, function(i, inputname) {
5718 if ($("#" + inputname).attr("type") == "checkbox") { more = ":checked"; }
5719 var inputvalue = $("#" + inputname + more).val();
5720 if (typeof inputvalue == "undefined") { inputvalue=""; }
5721 options += "&" + inputname + "=" + encodeURIComponent(inputvalue);
5724 var urljump=pageno + (pageno.indexOf("?") < 0 ? "?" : "&") + options;
5726 if (pageno.length > 0) {';
5727 if ($postconfirmas ==
'GET') {
5728 $formconfirm .=
'location.href = urljump;';
5730 $formconfirm .= $jsforcursor;
5731 $formconfirm .=
'var post = $.post(
5734 function(data) { $("body").html(data); jQuery("html,body,#id-container").removeClass("cursorwait"); }
5738 console.log("after post ko");
5740 $(this).dialog("close");
5746 var button = "' . $button .
'";
5747 if (button.length > 0) {
5748 $( "#" + button ).click(function() {
5749 $("#' . $dialogconfirm .
'").dialog("open");
5755 $formconfirm .=
"<!-- end ajax formconfirm -->\n";
5757 $formconfirm .=
"\n<!-- begin formconfirm page=" .
dol_escape_htmltag($page) .
" -->\n";
5759 if (empty($disableformtag)) {
5760 $formconfirm .=
'<form method="POST" action="' . $page .
'" class="notoptoleftroright">' .
"\n";
5763 $formconfirm .=
'<input type="hidden" name="action" value="' . $action .
'">' .
"\n";
5764 $formconfirm .=
'<input type="hidden" name="token" value="' .
newToken() .
'">' .
"\n";
5766 $formconfirm .=
'<table class="valid centpercent">' .
"\n";
5769 $formconfirm .=
'<tr class="validtitre"><td class="validtitre" colspan="2">';
5770 $formconfirm .=
img_picto(
'',
'pictoconfirm') .
' ' . $title;
5771 $formconfirm .=
'</td></tr>' .
"\n";
5774 if (is_array($formquestion) && array_key_exists(
'text', $formquestion) && !empty($formquestion[
'text'])) {
5775 $formconfirm .=
'<tr class="valid"><td class="valid" colspan="2">' . $formquestion[
'text'] .
'</td></tr>' .
"\n";
5780 $formconfirm .=
'<tr class="valid"><td class="valid" colspan="2">' .
"\n";
5781 $formconfirm .= $more;
5782 $formconfirm .=
'</td></tr>' .
"\n";
5786 $formconfirm .=
'<tr class="valid">';
5787 $formconfirm .=
'<td class="valid">' . $question .
'</td>';
5788 $formconfirm .=
'<td class="valid center">';
5789 $formconfirm .= $this->
selectyesno(
"confirm", $newselectedchoice, 0,
false, 0, 0,
'marginleftonly marginrightonly', $labelbuttonyes, $labelbuttonno);
5790 $formconfirm .=
'<input class="button valignmiddle confirmvalidatebutton small" type="submit" value="' . $langs->trans(
"Validate") .
'">';
5791 $formconfirm .=
'</td>';
5792 $formconfirm .=
'</tr>' .
"\n";
5794 $formconfirm .=
'</table>' .
"\n";
5796 if (empty($disableformtag)) {
5797 $formconfirm .=
"</form>\n";
5799 $formconfirm .=
'<br>';
5801 if (!empty($conf->use_javascript_ajax)) {
5802 $formconfirm .=
'<!-- code to disable button to avoid double clic -->';
5803 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
5805 $(document).ready(function () {
5806 $(".confirmvalidatebutton").on("click", function() {
5807 console.log("We click on button confirmvalidatebutton");
5808 $(this).attr("disabled", "disabled");
5809 setTimeout(\'$(".confirmvalidatebutton").removeAttr("disabled")\', 3000);
5810 //console.log($(this).closest("form"));
5811 $(this).closest("form").submit();
5815 $formconfirm .=
'</script>' .
"\n";
5818 $formconfirm .=
"<!-- end formconfirm -->\n";
5821 return $formconfirm;