Code

Cleaned up aclResolver
[gosa.git] / gosa-core / plugins / generic / references / class_aclResolver.inc
1 <?php
3 class aclResolver 
4 {
6     private $classMapping = array();
7     private $aclTypes = array();
8     private $affectingACLs = array();
10     function __construct($config, $dn, $parent)
11     {
12         $this->config = &$config;
13         $this->dn = $dn;
15         // Get ACL category for the current object.
16         if(isset($parent->acl_category) && !empty($parent->acl_category)){
17             $this->acl_category = preg_replace("/\/$/","",$parent->acl_category);
18         }
20         // Build class mapping
21         if(!session::is_set('aclConverter::classMapping')){
22             $tmp= session::global_get('plist');
23             $plist= $tmp->info;
24             $map = array();
25             $map['all']= _("All categories");
26             foreach($plist as $class => $plInfo){
27                 if(isset($plInfo['plCategory']) && is_array($plInfo['plCategory'])){
28                     foreach($plInfo['plCategory'] as $category => $desc){
29                         if(!is_numeric($category)){
30                             $map[$category] = $desc['description'];
31                         }
32                     }
33                 }
34             }
35             foreach($plist as $class => $plInfo){
36                 if(isset($plInfo['plCategory']) && is_array($plInfo['plCategory'])){
37                     foreach($plInfo['plCategory'] as $category => $desc){
38                         if(!is_numeric($category)){
39                             $map[$category."/".$class] = $map[$category]." - ".$plInfo['plDescription'];
40                         }else{
41                             $map[$desc."/".$class] = $map[$desc]." - ".$plInfo['plDescription'];
42                         }
43                     }
45                 }
46             }
47             session::set('aclConverter::classMapping', $map);
48         }
49         $this->classMapping = session::get('aclConverter::classMapping');
51         // Go through all ACLs and get those matching out DN.
52         $ui = get_userinfo();
53         foreach($ui->allACLs as $dn => $acls){
54             if(preg_match("/".preg_quote($dn,'/')."$/i", $this->dn)){
55                 foreach($acls as $prio => $acl){
56                     if($acl['type'] == "reset"){
57                         $this->affectingACLs[$dn][$prio] = $acl;
58                         break;
59                     }else{
60                         foreach($acl['acl'] as $category => $attributes){
61                             if(preg_match("/^all($|\/)/", $category) || 
62                                     preg_match("/^".$this->acl_category."($|\/)/", $category)){
63                                 $this->affectingACLs[$dn][$prio] = $acl;
64                                 break;
65                             }
66                         }
67                     }
68                 }
69             }
70         }
72         // Define ACL type translations
73         $this->aclTypes= array("reset" => _("Reset ACLs"),
74                 "one" => _("One level"),
75                 "base" => _("Current object"),
76                 "sub" => _("Complete subtree"),
77                 "psub" => _("Complete subtree (permanent)"),
78                 "role" => _("Use ACL defined in role"));
79     }
82     /*! \brief   Create a human readable HTML result 
83      */    
84     function getReadableACL() 
85     {
86         $str = "<table summary='"._("Object permissions")."' width='100%'>";
87         foreach($this->affectingACLs as $dn => $acls){
88             foreach($acls as $acl){
89                 $str.="<tr>"; 
90                 if(isset($this->config->idepartments[$dn])){
91                     $image= image("images/select_department.png");
92                 }else{
93                     $image= image("images/lists/element.png");
94                 }
96                 $str.="<td style='width:20px;'>".$image."</td>";
97                 $str.="<td><b>".$dn."</b></td>";
98                 $str.="<td rowspan=3>".$this->aclTypes[$acl['type']]."</td>";
99                 $str.="</tr><tr>";
100                 $str.="<td></td><td><b>"._("Members")."</b><ul>";
101                 foreach($acl['members'] as $type => $name){
102                     $str .= "<li>".$name."</li>";
103                 }
104                 $str .= "</ul>"; 
105                 $str .= "</td>"; 
106                 $str .= "</tr><tr><td></td>";
108                 if($acl['type']!='reset'){
109                     $str.="<td><b>"._("Acls")."</b><ul>";
110                     foreach($acl['acl'] as $type => $acl){
112                         if(isset($this->classMapping[$type])){
113                             $str .= "<li>".$this->classMapping[$type].": ".$this->aclToString($acl)."</li>";
114                         }else{
115                             $str .= "<li>".$type.": ".$this->aclToString($acl)."</li>";
116                         }
117                     }
118                     $str .= "</ul>"; 
119                     $str .= "</td>"; 
120                     $str .= "</tr>"; 
121                 }else{
122                     $str .= "<td></td>";
123                 }
124                 $str .= "<tr><td colspan=3><hr></td></tr>"; 
125             }
126         }
127         $str .= "</table>"; 
128         return($str);
129     }
131     function aclToString($acls)
132     {
133         $str ="<ul>";
134         foreach($acls as $name => $acl){
136             if($name == "0") $name = _("All");
138             $str .= "<li>".$name.": <i>";
140             if(preg_match("/r/", $acl)) $str.= _("read").', '; 
141             if(preg_match("/w/", $acl)) $str.= _("write").', '; 
142             if(preg_match("/c/", $acl)) $str.= _("Create").', '; 
143             if(preg_match("/d/", $acl)) $str.= _("Remove").', '; 
144             if(preg_match("/m/", $acl)) $str.= _("Move").', '; 
145             if(preg_match("/s/", $acl)) $str.= _("Owner").', '; 
146             $str = trim($str,', ');
147             $str.= "</i></li>";
148         }
149         return($str."</ul>");
150     }
153 ?>