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