Code

Prepared ogroup fot terminal service.
[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)) && (!preg_match("/W/",$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       if(!isset($this->by_object['termservice'])){
106         $this->by_name['termservice']= _("Service");
107         $this->by_object['termservice']= new termservice($this->config, $this->dn);
108         $this->by_object['termservice']->parent= &$this;
109       }
110     }
111     
112     /* Add Workstation tabs */
113     if((preg_match("/W/",$objects))&&(!isset($this->by_object['workservice']))){
114         $this->by_name['workservice']= _("Devices");
115         $this->by_object['workservice']= new workservice($this->config, $this->dn);
116         $this->by_object['workservice']->inheritTimeServer = false;
117         $this->by_object['workservice']->parent= &$this;
118         $this->by_object['workservice']->acl = "#all#";
119     }
120     if((preg_match("/S/",$objects) || preg_match("/W/",$objects))&&(!isset($this->by_object['workstartup']))){
121         $this->by_name['workstartup']= _("Startup");
122         $this->by_object['workstartup']= new workstartup($this->config, $this->dn);
123         $this->by_object['workstartup']->parent= &$this;
124         $this->by_object['workstartup']->acl = "#all#";
125         $this->by_name['faiSummary']= _("Summary");
126         $this->by_object['faiSummary']= new faiSummaryTab($this->config, $this->dn);
127         $this->by_object['faiSummary']->parent= &$this;
128     }
130     /* Add application tab if user or group is member in this object group*/
131     if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['appgroup'])){
132       $this->by_name['appgroup']= _("Application");
133       $this->by_object['appgroup']= new appgroup($this->config, $this->dn);
134       $this->by_object['appgroup']->acl = "#all#";
135       $this->by_object['appgroup']->parent= &$this;
136     }
138     /* Remove application tab if not required any longer */
139     if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['appgroup'])){
140       $this->by_object['appgroup']->remove_from_parent();
141       unset($this->by_name['appgroup']);
142       unset($this->by_object['appgroup']);
143     }
145     /* Add environment tab if user or group is member in this object group*/
146     if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['environment'])){
147       $this->by_name['environment']= _("Environment");
148       $this->by_object['environment']= new environment($this->config, $this->dn);
149       $this->by_object['environment']->acl = "#all#";
150       $this->by_object['environment']->parent= &$this;
151     }
153     /* Remove environment tab if not required any longer */
154     if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['environment'])){
155       $this->by_object['environment']->remove_from_parent();
156       unset($this->by_name['environment']);
157       unset($this->by_object['environment']);
158     }
159     /* Move reference tab to second position from right */
160     if(isset($this->by_name['acl'])){
161       $tmp = $this->by_name['acl'];
162       unset($this->by_name['acl']);
163       $this->by_name['acl'] = $tmp;
164     }
165   
166     /* Move reference tab to last position*/
167     if(isset($this->by_name['reference'])){
168       $tmp = $this->by_name['reference'];
169       unset($this->by_name['reference']);
170       $this->by_name['reference'] = $tmp;
171     }
173     /* Reset acls */
174     $this->set_acl_base($this->base);
175     foreach($this->by_object as $name => $obj){
176       $this->by_object[$name]->set_acl_category($this->acl_category);
177     }
178   }
180   function execute(){
181     $str = "";
182     $this->by_object['ogroup']->AddDelMembership();
183     $this->reload($this->by_object['ogroup']->gosaGroupObjects);
184     $str .= tabs::execute();
185     return ( $str);
186   }  
188   function ogrouptabs($config, $data, $dn,$category ="ogroups")
189   {
191     tabs::tabs($config, $data, $dn, $category);
192     $this->base= $this->by_object['ogroup']->base;
193     $this->acl_category = $category;
195     /* Insert extra tabs for several object types - if present */
197     $objects= preg_replace('/[\[\]]/', '', $this->by_object['ogroup']->gosaGroupObjects);
198    
199     for ($n= 0; $n<strlen($objects); $n++){
200       switch ($objects[$n]){
201         case "T":
202           /* Add a terminal tab */
203           $this->by_name['termgroup']= _("Terminals");
204           $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
205           $this->by_object['termgroup']->parent= &$this;
207           $this->by_name['termservice']= _("Service");
208           $this->by_object['termservice']= new termservice($this->config, $this->dn);
209           $this->by_object['termservice']->parent= &$this;
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 ?>