| [ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare - Preferences * 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.uiaclprefs.inc.php 20129 2005-12-14 23:26:26Z ralfbecker $ */ 13 14 class uiaclprefs 15 { 16 var $acl; 17 var $template; 18 19 var $public_functions = array('index' => True); 20 21 function uiaclprefs() 22 { 23 $GLOBALS['egw']->nextmatchs =& CreateObject('phpgwapi.nextmatchs'); 24 25 if (!is_object($GLOBALS['egw']->html)) 26 { 27 $GLOBALS['egw']->html =& CreateObject('phpgwapi.html'); 28 } 29 } 30 31 function index() 32 { 33 $acl_app = get_var('acl_app',array('POST','GET')); 34 $start = get_var('start',array('POST','GET'),0); 35 $query = get_var('query',array('POST','GET')); 36 $owner = get_var('owner',array('POST','GET'),$GLOBALS['egw_info']['user']['account_id']); 37 38 if (!$acl_app) 39 { 40 $acl_app = 'preferences'; 41 $acl_app_not_passed = True; 42 } 43 else 44 { 45 $GLOBALS['egw']->translation->add_app($acl_app); 46 } 47 // make acl called via sidebox menu of an app, to behave like a part of that app 48 $referer = $_POST['referer']; 49 if (!$referer) 50 { 51 $referer = $GLOBALS['egw']->common->get_referer('/preferences/index.php'); 52 } 53 //echo '<p align="right">'."referer='$referer'</p>\n"; 54 55 $GLOBALS['egw_info']['flags']['currentapp'] = $acl_app; 56 57 if ($acl_app_not_passed) 58 { 59 if(is_object($GLOBALS['egw']->log)) 60 { 61 $GLOBALS['egw']->log->message(array( 62 'text' => 'F-BadmenuactionVariable, failed to pass acl_app.', 63 'line' => __LINE__, 64 'file' => __FILE__ 65 )); 66 $GLOBALS['egw']->log->commit(); 67 } 68 } 69 70 if (($GLOBALS['egw_info']['server']['deny_user_grants_access'] || $owner != $GLOBALS['egw_info']['user']['account_id']) 71 && !isset($GLOBALS['egw_info']['user']['apps']['admin']) || $acl_app_not_passed) 72 { 73 $GLOBALS['egw']->common->egw_header(); 74 echo parse_navbar(); 75 echo '<center><b>' . lang('Access not permitted') . '</b></center>'; 76 $GLOBALS['egw']->common->egw_footer(); 77 return; 78 } 79 80 $owner_name = $GLOBALS['egw']->common->grab_owner_name($owner); 81 if(!($no_privat_grants = $GLOBALS['egw']->accounts->get_type($owner) == 'g')) 82 { 83 // admin setting acl-rights is handled as with group-rights => no private grants !! 84 $no_privat_grants = $owner != $GLOBALS['egw_info']['user']['account_id']; 85 } 86 $this->acl =& CreateObject('phpgwapi.acl',(int)$owner); 87 $this->acl->read_repository(); 88 89 if ($_POST['save'] || $_POST['apply']) 90 { 91 $processed = $_POST['processed']; 92 $to_remove = unserialize(urldecode($processed)); 93 foreach($to_remove as $uid) 94 { 95 //echo "deleting acl-records for $uid=".$GLOBALS['egw']->accounts->id2name($uid)." and $acl_app<br>\n"; 96 $this->acl->delete($acl_app,$uid); 97 } 98 99 /* Group records */ 100 $totalacl = array(); 101 $group_variable = $_POST['g_'.$GLOBALS['egw_info']['flags']['currentapp']]; 102 103 if (is_array($group_variable)) 104 { 105 foreach($group_variable as $rowinfo => $perm) 106 { 107 list($group_id,$rights) = explode('_',$rowinfo); 108 $totalacl[$group_id] += $rights; 109 } 110 foreach($totalacl as $group_id => $rights) 111 { 112 if($no_privat_grants) 113 { 114 /* Don't allow group-grants or admin to grant private */ 115 $rights &= ~EGW_ACL_PRIVATE; 116 } 117 //echo "adding acl-rights $rights for $group_id=".$GLOBALS['egw']->accounts->id2name($group_id)." and $acl_app<br>\n"; 118 $this->acl->add($GLOBALS['egw_info']['flags']['currentapp'],$group_id,$rights); 119 } 120 } 121 122 /* User records */ 123 $totalacl = array(); 124 $user_variable = $_POST['u_'.$GLOBALS['egw_info']['flags']['currentapp']]; 125 126 if (is_array($user_variable)) 127 { 128 foreach($user_variable as $rowinfo => $perm) 129 { 130 list($user_id,$rights) = explode('_',$rowinfo); 131 $totalacl[$user_id] += $rights; 132 } 133 foreach($totalacl as $user_id => $rights) 134 { 135 if($no_privat_grants) 136 { 137 /* Don't allow group-grants or admin to grant private */ 138 $rights &= ~ EGW_ACL_PRIVATE; 139 } 140 //echo "adding acl-rights $rights for $user_id=".$GLOBALS['egw']->accounts->id2name($user_id)." and $acl_app<br>\n"; 141 $this->acl->add($GLOBALS['egw_info']['flags']['currentapp'],$user_id,$rights); 142 } 143 } 144 $this->acl->save_repository(); 145 } 146 if ($_POST['save'] || $_POST['cancel']) 147 { 148 $GLOBALS['egw']->redirect_link($referer); 149 } 150 $GLOBALS['egw_info']['flags']['app_header'] = lang('%1 - Preferences',$GLOBALS['egw_info']['apps'][$acl_app]['title']).' - '.lang('acl').': '.$owner_name; 151 $GLOBALS['egw']->common->egw_header(); 152 echo parse_navbar(); 153 154 $this->template =& CreateObject('phpgwapi.Template',$GLOBALS['egw']->common->get_tpl_dir($acl_app)); 155 $templates = Array ( 156 'preferences' => '../../../preferences/templates/default/acl.tpl', 157 'row_colspan' => 'preference_colspan.tpl', 158 'acl_row' => 'preference_acl_row.tpl' 159 ); 160 161 $this->template->set_file($templates); 162 163 if ($submit) 164 { 165 $this->template->set_var('errors',lang('ACL grants have been updated')); 166 } 167 168 $common_hidden_vars = array( 169 'start' => $start, 170 'query' => $query, 171 'owner' => $owner, 172 'acl_app' => $acl_app, 173 'referer' => $referer, 174 ); 175 $var = Array( 176 'errors' => '', 177 'title' => '<br>', 178 'action_url' => $GLOBALS['egw']->link('/index.php','menuaction=preferences.uiaclprefs.index&acl_app=' . $acl_app), 179 'bg_color' => $GLOBALS['egw_info']['theme']['th_bg'], 180 'lang_save' => lang('Save'), 181 'lang_apply' => lang('Apply'), 182 'lang_cancel' => lang('Cancel'), 183 'common_hidden_vars_form' => $GLOBALS['egw']->html->input_hidden($common_hidden_vars) 184 ); 185 $this->template->set_var($var); 186 187 $vars = $this->template->get_undefined('row_colspan'); 188 foreach($vars as $var) 189 { 190 if(strstr($var,'lang_')) 191 { 192 $value = str_replace('lang_','',$var); 193 $value = str_replace('_',' ',$value); 194 195 $this->template->set_var($var,lang($value)); 196 } 197 } 198 199 $accounts = $GLOBALS['egw']->accounts->search(array( 200 'type' => 'both', 201 'start' => $start, 202 'query' => $query, 203 'order' => 'account_type,account_lid', 204 'sort' => 'ASC', 205 )); 206 $totalentries = $GLOBALS['egw']->accounts->total; 207 208 $memberships = array(); 209 foreach((array) $GLOBALS['egw']->accounts->membership($owner) as $data) 210 { 211 if ($data) $memberships[] = $data['account_id']; 212 } 213 $header_type = ''; 214 $processed = Array(); 215 foreach($accounts as $uid => $data) 216 { 217 if ($data['account_type'] == 'u' && $uid == $owner) 218 continue; /* no need to grant to self if user */ 219 220 if ($data['account_type'] != $header_type) 221 { 222 $this->template->set_var('string',$data['account_type'] == 'g' ? lang('Groups') : lang('Users')); 223 $this->template->parse('row','row_colspan',True); 224 $header_type = $data['account_type']; 225 } 226 $tr_class = $GLOBALS['egw']->nextmatchs->alternate_row_color($tr_color,true); 227 228 if ($data['account_type'] == 'g') 229 { 230 $this->display_row($tr_class,'g_',$data['account_id'],$data['account_lid'],$no_privat_grants,$memberships); 231 } 232 else 233 { 234 $this->display_row($tr_class,'u_',$data['account_id'],$GLOBALS['egw']->common->display_fullname($data['account_lid'],$data['account_firstname'],$data['account_lastname']),$no_privat_grants,$memberships); 235 } 236 $processed[] = $uid; 237 } 238 239 $extra_parms = array( 240 'menuaction' => 'preferences.uiaclprefs.index', 241 'acl_app' => $acl_app, 242 'owner' => $owner, 243 'referer' => $referer, 244 ); 245 246 $var = Array( 247 'nml' => $GLOBALS['egw']->nextmatchs->left('/index.php',$start,$totalentries,$extra_parms), 248 'nmr' => $GLOBALS['egw']->nextmatchs->right('/index.php',$start,$totalentries,$extra_parms), 249 'search_value' => isset($query) && $query ? $GLOBALS['egw']->html->htmlspecialchars($query) : '', 250 'search' => lang('search'), 251 'processed' => urlencode(serialize($processed)) 252 ); 253 254 $this->template->set_var($var); 255 256 $this->template->pfp('out','preferences'); 257 } 258 259 function check_acl($label,$id,$acl,$rights,$right,$disabled=False) 260 { 261 //echo "<p>check_acl($label,$id,$acl,$rights,$right,$disabled)</p>\n"; 262 $this->template->set_var($acl,$label.$GLOBALS['egw_info']['flags']['currentapp'].'['.$id.'_'.$right.']'); 263 $rights_set = ($rights & $right) ? ' checked="1"' : ''; 264 if ($disabled) 265 { 266 // This is so you can't select it in the GUI 267 $rights_set .= ' disabled="1"'; 268 } 269 $this->template->set_var($acl.'_selected',$rights_set); 270 } 271 272 function display_row($tr_class,$label,$id,$name,$no_privat_grants,$memberships) 273 { 274 //echo "<p>display_row(,$label,$id,$name,$no_privat_grants,".print_r($memberships,true).")</p>\n"; 275 $this->template->set_var('row_class',$tr_class); 276 $this->template->set_var('row_color',$GLOBALS['egw_info']['theme'][$tr_class]); 277 $this->template->set_var('user',$name); 278 $rights = $this->acl->get_rights($id,$GLOBALS['egw_info']['flags']['currentapp']); 279 $is_group = $GLOBALS['egw']->accounts->get_type($id) == 'g'; 280 281 foreach(array( 282 EGW_ACL_READ => 'read', 283 EGW_ACL_ADD => 'add', 284 EGW_ACL_EDIT => 'edit', 285 EGW_ACL_DELETE => 'delete', 286 EGW_ACL_PRIVATE => 'private', 287 EGW_ACL_CUSTOM_1 => 'custom_1', 288 EGW_ACL_CUSTOM_2 => 'custom_2', 289 EGW_ACL_CUSTOM_3 => 'custom_3', 290 ) as $right => $name) 291 { 292 $is_group_set = False; 293 if ($is_group) 294 { 295 $grantors = $this->acl->get_ids_for_location($id,$right,$GLOBALS['egw_info']['flags']['currentapp']); 296 if (is_array($grantors)) 297 { 298 foreach($grantors as $grantor) 299 { 300 //echo $GLOBALS['egw']->accounts->id2name($id)."=$id: $name-grant from ".$GLOBALS['egw']->accounts->id2name($grantor)."=$grantor<br>\n"; 301 // check if the grant comes from a group, the owner is a member off, in that case he is NOT allowed to remove it 302 if(in_array($grantor,$memberships)) 303 { 304 //echo "==> member of ==> set by group<br>"; 305 $is_group_set = True; 306 } 307 } 308 } 309 } 310 $this->check_acl($label,$id,$name,$rights,$right,$is_group_set || $no_privat_grants && $right == EGW_ACL_PRIVATE); 311 } 312 $this->template->parse('row','acl_row',True); 313 } 314 } 315 ?>
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 |