Code

Fixed snapshot base
[gosa.git] / plugins / admin / ogroups / tabs_ogroups.inc
1 <?php
3 class ogrouptabs extends tabs
4 {
5   var $base= "";
6   
7   function reload($dd){
8     $objects= preg_replace('/[\[\]]/', '', $dd);
9     
10     /* If there is a phonequeue,
11      * but there is no user left with goPhoneAccount ... remove it.
12      */
13     $usePhoneTab = false;
14     foreach($this->by_object['ogroup']->memberList as $dn => $val){
15       if(isset($val['objectClass'])){
16         if(in_array("goFonAccount",$val['objectClass'])){
17           $usePhoneTab = true;
18         }
19       }
20     }
21     if(((!$usePhoneTab)&&(isset($this->by_object['phonequeue'])))||((!preg_match("/U/",$objects))&&(isset($this->by_object['phonequeue'])))){
22       $this->by_object['phonequeue']->remove_from_parent();
23       unset($this->by_object['phonequeue']);
24       unset($this->by_name['phonequeue']);
25     }
26     /* Remove mail group if there is no user anymore */
27     if((!preg_match("/U/",$objects))&&(isset($this->by_object['mailogroup']))){
28       $this->by_object['mailogroup']->remove_from_parent();
29       unset($this->by_object['mailogroup']);
30       unset($this->by_name['mailogroup']);
31     }
32     
33     /* Remove terminal group, if theres no terminal left in the object list */
34     if(((!preg_match("/T/",$objects)) && (!preg_match("/W/",$objects)))&&(isset($this->by_object['termgroup']))){
35       $this->by_object['termgroup']->remove_from_parent();
36       unset($this->by_object['termgroup']);
37       unset($this->by_name['termgroup']);
38     }
39     
40     /* Remove ws tabs, if theres no ws left in the object list */
41     if((!preg_match("/W/",$objects))&&(isset($this->by_object['workstartup']))){
42       $this->by_object['workservice']->remove_from_parent();
43       unset($this->by_object['workservice']);
44       unset($this->by_name['workservice']);
45       $this->by_object['workstartup']->remove_from_parent();
46       unset($this->by_object['workstartup']);
47       unset($this->by_name['workstartup']);
48       $this->by_object['faiSummary']->remove_from_parent();
49       unset($this->by_object['faiSummary']);
50       unset($this->by_name['faiSummary']);
51     }
52   
53     /* Create goPhoneAccount if theres an user with goPhoneAccount
54      * but only if there is currently no queue enabled.
55      */
56     if(!isset($this->by_object['phonequeue'])){
57       foreach($this->by_object['ogroup']->memberList as $dn => $val){
58         if(isset($val['objectClass'])){
59           if(in_array("goFonAccount",$val['objectClass'])){
60             require_once("class_phonequeue.inc");
61             $this->by_name['phonequeue']= _("Phone queue");
62             $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
63             $this->by_object['phonequeue']->acl = "#all#";
64             $this->by_object['phonequeue']->parent= &$this;
65           }
66         }
67       }
68     }
70     /* Add mail group tab , if there is curerntly no mail tab defined */ 
71     if((preg_match("/U/",$objects))&&(!isset($this->by_object['mailogroup']))){
72       if(isset($this->config->current['MAILMETHOD'])){
73         if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
74           require_once("class_mailogroup.inc");
75           $this->by_name['mailogroup']= _("Mail");
76           $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
77           $this->by_object['mailogroup']->acl = "#all#";
78           $this->by_object['mailogroup']->parent= &$this;
79         }
80       }
81     }
83     /* Add Terminal tab */
84     if(((preg_match("/T/",$objects)) || (preg_match("/W/",$objects)))&&(!isset($this->by_object['termgroup']))){
85       require_once("class_termgroup.inc");
86       if(!isset($this->by_object['termgroup'])){
87         $this->by_name['termgroup']= _("System");
88         $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
89         $this->by_object['termgroup']->acl = "#all#";
90         $this->by_object['termgroup']->inheritTimeServer = false;
91         $this->by_object['termgroup']->parent= &$this;
92       }
93     }
94     
95     /* Add Workstation tabs */
96     if((preg_match("/W/",$objects))&&(!isset($this->by_object['workstartup']))){
97       if(!isset($this->by_object['workstartup'])){
98         $this->by_name['workstartup']= _("Startup");
99         $this->by_object['workstartup']= new workstartup($this->config, $this->dn);
100         $this->by_object['workstartup']->acl = "#all#";
101         $this->by_object['workstartup']->parent= &$this;
102         $this->by_name['workservice']= _("Devices");
103         $this->by_object['workservice']= new workservice($this->config, $this->dn);
104         $this->by_object['workservice']->acl = "#all#";
105         $this->by_object['workservice']->inheritTimeServer = false;
106         $this->by_object['workservice']->parent= &$this;
107         $this->by_name['faiSummary']= _("Summary");
108         $this->by_object['faiSummary']= new faiSummaryTab($this->config, $this->dn);
109         $this->by_object['faiSummary']->acl = "#all#";
110         $this->by_object['faiSummary']->parent= &$this;
111       }
112     }
113   
114     /* Move reference tab to last position*/
115     if(isset($this->by_name['reference'])){
116       $tmp = $this->by_name['reference'];
117       unset($this->by_name['reference']);
118       $this->by_name['reference'] = $tmp;
119     }
120   }
122   function execute(){
123     $str = "";
125     $this->by_object['ogroup']->AddDelMembership();
126     $this->reload($this->by_object['ogroup']->gosaGroupObjects);
127     $str .= tabs::execute();
128     return ( $str);
129   }  
131   function ogrouptabs($config, $data, $dn)
132   {
134     tabs::tabs($config, $data, $dn);
135     $this->base= $this->by_object['ogroup']->base;
137     /* Insert extra tabs for several object types - if present */
139     $objects= preg_replace('/[\[\]]/', '', $this->by_object['ogroup']->gosaGroupObjects);
140     
141     for ($n= 0; $n<strlen($objects); $n++){
142       switch ($objects[$n]){
143         case "T":
144           /* Add a terminal tab */
145           require_once("class_termgroup.inc");
146           $this->by_name['termgroup']= _("Terminals");
147           $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
148           $this->by_object['termgroup']->parent= &$this;
150           break;
152           case "U":
153             /* Append a PhoneQueue, if objectClass = goFonAccount */
154             $use = false;
155           foreach($this->by_object['ogroup']->memberList as $dn => $val){
156             if(isset($val['objectClass'])){
157               if(in_array("goFonAccount",$val['objectClass'])){
158                 $use = true; 
159               }
160             }
161           }
163           /* We found goFonAccount in users objectClasses*/
164           if($use){
165             require_once("class_phonequeue.inc");
166             $this->by_name['phonequeue']= _("Phone queue");
167             $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
168             $this->by_object['phonequeue']->parent= &$this;
170           } 
171  
172           /* Add a user tab used for mail distribution lists */
173           if(isset($this->config->current['MAILMETHOD'])){
174             if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
175               require_once("class_mailogroup.inc");
176               $this->by_name['mailogroup']= _("Mail");
177               $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
178               $this->by_object['mailogroup']->parent= &$this;
179             }
180           }
182           break;
183       }
184     }
185   }
188   function check()
189   {
190     return (tabs::check(FALSE));
191   }
194   function save_object($save_current= FALSE)
195   {
196     tabs::save_object($save_current);
198     /* Update reference, transfer variables */
199     $baseobject= $this->by_object['ogroup'];
200     foreach ($this->by_object as $name => $obj){
202       /* Don't touch base object */
203       if ($name != 'ogroup'){
204         $obj->parent= &$this;
205         $obj->uid= $baseobject->uid;
206         $obj->sn= $baseobject->uid;
207         $obj->givenName= $baseobject->uid;
208         $this->by_object[$name]= $obj;
209       }
211       /* Update parent in base object */
212       $this->by_object['ogroup']->parent= &$this;
213     }
214   }
217   function save()
218   {
219     $baseobject= $this->by_object['ogroup'];
221     /* Check for new 'dn', in order to propagate the
222        'dn' to all plugins */
223     $new_dn= 'cn='.$baseobject->cn.','.get_groups_ou().$baseobject->base;
225     /* Move group? */
226     if ($this->dn != $new_dn){
228       /* Write entry on new 'dn' */
229       if ($this->dn != "new"){
230         $baseobject->move($this->dn, $new_dn);
231         $this->by_object['ogroup']= $baseobject;
232       }
234       /* Happen to use the new one */
235       $this->dn= $new_dn;
236     }
238     if ($this->dn == "new"){
239       $this->dn= 'cn='.$baseobject->cn.','.get_groups_ou().$baseobject->base;
240     }
242     tabs::save();
244     /* Fix tagging if needed */
245                 $baseobject->dn= $new_dn;
246     $baseobject->handle_object_tagging();
247   }
251 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
252 ?>