2005-10-28 20:29:05 +02:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
|
|
|
* eGroupWare - eTemplate Widget for custom fields *
|
|
|
|
* http://www.egroupware.org *
|
|
|
|
* Written by Ralf Becker <RalfBecker@outdoor-training.de> and *
|
|
|
|
* Cornelius Weiss <egw@von-und-zu-weiss.de> *
|
|
|
|
* -------------------------------------------- *
|
|
|
|
* This program is free software; you can redistribute it and/or modify it *
|
|
|
|
* under the terms of the GNU General Public License as published by the *
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your *
|
|
|
|
* option) any later version. *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/**
|
2006-03-14 14:54:17 +01:00
|
|
|
* This widget generates a template for customfields based on definitions in egw_config table
|
2005-10-28 20:29:05 +02:00
|
|
|
*
|
2005-11-10 06:15:06 +01:00
|
|
|
* @package etemplate
|
2005-11-08 15:33:16 +01:00
|
|
|
* @subpackage extensions
|
2005-10-28 20:29:05 +02:00
|
|
|
* @author RalfBecker-At-outdoor-training.de
|
|
|
|
* @author Cornelius Weiss <egw@von-und-zu-weiss.de>
|
2005-11-08 15:33:16 +01:00
|
|
|
* @license GPL - GNU General Public License
|
2005-10-28 20:29:05 +02:00
|
|
|
*/
|
|
|
|
class customfields_widget
|
|
|
|
{
|
|
|
|
var $public_functions = array(
|
|
|
|
'pre_process' => True,
|
|
|
|
);
|
|
|
|
var $human_name = 'custom fields';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var $prefix string Prefix for every custiomfield name returned in $content (# for general (admin) customfields)
|
|
|
|
*/
|
|
|
|
var $prefix = '#';
|
|
|
|
|
|
|
|
function customfields_widget($ui)
|
|
|
|
{
|
|
|
|
$this->appname = $GLOBALS['egw_info']['flags']['currentapp'];
|
|
|
|
$this->config =& CreateObject('phpgwapi.config',$this->appname);
|
|
|
|
$this->config->appname = $this->appname;
|
|
|
|
$config = $this->config->read_repository();
|
2005-11-08 15:33:16 +01:00
|
|
|
//merge old config_name in egw_config table
|
2005-10-28 20:29:05 +02:00
|
|
|
$config_name = isset($config['customfields']) ? 'customfields' : 'custom_fields';
|
|
|
|
$this->customfields = $config[$config_name];
|
2006-03-14 14:54:17 +01:00
|
|
|
$this->types = $config['types'];
|
2005-11-02 17:48:24 +01:00
|
|
|
$this->advanced_search = $GLOBALS['egw_info']['etemplate']['advanced_search'];
|
|
|
|
|
2005-10-28 20:29:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
|
|
|
|
{
|
2005-11-08 15:33:16 +01:00
|
|
|
$readonly = $cell['readonly'] || $readonlys[$name];
|
|
|
|
|
2005-10-28 20:29:05 +02:00
|
|
|
// infolog compability
|
|
|
|
if ($this->appname == 'infolog')
|
|
|
|
{
|
2006-03-14 14:54:17 +01:00
|
|
|
$type2 = $value['###typ###'];
|
2005-10-28 20:29:05 +02:00
|
|
|
unset($value['###typ###']);
|
|
|
|
$this->customfields = $value;
|
|
|
|
}
|
|
|
|
|
2005-11-04 13:11:50 +01:00
|
|
|
if(!is_array($this->customfields))
|
2005-10-28 20:29:05 +02:00
|
|
|
{
|
|
|
|
$cell['type'] = 'label';
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
|
|
|
$tpl =& new etemplate;
|
|
|
|
$tpl->init('*** generated custom fields','','',0,'',0,0); // make an empty template
|
|
|
|
|
2005-11-08 15:33:16 +01:00
|
|
|
//echo '<pre style="text-align: left;">'; print_r($value); echo "</pre>\n";
|
2005-10-28 20:29:05 +02:00
|
|
|
foreach($this->customfields as $name => $field)
|
|
|
|
{
|
2006-03-14 14:54:17 +01:00
|
|
|
if (!empty($field['type2']) && $field['type2'] != $type2)
|
2005-10-28 20:29:05 +02:00
|
|
|
{
|
2006-03-14 14:54:17 +01:00
|
|
|
continue; // not for our content type
|
2005-10-28 20:29:05 +02:00
|
|
|
}
|
|
|
|
if(empty($field['type']))
|
|
|
|
{
|
|
|
|
if (count($field['values'])) $field['type'] = 'select'; // selectbox
|
|
|
|
elseif ($field['rows'] > 1) $field['type'] = 'textarea'; // textarea
|
|
|
|
elseif (intval($field['len']) > 0) $field['type'] = 'text'; // regular input field
|
|
|
|
else $field['type'] = 'label'; // header-row
|
|
|
|
}
|
|
|
|
|
|
|
|
$row_class = 'row';
|
|
|
|
$label = &$tpl->new_cell(++$n,'label',$field['label'],'',array(
|
|
|
|
'no_lang' => substr(lang($field['label']),-1) == '*' ? 2 : 0
|
|
|
|
));
|
|
|
|
switch ($field['type'])
|
|
|
|
{
|
|
|
|
case 'select' :
|
2005-11-02 17:48:24 +01:00
|
|
|
if($this->advanced_search) $field['values'][''] = lang('doesn\'t matter');
|
2005-10-28 20:29:05 +02:00
|
|
|
foreach($field['values'] as $key => $val)
|
|
|
|
{
|
|
|
|
if (substr($val = lang($val),-1) != '*')
|
|
|
|
{
|
|
|
|
$field['values'][$key] = $val;
|
|
|
|
}
|
|
|
|
}
|
2005-11-10 13:10:17 +01:00
|
|
|
$input = &$tpl->new_cell($n,'hbox');
|
|
|
|
if($this->advanced_search)
|
|
|
|
{
|
|
|
|
$not = &$tpl->add_child($input, $check = &$tpl->empty_cell('checkbox','!'.$this->prefix.$name,array(
|
|
|
|
'label' => 'NOT',
|
|
|
|
'no_lang' => True
|
|
|
|
)));
|
|
|
|
unset($not);
|
|
|
|
unset($check);
|
|
|
|
}
|
|
|
|
$select = &$tpl->add_child($input, $item = &$tpl->empty_cell('select',$this->prefix.$name,array(
|
2005-10-28 20:29:05 +02:00
|
|
|
'sel_options' => $field['values'],
|
|
|
|
'size' => $field['rows'],
|
|
|
|
'no_lang' => True
|
2005-11-10 13:10:17 +01:00
|
|
|
)));
|
|
|
|
unset($select);
|
|
|
|
unset($item);
|
2005-10-28 20:29:05 +02:00
|
|
|
break;
|
|
|
|
case 'label' :
|
|
|
|
$label['span'] = 'all';
|
|
|
|
$tpl->new_cell($n); // is needed even if its over-span-ed
|
|
|
|
$row_class = 'th';
|
|
|
|
break;
|
|
|
|
case 'checkbox' :
|
|
|
|
$input = &$tpl->new_cell($n,'checkbox','',$this->prefix.$name);
|
|
|
|
break;
|
|
|
|
case 'radio' :
|
2005-10-28 23:05:56 +02:00
|
|
|
$input = &$tpl->new_cell($n,'groupbox','','','');
|
2005-10-28 20:29:05 +02:00
|
|
|
$m = 0;
|
|
|
|
foreach ($field['values'] as $key => $val)
|
|
|
|
{
|
2005-10-28 23:05:56 +02:00
|
|
|
$radio = $tpl->empty_cell('radio',$this->prefix.$name);
|
|
|
|
$radio['label'] = $val;
|
|
|
|
$radio['size'] = $key;
|
|
|
|
$tpl->add_child($input,$radio);
|
|
|
|
unset($radio);
|
2005-10-28 20:29:05 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'text' :
|
|
|
|
case 'textarea' :
|
|
|
|
default :
|
|
|
|
$field['len'] = $field['len'] ? $field['len'] : 20;
|
2005-11-08 15:33:16 +01:00
|
|
|
if($field['rows'] <= 1)
|
2005-10-28 20:29:05 +02:00
|
|
|
{
|
|
|
|
list($max,$shown) = explode(',',$field['len']);
|
|
|
|
$input = &$tpl->new_cell($n,'text','',$this->prefix.$name,array(
|
|
|
|
'size' => intval($shown > 0 ? $shown : $max).','.intval($max)
|
|
|
|
));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$input = &$tpl->new_cell($n,'textarea','',$this->prefix.$name,array(
|
2005-11-08 15:33:16 +01:00
|
|
|
'size' => $field['rows'].($field['len'] > 0 ? ','.(int)$field['len'] : '')
|
2005-10-28 20:29:05 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2005-11-08 15:33:16 +01:00
|
|
|
if ($readonly) $input['readonly'] = true;
|
2005-10-28 20:29:05 +02:00
|
|
|
|
|
|
|
if (!empty($field['help']) && $row_class != 'th')
|
|
|
|
{
|
|
|
|
$input['help'] = $field['help'];
|
|
|
|
$input['no_lang'] = substr(lang($help),-1) == '*' ? 2 : 0;
|
|
|
|
}
|
2005-11-08 15:33:16 +01:00
|
|
|
$tpl->set_row_attributes($n,0,$row_class,'top');
|
2005-10-28 20:29:05 +02:00
|
|
|
}
|
|
|
|
// create an empty line which (should) take all the remaining height
|
|
|
|
$tpl->new_cell(++$n,'label','','',array(
|
|
|
|
'span' => 'all'
|
|
|
|
));
|
|
|
|
$tpl->set_row_attributes($n,'99%','row');
|
|
|
|
|
|
|
|
// set width of 1. (label) column to 100
|
|
|
|
$tpl->set_column_attributes(0,'100');
|
|
|
|
|
|
|
|
$tpl->set_rows_cols(); // msie (at least 5.5 shows nothing with div overflow=auto)
|
|
|
|
$tpl->size = '100%,100%'.($tpl->html->user_agent != 'msie' ? ',,,,,auto' : '');
|
|
|
|
//echo '<pre style="text-align: left;">'; print_r($tpl); echo "</pre>\n";
|
|
|
|
|
|
|
|
if (count($tpl->data) < 2)
|
|
|
|
{
|
|
|
|
$cell['type'] = 'label';
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
$cell['size'] = ''; // no separate namespace
|
|
|
|
$cell['type'] = 'template';
|
|
|
|
$cell['name'] = $tpl->name;
|
|
|
|
$cell['obj'] = &$tpl;
|
|
|
|
|
|
|
|
return True; // extra Label is ok
|
|
|
|
}
|
|
|
|
}
|