egroupware_official/resources/inc/class.ui_resources.inc.php

232 lines
6.9 KiB
PHP
Raw Normal View History

2005-02-03 17:42:20 +01:00
<?php
/**************************************************************************\
* eGroupWare - resources - Resource Management System *
* http://www.egroupware.org *
2005-02-17 18:29:07 +01:00
* Written by Lukas Weiss [ichLukas@gmx.de] and *
2005-02-03 17:42:20 +01:00
* Cornelius Weiss [nelius@gmx.net] *
* ----------------------------------------------- *
* 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. *
\**************************************************************************/
2005-02-09 15:41:43 +01:00
/* $Id$ */
2005-02-03 17:42:20 +01:00
class ui_resources
{
var $public_functions = array(
'index' => True,
'edit' => True,
2005-03-01 11:20:03 +01:00
'show' => True,
'admin' => True,
2005-02-03 17:42:20 +01:00
'writeLangFile' => True
);
/*!
@function ui_resources
@abstract constructor of class ui_resources
*/
function ui_resources()
{
2005-02-17 09:04:55 +01:00
// print_r($GLOBALS['phpgw_info']); die();
2005-02-03 17:42:20 +01:00
$this->tmpl = CreateObject('etemplate.etemplate','resources.show');
$this->bo = CreateObject('resources.bo_resources');
if(!@is_object($GLOBALS['phpgw']->js))
{
$GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
}
}
/*!
@function index
@abstract main resources list.
2005-02-17 10:53:46 +01:00
@autor Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
2005-02-03 17:42:20 +01:00
@param array $content content from eTemplate callback
FIXME don't translate cats in nextmach
*/
function index($content='')
{
if (is_array($content))
{
if (isset($content['nm']['rows']))
{
2005-02-28 16:19:31 +01:00
unset($content['nm']['rows']['checkbox']);
switch (key($content['nm']['rows']))
2005-02-03 17:42:20 +01:00
{
2005-02-28 16:19:31 +01:00
case 'edit':
list($id) = each($content['nm']['rows']['edit']);
return $this->edit($id);
case 'delete':
list($id) = each($content['nm']['rows']['delete']);
return $this->delete($id);
case 'new_acc':
list($id) = each($content['nm']['rows']['new_acc']);
2005-03-01 11:20:03 +01:00
return $this->edit(array('id' => 0, 'accessory_of' => $id));
2005-02-28 16:19:31 +01:00
case 'view_acc':
list($id) = each($content['nm']['rows']['view_acc']);
$content['view_accs_of'] = $id;
break;
case 'view':
case 'bookable':
case 'buyable':
2005-02-03 17:42:20 +01:00
}
}
if (isset($content['add']))
{
2005-03-01 11:20:03 +01:00
return $content['view_accs_of'] ? $this->edit(array('id' => 0, 'accessory_of' => $id)) : $this->edit(0);
2005-02-03 17:42:20 +01:00
}
2005-02-28 16:19:31 +01:00
if (isset($content['back']))
{
return $this->index();
}
2005-02-03 17:42:20 +01:00
}
$content['nm']['get_rows'] = 'resources.bo_resources.get_rows';
$content['nm']['no_filter'] = False;
2005-02-15 17:26:21 +01:00
$content['nm']['filter_label'] = 'Category';
2005-02-21 16:56:21 +01:00
$content['nm']['filter_help'] = lang('Select a category'); // is this used???
$content['nm']['options-filter']= array('0'=>lang('all categories'))+(array)$this->bo->acl->get_cats(PHPGW_ACL_READ);
$content['nm']['no_filter2'] = true;
$content['nm']['filter_no_lang'] = true;
$content['nm']['no_cat'] = true;
2005-02-03 17:42:20 +01:00
// check if user is permitted to add resources
if(!$this->bo->acl->get_cats(PHPGW_ACL_ADD))
{
$no_button['add'] = true;
}
2005-02-28 16:19:31 +01:00
$no_button['back'] = true;
2005-02-03 17:42:20 +01:00
2005-02-28 16:19:31 +01:00
if($content['view_accs_of'])
{
$content['nm']['get_rows'] = 'resources.bo_resources.get_rows';
$content['nm']['no_filter'] = true;
$content['nm']['no_filter2'] = true;
$content['nm']['view_accs_of'] = $content['view_accs_of'];
$no_button['back'] = false;
}
2005-03-01 11:20:03 +01:00
$preserv = $content;
2005-03-01 11:58:04 +01:00
$this->tmpl->read('resources.show');
2005-02-03 17:42:20 +01:00
$this->tmpl->exec('resources.ui_resources.index',$content,$sel_options,$no_button,$preserv);
}
/*!
@function edit
2005-02-24 19:24:26 +01:00
@syntax edit($content=0)
@author Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
2005-02-03 17:42:20 +01:00
@abstract invokes add or edit dialog for resources
2005-02-24 19:24:26 +01:00
@param $content Content from the eTemplate Exec call or id on inital call
2005-02-03 17:42:20 +01:00
*/
2005-02-24 19:24:26 +01:00
function edit($content=0)
2005-02-03 17:42:20 +01:00
{
if (is_array($content))
{
2005-02-24 19:24:26 +01:00
if(isset($content['save']) || isset($content['delete']))
2005-02-03 17:42:20 +01:00
{
2005-02-24 19:24:26 +01:00
if(isset($content['save']))
2005-02-12 09:25:26 +01:00
{
2005-02-24 19:24:26 +01:00
unset($content['save']);
if($content['id'] != 0)
{
// links are already saved by eTemplate
unset($resource['link_to']['to_id']);
}
$content['msg'] = $this->bo->save($content);
2005-02-12 09:25:26 +01:00
}
2005-02-24 19:24:26 +01:00
if(isset($content['delete']))
2005-02-03 17:42:20 +01:00
{
2005-02-24 19:24:26 +01:00
unset($content['delete']);
$content['msg'] = $this->delete($content['id']);
2005-02-03 17:42:20 +01:00
}
2005-03-01 11:20:03 +01:00
return $content['msg'] ? $this->edit($content) : $content['accessory_of'] ? $this->index(array('view_accs_of' => $content['accessory_of'])) : $this->index();
2005-02-24 19:24:26 +01:00
}
elseif($content['cancel'])
{
return $this->index();
2005-02-03 17:42:20 +01:00
}
}
2005-02-09 15:41:43 +01:00
else
{
2005-03-01 11:20:03 +01:00
$id = $content;
$content = array('id' => $id);
2005-02-24 19:24:26 +01:00
2005-03-01 11:20:03 +01:00
if ($id > 0)
2005-02-24 19:24:26 +01:00
{
2005-03-01 11:20:03 +01:00
$content = $this->bo->read($id);
2005-02-24 19:24:26 +01:00
$content['gen_src_list'] = strstr($content['picture_src'],'.') ? $content['picture_src'] : false;
$content['picture_src'] = strstr($content['picture_src'],'.') ? 'gen_src' : $content['picture_src'];
$content['link_to'] = array(
2005-03-01 11:20:03 +01:00
'to_id' => $id,
2005-02-24 19:24:26 +01:00
'to_app' => 'resources'
);
}
2005-02-25 12:15:27 +01:00
}
2005-02-28 16:19:31 +01:00
// some presetes
2005-03-01 11:20:03 +01:00
$content['resource_picture'] = $this->bo->get_picture($content['id'],$content['picture_src'],$size=true);
2005-02-28 16:19:31 +01:00
$content['accessory_of'] = $content['accessory_of'] ? $content['accessory_of'] : -1;
$content['quantity'] = $content['quantity'] ? $content['quantity'] : 1;
$content['useable'] = $content['useable'] ? $content['useable'] : 1;
$sel_options['cat_id'] = $this->bo->acl->get_cats(PHPGW_ACL_ADD);
2005-02-25 12:15:27 +01:00
$sel_options['cat_id'] = count($sel_options['cat_id']) == 1 ? $sel_options['cat_id'] : array('' => lang('select one')) + $sel_options['cat_id'];
2005-02-28 16:19:31 +01:00
if($content['accessory_of'] != -1)
{
$catofmaster = $this->bo->so->get_value('cat_id',$content['accessory_of']);
$sel_options['cat_id'] = array($catofmaster => $sel_options['cat_id'][$catofmaster]);
}
2005-02-25 12:15:27 +01:00
$sel_options['gen_src_list'] = $this->bo->get_genpicturelist();
2005-02-24 19:24:26 +01:00
$no_button = array(); // TODO: show delete button only if allowed to delete resource
$preserv = $content;
2005-02-03 17:42:20 +01:00
$this->tmpl->read('resources.edit');
$this->tmpl->exec('resources.ui_resources.edit',$content,$sel_options,$no_button,$preserv);
}
2005-03-01 11:58:04 +01:00
/*!
@function admin
@abstract adminsection of resources
@author Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
*/
function admin($content='')
{
if(is_array($content))
{
if(isset($content['save']))
{
$this->bo->conf->read_repository();
$this->bo->conf->save_value('dont_use_vfs',$content['dont_use_vfs']);
}
else
{
return $GLOBALS['phpgw']->redirect_link('/admin/index.php');
}
}
$content = $this->bo->conf->read_repository();
$this->tmpl->read('resources.admin');
$this->tmpl->exec('resources.ui_resources.admin',$content,$sel_options,$no_button,$preserv);
}
2005-02-03 17:42:20 +01:00
/*!
@function show
@abstract showes a single resource
@param int $id resource id
*/
function show($id)
{
}
function delete($id)
{
$this->bo->delete($id);
2005-02-17 18:29:07 +01:00
return $this->index();
2005-02-03 17:42:20 +01:00
}
}