Code

Updated get_ou()
[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         }
86         /* Remove terminal group, if theres no terminal left in the object list 
87          */
88         if(class_available("termgroup")){
89             if(($mixed_type && isset($this->by_object['termgroup'])) ||
90                     !preg_match("/T/",$objects) && !preg_match("/W/",$objects) && isset($this->by_object['termgroup'])){
91                 $this->remove('termgroup');    
92             }
93         }
94         if(class_available("termservice")){
95             if(($mixed_type && isset($this->by_object['termservice'])) ||
96                     !preg_match("/T/",$objects) &&(isset($this->by_object['termservice']))){
97                 $this->remove('termservice');    
98             }
99         }
100         if(class_available("termstartup")){
101             if(($mixed_type && isset($this->by_object['termstartup'])) ||
102                     !preg_match("/T/",$objects)&&(isset($this->by_object['termstartup']))){
103                 $this->remove('termstartup');
104             }
105         }
107         /* Remove ws tabs, if theres no ws left in the object list */
108         if(class_available("workservice")){
109             if(($mixed_type && isset($this->by_object['workservice'])) ||
110                     (!preg_match("/W/",$objects))&&(isset($this->by_object['workservice']))){
111                 $this->remove('workservice');
112             }
113         }
114         if(class_available("workstartup")){
115             if(($mixed_type && isset($this->by_object['workstartup'])) ||
116                     (!preg_match("/S/",$objects) && !preg_match("/W/",$objects))&&(isset($this->by_object['workstartup']))){
117                 $this->remove('workstartup');
118                 if (isset($this->by_object['faiSummary'])){
119                     $this->remove('faiSummary');
120                 }
121             }
122         }
124         /* Create goPhoneAccount if theres an user with goPhoneAccount
125          * but only if there is currently no queue enabled.
126          */
127         if(class_available("phonequeue")){
128             if(!isset($this->by_object['phonequeue'])){
129                 foreach($this->by_object['ogroup']->memberList as $dn => $val){
130                     if(isset($this->by_object['ogroup']->objcache[$dn])){
131                         $obj = $this->by_object['ogroup']->objcache[$dn];
132                         if(isset($obj['objectClass'])){
133                             if(in_array("goFonAccount",$obj['objectClass'])){
134                                 $this->by_name['phonequeue']= _("Phone queue");
135                                 $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
136                                 $this->by_object['phonequeue']->parent= &$this;
137                                 $this->add('phonequeue');
138                                 break;
139                             }
140                         }
141                     }
142                 }
143             }
144         }
146         /* Add mail group tab , if there is curerntly no mail tab defined */ 
147         if(class_available("mailogroup")){
148             if((preg_match("/U/",$objects))&&(!isset($this->by_object['mailogroup']))){
149                 if ($this->config->get_cfg_value("core","mailmethod") == "kolab"){
150                     $this->by_name['mailogroup']= _("Mail");
151                     $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
152                     $this->by_object['mailogroup']->parent= &$this;
153                     $this->add('mailogroup');
154                 }
155             }
156         }
158         /* Add Terminal tab */
159         if(class_available("termgroup")){
160             if(!$mixed_type && 
161                     ((preg_match("/T/",$objects)) || (preg_match("/W/",$objects)))&&(!isset($this->by_object['termgroup']))){
162                 if(!isset($this->by_object['termgroup'])){
163                     $this->by_name['termgroup']= _("System settings");
164                     $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
165                     $this->by_object['termgroup']->inheritTimeServer = false;
166                     $this->by_object['termgroup']->parent= &$this;
167                     $this->add('termgroup');
168                 }
169             }
170         }
171         if(class_available("termstartup")){
172             if(!$mixed_type &&
173                     preg_match("/T/",$objects) &&(!isset($this->by_object['termstartup']))){
174                 if(!isset($this->by_object['termstartup'])){
175                     $this->by_name['termstartup']= _("Recipe");
176                     $this->by_object['termstartup']= new termstartup($this->config, $this->dn,$this->by_object['ogroup']);
177                     $this->by_object['termstartup']->parent= &$this;
178                     $this->by_object['termstartup']->acl = "#all#";
179                     $this->add('termstartup');
180                 }
181             }
182         }
183         if(!$mixed_type &&
184                 class_available("termservice")){
185             if(preg_match("/T/",$objects) &&(!isset($this->by_object['termservice']))){
186                 if(!isset($this->by_object['termservice'])){
187                     $this->by_name['termservice']= _("Devices");
188                     $this->by_object['termservice']= new termservice($this->config, $this->dn,$this->by_object['ogroup']);
189                     $this->by_object['termservice']->parent= &$this;
190                     $this->by_object['termservice']->acl = "#all#";
191                     $this->add('termservice');
192                 }
193             }
194         }
196         /* Add Workstation tabs */
197         if(class_available("workstartup")){
198             if(!$mixed_type &&
199                     (preg_match("/S/",$objects) || preg_match("/W/",$objects))&&(!isset($this->by_object['workstartup']))){
200                 $this->by_name['workstartup']= _("Recipe");
201                 $this->by_object['workstartup']= new workstartup($this->config, $this->dn);
202                 $this->by_object['workstartup']->parent= &$this;
203                 $this->add("workstartup");
204             }
205         }
206         if(!$mixed_type &&
207                 class_available("workservice")){
208             if((preg_match("/W/",$objects))&&(!isset($this->by_object['workservice']))){
209                 $this->by_name['workservice']= _("Devices");
210                 $this->by_object['workservice']= new workservice($this->config, $this->dn);
211                 $this->by_object['workservice']->inheritTimeServer = false;
212                 $this->by_object['workservice']->parent= &$this;
213                 $this->add("workservice");
214             }
215         }
216         if(class_available("faiSummary")){
217             if(!$mixed_type &&
218                     (preg_match("/S/",$objects) || preg_match("/W/",$objects))&&(!isset($this->by_object['faiSummary']))){
219                 $this->by_name['faiSummary']= _("Deployment summary");
220                 $this->by_object['faiSummary']= new faiSummaryTab($this->config, $this->dn);
221                 $this->by_object['faiSummary']->parent= &$this;
222                 $this->add("faiSummary");
223             }
224         }
226         /* Add environment tab if user or group is member in this object group*/
227         if(class_available("environment")){
228             if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['environment'])){
229                 $this->by_name['environment']= _("Desktop");
230                 $this->by_object['environment']= new environment($this->config, $this->dn);
231                 $this->by_object['environment']->parent= &$this;
232                 $this->add("environment");
233             }
234         }
236         /* Remove environment tab if not required any longer */
237         if(class_available("environment")){
238             if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['environment'])){
239                 $this->remove("environment");
240             }
241         }
243         /* Add application tab if user or group is member in this object group*/
244         if(class_available("appgroup")){
245             if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['appgroup'])){
246                 $this->by_name['appgroup']= _("Applications");
247                 $this->by_object['appgroup']= new appgroup($this->config, $this->dn);
248                 $this->by_object['appgroup']->acl = "#all#";
249                 $this->by_object['appgroup']->parent= &$this;
250                 $this->add('appgroup');
251             }
252         }
254         /* Remove application tab if not required any longer */
255         if(class_available("appgroup")){
256             if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['appgroup'])){
257                 $this->remove('appgroup');
258             }
259         }
261         /* Move reference tab to second position from right */
262         if(class_available("acl")){
263             if(isset($this->by_name['acl'])){
264                 $tmp = $this->by_name['acl'];
265                 unset($this->by_name['acl']);
266                 $this->by_name['acl'] = $tmp;
267             }
269             /* Move reference tab to last position*/
270             if(class_available("reference")){
271                 if(isset($this->by_name['reference'])){
272                     $tmp = $this->by_name['reference'];
273                     unset($this->by_name['reference']);
274                     $this->by_name['reference'] = $tmp;
275                 }
276             }
278             /* Reset acls */
279             if($this->dn == "new"){
280                 $this->set_acl_base($this->base);
281             }else{
282                 $this->set_acl_base($this->dn);
283             }
284             foreach($this->by_object as $name => $obj){
285                 $this->by_object[$name]->set_acl_category($this->acl_category);
286             }
287         }
288     }
290     function execute(){
291         $str = "";
292         $this->by_object['ogroup']->AddDelMembership();
293         $this->reload($this->by_object['ogroup']->gosaGroupObjects);
294         $str .= tabs::execute();
295         return ( $str);
296     }  
298     function ogrouptabs($config, $data, $dn,$category ="ogroups",$hide_refs = FALSE, $hide_acls = FALSE)
299     {
301         tabs::tabs($config, $data, $dn, $category,$hide_refs, $hide_acls);
302         $this->base= $this->by_object['ogroup']->base;
303         $this->acl_category = $category;
305         /* Add references/acls/snapshots */
306         $this->reload($this->by_object['ogroup']->gosaGroupObjects);
307         $this->addSpecialTabs();
308     }
311     function check($ignore_account= FALSE)
312     {
313         return (tabs::check(FALSE));
314     }
317     function save_object($save_current= FALSE)
318     {
319         tabs::save_object($save_current);
321         /* Update reference, transfer variables */
322         $baseobject= $this->by_object['ogroup'];
323         foreach ($this->by_object as $name => $obj){
325             /* Don't touch base object */
326             if ($name != 'ogroup'){
327                 $obj->parent    = &$this;
328                 $obj->uid       = $baseobject->uid;
329                 $obj->cn        = $baseobject->cn;
330                 $obj->sn        = $baseobject->uid;
331                 $obj->givenName = $baseobject->uid;
332                 $this->by_object[$name]= $obj;
333             }
335             /* Update parent in base object */
336             $this->by_object['ogroup']->parent= &$this;
337         }
338     }
341     function save($ignore_account= FALSE)
342     {
343         $baseobject= $this->by_object['ogroup'];
345         /* Check for new 'dn', in order to propagate the
346            'dn' to all plugins */
347         $new_dn= 'cn='.$baseobject->cn.','.get_ou("group", "ogroupRDN").$baseobject->base;
349         /* Move group? */
350         if (LDAP::fix($this->dn) != LDAP::fix($new_dn)){
352             /* Write entry on new 'dn' */
353             if ($this->dn != "new"){
354                 $baseobject->move($this->dn, $new_dn);
355                 $this->by_object['ogroup']= $baseobject;
356             }
358             /* Happen to use the new one */
359             $this->dn= $new_dn;
360         }
362         if ($this->dn == "new"){
363             $this->dn= 'cn='.$baseobject->cn.','.get_ou("group", "ogroupRDN").$baseobject->base;
364         }
366         /* Only delete attributes if there are members left */
367         if (count($this->by_object['ogroup']->memberList) != 0) {
368             foreach(array_keys($this->to_remove) as $object) {
369                 $this->to_remove[$object]->remove_from_parent();
370             }
371         }
372         tabs::save();
373     }
375     function getCopyDialog()
376     {
377         $this->reload($this->by_object['ogroup']->gosaGroupObjects); 
378         return(tabs::getCopyDialog());
379     }
382 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
383 ?>