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