2006-10-04 22:23:44 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* eGroupWare eTemplate Extension - Contact 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$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eTemplate Extension: Contact widget
|
|
|
|
*
|
|
|
|
* This widget can be used to fetch fields of a contact specified by contact-id
|
|
|
|
*/
|
|
|
|
class contact_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(
|
|
|
|
'contact-value' => 'Contact',
|
2006-10-26 12:57:47 +02:00
|
|
|
'contact-account'=> 'Account contactdata',
|
2006-10-04 22:23:44 +02:00
|
|
|
'contact-fields' => 'Contact fields',
|
|
|
|
);
|
|
|
|
/**
|
|
|
|
* Instance of the contacts class
|
|
|
|
*
|
|
|
|
* @var contacts
|
|
|
|
*/
|
|
|
|
var $contacts;
|
|
|
|
/**
|
|
|
|
* Cached contact
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $contact;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor of the extension
|
|
|
|
*
|
|
|
|
* @param string $ui '' for html
|
|
|
|
*/
|
|
|
|
function contact_widget($ui)
|
|
|
|
{
|
|
|
|
$this->ui = $ui;
|
|
|
|
if (!is_object($GLOBALS['egw']->contacts))
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->contacts =& CreateObject('phpgwapi.contacts');
|
|
|
|
}
|
|
|
|
$this->contacts =& $GLOBALS['egw']->contacts;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 'contact-fields':
|
2006-10-05 10:05:25 +02:00
|
|
|
$GLOBALS['egw']->translation->add_app('addressbook');
|
|
|
|
$this->contacts->contacts();
|
2006-10-04 22:23:44 +02:00
|
|
|
$cell['sel_options'] = $this->contacts->contact_fields;
|
2007-08-20 09:52:42 +02:00
|
|
|
foreach($this->contacts->customfields as $name => $data)
|
|
|
|
{
|
|
|
|
$cell['sel_options']['#'.$name] = $data['label'];
|
|
|
|
}
|
2006-10-04 22:23:44 +02:00
|
|
|
$cell['type'] = 'select';
|
|
|
|
$cell['no_lang'] = 1;
|
2007-09-06 13:15:12 +02:00
|
|
|
$cell['size'] = 'None';
|
2006-10-04 22:23:44 +02:00
|
|
|
break;
|
|
|
|
|
2006-10-26 12:57:47 +02:00
|
|
|
case 'contact-account':
|
|
|
|
$value = 'account:'.$value;
|
|
|
|
// fall-throught
|
2006-10-04 22:23:44 +02:00
|
|
|
case 'contact-value':
|
|
|
|
default:
|
2006-10-05 10:05:25 +02:00
|
|
|
if (substr($value,0,12) == 'addressbook:') $value = substr($value,12); // link-entry syntax
|
2006-10-26 12:57:47 +02:00
|
|
|
if (!$value || !$cell['size'] || (!is_array($this->contact) ||
|
2006-10-26 13:09:34 +02:00
|
|
|
!($this->contact['id'] == $value || 'account:'.$this->contact['account_id'] == $value)) &&
|
2006-10-04 22:23:44 +02:00
|
|
|
!($this->contact = $this->contacts->read($value)))
|
|
|
|
{
|
|
|
|
$cell = $tmpl->empty_cell();
|
2006-10-19 20:19:11 +02:00
|
|
|
$value = '';
|
2006-10-04 22:23:44 +02:00
|
|
|
break;
|
|
|
|
}
|
2007-08-20 09:52:42 +02:00
|
|
|
$type = $cell['size'];
|
|
|
|
$value = $this->contact[$type];
|
2006-10-04 22:23:44 +02:00
|
|
|
$cell['size'] = '';
|
|
|
|
$cell['no_lang'] = 1;
|
|
|
|
$cell['readonly'] = true;
|
|
|
|
|
2007-08-20 09:52:42 +02:00
|
|
|
switch($type)
|
2006-10-04 22:23:44 +02:00
|
|
|
{
|
|
|
|
// ToDo: pseudo types like address-label
|
2007-08-20 09:52:42 +02:00
|
|
|
|
|
|
|
case 'bday':
|
|
|
|
$cell['type'] = 'date';
|
|
|
|
$cell['size'] = 'Y-m-d';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'owner':
|
|
|
|
case 'modifier':
|
|
|
|
case 'creator':
|
|
|
|
$cell['type'] = 'select-account';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'modified':
|
|
|
|
case 'created':
|
|
|
|
$cell['type'] = 'date-time';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'cat_id':
|
|
|
|
$cell['type'] = 'select-cat';
|
|
|
|
break;
|
2006-10-04 22:23:44 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
$cell['type'] = 'label';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return True; // extra label ok
|
|
|
|
}
|
|
|
|
}
|