Code

More speed optimizations
[gosa.git] / plugins / admin / groups / class_groupAcl.inc
1 <?php
4 /* FIXME: the complete acl stuff will be redesigned to be more intuitive,
5           which will be possible after introducing templates for html pages.
6           just be patient. */
9 class acl extends plugin
10 {
11   /* CLI vars */
12   var $cli_summary= "Manage group ACL's";
13   var $cli_description= "Some longer text\nfor help";
14   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
16   /* Helpers */
17   var $department= "";
18   var $objects= array();
19   var $object= "";
20   var $current_acl= "";
21   var $selfflag= FALSE;
23   var $gosaSubtreeACL;
25   /* attribute list for save action */
26   var $attributes= array("gosaSubtreeACL");
27   var $objectclasses= array("gosaObject");
29   function acl ($config, $dn= NULL, $parent= NULL)
30   {
31         plugin::plugin($config, $dn, $parent);
33         /* WorkAround */
34         include "acl_definition.inc";
35         $this->objects= $ACLD;
36         $tmp= array_keys($this->objects);
37         $this->object= reset($tmp);
39         $this->selfflag= FALSE;
40         if (isset($this->attrs['gosaSubtreeACL'][0])){
41                 $this->current_acl= preg_replace("/^[^:]*:/", "", $this->attrs['gosaSubtreeACL'][0]);
42                 if (preg_match("/^!:/", $this->attrs['gosaSubtreeACL'][0])){
43                         $this->selfflag= TRUE;
44                 }
45         }
47         /* This is allways true */
48         $this->is_account= TRUE;
49   }
51   function execute()
52   {
53         /* Call parent execute */
54         plugin::execute();
56         /* Do we represent a valid group? */
57         if (!$this->is_account && $this->parent == NULL){
58                 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
59                 _("This 'dn' is no acl container.")."</b>";
60                 return ($display);
61         }
63         /* Show main page */
64         $smarty= get_smarty();
65         if ($_SESSION['js']==FALSE){
66                 $smarty->assign("javascript", "false");
67         } else {
68                 $smarty->assign("javascript", "true");
69         }
70         $smarty->assign("object", $this->object);
71         $obj= array();
72         foreach($this->objects as $key => $value){
73                 $obj[$key]= $key;
74         }
75         if ($this->selfflag){
76                 $smarty->assign("selfflag", "checked");
77         } else {
78                 $smarty->assign("selfflag", "");
79         }
80         $smarty->assign("objects", $obj);
81         $display= $smarty->fetch (get_template_path('acl.tpl', TRUE));
83         /* Show acl stuff */
84         $this->acl= get_module_permission (array($this->current_acl), $this->object, "");
85         $display.= $this->print_attributes ($this->objects[$this->object]);
86         return ($display);
87   }
90   function remove_from_parent()
91   {
92         plugin::remove_from_parent();
93         
94         $this->attrs['gosaSubtreeACL']= array();
96         $ldap= $this->config->get_ldap_link();
97         $ldap->cd($this->dn);
98         $this->cleanup();
99         $ldap->modify ($this->attrs); 
100         show_ldap_error($ldap->get_error(), _("Removing ACL information failed"));
101   }
104   /* Save data to object */
105   function save_object()
106   {
107         plugin::save_object();
109         if (!isset($_POST['object'])){
110                 return;
111         }
113         /* Strip of old information */
114         if ($this->object == "all"){
115                 $this->current_acl= preg_replace ( "/[,]?all[,]?/", "", $this->current_acl);
116         }
117         $this->current_acl= preg_replace ( "/(^|[^a-z0-9A-Z])$this->object#[^,]*[,]?/", "", $this->current_acl);
119         /* assemble new attributes */
120         $attrs= "";
121         if (isset($_POST['all'])){
122                 $attrs.= "#all";
123         }
124         if ($this->object != "all" && !isset($_POST['all']) && $this->object != ""){
125                 foreach ($this->objects[$this->object] as $key => $val){
126                         if (is_integer($key)){
127                                 $aname= $val;
128                         } else {
129                                 $aname= $key;
130                         }
131                         if (isset($_POST[$aname])){
132                                 $attrs.= "#$aname";
133                         }
134                 }
135         }
137         /* append information */
138         if ($attrs != ""){
139                 $tmp= $this->object;
140                 $attrs= $tmp.$attrs;
141         }
142         if ($this->current_acl != "" && $attrs != ""){
143                 $this->current_acl.= ",";
144         }
145         $this->current_acl.= $attrs;
146         if (preg_match("/all#all/", $this->current_acl)){
147                 $this->current_acl= "all";
148         }
149         if (preg_match("/^all,/", $this->current_acl)){
150                 $this->current_acl= "all";
151         }
153         /* Save current object selection */
154         if (isset($_POST['object'])){
155                 $this->object= $_POST['object'];
156         }
157         if (isset($_POST['selfflag'])){
158                 $this->selfflag= TRUE;
159         } else {
160                 $this->selfflag= FALSE;
161         }
162   }
165   /* Save to LDAP */
166   function save()
167   {
168         /* Write back to LDAP */
169         $ldap= $this->config->get_ldap_link();
171         /* Read stuff and only modify subtreeACL entries */
172         plugin::save();
174         if ($this->current_acl != ""){
175                 if ($this->selfflag){
176                         $this->attrs['gosaSubtreeACL']= "!:".$this->current_acl;
177                 } else {
178                         $this->attrs['gosaSubtreeACL']= ":".$this->current_acl;
179                 }
180         } else {
181                 $objectclasses= array();
182                 foreach ($this->attrs['objectClass'] as $oc){
183                         if (!preg_match('/gosaObject/i', $oc)){
184                                 $objectclasses[]= $oc;
185                         }
186                 }
187                 $this->attrs['objectClass']= $objectclasses;
188                 $this->attrs['gosaSubtreeACL']= array();
189         }
191         /* Modify class */
192         $ldap->cd($this->dn);
193         $this->cleanup();
194         $ldap->modify ($this->attrs); 
196         show_ldap_error($ldap->get_error(), _("Saving ACL information failed"));
197   }
200   function print_attributes ($name)
201   {
202         $display= "<input type=checkbox name=\"all\" value=\"1\"";
203         if (chkacl ($this->acl, "all") == ""){
204                 $display.= " checked";
205         }
206         $display.= "><b>"._("All fields are writeable")."</b><br>";
208         # Put strings in right order
209         asort ($name);
211         # Generate checklist
212         $display.= "<table summary=\"\" style=\"width:100%;\">\n";
213         $switch= 0;
214         foreach ($name as $key => $val){
215                 if ($switch == 0){
216                         $display.= " <tr>\n";
217                 }
219                 if (is_integer($key)){
220                         $display.= "<td><input type=checkbox name=\"$val\" value=\"1\" ";
221                         if (chkacl ($this->acl, "$val") == ""){
222                                 $display.= "checked";
223                         }
224                         $display.= ">$val</td>";
225                 } else {
226                         $display.= "<td><input type=checkbox name=\"$key\" value=\"1\"";
227                         if (chkacl ($this->acl, "$key") == ""){
228                                 $display.= "checked";
229                         }
230                         $display.= ">"._($val)."</td>";
231                 }
233                 if ($switch++ == 1){
234                         $display.= " </tr>\n";
235                         $switch= 0;
236                 }
237         }
239         if ($switch == 1){
240                 $display.= "<td></td></tr>";
241         }
242         $display.= "</table>\n";
244         return ($display);
245   }
249 ?>