4if (empty($conf) || !is_object($conf)) {
5 print
"Error, template page can't be called as URL";
9if (empty($extrafieldsobjectkey) && is_object($object)) {
10 $extrafieldsobjectkey = $object->table_element;
14if (!empty($extrafieldsobjectkey) && !empty($search_array_options) && is_array($search_array_options)) {
15 if (empty($extrafieldsobjectprefix)) {
16 $extrafieldsobjectprefix =
'ef.';
18 if (empty($search_options_pattern)) {
19 $search_options_pattern =
'search_options_';
22 foreach ($search_array_options as $key => $val) {
24 $tmpkey = preg_replace(
'/'.$search_options_pattern.
'/',
'', $key);
25 $typ = $extrafields->attributes[$extrafieldsobjectkey][
'type'][$tmpkey];
27 if ($crit !=
'' && in_array($typ, array(
'date',
'datetime',
'timestamp'))) {
28 if (is_numeric($crit)) {
30 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
33 $sql .=
" AND ".$extrafieldsobjectprefix.$tmpkey.
" = '".$db->idate($crit).
"'";
34 } elseif (is_array($crit)) {
35 if ($crit[
'start'] !==
'' && $crit[
'end'] !==
'') {
36 $sql .=
" AND (".$extrafieldsobjectprefix.$tmpkey.
" BETWEEN '". $db->idate($crit[
'start']).
"' AND '".$db->idate($crit[
'end']) .
"')";
37 } elseif ($crit[
'start'] !==
'') {
38 $sql .=
" AND (".$extrafieldsobjectprefix.$tmpkey.
" >= '". $db->idate($crit[
'start']).
"')";
39 } elseif ($crit[
'end'] !==
'') {
40 $sql .=
" AND (".$extrafieldsobjectprefix.$tmpkey.
" <= '". $db->idate($crit[
'end']).
"')";
43 } elseif (in_array($typ, array(
'boolean'))) {
44 if ($crit !==
'-1' && $crit !==
'') {
45 $sql .=
" AND (".$extrafieldsobjectprefix.$tmpkey.
" = '".$db->escape($crit).
"'";
47 $sql .=
" OR ".$extrafieldsobjectprefix.$tmpkey.
" IS NULL";
51 } elseif ($crit !=
'' && (!in_array($typ, array(
'select',
'sellist',
'select')) || $crit !=
'0') && (!in_array($typ, array(
'link')) || $crit !=
'-1')) {
53 if (in_array($typ, array(
'int',
'double',
'real',
'price'))) {
56 if (in_array($typ, array(
'sellist',
'link')) && $crit !=
'0' && $crit !=
'-1') {
59 if (in_array($typ, array(
'sellist')) && !is_numeric($crit)) {
62 if (in_array($typ, array(
'chkbxlst',
'checkbox',
'select'))) {
65 if (is_array($crit)) {
66 $crit = implode(
' ', $crit);
67 } elseif ($typ ===
'select' and is_string($crit) and strpos($crit,
',') ===
false) {
68 $critSelect =
"'".implode(
"','", array_map(array($db,
'escape'), explode(
',', $crit))).
"'";
69 $sql .=
" AND (".$extrafieldsobjectprefix.$tmpkey.
" IN (".$db->sanitize($critSelect, 1).
") )";
72 $sql .=
natural_search($extrafieldsobjectprefix.$tmpkey, $crit, $mode_search);
dol_get_first_hour($date, $gm='tzserver')
Return GMT time for first hour of a given GMT date (it removes hours, min and second part)
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...