Code

Updated trunk, introduced gosa-core
[gosa.git] / 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     
45     /* Remove ws tabs, if theres no ws left in the object list */
46     if((!preg_match("/W/",$objects))&&(isset($this->by_object['workservice']))){
47       $this->by_object['workservice']->remove_from_parent();
48       unset($this->by_object['workservice']);
49       unset($this->by_name['workservice']);
50     }
51     if((!preg_match("/S/",$objects) && !preg_match("/W/",$objects))&&(isset($this->by_object['workstartup']))){
52       $this->by_object['workstartup']->remove_from_parent();
53       unset($this->by_object['workstartup']);
54       unset($this->by_name['workstartup']);
55       $this->by_object['faiSummary']->remove_from_parent();
56       unset($this->by_object['faiSummary']);
57       unset($this->by_name['faiSummary']);
58     }
59   
60     /* Create goPhoneAccount if theres an user with goPhoneAccount
61      * but only if there is currently no queue enabled.
62      */
63     if(!isset($this->by_object['phonequeue'])){
64       foreach($this->by_object['ogroup']->memberList as $dn => $val){
66         if(isset($this->by_object['ogroup']->objcache[$dn])){
67           $obj = $this->by_object['ogroup']->objcache[$dn];
69           if(isset($obj['objectClass'])){
70             if(in_array("goFonAccount",$obj['objectClass'])){
71               $this->by_name['phonequeue']= _("Phone queue");
72               $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
73               $this->by_object['phonequeue']->parent= &$this;
74               break;
75             }
76           }
77         }
78       }
79     }
81     /* Add mail group tab , if there is curerntly no mail tab defined */ 
82     if((preg_match("/U/",$objects))&&(!isset($this->by_object['mailogroup']))){
83       if(isset($this->config->current['MAILMETHOD'])){
84         if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
85           $this->by_name['mailogroup']= _("Mail");
86           $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
87           $this->by_object['mailogroup']->parent= &$this;
88         }
89       }
90     }
92     /* Add Terminal tab */
93     if(((preg_match("/T/",$objects)) || (preg_match("/W/",$objects)))&&(!isset($this->by_object['termgroup']))){
94       if(!isset($this->by_object['termgroup'])){
95         $this->by_name['termgroup']= _("System");
96         $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
97         $this->by_object['termgroup']->inheritTimeServer = false;
98         $this->by_object['termgroup']->parent= &$this;
99       }
100     }
101     
102     /* Add Workstation tabs */
103     if((preg_match("/W/",$objects))&&(!isset($this->by_object['workservice']))){
104         $this->by_name['workservice']= _("Devices");
105         $this->by_object['workservice']= new workservice($this->config, $this->dn);
106         $this->by_object['workservice']->inheritTimeServer = false;
107         $this->by_object['workservice']->parent= &$this;
108         $this->by_object['workservice']->acl = "#all#";
109     }
110     if((preg_match("/S/",$objects) || preg_match("/W/",$objects))&&(!isset($this->by_object['workstartup']))){
111         $this->by_name['workstartup']= _("Startup");
112         $this->by_object['workstartup']= new workstartup($this->config, $this->dn);
113         $this->by_object['workstartup']->parent= &$this;
114         $this->by_object['workstartup']->acl = "#all#";
115         $this->by_name['faiSummary']= _("Summary");
116         $this->by_object['faiSummary']= new faiSummaryTab($this->config, $this->dn);
117         $this->by_object['faiSummary']->parent= &$this;
118     }
120     /* Add application tab if user or group is member in this object group*/
121     if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['appgroup'])){
122       $this->by_name['appgroup']= _("Application");
123       $this->by_object['appgroup']= new appgroup($this->config, $this->dn);
124       $this->by_object['appgroup']->acl = "#all#";
125       $this->by_object['appgroup']->parent= &$this;
126     }
128     /* Remove application tab if not required any longer */
129     if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['appgroup'])){
130       $this->by_object['appgroup']->remove_from_parent();
131       unset($this->by_name['appgroup']);
132       unset($this->by_object['appgroup']);
133     }
135     /* Add environment tab if user or group is member in this object group*/
136     if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['environment'])){
137       $this->by_name['environment']= _("Environment");
138       $this->by_object['environment']= new environment($this->config, $this->dn);
139       $this->by_object['environment']->acl = "#all#";
140       $this->by_object['environment']->parent= &$this;
141     }
143     /* Remove environment tab if not required any longer */
144     if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['environment'])){
145       $this->by_object['environment']->remove_from_parent();
146       unset($this->by_name['environment']);
147       unset($this->by_object['environment']);
148     }
149     /* Move reference tab to second position from right */
150     if(isset($this->by_name['acl'])){
151       $tmp = $this->by_name['acl'];
152       unset($this->by_name['acl']);
153       $this->by_name['acl'] = $tmp;
154     }
155   
156     /* Move reference tab to last position*/
157     if(isset($this->by_name['reference'])){
158       $tmp = $this->by_name['reference'];
159       unset($this->by_name['reference']);
160       $this->by_name['reference'] = $tmp;
161     }
163     /* Reset acls */
164     $this->set_acl_base($this->base);
165     foreach($this->by_object as $name => $obj){
166       $this->by_object[$name]->set_acl_category($this->acl_category);
167     }
168   }
170   function execute(){
171     $str = "";
172     $this->by_object['ogroup']->AddDelMembership();
173     $this->reload($this->by_object['ogroup']->gosaGroupObjects);
174     $str .= tabs::execute();
175     return ( $str);
176   }  
178   function ogrouptabs($config, $data, $dn,$category ="ogroups")
179   {
181     tabs::tabs($config, $data, $dn, $category);
182     $this->base= $this->by_object['ogroup']->base;
183     $this->acl_category = $category;
185     /* Insert extra tabs for several object types - if present */
187     $objects= preg_replace('/[\[\]]/', '', $this->by_object['ogroup']->gosaGroupObjects);
188    
189     for ($n= 0; $n<strlen($objects); $n++){
190       switch ($objects[$n]){
191         case "T":
192           /* Add a terminal tab */
193           $this->by_name['termgroup']= _("Terminals");
194           $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
195           $this->by_object['termgroup']->parent= &$this;
197           break;
199           case "U":
200             /* Append a PhoneQueue, if objectClass = goFonAccount */
201             $use = false;
202           foreach($this->by_object['ogroup']->memberList as $dn => $val){
204             $obj = $this->by_object['ogroup']->objcache[$dn];
205             
206             if(isset($obj['objectClass'])){
207               if(in_array("goFonAccount",$obj['objectClass'])){
208                 $use = true; 
209               }
210             }
211           }
213           /* We found goFonAccount in users objectClasses*/
214           if($use){
215             $this->by_name['phonequeue']= _("Phone queue");
216             $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
217             $this->by_object['phonequeue']->parent= &$this;
218           } 
219  
220           /* Add a user tab used for mail distribution lists */
221           if(isset($this->config->current['MAILMETHOD'])){
222             if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
223               $this->by_name['mailogroup']= _("Mail");
224               $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
225               $this->by_object['mailogroup']->parent= &$this;
226             }
227           }
229           break;
230       }
231     }
233     /* Add references/acls/snapshots */
234     $this->reload($this->by_object['ogroup']->gosaGroupObjects);
235     $this->addSpecialTabs();
236   }
239   function check($ignore_account= FALSE)
240   {
241     return (tabs::check(FALSE));
242   }
245   function save_object($save_current= FALSE)
246   {
247     tabs::save_object($save_current);
249     /* Update reference, transfer variables */
250     $baseobject= $this->by_object['ogroup'];
251     foreach ($this->by_object as $name => $obj){
253       /* Don't touch base object */
254       if ($name != 'ogroup'){
255         $obj->parent    = &$this;
256         $obj->uid       = $baseobject->uid;
257         $obj->cn        = $baseobject->cn;
258         $obj->sn        = $baseobject->uid;
259         $obj->givenName = $baseobject->uid;
260         $this->by_object[$name]= $obj;
261       }
263       /* Update parent in base object */
264       $this->by_object['ogroup']->parent= &$this;
265     }
266   }
269   function save($ignore_account= FALSE)
270   {
271     $baseobject= $this->by_object['ogroup'];
273     /* Check for new 'dn', in order to propagate the
274        'dn' to all plugins */
275     $new_dn= 'cn='.$baseobject->cn.','.get_groups_ou().$baseobject->base;
277     /* Move group? */
278     if ($this->dn != $new_dn){
280       /* Write entry on new 'dn' */
281       if ($this->dn != "new"){
282         $baseobject->move($this->dn, $new_dn);
283         $this->by_object['ogroup']= $baseobject;
284       }
286       /* Happen to use the new one */
287       $this->dn= $new_dn;
288     }
290     if ($this->dn == "new"){
291       $this->dn= 'cn='.$baseobject->cn.','.get_groups_ou().$baseobject->base;
292     }
294     tabs::save();
296     /* Fix tagging if needed */
297                 $baseobject->dn= $new_dn;
298     $baseobject->handle_object_tagging();
299   }
301   function getCopyDialog()
302   {
303     $this->reload($this->by_object['ogroup']->gosaGroupObjects); 
304     return(tabs::getCopyDialog());
305   }
308 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
309 ?>