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
|
2014-07-08 15:52:48 +02:00
|
|
|
* @copyright (c) 2003-14 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
|
|
|
|
2006-10-04 19:40:33 +02:00
|
|
|
/**
|
|
|
|
* Administration of custom fields, type and status
|
|
|
|
*/
|
2008-10-07 14:50:14 +02:00
|
|
|
class infolog_customfields
|
2006-10-04 19:40:33 +02:00
|
|
|
{
|
|
|
|
var $public_functions = array(
|
2013-01-31 00:12:52 +01:00
|
|
|
'edit' => True,
|
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 etemplate class
|
|
|
|
*
|
|
|
|
* @var etemplate
|
|
|
|
*/
|
|
|
|
var $tmpl;
|
|
|
|
/**
|
|
|
|
* instance of the config class for infolog
|
2008-10-07 14:50:14 +02:00
|
|
|
*
|
2006-10-04 19:40:33 +02:00
|
|
|
* @var config
|
|
|
|
*/
|
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
|
|
|
{
|
2008-10-07 14:50:14 +02:00
|
|
|
$this->bo = new infolog_bo();
|
2013-09-19 14:52:50 +02:00
|
|
|
$this->tmpl = new etemplate_new();
|
2006-10-04 19:40:33 +02:00
|
|
|
$this->types = &$this->bo->enums['type'];
|
|
|
|
$this->status = &$this->bo->status;
|
2008-01-25 13:13:04 +01:00
|
|
|
$this->config_data = 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;
|
2006-10-04 19:40:33 +02:00
|
|
|
}
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2006-10-04 19:40:33 +02:00
|
|
|
/**
|
|
|
|
* Edit/Create an InfoLog Custom fields, typ and status
|
|
|
|
*
|
|
|
|
* @param array $content Content from the eTemplate Exec
|
|
|
|
*/
|
|
|
|
function edit($content=null)
|
|
|
|
{
|
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] = lang('InfoLog').' - '.lang('Custom fields, typ and status');
|
|
|
|
if (is_array($content))
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2006-10-04 19:40:33 +02:00
|
|
|
//echo '<pre style="text-align: left;">'; print_r($content); echo "</pre>\n";
|
|
|
|
list($action) = @each($content['button']);
|
|
|
|
switch($action)
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2006-10-04 19:40:33 +02:00
|
|
|
case 'create':
|
|
|
|
$this->create($content);
|
|
|
|
break;
|
|
|
|
case 'delete':
|
|
|
|
$this->delete($content);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!$content['status']['create'] && !$content['status']['delete'] &&
|
|
|
|
!$content['fields']['create'] && !$content['fields']['delete'])
|
|
|
|
{
|
|
|
|
break; // typ change
|
|
|
|
}
|
|
|
|
case 'save':
|
|
|
|
case 'apply':
|
|
|
|
$this->update($content);
|
|
|
|
if ($action != 'save')
|
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
break;
|
2006-10-04 19:40:33 +02:00
|
|
|
}
|
2014-07-08 15:52:48 +02:00
|
|
|
// fall through
|
2006-10-04 19:40:33 +02:00
|
|
|
case 'cancel':
|
2014-09-22 18:23:02 +02:00
|
|
|
egw::redirect_link('/index.php', array(
|
|
|
|
'menuaction' => 'admin.admin_ui.index',
|
|
|
|
'ajax' => 'true'
|
|
|
|
), 'admin');
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
2006-10-04 19:40:33 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
list($typ) = each($this->types);
|
|
|
|
$content = array(
|
|
|
|
'type2' => $typ,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$readonlys = array();
|
|
|
|
$readonlys['button[delete]'] = 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['status'] = array(
|
|
|
|
'default' => $this->status['defaults'][$content['type2']]
|
|
|
|
);
|
|
|
|
$n = 0;
|
|
|
|
foreach($this->status[$content['type2']] as $name => $label)
|
|
|
|
{
|
|
|
|
$content['status'][++$n] = array(
|
|
|
|
'name' => $name,
|
|
|
|
'label' => $label,
|
|
|
|
'disabled' => False
|
2003-08-28 16:31:11 +02:00
|
|
|
);
|
2006-10-04 19:40:33 +02:00
|
|
|
$preserv_status[$n]['old_name'] = $name;
|
|
|
|
if (isset($this->bo->stock_status[$content['type2']][$name]))
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2006-10-04 19:40:33 +02:00
|
|
|
$readonlys['status']["delete[$name]"] =
|
|
|
|
$readonlys['status'][$n.'[name]'] = True;
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
2006-10-04 19:40:33 +02:00
|
|
|
$readonlys['status']["create$name"] = True;
|
|
|
|
}
|
|
|
|
$content['status'][++$n] = array('name'=>''); // new line for create
|
|
|
|
$readonlys['status']["delete[]"] = True;
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2006-10-04 19:40:33 +02:00
|
|
|
//echo 'customfields=<pre style="text-align: left;">'; print_r($this->fields); echo "</pre>\n";
|
|
|
|
$content['fields'] = array();
|
|
|
|
$n = 0;
|
|
|
|
foreach($this->fields as $name => $field)
|
|
|
|
{
|
|
|
|
if (is_array($field['values']))
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2006-10-04 19:40:33 +02:00
|
|
|
$values = '';
|
|
|
|
foreach($field['values'] as $var => $value)
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2006-10-04 19:40:33 +02:00
|
|
|
$values .= (!empty($values) ? "\n" : '').$var.'='.$value;
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
2006-10-04 19:40:33 +02:00
|
|
|
$field['values'] = $values;
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
2006-11-23 15:20:48 +01:00
|
|
|
if (!$field['type2']) $field['type2']=''; // multiselect returns NULL for nothing selected (=All) which stops the autorepeat
|
2006-10-04 19:40:33 +02:00
|
|
|
$content['fields'][++$n] = $field + array(
|
|
|
|
'name' => $name
|
|
|
|
);
|
|
|
|
$preserv_fields[$n]['old_name'] = $name;
|
|
|
|
$readonlys['fields']["create$name"] = True;
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
2006-10-04 19:40:33 +02:00
|
|
|
$content['fields'][++$n] = array('type2'=>'','order' => 10 * $n); // new line for create
|
|
|
|
$readonlys['fields']["delete[]"] = True;
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2007-03-12 12:27:33 +01:00
|
|
|
$content['group_owner'] = $this->group_owners[$content['type2']];
|
2006-10-04 19:40:33 +02:00
|
|
|
|
2008-10-07 14:50:14 +02:00
|
|
|
//echo '<p>'.__METHOD__'.(content = <pre style="text-align: left;">'; print_r($content); echo "</pre>\n";
|
2006-10-04 19:40:33 +02:00
|
|
|
//echo 'readonlys = <pre style="text-align: left;">'; print_r($readonlys); echo "</pre>\n";
|
|
|
|
$this->tmpl->read('infolog.customfields');
|
2008-10-07 14:50:14 +02:00
|
|
|
$this->tmpl->exec('infolog.infolog_customfields.edit',$content,array(
|
2006-10-04 19:40:33 +02:00
|
|
|
'type2' => $this->types,
|
|
|
|
),$readonlys,array(
|
|
|
|
'status' => $preserv_status,
|
|
|
|
'fields' => $preserv_fields,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
function update_fields(&$content)
|
|
|
|
{
|
|
|
|
$typ = $content['type2'];
|
|
|
|
$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
|
|
|
{
|
2009-06-08 18:21:14 +02:00
|
|
|
list($var,$value) = explode('=',trim($line),2);
|
2006-10-04 19:40:33 +02:00
|
|
|
$var = trim($var);
|
|
|
|
$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;
|
|
|
|
foreach($this->fields as $name => $data)
|
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)
|
|
|
|
{
|
|
|
|
$typ = $content['type2'];
|
|
|
|
$status = &$content['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);
|
|
|
|
$this->update_fields($content);
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2007-03-12 12:27:33 +01:00
|
|
|
if ($content['group_owner'])
|
|
|
|
{
|
|
|
|
$this->group_owners[$content['type2']] = $content['group_owner'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unset($this->group_owners[$content['type2']]);
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
unset($this->types[$content['type2']]);
|
|
|
|
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']]);
|
2006-10-04 19:40:33 +02:00
|
|
|
list($content['type2']) = each($this->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
|
|
|
|
2006-10-04 19:40:33 +02:00
|
|
|
function create(&$content)
|
|
|
|
{
|
|
|
|
$new_name = trim($content['new_name']);
|
|
|
|
unset($content['new_name']);
|
|
|
|
if (empty($new_name) || isset($this->types[$new_name]))
|
|
|
|
{
|
|
|
|
$content['error_msg'] .= empty($new_name) ?
|
|
|
|
lang('You have to enter a name, to create a new typ!!!') :
|
|
|
|
lang("Typ '%1' already exists !!!",$new_name);
|
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
|
|
|
{
|
2006-10-04 19:40:33 +02:00
|
|
|
$this->types[$new_name] = $new_name;
|
|
|
|
$this->status[$new_name] = array(
|
|
|
|
'ongoing' => 'ongoing',
|
|
|
|
'done' => 'done'
|
|
|
|
);
|
|
|
|
$this->status['defaults'][$new_name] = 'ongoing';
|
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
// save changes to repository
|
2006-10-04 19:40:33 +02:00
|
|
|
$this->save_repository();
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2006-10-04 19:40:33 +02:00
|
|
|
$content['type2'] = $new_name; // show the new entry
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
|
|
|
}
|
2006-10-04 19:40:33 +02:00
|
|
|
function save_repository()
|
|
|
|
{
|
|
|
|
// save changes to repository
|
2008-01-25 13:13:04 +01:00
|
|
|
config::save_value('types',$this->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";
|
2008-01-25 13:13:04 +01:00
|
|
|
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";
|
2014-06-23 16:35:22 +02:00
|
|
|
egw_customfields::save('infolog', $this->fields);
|
2008-01-25 13:13:04 +01:00
|
|
|
config::save_value('group_owners',$this->group_owners,'infolog');
|
2006-10-04 19:40:33 +02:00
|
|
|
}
|
|
|
|
}
|