forked from extern/egroupware
added the needed code to enable the functionality of sorting and selecting by customfields
This commit is contained in:
parent
ab60a02467
commit
29820868fe
@ -673,12 +673,17 @@ class soinfolog // DB-Layer
|
||||
$link_extra = ($action == 'sp' ? 'OR' : 'AND')." main.info_id IN (".implode(',',$links).')';
|
||||
}
|
||||
}
|
||||
if (!empty($query['order']) && eregi('^[a-z_0-9, ]+$',$query['order']) && (empty($query['sort']) || eregi('^(DESC|ASC)$',$query['sort'])))
|
||||
$sortbycf='';
|
||||
if (!empty($query['order']) && (eregi('^[a-z_0-9, ]+$',$query['order']) || stripos($query['order'],'#')!==FALSE ) && (empty($query['sort']) || eregi('^(DESC|ASC)$',$query['sort'])))
|
||||
{
|
||||
$order = array();
|
||||
foreach(explode(',',$query['order']) as $val)
|
||||
{
|
||||
$val = trim($val);
|
||||
if (substr($val,0,1)=='#') {
|
||||
$sortbycf=substr($val,1);
|
||||
$val="cfsortcrit";
|
||||
} else {
|
||||
$val = (substr($val,0,5) != 'info_' ? 'info_' : '').$val;
|
||||
if ($val == 'info_des' && $this->db->capabilities['order_on_text'] !== true)
|
||||
{
|
||||
@ -686,6 +691,7 @@ class soinfolog // DB-Layer
|
||||
|
||||
$val = sprintf($this->db->capabilities['order_on_text'],$val);
|
||||
}
|
||||
}
|
||||
$order[] = $val;
|
||||
}
|
||||
$ordermethod = 'ORDER BY ' . implode(',',$order) . ' ' . $query['sort'];
|
||||
@ -697,12 +703,12 @@ class soinfolog // DB-Layer
|
||||
$acl_filter = $filtermethod = $this->aclFilter($query['filter']);
|
||||
$filtermethod .= $this->statusFilter($query['filter']);
|
||||
$filtermethod .= $this->dateFilter($query['filter']);
|
||||
|
||||
$cfcolfilter=0;
|
||||
if (is_array($query['col_filter']))
|
||||
{
|
||||
foreach($query['col_filter'] as $col => $data)
|
||||
{
|
||||
if (substr($col,0,5) != 'info_') $col = 'info_'.$col;
|
||||
if (substr($col,0,5) != 'info_' && substr($col,0,1)!='#') $col = 'info_'.$col;
|
||||
if (!empty($data) && eregi('^[a-z_0-9]+$',$col))
|
||||
{
|
||||
if ($col == 'info_responsible')
|
||||
@ -719,6 +725,10 @@ class soinfolog // DB-Layer
|
||||
$filtermethod .= ' AND '.$this->db->expression($this->info_table,array($col => $data));
|
||||
}
|
||||
}
|
||||
if (substr($col,0,1)=='#' && $query['custom_fields'] && $data) {
|
||||
$filtermethod.=" and main.info_id in (select distinct info_id from $this->extra_table"." where (info_extra_name='".substr($col,1)."' and info_extra_value='".$data."')) ";
|
||||
$cfcolfilter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
//echo "<p>filtermethod='$filtermethod'</p>";
|
||||
@ -748,7 +758,7 @@ class soinfolog // DB-Layer
|
||||
}
|
||||
if ($query['search'] || $query['custom_fields'] )
|
||||
{
|
||||
$join = "LEFT JOIN $this->extra_table ON main.info_id=$this->extra_table.info_id";
|
||||
$join = ($cfcolfilter>0 ? '':"LEFT")." JOIN $this->extra_table ON main.info_id=$this->extra_table.info_id ";
|
||||
// mssql and others cant use DISTICT if text columns (info_des) are involved
|
||||
$distinct = $this->db->capabilities['distinct_on_text'] ? 'DISTINCT' : '';
|
||||
}
|
||||
@ -776,7 +786,9 @@ class soinfolog // DB-Layer
|
||||
$count_subs = ",(SELECT count(*) FROM $this->info_table sub WHERE sub.info_id_parent=main.info_id AND $acl_filter) AS info_anz_subs";
|
||||
}
|
||||
$info_customfield = "";
|
||||
//$info_customfield = ", $this->extra_table.info_extra_value ";
|
||||
if ($sortbycf!='') {
|
||||
$info_customfield = ", (select distinct info_extra_value from $this->extra_table sub2 where sub2.info_id=main.info_id and info_extra_name='".$sortbycf."') AS cfsortcrit ";
|
||||
}
|
||||
//echo "SELECT $distinct main.* $count_subs $info_customfield $sql_query $ordermethod"."<br>";
|
||||
$this->db->query($sql="SELECT $distinct main.* $count_subs $info_customfield $sql_query $ordermethod",__LINE__,__FILE__,
|
||||
(int) $query['start'],isset($query['start']) ? (int) $query['num_rows'] : -1);
|
||||
@ -797,6 +809,8 @@ class soinfolog // DB-Layer
|
||||
(stripos($query['selectcols'],'#')===FALSE && stripos($query['selectcols'],'customfields')!==FALSE) ))
|
||||
{
|
||||
$ids[$row['info_id']]['#'.$row['info_extra_name']] = $row['info_extra_value'];
|
||||
} else {
|
||||
unset($ids[$row['info_id']]['#'.$row['info_extra_name']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user