1 | <?php |
---|
2 | /**************************************************************************\ |
---|
3 | * eGroupWare - News * |
---|
4 | * http://www.egroupware.org * |
---|
5 | * -------------------------------------------- * |
---|
6 | * This program is free software; you can redistribute it and/or modify it * |
---|
7 | * under the terms of the GNU General Public License as published by the * |
---|
8 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
9 | * option) any later version. * |
---|
10 | * -------------------------------------------- * |
---|
11 | \**************************************************************************/ |
---|
12 | |
---|
13 | |
---|
14 | class boacl |
---|
15 | { |
---|
16 | var $acl; |
---|
17 | var $start = 0; |
---|
18 | var $query = ''; |
---|
19 | var $sort = ''; |
---|
20 | var $total = 0; |
---|
21 | var $accounts; |
---|
22 | var $cats; |
---|
23 | |
---|
24 | var $debug; |
---|
25 | var $use_session = False; |
---|
26 | |
---|
27 | function boacl($session=False) |
---|
28 | { |
---|
29 | $this->so = CreateObject('news_admin.soacl'); |
---|
30 | $this->accounts = $GLOBALS['phpgw']->accounts->get_list('groups'); |
---|
31 | $this->debug = False; |
---|
32 | //all this is only needed when called from uiacl. not from ui, |
---|
33 | if($session) |
---|
34 | { |
---|
35 | $this->read_sessiondata(); |
---|
36 | $this->use_session = True; |
---|
37 | foreach(array('start','query','sort','order') as $var) |
---|
38 | { |
---|
39 | if (isset($_POST[$var])) |
---|
40 | { |
---|
41 | $this->$var = $_POST[$var]; |
---|
42 | } |
---|
43 | elseif (isset($_GET[$var])) |
---|
44 | { |
---|
45 | $this->$var = $_GET[$var]; |
---|
46 | } |
---|
47 | } |
---|
48 | $this->save_sessiondata(); |
---|
49 | $this->catbo = createobject('phpgwapi.categories'); |
---|
50 | // $main_cat = array(array('id' => 0, 'name' => lang('Global news'))); |
---|
51 | // $this->cats = array_merge($main_cat,$this->catbo->return_array('all',$this->start,True,$this->query,$this->sort,'cat_name',True)); |
---|
52 | $this->cats = $this->catbo->return_array('all',$this->start,True,$this->query,$this->sort,'cat_name',True); |
---|
53 | } |
---|
54 | $this->permissions = $this->get_permissions(True); |
---|
55 | } |
---|
56 | |
---|
57 | function save_sessiondata() |
---|
58 | { |
---|
59 | $data = array( |
---|
60 | 'start' => $this->start, |
---|
61 | 'query' => $this->query, |
---|
62 | 'sort' => $this->sort, |
---|
63 | 'order' => $this->order, |
---|
64 | 'limit' => $this->limit, |
---|
65 | ); |
---|
66 | if($this->debug) { echo '<br>Read:'; _debug_array($data); } |
---|
67 | $GLOBALS['phpgw']->session->appsession('session_data','news_admin_acl',$data); |
---|
68 | } |
---|
69 | |
---|
70 | function read_sessiondata() |
---|
71 | { |
---|
72 | $data = $GLOBALS['phpgw']->session->appsession('session_data','news_admin_acl'); |
---|
73 | if($this->debug) { echo '<br>Read:'; _debug_array($data); } |
---|
74 | |
---|
75 | $this->start = $data['start']; |
---|
76 | $this->query = $data['query']; |
---|
77 | $this->sort = $data['sort']; |
---|
78 | $this->order = $data['order']; |
---|
79 | $this->limit = $data['limit']; |
---|
80 | } |
---|
81 | |
---|
82 | function get_rights($cat_id) |
---|
83 | { |
---|
84 | return $this->so->get_rights('L'.$cat_id); |
---|
85 | } |
---|
86 | |
---|
87 | function is_permitted($cat_id,$right) |
---|
88 | { |
---|
89 | return $this->permissions['L'.$cat_id] & $right; |
---|
90 | } |
---|
91 | |
---|
92 | function is_readable($cat_id) |
---|
93 | { |
---|
94 | return $this->is_permitted($cat_id,PHPGW_ACL_READ); |
---|
95 | } |
---|
96 | |
---|
97 | function is_writeable($cat_id) |
---|
98 | { |
---|
99 | return $this->is_permitted($cat_id,PHPGW_ACL_ADD); |
---|
100 | } |
---|
101 | |
---|
102 | function set_rights($cat_id,$read,$write) |
---|
103 | { |
---|
104 | $readcat = $read ? $read : array(); |
---|
105 | $writecat = $write ? $write : array(); |
---|
106 | |
---|
107 | $this->so->remove_location('L' . $cat_id); |
---|
108 | reset($this->accounts); |
---|
109 | while (list($null,$account) = each($this->accounts)) |
---|
110 | { |
---|
111 | $account_id = $account['account_id']; |
---|
112 | //write implies read |
---|
113 | $rights = in_array($account_id,$writecat) ? |
---|
114 | (PHPGW_ACL_READ | PHPGW_ACL_ADD) : |
---|
115 | (in_array($account_id,$readcat) ? PHPGW_ACL_READ : False); |
---|
116 | if ($rights) |
---|
117 | { |
---|
118 | $GLOBALS['phpgw']->acl->add_repository('news_admin','L'.$cat_id,$account_id,$rights); |
---|
119 | } |
---|
120 | } |
---|
121 | } |
---|
122 | |
---|
123 | //access permissions for current user |
---|
124 | function get_permissions($inc_groups = False) |
---|
125 | { |
---|
126 | return $this->so->get_permissions($GLOBALS['phpgw_info']['user']['account_id'], $inc_groups); |
---|
127 | } |
---|
128 | } |
---|