2005-10-28 20:29:05 +02:00
|
|
|
<?php
|
2008-06-22 10:51:38 +02:00
|
|
|
/**
|
2012-08-09 14:41:47 +02:00
|
|
|
* EGroupware eTemplate Widget for custom fields
|
2008-06-22 10:51:38 +02:00
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
|
|
|
* @author Cornelius Weiss <egw@von-und-zu-weiss.de>
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @subpackage extensions
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This widget generates a template for customfields based on definitions in egw_config table
|
|
|
|
*
|
2010-04-07 19:00:09 +02:00
|
|
|
* All widgets here have 2+ comma-separated options ($cell[size]):
|
2008-06-22 10:51:38 +02:00
|
|
|
* - sub-type to display only the cf's without subtype or with a matching one
|
|
|
|
* - use-private to display only (non-)private cf's (0=regular ones, 1=private ones, default both)
|
2011-05-18 12:23:39 +02:00
|
|
|
* - field-name to display only the named custom field(s). Use ! before to display all but given field(s).
|
2010-04-07 19:00:09 +02:00
|
|
|
* Additional fields can be added with a comma between them
|
2008-06-22 10:51:38 +02:00
|
|
|
*
|
|
|
|
* Private cf's the user has no right to see (neither him nor his memberships are mentioned) are never displayed.
|
|
|
|
*/
|
|
|
|
class customfields_widget
|
|
|
|
{
|
|
|
|
var $public_functions = array(
|
|
|
|
'pre_process' => True,
|
|
|
|
);
|
|
|
|
var $human_name = array(
|
|
|
|
'customfields' => 'custom fields',
|
|
|
|
'customfields-types' => 'custom field types',
|
|
|
|
'customfields-list' => 'custom field list',
|
|
|
|
'customfields-no-label' => 'custom fields without label',
|
|
|
|
);
|
|
|
|
|
2006-04-20 19:12:30 +02:00
|
|
|
/**
|
2008-06-22 10:51:38 +02:00
|
|
|
* Allowd types of customfields
|
2006-04-20 19:12:30 +02:00
|
|
|
*
|
2008-06-22 10:51:38 +02:00
|
|
|
* 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
|
2006-04-20 19:12:30 +02:00
|
|
|
*/
|
2008-06-22 10:51:38 +02:00
|
|
|
var $cf_types = array(
|
|
|
|
'text' => 'Text',
|
2011-03-29 00:43:39 +02:00
|
|
|
'float' => 'Float',
|
2008-06-22 10:51:38 +02:00
|
|
|
'label' => 'Label',
|
|
|
|
'select' => 'Selectbox',
|
Add AJAX Select widget as a field type for custom fields.
Select options can be provided using one of three different methods:
1. key=value pairs, one per line, as for a selectbox
2. @filename.php - The file must be in the egw root, and define an array named $options, that has key => value pairs
3. Define the options normally used for the AJAX Select widget (get_rows, get_title, id_field) and it will pull values from the database, as normal.
Other options (icon, filter, template, link) can be used regardless of the method used to get the values.
2010-01-12 23:35:51 +01:00
|
|
|
'ajax_select' => 'Search',
|
2008-06-22 10:51:38 +02:00
|
|
|
'radio' => 'Radiobutton',
|
|
|
|
'checkbox' => 'Checkbox',
|
|
|
|
'date' => 'Date',
|
|
|
|
'date-time'=> 'Date+Time',
|
|
|
|
'select-account' => 'Select account',
|
|
|
|
'button' => 'Button', // button to execute javascript
|
|
|
|
'url' => 'Url',
|
|
|
|
'url-email'=> 'EMail',
|
|
|
|
'url-phone'=> 'Phone number',
|
2011-08-17 18:34:09 +02:00
|
|
|
'htmlarea' => 'Formatted Text (HTML)',
|
2008-06-22 10:51:38 +02:00
|
|
|
'link-entry' => 'Select entry', // should be last type, as the individual apps get added behind
|
|
|
|
);
|
2005-10-28 20:29:05 +02:00
|
|
|
|
|
|
|
/**
|
2008-06-22 10:51:38 +02:00
|
|
|
* @var $prefix string Prefix for every custiomfield name returned in $content (# for general (admin) customfields)
|
|
|
|
*/
|
|
|
|
var $prefix = '#';
|
|
|
|
/**
|
|
|
|
* Current application
|
2005-10-28 20:29:05 +02:00
|
|
|
*
|
2008-06-22 10:51:38 +02:00
|
|
|
* @var string
|
2005-10-28 20:29:05 +02:00
|
|
|
*/
|
2008-06-22 10:51:38 +02:00
|
|
|
var $appname;
|
|
|
|
/**
|
|
|
|
* Instance of the config class for $appname
|
|
|
|
*
|
|
|
|
* @var config
|
|
|
|
*/
|
|
|
|
var $config;
|
|
|
|
/**
|
|
|
|
* Our customfields as name => data array
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $customfields;
|
|
|
|
var $types;
|
|
|
|
var $advanced_search;
|
2007-07-11 17:39:41 +02:00
|
|
|
|
2005-10-28 20:29:05 +02:00
|
|
|
|
2011-09-13 10:38:16 +02:00
|
|
|
function __construct($ui=null,$appname=null)
|
2008-06-22 10:51:38 +02:00
|
|
|
{
|
|
|
|
$this->appname = $appname ? $appname : $GLOBALS['egw_info']['flags']['currentapp'];
|
|
|
|
$this->customfields = config::get_customfields($this->appname);
|
|
|
|
$this->types = config::get_content_types($this->appname);
|
|
|
|
$this->advanced_search = $GLOBALS['egw_info']['etemplate']['advanced_search'];
|
|
|
|
}
|
2007-11-27 16:03:54 +01:00
|
|
|
|
2011-05-18 12:23:39 +02:00
|
|
|
/**
|
|
|
|
* pre-processing of the extension
|
|
|
|
*
|
|
|
|
* This function is called before the extension gets rendered
|
|
|
|
*
|
|
|
|
* @param string $form_name form-name of the control
|
|
|
|
* @param mixed &$value value / existing content, can be modified
|
|
|
|
* @param array &$cell array with the widget, can be modified for ui-independent widgets
|
|
|
|
* @param array &$readonlys names of widgets as key, to be made readonly
|
|
|
|
* @param mixed &$extension_data data the extension can store persisten between pre- and post-process
|
|
|
|
* @param etemplate &$tmpl reference to the template we belong too
|
|
|
|
* @return boolean true if extra label is allowed, false otherwise
|
|
|
|
*/
|
2012-03-27 17:45:31 +02:00
|
|
|
function pre_process($form_name,&$value,&$cell,&$readonlys,&$extension_data,$tmpl)
|
2008-06-22 10:51:38 +02:00
|
|
|
{
|
2009-08-20 16:11:10 +02:00
|
|
|
list($app) = explode('.',$tmpl->name);
|
2012-01-04 23:01:15 +01:00
|
|
|
|
|
|
|
// if we are in the etemplate editor or a different app, load the cf's from the app the tpl belongs to
|
|
|
|
if ($app && $app != 'stylite' && $app != $this->appname)
|
2005-10-28 20:29:05 +02:00
|
|
|
{
|
2011-06-28 22:47:35 +02:00
|
|
|
self::__construct(null,$app); // app changed
|
2005-10-28 20:29:05 +02:00
|
|
|
}
|
2012-01-04 23:01:15 +01:00
|
|
|
|
2010-04-07 19:00:09 +02:00
|
|
|
list($type2,$use_private,$field_names) = explode(',',$cell['size'],3);
|
2008-06-22 10:51:38 +02:00
|
|
|
$fields_with_vals=array();
|
|
|
|
|
2010-04-07 19:00:09 +02:00
|
|
|
// Filter fields
|
|
|
|
if($field_names)
|
|
|
|
{
|
|
|
|
if($field_names[0] == '!') {
|
|
|
|
$negate_field_filter = true;
|
|
|
|
$field_names = substr($field_names,1);
|
|
|
|
}
|
|
|
|
$field_filter = explode(',', $field_names);
|
|
|
|
}
|
|
|
|
|
2008-06-22 10:51:38 +02:00
|
|
|
$fields = $this->customfields;
|
2005-10-28 20:29:05 +02:00
|
|
|
|
2008-06-22 10:51:38 +02:00
|
|
|
foreach((array)$fields as $key => $field)
|
2005-10-28 20:29:05 +02:00
|
|
|
{
|
2010-04-07 19:00:09 +02:00
|
|
|
// remove private or non-private cf's, if only one kind should be displayed
|
2008-06-22 10:51:38 +02:00
|
|
|
if ((string)$use_private !== '' && (boolean)$field['private'] != (boolean)$use_private)
|
2007-11-22 21:08:58 +01:00
|
|
|
{
|
2008-06-22 10:51:38 +02:00
|
|
|
unset($fields[$key]);
|
2007-11-22 21:08:58 +01:00
|
|
|
}
|
2010-04-07 19:00:09 +02:00
|
|
|
|
|
|
|
// Remove filtered fields
|
2011-05-18 12:23:39 +02:00
|
|
|
if($field_filter && (!$negate_field_filter && !in_array($key, $field_filter) ||
|
2010-04-07 19:00:09 +02:00
|
|
|
$negate_field_filter && in_array($key, $field_filter)))
|
|
|
|
{
|
|
|
|
unset($fields[$key]);
|
|
|
|
}
|
2008-06-22 10:51:38 +02:00
|
|
|
}
|
|
|
|
// check if name refers to a single custom field --> show only that
|
2012-12-31 21:22:05 +01:00
|
|
|
if (($pos=@strpos($cell['name'],$this->prefix)) !== false && // allow the prefixed name to be an array index too
|
2008-06-22 10:51:38 +02:00
|
|
|
preg_match("/$this->prefix([^\]]+)/",$cell['name'],$matches) && isset($fields[$name=$matches[1]]))
|
|
|
|
{
|
|
|
|
$fields = array($name => $fields[$name]);
|
|
|
|
$value = array($this->prefix.$name => $value);
|
|
|
|
$singlefield = true;
|
2011-05-18 12:23:39 +02:00
|
|
|
$form_name = substr($form_name,0,-strlen("[$this->prefix$name]"));
|
2008-06-22 10:51:38 +02:00
|
|
|
}
|
|
|
|
switch($type = $cell['type'])
|
|
|
|
{
|
|
|
|
case 'customfields-types':
|
|
|
|
$cell['type'] = 'select';
|
|
|
|
foreach($this->cf_types as $lname => $label)
|
|
|
|
{
|
|
|
|
$cell['sel_options'][$lname] = lang($label);
|
|
|
|
$fields_with_vals[]=$lname;
|
|
|
|
}
|
2012-01-05 18:04:54 +01:00
|
|
|
$link_types = array_intersect(egw_link::app_list('query'),egw_link::app_list('title'));
|
2008-06-22 10:51:38 +02:00
|
|
|
ksort($link_types);
|
|
|
|
foreach($link_types as $lname => $label) $cell['sel_options'][$lname] = '- '.$label;
|
|
|
|
$cell['no_lang'] = true;
|
|
|
|
return true;
|
2007-07-12 09:30:20 +02:00
|
|
|
|
2008-06-22 10:51:38 +02:00
|
|
|
case 'customfields-list':
|
|
|
|
foreach(array_reverse($fields) as $lname => $field)
|
|
|
|
{
|
|
|
|
if (!empty($type2) && !empty($field['type2']) && strpos(','.$field['type2'].',',','.$type2.',') === false) continue; // not for our content type//
|
|
|
|
if (isset($value[$this->prefix.$lname]) && $value[$this->prefix.$lname] !== '') //break;
|
|
|
|
{
|
|
|
|
$fields_with_vals[]=$lname;
|
|
|
|
}
|
|
|
|
//$stop_at_field = $name;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
foreach(array_reverse($fields) as $lname => $field)
|
2008-01-19 06:36:20 +01:00
|
|
|
{
|
2008-06-22 10:51:38 +02:00
|
|
|
$fields_with_vals[]=$lname;
|
2008-01-19 06:36:20 +01:00
|
|
|
}
|
2008-06-22 10:51:38 +02:00
|
|
|
}
|
|
|
|
$readonly = $cell['readonly'] || $readonlys[$name] || $type == 'customfields-list';
|
|
|
|
|
|
|
|
if(!is_array($fields))
|
|
|
|
{
|
|
|
|
$cell['type'] = 'label';
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
// making the cell an empty grid
|
|
|
|
$cell['type'] = 'grid';
|
|
|
|
$cell['data'] = array(array());
|
|
|
|
$cell['rows'] = $cell['cols'] = 0;
|
2011-08-18 11:22:59 +02:00
|
|
|
$cell['size'] = '';
|
2008-06-22 10:51:38 +02:00
|
|
|
|
|
|
|
$n = 1;
|
|
|
|
foreach($fields as $lname => $field)
|
|
|
|
{
|
2009-07-18 17:35:42 +02:00
|
|
|
if (array_search($lname,$fields_with_vals) !== false)
|
2007-11-22 21:08:58 +01:00
|
|
|
{
|
2009-07-18 17:35:42 +02:00
|
|
|
if ($stop_at_field && $lname == $stop_at_field) break; // no further row necessary
|
|
|
|
|
|
|
|
// check if the customfield get's displayed for type $value, we can have multiple comma-separated types now
|
|
|
|
if (!empty($type2) && !empty($field['type2']) && strpos(','.$field['type2'].',',','.$type2.',') === false)
|
|
|
|
{
|
|
|
|
continue; // not for our content type
|
|
|
|
}
|
2012-03-27 17:45:31 +02:00
|
|
|
$new_row = null; boetemplate::add_child($cell,$new_row);
|
2009-07-18 17:35:42 +02:00
|
|
|
if ($type != 'customfields-list' && $type == 'customfields')
|
|
|
|
{
|
|
|
|
$row_class = 'row';
|
2012-03-27 17:45:31 +02:00
|
|
|
boetemplate::add_child($cell,$label =& boetemplate::empty_cell('label','',array(
|
2009-07-18 17:35:42 +02:00
|
|
|
'label' => $field['label'],
|
|
|
|
'no_lang' => substr(lang($field['label']),-1) == '*' ? 2 : 0,
|
|
|
|
'span' => $field['type'] === 'label' ? '2' : '',
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
elseif ($type == 'customfields-list')
|
|
|
|
{
|
|
|
|
if (isset($value[$this->prefix.$lname]) && $value[$this->prefix.$lname] !== '')
|
2009-04-29 16:29:57 +02:00
|
|
|
{
|
2009-07-18 17:35:42 +02:00
|
|
|
switch ((string)$field['type'])
|
|
|
|
{
|
|
|
|
case 'checkbox':
|
|
|
|
if ($value[$this->prefix.$lname]==0) break;
|
|
|
|
default:
|
2012-03-27 17:45:31 +02:00
|
|
|
boetemplate::add_child($cell,$input =& boetemplate::empty_cell('image','info.png',
|
2009-07-18 17:35:42 +02:00
|
|
|
array('label'=> $field['label'],'width'=>"16px")));
|
|
|
|
}
|
2009-04-29 16:29:57 +02:00
|
|
|
}
|
2008-06-22 10:51:38 +02:00
|
|
|
}
|
|
|
|
|
2009-07-18 17:35:42 +02:00
|
|
|
switch ((string)$field['type'])
|
|
|
|
{
|
|
|
|
case 'select' :
|
|
|
|
if (count($field['values']) == 1 && isset($field['values']['@']))
|
2007-11-27 16:03:54 +01:00
|
|
|
{
|
2009-07-18 17:35:42 +02:00
|
|
|
$field['values'] = $this->_get_options_from_file($field['values']['@']);
|
2007-11-27 16:03:54 +01:00
|
|
|
}
|
2009-07-18 17:35:42 +02:00
|
|
|
if($this->advanced_search && $field['rows'] <= 1) $field['values'][''] = lang('doesn\'t matter');
|
|
|
|
foreach($field['values'] as $key => $val)
|
|
|
|
{
|
|
|
|
if (substr($val = lang($val),-1) != '*')
|
|
|
|
{
|
|
|
|
$field['values'][$key] = $val;
|
|
|
|
}
|
|
|
|
}
|
2012-03-27 17:45:31 +02:00
|
|
|
$input =& boetemplate::empty_cell('select',$this->prefix.$lname,array(
|
2008-06-22 10:51:38 +02:00
|
|
|
'sel_options' => $field['values'],
|
|
|
|
'size' => $field['rows'],
|
2012-12-31 21:22:05 +01:00
|
|
|
'enhance' => $field['enhance'],
|
2009-07-18 17:35:42 +02:00
|
|
|
'no_lang' => True,
|
|
|
|
));
|
|
|
|
if($this->advanced_search)
|
|
|
|
{
|
|
|
|
$select =& $input; unset($input);
|
2012-03-27 17:45:31 +02:00
|
|
|
$input =& boetemplate::empty_cell('hbox');
|
|
|
|
boetemplate::add_child($input, $select); unset($select);
|
2009-07-18 17:35:42 +02:00
|
|
|
/* the following seem to double the select fields in advanced search.
|
2012-03-27 17:45:31 +02:00
|
|
|
boetemplate::add_child($input, boetemplate::empty_cell('select',$this->prefix.$lname,array(
|
2009-07-18 17:35:42 +02:00
|
|
|
'sel_options' => $field['values'],
|
|
|
|
'size' => $field['rows'],
|
|
|
|
'no_lang' => True
|
|
|
|
)));
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
break;
|
Add AJAX Select widget as a field type for custom fields.
Select options can be provided using one of three different methods:
1. key=value pairs, one per line, as for a selectbox
2. @filename.php - The file must be in the egw root, and define an array named $options, that has key => value pairs
3. Define the options normally used for the AJAX Select widget (get_rows, get_title, id_field) and it will pull values from the database, as normal.
Other options (icon, filter, template, link) can be used regardless of the method used to get the values.
2010-01-12 23:35:51 +01:00
|
|
|
case 'ajax_select' :
|
|
|
|
// Set some reasonable defaults for the widget
|
|
|
|
$options = array(
|
|
|
|
'get_title' => 'etemplate.ajax_select_widget.array_title',
|
|
|
|
'get_rows' => 'etemplate.ajax_select_widget.array_rows',
|
|
|
|
'id_field' => ajax_select_widget::ARRAY_KEY,
|
|
|
|
);
|
|
|
|
if($field['rows']) {
|
|
|
|
$options['num_rows'] = $field['rows'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// If you specify an option known to the AJAX Select widget, it will be pulled from the list of values
|
|
|
|
// and used as such. All unknown values will be used for selection, not passed through to the query
|
|
|
|
if (isset($field['values']['@']))
|
|
|
|
{
|
|
|
|
$options['values'] = $this->_get_options_from_file($field['values']['@']);
|
|
|
|
unset($field['values']['@']);
|
|
|
|
} else {
|
|
|
|
$options['values'] = array_diff_key($field['values'], array_flip(ajax_select_widget::$known_options));
|
|
|
|
}
|
|
|
|
$options = array_merge($options, array_intersect_key($field['values'], array_flip(ajax_select_widget::$known_options)));
|
|
|
|
|
2012-03-27 17:45:31 +02:00
|
|
|
$input =& boetemplate::empty_cell('ajax_select', $this->prefix.$lname, array(
|
Add AJAX Select widget as a field type for custom fields.
Select options can be provided using one of three different methods:
1. key=value pairs, one per line, as for a selectbox
2. @filename.php - The file must be in the egw root, and define an array named $options, that has key => value pairs
3. Define the options normally used for the AJAX Select widget (get_rows, get_title, id_field) and it will pull values from the database, as normal.
Other options (icon, filter, template, link) can be used regardless of the method used to get the values.
2010-01-12 23:35:51 +01:00
|
|
|
'readonly' => $readonly,
|
|
|
|
'no_lang' => True,
|
|
|
|
'size' => $options
|
|
|
|
));
|
|
|
|
break;
|
2009-07-18 17:35:42 +02:00
|
|
|
case 'label' :
|
|
|
|
$row_class = 'th';
|
|
|
|
break;
|
|
|
|
case 'radio' :
|
|
|
|
$showthis = '#a#l#l#';
|
|
|
|
if (count($field['values']) == 1 && isset($field['values']['@']))
|
|
|
|
{
|
|
|
|
$field['values'] = $this->_get_options_from_file($field['values']['@']);
|
|
|
|
}
|
|
|
|
if($this->advanced_search && $field['rows'] <= 1) $field['values'][''] = lang('doesn\'t matter');
|
|
|
|
if ($readonly)
|
|
|
|
{
|
|
|
|
$showthis = $value[$this->prefix.$lname];
|
2012-03-27 17:45:31 +02:00
|
|
|
$input =& boetemplate::empty_cell('hbox');
|
2009-07-18 17:35:42 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-27 17:45:31 +02:00
|
|
|
$input =& boetemplate::empty_cell('groupbox');
|
2009-07-18 17:35:42 +02:00
|
|
|
}
|
|
|
|
$m = 0;
|
|
|
|
foreach ($field['values'] as $key => $val)
|
|
|
|
{
|
2012-03-27 17:45:31 +02:00
|
|
|
$radio = boetemplate::empty_cell('radio',$this->prefix.$lname);
|
2009-07-18 17:35:42 +02:00
|
|
|
$radio['label'] = $val;
|
|
|
|
$radio['size'] = $key;
|
2012-03-27 17:45:31 +02:00
|
|
|
if ($showthis == '#a#l#l#' || $showthis == $key) boetemplate::add_child($input,$radio);
|
2009-07-18 17:35:42 +02:00
|
|
|
unset($radio);
|
|
|
|
}
|
|
|
|
break;
|
2011-03-29 00:43:39 +02:00
|
|
|
case 'float':
|
|
|
|
$known_options = array('min'=>null, 'max'=>null,'size' => $field['len'], 'precision' => null);
|
|
|
|
$options = array_merge($known_options, $field['values']);
|
2012-03-27 17:45:31 +02:00
|
|
|
$input =& boetemplate::empty_cell($field['type'],$this->prefix.$lname,array(
|
2011-03-29 00:43:39 +02:00
|
|
|
'size' => implode(',',$options)
|
|
|
|
));
|
|
|
|
break;
|
2009-07-18 17:35:42 +02:00
|
|
|
case 'text' :
|
|
|
|
case 'textarea' :
|
|
|
|
case '' : // not set
|
|
|
|
$field['len'] = $field['len'] ? $field['len'] : 20;
|
|
|
|
if ($type != 'customfields-list')
|
|
|
|
{
|
|
|
|
if($field['rows'] <= 1)
|
|
|
|
{//text
|
|
|
|
list($max,$shown) = explode(',',$field['len']);
|
|
|
|
$tmparray=array(
|
|
|
|
'size' => intval($shown > 0 ? $shown : $max).','.intval($max),
|
|
|
|
'maxlength'=>intval($max),
|
2010-10-04 13:50:37 +02:00
|
|
|
'no_lang' => True,
|
2009-07-18 17:35:42 +02:00
|
|
|
);
|
|
|
|
if (is_array($field['values']))
|
|
|
|
{
|
|
|
|
if (array_key_exists('readonly',$field['values']))
|
|
|
|
{
|
|
|
|
if(!$this->advanced_search) $tmparray['readonly']='readonly';
|
|
|
|
}
|
|
|
|
}
|
2012-03-27 17:45:31 +02:00
|
|
|
$input =& boetemplate::empty_cell('text',$this->prefix.$lname,$tmparray);
|
2009-07-18 17:35:42 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{//textarea
|
|
|
|
$tmparray=array(
|
2010-10-04 13:50:37 +02:00
|
|
|
'size' => $field['rows'].($field['len'] >0 ? ','.(int)$field['len'] : ''),
|
|
|
|
'no_lang' => True,
|
2009-07-18 17:35:42 +02:00
|
|
|
);
|
|
|
|
if (is_array($field['values']) && array_key_exists('readonly',$field['values']))
|
2007-11-27 16:03:54 +01:00
|
|
|
{
|
2009-04-01 10:22:01 +02:00
|
|
|
if(!$this->advanced_search) $tmparray['readonly']='readonly';
|
2007-11-27 16:03:54 +01:00
|
|
|
}
|
2012-03-27 17:45:31 +02:00
|
|
|
$input =& boetemplate::empty_cell('textarea',$this->prefix.$lname,$tmparray);
|
2007-11-27 16:03:54 +01:00
|
|
|
}
|
2005-10-28 20:29:05 +02:00
|
|
|
}
|
2008-06-22 10:51:38 +02:00
|
|
|
else
|
|
|
|
{
|
2012-03-27 17:45:31 +02:00
|
|
|
$input =& boetemplate::empty_cell('label',$this->prefix.$lname,array('no_lang' => True));
|
2008-06-22 10:51:38 +02:00
|
|
|
}
|
2009-07-18 17:35:42 +02:00
|
|
|
break;
|
|
|
|
case 'date':
|
|
|
|
case 'date-time':
|
2012-03-27 17:45:31 +02:00
|
|
|
$input =& boetemplate::empty_cell($field['type'],$this->prefix.$lname,array(
|
2009-07-18 17:35:42 +02:00
|
|
|
'size' => $field['len'] ? $field['len'] : ($field['type'] == 'date' ? 'Y-m-d' : 'Y-m-d H:i:s'),
|
|
|
|
));
|
|
|
|
break;
|
|
|
|
case 'select-account':
|
|
|
|
list($opts) = explode('=',$field['values'][0]);
|
2012-03-27 17:45:31 +02:00
|
|
|
$input =& boetemplate::empty_cell('select-account',$this->prefix.$lname,array(
|
2009-07-18 17:35:42 +02:00
|
|
|
'size' => ($field['rows']>1?$field['rows']:lang('None')).','.$opts,
|
|
|
|
));
|
|
|
|
break;
|
|
|
|
case 'button': // button(s) to execute javascript (label=onclick) or textinputs (empty label, readonly with neg. length)
|
|
|
|
// a button does not seem to be helpful in advanced search ???,
|
|
|
|
if($this->advanced_search) break;
|
2012-03-27 17:45:31 +02:00
|
|
|
$input =& boetemplate::empty_cell('hbox');
|
2009-07-18 17:35:42 +02:00
|
|
|
foreach($field['values'] as $label => $js)
|
2008-06-22 10:51:38 +02:00
|
|
|
{
|
2009-07-18 17:35:42 +02:00
|
|
|
if (!$label) // display an readonly input
|
|
|
|
{
|
|
|
|
$tmparray = array(
|
|
|
|
'size' => $field['len'] ? $field['len'] : 20,
|
|
|
|
'readonly' => $field['len'] < 0,
|
|
|
|
'onchange' => $js,
|
|
|
|
);
|
2012-03-27 17:45:31 +02:00
|
|
|
$widget =& boetemplate::empty_cell('text',$this->prefix.$lname.$label,$tmparray);
|
2009-07-18 17:35:42 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ($readonly) continue; // dont display buttons if we're readonly
|
2012-03-27 17:45:31 +02:00
|
|
|
$widget =& boetemplate::empty_cell('buttononly',$this->prefix.$lname.$label,array(
|
2009-07-18 17:35:42 +02:00
|
|
|
'label' => $label ? $label : lang('Submit'),
|
|
|
|
'onclick' => $js,
|
|
|
|
'no_lang' => True
|
|
|
|
));
|
|
|
|
}
|
2012-03-27 17:45:31 +02:00
|
|
|
boetemplate::add_child($input,$widget);
|
2009-07-18 17:35:42 +02:00
|
|
|
unset($widget);
|
2008-06-22 10:51:38 +02:00
|
|
|
}
|
2009-07-18 17:35:42 +02:00
|
|
|
break;
|
|
|
|
case 'url-email':
|
|
|
|
list($max,$shown,$validation_type,$default) = explode(',',$field['len'],4);
|
|
|
|
if (empty($max)) $max =128;
|
|
|
|
if (empty($shown)) $shown = 28;
|
|
|
|
if (empty($validation_type)) $validation_type = 1;
|
|
|
|
$field['len'] = implode(',',array($shown, $max, $validation_type, $default));
|
2012-03-27 17:45:31 +02:00
|
|
|
$input =& boetemplate::empty_cell($field['type'],$this->prefix.$lname,array(
|
2009-07-18 17:35:42 +02:00
|
|
|
'size' => $field['len']
|
|
|
|
));
|
|
|
|
break;
|
|
|
|
case 'url':
|
|
|
|
case 'url-phone':
|
|
|
|
list($max,$shown,$validation_type) = explode(',',$field['len'],3);
|
|
|
|
if (empty($max)) $max =128;
|
|
|
|
if (empty($shown)) $shown = 28;
|
|
|
|
$field['len']=implode(',',array( $shown, $max, $validation_type));
|
2012-03-27 17:45:31 +02:00
|
|
|
$input =& boetemplate::empty_cell($field['type'],$this->prefix.$lname,array(
|
2009-07-18 17:35:42 +02:00
|
|
|
'size' => $field['len']
|
|
|
|
));
|
|
|
|
break;
|
2011-08-17 18:34:09 +02:00
|
|
|
case 'htmlarea': // defaults: len: width=100%,mode=simple,tooldbar=false; rows: 5
|
|
|
|
list($width,$mode,$toolbar) = explode(',',$field['len']);
|
2012-03-27 17:45:31 +02:00
|
|
|
$input =& boetemplate::empty_cell($field['type'],$this->prefix.$lname,array(
|
2011-08-17 18:34:09 +02:00
|
|
|
'size' => $mode.','.(($field['rows'] ? $field['rows'] : 5)*16).'px,'.$width.','.($toolbar=='true'?'true':'false'),
|
|
|
|
));
|
|
|
|
break;
|
2009-07-18 17:35:42 +02:00
|
|
|
// other etemplate types, which are used just as is
|
|
|
|
case 'checkbox' :
|
2012-03-27 17:45:31 +02:00
|
|
|
$input =& boetemplate::empty_cell($field['type'],$this->prefix.$lname);
|
2009-07-18 17:35:42 +02:00
|
|
|
break;
|
|
|
|
case 'link-entry':
|
|
|
|
default : // link-entry to given app
|
2012-03-27 17:45:31 +02:00
|
|
|
$input =& boetemplate::empty_cell('link-entry',$this->prefix.$lname,array(
|
2009-07-18 17:35:42 +02:00
|
|
|
'size' => $field['type'] == 'link-entry' ? '' : $field['type'],
|
|
|
|
));
|
2011-05-18 12:23:39 +02:00
|
|
|
// register post-processing of link widget to get eg. needed/required validation
|
2014-03-23 10:34:18 +01:00
|
|
|
etemplate::$request->set_to_process(etemplate::form_name($form_name,$this->prefix.$lname), 'ext-link');
|
2009-07-18 17:35:42 +02:00
|
|
|
}
|
|
|
|
$cell['data'][0]['c'.$n++] = $row_class.',top';
|
2008-06-22 10:51:38 +02:00
|
|
|
|
2009-07-18 17:35:42 +02:00
|
|
|
if (!is_null($input))
|
|
|
|
{
|
|
|
|
if ($readonly) $input['readonly'] = true;
|
2005-10-28 20:29:05 +02:00
|
|
|
|
2011-05-18 12:23:39 +02:00
|
|
|
$input['needed'] = $cell['needed'] || $field['needed'];
|
2007-11-27 16:03:54 +01:00
|
|
|
|
2009-07-18 17:35:42 +02:00
|
|
|
if (!empty($field['help']) && $row_class != 'th')
|
|
|
|
{
|
|
|
|
$input['help'] = $field['help'];
|
|
|
|
$input['no_lang'] = substr(lang($help),-1) == '*' ? 2 : 0;
|
|
|
|
}
|
|
|
|
if ($singlefield) // a single field, can & need to be returned instead of the cell (no grid)
|
|
|
|
{
|
2010-08-05 17:36:23 +02:00
|
|
|
$input['span'] = $cell['span']; // set span & class from original cell
|
2009-07-18 17:35:42 +02:00
|
|
|
$cell = $input;
|
|
|
|
if ($type == 'customfields') $cell['label'] = $field['label'];
|
2010-06-28 16:09:59 +02:00
|
|
|
$value = $value[$this->prefix.$lname];
|
2009-07-18 17:35:42 +02:00
|
|
|
return true;
|
|
|
|
}
|
2012-03-27 17:45:31 +02:00
|
|
|
boetemplate::add_child($cell,$input);
|
2009-07-18 17:35:42 +02:00
|
|
|
unset($input);
|
2008-06-22 10:51:38 +02:00
|
|
|
}
|
2009-07-18 17:35:42 +02:00
|
|
|
unset($label);
|
2007-09-13 14:43:58 +02:00
|
|
|
}
|
2008-06-22 10:51:38 +02:00
|
|
|
}
|
|
|
|
if ($type != 'customfields-list')
|
|
|
|
{
|
|
|
|
$cell['data'][0]['A'] = '100';
|
|
|
|
}
|
|
|
|
list($span,$class) = explode(',',$cell['span']); // msie (at least 5.5) shows nothing with div overflow=auto
|
|
|
|
// we dont want to use up the full space for the table created, so we skip the line below
|
|
|
|
//$cell['size'] = '100%,100%,0,'.$class.','.(in_array($type,array('customfields-list','customfields-no-label'))?'0,0':',').(html::$user_agent != 'msie' ? ',auto' : '');
|
|
|
|
|
|
|
|
return True; // extra Label is ok
|
|
|
|
}
|
2007-11-27 16:03:54 +01:00
|
|
|
|
2008-06-22 10:51:38 +02:00
|
|
|
/**
|
|
|
|
* Read the options of a 'select' or 'radio' custom field from a file
|
|
|
|
*
|
|
|
|
* For security reasons that file has to be relative to the eGW root
|
|
|
|
* (to not use that feature to explore arbitrary files on the server)
|
|
|
|
* and it has to be a php file setting one variable called options,
|
|
|
|
* (to not display it to anonymously by the webserver).
|
|
|
|
* The $options var has to be an array with value => label pairs, eg:
|
|
|
|
*
|
|
|
|
* <?php
|
|
|
|
* $options = array(
|
|
|
|
* 'a' => 'Option A',
|
|
|
|
* 'b' => 'Option B',
|
|
|
|
* 'c' => 'Option C',
|
|
|
|
* );
|
|
|
|
*
|
|
|
|
* @param string $file file name inside the eGW server root, either relative to it or absolute
|
|
|
|
* @return array in case of an error we return a single option with the message
|
|
|
|
*/
|
2012-08-09 14:41:47 +02:00
|
|
|
public static function _get_options_from_file($file)
|
2008-06-22 10:51:38 +02:00
|
|
|
{
|
|
|
|
if (!($path = realpath($file{0} == '/' ? $file : EGW_SERVER_ROOT.'/'.$file)) || // file does not exist
|
|
|
|
substr($path,0,strlen(EGW_SERVER_ROOT)+1) != EGW_SERVER_ROOT.'/' || // we are NOT inside the eGW root
|
|
|
|
basename($path,'.php').'.php' != basename($path) || // extension is NOT .php
|
|
|
|
basename($path) == 'header.inc.php') // dont allow to include our header again
|
|
|
|
{
|
|
|
|
return array(lang("'%1' is no php file in the eGW server root (%2)!".': '.$path,$file,EGW_SERVER_ROOT));
|
2007-09-13 14:43:58 +02:00
|
|
|
}
|
2008-06-22 10:51:38 +02:00
|
|
|
include($path);
|
|
|
|
|
|
|
|
return $options;
|
2005-10-28 20:29:05 +02:00
|
|
|
}
|
2008-09-11 16:57:20 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the customfield types containing links
|
|
|
|
*
|
|
|
|
* @return array with customefield types as values
|
|
|
|
*/
|
|
|
|
public static function get_customfield_link_types()
|
|
|
|
{
|
|
|
|
static $link_types;
|
|
|
|
|
|
|
|
if (is_null($link_types))
|
|
|
|
{
|
2012-01-06 11:11:16 +01:00
|
|
|
$link_types = array_keys(array_intersect(egw_link::app_list('query'),egw_link::app_list('title')));
|
2008-09-11 16:57:20 +02:00
|
|
|
$link_types[] = 'link-entry';
|
|
|
|
}
|
|
|
|
return $link_types;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if there are links in the custom fields and update them
|
|
|
|
*
|
|
|
|
* This function have to be called manually by an application, if cf's linking
|
|
|
|
* to other entries should be stored as links too (beside as cf's).
|
|
|
|
*
|
|
|
|
* @param string $own_app own appname
|
|
|
|
* @param array $values new values including the custom fields
|
|
|
|
* @param array $old=null old values before the update, if existing
|
|
|
|
* @param string $id_name='id' name/key of the (link-)id in $values
|
|
|
|
*/
|
|
|
|
public static function update_customfield_links($own_app,array $values,array $old=null,$id_name='id')
|
|
|
|
{
|
|
|
|
$link_types = self::get_customfield_link_types();
|
|
|
|
|
|
|
|
foreach(config::get_customfields($own_app) as $name => $data)
|
|
|
|
{
|
|
|
|
if (!in_array($data['type'],$link_types)) continue;
|
|
|
|
|
|
|
|
// do we have a different old value --> delete that link
|
|
|
|
if ($old && $old['#'.$name] && $old['#'.$name] != $values['#'.$name])
|
|
|
|
{
|
|
|
|
if ($data['type'] == 'link-entry')
|
|
|
|
{
|
|
|
|
list($app,$id) = explode(':',$old['#'.$name]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$app = $data['type'];
|
|
|
|
$id = $old['#'.$name];
|
|
|
|
}
|
|
|
|
egw_link::unlink(false,$own_app,$values[$id_name],'',$app,$id);
|
|
|
|
}
|
|
|
|
if ($data['type'] == 'link-entry')
|
|
|
|
{
|
|
|
|
list($app,$id) = explode(':',$values['#'.$name]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$app = $data['type'];
|
|
|
|
$id = $values['#'.$name];
|
|
|
|
}
|
|
|
|
if ($id) // create new link, does nothing for already existing links
|
|
|
|
{
|
|
|
|
egw_link::link($own_app,$values[$id_name],$app,$id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-09 14:41:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Non printable custom fields eg. UI elements
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public static $non_printable_fields = array('button');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format a single custom field value as string
|
|
|
|
*
|
|
|
|
* @param array $field field defintion incl. type
|
|
|
|
* @param string $value field value
|
|
|
|
* @return string formatted value
|
|
|
|
*/
|
|
|
|
public static function format_customfield(array $field, $value)
|
|
|
|
{
|
|
|
|
switch($field['type'])
|
|
|
|
{
|
|
|
|
case 'select-account':
|
|
|
|
if ($value)
|
|
|
|
{
|
|
|
|
$values = array();
|
|
|
|
foreach($field['rows'] > 1 ? explode(',', $value) : (array) $value as $value)
|
|
|
|
{
|
|
|
|
$values[] = common::grab_owner_name($value);
|
|
|
|
}
|
|
|
|
$value = implode(', ',$values);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'checkbox':
|
|
|
|
$value = $value ? 'X' : '';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'select':
|
|
|
|
case 'radio':
|
|
|
|
if (count($field['values']) == 1 && isset($field['values']['@']))
|
|
|
|
{
|
|
|
|
$field['values'] = customfields_widget::_get_options_from_file($field['values']['@']);
|
|
|
|
}
|
|
|
|
$values = array();
|
|
|
|
foreach($field['rows'] > 1 ? explode(',', $value) : (array) $value as $value)
|
|
|
|
{
|
|
|
|
$values[] = isset($field['values'][$value]) ? $field['values'][$value] : '#'.$value;
|
|
|
|
}
|
|
|
|
$value = implode(', ', $values);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'date':
|
|
|
|
case 'date-time':
|
|
|
|
if ($value)
|
|
|
|
{
|
|
|
|
$format = $field['len'] ? $field['len'] : ($field['type'] == 'date' ? 'Y-m-d' : 'Y-m-d H:i:s');
|
|
|
|
$date = array_combine(preg_split('/[\\/. :-]/',$format), preg_split('/[\\/. :-]/',$value));
|
|
|
|
$value = common::dateformatorder($date['Y'], $date['m'], $date['d'],true);
|
|
|
|
if (isset($date['H'])) $value .= ' '.common::formattime($date['H'], $date['i']);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'htmlarea': // ToDo: EMail probably has a nicer html2text method
|
|
|
|
if ($value) $value = strip_tags(preg_replace('/<(br|p)[^>]*>/i', "\r\n", str_replace(array("\r", "\n"), '', $value)));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'ajax_select': // ToDo: returns unchanged value for now
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// handling for several link types
|
|
|
|
if ($value && in_array($field['type'], self::get_customfield_link_types()))
|
|
|
|
{
|
|
|
|
if ($field['type'] == 'link-entry' || strpos($value, ':') !== false)
|
|
|
|
{
|
|
|
|
list($app, $value) = explode(':', $value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$app = $field['type'];
|
|
|
|
}
|
|
|
|
if ($value) $value = egw_link::title($app, $value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return $value;
|
|
|
|
}
|
2008-06-22 10:51:38 +02:00
|
|
|
}
|