mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-22 06:30:59 +01:00
widget to fetch infolog fields from linked infolog, eg. for advanced infolog forms (has also the ability to print an X if a compare value is given or to specify alternative fields if the original one is empty)
This commit is contained in:
parent
fde08a961d
commit
30bf7c6f06
231
infolog/inc/class.infolog_widget.inc.php
Normal file
231
infolog/inc/class.infolog_widget.inc.php
Normal file
@ -0,0 +1,231 @@
|
||||
<?php
|
||||
/**
|
||||
* eGroupWare eTemplate Extension - InfoLog Widget
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @package etemplate
|
||||
* @subpackage extensions
|
||||
* @link http://www.egroupware.org
|
||||
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
require_once(EGW_INCLUDE_ROOT.'/infolog/inc/class.boinfolog.inc.php');
|
||||
|
||||
/**
|
||||
* eTemplate Extension: InfoLog widget
|
||||
*
|
||||
* This widget can be used to display data from an InfoLog specified by it's id
|
||||
*
|
||||
* The infolog-value widget takes 3 comma-separated arguments (beside the name) in the options/size field:
|
||||
* 1) name of the field (as provided by the infolog-fields widget)
|
||||
* 2) an optional compare value: if given the selected field is compared with its value and an X is printed on equality, nothing otherwise
|
||||
* 3) colon (:) separted list of alternative fields: the first non-empty one is used if the selected value is empty
|
||||
* There's a special field "sum" in 1), which sums up all fields given in alternatives.
|
||||
*/
|
||||
class infolog_widget
|
||||
{
|
||||
/**
|
||||
* exported methods of this class
|
||||
*
|
||||
* @var array $public_functions
|
||||
*/
|
||||
var $public_functions = array(
|
||||
'pre_process' => True,
|
||||
);
|
||||
/**
|
||||
* availible extensions and there names for the editor
|
||||
*
|
||||
* @var string/array $human_name
|
||||
*/
|
||||
var $human_name = array(
|
||||
'infolog-value' => 'InfoLog',
|
||||
'infolog-fields' => 'InfoLog fields',
|
||||
);
|
||||
/**
|
||||
* Instance of the boinfolog class
|
||||
*
|
||||
* @var boinfolog
|
||||
*/
|
||||
var $infolog;
|
||||
/**
|
||||
* Cached infolog
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
||||
/**
|
||||
* Constructor of the extension
|
||||
*
|
||||
* @param string $ui '' for html
|
||||
*/
|
||||
function infolog_widget($ui)
|
||||
{
|
||||
$this->ui = $ui;
|
||||
$this->infolog =& new boinfolog();
|
||||
}
|
||||
|
||||
/**
|
||||
* pre-processing of the extension
|
||||
*
|
||||
* This function is called before the extension gets rendered
|
||||
*
|
||||
* @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
|
||||
* @param etemplate &$tmpl reference to the template we belong too
|
||||
* @return boolean true if extra label is allowed, false otherwise
|
||||
*/
|
||||
function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
|
||||
{
|
||||
switch($cell['type'])
|
||||
{
|
||||
case 'infolog-fields':
|
||||
$GLOBALS['egw']->translation->add_app('addressbook');
|
||||
$cell['sel_options'] = $this->_get_info_fields();
|
||||
$cell['type'] = 'select';
|
||||
$cell['no_lang'] = 1;
|
||||
break;
|
||||
|
||||
case 'infolog-value':
|
||||
default:
|
||||
if (substr($value,0,8) == 'infolog:') $value = substr($value,8); // link-entry syntax
|
||||
if (!$value || !$cell['size'] || (!is_array($this->info) || $this->info['info_id'] != $value) &&
|
||||
!($this->info = $this->infolog->read($value)))
|
||||
{
|
||||
$cell = $tmpl->empty_cell();
|
||||
$value = '';
|
||||
break;
|
||||
}
|
||||
list($type,$compare,$alternatives) = explode(',',$cell['size']);
|
||||
$value = $this->info[$type];
|
||||
$cell['size'] = '';
|
||||
$cell['no_lang'] = 1;
|
||||
$cell['readonly'] = true;
|
||||
|
||||
switch($type)
|
||||
{
|
||||
case '': // Sum of the alternatives
|
||||
$cell['type'] = 'float';
|
||||
$cell['size'] = ',,,2';
|
||||
$value = 0.0;
|
||||
foreach(explode(':',$alternatives) as $name)
|
||||
{
|
||||
$value += str_replace(array(' ',','),array('','.'),$this->info[$name]);
|
||||
}
|
||||
$alternatives = '';
|
||||
break;
|
||||
|
||||
case 'info_startdate':
|
||||
case 'info_datemodified':
|
||||
case 'info_datecompleted':
|
||||
$cell['type'] = 'date-time';
|
||||
break;
|
||||
|
||||
case 'info_enddate':
|
||||
$cell['type'] = 'date';
|
||||
break;
|
||||
|
||||
case 'info_owner':
|
||||
case 'info_responsible':
|
||||
$cell['type'] = 'select-owner';
|
||||
break;
|
||||
|
||||
case 'info_cat':
|
||||
$cell['type'] = 'select-cat';
|
||||
break;
|
||||
|
||||
case 'info_access':
|
||||
$cell['type'] = 'select-access';
|
||||
break;
|
||||
|
||||
case 'info_type':
|
||||
case 'info_priority':
|
||||
case 'info_confirm':
|
||||
$cell['sel_options'] = $this->infolog->enums[$type];
|
||||
$cell['type'] = 'select';
|
||||
break;
|
||||
|
||||
case 'info_status':
|
||||
$cell['sel_options'] = $this->infolog->status[$this->info['info_type']];
|
||||
$cell['type'] = 'select';
|
||||
break;
|
||||
|
||||
default:
|
||||
if ($type{0} == '#') // custom field --> use field-type itself
|
||||
{
|
||||
$field = $this->infolog->customfields[substr($type,1)];
|
||||
if (($cell['type'] = $field['type'])) break;
|
||||
}
|
||||
$cell['type'] = 'label';
|
||||
break;
|
||||
}
|
||||
if ($alternatives && empty($value)) // use first non-empty alternative if value is empty
|
||||
{
|
||||
foreach(explode(':',$alternatives) as $name)
|
||||
{
|
||||
if (($value = $this->info[$name])) break;
|
||||
}
|
||||
}
|
||||
if (!empty($compare)) // compare with value and print a X is equal and nothing otherwise
|
||||
{
|
||||
$value = $value == $compare ? 'X' : '';
|
||||
$cell['type'] = 'label';
|
||||
}
|
||||
break;
|
||||
}
|
||||
return True; // extra label ok
|
||||
}
|
||||
|
||||
function _get_info_fields()
|
||||
{
|
||||
static $fields;
|
||||
|
||||
if (!is_null($fields)) return $fields;
|
||||
|
||||
$fields = array(
|
||||
'' => lang('Sum'),
|
||||
'info_type' => lang('Type'),
|
||||
'info_subject' => lang('Subject'),
|
||||
'info_des' => lang('Description'),
|
||||
'info_cat' => lang('Category'),
|
||||
'info_from' => lang('Contact'),
|
||||
'info_addr' => lang('Phone/Email'),
|
||||
'info_responsible' => lang('Responsible'),
|
||||
'info_startdate' => lang('Startdate'),
|
||||
'info_enddate' => lang('Enddate'),
|
||||
'info_status' => lang('Status'),
|
||||
'info_priority' => lang('Priority'),
|
||||
'info_location' => lang('Location'),
|
||||
'info_percent' => lang('Completed'),
|
||||
'info_datecompleted' => lang('Date completed'),
|
||||
// meta data
|
||||
// PM fields
|
||||
'info_planned_time' => lang('planned time'),
|
||||
'info_used_time' => lang('used time'),
|
||||
'pl_id' => lang('Pricelist'),
|
||||
'info_price' => lang('Price'),
|
||||
// other
|
||||
'info_owner' => lang('Owner'),
|
||||
'info_access' => lang('Access'),
|
||||
'info_id' => lang('Id#'),
|
||||
'info_link_id' => lang('primary link'),
|
||||
'info_modifier' => lang('Modifierer'),
|
||||
'info_datemodified' => lang('Last modified'),
|
||||
// 'info_id_parent' => lang('Parent'),
|
||||
// 'info_confirm' => lang('Confirm'),
|
||||
// 'info_custom_from' => lang('Custom from'),
|
||||
|
||||
);
|
||||
if ($this->infolog->customfields)
|
||||
{
|
||||
foreach($this->infolog->customfields as $name => $data)
|
||||
{
|
||||
$fields['#'.$name] = lang($data['label']);
|
||||
}
|
||||
}
|
||||
return $fields;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user