219 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 =
'')
221 global $conf, $langs;
226 if (empty($typeofdata)) {
227 return 'ErrorBadParameter typeofdata is empty';
230 if ($typeofdata ==
'datetime') {
231 $typeofdata =
'dayhour';
234 if (preg_match(
'/^(\w+)\((\d+)\)$/', $typeofdata, $reg)) {
235 if ($reg[1] ==
'varchar') {
236 $typeofdata =
'string';
237 } elseif ($reg[1] ==
'int') {
238 $typeofdata =
'numeric';
240 return 'ErrorBadParameter ' . $typeofdata;
245 if (
getDolGlobalString(
'MAIN_USE_JQUERY_JEDITABLE') && !preg_match(
'/^select;|day|datepicker|dayhour|datehourpicker/', $typeofdata)) {
246 $ret .= $this->
editInPlace($object, $value, $htmlname, $perm, $typeofdata, $editvalue, $extObject, $custommsg);
248 if ($editaction ==
'') {
249 $editaction =
GETPOST(
'action',
'aZ09');
251 $editmode = ($editaction ==
'edit' . $htmlname);
254 $ret .=
'<form method="post" action="' . $_SERVER[
"PHP_SELF"] . ($moreparam ?
'?' . $moreparam :
'') .
'">';
255 $ret .=
'<input type="hidden" name="action" value="set' . $htmlname .
'">';
256 $ret .=
'<input type="hidden" name="token" value="' . newToken() .
'">';
257 $ret .=
'<input type="hidden" name="' . $paramid .
'" value="' . $object->id .
'">';
258 if (empty($notabletag)) {
259 $ret .=
'<table class="nobordernopadding centpercent">';
261 if (empty($notabletag)) {
264 if (preg_match(
'/^(string|safehtmlstring|email|phone|url)/', $typeofdata)) {
265 $tmp = explode(
':', $typeofdata);
266 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($editvalue ? $editvalue : $value) .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
267 } elseif (preg_match(
'/^(integer)/', $typeofdata)) {
268 $tmp = explode(
':', $typeofdata);
269 $valuetoshow =
price2num($editvalue ? $editvalue : $value, 0);
270 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $valuetoshow .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
271 } elseif (preg_match(
'/^(numeric|amount)/', $typeofdata)) {
272 $tmp = explode(
':', $typeofdata);
273 $valuetoshow =
price2num($editvalue ? $editvalue : $value);
274 $ret .=
'<input type="text" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($valuetoshow !=
'' ?
price($valuetoshow) :
'') .
'"' . (empty($tmp[1]) ?
'' :
' size="' . $tmp[1] .
'"') .
' autofocus>';
275 } elseif (preg_match(
'/^(checkbox)/', $typeofdata)) {
276 $tmp = explode(
':', $typeofdata);
277 $ret .=
'<input type="checkbox" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . ($value ? $value :
'on') .
'"' . ($value ?
' checked' :
'') . (empty($tmp[1]) ?
'' : $tmp[1]) .
'/>';
278 } elseif (preg_match(
'/^text/', $typeofdata) || preg_match(
'/^note/', $typeofdata)) {
279 $tmp = explode(
':', $typeofdata);
280 $cols = (empty($tmp[2]) ?
'' : $tmp[2]);
282 if (preg_match(
'/%/', $cols)) {
283 $morealt =
' style="width: ' . $cols .
'"';
286 $valuetoshow = ($editvalue ? $editvalue : $value);
287 $ret .=
'<textarea id="' . $htmlname .
'" name="' . $htmlname .
'" wrap="soft" rows="' . (empty($tmp[1]) ?
'20' : $tmp[1]) .
'"' . ($cols ?
' cols="' . $cols .
'"' :
'class="quatrevingtpercent"') . $morealt .
'" autofocus>';
290 $valuetoshow = str_replace(
'&',
'&', $valuetoshow);
292 $ret .=
'</textarea>';
293 } elseif ($typeofdata ==
'day' || $typeofdata ==
'datepicker') {
294 $addnowlink = empty($moreoptions[
'addnowlink']) ? 0 : $moreoptions[
'addnowlink'];
295 $adddateof = empty($moreoptions[
'adddateof']) ?
'' : $moreoptions[
'adddateof'];
296 $labeladddateof = empty($moreoptions[
'labeladddateof']) ?
'' : $moreoptions[
'labeladddateof'];
297 $ret .= $this->
selectDate($value, $htmlname, 0, 0, 1,
'form' . $htmlname, 1, $addnowlink, 0,
'',
'', $adddateof,
'', 1, $labeladddateof,
'', $gm);
298 } elseif ($typeofdata ==
'dayhour' || $typeofdata ==
'datehourpicker') {
299 $addnowlink = empty($moreoptions[
'addnowlink']) ? 0 : $moreoptions[
'addnowlink'];
300 $adddateof = empty($moreoptions[
'adddateof']) ?
'' : $moreoptions[
'adddateof'];
301 $labeladddateof = empty($moreoptions[
'labeladddateof']) ?
'' : $moreoptions[
'labeladddateof'];
302 $ret .= $this->
selectDate($value, $htmlname, 1, 1, 1,
'form' . $htmlname, 1, $addnowlink, 0,
'',
'', $adddateof,
'', 1, $labeladddateof,
'', $gm);
303 } elseif (preg_match(
'/^select;/', $typeofdata)) {
304 $arraydata = explode(
',', preg_replace(
'/^select;/',
'', $typeofdata));
305 $arraylist = array();
306 foreach ($arraydata as $val) {
307 $tmp = explode(
':', $val);
308 $tmpkey = str_replace(
'|',
':', $tmp[0]);
309 $arraylist[$tmpkey] = $tmp[1];
311 $ret .= $this->
selectarray($htmlname, $arraylist, $value);
312 } elseif (preg_match(
'/^link/', $typeofdata)) {
314 } elseif (preg_match(
'/^ckeditor/', $typeofdata)) {
315 $tmp = explode(
':', $typeofdata);
316 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
317 $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]));
318 $ret .= $doleditor->Create(1);
319 } elseif ($typeofdata ==
'asis') {
320 $ret .= ($editvalue ? $editvalue : $value);
322 if (empty($notabletag)) {
327 if (empty($notabletag)) {
331 $ret .=
'<input type="submit" class="smallpaddingimp button' . (empty($notabletag) ?
'' :
' ') .
'" name="modify" value="' . $langs->trans(
"Modify") .
'">';
332 if (preg_match(
'/ckeditor|textarea/', $typeofdata) && empty($notabletag)) {
333 $ret .=
'<br>' .
"\n";
335 $ret .=
'<input type="submit" class="smallpaddingimp button button-cancel' . (empty($notabletag) ?
'' :
' ') .
'" name="cancel" value="' . $langs->trans(
"Cancel") .
'">';
336 if (empty($notabletag)) {
340 if (empty($notabletag)) {
341 $ret .=
'</tr></table>' .
"\n";
343 $ret .=
'</form>' .
"\n";
345 if (preg_match(
'/^email/', $typeofdata)) {
347 } elseif (preg_match(
'/^phone/', $typeofdata)) {
349 } elseif (preg_match(
'/^url/', $typeofdata)) {
351 } elseif (preg_match(
'/^(amount|numeric)/', $typeofdata)) {
352 $ret .= ($value !=
'' ?
price($value,
'', $langs, 0, -1, -1, $conf->currency) :
'');
353 } elseif (preg_match(
'/^checkbox/', $typeofdata)) {
354 $tmp = explode(
':', $typeofdata);
355 $ret .=
'<input type="checkbox" disabled id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $value .
'"' . ($value ?
' checked' :
'') . ($tmp[1] ? $tmp[1] :
'') .
'/>';
356 } elseif (preg_match(
'/^text/', $typeofdata) || preg_match(
'/^note/', $typeofdata)) {
358 } elseif (preg_match(
'/^(safehtmlstring|restricthtml)/', $typeofdata)) {
360 } elseif ($typeofdata ==
'day' || $typeofdata ==
'datepicker') {
361 $ret .=
'<span class="valuedate">' .
dol_print_date($value,
'day', $gm) .
'</span>';
362 } elseif ($typeofdata ==
'dayhour' || $typeofdata ==
'datehourpicker') {
363 $ret .=
'<span class="valuedate">' .
dol_print_date($value,
'dayhour', $gm) .
'</span>';
364 } elseif (preg_match(
'/^select;/', $typeofdata)) {
365 $arraydata = explode(
',', preg_replace(
'/^select;/',
'', $typeofdata));
366 $arraylist = array();
367 foreach ($arraydata as $val) {
368 $tmp = explode(
':', $val);
369 $arraylist[$tmp[0]] = $tmp[1];
371 $ret .= $arraylist[$value];
372 if ($htmlname ==
'fk_product_type') {
374 $ret =
img_picto($langs->trans(
"Product"),
'product',
'class="paddingleftonly paddingrightonly colorgrey"') . $ret;
376 $ret =
img_picto($langs->trans(
"Service"),
'service',
'class="paddingleftonly paddingrightonly colorgrey"') . $ret;
379 } elseif (preg_match(
'/^ckeditor/', $typeofdata)) {
382 $firstline = preg_replace(
'/<br>.*/',
'', $tmpcontent);
383 $firstline = preg_replace(
'/[\n\r].*/',
'', $firstline);
384 $tmpcontent = $firstline . ((strlen($firstline) != strlen($tmpcontent)) ?
'...' :
'');
390 if (empty($moreoptions[
'valuealreadyhtmlescaped'])) {
398 if ($formatfunc && method_exists($object, $formatfunc)) {
399 $ret = $object->$formatfunc($ret);
937 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)
940 global $conf, $langs, $mysoc;
942 $langs->load(
"dict");
945 $countryArray = array();
948 $atleastonefavorite = 0;
950 $sql =
"SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite, eec";
951 $sql .=
" FROM " . $this->db->prefix() .
"c_country";
952 $sql .=
" WHERE active > 0";
955 dol_syslog(get_class($this) .
"::select_country", LOG_DEBUG);
956 $resql = $this->db->query($sql);
958 $out .=
'<select id="select' . $htmlname .
'" class="flat maxwidth200onsmartphone selectcountry' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" ' . $htmloption .
'>';
959 $num = $this->db->num_rows($resql);
963 $obj = $this->db->fetch_object($resql);
965 $countryArray[$i][
'rowid'] = $obj->rowid;
966 $countryArray[$i][
'code_iso'] = $obj->code_iso;
967 $countryArray[$i][
'code_iso3'] = $obj->code_iso3;
968 $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 :
''));
969 $countryArray[$i][
'favorite'] = $obj->favorite;
970 $countryArray[$i][
'eec'] = $obj->eec;
971 $favorite[$i] = $obj->favorite;
976 if (empty($disablefavorites)) {
977 $array1_sort_order = SORT_DESC;
978 $array2_sort_order = SORT_ASC;
979 array_multisort($favorite, $array1_sort_order, $label, $array2_sort_order, $countryArray);
985 if (is_numeric($showempty)) {
986 $out .=
'<option value=""> </option>' .
"\n";
988 $out .=
'<option value="-1">' . $langs->trans($showempty) .
'</option>' .
"\n";
992 if ($addspecialentries) {
994 $out .=
'<option value="special_allnotme"' . ($selected ==
'special_allnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesExceptMe", $langs->transnoentitiesnoconv(
"Country" . $mysoc->country_code)) .
'</option>';
995 $out .=
'<option value="special_eec"' . ($selected ==
'special_eec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEEC") .
'</option>';
996 if ($mysoc->isInEEC()) {
997 $out .=
'<option value="special_eecnotme"' . ($selected ==
'special_eecnotme' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesInEECExceptMe", $langs->transnoentitiesnoconv(
"Country" . $mysoc->country_code)) .
'</option>';
999 $out .=
'<option value="special_noteec"' . ($selected ==
'special_noteec' ?
' selected' :
'') .
'>' . $langs->trans(
"CountriesNotInEEC") .
'</option>';
1000 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1003 foreach ($countryArray as $row) {
1005 if (empty($row[
'rowid'])) {
1008 if (is_array($exclude_country_code) && count($exclude_country_code) && in_array($row[
'code_iso'], $exclude_country_code)) {
1012 if (empty($disablefavorites) && $row[
'favorite'] && $row[
'code_iso']) {
1013 $atleastonefavorite++;
1015 if (empty($row[
'favorite']) && $atleastonefavorite) {
1016 $atleastonefavorite = 0;
1017 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
1021 if ($row[
'label']) {
1022 $labeltoshow .=
dol_trunc($row[
'label'], $maxlength,
'middle');
1024 $labeltoshow .=
' ';
1026 if ($row[
'code_iso']) {
1027 $labeltoshow .=
' <span class="opacitymedium">(' . $row[
'code_iso'] .
')</span>';
1028 if (empty($hideflags)) {
1029 $tmpflag =
picto_from_langcode($row[
'code_iso'],
'class="saturatemedium paddingrightonly"', 1);
1030 $labeltoshow = $tmpflag .
' ' . $labeltoshow;
1034 if ($selected && $selected !=
'-1' && ($selected == $row[
'rowid'] || $selected == $row[
'code_iso'] || $selected == $row[
'code_iso3'] || $selected == $row[
'label'])) {
1035 $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']) .
'">';
1037 $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']) .
'">';
1039 $out .= $labeltoshow;
1040 $out .=
'</option>' .
"\n";
1043 $out .=
'</select>';
1049 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1050 $out .=
ajax_combobox(
'select' . $htmlname, array(), 0, 0,
'resolve');
1322 public function select_company($selected =
'', $htmlname =
'socid', $filter =
'', $showempty =
'', $showtype = 0, $forcecombo = 0, $events = array(), $limit = 0, $morecss =
'minwidth100', $moreparam =
'', $selected_input_value =
'', $hidelabel = 1, $ajaxoptions = array(), $multiple =
false, $excludeids = array(), $showcode = 0)
1325 global $conf, $user, $langs;
1329 if (!empty($conf->use_javascript_ajax) &&
getDolGlobalString(
'COMPANY_USE_SEARCH_TO_SELECT') && !$forcecombo) {
1330 if (is_null($ajaxoptions)) {
1331 $ajaxoptions = array();
1334 require_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1338 if ($selected && empty($selected_input_value)) {
1339 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
1340 $societetmp =
new Societe($this->db);
1341 $societetmp->fetch($selected);
1342 $selected_input_value = $societetmp->name;
1347 $urloption =
'htmlname=' . urlencode(str_replace(
'.',
'_', $htmlname)) .
'&outjson=1&filter=' . urlencode($filter) . (empty($excludeids) ?
'' :
'&excludeids=' . join(
',', $excludeids)) . ($showtype ?
'&showtype=' . urlencode($showtype) :
'') . ($showcode ?
'&showcode=' . urlencode($showcode) :
'');
1349 $out .=
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
1350 if (empty($hidelabel)) {
1351 print $langs->trans(
"RefOrLabel") .
' : ';
1352 } elseif ($hidelabel > 1) {
1353 $placeholder = $langs->trans(
"RefOrLabel");
1354 if ($hidelabel == 2) {
1355 $out .=
img_picto($langs->trans(
"Search"),
'search');
1358 $out .=
'<input type="text" class="' . $morecss .
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . ($placeholder ?
' placeholder="' .
dol_escape_htmltag($placeholder) .
'"' :
'') .
' ' . (
getDolGlobalString(
'THIRDPARTY_SEARCH_AUTOFOCUS') ?
'autofocus' :
'') .
' />';
1359 if ($hidelabel == 3) {
1360 $out .=
img_picto($langs->trans(
"Search"),
'search');
1365 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT .
'/societe/ajax/company.php', $urloption, $conf->global->COMPANY_USE_SEARCH_TO_SELECT, 0, $ajaxoptions);
1368 $out .= $this->
select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events,
'', 0, $limit, $morecss, $moreparam, $multiple, $excludeids, $showcode);
1399 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)
1402 global $conf, $user, $langs;
1403 global $hookmanager;
1407 $outarray = array();
1409 if ($selected ===
'') {
1410 $selected = array();
1411 } elseif (!is_array($selected)) {
1412 $selected = array($selected);
1416 if (function_exists(
'testSqlAndScriptInject')) {
1419 return 'SQLInjectionTryDetected';
1423 if ($filter !=
'') {
1424 if (preg_match(
'/[\(\)]/', $filter)) {
1430 if (function_exists(
'testSqlAndScriptInject')) {
1433 return 'SQLInjectionTryDetected';
1439 dol_syslog(
"Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Syntax.", LOG_WARNING);
1444 $sql =
"SELECT s.rowid, s.nom as name, s.name_alias, s.tva_intra, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
1446 $sql .=
", s.address, s.zip, s.town";
1447 $sql .=
", dictp.code as country_code";
1449 $sql .=
" FROM " . $this->db->prefix() .
"societe as s";
1451 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_country as dictp ON dictp.rowid = s.fk_pays";
1453 if (!$user->hasRight(
'societe',
'client',
'voir') && !$user->socid) {
1454 $sql .=
", " . $this->db->prefix() .
"societe_commerciaux as sc";
1456 $sql .=
" WHERE s.entity IN (" .
getEntity(
'societe') .
")";
1457 if (!empty($user->socid)) {
1458 $sql .=
" AND s.rowid = " . ((int) $user->socid);
1463 $sql .=
" AND (" . $filter .
")";
1465 if (!$user->hasRight(
'societe',
'client',
'voir') && !$user->socid) {
1466 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = " . ((int) $user->id);
1469 $sql .=
" AND s.status <> 0";
1471 if (!empty($excludeids)) {
1472 $sql .=
" AND s.rowid NOT IN (" . $this->db->sanitize(join(
',', $excludeids)) .
")";
1475 $parameters = array();
1476 $reshook = $hookmanager->executeHooks(
'selectThirdpartyListWhere', $parameters);
1477 $sql .= $hookmanager->resPrint;
1479 if ($filterkey && $filterkey !=
'') {
1483 $scrit = explode(
' ', $filterkey);
1485 if (count($scrit) > 1) {
1488 foreach ($scrit as $crit) {
1492 $sql .=
"(s.nom LIKE '" . $this->db->escape($prefix . $crit) .
"%')";
1495 if (count($scrit) > 1) {
1498 if (isModEnabled(
'barcode')) {
1499 $sql .=
" OR s.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1501 $sql .=
" OR s.code_client LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.code_fournisseur LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1502 $sql .=
" OR s.name_alias LIKE '" . $this->db->escape($prefix . $filterkey) .
"%' OR s.tva_intra LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
1505 $sql .= $this->db->order(
"nom",
"ASC");
1506 $sql .= $this->db->plimit($limit, 0);
1509 dol_syslog(get_class($this).
"::select_thirdparty_list", LOG_DEBUG);
1510 $resql = $this->db->query($sql);
1513 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1518 $out .=
'<select id="' . $htmlname .
'" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'"' . ($moreparam ?
' ' . $moreparam :
'') .
' name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
'>' .
"\n";
1520 $textifempty = (($showempty && !is_numeric($showempty)) ? $langs->trans($showempty) :
'');
1524 if ($showempty && !is_numeric($showempty)) {
1525 $textifempty = $langs->trans($showempty);
1527 $textifempty .= $langs->trans(
"All");
1531 $out .=
'<option value="-1" data-html="' .
dol_escape_htmltag(
'<span class="opacitymedium">' . ($textifempty ? $textifempty :
' ') .
'</span>') .
'">' . $textifempty .
'</option>' .
"\n";
1534 $companytemp =
new Societe($this->db);
1536 $num = $this->db->num_rows($resql);
1540 $obj = $this->db->fetch_object($resql);
1543 if (($obj->client) && (!empty($obj->code_client))) {
1544 $label = $obj->code_client .
' - ';
1546 if (($obj->fournisseur) && (!empty($obj->code_fournisseur))) {
1547 $label .= $obj->code_fournisseur .
' - ';
1549 $label .=
' ' . $obj->name;
1551 $label = $obj->name;
1554 if (!empty($obj->name_alias)) {
1555 $label .=
' (' . $obj->name_alias .
')';
1559 $label .=
' - '.$obj->tva_intra;
1562 $labelhtml = $label;
1565 $companytemp->id = $obj->rowid;
1566 $companytemp->client = $obj->client;
1567 $companytemp->fournisseur = $obj->fournisseur;
1568 $tmptype = $companytemp->getTypeUrl(1,
'', 0,
'span');
1570 $labelhtml .=
' ' . $tmptype;
1573 if ($obj->client || $obj->fournisseur) {
1576 if ($obj->client == 1 || $obj->client == 3) {
1577 $label .= $langs->trans(
"Customer");
1579 if ($obj->client == 2 || $obj->client == 3) {
1580 $label .= ($obj->client == 3 ?
', ' :
'') . $langs->trans(
"Prospect");
1582 if ($obj->fournisseur) {
1583 $label .= ($obj->client ?
', ' :
'') . $langs->trans(
"Supplier");
1585 if ($obj->client || $obj->fournisseur) {
1591 $s = ($obj->address ?
' - ' . $obj->address :
'') . ($obj->zip ?
' - ' . $obj->zip :
'') . ($obj->town ?
' ' . $obj->town :
'');
1592 if (!empty($obj->country_code)) {
1593 $s .=
', ' . $langs->trans(
'Country' . $obj->country_code);
1599 if (empty($outputmode)) {
1600 if (in_array($obj->rowid, $selected)) {
1601 $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>';
1603 $out .=
'<option value="' . $obj->rowid .
'" data-html="' .
dol_escape_htmltag($labelhtml, 0, 0,
'', 0, 1) .
'">' .
dol_escape_htmltag($label, 0, 0,
'', 0, 1) .
'</option>';
1606 array_push($outarray, array(
'key' => $obj->rowid,
'value' => $label,
'label' => $label,
'labelhtml' => $labelhtml));
1610 if (($i % 10) == 0) {
1615 $out .=
'</select>' .
"\n";
1620 $this->result = array(
'nbofthirdparties' => $num);
1769 public function selectcontacts($socid, $selected = array(), $htmlname =
'contactid', $showempty = 0, $exclude =
'', $limitto =
'', $showfunction = 0, $morecss =
'', $options_only =
false, $showsoc = 0, $forcecombo = 0, $events = array(), $moreparam =
'', $htmlid =
'', $multiple =
false, $disableifempty = 0)
1771 global $conf, $langs, $hookmanager, $action;
1773 $langs->load(
'companies');
1775 if (empty($htmlid)) {
1776 $htmlid = $htmlname;
1780 if ($selected ===
'') {
1781 $selected = array();
1782 } elseif (!is_array($selected)) {
1783 $selected = array($selected);
1787 if (!is_object($hookmanager)) {
1788 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
1793 $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";
1794 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
1795 $sql .=
", s.nom as company, s.town AS company_town";
1797 $sql .=
" FROM " . $this->db->prefix() .
"socpeople as sp";
1798 if ($showsoc > 0 ||
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
1799 $sql .=
" LEFT OUTER JOIN " . $this->db->prefix() .
"societe as s ON s.rowid=sp.fk_soc";
1801 $sql .=
" WHERE sp.entity IN (" .
getEntity(
'contact') .
")";
1802 if ($socid > 0 || $socid == -1) {
1803 $sql .=
" AND sp.fk_soc = " . ((int) $socid);
1806 $sql .=
" AND sp.statut <> 0";
1809 $parameters = array();
1810 $reshook = $hookmanager->executeHooks(
'selectContactListWhere', $parameters);
1811 $sql .= $hookmanager->resPrint;
1812 $sql .=
" ORDER BY sp.lastname ASC";
1814 dol_syslog(get_class($this) .
"::selectcontacts", LOG_DEBUG);
1815 $resql = $this->db->query($sql);
1817 $num = $this->db->num_rows($resql);
1819 if ($htmlname !=
'none' && !$options_only) {
1820 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlid .
'" name="' . $htmlname . (($num || empty($disableifempty)) ?
'' :
' disabled') . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . (!empty($moreparam) ? $moreparam :
'') .
'>';
1823 if ($showempty && !is_numeric($showempty)) {
1824 $textforempty = $showempty;
1825 $out .=
'<option class="optiongrey" value="-1"' . (in_array(-1, $selected) ?
' selected' :
'') .
'>' . $textforempty .
'</option>';
1827 if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) {
1828 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'> </option>';
1830 if ($showempty == 2) {
1831 $out .=
'<option value="0"' . (in_array(0, $selected) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Internal") .
' --</option>';
1837 include_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
1838 $contactstatic =
new Contact($this->db);
1841 $obj = $this->db->fetch_object($resql);
1844 $extendedInfos =
'';
1846 $extendedInfos = array();
1847 $email = trim($obj->email);
1848 if (!empty($email)) {
1849 $extendedInfos[] = $email;
1851 $phone = trim($obj->phone);
1852 $phone_perso = trim($obj->phone_perso);
1853 $phone_mobile = trim($obj->phone_mobile);
1854 if (!empty($phone)) {
1855 $extendedInfos[] = $phone;
1857 if (!empty($phone_perso)) {
1858 $extendedInfos[] = $phone_perso;
1860 if (!empty($phone_mobile)) {
1861 $extendedInfos[] = $phone_mobile;
1864 $contact_town = trim($obj->contact_town);
1865 $company_town = trim($obj->company_town);
1866 if (!empty($contact_town)) {
1867 $extendedInfos[] = $contact_town;
1868 } elseif (!empty($company_town)) {
1869 $extendedInfos[] = $company_town;
1871 $extendedInfos = implode(
' - ', $extendedInfos);
1872 if (!empty($extendedInfos)) {
1873 $extendedInfos =
' - ' . $extendedInfos;
1877 $contactstatic->id = $obj->rowid;
1878 $contactstatic->lastname = $obj->lastname;
1879 $contactstatic->firstname = $obj->firstname;
1880 if ($obj->statut == 1) {
1881 if ($htmlname !=
'none') {
1883 if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) {
1886 if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) {
1889 if (!empty($selected) && in_array($obj->rowid, $selected)) {
1890 $out .=
'<option value="' . $obj->rowid .
'"';
1892 $out .=
' disabled';
1894 $out .=
' selected>';
1895 $out .= $contactstatic->getFullName($langs) . $extendedInfos;
1896 if ($showfunction && $obj->poste) {
1897 $out .=
' (' . $obj->poste .
')';
1899 if (($showsoc > 0) && $obj->company) {
1900 $out .=
' - (' . $obj->company .
')';
1902 $out .=
'</option>';
1904 $out .=
'<option value="' . $obj->rowid .
'"';
1906 $out .=
' disabled';
1909 $out .= $contactstatic->getFullName($langs) . $extendedInfos;
1910 if ($showfunction && $obj->poste) {
1911 $out .=
' (' . $obj->poste .
')';
1913 if (($showsoc > 0) && $obj->company) {
1914 $out .=
' - (' . $obj->company .
')';
1916 $out .=
'</option>';
1919 if (in_array($obj->rowid, $selected)) {
1920 $out .= $contactstatic->getFullName($langs) . $extendedInfos;
1921 if ($showfunction && $obj->poste) {
1922 $out .=
' (' . $obj->poste .
')';
1924 if (($showsoc > 0) && $obj->company) {
1925 $out .=
' - (' . $obj->company .
')';
1933 $labeltoshow = ($socid != -1) ? ($langs->trans($socid ?
"NoContactDefinedForThirdParty" :
"NoContactDefined")) : $langs->trans(
'SelectAThirdPartyFirst');
1934 $out .=
'<option class="disabled" value="-1"' . (($showempty == 2 || $multiple) ?
'' :
' selected') .
' disabled="disabled">';
1935 $out .= $labeltoshow;
1936 $out .=
'</option>';
1939 $parameters = array(
1941 'htmlname' => $htmlname,
1944 'showfunction' => $showfunction,
1945 'showsoc' => $showsoc,
1948 $reshook = $hookmanager->executeHooks(
'afterSelectContactOptions', $parameters, $this, $action);
1950 if ($htmlname !=
'none' && !$options_only) {
1951 $out .=
'</select>';
1954 if ($conf->use_javascript_ajax && !$forcecombo && !$options_only) {
1955 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2016 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)
2019 global $conf, $user, $langs, $hookmanager;
2023 if ((is_numeric($selected) && ($selected < -2 || empty($selected))) && !
getDolGlobalString(
'SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE')) {
2024 $selected = $user->id;
2027 if ($selected ===
'') {
2028 $selected = array();
2029 } elseif (!is_array($selected)) {
2030 $selected = array($selected);
2033 $excludeUsers =
null;
2034 $includeUsers =
null;
2037 if (is_array($exclude)) {
2038 $excludeUsers = implode(
",", $exclude);
2041 if (is_array($include)) {
2042 $includeUsers = implode(
",", $include);
2043 } elseif ($include ==
'hierarchy') {
2045 $includeUsers = implode(
",", $user->getAllChildIds(0));
2046 } elseif ($include ==
'hierarchyme') {
2048 $includeUsers = implode(
",", $user->getAllChildIds(1));
2052 $outarray = array();
2053 $outarray2 = array();
2056 $sql =
"SELECT DISTINCT u.rowid, u.lastname as lastname, u.firstname, u.statut as status, u.login, u.admin, u.entity, u.photo";
2057 if (isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
2058 $sql .=
", e.label";
2060 $sql .=
" FROM " . $this->db->prefix() .
"user as u";
2061 if (isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
2062 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entity as e ON e.rowid = u.entity";
2063 if (!empty($force_entity)) {
2064 $sql .=
" WHERE u.entity IN (0, " . $this->db->sanitize($force_entity) .
")";
2066 $sql .=
" WHERE u.entity IS NOT NULL";
2069 if (isModEnabled(
'multicompany') &&
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE')) {
2070 $sql .=
" WHERE u.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
2072 $sql .=
" WHERE u.entity IN (" .
getEntity(
'user') .
")";
2075 if (!empty($user->socid)) {
2076 $sql .=
" AND u.fk_soc = " . ((int) $user->socid);
2078 if (is_array($exclude) && $excludeUsers) {
2079 $sql .=
" AND u.rowid NOT IN (" . $this->db->sanitize($excludeUsers) .
")";
2081 if ($includeUsers) {
2082 $sql .=
" AND u.rowid IN (" . $this->db->sanitize($includeUsers) .
")";
2085 $sql .=
" AND u.statut <> 0";
2087 if (!empty($morefilter)) {
2088 $sql .=
" " . $morefilter;
2092 $reshook = $hookmanager->executeHooks(
'addSQLWhereFilterOnSelectUsers', array(), $this, $action);
2093 if (!empty($reshook)) {
2094 $sql .= $hookmanager->resPrint;
2098 $sql .=
" ORDER BY u.statut DESC, u.firstname ASC, u.lastname ASC";
2100 $sql .=
" ORDER BY u.statut DESC, u.lastname ASC, u.firstname ASC";
2103 dol_syslog(get_class($this) .
"::select_dolusers", LOG_DEBUG);
2105 $resql = $this->db->query($sql);
2107 $num = $this->db->num_rows($resql);
2111 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
' minwidth200') .
'" id="' . $htmlname .
'" name="' . $htmlname . ($multiple ?
'[]' :
'') .
'" ' . ($multiple ?
'multiple' :
'') .
' ' . ($disabled ?
' disabled' :
'') .
'>';
2112 if ($show_empty && !$multiple) {
2113 $textforempty =
' ';
2114 if (!empty($conf->use_javascript_ajax)) {
2115 $textforempty =
' ';
2117 if (!is_numeric($show_empty)) {
2118 $textforempty = $show_empty;
2120 $out .=
'<option class="optiongrey" value="' . ($show_empty < 0 ? $show_empty : -1) .
'"' . ((empty($selected) || in_array(-1, $selected)) ?
' selected' :
'') .
'>' . $textforempty .
'</option>' .
"\n";
2123 $out .=
'<option value="-2"' . ((in_array(-2, $selected)) ?
' selected' :
'') .
'>-- ' . $langs->trans(
"Everybody") .
' --</option>' .
"\n";
2126 $userstatic =
new User($this->db);
2129 $obj = $this->db->fetch_object($resql);
2131 $userstatic->id = $obj->rowid;
2132 $userstatic->lastname = $obj->lastname;
2133 $userstatic->firstname = $obj->firstname;
2134 $userstatic->photo = $obj->photo;
2135 $userstatic->statut = $obj->status;
2136 $userstatic->entity = $obj->entity;
2137 $userstatic->admin = $obj->admin;
2140 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
2141 $disableline = ($enableonlytext ? $enableonlytext :
'1');
2145 $labeltoshowhtml =
'';
2152 $labeltoshow .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2153 $labeltoshowhtml .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2154 if (empty($obj->firstname) && empty($obj->lastname)) {
2155 $labeltoshow .= $obj->login;
2156 $labeltoshowhtml .= $obj->login;
2163 $moreinfo .= ($moreinfo ?
' - ' :
' (');
2164 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(');
2165 $moreinfo .= $obj->login;
2166 $moreinfohtml .= $obj->login;
2168 if ($showstatus >= 0) {
2169 if ($obj->status == 1 && $showstatus == 1) {
2170 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Enabled');
2171 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Enabled');
2173 if ($obj->status == 0 && $showstatus == 1) {
2174 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
'Disabled');
2175 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
'Disabled');
2178 if (isModEnabled(
'multicompany') && !
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE') && $conf->entity == 1 && !empty($user->admin) && empty($user->entity)) {
2179 if (empty($obj->entity)) {
2180 $moreinfo .= ($moreinfo ?
' - ' :
' (') . $langs->trans(
"AllEntities");
2181 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . $langs->trans(
"AllEntities");
2183 if ($obj->entity != $conf->entity) {
2184 $moreinfo .= ($moreinfo ?
' - ' :
' (') . ($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2185 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(') . ($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2189 $moreinfo .= (!empty($moreinfo) ?
')' :
'');
2190 $moreinfohtml .= (!empty($moreinfohtml) ?
')</span>' :
'');
2191 if (!empty($disableline) && $disableline !=
'1') {
2193 $moreinfo .=
' - ' . $disableline;
2194 $moreinfohtml .=
' - ' . $disableline;
2196 $labeltoshow .= $moreinfo;
2197 $labeltoshowhtml .= $moreinfohtml;
2199 $out .=
'<option value="' . $obj->rowid .
'"';
2200 if (!empty($disableline)) {
2201 $out .=
' disabled';
2203 if ((is_object($selected) && $selected->id == $obj->rowid) || (!is_object($selected) && in_array($obj->rowid, $selected))) {
2204 $out .=
' selected';
2206 $out .=
' data-html="';
2207 $outhtml = $userstatic->getNomUrl(-3,
'', 0, 1, 24, 1,
'login',
'', 1) .
' ';
2208 if ($showstatus >= 0 && $obj->status == 0) {
2209 $outhtml .=
'<strike class="opacitymediumxxx">';
2211 $outhtml .= $labeltoshowhtml;
2212 if ($showstatus >= 0 && $obj->status == 0) {
2213 $outhtml .=
'</strike>';
2217 $out .= $labeltoshow;
2218 $out .=
'</option>';
2220 $outarray[$userstatic->id] = $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength) . $moreinfo;
2221 $outarray2[$userstatic->id] = array(
2222 'id'=>$userstatic->id,
2223 'label'=>$labeltoshow,
2224 'labelhtml'=>$labeltoshowhtml,
2232 $out .=
'<select class="flat" id="' . $htmlname .
'" name="' . $htmlname .
'" disabled>';
2233 $out .=
'<option value="">' . $langs->trans(
"None") .
'</option>';
2235 $out .=
'</select>';
2237 if ($num && !$forcecombo) {
2239 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2246 if ($outputmode == 2) {
2248 } elseif ($outputmode) {
2469 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)
2472 global $langs, $conf;
2477 $price_level = (!empty($price_level) ? $price_level : 0);
2478 if (is_null($ajaxoptions)) {
2479 $ajaxoptions = array();
2482 if (strval($filtertype) ===
'' && (isModEnabled(
"product") || isModEnabled(
"service"))) {
2483 if (isModEnabled(
"product") && !isModEnabled(
'service')) {
2485 } elseif (!isModEnabled(
'product') && isModEnabled(
"service")) {
2490 if (!empty($conf->use_javascript_ajax) &&
getDolGlobalString(
'PRODUIT_USE_SEARCH_TO_SELECT')) {
2493 if ($selected && empty($selected_input_value)) {
2494 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
2495 $producttmpselect =
new Product($this->db);
2496 $producttmpselect->fetch($selected);
2497 $selected_input_value = $producttmpselect->ref;
2498 unset($producttmpselect);
2501 if ($filtertype ==
'') {
2502 if (!isModEnabled(
'product')) {
2504 } elseif (!isModEnabled(
'service')) {
2509 $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;
2510 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT .
'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
2512 if (isModEnabled(
'variants') && is_array($selected_combinations)) {
2516 <!-- script to auto show attributes select tags if a variant was selected -->
2517 <script nonce="' .
getNonce() .
'">
2518 // auto show attributes fields
2519 selected = ' . json_encode($selected_combinations) .
';
2522 jQuery(document).ready(function () {
2524 jQuery("input[name=\'prod_entry_mode\']").change(function () {
2525 if (jQuery(this).val() == \'free\') {
2526 jQuery(\'div#attributes_box\').empty();
2530 jQuery("input#' . $htmlname .
'").change(function () {
2532 if (!jQuery(this).val()) {
2533 jQuery(\'div#attributes_box\').empty();
2537 console.log("A change has started. We get variants fields to inject html select");
2539 jQuery.getJSON("' . DOL_URL_ROOT .
'/variants/ajax/getCombinations.php", {
2540 id: jQuery(this).val()
2541 }, function (data) {
2542 jQuery(\'div#attributes_box\').empty();
2544 jQuery.each(data, function (key, val) {
2546 combvalues[val.id] = val.values;
2548 var span = jQuery(document.createElement(\'div\')).css({
2549 \'display\': \'table-row\'
2553 jQuery(document.createElement(\'div\')).text(val.label).css({
2554 \'font-weight\': \'bold\',
2555 \'display\': \'table-cell\'
2559 var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({
2560 \'margin-left\': \'15px\',
2561 \'white-space\': \'pre\'
2563 jQuery(document.createElement(\'option\')).val(\'\')
2566 jQuery.each(combvalues[val.id], function (key, val) {
2567 var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value);
2569 if (selected[val.fk_product_attribute] == val.id) {
2570 tag.attr(\'selected\', \'selected\');
2577 jQuery(\'div#attributes_box\').append(span);
2582 ' . ($selected ?
'jQuery("input#' . $htmlname .
'").change();' :
'') .
'
2588 if (empty($hidelabel)) {
2589 $out .= $langs->trans(
"RefOrLabel") .
' : ';
2590 } elseif ($hidelabel > 1) {
2591 $placeholder =
' placeholder="' . $langs->trans(
"RefOrLabel") .
'"';
2592 if ($hidelabel == 2) {
2593 $out .=
img_picto($langs->trans(
"Search"),
'search');
2596 $out .=
'<input type="text" class="minwidth100' . ($morecss ?
' ' . $morecss :
'') .
'" name="search_' . $htmlname .
'" id="search_' . $htmlname .
'" value="' . $selected_input_value .
'"' . $placeholder .
' ' . (
getDolGlobalString(
'PRODUCT_SEARCH_AUTOFOCUS') ?
'autofocus' :
'') .
' />';
2597 if ($hidelabel == 3) {
2598 $out .=
img_picto($langs->trans(
"Search"),
'search');
2601 $out .= $this->
select_produits_list($selected, $htmlname, $filtertype, $limit, $price_level,
'', $status, $finished, 0, $socid, $showempty, $forcecombo, $morecss, $hidepriceinlabel, $warehouseStatus, $status_purchase);
2604 if (empty($nooutput)) {
2718 public function select_produits_list($selected =
'', $htmlname =
'productid', $filtertype =
'', $limit = 20, $price_level = 0, $filterkey =
'', $status = 1, $finished = 2, $outputmode = 0, $socid = 0, $showempty =
'1', $forcecombo = 0, $morecss =
'', $hidepriceinlabel = 0, $warehouseStatus =
'', $status_purchase = -1)
2721 global $langs, $conf;
2722 global $hookmanager;
2725 $outarray = array();
2729 $langs->load(
'other');
2732 $warehouseStatusArray = array();
2733 if (!empty($warehouseStatus)) {
2734 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/entrepot.class.php';
2735 if (preg_match(
'/warehouseclosed/', $warehouseStatus)) {
2738 if (preg_match(
'/warehouseopen/', $warehouseStatus)) {
2741 if (preg_match(
'/warehouseinternal/', $warehouseStatus)) {
2746 $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";
2747 if (count($warehouseStatusArray)) {
2748 $selectFieldsGrouped =
", sum(" . $this->db->ifsql(
"e.statut IS NULL",
"0",
"ps.reel") .
") as stock";
2750 $selectFieldsGrouped =
", " . $this->db->ifsql(
"p.stock IS NULL", 0,
"p.stock") .
" AS stock";
2756 $parameters = array();
2757 $reshook = $hookmanager->executeHooks(
'selectProductsListSelect', $parameters);
2758 if (empty($reshook)) {
2759 $sql .= $selectFields.$selectFieldsGrouped.$hookmanager->resPrint;
2761 $sql .= $hookmanager->resPrint;
2766 $sql .=
", (SELECT " . $this->db->prefix() .
"categorie_product.fk_categorie
2767 FROM " . $this->db->prefix() .
"categorie_product
2768 WHERE " . $this->db->prefix() .
"categorie_product.fk_product=p.rowid
2770 ) AS categorie_product_id ";
2775 $sql .=
', pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,';
2776 $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';
2777 $selectFields .=
", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custdefault_vat_code, custref";
2781 $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";
2782 $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';
2787 $sql .=
", pl.label as label_translated";
2788 $sql .=
", pl.description as description_translated";
2789 $selectFields .=
", label_translated";
2790 $selectFields .=
", description_translated";
2794 $sql .=
", (SELECT pp.rowid FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
2795 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
2796 $sql .=
" AND price_level = " . ((int) $price_level);
2798 $sql .=
" ORDER BY date_price";
2799 $sql .=
" DESC LIMIT 1) as price_rowid";
2800 $sql .=
", (SELECT pp.price_by_qty FROM " . $this->db->prefix() .
"product_price as pp WHERE pp.fk_product = p.rowid";
2801 if ($price_level >= 1 &&
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
2802 $sql .=
" AND price_level = " . ((int) $price_level);
2804 $sql .=
" ORDER BY date_price";
2805 $sql .=
" DESC LIMIT 1) as price_by_qty";
2806 $selectFields .=
", price_rowid, price_by_qty";
2809 $sql .=
" FROM ".$this->db->prefix().
"product as p";
2811 $parameters = array();
2812 $reshook = $hookmanager->executeHooks(
'selectProductsListFrom', $parameters);
2813 $sql .= $hookmanager->resPrint;
2815 if (count($warehouseStatusArray)) {
2816 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_stock as ps on ps.fk_product = p.rowid";
2817 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"entrepot as e on ps.fk_entrepot = e.rowid AND e.entity IN (" .
getEntity(
'stock') .
")";
2818 $sql .=
' AND e.statut IN (' . $this->db->sanitize($this->db->escape(implode(
',', $warehouseStatusArray))) .
')';
2823 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
2828 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_customer_price as pcp ON pcp.fk_soc=" . ((int) $socid) .
" AND pcp.fk_product=p.rowid";
2832 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
2836 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_lang as pl ON pl.fk_product = p.rowid ";
2838 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
2839 $soc =
new Societe($this->db);
2840 $result = $soc->fetch($socid);
2841 if ($result > 0 && !empty($soc->default_lang)) {
2842 $sql .=
" AND pl.lang = '" . $this->db->escape($soc->default_lang) .
"'";
2844 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
2847 $sql .=
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) .
"'";
2852 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_attribute_combination pac ON pac.fk_product_child = p.rowid";
2855 $sql .=
' WHERE p.entity IN (' .
getEntity(
'product') .
')';
2858 $sql .=
" AND pac.rowid IS NULL";
2861 if ($finished == 0) {
2862 $sql .=
" AND p.finished = " . ((int) $finished);
2863 } elseif ($finished == 1) {
2864 $sql .=
" AND p.finished = ".((int) $finished);
2867 $sql .=
" AND p.tosell = ".((int) $status);
2869 if ($status_purchase >= 0) {
2870 $sql .=
" AND p.tobuy = " . ((int) $status_purchase);
2873 if (strval($filtertype) !=
'') {
2874 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
2875 } elseif (!isModEnabled(
'product')) {
2876 $sql .=
" AND p.fk_product_type = 1";
2877 } elseif (!isModEnabled(
'service')) {
2878 $sql .=
" AND p.fk_product_type = 0";
2881 $parameters = array();
2882 $reshook = $hookmanager->executeHooks(
'selectProductsListWhere', $parameters);
2883 $sql .= $hookmanager->resPrint;
2885 if ($filterkey !=
'') {
2889 $scrit = explode(
' ', $filterkey);
2891 if (count($scrit) > 1) {
2894 foreach ($scrit as $crit) {
2898 $sql .=
"(p.ref LIKE '" . $this->db->escape($prefix . $crit) .
"%' OR p.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
2900 $sql .=
" OR pl.label LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
2903 $sql .=
" OR pcp.ref_customer LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
2906 $sql .=
" OR p.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
2908 $sql .=
" OR pl.description LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
2912 $sql .=
" OR pfp.ref_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
2917 if (count($scrit) > 1) {
2920 if (isModEnabled(
'barcode')) {
2921 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
2925 if (count($warehouseStatusArray)) {
2926 $sql .=
" GROUP BY " . $selectFields;
2931 $sql .=
" ORDER BY categorie_product_id ";
2933 (
getDolGlobalInt(
'PRODUCT_SORT_BY_CATEGORY') == 1) ? $sql .=
"ASC" : $sql .=
"DESC";
2935 $sql .= $this->db->order(
"p.ref");
2938 $sql .= $this->db->plimit($limit, 0);
2941 dol_syslog(get_class($this) .
"::select_produits_list search products", LOG_DEBUG);
2942 $result = $this->db->query($sql);
2944 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
2945 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
2946 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
2948 $num = $this->db->num_rows($result);
2953 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2957 $out .=
'<select class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" name="' . $htmlname .
'" id="' . $htmlname .
'">';
2963 if ($showempty && !is_numeric($showempty)) {
2964 $textifempty = $langs->trans($showempty);
2966 $textifempty .= $langs->trans(
"All");
2969 if ($showempty && !is_numeric($showempty)) {
2970 $textifempty = $langs->trans($showempty);
2974 $out .=
'<option value="-1" selected>' . ($textifempty ? $textifempty :
' ') .
'</option>';
2978 while ($num && $i < $num) {
2981 $objp = $this->db->fetch_object($result);
2983 if ((
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1) {
2984 $sql =
"SELECT rowid, quantity, price, unitprice, remise_percent, remise, price_base_type";
2985 $sql .=
" FROM " . $this->db->prefix() .
"product_price_by_qty";
2986 $sql .=
" WHERE fk_product_price = " . ((int) $objp->price_rowid);
2987 $sql .=
" ORDER BY quantity ASC";
2989 dol_syslog(get_class($this) .
"::select_produits_list search prices by qty", LOG_DEBUG);
2990 $result2 = $this->db->query($sql);
2992 $nb_prices = $this->db->num_rows($result2);
2994 while ($nb_prices && $j < $nb_prices) {
2995 $objp2 = $this->db->fetch_object($result2);
2997 $objp->price_by_qty_rowid = $objp2->rowid;
2998 $objp->price_by_qty_price_base_type = $objp2->price_base_type;
2999 $objp->price_by_qty_quantity = $objp2->quantity;
3000 $objp->price_by_qty_unitprice = $objp2->unitprice;
3001 $objp->price_by_qty_remise_percent = $objp2->remise_percent;
3003 $objp->quantity = $objp2->quantity;
3004 $objp->price = $objp2->price;
3005 $objp->unitprice = $objp2->unitprice;
3006 $objp->remise_percent = $objp2->remise_percent;
3019 array_push($outarray, $optJson);
3023 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_price_expression)) {
3024 $price_product =
new Product($this->db);
3025 $price_product->fetch($objp->rowid,
'',
'', 1);
3027 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3029 $price_result = $priceparser->parseProduct($price_product);
3030 if ($price_result >= 0) {
3031 $objp->price = $price_result;
3032 $objp->unitprice = $price_result;
3034 $objp->price_ttc =
price2num($objp->price) * (1 + ($objp->tva_tx / 100));
3035 $objp->price_ttc =
price2num($objp->price_ttc,
'MU');
3044 array_push($outarray, $optJson);
3050 $out .=
'</select>';
3052 $this->db->free($result);
3054 if (empty($outputmode)) {
3081 protected function constructProductListOption(&$objp, &$opt, &$optJson, $price_level, $selected, $hidepriceinlabel = 0, $filterkey =
'', $novirtualstock = 0)
3083 global $langs, $conf, $user;
3084 global $hookmanager;
3090 $outlabel_translated =
'';
3092 $outdesc_translated =
'';
3098 $outpricebasetype =
'';
3100 $outdefault_vat_code =
'';
3104 $maxlengtharticle = (!
getDolGlobalString(
'PRODUCT_MAX_LENGTH_COMBO') ? 48 : $conf->global->PRODUCT_MAX_LENGTH_COMBO);
3106 $label = $objp->label;
3107 if (!empty($objp->label_translated)) {
3108 $label = $objp->label_translated;
3110 if (!empty($filterkey) && $filterkey !=
'') {
3111 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
3114 $outkey = $objp->rowid;
3115 $outref = $objp->ref;
3116 $outrefcust = empty($objp->custref) ?
'' : $objp->custref;
3117 $outlabel = $objp->label;
3118 $outdesc = $objp->description;
3120 $outlabel_translated = $objp->label_translated;
3121 $outdesc_translated = $objp->description_translated;
3123 $outbarcode = $objp->barcode;
3124 $outorigin = $objp->fk_country;
3125 $outpbq = empty($objp->price_by_qty_rowid) ?
'' : $objp->price_by_qty_rowid;
3127 $outtype = $objp->fk_product_type;
3132 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
3138 if (!empty($objp->unit_short)) {
3139 $outvalUnits .=
' - ' . $objp->unit_short;
3143 if (!empty($objp->weight) && $objp->weight_units !==
null) {
3145 $outvalUnits .=
' - ' . $unitToShow;
3147 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
3148 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
3149 $outvalUnits .=
' - ' . $unitToShow;
3151 if (!empty($objp->surface) && $objp->surface_units !==
null) {
3153 $outvalUnits .=
' - ' . $unitToShow;
3155 if (!empty($objp->volume) && $objp->volume_units !==
null) {
3157 $outvalUnits .=
' - ' . $unitToShow;
3160 if ($outdurationvalue && $outdurationunit) {
3162 'h' => $langs->trans(
'Hour'),
3163 'd' => $langs->trans(
'Day'),
3164 'w' => $langs->trans(
'Week'),
3165 'm' => $langs->trans(
'Month'),
3166 'y' => $langs->trans(
'Year')
3168 if (isset($da[$outdurationunit])) {
3169 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
3173 $opt =
'<option value="' . $objp->rowid .
'"';
3174 $opt .= ($objp->rowid == $selected) ?
' selected' :
'';
3175 if (!empty($objp->price_by_qty_rowid) && $objp->price_by_qty_rowid > 0) {
3176 $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 .
'"';
3179 if ($user->hasRight(
'stock',
'lire')) {
3180 if ($objp->stock > 0) {
3181 $opt .=
' class="product_line_stock_ok"';
3182 } elseif ($objp->stock <= 0) {
3183 $opt .=
' class="product_line_stock_too_low"';
3188 $opt .=
' data-labeltrans="' . $outlabel_translated .
'"';
3193 if (!empty($objp->custref)) {
3194 $opt .=
' (' . $objp->custref .
')';
3197 $opt .=
' (' . $outbarcode .
')';
3199 $opt .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3201 $opt .=
' (' .
getCountry($outorigin, 1) .
')';
3204 $objRef = $objp->ref;
3205 if (!empty($objp->custref)) {
3206 $objRef .=
' (' . $objp->custref .
')';
3208 if (!empty($filterkey) && $filterkey !=
'') {
3209 $objRef = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRef, 1);
3213 $outval .=
' (' . $outbarcode .
')';
3215 $outval .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3217 $outval .=
' (' .
getCountry($outorigin, 1) .
')';
3221 $opt .= $outvalUnits;
3222 $outval .= $outvalUnits;
3229 $sql =
"SELECT price, price_ttc, price_base_type, tva_tx, default_vat_code";
3230 $sql .=
" FROM " . $this->db->prefix() .
"product_price";
3231 $sql .=
" WHERE fk_product = " . ((int) $objp->rowid);
3232 $sql .=
" AND entity IN (" .
getEntity(
'productprice') .
")";
3233 $sql .=
" AND price_level = " . ((int) $price_level);
3234 $sql .=
" ORDER BY date_price DESC, rowid DESC";
3237 dol_syslog(get_class($this) .
'::constructProductListOption search price for product ' . $objp->rowid .
' AND level ' . $price_level, LOG_DEBUG);
3238 $result2 = $this->db->query($sql);
3240 $objp2 = $this->db->fetch_object($result2);
3243 if ($objp2->price_base_type ==
'HT') {
3244 $opt .=
' - ' .
price($objp2->price, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"HT");
3245 $outval .=
' - ' .
price($objp2->price, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"HT");
3247 $opt .=
' - ' .
price($objp2->price_ttc, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"TTC");
3248 $outval .=
' - ' .
price($objp2->price_ttc, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3250 $outprice_ht =
price($objp2->price);
3251 $outprice_ttc =
price($objp2->price_ttc);
3252 $outpricebasetype = $objp2->price_base_type;
3254 $outtva_tx = $objp2->tva_tx;
3255 $outdefault_vat_code = $objp2->default_vat_code;
3257 $outtva_tx = $objp->tva_tx;
3258 $outdefault_vat_code = $objp->default_vat_code;
3267 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1 && (
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') ||
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
3269 $outqty = $objp->quantity;
3270 $outdiscount = $objp->remise_percent;
3271 if ($objp->quantity == 1) {
3272 $opt .=
' - ' .
price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency) .
"/";
3273 $outval .=
' - ' .
price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency) .
"/";
3274 $opt .= $langs->trans(
"Unit");
3275 $outval .= $langs->transnoentities(
"Unit");
3277 $opt .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1, $conf->currency) .
"/" . $objp->quantity;
3278 $outval .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1, $conf->currency) .
"/" . $objp->quantity;
3279 $opt .= $langs->trans(
"Units");
3280 $outval .= $langs->transnoentities(
"Units");
3283 $outprice_ht =
price($objp->unitprice);
3284 $outprice_ttc =
price($objp->unitprice * (1 + ($objp->tva_tx / 100)));
3285 $outpricebasetype = $objp->price_base_type;
3286 $outtva_tx = $objp->tva_tx;
3287 $outdefault_vat_code = $objp->default_vat_code;
3289 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1) {
3290 $opt .=
" (" .
price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency) .
"/" . $langs->trans(
"Unit") .
")";
3291 $outval .=
" (" .
price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency) .
"/" . $langs->transnoentities(
"Unit") .
")";
3293 if (empty($hidepriceinlabel) && !empty($objp->remise_percent) && $objp->remise_percent >= 1) {
3294 $opt .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3295 $outval .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3300 if (!empty($objp->idprodcustprice)) {
3303 if ($objp->custprice_base_type ==
'HT') {
3304 $opt .=
' - ' .
price($objp->custprice, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"HT");
3305 $outval .=
' - ' .
price($objp->custprice, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"HT");
3307 $opt .=
' - ' .
price($objp->custprice_ttc, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"TTC");
3308 $outval .=
' - ' .
price($objp->custprice_ttc, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3311 $outprice_ht =
price($objp->custprice);
3312 $outprice_ttc =
price($objp->custprice_ttc);
3313 $outpricebasetype = $objp->custprice_base_type;
3314 $outtva_tx = $objp->custtva_tx;
3315 $outdefault_vat_code = $objp->custdefault_vat_code;
3320 if (empty($hidepriceinlabel) && !$found) {
3321 if ($objp->price_base_type ==
'HT') {
3322 $opt .=
' - ' .
price($objp->price, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"HT");
3323 $outval .=
' - ' .
price($objp->price, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"HT");
3325 $opt .=
' - ' .
price($objp->price_ttc, 1, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->trans(
"TTC");
3326 $outval .=
' - ' .
price($objp->price_ttc, 0, $langs, 0, 0, -1, $conf->currency) .
' ' . $langs->transnoentities(
"TTC");
3328 $outprice_ht =
price($objp->price);
3329 $outprice_ttc =
price($objp->price_ttc);
3330 $outpricebasetype = $objp->price_base_type;
3331 $outtva_tx = $objp->tva_tx;
3332 $outdefault_vat_code = $objp->default_vat_code;
3336 if ($user->hasRight(
'stock',
'lire')) {
3337 $opt .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'));
3339 if ($objp->stock > 0) {
3340 $outval .=
' - <span class="product_line_stock_ok">';
3341 } elseif ($objp->stock <= 0) {
3342 $outval .=
' - <span class="product_line_stock_too_low">';
3344 $outval .= $langs->transnoentities(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'));
3345 $outval .=
'</span>';
3346 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
3347 $langs->load(
"stocks");
3349 $tmpproduct =
new Product($this->db);
3350 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
3351 $tmpproduct->load_virtual_stock();
3352 $virtualstock = $tmpproduct->stock_theorique;
3354 $opt .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
3356 $outval .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
3357 if ($virtualstock > 0) {
3358 $outval .=
'<span class="product_line_stock_ok">';
3359 } elseif ($virtualstock <= 0) {
3360 $outval .=
'<span class="product_line_stock_too_low">';
3362 $outval .= $virtualstock;
3363 $outval .=
'</span>';
3370 $parameters = array(
'objp'=>$objp);
3371 $reshook = $hookmanager->executeHooks(
'constructProductListOption', $parameters);
3372 if (empty($reshook)) {
3373 $opt .= $hookmanager->resPrint;
3375 $opt = $hookmanager->resPrint;
3378 $opt .=
"</option>\n";
3383 'label2' => $outlabel,
3387 'price_ttc' =>
price2num($outprice_ttc),
3390 'pricebasetype' => $outpricebasetype,
3391 'tva_tx' => $outtva_tx,
3392 'default_vat_code' => $outdefault_vat_code,
3394 'discount' => $outdiscount,
3395 'duration_value' => $outdurationvalue,
3396 'duration_unit' => $outdurationunit,
3398 'labeltrans' => $outlabel_translated,
3399 'desctrans' => $outdesc_translated,
3400 'ref_customer' => $outrefcust
3471 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 =
'')
3474 global $langs, $conf, $user;
3475 global $hookmanager;
3478 $outarray = array();
3480 $maxlengtharticle = (!
getDolGlobalString(
'PRODUCT_MAX_LENGTH_COMBO') ? 48 : $conf->global->PRODUCT_MAX_LENGTH_COMBO);
3482 $langs->load(
'stocks');
3485 $langs->load(
'other');
3488 $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,";
3489 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice,";
3490 $sql .=
" pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.default_vat_code, pfp.fk_soc, s.nom as name,";
3491 $sql .=
" pfp.supplier_reputation";
3494 $sql .=
", pfp.desc_fourn as description";
3496 $sql .=
", p.description";
3500 $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";
3502 if (isModEnabled(
'barcode')) {
3503 $sql .=
", pfp.barcode";
3505 $sql .=
" FROM " . $this->db->prefix() .
"product as p";
3506 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN (" .
getEntity(
'product') .
") )";
3508 $sql .=
" AND pfp.fk_soc = " . ((int) $socid);
3510 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"societe as s ON pfp.fk_soc = s.rowid";
3513 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"c_units u ON u.rowid = p.fk_unit";
3515 $sql .=
" WHERE p.entity IN (" .
getEntity(
'product') .
")";
3516 if ($statut != -1) {
3517 $sql .=
" AND p.tobuy = " . ((int) $statut);
3519 if (strval($filtertype) !=
'') {
3520 $sql .=
" AND p.fk_product_type = " . ((int) $filtertype);
3522 if (!empty($filtre)) {
3523 $sql .=
" " . $filtre;
3526 $parameters = array();
3527 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListWhere', $parameters);
3528 $sql .= $hookmanager->resPrint;
3530 if ($filterkey !=
'') {
3534 $scrit = explode(
' ', $filterkey);
3536 if (count($scrit) > 1) {
3539 foreach ($scrit as $crit) {
3543 $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) .
"%'";
3545 $sql .=
" OR pfp.desc_fourn LIKE '" . $this->db->escape($prefix . $crit) .
"%'";
3550 if (count($scrit) > 1) {
3553 if (isModEnabled(
'barcode')) {
3554 $sql .=
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3555 $sql .=
" OR pfp.barcode LIKE '" . $this->db->escape($prefix . $filterkey) .
"%'";
3559 $sql .=
" ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC";
3560 $sql .= $this->db->plimit($limit, 0);
3564 dol_syslog(get_class($this) .
"::select_produits_fournisseurs_list", LOG_DEBUG);
3565 $result = $this->db->query($sql);
3567 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3568 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
3570 $num = $this->db->num_rows($result);
3573 $out .=
'<select class="flat ' . ($morecss ?
' ' . $morecss :
'') .
'" id="' . $htmlname .
'" name="' . $htmlname .
'">';
3575 $out .=
'<option value="-1" selected>' . ($placeholder ? $placeholder :
' ') .
'</option>';
3577 $out .=
'<option value="-1">' . ($placeholder ? $placeholder :
' ') .
'</option>';
3582 $objp = $this->db->fetch_object($result);
3584 if (is_null($objp->idprodfournprice)) {
3586 $objp->tva_tx = $objp->tva_tx_sale;
3587 $objp->default_vat_code = $objp->default_vat_code_sale;
3590 $outkey = $objp->idprodfournprice;
3591 if (!$outkey && $alsoproductwithnosupplierprice) {
3592 $outkey =
'idprod_' . $objp->rowid;
3595 $outref = $objp->ref;
3596 $outbarcode = $objp->barcode;
3599 $outtype = $objp->fk_product_type;
3606 if (!empty($objp->unit_short)) {
3607 $outvalUnits .=
' - ' . $objp->unit_short;
3609 if (!empty($objp->weight) && $objp->weight_units !==
null) {
3611 $outvalUnits .=
' - ' . $unitToShow;
3613 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
3614 $unitToShow = $objp->length .
' x ' . $objp->width .
' x ' . $objp->height .
' ' .
measuringUnitString(0,
'size', $objp->length_units);
3615 $outvalUnits .=
' - ' . $unitToShow;
3617 if (!empty($objp->surface) && $objp->surface_units !==
null) {
3619 $outvalUnits .=
' - ' . $unitToShow;
3621 if (!empty($objp->volume) && $objp->volume_units !==
null) {
3623 $outvalUnits .=
' - ' . $unitToShow;
3625 if ($outdurationvalue && $outdurationunit) {
3627 'h' => $langs->trans(
'Hour'),
3628 'd' => $langs->trans(
'Day'),
3629 'w' => $langs->trans(
'Week'),
3630 'm' => $langs->trans(
'Month'),
3631 'y' => $langs->trans(
'Year')
3633 if (isset($da[$outdurationunit])) {
3634 $outvalUnits .=
' - ' . $outdurationvalue .
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ?
's' :
''));
3639 $objRef = $objp->ref;
3640 if ($filterkey && $filterkey !=
'') {
3641 $objRef = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRef, 1);
3643 $objRefFourn = $objp->ref_fourn;
3644 if ($filterkey && $filterkey !=
'') {
3645 $objRefFourn = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $objRefFourn, 1);
3647 $label = $objp->label;
3648 if ($filterkey && $filterkey !=
'') {
3649 $label = preg_replace(
'/(' . preg_quote($filterkey,
'/') .
')/i',
'<strong>$1</strong>', $label, 1);
3652 switch ($objp->fk_product_type) {
3664 if (empty($picto)) {
3667 $optlabel =
img_object(
'', $picto,
'class="paddingright classfortooltip"', 0, 0, 1);
3670 $optlabel .= $objp->ref;
3671 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
3672 $optlabel .=
' <span class="opacitymedium">(' . $objp->ref_fourn .
')</span>';
3674 if (isModEnabled(
'barcode') && !empty($objp->barcode)) {
3675 $optlabel .=
' (' . $outbarcode .
')';
3677 $optlabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3679 $outvallabel = $objRef;
3680 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
3681 $outvallabel .=
' (' . $objRefFourn .
')';
3683 if (isModEnabled(
'barcode') && !empty($objp->barcode)) {
3684 $outvallabel .=
' (' . $outbarcode .
')';
3686 $outvallabel .=
' - ' .
dol_trunc($label, $maxlengtharticle);
3689 $optlabel .= $outvalUnits;
3690 $outvallabel .= $outvalUnits;
3692 if (!empty($objp->idprodfournprice)) {
3693 $outqty = $objp->quantity;
3694 $outdiscount = $objp->remise_percent;
3695 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
3697 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
3698 $prod_supplier->id = $objp->fk_product;
3699 $prod_supplier->fourn_qty = $objp->quantity;
3700 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
3701 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
3703 require_once DOL_DOCUMENT_ROOT .
'/product/dynamic_price/class/price_parser.class.php';
3705 $price_result = $priceparser->parseProductSupplier($prod_supplier);
3706 if ($price_result >= 0) {
3707 $objp->fprice = $price_result;
3708 if ($objp->quantity >= 1) {
3709 $objp->unitprice = $objp->fprice / $objp->quantity;
3713 if ($objp->quantity == 1) {
3714 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency) .
"/";
3715 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1, $conf->currency) .
"/";
3716 $optlabel .= $langs->trans(
"Unit");
3717 $outvallabel .= $langs->transnoentities(
"Unit");
3719 $optlabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency) .
"/" . $objp->quantity;
3720 $outvallabel .=
' - ' .
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1, $conf->currency) .
"/" . $objp->quantity;
3721 $optlabel .=
' ' . $langs->trans(
"Units");
3722 $outvallabel .=
' ' . $langs->transnoentities(
"Units");
3725 if ($objp->quantity > 1) {
3726 $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") .
")";
3727 $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") .
")";
3729 if ($objp->remise_percent >= 1) {
3730 $optlabel .=
" - " . $langs->trans(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3731 $outvallabel .=
" - " . $langs->transnoentities(
"Discount") .
" : " .
vatrate($objp->remise_percent) .
' %';
3733 if ($objp->duration) {
3734 $optlabel .=
" - " . $objp->duration;
3735 $outvallabel .=
" - " . $objp->duration;
3738 $optlabel .=
" - " .
dol_trunc($objp->name, 8);
3739 $outvallabel .=
" - " .
dol_trunc($objp->name, 8);
3741 if ($objp->supplier_reputation) {
3743 $reputations = array(
'' => $langs->trans(
'Standard'),
'FAVORITE' => $langs->trans(
'Favorite'),
'NOTTHGOOD' => $langs->trans(
'NotTheGoodQualitySupplier'),
'DONOTORDER' => $langs->trans(
'DoNotOrderThisProductToThisSupplier'));
3745 $optlabel .=
" - " . $reputations[$objp->supplier_reputation];
3746 $outvallabel .=
" - " . $reputations[$objp->supplier_reputation];
3749 if (empty($alsoproductwithnosupplierprice)) {
3750 $optlabel .=
" - <span class='opacitymedium'>" . $langs->trans(
"NoPriceDefinedForThisSupplier") .
'</span>';
3751 $outvallabel .=
' - ' . $langs->transnoentities(
"NoPriceDefinedForThisSupplier");
3753 $optlabel .=
" - <span class='opacitymedium'>" . $langs->trans(
"NoPriceDefinedForThisSupplier") .
'</span>';
3754 $outvallabel .=
' - ' . $langs->transnoentities(
"NoPriceDefinedForThisSupplier");
3759 $novirtualstock = ($showstockinlist == 2);
3761 if ($user->hasRight(
'stock',
'lire')) {
3762 $outvallabel .=
' - ' . $langs->trans(
"Stock") .
': ' .
price(
price2num($objp->stock,
'MS'));
3764 if ($objp->stock > 0) {
3765 $optlabel .=
' - <span class="product_line_stock_ok">';
3766 } elseif ($objp->stock <= 0) {
3767 $optlabel .=
' - <span class="product_line_stock_too_low">';
3769 $optlabel .= $langs->transnoentities(
"Stock") .
':' .
price(
price2num($objp->stock,
'MS'));
3770 $optlabel .=
'</span>';
3771 if (empty($novirtualstock) &&
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {
3772 $langs->load(
"stocks");
3774 $tmpproduct =
new Product($this->db);
3775 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
3776 $tmpproduct->load_virtual_stock();
3777 $virtualstock = $tmpproduct->stock_theorique;
3779 $outvallabel .=
' - ' . $langs->trans(
"VirtualStock") .
':' . $virtualstock;
3781 $optlabel .=
' - ' . $langs->transnoentities(
"VirtualStock") .
':';
3782 if ($virtualstock > 0) {
3783 $optlabel .=
'<span class="product_line_stock_ok">';
3784 } elseif ($virtualstock <= 0) {
3785 $optlabel .=
'<span class="product_line_stock_too_low">';
3787 $optlabel .= $virtualstock;
3788 $optlabel .=
'</span>';
3795 $optstart =
'<option value="' . $outkey .
'"';
3796 if ($selected && $selected == $objp->idprodfournprice) {
3797 $optstart .=
' selected';
3799 if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) {
3800 $optstart .=
' disabled';
3803 if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) {
3812 $optstart .=
' data-default-vat-code="' .
dol_escape_htmltag($objp->default_vat_code) .
'"';
3815 $optstart .=
' data-description="' .
dol_escape_htmltag($objp->description, 0, 1) .
'"';
3817 $outarrayentry = array(
3820 'label' => $outvallabel,
3822 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
3823 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
3824 'price_ht' =>
price2num($objp->unitprice,
'MU'),
3825 'tva_tx_formated' =>
price($objp->tva_tx, 0, $langs, 1, -1, 2),
3827 'default_vat_code' => $objp->default_vat_code,
3828 'discount' => $outdiscount,
3830 'duration_value' => $outdurationvalue,
3831 'duration_unit' => $outdurationunit,
3832 'disabled' => (empty($objp->idprodfournprice) ?
true :
false),
3833 'description' => $objp->description
3836 $parameters = array(
3838 'optstart' => &$optstart,
3839 'optlabel' => &$optlabel,
3840 'outvallabel' => &$outvallabel,
3841 'outarrayentry' => &$outarrayentry
3843 $reshook = $hookmanager->executeHooks(
'selectProduitsFournisseurListOption', $parameters, $this);
3849 $out .= $optstart .
' data-html="' .
dol_escape_htmltag($optlabel) .
'">' . $optlabel .
"</option>\n";
3852 array(
'key' => $outkey,
3854 'label' => $outvallabel,
3856 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
3857 'price_qty_ht_locale' =>
price($objp->fprice),
3858 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
3859 'price_unit_ht_locale' =>
price($objp->unitprice),
3860 'price_ht' =>
price2num($objp->unitprice,
'MU'),
3861 'tva_tx_formated' =>
price($objp->tva_tx),
3863 'default_vat_code' => $objp->default_vat_code,
3864 'discount' => $outdiscount,
3866 'duration_value' => $outdurationvalue,
3867 'duration_unit' => $outdurationunit,
3868 'disabled' => (empty($objp->idprodfournprice) ?
true :
false),
3869 'description' => $objp->description
3883 $out .=
'</select>';
3885 $this->db->free($result);
3887 include_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
3893 if (empty($outputmode)) {
5221 public function formconfirm($page, $title, $question, $action, $formquestion =
'', $selectedchoice =
'', $useajax = 0, $height = 0, $width = 500, $disableformtag = 0, $labelbuttonyes =
'Yes', $labelbuttonno =
'No')
5223 global $langs, $conf;
5225 $more =
'<!-- formconfirm - before call, page=' .
dol_escape_htmltag($page) .
' -->';
5231 $newselectedchoice = empty($selectedchoice) ?
"no" : $selectedchoice;
5232 if ($conf->browser->layout ==
'phone') {
5237 if (empty($height)) {
5239 if (is_array($formquestion) && count($formquestion) > 2) {
5240 $height += ((count($formquestion) - 2) * 24);
5244 if (is_array($formquestion) && !empty($formquestion)) {
5246 foreach ($formquestion as $key => $input) {
5247 if (is_array($input) && !empty($input)) {
5248 if ($input[
'type'] ==
'hidden') {
5249 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
5250 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
5258 $moreonecolumn =
'';
5259 $more .=
'<div class="tagtable paddingtopbottomonly centpercent noborderspacing">' .
"\n";
5260 foreach ($formquestion as $key => $input) {
5261 if (is_array($input) && !empty($input)) {
5262 $size = (!empty($input[
'size']) ?
' size="' . $input[
'size'] .
'"' :
'');
5263 $moreattr = (!empty($input[
'moreattr']) ?
' ' . $input[
'moreattr'] :
'');
5264 $morecss = (!empty($input[
'morecss']) ?
' ' . $input[
'morecss'] :
'');
5266 if ($input[
'type'] ==
'text') {
5267 $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";
5268 } elseif ($input[
'type'] ==
'password') {
5269 $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";
5270 } elseif ($input[
'type'] ==
'textarea') {
5276 $moreonecolumn .=
'<div class="margintoponly">';
5277 $moreonecolumn .= $input[
'label'] .
'<br>';
5279 $moreonecolumn .= $input[
'value'];
5280 $moreonecolumn .=
'</textarea>';
5281 $moreonecolumn .=
'</div>';
5282 } elseif (in_array($input[
'type'], [
'select',
'multiselect'])) {
5283 if (empty($morecss)) {
5284 $morecss =
'minwidth100';
5287 $show_empty = isset($input[
'select_show_empty']) ? $input[
'select_show_empty'] : 1;
5288 $key_in_label = isset($input[
'select_key_in_label']) ? $input[
'select_key_in_label'] : 0;
5289 $value_as_key = isset($input[
'select_value_as_key']) ? $input[
'select_value_as_key'] : 0;
5290 $translate = isset($input[
'select_translate']) ? $input[
'select_translate'] : 0;
5291 $maxlen = isset($input[
'select_maxlen']) ? $input[
'select_maxlen'] : 0;
5292 $disabled = isset($input[
'select_disabled']) ? $input[
'select_disabled'] : 0;
5293 $sort = isset($input[
'select_sort']) ? $input[
'select_sort'] :
'';
5295 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">';
5296 if (!empty($input[
'label'])) {
5297 $more .= $input[
'label'] .
'</div><div class="tagtd left">';
5299 if ($input[
'type'] ==
'select') {
5300 $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);
5302 $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);
5304 $more .=
'</div></div>' .
"\n";
5305 } elseif ($input[
'type'] ==
'checkbox') {
5306 $more .=
'<div class="tagtr">';
5307 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'"><label for="' .
dol_escape_htmltag($input[
'name']) .
'">' . $input[
'label'] .
'</label></div><div class="tagtd">';
5308 $more .=
'<input type="checkbox" class="flat' . ($morecss ?
' ' . $morecss :
'') .
'" id="' .
dol_escape_htmltag($input[
'name']) .
'" name="' .
dol_escape_htmltag($input[
'name']) .
'"' . $moreattr;
5309 if (!is_bool($input[
'value']) && $input[
'value'] !=
'false' && $input[
'value'] !=
'0' && $input[
'value'] !=
'') {
5310 $more .=
' checked';
5312 if (is_bool($input[
'value']) && $input[
'value']) {
5313 $more .=
' checked';
5315 if (isset($input[
'disabled'])) {
5316 $more .=
' disabled';
5318 $more .=
' /></div>';
5319 $more .=
'</div>' .
"\n";
5320 } elseif ($input[
'type'] ==
'radio') {
5322 foreach ($input[
'values'] as $selkey => $selval) {
5323 $more .=
'<div class="tagtr">';
5324 if (isset($input[
'label'])) {
5326 $more .=
'<div class="tagtd' . (empty($input[
'tdclass']) ?
' tdtop' : (
' tdtop ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
5328 $more .=
'<div clas="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' "' . $input[
'tdclass'])) .
'"> </div>';
5331 $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;
5332 if (!empty($input[
'disabled'])) {
5333 $more .=
' disabled';
5335 if (isset($input[
'default']) && $input[
'default'] === $selkey) {
5336 $more .=
' checked="checked"';
5339 $more .=
'<label for="' .
dol_escape_htmltag($input[
'name'] . $selkey) .
'" class="valignmiddle">' . $selval .
'</label>';
5340 $more .=
'</div></div>' .
"\n";
5343 } elseif ($input[
'type'] ==
'date' || $input[
'type'] ==
'datetime') {
5344 $more .=
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ?
'' : (
' ' . $input[
'tdclass'])) .
'">' . $input[
'label'] .
'</div>';
5345 $more .=
'<div class="tagtd">';
5346 $addnowlink = (empty($input[
'datenow']) ? 0 : 1);
5348 if ($input[
'type'] ==
'datetime') {
5349 $h = isset($input[
'hours']) ? $input[
'hours'] : 1;
5350 $m = isset($input[
'minutes']) ? $input[
'minutes'] : 1;
5352 $more .= $this->
selectDate($input[
'value'], $input[
'name'], $h, $m, 0,
'', 1, $addnowlink);
5353 $more .=
'</div></div>'.
"\n";
5354 $formquestion[] = array(
'name'=>$input[
'name'].
'day');
5355 $formquestion[] = array(
'name'=>$input[
'name'].
'month');
5356 $formquestion[] = array(
'name'=>$input[
'name'].
'year');
5357 $formquestion[] = array(
'name'=>$input[
'name'].
'hour');
5358 $formquestion[] = array(
'name'=>$input[
'name'].
'min');
5359 } elseif ($input[
'type'] ==
'other') {
5360 $more .=
'<div class="tagtr"><div class="tagtd'.(empty($input[
'tdclass']) ?
'' : (
' '.$input[
'tdclass'])).
'">';
5361 if (!empty($input[
'label'])) {
5362 $more .= $input[
'label'] .
'</div><div class="tagtd">';
5364 $more .= $input[
'value'];
5365 $more .=
'</div></div>' .
"\n";
5366 } elseif ($input[
'type'] ==
'onecolumn') {
5367 $moreonecolumn .=
'<div class="margintoponly">';
5368 $moreonecolumn .= $input[
'value'];
5369 $moreonecolumn .=
'</div>' .
"\n";
5370 } elseif ($input[
'type'] ==
'hidden') {
5372 } elseif ($input[
'type'] ==
'separator') {
5375 $more .=
'Error type ' . $input[
'type'] .
' for the confirm box is not a supported type';
5379 $more .=
'</div>' .
"\n";
5380 $more .= $moreonecolumn;
5386 if (!empty($conf->dol_use_jmobile)) {
5389 if (empty($conf->use_javascript_ajax)) {
5395 $dialogconfirm =
'dialog-confirm';
5397 if (!is_numeric($useajax)) {
5401 $dialogconfirm .=
'-' . $button;
5403 $pageyes = $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=yes';
5404 $pageno = ($useajax == 2 ? $page . (preg_match(
'/\?/', $page) ?
'&' :
'?') .
'action=' . urlencode($action) .
'&confirm=no' :
'');
5407 if (is_array($formquestion)) {
5408 foreach ($formquestion as $key => $input) {
5411 if (is_array($input) && isset($input[
'name'])) {
5412 if (strpos($input[
'name'],
',') > 0) {
5413 $inputok = array_merge($inputok, explode(
',', $input[
'name']));
5415 array_push($inputok, $input[
'name']);
5419 if (isset($input[
'inputko']) && $input[
'inputko'] == 1) {
5420 array_push($inputko, $input[
'name']);
5426 $formconfirm .=
'<div id="' . $dialogconfirm .
'" title="' .
dol_escape_htmltag($title) .
'" style="display: none;">';
5427 if (is_array($formquestion) && !empty($formquestion[
'text'])) {
5428 $formconfirm .=
'<div class="confirmtext">' . $formquestion[
'text'] .
'</div>' .
"\n";
5430 if (!empty($more)) {
5431 $formconfirm .=
'<div class="confirmquestions">' . $more .
'</div>' .
"\n";
5433 $formconfirm .= ($question ?
'<div class="confirmmessage">' .
img_help(
'',
'') .
' ' . $question .
'</div>' :
'');
5434 $formconfirm .=
'</div>' .
"\n";
5436 $formconfirm .=
"\n<!-- begin code of popup for formconfirm page=" . $page .
" -->\n";
5437 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
5438 $formconfirm .=
"/* Code for the jQuery('#dialogforpopup').dialog() */\n";
5439 $formconfirm .=
'jQuery(document).ready(function() {
5441 $( "#' . $dialogconfirm .
'" ).dialog(
5443 autoOpen: ' . ($autoOpen ?
"true" :
"false") .
',';
5444 if ($newselectedchoice ==
'no') {
5447 $(this).parent().find("button.ui-button:eq(2)").focus();
5452 if ($useajax == 1) {
5453 $jsforcursor =
'// The call to urljump can be slow, so we set the wait cursor' .
"\n";
5454 $jsforcursor .=
'jQuery("html,body,#id-container").addClass("cursorwait");' .
"\n";
5457 $postconfirmas =
'GET';
5461 height: "' . $height .
'",
5462 width: "' . $width .
'",
5464 closeOnEscape: false,
5466 "' .
dol_escape_js($langs->transnoentities($labelbuttonyes)) .
'": function() {
5467 var options = "token=' . urlencode(newToken()) .
'";
5468 var inputok = ' . json_encode($inputok) .
'; /* List of fields into form */
5469 var page = "' .
dol_escape_js(!empty($page) ? $page :
'') .
'";
5470 var pageyes = "' .
dol_escape_js(!empty($pageyes) ? $pageyes :
'') .
'";
5472 if (inputok.length > 0) {
5473 $.each(inputok, function(i, inputname) {
5476 if ($("input[name=\'" + inputname + "\']").attr("type") == "radio") {
5477 inputvalue = $("input[name=\'" + inputname + "\']:checked").val();
5479 if ($("#" + inputname).attr("type") == "checkbox") { more = ":checked"; }
5480 inputvalue = $("#" + inputname + more).val();
5482 if (typeof inputvalue == "undefined") { inputvalue=""; }
5483 console.log("formconfirm check inputname="+inputname+" inputvalue="+inputvalue);
5484 options += "&" + inputname + "=" + encodeURIComponent(inputvalue);
5487 var urljump = pageyes + (pageyes.indexOf("?") < 0 ? "?" : "&") + options;
5488 if (pageyes.length > 0) {';
5489 if ($postconfirmas ==
'GET') {
5490 $formconfirm .=
'location.href = urljump;';
5492 $formconfirm .= $jsforcursor;
5493 $formconfirm .=
'var post = $.post(
5496 function(data) { $("body").html(data); jQuery("html,body,#id-container").removeClass("cursorwait"); }
5500 console.log("after post ok");
5502 $(this).dialog("close");
5504 "' .
dol_escape_js($langs->transnoentities($labelbuttonno)) .
'": function() {
5505 var options = "token=' . urlencode(newToken()) .
'";
5506 var inputko = ' . json_encode($inputko) .
'; /* List of fields into form */
5507 var page = "' .
dol_escape_js(!empty($page) ? $page :
'') .
'";
5508 var pageno="' .
dol_escape_js(!empty($pageno) ? $pageno :
'') .
'";
5509 if (inputko.length > 0) {
5510 $.each(inputko, function(i, inputname) {
5512 if ($("#" + inputname).attr("type") == "checkbox") { more = ":checked"; }
5513 var inputvalue = $("#" + inputname + more).val();
5514 if (typeof inputvalue == "undefined") { inputvalue=""; }
5515 options += "&" + inputname + "=" + encodeURIComponent(inputvalue);
5518 var urljump=pageno + (pageno.indexOf("?") < 0 ? "?" : "&") + options;
5520 if (pageno.length > 0) {';
5521 if ($postconfirmas ==
'GET') {
5522 $formconfirm .=
'location.href = urljump;';
5524 $formconfirm .= $jsforcursor;
5525 $formconfirm .=
'var post = $.post(
5528 function(data) { $("body").html(data); jQuery("html,body,#id-container").removeClass("cursorwait"); }
5532 console.log("after post ko");
5534 $(this).dialog("close");
5540 var button = "' . $button .
'";
5541 if (button.length > 0) {
5542 $( "#" + button ).click(function() {
5543 $("#' . $dialogconfirm .
'").dialog("open");
5549 $formconfirm .=
"<!-- end ajax formconfirm -->\n";
5551 $formconfirm .=
"\n<!-- begin formconfirm page=" .
dol_escape_htmltag($page) .
" -->\n";
5553 if (empty($disableformtag)) {
5554 $formconfirm .=
'<form method="POST" action="' . $page .
'" class="notoptoleftroright">' .
"\n";
5557 $formconfirm .=
'<input type="hidden" name="action" value="' . $action .
'">' .
"\n";
5558 $formconfirm .=
'<input type="hidden" name="token" value="' . newToken() .
'">' .
"\n";
5560 $formconfirm .=
'<table class="valid centpercent">' .
"\n";
5563 $formconfirm .=
'<tr class="validtitre"><td class="validtitre" colspan="2">';
5564 $formconfirm .=
img_picto(
'',
'pictoconfirm') .
' ' . $title;
5565 $formconfirm .=
'</td></tr>' .
"\n";
5568 if (is_array($formquestion) && !empty($formquestion[
'text'])) {
5569 $formconfirm .=
'<tr class="valid"><td class="valid" colspan="2">' . $formquestion[
'text'] .
'</td></tr>' .
"\n";
5574 $formconfirm .=
'<tr class="valid"><td class="valid" colspan="2">' .
"\n";
5575 $formconfirm .= $more;
5576 $formconfirm .=
'</td></tr>' .
"\n";
5580 $formconfirm .=
'<tr class="valid">';
5581 $formconfirm .=
'<td class="valid">' . $question .
'</td>';
5582 $formconfirm .=
'<td class="valid center">';
5583 $formconfirm .= $this->
selectyesno(
"confirm", $newselectedchoice, 0,
false, 0, 0,
'marginleftonly marginrightonly', $labelbuttonyes, $labelbuttonno);
5584 $formconfirm .=
'<input class="button valignmiddle confirmvalidatebutton small" type="submit" value="' . $langs->trans(
"Validate") .
'">';
5585 $formconfirm .=
'</td>';
5586 $formconfirm .=
'</tr>' .
"\n";
5588 $formconfirm .=
'</table>' .
"\n";
5590 if (empty($disableformtag)) {
5591 $formconfirm .=
"</form>\n";
5593 $formconfirm .=
'<br>';
5595 if (!empty($conf->use_javascript_ajax)) {
5596 $formconfirm .=
'<!-- code to disable button to avoid double clic -->';
5597 $formconfirm .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">' .
"\n";
5599 $(document).ready(function () {
5600 $(".confirmvalidatebutton").on("click", function() {
5601 console.log("We click on button confirmvalidatebutton");
5602 $(this).attr("disabled", "disabled");
5603 setTimeout(\'$(".confirmvalidatebutton").removeAttr("disabled")\', 3000);
5604 //console.log($(this).closest("form"));
5605 $(this).closest("form").submit();
5609 $formconfirm .=
'</script>' .
"\n";
5612 $formconfirm .=
"<!-- end formconfirm -->\n";
5615 return $formconfirm;