2003-08-28 16:31:11 +02:00
|
|
|
<?php
|
2006-10-04 19:40:33 +02:00
|
|
|
/**
|
2007-05-22 15:40:35 +02:00
|
|
|
* InfoLog - Custom fields
|
2006-10-04 19:40:33 +02:00
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
|
|
|
* @package infolog
|
2016-04-30 19:05:23 +02:00
|
|
|
* @copyright (c) 2003-16 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
2006-10-04 19:40:33 +02:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2016-04-30 19:05:23 +02:00
|
|
|
use EGroupware\Api;
|
|
|
|
use EGroupware\Api\Etemplate;
|
|
|
|
|
2006-10-04 19:40:33 +02:00
|
|
|
/**
|
|
|
|
* Administration of custom fields, type and status
|
|
|
|
*/
|
2016-08-12 11:35:30 +02:00
|
|
|
class infolog_customfields extends admin_customfields
|
2006-10-04 19:40:33 +02:00
|
|
|
{
|
2014-10-23 19:33:03 +02:00
|
|
|
public $appname = 'infolog';
|
2006-10-04 19:40:33 +02:00
|
|
|
/**
|
|
|
|
* Instance of the infolog BO class
|
|
|
|
*
|
2014-01-28 09:34:23 +01:00
|
|
|
* @var infolog_bo
|
2006-10-04 19:40:33 +02:00
|
|
|
*/
|
|
|
|
var $bo;
|
|
|
|
/**
|
|
|
|
* instance of the config class for infolog
|
2008-10-07 14:50:14 +02:00
|
|
|
*
|
2016-04-30 19:05:23 +02:00
|
|
|
* @var Api\Config
|
2006-10-04 19:40:33 +02:00
|
|
|
*/
|
2008-01-25 13:13:04 +01:00
|
|
|
var $config_data;
|
2007-03-12 12:27:33 +01:00
|
|
|
/**
|
2008-10-07 14:50:14 +02:00
|
|
|
* Group owners for certain types read from the infolog config
|
2007-03-12 12:27:33 +01:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $group_owners;
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2008-10-07 14:50:14 +02:00
|
|
|
function __construct( )
|
2006-10-04 19:40:33 +02:00
|
|
|
{
|
2014-10-23 19:33:03 +02:00
|
|
|
parent::__construct('infolog');
|
2016-04-30 19:05:23 +02:00
|
|
|
|
2008-10-07 14:50:14 +02:00
|
|
|
$this->bo = new infolog_bo();
|
2016-04-30 19:05:23 +02:00
|
|
|
$this->tmpl = new Etemplate();
|
2014-10-23 19:33:03 +02:00
|
|
|
$this->content_types = &$this->bo->enums['type'];
|
2006-10-04 19:40:33 +02:00
|
|
|
$this->status = &$this->bo->status;
|
2016-04-30 19:05:23 +02:00
|
|
|
$this->config_data = Api\Config::read('infolog');
|
2006-10-04 19:40:33 +02:00
|
|
|
$this->fields = &$this->bo->customfields;
|
2007-03-12 12:27:33 +01:00
|
|
|
$this->group_owners =& $this->bo->group_owners;
|
2016-08-12 11:35:30 +02:00
|
|
|
|
|
|
|
Api\Translation::add_app('infolog');
|
2006-10-04 19:40:33 +02:00
|
|
|
}
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2014-10-23 19:33:03 +02:00
|
|
|
|
2006-10-04 19:40:33 +02:00
|
|
|
/**
|
2014-10-23 19:33:03 +02:00
|
|
|
* Hook from parent class so we can interfere and add owner & status
|
2006-10-04 19:40:33 +02:00
|
|
|
*/
|
2014-10-23 19:33:03 +02:00
|
|
|
protected function app_index(&$content, &$sel_options, &$readonlys, &$preserve)
|
2006-10-04 19:40:33 +02:00
|
|
|
{
|
2016-04-30 19:05:23 +02:00
|
|
|
unset($sel_options); // not used, but required by function signature
|
|
|
|
|
2006-10-04 19:40:33 +02:00
|
|
|
$n = 0;
|
2014-10-23 19:33:03 +02:00
|
|
|
foreach($this->status[$this->content_type] as $name => $label)
|
2006-10-04 19:40:33 +02:00
|
|
|
{
|
2014-10-23 19:33:03 +02:00
|
|
|
$content['content_type_options']['status'][++$n] = array(
|
2006-10-04 19:40:33 +02:00
|
|
|
'name' => $name,
|
|
|
|
'label' => $label,
|
|
|
|
'disabled' => False
|
2003-08-28 16:31:11 +02:00
|
|
|
);
|
2014-10-23 19:33:03 +02:00
|
|
|
$preserve['content_type_options']['status'][$n]['old_name'] = $name;
|
|
|
|
if (isset($this->bo->stock_status[$this->content_type][$name]))
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2014-10-23 19:33:03 +02:00
|
|
|
$readonlys['content_type_options']['status']["delete[$name]"] =
|
|
|
|
$readonlys['content_type_options']['status'][$n.'[name]'] = True;
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
2014-10-23 19:33:03 +02:00
|
|
|
$readonlys['content_type_options']['status']["create$name"] = True;
|
2006-10-04 19:40:33 +02:00
|
|
|
}
|
2014-11-19 22:15:48 +01:00
|
|
|
$content['content_type_options']['status'][++$n] = array(
|
|
|
|
'name' => '',
|
|
|
|
'label' => '',
|
|
|
|
'disabled' => False
|
|
|
|
);
|
2014-10-23 19:33:03 +02:00
|
|
|
$content['content_type_options']['status']['default'] = $this->status['defaults'][$this->content_type];
|
|
|
|
$content['content_type_options']['group_owner'] = $this->group_owners[$this->content_type];
|
|
|
|
$readonlys['content_types']['delete'] = isset($this->bo->stock_enums['type'][$this->content_type]);
|
2006-10-04 19:40:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function update_fields(&$content)
|
|
|
|
{
|
|
|
|
$fields = &$content['fields'];
|
|
|
|
|
|
|
|
$create = $fields['create'];
|
|
|
|
unset($fields['create']);
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2006-10-04 19:40:33 +02:00
|
|
|
if ($fields['delete'])
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2006-10-04 19:40:33 +02:00
|
|
|
list($delete) = each($fields['delete']);
|
|
|
|
unset($fields['delete']);
|
|
|
|
}
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2006-10-04 19:40:33 +02:00
|
|
|
foreach($fields as $field)
|
|
|
|
{
|
|
|
|
$name = trim($field['name']);
|
|
|
|
$old_name = $field['old_name'];
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2006-10-04 19:40:33 +02:00
|
|
|
if (!empty($delete) && $delete == $old_name)
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2006-10-04 19:40:33 +02:00
|
|
|
unset($this->fields[$old_name]);
|
|
|
|
continue;
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
2006-10-04 19:40:33 +02:00
|
|
|
if (isset($field['name']) && empty($name) && ($create || !empty($old_name))) // empty name not allowed
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2006-10-04 19:40:33 +02:00
|
|
|
$content['error_msg'] = lang('Name must not be empty !!!');
|
|
|
|
}
|
|
|
|
if (isset($field['old_name']))
|
|
|
|
{
|
|
|
|
if (!empty($name) && $old_name != $name) // renamed
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
|
|
|
unset($this->fields[$old_name]);
|
|
|
|
}
|
2006-10-04 19:40:33 +02:00
|
|
|
elseif (empty($name))
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2006-10-04 19:40:33 +02:00
|
|
|
$name = $old_name;
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
|
|
|
}
|
2006-10-04 19:40:33 +02:00
|
|
|
elseif (empty($name)) // new item and empty ==> ignore it
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$values = array();
|
|
|
|
if (!empty($field['values']))
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2006-10-04 19:40:33 +02:00
|
|
|
foreach(explode("\n",$field['values']) as $line)
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2016-04-30 19:05:23 +02:00
|
|
|
list($var2,$value) = explode('=',trim($line),2);
|
|
|
|
$var = trim($var2);
|
2006-10-04 19:40:33 +02:00
|
|
|
$values[$var] = empty($value) ? $var : $value;
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
|
|
|
}
|
2006-10-04 19:40:33 +02:00
|
|
|
$this->fields[$name] = array(
|
|
|
|
'type2' => $field['type2'],
|
|
|
|
'type' => $field['type'],
|
|
|
|
'label' => empty($field['label']) ? $name : $field['label'],
|
|
|
|
'help' => $field['help'],
|
|
|
|
'values'=> $values,
|
|
|
|
'len' => $field['len'],
|
|
|
|
'rows' => (int)$field['rows'],
|
|
|
|
'order' => (int)$field['order'],
|
2011-05-18 12:25:39 +02:00
|
|
|
'needed' => $field['needed'],
|
2006-10-04 19:40:33 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
if (!function_exists('sort_by_order'))
|
|
|
|
{
|
|
|
|
function sort_by_order($arr1,$arr2)
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2006-10-04 19:40:33 +02:00
|
|
|
return $arr1['order'] - $arr2['order'];
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
|
|
|
}
|
2006-10-04 19:40:33 +02:00
|
|
|
uasort($this->fields,sort_by_order);
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2006-10-04 19:40:33 +02:00
|
|
|
$n = 0;
|
2016-04-30 19:05:23 +02:00
|
|
|
foreach(array_keys($this->fields) as $name)
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2006-10-04 19:40:33 +02:00
|
|
|
$this->fields[$name]['order'] = ($n += 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function update_status(&$content)
|
|
|
|
{
|
2014-10-23 19:33:03 +02:00
|
|
|
$typ = $this->content_type;
|
|
|
|
$status = &$content['content_type_options']['status'];
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2006-10-04 19:40:33 +02:00
|
|
|
$default = $status['default'];
|
|
|
|
unset($status['default']);
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2006-10-04 19:40:33 +02:00
|
|
|
$create = $status['create'];
|
|
|
|
unset($status['create']);
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2006-10-04 19:40:33 +02:00
|
|
|
if ($status['delete'])
|
|
|
|
{
|
|
|
|
list($delete) = each($status['delete']);
|
|
|
|
unset($status['delete']);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($status as $stat)
|
|
|
|
{
|
|
|
|
$name = trim($stat['name']);
|
|
|
|
$old_name = $stat['old_name'];
|
|
|
|
|
|
|
|
if (!empty($delete) && $delete == $old_name)
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2006-10-04 19:40:33 +02:00
|
|
|
unset($this->status[$typ][$old_name]);
|
|
|
|
continue;
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
2006-10-04 19:40:33 +02:00
|
|
|
if (isset($stat['name']) && empty($name) && ($create || !empty($old_name))) // empty name not allowed
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2006-10-04 19:40:33 +02:00
|
|
|
$content['error_msg'] = lang('Name must not be empty !!!');
|
|
|
|
}
|
|
|
|
if (isset($stat['old_name']))
|
|
|
|
{
|
|
|
|
if (!empty($name) && $old_name != $name) // renamed
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
|
|
|
unset($this->status[$typ][$old_name]);
|
|
|
|
|
2006-10-04 19:40:33 +02:00
|
|
|
if ($default == $old_name)
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2006-10-04 19:40:33 +02:00
|
|
|
$default = $name;
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
|
|
|
}
|
2006-10-04 19:40:33 +02:00
|
|
|
elseif (empty($name))
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2006-10-04 19:40:33 +02:00
|
|
|
$name = $old_name;
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
|
|
|
}
|
2006-10-04 19:40:33 +02:00
|
|
|
elseif (empty($name)) // new item and empty ==> ignore it
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2006-10-04 19:40:33 +02:00
|
|
|
continue;
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
2006-10-04 19:40:33 +02:00
|
|
|
$this->status[$typ][$name] = empty($stat['label']) ? $name : $stat['label'];
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
2006-10-04 19:40:33 +02:00
|
|
|
$this->status['defaults'][$typ] = empty($default) ? $name : $default;
|
|
|
|
if (!isset($this->status[$typ][$this->status['defaults'][$typ]]))
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2006-10-04 19:40:33 +02:00
|
|
|
list($this->status['defaults'][$typ]) = @each($this->status[$typ]);
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
2006-10-04 19:40:33 +02:00
|
|
|
}
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2006-10-04 19:40:33 +02:00
|
|
|
function update(&$content)
|
|
|
|
{
|
|
|
|
$this->update_status($content);
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2014-10-23 19:33:03 +02:00
|
|
|
if ($content['content_type_options']['group_owner'])
|
2007-03-12 12:27:33 +01:00
|
|
|
{
|
2014-10-23 19:33:03 +02:00
|
|
|
$this->group_owners[$this->content_type] = $content['content_type_options']['group_owner'];
|
2007-03-12 12:27:33 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-23 19:33:03 +02:00
|
|
|
unset($this->group_owners[$this->content_type]);
|
2007-03-12 12:27:33 +01:00
|
|
|
}
|
2006-10-04 19:40:33 +02:00
|
|
|
// save changes to repository
|
|
|
|
$this->save_repository();
|
|
|
|
}
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2006-10-04 19:40:33 +02:00
|
|
|
function delete(&$content)
|
|
|
|
{
|
|
|
|
if (isset($this->bo->stock_enums['type'][$content['type2']]))
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2006-10-04 19:40:33 +02:00
|
|
|
$content['error_msg'] .= lang("You can't delete one of the stock types !!!");
|
|
|
|
return;
|
|
|
|
}
|
2014-10-23 19:33:03 +02:00
|
|
|
unset($this->content_types[$content['type2']]);
|
2006-10-04 19:40:33 +02:00
|
|
|
unset($this->status[$content['type2']]);
|
|
|
|
unset($this->status['defaults'][$content['type2']]);
|
2010-03-28 17:38:12 +02:00
|
|
|
unset($this->group_owners[$content['type2']]);
|
2014-10-23 19:33:03 +02:00
|
|
|
list($content['type2']) = each($this->content_types);
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2006-10-04 19:40:33 +02:00
|
|
|
// save changes to repository
|
|
|
|
$this->save_repository();
|
|
|
|
}
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2014-11-19 22:15:48 +01:00
|
|
|
function create_content_type(&$content)
|
2006-10-04 19:40:33 +02:00
|
|
|
{
|
2014-11-19 22:15:48 +01:00
|
|
|
$new_name = trim($content['content_types']['name']);
|
|
|
|
if (empty($new_name))
|
2006-10-04 19:40:33 +02:00
|
|
|
{
|
2014-11-19 22:15:48 +01:00
|
|
|
$this->tmpl->set_validation_error('content_types[name]','You have to enter a name, to create a new type!!!');
|
|
|
|
return false;
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
2006-10-04 19:40:33 +02:00
|
|
|
else
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2016-04-30 19:05:23 +02:00
|
|
|
foreach($this->content_types as $name)
|
2014-11-19 22:15:48 +01:00
|
|
|
{
|
|
|
|
if($name == $new_name)
|
|
|
|
{
|
|
|
|
$this->tmpl->set_validation_error('content_types[name]',lang("type '%1' already exists !!!",$new_name));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
2014-11-19 22:15:48 +01:00
|
|
|
$this->content_types[$new_name] = $new_name;
|
|
|
|
$this->status[$new_name] = array(
|
|
|
|
'ongoing' => 'ongoing',
|
|
|
|
'done' => 'done'
|
|
|
|
);
|
|
|
|
$this->status['defaults'][$new_name] = 'ongoing';
|
|
|
|
|
|
|
|
// save changes to repository
|
|
|
|
$this->save_repository();
|
|
|
|
return $new_name;
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
2016-04-30 19:05:23 +02:00
|
|
|
|
2006-10-04 19:40:33 +02:00
|
|
|
function save_repository()
|
|
|
|
{
|
|
|
|
// save changes to repository
|
2016-04-30 19:05:23 +02:00
|
|
|
Api\Config::save_value('types',$this->content_types,'infolog');
|
2008-10-07 14:50:14 +02:00
|
|
|
//echo '<p>'.__METHOD__.'() \$this->status=<pre style="text-aling: left;">'; print_r($this->status); echo "</pre>\n";
|
2016-04-30 19:05:23 +02:00
|
|
|
Api\Config::save_value('status',$this->status,'infolog');
|
2008-10-07 14:50:14 +02:00
|
|
|
//echo '<p>'.__METHOD__.'() \$this->fields=<pre style="text-aling: left;">'; print_r($this->fields); echo "</pre>\n";
|
2016-04-30 19:05:23 +02:00
|
|
|
Api\Storage\Customfields::save('infolog', $this->fields);
|
|
|
|
Api\Config::save_value('group_owners',$this->group_owners,'infolog');
|
2006-10-04 19:40:33 +02:00
|
|
|
}
|
|
|
|
}
|