2005-10-28 20:27:06 +02:00
|
|
|
<?php
|
2009-04-23 13:18:51 +02:00
|
|
|
/**
|
|
|
|
* eGgroupWare admin - UI for adding custom fields
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
|
|
|
* @author Cornelius Weiss <nelius-AT-von-und-zu-weiss.de>
|
|
|
|
* @package admin
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
2005-10-28 20:27:06 +02:00
|
|
|
|
2009-04-23 13:18:51 +02:00
|
|
|
/**
|
2014-10-23 19:33:03 +02:00
|
|
|
* Customfields class - manages customfield definitions in egw_config table
|
|
|
|
*
|
|
|
|
* The repository name (config_name) is 'customfields'.
|
|
|
|
*
|
|
|
|
* Applications can have customfields by sub-type by having a template
|
|
|
|
* named '<appname>.admin.types'. See admin.customfields.types as an
|
|
|
|
* example, but the template can even be empty if types are handled by the
|
|
|
|
* application in another way.
|
|
|
|
*
|
|
|
|
* Applications can extend this class to customize the custom fields and handle
|
|
|
|
* extra information from the above template by extending and implementing
|
|
|
|
* update() and app_index().
|
|
|
|
*/
|
2009-04-23 13:18:51 +02:00
|
|
|
class customfields
|
|
|
|
{
|
2005-10-28 20:27:06 +02:00
|
|
|
|
|
|
|
/**
|
2009-04-23 13:18:51 +02:00
|
|
|
* appname of app which want to add / edit its customfields
|
2005-10-28 20:27:06 +02:00
|
|
|
*
|
2009-04-23 13:18:51 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $appname;
|
|
|
|
|
2014-10-22 21:55:27 +02:00
|
|
|
/**
|
|
|
|
* Allow custom fields to be restricted to certain users/groups
|
|
|
|
*/
|
|
|
|
protected $use_private = false;
|
|
|
|
|
2009-04-23 13:18:51 +02:00
|
|
|
/**
|
|
|
|
* userdefiened types e.g. type of infolog
|
2005-11-08 14:51:43 +01:00
|
|
|
*
|
2009-04-23 13:18:51 +02:00
|
|
|
* @var array
|
2005-10-28 20:27:06 +02:00
|
|
|
*/
|
2009-04-23 13:18:51 +02:00
|
|
|
var $types2 = array();
|
|
|
|
var $content_types,$fields;
|
2005-10-28 20:27:06 +02:00
|
|
|
|
2014-10-23 19:33:03 +02:00
|
|
|
/**
|
|
|
|
* Currently selected content type (if used by app)
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $content_type = null;
|
|
|
|
|
2009-04-23 13:18:51 +02:00
|
|
|
var $public_functions = array(
|
2014-10-22 21:55:27 +02:00
|
|
|
'index' => true,
|
2009-04-23 13:18:51 +02:00
|
|
|
'edit' => True
|
|
|
|
);
|
|
|
|
/**
|
|
|
|
* Instance of etemplate class
|
|
|
|
*
|
|
|
|
* @var etemplate
|
|
|
|
*/
|
|
|
|
var $tmpl;
|
2008-01-19 06:32:51 +01:00
|
|
|
|
2014-11-24 22:58:07 +01:00
|
|
|
/**
|
|
|
|
* @var Description of the options or value format for each cf_type
|
|
|
|
*/
|
|
|
|
public static $type_option_help = array(
|
2014-12-10 15:34:48 +01:00
|
|
|
'select' => 'each value is a line like id[=label], or use @path to read options from a file in EGroupware directory',
|
|
|
|
'radio' => 'each value is a line like id[=label], or use @path to read options from a file in EGroupware directory',
|
2014-11-24 22:58:07 +01:00
|
|
|
'button' => 'each value is a line like label=[javascript]'
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Custom fields can also have length and rows set, but these are't used for all types
|
|
|
|
* If not set to true here, the field will be disabled when selecting the type
|
|
|
|
*/
|
|
|
|
public static $type_attribute_flags = array(
|
|
|
|
'text' => array('cf_len' => true, 'cf_rows' => true),
|
2014-12-08 23:13:25 +01:00
|
|
|
'float' => array('cf_len' => true),
|
2014-11-27 17:58:11 +01:00
|
|
|
'label' => array('cf_values' => true),
|
|
|
|
'select' => array('cf_len' => false, 'cf_rows' => true, 'cf_values' => true),
|
2015-04-21 21:46:33 +02:00
|
|
|
'date' => array('cf_len' => true, 'cf_rows' => false, 'cf_values' => true),
|
|
|
|
'date-time' => array('cf_len' => true, 'cf_rows' => false, 'cf_values' => true),
|
2014-11-24 22:58:07 +01:00
|
|
|
'select-account' => array('cf_len' => false, 'cf_rows' => true),
|
|
|
|
'htmlarea' => array('cf_len' => true, 'cf_rows' => true),
|
2014-11-27 17:58:11 +01:00
|
|
|
'button' => array('cf_values' => true),
|
|
|
|
'ajax_select' => array('cf_values' => true),
|
|
|
|
'radio' => array('cf_values' => true),
|
|
|
|
'checkbox' => array('cf_values' => true),
|
2014-11-24 22:58:07 +01:00
|
|
|
);
|
|
|
|
|
2009-04-23 13:18:51 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param string $appname
|
|
|
|
*/
|
|
|
|
function __construct($appname='')
|
|
|
|
{
|
|
|
|
if (($this->appname = $appname))
|
|
|
|
{
|
2014-06-23 16:35:22 +02:00
|
|
|
$this->fields = egw_customfields::get($this->appname,true);
|
2009-04-23 13:18:51 +02:00
|
|
|
$this->content_types = config::get_content_types($this->appname);
|
2005-10-28 20:27:06 +02:00
|
|
|
}
|
2014-10-22 21:55:27 +02:00
|
|
|
$this->so = new so_sql('phpgwapi','egw_customfields',null,'',true);
|
2009-04-23 13:18:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-10-22 21:55:27 +02:00
|
|
|
* List custom fields
|
2009-04-23 13:18:51 +02:00
|
|
|
*/
|
2014-10-22 21:55:27 +02:00
|
|
|
public function index($content = array())
|
2009-04-23 13:18:51 +02:00
|
|
|
{
|
|
|
|
// determine appname
|
2014-10-23 19:33:03 +02:00
|
|
|
$this->appname = $this->appname ? $this->appname : ($_GET['appname'] ? $_GET['appname'] : ($content['appname'] ? $content['appname'] : false));
|
2009-04-23 13:18:51 +02:00
|
|
|
if(!$this->appname) die(lang('Error! No appname found'));
|
2005-10-28 20:27:06 +02:00
|
|
|
|
2014-10-22 21:55:27 +02:00
|
|
|
$this->use_private = !isset($_GET['use_private']) || (boolean)$_GET['use_private'] || $content['use_private'];
|
|
|
|
|
|
|
|
// Read fields, constructor doesn't always know appname
|
2014-06-23 16:35:22 +02:00
|
|
|
$this->fields = egw_customfields::get($this->appname,true);
|
2014-10-22 21:55:27 +02:00
|
|
|
|
|
|
|
$this->tmpl = new etemplate_new();
|
2009-04-23 13:18:51 +02:00
|
|
|
$this->tmpl->read('admin.customfields');
|
|
|
|
|
2014-10-22 21:55:27 +02:00
|
|
|
// do we manage content-types?
|
|
|
|
$test = new etemplate_new();
|
|
|
|
if($test->read($this->appname.'.admin.types')) $this->manage_content_types = true;
|
|
|
|
|
2014-10-23 19:33:03 +02:00
|
|
|
// Handle incoming - types, options, etc.
|
2011-05-18 12:25:39 +02:00
|
|
|
if($this->manage_content_types)
|
2010-02-10 15:27:14 +01:00
|
|
|
{
|
2014-10-23 19:33:03 +02:00
|
|
|
if(count($this->content_types) == 0)
|
|
|
|
{
|
|
|
|
$this->content_types = config::get_content_types($this->appname);
|
|
|
|
}
|
2011-05-18 12:25:39 +02:00
|
|
|
if (count($this->content_types)==0)
|
2010-02-10 15:27:14 +01:00
|
|
|
{
|
|
|
|
// if you define your default types of your app with the search_link hook, they are available here, if no types were found
|
|
|
|
$this->content_types = (array)egw_link::get_registry($this->appname,'default_types');
|
|
|
|
}
|
2014-10-23 19:33:03 +02:00
|
|
|
// Set this now, we need to know it for updates
|
2014-11-19 22:15:48 +01:00
|
|
|
$this->content_type = $content['content_types']['types'] ? $content['content_types']['types'] : (array_key_exists(0,$this->content_types) ? $this->content_types[0] : key($this->content_types));
|
2014-10-23 19:33:03 +02:00
|
|
|
|
|
|
|
// Common type changes - add, delete
|
|
|
|
if($content['content_types']['delete'])
|
|
|
|
{
|
|
|
|
$this->delete_content_type($content);
|
|
|
|
}
|
2014-10-22 21:55:27 +02:00
|
|
|
elseif($content['content_types']['create'])
|
2006-03-14 14:54:17 +01:00
|
|
|
{
|
2014-11-19 22:15:48 +01:00
|
|
|
if($new_type = $this->create_content_type($content))
|
|
|
|
{
|
|
|
|
$content['content_types']['types'] = $this->content_type = $new_type;
|
|
|
|
}
|
|
|
|
unset($content['content_types']['create']);
|
2014-10-22 21:55:27 +02:00
|
|
|
unset($content['content_types']['name']);
|
2006-03-14 14:54:17 +01:00
|
|
|
}
|
2014-10-23 19:33:03 +02:00
|
|
|
// No common type change and type didn't change, try an update
|
|
|
|
elseif($this->content_type && is_array($content) && $this->content_type == $content['old_content_type'])
|
|
|
|
{
|
|
|
|
$this->update($content);
|
|
|
|
}
|
2014-10-22 21:55:27 +02:00
|
|
|
}
|
2014-10-23 19:33:03 +02:00
|
|
|
|
|
|
|
// Custom field deleted from nextmatch
|
2014-10-22 21:55:27 +02:00
|
|
|
if($content['nm']['action'] == 'delete')
|
|
|
|
{
|
|
|
|
foreach($this->fields as $name => $data)
|
2005-10-28 20:27:06 +02:00
|
|
|
{
|
2014-10-22 21:55:27 +02:00
|
|
|
if(in_array($data['id'],$content['nm']['selected']))
|
2006-03-14 14:54:17 +01:00
|
|
|
{
|
2014-10-22 21:55:27 +02:00
|
|
|
unset($this->fields[$name]);
|
2006-03-14 14:54:17 +01:00
|
|
|
}
|
2005-10-28 20:27:06 +02:00
|
|
|
}
|
2014-10-22 21:55:27 +02:00
|
|
|
// save changes to repository
|
|
|
|
$this->save_repository();
|
2009-04-23 13:18:51 +02:00
|
|
|
}
|
2014-12-10 15:34:48 +01:00
|
|
|
|
2014-10-22 21:55:27 +02:00
|
|
|
$content['nm']= $GLOBALS['egw']->session->appsession('customfield-index','admin');
|
|
|
|
if (!is_array($content['nm']))
|
2009-04-23 13:18:51 +02:00
|
|
|
{
|
2014-10-22 21:55:27 +02:00
|
|
|
// Initialize nextmatch
|
|
|
|
$content['nm'] = array(
|
|
|
|
'get_rows' => 'admin.customfields.get_rows',
|
|
|
|
'no_cat' => 'true',
|
|
|
|
'no_filter' => 'true',
|
|
|
|
'no_filter2' => 'true',
|
|
|
|
'row_id' => 'cf_id',
|
|
|
|
'order' => 'cf_order',// IO name of the column to sort
|
|
|
|
'sort' => 'ASC',// IO direction of the sort: 'ASC' or 'DESC'
|
|
|
|
'actions' => $this->get_actions()
|
|
|
|
);
|
2009-04-23 13:18:51 +02:00
|
|
|
}
|
2014-10-22 21:55:27 +02:00
|
|
|
$content['nm']['appname'] = $this->appname;
|
|
|
|
$content['nm']['use_private'] = $this->use_private;
|
2014-12-10 15:34:48 +01:00
|
|
|
|
2014-10-22 21:55:27 +02:00
|
|
|
// Set up sub-types
|
2009-04-23 13:18:51 +02:00
|
|
|
if($this->manage_content_types)
|
|
|
|
{
|
|
|
|
foreach($this->content_types as $type => $entry)
|
2005-10-28 20:27:06 +02:00
|
|
|
{
|
2014-10-23 19:33:03 +02:00
|
|
|
if(!is_array($entry))
|
|
|
|
{
|
|
|
|
$this->content_types[$type] = array('name' => $entry);
|
|
|
|
$entry = $this->content_types[$type];
|
|
|
|
}
|
2009-04-23 13:18:51 +02:00
|
|
|
$this->types2[$type] = $entry['name'];
|
|
|
|
}
|
2014-10-22 21:55:27 +02:00
|
|
|
$sel_options['types'] = $sel_options['cf_type2'] = $this->types2;
|
|
|
|
|
2014-10-23 19:33:03 +02:00
|
|
|
$content['type_template'] = $this->appname . '.admin.types';
|
2014-10-22 21:55:27 +02:00
|
|
|
$content['content_types']['appname'] = $this->appname;
|
|
|
|
$content_types = array_keys($this->content_types);
|
|
|
|
|
2009-04-23 13:18:51 +02:00
|
|
|
$content['content_type_options'] = $this->content_types[$this->content_type]['options'];
|
2014-10-23 19:33:03 +02:00
|
|
|
$content['content_type_options']['type'] = $this->types2[$this->content_type];
|
2009-04-23 13:18:51 +02:00
|
|
|
if ($this->content_types[$this->content_type]['non_deletable'])
|
|
|
|
{
|
|
|
|
$content['content_types']['non_deletable'] = true;
|
|
|
|
}
|
2011-01-25 21:32:38 +01:00
|
|
|
if ($this->content_types['']['no_add'])
|
|
|
|
{
|
|
|
|
$content['content_types']['no_add'] = true;
|
|
|
|
}
|
|
|
|
if ($content['content_types']['non_deletable'] && $content['content_types']['no_add'])
|
|
|
|
{
|
|
|
|
// Hide the whole line if you can't add or delete
|
|
|
|
$content['content_types']['no_edit_types'] = true;
|
|
|
|
}
|
2014-10-22 21:55:27 +02:00
|
|
|
// do NOT allow to delete original contact content-type for addressbook,
|
|
|
|
// as it only creates support problems as users incidently delete it
|
|
|
|
if ($this->appname == 'addressbook' && $this->content_type == 'n')
|
|
|
|
{
|
|
|
|
$readonlys['content_types']['delete'] = true;
|
|
|
|
}
|
|
|
|
$content['nm']['type2'] = true;
|
2009-04-23 13:18:51 +02:00
|
|
|
}
|
2014-10-22 21:55:27 +02:00
|
|
|
else
|
2009-04-23 13:18:51 +02:00
|
|
|
{
|
2014-10-22 21:55:27 +02:00
|
|
|
// Disable content types
|
|
|
|
$this->tmpl->disableElement('content_types', true);
|
|
|
|
}
|
2014-10-23 19:33:03 +02:00
|
|
|
$preserve = array(
|
|
|
|
'appname' => $this->appname,
|
|
|
|
'use_private' => $this->use_private,
|
|
|
|
'old_content_type' => $this->content_type
|
|
|
|
);
|
|
|
|
|
|
|
|
// Allow extending app a change to change content before display
|
|
|
|
static::app_index($content, $sel_options, $readonlys, $preserve);
|
2014-10-22 21:55:27 +02:00
|
|
|
|
2014-11-24 18:06:06 +01:00
|
|
|
// Make sure app css gets loaded, extending app might cause et2 to miss it
|
|
|
|
egw_framework::includeCSS('admin','app');
|
|
|
|
|
2014-10-22 21:55:27 +02:00
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] = $GLOBALS['egw_info']['apps'][$this->appname]['title'].' - '.lang('Custom fields');
|
2014-10-23 19:33:03 +02:00
|
|
|
|
|
|
|
// Some logic to make sure extending class (if there is one) gets called
|
|
|
|
// when etemplate2 comes back instead of parent class
|
|
|
|
$exec = get_class() == get_called_class() ? 'admin.customfields.index' : $this->appname . '.' . get_called_class() . '.index';
|
2014-12-10 15:34:48 +01:00
|
|
|
|
2014-10-23 19:33:03 +02:00
|
|
|
$this->tmpl->exec($exec,$content,$sel_options,$readonlys,$preserve);
|
2014-10-22 21:55:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit/Create Custom fields with type
|
|
|
|
*
|
|
|
|
* @author Ralf Becker <ralfbecker-AT-outdoor-training.de>
|
|
|
|
* @param array $content Content from the eTemplate Exec
|
|
|
|
*/
|
|
|
|
function edit($content = null)
|
|
|
|
{
|
|
|
|
$cf_id = $_GET['cf_id'] ? (int)$_GET['cf_id'] : (int)$content['cf_id'];
|
|
|
|
|
|
|
|
// determine appname
|
2014-10-23 19:33:03 +02:00
|
|
|
$this->appname = $this->appname ? $this->appname : ($_GET['appname'] ? $_GET['appname'] : ($content['cf_app'] ? $content['cf_app'] : false));
|
2014-10-22 21:55:27 +02:00
|
|
|
if(!$this->appname)
|
|
|
|
{
|
|
|
|
if($cf_id && $this->so)
|
2009-04-23 13:18:51 +02:00
|
|
|
{
|
2014-10-22 21:55:27 +02:00
|
|
|
$content = $this->so->read($cf_id);
|
|
|
|
$this->appname = $content['cf_app'];
|
2009-04-23 13:18:51 +02:00
|
|
|
}
|
2014-10-22 21:55:27 +02:00
|
|
|
}
|
|
|
|
if(!$this->appname)
|
|
|
|
{
|
|
|
|
die(lang('Error! No appname found'));
|
|
|
|
}
|
|
|
|
$this->use_private = !isset($_GET['use_private']) || (boolean)$_GET['use_private'] || $content['use_private'];
|
|
|
|
|
|
|
|
// Read fields, constructor doesn't always know appname
|
|
|
|
$this->fields = egw_customfields::get($this->appname,true);
|
|
|
|
|
|
|
|
// Update based on info returned from template
|
|
|
|
if (is_array($content))
|
|
|
|
{
|
|
|
|
list($action) = @each($content['button']);
|
|
|
|
switch($action)
|
2009-04-23 13:18:51 +02:00
|
|
|
{
|
2014-10-22 21:55:27 +02:00
|
|
|
case 'delete':
|
|
|
|
$this->so->delete($cf_id);
|
2015-04-20 23:49:05 +02:00
|
|
|
egw_framework::refresh_opener('Deleted', 'admin', $cf_id /* Conflicts with accounts 'delete'*/);
|
2014-10-22 21:55:27 +02:00
|
|
|
egw_framework::window_close();
|
|
|
|
break;
|
|
|
|
case 'save':
|
|
|
|
case 'apply':
|
2015-04-20 23:49:05 +02:00
|
|
|
if(!$cf_id && $this->fields[$content['cf_name']])
|
|
|
|
{
|
|
|
|
egw_framework::message(lang("Field '%1' already exists !!!",$content['cf_name']),'error');
|
|
|
|
$content['cf_name'] = '';
|
|
|
|
break;
|
|
|
|
}
|
2015-02-18 19:23:35 +01:00
|
|
|
if(empty($content['cf_label']))
|
|
|
|
{
|
|
|
|
$content['cf_label'] = $content['cf_name'];
|
|
|
|
}
|
2014-10-22 21:55:27 +02:00
|
|
|
if (!empty($content['cf_values']))
|
|
|
|
{
|
|
|
|
$values = array();
|
2015-04-21 18:13:10 +02:00
|
|
|
if($content['cf_values'][0] === '@')
|
2014-10-22 21:55:27 +02:00
|
|
|
{
|
2015-04-21 18:13:10 +02:00
|
|
|
$values['@'] = substr($content['cf_values'], $content['cf_values'][1] === '=' ? 2:1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-19 21:58:43 +02:00
|
|
|
foreach(explode("\n",trim($content['cf_values'])) as $line)
|
2015-04-21 18:13:10 +02:00
|
|
|
{
|
|
|
|
list($var,$value) = explode('=',trim($line),2);
|
|
|
|
$var = trim($var);
|
2015-04-21 21:46:33 +02:00
|
|
|
$values[$var] = trim($value)==='' ? $var : $value;
|
2015-04-21 18:13:10 +02:00
|
|
|
}
|
2014-10-22 21:55:27 +02:00
|
|
|
}
|
|
|
|
$content['cf_values'] = $values;
|
|
|
|
}
|
2014-10-27 17:31:24 +01:00
|
|
|
$update_content = array();
|
|
|
|
foreach($content as $key => $value)
|
|
|
|
{
|
|
|
|
if(substr($key,0,3) == 'cf_')
|
|
|
|
{
|
|
|
|
$update_content[substr($key,3)] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
egw_customfields::update($update_content);
|
2015-04-21 00:54:58 +02:00
|
|
|
if(!$cf_id)
|
|
|
|
{
|
|
|
|
$this->fields = egw_customfields::get($this->appname,true);
|
|
|
|
$cf_id = (int)$this->fields[$content['cf_name']]['id'];
|
|
|
|
}
|
2014-10-22 21:55:27 +02:00
|
|
|
egw_framework::refresh_opener('Saved', 'admin', $cf_id, 'edit');
|
|
|
|
if ($action != 'save')
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
//fall through
|
|
|
|
case 'cancel':
|
|
|
|
egw_framework::window_close();
|
2005-10-28 20:27:06 +02:00
|
|
|
}
|
|
|
|
}
|
2014-10-22 21:55:27 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$content['use_private'] = !isset($_GET['use_private']) || (boolean)$_GET['use_private'];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// do we manage content-types?
|
|
|
|
$test = new etemplate_new();
|
|
|
|
if($test->read($this->appname.'.admin.types')) $this->manage_content_types = true;
|
|
|
|
|
|
|
|
$this->tmpl = new etemplate_new();
|
|
|
|
$this->tmpl->read('admin.customfield_edit');
|
2009-04-23 13:18:51 +02:00
|
|
|
|
2014-10-22 21:55:27 +02:00
|
|
|
translation::add_app('infolog'); // til we move the translations
|
|
|
|
|
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] = $GLOBALS['egw_info']['apps'][$this->appname]['title'].' - '.lang('Custom fields');
|
|
|
|
$sel_options = array();
|
|
|
|
$readonlys = array();
|
2013-06-10 22:17:41 +02:00
|
|
|
|
2014-10-22 21:55:27 +02:00
|
|
|
//echo 'customfields=<pre style="text-align: left;">'; print_r($this->fields); echo "</pre>\n";
|
|
|
|
$content['cf_order'] = (count($this->fields)+1) * 10;
|
|
|
|
$content['use_private'] = $this->use_private;
|
|
|
|
|
|
|
|
if($cf_id)
|
|
|
|
{
|
|
|
|
$content = array_merge($content, $this->so->read($cf_id));
|
|
|
|
$this->appname = $content['cf_app'];
|
|
|
|
if($content['cf_private'])
|
|
|
|
{
|
|
|
|
$content['cf_private'] = explode(',',$content['cf_private']);
|
|
|
|
}
|
2015-04-20 23:49:05 +02:00
|
|
|
if($content['cf_name'])
|
|
|
|
{
|
|
|
|
$readonlys['cf_name'] = true;
|
|
|
|
}
|
2015-04-21 00:54:58 +02:00
|
|
|
$content['cf_values'] = json_decode($content['cf_values'], true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$readonlys['button[delete]'] = true;
|
2014-10-22 21:55:27 +02:00
|
|
|
}
|
|
|
|
if (is_array($content['cf_values']))
|
2010-01-07 05:54:48 +01:00
|
|
|
{
|
2014-10-22 21:55:27 +02:00
|
|
|
$values = '';
|
|
|
|
foreach($content['cf_values'] as $var => $value)
|
|
|
|
{
|
|
|
|
$values .= (!empty($values) ? "\n" : '').$var.'='.$value;
|
|
|
|
}
|
|
|
|
$content['cf_values'] = $values;
|
2010-01-07 05:54:48 +01:00
|
|
|
}
|
2014-10-22 21:55:27 +02:00
|
|
|
|
|
|
|
// Show sub-type row, and get types
|
|
|
|
if($this->manage_content_types)
|
|
|
|
{
|
2014-10-23 19:33:03 +02:00
|
|
|
if(count($this->content_types) == 0)
|
|
|
|
{
|
|
|
|
$this->content_types = config::get_content_types($this->appname);
|
|
|
|
}
|
2014-10-22 21:55:27 +02:00
|
|
|
if (count($this->content_types)==0)
|
|
|
|
{
|
|
|
|
// if you define your default types of your app with the search_link hook, they are available here, if no types were found
|
|
|
|
$this->content_types = (array)egw_link::get_registry($this->appname,'default_types');
|
|
|
|
}
|
|
|
|
foreach($this->content_types as $type => $entry)
|
|
|
|
{
|
2014-10-23 19:33:03 +02:00
|
|
|
$this->types2[$type] = is_array($entry) ? $entry['name'] : $entry;
|
2014-10-22 21:55:27 +02:00
|
|
|
}
|
2014-10-23 19:33:03 +02:00
|
|
|
$sel_options['cf_type2'] = $this->types2;
|
2014-10-22 21:55:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$content['no_types'] = true;
|
|
|
|
}
|
|
|
|
|
2014-11-24 22:58:07 +01:00
|
|
|
// Include type-specific value help
|
2015-06-18 18:48:16 +02:00
|
|
|
foreach(self::$type_option_help as $key => $value)
|
|
|
|
{
|
|
|
|
$content['options'][$key] = lang($value);
|
|
|
|
}
|
2014-11-24 22:58:07 +01:00
|
|
|
$content['statustext'] = $content['options'][$content['cf_type']];
|
|
|
|
$content['attributes'] = self::$type_attribute_flags;
|
2014-11-27 17:58:11 +01:00
|
|
|
|
2009-04-23 13:18:51 +02:00
|
|
|
$this->tmpl->exec('admin.customfields.edit',$content,$sel_options,$readonlys,array(
|
2014-10-22 21:55:27 +02:00
|
|
|
'cf_id' => $cf_id,
|
|
|
|
'cf_app' => $this->appname,
|
2015-04-20 23:49:05 +02:00
|
|
|
'cf_name' => $content['cf_name'],
|
2014-10-22 21:55:27 +02:00
|
|
|
'use_private' => $this->use_private,
|
2014-10-30 16:24:05 +01:00
|
|
|
),2);
|
2009-04-23 13:18:51 +02:00
|
|
|
}
|
2005-10-28 20:27:06 +02:00
|
|
|
|
2014-10-23 19:33:03 +02:00
|
|
|
/**
|
|
|
|
* Allow extending apps a change to interfere and add content to support
|
|
|
|
* their custom template. This is called right before etemplate->exec().
|
|
|
|
*/
|
|
|
|
protected function app_index(&$content, &$sel_options, &$readonlys)
|
|
|
|
{
|
|
|
|
// This is just a stub.
|
|
|
|
}
|
|
|
|
|
2014-10-22 21:55:27 +02:00
|
|
|
/**
|
|
|
|
* Get actions / context menu for index
|
|
|
|
*
|
|
|
|
* Changes here, require to log out, as $content['nm'] get stored in session!
|
|
|
|
*
|
|
|
|
* @return array see nextmatch_widget::egw_actions()
|
|
|
|
*/
|
2014-10-23 19:33:03 +02:00
|
|
|
protected function get_actions()
|
2014-10-22 21:55:27 +02:00
|
|
|
{
|
|
|
|
$actions = array(
|
|
|
|
'open' => array( // does edit if allowed, otherwise view
|
|
|
|
'caption' => 'Open',
|
|
|
|
'default' => true,
|
|
|
|
'allowOnMultiple' => false,
|
|
|
|
'url' => 'menuaction=admin.customfields.edit&cf_id=$id&use_private='.$this->use_private,
|
2014-11-27 17:58:11 +01:00
|
|
|
'popup' => '500x380',
|
2014-10-22 21:55:27 +02:00
|
|
|
'group' => $group=1,
|
|
|
|
'disableClass' => 'th',
|
|
|
|
),
|
|
|
|
'add' => array(
|
|
|
|
'caption' => 'Add',
|
|
|
|
'url' => 'menuaction=admin.customfields.edit&appname='.$this->appname.'&use_private='.$this->use_private,
|
2014-11-27 17:58:11 +01:00
|
|
|
'popup' => '500x380',
|
2014-10-22 21:55:27 +02:00
|
|
|
'group' => $group,
|
|
|
|
),
|
|
|
|
'delete' => array(
|
|
|
|
'caption' => 'Delete',
|
|
|
|
'confirm' => 'Delete this entry',
|
|
|
|
'confirm_multiple' => 'Delete these entries',
|
|
|
|
'group' => ++$group,
|
|
|
|
'disableClass' => 'rowNoDelete',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
return $actions;
|
|
|
|
}
|
|
|
|
|
2009-04-23 13:18:51 +02:00
|
|
|
function update_fields(&$content)
|
|
|
|
{
|
|
|
|
foreach($content['fields'] as $field)
|
2005-10-28 20:27:06 +02:00
|
|
|
{
|
2009-04-23 13:18:51 +02:00
|
|
|
$name = trim($field['name']);
|
|
|
|
$old_name = $field['old_name'];
|
2005-10-28 20:27:06 +02:00
|
|
|
|
2009-04-23 13:18:51 +02:00
|
|
|
if (!empty($delete) && $delete == $old_name)
|
|
|
|
{
|
|
|
|
unset($this->fields[$old_name]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (isset($field['old_name']))
|
|
|
|
{
|
|
|
|
if (empty($name)) // empty name not allowed
|
2005-10-28 20:27:06 +02:00
|
|
|
{
|
2009-04-23 13:18:51 +02:00
|
|
|
$content['error_msg'] = lang('Name must not be empty !!!');
|
|
|
|
$name = $old_name;
|
2005-10-28 20:27:06 +02:00
|
|
|
}
|
2009-04-23 13:18:51 +02:00
|
|
|
if (!empty($name) && $old_name != $name) // renamed
|
2006-03-14 14:54:17 +01:00
|
|
|
{
|
2009-04-23 13:18:51 +02:00
|
|
|
unset($this->fields[$old_name]);
|
2006-03-14 14:54:17 +01:00
|
|
|
}
|
2005-10-28 20:27:06 +02:00
|
|
|
}
|
2009-04-23 13:18:51 +02:00
|
|
|
elseif (empty($name)) // new item and empty ==> ignore it
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$values = array();
|
|
|
|
if (!empty($field['values']))
|
2005-10-28 20:27:06 +02:00
|
|
|
{
|
2009-04-23 13:18:51 +02:00
|
|
|
foreach(explode("\n",$field['values']) as $line)
|
2005-10-28 20:27:06 +02:00
|
|
|
{
|
2009-06-08 18:21:14 +02:00
|
|
|
list($var,$value) = explode('=',trim($line),2);
|
2009-04-23 13:18:51 +02:00
|
|
|
$var = trim($var);
|
|
|
|
$values[$var] = empty($value) ? $var : $value;
|
2005-10-28 20:27:06 +02:00
|
|
|
}
|
|
|
|
}
|
2009-04-23 13:18:51 +02:00
|
|
|
$this->fields[$name] = array(
|
|
|
|
'type' => $field['type'],
|
|
|
|
'type2' => $field['type2'],
|
|
|
|
'label' => empty($field['label']) ? $name : $field['label'],
|
|
|
|
'help' => $field['help'],
|
|
|
|
'values'=> $values,
|
|
|
|
'len' => $field['len'],
|
|
|
|
'rows' => (int)$field['rows'],
|
|
|
|
'order' => (int)$field['order'],
|
|
|
|
'private' => $field['private'],
|
2011-05-18 12:25:39 +02:00
|
|
|
'needed' => $field['needed'],
|
2009-04-23 13:18:51 +02:00
|
|
|
);
|
|
|
|
if(!$this->fields[$name]['type2'] && $this->manage_content_types)
|
2005-10-28 20:27:06 +02:00
|
|
|
{
|
2009-04-23 13:18:51 +02:00
|
|
|
$this->fields[$name]['type2'] = (string)0;
|
2005-10-28 20:27:06 +02:00
|
|
|
}
|
|
|
|
}
|
2009-04-23 13:18:51 +02:00
|
|
|
if (!function_exists('sort_by_order'))
|
|
|
|
{
|
|
|
|
function sort_by_order($arr1,$arr2)
|
|
|
|
{
|
|
|
|
return $arr1['order'] - $arr2['order'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uasort($this->fields,sort_by_order);
|
2005-10-28 20:27:06 +02:00
|
|
|
|
2009-04-23 13:18:51 +02:00
|
|
|
$n = 0;
|
|
|
|
foreach($this->fields as $name => $data)
|
2005-10-28 20:27:06 +02:00
|
|
|
{
|
2009-04-23 13:18:51 +02:00
|
|
|
$this->fields[$name]['order'] = ($n += 10);
|
2005-10-28 20:27:06 +02:00
|
|
|
}
|
2009-04-23 13:18:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function update(&$content)
|
|
|
|
{
|
|
|
|
$this->content_types[$this->content_type]['options'] = $content['content_type_options'];
|
|
|
|
// save changes to repository
|
|
|
|
$this->save_repository();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* deletes custom field from customfield definitions
|
|
|
|
*/
|
|
|
|
function delete_field(&$content)
|
|
|
|
{
|
|
|
|
unset($this->fields[key($content['fields']['delete'])]);
|
|
|
|
// save changes to repository
|
|
|
|
$this->save_repository();
|
|
|
|
}
|
|
|
|
|
|
|
|
function delete_content_type(&$content)
|
|
|
|
{
|
|
|
|
unset($this->content_types[$content['content_types']['types']]);
|
|
|
|
// save changes to repository
|
|
|
|
$this->save_repository();
|
|
|
|
}
|
2005-10-28 20:27:06 +02:00
|
|
|
|
2009-04-23 13:18:51 +02:00
|
|
|
/**
|
|
|
|
* create a new custom field
|
|
|
|
*/
|
|
|
|
function create_field(&$content)
|
|
|
|
{
|
|
|
|
$new_name = trim($content['fields'][count($content['fields'])-1]['name']);
|
|
|
|
if (empty($new_name) || isset($this->fields[$new_name]))
|
2005-10-28 20:27:06 +02:00
|
|
|
{
|
2009-04-23 13:18:51 +02:00
|
|
|
$content['error_msg'] .= empty($new_name) ?
|
|
|
|
lang('You have to enter a name, to create a new field!!!') :
|
|
|
|
lang("Field '%1' already exists !!!",$new_name);
|
2005-10-28 20:27:06 +02:00
|
|
|
}
|
2009-04-23 13:18:51 +02:00
|
|
|
else
|
2006-03-14 14:54:17 +01:00
|
|
|
{
|
2009-04-23 13:18:51 +02:00
|
|
|
$this->fields[$new_name] = $content['fields'][count($content['fields'])-1];
|
|
|
|
if(!$this->fields[$new_name]['label']) $this->fields[$new_name]['label'] = $this->fields[$new_name]['name'];
|
2006-03-14 14:54:17 +01:00
|
|
|
$this->save_repository();
|
|
|
|
}
|
2009-04-23 13:18:51 +02:00
|
|
|
}
|
|
|
|
|
2014-11-19 22:15:48 +01:00
|
|
|
/**
|
|
|
|
* Validate and create a new content type
|
|
|
|
*
|
|
|
|
* @param array $content
|
|
|
|
* @return string|boolean New type ID, or false for error
|
|
|
|
*/
|
2009-04-23 13:18:51 +02:00
|
|
|
function create_content_type(&$content)
|
|
|
|
{
|
|
|
|
$new_name = trim($content['content_types']['name']);
|
2014-10-22 21:55:27 +02:00
|
|
|
$new_type = false;
|
|
|
|
if (empty($new_name))
|
2005-10-28 20:27:06 +02:00
|
|
|
{
|
2014-10-22 21:55:27 +02:00
|
|
|
$this->tmpl->set_validation_error('content_types[name]','You have to enter a name, to create a new type!!!');
|
2005-10-28 20:27:06 +02:00
|
|
|
}
|
2009-04-23 13:18:51 +02:00
|
|
|
else
|
2006-03-14 14:54:17 +01:00
|
|
|
{
|
2014-10-22 21:55:27 +02:00
|
|
|
foreach($this->content_types as $letter => $type)
|
|
|
|
{
|
|
|
|
if($type['name'] == $new_name)
|
|
|
|
{
|
|
|
|
$this->tmpl->set_validation_error('content_types[name]',lang("type '%1' already exists !!!",$new_name));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2009-04-23 13:18:51 +02:00
|
|
|
// search free type character
|
|
|
|
for($i=97;$i<=122;$i++)
|
2006-03-14 14:54:17 +01:00
|
|
|
{
|
2012-05-08 10:50:19 +02:00
|
|
|
if (!$this->content_types[chr($i)] &&
|
|
|
|
// skip letter of deleted type for addressbook content-types, as it gives SQL error
|
|
|
|
// content-type are lowercase, addressbook_so::DELETED_TYPE === 'D', but DB is case-insensitive
|
|
|
|
($this->appname !== 'addressbook' || chr($i) !== strtolower(addressbook_so::DELETED_TYPE)))
|
2006-03-14 14:54:17 +01:00
|
|
|
{
|
2009-04-23 13:18:51 +02:00
|
|
|
$new_type = chr($i);
|
|
|
|
break;
|
2006-03-14 14:54:17 +01:00
|
|
|
}
|
|
|
|
}
|
2009-04-23 13:18:51 +02:00
|
|
|
$this->content_types[$new_type] = array('name' => $new_name);
|
|
|
|
$this->save_repository();
|
2006-03-14 14:54:17 +01:00
|
|
|
}
|
2014-10-22 21:55:27 +02:00
|
|
|
return $new_type;
|
2009-04-23 13:18:51 +02:00
|
|
|
}
|
2005-10-28 20:27:06 +02:00
|
|
|
|
2009-04-23 13:18:51 +02:00
|
|
|
/**
|
|
|
|
* save changes to repository
|
|
|
|
*/
|
|
|
|
function save_repository()
|
|
|
|
{
|
|
|
|
//echo '<p>uicustomfields::save_repository() \$this->fields=<pre style="text-aling: left;">'; print_r($this->fields); echo "</pre>\n";
|
|
|
|
$config = new config($this->appname);
|
|
|
|
$config->read_repository();
|
|
|
|
$config->value('types',$this->content_types);
|
|
|
|
$config->save_repository();
|
2014-06-23 16:35:22 +02:00
|
|
|
|
|
|
|
egw_customfields::save($this->appname, $this->fields);
|
2009-04-23 13:18:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get customfields of using application
|
|
|
|
*
|
2014-06-23 16:35:22 +02:00
|
|
|
* @deprecated use egw_customfields::get() direct, no need to instanciate this UI class
|
2009-04-23 13:18:51 +02:00
|
|
|
* @author Cornelius Weiss
|
|
|
|
* @param boolean $all_private_too=false should all the private fields be returned too
|
|
|
|
* @return array with customfields
|
|
|
|
*/
|
|
|
|
function get_customfields($all_private_too=false)
|
|
|
|
{
|
2014-06-23 16:35:22 +02:00
|
|
|
return egw_customfields::get($this->appname,$all_private_too);
|
2009-04-23 13:18:51 +02:00
|
|
|
}
|
2006-03-14 14:54:17 +01:00
|
|
|
|
2009-04-23 13:18:51 +02:00
|
|
|
/**
|
|
|
|
* get_content_types of using application
|
|
|
|
*
|
|
|
|
* @deprecated use config::get_content_types() direct, no need to instanciate this UI class
|
|
|
|
* @author Cornelius Weiss
|
|
|
|
* @return array with content-types
|
|
|
|
*/
|
|
|
|
function get_content_types()
|
|
|
|
{
|
|
|
|
return config::get_content_types($this->appname);
|
2005-10-28 20:27:06 +02:00
|
|
|
}
|
2009-04-23 13:18:51 +02:00
|
|
|
|
2014-10-22 21:55:27 +02:00
|
|
|
/**
|
|
|
|
* Get list of customfields for the nextmatch
|
|
|
|
*/
|
|
|
|
public function get_rows(&$query, &$rows, &$readonlys)
|
|
|
|
{
|
|
|
|
$rows = array();
|
|
|
|
|
|
|
|
$query['col_filter']['cf_app'] = $query['appname'];
|
|
|
|
$total = $this->so->get_rows($query, $rows, $readonlys);
|
|
|
|
unset($query['col_filter']['cf_app']);
|
|
|
|
|
|
|
|
foreach($rows as &$row)
|
|
|
|
{
|
|
|
|
$row['cf_values'] = json_decode($row['cf_values'], true);
|
|
|
|
if (is_array($row['cf_values']))
|
|
|
|
{
|
|
|
|
$values = '';
|
|
|
|
foreach($row['cf_values'] as $var => $value)
|
|
|
|
{
|
|
|
|
$values .= (!empty($values) ? "\n" : '').$var.'='.$value;
|
|
|
|
}
|
|
|
|
$row['cf_values'] = $values;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $total;
|
|
|
|
}
|
2009-04-23 13:18:51 +02:00
|
|
|
}
|