1<?php 2/** 3 * ACL administration functions 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Andreas Gohr <andi@splitbrain.org> 7 * @author Anika Henke <anika@selfthinker.org> (concepts) 8 * @author Frank Schubert <frank@schokilade.de> (old version) 9 */ 10 11/** 12 * All DokuWiki plugins to extend the admin function 13 * need to inherit from this class 14 */ 15class admin_plugin_acl extends DokuWiki_Admin_Plugin { 16 public $acl = null; 17 protected $ns = null; 18 /** 19 * The currently selected item, associative array with id and type. 20 * Populated from (in this order): 21 * $_REQUEST['current_ns'] 22 * $_REQUEST['current_id'] 23 * $ns 24 * $ID 25 */ 26 protected $current_item = null; 27 protected $who = ''; 28 protected $usersgroups = array(); 29 protected $specials = array(); 30 31 /** 32 * return prompt for admin menu 33 */ 34 public function getMenuText($language) { 35 return $this->getLang('admin_acl'); 36 } 37 38 /** 39 * return sort order for position in admin menu 40 */ 41 public function getMenuSort() { 42 return 1; 43 } 44 45 /** 46 * handle user request 47 * 48 * Initializes internal vars and handles modifications 49 * 50 * @author Andreas Gohr <andi@splitbrain.org> 51 */ 52 public function handle() { 53 global $AUTH_ACL; 54 global $ID; 55 global $auth; 56 global $config_cascade; 57 global $INPUT; 58 59 // fresh 1:1 copy without replacements 60 $AUTH_ACL = file($config_cascade['acl']['default']); 61 62 // namespace given? 63 if($INPUT->str('ns') == '*'){ 64 $this->ns = '*'; 65 }else{ 66 $this->ns = cleanID($INPUT->str('ns')); 67 } 68 69 if ($INPUT->str('current_ns')) { 70 $this->current_item = array('id' => cleanID($INPUT->str('current_ns')), 'type' => 'd'); 71 } elseif ($INPUT->str('current_id')) { 72 $this->current_item = array('id' => cleanID($INPUT->str('current_id')), 'type' => 'f'); 73 } elseif ($this->ns) { 74 $this->current_item = array('id' => $this->ns, 'type' => 'd'); 75 } else { 76 $this->current_item = array('id' => $ID, 'type' => 'f'); 77 } 78 79 // user or group choosen? 80 $who = trim($INPUT->str('acl_w')); 81 if($INPUT->str('acl_t') == '__g__' && $who){ 82 $this->who = '@'.ltrim($auth->cleanGroup($who),'@'); 83 }elseif($INPUT->str('acl_t') == '__u__' && $who){ 84 $this->who = ltrim($who,'@'); 85 if($this->who != '%USER%' && $this->who != '%GROUP%'){ #keep wildcard as is 86 $this->who = $auth->cleanUser($this->who); 87 } 88 }elseif($INPUT->str('acl_t') && 89 $INPUT->str('acl_t') != '__u__' && 90 $INPUT->str('acl_t') != '__g__'){ 91 $this->who = $INPUT->str('acl_t'); 92 }elseif($who){ 93 $this->who = $who; 94 } 95 96 // handle modifications 97 if($INPUT->has('cmd') && checkSecurityToken()){ 98 $cmd = $INPUT->extract('cmd')->str('cmd'); 99 100 // scope for modifications 101 if($this->ns){ 102 if($this->ns == '*'){ 103 $scope = '*'; 104 }else{ 105 $scope = $this->ns.':*'; 106 } 107 }else{ 108 $scope = $ID; 109 } 110 111 if($cmd == 'save' && $scope && $this->who && $INPUT->has('acl')){ 112 // handle additions or single modifications 113 $this->_acl_del($scope, $this->who); 114 $this->_acl_add($scope, $this->who, $INPUT->int('acl')); 115 }elseif($cmd == 'del' && $scope && $this->who){ 116 // handle single deletions 117 $this->_acl_del($scope, $this->who); 118 }elseif($cmd == 'update'){ 119 $acl = $INPUT->arr('acl'); 120 121 // handle update of the whole file 122 foreach($INPUT->arr('del') as $where => $names){ 123 // remove all rules marked for deletion 124 foreach($names as $who) 125 unset($acl[$where][$who]); 126 } 127 // prepare lines 128 $lines = array(); 129 // keep header 130 foreach($AUTH_ACL as $line){ 131 if($line{0} == '#'){ 132 $lines[] = $line; 133 }else{ 134 break; 135 } 136 } 137 // re-add all rules 138 foreach($acl as $where => $opt){ 139 foreach($opt as $who => $perm){ 140 if ($who[0]=='@') { 141 if ($who!='@ALL') { 142 $who = '@'.ltrim($auth->cleanGroup($who),'@'); 143 } 144 } elseif ($who != '%USER%' && $who != '%GROUP%'){ #keep wildcard as is 145 $who = $auth->cleanUser($who); 146 } 147 $who = auth_nameencode($who,true); 148 $lines[] = "$where\t$who\t$perm\n"; 149 } 150 } 151 // save it 152 io_saveFile($config_cascade['acl']['default'], join('',$lines)); 153 } 154 155 // reload ACL config 156 $AUTH_ACL = file($config_cascade['acl']['default']); 157 } 158 159 // initialize ACL array 160 $this->_init_acl_config(); 161 } 162 163 /** 164 * ACL Output function 165 * 166 * print a table with all significant permissions for the 167 * current id 168 * 169 * @author Frank Schubert <frank@schokilade.de> 170 * @author Andreas Gohr <andi@splitbrain.org> 171 */ 172 public function html() { 173 echo '<div id="acl_manager">'.NL; 174 echo '<h1>'.$this->getLang('admin_acl').'</h1>'.NL; 175 echo '<div class="level1">'.NL; 176 177 echo '<div id="acl__tree">'.NL; 178 $this->_html_explorer(); 179 echo '</div>'.NL; 180 181 echo '<div id="acl__detail">'.NL; 182 $this->_html_detail(); 183 echo '</div>'.NL; 184 echo '</div>'.NL; 185 186 echo '<div class="clearer"></div>'; 187 echo '<h2>'.$this->getLang('current').'</h2>'.NL; 188 echo '<div class="level2">'.NL; 189 $this->_html_table(); 190 echo '</div>'.NL; 191 192 echo '<div class="footnotes"><div class="fn">'.NL; 193 echo '<sup><a id="fn__1" class="fn_bot" href="#fnt__1">1)</a></sup>'.NL; 194 echo $this->getLang('p_include'); 195 echo '</div></div>'; 196 197 echo '</div>'.NL; 198 } 199 200 /** 201 * returns array with set options for building links 202 * 203 * @author Andreas Gohr <andi@splitbrain.org> 204 */ 205 protected function _get_opts($addopts=null){ 206 $opts = array( 207 'do'=>'admin', 208 'page'=>'acl', 209 ); 210 if($this->ns) $opts['ns'] = $this->ns; 211 if($this->who) $opts['acl_w'] = $this->who; 212 213 if(is_null($addopts)) return $opts; 214 return array_merge($opts, $addopts); 215 } 216 217 /** 218 * Display a tree menu to select a page or namespace 219 * 220 * @author Andreas Gohr <andi@splitbrain.org> 221 */ 222 protected function _html_explorer(){ 223 global $conf; 224 global $ID; 225 global $lang; 226 227 $ns = $this->ns; 228 if(empty($ns)){ 229 $ns = dirname(str_replace(':','/',$ID)); 230 if($ns == '.') $ns =''; 231 }elseif($ns == '*'){ 232 $ns =''; 233 } 234 $ns = utf8_encodeFN(str_replace(':','/',$ns)); 235 236 $data = $this->_get_tree($ns); 237 238 // wrap a list with the root level around the other namespaces 239 array_unshift($data, array( 'level' => 0, 'id' => '*', 'type' => 'd', 240 'open' =>'true', 'label' => '['.$lang['mediaroot'].']')); 241 242 echo html_buildlist($data,'acl', 243 array($this,'_html_list_acl'), 244 array($this,'_html_li_acl')); 245 246 } 247 248 /** 249 * get a combined list of media and page files 250 * 251 * @param string $folder an already converted filesystem folder of the current namespace 252 * @param string $limit limit the search to this folder 253 * @return array 254 */ 255 protected function _get_tree($folder,$limit=''){ 256 global $conf; 257 258 // read tree structure from pages and media 259 $data = array(); 260 search($data,$conf['datadir'],'search_index',array('ns' => $folder),$limit); 261 $media = array(); 262 search($media,$conf['mediadir'],'search_index',array('ns' => $folder, 'nofiles' => true),$limit); 263 $data = array_merge($data,$media); 264 unset($media); 265 266 // combine by sorting and removing duplicates 267 usort($data,array($this,'_tree_sort')); 268 $count = count($data); 269 if($count>0) for($i=1; $i<$count; $i++){ 270 if($data[$i-1]['id'] == $data[$i]['id'] && $data[$i-1]['type'] == $data[$i]['type']) { 271 unset($data[$i]); 272 $i++; // duplicate found, next $i can't be a duplicate, so skip forward one 273 } 274 } 275 return $data; 276 } 277 278 /** 279 * usort callback 280 * 281 * Sorts the combined trees of media and page files 282 */ 283 public function _tree_sort($a,$b){ 284 // handle the trivial cases first 285 if ($a['id'] == '') return -1; 286 if ($b['id'] == '') return 1; 287 // split up the id into parts 288 $a_ids = explode(':', $a['id']); 289 $b_ids = explode(':', $b['id']); 290 // now loop through the parts 291 while (count($a_ids) && count($b_ids)) { 292 // compare each level from upper to lower 293 // until a non-equal component is found 294 $cur_result = strcmp(array_shift($a_ids), array_shift($b_ids)); 295 if ($cur_result) { 296 // if one of the components is the last component and is a file 297 // and the other one is either of a deeper level or a directory, 298 // the file has to come after the deeper level or directory 299 if (empty($a_ids) && $a['type'] == 'f' && (count($b_ids) || $b['type'] == 'd')) return 1; 300 if (empty($b_ids) && $b['type'] == 'f' && (count($a_ids) || $a['type'] == 'd')) return -1; 301 return $cur_result; 302 } 303 } 304 // The two ids seem to be equal. One of them might however refer 305 // to a page, one to a namespace, the namespace needs to be first. 306 if (empty($a_ids) && empty($b_ids)) { 307 if ($a['type'] == $b['type']) return 0; 308 if ($a['type'] == 'f') return 1; 309 return -1; 310 } 311 // Now the empty part is either a page in the parent namespace 312 // that obviously needs to be after the namespace 313 // Or it is the namespace that contains the other part and should be 314 // before that other part. 315 if (empty($a_ids)) return ($a['type'] == 'd') ? -1 : 1; 316 if (empty($b_ids)) return ($b['type'] == 'd') ? 1 : -1; 317 return 0; //shouldn't happen 318 } 319 320 /** 321 * Display the current ACL for selected where/who combination with 322 * selectors and modification form 323 * 324 * @author Andreas Gohr <andi@splitbrain.org> 325 */ 326 protected function _html_detail(){ 327 global $ID; 328 329 echo '<form action="'.wl().'" method="post" accept-charset="utf-8"><div class="no">'.NL; 330 331 echo '<div id="acl__user">'; 332 echo $this->getLang('acl_perms').' '; 333 $inl = $this->_html_select(); 334 echo '<input type="text" name="acl_w" class="edit" value="'.(($inl)?'':hsc(ltrim($this->who,'@'))).'" />'.NL; 335 echo '<button type="submit">'.$this->getLang('btn_select').'</button>'.NL; 336 echo '</div>'.NL; 337 338 echo '<div id="acl__info">'; 339 $this->_html_info(); 340 echo '</div>'; 341 342 echo '<input type="hidden" name="ns" value="'.hsc($this->ns).'" />'.NL; 343 echo '<input type="hidden" name="id" value="'.hsc($ID).'" />'.NL; 344 echo '<input type="hidden" name="do" value="admin" />'.NL; 345 echo '<input type="hidden" name="page" value="acl" />'.NL; 346 echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />'.NL; 347 echo '</div></form>'.NL; 348 } 349 350 /** 351 * Print info and editor 352 */ 353 protected function _html_info(){ 354 global $ID; 355 356 if($this->who){ 357 $current = $this->_get_exact_perm(); 358 359 // explain current permissions 360 $this->_html_explain($current); 361 // load editor 362 $this->_html_acleditor($current); 363 }else{ 364 echo '<p>'; 365 if($this->ns){ 366 printf($this->getLang('p_choose_ns'),hsc($this->ns)); 367 }else{ 368 printf($this->getLang('p_choose_id'),hsc($ID)); 369 } 370 echo '</p>'; 371 372 echo $this->locale_xhtml('help'); 373 } 374 } 375 376 /** 377 * Display the ACL editor 378 * 379 * @author Andreas Gohr <andi@splitbrain.org> 380 */ 381 protected function _html_acleditor($current){ 382 global $lang; 383 384 echo '<fieldset>'; 385 if(is_null($current)){ 386 echo '<legend>'.$this->getLang('acl_new').'</legend>'; 387 }else{ 388 echo '<legend>'.$this->getLang('acl_mod').'</legend>'; 389 } 390 391 echo $this->_html_checkboxes($current,empty($this->ns),'acl'); 392 393 if(is_null($current)){ 394 echo '<button type="submit" name="cmd[save]">'.$lang['btn_save'].'</button>'.NL; 395 }else{ 396 echo '<button type="submit" name="cmd[save]">'.$lang['btn_update'].'</button>'.NL; 397 echo '<button type="submit" name="cmd[del]">'.$lang['btn_delete'].'</button>'.NL; 398 } 399 400 echo '</fieldset>'; 401 } 402 403 /** 404 * Explain the currently set permissions in plain english/$lang 405 * 406 * @author Andreas Gohr <andi@splitbrain.org> 407 */ 408 protected function _html_explain($current){ 409 global $ID; 410 global $auth; 411 412 $who = $this->who; 413 $ns = $this->ns; 414 415 // prepare where to check 416 if($ns){ 417 if($ns == '*'){ 418 $check='*'; 419 }else{ 420 $check=$ns.':*'; 421 } 422 }else{ 423 $check = $ID; 424 } 425 426 // prepare who to check 427 if($who{0} == '@'){ 428 $user = ''; 429 $groups = array(ltrim($who,'@')); 430 }else{ 431 $user = $who; 432 $info = $auth->getUserData($user); 433 if($info === false){ 434 $groups = array(); 435 }else{ 436 $groups = $info['grps']; 437 } 438 } 439 440 // check the permissions 441 $perm = auth_aclcheck($check,$user,$groups); 442 443 // build array of named permissions 444 $names = array(); 445 if($perm){ 446 if($ns){ 447 if($perm >= AUTH_DELETE) $names[] = $this->getLang('acl_perm16'); 448 if($perm >= AUTH_UPLOAD) $names[] = $this->getLang('acl_perm8'); 449 if($perm >= AUTH_CREATE) $names[] = $this->getLang('acl_perm4'); 450 } 451 if($perm >= AUTH_EDIT) $names[] = $this->getLang('acl_perm2'); 452 if($perm >= AUTH_READ) $names[] = $this->getLang('acl_perm1'); 453 $names = array_reverse($names); 454 }else{ 455 $names[] = $this->getLang('acl_perm0'); 456 } 457 458 // print permission explanation 459 echo '<p>'; 460 if($user){ 461 if($ns){ 462 printf($this->getLang('p_user_ns'),hsc($who),hsc($ns),join(', ',$names)); 463 }else{ 464 printf($this->getLang('p_user_id'),hsc($who),hsc($ID),join(', ',$names)); 465 } 466 }else{ 467 if($ns){ 468 printf($this->getLang('p_group_ns'),hsc(ltrim($who,'@')),hsc($ns),join(', ',$names)); 469 }else{ 470 printf($this->getLang('p_group_id'),hsc(ltrim($who,'@')),hsc($ID),join(', ',$names)); 471 } 472 } 473 echo '</p>'; 474 475 // add note if admin 476 if($perm == AUTH_ADMIN){ 477 echo '<p>'.$this->getLang('p_isadmin').'</p>'; 478 }elseif(is_null($current)){ 479 echo '<p>'.$this->getLang('p_inherited').'</p>'; 480 } 481 } 482 483 484 /** 485 * Item formatter for the tree view 486 * 487 * User function for html_buildlist() 488 * 489 * @author Andreas Gohr <andi@splitbrain.org> 490 */ 491 protected function _html_list_acl($item){ 492 $ret = ''; 493 // what to display 494 if(!empty($item['label'])){ 495 $base = $item['label']; 496 }else{ 497 $base = ':'.$item['id']; 498 $base = substr($base,strrpos($base,':')+1); 499 } 500 501 // highlight? 502 if( ($item['type']== $this->current_item['type'] && $item['id'] == $this->current_item['id'])) { 503 $cl = ' cur'; 504 } else { 505 $cl = ''; 506 } 507 508 // namespace or page? 509 if($item['type']=='d'){ 510 if($item['open']){ 511 $img = DOKU_BASE.'lib/images/minus.gif'; 512 $alt = '−'; 513 }else{ 514 $img = DOKU_BASE.'lib/images/plus.gif'; 515 $alt = '+'; 516 } 517 $ret .= '<img src="'.$img.'" alt="'.$alt.'" />'; 518 $ret .= '<a href="'. 519 wl('',$this->_get_opts(array('ns'=>$item['id'],'sectok'=>getSecurityToken()))). 520 '" class="idx_dir'.$cl.'">'; 521 $ret .= $base; 522 $ret .= '</a>'; 523 }else{ 524 $ret .= '<a href="'. 525 wl('',$this->_get_opts(array('id'=>$item['id'],'ns'=>'','sectok'=>getSecurityToken()))). 526 '" class="wikilink1'.$cl.'">'; 527 $ret .= noNS($item['id']); 528 $ret .= '</a>'; 529 } 530 return $ret; 531 } 532 533 /** 534 * List Item formatter 535 * 536 * @param array $item 537 * @return string 538 */ 539 public function _html_li_acl($item){ 540 return '<li class="level' . $item['level'] . ' ' . 541 ($item['open'] ? 'open' : 'closed') . '">'; 542 } 543 544 545 /** 546 * Get current ACL settings as multidim array 547 * 548 * @author Andreas Gohr <andi@splitbrain.org> 549 */ 550 public function _init_acl_config(){ 551 global $AUTH_ACL; 552 global $conf; 553 $acl_config=array(); 554 $usersgroups = array(); 555 556 // get special users and groups 557 $this->specials[] = '@ALL'; 558 $this->specials[] = '@'.$conf['defaultgroup']; 559 if($conf['manager'] != '!!not set!!'){ 560 $this->specials = array_merge($this->specials, 561 array_map('trim', 562 explode(',',$conf['manager']))); 563 } 564 $this->specials = array_filter($this->specials); 565 $this->specials = array_unique($this->specials); 566 sort($this->specials); 567 568 foreach($AUTH_ACL as $line){ 569 $line = trim(preg_replace('/#.*$/','',$line)); //ignore comments 570 if(!$line) continue; 571 572 $acl = preg_split('/[ \t]+/',$line); 573 //0 is pagename, 1 is user, 2 is acl 574 575 $acl[1] = rawurldecode($acl[1]); 576 $acl_config[$acl[0]][$acl[1]] = $acl[2]; 577 578 // store non-special users and groups for later selection dialog 579 $ug = $acl[1]; 580 if(in_array($ug,$this->specials)) continue; 581 $usersgroups[] = $ug; 582 } 583 584 $usersgroups = array_unique($usersgroups); 585 sort($usersgroups); 586 ksort($acl_config); 587 588 $this->acl = $acl_config; 589 $this->usersgroups = $usersgroups; 590 } 591 592 /** 593 * Display all currently set permissions in a table 594 * 595 * @author Andreas Gohr <andi@splitbrain.org> 596 */ 597 protected function _html_table(){ 598 global $lang; 599 global $ID; 600 601 echo '<form action="'.wl().'" method="post" accept-charset="utf-8"><div class="no">'.NL; 602 if($this->ns){ 603 echo '<input type="hidden" name="ns" value="'.hsc($this->ns).'" />'.NL; 604 }else{ 605 echo '<input type="hidden" name="id" value="'.hsc($ID).'" />'.NL; 606 } 607 echo '<input type="hidden" name="acl_w" value="'.hsc($this->who).'" />'.NL; 608 echo '<input type="hidden" name="do" value="admin" />'.NL; 609 echo '<input type="hidden" name="page" value="acl" />'.NL; 610 echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />'.NL; 611 echo '<div class="table">'; 612 echo '<table class="inline">'; 613 echo '<tr>'; 614 echo '<th>'.$this->getLang('where').'</th>'; 615 echo '<th>'.$this->getLang('who').'</th>'; 616 echo '<th>'.$this->getLang('perm').'<sup><a id="fnt__1" class="fn_top" href="#fn__1">1)</a></sup></th>'; 617 echo '<th>'.$lang['btn_delete'].'</th>'; 618 echo '</tr>'; 619 foreach($this->acl as $where => $set){ 620 foreach($set as $who => $perm){ 621 echo '<tr>'; 622 echo '<td>'; 623 if(substr($where,-1) == '*'){ 624 echo '<span class="aclns">'.hsc($where).'</span>'; 625 $ispage = false; 626 }else{ 627 echo '<span class="aclpage">'.hsc($where).'</span>'; 628 $ispage = true; 629 } 630 echo '</td>'; 631 632 echo '<td>'; 633 if($who{0} == '@'){ 634 echo '<span class="aclgroup">'.hsc($who).'</span>'; 635 }else{ 636 echo '<span class="acluser">'.hsc($who).'</span>'; 637 } 638 echo '</td>'; 639 640 echo '<td>'; 641 echo $this->_html_checkboxes($perm,$ispage,'acl['.$where.']['.$who.']'); 642 echo '</td>'; 643 644 echo '<td class="check">'; 645 echo '<input type="checkbox" name="del['.hsc($where).'][]" value="'.hsc($who).'" />'; 646 echo '</td>'; 647 echo '</tr>'; 648 } 649 } 650 651 echo '<tr>'; 652 echo '<th class="action" colspan="4">'; 653 echo '<button type="submit" name="cmd[update]">'.$lang['btn_update'].'</button>'; 654 echo '</th>'; 655 echo '</tr>'; 656 echo '</table>'; 657 echo '</div>'; 658 echo '</div></form>'.NL; 659 } 660 661 /** 662 * Returns the permission which were set for exactly the given user/group 663 * and page/namespace. Returns null if no exact match is available 664 * 665 * @author Andreas Gohr <andi@splitbrain.org> 666 */ 667 protected function _get_exact_perm(){ 668 global $ID; 669 if($this->ns){ 670 if($this->ns == '*'){ 671 $check = '*'; 672 }else{ 673 $check = $this->ns.':*'; 674 } 675 }else{ 676 $check = $ID; 677 } 678 679 if(isset($this->acl[$check][$this->who])){ 680 return $this->acl[$check][$this->who]; 681 }else{ 682 return null; 683 } 684 } 685 686 /** 687 * adds new acl-entry to conf/acl.auth.php 688 * 689 * @author Frank Schubert <frank@schokilade.de> 690 */ 691 public function _acl_add($acl_scope, $acl_user, $acl_level){ 692 global $config_cascade; 693 $acl_user = auth_nameencode($acl_user,true); 694 695 // max level for pagenames is edit 696 if(strpos($acl_scope,'*') === false) { 697 if($acl_level > AUTH_EDIT) $acl_level = AUTH_EDIT; 698 } 699 700 $new_acl = "$acl_scope\t$acl_user\t$acl_level\n"; 701 702 return io_saveFile($config_cascade['acl']['default'], $new_acl, true); 703 } 704 705 /** 706 * remove acl-entry from conf/acl.auth.php 707 * 708 * @author Frank Schubert <frank@schokilade.de> 709 */ 710 public function _acl_del($acl_scope, $acl_user){ 711 global $config_cascade; 712 $acl_user = auth_nameencode($acl_user,true); 713 714 $acl_pattern = '^'.preg_quote($acl_scope,'/').'[ \t]+'.$acl_user.'[ \t]+[0-8].*$'; 715 716 return io_deleteFromFile($config_cascade['acl']['default'], "/$acl_pattern/", true); 717 } 718 719 /** 720 * print the permission radio boxes 721 * 722 * @author Frank Schubert <frank@schokilade.de> 723 * @author Andreas Gohr <andi@splitbrain.org> 724 */ 725 protected function _html_checkboxes($setperm,$ispage,$name){ 726 global $lang; 727 728 static $label = 0; //number labels 729 $ret = ''; 730 731 if($ispage && $setperm > AUTH_EDIT) $setperm = AUTH_EDIT; 732 733 foreach(array(AUTH_NONE,AUTH_READ,AUTH_EDIT,AUTH_CREATE,AUTH_UPLOAD,AUTH_DELETE) as $perm){ 734 $label += 1; 735 736 //general checkbox attributes 737 $atts = array( 'type' => 'radio', 738 'id' => 'pbox'.$label, 739 'name' => $name, 740 'value' => $perm ); 741 //dynamic attributes 742 if(!is_null($setperm) && $setperm == $perm) $atts['checked'] = 'checked'; 743 if($ispage && $perm > AUTH_EDIT){ 744 $atts['disabled'] = 'disabled'; 745 $class = ' class="disabled"'; 746 }else{ 747 $class = ''; 748 } 749 750 //build code 751 $ret .= '<label for="pbox'.$label.'"'.$class.'>'; 752 $ret .= '<input '.buildAttributes($atts).' /> '; 753 $ret .= $this->getLang('acl_perm'.$perm); 754 $ret .= '</label>'.NL; 755 } 756 return $ret; 757 } 758 759 /** 760 * Print a user/group selector (reusing already used users and groups) 761 * 762 * @author Andreas Gohr <andi@splitbrain.org> 763 */ 764 protected function _html_select(){ 765 $inlist = false; 766 $usel = ''; 767 $gsel = ''; 768 769 if($this->who && 770 !in_array($this->who,$this->usersgroups) && 771 !in_array($this->who,$this->specials)){ 772 773 if($this->who{0} == '@'){ 774 $gsel = ' selected="selected"'; 775 }else{ 776 $usel = ' selected="selected"'; 777 } 778 }else{ 779 $inlist = true; 780 } 781 782 echo '<select name="acl_t" class="edit">'.NL; 783 echo ' <option value="__g__" class="aclgroup"'.$gsel.'>'.$this->getLang('acl_group').'</option>'.NL; 784 echo ' <option value="__u__" class="acluser"'.$usel.'>'.$this->getLang('acl_user').'</option>'.NL; 785 if (!empty($this->specials)) { 786 echo ' <optgroup label=" ">'.NL; 787 foreach($this->specials as $ug){ 788 if($ug == $this->who){ 789 $sel = ' selected="selected"'; 790 $inlist = true; 791 }else{ 792 $sel = ''; 793 } 794 795 if($ug{0} == '@'){ 796 echo ' <option value="'.hsc($ug).'" class="aclgroup"'.$sel.'>'.hsc($ug).'</option>'.NL; 797 }else{ 798 echo ' <option value="'.hsc($ug).'" class="acluser"'.$sel.'>'.hsc($ug).'</option>'.NL; 799 } 800 } 801 echo ' </optgroup>'.NL; 802 } 803 if (!empty($this->usersgroups)) { 804 echo ' <optgroup label=" ">'.NL; 805 foreach($this->usersgroups as $ug){ 806 if($ug == $this->who){ 807 $sel = ' selected="selected"'; 808 $inlist = true; 809 }else{ 810 $sel = ''; 811 } 812 813 if($ug{0} == '@'){ 814 echo ' <option value="'.hsc($ug).'" class="aclgroup"'.$sel.'>'.hsc($ug).'</option>'.NL; 815 }else{ 816 echo ' <option value="'.hsc($ug).'" class="acluser"'.$sel.'>'.hsc($ug).'</option>'.NL; 817 } 818 } 819 echo ' </optgroup>'.NL; 820 } 821 echo '</select>'.NL; 822 return $inlist; 823 } 824} 825