dolibarr  9.0.0
extrafields_list_search_sql.tpl.php
1 <?php
2 
3 // Protection to avoid direct call of template
4 if (empty($conf) || ! is_object($conf))
5 {
6  print "Error, template page can't be called as URL";
7  exit;
8 }
9 
10 if (empty($extrafieldsobjectkey) && is_object($object)) $extrafieldsobjectkey=$object->table_element;
11 
12 // Loop to complete the sql search criterias from extrafields
13 if (! empty($extrafieldsobjectkey) && ! empty($search_array_options) && is_array($search_array_options)) // $extrafieldsobject is the $object->table_element like 'societe', 'socpeople', ...
14 {
15  foreach ($search_array_options as $key => $val)
16  {
17  $crit=$val;
18  $tmpkey=preg_replace('/search_options_/','',$key);
19  $typ=$extrafields->attributes[$extrafieldsobjectkey]['type'][$tmpkey];
20 
21  if ($crit != '' && in_array($typ, array('date', 'datetime', 'timestamp')))
22  {
23  $sql .= " AND ef.".$tmpkey." = '".$db->idate($crit)."'";
24  }
25  elseif ($crit != '' && (! in_array($typ, array('select','sellist')) || $crit != '0') && (! in_array($typ, array('link')) || $crit != '-1'))
26  {
27  $mode_search=0;
28  if (in_array($typ, array('int','double','real'))) $mode_search=1; // Search on a numeric
29  if (in_array($typ, array('sellist','link')) && $crit != '0' && $crit != '-1') $mode_search=2; // Search on a foreign key int
30  if (in_array($typ, array('chkbxlst','checkbox'))) $mode_search=4; // Search on a multiselect field with sql type = text
31 
32  $sql .= natural_search('ef.'.$tmpkey, $crit, $mode_search);
33  }
34  }
35 }
print
Draft customers invoices.
Definition: index.php:91
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...