Code

Added app tab if user or group is member
[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['workstartup']))){
43       $this->by_object['workservice']->remove_from_parent();
44       unset($this->by_object['workservice']);
45       unset($this->by_name['workservice']);
46       $this->by_object['workstartup']->remove_from_parent();
47       unset($this->by_object['workstartup']);
48       unset($this->by_name['workstartup']);
49       $this->by_object['faiSummary']->remove_from_parent();
50       unset($this->by_object['faiSummary']);
51       unset($this->by_name['faiSummary']);
52     }
53   
54     /* Create goPhoneAccount if theres an user with goPhoneAccount
55      * but only if there is currently no queue enabled.
56      */
57     $o_cache = $this->by_object['ogroup']->objcache;
58     if(!isset($this->by_object['phonequeue'])){
59       foreach($this->by_object['ogroup']->memberList as $dn => $val){
60         if(isset($o_cache[$dn]['objectClass'])){
61           if(in_array("goFonAccount",$o_cache[$dn]['objectClass'])){
62             require_once("class_phonequeue.inc");
63             $this->by_name['phonequeue']= _("Phone queue");
64             $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
65             $this->by_object['phonequeue']->acl = "#all#";
66             $this->by_object['phonequeue']->parent= &$this;
67           }
68         }
69       }
70     }
72     /* Add mail group tab , if there is curerntly no mail tab defined */ 
73     if((preg_match("/U/",$objects))&&(!isset($this->by_object['mailogroup']))){
74       if(isset($this->config->current['MAILMETHOD'])){
75         if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
76           require_once("class_mailogroup.inc");
77           $this->by_name['mailogroup']= _("Mail");
78           $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
79           $this->by_object['mailogroup']->acl = "#all#";
80           $this->by_object['mailogroup']->parent= &$this;
81         }
82       }
83     }
85     /* Add Terminal tab */
86     if(((preg_match("/T/",$objects)) || (preg_match("/W/",$objects)))&&(!isset($this->by_object['termgroup']))){
87       require_once("class_termgroup.inc");
88       if(!isset($this->by_object['termgroup'])){
89         $this->by_name['termgroup']= _("System");
90         $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
91         $this->by_object['termgroup']->acl = "#all#";
92         $this->by_object['termgroup']->inheritTimeServer = false;
93         $this->by_object['termgroup']->parent= &$this;
94       }
95     }
96     
97     /* Add Workstation tabs */
98     if((preg_match("/W/",$objects))&&(!isset($this->by_object['workstartup']))){
99       if(!isset($this->by_object['workstartup'])){
100         $this->by_name['workstartup']= _("Startup");
101         $this->by_object['workstartup']= new workstartup($this->config, $this->dn);
102         $this->by_object['workstartup']->acl = "#all#";
103         $this->by_object['workstartup']->parent= &$this;
104         $this->by_name['workservice']= _("Devices");
105         $this->by_object['workservice']= new workservice($this->config, $this->dn);
106         $this->by_object['workservice']->acl = "#all#";
107         $this->by_object['workservice']->inheritTimeServer = false;
108         $this->by_object['workservice']->parent= &$this;
109         $this->by_name['faiSummary']= _("Summary");
110         $this->by_object['faiSummary']= new faiSummaryTab($this->config, $this->dn);
111         $this->by_object['faiSummary']->acl = "#all#";
112         $this->by_object['faiSummary']->parent= &$this;
113       }
114     }
116     /* Add application tab if user or group is member in this object group*/ 
117     if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['appgroup'])){
118       $this->by_name['appgroup']= _("Application");
119       $this->by_object['appgroup']= new appgroup($this->config, $this->dn);
120       $this->by_object['appgroup']->acl = "#all#";
121       $this->by_object['appgroup']->parent= &$this;
122     }
124     /* Remove application tab if not required any longer */
125     if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['appgroup'])){
126       $this->by_object['appgroup']->remove_from_parent();
127       unset($this->by_name['appgroup']);
128       unset($this->by_object['appgroup']);
129     }  
130   
131  
132     /* Move reference tab to last position*/
133     if(isset($this->by_name['reference'])){
134       $tmp = $this->by_name['reference'];
135       unset($this->by_name['reference']);
136       $this->by_name['reference'] = $tmp;
137     }
138   }
140   function execute(){
141     $str = "";
142     $this->by_object['ogroup']->AddDelMembership();
143     $this->reload($this->by_object['ogroup']->gosaGroupObjects);
144     $str .= tabs::execute();
145     return ( $str);
146   }  
148   function ogrouptabs($config, $data, $dn)
149   {
151     tabs::tabs($config, $data, $dn);
152     $this->base= $this->by_object['ogroup']->base;
154     /* Insert extra tabs for several object types - if present */
156     $objects= preg_replace('/[\[\]]/', '', $this->by_object['ogroup']->gosaGroupObjects);
157     
158     for ($n= 0; $n<strlen($objects); $n++){
159       switch ($objects[$n]){
160         case "T":
161           /* Add a terminal tab */
162           require_once("class_termgroup.inc");
163           $this->by_name['termgroup']= _("Terminals");
164           $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
165           $this->by_object['termgroup']->parent= &$this;
167           break;
169           case "U":
170             /* Append a PhoneQueue, if objectClass = goFonAccount */
171             $use = false;
172           $o_cache = $this->by_object['ogroup']->objcache;
173           foreach($this->by_object['ogroup']->memberList as $dn => $val){
174             if(isset($o_cache[$dn]['objectClass'])){
175               if(in_array("goFonAccount",$o_cache[$dn]['objectClass'])){
176                 $use = true; 
177               }
178             }
179           }
181           /* We found goFonAccount in users objectClasses*/
182           if($use){
183             require_once("class_phonequeue.inc");
184             $this->by_name['phonequeue']= _("Phone queue");
185             $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
186             $this->by_object['phonequeue']->parent= &$this;
188           } 
189  
190           /* Add a user tab used for mail distribution lists */
191           if(isset($this->config->current['MAILMETHOD'])){
192             if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
193               require_once("class_mailogroup.inc");
194               $this->by_name['mailogroup']= _("Mail");
195               $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
196               $this->by_object['mailogroup']->parent= &$this;
197             }
198           }
200           break;
201       }
202     }
203     $this->reload($this->by_object['ogroup']->gosaGroupObjects);
204   }
207   function check()
208   {
209     return (tabs::check(FALSE));
210   }
213   function save_object($save_current= FALSE)
214   {
215     tabs::save_object($save_current);
217     /* Update reference, transfer variables */
218     $baseobject= $this->by_object['ogroup'];
219     foreach ($this->by_object as $name => $obj){
221       /* Don't touch base object */
222       if ($name != 'ogroup'){
223         $obj->parent    = &$this;
224         $obj->uid       = $baseobject->uid;
225         $obj->cn        = $baseobject->cn;
226         $obj->sn        = $baseobject->uid;
227         $obj->givenName = $baseobject->uid;
228         $this->by_object[$name]= $obj;
229       }
231       /* Update parent in base object */
232       $this->by_object['ogroup']->parent= &$this;
233     }
234   }
237   function save()
238   {
239     $baseobject= $this->by_object['ogroup'];
241     /* Check for new 'dn', in order to propagate the
242        'dn' to all plugins */
243     $new_dn= 'cn='.$baseobject->cn.','.get_groups_ou().$baseobject->base;
245     /* Move group? */
246     if ($this->dn != $new_dn){
248       /* Write entry on new 'dn' */
249       if ($this->dn != "new"){
250         $baseobject->move($this->dn, $new_dn);
251         $this->by_object['ogroup']= $baseobject;
252       }
254       /* Happen to use the new one */
255       $this->dn= $new_dn;
256     }
258     if ($this->dn == "new"){
259       $this->dn= 'cn='.$baseobject->cn.','.get_groups_ou().$baseobject->base;
260     }
262     tabs::save();
264     /* Fix tagging if needed */
265                 $baseobject->dn= $new_dn;
266     $baseobject->handle_object_tagging();
267   }
269   function saveCopyDialog()
270   {
271     tabs::saveCopyDialog();
272     $baseobject= $this->by_object['ogroup'];
273     $cn = $baseobject->cn;
274     foreach($this->by_object as  $name => $obj){
275       $this->by_object[$name]->cn = $cn;
276     }
277   }
281 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
282 ?>