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);
938 public function select_country($selected =
'', $htmlname =
'country_id', $htmloption =
'', $maxlength = 0, $morecss =
'minwidth300', $usecodeaskey =
'', $showempty = 1, $disablefavorites = 0, $addspecialentries = 0, $exclude_country_code = array(), $hideflags = 0)
941 global
$conf, $langs, $mysoc;
943 $langs->load(
"dict");
946 $countryArray = array();
949 $atleastonefavorite = 0;
951 $sql =
"SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite, eec";
952 $sql .=
" FROM " . $this->db->prefix() .
"c_country";
953 $sql .=
" WHERE active > 0";
956 dol_syslog(get_class($this) .
"::select_country", LOG_DEBUG);
957 $resql = $this->db->query($sql);
959 $out .=
'<select id="select' . $htmlname .
'" class="flat maxwidth200onsmartphone selectcountry' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" ' . $htmloption .
'>';
960 $num = $this->db->num_rows($resql);
964 $obj = $this->db->fetch_object($resql);
966 $countryArray[$i][
'rowid'] = $obj->rowid;
967 $countryArray[$i][
'code_iso'] = $obj->code_iso;
968 $countryArray[$i][
'code_iso3'] = $obj->code_iso3;
969 $countryArray[$i][
'label'] = ($obj->code_iso && $langs->transnoentitiesnoconv(
"Country" . $obj->code_iso) !=
"Country" . $obj->code_iso ? $langs->transnoentitiesnoconv(
"Country" . $obj->code_iso) : ($obj->label !=
'-' ? $obj->label :
''));
970 $countryArray[$i][
'favorite'] = $obj->favorite;
971 $countryArray[$i][
'eec'] = $obj->eec;
972 $favorite[$i] = $obj->favorite;
977 if (empty($disablefavorites)) {
978 $array1_sort_order = SORT_DESC;
979 $array2_sort_order = SORT_ASC;
980 array_multisort($favorite, $array1_sort_order, $label, $array2_sort_order, $countryArray);
986 if (is_numeric($showempty)) {
987 $out .=
'<option value=""> </option>' .
"\n";
989 $out .=
'<option value="-1">' . $langs->trans($showempty) .
'</option>' .
"\n";
993 if ($addspecialentries) {
995 $out .=
'<option value="special_allnotme"' . ($selected ==
'special_allnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesExceptMe", $langs->transnoentitiesnoconv(
"Country" . $mysoc->country_code)) .
'</option>';
996 $out .=
'<option value="special_eec"' . ($selected ==
'special_eec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEEC") .
'</option>';
997 if ($mysoc->isInEEC()) {
998 $out .=
'<option value="special_eecnotme"' . ($selected ==
'special_eecnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEECExceptMe", $langs->transnoentitiesnoconv(
"Country" . $mysoc->country_code)) .
'</option>';
1000 $out .=
'<option value="special_noteec"' . ($selected ==
'special_noteec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesNotInEEC") .
'</option>';
1001 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1004 foreach ($countryArray as $row) {
1006 if (empty($row[
'rowid'])) {
1009 if (is_array($exclude_country_code) && count($exclude_country_code) && in_array($row[
'code_iso'], $exclude_country_code)) {
1013 if (empty($disablefavorites) && $row[
'favorite'] && $row[
'code_iso']) {
1014 $atleastonefavorite++;
1016 if (empty($row[
'favorite']) && $atleastonefavorite) {
1017 $atleastonefavorite = 0;
1018 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1022 if ($row[
'label']) {
1023 $labeltoshow .=
dol_trunc($row[
'label'], $maxlength,
'middle');
1025 $labeltoshow .=
' ';
1027 if ($row[
'code_iso']) {
1028 $labeltoshow .=
' <span class="opacitymedium">(' . $row[
'code_iso'] .
')</span>';
1029 if (empty($hideflags)) {
1030 $tmpflag =
picto_from_langcode($row[
'code_iso'],
'class="saturatemedium paddingrightonly"', 1);
1031 $labeltoshow = $tmpflag .
' ' . $labeltoshow;
1035 if ($selected && $selected !=
'-1' && ($selected == $row[
'rowid'] || $selected == $row[
'code_iso'] || $selected == $row[
'code_iso3'] || $selected == $row[
'label'])) {
1036 $out .=
'<option value="' . ($usecodeaskey ? ($usecodeaskey ==
'code2' ? $row[
'code_iso'] : $row[
'code_iso3']) : $row[
'rowid']) .
'" selected data-html="' .
dol_escape_htmltag($labeltoshow) .
'" data-eec="' . ((int) $row[
'eec']) .
'">';
1038 $out .=
'<option value="' . ($usecodeaskey ? ($usecodeaskey ==
'code2' ? $row[
'code_iso'] : $row[
'code_iso3']) : $row[
'rowid']) .
'" data-html="' .
dol_escape_htmltag($labeltoshow) .
'" data-eec="' . ((int) $row[
'eec']) .
'">';
1040 $out .= $labeltoshow;
1041 $out .=
'</option>' .
"\n";
1044 $out .=
'</select>';
1050 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1051 $out .=
ajax_combobox(
'select' . $htmlname, array(), 0, 0,
'resolve');
1503 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)
1506 global $user, $langs;
1507 global $hookmanager;
1509 $langs->loadLangs(array(
"companies",
"suppliers"));
1513 $outarray = array();
1515 if ($selected ===
'') {
1516 $selected = array();
1517 } elseif (!is_array($selected)) {
1518 $selected = array($selected);
1522 if (function_exists(
'testSqlAndScriptInject')) {
1525 return 'SQLInjectionTryDetected';
1529 if ($filter !=
'') {
1530 if (preg_match(
'/[\(\)]/', $filter)) {
1536 if (function_exists(
'testSqlAndScriptInject')) {
1539 return 'SQLInjectionTryDetected';
1545 dol_syslog(
"Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Syntax.", LOG_WARNING);
1550 $sql =
"SELECT s.rowid, s.nom as name, s.name_alias, s.tva_intra, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
1552 $sql .=
", s.address, s.zip, s.town";
1553 $sql .=
", dictp.code as country_code";
1555 $sql .=
" FROM " . $this->db->prefix() .
"societe as s";
1557 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_country as dictp ON dictp.rowid = s.fk_pays";
1559 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1560 $sql .=
", " . $this->db->prefix() .
"societe_commerciaux as sc";
1562 $sql .=
" WHERE s.entity IN (" .
getEntity(
'societe') .
")";
1563 if (!empty($user->socid)) {
1564 $sql .=
" AND s.rowid = " . ((int) $user->socid);
1569 $sql .=
" AND (" . $filter .
")";
1571 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1572 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = " . ((int) $user->id);
1575 $sql .=
" AND s.status <> 0";
1577 if (!empty($excludeids)) {
1578 $sql .=
" AND s.rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeids)) .
")";
1581 $parameters = array();
1582 $reshook = $hookmanager->executeHooks(
'selectThirdpartyListWhere', $parameters);
1583 $sql .= $hookmanager->resPrint;
1585 if ($filterkey && $filterkey !=
'') {
1589 $search_crit = explode(
' ', $filterkey);
1591 if (count($search_crit) > 1) {
1594 foreach ($search_crit as $crit) {
1598 $sql .=
"(s.nom LIKE '" . $this->db->escape($prefix . $crit) .
"%')";
1601 if (count($search_crit) > 1) {
1604 if (isModEnabled(
'barcode')) {
1605 $sql .=
" OR s.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1607 $sql .=
" OR s.code_client LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.code_fournisseur LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1608 $sql .=
" OR s.name_alias LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.tva_intra LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1611 $sql .= $this->db->order(
"nom",
"ASC");
1612 $sql .= $this->db->plimit($limit, 0);
1615 dol_syslog(get_class($this).
"::select_thirdparty_list", LOG_DEBUG);
1616 $resql = $this->db->query($sql);
1619 $out .=
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
' name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
'>' .
"\n";
1621 $textifempty = (($showempty && !is_numeric($showempty)) ? $langs->trans($showempty) :
'');
1625 if ($showempty && !is_numeric($showempty)) {
1626 $textifempty = $langs->trans($showempty);
1628 $textifempty .= $langs->trans(
"All");
1632 $out .=
'<option value="-1" data-html="' .
dol_escape_htmltag(
'<span class="opacitymedium">' . ($textifempty ? $textifempty :
' ') .
'</span>') .
'">' . $textifempty .
'</option>' .
"\n";
1635 $companytemp =
new Societe($this->db);
1637 $num = $this->db->num_rows($resql);
1641 $obj = $this->db->fetch_object($resql);
1644 if (($obj->client) && (!empty($obj->code_client))) {
1645 $label = $obj->code_client .
' - ';
1647 if (($obj->fournisseur) && (!empty($obj->code_fournisseur))) {
1648 $label .= $obj->code_fournisseur .
' - ';
1650 $label .=
' ' . $obj->name;
1652 $label = $obj->name;
1655 if (!empty($obj->name_alias)) {
1656 $label .=
' (' . $obj->name_alias .
')';
1660 $label .=
' - '.$obj->tva_intra;
1663 $labelhtml = $label;
1666 $companytemp->id = $obj->rowid;
1667 $companytemp->client = $obj->client;
1668 $companytemp->fournisseur = $obj->fournisseur;
1669 $tmptype = $companytemp->getTypeUrl(1,
'', 0,
'span');
1671 $labelhtml .=
' ' . $tmptype;
1674 if ($obj->client || $obj->fournisseur) {
1677 if ($obj->client == 1 || $obj->client == 3) {
1678 $label .= $langs->trans(
"Customer");
1680 if ($obj->client == 2 || $obj->client == 3) {
1681 $label .= ($obj->client == 3 ?
', ' :
'') . $langs->trans(
"Prospect");
1683 if ($obj->fournisseur) {
1684 $label .= ($obj->client ?
', ' :
'') . $langs->trans(
"Supplier");
1686 if ($obj->client || $obj->fournisseur) {
1692 $s = ($obj->address ?
' - ' . $obj->address :
'') . ($obj->zip ?
' - ' . $obj->zip :
'') . ($obj->town ?
' ' . $obj->town :
'');
1693 if (!empty($obj->country_code)) {
1694 $s .=
', ' . $langs->trans(
'Country' . $obj->country_code);
1700 if (empty($outputmode)) {
1701 if (in_array($obj->rowid, $selected)) {
1702 $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>';
1704 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
1707 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label,
'labelhtml' => $labelhtml));
1711 if (($i % 10) == 0) {
1716 $out .=
'</select>' .
"\n";
1718 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1725 $this->result = array(
'nbofthirdparties' => $num);
1759 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 =
'')
1761 global
$conf, $user, $langs, $hookmanager, $action;
1763 $langs->load(
'companies');
1765 if (empty($htmlid)) {
1766 $htmlid = $htmlname;
1770 $outarray = array();
1772 if ($selected ===
'') {
1773 $selected = array();
1774 } elseif (!is_array($selected)) {
1775 $selected = array((
int) $selected);
1779 if (function_exists(
'testSqlAndScriptInject')) {
1782 return 'SQLInjectionTryDetected';
1786 if ($filter !=
'') {
1787 if (preg_match(
'/[\(\)]/', $filter)) {
1793 if (function_exists(
'testSqlAndScriptInject')) {
1796 return 'SQLInjectionTryDetected';
1802 dol_syslog(
"Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Filter Syntax.", LOG_WARNING);
1806 if (!is_object($hookmanager)) {
1807 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
1812 $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";
1813 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
1814 $sql .=
", s.nom as company, s.town AS company_town";
1816 $sql .=
" FROM " . $this->db->prefix() .
"socpeople as sp";
1817 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
1818 $sql .=
" LEFT OUTER JOIN " . $this->db->prefix() .
"societe as s ON s.rowid=sp.fk_soc";
1820 $sql .=
" WHERE sp.entity IN (" .
getEntity(
'contact') .
")";
1821 $sql .=
" AND ((sp.fk_user_creat = ".((int) $user->id).
" AND sp.priv = 1) OR sp.priv = 0)";
1822 if ($socid > 0 || $socid == -1) {
1823 $sql .=
" AND sp.fk_soc = " . ((int) $socid);
1826 $sql .=
" AND sp.statut <> 0";
1831 $sql .=
" AND (" . $filter .
")";
1834 $parameters = array();
1835 $reshook = $hookmanager->executeHooks(
'selectContactListWhere', $parameters);
1836 $sql .= $hookmanager->resPrint;
1837 $sql .=
" ORDER BY sp.lastname ASC";
1839 dol_syslog(get_class($this) .
"::selectcontacts", LOG_DEBUG);
1840 $resql = $this->db->query($sql);
1842 $num = $this->db->num_rows($resql);
1844 if ($htmlname !=
'none' && !$options_only) {
1845 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlid .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . (($num || empty($disableifempty)) ?
'' :
' disabled') . ($multiple ?
'multiple' :
'') .
' ' . (!empty($moreparam) ? $moreparam :
'') .
'>';
1848 if ($showempty && !is_numeric($showempty)) {
1849 $textforempty = $showempty;
1850 $out .=
'<option class="optiongrey" value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'>' . $textforempty .
'</option>';
1852 if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) {
1853 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'> </option>';
1855 if ($showempty == 2) {
1856 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Internal") .
' --</option>';
1862 include_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
1863 $contactstatic =
new Contact($this->db);
1866 $obj = $this->db->fetch_object($resql);
1869 $extendedInfos =
'';
1871 $extendedInfos = array();
1872 $email = trim($obj->email);
1873 if (!empty($email)) {
1874 $extendedInfos[] = $email;
1876 $phone = trim($obj->phone);
1877 $phone_perso = trim($obj->phone_perso);
1878 $phone_mobile = trim($obj->phone_mobile);
1879 if (!empty($phone)) {
1880 $extendedInfos[] = $phone;
1882 if (!empty($phone_perso)) {
1883 $extendedInfos[] = $phone_perso;
1885 if (!empty($phone_mobile)) {
1886 $extendedInfos[] = $phone_mobile;
1889 $contact_town = trim($obj->contact_town);
1890 $company_town = trim($obj->company_town);
1891 if (!empty($contact_town)) {
1892 $extendedInfos[] = $contact_town;
1893 } elseif (!empty($company_town)) {
1894 $extendedInfos[] = $company_town;
1896 $extendedInfos = implode(
' - ', $extendedInfos);
1897 if (!empty($extendedInfos)) {
1898 $extendedInfos =
' - ' . $extendedInfos;
1902 $contactstatic->id = $obj->rowid;
1903 $contactstatic->lastname = $obj->lastname;
1904 $contactstatic->firstname = $obj->firstname;
1905 if ($obj->statut == 1) {
1907 if ($htmlname !=
'none') {
1909 if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) {
1912 if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) {
1915 if (!empty($selected) && in_array($obj->rowid, $selected)) {
1916 $out .=
'<option value="' . $obj->rowid .
'"';
1918 $out .=
' disabled';
1920 $out .=
' selected>';
1922 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1923 if ($showfunction && $obj->poste) {
1924 $tmplabel .=
' (' . $obj->poste .
')';
1926 if (($showsoc > 0) && $obj->company) {
1927 $tmplabel .=
' - (' . $obj->company .
')';
1931 $out .=
'</option>';
1933 $out .=
'<option value="' . $obj->rowid .
'"';
1935 $out .=
' disabled';
1939 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1940 if ($showfunction && $obj->poste) {
1941 $tmplabel .=
' (' . $obj->poste .
')';
1943 if (($showsoc > 0) && $obj->company) {
1944 $tmplabel .=
' - (' . $obj->company .
')';
1948 $out .=
'</option>';
1951 if (in_array($obj->rowid, $selected)) {
1952 $tmplabel = $contactstatic->getFullName($langs) . $extendedInfos;
1953 if ($showfunction && $obj->poste) {
1954 $tmplabel .=
' (' . $obj->poste .
')';
1956 if (($showsoc > 0) && $obj->company) {
1957 $tmplabel .=
' - (' . $obj->company .
')';
1964 if ($tmplabel !=
'') {
1965 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $tmplabel,
'label' => $tmplabel,
'labelhtml' => $tmplabel));
1971 $labeltoshow = ($socid != -1) ? ($langs->trans($socid ?
"NoContactDefinedForThirdParty" :
"NoContactDefined")) : $langs->trans(
'SelectAThirdPartyFirst');
1972 $out .=
'<option class="disabled" value="-1"' . (($showempty == 2 || $multiple) ?
'' :
' selected') .
' disabled="disabled">';
1973 $out .= $labeltoshow;
1974 $out .=
'</option>';
1977 $parameters = array(
1979 'htmlname' => $htmlname,
1982 'showfunction' => $showfunction,
1983 'showsoc' => $showsoc,
1986 $reshook = $hookmanager->executeHooks(
'afterSelectContactOptions', $parameters, $this, $action);
1988 if ($htmlname !=
'none' && !$options_only) {
1989 $out .=
'</select>';
1992 if (
$conf->use_javascript_ajax && !$forcecombo && !$options_only) {
1993 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1999 if ($options_only === 2) {
2149 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)
2152 global
$conf, $user, $langs, $hookmanager;
2156 if ((is_numeric($selected) && ($selected < -2 || empty($selected))) && !
getDolGlobalString(
'SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE')) {
2157 $selected = $user->id;
2160 if ($selected ===
'') {
2161 $selected = array();
2162 } elseif (!is_array($selected)) {
2163 $selected = array($selected);
2166 $excludeUsers =
null;
2167 $includeUsers =
null;
2170 if (is_array($exclude)) {
2171 $excludeUsers = implode(
",", $exclude);
2174 if (is_array($include)) {
2175 $includeUsers = implode(
",", $include);
2176 } elseif ($include ==
'hierarchy') {
2178 $includeUsers = implode(
",", $user->getAllChildIds(0));
2179 } elseif ($include ==
'hierarchyme') {
2181 $includeUsers = implode(
",", $user->getAllChildIds(1));
2187 $outarray = array();
2188 $outarray2 = array();
2191 $showlabelofentity = isModEnabled(
'multicompany') && !
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE') &&
$conf->entity == 1 && !empty($user->admin) && empty($user->entity);
2192 $userissuperadminentityone = isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && empty($user->entity);
2195 $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";
2196 if ($showlabelofentity) {
2197 $sql .=
", e.label";
2199 $sql .=
" FROM " . $this->db->prefix() .
"user as u";
2200 if ($showlabelofentity) {
2201 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid = u.entity";
2204 if ($userissuperadminentityone && $force_entity !=
'default') {
2205 if (!empty($force_entity)) {
2206 $sql .=
" WHERE u.entity IN (0, " . $this->db->sanitize($force_entity) .
")";
2208 $sql .=
" WHERE u.entity IS NOT NULL";
2211 if (isModEnabled(
'multicompany') &&
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE')) {
2212 $sql .=
" WHERE u.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
2214 $sql .=
" WHERE u.entity IN (" .
getEntity(
'user') .
")";
2218 if (!empty($user->socid)) {
2219 $sql .=
" AND u.fk_soc = " . ((int) $user->socid);
2221 if (is_array($exclude) && $excludeUsers) {
2222 $sql .=
" AND u.rowid NOT IN (" . $this->db->sanitize($excludeUsers) .
")";
2224 if ($includeUsers) {
2225 $sql .=
" AND u.rowid IN (" . $this->db->sanitize($includeUsers) .
")";
2228 $sql .=
" AND u.statut <> 0";
2231 $sql .=
" AND u.employee <> 0";
2234 $sql .=
" AND u.fk_soc IS NULL";
2236 if (!empty($morefilter)) {
2239 if ($errormessage) {
2240 $this->errors[] = $errormessage;
2241 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2242 if ($outputmode == 0) {
2243 return 'Error bad param $morefilter';
2251 $reshook = $hookmanager->executeHooks(
'addSQLWhereFilterOnSelectUsers', array(), $this, $action);
2252 if (!empty($reshook)) {
2253 $sql .= $hookmanager->resPrint;
2257 $sql .=
" ORDER BY u.statut DESC, u.firstname ASC, u.lastname ASC";
2259 $sql .=
" ORDER BY u.statut DESC, u.lastname ASC, u.firstname ASC";
2262 dol_syslog(get_class($this) .
"::select_dolusers", LOG_DEBUG);
2264 $resql = $this->db->query($sql);
2266 $num = $this->db->num_rows($resql);
2270 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
' minwidth200') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
2271 if ($show_empty && !$multiple) {
2272 $textforempty =
' ';
2273 if (!empty(
$conf->use_javascript_ajax)) {
2274 $textforempty =
' ';
2276 if (!is_numeric($show_empty)) {
2277 $textforempty = $show_empty;
2279 $out .=
'<option class="optiongrey" value="' . ($show_empty < 0 ? $show_empty : -1) .
'"' . ((empty($selected) || in_array(-1, $selected)) ?
' selected' :
'') .
'>' . $textforempty .
'</option>' .
"\n";
2281 $outarray[($show_empty < 0 ? $show_empty : -1)] = $textforempty;
2282 $outarray2[($show_empty < 0 ? $show_empty : -1)] = array(
2283 'id' => ($show_empty < 0 ? $show_empty : -1),
2284 'label' => $textforempty,
2285 'labelhtml' => $textforempty,
2291 $out .=
'<option value="-2"' . ((in_array(-2, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Everybody") .
' --</option>' .
"\n";
2293 $outarray[-2] =
'-- ' . $langs->trans(
"Everybody") .
' --';
2294 $outarray2[-2] = array(
2296 'label' =>
'-- ' . $langs->trans(
"Everybody") .
' --',
2297 'labelhtml' =>
'-- ' . $langs->trans(
"Everybody") .
' --',
2303 $userstatic =
new User($this->db);
2306 $obj = $this->db->fetch_object($resql);
2308 $userstatic->id = $obj->rowid;
2309 $userstatic->lastname = $obj->lastname;
2310 $userstatic->firstname = $obj->firstname;
2311 $userstatic->photo = $obj->photo;
2312 $userstatic->status = $obj->status;
2313 $userstatic->entity = $obj->entity;
2314 $userstatic->admin = $obj->admin;
2315 $userstatic->gender = $obj->gender;
2318 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
2319 $disableline = ($enableonlytext ? $enableonlytext :
'1');
2323 $labeltoshowhtml =
'';
2330 $labeltoshow .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2331 $labeltoshowhtml .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2332 if (empty($obj->firstname) && empty($obj->lastname)) {
2333 $labeltoshow .= $obj->login;
2334 $labeltoshowhtml .= $obj->login;
2341 $moreinfo .= ($moreinfo ?
' - ' :
' (');
2342 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(');
2343 $moreinfo .= $obj->login;
2344 $moreinfohtml .= $obj->login;
2346 if ($showstatus >= 0) {
2347 if ($obj->status == 1 && $showstatus == 1) {
2348 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Enabled');
2349 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Enabled');
2351 if ($obj->status == 0 && $showstatus == 1) {
2352 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Disabled');
2353 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Disabled');
2356 if ($showlabelofentity) {
2357 if (empty($obj->entity)) {
2358 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
"AllEntities");
2359 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
"AllEntities");
2361 if ($obj->entity !=
$conf->entity) {
2362 $moreinfo .= ($moreinfo ?
' - ' :
' (') . ($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2363 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(').($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2367 $moreinfo .= (!empty($moreinfo) ?
')' :
'');
2368 $moreinfohtml .= (!empty($moreinfohtml) ?
')</span>' :
'');
2369 if (!empty($disableline) && $disableline !=
'1') {
2371 $moreinfo .=
' - ' . $disableline;
2372 $moreinfohtml .=
' - ' . $disableline;
2374 $labeltoshow .= $moreinfo;
2375 $labeltoshowhtml .= $moreinfohtml;
2377 $out .=
'<option value="' . $obj->rowid .
'"';
2378 if (!empty($disableline)) {
2379 $out .=
' disabled';
2381 if ((!empty($selected[0]) && is_object($selected[0])) ? $selected[0]->id == $obj->rowid : in_array($obj->rowid, $selected)) {
2382 $out .=
' selected';
2384 $out .=
' data-html="';
2386 $outhtml = $userstatic->getNomUrl(-3,
'', 0, 1, 24, 1,
'login',
'', 1) .
' ';
2387 if ($showstatus >= 0 && $obj->status == 0) {
2388 $outhtml .=
'<strike class="opacitymediumxxx">';
2390 $outhtml .= $labeltoshowhtml;
2391 if ($showstatus >= 0 && $obj->status == 0) {
2392 $outhtml .=
'</strike>';
2394 $labeltoshowhtml = $outhtml;
2398 $out .= $labeltoshow;
2399 $out .=
'</option>';
2401 $outarray[$userstatic->id] = $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength) . $moreinfo;
2402 $outarray2[$userstatic->id] = array(
2403 'id' => $userstatic->id,
2404 'label' => $labeltoshow,
2405 'labelhtml' => $labeltoshowhtml,
2413 $out .=
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'" disabled>';
2414 $out .=
'<option value="">' . $langs->trans(
"None") .
'</option>';
2416 $out .=
'</select>';
2418 if ($num && !$forcecombo) {
2420 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2429 if ($outputmode == 2) {
2431 } elseif ($outputmode) {
2680 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)
2683 global $langs,
$conf;
2688 $price_level = (!empty($price_level) ? $price_level : 0);
2689 if (is_null($ajaxoptions)) {
2690 $ajaxoptions = array();
2693 if (strval($filtertype) ===
'' && (isModEnabled(
"product") || isModEnabled(
"service"))) {
2694 if (isModEnabled(
"product") && !isModEnabled(
'service')) {
2696 } elseif (!isModEnabled(
'product') && isModEnabled(
"service")) {
2702 $placeholder = (is_numeric($showempty) ?
'' :
'placeholder="'.dolPrintHTML($showempty).
'"');
2704 if ($selected && empty($selected_input_value)) {
2705 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
2706 $producttmpselect =
new Product($this->db);
2707 $producttmpselect->fetch($selected);
2708 $selected_input_value = $producttmpselect->ref;
2709 unset($producttmpselect);
2712 if ($filtertype ==
'') {
2713 if (!isModEnabled(
'product')) {
2715 } elseif (!isModEnabled(
'service')) {
2720 $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;
2721 if ((
int) $warehouseId > 0) {
2722 $urloption .=
'&warehouseid=' . (int) $warehouseId;
2725 $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);
2727 if (isModEnabled(
'variants') && is_array($selected_combinations)) {
2731 <!-- script to auto show attributes select tags if a variant was selected -->
2732 <script nonce="' .
getNonce() .
'">
2733 // auto show attributes fields
2734 selected = ' . json_encode($selected_combinations) .
';
2737 jQuery(document).ready(function () {
2739 jQuery("input[name=\'prod_entry_mode\']").change(function () {
2740 if (jQuery(this).val() == \'free\') {
2741 jQuery(\'div#attributes_box\').empty();
2745 jQuery("input#' . $htmlname .
'").change(function () {
2747 if (!jQuery(this).val()) {
2748 jQuery(\'div#attributes_box\').empty();
2752 console.log("A change has started. We get variants fields to inject html select");
2754 jQuery.getJSON("' . DOL_URL_ROOT .
'/variants/ajax/getCombinations.php", {
2755 id: jQuery(this).val()
2756 }, function (data) {
2757 jQuery(\'div#attributes_box\').empty();
2759 jQuery.each(data, function (key, val) {
2761 combvalues[val.id] = val.values;
2763 var span = jQuery(document.createElement(\'div\')).css({
2764 \'display\': \'table-row\'
2768 jQuery(document.createElement(\'div\')).text(val.label).css({
2769 \'font-weight\': \'bold\',
2770 \'display\': \'table-cell\'
2774 var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({
2775 \'margin-left\': \'15px\',
2776 \'white-space\': \'pre\'
2778 jQuery(document.createElement(\'option\')).val(\'\')
2781 jQuery.each(combvalues[val.id], function (key, val) {
2782 var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value);
2784 if (selected[val.fk_product_attribute] == val.id) {
2785 tag.attr(\'selected\', \'selected\');
2792 jQuery(\'div#attributes_box\').append(span);
2797 ' . ($selected ?
'jQuery("input#' . $htmlname .
'").change();' :
'') .
'
2803 if (empty($hidelabel)) {
2805 } elseif ($hidelabel > 1) {
2807 if ($hidelabel == 2) {
2808 $out .=
img_picto($langs->trans(
"Search"),
'search');
2812 $out .=
'<input type="text" class="minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . $placeholder .
' ' . (
getDolGlobalString(
'PRODUCT_SEARCH_AUTOFOCUS') ?
'autofocus' :
'') .
' />';
2813 if ($hidelabel == 3) {
2814 $out .=
img_picto($langs->trans(
"Search"),
'search');
2817 $out .= $this->
select_produits_list($selected, $htmlname, $filtertype, $limit, $price_level,
'', $status, $finished, 0, $socid, $showempty, $forcecombo, $morecss, $hidepriceinlabel, $warehouseStatus, $status_purchase, $warehouseId);
2820 if (empty($nooutput)) {
2935 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)
2939 global $hookmanager;
2942 $outarray = array();
2946 $langs->load(
'other');
2949 $warehouseStatusArray = array();
2950 if (!empty($warehouseStatus)) {
2951 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/entrepot.class.php';
2952 if (preg_match(
'/warehouseclosed/', $warehouseStatus)) {
2955 if (preg_match(
'/warehouseopen/', $warehouseStatus)) {
2958 if (preg_match(
'/warehouseinternal/', $warehouseStatus)) {
2963 $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";
2964 if (count($warehouseStatusArray)) {
2965 $selectFieldsGrouped =
", sum(" . $this->db->ifsql(
"e.statut IS NULL",
"0",
"ps.reel") .
") as stock";
2967 $selectFieldsGrouped =
", " . $this->db->ifsql(
"p.stock IS NULL", 0,
"p.stock") .
" AS stock";
2973 $parameters = array();
2974 $reshook = $hookmanager->executeHooks(
'selectProductsListSelect', $parameters);
2975 if (empty($reshook)) {
2976 $sql .= $selectFields.$selectFieldsGrouped.$hookmanager->resPrint;
2978 $sql .= $hookmanager->resPrint;
2983 $sql .=
", (SELECT " . $this->db->prefix() .
"categorie_product.fk_categorie
2984 FROM " . $this->db->prefix() .
"categorie_product
2985 WHERE " . $this->db->prefix() .
"categorie_product.fk_product=p.rowid
2987 ) AS categorie_product_id ";
2992 $sql .=
', pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,';
2993 $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';
2994 $selectFields .=
", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custdefault_vat_code, custref";
2998 $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";
2999 $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';
3004 $sql .=
", pl.label as label_translated";
3005 $sql .=
", pl.description as description_translated";
3006 $selectFields .=
", label_translated";
3007 $selectFields .=
", description_translated";
3011 $sql .=
", (SELECT pp.rowid FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
3012 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
3013 $sql .=
" AND price_level = " . ((int) $price_level);
3015 $sql .=
" ORDER BY date_price";
3016 $sql .=
" DESC LIMIT 1) as price_rowid";
3017 $sql .=
", (SELECT pp.price_by_qty FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
3018 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
3019 $sql .=
" AND price_level = " . ((int) $price_level);
3021 $sql .=
" ORDER BY date_price";
3022 $sql .=
" DESC LIMIT 1) as price_by_qty";
3023 $selectFields .=
", price_rowid, price_by_qty";
3026 $sql .=
" FROM ".$this->db->prefix().
"product as p";
3029 $sql .=
" USE INDEX (" . $this->db->sanitize(
getDolGlobalString(
'MAIN_PRODUCT_FORCE_INDEX')) .
")";
3033 $parameters = array();
3034 $reshook = $hookmanager->executeHooks(
'selectProductsListFrom', $parameters);
3035 $sql .= $hookmanager->resPrint;
3037 if (count($warehouseStatusArray)) {
3038 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_stock as ps on ps.fk_product = p.rowid";
3039 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entrepot as e on ps.fk_entrepot = e.rowid AND e.entity IN (" .
getEntity(
'stock') .
")";
3040 $sql .=
' AND e.statut IN (' . $this->db->sanitize($this->db->escape(implode(
',', $warehouseStatusArray))) .
')';
3045 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
3050 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_customer_price as pcp ON pcp.fk_soc=" . ((int) $socid) .
" AND pcp.fk_product=p.rowid";
3054 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
3058 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_lang as pl ON pl.fk_product = p.rowid ";
3060 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
3061 $soc =
new Societe($this->db);
3062 $result = $soc->fetch($socid);
3063 if ($result > 0 && !empty($soc->default_lang)) {
3064 $sql .=
" AND pl.lang = '" . $this->db->escape($soc->default_lang) .
"'";
3066 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3069 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
3074 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_attribute_combination pac ON pac.fk_product_child = p.rowid";
3077 $sql .=
' WHERE p.entity IN (' .
getEntity(
'product') .
')';
3080 $sql .=
" AND pac.rowid IS NULL";
3083 if ($finished == 0) {
3084 $sql .=
" AND p.finished = " . ((int) $finished);
3085 } elseif ($finished == 1) {
3086 $sql .=
" AND p.finished = ".((int) $finished);
3089 $sql .=
" AND p.tosell = ".((int) $status);
3091 if ($status_purchase >= 0) {
3092 $sql .=
" AND p.tobuy = " . ((int) $status_purchase);
3095 if (strval($filtertype) !=
'') {
3096 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
3097 } elseif (!isModEnabled(
'product')) {
3098 $sql .=
" AND p.fk_product_type = 1";
3099 } elseif (!isModEnabled(
'service')) {
3100 $sql .=
" AND p.fk_product_type = 0";
3103 if ((
int) $warehouseId > 0) {
3104 $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)";
3108 $parameters = array();
3109 $reshook = $hookmanager->executeHooks(
'selectProductsListWhere', $parameters);
3110 $sql .= $hookmanager->resPrint;
3112 if ($filterkey !=
'') {
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) .
"%'";
3139 $sql .=
" OR pfp.ref_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3144 if (count($search_crit) > 1) {
3147 if (isModEnabled(
'barcode')) {
3148 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3152 if (count($warehouseStatusArray)) {
3153 $sql .=
" GROUP BY " . $selectFields;
3158 $sql .=
" ORDER BY categorie_product_id ";
3160 (
getDolGlobalInt(
'PRODUCT_SORT_BY_CATEGORY') == 1) ? $sql .=
"ASC" : $sql .=
"DESC";
3162 $sql .= $this->db->order(
"p.ref");
3165 $sql .= $this->db->plimit($limit, 0);
3168 dol_syslog(get_class($this) .
"::select_produits_list search products", LOG_DEBUG);
3169 $result = $this->db->query($sql);
3171 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
3172 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3173 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
3175 $num = $this->db->num_rows($result);
3180 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3184 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
3190 if ($showempty && !is_numeric($showempty)) {
3191 $textifempty = $langs->trans($showempty);
3193 $textifempty .= $langs->trans(
"All");
3196 if ($showempty && !is_numeric($showempty)) {
3197 $textifempty = $langs->trans($showempty);
3201 $out .=
'<option value="-1" selected>' . ($textifempty ? $textifempty :
' ') .
'</option>';
3205 while ($num && $i < $num) {
3208 $objp = $this->db->fetch_object($result);
3210 if ((
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1) {
3211 $sql =
"SELECT rowid, quantity, price, unitprice, remise_percent, remise, price_base_type";
3212 $sql .=
" FROM " . $this->db->prefix() .
"product_price_by_qty";
3213 $sql .=
" WHERE fk_product_price = " . ((int) $objp->price_rowid);
3214 $sql .=
" ORDER BY quantity ASC";
3216 dol_syslog(get_class($this) .
"::select_produits_list search prices by qty", LOG_DEBUG);
3217 $result2 = $this->db->query($sql);
3219 $nb_prices = $this->db->num_rows($result2);
3221 while ($nb_prices && $j < $nb_prices) {
3222 $objp2 = $this->db->fetch_object($result2);
3224 $objp->price_by_qty_rowid = $objp2->rowid;
3225 $objp->price_by_qty_price_base_type = $objp2->price_base_type;
3226 $objp->price_by_qty_quantity = $objp2->quantity;
3227 $objp->price_by_qty_unitprice = $objp2->unitprice;
3228 $objp->price_by_qty_remise_percent = $objp2->remise_percent;
3230 $objp->quantity = $objp2->quantity;
3231 $objp->price = $objp2->price;
3232 $objp->unitprice = $objp2->unitprice;
3233 $objp->remise_percent = $objp2->remise_percent;
3239 '@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';
3246 array_push($outarray, $optJson);
3250 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_price_expression)) {
3251 $price_product =
new Product($this->db);
3252 $price_product->fetch($objp->rowid,
'',
'', 1);
3254 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3256 $price_result = $priceparser->parseProduct($price_product);
3257 if ($price_result >= 0) {
3258 $objp->price = $price_result;
3259 $objp->unitprice = $price_result;
3261 $objp->price_ttc = (float)
price2num($objp->price) * (1 + ($objp->tva_tx / 100));
3262 $objp->price_ttc =
price2num($objp->price_ttc,
'MU');
3265 if (
getDolGlobalInt(
'PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES') && !empty($objp->custprice)) {
3273 array_push($outarray, $optJson);
3279 $out .=
'</select>';
3281 $this->db->free($result);
3283 if (empty($outputmode)) {
3310 protected function constructProductListOption(&$objp, &$opt, &$optJson, $price_level, $selected, $hidepriceinlabel = 0, $filterkey =
'', $novirtualstock = 0)
3312 global $langs,
$conf, $user;
3313 global $hookmanager;
3319 $outlabel_translated =
'';
3321 $outdesc_translated =
'';
3327 $outpricebasetype =
'';
3329 $outdefault_vat_code =
'';
3333 $maxlengtharticle = (!
getDolGlobalString(
'PRODUCT_MAX_LENGTH_COMBO') ? 48 :
$conf->global->PRODUCT_MAX_LENGTH_COMBO);
3335 $label = $objp->label;
3336 if (!empty($objp->label_translated)) {
3337 $label = $objp->label_translated;
3339 if (!empty($filterkey) && $filterkey !=
'') {
3340 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
3343 $outkey = $objp->rowid;
3344 $outref = $objp->ref;
3345 $outrefcust = empty($objp->custref) ?
'' : $objp->custref;
3346 $outlabel = $objp->label;
3347 $outdesc = $objp->description;
3349 $outlabel_translated = $objp->label_translated;
3350 $outdesc_translated = $objp->description_translated;
3352 $outbarcode = $objp->barcode;
3353 $outorigin = $objp->fk_country;
3354 $outpbq = empty($objp->price_by_qty_rowid) ?
'' : $objp->price_by_qty_rowid;
3356 $outtype = $objp->fk_product_type;
3361 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
3367 if (!empty($objp->unit_short)) {
3368 $outvalUnits .=
' - ' . $objp->unit_short;
3372 if (!empty($objp->weight) && $objp->weight_units !==
null) {
3374 $outvalUnits .=
' - ' . $unitToShow;
3376 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
3377 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
3378 $outvalUnits .=
' - ' . $unitToShow;
3380 if (!empty($objp->surface) && $objp->surface_units !==
null) {
3382 $outvalUnits .=
' - ' . $unitToShow;
3384 if (!empty($objp->volume) && $objp->volume_units !==
null) {
3386 $outvalUnits .=
' - ' . $unitToShow;
3389 if ($outdurationvalue && $outdurationunit) {
3391 'h' => $langs->trans(
'Hour'),
3392 'd' => $langs->trans(
'Day'),
3393 'w' => $langs->trans(
'Week'),
3394 'm' => $langs->trans(
'Month'),
3395 'y' => $langs->trans(
'Year')
3397 if (isset($da[$outdurationunit])) {
3398 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
3405 if ($user->hasRight(
'stock',
'lire')) {
3406 if ($objp->stock > 0) {
3408 } elseif ($objp->stock <= 0) {
3416 $labeltoshow .= $objp->ref;
3417 if (!empty($objp->custref)) {
3418 $labeltoshow .=
' (' . $objp->custref .
')';
3421 $labeltoshow .=
' (' . $outbarcode .
')';
3423 $labeltoshow .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3425 $labeltoshow .=
' (' .
getCountry($outorigin,
'1') .
')';
3429 $labeltoshowhtml =
'';
3430 $labeltoshowhtml .= $objp->ref;
3431 if (!empty($objp->custref)) {
3432 $labeltoshowhtml .=
' (' . $objp->custref .
')';
3434 if (!empty($filterkey) && $filterkey !=
'') {
3435 $labeltoshowhtml = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $labeltoshowhtml, 1);
3438 $labeltoshowhtml .=
' (' . $outbarcode .
')';
3440 $labeltoshowhtml .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3442 $labeltoshowhtml .=
' (' .
getCountry($outorigin,
'1') .
')';
3446 $labeltoshowstock =
'';
3447 $labeltoshowhtmlstock =
'';
3449 if ($user->hasRight(
'stock',
'lire')) {
3450 $labeltoshowstock .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
3452 if ($objp->stock > 0) {
3453 $labeltoshowhtmlstock .=
' - <span class="product_line_stock_ok">';
3454 } elseif ($objp->stock <= 0) {
3455 $labeltoshowhtmlstock .=
' - <span class="product_line_stock_too_low">';
3457 $labeltoshowhtmlstock .= $langs->transnoentities(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
3458 $labeltoshowhtmlstock .=
'</span>';
3460 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
3461 $langs->load(
"stocks");
3463 $tmpproduct =
new Product($this->db);
3464 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
3465 $tmpproduct->load_virtual_stock();
3466 $virtualstock = $tmpproduct->stock_theorique;
3468 $labeltoshowstock .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
3470 $labeltoshowhtmlstock .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
3471 if ($virtualstock > 0) {
3472 $labeltoshowhtmlstock .=
'<span class="product_line_stock_ok">';
3473 } elseif ($virtualstock <= 0) {
3474 $labeltoshowhtmlstock .=
'<span class="product_line_stock_too_low">';
3476 $labeltoshowhtmlstock .= $virtualstock;
3477 $labeltoshowhtmlstock .=
'</span>';
3486 $labeltoshowprice =
'';
3487 $labeltoshowhtmlprice =
'';
3490 $sql =
"SELECT price, price_ttc, price_base_type, tva_tx, default_vat_code";
3491 $sql .=
" FROM " . $this->db->prefix() .
"product_price";
3492 $sql .=
" WHERE fk_product = " . ((int) $objp->rowid);
3493 $sql .=
" AND entity IN (" .
getEntity(
'productprice') .
")";
3494 $sql .=
" AND price_level = " . ((int) $price_level);
3495 $sql .=
" ORDER BY date_price DESC, rowid DESC";
3498 dol_syslog(get_class($this) .
'::constructProductListOption search price for product ' . $objp->rowid .
' AND level ' . $price_level, LOG_DEBUG);
3499 $result2 = $this->db->query($sql);
3501 $objp2 = $this->db->fetch_object($result2);
3504 if ($objp2->price_base_type ==
'HT') {
3505 $labeltoshowprice .=
' - ' .
price($objp2->price, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
3506 $labeltoshowhtmlprice .=
' - ' .
price($objp2->price, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
3508 $labeltoshowprice .=
' - ' .
price($objp2->price_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
3509 $labeltoshowhtmlprice .=
' - ' .
price($objp2->price_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3511 $outprice_ht =
price($objp2->price);
3512 $outprice_ttc =
price($objp2->price_ttc);
3513 $outpricebasetype = $objp2->price_base_type;
3515 $outtva_tx = $objp2->tva_tx;
3516 $outdefault_vat_code = $objp2->default_vat_code;
3518 $outtva_tx = $objp->tva_tx;
3519 $outdefault_vat_code = $objp->default_vat_code;
3528 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1 && (
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
3530 $outqty = $objp->quantity;
3531 $outdiscount = $objp->remise_percent;
3532 if ($objp->quantity == 1) {
3533 $labeltoshowprice .=
' - ' .
price($objp->unitprice, 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
3534 $labeltoshowhtmlprice .=
' - ' .
price($objp->unitprice, 0, $langs, 0, 0, -1,
$conf->currency) .
"/";
3535 $labeltoshowprice .= $langs->trans(
"Unit");
3536 $labeltoshowhtmlprice .= $langs->transnoentities(
"Unit");
3538 $labeltoshowprice .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
3539 $labeltoshowhtmlprice .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
3540 $labeltoshowprice .= $langs->trans(
"Units");
3541 $labeltoshowhtmlprice .= $langs->transnoentities(
"Units");
3544 $outprice_ht =
price($objp->unitprice);
3545 $outprice_ttc =
price($objp->unitprice * (1 + ($objp->tva_tx / 100)));
3546 $outpricebasetype = $objp->price_base_type;
3547 $outtva_tx = $objp->tva_tx;
3548 $outdefault_vat_code = $objp->default_vat_code;
3550 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1) {
3551 $labeltoshowprice .=
" (" .
price($objp->unitprice, 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->trans(
"Unit") .
")";
3552 $labeltoshowhtmlprice .=
" (" .
price($objp->unitprice, 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $langs->transnoentities(
"Unit") .
")";
3554 if (empty($hidepriceinlabel) && !empty($objp->remise_percent) && $objp->remise_percent >= 1) {
3555 $labeltoshowprice .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3556 $labeltoshowhtmlprice .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3561 if (!empty($objp->idprodcustprice)) {
3564 if ($objp->custprice_base_type ==
'HT') {
3565 $labeltoshowprice .=
' - ' .
price($objp->custprice, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
3566 $labeltoshowhtmlprice .=
' - ' .
price($objp->custprice, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
3568 $labeltoshowprice .=
' - ' .
price($objp->custprice_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
3569 $labeltoshowhtmlprice .=
' - ' .
price($objp->custprice_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3572 $outprice_ht =
price($objp->custprice);
3573 $outprice_ttc =
price($objp->custprice_ttc);
3574 $outpricebasetype = $objp->custprice_base_type;
3575 $outtva_tx = $objp->custtva_tx;
3576 $outdefault_vat_code = $objp->custdefault_vat_code;
3581 if (empty($hidepriceinlabel) && !$found) {
3582 if ($objp->price_base_type ==
'HT') {
3583 $labeltoshowprice .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"HT");
3584 $labeltoshowhtmlprice .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"HT");
3586 $labeltoshowprice .=
' - ' .
price($objp->price_ttc, 1, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->trans(
"TTC");
3587 $labeltoshowhtmlprice .=
' - ' .
price($objp->price_ttc, 0, $langs, 0, 0, -1,
$conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3589 $outprice_ht =
price($objp->price);
3590 $outprice_ttc =
price($objp->price_ttc);
3591 $outpricebasetype = $objp->price_base_type;
3592 $outtva_tx = $objp->tva_tx;
3593 $outdefault_vat_code = $objp->default_vat_code;
3597 $opt =
'<option value="' . $objp->rowid .
'"';
3598 $opt .= ($objp->rowid == $selected) ?
' selected' :
'';
3599 if (!empty($objp->price_by_qty_rowid) && $objp->price_by_qty_rowid > 0) {
3600 $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 .
'"';
3603 $opt .=
' data-labeltrans="' . $outlabel_translated .
'"';
3607 if ($stocktag == 1) {
3608 $opt .=
' class="product_line_stock_ok" data-html="'.$labeltoshowhtml.$outvalUnits.$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
3611 if ($stocktag == -1) {
3612 $opt .=
' class="product_line_stock_too_low" data-html="'.$labeltoshowhtml.$outvalUnits.$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).
'"';
3619 $opt .= $labeltoshow;
3620 $outval .= $labeltoshowhtml;
3623 $opt .= $outvalUnits;
3624 $outval .= $outvalUnits;
3627 $opt .= $labeltoshowprice;
3628 $outval .= $labeltoshowhtmlprice;
3631 $opt .= $labeltoshowstock;
3632 $outval .= $labeltoshowhtmlstock;
3635 $parameters = array(
'objp' => $objp);
3636 $reshook = $hookmanager->executeHooks(
'constructProductListOption', $parameters);
3637 if (empty($reshook)) {
3638 $opt .= $hookmanager->resPrint;
3640 $opt = $hookmanager->resPrint;
3643 $opt .=
"</option>\n";
3648 'label2' => $outlabel,
3652 'price_ttc' =>
price2num($outprice_ttc),
3655 'pricebasetype' => $outpricebasetype,
3656 'tva_tx' => $outtva_tx,
3657 'default_vat_code' => $outdefault_vat_code,
3659 'discount' => $outdiscount,
3660 'duration_value' => $outdurationvalue,
3661 'duration_unit' => $outdurationunit,
3663 'labeltrans' => $outlabel_translated,
3664 'desctrans' => $outdesc_translated,
3665 'ref_customer' => $outrefcust
3736 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 =
'')
3739 global $langs,
$conf, $user;
3740 global $hookmanager;
3743 $outarray = array();
3745 $maxlengtharticle = (!
getDolGlobalString(
'PRODUCT_MAX_LENGTH_COMBO') ? 48 :
$conf->global->PRODUCT_MAX_LENGTH_COMBO);
3747 $langs->load(
'stocks');
3750 $langs->load(
'other');
3753 $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,";
3754 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice, pfp.barcode";
3755 $sql .=
", pfp.multicurrency_code, pfp.multicurrency_unitprice";
3756 $sql .=
", pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.default_vat_code, pfp.fk_soc, s.nom as name";
3757 $sql .=
", pfp.supplier_reputation";
3760 $sql .=
", pfp.desc_fourn as description";
3762 $sql .=
", p.description";
3766 $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";
3768 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
3769 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN (" .
getEntity(
'product') .
") )";
3771 $sql .=
" AND pfp.fk_soc = " . ((int) $socid);
3773 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
3776 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
3778 $sql .=
" WHERE p.entity IN (" .
getEntity(
'product') .
")";
3779 if ($statut != -1) {
3780 $sql .=
" AND p.tobuy = " . ((int) $statut);
3782 if (strval($filtertype) !=
'') {
3783 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
3785 if (!empty($filtre)) {
3786 $sql .=
" " . $filtre;
3789 $parameters = array();
3790 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListWhere', $parameters);
3791 $sql .= $hookmanager->resPrint;
3793 if ($filterkey !=
'') {
3797 $search_crit = explode(
' ', $filterkey);
3799 if (count($search_crit) > 1) {
3802 foreach ($search_crit as $crit) {
3806 $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) .
"%'";
3808 $sql .=
" OR pfp.desc_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3813 if (count($search_crit) > 1) {
3816 if (isModEnabled(
'barcode')) {
3817 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3818 $sql .=
" OR pfp.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3822 $sql .=
" ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC";
3823 $sql .= $this->db->plimit($limit, 0);
3827 dol_syslog(get_class($this) .
"::select_produits_fournisseurs_list", LOG_DEBUG);
3828 $result = $this->db->query($sql);
3830 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3831 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
3833 $num = $this->db->num_rows($result);
3836 $out .=
'<select class="flat ' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'">';
3838 $out .=
'<option value="-1" selected>' . ($placeholder ? $placeholder :
' ') .
'</option>';
3840 $out .=
'<option value="-1">' . ($placeholder ? $placeholder :
' ') .
'</option>';
3845 $objp = $this->db->fetch_object($result);
3847 if (is_null($objp->idprodfournprice)) {
3849 $objp->tva_tx = $objp->tva_tx_sale;
3850 $objp->default_vat_code = $objp->default_vat_code_sale;
3853 $outkey = $objp->idprodfournprice;
3854 if (!$outkey && $alsoproductwithnosupplierprice) {
3855 $outkey =
'idprod_' . $objp->rowid;
3858 $outref = $objp->ref;
3859 $outbarcode = $objp->barcode;
3862 $outtype = $objp->fk_product_type;
3869 if (!empty($objp->unit_short)) {
3870 $outvalUnits .=
' - ' . $objp->unit_short;
3872 if (!empty($objp->weight) && $objp->weight_units !==
null) {
3874 $outvalUnits .=
' - ' . $unitToShow;
3876 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
3877 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
3878 $outvalUnits .=
' - ' . $unitToShow;
3880 if (!empty($objp->surface) && $objp->surface_units !==
null) {
3882 $outvalUnits .=
' - ' . $unitToShow;
3884 if (!empty($objp->volume) && $objp->volume_units !==
null) {
3886 $outvalUnits .=
' - ' . $unitToShow;
3888 if ($outdurationvalue && $outdurationunit) {
3890 'h' => $langs->trans(
'Hour'),
3891 'd' => $langs->trans(
'Day'),
3892 'w' => $langs->trans(
'Week'),
3893 'm' => $langs->trans(
'Month'),
3894 'y' => $langs->trans(
'Year')
3896 if (isset($da[$outdurationunit])) {
3897 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
3902 $objRef = $objp->ref;
3903 if ($filterkey && $filterkey !=
'') {
3904 $objRef = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRef, 1);
3906 $objRefFourn = $objp->ref_fourn;
3907 if ($filterkey && $filterkey !=
'') {
3908 $objRefFourn = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRefFourn, 1);
3910 $label = $objp->label;
3911 if ($filterkey && $filterkey !=
'') {
3912 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
3915 switch ($objp->fk_product_type) {
3927 if (empty($picto)) {
3930 $optlabel =
img_object(
'', $picto,
'class="paddingright classfortooltip"', 0, 0, 1);
3933 $optlabel .= $objp->ref;
3934 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
3935 $optlabel .=
' <span class="opacitymedium">(' . $objp->ref_fourn .
')</span>';
3937 if (isModEnabled(
'barcode') && !empty($objp->barcode)) {
3938 $optlabel .=
' (' . $outbarcode .
')';
3940 $optlabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3942 $outvallabel = $objRef;
3943 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
3944 $outvallabel .=
' (' . $objRefFourn .
')';
3946 if (isModEnabled(
'barcode') && !empty($objp->barcode)) {
3947 $outvallabel .=
' (' . $outbarcode .
')';
3949 $outvallabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3952 $optlabel .= $outvalUnits;
3953 $outvallabel .= $outvalUnits;
3955 if (!empty($objp->idprodfournprice)) {
3956 $outqty = $objp->quantity;
3957 $outdiscount = $objp->remise_percent;
3958 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
3960 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
3961 $prod_supplier->id = $objp->fk_product;
3962 $prod_supplier->fourn_qty = $objp->quantity;
3963 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
3964 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
3966 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3968 $price_result = $priceparser->parseProductSupplier($prod_supplier);
3969 if ($price_result >= 0) {
3970 $objp->fprice = $price_result;
3971 if ($objp->quantity >= 1) {
3972 $objp->unitprice = $objp->fprice / $objp->quantity;
3976 if ($objp->quantity == 1) {
3977 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/";
3978 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1,
$conf->currency) .
"/";
3979 $optlabel .= $langs->trans(
"Unit");
3980 $outvallabel .= $langs->transnoentities(
"Unit");
3982 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
3983 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1,
$conf->currency) .
"/" . $objp->quantity;
3984 $optlabel .=
' ' . $langs->trans(
"Units");
3985 $outvallabel .=
' ' . $langs->transnoentities(
"Units");
3988 if ($objp->quantity > 1) {
3989 $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") .
")";
3990 $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") .
")";
3992 if ($objp->remise_percent >= 1) {
3993 $optlabel .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3994 $outvallabel .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3996 if ($objp->duration) {
3997 $optlabel .=
" - " . $objp->duration;
3998 $outvallabel .=
" - " . $objp->duration;
4001 $optlabel .=
" - " .
dol_trunc($objp->name, 8);
4002 $outvallabel .=
" - " .
dol_trunc($objp->name, 8);
4004 if ($objp->supplier_reputation) {
4006 $reputations = array(
'' => $langs->trans(
'Standard'),
'FAVORITE' => $langs->trans(
'Favorite'),
'NOTTHGOOD' => $langs->trans(
'NotTheGoodQualitySupplier'),
'DONOTORDER' => $langs->trans(
'DoNotOrderThisProductToThisSupplier'));
4008 $optlabel .=
" - " . $reputations[$objp->supplier_reputation];
4009 $outvallabel .=
" - " . $reputations[$objp->supplier_reputation];
4012 $optlabel .=
" - <span class='opacitymedium'>" . $langs->trans(
"NoPriceDefinedForThisSupplier") .
'</span>';
4013 $outvallabel .=
' - ' . $langs->transnoentities(
"NoPriceDefinedForThisSupplier");
4017 $novirtualstock = ($showstockinlist == 2);
4019 if ($user->hasRight(
'stock',
'lire')) {
4020 $outvallabel .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'), 0, $langs, 0, 0);
4022 if ($objp->stock > 0) {
4023 $optlabel .=
' - <span class="product_line_stock_ok">';
4024 } elseif ($objp->stock <= 0) {
4025 $optlabel .=
' - <span class="product_line_stock_too_low">';
4027 $optlabel .= $langs->transnoentities(
"Stock") .
':' .
price(
price2num($objp->stock,
'MS'));
4028 $optlabel .=
'</span>';
4029 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
4030 $langs->load(
"stocks");
4032 $tmpproduct =
new Product($this->db);
4033 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
4034 $tmpproduct->load_virtual_stock();
4035 $virtualstock = $tmpproduct->stock_theorique;
4037 $outvallabel .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
4039 $optlabel .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
4040 if ($virtualstock > 0) {
4041 $optlabel .=
'<span class="product_line_stock_ok">';
4042 } elseif ($virtualstock <= 0) {
4043 $optlabel .=
'<span class="product_line_stock_too_low">';
4045 $optlabel .= $virtualstock;
4046 $optlabel .=
'</span>';
4053 $optstart =
'<option value="' . $outkey .
'"';
4054 if ($selected && $selected == $objp->idprodfournprice) {
4055 $optstart .=
' selected';
4057 if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) {
4058 $optstart .=
' disabled';
4061 if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) {
4070 $optstart .=
' data-default-vat-code="' .
dol_escape_htmltag($objp->default_vat_code) .
'"';
4072 if (isModEnabled(
'multicurrency')) {
4073 $optstart .=
' data-multicurrency-code="' .
dol_escape_htmltag($objp->multicurrency_code) .
'"';
4074 $optstart .=
' data-multicurrency-unitprice="' .
dol_escape_htmltag($objp->multicurrency_unitprice) .
'"';
4077 $optstart .=
' data-description="' .
dol_escape_htmltag($objp->description, 0, 1) .
'"';
4080 $outarrayentry = array(
4083 'label' => $outvallabel,
4084 'labelhtml' => $optlabel,
4086 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4087 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4088 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4089 'tva_tx_formated' =>
price($objp->tva_tx, 0, $langs, 1, -1, 2),
4091 'default_vat_code' => $objp->default_vat_code,
4092 'supplier_ref' => $objp->ref_fourn,
4093 'discount' => $outdiscount,
4095 'duration_value' => $outdurationvalue,
4096 'duration_unit' => $outdurationunit,
4097 'disabled' => empty($objp->idprodfournprice),
4098 'description' => $objp->description
4100 if (isModEnabled(
'multicurrency')) {
4101 $outarrayentry[
'multicurrency_code'] = $objp->multicurrency_code;
4102 $outarrayentry[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4104 $parameters = array(
4106 'optstart' => &$optstart,
4107 'optlabel' => &$optlabel,
4108 'outvallabel' => &$outvallabel,
4109 'outarrayentry' => &$outarrayentry,
4112 $reshook = $hookmanager->executeHooks(
'selectProduitsFournisseurListOption', $parameters, $this);
4118 $out .= $optstart .
' data-html="' .
dol_escape_htmltag($optlabel) .
'">' . $optlabel .
"</option>\n";
4119 $outarraypush = array(
4122 'label' => $outvallabel,
4123 'labelhtml' => $optlabel,
4125 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
4126 'price_qty_ht_locale' =>
price($objp->fprice),
4127 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
4128 'price_unit_ht_locale' =>
price($objp->unitprice),
4129 'price_ht' =>
price2num($objp->unitprice,
'MU'),
4130 'tva_tx_formated' =>
price($objp->tva_tx),
4132 'default_vat_code' => $objp->default_vat_code,
4133 'supplier_ref' => $objp->ref_fourn,
4134 'discount' => $outdiscount,
4136 'duration_value' => $outdurationvalue,
4137 'duration_unit' => $outdurationunit,
4138 'disabled' => empty($objp->idprodfournprice),
4139 'description' => $objp->description
4141 if (isModEnabled(
'multicurrency')) {
4142 $outarraypush[
'multicurrency_code'] = $objp->multicurrency_code;
4143 $outarraypush[
'multicurrency_unitprice'] =
price2num($objp->multicurrency_unitprice,
'MU');
4145 array_push($outarray, $outarraypush);
4158 $out .=
'</select>';
4160 $this->db->free($result);
4162 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
4168 if (empty($outputmode)) {
5648 public function formconfirm($page, $title, $question, $action, $formquestion =
'', $selectedchoice =
'', $useajax = 0, $height = 0, $width = 500, $disableformtag = 0, $labelbuttonyes =
'Yes', $labelbuttonno =
'No')
5650 global $langs,
$conf;
5652 $more =
'<!-- formconfirm - before call, page=' .
dol_escape_htmltag($page) .
' -->';
5658 $newselectedchoice = empty($selectedchoice) ?
"no" : $selectedchoice;
5659 if (
$conf->browser->layout ==
'phone') {
5664 if (empty($height)) {
5666 if (is_array($formquestion) && count($formquestion) > 2) {
5667 $height += ((count($formquestion) - 2) * 24);
5671 if (is_array($formquestion) && !empty($formquestion)) {
5673 foreach ($formquestion as $key => $input) {
5674 if (is_array($input) && !empty($input)) {
5675 if ($input[
'type'] ==
'hidden') {
5676 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
5677 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
5685 $moreonecolumn =
'';
5686 $more .=
'<div class="tagtable paddingtopbottomonly centpercent noborderspacing">' .
"\n";
5687 foreach ($formquestion as $key => $input) {
5688 if (is_array($input) && !empty($input)) {
5689 $size = (!empty($input[
'size']) ?
' size="' . $input[
'size'] .
'"' :
'');
5690 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
5691 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
5693 if ($input[
'type'] ==
'text') {
5694 $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";
5695 } elseif ($input[
'type'] ==
'password') {
5696 $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";
5697 } elseif ($input[
'type'] ==
'textarea') {
5703 $moreonecolumn .=
'<div class="margintoponly">';
5704 $moreonecolumn .= $input[
'label'] .
'<br>';
5706 $moreonecolumn .= $input[
'value'];
5707 $moreonecolumn .=
'</textarea>';
5708 $moreonecolumn .=
'</div>';
5709 } elseif (in_array($input[
'type'], [
'select',
'multiselect'])) {
5710 if (empty($morecss)) {
5711 $morecss =
'minwidth100';
5714 $show_empty = isset($input[
'select_show_empty']) ? $input[
'select_show_empty'] : 1;
5715 $key_in_label = isset($input[
'select_key_in_label']) ? $input[
'select_key_in_label'] : 0;
5716 $value_as_key = isset($input[
'select_value_as_key']) ? $input[
'select_value_as_key'] : 0;
5717 $translate = isset($input[
'select_translate']) ? $input[
'select_translate'] : 0;
5718 $maxlen = isset($input[
'select_maxlen']) ? $input[
'select_maxlen'] : 0;
5719 $disabled = isset($input[
'select_disabled']) ? $input[
'select_disabled'] : 0;
5720 $sort = isset($input[
'select_sort']) ? $input[
'select_sort'] :
'';
5722 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">';
5723 if (!empty($input[
'label'])) {
5724 $more .= $input[
'label'] .
'</div><div class="tagtd left">';
5726 if ($input[
'type'] ==
'select') {
5727 $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);
5729 $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);
5731 $more .=
'</div></div>' .
"\n";
5732 } elseif ($input[
'type'] ==
'checkbox') {
5733 $more .=
'<div class="tagtr">';
5734 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'"><label for="' .
dol_escape_htmltag($input[
'name']) .
'">' . $input[
'label'] .
'</label></div><div class="tagtd">';
5735 $more .=
'<input type="checkbox" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' .
dol_escape_htmltag($input[
'name']) .
'" name="' .
dol_escape_htmltag($input[
'name']) .
'"' . $moreattr;
5736 if (!is_bool($input[
'value']) && $input[
'value'] !=
'false' && $input[
'value'] !=
'0' && $input[
'value'] !=
'') {
5737 $more .=
' checked';
5739 if (is_bool($input[
'value']) && $input[
'value']) {
5740 $more .=
' checked';
5742 if (isset($input[
'disabled'])) {
5743 $more .=
' disabled';
5745 $more .=
' /></div>';
5746 $more .=
'</div>' .
"\n";
5747 } elseif ($input[
'type'] ==
'radio') {
5749 foreach ($input[
'values'] as $selkey => $selval) {
5750 $more .=
'<div class="tagtr">';
5751 if (isset($input[
'label'])) {
5753 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
' tdtop' : (
' tdtop ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
5755 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' "' . $input[
'tdclass'])) .
'"> </div>';
5758 $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;
5759 if (!empty($input[
'disabled'])) {
5760 $more .=
' disabled';
5762 if (isset($input[
'default']) && $input[
'default'] === $selkey) {
5763 $more .=
' checked="checked"';
5766 $more .=
'<label for="' .
dol_escape_htmltag($input[
'name'] . $selkey) .
'" class="valignmiddle">' . $selval .
'</label>';
5767 $more .=
'</div></div>' .
"\n";
5770 } elseif ($input[
'type'] ==
'date' || $input[
'type'] ==
'datetime') {
5771 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
5772 $more .=
'<div class="tagtd">';
5773 $addnowlink = (empty($input[
'datenow']) ? 0 : 1);
5775 if ($input[
'type'] ==
'datetime') {
5776 $h = isset($input[
'hours']) ? $input[
'hours'] : 1;
5777 $m = isset($input[
'minutes']) ? $input[
'minutes'] : 1;
5779 $more .= $this->
selectDate(isset($input[
'value']) ? $input[
'value'] : -1, $input[
'name'], $h, $m, 0,
'', 1, $addnowlink);
5780 $more .=
'</div></div>'.
"\n";
5781 $formquestion[] = array(
'name' => $input[
'name'].
'day');
5782 $formquestion[] = array(
'name' => $input[
'name'].
'month');
5783 $formquestion[] = array(
'name' => $input[
'name'].
'year');
5784 $formquestion[] = array(
'name' => $input[
'name'].
'hour');
5785 $formquestion[] = array(
'name' => $input[
'name'].
'min');
5786 } elseif ($input[
'type'] ==
'other') {
5787 $more .=
'<div class="tagtr"><div class="tagtd'.(empty($input[
'tdclass']) ?
'' : (
' '.$input[
'tdclass'])).
'">';
5788 if (!empty($input[
'label'])) {
5789 $more .= $input[
'label'] .
'</div><div class="tagtd">';
5791 $more .= $input[
'value'];
5792 $more .=
'</div></div>' .
"\n";
5793 } elseif ($input[
'type'] ==
'onecolumn') {
5794 $moreonecolumn .=
'<div class="margintoponly">';
5795 $moreonecolumn .= $input[
'value'];
5796 $moreonecolumn .=
'</div>' .
"\n";
5797 } elseif ($input[
'type'] ==
'hidden') {
5799 } elseif ($input[
'type'] ==
'separator') {
5802 $more .=
'Error type ' . $input[
'type'] .
' for the confirm box is not a supported type';
5806 $more .=
'</div>' .
"\n";
5807 $more .= $moreonecolumn;
5813 if (!empty(
$conf->dol_use_jmobile)) {
5816 if (empty(
$conf->use_javascript_ajax)) {
5822 $dialogconfirm =
'dialog-confirm';
5824 if (!is_numeric($useajax)) {
5828 $dialogconfirm .=
'-' . $button;
5830 $pageyes = $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=yes';
5831 $pageno = ($useajax == 2 ? $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=no' :
'');
5834 if (is_array($formquestion)) {
5835 foreach ($formquestion as $key => $input) {
5838 if (is_array($input) && isset($input[
'name'])) {
5839 if (strpos($input[
'name'],
',') > 0) {
5840 $inputok = array_merge($inputok, explode(
',', $input[
'name']));
5842 array_push($inputok, $input[
'name']);
5847 if (is_array($input) && isset($input[
'inputko']) && $input[
'inputko'] == 1 && isset($input[
'name'])) {
5848 array_push($inputko, $input[
'name']);
5854 $formconfirm .=
'<div id="' . $dialogconfirm .
'" title="' .
dol_escape_htmltag($title) .
'" style="display: none;">';
5855 if (is_array($formquestion) && array_key_exists(
'text', $formquestion) && !empty($formquestion[
'text'])) {
5856 $formconfirm .=
'<div class="confirmtext">' . $formquestion[
'text'] .
'</div>' .
"\n";
5858 if (!empty($more)) {
5859 $formconfirm .=
'<div class="confirmquestions">' . $more .
'</div>' .
"\n";
5861 $formconfirm .= ($question ?
'<div class="confirmmessage">' .
img_help(0,
'') .
' ' . $question .
'</div>' :
'');
5862 $formconfirm .=
'</div>' .
"\n";
5864 $formconfirm .=
"\n<!-- begin code of popup for formconfirm page=" . $page .
" -->\n";
5865 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
5866 $formconfirm .=
"/* Code for the jQuery('#dialogforpopup').dialog() */\n";
5867 $formconfirm .=
'jQuery(document).ready(function() {
5869 $( "#' . $dialogconfirm .
'" ).dialog(
5871 autoOpen: ' . ($autoOpen ?
"true" :
"false") .
',';
5872 if ($newselectedchoice ==
'no') {
5875 $(this).parent().find("button.ui-button:eq(2)").focus();
5880 if ($useajax == 1) {
5881 $jsforcursor =
'// The call to urljump can be slow, so we set the wait cursor' .
"\n";
5882 $jsforcursor .=
'jQuery("html,body,#id-container").addClass("cursorwait");' .
"\n";
5885 $postconfirmas =
'GET';
5889 height: "' . $height .
'",
5890 width: "' . $width .
'",
5892 closeOnEscape: false,
5894 "' .
dol_escape_js($langs->transnoentities($labelbuttonyes)) .
'": function() {
5895 var options = "token=' . urlencode(
newToken()) .
'";
5896 var inputok = ' . json_encode($inputok) .
'; /* List of fields into form */
5897 var page = "' .
dol_escape_js(!empty($page) ? $page :
'') .
'";
5898 var pageyes = "' .
dol_escape_js(!empty($pageyes) ? $pageyes :
'') .
'";
5900 if (inputok.length > 0) {
5901 $.each(inputok, function(i, inputname) {
5904 if ($("input[name=\'" + inputname + "\']").attr("type") == "radio") {
5905 inputvalue = $("input[name=\'" + inputname + "\']:checked").val();
5907 if ($("#" + inputname).attr("type") == "checkbox") { more = ":checked"; }
5908 inputvalue = $("#" + inputname + more).val();
5910 if (typeof inputvalue == "undefined") { inputvalue=""; }
5911 console.log("formconfirm check inputname="+inputname+" inputvalue="+inputvalue);
5912 options += "&" + inputname + "=" + encodeURIComponent(inputvalue);
5915 var urljump = pageyes + (pageyes.indexOf("?") < 0 ? "?" : "&") + options;
5916 if (pageyes.length > 0) {';
5917 if ($postconfirmas ==
'GET') {
5918 $formconfirm .=
'location.href = urljump;';
5920 $formconfirm .= $jsforcursor;
5921 $formconfirm .=
'var post = $.post(
5924 function(data) { $("body").html(data); jQuery("html,body,#id-container").removeClass("cursorwait"); }
5928 console.log("after post ok");
5930 $(this).dialog("close");
5932 "' .
dol_escape_js($langs->transnoentities($labelbuttonno)) .
'": function() {
5933 var options = "token=' . urlencode(
newToken()) .
'";
5934 var inputko = ' . json_encode($inputko) .
'; /* List of fields into form */
5935 var page = "' .
dol_escape_js(!empty($page) ? $page :
'') .
'";
5936 var pageno="' .
dol_escape_js(!empty($pageno) ? $pageno :
'') .
'";
5937 if (inputko.length > 0) {
5938 $.each(inputko, function(i, inputname) {
5940 if ($("#" + inputname).attr("type") == "checkbox") { more = ":checked"; }
5941 var inputvalue = $("#" + inputname + more).val();
5942 if (typeof inputvalue == "undefined") { inputvalue=""; }
5943 options += "&" + inputname + "=" + encodeURIComponent(inputvalue);
5946 var urljump=pageno + (pageno.indexOf("?") < 0 ? "?" : "&") + options;
5948 if (pageno.length > 0) {';
5949 if ($postconfirmas ==
'GET') {
5950 $formconfirm .=
'location.href = urljump;';
5952 $formconfirm .= $jsforcursor;
5953 $formconfirm .=
'var post = $.post(
5956 function(data) { $("body").html(data); jQuery("html,body,#id-container").removeClass("cursorwait"); }
5960 console.log("after post ko");
5962 $(this).dialog("close");
5968 var button = "' . $button .
'";
5969 if (button.length > 0) {
5970 $( "#" + button ).click(function() {
5971 $("#' . $dialogconfirm .
'").dialog("open");
5977 $formconfirm .=
"<!-- end ajax formconfirm -->\n";
5979 $formconfirm .=
"\n<!-- begin formconfirm page=" .
dol_escape_htmltag($page) .
" -->\n";
5981 if (empty($disableformtag)) {
5982 $formconfirm .=
'<form method="POST" action="' . $page .
'" class="notoptoleftnoright">' .
"\n";
5985 $formconfirm .=
'<input type="hidden" name="action" value="' . $action .
'">' .
"\n";
5986 $formconfirm .=
'<input type="hidden" name="token" value="' .
newToken() .
'">' .
"\n";
5988 $formconfirm .=
'<table class="valid centpercent">' .
"\n";
5991 $formconfirm .=
'<tr class="validtitre"><td class="validtitre" colspan="2">';
5992 $formconfirm .=
img_picto(
'',
'pictoconfirm') .
' ' . $title;
5993 $formconfirm .=
'</td></tr>' .
"\n";
5996 if (is_array($formquestion) && array_key_exists(
'text', $formquestion) && !empty($formquestion[
'text'])) {
5997 $formconfirm .=
'<tr class="valid"><td class="valid" colspan="2">' . $formquestion[
'text'] .
'</td></tr>' .
"\n";
6002 $formconfirm .=
'<tr class="valid"><td class="valid" colspan="2">' .
"\n";
6003 $formconfirm .= $more;
6004 $formconfirm .=
'</td></tr>' .
"\n";
6008 $formconfirm .=
'<tr class="valid">';
6009 $formconfirm .=
'<td class="valid">' . $question .
'</td>';
6010 $formconfirm .=
'<td class="valid center">';
6011 $formconfirm .= $this->
selectyesno(
"confirm", $newselectedchoice, 0,
false, 0, 0,
'marginleftonly marginrightonly', $labelbuttonyes, $labelbuttonno);
6012 $formconfirm .=
'<input class="button valignmiddle confirmvalidatebutton small" type="submit" value="' . $langs->trans(
"Validate") .
'">';
6013 $formconfirm .=
'</td>';
6014 $formconfirm .=
'</tr>' .
"\n";
6016 $formconfirm .=
'</table>' .
"\n";
6018 if (empty($disableformtag)) {
6019 $formconfirm .=
"</form>\n";
6021 $formconfirm .=
'<br>';
6023 if (!empty(
$conf->use_javascript_ajax)) {
6024 $formconfirm .=
'<!-- code to disable button to avoid double clic -->';
6025 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
6027 $(document).ready(function () {
6028 $(".confirmvalidatebutton").on("click", function() {
6029 console.log("We click on button confirmvalidatebutton");
6030 $(this).attr("disabled", "disabled");
6031 setTimeout(\'$(".confirmvalidatebutton").removeAttr("disabled")\', 3000);
6032 //console.log($(this).closest("form"));
6033 $(this).closest("form").submit();
6037 $formconfirm .=
'</script>' .
"\n";
6040 $formconfirm .=
"<!-- end formconfirm -->\n";
6043 return $formconfirm;