Code

Fixed sorting of management plugin.
[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     $o_cache = $this->by_object['ogroup']->objcache;
15     foreach($this->by_object['ogroup']->memberList as $dn => $val){
16       if(isset($o_cache[$dn]['objectClass'])){
17         if(in_array("goFonAccount",$o_cache[$dn]['objectClass'])){
18           $usePhoneTab = true;
19         }
20       }
21     }
22     if(((!$usePhoneTab)&&(isset($this->by_object['phonequeue'])))||((!preg_match("/U/",$objects))&&(isset($this->by_object['phonequeue'])))){
23       $this->by_object['phonequeue']->remove_from_parent();
24       unset($this->by_object['phonequeue']);
25       unset($this->by_name['phonequeue']);
26     }
27     /* Remove mail group if there is no user anymore */
28     if((!preg_match("/U/",$objects))&&(isset($this->by_object['mailogroup']))){
29       $this->by_object['mailogroup']->remove_from_parent();
30       unset($this->by_object['mailogroup']);
31       unset($this->by_name['mailogroup']);
32     }
33     
34     /* Remove terminal group, if theres no terminal left in the object list */
35     if(((!preg_match("/T/",$objects)) && (!preg_match("/W/",$objects)))&&(isset($this->by_object['termgroup']))){
36       $this->by_object['termgroup']->remove_from_parent();
37       unset($this->by_object['termgroup']);
38       unset($this->by_name['termgroup']);
39     }
40     
41     /* Remove ws tabs, if theres no ws left in the object list */
42     if((!preg_match("/W/",$objects))&&(isset($this->by_object['workservice']))){
43       $this->by_object['workservice']->remove_from_parent();
44       unset($this->by_object['workservice']);
45       unset($this->by_name['workservice']);
46     }
47     if((!preg_match("/S/",$objects) && !preg_match("/W/",$objects))&&(isset($this->by_object['workstartup']))){
48       $this->by_object['workstartup']->remove_from_parent();
49       unset($this->by_object['workstartup']);
50       unset($this->by_name['workstartup']);
51       $this->by_object['faiSummary']->remove_from_parent();
52       unset($this->by_object['faiSummary']);
53       unset($this->by_name['faiSummary']);
54     }
55   
56     /* Create goPhoneAccount if theres an user with goPhoneAccount
57      * but only if there is currently no queue enabled.
58      */
59     $o_cache = $this->by_object['ogroup']->objcache;
60     if(!isset($this->by_object['phonequeue'])){
61       foreach($this->by_object['ogroup']->memberList as $dn => $val){
62         if(isset($o_cache[$dn]['objectClass'])){
63           if(in_array("goFonAccount",$o_cache[$dn]['objectClass'])){
64             require_once("class_phonequeue.inc");
65             $this->by_name['phonequeue']= _("Phone queue");
66             $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
67             $this->by_object['phonequeue']->acl = "#all#";
68             $this->by_object['phonequeue']->parent= &$this;
69           }
70         }
71       }
72     }
74     /* Add mail group tab , if there is curerntly no mail tab defined */ 
75     if((preg_match("/U/",$objects))&&(!isset($this->by_object['mailogroup']))){
76       if(isset($this->config->current['MAILMETHOD'])){
77         if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
78           require_once("class_mailogroup.inc");
79           $this->by_name['mailogroup']= _("Mail");
80           $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
81           $this->by_object['mailogroup']->acl = "#all#";
82           $this->by_object['mailogroup']->parent= &$this;
83         }
84       }
85     }
87     /* Add Terminal tab */
88     if(((preg_match("/T/",$objects)) || (preg_match("/W/",$objects)))&&(!isset($this->by_object['termgroup']))){
89       require_once("class_termgroup.inc");
90       if(!isset($this->by_object['termgroup'])){
91         $this->by_name['termgroup']= _("System");
92         $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
93         $this->by_object['termgroup']->acl = "#all#";
94         $this->by_object['termgroup']->inheritTimeServer = false;
95         $this->by_object['termgroup']->parent= &$this;
96       }
97     }
99     /* Add Workstation tabs */
100     if((preg_match("/W/",$objects))&&(!isset($this->by_object['workservice']))){
101       $this->by_name['workservice']= _("Devices");
102       $this->by_object['workservice']= new workservice($this->config, $this->dn);
103       $this->by_object['workservice']->inheritTimeServer = false;
104       $this->by_object['workservice']->parent= &$this;
105       $this->by_object['workservice']->acl = "#all#";
106     }
107     if((preg_match("/S/",$objects) || preg_match("/W/",$objects))&&(!isset($this->by_object['workstartup']))){
108       $this->by_name['workstartup']= _("Startup");
109       $this->by_object['workstartup']= new workstartup($this->config, $this->dn);
110       $this->by_object['workstartup']->parent= &$this;
111       $this->by_object['workstartup']->acl = "#all#";
112       $this->by_name['faiSummary']= _("Summary");
113       $this->by_object['faiSummary']= new faiSummaryTab($this->config, $this->dn);
114       $this->by_object['faiSummary']->parent= &$this;
115     }
117     /* Add application tab if user or group is member in this object group*/ 
118     if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['appgroup'])){
119       $this->by_name['appgroup']= _("Application");
120       $this->by_object['appgroup']= new appgroup($this->config, $this->dn);
121       $this->by_object['appgroup']->acl = "#all#";
122       $this->by_object['appgroup']->parent= &$this;
123     }
125     /* Remove application tab if not required any longer */
126     if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['appgroup'])){
127       $this->by_object['appgroup']->remove_from_parent();
128       unset($this->by_name['appgroup']);
129       unset($this->by_object['appgroup']);
130     }  
131  
132  
133     /* Add environment tab if user or group is member in this object group*/ 
134     if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['environment'])){
135       $this->by_name['environment']= _("Environment");
136       $this->by_object['environment']= new environment($this->config, $this->dn);
137       $this->by_object['environment']->acl = "#all#";
138       $this->by_object['environment']->parent= &$this;
139     }
141     /* Remove environment tab if not required any longer */
142     if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['environment'])){
143       $this->by_object['environment']->remove_from_parent();
144       unset($this->by_name['environment']);
145       unset($this->by_object['environment']);
146     }  
148  
149     /* Move reference tab to last position*/
150     if(isset($this->by_name['reference'])){
151       $tmp = $this->by_name['reference'];
152       unset($this->by_name['reference']);
153       $this->by_name['reference'] = $tmp;
154     }
155   }
157   function execute(){
158     $str = "";
159     $this->by_object['ogroup']->AddDelMembership();
160     $this->reload($this->by_object['ogroup']->gosaGroupObjects);
161     $str .= tabs::execute();
162     return ( $str);
163   }  
165   function ogrouptabs($config, $data, $dn)
166   {
168     tabs::tabs($config, $data, $dn);
169     $this->base= $this->by_object['ogroup']->base;
171     /* Insert extra tabs for several object types - if present */
173     $objects= preg_replace('/[\[\]]/', '', $this->by_object['ogroup']->gosaGroupObjects);
174     
175     for ($n= 0; $n<strlen($objects); $n++){
176       switch ($objects[$n]){
177         case "T":
178           /* Add a terminal tab */
179           require_once("class_termgroup.inc");
180           $this->by_name['termgroup']= _("Terminals");
181           $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
182           $this->by_object['termgroup']->parent= &$this;
184           break;
186           case "U":
187             /* Append a PhoneQueue, if objectClass = goFonAccount */
188             $use = false;
189           $o_cache = $this->by_object['ogroup']->objcache;
190           foreach($this->by_object['ogroup']->memberList as $dn => $val){
191             if(isset($o_cache[$dn]['objectClass'])){
192               if(in_array("goFonAccount",$o_cache[$dn]['objectClass'])){
193                 $use = true; 
194               }
195             }
196           }
198           /* We found goFonAccount in users objectClasses*/
199           if($use){
200             require_once("class_phonequeue.inc");
201             $this->by_name['phonequeue']= _("Phone queue");
202             $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
203             $this->by_object['phonequeue']->parent= &$this;
205           } 
206  
207           /* Add a user tab used for mail distribution lists */
208           if(isset($this->config->current['MAILMETHOD'])){
209             if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
210               require_once("class_mailogroup.inc");
211               $this->by_name['mailogroup']= _("Mail");
212               $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
213               $this->by_object['mailogroup']->parent= &$this;
214             }
215           }
217           break;
218       }
219     }
220     $this->reload($this->by_object['ogroup']->gosaGroupObjects);
221   }
224   function check()
225   {
226     return (tabs::check(FALSE));
227   }
230   function save_object($save_current= FALSE)
231   {
232     tabs::save_object($save_current);
234     /* Update reference, transfer variables */
235     $baseobject= $this->by_object['ogroup'];
236     foreach ($this->by_object as $name => $obj){
238       /* Don't touch base object */
239       if ($name != 'ogroup'){
240         $obj->parent    = &$this;
241         $obj->uid       = $baseobject->uid;
242         $obj->cn        = $baseobject->cn;
243         $obj->sn        = $baseobject->uid;
244         $obj->givenName = $baseobject->uid;
245         $this->by_object[$name]= $obj;
246       }
248       /* Update parent in base object */
249       $this->by_object['ogroup']->parent= &$this;
250     }
251   }
254   function save()
255   {
256     $baseobject= $this->by_object['ogroup'];
258     /* Check for new 'dn', in order to propagate the
259        'dn' to all plugins */
260     $new_dn= 'cn='.$baseobject->cn.','.get_groups_ou().$baseobject->base;
262     /* Move group? */
263     if ($this->dn != $new_dn){
265       /* Write entry on new 'dn' */
266       if ($this->dn != "new"){
267         $baseobject->move($this->dn, $new_dn);
268         $this->by_object['ogroup']= $baseobject;
269       }
271       /* Happen to use the new one */
272       $this->dn= $new_dn;
273     }
275     if ($this->dn == "new"){
276       $this->dn= 'cn='.$baseobject->cn.','.get_groups_ou().$baseobject->base;
277     }
279     tabs::save();
281     /* Fix tagging if needed */
282                 $baseobject->dn= $new_dn;
283     $baseobject->handle_object_tagging();
284   }
286   function saveCopyDialog()
287   {
288     tabs::saveCopyDialog();
289     $baseobject= $this->by_object['ogroup'];
290     $cn = $baseobject->cn;
291     foreach($this->by_object as  $name => $obj){
292       $this->by_object[$name]->cn = $cn;
293     }
294   }
298 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
299 ?>