[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare SiteMgr - Web Content Management * 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 /* $Id: class.ACL_BO.inc.php 20295 2006-02-15 12:31:25Z $ */ 13 14 define('SITEMGR_ACL_IS_ADMIN',1); 15 16 class ACL_BO 17 { 18 var $acct; 19 var $acl; 20 21 function ACL_BO() 22 { 23 $this->acct =& $GLOBALS['egw']->accounts; 24 $this->acl =& $GLOBALS['egw']->acl; 25 } 26 27 /** 28 * Checks if user is admin of the specified site 29 * 30 * @param int $site_id=0 id of the site, default to current site 31 * @return boolean 32 */ 33 function is_admin($site_id=0) 34 { 35 static $cache; 36 37 if (!$site_id) $site_id = CURRENT_SITE_ID; 38 39 if (isset($cache[$site_id])) return $cache[$site_id]; 40 41 return $cache[$site_id] = !!($this->acl->get_rights('L'.$site_id,'sitemgr') & SITEMGR_ACL_IS_ADMIN); 42 } 43 44 function set_adminlist($site_id,$account_list) 45 { 46 $this->remove_location($site_id); 47 while (list($null,$account_id) = @each($account_list)) 48 { 49 $this->acl->add_repository('sitemgr','L'.$site_id,$account_id,SITEMGR_ACL_IS_ADMIN); 50 } 51 } 52 53 function remove_location($category_id) 54 { 55 // Used when a category_id is deleted 56 $this->acl->delete_repository('sitemgr','L'.$category_id,false); 57 } 58 59 function copy_permissions($fromcat,$tocat) 60 { 61 $this->remove_location($tocat); 62 63 foreach($this->acl->get_all_rights('L'.$fromcat,'sitemgr') as $account_id => $right) 64 { 65 $this->acl->add_repository('sitemgr','L'.$tocat,$account_id,$right); 66 } 67 } 68 69 function grant_permissions($user, $category_id, $can_read, $can_write) 70 { 71 $rights = 0; 72 if($can_read) 73 { 74 $rights = EGW_ACL_READ; 75 } 76 if($can_write) 77 { 78 $rights = ($rights | EGW_ACL_ADD); 79 } 80 81 if ($rights == 0) 82 { 83 return $this->acl->delete_repository('sitemgr','L'.$category_id,$user); 84 } 85 else 86 { 87 return $this->acl->add_repository('sitemgr','L'.$category_id,$user,$rights); 88 } 89 } 90 91 function get_user_permission_list($category_id) 92 { 93 return $this->get_permission_list($category_id, 'accounts'); 94 } 95 96 function get_group_permission_list($category_id) 97 { 98 return $this->get_permission_list($category_id, 'groups'); 99 } 100 101 function get_permission_list($category_id, $acct_type='both') 102 { 103 static $cache; 104 105 if (isset($cache[$category_id.'-'.$acct_type])) return $cache[$category_id.'-'.$acct_type]; 106 107 $permissions = Array(); 108 foreach($this->acct->get_list($acct_type) as $user) 109 { 110 $permissions[$user['account_id']] = $this->acl->get_specific_rights_for_account($user['account_id'],'L'.$category_id,'sitemgr'); 111 } 112 return $cache[$category_id.'-'.$acct_type] = $permissions; 113 } 114 115 /** 116 * retrives the ACL for a given category 117 * 118 * for the toplevel site_category, there is only an implicit ACL: everybody can read it, site-Admins can change it 119 * 120 * @param int $category_id 121 * @return int EGW_ACL_READ | EGW_ACL_ADD depending on the rights 122 */ 123 function category_acl($category_id) 124 { 125 static $cache; 126 127 if (isset($cache[$category_id])) return $cache[$category_id]; 128 129 if ($category_id == CURRENT_SITE_ID) 130 { 131 $cache[$category_id] = $this->is_admin() ? EGW_ACL_READ | EGW_ACL_ADD : 0; 132 } 133 else 134 { 135 $cache[$category_id] = $this->acl->get_rights('L'.$category_id,'sitemgr'); 136 } 137 return $cache[$category_id]; 138 } 139 140 /** 141 * checks if user can read a given category 142 * 143 * for the toplevel site_category, there is only an implicit ACL: everybody can read it, site-Admins can change it 144 * 145 * @param int $category_id 146 * @return boolean 147 */ 148 function can_read_category($category_id) 149 { 150 return !!($this->category_acl($category_id) & EGW_ACL_READ); 151 } 152 153 /** 154 * checks if user can write / change a given category 155 * 156 * for the toplevel site_category, there is only an implicit ACL: everybody can read it, site-Admins can change it 157 * 158 * @param int $category_id 159 * @return boolean 160 */ 161 function can_write_category($category_id) 162 { 163 if ($this->is_admin()) 164 { 165 return true; 166 } 167 return !!($this->category_acl($category_id) & EGW_ACL_ADD); 168 } 169 170 function get_group_list() 171 { 172 return $this->acct->get_list('groups'); 173 } 174 175 function get_simple_group_list() 176 { 177 return $this->get_simple_list('groups'); 178 } 179 180 function get_simple_list($acct_type='') 181 { 182 $accounts=array(); 183 foreach($this->acct->get_list($acct_type) as $data) 184 { 185 $accounts['i'.$data['account_id']] = array(); 186 } 187 return $accounts; 188 } 189 190 function get_simple_user_list() 191 { 192 return $this->get_simple_list('accounts'); 193 } 194 195 function get_user_list() 196 { 197 return $this->acct->get_list('accounts'); 198 } 199 } 200 ?>
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 |