xref: /dokuwiki/lib/plugins/acl/admin.php (revision 4b3d1701df2b99bcd239b0ab8e55217f523ea8df)
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    var $acl = null;
17    var $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    var $current_item = null;
27    var $who = '';
28    var $usersgroups = array();
29    var $specials = array();
30
31    /**
32     * return prompt for admin menu
33     */
34    function getMenuText($language) {
35        return $this->getLang('admin_acl');
36    }
37
38    /**
39     * return sort order for position in admin menu
40     */
41    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    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    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    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    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     */
254    function _get_tree($folder,$limit=''){
255        global $conf;
256
257        // read tree structure from pages and media
258        $data = array();
259        search($data,$conf['datadir'],'search_index',array('ns' => $folder),$limit);
260        $media = array();
261        search($media,$conf['mediadir'],'search_index',array('ns' => $folder, 'nofiles' => true),$limit);
262        $data = array_merge($data,$media);
263        unset($media);
264
265        // combine by sorting and removing duplicates
266        usort($data,array($this,'_tree_sort'));
267        $count = count($data);
268        if($count>0) for($i=1; $i<$count; $i++){
269            if($data[$i-1]['id'] == $data[$i]['id'] && $data[$i-1]['type'] == $data[$i]['type']) {
270                unset($data[$i]);
271                $i++;  // duplicate found, next $i can't be a duplicate, so skip forward one
272            }
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 '<button type="submit">'.$this->getLang('btn_select').'</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 info 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        echo $this->_html_checkboxes($current,empty($this->ns),'acl');
390
391        if(is_null($current)){
392            echo '<button type="submit" name="cmd[save]">'.$lang['btn_save'].'</button>'.NL;
393        }else{
394            echo '<button type="submit" name="cmd[save]">'.$lang['btn_update'].'</button>'.NL;
395            echo '<button type="submit" name="cmd[del]">'.$lang['btn_delete'].'</button>'.NL;
396        }
397
398        echo '</fieldset>';
399    }
400
401    /**
402     * Explain the currently set permissions in plain english/$lang
403     *
404     * @author Andreas Gohr <andi@splitbrain.org>
405     */
406    function _html_explain($current){
407        global $ID;
408        global $auth;
409
410        $who = $this->who;
411        $ns  = $this->ns;
412
413        // prepare where to check
414        if($ns){
415            if($ns == '*'){
416                $check='*';
417            }else{
418                $check=$ns.':*';
419            }
420        }else{
421            $check = $ID;
422        }
423
424        // prepare who to check
425        if($who{0} == '@'){
426            $user   = '';
427            $groups = array(ltrim($who,'@'));
428        }else{
429            $user = $who;
430            $info = $auth->getUserData($user);
431            if($info === false){
432                $groups = array();
433            }else{
434                $groups = $info['grps'];
435            }
436        }
437
438        // check the permissions
439        $perm = auth_aclcheck($check,$user,$groups);
440
441        // build array of named permissions
442        $names = array();
443        if($perm){
444            if($ns){
445                if($perm >= AUTH_DELETE) $names[] = $this->getLang('acl_perm16');
446                if($perm >= AUTH_UPLOAD) $names[] = $this->getLang('acl_perm8');
447                if($perm >= AUTH_CREATE) $names[] = $this->getLang('acl_perm4');
448            }
449            if($perm >= AUTH_EDIT) $names[] = $this->getLang('acl_perm2');
450            if($perm >= AUTH_READ) $names[] = $this->getLang('acl_perm1');
451            $names = array_reverse($names);
452        }else{
453            $names[] = $this->getLang('acl_perm0');
454        }
455
456        // print permission explanation
457        echo '<p>';
458        if($user){
459            if($ns){
460                printf($this->getLang('p_user_ns'),hsc($who),hsc($ns),join(', ',$names));
461            }else{
462                printf($this->getLang('p_user_id'),hsc($who),hsc($ID),join(', ',$names));
463            }
464        }else{
465            if($ns){
466                printf($this->getLang('p_group_ns'),hsc(ltrim($who,'@')),hsc($ns),join(', ',$names));
467            }else{
468                printf($this->getLang('p_group_id'),hsc(ltrim($who,'@')),hsc($ID),join(', ',$names));
469            }
470        }
471        echo '</p>';
472
473        // add note if admin
474        if($perm == AUTH_ADMIN){
475            echo '<p>'.$this->getLang('p_isadmin').'</p>';
476        }elseif(is_null($current)){
477            echo '<p>'.$this->getLang('p_inherited').'</p>';
478        }
479    }
480
481
482    /**
483     * Item formatter for the tree view
484     *
485     * User function for html_buildlist()
486     *
487     * @author Andreas Gohr <andi@splitbrain.org>
488     */
489    function _html_list_acl($item){
490        $ret = '';
491        // what to display
492        if(!empty($item['label'])){
493            $base = $item['label'];
494        }else{
495            $base = ':'.$item['id'];
496            $base = substr($base,strrpos($base,':')+1);
497        }
498
499        // highlight?
500        if( ($item['type']== $this->current_item['type'] && $item['id'] == $this->current_item['id'])) {
501            $cl = ' cur';
502        } else {
503            $cl = '';
504        }
505
506        // namespace or page?
507        if($item['type']=='d'){
508            if($item['open']){
509                $img   = DOKU_BASE.'lib/images/minus.gif';
510                $alt   = '−';
511            }else{
512                $img   = DOKU_BASE.'lib/images/plus.gif';
513                $alt   = '+';
514            }
515            $ret .= '<img src="'.$img.'" alt="'.$alt.'" />';
516            $ret .= '<a href="'.wl('',$this->_get_opts(array('ns'=>$item['id'],'sectok'=>getSecurityToken()))).'" class="idx_dir'.$cl.'">';
517            $ret .= $base;
518            $ret .= '</a>';
519        }else{
520            $ret .= '<a href="'.wl('',$this->_get_opts(array('id'=>$item['id'],'ns'=>'','sectok'=>getSecurityToken()))).'" class="wikilink1'.$cl.'">';
521            $ret .= noNS($item['id']);
522            $ret .= '</a>';
523        }
524        return $ret;
525    }
526
527
528    function _html_li_acl($item){
529        return '<li class="level' . $item['level'] . ' ' .
530               ($item['open'] ? 'open' : 'closed') . '">';
531    }
532
533
534    /**
535     * Get current ACL settings as multidim array
536     *
537     * @author Andreas Gohr <andi@splitbrain.org>
538     */
539    function _init_acl_config(){
540        global $AUTH_ACL;
541        global $conf;
542        $acl_config=array();
543        $usersgroups = array();
544
545        // get special users and groups
546        $this->specials[] = '@ALL';
547        $this->specials[] = '@'.$conf['defaultgroup'];
548        if($conf['manager'] != '!!not set!!'){
549            $this->specials = array_merge($this->specials,
550                                          array_map('trim',
551                                                    explode(',',$conf['manager'])));
552        }
553        $this->specials = array_filter($this->specials);
554        $this->specials = array_unique($this->specials);
555        sort($this->specials);
556
557        foreach($AUTH_ACL as $line){
558            $line = trim(preg_replace('/#.*$/','',$line)); //ignore comments
559            if(!$line) continue;
560
561            $acl = preg_split('/[ \t]+/',$line);
562            //0 is pagename, 1 is user, 2 is acl
563
564            $acl[1] = rawurldecode($acl[1]);
565            $acl_config[$acl[0]][$acl[1]] = $acl[2];
566
567            // store non-special users and groups for later selection dialog
568            $ug = $acl[1];
569            if(in_array($ug,$this->specials)) continue;
570            $usersgroups[] = $ug;
571        }
572
573        $usersgroups = array_unique($usersgroups);
574        sort($usersgroups);
575        ksort($acl_config);
576
577        $this->acl = $acl_config;
578        $this->usersgroups = $usersgroups;
579    }
580
581    /**
582     * Display all currently set permissions in a table
583     *
584     * @author Andreas Gohr <andi@splitbrain.org>
585     */
586    function _html_table(){
587        global $lang;
588        global $ID;
589
590        echo '<form action="'.wl().'" method="post" accept-charset="utf-8"><div class="no">'.NL;
591        if($this->ns){
592            echo '<input type="hidden" name="ns" value="'.hsc($this->ns).'" />'.NL;
593        }else{
594            echo '<input type="hidden" name="id" value="'.hsc($ID).'" />'.NL;
595        }
596        echo '<input type="hidden" name="acl_w" value="'.hsc($this->who).'" />'.NL;
597        echo '<input type="hidden" name="do" value="admin" />'.NL;
598        echo '<input type="hidden" name="page" value="acl" />'.NL;
599        echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />'.NL;
600        echo '<div class="table">';
601        echo '<table class="inline">';
602        echo '<tr>';
603        echo '<th>'.$this->getLang('where').'</th>';
604        echo '<th>'.$this->getLang('who').'</th>';
605        echo '<th>'.$this->getLang('perm').'<sup><a id="fnt__1" class="fn_top" href="#fn__1">1)</a></sup></th>';
606        echo '<th>'.$lang['btn_delete'].'</th>';
607        echo '</tr>';
608        foreach($this->acl as $where => $set){
609            foreach($set as $who => $perm){
610                echo '<tr>';
611                echo '<td>';
612                if(substr($where,-1) == '*'){
613                    echo '<span class="aclns">'.hsc($where).'</span>';
614                    $ispage = false;
615                }else{
616                    echo '<span class="aclpage">'.hsc($where).'</span>';
617                    $ispage = true;
618                }
619                echo '</td>';
620
621                echo '<td>';
622                if($who{0} == '@'){
623                    echo '<span class="aclgroup">'.hsc($who).'</span>';
624                }else{
625                    echo '<span class="acluser">'.hsc($who).'</span>';
626                }
627                echo '</td>';
628
629                echo '<td>';
630                echo $this->_html_checkboxes($perm,$ispage,'acl['.$where.']['.$who.']');
631                echo '</td>';
632
633                echo '<td class="check">';
634                echo '<input type="checkbox" name="del['.hsc($where).'][]" value="'.hsc($who).'" />';
635                echo '</td>';
636                echo '</tr>';
637            }
638        }
639
640        echo '<tr>';
641        echo '<th class="action" colspan="4">';
642        echo '<button type="submit" name="cmd[update]">'.$lang['btn_update'].'</button>';
643        echo '</th>';
644        echo '</tr>';
645        echo '</table>';
646        echo '</div>';
647        echo '</div></form>'.NL;
648    }
649
650    /**
651     * Returns the permission which were set for exactly the given user/group
652     * and page/namespace. Returns null if no exact match is available
653     *
654     * @author Andreas Gohr <andi@splitbrain.org>
655     */
656    function _get_exact_perm(){
657        global $ID;
658        if($this->ns){
659            if($this->ns == '*'){
660                $check = '*';
661            }else{
662                $check = $this->ns.':*';
663            }
664        }else{
665            $check = $ID;
666        }
667
668        if(isset($this->acl[$check][$this->who])){
669            return $this->acl[$check][$this->who];
670        }else{
671            return null;
672        }
673    }
674
675    /**
676     * adds new acl-entry to conf/acl.auth.php
677     *
678     * @author  Frank Schubert <frank@schokilade.de>
679     */
680    function _acl_add($acl_scope, $acl_user, $acl_level){
681        global $config_cascade;
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        $new_acl = "$acl_scope\t$acl_user\t$acl_level\n";
690
691        return io_saveFile($config_cascade['acl']['default'], $new_acl, true);
692    }
693
694    /**
695     * remove acl-entry from conf/acl.auth.php
696     *
697     * @author  Frank Schubert <frank@schokilade.de>
698     */
699    function _acl_del($acl_scope, $acl_user){
700        global $config_cascade;
701        $acl_user = auth_nameencode($acl_user,true);
702
703        $acl_pattern = '^'.preg_quote($acl_scope,'/').'[ \t]+'.$acl_user.'[ \t]+[0-8].*$';
704
705        return io_deleteFromFile($config_cascade['acl']['default'], "/$acl_pattern/", true);
706    }
707
708    /**
709     * print the permission radio boxes
710     *
711     * @author  Frank Schubert <frank@schokilade.de>
712     * @author  Andreas Gohr <andi@splitbrain.org>
713     */
714    function _html_checkboxes($setperm,$ispage,$name){
715        global $lang;
716
717        static $label = 0; //number labels
718        $ret = '';
719
720        if($ispage && $setperm > AUTH_EDIT) $setperm = AUTH_EDIT;
721
722        foreach(array(AUTH_NONE,AUTH_READ,AUTH_EDIT,AUTH_CREATE,AUTH_UPLOAD,AUTH_DELETE) as $perm){
723            $label += 1;
724
725            //general checkbox attributes
726            $atts = array( 'type'  => 'radio',
727                           'id'    => 'pbox'.$label,
728                           'name'  => $name,
729                           'value' => $perm );
730            //dynamic attributes
731            if(!is_null($setperm) && $setperm == $perm) $atts['checked']  = 'checked';
732            if($ispage && $perm > AUTH_EDIT){
733                $atts['disabled'] = 'disabled';
734                $class = ' class="disabled"';
735            }else{
736                $class = '';
737            }
738
739            //build code
740            $ret .= '<label for="pbox'.$label.'"'.$class.'>';
741            $ret .= '<input '.buildAttributes($atts).' />&#160;';
742            $ret .= $this->getLang('acl_perm'.$perm);
743            $ret .= '</label>'.NL;
744        }
745        return $ret;
746    }
747
748    /**
749     * Print a user/group selector (reusing already used users and groups)
750     *
751     * @author  Andreas Gohr <andi@splitbrain.org>
752     */
753    function _html_select(){
754        $inlist = false;
755        $usel = '';
756        $gsel = '';
757
758        if($this->who &&
759           !in_array($this->who,$this->usersgroups) &&
760           !in_array($this->who,$this->specials)){
761
762            if($this->who{0} == '@'){
763                $gsel = ' selected="selected"';
764            }else{
765                $usel = ' selected="selected"';
766            }
767        }else{
768            $inlist = true;
769        }
770
771        echo '<select name="acl_t" class="edit">'.NL;
772        echo '  <option value="__g__" class="aclgroup"'.$gsel.'>'.$this->getLang('acl_group').'</option>'.NL;
773        echo '  <option value="__u__"  class="acluser"'.$usel.'>'.$this->getLang('acl_user').'</option>'.NL;
774        if (!empty($this->specials)) {
775            echo '  <optgroup label="&#160;">'.NL;
776            foreach($this->specials as $ug){
777                if($ug == $this->who){
778                    $sel    = ' selected="selected"';
779                    $inlist = true;
780                }else{
781                    $sel = '';
782                }
783
784                if($ug{0} == '@'){
785                        echo '  <option value="'.hsc($ug).'" class="aclgroup"'.$sel.'>'.hsc($ug).'</option>'.NL;
786                }else{
787                        echo '  <option value="'.hsc($ug).'" class="acluser"'.$sel.'>'.hsc($ug).'</option>'.NL;
788                }
789            }
790            echo '  </optgroup>'.NL;
791        }
792        if (!empty($this->usersgroups)) {
793            echo '  <optgroup label="&#160;">'.NL;
794            foreach($this->usersgroups as $ug){
795                if($ug == $this->who){
796                    $sel    = ' selected="selected"';
797                    $inlist = true;
798                }else{
799                    $sel = '';
800                }
801
802                if($ug{0} == '@'){
803                        echo '  <option value="'.hsc($ug).'" class="aclgroup"'.$sel.'>'.hsc($ug).'</option>'.NL;
804                }else{
805                        echo '  <option value="'.hsc($ug).'" class="acluser"'.$sel.'>'.hsc($ug).'</option>'.NL;
806                }
807            }
808            echo '  </optgroup>'.NL;
809        }
810        echo '</select>'.NL;
811        return $inlist;
812    }
813}
814