2005-02-03 17:42:20 +01:00
|
|
|
<?php
|
2005-11-11 00:35:55 +01:00
|
|
|
/**
|
2009-11-05 20:37:28 +01:00
|
|
|
* EGroupWare - resources
|
2005-11-11 00:35:55 +01:00
|
|
|
*
|
2016-05-05 22:22:04 +02:00
|
|
|
* @license http://www.gnu.org/licenses/gpl.Api\Html GNU General Public License
|
2005-11-11 00:35:55 +01:00
|
|
|
* @package resources
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
2005-11-09 22:03:35 +01:00
|
|
|
|
2016-05-05 22:22:04 +02:00
|
|
|
use EGroupware\Api;
|
|
|
|
use EGroupware\Api\Acl;
|
|
|
|
|
2005-11-09 22:03:35 +01:00
|
|
|
/**
|
|
|
|
* ACL business object for resources
|
|
|
|
*
|
2009-11-05 20:37:28 +01:00
|
|
|
* Category rights and admins get inherited from parent categories.
|
|
|
|
* Current rights and the ones inherited from parents get ORed together,
|
|
|
|
* while for admins the "closest" cat-admin will be used.
|
2005-11-09 22:03:35 +01:00
|
|
|
*/
|
2016-05-26 23:32:00 +02:00
|
|
|
class resources_acl_bo
|
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
|
|
|
|
2016-05-26 23:32:00 +02:00
|
|
|
const CAT_ADMIN = 64;
|
|
|
|
const DIRECT_BOOKING = 128;
|
|
|
|
const CAL_READ = 256;
|
2009-08-10 21:50:36 +02:00
|
|
|
/**
|
|
|
|
* Instance of categories class for resources
|
|
|
|
*
|
2016-05-05 22:22:04 +02:00
|
|
|
* @var egw_cats
|
2009-08-10 21:50:36 +02:00
|
|
|
*/
|
|
|
|
var $egw_cats;
|
|
|
|
|
2009-11-05 20:37:28 +01:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
2014-07-23 14:30:39 +02:00
|
|
|
* @param int $user=null account_id of user whos rights to return, or null for current user
|
2009-11-05 20:37:28 +01:00
|
|
|
* @param boolean $session
|
|
|
|
*/
|
2014-07-23 14:30:39 +02:00
|
|
|
function __construct($session=False, $user=null)
|
2005-11-09 22:03:35 +01:00
|
|
|
{
|
2016-05-05 22:22:04 +02:00
|
|
|
$this->egw_cats = new Api\Categories($user, 'resources');
|
2005-11-09 22:03:35 +01:00
|
|
|
$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>
|
2016-05-26 23:32:00 +02:00
|
|
|
* @param int $perm_type one of Acl::READ, Acl::ADD, Acl::EDIT, Acl::DELETE, self::DIRECT_BOOKING
|
2009-08-10 21:50:36 +02:00
|
|
|
* @param int $parent_id=0 cat_id of parent to return only children of that category
|
2005-11-09 22:03:35 +01:00
|
|
|
* @return array cat_id => cat_name
|
|
|
|
* TODO mark subcats and so on!
|
|
|
|
*/
|
2009-08-10 21:50:36 +02:00
|
|
|
function get_cats($perm_type,$parent_id=0)
|
2005-11-09 22:03:35 +01:00
|
|
|
{
|
2009-08-10 21:50:36 +02:00
|
|
|
$cats = $this->egw_cats->return_sorted_array(0,false,'','','',true,$parent_id);
|
2009-02-25 10:00:58 +01:00
|
|
|
#_debug_array($cats);
|
|
|
|
if (!is_array($cats)) $cats = array();
|
2013-08-01 14:59:29 +02:00
|
|
|
$perm_cats = array();
|
2009-02-25 10:00:58 +01:00
|
|
|
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-11-06 11:00:02 +01:00
|
|
|
$s = str_repeat(' ',$cat['level']) . stripslashes($cat['name']);
|
2009-08-10 21:19:10 +02:00
|
|
|
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
|
|
|
}
|
2011-07-08 09:47:45 +02:00
|
|
|
return isset($perm_cats)?$perm_cats:array();
|
2005-11-09 22:03:35 +01:00
|
|
|
}
|
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
|
|
|
|
*/
|
2009-11-05 20:37:28 +01:00
|
|
|
static public function get_cat_name($cat_id)
|
2005-11-09 22:03:35 +01:00
|
|
|
{
|
2009-11-05 20:37:28 +01:00
|
|
|
return $GLOBALS['egw']->categories->id2name($cat_id);
|
2005-11-09 22:03:35 +01:00
|
|
|
}
|
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
|
2018-05-23 10:42:39 +02:00
|
|
|
* @return int|null userid of cat admin or null for none set
|
2005-11-09 22:03:35 +01:00
|
|
|
*/
|
2009-11-05 20:37:28 +01:00
|
|
|
static public function get_cat_admin($cat_id)
|
2005-11-09 22:03:35 +01:00
|
|
|
{
|
2009-11-05 20:37:28 +01:00
|
|
|
$cat_rights = self::get_rights($cat_id);
|
2005-11-09 22:03:35 +01:00
|
|
|
foreach ($cat_rights as $userid => $right)
|
2005-02-20 18:10:48 +01:00
|
|
|
{
|
2016-05-26 23:32:00 +02:00
|
|
|
if ($right & self::CAT_ADMIN)
|
2005-11-09 22:03:35 +01:00
|
|
|
{
|
|
|
|
return $userid;
|
|
|
|
}
|
2005-02-20 18:10:48 +01:00
|
|
|
}
|
2009-11-05 20:37:28 +01:00
|
|
|
// check for an inherited cat admin
|
|
|
|
if (($parent = $GLOBALS['egw']->categories->id2name($cat_id,'parent')))
|
|
|
|
{
|
|
|
|
return self::get_cat_admin($parent);
|
|
|
|
}
|
2018-05-23 10:42:39 +02:00
|
|
|
return null;
|
2005-11-09 22:03:35 +01:00
|
|
|
}
|
2009-08-10 21:19:10 +02:00
|
|
|
|
2005-11-09 22:03:35 +01:00
|
|
|
/**
|
2009-11-05 20:37:28 +01:00
|
|
|
* Permissions including inherited ones
|
|
|
|
*
|
|
|
|
* @var array cat_id => rights
|
|
|
|
*/
|
|
|
|
static private $permissions;
|
|
|
|
static private $resource_acl;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get permissions of current user on a given category
|
|
|
|
*
|
|
|
|
* @param int $cat_id
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
static public function get_permissions($cat_id)
|
2005-11-09 22:03:35 +01:00
|
|
|
{
|
2009-11-05 20:37:28 +01:00
|
|
|
if (!isset(self::$permissions[$cat_id]))
|
|
|
|
{
|
|
|
|
if (is_null(self::$resource_acl))
|
|
|
|
{
|
|
|
|
self::$resource_acl = $GLOBALS['egw']->acl->get_all_location_rights($GLOBALS['egw_info']['user']['account_id'],'resources',true);
|
|
|
|
}
|
|
|
|
self::$permissions[$cat_id] = (int)self::$resource_acl['L'.$cat_id];
|
|
|
|
if (($parent = $GLOBALS['egw']->categories->id2name($cat_id,'parent')))
|
|
|
|
{
|
|
|
|
self::$permissions[$cat_id] |= self::get_permissions($parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//echo "<p>".__METHOD__."($cat_id) = ".self::$permissions[$cat_id]."</p>\n";
|
|
|
|
return self::$permissions[$cat_id];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* checks one of the following rights for current user:
|
|
|
|
*
|
2016-05-26 23:32:00 +02:00
|
|
|
* Acl::READ, Acl::ADD, Acl::EDIT, Acl::DELETE, self::DIRECT_BOOKING
|
2009-11-05 20:37:28 +01:00
|
|
|
*
|
|
|
|
* @param int $cat_id
|
|
|
|
* @param int $right
|
|
|
|
* @return boolean user is permitted or not for right
|
|
|
|
*/
|
|
|
|
static public function is_permitted($cat_id,$right)
|
|
|
|
{
|
|
|
|
if (!isset(self::$permissions[$cat_id]))
|
|
|
|
{
|
|
|
|
self::get_permissions($cat_id);
|
|
|
|
}
|
|
|
|
//echo "<p>".__METHOD__."($cat_id,$right) = ".self::$permissions[$cat_id]." & $right = ".(self::$permissions[$cat_id] & $right)."</p>\n";
|
2012-12-17 23:14:32 +01:00
|
|
|
|
2009-11-05 20:37:28 +01:00
|
|
|
return (boolean) (self::$permissions[$cat_id] & $right);
|
2005-11-09 22:03:35 +01:00
|
|
|
}
|
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
|
|
|
|
*/
|
2009-11-05 20:37:28 +01:00
|
|
|
static public function get_rights($cat_id)
|
2005-11-09 22:03:35 +01:00
|
|
|
{
|
|
|
|
return $GLOBALS['egw']->acl->get_all_rights('L'.$cat_id,'resources');
|
|
|
|
}
|
2005-02-20 18:10:48 +01:00
|
|
|
|
2018-10-01 18:25:55 +02:00
|
|
|
static public function check_calendar_invite($uid)
|
|
|
|
{
|
|
|
|
$resources_config = Api\Config::read('resources');
|
|
|
|
$resources_so = new resources_so();
|
|
|
|
if ($resources_config['bookingrequests'] === 'disabled') {
|
|
|
|
$resources_so = new resources_so();
|
|
|
|
$cat_id = $resources_so->get_value('cat_id', intval(substr($uid, 1)));
|
|
|
|
return resources_acl_bo::is_permitted($cat_id, resources_acl_bo::DIRECT_BOOKING);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
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); }
|
2016-05-05 22:22:04 +02:00
|
|
|
Api\Cache::setSession('resources_acl', 'session_data', $data);
|
2005-11-09 22:03:35 +01:00
|
|
|
}
|
2005-02-03 17:42:20 +01:00
|
|
|
|
2005-11-09 22:03:35 +01:00
|
|
|
function read_sessiondata()
|
|
|
|
{
|
2016-05-05 22:22:04 +02:00
|
|
|
$data = Api\Cache::getSession('resources_acl', 'session_data');
|
2005-11-09 22:03:35 +01:00
|
|
|
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
|
|
|
|
2016-05-26 23:32:00 +02:00
|
|
|
public static function set_rights($cat_id,$read,$write,$calread,$calbook,$admin)
|
2005-11-09 22:03:35 +01:00
|
|
|
{
|
2011-04-14 18:57:49 +02:00
|
|
|
// Clear cache
|
|
|
|
unset(self::$permissions[$cat_id]);
|
|
|
|
|
2005-11-09 22:03:35 +01:00
|
|
|
$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
|
|
|
|
2016-06-14 04:35:43 +02:00
|
|
|
foreach(array_unique(array_merge($readcat, $writecat, $calreadcat, $calbookcat, $admincat)) as $account_id)
|
2005-11-09 22:03:35 +01:00
|
|
|
{
|
|
|
|
$rights = false;
|
2016-05-05 22:22:04 +02:00
|
|
|
$rights = in_array($account_id,$readcat) ? ($rights | Acl::READ) : false;
|
|
|
|
$rights = in_array($account_id,$writecat) ? ($rights | Acl::READ | Acl::ADD | Acl::EDIT | Acl::DELETE): $rights;
|
2016-05-26 23:32:00 +02:00
|
|
|
$rights = in_array($account_id,$calreadcat) ? ($rights | self::CAL_READ) : $rights;
|
|
|
|
$rights = in_array($account_id,$calbookcat) ? ($rights | self::DIRECT_BOOKING | self::CAL_READ) : $rights;
|
2005-11-09 22:03:35 +01:00
|
|
|
$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
|
|
|
}
|