From 29820868feaf62afe700eb3cf4a4e0ee861e05fb Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Thu, 13 Dec 2007 11:18:44 +0000 Subject: [PATCH] added the needed code to enable the functionality of sorting and selecting by customfields --- infolog/inc/class.soinfolog.inc.php | 34 ++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/infolog/inc/class.soinfolog.inc.php b/infolog/inc/class.soinfolog.inc.php index 059462a996..f2a265db2c 100644 --- a/infolog/inc/class.soinfolog.inc.php +++ b/infolog/inc/class.soinfolog.inc.php @@ -673,18 +673,24 @@ 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); - $val = (substr($val,0,5) != 'info_' ? 'info_' : '').$val; - if ($val == 'info_des' && $this->db->capabilities['order_on_text'] !== true) - { - if (!$this->db->capabilities['order_on_text']) continue; + 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) + { + if (!$this->db->capabilities['order_on_text']) continue; - $val = sprintf($this->db->capabilities['order_on_text'],$val); + $val = sprintf($this->db->capabilities['order_on_text'],$val); + } } $order[] = $val; } @@ -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 "

filtermethod='$filtermethod'

"; @@ -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"."
"; $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']]); } } }