* * -------------------------------------------- * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * \**************************************************************************/ /* $Id$ */ /** * eTemplate Extension: several select-boxes with predefined eGW specific content * * This widgets replaces the old phpgwapi.sbox class. The widgets are independent of the UI, * as they only uses etemplate-widgets and therefor have no render-function. * * @package etemplate * @subpackage extensions * @author RalfBecker-AT-outdoor-training.de * @license GPL */ class select_widget { /** * exported methods of this class * @var array */ var $public_functions = array( 'pre_process' => True, 'post_process' => True, ); /** * availible extensions and there names for the editor * @var array */ var $human_name = array( 'select-percent' => 'Select Percentage', 'select-priority' => 'Select Priority', 'select-access' => 'Select Access', 'select-country' => 'Select Country', 'select-state' => 'Select State', // US-states 'select-cat' => 'Select Category', // Category-Selection, size: -1=Single+All, 0=Single, >0=Multiple with size lines 'select-account' => 'Select Account', // label=accounts(default),groups,both // size: -1=Single+not assigned, 0=Single, >0=Multiple 'select-year' => 'Select Year', 'select-month' => 'Select Month', 'select-day' => 'Select Day', 'select-dow' => 'Select Day of week', 'select-number' => 'Select Number', 'select-app' => 'Select Application' ); /** * @var array */ 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' ); /** * @var array */ var $states = array( '' => '', '--' => 'non US', 'AL' => 'Alabama', 'AK' => 'Alaska', 'AZ' => 'Arizona', 'AR' => 'Arkansas', 'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware', 'DC' => 'District of Columbia', 'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho', 'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas', 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine', 'MD' => 'Maryland', 'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MO' => 'Missouri', 'MS' => 'Mississippi', 'MT' => 'Montana', 'NC' => 'North Carolina', 'ND' => 'Noth Dakota', 'NE' => 'Nebraska', 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NV' => 'Nevada', 'NY' => 'New York', 'OH' => 'Ohio', 'OK' => 'Oklahoma', 'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', 'SC' => 'South Carolina', 'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah', 'VA' => 'Virginia', 'VT' => 'Vermont', 'WA' => 'Washington', 'WI' => 'Wisconsin', 'WV' => 'West Virginia', 'WY' => 'Wyoming' ); /** * Constructor of the extension * * @param string $ui '' for html */ function select_widget($ui) { foreach($this->monthnames as $k => $name) { if ($name) { $this->monthnames[$k] = lang($name); } } $this->ui = $ui; } /** * 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 */ function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl) { list($rows,$type,$type2,$type3) = explode(',',$cell['size']); $extension_data['type'] = $cell['type']; switch ($cell['type']) { case 'select-percent': // options: #row,decrement(default=10) $decr = $type > 0 ? $type : 10; for ($i=0; $i <= 100; $i += $decr) { $cell['sel_options'][intval($i)] = intval($i).'%'; } $cell['sel_options'][100] = '100%'; if (!$rows || !empty($value)) { $value = intval(($value+($decr/2)) / $decr) * $decr; } $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; case 'select-country': if (!$this->countrys) { $country =& CreateObject('phpgwapi.country'); $this->countrys = &$country->country_array; unset($country); unset($this->countrys[' ']); $this->countrys[''] = ''; // try to translate them and sort alphabetic foreach($this->countrys as $k => $name) { if (($translated = lang($name)) != $name.'*') { $this->countrys[$k] = $translated; } } asort($this->countrys); } $cell['sel_options'] = $this->countrys; $cell['no_lang'] = True; break; case 'select-state': $cell['sel_options'] = $this->states; $cell['no_lang'] = True; break; case 'select-cat': // !$type == globals cats too, $type2: extraStyleMultiselect if (!is_object($GLOBALS['egw']->categories)) { $GLOBALS['egw']->categories =& CreateObject('phpgwapi.categories'); } foreach((array)$GLOBALS['egw']->categories->return_sorted_array(0,False,'','','',!$type) as $cat) { $s = str_repeat(' ',$cat['level']) . $GLOBALS['egw']->strip_html($cat['name']); if ($cat['app_name'] == 'phpgw' || $cat['owner'] == '-1') { $s .= ' ♦'; } if (!$tmpl->xslt) { $cell['sel_options'][$cat['id']] = $s; // 0.9.14 only } else { $cell['sel_options'][$cat['cat_id']] = $s; } } $cell['size'] = $rows.($type2 ? ','.$type2 : ''); $cell['no_lang'] = True; break; case 'select-account': // options: #rows,{accounts(default)|both|groups|owngroups},{0(=lid)|1(default=name)|2(=lid+name))} //echo "
select-account widget: name=$cell[name], type='$type', rows=$rows, readonly=".(int)($cell['readonly'] || $readonlys)."
\n"; if($type == 'owngroups') { $type = 'groups'; $owngroups = true; foreach($GLOBALS['egw']->accounts->membership() as $group) $mygroups[] = $group['account_id']; } // in case of readonly, we read/create only the needed entries, as reading accounts is expensive if ($cell['readonly'] || $readonlys) { $cell['no_lang'] = True; foreach(is_array($value) ? $value : (strpos($value,',') !== false ? explode(',',$value) : array($value)) as $id) { $cell['sel_options'][$id] = $this->accountInfo($id,$acc,$type2,$type=='both'); } break; } if ($this->ui == 'html' && $type != 'groups') // use eGW's new account-selection (html only) { if (!is_object($GLOBALS['egw']->uiaccountsel)) { $GLOBALS['egw']->uiaccountsel =& CreateObject('phpgwapi.uiaccountsel'); } $help = (int)$cell['no_lang'] < 2 ? lang($cell['help']) : $cell['help']; $onFocus = "self.status='".addslashes(htmlspecialchars($help))."'; return true;"; $onBlur = "self.status=''; return true;"; 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('select_widget::post_process('$name',...,'$value_in'): value='$value'
\n"; break; default: $value = $value_in; break; } //echo "select_widget::post_process('$name',,'$extension_data',,,'$value_in'): value='$value', is_null(value)=".(int)is_null($value)."
\n"; return !is_null($value); } }