source: contrib/resources/inc/class.bo_acl.inc.php @ 3524

Revision 3524, 5.4 KB checked in by afernandes, 13 years ago (diff)

Ticket #1416 - Disponibilizado módulo de recursos para a comunidade

  • Property svn:executable set to *
Line 
1<?php
2/**
3 * eGroupWare - resources
4 *
5 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
6 * @package resources
7 * @link http://www.egroupware.org
8 * @version $Id: class.bo_acl.inc.php 22893 2006-12-07 08:12:19Z nelius_weiss $
9 */
10
11/**
12 * ACL business object for resources
13 *
14 * @package resources
15 */
16class bo_acl
17{
18        /**
19        * @var $permissions Holds alls permissions for resources of user
20        */
21        var $permissions;
22       
23        var $acl;
24        var $start = 0;
25        var $query = '';
26        var $sort  = '';
27        var $total = 0;
28        var $cats;
29
30        var $debug;
31        var $use_session = False;
32
33        function bo_acl($session=False)
34        {
35                define('phpgw_ACL_CAT_ADMIN',64);
36                define('phpgw_ACL_DIRECT_BOOKING',128);
37                define('phpgw_ACL_CALREAD',256);
38
39                $this->permissions = $GLOBALS['phpgw']->acl->get_all_location_rights($GLOBALS['phpgw_info']['user']['account_id'],'resources',true);
40                $this->phpgw_cats =& CreateObject('phpgwapi.categories','','resources');
41                $this->debug = False;
42               
43                //all this is only needed when called from uiacl.
44                if($session)
45                {
46                        $this->read_sessiondata();
47                        $this->use_session = True;
48                        foreach(array('start','query','sort','order') as $var)
49                        {
50                                if (isset($_POST[$var]))
51                                {
52                                        $this->$var = $_POST[$var];
53                                }
54                                elseif (isset($_GET[$var]))
55                                {
56                                        $this->$var = $_GET[$var];
57                                }
58                        }
59                        $this->save_sessiondata();
60                        $this->cats = $this->phpgw_cats->return_sorted_array(0,false,'','','',true);
61                }
62        }
63
64        /**
65        * get list of cats where current user has given rights
66        *
67        * @author Cornelius Weiss <phpgw@von-und-zu-weiss.de>
68        * @param int $perm_type one of phpgw_ACL_READ, phpgw_ACL_ADD, phpgw_ACL_EDIT, phpgw_ACL_DELETE, phpgw_ACL_DIRECT_BOOKING
69        * @return array cat_id => cat_name
70        * TODO mark subcats and so on!
71        */
72        function get_cats($perm_type)
73        {
74                $cats = $this->phpgw_cats->return_sorted_array(0,false,'','','',true);
75                while (list(,$cat) = @each($cats))
76                {
77                        if($this->is_permitted($cat['id'],$perm_type))
78                        {
79                                for ($j=0,$s=''; $j < $cat['level']; $j++)
80                                {
81                                        $s .= '&nbsp;';
82                                }
83                                $s .= $GLOBALS['phpgw']->strip_html($cat['name']);
84                                if ($cat['app_name'] == 'phpgw')
85                                {
86                                        $s .= '&nbsp;&lt;' . lang('Global') . '&gt;';
87                                }
88                                if ($cat['owner'] == '-1')
89                                {
90                                        $s .= '&nbsp;&lt;' . lang('Global') . '&nbsp;' . lang($cat['app_name']) . '&gt;';
91                                }
92                                $perm_cats[$cat['id']] = $s;
93                        }
94                }
95                return $perm_cats;
96        }
97       
98       
99        /**
100        * gets name of category
101        *
102        * @author Lukas Weiss <wnz.gh05t@users.sourceforge.net>
103        * @param int $cat_id
104        * @return mixed name of category
105        */
106        function get_cat_name($cat_id)
107        {
108                return $this->phpgw_cats->id2name($cat_id);
109        }
110       
111        /**
112        * gets userid of admin for given category
113        *
114        * @author Cornelius Weiss <phpgw@von-und-zu-weiss.de>
115        * @param int $cat_id
116        * @return int userid of cat admin
117        */
118        function get_cat_admin($cat_id)
119        {
120                $cat_rights = $this->get_rights($cat_id);
121                foreach ($cat_rights as $userid => $right)
122                {
123                        if ($right & phpgw_ACL_CAT_ADMIN)
124                        {
125                                return $userid;
126                        }
127                }
128                return lang('none');
129        }
130       
131        /**
132        * cheks one of the following rights for current user:
133        *
134        * phpgw_ACL_READ, phpgw_ACL_ADD, phpgw_ACL_EDIT, phpgw_ACL_DELETE, phpgw_ACL_DIRECT_BOOKING
135        *
136        * @param int $cat_id
137        * @param int $right
138        * @return bool user is permitted or not for right
139        */
140        function is_permitted($cat_id,$right)
141        {
142                return $this->permissions['L'.$cat_id] & $right;
143        }
144       
145        /**
146        * gets all rights from all user for given cat
147        *
148        * @param int $cat_id
149        * @return array userid => right
150        */
151        function get_rights($cat_id)
152        {
153                return $GLOBALS['phpgw']->acl->get_all_rights('L'.$cat_id,'resources');
154        }
155
156
157        // privat functions from here on -------------------------------------------------------------------------
158        function save_sessiondata()
159        {
160                $data = array(
161                        'start' => $this->start,
162                        'query' => $this->query,
163                        'sort'  => $this->sort,
164                        'order' => $this->order,
165                        'limit' => $this->limit,
166                );
167                if($this->debug) { echo '<br>Read:'; _debug_array($data); }
168                $GLOBALS['phpgw']->session->appsession('session_data','resources_acl',$data);
169        }
170
171        function read_sessiondata()
172        {
173                $data = $GLOBALS['phpgw']->session->appsession('session_data','resources_acl');
174                if($this->debug) { echo '<br>Read:'; _debug_array($data); }
175
176                $this->start  = $data['start'];
177                $this->query  = $data['query'];
178                $this->sort   = $data['sort'];
179                $this->order  = $data['order'];
180                $this->limit = $data['limit'];
181        }
182
183        function set_rights($cat_id,$read,$write,$calread,$calbook,$admin)
184        {
185                $readcat = $read ? $read : array();
186                $writecat = $write ? $write : array();
187                $calreadcat = $calread ? $calread : array();
188                $calbookcat = $calbook ? $calbook : array();
189                $admincat = $admin ? $admin : array();
190
191                $GLOBALS['phpgw']->acl->delete_repository('resources','L' . $cat_id,false);
192
193                foreach($GLOBALS['phpgw']->accounts->get_list() as $num => $account)
194                {
195                        $account_id = $account['account_id'];
196                        $rights = false;
197                        $rights = in_array($account_id,$readcat) ? ($rights | phpgw_ACL_READ) : false;
198                        $rights = in_array($account_id,$writecat) ? ($rights | phpgw_ACL_READ | phpgw_ACL_ADD | phpgw_ACL_EDIT | phpgw_ACL_DELETE): $rights;
199                        $rights = in_array($account_id,$calreadcat) ? ($rights | phpgw_ACL_CALREAD) : $rights;
200                        $rights = in_array($account_id,$calbookcat) ? ($rights | phpgw_ACL_DIRECT_BOOKING | phpgw_ACL_CALREAD) : $rights;
201                        $rights = in_array($account_id,$admincat) ? ($rights = 511) : $rights;
202                        if ($rights)
203                        {
204                                $GLOBALS['phpgw']->acl->add_repository('resources','L'.$cat_id,$account_id,$rights);
205                        }
206                }
207        }
208}
Note: See TracBrowser for help on using the repository browser.