[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
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 20258 2006-01-17 16:49:46Z nelius_weiss $ 9 */ 10 11 /** 12 * ACL business object for resources 13 * 14 * @package resources 15 */ 16 class 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 $accounts; 29 var $cats; 30 31 var $debug; 32 var $use_session = False; 33 34 function bo_acl($session=False) 35 { 36 define('EGW_ACL_CAT_ADMIN',64); 37 define('EGW_ACL_DIRECT_BOOKING',128); 38 define('EGW_ACL_CALREAD',256); 39 40 $this->permissions = $GLOBALS['egw']->acl->get_all_location_rights($GLOBALS['egw_info']['user']['account_id'],'resources',true); 41 $this->egw_cats =& CreateObject('phpgwapi.categories','','resources'); 42 $this->accounts = $GLOBALS['egw']->accounts->get_list(); 43 $this->debug = False; 44 45 //all this is only needed when called from uiacl. 46 if($session) 47 { 48 $this->read_sessiondata(); 49 $this->use_session = True; 50 foreach(array('start','query','sort','order') as $var) 51 { 52 if (isset($_POST[$var])) 53 { 54 $this->$var = $_POST[$var]; 55 } 56 elseif (isset($_GET[$var])) 57 { 58 $this->$var = $_GET[$var]; 59 } 60 } 61 $this->save_sessiondata(); 62 $this->cats = $this->egw_cats->return_sorted_array(0,false,'','','',true); 63 } 64 } 65 66 /** 67 * get list of cats where current user has given rights 68 * 69 * @author Cornelius Weiss <egw@von-und-zu-weiss.de> 70 * @param int $perm_type one of EGW_ACL_READ, EGW_ACL_ADD, EGW_ACL_EDIT, EGW_ACL_DELETE, EGW_ACL_DIRECT_BOOKING 71 * @return array cat_id => cat_name 72 * TODO mark subcats and so on! 73 */ 74 function get_cats($perm_type) 75 { 76 $cats = $this->egw_cats->return_sorted_array(0,false,'','','',true); 77 while (list(,$cat) = @each($cats)) 78 { 79 if($this->is_permitted($cat['id'],$perm_type)) 80 { 81 for ($j=0,$s=''; $j < $cat['level']; $j++) 82 { 83 $s .= ' '; 84 } 85 $s .= $GLOBALS['egw']->strip_html($cat['name']); 86 if ($cat['app_name'] == 'phpgw') 87 { 88 $s .= ' <' . lang('Global') . '>'; 89 } 90 if ($cat['owner'] == '-1') 91 { 92 $s .= ' <' . lang('Global') . ' ' . lang($cat['app_name']) . '>'; 93 } 94 $perm_cats[$cat['id']] = $s; 95 } 96 } 97 return $perm_cats; 98 } 99 100 101 /** 102 * gets name of category 103 * 104 * @author Lukas Weiss <wnz.gh05t@users.sourceforge.net> 105 * @param int $cat_id 106 * @return mixed name of category 107 */ 108 function get_cat_name($cat_id) 109 { 110 return $this->egw_cats->id2name($cat_id); 111 } 112 113 /** 114 * gets userid of admin for given category 115 * 116 * @author Cornelius Weiss <egw@von-und-zu-weiss.de> 117 * @param int $cat_id 118 * @return int userid of cat admin 119 */ 120 function get_cat_admin($cat_id) 121 { 122 $cat_rights = $this->get_rights($cat_id); 123 foreach ($cat_rights as $userid => $right) 124 { 125 if ($right & EGW_ACL_CAT_ADMIN) 126 { 127 return $userid; 128 } 129 } 130 return lang('none'); 131 } 132 133 /** 134 * cheks one of the following rights for current user: 135 * 136 * EGW_ACL_READ, EGW_ACL_ADD, EGW_ACL_EDIT, EGW_ACL_DELETE, EGW_ACL_DIRECT_BOOKING 137 * 138 * @param int $cat_id 139 * @param int $right 140 * @return bool user is permitted or not for right 141 */ 142 function is_permitted($cat_id,$right) 143 { 144 return $this->permissions['L'.$cat_id] & $right; 145 } 146 147 /** 148 * gets all rights from all user for given cat 149 * 150 * @param int $cat_id 151 * @return array userid => right 152 */ 153 function get_rights($cat_id) 154 { 155 return $GLOBALS['egw']->acl->get_all_rights('L'.$cat_id,'resources'); 156 } 157 158 159 // privat functions from here on ------------------------------------------------------------------------- 160 function save_sessiondata() 161 { 162 $data = array( 163 'start' => $this->start, 164 'query' => $this->query, 165 'sort' => $this->sort, 166 'order' => $this->order, 167 'limit' => $this->limit, 168 ); 169 if($this->debug) { echo '<br>Read:'; _debug_array($data); } 170 $GLOBALS['egw']->session->appsession('session_data','resources_acl',$data); 171 } 172 173 function read_sessiondata() 174 { 175 $data = $GLOBALS['egw']->session->appsession('session_data','resources_acl'); 176 if($this->debug) { echo '<br>Read:'; _debug_array($data); } 177 178 $this->start = $data['start']; 179 $this->query = $data['query']; 180 $this->sort = $data['sort']; 181 $this->order = $data['order']; 182 $this->limit = $data['limit']; 183 } 184 185 function set_rights($cat_id,$read,$write,$calread,$calbook,$admin) 186 { 187 $readcat = $read ? $read : array(); 188 $writecat = $write ? $write : array(); 189 $calreadcat = $calread ? $calread : array(); 190 $calbookcat = $calbook ? $calbook : array(); 191 $admincat = $admin ? $admin : array(); 192 193 $GLOBALS['egw']->acl->delete_repository('resources','L' . $cat_id,false); 194 195 foreach($this->accounts as $num => $account) 196 { 197 $account_id = $account['account_id']; 198 $rights = false; 199 $rights = in_array($account_id,$readcat) ? ($rights | EGW_ACL_READ) : false; 200 $rights = in_array($account_id,$writecat) ? ($rights | EGW_ACL_READ | EGW_ACL_ADD | EGW_ACL_EDIT | EGW_ACL_DELETE): $rights; 201 $rights = in_array($account_id,$calreadcat) ? ($rights | EGW_ACL_CALREAD) : $rights; 202 $rights = in_array($account_id,$calbookcat) ? ($rights | EGW_ACL_DIRECT_BOOKING | EGW_ACL_CALREAD) : $rights; 203 $rights = in_array($account_id,$admincat) ? ($rights = 511) : $rights; 204 if ($rights) 205 { 206 $GLOBALS['egw']->acl->add_repository('resources','L'.$cat_id,$account_id,$rights); 207 } 208 } 209 } 210 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |