diff --git a/resources/inc/class.bo_resources.inc.php b/resources/inc/class.bo_resources.inc.php index c5f88b1adf..4b064a04ff 100755 --- a/resources/inc/class.bo_resources.inc.php +++ b/resources/inc/class.bo_resources.inc.php @@ -326,15 +326,12 @@ class bo_resources $only_keys = 'res_id,name,short_description'; $filter = array( 'cat_id' => array_flip((array)$this->acl->get_cats(EGW_ACL_READ)), - //'accessory_of' => '-1' + 'accessory_of' => '-1' ); $data = $this->so->search($criteria,$only_keys,$order_by='',$extra_cols='',$wildcard='%',$empty,$op='OR','',$filter); - foreach($data as $num => $resource) + foreach((array)$data as $num => $resource) { - if($num != 0) - { - $list[$resource['res_id']] = $resource['name']. ($resource['short_description'] ? ', ['.$resource['short_description'].']':''); - } + $list[$resource['res_id']] = $resource['name']. ($resource['short_description'] ? ', ['.$resource['short_description'].']':''); } return $list; } diff --git a/resources/inc/class.resources_select_widget.inc.php b/resources/inc/class.resources_select_widget.inc.php new file mode 100644 index 0000000000..fcf6865e8d --- /dev/null +++ b/resources/inc/class.resources_select_widget.inc.php @@ -0,0 +1,106 @@ + True, + ); + /** + * availible extensions and there names for the editor + * @var array + */ + var $human_name = 'Select Resources'; + + /** + * Constructor of the extension + * + * @param string $ui '' for html + */ + function resources_select_widget($ui) + { + $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) + { + if ($cell['readonly'] && !is_array($value)) + { + // no acl check here cause names are allways viewable + list($res_id,$quantity) = explode(':',$value); + $data = ExecMethod('resources.bo_resources.get_calendar_info',$res_id); + $cell['type'] = 'label'; + $value = $data[0]['name']. ($data[0]['useable'] > 1 ? ' ['. ($quantity > 1 ? $quantity : 1). '/'. $data[0]['useable']. ']' : ''); + return true; + } + + if (!$GLOBALS['egw_info']['user']['apps']['resources']) + { + $cell = $tmpl->empty_cell(); + $cell['label'] = 'no resources'; + return false; + } + $tpl =& new etemplate('resources.resource_selectbox'); + // keep the editor away from the generated tmpls + $tpl->no_onclick = true; + + if ($value) + { + $value = is_array($value) ? $value : explode(',',$value); + foreach((array)$value as $id) + { + list($res_id,$quantity) = explode(':',$id); + $data = ExecMethod('resources.bo_resources.get_calendar_info',$res_id); + $sel_options[$data[0]['res_id'].($quantity > 1 ? (':'.$quantity) : '')] = + $data[0]['name'].' ['.($quantity > 1 ? $quantity : 1).'/'.$data[0]['useable'].']'; + } + $tpl->set_cell_attribute('resources','sel_options',$sel_options); + } + + $tpl->set_cell_attribute('resources','size',(int)$cell['size'].'+'); + $tpl->set_cell_attribute('resources','label',$cell['label']); + $tpl->set_cell_attribute('resources','id','resources_selectbox'); + $tpl->set_cell_attribute('resources','name',$cell['name']); + if ($cell['help']) + { + $tpl->set_cell_attribute('resources','help',$cell['help']); + $tpl->set_cell_attribute('popup','label',$cell['help']); + } + $cell['type'] = 'template'; + $cell['size'] = $cell['label'] = ''; + $cell['name'] = 'resources.resource_selectbox'; + $cell['obj'] =& $tpl; + + return True; // extra Label Ok + } +}