Code

df5694788e89b0b5d7995922e4b97f3412b9324e
[gosa.git] / gosa-core / plugins / admin / ogroups / tabs_ogroups.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class ogrouptabs extends tabs
24 {
25     var $base= "";
26     var $acl_category; 
27     var $to_remove=array();
29     /*! \brief Stage an object for removal */
30     function remove($object) {
31         if (!isset($this->to_remove[$object])) {
32             $this->to_remove[$object] = $this->by_object[$object];
33             unset($this->by_object[$object]);
34             unset($this->by_name[$object]);
35         }
36     }
38     /*! \brief Unstage an object from removal */
39     function add($object) {
40         if (isset($this->to_remove[$object])) {
41             unset($this->to_remove[$object]);
42         }
43     }
45     function reload($dd)
46     {
47         $objects      = preg_replace('/[\[\]]/', '', $dd);
49         /* Check if we have a group with a set different mixed objects.
50          */
51         $mixed_type = FALSE;
52         for($i = 0 ; $i < (strlen($objects) -1 );$i++){
53             $mixed_type |= $objects[$i] != $objects[($i+1)];
54         }
56         /* If there is a phonequeue,
57          * but there is no user left with goPhoneAccount ... remove it.
58          */
59         $usePhoneTab = false;
60         if(class_available("phonequeue")){
62             foreach($this->by_object['ogroup']->memberList as $dn => $val){
63                 if(isset($this->by_object['ogroup']->objcache[$dn])){
64                     $obj = $this->by_object['ogroup']->objcache[$dn];
65                     if(isset($obj['objectClass'])){
66                         if(in_array("goFonAccount",$obj['objectClass'])){
67                             $usePhoneTab = true;
68                         }
69                     }
70                 }
71             }
72             if((!$usePhoneTab && isset($this->by_object['phonequeue']))||
73                     (!preg_match("/U/",$objects) && isset($this->by_object['phonequeue']))){
74                 $this->remove('phonequeue');
75             }
76         }
78         /* Remove mail group if there is no user anymore 
79          */
80         if(class_available("mailogroup")){
81             if(!preg_match("/U/",$objects) && isset($this->by_object['mailogroup'])){
82                 $this->remove('mailogroup');
83             }
84         }
85         if(class_available("GroupwareDistributionList")){
86             if(!preg_match("/U/",$objects) && isset($this->by_object['GroupwareDistributionList'])){
87                 $this->remove('GroupwareDistributionList');
88             }
89         }
91         /* Remove terminal group, if theres no terminal left in the object list 
92          */
93         if(class_available("termgroup")){
94             if(($mixed_type && isset($this->by_object['termgroup'])) ||
95                     !preg_match("/T/",$objects) && !preg_match("/W/",$objects) && isset($this->by_object['termgroup'])){
96                 $this->remove('termgroup');    
97             }
98         }
99         if(class_available("termservice")){
100             if(($mixed_type && isset($this->by_object['termservice'])) ||
101                     !preg_match("/T/",$objects) &&(isset($this->by_object['termservice']))){
102                 $this->remove('termservice');    
103             }
104         }
105         if(class_available("termstartup")){
106             if(($mixed_type && isset($this->by_object['termstartup'])) ||
107                     !preg_match("/T/",$objects)&&(isset($this->by_object['termstartup']))){
108                 $this->remove('termstartup');
109             }
110         }
112         /* Remove ws tabs, if theres no ws left in the object list */
113         if(class_available("workservice")){
114             if(($mixed_type && isset($this->by_object['workservice'])) ||
115                     (!preg_match("/W/",$objects))&&(isset($this->by_object['workservice']))){
116                 $this->remove('workservice');
117             }
118         }
119         if(class_available("workstartup")){
120             if(($mixed_type && isset($this->by_object['workstartup'])) ||
121                     (!preg_match("/S/",$objects) && !preg_match("/W/",$objects))&&(isset($this->by_object['workstartup']))){
122                 $this->remove('workstartup');
123                 if (isset($this->by_object['faiSummary'])){
124                     $this->remove('faiSummary');
125                 }
126             }
127         }
129         /* Create goPhoneAccount if theres an user with goPhoneAccount
130          * but only if there is currently no queue enabled.
131          */
132         if(class_available("phonequeue")){
133             if(!isset($this->by_object['phonequeue'])){
134                 foreach($this->by_object['ogroup']->memberList as $dn => $val){
135                     if(isset($this->by_object['ogroup']->objcache[$dn])){
136                         $obj = $this->by_object['ogroup']->objcache[$dn];
137                         if(isset($obj['objectClass'])){
138                             if(in_array("goFonAccount",$obj['objectClass'])){
139                                 $this->by_name['phonequeue']= _("Phone queue");
140                                 $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
141                                 $this->by_object['phonequeue']->parent= &$this;
142                                 $this->add('phonequeue');
143                                 break;
144                             }
145                         }
146                     }
147                 }
148             }
149         }
151         /* Add mail group tab , if there is curerntly no mail tab defined */ 
152         if(class_available("mailogroup")){
153             if((preg_match("/U/",$objects))&&(!isset($this->by_object['mailogroup']))){
154                 if (preg_match("/olab/i",$this->config->get_cfg_value("core","mailMethod"))){
155                     $this->by_name['mailogroup']= _("Mail");
156                     $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
157                     $this->by_object['mailogroup']->parent= &$this;
158                     $this->add('mailogroup');
159                 }
160             }
161         }
162         if(class_available("GroupwareDistributionList")){
163             if((preg_match("/U/",$objects))&&(!isset($this->by_object['GroupwareDistributionList']))){
164                 $this->by_name['GroupwareDistributionList']= _("Groupware");
165                 $this->by_object['GroupwareDistributionList']= new GroupwareDistributionList($this->config, $this->dn);
166                 $this->by_object['GroupwareDistributionList']->parent= &$this;
167                 $this->add('GroupwareDistributionList');
168             }
169         }
171         /* Add Terminal tab */
172         if(class_available("termgroup")){
173             if(!$mixed_type && 
174                     ((preg_match("/T/",$objects)) || (preg_match("/W/",$objects)))&&(!isset($this->by_object['termgroup']))){
175                 if(!isset($this->by_object['termgroup'])){
176                     $this->by_name['termgroup']= _("System settings");
177                     $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
178                     $this->by_object['termgroup']->inheritTimeServer = false;
179                     $this->by_object['termgroup']->parent= &$this;
180                     $this->add('termgroup');
181                 }
182             }
183         }
184         if(class_available("termstartup")){
185             if(!$mixed_type &&
186                     preg_match("/T/",$objects) &&(!isset($this->by_object['termstartup']))){
187                 if(!isset($this->by_object['termstartup'])){
188                     $this->by_name['termstartup']= _("Recipe");
189                     $this->by_object['termstartup']= new termstartup($this->config, $this->dn,$this->by_object['ogroup']);
190                     $this->by_object['termstartup']->parent= &$this;
191                     $this->by_object['termstartup']->acl = "#all#";
192                     $this->add('termstartup');
193                 }
194             }
195         }
196         if(!$mixed_type &&
197                 class_available("termservice")){
198             if(preg_match("/T/",$objects) &&(!isset($this->by_object['termservice']))){
199                 if(!isset($this->by_object['termservice'])){
200                     $this->by_name['termservice']= _("Devices");
201                     $this->by_object['termservice']= new termservice($this->config, $this->dn,$this->by_object['ogroup']);
202                     $this->by_object['termservice']->parent= &$this;
203                     $this->by_object['termservice']->acl = "#all#";
204                     $this->add('termservice');
205                 }
206             }
207         }
209         /* Add Workstation tabs */
210         if(class_available("workstartup")){
211             if(!$mixed_type &&
212                     (preg_match("/S/",$objects) || preg_match("/W/",$objects))&&(!isset($this->by_object['workstartup']))){
213                 $this->by_name['workstartup']= _("Recipe");
214                 $this->by_object['workstartup']= new workstartup($this->config, $this->dn);
215                 $this->by_object['workstartup']->parent= &$this;
216                 $this->add("workstartup");
217             }
218         }
219         if(!$mixed_type &&
220                 class_available("workservice")){
221             if((preg_match("/W/",$objects))&&(!isset($this->by_object['workservice']))){
222                 $this->by_name['workservice']= _("Devices");
223                 $this->by_object['workservice']= new workservice($this->config, $this->dn);
224                 $this->by_object['workservice']->inheritTimeServer = false;
225                 $this->by_object['workservice']->parent= &$this;
226                 $this->add("workservice");
227             }
228         }
229         if(class_available("faiSummary")){
230             if(!$mixed_type &&
231                     (preg_match("/S/",$objects) || preg_match("/W/",$objects))&&(!isset($this->by_object['faiSummary']))){
232                 $this->by_name['faiSummary']= _("Deployment summary");
233                 $this->by_object['faiSummary']= new faiSummaryTab($this->config, $this->dn);
234                 $this->by_object['faiSummary']->parent= &$this;
235                 $this->add("faiSummary");
236             }
237         }
239         /* Add environment tab if user or group is member in this object group*/
240         if(class_available("environment")){
241             if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['environment'])){
242                 $this->by_name['environment']= _("Desktop");
243                 $this->by_object['environment']= new environment($this->config, $this->dn);
244                 $this->by_object['environment']->parent= &$this;
245                 $this->add("environment");
246             }
247         }
249         /* Remove environment tab if not required any longer */
250         if(class_available("environment")){
251             if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['environment'])){
252                 $this->remove("environment");
253             }
254         }
256         /* Add application tab if user or group is member in this object group*/
257         if(class_available("appgroup")){
258             if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['appgroup'])){
259                 $this->by_name['appgroup']= _("Applications");
260                 $this->by_object['appgroup']= new appgroup($this->config, $this->dn);
261                 $this->by_object['appgroup']->acl = "#all#";
262                 $this->by_object['appgroup']->parent= &$this;
263                 $this->add('appgroup');
264             }
265         }
267         /* Remove application tab if not required any longer */
268         if(class_available("appgroup")){
269             if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['appgroup'])){
270                 $this->remove('appgroup');
271             }
272         }
274         /* Move reference tab to second position from right */
275         if(class_available("acl")){
276             if(isset($this->by_name['acl'])){
277                 $tmp = $this->by_name['acl'];
278                 unset($this->by_name['acl']);
279                 $this->by_name['acl'] = $tmp;
280             }
282             /* Move reference tab to last position*/
283             if(class_available("reference")){
284                 if(isset($this->by_name['reference'])){
285                     $tmp = $this->by_name['reference'];
286                     unset($this->by_name['reference']);
287                     $this->by_name['reference'] = $tmp;
288                 }
289             }
291             /* Reset acls */
292             if($this->dn == "new"){
293                 $this->set_acl_base($this->base);
294             }else{
295                 $this->set_acl_base($this->dn);
296             }
297             foreach($this->by_object as $name => $obj){
298                 $this->by_object[$name]->set_acl_category($this->acl_category);
299             }
300         }
301     }
303     function execute(){
304         $str = "";
305         $this->by_object['ogroup']->AddDelMembership();
306         $this->reload($this->by_object['ogroup']->gosaGroupObjects);
307         $str .= tabs::execute();
308         return ( $str);
309     }  
311     function ogrouptabs($config, $data, $dn,$category ="ogroups",$hide_refs = FALSE, $hide_acls = FALSE)
312     {
314         tabs::tabs($config, $data, $dn, $category,$hide_refs, $hide_acls);
315         $this->base= $this->by_object['ogroup']->base;
316         $this->acl_category = $category;
318         /* Add references/acls/snapshots */
319         $this->reload($this->by_object['ogroup']->gosaGroupObjects);
320         $this->addSpecialTabs();
321     }
324     function check($ignore_account= FALSE)
325     {
326         return (tabs::check(FALSE));
327     }
330     function save_object($save_current= FALSE)
331     {
332         tabs::save_object($save_current);
334         /* Update reference, transfer variables */
335         $baseobject= $this->by_object['ogroup'];
336         foreach ($this->by_object as $name => $obj){
338             /* Don't touch base object */
339             if ($name != 'ogroup'){
340                 $obj->parent    = &$this;
341                 $obj->uid       = $baseobject->uid;
342                 $obj->cn        = $baseobject->cn;
343                 $obj->sn        = $baseobject->uid;
344                 $obj->givenName = $baseobject->uid;
345                 $this->by_object[$name]= $obj;
346             }
348             /* Update parent in base object */
349             $this->by_object['ogroup']->parent= &$this;
350         }
351     }
354     function save($ignore_account= FALSE)
355     {
356         $baseobject= $this->by_object['ogroup'];
358         /* Check for new 'dn', in order to propagate the
359            'dn' to all plugins */
360         $cn      = preg_replace('/,/', '\,', $baseobject->cn); 
361         $cn      = preg_replace('/"/', '\"', $cn); 
362         $new_dn= 'cn='.$cn.','.get_ou("group", "ogroupRDN").$baseobject->base;
364         /* Move group? */
365         if (LDAP::fix($this->dn) != LDAP::fix($new_dn)){
367             /* Write entry on new 'dn' */
368             if ($this->dn != "new"){
369                 $baseobject->move($this->dn, $new_dn);
370                 $this->by_object['ogroup']= $baseobject;
371             }
373             /* Happen to use the new one */
374             $this->dn= $new_dn;
375         }
377         if ($this->dn == "new"){
378             $this->dn= 'cn='.$baseobject->cn.','.get_ou("group", "ogroupRDN").$baseobject->base;
379         }
381         foreach(array_keys($this->to_remove) as $object) {
382             $this->to_remove[$object]->remove_from_parent();
383         }
384         tabs::save();
385     }
387     function getCopyDialog()
388     {
389         $this->reload($this->by_object['ogroup']->gosaGroupObjects); 
390         return(tabs::getCopyDialog());
391     }
394 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
395 ?>