2002-10-02 02:44:33 +02:00
|
|
|
<?php
|
2006-04-20 19:12:30 +02:00
|
|
|
/**
|
|
|
|
* eGroupWare eTemplate Extension - Select Widgets
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
2002-10-02 02:44:33 +02:00
|
|
|
|
2005-02-18 23:44:42 +01:00
|
|
|
/**
|
|
|
|
* eTemplate Extension: several select-boxes with predefined eGW specific content
|
|
|
|
*
|
2006-07-07 00:55:30 +02:00
|
|
|
* This widgets replaces the not longer exiting phpgwapi.sbox class. The widgets are independent of the UI,
|
2005-02-18 23:44:42 +01:00
|
|
|
* as they only uses etemplate-widgets and therefor have no render-function.
|
|
|
|
*
|
|
|
|
* @package etemplate
|
|
|
|
* @subpackage extensions
|
|
|
|
* @author RalfBecker-AT-outdoor-training.de
|
|
|
|
* @license GPL
|
|
|
|
*/
|
2002-10-02 02:44:33 +02:00
|
|
|
class select_widget
|
|
|
|
{
|
2005-02-18 23:44:42 +01:00
|
|
|
/**
|
|
|
|
* exported methods of this class
|
|
|
|
* @var array
|
|
|
|
*/
|
2002-10-02 02:44:33 +02:00
|
|
|
var $public_functions = array(
|
2004-10-07 23:58:33 +02:00
|
|
|
'pre_process' => True,
|
|
|
|
'post_process' => True,
|
2002-10-02 02:44:33 +02:00
|
|
|
);
|
2005-02-18 23:44:42 +01:00
|
|
|
/**
|
|
|
|
* availible extensions and there names for the editor
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $human_name = array(
|
2002-10-02 02:44:33 +02:00
|
|
|
'select-percent' => 'Select Percentage',
|
|
|
|
'select-priority' => 'Select Priority',
|
|
|
|
'select-access' => 'Select Access',
|
|
|
|
'select-country' => 'Select Country',
|
|
|
|
'select-state' => 'Select State', // US-states
|
2005-02-18 23:44:42 +01:00
|
|
|
'select-cat' => 'Select Category', // Category-Selection, size: -1=Single+All, 0=Single, >0=Multiple with size lines
|
2002-10-02 02:44:33 +02:00
|
|
|
'select-account' => 'Select Account', // label=accounts(default),groups,both
|
2005-02-18 23:44:42 +01:00
|
|
|
// size: -1=Single+not assigned, 0=Single, >0=Multiple
|
2002-10-03 18:43:26 +02:00
|
|
|
'select-year' => 'Select Year',
|
|
|
|
'select-month' => 'Select Month',
|
2003-03-18 14:06:27 +01:00
|
|
|
'select-day' => 'Select Day',
|
2004-10-07 23:58:33 +02:00
|
|
|
'select-dow' => 'Select Day of week',
|
2006-07-07 00:55:30 +02:00
|
|
|
'select-hour' => 'Select Hour', // either 0-23 or 12am,1am-11am,12pm,1pm-11pm
|
2003-04-13 21:14:50 +02:00
|
|
|
'select-number' => 'Select Number',
|
2003-03-18 14:06:27 +01:00
|
|
|
'select-app' => 'Select Application'
|
2002-10-02 02:44:33 +02:00
|
|
|
);
|
2005-02-18 23:44:42 +01:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2002-10-02 02:44:33 +02:00
|
|
|
var $monthnames = array(
|
|
|
|
0 => '',
|
|
|
|
1 => 'January',
|
|
|
|
2 => 'February',
|
|
|
|
3 => 'March',
|
|
|
|
4 => 'April',
|
|
|
|
5 => 'May',
|
|
|
|
6 => 'June',
|
|
|
|
7 => 'July',
|
|
|
|
8 => 'August',
|
|
|
|
9 => 'September',
|
|
|
|
10 => 'October',
|
|
|
|
11 => 'November',
|
|
|
|
12 => 'December'
|
|
|
|
);
|
|
|
|
|
2005-02-18 23:44:42 +01:00
|
|
|
/**
|
|
|
|
* Constructor of the extension
|
|
|
|
*
|
|
|
|
* @param string $ui '' for html
|
|
|
|
*/
|
2002-10-02 02:44:33 +02:00
|
|
|
function select_widget($ui)
|
|
|
|
{
|
2003-04-13 23:47:35 +02:00
|
|
|
foreach($this->monthnames as $k => $name)
|
|
|
|
{
|
|
|
|
if ($name)
|
|
|
|
{
|
|
|
|
$this->monthnames[$k] = lang($name);
|
|
|
|
}
|
|
|
|
}
|
2004-07-09 20:21:01 +02:00
|
|
|
$this->ui = $ui;
|
2002-10-02 02:44:33 +02:00
|
|
|
}
|
|
|
|
|
2005-02-18 23:44:42 +01:00
|
|
|
/**
|
|
|
|
* 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 object &$tmpl reference to the template we belong too
|
|
|
|
* @return boolean true if extra label is allowed, false otherwise
|
|
|
|
*/
|
2002-10-02 02:44:33 +02:00
|
|
|
function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
|
|
|
|
{
|
2003-04-13 21:14:50 +02:00
|
|
|
list($rows,$type,$type2,$type3) = explode(',',$cell['size']);
|
2002-10-02 02:44:33 +02:00
|
|
|
|
2005-07-14 08:31:05 +02:00
|
|
|
$extension_data['type'] = $cell['type'];
|
2004-10-07 23:58:33 +02:00
|
|
|
|
2006-09-20 15:32:47 +02:00
|
|
|
$readonly = $cell['readonly'] || $readonlys;
|
2002-10-02 02:44:33 +02:00
|
|
|
switch ($cell['type'])
|
|
|
|
{
|
2002-10-03 18:43:26 +02:00
|
|
|
case 'select-percent': // options: #row,decrement(default=10)
|
|
|
|
$decr = $type > 0 ? $type : 10;
|
|
|
|
for ($i=0; $i <= 100; $i += $decr)
|
2002-10-02 02:44:33 +02:00
|
|
|
{
|
2002-10-03 18:43:26 +02:00
|
|
|
$cell['sel_options'][intval($i)] = intval($i).'%';
|
2002-10-02 02:44:33 +02:00
|
|
|
}
|
2002-10-03 18:43:26 +02:00
|
|
|
$cell['sel_options'][100] = '100%';
|
2005-04-15 00:34:13 +02:00
|
|
|
if (!$rows || !empty($value))
|
|
|
|
{
|
|
|
|
$value = intval(($value+($decr/2)) / $decr) * $decr;
|
|
|
|
}
|
2002-10-02 02:44:33 +02:00
|
|
|
$cell['no_lang'] = True;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'select-priority':
|
|
|
|
$cell['sel_options'] = array('','low','normal','high');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'select-access':
|
|
|
|
$cell['sel_options'] = array(
|
|
|
|
'private' => 'Private',
|
|
|
|
'public' => 'Global public',
|
|
|
|
'group' => 'Group public'
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
2006-07-07 00:55:30 +02:00
|
|
|
case 'select-country': // #Row|Extralabel,1=use country name, 0=use 2 letter-code
|
|
|
|
if (!is_object($GLOBALS['egw']->country))
|
2004-06-15 09:50:58 +02:00
|
|
|
{
|
2006-07-07 00:55:30 +02:00
|
|
|
$GLOBALS['egw']->country =& CreateObject('phpgwapi.country');
|
|
|
|
}
|
|
|
|
$cell['sel_options'] = $GLOBALS['egw']->country->countries();
|
|
|
|
|
|
|
|
if (($extension_data['country_use_name'] = $type) && $value)
|
|
|
|
{
|
|
|
|
$value = $GLOBALS['egw']->country->country_code($value);
|
|
|
|
if (!isset($cell['sel_options'][$value]))
|
2004-06-15 09:50:58 +02:00
|
|
|
{
|
2006-07-07 00:55:30 +02:00
|
|
|
$cell['sel_options'][$value] = $value;
|
2004-06-15 09:50:58 +02:00
|
|
|
}
|
|
|
|
}
|
2002-10-02 02:44:33 +02:00
|
|
|
$cell['no_lang'] = True;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'select-state':
|
2006-07-07 00:55:30 +02:00
|
|
|
if (!is_object($GLOBALS['egw']->country))
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->country =& CreateObject('phpgwapi.country');
|
|
|
|
}
|
|
|
|
$cell['sel_options'] = $GLOBALS['egw']->country->us_states();
|
2002-10-02 02:44:33 +02:00
|
|
|
$cell['no_lang'] = True;
|
|
|
|
break;
|
|
|
|
|
2006-03-20 22:51:55 +01:00
|
|
|
case 'select-cat': // !$type == globals cats too, $type2: extraStyleMultiselect
|
2005-11-09 21:50:45 +01:00
|
|
|
if (!is_object($GLOBALS['egw']->categories))
|
2002-10-02 02:44:33 +02:00
|
|
|
{
|
2005-11-09 21:50:45 +01:00
|
|
|
$GLOBALS['egw']->categories =& CreateObject('phpgwapi.categories');
|
2002-10-02 02:44:33 +02:00
|
|
|
}
|
2006-09-20 15:32:47 +02:00
|
|
|
if ($readonly) // for readonly we dont need to fetch all cat's, nor do we need to indent them by level
|
|
|
|
{
|
|
|
|
$cell['no_lang'] = True;
|
|
|
|
foreach(is_array($value) ? $value : (strpos($value,',') !== false ? explode(',',$value) : array($value)) as $id)
|
|
|
|
{
|
|
|
|
if ($id) $cell['sel_options'][$id] = $GLOBALS['egw']->strip_html($GLOBALS['egw']->categories->id2name($id));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2005-11-09 21:50:45 +01:00
|
|
|
foreach((array)$GLOBALS['egw']->categories->return_sorted_array(0,False,'','','',!$type) as $cat)
|
2002-10-02 02:44:33 +02:00
|
|
|
{
|
2005-07-30 14:48:27 +02:00
|
|
|
$s = str_repeat(' ',$cat['level']) . $GLOBALS['egw']->strip_html($cat['name']);
|
|
|
|
|
2005-11-12 00:05:35 +01:00
|
|
|
if ($cat['app_name'] == 'phpgw' || $cat['owner'] == '-1')
|
2002-10-02 02:44:33 +02:00
|
|
|
{
|
2005-11-12 00:05:35 +01:00
|
|
|
$s .= ' ♦';
|
2002-10-02 02:44:33 +02:00
|
|
|
}
|
2005-02-14 16:05:11 +01:00
|
|
|
if (!$tmpl->xslt)
|
2002-10-12 22:40:18 +02:00
|
|
|
{
|
|
|
|
$cell['sel_options'][$cat['id']] = $s; // 0.9.14 only
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$cell['sel_options'][$cat['cat_id']] = $s;
|
|
|
|
}
|
2002-10-02 02:44:33 +02:00
|
|
|
}
|
2006-03-20 22:51:55 +01:00
|
|
|
$cell['size'] = $rows.($type2 ? ','.$type2 : '');
|
2002-10-02 02:44:33 +02:00
|
|
|
$cell['no_lang'] = True;
|
|
|
|
break;
|
|
|
|
|
2006-03-14 14:54:17 +01:00
|
|
|
case 'select-account': // options: #rows,{accounts(default)|both|groups|owngroups},{0(=lid)|1(default=name)|2(=lid+name))}
|
2006-03-27 00:17:55 +02:00
|
|
|
//echo "<p>select-account widget: name=$cell[name], type='$type', rows=$rows, readonly=".(int)($cell['readonly'] || $readonlys)."</p>\n";
|
2006-03-14 14:54:17 +01:00
|
|
|
if($type == 'owngroups')
|
|
|
|
{
|
|
|
|
$type = 'groups';
|
|
|
|
$owngroups = true;
|
|
|
|
foreach($GLOBALS['egw']->accounts->membership() as $group) $mygroups[] = $group['account_id'];
|
|
|
|
}
|
2004-02-05 22:22:39 +01:00
|
|
|
// in case of readonly, we read/create only the needed entries, as reading accounts is expensive
|
2006-09-20 15:32:47 +02:00
|
|
|
if ($readonly)
|
2004-02-05 22:22:39 +01:00
|
|
|
{
|
2004-07-09 20:21:01 +02:00
|
|
|
$cell['no_lang'] = True;
|
2006-03-14 14:54:17 +01:00
|
|
|
foreach(is_array($value) ? $value : (strpos($value,',') !== false ? explode(',',$value) : array($value)) as $id)
|
2004-02-05 22:22:39 +01:00
|
|
|
{
|
|
|
|
$cell['sel_options'][$id] = $this->accountInfo($id,$acc,$type2,$type=='both');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2004-07-09 20:21:01 +02:00
|
|
|
if ($this->ui == 'html' && $type != 'groups') // use eGW's new account-selection (html only)
|
|
|
|
{
|
2005-11-09 21:50:45 +01:00
|
|
|
if (!is_object($GLOBALS['egw']->uiaccountsel))
|
2004-07-09 20:21:01 +02:00
|
|
|
{
|
2005-11-09 21:50:45 +01:00
|
|
|
$GLOBALS['egw']->uiaccountsel =& CreateObject('phpgwapi.uiaccountsel');
|
2004-07-09 20:21:01 +02:00
|
|
|
}
|
|
|
|
$help = (int)$cell['no_lang'] < 2 ? lang($cell['help']) : $cell['help'];
|
|
|
|
$onFocus = "self.status='".addslashes(htmlspecialchars($help))."'; return true;";
|
|
|
|
$onBlur = "self.status=''; return true;";
|
2006-03-27 00:17:55 +02:00
|
|
|
if ($cell['noprint'])
|
|
|
|
{
|
|
|
|
foreach(is_array($value) ? $value : (strpos($value,',') !== false ? explode(',',$value) : array($value)) as $id)
|
|
|
|
{
|
|
|
|
if ($id) $onlyPrint[] = $this->accountInfo($id,$acc,$type2,$type=='both');
|
|
|
|
}
|
|
|
|
$onlyPrint = $onlyPrint ? implode('<br />',$onlyPrint) : lang((int)$rows < 0 ? 'all' : $rows);
|
|
|
|
$noPrint_class = ' class="noPrint"';
|
|
|
|
}
|
2005-11-09 21:50:45 +01:00
|
|
|
$value = $GLOBALS['egw']->uiaccountsel->selection($name,'eT_accountsel_'.str_replace(array('[','][',']'),array('_','_',''),$name),
|
2006-03-27 00:17:55 +02:00
|
|
|
$value,$type,$rows > 0 ? $rows : 0,False,' onfocus="'.$onFocus.'" onblur="'.$onBlur.'"'.$noPrint_class,
|
2004-07-09 20:21:01 +02:00
|
|
|
$cell['onchange'] == '1' ? 'this.form.submit();' : $cell['onchange'],
|
|
|
|
!empty($rows) && 0+$rows <= 0 ? lang($rows < 0 ? 'all' : $rows) : False);
|
2006-03-27 00:17:55 +02:00
|
|
|
if ($cell['noprint'])
|
|
|
|
{
|
|
|
|
$value = '<span class="onlyPrint">'.$onlyPrint.'</span>'.$value;
|
|
|
|
}
|
2004-07-09 20:21:01 +02:00
|
|
|
$cell['type'] = 'html';
|
|
|
|
$cell['size'] = ''; // is interpreted as link otherwise
|
2005-11-09 21:50:45 +01:00
|
|
|
$GLOBALS['egw_info']['etemplate']['to_process'][$name] = 'select';
|
2004-07-09 20:21:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
$cell['no_lang'] = True;
|
2005-11-09 21:50:45 +01:00
|
|
|
$accs = $GLOBALS['egw']->accounts->get_list(empty($type) ? 'accounts' : $type); // default is accounts
|
2004-02-05 22:22:39 +01:00
|
|
|
foreach($accs as $acc)
|
2002-10-02 02:44:33 +02:00
|
|
|
{
|
2004-07-09 20:21:01 +02:00
|
|
|
if ($acc['account_type'] == 'u')
|
2004-02-05 22:22:39 +01:00
|
|
|
{
|
2002-10-03 18:43:26 +02:00
|
|
|
$cell['sel_options'][$acc['account_id']] = $this->accountInfo($acc['account_id'],$acc,$type2,$type=='both');
|
2004-02-05 22:22:39 +01:00
|
|
|
}
|
2002-10-03 18:43:26 +02:00
|
|
|
}
|
2004-02-05 22:22:39 +01:00
|
|
|
foreach($accs as $acc)
|
2002-10-03 18:43:26 +02:00
|
|
|
{
|
2006-03-14 14:54:17 +01:00
|
|
|
if ($acc['account_type'] == 'g' && (!$owngroups || ($owngroups && in_array($acc['account_id'],(array)$mygroups))))
|
2004-02-05 22:22:39 +01:00
|
|
|
{
|
2002-10-03 18:43:26 +02:00
|
|
|
$cell['sel_options'][$acc['account_id']] = $this->accountInfo($acc['account_id'],$acc,$type2,$type=='both');
|
2004-02-05 22:22:39 +01:00
|
|
|
}
|
2002-10-03 18:43:26 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'select-year': // options: #rows,#before(default=3),#after(default=2)
|
|
|
|
$cell['sel_options'][''] = '';
|
|
|
|
if ($type <= 0) $type = 3;
|
|
|
|
if ($type2 <= 0) $type2 = 2;
|
|
|
|
if ($type > 100 && $type2 > 100 && $type > $type) { $y = $type; $type=$type2; $type2=$y; }
|
|
|
|
$y = date('Y')-$type;
|
|
|
|
if ($value && $value-$type < $y || $type > 100) $y = $type > 100 ? $type : $value-$type;
|
|
|
|
$to = date('Y')+$type2;
|
|
|
|
if ($value && $value+$type2 > $to || $type2 > 100) $to = $type2 > 100 ? $type2 : $value+$type2;
|
|
|
|
for ($n = 0; $y <= $to && $n < 200; ++$n)
|
|
|
|
{
|
|
|
|
$cell['sel_options'][$y] = $y++;
|
2002-10-02 02:44:33 +02:00
|
|
|
}
|
|
|
|
$cell['no_lang'] = True;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'select-month':
|
|
|
|
$cell['sel_options'] = $this->monthnames;
|
2002-10-06 02:16:31 +02:00
|
|
|
$value = intval($value);
|
2002-10-02 02:44:33 +02:00
|
|
|
break;
|
2004-10-07 23:58:33 +02:00
|
|
|
|
2006-03-20 22:51:55 +01:00
|
|
|
case 'select-dow': // options: rows[,0=summaries befor days, 1=summaries after days, 2=no summaries[,extraStyleMultiselect]]
|
2004-10-07 23:58:33 +02:00
|
|
|
if (!defined('MCAL_M_SUNDAY'))
|
|
|
|
{
|
|
|
|
define('MCAL_M_SUNDAY',1);
|
|
|
|
define('MCAL_M_MONDAY',2);
|
|
|
|
define('MCAL_M_TUESDAY',4);
|
|
|
|
define('MCAL_M_WEDNESDAY',8);
|
|
|
|
define('MCAL_M_THURSDAY',16);
|
|
|
|
define('MCAL_M_FRIDAY',32);
|
|
|
|
define('MCAL_M_SATURDAY',64);
|
|
|
|
|
|
|
|
define('MCAL_M_WEEKDAYS',62);
|
|
|
|
define('MCAL_M_WEEKEND',65);
|
|
|
|
define('MCAL_M_ALLDAYS',127);
|
|
|
|
}
|
2005-11-09 21:50:45 +01:00
|
|
|
$weekstart = $GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts'];
|
2004-10-08 00:09:02 +02:00
|
|
|
$cell['sel_options'] = array();
|
2005-06-19 13:10:38 +02:00
|
|
|
if ($rows >= 2 && !$type)
|
2004-10-08 00:09:02 +02:00
|
|
|
{
|
|
|
|
$cell['sel_options'] = array(
|
|
|
|
MCAL_M_ALLDAYS => 'all days',
|
|
|
|
MCAL_M_WEEKDAYS => 'working days',
|
|
|
|
MCAL_M_WEEKEND => 'weekend',
|
|
|
|
);
|
|
|
|
}
|
2004-10-07 23:58:33 +02:00
|
|
|
if ($weekstart == 'Saturday') $cell['sel_options'][MCAL_M_SATURDAY] = 'saturday';
|
|
|
|
if ($weekstart != 'Monday') $cell['sel_options'][MCAL_M_SUNDAY] = 'sunday';
|
|
|
|
$cell['sel_options'] += array(
|
|
|
|
MCAL_M_MONDAY => 'monday',
|
|
|
|
MCAL_M_TUESDAY => 'tuesday',
|
|
|
|
MCAL_M_WEDNESDAY=> 'wednesday',
|
|
|
|
MCAL_M_THURSDAY => 'thursday',
|
|
|
|
MCAL_M_FRIDAY => 'friday',
|
|
|
|
);
|
|
|
|
if ($weekstart != 'Saturday') $cell['sel_options'][MCAL_M_SATURDAY] = 'saturday';
|
|
|
|
if ($weekstart == 'Monday') $cell['sel_options'][MCAL_M_SUNDAY] = 'sunday';
|
2005-06-19 13:10:38 +02:00
|
|
|
if ($rows >= 2 && $type == 1)
|
|
|
|
{
|
|
|
|
$cell['sel_options'] += array(
|
|
|
|
MCAL_M_ALLDAYS => 'all days',
|
|
|
|
MCAL_M_WEEKDAYS => 'working days',
|
|
|
|
MCAL_M_WEEKEND => 'weekend',
|
|
|
|
);
|
|
|
|
}
|
2004-10-07 23:58:33 +02:00
|
|
|
$value_in = $value;
|
|
|
|
$value = array();
|
|
|
|
foreach($cell['sel_options'] as $val => $lable)
|
|
|
|
{
|
|
|
|
if (($value_in & $val) == $val)
|
|
|
|
{
|
2005-06-19 13:10:38 +02:00
|
|
|
$value[] = $val;
|
2004-10-07 23:58:33 +02:00
|
|
|
|
|
|
|
if ($val == MCAL_M_ALLDAYS ||
|
|
|
|
$val == MCAL_M_WEEKDAYS && $value_in == MCAL_M_WEEKDAYS ||
|
|
|
|
$val == MCAL_M_WEEKEND && $value_in == MCAL_M_WEEKEND)
|
|
|
|
{
|
|
|
|
break; // dont set the others
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-06-19 13:10:38 +02:00
|
|
|
if (!$readonly)
|
2004-10-07 23:58:33 +02:00
|
|
|
{
|
2005-11-09 21:50:45 +01:00
|
|
|
$GLOBALS['egw_info']['etemplate']['to_process'][$name] = 'ext-select-dow';
|
2004-10-07 23:58:33 +02:00
|
|
|
}
|
2006-03-20 22:51:55 +01:00
|
|
|
$cell['size'] = $rows.($type2 ? ','.$type2 : '');
|
2004-10-07 23:58:33 +02:00
|
|
|
break;
|
2002-10-03 18:43:26 +02:00
|
|
|
|
|
|
|
case 'select-day':
|
2003-04-13 21:14:50 +02:00
|
|
|
$type = 1;
|
|
|
|
$type2 = 31;
|
|
|
|
$type3 = 1;
|
|
|
|
// fall-through
|
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
case 'select-number': // options: rows,min,max,decrement
|
|
|
|
$type = $type === '' ? 1 : intval($type); // min
|
|
|
|
$type2 = $type2 === '' ? 10 : intval($type2); // max
|
|
|
|
$format = '%d';
|
|
|
|
if (!empty($type3) && $type3[0] == '0') // leading zero
|
|
|
|
{
|
|
|
|
$format = '%0'.strlen($type3).'d';
|
|
|
|
}
|
|
|
|
$type3 = !$type3 ? 1 : intval($type3); // decrement
|
2003-04-13 21:14:50 +02:00
|
|
|
if (($type < $type2) != ($type3 > 0))
|
|
|
|
{
|
|
|
|
$type3 = -$type3; // void infinite loop
|
|
|
|
}
|
|
|
|
for ($i=0,$n=$type; $n <= $type2 && $i <= 100; $n += $type3)
|
2002-10-03 18:43:26 +02:00
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$cell['sel_options'][$n] = sprintf($format,$n);
|
2002-10-03 18:43:26 +02:00
|
|
|
}
|
|
|
|
$cell['no_lang'] = True;
|
|
|
|
break;
|
2003-03-18 14:06:27 +01:00
|
|
|
|
2006-06-22 18:14:08 +02:00
|
|
|
case 'select-hour':
|
|
|
|
for ($h = 0; $h <= 23; ++$h)
|
|
|
|
{
|
|
|
|
$cell['sel_options'][$h] = $GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ?
|
|
|
|
(($h % 12 ? $h % 12 : 12).' '.($h < 12 ? lang('am') : lang('pm'))) :
|
|
|
|
sprintf('%02d',$h);
|
|
|
|
}
|
|
|
|
$cell['no_lang'] = True;
|
|
|
|
break;
|
|
|
|
|
2003-03-18 14:06:27 +01:00
|
|
|
case 'select-app': // type2: ''=users enabled apps, 'installed', 'all' = not installed ones too
|
|
|
|
$apps = array();
|
2005-11-09 21:50:45 +01:00
|
|
|
foreach ($GLOBALS['egw_info']['apps'] as $app => $data)
|
2003-03-18 14:06:27 +01:00
|
|
|
{
|
2005-11-09 21:50:45 +01:00
|
|
|
if (!$type2 || $GLOBALS['egw_info']['user']['apps'][$app])
|
2003-03-18 14:06:27 +01:00
|
|
|
{
|
|
|
|
$apps[$app] = $data['title'] ? $data['title'] : lang($app);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($type2 == 'all')
|
|
|
|
{
|
2005-11-09 21:50:45 +01:00
|
|
|
$dir = opendir(EGW_SERVER_ROOT);
|
2003-03-18 14:06:27 +01:00
|
|
|
while ($file = readdir($dir))
|
|
|
|
{
|
2005-11-09 21:50:45 +01:00
|
|
|
if (@is_dir(EGW_SERVER_ROOT."/$file/setup") && $file[0] != '.' &&
|
|
|
|
!isset($apps[$app = basename($file)]))
|
2003-03-18 14:06:27 +01:00
|
|
|
{
|
|
|
|
$apps[$app] = $app . ' (*)';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($dir);
|
|
|
|
}
|
|
|
|
$apps_lower = $apps; // case-in-sensitve sort
|
|
|
|
foreach ($apps_lower as $app => $title)
|
|
|
|
{
|
|
|
|
$apps_lower[$app] = strtolower($title);
|
|
|
|
}
|
|
|
|
asort($apps_lower);
|
|
|
|
foreach ($apps_lower as $app => $title)
|
|
|
|
{
|
|
|
|
$cell['sel_options'][$app] = $apps[$app];
|
|
|
|
}
|
|
|
|
break;
|
2002-10-03 18:43:26 +02:00
|
|
|
}
|
|
|
|
if ($rows > 1)
|
|
|
|
{
|
|
|
|
unset($cell['sel_options']['']);
|
2002-10-02 02:44:33 +02:00
|
|
|
}
|
|
|
|
return True; // extra Label Ok
|
|
|
|
}
|
|
|
|
|
2005-02-18 23:44:42 +01:00
|
|
|
/**
|
|
|
|
* internal function to format account-data
|
|
|
|
*/
|
2002-10-03 18:43:26 +02:00
|
|
|
function accountInfo($id,$acc=0,$longnames=0,$show_type=0)
|
2002-10-02 02:44:33 +02:00
|
|
|
{
|
|
|
|
if (!$id)
|
|
|
|
{
|
|
|
|
return ' ';
|
|
|
|
}
|
|
|
|
|
2002-10-03 18:43:26 +02:00
|
|
|
if (!is_array($acc))
|
2002-10-02 02:44:33 +02:00
|
|
|
{
|
2005-11-09 21:50:45 +01:00
|
|
|
$data = $GLOBALS['egw']->accounts->get_account_data($id);
|
2004-02-05 22:22:39 +01:00
|
|
|
foreach(array('type','lid','firstname','lastname') as $name)
|
|
|
|
{
|
|
|
|
$acc['account_'.$name] = $data[$id][$name];
|
|
|
|
}
|
2002-10-02 02:44:33 +02:00
|
|
|
}
|
2002-10-03 18:43:26 +02:00
|
|
|
$info = $show_type ? '('.$acc['account_type'].') ' : '';
|
2005-06-07 10:45:53 +02:00
|
|
|
|
|
|
|
if ($acc['account_type'] == 'g')
|
|
|
|
{
|
|
|
|
$longnames = 1;
|
|
|
|
}
|
2002-10-02 02:44:33 +02:00
|
|
|
switch ($longnames)
|
|
|
|
{
|
2002-10-03 18:43:26 +02:00
|
|
|
case 2:
|
|
|
|
$info .= '<'.$acc['account_lid'].'> ';
|
|
|
|
// fall-through
|
|
|
|
case 1:
|
|
|
|
$info .= $acc['account_type'] == 'g' ? lang('group').' '.$acc['account_lid'] :
|
|
|
|
$acc['account_firstname'].' '.$acc['account_lastname'];
|
|
|
|
break;
|
|
|
|
case '0':
|
|
|
|
$info .= $acc['account_lid'];
|
|
|
|
break;
|
2003-05-04 11:18:56 +02:00
|
|
|
default: // use the phpgw default
|
2005-11-09 21:50:45 +01:00
|
|
|
$info = $GLOBALS['egw']->common->display_fullname($acc['account_lid'],
|
2003-05-04 11:18:56 +02:00
|
|
|
$acc['account_firstname'],$acc['account_lastname']);
|
|
|
|
break;
|
2002-10-02 02:44:33 +02:00
|
|
|
}
|
|
|
|
return $info;
|
|
|
|
}
|
2004-10-07 23:58:33 +02:00
|
|
|
|
|
|
|
/**
|
2005-02-18 23:44:42 +01:00
|
|
|
* postprocessing method, called after the submission of the form
|
|
|
|
*
|
|
|
|
* It has to copy the allowed/valid data from $value_in to $value, otherwise the widget
|
|
|
|
* will return no data (if it has a preprocessing method). The framework insures that
|
|
|
|
* the post-processing of all contained widget has been done before.
|
|
|
|
*
|
|
|
|
* Only used by select-dow so far
|
|
|
|
*
|
|
|
|
* @param string $name form-name of the widget
|
|
|
|
* @param mixed &$value the extension returns here it's input, if there's any
|
|
|
|
* @param mixed &$extension_data persistent storage between calls or pre- and post-process
|
|
|
|
* @param boolean &$loop can be set to true to request a re-submision of the form/dialog
|
|
|
|
* @param object &$tmpl the eTemplate the widget belongs too
|
|
|
|
* @param mixed &value_in the posted values (already striped of magic-quotes)
|
|
|
|
* @return boolean true if $value has valid content, on false no content will be returned!
|
2004-10-07 23:58:33 +02:00
|
|
|
*/
|
|
|
|
function post_process($name,&$value,&$extension_data,&$loop,&$tmpl,$value_in)
|
|
|
|
{
|
2005-07-14 08:31:05 +02:00
|
|
|
switch ($extension_data['type'])
|
2004-10-07 23:58:33 +02:00
|
|
|
{
|
|
|
|
case 'select-dow':
|
|
|
|
$value = 0;
|
|
|
|
if (!is_array($value_in)) $value_in = explode(',',$value_in);
|
|
|
|
foreach($value_in as $val)
|
|
|
|
{
|
|
|
|
$value |= $val;
|
|
|
|
}
|
|
|
|
//echo "<p>select_widget::post_process('$name',...,'$value_in'): value='$value'</p>\n";
|
|
|
|
break;
|
2006-07-07 00:55:30 +02:00
|
|
|
case 'select-country':
|
|
|
|
if ($extension_data['country_use_name'] && $value_in)
|
|
|
|
{
|
|
|
|
if (!is_object($GLOBALS['egw']->country))
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->country =& CreateObject('phpgwapi.country');
|
|
|
|
}
|
|
|
|
if (($value = $GLOBALS['egw']->country->get_full_name($value_in)))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// fall through
|
2004-10-07 23:58:33 +02:00
|
|
|
default:
|
|
|
|
$value = $value_in;
|
|
|
|
break;
|
|
|
|
}
|
2005-04-06 08:31:27 +02:00
|
|
|
//echo "<p>select_widget::post_process('$name',,'$extension_data',,,'$value_in'): value='$value', is_null(value)=".(int)is_null($value)."</p>\n";
|
2006-08-12 08:14:28 +02:00
|
|
|
return true;
|
2004-10-07 23:58:33 +02:00
|
|
|
}
|
2002-10-12 22:40:18 +02:00
|
|
|
}
|