xref: /dokuwiki/lib/plugins/acl/admin.php (revision 2b580f7af6af343aef14df02fb81a9ba382ae41a)
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               ($item['open'] ? 'open' : 'closed') . '">';
545    }
546
547
548    /**
549     * Get current ACL settings as multidim array
550     *
551     * @author Andreas Gohr <andi@splitbrain.org>
552     */
553    function _init_acl_config(){
554        global $AUTH_ACL;
555        global $conf;
556        $acl_config=array();
557        $usersgroups = array();
558
559        // get special users and groups
560        $this->specials[] = '@ALL';
561        $this->specials[] = '@'.$conf['defaultgroup'];
562        if($conf['manager'] != '!!not set!!'){
563            $this->specials = array_merge($this->specials,
564                                          array_map('trim',
565                                                    explode(',',$conf['manager'])));
566        }
567        $this->specials = array_filter($this->specials);
568        $this->specials = array_unique($this->specials);
569        sort($this->specials);
570
571        foreach($AUTH_ACL as $line){
572            $line = trim(preg_replace('/#.*$/','',$line)); //ignore comments
573            if(!$line) continue;
574
575            $acl = preg_split('/\s+/',$line);
576            //0 is pagename, 1 is user, 2 is acl
577
578            $acl[1] = rawurldecode($acl[1]);
579            $acl_config[$acl[0]][$acl[1]] = $acl[2];
580
581            // store non-special users and groups for later selection dialog
582            $ug = $acl[1];
583            if(in_array($ug,$this->specials)) continue;
584            $usersgroups[] = $ug;
585        }
586
587        $usersgroups = array_unique($usersgroups);
588        sort($usersgroups);
589        ksort($acl_config);
590
591        $this->acl = $acl_config;
592        $this->usersgroups = $usersgroups;
593    }
594
595    /**
596     * Display all currently set permissions in a table
597     *
598     * @author Andreas Gohr <andi@splitbrain.org>
599     */
600    function _html_table(){
601        global $lang;
602        global $ID;
603
604        echo '<form action="'.wl().'" method="post" accept-charset="utf-8"><div class="no">'.NL;
605        if($this->ns){
606            echo '<input type="hidden" name="ns" value="'.hsc($this->ns).'" />'.NL;
607        }else{
608            echo '<input type="hidden" name="id" value="'.hsc($ID).'" />'.NL;
609        }
610        echo '<input type="hidden" name="acl_w" value="'.hsc($this->who).'" />'.NL;
611        echo '<input type="hidden" name="do" value="admin" />'.NL;
612        echo '<input type="hidden" name="page" value="acl" />'.NL;
613        echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />'.NL;
614        echo '<table class="inline">';
615        echo '<tr>';
616        echo '<th>'.$this->getLang('where').'</th>';
617        echo '<th>'.$this->getLang('who').'</th>';
618        echo '<th>'.$this->getLang('perm').'<sup><a id="fnt__1" class="fn_top" name="fnt__1" href="#fn__1">1)</a></sup></th>';
619        echo '<th>'.$lang['btn_delete'].'</th>';
620        echo '</tr>';
621        foreach($this->acl as $where => $set){
622            foreach($set as $who => $perm){
623                echo '<tr>';
624                echo '<td>';
625                if(substr($where,-1) == '*'){
626                    echo '<span class="aclns">'.hsc($where).'</span>';
627                    $ispage = false;
628                }else{
629                    echo '<span class="aclpage">'.hsc($where).'</span>';
630                    $ispage = true;
631                }
632                echo '</td>';
633
634                echo '<td>';
635                if($who{0} == '@'){
636                    echo '<span class="aclgroup">'.hsc($who).'</span>';
637                }else{
638                    echo '<span class="acluser">'.hsc($who).'</span>';
639                }
640                echo '</td>';
641
642                echo '<td>';
643                echo $this->_html_checkboxes($perm,$ispage,'acl['.$where.']['.$who.']');
644                echo '</td>';
645
646                echo '<td align="center">';
647                echo '<input type="checkbox" name="del['.hsc($where).'][]" value="'.hsc($who).'" />';
648                echo '</td>';
649                echo '</tr>';
650            }
651        }
652
653        echo '<tr>';
654        echo '<th align="right" colspan="4">';
655        echo '<input type="submit" value="'.$lang['btn_update'].'" name="cmd[update]" class="button" />';
656        echo '</th>';
657        echo '</tr>';
658        echo '</table>';
659        echo '</div></form>'.NL;
660    }
661
662
663    /**
664     * Returns the permission which were set for exactly the given user/group
665     * and page/namespace. Returns null if no exact match is available
666     *
667     * @author Andreas Gohr <andi@splitbrain.org>
668     */
669    function _get_exact_perm(){
670        global $ID;
671        if($this->ns){
672            if($this->ns == '*'){
673                $check = '*';
674            }else{
675                $check = $this->ns.':*';
676            }
677        }else{
678            $check = $ID;
679        }
680
681        if(isset($this->acl[$check][$this->who])){
682            return $this->acl[$check][$this->who];
683        }else{
684            return null;
685        }
686    }
687
688    /**
689     * adds new acl-entry to conf/acl.auth.php
690     *
691     * @author  Frank Schubert <frank@schokilade.de>
692     */
693    function _acl_add($acl_scope, $acl_user, $acl_level){
694        global $config_cascade;
695        $acl_config = file_get_contents($config_cascade['acl']['default']);
696        $acl_user = auth_nameencode($acl_user,true);
697
698        // max level for pagenames is edit
699        if(strpos($acl_scope,'*') === false) {
700            if($acl_level > AUTH_EDIT) $acl_level = AUTH_EDIT;
701        }
702
703
704        $new_acl = "$acl_scope\t$acl_user\t$acl_level\n";
705
706        $new_config = $acl_config.$new_acl;
707
708        return io_saveFile($config_cascade['acl']['default'], $new_config);
709    }
710
711    /**
712     * remove acl-entry from conf/acl.auth.php
713     *
714     * @author  Frank Schubert <frank@schokilade.de>
715     */
716    function _acl_del($acl_scope, $acl_user){
717        global $config_cascade;
718        $acl_config = file($config_cascade['acl']['default']);
719        $acl_user = auth_nameencode($acl_user,true);
720
721        $acl_pattern = '^'.preg_quote($acl_scope,'/').'\s+'.$acl_user.'\s+[0-8].*$';
722
723        // save all non!-matching
724        $new_config = preg_grep("/$acl_pattern/", $acl_config, PREG_GREP_INVERT);
725
726        return io_saveFile($config_cascade['acl']['default'], join('',$new_config));
727    }
728
729    /**
730     * print the permission radio boxes
731     *
732     * @author  Frank Schubert <frank@schokilade.de>
733     * @author  Andreas Gohr <andi@splitbrain.org>
734     */
735    function _html_checkboxes($setperm,$ispage,$name){
736        global $lang;
737
738        static $label = 0; //number labels
739        $ret = '';
740
741        if($ispage && $setperm > AUTH_EDIT) $perm = AUTH_EDIT;
742
743        foreach(array(AUTH_NONE,AUTH_READ,AUTH_EDIT,AUTH_CREATE,AUTH_UPLOAD,AUTH_DELETE) as $perm){
744            $label += 1;
745
746            //general checkbox attributes
747            $atts = array( 'type'  => 'radio',
748                           'id'    => 'pbox'.$label,
749                           'name'  => $name,
750                           'value' => $perm );
751            //dynamic attributes
752            if(!is_null($setperm) && $setperm == $perm) $atts['checked']  = 'checked';
753            if($ispage && $perm > AUTH_EDIT){
754                $atts['disabled'] = 'disabled';
755                $class = ' class="disabled"';
756            }else{
757                $class = '';
758            }
759
760            //build code
761            $ret .= '<label for="pbox'.$label.'" title="'.$this->getLang('acl_perm'.$perm).'"'.$class.'>';
762            $ret .= '<input '.buildAttributes($atts).' />&nbsp;';
763            $ret .= $this->getLang('acl_perm'.$perm);
764            $ret .= '</label>'.NL;
765        }
766        return $ret;
767    }
768
769    /**
770     * Print a user/group selector (reusing already used users and groups)
771     *
772     * @author  Andreas Gohr <andi@splitbrain.org>
773     */
774    function _html_select(){
775        global $conf;
776        $inlist = false;
777
778        if($this->who &&
779           !in_array($this->who,$this->usersgroups) &&
780           !in_array($this->who,$this->specials)){
781
782            if($this->who{0} == '@'){
783                $gsel = ' selected="selected"';
784            }else{
785                $usel   = ' selected="selected"';
786            }
787        }else{
788            $usel = '';
789            $gsel = '';
790            $inlist = true;
791        }
792
793
794        echo '<select name="acl_t" class="edit">'.NL;
795        echo '  <option value="__g__" class="aclgroup"'.$gsel.'>'.$this->getLang('acl_group').':</option>'.NL;
796        echo '  <option value="__u__"  class="acluser"'.$usel.'>'.$this->getLang('acl_user').':</option>'.NL;
797        if (!empty($this->specials)) {
798            echo '  <optgroup label="&nbsp;">'.NL;
799            foreach($this->specials as $ug){
800                if($ug == $this->who){
801                    $sel    = ' selected="selected"';
802                    $inlist = true;
803                }else{
804                    $sel = '';
805                }
806
807                if($ug{0} == '@'){
808                        echo '  <option value="'.hsc($ug).'" class="aclgroup"'.$sel.'>'.hsc($ug).'</option>'.NL;
809                }else{
810                        echo '  <option value="'.hsc($ug).'" class="acluser"'.$sel.'>'.hsc($ug).'</option>'.NL;
811                }
812            }
813            echo '  </optgroup>'.NL;
814        }
815        if (!empty($this->usersgroups)) {
816            echo '  <optgroup label="&nbsp;">'.NL;
817            foreach($this->usersgroups as $ug){
818                if($ug == $this->who){
819                    $sel    = ' selected="selected"';
820                    $inlist = true;
821                }else{
822                    $sel = '';
823                }
824
825                if($ug{0} == '@'){
826                        echo '  <option value="'.hsc($ug).'" class="aclgroup"'.$sel.'>'.hsc($ug).'</option>'.NL;
827                }else{
828                        echo '  <option value="'.hsc($ug).'" class="acluser"'.$sel.'>'.hsc($ug).'</option>'.NL;
829                }
830            }
831            echo '  </optgroup>'.NL;
832        }
833        echo '</select>'.NL;
834        return $inlist;
835    }
836}
837