2006-08-11 22:49:43 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* eTemplate Widget for the historylog
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author RalfBecker-At-outdoor-training.de
|
2011-04-19 17:00:49 +02:00
|
|
|
* @copyright 2006-11 by RalfBecker-At-outdoor-training.de
|
2006-08-11 22:49:43 +02:00
|
|
|
* @license GPL - GNU General Public License
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This widget shows the historylog for one entry of an application
|
|
|
|
*
|
|
|
|
* It takes as parameter either just the id or an array with the following keys:
|
|
|
|
* - 'id' integer id of the entry
|
|
|
|
* - 'app' string app-name, defaults to $GLOBALS['egw_info']['flags']['currentapp']
|
|
|
|
* - 'status-widgets' array with status-values as key and widget names or array with select-options as value,
|
|
|
|
* all not set stati are displayed via a label-widget - just as text
|
2011-04-19 17:00:49 +02:00
|
|
|
* widget types for custom fields do NOT need to be added, they are automatically detected!
|
2006-08-11 22:49:43 +02:00
|
|
|
* You can set $sel_options['status'] to translate the status-values to meaningful labels.
|
2009-08-21 14:57:12 +02:00
|
|
|
* If status is already used for a field, you can also set options to an other name, eg. 'labels' or 'fields'
|
|
|
|
*
|
|
|
|
* If you have a 1:N relation the 'status-widget' entry should be an array with widget types as values (corresponding
|
|
|
|
* to order and fields used in bo_tracking's field2history array).
|
2008-06-03 08:22:35 +02:00
|
|
|
*
|
2006-08-11 22:49:43 +02:00
|
|
|
* @package etemplate
|
|
|
|
* @subpackage extensions
|
|
|
|
* @author RalfBecker-At-outdoor-training.de
|
|
|
|
*/
|
|
|
|
class historylog_widget
|
|
|
|
{
|
2008-06-03 08:22:35 +02:00
|
|
|
/**
|
2006-08-11 22:49:43 +02:00
|
|
|
* @var array exported methods of this class
|
|
|
|
*/
|
|
|
|
var $public_functions = array(
|
|
|
|
'pre_process' => True,
|
|
|
|
);
|
|
|
|
/**
|
|
|
|
* @var array/string availible extensions and there names for the editor
|
|
|
|
*/
|
|
|
|
var $human_name = array(
|
|
|
|
'historylog' => 'History Log',
|
|
|
|
// 'historylog-helper' => '',
|
|
|
|
);
|
2008-06-03 08:22:35 +02:00
|
|
|
|
2009-08-21 14:57:12 +02:00
|
|
|
/**
|
|
|
|
* pre-processing of the history logging extension
|
|
|
|
*
|
|
|
|
* @param string $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
|
2011-04-19 17:00:49 +02:00
|
|
|
* @param etemplate $tmpl reference to the template we belong too
|
2009-08-21 14:57:12 +02:00
|
|
|
* @return boolean true if extra label is allowed, false otherwise
|
|
|
|
*/
|
2011-04-19 17:00:49 +02:00
|
|
|
function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,etemplate $tmpl)
|
2006-08-11 22:49:43 +02:00
|
|
|
{
|
2009-08-21 14:57:12 +02:00
|
|
|
static $status_widgets;
|
2006-08-11 22:49:43 +02:00
|
|
|
|
|
|
|
if ($cell['type'] == 'historylog-helper')
|
|
|
|
{
|
2009-08-21 14:57:12 +02:00
|
|
|
if (empty($value) && (string)$value !== '0')
|
|
|
|
{
|
|
|
|
$cell = etemplate::empty_cell();
|
|
|
|
return true;
|
|
|
|
}
|
2006-08-11 22:49:43 +02:00
|
|
|
//echo $value.'/'.$cell['size']; _debug_array($status_widgets);
|
2009-08-21 14:57:12 +02:00
|
|
|
$type = isset($status_widgets[$cell['size']]) ? $status_widgets[$cell['size']] : 'label';
|
2009-08-26 19:09:07 +02:00
|
|
|
$options = '';
|
|
|
|
if (!is_array($type) && strpos($type,':') !== false)
|
|
|
|
{
|
|
|
|
list($type,$options) = explode(':',$type,2);
|
|
|
|
}
|
2011-02-18 19:27:01 +01:00
|
|
|
// For all select-cats, show missing entries as IDs
|
2011-03-10 14:08:29 +01:00
|
|
|
if($type == 'select-cat')
|
|
|
|
{
|
|
|
|
list($rows,$type1,$type2,$type3,$type4,$type5,$type6) = explode(',',$options);
|
2011-08-04 16:00:15 +02:00
|
|
|
$type6 = 2;
|
2011-02-18 19:27:01 +01:00
|
|
|
$options = implode(',',array($rows,$type1,$type2,$type3,$type4,$type5,$type6));
|
|
|
|
}
|
2009-08-26 19:09:07 +02:00
|
|
|
$cell = etemplate::empty_cell($type,$cell['name'],array('readonly' => true,'size' => $options));
|
2009-08-21 14:57:12 +02:00
|
|
|
if (is_array($type))
|
2006-08-11 22:49:43 +02:00
|
|
|
{
|
2011-08-04 16:00:15 +02:00
|
|
|
list($t) = explode(':',$type[0]);
|
2010-08-27 18:11:02 +02:00
|
|
|
if (isset($type[0]) && // numeric indexed array --> multiple values of 1:N releation
|
2011-08-04 16:00:15 +02:00
|
|
|
$tmpl->widgetExists($t))
|
2009-08-21 14:57:12 +02:00
|
|
|
{
|
|
|
|
$cell['type'] = 'vbox';
|
|
|
|
$cell['size'] = '0,,0,0';
|
|
|
|
$value = explode(bo_tracking::ONE2N_SEPERATOR,$value);
|
|
|
|
foreach($type as $n => $t)
|
|
|
|
{
|
2009-10-14 21:00:16 +02:00
|
|
|
$opt = '';
|
2010-05-15 15:44:42 +02:00
|
|
|
if(is_array($t))
|
|
|
|
{
|
2010-02-12 19:34:33 +01:00
|
|
|
$sel_options = $t;
|
|
|
|
$t = 'select';
|
|
|
|
}
|
2010-05-15 15:44:42 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
list($t,$opt) = explode(':',$t);
|
|
|
|
}
|
2009-10-14 21:00:16 +02:00
|
|
|
$child = etemplate::empty_cell($t,$cell['name']."[$n]",array('readonly' => true,'no_lang' => true,'size' => $opt));
|
2010-02-12 19:34:33 +01:00
|
|
|
$child['sel_options'] = $sel_options;
|
2009-08-21 14:57:12 +02:00
|
|
|
etemplate::add_child($cell,$child);
|
2010-02-12 19:34:33 +01:00
|
|
|
unset($sel_options);
|
2009-08-21 14:57:12 +02:00
|
|
|
unset($child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$cell['sel_options'] = $cell['type'];
|
|
|
|
$cell['type'] = 'select';
|
|
|
|
}
|
2006-08-11 22:49:43 +02:00
|
|
|
}
|
2011-06-16 17:14:14 +02:00
|
|
|
// For all times, show time in user time
|
|
|
|
elseif ($type == 'date-time' && $value)
|
|
|
|
{
|
|
|
|
$value = egw_time::server2user($value);
|
|
|
|
}
|
2006-08-11 22:49:43 +02:00
|
|
|
if ($cell['type'] == 'label') $cell['no_lang'] = 'true';
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
$app = is_array($value) ? $value['app'] : $GLOBALS['egw_info']['flags']['currentapp'];
|
|
|
|
$status_widgets = is_array($value) && isset($value['status-widgets']) ? $value['status-widgets'] : null;
|
2011-04-19 17:00:49 +02:00
|
|
|
|
2006-08-11 22:49:43 +02:00
|
|
|
$id = is_array($value) ? $value['id'] : $value;
|
2010-02-12 19:34:33 +01:00
|
|
|
$filter = is_array($value) ? $value['filter'] : array();
|
2008-06-03 08:22:35 +02:00
|
|
|
|
2009-06-08 18:21:14 +02:00
|
|
|
$historylog = new historylog($app);
|
2006-08-11 22:49:43 +02:00
|
|
|
if (!$id || method_exists($historylog,'search'))
|
|
|
|
{
|
2010-02-12 19:34:33 +01:00
|
|
|
$value = $id ? $historylog->search($filter ? array('history_record_id'=>$id) + $filter : $id) : false;
|
2006-08-11 22:49:43 +02:00
|
|
|
}
|
|
|
|
unset($historylog);
|
|
|
|
|
2009-06-08 18:21:14 +02:00
|
|
|
$tpl = new etemplate;
|
2006-08-11 22:49:43 +02:00
|
|
|
$tpl->init('*** generated fields for historylog','','',0,'',0,0); // make an empty template
|
|
|
|
// keep the editor away from the generated tmpls
|
|
|
|
$tpl->no_onclick = true;
|
|
|
|
|
|
|
|
// header rows
|
|
|
|
$tpl->new_cell(1,'label','Date');
|
|
|
|
$tpl->new_cell(1,'label','User');
|
|
|
|
$tpl->new_cell(1,'label','Changed');
|
|
|
|
$tpl->new_cell(1,'label','New value');
|
|
|
|
$tpl->new_cell(1,'label','Old value');
|
2008-06-03 08:22:35 +02:00
|
|
|
|
2009-08-21 14:57:12 +02:00
|
|
|
$status = 'status';
|
|
|
|
// allow to set a diffent name for status (field-name), eg. because status is already used for something else
|
2010-04-27 12:37:50 +02:00
|
|
|
if (!empty($cell['size']) && isset($tmpl->sel_options[$cell['size']]) && is_array($value))
|
2009-08-21 14:57:12 +02:00
|
|
|
{
|
|
|
|
$status = $cell['size'];
|
|
|
|
foreach($value as &$row)
|
|
|
|
{
|
|
|
|
$row[$status] = $row['status'];
|
|
|
|
}
|
|
|
|
}
|
2011-04-19 17:00:49 +02:00
|
|
|
// adding custom fields automatically to status-widgets, no need for each app to do that
|
|
|
|
foreach(config::get_customfields($app,true) as $cf_name => $cf_data)
|
|
|
|
{
|
|
|
|
// add cf label, if not set by app
|
|
|
|
if (!isset($tmpl->sel_options[$status]['#'.$cf_name]))
|
|
|
|
{
|
|
|
|
$tmpl->sel_options[$status]['#'.$cf_name] = lang($cf_data['label']);
|
|
|
|
}
|
|
|
|
if (isset($status_widgets['#'.$cf_name])) continue; // app set a status widget --> use that
|
|
|
|
|
2011-04-19 20:50:23 +02:00
|
|
|
if(!is_array($cf_data['values']) || !$cf_data['values'])
|
2011-04-19 17:00:49 +02:00
|
|
|
{
|
2011-04-19 20:50:23 +02:00
|
|
|
$status_widgets['#'.$cf_name] = $cf_data['type'] != 'text' ? $cf_data['type'] : 'label';
|
2011-04-19 17:00:49 +02:00
|
|
|
}
|
|
|
|
elseif($cf_data['values']['@'])
|
|
|
|
{
|
|
|
|
$status_widgets['#'.$cf_name] = customfields_widget::_get_options_from_file($cf_data['values']['@']);
|
|
|
|
}
|
|
|
|
elseif(count($cf_data['values']))
|
|
|
|
{
|
|
|
|
$status_widgets['#'.$cf_name] = $cf_data['values'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-11 22:49:43 +02:00
|
|
|
if ($value) // autorepeated data-row only if there is data
|
|
|
|
{
|
|
|
|
$tpl->new_cell(2,'date-time','','${row}[user_ts]',array('readonly' => true));
|
|
|
|
$tpl->new_cell(2,'select-account','','${row}[owner]',array('readonly' => true));
|
2009-08-21 14:57:12 +02:00
|
|
|
|
|
|
|
|
2006-08-11 22:49:43 +02:00
|
|
|
// if $sel_options[status] is set, use them and a readonly selectbox
|
2009-08-21 14:57:12 +02:00
|
|
|
if (isset($tmpl->sel_options[$status]))
|
2006-08-11 22:49:43 +02:00
|
|
|
{
|
2009-08-21 14:57:12 +02:00
|
|
|
$tpl->new_cell(2,'select','','${row}['.$status.']',array('readonly' => true));
|
2006-08-11 22:49:43 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$tpl->new_cell(2,'label','','${row}[status]',array('no_lang' => true));
|
|
|
|
}
|
2008-06-03 08:22:35 +02:00
|
|
|
// if $value[status-widgets] is set, use them together with the historylog-helper
|
2006-08-11 22:49:43 +02:00
|
|
|
// to display new_ & old_value in the specified widget, otherwise use a label
|
|
|
|
if ($status_widgets)
|
|
|
|
{
|
|
|
|
$tpl->new_cell(2,'historylog-helper','','${row}[new_value]',array('size' => '$row_cont[status]','no_lang' => true,'readonly' => true));
|
|
|
|
$tpl->new_cell(2,'historylog-helper','','${row}[old_value]',array('size' => '$row_cont[status]','no_lang' => true,'readonly' => true));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$tpl->new_cell(2,'label','','${row}[new_value]',array('no_lang' => true));
|
|
|
|
$tpl->new_cell(2,'label','','${row}[old_value]',array('no_lang' => true));
|
|
|
|
}
|
|
|
|
array_unshift($value,false); // addjust index to start with 1, as we have a header-row
|
|
|
|
}
|
|
|
|
$tpl->data[0] = array(
|
|
|
|
'c1' => 'th',
|
|
|
|
'c2' => 'row',
|
|
|
|
);
|
|
|
|
$tpl->size = '100%';
|
|
|
|
|
|
|
|
$cell['size'] = $cell['name'];
|
|
|
|
$cell['type'] = 'template';
|
|
|
|
$cell['name'] = $tpl->name;
|
|
|
|
$cell['obj'] = &$tpl;
|
|
|
|
|
|
|
|
return True; // extra Label is ok
|
|
|
|
}
|
|
|
|
}
|