2005-02-03 17:42:20 +01:00
|
|
|
<?php
|
2005-11-11 00:35:55 +01:00
|
|
|
/**
|
|
|
|
* eGroupWare - resources
|
|
|
|
*
|
|
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License
|
|
|
|
* @package resources
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
2005-11-09 22:03:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ACL business object for resources
|
|
|
|
*
|
|
|
|
* @package resources
|
|
|
|
*/
|
|
|
|
class bo_acl
|
|
|
|
{
|
|
|
|
/**
|
2009-08-10 21:19:10 +02:00
|
|
|
* @var $permissions Holds alls permissions for resources of user
|
2005-11-09 22:03:35 +01:00
|
|
|
*/
|
|
|
|
var $permissions;
|
2009-08-10 21:19:10 +02:00
|
|
|
|
2005-11-09 22:03:35 +01:00
|
|
|
var $acl;
|
|
|
|
var $start = 0;
|
|
|
|
var $query = '';
|
|
|
|
var $sort = '';
|
|
|
|
var $total = 0;
|
|
|
|
var $cats;
|
2005-02-03 17:42:20 +01:00
|
|
|
|
2005-11-09 22:03:35 +01:00
|
|
|
var $debug;
|
|
|
|
var $use_session = False;
|
2005-02-03 17:42:20 +01:00
|
|
|
|
2005-11-09 22:03:35 +01:00
|
|
|
function bo_acl($session=False)
|
|
|
|
{
|
|
|
|
define('EGW_ACL_CAT_ADMIN',64);
|
|
|
|
define('EGW_ACL_DIRECT_BOOKING',128);
|
|
|
|
define('EGW_ACL_CALREAD',256);
|
2005-02-20 15:41:52 +01:00
|
|
|
|
2005-11-09 22:03:35 +01:00
|
|
|
$this->permissions = $GLOBALS['egw']->acl->get_all_location_rights($GLOBALS['egw_info']['user']['account_id'],'resources',true);
|
|
|
|
$this->egw_cats =& CreateObject('phpgwapi.categories','','resources');
|
|
|
|
$this->debug = False;
|
2009-08-10 21:19:10 +02:00
|
|
|
|
2005-11-09 22:03:35 +01:00
|
|
|
//all this is only needed when called from uiacl.
|
|
|
|
if($session)
|
|
|
|
{
|
|
|
|
$this->read_sessiondata();
|
|
|
|
$this->use_session = True;
|
|
|
|
foreach(array('start','query','sort','order') as $var)
|
2005-02-03 17:42:20 +01:00
|
|
|
{
|
2005-11-09 22:03:35 +01:00
|
|
|
if (isset($_POST[$var]))
|
2005-02-03 17:42:20 +01:00
|
|
|
{
|
2005-11-09 22:03:35 +01:00
|
|
|
$this->$var = $_POST[$var];
|
|
|
|
}
|
|
|
|
elseif (isset($_GET[$var]))
|
|
|
|
{
|
|
|
|
$this->$var = $_GET[$var];
|
2005-02-03 17:42:20 +01:00
|
|
|
}
|
|
|
|
}
|
2005-11-09 22:03:35 +01:00
|
|
|
$this->save_sessiondata();
|
2006-01-17 17:49:46 +01:00
|
|
|
$this->cats = $this->egw_cats->return_sorted_array(0,false,'','','',true);
|
2005-02-03 17:42:20 +01:00
|
|
|
}
|
2005-11-09 22:03:35 +01:00
|
|
|
}
|
2005-02-03 17:42:20 +01:00
|
|
|
|
2005-11-09 22:03:35 +01:00
|
|
|
/**
|
|
|
|
* get list of cats where current user has given rights
|
|
|
|
*
|
|
|
|
* @author Cornelius Weiss <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!
|
|
|
|
*/
|
|
|
|
function get_cats($perm_type)
|
|
|
|
{
|
2006-01-17 17:49:46 +01:00
|
|
|
$cats = $this->egw_cats->return_sorted_array(0,false,'','','',true);
|
2009-02-25 10:00:58 +01:00
|
|
|
#_debug_array($cats);
|
|
|
|
if (!is_array($cats)) $cats = array();
|
|
|
|
foreach($cats as $key=>$cat) {
|
|
|
|
#echo "key:$key"._debug_array($value)."<br>";
|
|
|
|
#_debug_array($cat)."hier<br>";
|
2005-11-09 22:03:35 +01:00
|
|
|
if($this->is_permitted($cat['id'],$perm_type))
|
2005-02-03 17:42:20 +01:00
|
|
|
{
|
2009-08-10 21:19:10 +02:00
|
|
|
$s = str_repeat(' ',$cat['level']) . stripslashes($cat['name']);
|
|
|
|
if ($cat['app_name'] == 'phpgw' || $cat['owner'] == '-1')
|
2005-05-07 15:08:28 +02:00
|
|
|
{
|
2009-08-10 21:19:10 +02:00
|
|
|
$s .= ' ♦';
|
2005-05-07 15:08:28 +02:00
|
|
|
}
|
2005-11-09 22:03:35 +01:00
|
|
|
$perm_cats[$cat['id']] = $s;
|
2005-05-07 15:08:28 +02:00
|
|
|
}
|
2005-02-20 18:10:48 +01:00
|
|
|
}
|
2005-11-09 22:03:35 +01:00
|
|
|
return $perm_cats;
|
|
|
|
}
|
2009-08-10 21:19:10 +02:00
|
|
|
|
|
|
|
|
2005-11-09 22:03:35 +01:00
|
|
|
/**
|
2009-08-10 21:19:10 +02:00
|
|
|
* gets name of category
|
2005-11-09 22:03:35 +01:00
|
|
|
*
|
|
|
|
* @author Lukas Weiss <wnz.gh05t@users.sourceforge.net>
|
|
|
|
* @param int $cat_id
|
|
|
|
* @return mixed name of category
|
|
|
|
*/
|
|
|
|
function get_cat_name($cat_id)
|
|
|
|
{
|
|
|
|
return $this->egw_cats->id2name($cat_id);
|
|
|
|
}
|
2009-08-10 21:19:10 +02:00
|
|
|
|
2005-11-09 22:03:35 +01:00
|
|
|
/**
|
|
|
|
* gets userid of admin for given category
|
|
|
|
*
|
|
|
|
* @author Cornelius Weiss <egw@von-und-zu-weiss.de>
|
|
|
|
* @param int $cat_id
|
|
|
|
* @return int userid of cat admin
|
|
|
|
*/
|
|
|
|
function get_cat_admin($cat_id)
|
|
|
|
{
|
|
|
|
$cat_rights = $this->get_rights($cat_id);
|
|
|
|
foreach ($cat_rights as $userid => $right)
|
2005-02-20 18:10:48 +01:00
|
|
|
{
|
2005-11-09 22:03:35 +01:00
|
|
|
if ($right & EGW_ACL_CAT_ADMIN)
|
|
|
|
{
|
|
|
|
return $userid;
|
|
|
|
}
|
2005-02-20 18:10:48 +01:00
|
|
|
}
|
2005-11-09 22:03:35 +01:00
|
|
|
return lang('none');
|
|
|
|
}
|
2009-08-10 21:19:10 +02:00
|
|
|
|
2005-11-09 22:03:35 +01: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
|
|
|
|
*/
|
|
|
|
function is_permitted($cat_id,$right)
|
|
|
|
{
|
|
|
|
return $this->permissions['L'.$cat_id] & $right;
|
|
|
|
}
|
2009-08-10 21:19:10 +02:00
|
|
|
|
2005-11-09 22:03:35 +01:00
|
|
|
/**
|
|
|
|
* gets all rights from all user for given cat
|
|
|
|
*
|
|
|
|
* @param int $cat_id
|
|
|
|
* @return array userid => right
|
|
|
|
*/
|
|
|
|
function get_rights($cat_id)
|
|
|
|
{
|
|
|
|
return $GLOBALS['egw']->acl->get_all_rights('L'.$cat_id,'resources');
|
|
|
|
}
|
2005-02-20 18:10:48 +01:00
|
|
|
|
2005-02-20 18:50:39 +01:00
|
|
|
|
2005-11-09 22:03:35 +01:00
|
|
|
// privat functions from here on -------------------------------------------------------------------------
|
|
|
|
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); }
|
|
|
|
$GLOBALS['egw']->session->appsession('session_data','resources_acl',$data);
|
|
|
|
}
|
2005-02-03 17:42:20 +01:00
|
|
|
|
2005-11-09 22:03:35 +01:00
|
|
|
function read_sessiondata()
|
|
|
|
{
|
|
|
|
$data = $GLOBALS['egw']->session->appsession('session_data','resources_acl');
|
|
|
|
if($this->debug) { echo '<br>Read:'; _debug_array($data); }
|
2005-02-03 17:42:20 +01:00
|
|
|
|
2005-11-09 22:03:35 +01:00
|
|
|
$this->start = $data['start'];
|
|
|
|
$this->query = $data['query'];
|
|
|
|
$this->sort = $data['sort'];
|
|
|
|
$this->order = $data['order'];
|
|
|
|
$this->limit = $data['limit'];
|
|
|
|
}
|
2005-02-03 17:42:20 +01:00
|
|
|
|
2005-11-09 22:03:35 +01:00
|
|
|
function set_rights($cat_id,$read,$write,$calread,$calbook,$admin)
|
|
|
|
{
|
|
|
|
$readcat = $read ? $read : array();
|
|
|
|
$writecat = $write ? $write : array();
|
|
|
|
$calreadcat = $calread ? $calread : array();
|
|
|
|
$calbookcat = $calbook ? $calbook : array();
|
|
|
|
$admincat = $admin ? $admin : array();
|
2005-02-03 17:42:20 +01:00
|
|
|
|
2005-11-09 22:03:35 +01:00
|
|
|
$GLOBALS['egw']->acl->delete_repository('resources','L' . $cat_id,false);
|
2005-06-12 10:20:44 +02:00
|
|
|
|
2006-12-07 09:12:19 +01:00
|
|
|
foreach($GLOBALS['egw']->accounts->get_list() as $num => $account)
|
2005-11-09 22:03:35 +01:00
|
|
|
{
|
|
|
|
$account_id = $account['account_id'];
|
|
|
|
$rights = false;
|
|
|
|
$rights = in_array($account_id,$readcat) ? ($rights | EGW_ACL_READ) : false;
|
|
|
|
$rights = in_array($account_id,$writecat) ? ($rights | EGW_ACL_READ | EGW_ACL_ADD | EGW_ACL_EDIT | EGW_ACL_DELETE): $rights;
|
|
|
|
$rights = in_array($account_id,$calreadcat) ? ($rights | EGW_ACL_CALREAD) : $rights;
|
|
|
|
$rights = in_array($account_id,$calbookcat) ? ($rights | EGW_ACL_DIRECT_BOOKING | EGW_ACL_CALREAD) : $rights;
|
|
|
|
$rights = in_array($account_id,$admincat) ? ($rights = 511) : $rights;
|
|
|
|
if ($rights)
|
2009-08-10 21:19:10 +02:00
|
|
|
{
|
2005-11-09 22:03:35 +01:00
|
|
|
$GLOBALS['egw']->acl->add_repository('resources','L'.$cat_id,$account_id,$rights);
|
2005-02-03 17:42:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-11-09 22:03:35 +01:00
|
|
|
}
|