Code

Updated reference tab
[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>";
101                 $str.="<tr>";
102                 $str.="<td></td><td><b>"._("Group members")."</b><ul>";
103                 foreach($acl['members'] as $type => $name){
104                     if(preg_match("/^G/", $type))
105                     $str .= "<li>".$name."</li>";
106                 }
107                 $str .= "</ul>"; 
108                 $str .= "</td>"; 
109                 $str .= "</tr>";
111                 $str.="<tr>";
112                 $str.="<td></td><td><b>"._("Members")."</b><ul>";
113                 foreach($acl['members'] as $type => $name){
114                     if(!preg_match("/^G/", $type))
115                     $str .= "<li>".$name."</li>";
116                 }
117                 $str .= "</ul>"; 
118                 $str .= "</td>"; 
119                 $str .= "</tr>";
121                 $str .= "<tr><td></td>";
123                 if($acl['type']!='reset'){
124                     $str.="<td><b>"._("Acls")."</b><ul>";
125                     foreach($acl['acl'] as $type => $acl){
127                         if(isset($this->classMapping[$type])){
128                             $str .= "<li>".$this->classMapping[$type].": ".$this->aclToString($acl)."</li>";
129                         }else{
130                             $str .= "<li>".$type.": ".$this->aclToString($acl)."</li>";
131                         }
132                     }
133                     $str .= "</ul>"; 
134                     $str .= "</td>"; 
135                     $str .= "</tr>"; 
136                 }else{
137                     $str .= "<td></td>";
138                 }
139                 $str .= "<tr><td colspan=3><hr></td></tr>"; 
140             }
141         }
142         $str .= "</table>"; 
143         return($str);
144     }
146     function aclToString($acls)
147     {
148         $str ="<ul>";
149         foreach($acls as $name => $acl){
151             if($name == "0") $name = _("All");
153             $str .= "<li>".$name.": <i>";
155             if(preg_match("/r/", $acl)) $str.= _("read").', '; 
156             if(preg_match("/w/", $acl)) $str.= _("write").', '; 
157             if(preg_match("/c/", $acl)) $str.= _("Create").', '; 
158             if(preg_match("/d/", $acl)) $str.= _("Remove").', '; 
159             if(preg_match("/m/", $acl)) $str.= _("Move").', '; 
160             if(preg_match("/s/", $acl)) $str.= _("Owner").', '; 
161             $str = trim($str,', ');
162             $str.= "</i></li>";
163         }
164         return($str."</ul>");
165     }
168 ?>