Code

Moved fai summary around
[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  
28   function reload($dd){
29     $objects= preg_replace('/[\[\]]/', '', $dd);
30     
31     /* If there is a phonequeue,
32      * but there is no user left with goPhoneAccount ... remove it.
33      */
34     $usePhoneTab = false;
35     foreach($this->by_object['ogroup']->memberList as $dn => $val){
37       if(isset($this->by_object['ogroup']->objcache[$dn])){
38         $obj = $this->by_object['ogroup']->objcache[$dn];
39         if(isset($obj['objectClass'])){
40           if(in_array("goFonAccount",$obj['objectClass'])){
41             $usePhoneTab = true;
42           }
43         }
44       }
45     }
46     if(((!$usePhoneTab)&&(isset($this->by_object['phonequeue'])))||((!preg_match("/U/",$objects))&&(isset($this->by_object['phonequeue'])))){
47       $this->by_object['phonequeue']->remove_from_parent();
48       unset($this->by_object['phonequeue']);
49       unset($this->by_name['phonequeue']);
50     }
51     /* Remove mail group if there is no user anymore */
52     if((!preg_match("/U/",$objects))&&(isset($this->by_object['mailogroup']))){
53       $this->by_object['mailogroup']->remove_from_parent();
54       unset($this->by_object['mailogroup']);
55       unset($this->by_name['mailogroup']);
56     }
57     
58     /* Remove terminal group, if theres no terminal left in the object list */
59     if(((!preg_match("/T/",$objects)) && (!preg_match("/W/",$objects)))&&(isset($this->by_object['termgroup']))){
60       $this->by_object['termgroup']->remove_from_parent();
61       unset($this->by_object['termgroup']);
62       unset($this->by_name['termgroup']);
63     }
64     if(!preg_match("/T/",$objects) &&(isset($this->by_object['termservice']))){
65       $this->by_object['termservice']->remove_from_parent();
66       unset($this->by_object['termservice']);
67       unset($this->by_name['termservice']);
68     }
69     
70     /* Remove ws tabs, if theres no ws left in the object list */
71     if((!preg_match("/W/",$objects))&&(isset($this->by_object['workservice']))){
72       $this->by_object['workservice']->remove_from_parent();
73       unset($this->by_object['workservice']);
74       unset($this->by_name['workservice']);
75     }
76     if((!preg_match("/S/",$objects) && !preg_match("/W/",$objects))&&(isset($this->by_object['workstartup']))){
77       $this->by_object['workstartup']->remove_from_parent();
78       unset($this->by_object['workstartup']);
79       unset($this->by_name['workstartup']);
80       $this->by_object['faiSummary']->remove_from_parent();
81       unset($this->by_object['faiSummary']);
82       unset($this->by_name['faiSummary']);
83     }
84   
85     /* Create goPhoneAccount if theres an user with goPhoneAccount
86      * but only if there is currently no queue enabled.
87      */
88     if(!isset($this->by_object['phonequeue'])){
89       foreach($this->by_object['ogroup']->memberList as $dn => $val){
91         if(isset($this->by_object['ogroup']->objcache[$dn])){
92           $obj = $this->by_object['ogroup']->objcache[$dn];
94           if(isset($obj['objectClass'])){
95             if(in_array("goFonAccount",$obj['objectClass'])){
96               $this->by_name['phonequeue']= _("Phone queue");
97               $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
98               $this->by_object['phonequeue']->parent= &$this;
99               break;
100             }
101           }
102         }
103       }
104     }
106     /* Add mail group tab , if there is curerntly no mail tab defined */ 
107     if((preg_match("/U/",$objects))&&(!isset($this->by_object['mailogroup']))){
108       if(isset($this->config->current['MAILMETHOD'])){
109         if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
110           $this->by_name['mailogroup']= _("Mail");
111           $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
112           $this->by_object['mailogroup']->parent= &$this;
113         }
114       }
115     }
117     /* Add Terminal tab */
118     if(((preg_match("/T/",$objects)) || (preg_match("/W/",$objects)))&&(!isset($this->by_object['termgroup']))){
119       if(!isset($this->by_object['termgroup'])){
120         $this->by_name['termgroup']= _("Systems");
121         $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
122         $this->by_object['termgroup']->inheritTimeServer = false;
123         $this->by_object['termgroup']->parent= &$this;
124       }
125     }
126     if(preg_match("/T/",$objects) &&(!isset($this->by_object['termservice']))){
127       if(!isset($this->by_object['termservice'])){
128         $this->by_name['termservice']= _("Devices");
129         $this->by_object['termservice']= new termservice($this->config, $this->dn,$this->by_object['ogroup']);
130       }
131     }
133     /* Add Workstation tabs */
134     if((preg_match("/S/",$objects) || preg_match("/W/",$objects))&&(!isset($this->by_object['workstartup']))){
135         $this->by_name['workstartup']= _("Startup");
136         $this->by_object['workstartup']= new workstartup($this->config, $this->dn);
137         $this->by_object['workstartup']->parent= &$this;
138         $this->by_object['workstartup']->acl = "#all#";
139     }
140     if((preg_match("/W/",$objects))&&(!isset($this->by_object['workservice']))){
141         $this->by_name['workservice']= _("Devices");
142         $this->by_object['workservice']= new workservice($this->config, $this->dn);
143         $this->by_object['workservice']->inheritTimeServer = false;
144         $this->by_object['workservice']->parent= &$this;
145         $this->by_object['workservice']->acl = "#all#";
146     }
147     if((preg_match("/S/",$objects) || preg_match("/W/",$objects))&&(!isset($this->by_object['workstartup']))){
148         $this->by_name['faiSummary']= _("FAI summary");
149         $this->by_object['faiSummary']= new faiSummaryTab($this->config, $this->dn);
150         $this->by_object['faiSummary']->parent= &$this;
151     }
153     /* Add application tab if user or group is member in this object group*/
154     if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['appgroup'])){
155       $this->by_name['appgroup']= _("Application");
156       $this->by_object['appgroup']= new appgroup($this->config, $this->dn);
157       $this->by_object['appgroup']->acl = "#all#";
158       $this->by_object['appgroup']->parent= &$this;
159     }
161     /* Remove application tab if not required any longer */
162     if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['appgroup'])){
163       $this->by_object['appgroup']->remove_from_parent();
164       unset($this->by_name['appgroup']);
165       unset($this->by_object['appgroup']);
166     }
168     /* Add environment tab if user or group is member in this object group*/
169     if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['environment'])){
170       $this->by_name['environment']= _("Environment");
171       $this->by_object['environment']= new environment($this->config, $this->dn);
172       $this->by_object['environment']->acl = "#all#";
173       $this->by_object['environment']->parent= &$this;
174     }
176     /* Remove environment tab if not required any longer */
177     if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['environment'])){
178       $this->by_object['environment']->remove_from_parent();
179       unset($this->by_name['environment']);
180       unset($this->by_object['environment']);
181     }
182     /* Move reference tab to second position from right */
183     if(isset($this->by_name['acl'])){
184       $tmp = $this->by_name['acl'];
185       unset($this->by_name['acl']);
186       $this->by_name['acl'] = $tmp;
187     }
188   
189     /* Move reference tab to last position*/
190     if(isset($this->by_name['reference'])){
191       $tmp = $this->by_name['reference'];
192       unset($this->by_name['reference']);
193       $this->by_name['reference'] = $tmp;
194     }
196     /* Reset acls */
197     $this->set_acl_base($this->base);
198     foreach($this->by_object as $name => $obj){
199       $this->by_object[$name]->set_acl_category($this->acl_category);
200     }
201   }
203   function execute(){
204     $str = "";
205     $this->by_object['ogroup']->AddDelMembership();
206     $this->reload($this->by_object['ogroup']->gosaGroupObjects);
207     $str .= tabs::execute();
208     return ( $str);
209   }  
211   function ogrouptabs($config, $data, $dn,$category ="ogroups")
212   {
214     tabs::tabs($config, $data, $dn, $category);
215     $this->base= $this->by_object['ogroup']->base;
216     $this->acl_category = $category;
218     /* Insert extra tabs for several object types - if present */
220     $objects= preg_replace('/[\[\]]/', '', $this->by_object['ogroup']->gosaGroupObjects);
221    
222     for ($n= 0; $n<strlen($objects); $n++){
223       switch ($objects[$n]){
224         case "T":
225           /* Add a terminal tab */
226           $this->by_name['termgroup']= _("Terminals");
227           $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
228           $this->by_object['termgroup']->parent= &$this;
230           $this->by_name['termservice']= _("Devices");
231           $this->by_object['termservice']= new termservice($this->config, $this->dn,$this->by_object['ogroup']);
232           break;
234           case "U":
235             /* Append a PhoneQueue, if objectClass = goFonAccount */
236             $use = false;
237           foreach($this->by_object['ogroup']->memberList as $dn => $val){
239             $obj = $this->by_object['ogroup']->objcache[$dn];
240             
241             if(isset($obj['objectClass'])){
242               if(in_array("goFonAccount",$obj['objectClass'])){
243                 $use = true; 
244               }
245             }
246           }
248           /* We found goFonAccount in users objectClasses*/
249           if($use){
250             $this->by_name['phonequeue']= _("Phone queue");
251             $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
252             $this->by_object['phonequeue']->parent= &$this;
253           } 
254  
255           /* Add a user tab used for mail distribution lists */
256           if(isset($this->config->current['MAILMETHOD'])){
257             if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
258               $this->by_name['mailogroup']= _("Mail");
259               $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
260               $this->by_object['mailogroup']->parent= &$this;
261             }
262           }
264           break;
265       }
266     }
268     /* Add references/acls/snapshots */
269     $this->reload($this->by_object['ogroup']->gosaGroupObjects);
270     $this->addSpecialTabs();
271   }
274   function check($ignore_account= FALSE)
275   {
276     return (tabs::check(FALSE));
277   }
280   function save_object($save_current= FALSE)
281   {
282     tabs::save_object($save_current);
284     /* Update reference, transfer variables */
285     $baseobject= $this->by_object['ogroup'];
286     foreach ($this->by_object as $name => $obj){
288       /* Don't touch base object */
289       if ($name != 'ogroup'){
290         $obj->parent    = &$this;
291         $obj->uid       = $baseobject->uid;
292         $obj->cn        = $baseobject->cn;
293         $obj->sn        = $baseobject->uid;
294         $obj->givenName = $baseobject->uid;
295         $this->by_object[$name]= $obj;
296       }
298       /* Update parent in base object */
299       $this->by_object['ogroup']->parent= &$this;
300     }
301   }
304   function save($ignore_account= FALSE)
305   {
306     $baseobject= $this->by_object['ogroup'];
308     /* Check for new 'dn', in order to propagate the
309        'dn' to all plugins */
310     $new_dn= 'cn='.$baseobject->cn.','.get_ou('ogroupou').$baseobject->base;
312     /* Move group? */
313     if ($this->dn != $new_dn){
315       /* Write entry on new 'dn' */
316       if ($this->dn != "new"){
317         $baseobject->move($this->dn, $new_dn);
318         $this->by_object['ogroup']= $baseobject;
319       }
321       /* Happen to use the new one */
322       $this->dn= $new_dn;
323     }
325     if ($this->dn == "new"){
326       $this->dn= 'cn='.$baseobject->cn.','.get_ou('ogroupou').$baseobject->base;
327     }
329     tabs::save();
330   }
332   function getCopyDialog()
333   {
334     $this->reload($this->by_object['ogroup']->gosaGroupObjects); 
335     return(tabs::getCopyDialog());
336   }
339 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
340 ?>