permissions = $GLOBALS['phpgw']->acl->get_all_location_rights($GLOBALS['phpgw_info']['user']['account_id'],'resources',true); $this->phpgw_cats =& CreateObject('phpgwapi.categories','','resources'); $this->debug = False; //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) { if (isset($_POST[$var])) { $this->$var = $_POST[$var]; } elseif (isset($_GET[$var])) { $this->$var = $_GET[$var]; } } $this->save_sessiondata(); $this->cats = $this->phpgw_cats->return_sorted_array(0,false,'','','',true); } } /** * get list of cats where current user has given rights * * @author Cornelius Weiss * @param int $perm_type one of phpgw_ACL_READ, phpgw_ACL_ADD, phpgw_ACL_EDIT, phpgw_ACL_DELETE, phpgw_ACL_DIRECT_BOOKING * @return array cat_id => cat_name * TODO mark subcats and so on! */ function get_cats($perm_type) { $cats = $this->phpgw_cats->return_sorted_array(0,false,'','','',true); while (list(,$cat) = @each($cats)) { if($this->is_permitted($cat['id'],$perm_type)) { for ($j=0,$s=''; $j < $cat['level']; $j++) { $s .= ' '; } $s .= $GLOBALS['phpgw']->strip_html($cat['name']); if ($cat['app_name'] == 'phpgw') { $s .= ' <' . lang('Global') . '>'; } if ($cat['owner'] == '-1') { $s .= ' <' . lang('Global') . ' ' . lang($cat['app_name']) . '>'; } $perm_cats[$cat['id']] = $s; } } return $perm_cats; } /** * gets name of category * * @author Lukas Weiss * @param int $cat_id * @return mixed name of category */ function get_cat_name($cat_id) { return $this->phpgw_cats->id2name($cat_id); } /** * gets userid of admin for given category * * @author Cornelius Weiss * @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) { if ($right & phpgw_ACL_CAT_ADMIN) { return $userid; } } return lang('none'); } /** * cheks one of the following rights for current user: * * phpgw_ACL_READ, phpgw_ACL_ADD, phpgw_ACL_EDIT, phpgw_ACL_DELETE, phpgw_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; } /** * gets all rights from all user for given cat * * @param int $cat_id * @return array userid => right */ function get_rights($cat_id) { return $GLOBALS['phpgw']->acl->get_all_rights('L'.$cat_id,'resources'); } // 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 '
Read:'; _debug_array($data); } $GLOBALS['phpgw']->session->appsession('session_data','resources_acl',$data); } function read_sessiondata() { $data = $GLOBALS['phpgw']->session->appsession('session_data','resources_acl'); if($this->debug) { echo '
Read:'; _debug_array($data); } $this->start = $data['start']; $this->query = $data['query']; $this->sort = $data['sort']; $this->order = $data['order']; $this->limit = $data['limit']; } 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(); $GLOBALS['phpgw']->acl->delete_repository('resources','L' . $cat_id,false); foreach($GLOBALS['phpgw']->accounts->get_list() as $num => $account) { $account_id = $account['account_id']; $rights = false; $rights = in_array($account_id,$readcat) ? ($rights | phpgw_ACL_READ) : false; $rights = in_array($account_id,$writecat) ? ($rights | phpgw_ACL_READ | phpgw_ACL_ADD | phpgw_ACL_EDIT | phpgw_ACL_DELETE): $rights; $rights = in_array($account_id,$calreadcat) ? ($rights | phpgw_ACL_CALREAD) : $rights; $rights = in_array($account_id,$calbookcat) ? ($rights | phpgw_ACL_DIRECT_BOOKING | phpgw_ACL_CALREAD) : $rights; $rights = in_array($account_id,$admincat) ? ($rights = 511) : $rights; if ($rights) { $GLOBALS['phpgw']->acl->add_repository('resources','L'.$cat_id,$account_id,$rights); } } } }