2005-02-03 17:42:20 +01:00
|
|
|
|
<?php
|
|
|
|
|
/**************************************************************************\
|
|
|
|
|
* eGroupWare - resources *
|
|
|
|
|
* http://www.egroupware.org *
|
|
|
|
|
* -------------------------------------------- *
|
|
|
|
|
* 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-20 18:50:39 +01:00
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
2005-02-03 17:42:20 +01:00
|
|
|
|
class bo_acl
|
|
|
|
|
{
|
2005-06-10 22:40:57 +02:00
|
|
|
|
/**
|
|
|
|
|
* @var $permissions Holds alls permissions for resources of user
|
|
|
|
|
*/
|
2005-02-03 17:42:20 +01:00
|
|
|
|
var $permissions;
|
|
|
|
|
|
|
|
|
|
var $acl;
|
|
|
|
|
var $start = 0;
|
|
|
|
|
var $query = '';
|
|
|
|
|
var $sort = '';
|
|
|
|
|
var $total = 0;
|
|
|
|
|
var $accounts;
|
|
|
|
|
var $cats;
|
|
|
|
|
|
|
|
|
|
var $debug;
|
|
|
|
|
var $use_session = False;
|
|
|
|
|
|
|
|
|
|
function bo_acl($session=False)
|
|
|
|
|
{
|
2005-06-10 22:40:57 +02:00
|
|
|
|
define('EGW_ACL_CAT_ADMIN',64);
|
|
|
|
|
define('EGW_ACL_DIRECT_BOOKING',128);
|
2005-06-11 10:10:22 +02:00
|
|
|
|
define('EGW_ACL_CALREAD',256);
|
2005-02-20 15:41:52 +01:00
|
|
|
|
|
2005-06-10 22:40:57 +02:00
|
|
|
|
$this->so =& CreateObject('resources.so_acl');
|
|
|
|
|
$this->permissions = $this->so->get_permissions($GLOBALS['egw_info']['user']['account_id'],true);
|
|
|
|
|
$this->egw_cats =& createobject('phpgwapi.categories');
|
|
|
|
|
$this->accounts = $GLOBALS['egw']->accounts->get_list();
|
2005-02-03 17:42:20 +01:00
|
|
|
|
$this->debug = False;
|
2005-02-20 18:10:48 +01:00
|
|
|
|
|
|
|
|
|
//all this is only needed when called from uiacl.
|
2005-02-03 17:42:20 +01:00
|
|
|
|
if($session)
|
|
|
|
|
{
|
|
|
|
|
$this->read_sessiondata();
|
|
|
|
|
$this->use_session = True;
|
|
|
|
|
foreach(array('start','query','sort','order') as $var)
|
|
|
|
|
{
|
|
|
|
|
if (isset($_POST[$var]))
|
|
|
|
|
{
|
|
|
|
|
$this->$var = $_POST[$var];
|
|
|
|
|
}
|
|
|
|
|
elseif (isset($_GET[$var]))
|
|
|
|
|
{
|
|
|
|
|
$this->$var = $_GET[$var];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$this->save_sessiondata();
|
|
|
|
|
$this->cats = $this->egw_cats->return_array('all',$this->start,True,$this->query,$this->sort,'cat_name',True);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-10 22:40:57 +02:00
|
|
|
|
/**
|
|
|
|
|
* get list of cats where current user has given rights
|
|
|
|
|
*
|
|
|
|
|
* @author Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
|
|
|
|
|
* @param int $perm_type one of EGW_ACL_READ, EGW_ACL_ADD, EGW_ACL_EDIT, EGW_ACL_DELETE, EGW_ACL_DIRECT_BOOKING
|
|
|
|
|
* @return array cat_id => cat_name
|
|
|
|
|
* TODO mark subcats and so on!
|
|
|
|
|
*/
|
2005-02-03 17:42:20 +01:00
|
|
|
|
function get_cats($perm_type)
|
|
|
|
|
{
|
2005-02-20 18:50:39 +01:00
|
|
|
|
$cats = $this->egw_cats->return_sorted_array(0,False,'','','',!$type);
|
|
|
|
|
while (list(,$cat) = @each($cats))
|
2005-02-03 17:42:20 +01:00
|
|
|
|
{
|
2005-02-20 18:50:39 +01:00
|
|
|
|
if($this->is_permitted($cat['id'],$perm_type))
|
2005-02-03 17:42:20 +01:00
|
|
|
|
{
|
2005-02-20 18:50:39 +01:00
|
|
|
|
for ($j=0,$s=''; $j < $cat['level']; $j++)
|
|
|
|
|
{
|
|
|
|
|
$s .= ' ';
|
|
|
|
|
}
|
2005-06-10 22:40:57 +02:00
|
|
|
|
$s .= $GLOBALS['egw']->strip_html($cat['name']);
|
2005-02-20 18:50:39 +01:00
|
|
|
|
if ($cat['app_name'] == 'phpgw')
|
|
|
|
|
{
|
|
|
|
|
$s .= ' <' . lang('Global') . '>';
|
|
|
|
|
}
|
|
|
|
|
if ($cat['owner'] == '-1')
|
|
|
|
|
{
|
|
|
|
|
$s .= ' <' . lang('Global') . ' ' . lang($cat['app_name']) . '>';
|
|
|
|
|
}
|
|
|
|
|
$perm_cats[$cat['id']] = $s;
|
2005-02-03 17:42:20 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2005-02-20 18:50:39 +01:00
|
|
|
|
return $perm_cats;
|
2005-02-03 17:42:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-21 10:52:53 +01:00
|
|
|
|
|
2005-06-10 22:40:57 +02:00
|
|
|
|
/**
|
|
|
|
|
* gets name of category
|
|
|
|
|
*
|
|
|
|
|
* @author Lukas Wei<EFBFBD> <wnz.gh05t@users.sourceforge.net>
|
|
|
|
|
* @param int $cat_id
|
|
|
|
|
* @return mixed name of category
|
|
|
|
|
*/
|
2005-03-21 10:52:53 +01:00
|
|
|
|
function get_cat_name($cat_id)
|
|
|
|
|
{
|
2005-06-10 22:40:57 +02:00
|
|
|
|
$cat = $this->egw_cats->return_single($cat_id);
|
|
|
|
|
return $cat[0]['name'];
|
2005-03-21 10:52:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
2005-06-10 22:40:57 +02:00
|
|
|
|
/**
|
|
|
|
|
* gets userid of admin for given category
|
|
|
|
|
*
|
|
|
|
|
* @author Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
|
|
|
|
|
* @param int $cat_id
|
|
|
|
|
* @return int userid of cat admin
|
|
|
|
|
*/
|
2005-02-20 18:10:48 +01:00
|
|
|
|
function get_cat_admin($cat_id)
|
|
|
|
|
{
|
2005-05-07 15:09:48 +02:00
|
|
|
|
$cat_rights = $this->get_rights($cat_id);
|
2005-05-07 15:08:28 +02:00
|
|
|
|
foreach ($cat_rights as $userid => $right)
|
|
|
|
|
{
|
2005-06-10 22:40:57 +02:00
|
|
|
|
if ($right & EGW_ACL_CAT_ADMIN)
|
2005-05-07 15:08:28 +02:00
|
|
|
|
{
|
|
|
|
|
return $userid;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return lang('none');
|
2005-02-20 18:10:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
2005-06-10 22:40:57 +02:00
|
|
|
|
/**
|
|
|
|
|
* cheks one of the following rights for current user:
|
|
|
|
|
*
|
|
|
|
|
* EGW_ACL_READ, EGW_ACL_ADD, EGW_ACL_EDIT, EGW_ACL_DELETE, EGW_ACL_DIRECT_BOOKING
|
|
|
|
|
*
|
|
|
|
|
* @param int $cat_id
|
|
|
|
|
* @param int $right
|
|
|
|
|
* @return bool user is permitted or not for right
|
|
|
|
|
*/
|
2005-02-20 18:10:48 +01:00
|
|
|
|
function is_permitted($cat_id,$right)
|
|
|
|
|
{
|
|
|
|
|
return $this->permissions['L'.$cat_id] & $right;
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-10 22:40:57 +02:00
|
|
|
|
/**
|
|
|
|
|
* gets all rights from all user for given cat
|
|
|
|
|
*
|
|
|
|
|
* @param int $cat_id
|
|
|
|
|
* @return array userid => right
|
|
|
|
|
*/
|
2005-02-20 18:10:48 +01:00
|
|
|
|
function get_rights($cat_id)
|
|
|
|
|
{
|
|
|
|
|
return $this->so->get_rights('L'.$cat_id);
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-20 18:50:39 +01:00
|
|
|
|
|
2005-02-20 18:10:48 +01:00
|
|
|
|
// privat functions from here on -------------------------------------------------------------------------
|
2005-02-03 17:42:20 +01:00
|
|
|
|
function save_sessiondata()
|
|
|
|
|
{
|
|
|
|
|
$data = array(
|
|
|
|
|
'start' => $this->start,
|
|
|
|
|
'query' => $this->query,
|
|
|
|
|
'sort' => $this->sort,
|
|
|
|
|
'order' => $this->order,
|
|
|
|
|
'limit' => $this->limit,
|
|
|
|
|
);
|
|
|
|
|
if($this->debug) { echo '<br>Read:'; _debug_array($data); }
|
2005-06-10 22:40:57 +02:00
|
|
|
|
$GLOBALS['egw']->session->appsession('session_data','resources_acl',$data);
|
2005-02-03 17:42:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function read_sessiondata()
|
|
|
|
|
{
|
2005-06-10 22:40:57 +02:00
|
|
|
|
$data = $GLOBALS['egw']->session->appsession('session_data','resources_acl');
|
2005-02-03 17:42:20 +01:00
|
|
|
|
if($this->debug) { echo '<br>Read:'; _debug_array($data); }
|
|
|
|
|
|
|
|
|
|
$this->start = $data['start'];
|
|
|
|
|
$this->query = $data['query'];
|
|
|
|
|
$this->sort = $data['sort'];
|
|
|
|
|
$this->order = $data['order'];
|
|
|
|
|
$this->limit = $data['limit'];
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-11 10:10:22 +02:00
|
|
|
|
function set_rights($cat_id,$read,$write,$calread,$calbook,$admin)
|
2005-02-03 17:42:20 +01:00
|
|
|
|
{
|
|
|
|
|
$readcat = $read ? $read : array();
|
|
|
|
|
$writecat = $write ? $write : array();
|
2005-06-11 10:10:22 +02:00
|
|
|
|
$calreadcat = $calread ? $calread : array();
|
|
|
|
|
$calbookcat = $calbook ? $calbook : array();
|
2005-02-20 18:10:48 +01:00
|
|
|
|
$admincat = $admin ? $admin : array();
|
2005-02-03 17:42:20 +01:00
|
|
|
|
|
|
|
|
|
$this->so->remove_location('L' . $cat_id);
|
|
|
|
|
reset($this->accounts);
|
|
|
|
|
while (list($null,$account) = each($this->accounts))
|
|
|
|
|
{
|
|
|
|
|
$account_id = $account['account_id'];
|
|
|
|
|
//write implies read
|
|
|
|
|
$rights = in_array($account_id,$writecat) ?
|
2005-06-10 22:40:57 +02:00
|
|
|
|
(EGW_ACL_READ | EGW_ACL_ADD | EGW_ACL_EDIT | EGW_ACL_DELETE) :
|
|
|
|
|
(in_array($account_id,$readcat) ? EGW_ACL_READ : False);
|
2005-06-11 10:10:22 +02:00
|
|
|
|
$rights = in_array($account_id,$calreadcat) ? ($rights | EGW_ACL_CALREAD) : $rights;
|
|
|
|
|
$rights = in_array($account_id,$calbookcat) ? ($rights | EGW_ACL_DIRECT_BOOKING) : $rights;
|
2005-06-10 22:40:57 +02:00
|
|
|
|
$rights = in_array($account_id,$admincat) ? ($rights | EGW_ACL_CAT_ADMIN) : $rights;
|
2005-02-03 17:42:20 +01:00
|
|
|
|
if ($rights)
|
|
|
|
|
{
|
2005-06-10 22:40:57 +02:00
|
|
|
|
$GLOBALS['egw']->acl->add_repository('resources','L'.$cat_id,$account_id,$rights);
|
2005-02-03 17:42:20 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|