1 | <?php |
---|
2 | /** |
---|
3 | * eGroupWare - eTemplate Extension - Resource Select Widgets |
---|
4 | * |
---|
5 | * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License |
---|
6 | * @package resources |
---|
7 | * @link http://www.egroupware.org |
---|
8 | * @author RalfBecker-AT-outdoor-training.de |
---|
9 | * @version $Id: class.resources_select_widget.inc.php 22438 2006-09-15 19:37:19Z nelius_weiss $ |
---|
10 | */ |
---|
11 | |
---|
12 | /** |
---|
13 | * eTemplate Extension: select a resource |
---|
14 | * |
---|
15 | * @package resources |
---|
16 | */ |
---|
17 | class resources_select_widget |
---|
18 | { |
---|
19 | /** |
---|
20 | * exported methods of this class |
---|
21 | * @var array |
---|
22 | */ |
---|
23 | var $public_functions = array( |
---|
24 | 'pre_process' => True, |
---|
25 | ); |
---|
26 | /** |
---|
27 | * availible extensions and there names for the editor |
---|
28 | * @var array |
---|
29 | */ |
---|
30 | var $human_name = 'Select Resources'; |
---|
31 | |
---|
32 | /** |
---|
33 | * Constructor of the extension |
---|
34 | * |
---|
35 | * @param string $ui '' for html |
---|
36 | */ |
---|
37 | function resources_select_widget($ui) |
---|
38 | { |
---|
39 | $this->ui = $ui; |
---|
40 | } |
---|
41 | |
---|
42 | /** |
---|
43 | * pre-processing of the extension |
---|
44 | * |
---|
45 | * This function is called before the extension gets rendered |
---|
46 | * |
---|
47 | * @param string $name form-name of the control |
---|
48 | * @param mixed &$value value / existing content, can be modified |
---|
49 | * @param array &$cell array with the widget, can be modified for ui-independent widgets |
---|
50 | * @param array &$readonlys names of widgets as key, to be made readonly |
---|
51 | * @param mixed &$extension_data data the extension can store persisten between pre- and post-process |
---|
52 | * @param object &$tmpl reference to the template we belong too |
---|
53 | * @return boolean true if extra label is allowed, false otherwise |
---|
54 | */ |
---|
55 | function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl) |
---|
56 | { |
---|
57 | if ($cell['readonly'] && !is_array($value)) |
---|
58 | { |
---|
59 | // no acl check here cause names are allways viewable |
---|
60 | list($res_id,$quantity) = explode(':',$value); |
---|
61 | $data = ExecMethod('resources.bo_resources.get_calendar_info',$res_id); |
---|
62 | $cell['type'] = 'label'; |
---|
63 | $value = $data[0]['name']. ($data[0]['useable'] > 1 ? ' ['. ($quantity > 1 ? $quantity : 1). '/'. $data[0]['useable']. ']' : ''); |
---|
64 | return true; |
---|
65 | } |
---|
66 | |
---|
67 | if (!$GLOBALS['phpgw_info']['user']['apps']['resources']) |
---|
68 | { |
---|
69 | $cell = $tmpl->empty_cell(); |
---|
70 | $cell['label'] = 'no resources'; |
---|
71 | return false; |
---|
72 | } |
---|
73 | $tpl =& new etemplate('resources.resource_selectbox'); |
---|
74 | // keep the editor away from the generated tmpls |
---|
75 | $tpl->no_onclick = true; |
---|
76 | |
---|
77 | if ($value) |
---|
78 | { |
---|
79 | $value = is_array($value) ? $value : explode(',',$value); |
---|
80 | foreach((array)$value as $id) |
---|
81 | { |
---|
82 | list($res_id,$quantity) = explode(':',$id); |
---|
83 | $data = ExecMethod('resources.bo_resources.get_calendar_info',$res_id); |
---|
84 | $sel_options[$data[0]['res_id'].($quantity > 1 ? (':'.$quantity) : '')] = |
---|
85 | $data[0]['name'].' ['.($quantity > 1 ? $quantity : 1).'/'.$data[0]['useable'].']'; |
---|
86 | } |
---|
87 | $tpl->set_cell_attribute('resources','sel_options',$sel_options); |
---|
88 | } |
---|
89 | |
---|
90 | $tpl->set_cell_attribute('resources','size',(int)$cell['size'].'+'); |
---|
91 | $tpl->set_cell_attribute('resources','label',$cell['label']); |
---|
92 | $tpl->set_cell_attribute('resources','id','resources_selectbox'); |
---|
93 | $tpl->set_cell_attribute('resources','name',$cell['name']); |
---|
94 | if ($cell['help']) |
---|
95 | { |
---|
96 | $tpl->set_cell_attribute('resources','help',$cell['help']); |
---|
97 | $tpl->set_cell_attribute('popup','label',$cell['help']); |
---|
98 | } |
---|
99 | $cell['type'] = 'template'; |
---|
100 | $cell['size'] = $cell['label'] = ''; |
---|
101 | $cell['name'] = 'resources.resource_selectbox'; |
---|
102 | $cell['obj'] =& $tpl; |
---|
103 | |
---|
104 | return True; // extra Label Ok |
---|
105 | } |
---|
106 | } |
---|