2005-10-28 20:29:05 +02:00
|
|
|
<?php
|
2006-04-20 19:12:30 +02:00
|
|
|
/**
|
|
|
|
* eGroupWare eTemplate Widget for custom fields
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Cornelius Weiss <egw@von-und-zu-weiss.de>
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
2005-10-28 20:29:05 +02:00
|
|
|
|
|
|
|
/**
|
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,
|
|
|
|
);
|
2007-07-11 17:43:09 +02:00
|
|
|
var $human_name = array(
|
|
|
|
'customfields' => 'custom fields',
|
|
|
|
'customfields-types' => 'custom field types',
|
|
|
|
'customfields-list' => 'custom field list',
|
|
|
|
);
|
2005-10-28 20:29:05 +02:00
|
|
|
|
2007-07-11 17:43:09 +02:00
|
|
|
/**
|
|
|
|
* Allowd types of customfields
|
|
|
|
*
|
|
|
|
* The additionally allowed app-names from the link-class, will be add by the edit-method only,
|
|
|
|
* as the link-class has to be called, which can NOT be instanciated by the constructor, as
|
|
|
|
* we get a loop in the instanciation.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $cf_types = array(
|
|
|
|
'text' => 'Text',
|
|
|
|
'label' => 'Label',
|
|
|
|
'select' => 'Selectbox',
|
|
|
|
'radio' => 'Radiobutton',
|
|
|
|
'checkbox' => 'Checkbox',
|
|
|
|
'date' => 'Date',
|
|
|
|
'date-time'=> 'Date+Time',
|
|
|
|
'select-account' => 'Select account',
|
|
|
|
'link-entry' => 'Select entry', // should be last type, as the individual apps get added behind
|
|
|
|
);
|
|
|
|
|
2005-10-28 20:29:05 +02:00
|
|
|
/**
|
|
|
|
* @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';
|
2007-07-11 17:43:09 +02:00
|
|
|
$this->customfields = $config[$config_name] ? $config[$config_name] : array('test'=>array('type'=>'label'));
|
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)
|
|
|
|
{
|
2007-07-12 09:31:32 +02:00
|
|
|
$type2 = $cell['size'];
|
|
|
|
|
2007-07-11 17:43:09 +02:00
|
|
|
switch($type = $cell['type'])
|
|
|
|
{
|
|
|
|
case 'customfields-types':
|
|
|
|
$cell['type'] = 'select';
|
|
|
|
foreach($this->cf_types as $name => $label) $cell['sel_options'][$name] = lang($label);
|
|
|
|
$link_types = ExecMethod('phpgwapi.bolink.app_list','');
|
|
|
|
ksort($link_types);
|
|
|
|
foreach($link_types as $name => $label) $cell['sel_options'][$name] = '- '.$label;
|
|
|
|
$cell['no_lang'] = true;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case 'customfields-list':
|
|
|
|
foreach(array_reverse($this->customfields) as $name => $field)
|
|
|
|
{
|
2007-07-12 09:31:32 +02:00
|
|
|
if (!empty($field['type2']) && strpos(','.$field['type2'].',',','.$type2.',') === false) continue; // not for our content type
|
2007-07-11 17:43:09 +02:00
|
|
|
if (isset($value[$this->prefix.$name]) && $value[$this->prefix.$name] !== '') break;
|
|
|
|
$stop_at_field = $name;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$readonly = $cell['readonly'] || $readonlys[$name] || $type == 'customfields-list';
|
2005-11-08 15:33:16 +01:00
|
|
|
|
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;
|
|
|
|
}
|
2007-07-11 17:43:09 +02:00
|
|
|
// making the cell an empty grid
|
|
|
|
$cell['type'] = 'grid';
|
|
|
|
$cell['data'] = array(array());
|
|
|
|
$cell['rows'] = $cell['cols'] = 0;
|
2005-10-28 20:29:05 +02:00
|
|
|
|
2007-07-11 17:43:09 +02:00
|
|
|
$n = 1;
|
2005-10-28 20:29:05 +02:00
|
|
|
foreach($this->customfields as $name => $field)
|
|
|
|
{
|
2007-07-11 17:43:09 +02:00
|
|
|
if ($stop_at_field && $name == $stop_at_field) break; // no further row necessary
|
|
|
|
|
2006-11-23 14:52:56 +01:00
|
|
|
// check if the customfield get's displayed for type $value, we can have multiple comma-separated types now
|
2007-07-12 09:31:32 +02:00
|
|
|
if (!empty($field['type2']) && strpos(','.$field['type2'].',',','.$type2.',') === false)
|
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
|
|
|
}
|
2007-07-11 17:43:09 +02:00
|
|
|
$new_row = null; etemplate::add_child($cell,$new_row);
|
|
|
|
|
|
|
|
if ($type != 'customfields-list')
|
|
|
|
{
|
|
|
|
$row_class = 'row';
|
|
|
|
etemplate::add_child($cell,$label =& etemplate::empty_cell('label','',array(
|
|
|
|
'label' => $field['label'],
|
2007-07-12 10:03:37 +02:00
|
|
|
'no_lang' => substr(lang($field['label']),-1) == '*' ? 2 : 0,
|
|
|
|
'span' => $field['type'] === 'label' ? '2' : '',
|
2007-07-11 17:43:09 +02:00
|
|
|
)));
|
|
|
|
}
|
2006-10-04 19:10:05 +02:00
|
|
|
switch ((string)$field['type'])
|
2005-10-28 20:29:05 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2007-07-11 17:43:09 +02:00
|
|
|
$input =& etemplate::empty_cell('select',$this->prefix.$name,array(
|
|
|
|
'sel_options' => $field['values'],
|
|
|
|
'size' => $field['rows'],
|
|
|
|
'no_lang' => True
|
|
|
|
));
|
2005-11-10 13:10:17 +01:00
|
|
|
if($this->advanced_search)
|
|
|
|
{
|
2007-07-11 17:43:09 +02:00
|
|
|
$select =& $input; unset($input);
|
|
|
|
$input =& etemplate::empty_cell('hbox');
|
|
|
|
etemplate::add_child($input, $select); unset($select);
|
|
|
|
etemplate::add_child($input, etemplate::empty_cell('select',$this->prefix.$name,array(
|
|
|
|
'sel_options' => $field['values'],
|
|
|
|
'size' => $field['rows'],
|
2005-11-10 13:10:17 +01:00
|
|
|
'no_lang' => True
|
|
|
|
)));
|
|
|
|
}
|
2005-10-28 20:29:05 +02:00
|
|
|
break;
|
|
|
|
case 'label' :
|
|
|
|
$row_class = 'th';
|
|
|
|
break;
|
|
|
|
case 'checkbox' :
|
2007-07-11 17:43:09 +02:00
|
|
|
$input =& etemplate::empty_cell('checkbox',$this->prefix.$name);
|
2005-10-28 20:29:05 +02:00
|
|
|
break;
|
|
|
|
case 'radio' :
|
2007-07-11 17:43:09 +02:00
|
|
|
$input =& etemplate::empty_cell('groupbox');
|
2005-10-28 20:29:05 +02:00
|
|
|
$m = 0;
|
|
|
|
foreach ($field['values'] as $key => $val)
|
|
|
|
{
|
2007-07-16 18:55:48 +02:00
|
|
|
$radio = etemplate::empty_cell('radio',$this->prefix.$name);
|
2005-10-28 23:05:56 +02:00
|
|
|
$radio['label'] = $val;
|
|
|
|
$radio['size'] = $key;
|
2007-07-11 17:43:09 +02:00
|
|
|
etemplate::add_child($input,$radio);
|
2005-10-28 23:05:56 +02:00
|
|
|
unset($radio);
|
2005-10-28 20:29:05 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'text' :
|
|
|
|
case 'textarea' :
|
2006-10-04 19:10:05 +02:00
|
|
|
case '' : // not set
|
2005-10-28 20:29:05 +02:00
|
|
|
$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']);
|
2007-07-11 17:43:09 +02:00
|
|
|
$input =& etemplate::empty_cell('text',$this->prefix.$name,array(
|
2005-10-28 20:29:05 +02:00
|
|
|
'size' => intval($shown > 0 ? $shown : $max).','.intval($max)
|
|
|
|
));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-07-11 17:43:09 +02:00
|
|
|
$input =& etemplate::empty_cell('textarea',$this->prefix.$name,array(
|
2005-11-08 15:33:16 +01:00
|
|
|
'size' => $field['rows'].($field['len'] > 0 ? ','.(int)$field['len'] : '')
|
2006-10-04 19:10:05 +02:00
|
|
|
));
|
2005-10-28 20:29:05 +02:00
|
|
|
}
|
|
|
|
break;
|
2007-05-22 06:04:13 +02:00
|
|
|
case 'date':
|
|
|
|
case 'date-time':
|
2007-07-11 17:43:09 +02:00
|
|
|
$input =& etemplate::empty_cell($field['type'],$this->prefix.$name,array(
|
2007-05-22 06:04:13 +02:00
|
|
|
'size' => $field['len'] ? $field['len'] : ($field['type'] == 'date' ? 'Y-m-d' : 'Y-m-d H:i:s'),
|
|
|
|
));
|
|
|
|
break;
|
2007-07-11 17:43:09 +02:00
|
|
|
case 'select-account':
|
|
|
|
list($opts) = explode('=',$field['values'][0]);
|
|
|
|
$input =& etemplate::empty_cell('select-account',$this->prefix.$name,array(
|
|
|
|
'size' => ($field['rows']>1?$field['rows']:lang('None')).','.$opts,
|
|
|
|
));
|
|
|
|
break;
|
2006-10-04 19:10:05 +02:00
|
|
|
case 'link-entry':
|
|
|
|
default : // link-entry to given app
|
2007-07-11 17:43:09 +02:00
|
|
|
$input =& etemplate::empty_cell('link-entry',$this->prefix.$name,array(
|
2006-10-04 19:10:05 +02:00
|
|
|
'size' => $field['type'] == 'link-entry' ? '' : $field['type'],
|
|
|
|
));
|
2005-10-28 20:29:05 +02:00
|
|
|
}
|
2007-07-12 10:03:37 +02:00
|
|
|
$cell['data'][0]['c'.$n++] = $row_class.',top';
|
2005-10-28 20:29:05 +02:00
|
|
|
|
2007-07-12 10:03:37 +02:00
|
|
|
if (!is_null($input))
|
2005-10-28 20:29:05 +02:00
|
|
|
{
|
2007-07-12 10:03:37 +02:00
|
|
|
if ($readonly) $input['readonly'] = true;
|
|
|
|
|
|
|
|
if (!empty($field['help']) && $row_class != 'th')
|
|
|
|
{
|
|
|
|
$input['help'] = $field['help'];
|
|
|
|
$input['no_lang'] = substr(lang($help),-1) == '*' ? 2 : 0;
|
|
|
|
}
|
|
|
|
etemplate::add_child($cell,$input);
|
|
|
|
unset($input);
|
2005-10-28 20:29:05 +02:00
|
|
|
}
|
2007-07-11 17:43:09 +02:00
|
|
|
unset($label);
|
2005-10-28 20:29:05 +02:00
|
|
|
}
|
2007-07-11 17:43:09 +02:00
|
|
|
if ($type != 'customfields-list')
|
2005-10-28 20:29:05 +02:00
|
|
|
{
|
2007-07-11 17:43:09 +02:00
|
|
|
$cell['data'][0]['A'] = '100';
|
2005-10-28 20:29:05 +02:00
|
|
|
}
|
2007-07-11 17:43:09 +02:00
|
|
|
list($span,$class) = explode(',',$cell['span']); // msie (at least 5.5) shows nothing with div overflow=auto
|
2007-07-16 18:55:48 +02:00
|
|
|
$cell['size'] = '100%,100%,0,'.$class.','.($type=='customfields-list'?',0':',').($tmpl->html->user_agent != 'msie' ? ',auto' : '');
|
2005-10-28 20:29:05 +02:00
|
|
|
|
|
|
|
return True; // extra Label is ok
|
|
|
|
}
|
|
|
|
}
|