added the option to display customfields in the infolog main view.

after selecting customfields with the columnselector, you can choose which customfields you want to display
in the customfields column with the columnselector.
This commit is contained in:
Klaus Leithoff 2007-11-23 12:51:59 +00:00
parent 503a7a06d0
commit ecbb4e2b55
2 changed files with 132 additions and 5 deletions

View File

@ -73,6 +73,41 @@ class soinfolog // DB-Layer
* @var int
*/
var $tz_offset;
/**
* @var string
*/
var $extra_id = 'info_id';
/**
* @var string
*/
var $extra_key = 'info_extra_name';
/**
* @var string
*/
var $extra_value = 'info_extra_value';
/**
* custom fields backend
*
* @var so_sql
*/
var $soextra;
/**
* customfields name => array(...) pairs
*
* @var array
*/
var $customfields = array();
/**
* content-types as name => array(...) pairs
*
* @var array
*/
var $content_types = array();
/**
* Constructor
@ -90,7 +125,23 @@ class soinfolog // DB-Layer
$this->links =& new solink();
$this->tz_offset = $GLOBALS['egw_info']['user']['preferences']['common']['tz_offset'];
}
$this->soextra =& CreateObject('etemplate.so_sql');
$this->soextra->so_sql('infolog',$this->extra_table);
$custom =& CreateObject('admin.customfields','infolog');
$this->customfields = $custom->get_customfields();
$this->content_types = $custom->get_content_types();
if (!$this->content_types)
{
$this->content_types = $custom->content_types = array('n' => array(
'name' => 'infolog',
'options' => array(
'template' => 'infolog.edit',
'icon' => 'navbar.png'
)));
$custom->save_repository();
}
}
/**
* Check if use is responsible for an entry: he or one of his memberships is in responsible
@ -694,6 +745,9 @@ class soinfolog // DB-Layer
$sql_query = 'AND ('.(is_numeric($query['search']) ? 'main.info_id='.(int)$query['search'].' OR ' : '').
implode(" LIKE $pattern OR ",$columns)." LIKE $pattern) ";
}
if ($query['search'] || $query['custom_fields'] )
{
$join = "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' : '';
@ -721,7 +775,10 @@ 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";
}
$this->db->query($sql="SELECT $distinct main.* $count_subs $sql_query $ordermethod",__LINE__,__FILE__,
$info_customfield = "";
//$info_customfield = ", $this->extra_table.info_extra_value ";
//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);
//echo "<p>db::query('$sql',,,".(int)$query['start'].','.(isset($query['start']) ? (int) $query['num_rows'] : -1).")</p>\n";
while (($info =& $this->db->row(true)))
@ -735,7 +792,12 @@ class soinfolog // DB-Layer
$this->db->select($this->extra_table,'*',array('info_id'=>array_keys($ids)),__LINE__,__FILE__);
while ($row = $this->db->row(true))
{
$ids[$row['info_id']]['#'.$row['info_extra_name']] = $row['info_extra_value'];
if ((isset($row['info_extra_value'])&&strlen($row['info_extra_value'])>0) &&
(stripos($query['selectcols'],'#'.$row['info_extra_name'])!==FALSE || !isset($query['selectcols']) ||
(stripos($query['selectcols'],'#')===FALSE && stripos($query['selectcols'],'customfields')!==FALSE) ))
{
$ids[$row['info_id']]['#'.$row['info_extra_name']] = $row['info_extra_value'];
}
}
}
}

View File

@ -341,6 +341,61 @@ class uiinfolog
}
//echo "<p align=right>template ='".'infolog.index.rows.'.$query['col_filter']['info_type']."'".(!$query['template'] ? ' not' : '')." found</p>\n";
}
// do we need to read the custom fields, depends on the column is enabled and customfields exist
$columselection = $this->prefs['nextmatch-infolog.index.rows'];
//_debug_array($columselection);
if ($columselection)
{
if (!isset($query['selectcols'])) $query['selectcols']=$columselection;
$columselection = explode(',',$columselection);
}
$show_custom_fields = (!$columselection || in_array('customfields',$columselection)) && $this->bo->customfields;
$lv_customfields=array(); // used to set the visible columns
$showallcustfields=0; // control the switching on and off, of the customfields
if ((stripos($query['selectcols'],'#')===FALSE && stripos($query['selectcols'],'customfields')!==FALSE) ) $showallcustfields=1;
if ( $show_custom_fields || $query['custom_fields'] )
{
if ($query['col_filter']['info_type'])
{
foreach ($this->bo->customfields as $cf=>$cfa)
{
if (isset($cfa['type2'])&& trim($cfa['type2'])!=='') // type specific fields
{
if ((stripos($cfa['type2'], $query['col_filter']['info_type'] )) !== FALSE &&
(in_array('#'.$cf,$columselection)||$showallcustfields==1))
{
$lv_customfields[$cf]=$cfa;
$readonlys['#'.$cf] = true;
if (stripos($query['selectcols'],'#'.$cf)===FALSE) $query['selectcols'].=",#".$cf;
}
} else {
if ($showallcustfields==1 || in_array('#'.$cf,$columselection)) {
$lv_customfields[$cf]=$cfa;
$readonlys['#'.$cf] = true;
if (stripos($query['selectcols'],'#'.$cf)===FALSE) $query['selectcols'].=",#".$cf;
}
}
// set the array for the available cust-cols
$query['options-selectcols']['#'.$cf]=$cfa['label'];
}
} else {
// set the columns to be available for selections
$cvp=array();
foreach($this->bo->customfields as $name => $value)
{
if ($showallcustfields==1 || in_array('#'.$name,$columselection)) {
$lv_customfields[$name]=$value;
//echo $name."->". $value['label']."<br>";
$readonlys['#'.$name] = true;
if (stripos($query['selectcols'],'#'.$name)!==FALSE) $query['selectcols'].=",#".$name;
}
//set the array for the available cust-cols
$cvp['#'.$name] = $value['label'];
}
$query['options-selectcols']=$cvp;
}
$query['custom_fields'] =true;
}
$ids = $this->bo->search($query);
if (!is_array($ids))
{
@ -375,11 +430,22 @@ class uiinfolog
}
}
$rows[] = $info;
//foreach($info as $name => $value)
//{
// if (!(stripos($name,'#')===false))
// {
// $customfields[$id][$name]=$value;
// }
//}
}
if ($query['cat_id']) $rows['no_cat_id'] = true;
if ($query['no_actions']) $rows['no_actions'] = true;
$rows['no_timesheet'] = !isset($GLOBALS['egw_info']['user']['apps']['timesheet']);
$rows['duration_format'] = ','.$this->duration_format.',,1';
if ( $show_custom_fields || $query['custom_fields'] )
{
$rows['customfields'] = array_values($lv_customfields);
}
if ($GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'none' &&
!isset($GLOBALS['egw_info']['user']['apps']['admin']))
{
@ -557,7 +623,7 @@ class uiinfolog
$readonlys['cancel'] = $action != 'sp';
$this->tmpl->read('infolog.index');
$values['nm']['options-filter'] = $this->filters;
$values['nm']['get_rows'] = 'infolog.uiinfolog.get_rows';
$values['nm']['options-filter2'] = (in_array($this->prefs['show_links'],array('all','no_describtion')) ? array() : array(
@ -590,7 +656,6 @@ class uiinfolog
$persist['called_as'] = $called_as;
$persist['own_referer'] = $own_referer;
$values['nm']['csv_fields'] = true; // get set in get_rows to not include all custom fields
$all_stati = array();
foreach($this->bo->status as $typ => $stati)
{