Code

Updated ogroup
[gosa.git] / gosa-core / plugins / admin / ogroups / tabs_ogroups.inc
1 <?php
3 class ogrouptabs extends tabs
4 {
5   var $base= "";
6   var $acl_category; 
7  
8   function reload($dd){
9     $objects= preg_replace('/[\[\]]/', '', $dd);
10     
11     /* If there is a phonequeue,
12      * but there is no user left with goPhoneAccount ... remove it.
13      */
14     $usePhoneTab = false;
15     foreach($this->by_object['ogroup']->memberList as $dn => $val){
17       if(isset($this->by_object['ogroup']->objcache[$dn])){
18         $obj = $this->by_object['ogroup']->objcache[$dn];
19         if(isset($obj['objectClass'])){
20           if(in_array("goFonAccount",$obj['objectClass'])){
21             $usePhoneTab = true;
22           }
23         }
24       }
25     }
26     if(((!$usePhoneTab)&&(isset($this->by_object['phonequeue'])))||((!preg_match("/U/",$objects))&&(isset($this->by_object['phonequeue'])))){
27       $this->by_object['phonequeue']->remove_from_parent();
28       unset($this->by_object['phonequeue']);
29       unset($this->by_name['phonequeue']);
30     }
31     /* Remove mail group if there is no user anymore */
32     if((!preg_match("/U/",$objects))&&(isset($this->by_object['mailogroup']))){
33       $this->by_object['mailogroup']->remove_from_parent();
34       unset($this->by_object['mailogroup']);
35       unset($this->by_name['mailogroup']);
36     }
37     
38     /* Remove terminal group, if theres no terminal left in the object list */
39     if(((!preg_match("/T/",$objects)) && (!preg_match("/W/",$objects)))&&(isset($this->by_object['termgroup']))){
40       $this->by_object['termgroup']->remove_from_parent();
41       unset($this->by_object['termgroup']);
42       unset($this->by_name['termgroup']);
43     }
44     if(!preg_match("/T/",$objects) &&(isset($this->by_object['termservice']))){
45       $this->by_object['termservice']->remove_from_parent();
46       unset($this->by_object['termservice']);
47       unset($this->by_name['termservice']);
48     }
49     
50     /* Remove ws tabs, if theres no ws left in the object list */
51     if((!preg_match("/W/",$objects))&&(isset($this->by_object['workservice']))){
52       $this->by_object['workservice']->remove_from_parent();
53       unset($this->by_object['workservice']);
54       unset($this->by_name['workservice']);
55     }
56     if((!preg_match("/S/",$objects) && !preg_match("/W/",$objects))&&(isset($this->by_object['workstartup']))){
57       $this->by_object['workstartup']->remove_from_parent();
58       unset($this->by_object['workstartup']);
59       unset($this->by_name['workstartup']);
60       $this->by_object['faiSummary']->remove_from_parent();
61       unset($this->by_object['faiSummary']);
62       unset($this->by_name['faiSummary']);
63     }
64   
65     /* Create goPhoneAccount if theres an user with goPhoneAccount
66      * but only if there is currently no queue enabled.
67      */
68     if(!isset($this->by_object['phonequeue'])){
69       foreach($this->by_object['ogroup']->memberList as $dn => $val){
71         if(isset($this->by_object['ogroup']->objcache[$dn])){
72           $obj = $this->by_object['ogroup']->objcache[$dn];
74           if(isset($obj['objectClass'])){
75             if(in_array("goFonAccount",$obj['objectClass'])){
76               $this->by_name['phonequeue']= _("Phone queue");
77               $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
78               $this->by_object['phonequeue']->parent= &$this;
79               break;
80             }
81           }
82         }
83       }
84     }
86     /* Add mail group tab , if there is curerntly no mail tab defined */ 
87     if((preg_match("/U/",$objects))&&(!isset($this->by_object['mailogroup']))){
88       if(isset($this->config->current['MAILMETHOD'])){
89         if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
90           $this->by_name['mailogroup']= _("Mail");
91           $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
92           $this->by_object['mailogroup']->parent= &$this;
93         }
94       }
95     }
97     /* Add Terminal tab */
98     if(((preg_match("/T/",$objects)) || (preg_match("/W/",$objects)))&&(!isset($this->by_object['termgroup']))){
99       if(!isset($this->by_object['termgroup'])){
100         $this->by_name['termgroup']= _("System");
101         $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
102         $this->by_object['termgroup']->inheritTimeServer = false;
103         $this->by_object['termgroup']->parent= &$this;
104       }
105     }
106     if(preg_match("/T/",$objects) &&(!isset($this->by_object['termservice']))){
107       if(!isset($this->by_object['termservice'])){
108         $this->by_name['termservice']= _("Devices");
109         $this->by_object['termservice']= new termservice($this->config, $this->dn,$this->by_object['ogroup']);
110       }
111     }
113     /* Add Workstation tabs */
114     if((preg_match("/W/",$objects))&&(!isset($this->by_object['workservice']))){
115         $this->by_name['workservice']= _("Devices");
116         $this->by_object['workservice']= new workservice($this->config, $this->dn);
117         $this->by_object['workservice']->inheritTimeServer = false;
118         $this->by_object['workservice']->parent= &$this;
119         $this->by_object['workservice']->acl = "#all#";
120     }
121     if((preg_match("/S/",$objects) || preg_match("/W/",$objects))&&(!isset($this->by_object['workstartup']))){
122         $this->by_name['workstartup']= _("Startup");
123         $this->by_object['workstartup']= new workstartup($this->config, $this->dn);
124         $this->by_object['workstartup']->parent= &$this;
125         $this->by_object['workstartup']->acl = "#all#";
126         $this->by_name['faiSummary']= _("Summary");
127         $this->by_object['faiSummary']= new faiSummaryTab($this->config, $this->dn);
128         $this->by_object['faiSummary']->parent= &$this;
129     }
131     /* Add application tab if user or group is member in this object group*/
132     if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['appgroup'])){
133       $this->by_name['appgroup']= _("Application");
134       $this->by_object['appgroup']= new appgroup($this->config, $this->dn);
135       $this->by_object['appgroup']->acl = "#all#";
136       $this->by_object['appgroup']->parent= &$this;
137     }
139     /* Remove application tab if not required any longer */
140     if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['appgroup'])){
141       $this->by_object['appgroup']->remove_from_parent();
142       unset($this->by_name['appgroup']);
143       unset($this->by_object['appgroup']);
144     }
146     /* Add environment tab if user or group is member in this object group*/
147     if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['environment'])){
148       $this->by_name['environment']= _("Environment");
149       $this->by_object['environment']= new environment($this->config, $this->dn);
150       $this->by_object['environment']->acl = "#all#";
151       $this->by_object['environment']->parent= &$this;
152     }
154     /* Remove environment tab if not required any longer */
155     if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['environment'])){
156       $this->by_object['environment']->remove_from_parent();
157       unset($this->by_name['environment']);
158       unset($this->by_object['environment']);
159     }
160     /* Move reference tab to second position from right */
161     if(isset($this->by_name['acl'])){
162       $tmp = $this->by_name['acl'];
163       unset($this->by_name['acl']);
164       $this->by_name['acl'] = $tmp;
165     }
166   
167     /* Move reference tab to last position*/
168     if(isset($this->by_name['reference'])){
169       $tmp = $this->by_name['reference'];
170       unset($this->by_name['reference']);
171       $this->by_name['reference'] = $tmp;
172     }
174     /* Reset acls */
175     $this->set_acl_base($this->base);
176     foreach($this->by_object as $name => $obj){
177       $this->by_object[$name]->set_acl_category($this->acl_category);
178     }
179   }
181   function execute(){
182     $str = "";
183     $this->by_object['ogroup']->AddDelMembership();
184     $this->reload($this->by_object['ogroup']->gosaGroupObjects);
185     $str .= tabs::execute();
186     return ( $str);
187   }  
189   function ogrouptabs($config, $data, $dn,$category ="ogroups")
190   {
192     tabs::tabs($config, $data, $dn, $category);
193     $this->base= $this->by_object['ogroup']->base;
194     $this->acl_category = $category;
196     /* Insert extra tabs for several object types - if present */
198     $objects= preg_replace('/[\[\]]/', '', $this->by_object['ogroup']->gosaGroupObjects);
199    
200     for ($n= 0; $n<strlen($objects); $n++){
201       switch ($objects[$n]){
202         case "T":
203           /* Add a terminal tab */
204           $this->by_name['termgroup']= _("Terminals");
205           $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
206           $this->by_object['termgroup']->parent= &$this;
208           $this->by_name['termservice']= _("Devices");
209           $this->by_object['termservice']= new termservice($this->config, $this->dn,$this->by_object['ogroup']);
210           break;
212           case "U":
213             /* Append a PhoneQueue, if objectClass = goFonAccount */
214             $use = false;
215           foreach($this->by_object['ogroup']->memberList as $dn => $val){
217             $obj = $this->by_object['ogroup']->objcache[$dn];
218             
219             if(isset($obj['objectClass'])){
220               if(in_array("goFonAccount",$obj['objectClass'])){
221                 $use = true; 
222               }
223             }
224           }
226           /* We found goFonAccount in users objectClasses*/
227           if($use){
228             $this->by_name['phonequeue']= _("Phone queue");
229             $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
230             $this->by_object['phonequeue']->parent= &$this;
231           } 
232  
233           /* Add a user tab used for mail distribution lists */
234           if(isset($this->config->current['MAILMETHOD'])){
235             if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
236               $this->by_name['mailogroup']= _("Mail");
237               $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
238               $this->by_object['mailogroup']->parent= &$this;
239             }
240           }
242           break;
243       }
244     }
246     /* Add references/acls/snapshots */
247     $this->reload($this->by_object['ogroup']->gosaGroupObjects);
248     $this->addSpecialTabs();
249   }
252   function check($ignore_account= FALSE)
253   {
254     return (tabs::check(FALSE));
255   }
258   function save_object($save_current= FALSE)
259   {
260     tabs::save_object($save_current);
262     /* Update reference, transfer variables */
263     $baseobject= $this->by_object['ogroup'];
264     foreach ($this->by_object as $name => $obj){
266       /* Don't touch base object */
267       if ($name != 'ogroup'){
268         $obj->parent    = &$this;
269         $obj->uid       = $baseobject->uid;
270         $obj->cn        = $baseobject->cn;
271         $obj->sn        = $baseobject->uid;
272         $obj->givenName = $baseobject->uid;
273         $this->by_object[$name]= $obj;
274       }
276       /* Update parent in base object */
277       $this->by_object['ogroup']->parent= &$this;
278     }
279   }
282   function save($ignore_account= FALSE)
283   {
284     $baseobject= $this->by_object['ogroup'];
286     /* Check for new 'dn', in order to propagate the
287        'dn' to all plugins */
288     $new_dn= 'cn='.$baseobject->cn.','.get_ou('ogroupou').$baseobject->base;
290     /* Move group? */
291     if ($this->dn != $new_dn){
293       /* Write entry on new 'dn' */
294       if ($this->dn != "new"){
295         $baseobject->move($this->dn, $new_dn);
296         $this->by_object['ogroup']= $baseobject;
297       }
299       /* Happen to use the new one */
300       $this->dn= $new_dn;
301     }
303     if ($this->dn == "new"){
304       $this->dn= 'cn='.$baseobject->cn.','.get_ou('ogroupou').$baseobject->base;
305     }
307     tabs::save();
308   }
310   function getCopyDialog()
311   {
312     $this->reload($this->by_object['ogroup']->gosaGroupObjects); 
313     return(tabs::getCopyDialog());
314   }
317 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
318 ?>